jr: show gajuphrase works!

This commit is contained in:
2024-03-19 04:08:21 -06:00
parent 46d0fecd03
commit df3bb57c5c
2 changed files with 80 additions and 0 deletions
+57
View File
@@ -53,6 +53,7 @@
import * as awcp from './jex_include/local-awcp-0.2.3/dist/awcp.js';
import * as vdk_aecrypt from './jex_include/local-vdk_aecrypt-0.1.2/dist/vdk_aecrypt.js';
import * as vdk_aertext from './jex_include/local-vdk_aertext-0.1.0/dist/vdk_aertext.js';
import * as vdk_aeser from './jex_include/local-vdk_aeser-0.1.1/dist/vdk_aeser.js';
import * as vdk_binary from './jex_include/local-vdk_binary-0.1.0/dist/vdk_binary.js';
@@ -72,6 +73,7 @@ export {
p_get_unique_name,
p_activate_key,
p_delete_key,
p_get_gphrase,
// background script api
b_main
};
@@ -203,6 +205,18 @@ p_delete_key
}
async function
p_get_gphrase
(name: string)
: Promise<string>
{
console.log('b_lib p_get_gphrase', {name: name});
return await browser.runtime.sendMessage({frum: 'popup',
data: {method : 'p_get_gphrase',
args : {name: name}}}) as string;
}
//=============================================================================
//=============================================================================
// API: BACKGROUND SCRIPT
@@ -937,6 +951,7 @@ type bi_popup_calldata
| bi_pc_p_get_unique_name
| bi_pc_p_activate_key
| bi_pc_p_delete_key
| bi_pc_p_get_gphrase
;
type bi_pc_p_get_data
@@ -959,6 +974,10 @@ type bi_pc_p_delete_key
= {method : 'p_delete_key',
args : {name: string}};
type bi_pc_p_get_gphrase
= {method : 'p_get_gphrase',
args : {name: string}};
type bi_popup_return_data
= p_data
@@ -992,6 +1011,8 @@ bi_msg_handler_popup
return await bi_p_activate_key(msg.args);
case 'p_delete_key':
return await bi_p_delete_key(msg.args);
case 'p_get_gphrase':
return await bi_p_get_gphrase(msg.args);
default:
throw new Error('unsupported popup call method');
}
@@ -1193,6 +1214,42 @@ bi_p_delete_key
}
async function
bi_p_get_gphrase
(args: {name: string})
: Promise<string>
{
console.log('b_lib bi_p_get_gphrase', {name: 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>};
for (let this_irkp of istate.rich_keypairs) {
if (args.name === this_irkp.name)
return await bi_privkey2gphrase(this_irkp.nacl_keypair.secretKey);
}
return "ERROR: impossible state (getting GajuPhrase of key that doesn't exist)";
}
async function
bi_privkey2gphrase
(privkey: Uint8Array)
: Promise<string>
{
return await vdk_aertext.encode(privkey);
}