diff --git a/bundler/wasm.d.ts b/bundler/wasm.d.ts index 13b0affe..427a4a7d 100644 --- a/bundler/wasm.d.ts +++ b/bundler/wasm.d.ts @@ -951,9 +951,10 @@ export class TransactionBuilder { * @param am: amount to pay * @param kp: owner's XfrKeyPair * @param {XfrKeyPair} kp +* @param {string | undefined} memo * @returns {TransactionBuilder} */ - add_fee_relative_auto(kp: XfrKeyPair): TransactionBuilder; + add_fee_relative_auto(kp: XfrKeyPair, memo?: string): TransactionBuilder; /** * Use this func to get the necessary infomations for generating `Relative Inputs` * @@ -966,9 +967,10 @@ export class TransactionBuilder { * As the last operation of any transaction, * add a static fee to the transaction. * @param {FeeInputs} inputs +* @param {string | undefined} memo * @returns {TransactionBuilder} */ - add_fee(inputs: FeeInputs): TransactionBuilder; + add_fee(inputs: FeeInputs, memo?: string): TransactionBuilder; /** * A simple fee checker for mainnet v1.0. * @@ -1214,9 +1216,10 @@ export class TransferOperationBuilder { * @param {string} code * @param {boolean} conf_amount * @param {boolean} conf_type +* @param {string | undefined} memo * @returns {TransferOperationBuilder} */ - add_output_with_tracing(amount: bigint, recipient: XfrPublicKey, tracing_policies: TracingPolicies, code: string, conf_amount: boolean, conf_type: boolean): TransferOperationBuilder; + add_output_with_tracing(amount: bigint, recipient: XfrPublicKey, tracing_policies: TracingPolicies, code: string, conf_amount: boolean, conf_type: boolean, memo?: string): TransferOperationBuilder; /** * Wraps around TransferOperationBuilder to add an output to a transfer operation builder. * @@ -1231,9 +1234,10 @@ export class TransferOperationBuilder { * @param {string} code * @param {boolean} conf_amount * @param {boolean} conf_type +* @param {string | undefined} memo * @returns {TransferOperationBuilder} */ - add_output_no_tracing(amount: bigint, recipient: XfrPublicKey, code: string, conf_amount: boolean, conf_type: boolean): TransferOperationBuilder; + add_output_no_tracing(amount: bigint, recipient: XfrPublicKey, code: string, conf_amount: boolean, conf_type: boolean, memo?: string): TransferOperationBuilder; /** * Wraps around TransferOperationBuilder to ensure the transfer inputs and outputs are balanced. * This function will add change outputs for all unspent portions of input records. diff --git a/bundler/wasm_bg.js b/bundler/wasm_bg.js index e9900329..b1e91bb8 100644 --- a/bundler/wasm_bg.js +++ b/bundler/wasm_bg.js @@ -4,26 +4,6 @@ export function __wbg_set_wasm(val) { } -const heap = new Array(128).fill(undefined); - -heap.push(undefined, null, true, false); - -function getObject(idx) { return heap[idx]; } - -let heap_next = heap.length; - -function dropObject(idx) { - if (idx < 132) return; - heap[idx] = heap_next; - heap_next = idx; -} - -function takeObject(idx) { - const ret = getObject(idx); - dropObject(idx); - return ret; -} - const lTextDecoder = typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder; let cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true }); @@ -43,6 +23,12 @@ function getStringFromWasm0(ptr, len) { return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len)); } +const heap = new Array(128).fill(undefined); + +heap.push(undefined, null, true, false); + +let heap_next = heap.length; + function addHeapObject(obj) { if (heap_next === heap.length) heap.push(heap.length + 1); const idx = heap_next; @@ -52,6 +38,8 @@ function addHeapObject(obj) { return idx; } +function getObject(idx) { return heap[idx]; } + let WASM_VECTOR_LEN = 0; const lTextEncoder = typeof TextEncoder === 'undefined' ? (0, module.require)('util').TextEncoder : TextEncoder; @@ -118,6 +106,18 @@ function getInt32Memory0() { return cachedInt32Memory0; } +function dropObject(idx) { + if (idx < 132) return; + heap[idx] = heap_next; + heap_next = idx; +} + +function takeObject(idx) { + const ret = getObject(idx); + dropObject(idx); + return ret; +} + function debugString(val) { // primitive types const type = typeof val; @@ -2762,15 +2762,18 @@ export class TransactionBuilder { * @param am: amount to pay * @param kp: owner's XfrKeyPair * @param {XfrKeyPair} kp + * @param {string | undefined} memo * @returns {TransactionBuilder} */ - add_fee_relative_auto(kp) { + add_fee_relative_auto(kp, memo) { try { const ptr = this.__destroy_into_raw(); const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); _assertClass(kp, XfrKeyPair); var ptr0 = kp.__destroy_into_raw(); - wasm.transactionbuilder_add_fee_relative_auto(retptr, ptr, ptr0); + var ptr1 = isLikeNone(memo) ? 0 : passStringToWasm0(memo, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + var len1 = WASM_VECTOR_LEN; + wasm.transactionbuilder_add_fee_relative_auto(retptr, ptr, ptr0, ptr1, len1); var r0 = getInt32Memory0()[retptr / 4 + 0]; var r1 = getInt32Memory0()[retptr / 4 + 1]; var r2 = getInt32Memory0()[retptr / 4 + 2]; @@ -2806,15 +2809,18 @@ export class TransactionBuilder { * As the last operation of any transaction, * add a static fee to the transaction. * @param {FeeInputs} inputs + * @param {string | undefined} memo * @returns {TransactionBuilder} */ - add_fee(inputs) { + add_fee(inputs, memo) { try { const ptr = this.__destroy_into_raw(); const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); _assertClass(inputs, FeeInputs); var ptr0 = inputs.__destroy_into_raw(); - wasm.transactionbuilder_add_fee(retptr, ptr, ptr0); + var ptr1 = isLikeNone(memo) ? 0 : passStringToWasm0(memo, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + var len1 = WASM_VECTOR_LEN; + wasm.transactionbuilder_add_fee(retptr, ptr, ptr0, ptr1, len1); var r0 = getInt32Memory0()[retptr / 4 + 0]; var r1 = getInt32Memory0()[retptr / 4 + 1]; var r2 = getInt32Memory0()[retptr / 4 + 2]; @@ -3434,9 +3440,10 @@ export class TransferOperationBuilder { * @param {string} code * @param {boolean} conf_amount * @param {boolean} conf_type + * @param {string | undefined} memo * @returns {TransferOperationBuilder} */ - add_output_with_tracing(amount, recipient, tracing_policies, code, conf_amount, conf_type) { + add_output_with_tracing(amount, recipient, tracing_policies, code, conf_amount, conf_type, memo) { try { const ptr = this.__destroy_into_raw(); const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); @@ -3444,7 +3451,9 @@ export class TransferOperationBuilder { _assertClass(tracing_policies, TracingPolicies); const ptr0 = passStringToWasm0(code, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); const len0 = WASM_VECTOR_LEN; - wasm.transferoperationbuilder_add_output_with_tracing(retptr, ptr, amount, recipient.ptr, tracing_policies.ptr, ptr0, len0, conf_amount, conf_type); + var ptr1 = isLikeNone(memo) ? 0 : passStringToWasm0(memo, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + var len1 = WASM_VECTOR_LEN; + wasm.transferoperationbuilder_add_output_with_tracing(retptr, ptr, amount, recipient.ptr, tracing_policies.ptr, ptr0, len0, conf_amount, conf_type, ptr1, len1); var r0 = getInt32Memory0()[retptr / 4 + 0]; var r1 = getInt32Memory0()[retptr / 4 + 1]; var r2 = getInt32Memory0()[retptr / 4 + 2]; @@ -3470,16 +3479,19 @@ export class TransferOperationBuilder { * @param {string} code * @param {boolean} conf_amount * @param {boolean} conf_type + * @param {string | undefined} memo * @returns {TransferOperationBuilder} */ - add_output_no_tracing(amount, recipient, code, conf_amount, conf_type) { + add_output_no_tracing(amount, recipient, code, conf_amount, conf_type, memo) { try { const ptr = this.__destroy_into_raw(); const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); _assertClass(recipient, XfrPublicKey); const ptr0 = passStringToWasm0(code, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); const len0 = WASM_VECTOR_LEN; - wasm.transferoperationbuilder_add_output_no_tracing(retptr, ptr, amount, recipient.ptr, ptr0, len0, conf_amount, conf_type); + var ptr1 = isLikeNone(memo) ? 0 : passStringToWasm0(memo, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + var len1 = WASM_VECTOR_LEN; + wasm.transferoperationbuilder_add_output_no_tracing(retptr, ptr, amount, recipient.ptr, ptr0, len0, conf_amount, conf_type, ptr1, len1); var r0 = getInt32Memory0()[retptr / 4 + 0]; var r1 = getInt32Memory0()[retptr / 4 + 1]; var r2 = getInt32Memory0()[retptr / 4 + 2]; @@ -3805,12 +3817,8 @@ export class ZorroScalar { } } -export function __wbindgen_object_drop_ref(arg0) { - takeObject(arg0); -}; - -export function __wbindgen_string_new(arg0, arg1) { - const ret = getStringFromWasm0(arg0, arg1); +export function __wbindgen_json_parse(arg0, arg1) { + const ret = JSON.parse(getStringFromWasm0(arg0, arg1)); return addHeapObject(ret); }; @@ -3823,14 +3831,13 @@ export function __wbindgen_json_serialize(arg0, arg1) { getInt32Memory0()[arg0 / 4 + 0] = ptr0; }; -export function __wbindgen_json_parse(arg0, arg1) { - const ret = JSON.parse(getStringFromWasm0(arg0, arg1)); - return addHeapObject(ret); +export function __wbindgen_object_drop_ref(arg0) { + takeObject(arg0); }; -export function __wbg_now_c644db5194be8437(arg0) { - const ret = getObject(arg0).now(); - return ret; +export function __wbindgen_string_new(arg0, arg1) { + const ret = getStringFromWasm0(arg0, arg1); + return addHeapObject(ret); }; export function __wbindgen_object_clone_ref(arg0) { @@ -3838,7 +3845,20 @@ export function __wbindgen_object_clone_ref(arg0) { return addHeapObject(ret); }; -export function __wbg_crypto_58f13aa23ffcb166(arg0) { +export function __wbg_now_c644db5194be8437(arg0) { + const ret = getObject(arg0).now(); + return ret; +}; + +export function __wbg_getRandomValues_37fa2ca9e4e07fab() { return handleError(function (arg0, arg1) { + getObject(arg0).getRandomValues(getObject(arg1)); +}, arguments) }; + +export function __wbg_randomFillSync_dc1e9a60c158336d() { return handleError(function (arg0, arg1) { + getObject(arg0).randomFillSync(takeObject(arg1)); +}, arguments) }; + +export function __wbg_crypto_c48a774b022d20ac(arg0) { const ret = getObject(arg0).crypto; return addHeapObject(ret); }; @@ -3849,17 +3869,17 @@ export function __wbindgen_is_object(arg0) { return ret; }; -export function __wbg_process_5b786e71d465a513(arg0) { +export function __wbg_process_298734cf255a885d(arg0) { const ret = getObject(arg0).process; return addHeapObject(ret); }; -export function __wbg_versions_c2ab80650590b6a2(arg0) { +export function __wbg_versions_e2e78e134e3e5d01(arg0) { const ret = getObject(arg0).versions; return addHeapObject(ret); }; -export function __wbg_node_523d7bd03ef69fba(arg0) { +export function __wbg_node_1cd7a5d853dbea79(arg0) { const ret = getObject(arg0).node; return addHeapObject(ret); }; @@ -3869,12 +3889,12 @@ export function __wbindgen_is_string(arg0) { return ret; }; -export function __wbg_msCrypto_abcb1295e768d1f2(arg0) { +export function __wbg_msCrypto_bcb970640f50a1e8(arg0) { const ret = getObject(arg0).msCrypto; return addHeapObject(ret); }; -export function __wbg_require_2784e593a4674877() { return handleError(function () { +export function __wbg_require_8f08ceecec0f4fee() { return handleError(function () { const ret = module.require; return addHeapObject(ret); }, arguments) }; @@ -3884,13 +3904,13 @@ export function __wbindgen_is_function(arg0) { return ret; }; -export function __wbg_randomFillSync_a0d98aa11c81fe89() { return handleError(function (arg0, arg1) { - getObject(arg0).randomFillSync(takeObject(arg1)); -}, arguments) }; +export function __wbg_randomFillSync_85b3f4c52c56c313(arg0, arg1, arg2) { + getObject(arg0).randomFillSync(getArrayU8FromWasm0(arg1, arg2)); +}; -export function __wbg_getRandomValues_504510b5564925af() { return handleError(function (arg0, arg1) { +export function __wbg_getRandomValues_cd175915511f705e(arg0, arg1) { getObject(arg0).getRandomValues(getObject(arg1)); -}, arguments) }; +}; export function __wbg_self_7eede1f4488bf346() { return handleError(function () { const ret = self.self; @@ -3927,14 +3947,6 @@ export function __wbg_getRandomValues_307049345d0bd88c(arg0) { return addHeapObject(ret); }; -export function __wbg_getRandomValues_cd175915511f705e(arg0, arg1) { - getObject(arg0).getRandomValues(getObject(arg1)); -}; - -export function __wbg_randomFillSync_85b3f4c52c56c313(arg0, arg1, arg2) { - getObject(arg0).randomFillSync(getArrayU8FromWasm0(arg1, arg2)); -}; - export function __wbg_newnoargs_2b8b6bd7753c76ba(arg0, arg1) { const ret = new Function(getStringFromWasm0(arg0, arg1)); return addHeapObject(ret); diff --git a/bundler/wasm_bg.wasm b/bundler/wasm_bg.wasm index 9a95689e..e7afef23 100644 Binary files a/bundler/wasm_bg.wasm and b/bundler/wasm_bg.wasm differ diff --git a/bundler/wasm_bg.wasm.d.ts b/bundler/wasm_bg.wasm.d.ts index 68d73814..094458ad 100644 --- a/bundler/wasm_bg.wasm.d.ts +++ b/bundler/wasm_bg.wasm.d.ts @@ -12,9 +12,9 @@ export function __wbg_feeinputs_free(a: number): void; export function feeinputs_new(): number; export function feeinputs_append(a: number, b: number, c: number, d: number, e: number, f: number): void; export function feeinputs_append2(a: number, b: number, c: number, d: number, e: number, f: number): number; -export function transactionbuilder_add_fee_relative_auto(a: number, b: number, c: number): void; +export function transactionbuilder_add_fee_relative_auto(a: number, b: number, c: number, d: number, e: number): void; export function transactionbuilder_get_relative_outputs(a: number, b: number): void; -export function transactionbuilder_add_fee(a: number, b: number, c: number): void; +export function transactionbuilder_add_fee(a: number, b: number, c: number, d: number, e: number): void; export function transactionbuilder_check_fee(a: number): number; export function transactionbuilder_new(a: number): number; export function transactionbuilder_add_operation_create_asset(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number): void; @@ -43,8 +43,8 @@ export function __wbg_transferoperationbuilder_free(a: number): void; export function transferoperationbuilder_new(): number; export function transferoperationbuilder_add_input_with_tracing(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number): void; export function transferoperationbuilder_add_input_no_tracing(a: number, b: number, c: number, d: number, e: number, f: number, g: number): void; -export function transferoperationbuilder_add_output_with_tracing(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number): void; -export function transferoperationbuilder_add_output_no_tracing(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number): void; +export function transferoperationbuilder_add_output_with_tracing(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number): void; +export function transferoperationbuilder_add_output_no_tracing(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number): void; export function transferoperationbuilder_balance(a: number, b: number): void; export function transferoperationbuilder_create(a: number, b: number): void; export function transferoperationbuilder_sign(a: number, b: number, c: number): void; @@ -149,22 +149,22 @@ export function assetrules_set_decimals(a: number, b: number, c: number): void; export function __wbg_credentialsignature_free(a: number): void; export function __wbg_xpublickey_free(a: number): void; export function __wbg_xsecretkey_free(a: number): void; -export function __wbg_blsg2_free(a: number): void; -export function __wbg_blsscalar_free(a: number): void; -export function __wbg_blsg1_free(a: number): void; -export function __wbg_secp256k1g1_free(a: number): void; -export function __wbg_jubjubscalar_free(a: number): void; -export function __wbg_zorrog1_free(a: number): void; -export function __wbg_ed25519scalar_free(a: number): void; export function __wbg_zorrofq_free(a: number): void; export function __wbg_secq256k1g1_free(a: number): void; -export function __wbg_zorroscalar_free(a: number): void; +export function __wbg_zorrog1_free(a: number): void; +export function __wbg_blsg1_free(a: number): void; +export function __wbg_blsg2_free(a: number): void; +export function __wbg_secp256k1g1_free(a: number): void; +export function __wbg_ed25519point_free(a: number): void; +export function __wbg_blsscalar_free(a: number): void; export function __wbg_secq256k1scalar_free(a: number): void; export function __wbg_secp256k1scalar_free(a: number): void; export function __wbg_blsfq_free(a: number): void; export function __wbg_blsgt_free(a: number): void; -export function __wbg_ed25519point_free(a: number): void; -export function ring_core_0_17_6_bn_mul_mont(a: number, b: number, c: number, d: number, e: number, f: number): void; +export function __wbg_ed25519scalar_free(a: number): void; +export function __wbg_zorroscalar_free(a: number): void; +export function __wbg_jubjubscalar_free(a: number): void; +export function ring_core_0_17_5_bn_mul_mont(a: number, b: number, c: number, d: number, e: number, f: number): void; export function __wbg_credissuersecretkey_free(a: number): void; export function __wbg_credissuerpublickey_free(a: number): void; export function __wbg_creduserpublickey_free(a: number): void; diff --git a/demo.js b/demo.js new file mode 100644 index 00000000..3e480f37 --- /dev/null +++ b/demo.js @@ -0,0 +1,42 @@ +// Call 'wasm-pack build --target nodejs' to build from this directory for this command to work +const wasm = require('./wasm.js'); +const axios = require('axios'); + +let kp_sender = wasm.restore_keypair_from_mnemonic_default("zoo nerve assault talk depend approve mercy surge bicycle ridge dismiss satoshi boring opera next fat cinnamon valley office actor above spray alcohol giant"); +//console.log("sender:", wasm.public_key_to_base64(kp_sender.pub_key)); +let kp_reveicer = wasm.new_keypair(); +//console.log("reveicer:",wasm.keypair_to_str(kp_reveicer)); + +let utxo = JSON.parse('{"id":null,"record":{"amount":{"NonConfidential":"47489623119996"},"asset_type":{"NonConfidential":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]},"public_key":"HZnxwPI5PD_xpQX1NqKTHXqPdHXVXtGe7yQ0JI3MVTs="}}'); +let fee_pub_key = wasm.public_key_from_base64("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="); +let transfer_op = wasm.TransferOperationBuilder.new() + .add_input_no_tracing(wasm.TxoRef.absolute(57314n), wasm.ClientAssetRecord.from_json(utxo), null, kp_sender, 1000n) + .add_output_no_tracing(10000n, fee_pub_key, wasm.fra_get_asset_code(), false, false, null) + //.add_output_no_tracing(1n, kp_reveicer.pub_key, wasm.fra_get_asset_code(), false, false, '{"p":"brc-20","op":"deploy","tick":"ordi","max":"21000000","lim":"1000"}') + //.add_output_no_tracing(1n, kp_reveicer.pub_key, wasm.fra_get_asset_code(), false, false, '{"p":"brc-20","op":"mint","tick":"ordi","amt":"1000"}') + .add_output_no_tracing(1n, kp_reveicer.pub_key, wasm.fra_get_asset_code(), false, false, '{"p":"brc-20","op":"transfer","tick":"ordi","amt":"1000"}') + .add_output_no_tracing(47489623109995n, kp_sender.pub_key, wasm.fra_get_asset_code(), false, false, null) + .create() + .sign(kp_sender) + .transaction(); + +let seq_id = 19121n; +let asset_rules = wasm.AssetRules.new(); +let tx =wasm.TransactionBuilder.new(seq_id).add_transfer_operation(transfer_op) + .sign(kp_sender) + .transaction(); +//console.log(tx) + +const stringToHex = (str) => { + let hex = ''; + for (let i = 0; i < str.length; i++) { + const charCode = str.charCodeAt(i); + const hexValue = charCode.toString(16); + + // Pad with zeros to ensure two-digit representation + hex += hexValue.padStart(2, '0'); + } + return hex; +}; + +console.log(stringToHex(tx)); diff --git a/nodejs/wasm.d.ts b/nodejs/wasm.d.ts index 13b0affe..427a4a7d 100644 --- a/nodejs/wasm.d.ts +++ b/nodejs/wasm.d.ts @@ -951,9 +951,10 @@ export class TransactionBuilder { * @param am: amount to pay * @param kp: owner's XfrKeyPair * @param {XfrKeyPair} kp +* @param {string | undefined} memo * @returns {TransactionBuilder} */ - add_fee_relative_auto(kp: XfrKeyPair): TransactionBuilder; + add_fee_relative_auto(kp: XfrKeyPair, memo?: string): TransactionBuilder; /** * Use this func to get the necessary infomations for generating `Relative Inputs` * @@ -966,9 +967,10 @@ export class TransactionBuilder { * As the last operation of any transaction, * add a static fee to the transaction. * @param {FeeInputs} inputs +* @param {string | undefined} memo * @returns {TransactionBuilder} */ - add_fee(inputs: FeeInputs): TransactionBuilder; + add_fee(inputs: FeeInputs, memo?: string): TransactionBuilder; /** * A simple fee checker for mainnet v1.0. * @@ -1214,9 +1216,10 @@ export class TransferOperationBuilder { * @param {string} code * @param {boolean} conf_amount * @param {boolean} conf_type +* @param {string | undefined} memo * @returns {TransferOperationBuilder} */ - add_output_with_tracing(amount: bigint, recipient: XfrPublicKey, tracing_policies: TracingPolicies, code: string, conf_amount: boolean, conf_type: boolean): TransferOperationBuilder; + add_output_with_tracing(amount: bigint, recipient: XfrPublicKey, tracing_policies: TracingPolicies, code: string, conf_amount: boolean, conf_type: boolean, memo?: string): TransferOperationBuilder; /** * Wraps around TransferOperationBuilder to add an output to a transfer operation builder. * @@ -1231,9 +1234,10 @@ export class TransferOperationBuilder { * @param {string} code * @param {boolean} conf_amount * @param {boolean} conf_type +* @param {string | undefined} memo * @returns {TransferOperationBuilder} */ - add_output_no_tracing(amount: bigint, recipient: XfrPublicKey, code: string, conf_amount: boolean, conf_type: boolean): TransferOperationBuilder; + add_output_no_tracing(amount: bigint, recipient: XfrPublicKey, code: string, conf_amount: boolean, conf_type: boolean, memo?: string): TransferOperationBuilder; /** * Wraps around TransferOperationBuilder to ensure the transfer inputs and outputs are balanced. * This function will add change outputs for all unspent portions of input records. diff --git a/nodejs/wasm.js b/nodejs/wasm.js index fc76159d..89330600 100644 --- a/nodejs/wasm.js +++ b/nodejs/wasm.js @@ -3,26 +3,6 @@ imports['__wbindgen_placeholder__'] = module.exports; let wasm; const { TextDecoder, TextEncoder } = require(`util`); -const heap = new Array(128).fill(undefined); - -heap.push(undefined, null, true, false); - -function getObject(idx) { return heap[idx]; } - -let heap_next = heap.length; - -function dropObject(idx) { - if (idx < 132) return; - heap[idx] = heap_next; - heap_next = idx; -} - -function takeObject(idx) { - const ret = getObject(idx); - dropObject(idx); - return ret; -} - let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }); cachedTextDecoder.decode(); @@ -40,6 +20,12 @@ function getStringFromWasm0(ptr, len) { return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len)); } +const heap = new Array(128).fill(undefined); + +heap.push(undefined, null, true, false); + +let heap_next = heap.length; + function addHeapObject(obj) { if (heap_next === heap.length) heap.push(heap.length + 1); const idx = heap_next; @@ -49,6 +35,8 @@ function addHeapObject(obj) { return idx; } +function getObject(idx) { return heap[idx]; } + let WASM_VECTOR_LEN = 0; let cachedTextEncoder = new TextEncoder('utf-8'); @@ -113,6 +101,18 @@ function getInt32Memory0() { return cachedInt32Memory0; } +function dropObject(idx) { + if (idx < 132) return; + heap[idx] = heap_next; + heap_next = idx; +} + +function takeObject(idx) { + const ret = getObject(idx); + dropObject(idx); + return ret; +} + function debugString(val) { // primitive types const type = typeof val; @@ -2794,15 +2794,18 @@ class TransactionBuilder { * @param am: amount to pay * @param kp: owner's XfrKeyPair * @param {XfrKeyPair} kp + * @param {string | undefined} memo * @returns {TransactionBuilder} */ - add_fee_relative_auto(kp) { + add_fee_relative_auto(kp, memo) { try { const ptr = this.__destroy_into_raw(); const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); _assertClass(kp, XfrKeyPair); var ptr0 = kp.__destroy_into_raw(); - wasm.transactionbuilder_add_fee_relative_auto(retptr, ptr, ptr0); + var ptr1 = isLikeNone(memo) ? 0 : passStringToWasm0(memo, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + var len1 = WASM_VECTOR_LEN; + wasm.transactionbuilder_add_fee_relative_auto(retptr, ptr, ptr0, ptr1, len1); var r0 = getInt32Memory0()[retptr / 4 + 0]; var r1 = getInt32Memory0()[retptr / 4 + 1]; var r2 = getInt32Memory0()[retptr / 4 + 2]; @@ -2838,15 +2841,18 @@ class TransactionBuilder { * As the last operation of any transaction, * add a static fee to the transaction. * @param {FeeInputs} inputs + * @param {string | undefined} memo * @returns {TransactionBuilder} */ - add_fee(inputs) { + add_fee(inputs, memo) { try { const ptr = this.__destroy_into_raw(); const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); _assertClass(inputs, FeeInputs); var ptr0 = inputs.__destroy_into_raw(); - wasm.transactionbuilder_add_fee(retptr, ptr, ptr0); + var ptr1 = isLikeNone(memo) ? 0 : passStringToWasm0(memo, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + var len1 = WASM_VECTOR_LEN; + wasm.transactionbuilder_add_fee(retptr, ptr, ptr0, ptr1, len1); var r0 = getInt32Memory0()[retptr / 4 + 0]; var r1 = getInt32Memory0()[retptr / 4 + 1]; var r2 = getInt32Memory0()[retptr / 4 + 2]; @@ -3467,9 +3473,10 @@ class TransferOperationBuilder { * @param {string} code * @param {boolean} conf_amount * @param {boolean} conf_type + * @param {string | undefined} memo * @returns {TransferOperationBuilder} */ - add_output_with_tracing(amount, recipient, tracing_policies, code, conf_amount, conf_type) { + add_output_with_tracing(amount, recipient, tracing_policies, code, conf_amount, conf_type, memo) { try { const ptr = this.__destroy_into_raw(); const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); @@ -3477,7 +3484,9 @@ class TransferOperationBuilder { _assertClass(tracing_policies, TracingPolicies); const ptr0 = passStringToWasm0(code, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); const len0 = WASM_VECTOR_LEN; - wasm.transferoperationbuilder_add_output_with_tracing(retptr, ptr, amount, recipient.ptr, tracing_policies.ptr, ptr0, len0, conf_amount, conf_type); + var ptr1 = isLikeNone(memo) ? 0 : passStringToWasm0(memo, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + var len1 = WASM_VECTOR_LEN; + wasm.transferoperationbuilder_add_output_with_tracing(retptr, ptr, amount, recipient.ptr, tracing_policies.ptr, ptr0, len0, conf_amount, conf_type, ptr1, len1); var r0 = getInt32Memory0()[retptr / 4 + 0]; var r1 = getInt32Memory0()[retptr / 4 + 1]; var r2 = getInt32Memory0()[retptr / 4 + 2]; @@ -3503,16 +3512,19 @@ class TransferOperationBuilder { * @param {string} code * @param {boolean} conf_amount * @param {boolean} conf_type + * @param {string | undefined} memo * @returns {TransferOperationBuilder} */ - add_output_no_tracing(amount, recipient, code, conf_amount, conf_type) { + add_output_no_tracing(amount, recipient, code, conf_amount, conf_type, memo) { try { const ptr = this.__destroy_into_raw(); const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); _assertClass(recipient, XfrPublicKey); const ptr0 = passStringToWasm0(code, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); const len0 = WASM_VECTOR_LEN; - wasm.transferoperationbuilder_add_output_no_tracing(retptr, ptr, amount, recipient.ptr, ptr0, len0, conf_amount, conf_type); + var ptr1 = isLikeNone(memo) ? 0 : passStringToWasm0(memo, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + var len1 = WASM_VECTOR_LEN; + wasm.transferoperationbuilder_add_output_no_tracing(retptr, ptr, amount, recipient.ptr, ptr0, len0, conf_amount, conf_type, ptr1, len1); var r0 = getInt32Memory0()[retptr / 4 + 0]; var r1 = getInt32Memory0()[retptr / 4 + 1]; var r2 = getInt32Memory0()[retptr / 4 + 2]; @@ -3847,12 +3859,8 @@ class ZorroScalar { } module.exports.ZorroScalar = ZorroScalar; -module.exports.__wbindgen_object_drop_ref = function(arg0) { - takeObject(arg0); -}; - -module.exports.__wbindgen_string_new = function(arg0, arg1) { - const ret = getStringFromWasm0(arg0, arg1); +module.exports.__wbindgen_json_parse = function(arg0, arg1) { + const ret = JSON.parse(getStringFromWasm0(arg0, arg1)); return addHeapObject(ret); }; @@ -3865,14 +3873,13 @@ module.exports.__wbindgen_json_serialize = function(arg0, arg1) { getInt32Memory0()[arg0 / 4 + 0] = ptr0; }; -module.exports.__wbindgen_json_parse = function(arg0, arg1) { - const ret = JSON.parse(getStringFromWasm0(arg0, arg1)); - return addHeapObject(ret); +module.exports.__wbindgen_object_drop_ref = function(arg0) { + takeObject(arg0); }; -module.exports.__wbg_now_c644db5194be8437 = function(arg0) { - const ret = getObject(arg0).now(); - return ret; +module.exports.__wbindgen_string_new = function(arg0, arg1) { + const ret = getStringFromWasm0(arg0, arg1); + return addHeapObject(ret); }; module.exports.__wbindgen_object_clone_ref = function(arg0) { @@ -3880,7 +3887,20 @@ module.exports.__wbindgen_object_clone_ref = function(arg0) { return addHeapObject(ret); }; -module.exports.__wbg_crypto_58f13aa23ffcb166 = function(arg0) { +module.exports.__wbg_now_c644db5194be8437 = function(arg0) { + const ret = getObject(arg0).now(); + return ret; +}; + +module.exports.__wbg_getRandomValues_37fa2ca9e4e07fab = function() { return handleError(function (arg0, arg1) { + getObject(arg0).getRandomValues(getObject(arg1)); +}, arguments) }; + +module.exports.__wbg_randomFillSync_dc1e9a60c158336d = function() { return handleError(function (arg0, arg1) { + getObject(arg0).randomFillSync(takeObject(arg1)); +}, arguments) }; + +module.exports.__wbg_crypto_c48a774b022d20ac = function(arg0) { const ret = getObject(arg0).crypto; return addHeapObject(ret); }; @@ -3891,17 +3911,17 @@ module.exports.__wbindgen_is_object = function(arg0) { return ret; }; -module.exports.__wbg_process_5b786e71d465a513 = function(arg0) { +module.exports.__wbg_process_298734cf255a885d = function(arg0) { const ret = getObject(arg0).process; return addHeapObject(ret); }; -module.exports.__wbg_versions_c2ab80650590b6a2 = function(arg0) { +module.exports.__wbg_versions_e2e78e134e3e5d01 = function(arg0) { const ret = getObject(arg0).versions; return addHeapObject(ret); }; -module.exports.__wbg_node_523d7bd03ef69fba = function(arg0) { +module.exports.__wbg_node_1cd7a5d853dbea79 = function(arg0) { const ret = getObject(arg0).node; return addHeapObject(ret); }; @@ -3911,12 +3931,12 @@ module.exports.__wbindgen_is_string = function(arg0) { return ret; }; -module.exports.__wbg_msCrypto_abcb1295e768d1f2 = function(arg0) { +module.exports.__wbg_msCrypto_bcb970640f50a1e8 = function(arg0) { const ret = getObject(arg0).msCrypto; return addHeapObject(ret); }; -module.exports.__wbg_require_2784e593a4674877 = function() { return handleError(function () { +module.exports.__wbg_require_8f08ceecec0f4fee = function() { return handleError(function () { const ret = module.require; return addHeapObject(ret); }, arguments) }; @@ -3926,13 +3946,13 @@ module.exports.__wbindgen_is_function = function(arg0) { return ret; }; -module.exports.__wbg_randomFillSync_a0d98aa11c81fe89 = function() { return handleError(function (arg0, arg1) { - getObject(arg0).randomFillSync(takeObject(arg1)); -}, arguments) }; +module.exports.__wbg_randomFillSync_85b3f4c52c56c313 = function(arg0, arg1, arg2) { + getObject(arg0).randomFillSync(getArrayU8FromWasm0(arg1, arg2)); +}; -module.exports.__wbg_getRandomValues_504510b5564925af = function() { return handleError(function (arg0, arg1) { +module.exports.__wbg_getRandomValues_cd175915511f705e = function(arg0, arg1) { getObject(arg0).getRandomValues(getObject(arg1)); -}, arguments) }; +}; module.exports.__wbg_self_7eede1f4488bf346 = function() { return handleError(function () { const ret = self.self; @@ -3969,14 +3989,6 @@ module.exports.__wbg_getRandomValues_307049345d0bd88c = function(arg0) { return addHeapObject(ret); }; -module.exports.__wbg_getRandomValues_cd175915511f705e = function(arg0, arg1) { - getObject(arg0).getRandomValues(getObject(arg1)); -}; - -module.exports.__wbg_randomFillSync_85b3f4c52c56c313 = function(arg0, arg1, arg2) { - getObject(arg0).randomFillSync(getArrayU8FromWasm0(arg1, arg2)); -}; - module.exports.__wbg_newnoargs_2b8b6bd7753c76ba = function(arg0, arg1) { const ret = new Function(getStringFromWasm0(arg0, arg1)); return addHeapObject(ret); diff --git a/nodejs/wasm_bg.wasm b/nodejs/wasm_bg.wasm index 2fa9ac98..1c0f49c3 100644 Binary files a/nodejs/wasm_bg.wasm and b/nodejs/wasm_bg.wasm differ diff --git a/nodejs/wasm_bg.wasm.d.ts b/nodejs/wasm_bg.wasm.d.ts index 68d73814..094458ad 100644 --- a/nodejs/wasm_bg.wasm.d.ts +++ b/nodejs/wasm_bg.wasm.d.ts @@ -12,9 +12,9 @@ export function __wbg_feeinputs_free(a: number): void; export function feeinputs_new(): number; export function feeinputs_append(a: number, b: number, c: number, d: number, e: number, f: number): void; export function feeinputs_append2(a: number, b: number, c: number, d: number, e: number, f: number): number; -export function transactionbuilder_add_fee_relative_auto(a: number, b: number, c: number): void; +export function transactionbuilder_add_fee_relative_auto(a: number, b: number, c: number, d: number, e: number): void; export function transactionbuilder_get_relative_outputs(a: number, b: number): void; -export function transactionbuilder_add_fee(a: number, b: number, c: number): void; +export function transactionbuilder_add_fee(a: number, b: number, c: number, d: number, e: number): void; export function transactionbuilder_check_fee(a: number): number; export function transactionbuilder_new(a: number): number; export function transactionbuilder_add_operation_create_asset(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number): void; @@ -43,8 +43,8 @@ export function __wbg_transferoperationbuilder_free(a: number): void; export function transferoperationbuilder_new(): number; export function transferoperationbuilder_add_input_with_tracing(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number): void; export function transferoperationbuilder_add_input_no_tracing(a: number, b: number, c: number, d: number, e: number, f: number, g: number): void; -export function transferoperationbuilder_add_output_with_tracing(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number): void; -export function transferoperationbuilder_add_output_no_tracing(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number): void; +export function transferoperationbuilder_add_output_with_tracing(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number): void; +export function transferoperationbuilder_add_output_no_tracing(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number): void; export function transferoperationbuilder_balance(a: number, b: number): void; export function transferoperationbuilder_create(a: number, b: number): void; export function transferoperationbuilder_sign(a: number, b: number, c: number): void; @@ -149,22 +149,22 @@ export function assetrules_set_decimals(a: number, b: number, c: number): void; export function __wbg_credentialsignature_free(a: number): void; export function __wbg_xpublickey_free(a: number): void; export function __wbg_xsecretkey_free(a: number): void; -export function __wbg_blsg2_free(a: number): void; -export function __wbg_blsscalar_free(a: number): void; -export function __wbg_blsg1_free(a: number): void; -export function __wbg_secp256k1g1_free(a: number): void; -export function __wbg_jubjubscalar_free(a: number): void; -export function __wbg_zorrog1_free(a: number): void; -export function __wbg_ed25519scalar_free(a: number): void; export function __wbg_zorrofq_free(a: number): void; export function __wbg_secq256k1g1_free(a: number): void; -export function __wbg_zorroscalar_free(a: number): void; +export function __wbg_zorrog1_free(a: number): void; +export function __wbg_blsg1_free(a: number): void; +export function __wbg_blsg2_free(a: number): void; +export function __wbg_secp256k1g1_free(a: number): void; +export function __wbg_ed25519point_free(a: number): void; +export function __wbg_blsscalar_free(a: number): void; export function __wbg_secq256k1scalar_free(a: number): void; export function __wbg_secp256k1scalar_free(a: number): void; export function __wbg_blsfq_free(a: number): void; export function __wbg_blsgt_free(a: number): void; -export function __wbg_ed25519point_free(a: number): void; -export function ring_core_0_17_6_bn_mul_mont(a: number, b: number, c: number, d: number, e: number, f: number): void; +export function __wbg_ed25519scalar_free(a: number): void; +export function __wbg_zorroscalar_free(a: number): void; +export function __wbg_jubjubscalar_free(a: number): void; +export function ring_core_0_17_5_bn_mul_mont(a: number, b: number, c: number, d: number, e: number, f: number): void; export function __wbg_credissuersecretkey_free(a: number): void; export function __wbg_credissuerpublickey_free(a: number): void; export function __wbg_creduserpublickey_free(a: number): void; diff --git a/send_tx.rs b/send_tx.rs new file mode 100644 index 00000000..64168012 --- /dev/null +++ b/send_tx.rs @@ -0,0 +1,25 @@ +use sha2::{Digest, Sha256}; + +fn main() { + let tx = "7b22626f6479223a7b226e6f5f7265706c61795f746f6b656e223a5b5b3131302c3230372c33332c3138362c3235342c3134372c3138362c3133375d2c31393132315d2c226f7065726174696f6e73223a5b7b225472616e736665724173736574223a7b22626f6479223a7b22696e70757473223a5b7b224162736f6c757465223a35373331347d5d2c22706f6c6963696573223a7b2276616c6964223a747275652c22696e707574735f74726163696e675f706f6c6963696573223a5b5b5d5d2c22696e707574735f7369675f636f6d6d69746d656e7473223a5b6e756c6c5d2c226f7574707574735f74726163696e675f706f6c6963696573223a5b5b5d2c5b5d2c5b5d5d2c226f7574707574735f7369675f636f6d6d69746d656e7473223a5b6e756c6c2c6e756c6c2c6e756c6c5d7d2c226f757470757473223a5b7b226964223a6e756c6c2c227265636f7264223a7b22616d6f756e74223a7b224e6f6e436f6e666964656e7469616c223a223130303030227d2c2261737365745f74797065223a7b224e6f6e436f6e666964656e7469616c223a5b302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c305d7d2c227075626c69635f6b6579223a22414141414141414141414141414141414141414141414141414141414141414141414141414141414141413d227d7d2c7b226964223a6e756c6c2c227265636f7264223a7b22616d6f756e74223a7b224e6f6e436f6e666964656e7469616c223a2231227d2c2261737365745f74797065223a7b224e6f6e436f6e666964656e7469616c223a5b302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c305d7d2c227075626c69635f6b6579223a226c30517567744e554b47443533574b6646364271364548457550775a63526e45766e5f5047343852336a673d227d2c226d656d6f223a227b5c22705c223a5c226272632d32305c222c5c226f705c223a5c227472616e736665725c222c5c227469636b5c223a5c226f7264695c222c5c22616d745c223a5c22313030305c227d227d2c7b226964223a6e756c6c2c227265636f7264223a7b22616d6f756e74223a7b224e6f6e436f6e666964656e7469616c223a223437343839363233313039393935227d2c2261737365745f74797065223a7b224e6f6e436f6e666964656e7469616c223a5b302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c305d7d2c227075626c69635f6b6579223a22485a6e787750493550445f78705158314e714b54485871506448585658744765377951304a49334d5654733d227d7d5d2c227472616e73666572223a7b22696e70757473223a5b7b22616d6f756e74223a7b224e6f6e436f6e666964656e7469616c223a223437343839363233313139393936227d2c2261737365745f74797065223a7b224e6f6e436f6e666964656e7469616c223a5b302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c305d7d2c227075626c69635f6b6579223a22485a6e787750493550445f78705158314e714b54485871506448585658744765377951304a49334d5654733d227d5d2c226f757470757473223a5b7b22616d6f756e74223a7b224e6f6e436f6e666964656e7469616c223a223130303030227d2c2261737365745f74797065223a7b224e6f6e436f6e666964656e7469616c223a5b302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c305d7d2c227075626c69635f6b6579223a22414141414141414141414141414141414141414141414141414141414141414141414141414141414141413d227d2c7b22616d6f756e74223a7b224e6f6e436f6e666964656e7469616c223a2231227d2c2261737365745f74797065223a7b224e6f6e436f6e666964656e7469616c223a5b302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c305d7d2c227075626c69635f6b6579223a226c30517567744e554b47443533574b6646364271364548457550775a63526e45766e5f5047343852336a673d227d2c7b22616d6f756e74223a7b224e6f6e436f6e666964656e7469616c223a223437343839363233313039393935227d2c2261737365745f74797065223a7b224e6f6e436f6e666964656e7469616c223a5b302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c305d7d2c227075626c69635f6b6579223a22485a6e787750493550445f78705158314e714b54485871506448585658744765377951304a49334d5654733d227d5d2c2270726f6f6673223a7b2261737365745f747970655f616e645f616d6f756e745f70726f6f66223a224e6f50726f6f66222c2261737365745f74726163696e675f70726f6f66223a7b2261737365745f747970655f616e645f616d6f756e745f70726f6f6673223a5b5d2c22696e707574735f6964656e746974795f70726f6f6673223a5b5b5d5d2c226f7574707574735f6964656e746974795f70726f6f6673223a5b5b5d2c5b5d2c5b5d5d7d7d2c2261737365745f74726163696e675f6d656d6f73223a5b5b5d2c5b5d2c5b5d2c5b5d5d2c226f776e6572735f6d656d6f73223a5b6e756c6c2c6e756c6c2c6e756c6c5d7d2c227472616e736665725f74797065223a225374616e64617264227d2c22626f64795f7369676e617475726573223a5b7b2261646472657373223a7b226b6579223a22485a6e787750493550445f78705158314e714b54485871506448585658744765377951304a49334d5654733d227d2c227369676e6174757265223a22594e2d473466437258334b5938614d464a78734e6a654b6135527266396c79584861453975773876583877455f557575706633736a6b67477530347573334e574f6d6f4167733042317a32624a31636f7356396344513d3d227d5d7d7d5d7d2c227075626b65795f7369676e5f6d6170223a7b22485a6e787750493550445f78705158314e714b54485871506448585658744765377951304a49334d5654733d223a2261556f7775334b7462634d446b4539592d4b6673646859617467596852613367475833774464505a595337394847634a6d617a6d567134337669384d6561584e4c446944333268324165716f4c506a31554c713742773d3d227d7d"; + let tx_bytes = hex::decode(tx.strip_prefix("0x").unwrap_or(tx)).unwrap(); + let url = "https://prod-testnet.prod.findora.org:26657"; + let txn_b64 = base64::encode_config(&tx_bytes, base64::URL_SAFE); + + let json_rpc = + format!( + "{{\"jsonrpc\":\"2.0\",\"id\":\"anything\",\"method\":\"broadcast_tx_sync\",\"params\": {{\"tx\": \"{}\"}}}}", + &txn_b64 + ); + + attohttpc::post(url) + .header(attohttpc::header::CONTENT_TYPE, "application/json") + .text(json_rpc) + .send() + .and_then(|v| v.error_for_status()) + .map(|v| println!("{:?}", v)) + .unwrap(); + + let tx_hash = Sha256::digest(tx_bytes); + println!("{}", hex::encode(tx_hash)); +} diff --git a/web/wasm.d.ts b/web/wasm.d.ts index d25c7959..3f5360f2 100644 --- a/web/wasm.d.ts +++ b/web/wasm.d.ts @@ -951,9 +951,10 @@ export class TransactionBuilder { * @param am: amount to pay * @param kp: owner's XfrKeyPair * @param {XfrKeyPair} kp +* @param {string | undefined} memo * @returns {TransactionBuilder} */ - add_fee_relative_auto(kp: XfrKeyPair): TransactionBuilder; + add_fee_relative_auto(kp: XfrKeyPair, memo?: string): TransactionBuilder; /** * Use this func to get the necessary infomations for generating `Relative Inputs` * @@ -966,9 +967,10 @@ export class TransactionBuilder { * As the last operation of any transaction, * add a static fee to the transaction. * @param {FeeInputs} inputs +* @param {string | undefined} memo * @returns {TransactionBuilder} */ - add_fee(inputs: FeeInputs): TransactionBuilder; + add_fee(inputs: FeeInputs, memo?: string): TransactionBuilder; /** * A simple fee checker for mainnet v1.0. * @@ -1214,9 +1216,10 @@ export class TransferOperationBuilder { * @param {string} code * @param {boolean} conf_amount * @param {boolean} conf_type +* @param {string | undefined} memo * @returns {TransferOperationBuilder} */ - add_output_with_tracing(amount: bigint, recipient: XfrPublicKey, tracing_policies: TracingPolicies, code: string, conf_amount: boolean, conf_type: boolean): TransferOperationBuilder; + add_output_with_tracing(amount: bigint, recipient: XfrPublicKey, tracing_policies: TracingPolicies, code: string, conf_amount: boolean, conf_type: boolean, memo?: string): TransferOperationBuilder; /** * Wraps around TransferOperationBuilder to add an output to a transfer operation builder. * @@ -1231,9 +1234,10 @@ export class TransferOperationBuilder { * @param {string} code * @param {boolean} conf_amount * @param {boolean} conf_type +* @param {string | undefined} memo * @returns {TransferOperationBuilder} */ - add_output_no_tracing(amount: bigint, recipient: XfrPublicKey, code: string, conf_amount: boolean, conf_type: boolean): TransferOperationBuilder; + add_output_no_tracing(amount: bigint, recipient: XfrPublicKey, code: string, conf_amount: boolean, conf_type: boolean, memo?: string): TransferOperationBuilder; /** * Wraps around TransferOperationBuilder to ensure the transfer inputs and outputs are balanced. * This function will add change outputs for all unspent portions of input records. @@ -1360,9 +1364,9 @@ export interface InitOutput { readonly feeinputs_new: () => number; readonly feeinputs_append: (a: number, b: number, c: number, d: number, e: number, f: number) => void; readonly feeinputs_append2: (a: number, b: number, c: number, d: number, e: number, f: number) => number; - readonly transactionbuilder_add_fee_relative_auto: (a: number, b: number, c: number) => void; + readonly transactionbuilder_add_fee_relative_auto: (a: number, b: number, c: number, d: number, e: number) => void; readonly transactionbuilder_get_relative_outputs: (a: number, b: number) => void; - readonly transactionbuilder_add_fee: (a: number, b: number, c: number) => void; + readonly transactionbuilder_add_fee: (a: number, b: number, c: number, d: number, e: number) => void; readonly transactionbuilder_check_fee: (a: number) => number; readonly transactionbuilder_new: (a: number) => number; readonly transactionbuilder_add_operation_create_asset: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => void; @@ -1391,8 +1395,8 @@ export interface InitOutput { readonly transferoperationbuilder_new: () => number; readonly transferoperationbuilder_add_input_with_tracing: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => void; readonly transferoperationbuilder_add_input_no_tracing: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void; - readonly transferoperationbuilder_add_output_with_tracing: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => void; - readonly transferoperationbuilder_add_output_no_tracing: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => void; + readonly transferoperationbuilder_add_output_with_tracing: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number) => void; + readonly transferoperationbuilder_add_output_no_tracing: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number) => void; readonly transferoperationbuilder_balance: (a: number, b: number) => void; readonly transferoperationbuilder_create: (a: number, b: number) => void; readonly transferoperationbuilder_sign: (a: number, b: number, c: number) => void; @@ -1497,22 +1501,22 @@ export interface InitOutput { readonly __wbg_credentialsignature_free: (a: number) => void; readonly __wbg_xpublickey_free: (a: number) => void; readonly __wbg_xsecretkey_free: (a: number) => void; - readonly __wbg_blsg2_free: (a: number) => void; - readonly __wbg_blsscalar_free: (a: number) => void; - readonly __wbg_blsg1_free: (a: number) => void; - readonly __wbg_secp256k1g1_free: (a: number) => void; - readonly __wbg_jubjubscalar_free: (a: number) => void; - readonly __wbg_zorrog1_free: (a: number) => void; - readonly __wbg_ed25519scalar_free: (a: number) => void; readonly __wbg_zorrofq_free: (a: number) => void; readonly __wbg_secq256k1g1_free: (a: number) => void; - readonly __wbg_zorroscalar_free: (a: number) => void; + readonly __wbg_zorrog1_free: (a: number) => void; + readonly __wbg_blsg1_free: (a: number) => void; + readonly __wbg_blsg2_free: (a: number) => void; + readonly __wbg_secp256k1g1_free: (a: number) => void; + readonly __wbg_ed25519point_free: (a: number) => void; + readonly __wbg_blsscalar_free: (a: number) => void; readonly __wbg_secq256k1scalar_free: (a: number) => void; readonly __wbg_secp256k1scalar_free: (a: number) => void; readonly __wbg_blsfq_free: (a: number) => void; readonly __wbg_blsgt_free: (a: number) => void; - readonly __wbg_ed25519point_free: (a: number) => void; - readonly ring_core_0_17_6_bn_mul_mont: (a: number, b: number, c: number, d: number, e: number, f: number) => void; + readonly __wbg_ed25519scalar_free: (a: number) => void; + readonly __wbg_zorroscalar_free: (a: number) => void; + readonly __wbg_jubjubscalar_free: (a: number) => void; + readonly ring_core_0_17_5_bn_mul_mont: (a: number, b: number, c: number, d: number, e: number, f: number) => void; readonly __wbg_credissuersecretkey_free: (a: number) => void; readonly __wbg_credissuerpublickey_free: (a: number) => void; readonly __wbg_creduserpublickey_free: (a: number) => void; diff --git a/web/wasm.js b/web/wasm.js index b5ef9f12..79c6076f 100644 --- a/web/wasm.js +++ b/web/wasm.js @@ -1,25 +1,5 @@ let wasm; -const heap = new Array(128).fill(undefined); - -heap.push(undefined, null, true, false); - -function getObject(idx) { return heap[idx]; } - -let heap_next = heap.length; - -function dropObject(idx) { - if (idx < 132) return; - heap[idx] = heap_next; - heap_next = idx; -} - -function takeObject(idx) { - const ret = getObject(idx); - dropObject(idx); - return ret; -} - const cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }); cachedTextDecoder.decode(); @@ -37,6 +17,12 @@ function getStringFromWasm0(ptr, len) { return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len)); } +const heap = new Array(128).fill(undefined); + +heap.push(undefined, null, true, false); + +let heap_next = heap.length; + function addHeapObject(obj) { if (heap_next === heap.length) heap.push(heap.length + 1); const idx = heap_next; @@ -46,6 +32,8 @@ function addHeapObject(obj) { return idx; } +function getObject(idx) { return heap[idx]; } + let WASM_VECTOR_LEN = 0; const cachedTextEncoder = new TextEncoder('utf-8'); @@ -110,6 +98,18 @@ function getInt32Memory0() { return cachedInt32Memory0; } +function dropObject(idx) { + if (idx < 132) return; + heap[idx] = heap_next; + heap_next = idx; +} + +function takeObject(idx) { + const ret = getObject(idx); + dropObject(idx); + return ret; +} + function debugString(val) { // primitive types const type = typeof val; @@ -2754,15 +2754,18 @@ export class TransactionBuilder { * @param am: amount to pay * @param kp: owner's XfrKeyPair * @param {XfrKeyPair} kp + * @param {string | undefined} memo * @returns {TransactionBuilder} */ - add_fee_relative_auto(kp) { + add_fee_relative_auto(kp, memo) { try { const ptr = this.__destroy_into_raw(); const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); _assertClass(kp, XfrKeyPair); var ptr0 = kp.__destroy_into_raw(); - wasm.transactionbuilder_add_fee_relative_auto(retptr, ptr, ptr0); + var ptr1 = isLikeNone(memo) ? 0 : passStringToWasm0(memo, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + var len1 = WASM_VECTOR_LEN; + wasm.transactionbuilder_add_fee_relative_auto(retptr, ptr, ptr0, ptr1, len1); var r0 = getInt32Memory0()[retptr / 4 + 0]; var r1 = getInt32Memory0()[retptr / 4 + 1]; var r2 = getInt32Memory0()[retptr / 4 + 2]; @@ -2798,15 +2801,18 @@ export class TransactionBuilder { * As the last operation of any transaction, * add a static fee to the transaction. * @param {FeeInputs} inputs + * @param {string | undefined} memo * @returns {TransactionBuilder} */ - add_fee(inputs) { + add_fee(inputs, memo) { try { const ptr = this.__destroy_into_raw(); const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); _assertClass(inputs, FeeInputs); var ptr0 = inputs.__destroy_into_raw(); - wasm.transactionbuilder_add_fee(retptr, ptr, ptr0); + var ptr1 = isLikeNone(memo) ? 0 : passStringToWasm0(memo, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + var len1 = WASM_VECTOR_LEN; + wasm.transactionbuilder_add_fee(retptr, ptr, ptr0, ptr1, len1); var r0 = getInt32Memory0()[retptr / 4 + 0]; var r1 = getInt32Memory0()[retptr / 4 + 1]; var r2 = getInt32Memory0()[retptr / 4 + 2]; @@ -3426,9 +3432,10 @@ export class TransferOperationBuilder { * @param {string} code * @param {boolean} conf_amount * @param {boolean} conf_type + * @param {string | undefined} memo * @returns {TransferOperationBuilder} */ - add_output_with_tracing(amount, recipient, tracing_policies, code, conf_amount, conf_type) { + add_output_with_tracing(amount, recipient, tracing_policies, code, conf_amount, conf_type, memo) { try { const ptr = this.__destroy_into_raw(); const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); @@ -3436,7 +3443,9 @@ export class TransferOperationBuilder { _assertClass(tracing_policies, TracingPolicies); const ptr0 = passStringToWasm0(code, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); const len0 = WASM_VECTOR_LEN; - wasm.transferoperationbuilder_add_output_with_tracing(retptr, ptr, amount, recipient.ptr, tracing_policies.ptr, ptr0, len0, conf_amount, conf_type); + var ptr1 = isLikeNone(memo) ? 0 : passStringToWasm0(memo, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + var len1 = WASM_VECTOR_LEN; + wasm.transferoperationbuilder_add_output_with_tracing(retptr, ptr, amount, recipient.ptr, tracing_policies.ptr, ptr0, len0, conf_amount, conf_type, ptr1, len1); var r0 = getInt32Memory0()[retptr / 4 + 0]; var r1 = getInt32Memory0()[retptr / 4 + 1]; var r2 = getInt32Memory0()[retptr / 4 + 2]; @@ -3462,16 +3471,19 @@ export class TransferOperationBuilder { * @param {string} code * @param {boolean} conf_amount * @param {boolean} conf_type + * @param {string | undefined} memo * @returns {TransferOperationBuilder} */ - add_output_no_tracing(amount, recipient, code, conf_amount, conf_type) { + add_output_no_tracing(amount, recipient, code, conf_amount, conf_type, memo) { try { const ptr = this.__destroy_into_raw(); const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); _assertClass(recipient, XfrPublicKey); const ptr0 = passStringToWasm0(code, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); const len0 = WASM_VECTOR_LEN; - wasm.transferoperationbuilder_add_output_no_tracing(retptr, ptr, amount, recipient.ptr, ptr0, len0, conf_amount, conf_type); + var ptr1 = isLikeNone(memo) ? 0 : passStringToWasm0(memo, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + var len1 = WASM_VECTOR_LEN; + wasm.transferoperationbuilder_add_output_no_tracing(retptr, ptr, amount, recipient.ptr, ptr0, len0, conf_amount, conf_type, ptr1, len1); var r0 = getInt32Memory0()[retptr / 4 + 0]; var r1 = getInt32Memory0()[retptr / 4 + 1]; var r2 = getInt32Memory0()[retptr / 4 + 2]; @@ -3831,11 +3843,8 @@ async function load(module, imports) { function getImports() { const imports = {}; imports.wbg = {}; - imports.wbg.__wbindgen_object_drop_ref = function(arg0) { - takeObject(arg0); - }; - imports.wbg.__wbindgen_string_new = function(arg0, arg1) { - const ret = getStringFromWasm0(arg0, arg1); + imports.wbg.__wbindgen_json_parse = function(arg0, arg1) { + const ret = JSON.parse(getStringFromWasm0(arg0, arg1)); return addHeapObject(ret); }; imports.wbg.__wbindgen_json_serialize = function(arg0, arg1) { @@ -3846,19 +3855,28 @@ function getImports() { getInt32Memory0()[arg0 / 4 + 1] = len0; getInt32Memory0()[arg0 / 4 + 0] = ptr0; }; - imports.wbg.__wbindgen_json_parse = function(arg0, arg1) { - const ret = JSON.parse(getStringFromWasm0(arg0, arg1)); - return addHeapObject(ret); + imports.wbg.__wbindgen_object_drop_ref = function(arg0) { + takeObject(arg0); }; - imports.wbg.__wbg_now_c644db5194be8437 = function(arg0) { - const ret = getObject(arg0).now(); - return ret; + imports.wbg.__wbindgen_string_new = function(arg0, arg1) { + const ret = getStringFromWasm0(arg0, arg1); + return addHeapObject(ret); }; imports.wbg.__wbindgen_object_clone_ref = function(arg0) { const ret = getObject(arg0); return addHeapObject(ret); }; - imports.wbg.__wbg_crypto_58f13aa23ffcb166 = function(arg0) { + imports.wbg.__wbg_now_c644db5194be8437 = function(arg0) { + const ret = getObject(arg0).now(); + return ret; + }; + imports.wbg.__wbg_getRandomValues_37fa2ca9e4e07fab = function() { return handleError(function (arg0, arg1) { + getObject(arg0).getRandomValues(getObject(arg1)); + }, arguments) }; + imports.wbg.__wbg_randomFillSync_dc1e9a60c158336d = function() { return handleError(function (arg0, arg1) { + getObject(arg0).randomFillSync(takeObject(arg1)); + }, arguments) }; + imports.wbg.__wbg_crypto_c48a774b022d20ac = function(arg0) { const ret = getObject(arg0).crypto; return addHeapObject(ret); }; @@ -3867,15 +3885,15 @@ function getImports() { const ret = typeof(val) === 'object' && val !== null; return ret; }; - imports.wbg.__wbg_process_5b786e71d465a513 = function(arg0) { + imports.wbg.__wbg_process_298734cf255a885d = function(arg0) { const ret = getObject(arg0).process; return addHeapObject(ret); }; - imports.wbg.__wbg_versions_c2ab80650590b6a2 = function(arg0) { + imports.wbg.__wbg_versions_e2e78e134e3e5d01 = function(arg0) { const ret = getObject(arg0).versions; return addHeapObject(ret); }; - imports.wbg.__wbg_node_523d7bd03ef69fba = function(arg0) { + imports.wbg.__wbg_node_1cd7a5d853dbea79 = function(arg0) { const ret = getObject(arg0).node; return addHeapObject(ret); }; @@ -3883,11 +3901,11 @@ function getImports() { const ret = typeof(getObject(arg0)) === 'string'; return ret; }; - imports.wbg.__wbg_msCrypto_abcb1295e768d1f2 = function(arg0) { + imports.wbg.__wbg_msCrypto_bcb970640f50a1e8 = function(arg0) { const ret = getObject(arg0).msCrypto; return addHeapObject(ret); }; - imports.wbg.__wbg_require_2784e593a4674877 = function() { return handleError(function () { + imports.wbg.__wbg_require_8f08ceecec0f4fee = function() { return handleError(function () { const ret = module.require; return addHeapObject(ret); }, arguments) }; @@ -3895,12 +3913,12 @@ function getImports() { const ret = typeof(getObject(arg0)) === 'function'; return ret; }; - imports.wbg.__wbg_randomFillSync_a0d98aa11c81fe89 = function() { return handleError(function (arg0, arg1) { - getObject(arg0).randomFillSync(takeObject(arg1)); - }, arguments) }; - imports.wbg.__wbg_getRandomValues_504510b5564925af = function() { return handleError(function (arg0, arg1) { + imports.wbg.__wbg_randomFillSync_85b3f4c52c56c313 = function(arg0, arg1, arg2) { + getObject(arg0).randomFillSync(getArrayU8FromWasm0(arg1, arg2)); + }; + imports.wbg.__wbg_getRandomValues_cd175915511f705e = function(arg0, arg1) { getObject(arg0).getRandomValues(getObject(arg1)); - }, arguments) }; + }; imports.wbg.__wbg_self_7eede1f4488bf346 = function() { return handleError(function () { const ret = self.self; return addHeapObject(ret); @@ -3929,12 +3947,6 @@ function getImports() { const ret = getObject(arg0).getRandomValues; return addHeapObject(ret); }; - imports.wbg.__wbg_getRandomValues_cd175915511f705e = function(arg0, arg1) { - getObject(arg0).getRandomValues(getObject(arg1)); - }; - imports.wbg.__wbg_randomFillSync_85b3f4c52c56c313 = function(arg0, arg1, arg2) { - getObject(arg0).randomFillSync(getArrayU8FromWasm0(arg1, arg2)); - }; imports.wbg.__wbg_newnoargs_2b8b6bd7753c76ba = function(arg0, arg1) { const ret = new Function(getStringFromWasm0(arg0, arg1)); return addHeapObject(ret); diff --git a/web/wasm_bg.wasm b/web/wasm_bg.wasm index 2c1ebb28..59f81d0e 100644 Binary files a/web/wasm_bg.wasm and b/web/wasm_bg.wasm differ diff --git a/web/wasm_bg.wasm.d.ts b/web/wasm_bg.wasm.d.ts index 68d73814..094458ad 100644 --- a/web/wasm_bg.wasm.d.ts +++ b/web/wasm_bg.wasm.d.ts @@ -12,9 +12,9 @@ export function __wbg_feeinputs_free(a: number): void; export function feeinputs_new(): number; export function feeinputs_append(a: number, b: number, c: number, d: number, e: number, f: number): void; export function feeinputs_append2(a: number, b: number, c: number, d: number, e: number, f: number): number; -export function transactionbuilder_add_fee_relative_auto(a: number, b: number, c: number): void; +export function transactionbuilder_add_fee_relative_auto(a: number, b: number, c: number, d: number, e: number): void; export function transactionbuilder_get_relative_outputs(a: number, b: number): void; -export function transactionbuilder_add_fee(a: number, b: number, c: number): void; +export function transactionbuilder_add_fee(a: number, b: number, c: number, d: number, e: number): void; export function transactionbuilder_check_fee(a: number): number; export function transactionbuilder_new(a: number): number; export function transactionbuilder_add_operation_create_asset(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number): void; @@ -43,8 +43,8 @@ export function __wbg_transferoperationbuilder_free(a: number): void; export function transferoperationbuilder_new(): number; export function transferoperationbuilder_add_input_with_tracing(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number): void; export function transferoperationbuilder_add_input_no_tracing(a: number, b: number, c: number, d: number, e: number, f: number, g: number): void; -export function transferoperationbuilder_add_output_with_tracing(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number): void; -export function transferoperationbuilder_add_output_no_tracing(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number): void; +export function transferoperationbuilder_add_output_with_tracing(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number): void; +export function transferoperationbuilder_add_output_no_tracing(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number): void; export function transferoperationbuilder_balance(a: number, b: number): void; export function transferoperationbuilder_create(a: number, b: number): void; export function transferoperationbuilder_sign(a: number, b: number, c: number): void; @@ -149,22 +149,22 @@ export function assetrules_set_decimals(a: number, b: number, c: number): void; export function __wbg_credentialsignature_free(a: number): void; export function __wbg_xpublickey_free(a: number): void; export function __wbg_xsecretkey_free(a: number): void; -export function __wbg_blsg2_free(a: number): void; -export function __wbg_blsscalar_free(a: number): void; -export function __wbg_blsg1_free(a: number): void; -export function __wbg_secp256k1g1_free(a: number): void; -export function __wbg_jubjubscalar_free(a: number): void; -export function __wbg_zorrog1_free(a: number): void; -export function __wbg_ed25519scalar_free(a: number): void; export function __wbg_zorrofq_free(a: number): void; export function __wbg_secq256k1g1_free(a: number): void; -export function __wbg_zorroscalar_free(a: number): void; +export function __wbg_zorrog1_free(a: number): void; +export function __wbg_blsg1_free(a: number): void; +export function __wbg_blsg2_free(a: number): void; +export function __wbg_secp256k1g1_free(a: number): void; +export function __wbg_ed25519point_free(a: number): void; +export function __wbg_blsscalar_free(a: number): void; export function __wbg_secq256k1scalar_free(a: number): void; export function __wbg_secp256k1scalar_free(a: number): void; export function __wbg_blsfq_free(a: number): void; export function __wbg_blsgt_free(a: number): void; -export function __wbg_ed25519point_free(a: number): void; -export function ring_core_0_17_6_bn_mul_mont(a: number, b: number, c: number, d: number, e: number, f: number): void; +export function __wbg_ed25519scalar_free(a: number): void; +export function __wbg_zorroscalar_free(a: number): void; +export function __wbg_jubjubscalar_free(a: number): void; +export function ring_core_0_17_5_bn_mul_mont(a: number, b: number, c: number, d: number, e: number, f: number): void; export function __wbg_credissuersecretkey_free(a: number): void; export function __wbg_credissuerpublickey_free(a: number): void; export function __wbg_creduserpublickey_free(a: number): void;