@puzzlehq/aleo-wasm-web
Version:
Aleo SDK WASM
1,377 lines (1,367 loc) • 286 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,
});
});
}
/* @ts-self-types="./aleo_wasm.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;
/**
* 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 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);
}
}
/**
* Decrypt a ciphertext using the view key of the transition signer, transition public key, and
* (program, function, index) tuple.
*
* @param {ViewKey} view_key The view key of the transition signer.
* @param {Group} transition_public_key The transition public key used to encrypt the ciphertext.
* @param {string} program The program ID associated with the ciphertext.
* @param {string} function_name The name of the function associated with the encrypted inputs and outputs.
* @param {u16} index The index of the input or output parameter that was encrypted.
*
* @returns {Plaintext} The decrypted plaintext.
* @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, wasm.__wbindgen_export2);
const len2 = WASM_VECTOR_LEN;
const ptr3 = passStringToWasm0(function_name, wasm.__wbindgen_export, wasm.__wbindgen_export2);
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 The transition view key that was used to encrypt the ciphertext.
* @param {string} program The program ID associated with the ciphertext.
* @param {string} function_name The name of the function associated with the encrypted inputs and outputs.
* @param {u16} index The index of the input or output parameter that was encrypted.
*
* @returns {Plaintext} The decrypted plaintext.
* @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, wasm.__wbindgen_export2);
const len1 = WASM_VECTOR_LEN;
const ptr2 = passStringToWasm0(function_name, wasm.__wbindgen_export, wasm.__wbindgen_export2);
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);
}
}
/**
* 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);
}
}
/**
* 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 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);
}
}
/**
* 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 fromString(ciphertext) {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
const ptr0 = passStringToWasm0(ciphertext, wasm.__wbindgen_export, wasm.__wbindgen_export2);
const len0 = WASM_VECTOR_LEN;
wasm.ciphertext_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 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);
}
/**
* Serialize a Ciphertext object into a byte array.
*
* @returns {Uint8Array} The serialized Ciphertext.
* @returns {Uint8Array}
*/
toBytes() {
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 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 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);
}
}
/**
* Serialize a Ciphertext into a js string.
*
* @returns {string} The serialized Ciphertext.
* @returns {string}
*/
toString() {
let deferred1_0;
let deferred1_1;
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.ciphertext_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) Ciphertext.prototype[Symbol.dispose] = Ciphertext.prototype.free;
class ComputeKey {
static __wrap(ptr) {
ptr = ptr >>> 0;
const obj = Object.create(ComputeKey.prototype);
obj.__wbg_ptr = ptr;
ComputeKeyFinalization.register(obj, obj.__wbg_ptr, obj);
return obj;
}
__destroy_into_raw() {
const ptr = this.__wbg_ptr;
this.__wbg_ptr = 0;
ComputeKeyFinalization.unregister(this);
return ptr;
}
free() {
const ptr = this.__destroy_into_raw();
wasm.__wbg_computekey_free(ptr, 0);
}
/**
* Get the address from the compute key.
*
* @returns {Address}
* @returns {Address}
*/
address() {
const ret = wasm.address_from_compute_key(this.__wbg_ptr);
return Address.__wrap(ret);
}
/**
* Create a new compute key from a private key.
*
* @param {PrivateKey} private_key Private key
*
* @returns {ComputeKey} Compute key
* @param {PrivateKey} private_key
* @returns {ComputeKey}
*/
static from_private_key(private_key) {
_assertClass(private_key, PrivateKey);
const ret = wasm.computekey_from_private_key(private_key.__wbg_ptr);
return ComputeKey.__wrap(ret);
}
/**
* Get the pr_tag of the compute key.
*
* @returns {Group} pr_tag
* @returns {Group}
*/
pk_sig() {
const ret = wasm.address_toGroup(this.__wbg_ptr);
return Group.__wrap(ret);
}
/**
* Get the pr_sig of the compute key.
*
* @returns {Group} pr_sig
* @returns {Group}
*/
pr_sig() {
const ret = wasm.computekey_pr_sig(this.__wbg_ptr);
return Group.__wrap(ret);
}
/**
* Get the sk_prf of the compute key.
*
* @returns {Scalar} sk_prf
* @returns {Scalar}
*/
sk_prf() {
const ret = wasm.computekey_sk_prf(this.__wbg_ptr);
return Scalar.__wrap(ret);
}
}
if (Symbol.dispose) ComputeKey.prototype[Symbol.dispose] = ComputeKey.prototype.free;
/**
* Execution of an Aleo program.
*/
class Execution {
static __wrap(ptr) {
ptr = ptr >>> 0;
const obj = Object.create(Execution.prototype);
obj.__wbg_ptr = ptr;
ExecutionFinalization.register(obj, obj.__wbg_ptr, obj);
return obj;
}
__destroy_into_raw() {
const ptr = this.__wbg_ptr;
this.__wbg_ptr = 0;
ExecutionFinalization.unregister(this);
return ptr;
}
free() {
const ptr = this.__destroy_into_raw();
wasm.__wbg_execution_free(ptr, 0);
}
/**
* Creates an execution object from a string representation of an execution.
*
* @returns {Execution | Error} The wasm representation of an execution object.
* @param {string} execution
* @returns {Execution}
*/
static fromString(execution) {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
const ptr0 = passStringToWasm0(execution, wasm.__wbindgen_export, wasm.__wbindgen_export2);
const len0 = WASM_VECTOR_LEN;
wasm.execution_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 Execution.__wrap(r0);
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
}
}
/**
* Returns the global state root of the execution.
*
* @returns {Execution | Error} The global state root used in the execution.
* @returns {string}
*/
globalStateRoot() {
let deferred1_0;
let deferred1_1;
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.execution_globalStateRoot(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);
}
}
/**
* Returns the proof of the execution.
*
* @returns {string} The execution proof.
* @returns {string}
*/
proof() {
let deferred1_0;
let deferred1_1;
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.execution_proof(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);
}
}
/**
* Returns the string representation of the execution.
*
* @returns {string} The string representation of the execution.
* @returns {string}
*/
toString() {
let deferred1_0;
let deferred1_1;
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.execution_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);
}
}
/**
* Returns the transitions present in the execution.
*
* @returns Array<Transition> the array of transitions present in the execution.
* @returns {Array<any>}
*/
transitions() {
const ret = wasm.execution_transitions(this.__wbg_ptr);
return takeObject(ret);
}
}
if (Symbol.dispose) Execution.prototype[Symbol.dispose] = Execution.prototype.free;
class ExecutionRequest {
static __wrap(ptr) {
ptr = ptr >>> 0;
const obj = Object.create(ExecutionRequest.prototype);
obj.__wbg_ptr = ptr;
ExecutionRequestFinalization.register(obj, obj.__wbg_ptr, obj);
return obj;
}
__destroy_into_raw() {
const ptr = this.__wbg_ptr;
this.__wbg_ptr = 0;
ExecutionRequestFinalization.unregister(this);
return ptr;
}
free() {
const ptr = this.__destroy_into_raw();
wasm.__wbg_executionrequest_free(ptr, 0);
}
/**
* Creates an request object from a bytes representation of an request.
* @param {Uint8Array} bytes
* @returns {ExecutionRequest}
*/
static fromBytesLe(bytes) {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.executionrequest_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 ExecutionRequest.__wrap(r0);
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
}
}
/**
* Builds a request object from a string representation of a request.
*
* @param {string} request String representation of the request.
* @param {string} request
* @returns {ExecutionRequest}
*/
static fromString(request) {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
const ptr0 = passStringToWasm0(request, wasm.__wbindgen_export, wasm.__wbindgen_export2);
const len0 = WASM_VECTOR_LEN;
wasm.executionrequest_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 ExecutionRequest.__wrap(r0);
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
}
}
/**
* Returns the function name.
* @returns {string}
*/
function_name() {
let deferred1_0;
let deferred1_1;
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.executionrequest_function_name(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);
}
}
/**
* Returns the input IDs for the transition.
* @returns {Array<any>}
*/
input_ids() {
const ret = wasm.executionrequest_input_ids(this.__wbg_ptr);
return takeObject(ret);
}
/**
* Returns the function inputs as an array of strings.
* @returns {Array<any>}
*/
inputs() {
const ret = wasm.executionrequest_inputs(this.__wbg_ptr);
return takeObject(ret);
}
/**
* Returns the network ID.
* @returns {number}
*/
network_id() {
const ret = wasm.executionrequest_network_id(this.__wbg_ptr);
return ret;
}
/**
* Returns the program ID.
* @returns {string}
*/
program_id() {
let deferred1_0;
let deferred1_1;
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.executionrequest_program_id(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);
}
}
/**
* Returns the signer commitment `scm`.
* @returns {Field}
*/
scm() {
const ret = wasm.executionrequest_scm(this.__wbg_ptr);
return Field.__wrap(ret);
}
/**
* Create a new request by signing over a program ID and set of inputs.
*
* @param {PrivateKey} private_key The private key of the signer.
* @param {string} program_id The id of the program to create the signature for.
* @param {string} function_name The function name to create the signature for.
* @param {string[]} inputs The inputs to the function.
* @param {string[]} input_types The input types of the function.
* @param {Field | undefined} root_tvk The tvk of the function at the top of the call graph. This is undefined if this request is built for the top-level call or if there is only one function in the call graph.
* @param {boolean} is_root Flag to indicate if this is the top level function in the call graph.
* @param {PrivateKey} private_key
* @param {string} program_id
* @param {string} function_name
* @param {Array<any>} inputs
* @param {Array<any>} input_types
* @param {Field | null | undefined} root_tvk
* @param {Field | null | undefined} program_checksum
* @param {boolean} is_root
* @returns {ExecutionRequest}
*/
static sign(private_key, program_id, function_name, inputs, input_types, root_tvk, program_checksum, is_root) {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
_assertClass(private_key, PrivateKey);
var ptr0 = private_key.__destroy_into_raw();
const ptr1 = passStringToWasm0(program_id, wasm.__wbindgen_export, wasm.__wbindgen_export2);
const len1 = WASM_VECTOR_LEN;
const ptr2 = passStringToWasm0(function_name, wasm.__wbindgen_export, wasm.__wbindgen_export2);
const len2 = WASM_VECTOR_LEN;
let ptr3 = 0;
if (!isLikeNone(root_tvk)) {
_assertClass(root_tvk, Field);
ptr3 = root_tvk.__destroy_into_raw();
}
let ptr4 = 0;
if (!isLikeNone(program_checksum)) {
_assertClass(program_checksum, Field);
ptr4 = program_checksum.__destroy_into_raw();
}
wasm.executionrequest_sign(retptr, ptr0, ptr1, len1, ptr2, len2, addHeapObject(inputs), addHeapObject(input_types), ptr3, ptr4, is_root);
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 ExecutionRequest.__wrap(r0);
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
}
}
/**
* Returns the signature for the transition.
* @returns {Signature}
*/
signature() {
const ret = wasm.executionrequest_signature(this.__wbg_ptr);
return Signature.__wrap(ret);
}
/**
* Returns the request signer.
* @returns {Address}
*/
signer() {
const ret = wasm.executionrequest_signer(this.__wbg_ptr);
return Address.__wrap(ret);
}
/**
* Returns the tag secret key `sk_tag`.
* @returns {Field}
*/
sk_tag() {
const ret = wasm.executionrequest_sk_tag(this.__wbg_ptr);
return Field.__wrap(ret);
}
/**
* Returns the transition commitment `tcm`.
* @returns {Field}
*/
tcm() {
const ret = wasm.executionrequest_tcm(this.__wbg_ptr);
return Field.__wrap(ret);
}
/**
* Returns the bytes representation of the request.
* @returns {Uint8Array}
*/
toBytesLe() {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.executionrequest_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 request as a string.
*
* @returns {string} String representation of the request.
* @returns {string}
*/
toString() {
let deferred1_0;
let deferred1_1;
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.executionrequest_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);
}
}
/**
* Returns the transition