UNPKG

@provablehq/wasm

Version:

SnarkVM WASM binaries with javascript bindings

1,399 lines (1,327 loc) 316 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, }); }); } 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 addHeapObject(obj) { if (heap_next === heap.length) heap.push(heap.length + 1); const idx = heap_next; heap_next = heap[idx]; heap[idx] = obj; return idx; } const cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } ); if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); } let cachedUint8ArrayMemory0 = null; function getUint8ArrayMemory0() { if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.buffer !== wasm.memory.buffer) { cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer); } return cachedUint8ArrayMemory0; } function getStringFromWasm0(ptr, len) { ptr = ptr >>> 0; return cachedTextDecoder.decode(getUint8ArrayMemory0().slice(ptr, ptr + len)); } function handleError(f, args) { try { return f.apply(this, args); } catch (e) { wasm.__wbindgen_export_1(addHeapObject(e)); } } 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 WASM_VECTOR_LEN = 0; const cachedTextEncoder = (typeof TextEncoder !== 'undefined' ? new TextEncoder('utf-8') : { encode: () => { throw Error('TextEncoder not available') } } ); const encodeString = function (arg, view) { const buf = cachedTextEncoder.encode(arg); view.set(buf); return { read: arg.length, written: buf.length }; }; function passStringToWasm0(arg, malloc, realloc) { if (realloc === undefined) { const buf = cachedTextEncoder.encode(arg); const ptr = malloc(buf.length, 1) >>> 0; getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf); WASM_VECTOR_LEN = buf.length; return ptr; } let len = arg.length; let ptr = malloc(len, 1) >>> 0; const mem = getUint8ArrayMemory0(); let offset = 0; for (; offset < len; offset++) { const code = arg.charCodeAt(offset); if (code > 0x7F) break; mem[ptr + offset] = code; } if (offset !== len) { if (offset !== 0) { arg = arg.slice(offset); } ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0; const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len); const ret = encodeString(arg, view); offset += ret.written; ptr = realloc(ptr, len, offset, 1) >>> 0; } WASM_VECTOR_LEN = offset; return ptr; } function isLikeNone(x) { return x === undefined || x === null; } let cachedDataViewMemory0 = null; function getDataViewMemory0() { if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer !== wasm.memory.buffer) { cachedDataViewMemory0 = new DataView(wasm.memory.buffer); } return cachedDataViewMemory0; } const CLOSURE_DTORS = (typeof FinalizationRegistry === 'undefined') ? { register: () => {}, unregister: () => {} } : new FinalizationRegistry(state => { wasm.__wbindgen_export_5.get(state.dtor)(state.a, state.b); }); function makeMutClosure(arg0, arg1, dtor, f) { const state = { a: arg0, b: arg1, cnt: 1, dtor }; const real = (...args) => { // First up with a closure we increment the internal reference // count. This ensures that the Rust closure environment won't // be deallocated while we're invoking it. state.cnt++; const a = state.a; state.a = 0; try { return f(a, state.b, ...args); } finally { if (--state.cnt === 0) { wasm.__wbindgen_export_5.get(state.dtor)(a, state.b); CLOSURE_DTORS.unregister(state); } else { state.a = a; } } }; real.original = state; CLOSURE_DTORS.register(real, state, state); return real; } function _assertClass(instance, klass) { if (!(instance instanceof klass)) { throw new Error(`expected instance of ${klass.name}`); } } function passArray8ToWasm0(arg, malloc) { const ptr = malloc(arg.length * 1, 1) >>> 0; getUint8ArrayMemory0().set(arg, ptr / 1); WASM_VECTOR_LEN = arg.length; return ptr; } /** * Verify an execution. Executions with multiple transitions must have the program source code and * verifying keys of imported functions supplied from outside to correctly verify. Also, this does * not verify that the state root of the execution is included in the Aleo Network ledger. * * @param {Execution} execution The function execution to verify * @param {VerifyingKey} verifying_key The verifying key for the function * @param {Program} program The program that the function execution belongs to * @param {String} function_id The name of the function that was executed * @param {Object} imports The imports for the program in the form of { "program_id.aleo":"source code", ... } * @param {Object} import_verifying_keys The verifying keys for the imports in the form of { "program_id.aleo": [["function, "verifying_key"], ...], ...} * @returns {boolean} True if the execution is valid, false otherwise * @param {Execution} execution * @param {VerifyingKey} verifying_key * @param {Program} program * @param {string} function_id * @param {object | null} [imports] * @param {object | null} [imported_verifying_keys] * @returns {boolean} */ function verifyFunctionExecution(execution, verifying_key, program, function_id, imports, imported_verifying_keys) { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); _assertClass(execution, Execution); _assertClass(verifying_key, VerifyingKey); _assertClass(program, Program); const ptr0 = passStringToWasm0(function_id, wasm.__wbindgen_export_3, wasm.__wbindgen_export_4); const len0 = WASM_VECTOR_LEN; wasm.verifyFunctionExecution(retptr, execution.__wbg_ptr, verifying_key.__wbg_ptr, program.__wbg_ptr, ptr0, len0, isLikeNone(imports) ? 0 : addHeapObject(imports), isLikeNone(imported_verifying_keys) ? 0 : addHeapObject(imported_verifying_keys)); 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 r0 !== 0; } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } function getArrayU8FromWasm0(ptr, len) { ptr = ptr >>> 0; return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len); } let stack_pointer = 128; function addBorrowedObject(obj) { if (stack_pointer == 1) throw new Error('out of js stack'); heap[--stack_pointer] = obj; return stack_pointer; } /** * @param {number} receiver */ function runRayonThread(receiver) { wasm.runRayonThread(receiver); } /** * @param {URL} url * @param {number} num_threads * @returns {Promise<void>} */ function initThreadPool(url, num_threads) { const ret = wasm.initThreadPool(addHeapObject(url), num_threads); return takeObject(ret); } function __wbg_adapter_40(arg0, arg1, arg2) { wasm.__wbindgen_export_6(arg0, arg1, addHeapObject(arg2)); } function __wbg_adapter_526(arg0, arg1, arg2, arg3) { wasm.__wbindgen_export_7(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3)); } const __wbindgen_enum_RequestCredentials = ["omit", "same-origin", "include"]; const __wbindgen_enum_RequestMode = ["same-origin", "no-cors", "cors", "navigate"]; const AddressFinalization = (typeof FinalizationRegistry === 'undefined') ? { register: () => {}, unregister: () => {} } : new FinalizationRegistry(ptr => wasm.__wbg_address_free(ptr >>> 0, 1)); /** * 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); } /** * 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); } /** * 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); } /** * 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); } /** * 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 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 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 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 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 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 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); } /** * Get the group representation of the address object. * @returns {Group} */ toGroup() { const ret = wasm.address_toGroup(this.__wbg_ptr); return Group.__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_3, wasm.__wbindgen_export_4); const len0 = WASM_VECTOR_LEN; const ret = wasm.address_from_string(ptr0, len0); return Address.__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_export_2(deferred1_0, deferred1_1, 1); } } /** * Get the plaintext representation of the address. * @returns {Plaintext} */ toPlaintext() { const ret = wasm.address_toPlaintext(this.__wbg_ptr); return Plaintext.__wrap(ret); } /** * 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_3); const len0 = WASM_VECTOR_LEN; _assertClass(signature, Signature); const ret = wasm.address_verify(this.__wbg_ptr, ptr0, len0, signature.__wbg_ptr); return ret !== 0; } } const BHP1024Finalization = (typeof FinalizationRegistry === 'undefined') ? { register: () => {}, unregister: () => {} } : new FinalizationRegistry(ptr => wasm.__wbg_bhp1024_free(ptr >>> 0, 1)); 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); } /** * 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_3, wasm.__wbindgen_export_4); 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); } } /** * 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); } } /** * 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); } } } const BHP256Finalization = (typeof FinalizationRegistry === 'undefined') ? { register: () => {}, unregister: () => {} } : new FinalizationRegistry(ptr => wasm.__wbg_bhp256_free(ptr >>> 0, 1)); 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); } /** * 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_3, wasm.__wbindgen_export_4); 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); } } /** * 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); } } /** * 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); } } } const BHP512Finalization = (typeof FinalizationRegistry === 'undefined') ? { register: () => {}, unregister: () => {} } : new FinalizationRegistry(ptr => wasm.__wbg_bhp512_free(ptr >>> 0, 1)); 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); } /** * 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_3, wasm.__wbindgen_export_4); 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); } } /** * 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); } } /** * 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); } } } const BHP768Finalization = (typeof FinalizationRegistry === 'undefined') ? { register: () => {}, unregister: () => {} } : new FinalizationRegistry(ptr => wasm.__wbg_bhp768_free(ptr >>> 0, 1)); 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); } /** * 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_3, wasm.__wbindgen_export_4); 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); } } /** * 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); } } /** * 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); } } } const CiphertextFinalization = (typeof FinalizationRegistry === 'undefined') ? { register: () => {}, unregister: () => {} } : new FinalizationRegistry(ptr => wasm.__wbg_ciphertext_free(ptr >>> 0, 1)); /** * 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). * * @example */ 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); } } /** * Decrypt a ciphertext using the view key of the transition signer, transition public key, and * (program, function, index) tuple. * @param {ViewKey} view_key * @param {Group} transition_public_key * @param {string} program * @param {string} function_name * @param {number} index * @returns {Plaintext} */ decryptWithTransitionInfo(view_key, transition_public_key, program, function_name, index) { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); _assertClass(view_key, ViewKey); var ptr0 = view_key.__destroy_into_raw(); _assertClass(transition_public_key, Group); var ptr1 = transition_public_key.__destroy_into_raw(); const ptr2 = passStringToWasm0(program, wasm.__wbindgen_export_3, wasm.__wbindgen_export_4); const len2 = WASM_VECTOR_LEN; const ptr3 = passStringToWasm0(function_name, wasm.__wbindgen_export_3, wasm.__wbindgen_export_4); const len3 = WASM_VECTOR_LEN; wasm.ciphertext_decryptWithTransitionInfo(retptr, this.__wbg_ptr, ptr0, ptr1, ptr2, len2, ptr3, len3, index); 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); } } /** * Decrypt a ciphertext using the transition view key and a (program, function, index) tuple. * @param {Field} transition_view_key * @param {string} program * @param {string} function_name * @param {number} index * @returns {Plaintext} */ decryptWithTransitionViewKey(transition_view_key, program, function_name, index) { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); _assertClass(transition_view_key, Field); var ptr0 = transition_view_key.__destroy_into_raw(); const ptr1 = passStringToWasm0(program, wasm.__wbindgen_export_3, wasm.__wbindgen_export_4); const len1 = WASM_VECTOR_LEN; const ptr2 = passStringToWasm0(function_name, wasm.__wbindgen_export_3, wasm.__wbindgen_export_4); const len2 = WASM_VECTOR_LEN; wasm.ciphertext_decryptWithTransitionViewKey(retptr, this.__wbg_ptr, ptr0, ptr1, len1, ptr2, len2, index); 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 decrypted plaintext. * @param {Field} transition_view_key * @returns {Plaintext} */ decryptSymmetric(transition_view_key) { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); _assertClass(transition_view_key, Field); var ptr0 = transition_view_key.__destroy_into_raw(); wasm.ciphertext_decryptSymmetric(retptr, this.__wbg_ptr, 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 Plaintext.__wrap(r0); } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } /** * Deserialize a left endian byte array into a Ciphertext. * * @param {Uint8Array} bytes The byte array representing the Ciphertext. * * @returns {Ciphertext} The Ciphertext object. * @param {Uint8Array} bytes * @returns {Ciphertext} */ static fromBytesLe(bytes) { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.ciphertext_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 Ciphertext.__wrap(r0); } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } /** * Get the left endian byte array representation of the ciphertext. * @returns {Uint8Array} */ toBytesLe() { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.ciphertext_toBytes(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 a ciphertext object from a series of bits represented as a boolean array. * * @param {Array} bits A left endian boolean array representing the bits of the ciphertext. * * @returns {Ciphertext} The ciphertext object. * @param {Array<any>} bits * @returns {Ciphertext} */ static fromBitsLe(bits) { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.ciphertext_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 Ciphertext.__wrap(r0); } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } /** * Get the left endian boolean array representation of the bits of the ciphertext. * @returns {Array<any>} */ toBitsLe() { const ret = wasm.ciphertext_toBitsLe(this.__wbg_ptr); return takeObject(ret); } /** * Get a ciphertext object from an array of fields. * * @param {Array} fields An array of fields. * * @returns {Ciphertext} The ciphertext object. * @param {Array<any>} fields * @returns {Ciphertext} */ static fromFields(fields) { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.ciphertext_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 Ciphertext.__wrap(r0); } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } /** * Get the field array representation of the ciphertext. * @returns {Array<any>} */ toFields() { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.ciphertext_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); } } /** * Deserialize a Ciphertext string into a Ciphertext object. * * @param {string} ciphertext A string representation of the ciphertext. * * @returns {Ciphertext} The Ciphertext object. * @param {string} ciphertext * @returns {Ciphertext} */ static fromS