jr: generating new keypair works
This commit is contained in:
+98
-23
@@ -67,6 +67,7 @@ export type {
|
||||
export {
|
||||
// popup script api
|
||||
p_get_data,
|
||||
p_generate_keypair,
|
||||
// background script api
|
||||
b_main
|
||||
};
|
||||
@@ -115,30 +116,32 @@ p_get_data
|
||||
()
|
||||
: Promise<p_data>
|
||||
{
|
||||
console.log('popup p_data');
|
||||
console.log('b_lib p_get_data');
|
||||
|
||||
// type bi_state
|
||||
// = {keypairs: Array<bi_nacl_keypair>};
|
||||
// type bi_nacl_keypair
|
||||
// = {secretKey : Uint8Array,
|
||||
// publicKey : Uint8Array};
|
||||
let jr_state : bi_state = await bi_get_state();
|
||||
|
||||
// accumulator
|
||||
let akstrs : Array<string> = [];
|
||||
|
||||
for (let this_keypair of jr_state.keypairs) {
|
||||
let this_pubkey : Uint8Array = this_keypair.publicKey;
|
||||
let this_ak_str : string = await vdk_aeser.pubkey2ak_str(this_pubkey);
|
||||
akstrs.push(this_ak_str);
|
||||
}
|
||||
|
||||
// type p_data =
|
||||
// {pubkey_ak_strs : Array<string>};
|
||||
return {pubkey_ak_strs: akstrs};
|
||||
return await browser.runtime.sendMessage({frum: 'popup',
|
||||
data: {method : 'p_get_data',
|
||||
args : {}}}) as p_data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Called when user clicks "generate keypair" button in popup window
|
||||
*
|
||||
* Destructively updates jr state
|
||||
*/
|
||||
async function
|
||||
p_generate_keypair
|
||||
()
|
||||
: Promise<void>
|
||||
{
|
||||
console.log('b_lib p_generate_keypair');
|
||||
|
||||
return await browser.runtime.sendMessage({frum: 'popup',
|
||||
data: {method : 'p_generate_keypair',
|
||||
args : {}}}) as void;
|
||||
}
|
||||
|
||||
//=============================================================================
|
||||
//=============================================================================
|
||||
// API: BACKGROUND SCRIPT
|
||||
@@ -748,11 +751,20 @@ bi_mk_w2a_msg_err
|
||||
|
||||
|
||||
type bi_popup_calldata
|
||||
= 'init';
|
||||
= bi_pc_p_get_data
|
||||
| bi_pc_p_generate_keypair;
|
||||
|
||||
type bi_pc_p_get_data =
|
||||
{method : 'p_get_data',
|
||||
args : {}};
|
||||
|
||||
type bi_pc_p_generate_keypair =
|
||||
{method : 'p_generate_keypair',
|
||||
args : {}};
|
||||
|
||||
type bi_popup_return_data
|
||||
= 'die';
|
||||
= p_data
|
||||
| void;
|
||||
|
||||
|
||||
/**
|
||||
@@ -768,11 +780,74 @@ bi_msg_handler_popup
|
||||
: Promise<bi_popup_return_data>
|
||||
{
|
||||
console.log('jr bg_msg_handler_popup msg', msg);
|
||||
return 'die';
|
||||
|
||||
switch(msg.method) {
|
||||
case 'p_get_data':
|
||||
return await bi_p_get_data(msg.args);
|
||||
case 'p_generate_keypair':
|
||||
return await bi_p_generate_keypair(msg.args);
|
||||
default:
|
||||
throw new Error('unsupported popup call method');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
async function
|
||||
bi_p_get_data
|
||||
(args: {})
|
||||
: Promise<p_data>
|
||||
{
|
||||
console.log('b_lib bi_p_get_data');
|
||||
// type bi_state
|
||||
// = {keypairs: Array<bi_nacl_keypair>};
|
||||
// type bi_nacl_keypair
|
||||
// = {secretKey : Uint8Array,
|
||||
// publicKey : Uint8Array};
|
||||
let jr_state : bi_state = await bi_get_state();
|
||||
|
||||
// accumulator
|
||||
let akstrs : Array<string> = [];
|
||||
|
||||
for (let this_keypair of jr_state.keypairs) {
|
||||
let this_pubkey : Uint8Array = this_keypair.publicKey;
|
||||
let this_ak_str : string = await vdk_aeser.pubkey2ak_str(this_pubkey);
|
||||
akstrs.push(this_ak_str);
|
||||
}
|
||||
|
||||
// type p_data =
|
||||
// {pubkey_ak_strs : Array<string>};
|
||||
return {pubkey_ak_strs: akstrs};
|
||||
}
|
||||
|
||||
|
||||
|
||||
async function
|
||||
bi_p_generate_keypair
|
||||
(args: {})
|
||||
: Promise<void>
|
||||
{
|
||||
console.log('b_lib bi_p_generate_keypair');
|
||||
|
||||
// get state
|
||||
let state : bi_state = await bi_get_state();
|
||||
|
||||
// type bi_state
|
||||
// = {keypairs: Array<bi_nacl_keypair>};
|
||||
// type bi_nacl_keypair
|
||||
// = {secretKey : Uint8Array,
|
||||
// publicKey : Uint8Array};
|
||||
// @ts-ignore fuck off typescript
|
||||
let new_keypair : bi_nacl_keypair = nacl.sign.keyPair() as bi_nacl_keypair;
|
||||
state.keypairs.push(new_keypair);
|
||||
|
||||
// set new state
|
||||
await bi_set_state(state);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//=============================================================================
|
||||
//=============================================================================
|
||||
// INTERNALS: STORAGE API
|
||||
|
||||
Reference in New Issue
Block a user