[wip] somehow tx signature confirmation broke blakejs

it's all just so tiresome
This commit is contained in:
2023-10-02 16:56:12 -06:00
parent 7d87fd626f
commit 16a4bcebba
3 changed files with 93 additions and 27 deletions
+59 -19
View File
@@ -335,7 +335,13 @@ bi_msg_handler_content
let tx_str : string = msg.data.params.tx;
console.log('transaction: ', tx_str);
let result = await tx_sign(tx_str, secret_key)
return w2a_ok({signedTransaction: result.signedTransaction});
if
('good' === result.result) {
return w2a_ok({signedTransaction: result.signedTransaction});
}
else {
return w2a_err(awcp.ERROR_CODE_RpcRejectedByUserError, "your not pretty enough");
}
//if (result.result === 'good') {
// return w2a_ok({signedTransaction: result.signedTransaction});
//}
@@ -424,32 +430,66 @@ async function
tx_sign
(tx_str : string,
secret_key : Uint8Array)
: Promise<{signedTransaction : string}>
: Promise< {result : 'good',
signedTransaction : string}
| {result : 'bad'}
>
{
// does the user want to sign the message
let confirm_window = await browser.windows.create({url : '../pages/tx_confirm.html',
type : 'popup'});
// @ts-ignore shut the fuck up
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 tx_bytes : Uint8Array = (await vdk_aeser.unbaseNcheck(tx_str)).bytes;
// thank you ulf
// https://github.com/aeternity/protocol/tree/fd179822fc70241e79cbef7636625cf344a08109/consensus#transaction-signature
// we sign <<NetworkId, SerializedObject>>
// SerializedObject can either be the object or the hash of the object
// let's stick with hash for now
let network_id : Uint8Array = vdk_binary.encode_utf8('ae_uat');
// let tx_hash_bytes : Uint8Array = hash(tx_bytes);
let sign_data : Uint8Array = vdk_binary.bytes_concat(network_id, tx_bytes);
// @ts-ignore yes nacl is stupid
let signature : Uint8Array = nacl.sign.detached(sign_data, secret_key);
let signed_tx_bytes : Uint8Array = vdk_aeser.signed_tx([signature], tx_bytes);
let signed_tx_str : string = await vdk_aeser.baseNcheck('tx', signed_tx_bytes);
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
('good' === result) {
let tx_bytes : Uint8Array = (await vdk_aeser.unbaseNcheck(tx_str)).bytes;
// thank you ulf
// https://github.com/aeternity/protocol/tree/fd179822fc70241e79cbef7636625cf344a08109/consensus#transaction-signature
// we sign <<NetworkId, SerializedObject>>
// SerializedObject can either be the object or the hash of the object
// let's stick with hash for now
let network_id : Uint8Array = vdk_binary.encode_utf8('ae_uat');
// let tx_hash_bytes : Uint8Array = hash(tx_bytes);
let sign_data : Uint8Array = vdk_binary.bytes_concat(network_id, tx_bytes);
// @ts-ignore yes nacl is stupid
let signature : Uint8Array = nacl.sign.detached(sign_data, secret_key);
let signed_tx_bytes : Uint8Array = vdk_aeser.signed_tx([signature], tx_bytes);
let signed_tx_str : string = await vdk_aeser.baseNcheck('tx', signed_tx_bytes);
// debugging
let mansplained_stx : object = await vdk_aeser.mansplain(signed_tx_str);
console.log('mansplained signed tx:', mansplained_stx);
return {result : 'good',
signedTransaction : signed_tx_str};
}
// if user rejected the tx
else {
return {result : 'bad'};
}
// debugging
let mansplained_stx : object = await vdk_aeser.mansplain(signed_tx_str);
console.log('mansplained signed tx:', mansplained_stx);
return {signedTransaction: signed_tx_str};
}
/**