[wip] ironing out bugs in tx signing procedure
this time learned - need to have tag and version for the return data - i think i need to sign the hash of the transaction rather than the transaction
This commit is contained in:
+4
-1
@@ -52,6 +52,7 @@
|
|||||||
|
|
||||||
|
|
||||||
import * as awcp from './jex_include/local-awcp-0.2.2/dist/awcp.js';
|
import * as awcp from './jex_include/local-awcp-0.2.2/dist/awcp.js';
|
||||||
|
// @ts-ignore yes i know blake is stupid
|
||||||
import * as blake2b from './jex_include/local-blakejs-1.2.1/dist/blake2b.js';
|
import * as blake2b from './jex_include/local-blakejs-1.2.1/dist/blake2b.js';
|
||||||
//import * as vdk_aecrypt from './jex_include/local-vdk_aecrypt-0.1.0/dist/vdk_aecrypt.js';
|
//import * as vdk_aecrypt from './jex_include/local-vdk_aecrypt-0.1.0/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.0/dist/vdk_aeser.js';
|
||||||
@@ -326,7 +327,7 @@ bi_msg_handler_content
|
|||||||
case "transaction.sign":
|
case "transaction.sign":
|
||||||
console.log('jr bg content message handler transaction sign');
|
console.log('jr bg content message handler transaction sign');
|
||||||
let tx_str : string = msg.data.params.tx;
|
let tx_str : string = msg.data.params.tx;
|
||||||
console.log('transaction: ', tx);
|
console.log('transaction: ', tx_str);
|
||||||
let result = await tx_sign(tx_str, secret_key)
|
let result = await tx_sign(tx_str, secret_key)
|
||||||
console.log('signed transaction: ', result.signedTransaction);
|
console.log('signed transaction: ', result.signedTransaction);
|
||||||
return w2a_ok(result);
|
return w2a_ok(result);
|
||||||
@@ -358,6 +359,7 @@ msg_sign
|
|||||||
// https://github.com/aeternity/aepp-sdk-js/blob/5df22dd297abebc0607710793a7234e6761570d4/src/utils/crypto.ts#L141-L143
|
// https://github.com/aeternity/aepp-sdk-js/blob/5df22dd297abebc0607710793a7234e6761570d4/src/utils/crypto.ts#L141-L143
|
||||||
// https://github.com/aeternity/aepp-sdk-js/blob/5df22dd297abebc0607710793a7234e6761570d4/src/utils/crypto.ts#L160-L167
|
// https://github.com/aeternity/aepp-sdk-js/blob/5df22dd297abebc0607710793a7234e6761570d4/src/utils/crypto.ts#L160-L167
|
||||||
let hashed_salted_msg : Uint8Array = hash_and_salt_msg(msg_str);
|
let hashed_salted_msg : Uint8Array = hash_and_salt_msg(msg_str);
|
||||||
|
// @ts-ignore yes nacl is stupid
|
||||||
let signature : Uint8Array = nacl.sign.detached(hashed_salted_msg, secret_key);
|
let signature : Uint8Array = nacl.sign.detached(hashed_salted_msg, secret_key);
|
||||||
let signature_str : string = vdk_binary.bytes_to_hex_str(signature);
|
let signature_str : string = vdk_binary.bytes_to_hex_str(signature);
|
||||||
return {signature: signature_str};
|
return {signature: signature_str};
|
||||||
@@ -382,6 +384,7 @@ tx_sign
|
|||||||
: Promise<{signedTransaction : string}>
|
: Promise<{signedTransaction : string}>
|
||||||
{
|
{
|
||||||
let tx_bytes : Uint8Array = (await vdk_aeser.unbaseNcheck(tx_str)).bytes;
|
let tx_bytes : Uint8Array = (await vdk_aeser.unbaseNcheck(tx_str)).bytes;
|
||||||
|
// @ts-ignore yes nacl is stupid
|
||||||
let signature : Uint8Array = nacl.sign.detached(tx_bytes, secret_key);
|
let signature : Uint8Array = nacl.sign.detached(tx_bytes, secret_key);
|
||||||
let signed_tx_bytes : Uint8Array = vdk_aeser.signed_tx([signature], tx_bytes);
|
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 signed_tx_str : string = await vdk_aeser.baseNcheck('tx', signed_tx_bytes);
|
||||||
|
|||||||
@@ -270,5 +270,10 @@ signed_tx
|
|||||||
tx : Uint8Array)
|
tx : Uint8Array)
|
||||||
: Uint8Array
|
: Uint8Array
|
||||||
{
|
{
|
||||||
return vdk_rlp.encode([signatures, tx]);
|
// tag for signed tx
|
||||||
|
let tag_bytes = vdk_rlp.encode_uint(11);
|
||||||
|
// not sure what version number should be but guessing 1
|
||||||
|
let vsn_bytes = vdk_rlp.encode_uint(1);
|
||||||
|
// result is [tag, vsn, signatures, tx]
|
||||||
|
return vdk_rlp.encode([tag_bytes, vsn_bytes, signatures, tx]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,4 +2,4 @@
|
|||||||
{realm, local}.
|
{realm, local}.
|
||||||
{name, vdk_rlp}.
|
{name, vdk_rlp}.
|
||||||
{version, "0.1.0"}.
|
{version, "0.1.0"}.
|
||||||
{deps, []}.
|
{deps, ["local-vdk_binary-0.1.0"]}.
|
||||||
|
|||||||
@@ -19,9 +19,13 @@ export {
|
|||||||
decoded_data,
|
decoded_data,
|
||||||
decode_result,
|
decode_result,
|
||||||
decode,
|
decode,
|
||||||
encode
|
encode,
|
||||||
|
encode_uint,
|
||||||
|
encode_biguint
|
||||||
}
|
}
|
||||||
|
|
||||||
|
import * as vdk_binary from './jex_include/local-vdk_binary-0.1.0/dist/vdk_binary.js';
|
||||||
|
|
||||||
|
|
||||||
//=============================================================================
|
//=============================================================================
|
||||||
//=============================================================================
|
//=============================================================================
|
||||||
@@ -519,3 +523,29 @@ is_list
|
|||||||
{
|
{
|
||||||
return (x instanceof Array);
|
return (x instanceof Array);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encode an non-negative integer into RLP
|
||||||
|
*/
|
||||||
|
function
|
||||||
|
encode_uint
|
||||||
|
(n: number)
|
||||||
|
: Uint8Array
|
||||||
|
{
|
||||||
|
return encode_biguint(BigInt(n));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encode an unsigned BigInt into RLP
|
||||||
|
*/
|
||||||
|
function
|
||||||
|
encode_biguint
|
||||||
|
(n: bigint)
|
||||||
|
: Uint8Array
|
||||||
|
{
|
||||||
|
let bytes : Uint8Array = vdk_binary.bigint_to_bytes(n);
|
||||||
|
return encode(bytes);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user