jr: can now switch between keys
This commit is contained in:
+56
-1
@@ -70,6 +70,7 @@ export {
|
||||
p_get_data,
|
||||
p_generate_keypair,
|
||||
p_get_unique_name,
|
||||
p_activate_key,
|
||||
// background script api
|
||||
b_main
|
||||
};
|
||||
@@ -161,7 +162,7 @@ p_get_unique_name
|
||||
()
|
||||
: Promise<string>
|
||||
{
|
||||
console.log('b_lib p_generate_keypair');
|
||||
console.log('b_lib p_get_unique_name');
|
||||
|
||||
return await browser.runtime.sendMessage({frum: 'popup',
|
||||
data: {method : 'p_get_unique_name',
|
||||
@@ -169,6 +170,22 @@ p_get_unique_name
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Activate given key
|
||||
*/
|
||||
async function
|
||||
p_activate_key
|
||||
(name: string)
|
||||
: Promise<void>
|
||||
{
|
||||
console.log('b_lib p_activate_key');
|
||||
|
||||
return await browser.runtime.sendMessage({frum: 'popup',
|
||||
data: {method : 'p_activate_key',
|
||||
args : {name: name}}}) as void;
|
||||
}
|
||||
|
||||
|
||||
//=============================================================================
|
||||
//=============================================================================
|
||||
// API: BACKGROUND SCRIPT
|
||||
@@ -901,6 +918,7 @@ type bi_popup_calldata
|
||||
= bi_pc_p_get_data
|
||||
| bi_pc_p_generate_keypair
|
||||
| bi_pc_p_get_unique_name
|
||||
| bi_pc_p_activate_key
|
||||
;
|
||||
|
||||
type bi_pc_p_get_data
|
||||
@@ -915,6 +933,10 @@ type bi_pc_p_get_unique_name
|
||||
= {method : 'p_get_unique_name',
|
||||
args : {}};
|
||||
|
||||
type bi_pc_p_activate_key
|
||||
= {method : 'p_activate_key',
|
||||
args : {name: string}};
|
||||
|
||||
type bi_popup_return_data
|
||||
= p_data
|
||||
| void
|
||||
@@ -943,6 +965,8 @@ bi_msg_handler_popup
|
||||
return await bi_p_generate_keypair(msg.args);
|
||||
case 'p_get_unique_name':
|
||||
return await bi_p_get_unique_name(msg.args);
|
||||
case 'p_activate_key':
|
||||
return await bi_p_activate_key(msg.args);
|
||||
default:
|
||||
throw new Error('unsupported popup call method');
|
||||
}
|
||||
@@ -1068,6 +1092,37 @@ bi_name_unique
|
||||
}
|
||||
|
||||
|
||||
async function
|
||||
bi_p_activate_key
|
||||
(args: {name: string})
|
||||
: Promise<void>
|
||||
{
|
||||
console.log('b_lib bi_p_activate_key ' + args.name);
|
||||
|
||||
// get state
|
||||
let istate : bi_state = await bi_get_state();
|
||||
|
||||
// find key with name
|
||||
// type bi_rich_keypair
|
||||
// = {nacl_keypair : bi_nacl_keypair,
|
||||
// name : string,
|
||||
// active : boolean};
|
||||
// type bi_state
|
||||
// = {rich_keypairs: Array<bi_rich_keypair>};
|
||||
let new_rich_keypairs : Array<bi_rich_keypair> = [];
|
||||
for (let this_irkp of istate.rich_keypairs) {
|
||||
// if this is the name, set active = true
|
||||
if (args.name === this_irkp.name)
|
||||
this_irkp.active = true;
|
||||
else
|
||||
this_irkp.active = false;
|
||||
new_rich_keypairs.push(this_irkp);
|
||||
}
|
||||
|
||||
let new_state : bi_state = {rich_keypairs: new_rich_keypairs};
|
||||
await bi_set_state(new_state);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user