jr: show gajuphrase works!
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -144,10 +144,33 @@ pi_repop
|
||||
};
|
||||
del_li.appendChild(del_a);
|
||||
|
||||
// add gajuphrase button
|
||||
// add delete button
|
||||
let gphrase_li = document.createElement('li');
|
||||
|
||||
let gphrase_a = document.createElement('a');
|
||||
gphrase_a.href = '#'
|
||||
gphrase_a.innerHTML = this_rkp.akstr;
|
||||
gphrase_a.innerHTML = 'Show GajuPhrase';
|
||||
gphrase_a.onclick =
|
||||
async function () {
|
||||
let gphrase_s : string = await b_lib.p_get_gphrase(this_rkp.name);
|
||||
let br = document.createElement('br');
|
||||
gphrase_li.appendChild(br);
|
||||
|
||||
let gphrase_span = document.createElement('span');
|
||||
gphrase_span.innerHTML = gphrase_s;
|
||||
gphrase_span.style.fontSize = 'x-small';
|
||||
gphrase_li.appendChild(gphrase_span);
|
||||
};
|
||||
gphrase_li.appendChild(gphrase_a);
|
||||
|
||||
|
||||
// add everything inside-out
|
||||
rkp_ul.appendChild(addr_li);
|
||||
rkp_ul.appendChild(name_li);
|
||||
rkp_ul.appendChild(del_li);
|
||||
rkp_ul.appendChild(gphrase_li);
|
||||
this_li.appendChild(rkp_ul);
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user