jr: gajuphrase recovery seems to work
This commit is contained in:
+1
-1
@@ -5,6 +5,6 @@
|
||||
{deps, ["local-tweetnacl-1.0.3",
|
||||
"local-awcp-0.2.3",
|
||||
"local-vdk_aecrypt-0.1.2",
|
||||
"local-vdk_aertext-0.1.0",
|
||||
"local-vdk_aertext-0.1.1",
|
||||
"local-vdk_aeser-0.1.1",
|
||||
"local-vdk_binary-0.1.0"]}.
|
||||
|
||||
@@ -73,6 +73,9 @@
|
||||
</table>
|
||||
<!-- recover from faert phrase -->
|
||||
<form>
|
||||
<label for="faert-name">Name:</label>
|
||||
<input id="faert-name"></input>
|
||||
<br>
|
||||
<label for="faert-input">GajuPhrase:</label>
|
||||
<input id="faert-input"></input>
|
||||
<br>
|
||||
|
||||
+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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
+22
-3
@@ -35,8 +35,11 @@ p_main
|
||||
|
||||
|
||||
// add unique name for default
|
||||
let unique_name: string = await b_lib.p_get_unique_name();
|
||||
// @ts-ignore fuck off
|
||||
document.getElementById('generate-name')!.value = await b_lib.p_get_unique_name();
|
||||
document.getElementById('generate-name')!.value = unique_name;
|
||||
// @ts-ignore fuck off
|
||||
document.getElementById('faert-name')!.value = unique_name;
|
||||
|
||||
// add hooks for each button
|
||||
let onclick_generate =
|
||||
@@ -50,6 +53,22 @@ p_main
|
||||
document
|
||||
.getElementById('generate-btn')!
|
||||
.addEventListener('click', onclick_generate);
|
||||
|
||||
// gphrase recovery
|
||||
let onclick_gphrase =
|
||||
async function () {
|
||||
// get the phrase and name
|
||||
// @ts-ignore fuck off i know my own document
|
||||
//document.getElementById('faert-name')!.value = 'farts';
|
||||
let name = document.getElementById('faert-name')!.value;
|
||||
// @ts-ignore fuck off again
|
||||
let gphrase = document.getElementById('faert-input')!.value;
|
||||
await b_lib.p_gphrase_recover(gphrase, name);
|
||||
pi_repop();
|
||||
};
|
||||
document
|
||||
.getElementById('faert-btn')!
|
||||
.addEventListener('click', onclick_gphrase);
|
||||
}
|
||||
|
||||
|
||||
@@ -140,7 +159,7 @@ pi_repop
|
||||
del_a.onclick =
|
||||
async function () {
|
||||
await b_lib.p_delete_key(this_rkp.name);
|
||||
await pi_repop();
|
||||
pi_repop();
|
||||
};
|
||||
del_li.appendChild(del_a);
|
||||
|
||||
@@ -189,7 +208,7 @@ pi_repop
|
||||
async function () {
|
||||
// tell controller that we want to activate this key
|
||||
await b_lib.p_activate_key(this_rkp.name);
|
||||
await pi_repop();
|
||||
pi_repop();
|
||||
};
|
||||
// add li and a
|
||||
activate_li.appendChild(activate_a);
|
||||
|
||||
Reference in New Issue
Block a user