diff --git a/jrx/src/b_lib.ts b/jrx/src/b_lib.ts index 4176159..63ab66a 100644 --- a/jrx/src/b_lib.ts +++ b/jrx/src/b_lib.ts @@ -383,6 +383,11 @@ tx_sign secret_key : Uint8Array) : Promise<{signedTransaction : string}> { + // debug: show tx + let mansplained_tx : object = await vdk_aeser.mansplain(tx_str); + console.log('mansplained_tx,', mansplained_tx); + + let tx_bytes : Uint8Array = (await vdk_aeser.unbaseNcheck(tx_str)).bytes; // thank you ulf // https://github.com/aeternity/protocol/tree/fd179822fc70241e79cbef7636625cf344a08109/consensus#transaction-signature @@ -396,6 +401,11 @@ tx_sign 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 {signedTransaction: signed_tx_str}; } diff --git a/libs/vdk_aeser/src/vdk_aeser.ts b/libs/vdk_aeser/src/vdk_aeser.ts index e4c45d3..648a1c5 100644 --- a/libs/vdk_aeser/src/vdk_aeser.ts +++ b/libs/vdk_aeser/src/vdk_aeser.ts @@ -21,7 +21,12 @@ export { shasha4, unbaseNcheck, baseNcheck, - signed_tx + signed_tx, + mansplain +} + +export type { + baseNchecked } @@ -165,8 +170,11 @@ unbase64check : Promise { let bytes : Uint8Array = vdk_base64.decode(baseNstr); - let check_bytes : Uint8Array = bytes.slice(0, 4); - let data_bytes : Uint8Array = bytes.slice(4); + // ah ok here is the bug + let bytes_len : number = bytes.byteLength; + let data_bytes_len : number = bytes_len - 4; + let data_bytes : Uint8Array = bytes.slice(0, data_bytes_len); + let check_bytes : Uint8Array = bytes.slice(data_bytes_len); let correct_check_bytes : Uint8Array = await shasha4(data_bytes); let check_passed : boolean = vdk_binary.bytes_eq(correct_check_bytes, check_bytes); return {bytes : data_bytes, @@ -180,8 +188,10 @@ unbase58check : Promise { let bytes : Uint8Array = vdk_base58.decode(baseNstr); - let check_bytes : Uint8Array = bytes.slice(0, 4); - let data_bytes : Uint8Array = bytes.slice(4); + let bytes_len : number = bytes.byteLength; + let data_bytes_len : number = bytes_len - 4; + let data_bytes : Uint8Array = bytes.slice(0, data_bytes_len); + let check_bytes : Uint8Array = bytes.slice(data_bytes_len); let correct_check_bytes : Uint8Array = await shasha4(data_bytes); let check_passed : boolean = vdk_binary.bytes_eq(correct_check_bytes, check_bytes); return {bytes : data_bytes, @@ -277,3 +287,40 @@ signed_tx // result is [tag, vsn, signatures, tx] return vdk_rlp.encode([tag_bytes, vsn_bytes, signatures, tx]); } + + + +/** + * Take apart some API-encoded data and show its component parts + * + * For debugging purposes + */ +async function +mansplain + (api_str : string) + : Promise +{ + let prefix : string + + let x = await unbaseNcheck(api_str); + + let check_passed : boolean = x.check_passed; + let data_bytes : Uint8Array = x.bytes; + + let mansplained_data : object = mansplain_bytes(data_bytes); + + return {check_passed : check_passed, + data : mansplained_data}; +} + + +/** + * Take RLP encoded bytes and mansplain them + */ +function +mansplain_bytes + (data_bytes : Uint8Array) + : object +{ + return vdk_rlp.decode(data_bytes); +}