@provablehq/wasm
Version:
SnarkVM WASM binaries with javascript bindings
1,443 lines (1,365 loc) • 516 kB
JavaScript
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;
let heap = new Array(128).fill(undefined);
heap.push(undefined, null, true, false);
function getObject(idx) { return heap[idx]; }
function isLikeNone(x) {
return x === undefined || x === null;
}
function debugString(val) {
// primitive types
const type = typeof val;
if (type == 'number' || type == 'boolean' || val == null) {
return `${val}`;
}
if (type == 'string') {
return `"${val}"`;
}
if (type == 'symbol') {
const description = val.description;
if (description == null) {
return 'Symbol';
} else {
return `Symbol(${description})`;
}
}
if (type == 'function') {
const name = val.name;
if (typeof name == 'string' && name.length > 0) {
return `Function(${name})`;
} else {
return 'Function';
}
}
// objects
if (Array.isArray(val)) {
const length = val.length;
let debug = '[';
if (length > 0) {
debug += debugString(val[0]);
}
for(let i = 1; i < length; i++) {
debug += ', ' + debugString(val[i]);
}
debug += ']';
return debug;
}
// Test for built-in
const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
let className;
if (builtInMatches && builtInMatches.length > 1) {
className = builtInMatches[1];
} else {
// Failed to match the standard '[object ClassName]'
return toString.call(val);
}
if (className == 'Object') {
// we're a user defined class or Object
// JSON.stringify avoids problems with cycles, and is generally much
// easier than looping through ownProperties of `val`.
try {
return 'Object(' + JSON.stringify(val) + ')';
} catch (_) {
return 'Object';
}
}
// errors
if (val instanceof Error) {
return `${val.name}: ${val.message}\n${val.stack}`;
}
// TODO we could test for more things here, like `Set`s and `Map`s.
return className;
}
let WASM_VECTOR_LEN = 0;
let cachedUint8ArrayMemory0 = null;
function getUint8ArrayMemory0() {
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.buffer !== wasm.memory.buffer) {
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
}
return cachedUint8ArrayMemory0;
}
const cachedTextEncoder = (typeof TextEncoder !== 'undefined' ? new TextEncoder() : undefined);
if (cachedTextEncoder) {
cachedTextEncoder.encodeInto = 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 = cachedTextEncoder.encodeInto(arg, view);
offset += ret.written;
ptr = realloc(ptr, len, offset, 1) >>> 0;
}
WASM_VECTOR_LEN = offset;
return ptr;
}
let cachedDataViewMemory0 = null;
function getDataViewMemory0() {
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer !== wasm.memory.buffer) {
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
}
return cachedDataViewMemory0;
}
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;
}
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 = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : undefined);
if (cachedTextDecoder) cachedTextDecoder.decode();
const MAX_SAFARI_DECODE_BYTES = 2146435072;
let numBytesDecoded = 0;
function decodeText(ptr, len) {
numBytesDecoded += len;
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
cachedTextDecoder.decode();
numBytesDecoded = len;
}
return cachedTextDecoder.decode(getUint8ArrayMemory0().slice(ptr, ptr + len));
}
function getStringFromWasm0(ptr, len) {
ptr = ptr >>> 0;
return decodeText(ptr, len);
}
function handleError(f, args) {
try {
return f.apply(this, args);
} catch (e) {
wasm.__wbindgen_export3(addHeapObject(e));
}
}
function getArrayU8FromWasm0(ptr, len) {
ptr = ptr >>> 0;
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
}
const CLOSURE_DTORS = (typeof FinalizationRegistry === 'undefined')
? { register: () => {}, unregister: () => {} }
: new FinalizationRegistry(state => 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 {
state.a = a;
real._wbg_cb_unref();
}
};
real._wbg_cb_unref = () => {
if (--state.cnt === 0) {
state.dtor(state.a, state.b);
state.a = 0;
CLOSURE_DTORS.unregister(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}`);
}
}
/**
* @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);
}
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;
}
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 | undefined} imports
* @param {object | null | undefined} imported_verifying_keys
* @param {number} block_height
* @returns {boolean}
*/
function verifyFunctionExecution(execution, verifying_key, program, function_id, imports, imported_verifying_keys, block_height) {
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, wasm.__wbindgen_export2);
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), block_height);
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);
}
}
/**
* Set test consensus version heights for testing.
*
* @param {string | undefined} heights The block heights at which each consensus version applies. This input should be a simple csv list of block heights and there should be one number for each consensus version. If left undefined, the default test heights will be applied.
*
* @example
* import { getOrInitConsensusVersionHeights } from @provablehq/sdk;
*
* Set the consensus version heights.
* getOrInitConsensusVersionTestHeights("0,1,2,3,4,5,6,7,8,9,10");
* @param {string | null} [heights]
* @returns {Array<any>}
*/
function getOrInitConsensusVersionTestHeights(heights) {
var ptr0 = isLikeNone(heights) ? 0 : passStringToWasm0(heights, wasm.__wbindgen_export, wasm.__wbindgen_export2);
var len0 = WASM_VECTOR_LEN;
const ret = wasm.getOrInitConsensusVersionTestHeights(ptr0, len0);
return takeObject(ret);
}
function passArrayJsValueToWasm0(array, malloc) {
const ptr = malloc(array.length * 4, 4) >>> 0;
const mem = getDataViewMemory0();
for (let i = 0; i < array.length; i++) {
mem.setUint32(ptr + 4 * i, addHeapObject(array[i]), true);
}
WASM_VECTOR_LEN = array.length;
return ptr;
}
function getArrayJsValueFromWasm0(ptr, len) {
ptr = ptr >>> 0;
const mem = getDataViewMemory0();
const result = [];
for (let i = ptr; i < ptr + 4 * len; i += 4) {
result.push(takeObject(mem.getUint32(i, true)));
}
return result;
}
function __wasm_bindgen_func_elem_7859(arg0, arg1, arg2) {
wasm.__wasm_bindgen_func_elem_7859(arg0, arg1, addHeapObject(arg2));
}
function __wasm_bindgen_func_elem_6809(arg0, arg1, arg2, arg3) {
wasm.__wasm_bindgen_func_elem_6809(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);
}
/**
* 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 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);
}
}
/**
* 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);
}
/**
* 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 plaintext representation of the address.
* @returns {Plaintext}
*/
toPlaintext() {
const ret = wasm.address_toPlaintext(this.__wbg_ptr);
return Plaintext.__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);
}
}
/**
* 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 address of a program based on the program ID.
*
* @param {string} program_id The program ID string.
* @returns {Address} The address corresponding to the program ID.
* @param {string} program_id
* @returns {Address}
*/
static fromProgramId(program_id) {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
const ptr0 = passStringToWasm0(program_id, wasm.__wbindgen_export, wasm.__wbindgen_export2);
const len0 = WASM_VECTOR_LEN;
wasm.address_fromProgramId(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 Address.__wrap(r0);
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
}
}
/**
* 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);
}
/**
* 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;
}
/**
* 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 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 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);
}
}
}
if (Symbol.dispose) Address.prototype[Symbol.dispose] = Address.prototype.free;
const AuthorizationFinalization = (typeof FinalizationRegistry === 'undefined')
? { register: () => {}, unregister: () => {} }
: new FinalizationRegistry(ptr => wasm.__wbg_authorization_free(ptr >>> 0, 1));
/**
* 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);
}
/**
* 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);
}
}
/**
* 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);
}
}
/**
* 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);
}
/**
* 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);
}
}
/**
* 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);
}
}
/**
* 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/fee_private`.
* @returns {boolean}
*/
isFeePrivate() {
const ret = wasm.authorization_isFeePrivate(this.__wbg_ptr);
return ret !== 0;
}
/**
* 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);
}
}
/**
* 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);
}
}
/**
* 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);
}
}
/**
* 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;
}
/**
* 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/split`.
* @returns {boolean}
*/
isSplit() {
const ret = wasm.authorization_isSplit(this.__wbg_ptr);
return ret !== 0;
}
/**
* 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 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);
}
}
}
if (Symbol.dispose) Authorization.prototype[Symbol.dispose] = Authorization.prototype.free;
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);
}
/**
* 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 {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);
}
}
/**
* 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;
}
/**
* 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);
}
}
/**
* 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);
}
}
/**
* 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);
}
}
}
if (Symbol.dispose) BHP1024.prototype[Symbol.dispose] = BHP1024.prototype.free;
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);
}
/**
* 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 {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);
}
}
/**
* 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;
}
/**
* 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);
}
}
/**
* 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);
}
}
/**
* 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);
}
}
}
if (Symbol.dispose) BHP256.prototype[Symbol.dispose] = BHP256.prototype.free;
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);
}
/**
* 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 {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);
}
}
/**
* 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;
}
/**
* 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);
}
}
/**
* 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);
}
}
/**
* 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);
}
}
}
if (Symbol.dispose) BHP512.prototype[Symbol.dispose] = BHP512.prototype.free;
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);
}
/**
* 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(in