UNPKG

@puzzlehq/aleo-wasm-web

Version:
1,420 lines (1,408 loc) 504 kB
function spawnWorker(url, module, memory, address) { return new Promise((resolve) => { const worker = new Worker(url, { type: "module", }); worker.addEventListener("message", (event) => { // This is needed in Node to wait one extra tick, so that way // the Worker can fully initialize before we return. setTimeout(() => { resolve(worker); // When running in Node, this allows the process to exit // even though the Worker is still running. if (worker.unref) { worker.unref(); } }, 0); }, { capture: true, once: true, }); worker.postMessage({ module, memory, address, }); }); } /* @ts-self-types="./index.d.ts" */ /** * Public address of an Aleo account */ class Address { static __wrap(ptr) { ptr = ptr >>> 0; const obj = Object.create(Address.prototype); obj.__wbg_ptr = ptr; AddressFinalization.register(obj, obj.__wbg_ptr, obj); return obj; } __destroy_into_raw() { const ptr = this.__wbg_ptr; this.__wbg_ptr = 0; AddressFinalization.unregister(this); return ptr; } free() { const ptr = this.__destroy_into_raw(); wasm.__wbg_address_free(ptr, 0); } /** * Get an address from a series of bits represented as a boolean array. * * @param {Array} bits A left endian boolean array representing the bits of the address. * * @returns {Address} The address object. * @param {Array<any>} bits * @returns {Address} */ static fromBitsLe(bits) { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.address_fromBitsLe(retptr, addHeapObject(bits)); var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true); var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true); if (r2) { throw takeObject(r1); } return Address.__wrap(r0); } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } /** * Get an address from a series of bytes. * * @param {Uint8Array} bytes A left endian byte array representing the address. * * @returns {Address} The address object. * @param {Uint8Array} bytes * @returns {Address} */ static fromBytesLe(bytes) { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.address_fromBytesLe(retptr, addHeapObject(bytes)); var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true); var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true); if (r2) { throw takeObject(r1); } return Address.__wrap(r0); } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } /** * Get an address object from an array of fields. * * @param {Array} fields An array of fields. * * @returns {Plaintext} The address object. * @param {Array<any>} fields * @returns {Address} */ static fromFields(fields) { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.address_fromFields(retptr, addHeapObject(fields)); var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true); var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true); if (r2) { throw takeObject(r1); } return Address.__wrap(r0); } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } /** * Get an address object from a group. * * @param {Group} group The group object. * * @returns {Address} The address object. * @param {Group} group * @returns {Address} */ static fromGroup(group) { _assertClass(group, Group); var ptr0 = group.__destroy_into_raw(); const ret = wasm.address_fromGroup(ptr0); return Address.__wrap(ret); } /** * Derive an Aleo address from a compute key. * * @param {ComputeKey} compute_key The compute key to derive the address from * @param {ComputeKey} compute_key * @returns {Address} */ static from_compute_key(compute_key) { _assertClass(compute_key, ComputeKey); const ret = wasm.address_from_compute_key(compute_key.__wbg_ptr); return Address.__wrap(ret); } /** * Derive an Aleo address from a private key * * @param {PrivateKey} private_key The private key to derive the address from * @returns {Address} Address corresponding to the private key * @param {PrivateKey} private_key * @returns {Address} */ static from_private_key(private_key) { _assertClass(private_key, PrivateKey); const ret = wasm.address_from_private_key(private_key.__wbg_ptr); return Address.__wrap(ret); } /** * Create an aleo address object from a string representation of an address * * @param {string} address String representation of an addressm * @returns {Address} Address * @param {string} address * @returns {Address} */ static from_string(address) { const ptr0 = passStringToWasm0(address, wasm.__wbindgen_export, wasm.__wbindgen_export2); const len0 = WASM_VECTOR_LEN; const ret = wasm.address_from_string(ptr0, len0); return Address.__wrap(ret); } /** * Derive an Aleo address from a view key * * @param {ViewKey} view_key The view key to derive the address from * @returns {Address} Address corresponding to the view key * @param {ViewKey} view_key * @returns {Address} */ static from_view_key(view_key) { _assertClass(view_key, ViewKey); const ret = wasm.address_from_view_key(view_key.__wbg_ptr); return Address.__wrap(ret); } /** * Get the left endian boolean array representation of the bits of the address. * @returns {Array<any>} */ toBitsLe() { const ret = wasm.address_toBitsLe(this.__wbg_ptr); return takeObject(ret); } /** * Get the left endian byte array representation of the address. * @returns {Uint8Array} */ toBytesLe() { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.address_toBytesLe(retptr, this.__wbg_ptr); var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true); var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true); if (r2) { throw takeObject(r1); } return takeObject(r0); } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } /** * Get the field array representation of the address. * @returns {Array<any>} */ toFields() { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.address_toFields(retptr, this.__wbg_ptr); var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true); var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true); if (r2) { throw takeObject(r1); } return takeObject(r0); } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } /** * Get the group representation of the address object. * @returns {Group} */ toGroup() { const ret = wasm.address_toGroup(this.__wbg_ptr); return Group.__wrap(ret); } /** * Get the plaintext representation of the address. * @returns {Plaintext} */ toPlaintext() { const ret = wasm.address_toPlaintext(this.__wbg_ptr); return Plaintext.__wrap(ret); } /** * Get a string representation of an Aleo address object * * @param {Address} Address * @returns {string} String representation of the address * @returns {string} */ to_string() { let deferred1_0; let deferred1_1; try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.address_to_string(retptr, this.__wbg_ptr); var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true); deferred1_0 = r0; deferred1_1 = r1; return getStringFromWasm0(r0, r1); } finally { wasm.__wbindgen_add_to_stack_pointer(16); wasm.__wbindgen_export4(deferred1_0, deferred1_1, 1); } } /** * Verify a signature for a message signed by the address * * @param {Uint8Array} Byte array representing a message signed by the address * @returns {boolean} Boolean representing whether or not the signature is valid * @param {Uint8Array} message * @param {Signature} signature * @returns {boolean} */ verify(message, signature) { const ptr0 = passArray8ToWasm0(message, wasm.__wbindgen_export); const len0 = WASM_VECTOR_LEN; _assertClass(signature, Signature); const ret = wasm.address_verify(this.__wbg_ptr, ptr0, len0, signature.__wbg_ptr); return ret !== 0; } } if (Symbol.dispose) Address.prototype[Symbol.dispose] = Address.prototype.free; /** * Authorization object containing the authorization for a transaction. */ class Authorization { static __wrap(ptr) { ptr = ptr >>> 0; const obj = Object.create(Authorization.prototype); obj.__wbg_ptr = ptr; AuthorizationFinalization.register(obj, obj.__wbg_ptr, obj); return obj; } __destroy_into_raw() { const ptr = this.__wbg_ptr; this.__wbg_ptr = 0; AuthorizationFinalization.unregister(this); return ptr; } free() { const ptr = this.__destroy_into_raw(); wasm.__wbg_authorization_free(ptr, 0); } /** * Check if an Authorization object is the same as another. * * @param {Authorization} other The Authorization object to determine equality with. * @param {Authorization} other * @returns {boolean} */ equals(other) { _assertClass(other, Authorization); const ret = wasm.authorization_equals(this.__wbg_ptr, other.__wbg_ptr); return ret !== 0; } /** * Creates an authorization object from a left-endian byte representation of an Authorization. * * @param {Uint8Array} bytes Left-endian bytes representing the Authorization. * @param {Uint8Array} bytes * @returns {Authorization} */ static fromBytesLe(bytes) { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.authorization_fromBytesLe(retptr, addHeapObject(bytes)); var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true); var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true); if (r2) { throw takeObject(r1); } return Authorization.__wrap(r0); } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } /** * Reconstructs an Authorization object from its string representation. * * @param {String} authorization The string representation of the Authorization. * @param {string} authorization * @returns {Authorization} */ static fromString(authorization) { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); const ptr0 = passStringToWasm0(authorization, wasm.__wbindgen_export, wasm.__wbindgen_export2); const len0 = WASM_VECTOR_LEN; wasm.authorization_fromString(retptr, ptr0, len0); var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true); var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true); if (r2) { throw takeObject(r1); } return Authorization.__wrap(r0); } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } /** * Get the function name. * * @returns {string} The function name. * @returns {string} */ functionName() { let deferred2_0; let deferred2_1; try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.authorization_functionName(retptr, this.__wbg_ptr); var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true); var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true); var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true); var ptr1 = r0; var len1 = r1; if (r3) { ptr1 = 0; len1 = 0; throw takeObject(r2); } deferred2_0 = ptr1; deferred2_1 = len1; return getStringFromWasm0(ptr1, len1); } finally { wasm.__wbindgen_add_to_stack_pointer(16); wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1); } } /** * Insert a transition into the Authorization. * * @param {Transition} transition The transition object to insert into the Authorization. * @param {Transition} transition */ insertTransition(transition) { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); _assertClass(transition, Transition); var ptr0 = transition.__destroy_into_raw(); wasm.authorization_insertTransition(retptr, this.__wbg_ptr, ptr0); var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true); if (r1) { throw takeObject(r0); } } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } /** * Return `true` if the Authorization is empty. * @returns {boolean} */ isEmpty() { const ret = wasm.authorization_isEmpty(this.__wbg_ptr); return ret !== 0; } /** * Returns `true` if the Authorization is for `credits.aleo/fee_private`. * @returns {boolean} */ isFeePrivate() { const ret = wasm.authorization_isFeePrivate(this.__wbg_ptr); return ret !== 0; } /** * Returns `true` if the Authorization is for `credits.aleo/fee_public`. * @returns {boolean} */ isFeePublic() { const ret = wasm.authorization_isFeePublic(this.__wbg_ptr); return ret !== 0; } /** * Returns `true` if the Authorization is for `credits.aleo/split`. * @returns {boolean} */ isSplit() { const ret = wasm.authorization_isSplit(this.__wbg_ptr); return ret !== 0; } /** * Returns the number of `Request`s in the Authorization. * @returns {number} */ len() { const ret = wasm.authorization_len(this.__wbg_ptr); return ret >>> 0; } /** * Create a new authorization from a request object. * * @param {ExecutionRequest} request The ExecutionRequest to build the authorization from. * @param {ExecutionRequest} request * @returns {Authorization} */ static new(request) { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); _assertClass(request, ExecutionRequest); var ptr0 = request.__destroy_into_raw(); wasm.authorization_new(retptr, ptr0); var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true); var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true); if (r2) { throw takeObject(r1); } return Authorization.__wrap(r0); } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } /** * Returns a new and independent replica of the Authorization. * @returns {Authorization} */ replicate() { const ret = wasm.authorization_replicate(this.__wbg_ptr); return Authorization.__wrap(ret); } /** * Returns the left-endian byte representation of the Authorization. * @returns {Uint8Array} */ toBytesLe() { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.authorization_toBytesLe(retptr, this.__wbg_ptr); var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true); var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true); if (r2) { throw takeObject(r1); } return takeObject(r0); } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } /** * Returns the execution ID for the Authorization. * * @returns {Field} The execution ID for the Authorization, call toString() after this result to get the string representation. * @returns {Field} */ toExecutionId() { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.authorization_toExecutionId(retptr, this.__wbg_ptr); var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true); var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true); if (r2) { throw takeObject(r1); } return Field.__wrap(r0); } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } /** * Returns the string representation of the Authorization. * @returns {string} */ toString() { let deferred1_0; let deferred1_1; try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.authorization_toString(retptr, this.__wbg_ptr); var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true); deferred1_0 = r0; deferred1_1 = r1; return getStringFromWasm0(r0, r1); } finally { wasm.__wbindgen_add_to_stack_pointer(16); wasm.__wbindgen_export4(deferred1_0, deferred1_1, 1); } } /** * Get the transitions in an Authorization. * * @returns {Array<Transition>} Array of transition objects * @returns {Array<any>} */ transitions() { const ret = wasm.authorization_transitions(this.__wbg_ptr); return takeObject(ret); } } if (Symbol.dispose) Authorization.prototype[Symbol.dispose] = Authorization.prototype.free; class BHP1024 { static __wrap(ptr) { ptr = ptr >>> 0; const obj = Object.create(BHP1024.prototype); obj.__wbg_ptr = ptr; BHP1024Finalization.register(obj, obj.__wbg_ptr, obj); return obj; } __destroy_into_raw() { const ptr = this.__wbg_ptr; this.__wbg_ptr = 0; BHP1024Finalization.unregister(this); return ptr; } free() { const ptr = this.__destroy_into_raw(); wasm.__wbg_bhp1024_free(ptr, 0); } /** * Returns a BHP commitment with an input hasher of 1024 bits and randomizer. * @param {Array<any>} input * @param {Scalar} randomizer * @returns {Field} */ commit(input, randomizer) { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); _assertClass(randomizer, Scalar); var ptr0 = randomizer.__destroy_into_raw(); wasm.bhp1024_commit(retptr, this.__wbg_ptr, addHeapObject(input), ptr0); var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true); var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true); if (r2) { throw takeObject(r1); } return Field.__wrap(r0); } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } /** * Returns a BHP commitment with an input hasher of 1024 bits and randomizer. * @param {Array<any>} input * @param {Scalar} randomizer * @returns {Group} */ commitToGroup(input, randomizer) { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); _assertClass(randomizer, Scalar); var ptr0 = randomizer.__destroy_into_raw(); wasm.bhp1024_commitToGroup(retptr, this.__wbg_ptr, addHeapObject(input), ptr0); var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true); var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true); if (r2) { throw takeObject(r1); } return Group.__wrap(r0); } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } /** * Returns the BHP hash with an input hasher of 1024 bits. * @param {Array<any>} input * @returns {Field} */ hash(input) { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.bhp1024_hash(retptr, this.__wbg_ptr, addHeapObject(input)); var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true); var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true); if (r2) { throw takeObject(r1); } return Field.__wrap(r0); } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } /** * Returns a BHP hash with an input hasher of 1024 bits. * @param {Array<any>} input * @returns {Group} */ hashToGroup(input) { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.bhp1024_hashToGroup(retptr, this.__wbg_ptr, addHeapObject(input)); var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true); var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true); if (r2) { throw takeObject(r1); } return Group.__wrap(r0); } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } /** * Create a BHP hasher with an input size of 1024 bits. */ constructor() { const ret = wasm.bhp1024_new(); this.__wbg_ptr = ret >>> 0; BHP1024Finalization.register(this, this.__wbg_ptr, this); return this; } /** * Create a BHP hasher with an input size of 1024 bits with a custom domain separator. * @param {string} domain_separator * @returns {BHP1024} */ static setup(domain_separator) { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); const ptr0 = passStringToWasm0(domain_separator, wasm.__wbindgen_export, wasm.__wbindgen_export2); const len0 = WASM_VECTOR_LEN; wasm.bhp1024_setup(retptr, ptr0, len0); var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true); var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true); if (r2) { throw takeObject(r1); } return BHP1024.__wrap(r0); } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } } if (Symbol.dispose) BHP1024.prototype[Symbol.dispose] = BHP1024.prototype.free; class BHP256 { static __wrap(ptr) { ptr = ptr >>> 0; const obj = Object.create(BHP256.prototype); obj.__wbg_ptr = ptr; BHP256Finalization.register(obj, obj.__wbg_ptr, obj); return obj; } __destroy_into_raw() { const ptr = this.__wbg_ptr; this.__wbg_ptr = 0; BHP256Finalization.unregister(this); return ptr; } free() { const ptr = this.__destroy_into_raw(); wasm.__wbg_bhp256_free(ptr, 0); } /** * Returns a BHP commitment with an input hasher of 256 bits and randomizer. * @param {Array<any>} input * @param {Scalar} randomizer * @returns {Field} */ commit(input, randomizer) { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); _assertClass(randomizer, Scalar); var ptr0 = randomizer.__destroy_into_raw(); wasm.bhp256_commit(retptr, this.__wbg_ptr, addHeapObject(input), ptr0); var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true); var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true); if (r2) { throw takeObject(r1); } return Field.__wrap(r0); } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } /** * Returns a BHP commitment with an input hasher of 256 bits and randomizer. * @param {Array<any>} input * @param {Scalar} randomizer * @returns {Group} */ commitToGroup(input, randomizer) { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); _assertClass(randomizer, Scalar); var ptr0 = randomizer.__destroy_into_raw(); wasm.bhp256_commitToGroup(retptr, this.__wbg_ptr, addHeapObject(input), ptr0); var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true); var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true); if (r2) { throw takeObject(r1); } return Group.__wrap(r0); } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } /** * Returns the BHP hash with an input hasher of 256 bits. * @param {Array<any>} input * @returns {Field} */ hash(input) { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.bhp256_hash(retptr, this.__wbg_ptr, addHeapObject(input)); var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true); var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true); if (r2) { throw takeObject(r1); } return Field.__wrap(r0); } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } /** * Returns a BHP hash with an input hasher of 256 bits. * @param {Array<any>} input * @returns {Group} */ hashToGroup(input) { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.bhp256_hashToGroup(retptr, this.__wbg_ptr, addHeapObject(input)); var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true); var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true); if (r2) { throw takeObject(r1); } return Group.__wrap(r0); } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } /** * Create a BHP hasher with an input size of 256 bits. */ constructor() { const ret = wasm.bhp256_new(); this.__wbg_ptr = ret >>> 0; BHP256Finalization.register(this, this.__wbg_ptr, this); return this; } /** * Create a BHP hasher with an input size of 256 bits with a custom domain separator. * @param {string} domain_separator * @returns {BHP256} */ static setup(domain_separator) { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); const ptr0 = passStringToWasm0(domain_separator, wasm.__wbindgen_export, wasm.__wbindgen_export2); const len0 = WASM_VECTOR_LEN; wasm.bhp256_setup(retptr, ptr0, len0); var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true); var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true); if (r2) { throw takeObject(r1); } return BHP256.__wrap(r0); } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } } if (Symbol.dispose) BHP256.prototype[Symbol.dispose] = BHP256.prototype.free; class BHP512 { static __wrap(ptr) { ptr = ptr >>> 0; const obj = Object.create(BHP512.prototype); obj.__wbg_ptr = ptr; BHP512Finalization.register(obj, obj.__wbg_ptr, obj); return obj; } __destroy_into_raw() { const ptr = this.__wbg_ptr; this.__wbg_ptr = 0; BHP512Finalization.unregister(this); return ptr; } free() { const ptr = this.__destroy_into_raw(); wasm.__wbg_bhp512_free(ptr, 0); } /** * Returns a BHP commitment with an input hasher of 512 bits and randomizer. * @param {Array<any>} input * @param {Scalar} randomizer * @returns {Field} */ commit(input, randomizer) { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); _assertClass(randomizer, Scalar); var ptr0 = randomizer.__destroy_into_raw(); wasm.bhp512_commit(retptr, this.__wbg_ptr, addHeapObject(input), ptr0); var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true); var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true); if (r2) { throw takeObject(r1); } return Field.__wrap(r0); } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } /** * Returns a BHP commitment with an input hasher of 512 bits and randomizer. * @param {Array<any>} input * @param {Scalar} randomizer * @returns {Group} */ commitToGroup(input, randomizer) { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); _assertClass(randomizer, Scalar); var ptr0 = randomizer.__destroy_into_raw(); wasm.bhp512_commitToGroup(retptr, this.__wbg_ptr, addHeapObject(input), ptr0); var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true); var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true); if (r2) { throw takeObject(r1); } return Group.__wrap(r0); } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } /** * Returns the BHP hash with an input hasher of 512 bits. * @param {Array<any>} input * @returns {Field} */ hash(input) { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.bhp512_hash(retptr, this.__wbg_ptr, addHeapObject(input)); var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true); var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true); if (r2) { throw takeObject(r1); } return Field.__wrap(r0); } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } /** * Returns a BHP hash with an input hasher of 512 bits. * @param {Array<any>} input * @returns {Group} */ hashToGroup(input) { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.bhp512_hashToGroup(retptr, this.__wbg_ptr, addHeapObject(input)); var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true); var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true); if (r2) { throw takeObject(r1); } return Group.__wrap(r0); } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } /** * Create a BHP hasher with an input size of 512 bits. */ constructor() { const ret = wasm.bhp512_new(); this.__wbg_ptr = ret >>> 0; BHP512Finalization.register(this, this.__wbg_ptr, this); return this; } /** * Create a BHP hasher with an input size of 512 bits with a custom domain separator. * @param {string} domain_separator * @returns {BHP512} */ static setup(domain_separator) { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); const ptr0 = passStringToWasm0(domain_separator, wasm.__wbindgen_export, wasm.__wbindgen_export2); const len0 = WASM_VECTOR_LEN; wasm.bhp512_setup(retptr, ptr0, len0); var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true); var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true); if (r2) { throw takeObject(r1); } return BHP512.__wrap(r0); } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } } if (Symbol.dispose) BHP512.prototype[Symbol.dispose] = BHP512.prototype.free; class BHP768 { static __wrap(ptr) { ptr = ptr >>> 0; const obj = Object.create(BHP768.prototype); obj.__wbg_ptr = ptr; BHP768Finalization.register(obj, obj.__wbg_ptr, obj); return obj; } __destroy_into_raw() { const ptr = this.__wbg_ptr; this.__wbg_ptr = 0; BHP768Finalization.unregister(this); return ptr; } free() { const ptr = this.__destroy_into_raw(); wasm.__wbg_bhp768_free(ptr, 0); } /** * Returns a BHP commitment with an input hasher of 768 bits and randomizer. * @param {Array<any>} input * @param {Scalar} randomizer * @returns {Field} */ commit(input, randomizer) { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); _assertClass(randomizer, Scalar); var ptr0 = randomizer.__destroy_into_raw(); wasm.bhp768_commit(retptr, this.__wbg_ptr, addHeapObject(input), ptr0); var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true); var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true); if (r2) { throw takeObject(r1); } return Field.__wrap(r0); } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } /** * Returns a BHP commitment with an input hasher of 768 bits and randomizer. * @param {Array<any>} input * @param {Scalar} randomizer * @returns {Group} */ commitToGroup(input, randomizer) { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); _assertClass(randomizer, Scalar); var ptr0 = randomizer.__destroy_into_raw(); wasm.bhp768_commitToGroup(retptr, this.__wbg_ptr, addHeapObject(input), ptr0); var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true); var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true); if (r2) { throw takeObject(r1); } return Group.__wrap(r0); } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } /** * Returns the BHP hash with an input hasher of 768 bits. * @param {Array<any>} input * @returns {Field} */ hash(input) { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.bhp768_hash(retptr, this.__wbg_ptr, addHeapObject(input)); var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true); var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true); if (r2) { throw takeObject(r1); } return Field.__wrap(r0); } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } /** * Returns a BHP hash with an input hasher of 768 bits. * @param {Array<any>} input * @returns {Group} */ hashToGroup(input) { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.bhp768_hashToGroup(retptr, this.__wbg_ptr, addHeapObject(input)); var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true); var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true); if (r2) { throw takeObject(r1); } return Group.__wrap(r0); } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } /** * Create a BHP hasher with an input size of 768 bits. */ constructor() { const ret = wasm.bhp768_new(); this.__wbg_ptr = ret >>> 0; BHP768Finalization.register(this, this.__wbg_ptr, this); return this; } /** * Create a BHP hasher with an input size of 768 bits with a custom domain separator. * @param {string} domain_separator * @returns {BHP768} */ static setup(domain_separator) { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); const ptr0 = passStringToWasm0(domain_separator, wasm.__wbindgen_export, wasm.__wbindgen_export2); const len0 = WASM_VECTOR_LEN; wasm.bhp768_setup(retptr, ptr0, len0); var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true); var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true); if (r2) { throw takeObject(r1); } return BHP768.__wrap(r0); } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } } if (Symbol.dispose) BHP768.prototype[Symbol.dispose] = BHP768.prototype.free; /** * Boolean element. */ class Boolean { static __wrap(ptr) { ptr = ptr >>> 0; const obj = Object.create(Boolean.prototype); obj.__wbg_ptr = ptr; BooleanFinalization.register(obj, obj.__wbg_ptr, obj); return obj; } __destroy_into_raw() { const ptr = this.__wbg_ptr; this.__wbg_ptr = 0; BooleanFinalization.unregister(this); return ptr; } free() { const ptr = this.__destroy_into_raw(); wasm.__wbg_boolean_free(ptr, 0); } /** * Logical AND. * @param {Boolean} other * @returns {Boolean} */ and(other) { _assertClass(other, Boolean); const ret = wasm.boolean_and(this.__wbg_ptr, other.__wbg_ptr); return Boolean.__wrap(ret); } /** * Clone the boolean element. * @returns {Boolean} */ clone() { const ret = wasm.boolean_clone(this.__wbg_ptr); return Boolean.__wrap(ret); } /** * Check if one boolean element equals another. * @param {Boolean} other * @returns {boolean} */ equals(other) { _assertClass(other, Boolean); const ret = wasm.boolean_equals(this.__wbg_ptr, other.__wbg_ptr); return ret !== 0; } /** * Reconstruct a boolean element from a boolean array representation. * @param {Array<any>} bits * @returns {Boolean} */ static fromBitsLe(bits) { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.boolean_fromBitsLe(retptr, addBorrowedObject(bits)); var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true); var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true); if (r2) { throw takeObject(r1); } return Boolean.__wrap(r0); } finally { wasm.__wbindgen_add_to_stack_pointer(16); heap[stack_pointer++] = undefined; } } /** * Create a boolean element from a Uint8Array of left endian bytes. * @param {Uint8Array} bytes * @returns {Boolean} */ static fromBytesLe(bytes) { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.boolean_fromBytesLe(retptr, addBorrowedObject(bytes)); var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true); var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true); if (r2) { throw takeObject(r1); } return Boolean.__wrap(r0); } finally { wasm.__wbindgen_add_to_stack_pointer(16); heap[stack_pointer++] = undefined; } } /** * Creates a boolean object from a string representation ("true"/"false"). * @param {string} boolean * @returns {Boolean} */ static fromString(boolean) { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); const ptr0 = passStringToWasm0(boolean, wasm.__wbindgen_export, wasm.__wbindgen_export2); const len0 = WASM_VECTOR_LEN; wasm.boolean_fromString(retptr, ptr0, len0); var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true); var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true); if (r2) { throw takeObject(r1); } return Boolean.__wrap(r0); } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } /** * Logical NAND. * @param {Boolean} other * @returns {Boolean} */ nand(other) { _assertClass(other, Boolean); const ret = wasm.boolean_nand(this.__wbg_ptr, other.__wbg_ptr); return Boolean.__wrap(ret); } /** * Creates a Boolean from a native JS bool. * @param {boolean} value */ constructor(value) { const ret = wasm.boolean_new(value); this.__wbg_ptr = ret >>> 0; BooleanFinalization.register(this, this.__wbg_ptr, this); return this; } /** * Logical NOR. * @param {Boolean} other * @returns {Boolean} */ nor(other) { _assertClass(other, Boolean); const ret = wasm.boolean_nor(this.__wbg_ptr, other.__wbg_ptr); return Boolean.__wrap(ret); } /** * Logical NOT. * @returns {Boolean} */ not() { const ret = wasm.boolean_not(this.__wbg_ptr); return Boolean.__wrap(ret); } /** * Logical OR. * @param {Boolean} other * @returns {Boolean} */ or(other) { _assertClass(other, Boolean); const ret = wasm.boolean_or(this.__wbg_ptr, other.__wbg_ptr); return Boolean.__wrap(ret); } /** * Generate a random boolean element. * @returns {Boolean} */ static random() { const ret = wasm.boolean_random(); return Boolean.__wrap(ret); } /** * Get the left endian boolean array representation of the boolean element. * @returns {Array<any>} */ toBitsLe() { const ret = wasm.boolean_toBitsLe(this.__wbg_ptr); return takeObject(ret); } /** * Encode the boolean element as a Uint8Array of left endian bytes. * @returns {Uint8Array} */ toBytesLe() { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.boolean_toBytesLe(retptr, this.__wbg_ptr); var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true); var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true); if (r2) { throw takeObject(r1); } return takeObject(r0); } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } /** * Create a plaintext from the boolean element. * @returns {Plaintext} */ toPlaintext() { const ret = wasm.boolean_toPlaintext(this.__wbg_ptr); return Plaintext.__wrap(ret); } /** * Returns the string representation of the boolean element. * @returns {string} */ toString() { let deferred1_0; let deferred1_1; try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.boolean_toString(retptr, this.__wbg_ptr); var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true); deferred1_0 = r0; deferred1_1 = r1; return getStringFromWasm0(r0, r1); } finally { wasm.__wbindgen_add_to_stack_pointer(16); wasm.__wbindgen_export4(deferred1_0, deferred1_1, 1); } } /** * Logical XOR. * @param {Boolean} other * @returns {Boolean} */ xor(other) { _assertClass(other, Boolean); const ret = wasm.boolean_xor(this.__wbg_ptr, other.__wbg_ptr); return Boolean.__wrap(ret); } } if (Symbol.dispose) Boolean.prototype[Symbol.dispose] = Boolean.prototype.free; /** * SnarkVM Ciphertext object. A Ciphertext represents an symmetrically encrypted plaintext. This * object provides decryption methods to recover the plaintext from the ciphertext (given the * api consumer has the proper decryption materials). */ class Ciphertext { static __wrap(ptr) { ptr = ptr >>> 0; const obj = Object.create(Ciphertext.prototype); obj.__wbg_ptr = ptr; CiphertextFinalization.register(obj, obj.__wbg_ptr, obj); return obj; } __destroy_into_raw() { const ptr = this.__wbg_ptr; this.__wbg_ptr = 0; CiphertextFinalization.unregister(this); return ptr; } free() { const ptr = this.__destroy_into_raw(); wasm.__wbg_ciphertext_free(ptr, 0); } /** * Decrypt the ciphertext using the given view key. * * @param {ViewKey} viewKey The view key of the account that encrypted the ciphertext. * @param {Group} nonce The nonce used to encrypt the ciphertext. * * @returns {Plaintext} The decrypted plaintext. * @param {ViewKey} view_key * @param {Group} nonce * @returns {Plaintext} */ decrypt(view_key, nonce) { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); _assertClass(view_key, ViewKey); var ptr0 = view_key.__destroy_into_raw(); _assertClass(nonce, Group); var ptr1 = nonce.__destroy_into_raw(); wasm.ciphertext_decrypt(retptr, this.__wbg_ptr, ptr0, ptr1); var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true); var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true); if (r2) { throw takeObject(r1); } return Plaintext.__wrap(r0); } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } /** * Decrypts a ciphertext into plaintext using the given ciphertext view key. * * @param {Field} transition_view_key The transition view key that was used to encrypt the ciphertext. * * @returns {Plaintext} The dec