@puzzlehq/aleo-wasm-nodejs
Version:
Aleo SDK WASM
1,630 lines • 106 kB
TypeScript
/* tslint:disable */
/* eslint-disable */
/**
* 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
*/
export function verifyFunctionExecution(execution: Execution, verifying_key: VerifyingKey, program: Program, function_id: string, imports: object | null | undefined, imported_verifying_keys: object | null | undefined, block_height: number): boolean;
export function runRayonThread(receiver: number): void;
export function initThreadPool(url: URL, num_threads: number): Promise<void>;
/**
* Public address of an Aleo account
*/
export class Address {
private constructor();
free(): void;
/**
* 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
*/
static from_private_key(private_key: PrivateKey): Address;
/**
* 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
*/
static from_view_key(view_key: ViewKey): Address;
/**
* Derive an Aleo address from a compute key.
*
* @param {ComputeKey} compute_key The compute key to derive the address from
*/
static from_compute_key(compute_key: ComputeKey): Address;
/**
* Get an address from a series of bytes.
*
* @param {Uint8Array} bytes A left endian byte array representing the address.
*
* @returns {Address} The address object.
*/
static fromBytesLe(bytes: Uint8Array): Address;
/**
* Get the left endian byte array representation of the address.
*/
toBytesLe(): Uint8Array;
/**
* 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.
*/
static fromBitsLe(bits: Array<any>): Address;
/**
* Get the left endian boolean array representation of the bits of the address.
*/
toBitsLe(): Array<any>;
/**
* Get an address object from an array of fields.
*
* @param {Array} fields An array of fields.
*
* @returns {Plaintext} The address object.
*/
static fromFields(fields: Array<any>): Address;
/**
* Get the field array representation of the address.
*/
toFields(): Array<any>;
/**
* Get an address object from a group.
*
* @param {Group} group The group object.
*
* @returns {Address} The address object.
*/
static fromGroup(group: Group): Address;
/**
* Get the group representation of the address object.
*/
toGroup(): Group;
/**
* Create an aleo address object from a string representation of an address
*
* @param {string} address String representation of an addressm
* @returns {Address} Address
*/
static from_string(address: string): Address;
/**
* Get a string representation of an Aleo address object
*
* @param {Address} Address
* @returns {string} String representation of the address
*/
to_string(): string;
/**
* Get the plaintext representation of the address.
*/
toPlaintext(): Plaintext;
/**
* 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
*/
verify(message: Uint8Array, signature: Signature): boolean;
}
/**
* Authorization object containing the authorization for a transaction.
*/
export class Authorization {
private constructor();
free(): void;
/**
* Create a new authorization from a request object.
*
* @param {ExecutionRequest} request The ExecutionRequest to build the authorization from.
*/
static new(request: ExecutionRequest): Authorization;
/**
* Returns a new and independent replica of the Authorization.
*/
replicate(): Authorization;
/**
* Returns the string representation of the Authorization.
*/
toString(): string;
/**
* Reconstructs an Authorization object from its string representation.
*
* @param {String} authorization The string representation of the Authorization.
*/
static fromString(authorization: string): Authorization;
/**
* Returns the left-endian byte representation of the Authorization.
*/
toBytesLe(): Uint8Array;
/**
* Creates an authorization object from a left-endian byte representation of an Authorization.
*
* @param {Uint8Array} bytes Left-endian bytes representing the Authorization.
*/
static fromBytesLe(bytes: Uint8Array): Authorization;
/**
* Check if an Authorization object is the same as another.
*
* @param {Authorization} other The Authorization object to determine equality with.
*/
equals(other: Authorization): boolean;
/**
* Returns the number of `Request`s in the Authorization.
*/
len(): number;
/**
* Return `true` if the Authorization is empty.
*/
isEmpty(): boolean;
/**
* Returns `true` if the Authorization is for `credits.aleo/fee_private`.
*/
isFeePrivate(): boolean;
/**
* Returns `true` if the Authorization is for `credits.aleo/fee_public`.
*/
isFeePublic(): boolean;
/**
* Returns `true` if the Authorization is for `credits.aleo/split`.
*/
isSplit(): boolean;
/**
* Insert a transition into the Authorization.
*
* @param {Transition} transition The transition object to insert into the Authorization.
*/
insertTransition(transition: Transition): void;
/**
* Get the transitions in an Authorization.
*
* @returns {Array<Transition>} Array of transition objects
*/
transitions(): Array<any>;
/**
* 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.
*/
toExecutionId(): Field;
}
export class BHP1024 {
free(): void;
/**
* Create a BHP hasher with an input size of 1024 bits.
*/
constructor();
/**
* Create a BHP hasher with an input size of 1024 bits with a custom domain separator.
*/
static setup(domain_separator: string): BHP1024;
/**
* Returns the BHP hash with an input hasher of 1024 bits.
*/
hash(input: Array<any>): Field;
/**
* Returns a BHP hash with an input hasher of 1024 bits.
*/
hashToGroup(input: Array<any>): Group;
/**
* Returns a BHP commitment with an input hasher of 1024 bits and randomizer.
*/
commit(input: Array<any>, randomizer: Scalar): Field;
/**
* Returns a BHP commitment with an input hasher of 1024 bits and randomizer.
*/
commitToGroup(input: Array<any>, randomizer: Scalar): Group;
}
export class BHP256 {
free(): void;
/**
* Create a BHP hasher with an input size of 256 bits.
*/
constructor();
/**
* Create a BHP hasher with an input size of 256 bits with a custom domain separator.
*/
static setup(domain_separator: string): BHP256;
/**
* Returns the BHP hash with an input hasher of 256 bits.
*/
hash(input: Array<any>): Field;
/**
* Returns a BHP hash with an input hasher of 256 bits.
*/
hashToGroup(input: Array<any>): Group;
/**
* Returns a BHP commitment with an input hasher of 256 bits and randomizer.
*/
commit(input: Array<any>, randomizer: Scalar): Field;
/**
* Returns a BHP commitment with an input hasher of 256 bits and randomizer.
*/
commitToGroup(input: Array<any>, randomizer: Scalar): Group;
}
export class BHP512 {
free(): void;
/**
* Create a BHP hasher with an input size of 512 bits.
*/
constructor();
/**
* Create a BHP hasher with an input size of 512 bits with a custom domain separator.
*/
static setup(domain_separator: string): BHP512;
/**
* Returns the BHP hash with an input hasher of 512 bits.
*/
hash(input: Array<any>): Field;
/**
* Returns a BHP hash with an input hasher of 512 bits.
*/
hashToGroup(input: Array<any>): Group;
/**
* Returns a BHP commitment with an input hasher of 512 bits and randomizer.
*/
commit(input: Array<any>, randomizer: Scalar): Field;
/**
* Returns a BHP commitment with an input hasher of 512 bits and randomizer.
*/
commitToGroup(input: Array<any>, randomizer: Scalar): Group;
}
export class BHP768 {
free(): void;
/**
* Create a BHP hasher with an input size of 768 bits.
*/
constructor();
/**
* Create a BHP hasher with an input size of 768 bits with a custom domain separator.
*/
static setup(domain_separator: string): BHP768;
/**
* Returns the BHP hash with an input hasher of 768 bits.
*/
hash(input: Array<any>): Field;
/**
* Returns a BHP hash with an input hasher of 768 bits.
*/
hashToGroup(input: Array<any>): Group;
/**
* Returns a BHP commitment with an input hasher of 768 bits and randomizer.
*/
commit(input: Array<any>, randomizer: Scalar): Field;
/**
* Returns a BHP commitment with an input hasher of 768 bits and randomizer.
*/
commitToGroup(input: Array<any>, randomizer: Scalar): Group;
}
/**
* Boolean element.
*/
export class Boolean {
free(): void;
/**
* Creates a Boolean from a native JS bool.
*/
constructor(value: boolean);
/**
* Creates a boolean object from a string representation ("true"/"false").
*/
static fromString(boolean: string): Boolean;
/**
* Returns the string representation of the boolean element.
*/
toString(): string;
/**
* Create a boolean element from a Uint8Array of left endian bytes.
*/
static fromBytesLe(bytes: Uint8Array): Boolean;
/**
* Encode the boolean element as a Uint8Array of left endian bytes.
*/
toBytesLe(): Uint8Array;
/**
* Reconstruct a boolean element from a boolean array representation.
*/
static fromBitsLe(bits: Array<any>): Boolean;
/**
* Get the left endian boolean array representation of the boolean element.
*/
toBitsLe(): Array<any>;
/**
* Create a plaintext from the boolean element.
*/
toPlaintext(): Plaintext;
/**
* Clone the boolean element.
*/
clone(): Boolean;
/**
* Generate a random boolean element.
*/
static random(): Boolean;
/**
* Logical NOT.
*/
not(): Boolean;
/**
* Logical AND.
*/
and(other: Boolean): Boolean;
/**
* Logical OR.
*/
or(other: Boolean): Boolean;
/**
* Logical XOR.
*/
xor(other: Boolean): Boolean;
/**
* Logical NAND.
*/
nand(other: Boolean): Boolean;
/**
* Logical NOR.
*/
nor(other: Boolean): Boolean;
/**
* Check if one boolean element equals another.
*/
equals(other: Boolean): boolean;
}
/**
* 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).
*/
export class Ciphertext {
private constructor();
free(): void;
/**
* 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.
*/
decrypt(view_key: ViewKey, nonce: Group): Plaintext;
/**
* 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.
*/
decryptWithTransitionInfo(view_key: ViewKey, transition_public_key: Group, program: string, function_name: string, index: number): Plaintext;
/**
* 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.
*/
decryptWithTransitionViewKey(transition_view_key: Field, program: string, function_name: string, index: number): Plaintext;
/**
* 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.
*/
decryptSymmetric(transition_view_key: Field): Plaintext;
/**
* Deserialize a left endian byte array into a Ciphertext.
*
* @param {Uint8Array} bytes The byte array representing the Ciphertext.
*
* @returns {Ciphertext} The Ciphertext object.
*/
static fromBytesLe(bytes: Uint8Array): Ciphertext;
/**
* Get the left endian byte array representation of the ciphertext.
*/
toBytesLe(): Uint8Array;
/**
* 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.
*/
static fromBitsLe(bits: Array<any>): Ciphertext;
/**
* Get the left endian boolean array representation of the bits of the ciphertext.
*/
toBitsLe(): Array<any>;
/**
* Get a ciphertext object from an array of fields.
*
* @param {Array} fields An array of fields.
*
* @returns {Ciphertext} The ciphertext object.
*/
static fromFields(fields: Array<any>): Ciphertext;
/**
* Get the field array representation of the ciphertext.
*/
toFields(): Array<any>;
/**
* Deserialize a Ciphertext string into a Ciphertext object.
*
* @param {string} ciphertext A string representation of the ciphertext.
*
* @returns {Ciphertext} The Ciphertext object.
*/
static fromString(ciphertext: string): Ciphertext;
/**
* Serialize a Ciphertext object into a byte array.
*
* @returns {Uint8Array} The serialized Ciphertext.
*/
toBytes(): Uint8Array;
/**
* Serialize a Ciphertext into a js string.
*
* @returns {string} The serialized Ciphertext.
*/
toString(): string;
}
export class ComputeKey {
private constructor();
free(): void;
/**
* Create a new compute key from a private key.
*
* @param {PrivateKey} private_key Private key
*
* @returns {ComputeKey} Compute key
*/
static from_private_key(private_key: PrivateKey): ComputeKey;
/**
* Get the address from the compute key.
*
* @returns {Address}
*/
address(): Address;
/**
* Get the sk_prf of the compute key.
*
* @returns {Scalar} sk_prf
*/
sk_prf(): Scalar;
/**
* Get the pr_tag of the compute key.
*
* @returns {Group} pr_tag
*/
pk_sig(): Group;
/**
* Get the pr_sig of the compute key.
*
* @returns {Group} pr_sig
*/
pr_sig(): Group;
}
export class EncryptionToolkit {
private constructor();
free(): void;
/**
* Generates a transition view key from the view key and the transition public key.
*
* @param {ViewKey} view_key The view key of the account that generated the transition.
* @param {Group} tpk The transition public key.
*
* @returns {Field} The transition view key.
*/
static generateTvk(view_key: ViewKey, tpk: Group): Field;
/**
* Creates a record view key from the view key. This can be later be used to decrypt a
*
* @param {ViewKey} view_key The view key of the owner of the record.
* @param {RecordCiphertext} record_ciphertext The record ciphertext used to derive the record view key.
*
* @returns {Field} The record view key.
*/
static generateRecordViewKey(view_key: ViewKey, record_ciphertext: RecordCiphertext): Field;
/**
* Decrypts a record ciphertext using the record view key. Decryption only succeeds
* if the record view key was generated from the view key of the record owner.
*
* @param {Field} record_vk The record view key.
* @param {RecordCiphertext} record_ciphertext The record ciphertext to decrypt.
*
* @returns {RecordPlaintext} The decrypted record plaintext.
*/
static decryptRecordWithRVk(record_vk: Field, record_ciphertext: RecordCiphertext): RecordPlaintext;
/**
* Decrypts a transition using the transition view key. The ciphertext inputs and outputs
* can only be decrypted if the transition view key was generated by the transaction signer.
*
* @param {Transition} transition The transition to decrypt.
* @param {Field} transition_vk The transition view key.
*
* @returns {Transition} The decrypted transition.
*/
static decryptTransitionWithVk(transition: Transition, transition_vk: Field): Transition;
}
/**
* Execution of an Aleo program.
*/
export class Execution {
private constructor();
free(): void;
/**
* Returns the string representation of the execution.
*
* @returns {string} The string representation of the execution.
*/
toString(): string;
/**
* Creates an execution object from a string representation of an execution.
*
* @returns {Execution | Error} The wasm representation of an execution object.
*/
static fromString(execution: string): Execution;
/**
* Returns the global state root of the execution.
*
* @returns {Execution | Error} The global state root used in the execution.
*/
globalStateRoot(): string;
/**
* Returns the proof of the execution.
*
* @returns {string} The execution proof.
*/
proof(): string;
/**
* Returns the transitions present in the execution.
*
* @returns Array<Transition> the array of transitions present in the execution.
*/
transitions(): Array<any>;
}
export class ExecutionRequest {
private constructor();
free(): void;
/**
* Returns the request as a string.
*
* @returns {string} String representation of the request.
*/
toString(): string;
/**
* Builds a request object from a string representation of a request.
*
* @param {string} request String representation of the request.
*/
static fromString(request: string): ExecutionRequest;
/**
* Returns the bytes representation of the request.
*/
toBytesLe(): Uint8Array;
/**
* Creates an request object from a bytes representation of an request.
*/
static fromBytesLe(bytes: Uint8Array): ExecutionRequest;
/**
* Returns the request signer.
*/
signer(): Address;
/**
* Returns the network ID.
*/
network_id(): number;
/**
* Returns the program ID.
*/
program_id(): string;
/**
* Returns the function name.
*/
function_name(): string;
/**
* Returns the input IDs for the transition.
*/
input_ids(): Array<any>;
/**
* Returns the function inputs as an array of strings.
*/
inputs(): Array<any>;
/**
* Returns the signature for the transition.
*/
signature(): Signature;
/**
* Returns the tag secret key `sk_tag`.
*/
sk_tag(): Field;
/**
* Returns the transition view key `tvk`.
*/
tvk(): Field;
/**
* Returns the transition public key `tpk`.
*/
to_tpk(): Group;
/**
* Returns the transition commitment `tcm`.
*/
tcm(): Field;
/**
* Returns the signer commitment `scm`.
*/
scm(): Field;
/**
* 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.
*/
static sign(private_key: PrivateKey, program_id: string, function_name: string, inputs: Array<any>, input_types: Array<any>, root_tvk: Field | null | undefined, is_root: boolean): ExecutionRequest;
/**
* Verify the input types within a request.
*
* @param {string[]} The input_types within the request.
* @param {boolean} Flag to indicate whether this request is the first function in the call graph.
*/
verify(input_types: Array<any>, is_root: boolean): boolean;
}
/**
* Webassembly Representation of an Aleo function execution response
*
* This object is returned by the execution of an Aleo function off-chain. It provides methods for
* retrieving the outputs of the function execution.
*/
export class ExecutionResponse {
private constructor();
free(): void;
/**
* Get the outputs of the executed function
*
* @returns {Array} Array of strings representing the outputs of the function
*/
getOutputs(): Array<any>;
/**
* Returns the execution object if present, null if otherwise.
*
* @returns {Execution | undefined} The execution object if present, null if otherwise
*/
getExecution(): Execution | undefined;
/**
* Returns the program keys if present
*/
getKeys(): KeyPair;
/**
* Returns the proving_key if the proving key was cached in the Execution response.
* Note the proving key is removed from the response object after the first call to this
* function. Subsequent calls will return null.
*
* @returns {ProvingKey | undefined} The proving key
*/
getProvingKey(): ProvingKey | undefined;
/**
* Returns the verifying_key associated with the program
*
* @returns {VerifyingKey} The verifying key
*/
getVerifyingKey(): VerifyingKey;
/**
* Returns the function identifier
*/
getFunctionId(): string;
/**
* Returns the program
*/
getProgram(): Program;
}
/**
* Field element.
*/
export class Field {
private constructor();
free(): void;
/**
* Creates a field object from a string representation of a field element.
*/
static fromString(field: string): Field;
/**
* Returns the string representation of the field element.
*/
toString(): string;
/**
* Create a field element from a Uint8Array of left endian bytes.
*/
static fromBytesLe(bytes: Uint8Array): Field;
/**
* Encode the field element as a Uint8Array of left endian bytes.
*/
toBytesLe(): Uint8Array;
/**
* Reconstruct a field element from a boolean array representation.
*/
static fromBitsLe(bits: Array<any>): Field;
/**
* Get the left endian boolean array representation of the field element.
*/
toBitsLe(): Array<any>;
/**
* Create a plaintext from the field element.
*/
toPlaintext(): Plaintext;
/**
* Clone the field element.
*/
clone(): Field;
/**
* Generate a random field element.
*/
static random(): Field;
/**
* Add two field elements.
*/
add(other: Field): Field;
/**
* Subtract two field elements.
*/
subtract(other: Field): Field;
/**
* Multiply two field elements.
*/
multiply(other: Field): Field;
/**
* Divide two field elements.
*/
divide(other: Field): Field;
/**
* Power of a field element.
*/
pow(other: Field): Field;
/**
* Invert the field element.
*/
inverse(): Field;
/**
* Get the additive identity element of the field.
*/
static zero(): Field;
/**
* Get the multiplicative identity of the field.
*/
static one(): Field;
/**
* Double the field element.
*/
double(): Field;
/**
* Check if one field element equals another.
*/
equals(other: Field): boolean;
}
export class GraphKey {
private constructor();
free(): void;
/**
* Create a new graph key from a view key.
*
* @param {ViewKey} view_key View key
* @returns {GraphKey} Graph key
*/
static from_view_key(view_key: ViewKey): GraphKey;
/**
* Create a new graph key from a string representation of a graph key
*
* @param {string} graph_key String representation of a graph key
* @returns {GraphKey} Graph key
*/
static from_string(graph_key: string): GraphKey;
/**
* Get a string representation of a graph key
*
* @returns {string} String representation of a graph key
*/
to_string(): string;
/**
* Get the sk_tag of the graph key. Used to determine ownership of records.
*/
sk_tag(): Field;
}
/**
* Elliptic curve element.
*/
export class Group {
private constructor();
free(): void;
/**
* Creates a group object from a string representation of a group element.
*/
static fromString(group: string): Group;
/**
* Returns the string representation of the group element.
*/
toString(): string;
/**
* Create a group element from a Uint8Array of left endian bytes.
*/
static fromBytesLe(bytes: Uint8Array): Group;
/**
* Encode the group element as a Uint8Array of left endian bytes.
*/
toBytesLe(): Uint8Array;
/**
* Reconstruct a group element from a boolean array representation.
*/
static fromBitsLe(bits: Array<any>): Group;
/**
* Get the left endian boolean array representation of the group element.
*/
toBitsLe(): Array<any>;
/**
* Get the field array representation of the group.
*/
toFields(): Array<any>;
/**
* Get the x-coordinate of the group element.
*/
toXCoordinate(): Field;
/**
* Create a plaintext element from a group element.
*/
toPlaintext(): Plaintext;
/**
* Clone the group element.
*/
clone(): Group;
/**
* Generate a random group element.
*/
static random(): Group;
/**
* Add two group elements.
*/
add(other: Group): Group;
/**
* Subtract two group elements (equivalently: add the inverse of an element).
*/
subtract(other: Group): Group;
/**
* Multiply a group element by a scalar element.
*/
scalarMultiply(scalar: Scalar): Group;
/**
* Double the group element.
*/
double(): Group;
/**
* Get the inverse of the group element. This is the reflection of the point about the axis
* of symmetry i.e. (x,y) -> (x, -y).
*/
inverse(): Group;
/**
* Check if one group element equals another.
*/
equals(other: Group): boolean;
/**
* Get the group identity element under the group operation (i.e. the point at infinity.)
*/
static zero(): Group;
/**
* Get the generator of the group.
*/
static generator(): Group;
}
/**
* Key pair object containing both the function proving and verifying keys
*/
export class KeyPair {
free(): void;
/**
* Create new key pair from proving and verifying keys
*
* @param {ProvingKey} proving_key Proving key corresponding to a function in an Aleo program
* @param {VerifyingKey} verifying_key Verifying key corresponding to a function in an Aleo program
* @returns {KeyPair} Key pair object containing both the function proving and verifying keys
*/
constructor(proving_key: ProvingKey, verifying_key: VerifyingKey);
/**
* Get the proving key. This method will remove the proving key from the key pair
*
* @returns {ProvingKey}
*/
provingKey(): ProvingKey;
/**
* Get the verifying key. This method will remove the verifying key from the key pair
*
* @returns {VerifyingKey}
*/
verifyingKey(): VerifyingKey;
}
export class Metadata {
private constructor();
free(): void;
static baseUrl(): string;
static bond_public(): Metadata;
static bond_validator(): Metadata;
static claim_unbond_public(): Metadata;
static fee_private(): Metadata;
static fee_public(): Metadata;
static inclusion(): Metadata;
static join(): Metadata;
static set_validator_state(): Metadata;
static split(): Metadata;
static transfer_private(): Metadata;
static transfer_private_to_public(): Metadata;
static transfer_public(): Metadata;
static transfer_public_as_signer(): Metadata;
static transfer_public_to_private(): Metadata;
static unbond_public(): Metadata;
name: string;
locator: string;
prover: string;
verifier: string;
verifyingKey: string;
}
/**
* An offline query object used to insert the global state root and state paths needed to create
* a valid inclusion proof offline.
*/
export class OfflineQuery {
free(): void;
/**
* Creates a new offline query object. The state root is required to be passed in as a string
*
* @param {u32} block_height The block height.
* @param {string} state_root The state root of the current network.
*
* @returns {OfflineQuery} The newly created offline query object.
*/
constructor(block_height: number, state_root: string);
/**
* Add a new block height to the offline query object.
*
* @param {u32} block_height The block height to add.
*/
addBlockHeight(block_height: number): void;
/**
* Add a new state path to the offline query object.
*
* @param {string} commitment: The commitment corresponding to a record input.
* @param {string} state_path: The state path corresponding to the commitment.
*/
addStatePath(commitment: string, state_path: string): void;
/**
* Get a json string representation of the offline query object.
*
* @returns {string} JSON string representation of the offline query object.
*/
toString(): string;
/**
* Create an offline query object from a json string representation.
*
* @param {string} JSON string representation of the offline query object.
*/
static fromString(s: string): OfflineQuery;
}
export class Pedersen128 {
free(): void;
/**
* Create a Pedersen hasher for a given (up to) 128-bit input.
*/
constructor();
/**
* Create a Pedersen hasher for a given (up to) 128-bit input with a custom domain separator.
*/
static setup(domain_separator: string): Pedersen128;
/**
* Returns the Pedersen hash for a given (up to) 128-bit input.
*/
hash(input: Array<any>): Field;
/**
* Returns a Pedersen commitment for the given (up to) 128-bit input and randomizer.
*/
commit(input: Array<any>, randomizer: Scalar): Field;
/**
* Returns a Pedersen commitment for the given (up to) 128-bit input and randomizer.
*/
commitToGroup(input: Array<any>, randomizer: Scalar): Group;
}
export class Pedersen64 {
free(): void;
/**
* Create a Pedersen hasher for a given (up to) 64-bit input.
*/
constructor();
/**
* Create a Pedersen64 hasher for a given (up to) 64-bit input with a custom domain separator.
*/
static setup(domain_separator: string): Pedersen64;
/**
* Returns the Pedersen hash for a given (up to) 64-bit input.
*/
hash(input: Array<any>): Field;
/**
* Returns a Pedersen commitment for the given (up to) 64-bit input and randomizer.
*/
commit(input: Array<any>, randomizer: Scalar): Field;
/**
* Returns a Pedersen commitment for the given (up to) 64-bit input and randomizer.
*/
commitToGroup(input: Array<any>, randomizer: Scalar): Group;
}
/**
* SnarkVM Plaintext object. Plaintext is a fundamental monadic type used to represent Aleo
* primitive types (boolean, field, group, i8, i16, i32, i64, i128, u8, u16, u32, u64, u128,
* scalar, and signature), struct types, and array types.
*
* In the context of a web or NodeJS application, this type is useful for turning an Aleo type into
* a JS value, object, or array that might be necessary for performing computations within the
* application.
*
* @example
* // Get the bond state of an existing address.
* const bondState = await fetch(https://api.explorer.provable.com/v1/mainnet/program/credits.aleo/mapping/bond_state/aleo12zlythl7htjdtjjjz3ahdj4vl6wk3zuzm37s80l86qpx8fyx95fqnxcn2f);
* // Convert the bond state to a Plaintext object.
* const bondStatePlaintext = Plaintext.fromString(bond_state);
* // Convert the Plaintext object to a JS object.
* const bondStateObject = bond_state_plaintext.toObject();
* // Check if the bond state matches the expected object.
* const expectedObject = { validator: "aleo12zlythl7htjdtjjjz3ahdj4vl6wk3zuzm37s80l86qpx8fyx95fqnxcn2f", microcredits: 100000000u64 };
* assert( JSON.stringify(bondStateObject) === JSON.stringify(expectedObject) );
*/
export class Plaintext {
private constructor();
free(): void;
/**
* Find plaintext member if the plaintext is a struct. Returns `null` if the plaintext is not
* a struct or the member does not exist.
*
* @param {string} name The name of the plaintext member to find.
*
* @returns {Plaintext} The plaintext member.
*/
find(name: string): Plaintext;
/**
* Encrypt a plaintext with an address and randomizer.
*
* @param {Address} address The address to encrypt the plaintext for.
* @param {Scalar} randomizer The randomizer to use for encryption.
*
* @returns {Ciphertext} The encrypted ciphertext.
*/
encrypt(address: Address, randomizer: Scalar): Ciphertext;
/**
* Encrypt a plaintext with a transition view key.
*
* @param {Field} transition_view_key The transition view key of the transition
* associated with the plaintext.
*
* @returns {Ciphertext} The encrypted ciphertext.
*/
encryptSymmetric(transition_view_key: Field): Ciphertext;
/**
* Creates a plaintext object from a string representation of a plaintext.
*
* @param {string} plaintext The string representation of the plaintext.
*
* @returns {Plaintext} The plaintext object.
*/
static fromString(plaintext: string): Plaintext;
/**
* Get a plaintext object from a series of bytes.
*
* @param {Uint8Array} bytes A left endian byte array representing the plaintext.
*
* @returns {Plaintext} The plaintext object.
*/
static fromBytesLe(bytes: Uint8Array): Plaintext;
/**
* Get the left endian byte array representation of the plaintext.
*
* @returns {Uint8Array} The left endian byte array representation of the plaintext.
*/
toBytesLe(): Uint8Array;
/**
* Get a plaintext object from a series of bits represented as a boolean array.
*
* @param {Array} bits A left endian boolean array representing the bits plaintext.
*
* @returns {Plaintext} The plaintext object.
*/
static fromBitsLe(bits: Array<any>): Plaintext;
/**
* Get the left endian boolean array representation of the bits of the plaintext.
*
* @returns {Array} The left endian boolean array representation of the bits of the plaintext.
*/
toBitsLe(): Array<any>;
/**
* Get a plaintext object from an array of fields.
*
* @param {Array} fields An array of fields.
*
* @returns {Plaintext} The plaintext object.
*/
static fromFields(fields: Array<any>): Plaintext;
/**
* Get the field array representation of the plaintext.
*
* @returns {Array} The field array representation of the plaintext.
*/
toFields(): Array<any>;
/**
* Returns the string representation of the plaintext.
*
* @returns {string} The string representation of the plaintext.
*/
toString(): string;
/**
* Gives the type of the plaintext.
*
* @returns {string} The type of the plaintext.
*/
plaintextType(): string;
/**
* Attempt to convert the plaintext to a JS object.
*
* @returns {Object} The JS object representation of the plaintext.
*/
toObject(): any;
hashPoseidon2(): string;
}
export class Poseidon2 {
free(): void;
/**
* Create a Poseidon hasher with an input rate of 2.
*/
constructor();
/**
* Create a Poseidon hasher with an input rate of 2 and a custom domain separator.
*/
static setup(domain_separator: string): Poseidon2;
/**
* Returns the Poseidon hash with an input rate of 2.
*/
hash(input: Array<any>): Field;
/**
* Returns the extended Poseidon hash with an input rate of 2.
*/
hashMany(input: Array<any>, num_outputs: number): Array<any>;
/**
* Returns the Poseidon hash with an input rate of 2 on the scalar field.
*/
hashToScalar(input: Array<any>): Scalar;
/**
* Returns the Poseidon hash with an input rate of 2 on the affine curve.
*/
hashToGroup(input: Array<any>): Group;
}
export class Poseidon4 {
free(): void;
/**
* Create a Poseidon hasher with an input rate of 4.
*/
constructor();
/**
* Create a Poseidon hasher with an input rate of 4 and a custom domain separator.
*/
static setup(domain_separator: string): Poseidon4;
/**
* Returns the Poseidon hash with an input rate of 4.
*/
hash(input: Array<any>): Field;
/**
* Returns the extended Poseidon hash with an input rate of 4.
*/
hashMany(input: Array<any>, num_outputs: number): Array<any>;
/**
* Returns the Poseidon hash with an input rate of 4 on the scalar field.
*/
hashToScalar(input: Array<any>): Scalar;
/**
* Returns the Poseidon hash with an input rate of 4 on the affine curve.
*/
hashToGroup(input: Array<any>): Group;
}
export class Poseidon8 {
free(): void;
/**
* Create a Poseidon hasher with an input rate of 8.
*/
constructor();
/**
* Create a Poseidon hasher with an input rate of 8 and a custom domain separator.
*/
static setup(domain_separator: string): Poseidon8;
/**
* Returns the Poseidon hash with an input rate of 8.
*/
hash(input: Array<any>): Field;
/**
* Returns the extended Poseidon hash with an input rate of 8.
*/
hashMany(input: Array<any>, num_outputs: number): Array<any>;
/**
* Returns the Poseidon hash with an input rate of 8 on the scalar field.
*/
hashToScalar(input: Array<any>): Scalar;
/**
* Returns the Poseidon hash with an input rate of 8 on the affine curve.
*/
hashToGroup(input: Array<any>): Group;
}
/**
* Private key of an Aleo account
*/
export class PrivateKey {
free(): void;
/**
* Generate a new private key using a cryptographically secure random number generator
*
* @returns {PrivateKey}
*/
constructor();
/**
* Get a private key from a series of unchecked bytes
*
* @param {Uint8Array} seed Unchecked 32 byte long Uint8Array acting as the seed for the private key
* @returns {PrivateKey}
*/
static from_seed_unchecked(seed: Uint8Array): PrivateKey;
/**
* Get a private key from a string representation of a private key
*
* @param {string} seed String representation of a private key
* @returns {PrivateKey}
*/
static from_string(private_key: string): PrivateKey;
/**
* Get a string representation of the private key. This function should be used very carefully
* as it exposes the private key plaintext
*
* @returns {string} String representation of a private key
*/
to_string(): string;
/**
* Get the view key corresponding to the private key
*
* @returns {ViewKey}
*/
to_view_key(): ViewKey;
/**
* Get the address corresponding to the private key
*
* @returns {Address}
*/
to_address(): Address;
/**
* Sign a message with the private key
*
* @param {Uint8Array} Byte array representing a message signed by the address
* @returns {Signature} Signature generated by signing the message with the address
*/
sign(message: Uint8Array): Signature;
/**
* Get a new randomly generated private key ciphertext using a secret. The secret is sensitive
* and will be needed to decrypt the private key later, so it should be stored securely
*
* @param {string} secret Secret used to encrypt the private key
* @returns {PrivateKeyCiphertext} Ciphertext representation of the private key
*/
static newEncrypted(secret: string): PrivateKeyCiphertext;
/**
* Encrypt an existing private key with a secret. The secret is sensitive and will be needed to
* decrypt the private key later, so it should be stored securely
*
* @param {string} secret Secret used to encrypt the private key
* @returns {PrivateKeyCiphertext} Ciphertext representation of the private key
*/
toCiphertext(secret: string): PrivateKeyCiphertext;
/**
* Get private key from a private key ciphertext and secret originally used to encrypt it
*
* @param {PrivateKeyCiphertext} ciphertext Ciphertext representation of the private key
* @param {string} secret Secret originally used to encrypt the private key
* @returns {PrivateKey} Private key
*/
static fromPrivateKeyCiphertext(ciphertext: PrivateKeyCiphertext, secret: string): PrivateKey;
}
/**
* Private Key in ciphertext form
*/
export class PrivateKeyCiphertext {
private constructor();
free(): void;
/**
* Encrypt a private key using a secret string. The secret is sensitive and will be needed to
* decrypt the private key later, so it should be stored securely
*
* @param {PrivateKey} private_key Private key to encrypt
* @param {string} secret Secret to encrypt the private key with
* @returns {PrivateKeyCiphertext} Private key ciphertext
*/
static encryptPrivateKey(private_key: PrivateKey, secret: string): PrivateKeyCiphertext;
/**
* Decrypts a private ciphertext using a secret string. This must be the same secret used to
* encrypt the private key
*
* @param {string} secret Secret used to encrypt the private key
* @returns {PrivateKey} Private key
*/
decryptToPrivateKey(secret: string): PrivateKey;
/**
* Returns the ciphertext string
*
* @returns {string} Ciphertext string
*/
toString(): string;
/**
* Creates a PrivateKeyCiphertext from a string
*
* @param {string} ciphertext Ciphertext string
* @returns {PrivateKeyCiphertext} Private key ciphertext
*/
static fromString(ciphertext: string): PrivateKeyCiphertext;
}
/**
* Webassembly Representation of an Aleo program
*/
export class Program {
private constructor();
free(): void;
/**
* Create a program from a program string
*
* @param {string} program Aleo program source code
* @returns {Program} Program object
*/
static fromString(program: string): Program;
/**
* Get a string representation of the program
*
* @returns {string} String containing the program source code
*/
toString(): string;
/**
* Determine if a function is present in the program
*
* @param {string} functionName Name of the function to check for
* @returns {boolean} True if the program is valid, false otherwise
*/
hasFunction(function_name: string): boolean;
/**
* Get javascript array of functions names in the program
*
* @returns {Array} Array of all function names present in the program
*
* @example
* const expected_functions = [
* "mint",
* "transfer_private",
* "transfer_private_to_public",
* "transfer_public",
* "transfer_public_to_private",
* "join",
* "split",
* "fee"
* ]
*
* const credits_program = aleo_wasm.Program.getCreditsProgram();
* const credits_functions = credits_program.getFunctions();
* console.log(credits_functions === expected_functions); // Output should be "true"
*/
getFunctions(): Array<any>;
/**
* Get a javascript object representation of the function inputs and types. This can be used
* to generate a web form to capture user inputs for an execution of a function.
*
* @param {string} function_name Name of the function to get inputs for
* @returns {Array} Array of function inputs
*
* @example
* const expected_inputs = [
* {
* type:"record",
* visibility:"private",
* record:"credits",
* members:[
* {
* name:"microcredits",
* type:"u64",
* visibility:"private"
* }
* ],
* register:"r0"
* },
* {
* type:"address",
* visibility:"private",
* register:"r1"
* },
* {
* type:"u64",
* visibility:"private",
* register:"r2"
* }
* ];
*
* const credits_program = aleo_wasm.Program.getCreditsProgram();
* const transfer_function_inputs = credits_program.getFunctionInputs("transfer_private");
* console.log(transfer_function_inputs === expected_inputs); // Output should be "true"
*/
getFunctionInputs(function_name: string): Array<any>;
/**
* Get a the list of a program's mappings and the names/types of their keys and values.
*
* @returns {Array} - An array of objects representing the mappings in the program
* @example
* const expected_mappings = [
* {
* name: "account",
* key_name: "owner",
* key_type: "address",
* value_name: "microcredits",
* value_type: "u64"
* }
* ]
*
* const credits_program = aleo_wasm.Program.getCreditsProgram();
* const credits_mappings = credits_program.getMappings();
* console.log(credits_mappings === expected_mappings); // Output should be "true"
*/
getMappings(): Array<any>;
/**
* Get a javascript object representation of a program record and its types
*
* @param {string} record_name Name of the record to get members for
* @returns {Object} Object containing the record name, type, and members
*
* @example
*
* const expected_record = {
* type: "record",
* record: "Credits",
* members: [
* {
* name: "owner",
* type: "address",
* visibility: "private"
* },
* {
* name: "microcredits",
* type: "u64",
* visibility: "private"
* }
* ];
* };
*
* const credits_program = aleo_wasm.Program.getCreditsProgram();
* const credits_record = credits_program.getRecordMembers("Credits");
* console.log(credits_record === expected_record); // Output should be "true"
*/
getRecordMembers(record_name: string): object;
/**
* Get a javascript object representation of a program struct and its types
*
* @param {string} struct_name Name of the struct to get members for
* @returns {Array} Array containing the struct members
*
* @example
*
* const STRUCT_PROGRAM = "program token_issue.aleo;
*
* struct token_metadata:
* network as u32;
* version as u32;
*
* struct token:
* token_id as u32;
* metadata as token_metadata;
*
* function no_op:
* input r0 as u64;
* output r0 as u64;"
*
* const expected_struct_members = [
* {
* name: "token_id",
* type: "u32",
* },
* {
* name: "metadata",
* type: "struct",
* struct_id: "token_metadata",
* members: [
* {
* name: "network",
* type: "u32",
* }
* {
* name: "version",
* type: "u32",
* }
* ]
* }
* ];
*
* const program = aleo_wasm.Program.fromString(STRUCT_PROGRAM);
* const struct_members = program.getStructMembers("token");
* console.log(struct_members === expected_struct_members); // Output should be "true"
*/
getStructMembers(struct_name: string): Array<any>;
/**
* Get the credits.aleo program
*
* @returns {Program} The credits.aleo program
*/
static getCreditsProgram(): Program;
/**
* Get the id of the program
*
* @returns {string} The id of the program
*/
id(): string;
/**
* Get a unique address of the program
*
* @returns {Address} The address of the program
*/
address(): Address;
/**
* Determine equality with another program
*
* @param {Program} other The other program to compare
* @returns {boolean} True if the programs are equal, false otherwise
*/
isEqual(other: Program): boolean;
/**
* Get program_imports
*
* @returns {Array} The program imports
*
* @example
*
* const DOUBLE_TEST = "import multiply_test.aleo;
*
* program double_test.aleo;
*
* function double_it:
* input r0 as u32.private;
* call multiply_test.aleo/multiply 2u32 r0 into r1;
* output r1 as u32.private;";
*
* const expected_imports = [
* "multiply_test.aleo"
* ];
*
* const program = aleo_wasm.Program.fromString(DOUBLE_TEST_PROGRAM);
* const imports = program.getImports();
* console.log(imports === expected_imports); // Output should be "true"
*/
getImports(): Array<any>;
}
export class ProgramManager {
private constructor();
free(): void;
/**
* Create an execution `Authorization` for a given program:function tuple with specified i