jr: gajuphrase recovery seems to work
This commit is contained in:
+85
-1
@@ -53,7 +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_aertext from './jex_include/local-vdk_aertext-0.1.1/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';
|
||||
|
||||
@@ -74,6 +74,7 @@ export {
|
||||
p_activate_key,
|
||||
p_delete_key,
|
||||
p_get_gphrase,
|
||||
p_gphrase_recover,
|
||||
// background script api
|
||||
b_main
|
||||
};
|
||||
@@ -217,6 +218,21 @@ p_get_gphrase
|
||||
args : {name: name}}}) as string;
|
||||
}
|
||||
|
||||
|
||||
async function
|
||||
p_gphrase_recover
|
||||
(gphrase : string,
|
||||
name : string)
|
||||
: Promise<void>
|
||||
{
|
||||
console.log('b_lib p_gphrase_recover', {gphrase: gphrase, name: name});
|
||||
|
||||
return await browser.runtime.sendMessage({frum: 'popup',
|
||||
data: {method : 'p_gphrase_recover',
|
||||
args : {gphrase : gphrase,
|
||||
name : name}}}) as void;
|
||||
}
|
||||
|
||||
//=============================================================================
|
||||
//=============================================================================
|
||||
// API: BACKGROUND SCRIPT
|
||||
@@ -952,6 +968,7 @@ type bi_popup_calldata
|
||||
| bi_pc_p_activate_key
|
||||
| bi_pc_p_delete_key
|
||||
| bi_pc_p_get_gphrase
|
||||
| bi_pc_p_gphrase_recover
|
||||
;
|
||||
|
||||
type bi_pc_p_get_data
|
||||
@@ -978,6 +995,11 @@ type bi_pc_p_get_gphrase
|
||||
= {method : 'p_get_gphrase',
|
||||
args : {name: string}};
|
||||
|
||||
type bi_pc_p_gphrase_recover
|
||||
= {method : 'p_gphrase_recover',
|
||||
args : {gphrase : string,
|
||||
name : string}};
|
||||
|
||||
|
||||
type bi_popup_return_data
|
||||
= p_data
|
||||
@@ -1013,6 +1035,8 @@ bi_msg_handler_popup
|
||||
return await bi_p_delete_key(msg.args);
|
||||
case 'p_get_gphrase':
|
||||
return await bi_p_get_gphrase(msg.args);
|
||||
case 'p_gphrase_recover':
|
||||
return await bi_p_gphrase_recover(msg.args);
|
||||
default:
|
||||
throw new Error('unsupported popup call method');
|
||||
}
|
||||
@@ -1250,6 +1274,66 @@ bi_privkey2gphrase
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* If decoding throws an error we raise it here
|
||||
*/
|
||||
async function
|
||||
bi_gphrase2privkey_unsafe
|
||||
(gphrase: string)
|
||||
: Promise<Uint8Array>
|
||||
{
|
||||
let maybe_privkey = await vdk_aertext.decode(gphrase);
|
||||
if (maybe_privkey.ok)
|
||||
return maybe_privkey.result;
|
||||
else
|
||||
throw new Error(maybe_privkey.error);
|
||||
}
|
||||
|
||||
|
||||
|
||||
async function
|
||||
bi_p_gphrase_recover
|
||||
(args: {gphrase : string,
|
||||
name : string})
|
||||
: Promise<void>
|
||||
{
|
||||
console.log('b_lib bi_p_gphrase_recover', {gphrase: args.gphrase, name: args.name});
|
||||
|
||||
// get state
|
||||
let istate : bi_state = await bi_get_state();
|
||||
|
||||
// find key with name
|
||||
// type bi_nacl_keypair
|
||||
// = {secretKey : Uint8Array,
|
||||
// publicKey : Uint8Array};
|
||||
// type bi_rich_keypair
|
||||
// = {nacl_keypair : bi_nacl_keypair,
|
||||
// name : string,
|
||||
// active : boolean};
|
||||
// type bi_state
|
||||
// = {rich_keypairs: Array<bi_rich_keypair>};
|
||||
|
||||
// make secret key from this
|
||||
let privkey_bytes : Uint8Array = await bi_gphrase2privkey_unsafe(args.gphrase);
|
||||
// double check to make sure it's not already here
|
||||
for (let this_irkp of istate.rich_keypairs) {
|
||||
let this_privkey: Uint8Array = this_irkp.nacl_keypair.secretKey;
|
||||
if (vdk_binary.bytes_eq(this_privkey, privkey_bytes))
|
||||
throw new Error('key already added!');
|
||||
}
|
||||
|
||||
// @ts-ignore fuck off typescript we all know nacl sucks
|
||||
let nacl_keypair : bi_nacl_keypair = nacl.sign.keyPair.fromSecretKey(privkey_bytes);
|
||||
// only active if it's the first keypair
|
||||
let active : boolean = bi_no_keypairs(istate);
|
||||
let new_rich_keypair : bi_rich_keypair = {nacl_keypair : nacl_keypair,
|
||||
name : args.name,
|
||||
active : active};
|
||||
istate.rich_keypairs.push(new_rich_keypair);
|
||||
|
||||
await bi_set_state(istate);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user