[wip] done genericizing popup (works!)
now moving on to mansplaining
This commit is contained in:
+1
-1
@@ -5,5 +5,5 @@
|
|||||||
{deps, ["local-tweetnacl-1.0.3",
|
{deps, ["local-tweetnacl-1.0.3",
|
||||||
"local-awcp-0.2.3",
|
"local-awcp-0.2.3",
|
||||||
"local-vdk_aecrypt-0.1.2",
|
"local-vdk_aecrypt-0.1.2",
|
||||||
"local-vdk_aeser-0.1.0",
|
"local-vdk_aeser-0.1.1",
|
||||||
"local-vdk_binary-0.1.0"]}.
|
"local-vdk_binary-0.1.0"]}.
|
||||||
|
|||||||
+21
-38
@@ -53,7 +53,7 @@
|
|||||||
|
|
||||||
import * as awcp from './jex_include/local-awcp-0.2.3/dist/awcp.js';
|
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_aecrypt from './jex_include/local-vdk_aecrypt-0.1.2/dist/vdk_aecrypt.js';
|
||||||
import * as vdk_aeser from './jex_include/local-vdk_aeser-0.1.0/dist/vdk_aeser.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';
|
import * as vdk_binary from './jex_include/local-vdk_binary-0.1.0/dist/vdk_binary.js';
|
||||||
|
|
||||||
|
|
||||||
@@ -69,6 +69,14 @@ export {
|
|||||||
b_main
|
b_main
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// INTERNAL CONSTANTS ALL IN ONE PLACE
|
||||||
|
let GB_ITER_MS = 5; // [MS / ITER] 5 ms every 1 iteration
|
||||||
|
let GB_ITERS = 1;
|
||||||
|
let GB_SEC = 200*GB_ITERS; // [ITER]; 1iter / 5ms = 200iter / sec
|
||||||
|
let GB_MIN = 60*GB_SEC; // [ITER]
|
||||||
|
|
||||||
|
let MSG_SIGN_TIMEOUT = 30*GB_MIN;
|
||||||
|
let TX_SIGN_TIMEOUT = 30*GB_MIN;
|
||||||
|
|
||||||
|
|
||||||
//=============================================================================
|
//=============================================================================
|
||||||
@@ -381,12 +389,10 @@ msg_sign
|
|||||||
| {result : 'bad'}
|
| {result : 'bad'}
|
||||||
>
|
>
|
||||||
{
|
{
|
||||||
let result: 'good' | 'bad'
|
let result : gb = await gb('Do you want to sign this message?', msg_str, MSG_SIGN_TIMEOUT);
|
||||||
= await gb('Do you want to sign this message?',
|
|
||||||
msg_str,
|
|
||||||
30*GB_MIN);
|
|
||||||
|
|
||||||
// if confirm
|
// if the user wants us to sign the transaction, return the signed transaction
|
||||||
|
// confirm
|
||||||
if
|
if
|
||||||
(result === 'good') {
|
(result === 'good') {
|
||||||
// use nacl detached signatures
|
// use nacl detached signatures
|
||||||
@@ -401,6 +407,7 @@ msg_sign
|
|||||||
return {result : 'good',
|
return {result : 'good',
|
||||||
signature : signature_str};
|
signature : signature_str};
|
||||||
}
|
}
|
||||||
|
// otherwise don't
|
||||||
else {
|
else {
|
||||||
return {result : 'bad'};
|
return {result : 'bad'};
|
||||||
}
|
}
|
||||||
@@ -420,41 +427,19 @@ msg_sign
|
|||||||
*/
|
*/
|
||||||
async function
|
async function
|
||||||
tx_sign
|
tx_sign
|
||||||
(tx_str : string,
|
(tx_str : string,
|
||||||
secret_key : Uint8Array)
|
secret_key : Uint8Array)
|
||||||
: Promise< {result : 'good',
|
: Promise< {result : 'good',
|
||||||
signedTransaction : string}
|
signedTransaction : string}
|
||||||
| {result : 'bad'}
|
| {result : 'bad'}
|
||||||
>
|
>
|
||||||
{
|
{
|
||||||
// does the user want to sign the message
|
let mansplained_tx : string = await vdk_aeser.mansplain_str(tx_str);
|
||||||
let confirm_window = await browser.windows.create({url : '../pages/tx_confirm.html',
|
let result : gb = await gb('Do you want to sign this transaction?',
|
||||||
type : 'popup'});
|
mansplained_tx,
|
||||||
|
TX_SIGN_TIMEOUT);
|
||||||
|
|
||||||
// @ts-ignore shut the fuck up
|
// if we're supposed to sign the tx, then sign it
|
||||||
let tabid : number = confirm_window.tabs[0].id;
|
|
||||||
|
|
||||||
// stupid hack because otherwise the message gets sent before the listener in the page script is created
|
|
||||||
await sleep(200);
|
|
||||||
|
|
||||||
// debug: show tx
|
|
||||||
let mansplained_tx : object = await vdk_aeser.mansplain(tx_str);
|
|
||||||
console.log('mansplained_tx,', mansplained_tx);
|
|
||||||
|
|
||||||
type browser_send_data = {tx_str : string,
|
|
||||||
tx_data : object};
|
|
||||||
|
|
||||||
let result: 'good' | 'bad'
|
|
||||||
= await browser.tabs.sendMessage(tabid,
|
|
||||||
{tx_str : tx_str,
|
|
||||||
tx_data : mansplained_tx});
|
|
||||||
|
|
||||||
|
|
||||||
console.log('result', result);
|
|
||||||
|
|
||||||
// close the popup
|
|
||||||
browser.tabs.remove(tabid);
|
|
||||||
// if we're supposed to sign the tx
|
|
||||||
if
|
if
|
||||||
('good' === result) {
|
('good' === result) {
|
||||||
let tx_bytes : Uint8Array = (await vdk_aeser.unbaseNcheck(tx_str)).bytes;
|
let tx_bytes : Uint8Array = (await vdk_aeser.unbaseNcheck(tx_str)).bytes;
|
||||||
@@ -463,6 +448,7 @@ tx_sign
|
|||||||
// we sign <<NetworkId, SerializedObject>>
|
// we sign <<NetworkId, SerializedObject>>
|
||||||
// SerializedObject can either be the object or the hash of the object
|
// SerializedObject can either be the object or the hash of the object
|
||||||
// let's stick with hash for now
|
// let's stick with hash for now
|
||||||
|
// FIXME: get network id from application state
|
||||||
let network_id : Uint8Array = vdk_binary.encode_utf8('ae_uat');
|
let network_id : Uint8Array = vdk_binary.encode_utf8('ae_uat');
|
||||||
// let tx_hash_bytes : Uint8Array = hash(tx_bytes);
|
// let tx_hash_bytes : Uint8Array = hash(tx_bytes);
|
||||||
let sign_data : Uint8Array = vdk_binary.bytes_concat(network_id, tx_bytes);
|
let sign_data : Uint8Array = vdk_binary.bytes_concat(network_id, tx_bytes);
|
||||||
@@ -483,10 +469,7 @@ tx_sign
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
let GB_ITER_MS = 5; // [MS / ITER] 5 ms every 1 iteration
|
|
||||||
let GB_ITERS = 1;
|
|
||||||
let GB_SEC = 200*GB_ITERS; // [ITER]; 1iter / 5ms = 200iter / sec
|
|
||||||
let GB_MIN = 60*GB_SEC; // [ITER]
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This pops up a window for the luser and asks if the thing is good or bad.
|
* This pops up a window for the luser and asks if the thing is good or bad.
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{type, library}.
|
{type, library}.
|
||||||
{realm, local}.
|
{realm, local}.
|
||||||
{name, vdk_aeser}.
|
{name, vdk_aeser}.
|
||||||
{version, "0.1.0"}.
|
{version, "0.1.1"}.
|
||||||
{deps, ["local-vdk_base58-0.1.0",
|
{deps, ["local-vdk_base58-0.1.0",
|
||||||
"local-vdk_base64-0.1.0",
|
"local-vdk_base64-0.1.0",
|
||||||
"local-vdk_rlp-0.1.0",
|
"local-vdk_rlp-0.1.0",
|
||||||
|
|||||||
@@ -22,7 +22,8 @@ export {
|
|||||||
unbaseNcheck,
|
unbaseNcheck,
|
||||||
baseNcheck,
|
baseNcheck,
|
||||||
signed_tx,
|
signed_tx,
|
||||||
mansplain
|
mansplain,
|
||||||
|
mansplain_str
|
||||||
}
|
}
|
||||||
|
|
||||||
export type {
|
export type {
|
||||||
@@ -290,6 +291,24 @@ signed_tx
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Take apart some API-encoded data and return a string that explains it to the
|
||||||
|
* user.
|
||||||
|
*
|
||||||
|
* Mostly for the "confirm transaction" popup
|
||||||
|
*/
|
||||||
|
async function
|
||||||
|
mansplain_str
|
||||||
|
(api_str : string)
|
||||||
|
: Promise<string>
|
||||||
|
{
|
||||||
|
let mansplained_obj : object = await mansplain(api_str)
|
||||||
|
|
||||||
|
return JSON.stringify(mansplained_obj, undefined, 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Take apart some API-encoded data and show its component parts
|
* Take apart some API-encoded data and show its component parts
|
||||||
*
|
*
|
||||||
@@ -314,6 +333,7 @@ mansplain
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Take RLP encoded bytes and mansplain them
|
* Take RLP encoded bytes and mansplain them
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user