UNPKG

@provablehq/wasm

Version:

SnarkVM WASM binaries with javascript bindings

1,449 lines 87.1 kB
/* 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, imported_verifying_keys?: object | null): 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; } 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; } /** * SnarkVM Ciphertext object. A Ciphertext represents an symmetrically encrypted plaintext. This * object provides decryption methods to recover the plaintext from the ciphertext (given the * api consumer has the proper decryption materials). * * @example */ 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. */ 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. */ 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; } /** * 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>; } /** * 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 */ constructor(block_height: number, state_root: string); /** * Add a new block height to the offline query object. */ addBlockHeight(block_height: number): void; /** * Add a new state path to the offline query object. * * @param {string} commitment: The commitment corresponding to a record inpout * @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 */ toString(): string; /** * Create an offline query object from a json string representation */ 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. */ encrypt(address: Address, randomizer: Scalar): Ciphertext; /** * Encrypt a plaintext with a transition view key. */ 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. */ 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. */ 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. */ 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; } 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; /** * Deploy an Aleo program * * @param private_key The private key of the sender * @param program The source code of the program being deployed * @param imports A javascript object holding the source code of any imported programs in the * form \{"program_name1": "program_source_code", "program_name2": "program_source_code", ..\}. * Note that all imported programs must be deployed on chain before the main program in order * for the deployment to succeed * @param priority_fee_credits The optional priority fee to be paid for the transaction * @param fee_record The record to spend the fee from * @param url The url of the Aleo network node to send the transaction to * @param imports (optional) Provide a list of imports to use for the program deployment in the * form of a javascript object where the keys are a string of the program name and the values * are a string representing the program source code \{ "hello.aleo": "hello.aleo source code" \} * @param fee_proving_key (optional) Provide a proving key to use for the fee execution * @param fee_verifying_key (optional) Provide a verifying key to use for the fee execution * @returns {Transaction} */ static buildDeploymentTransaction(private_key: PrivateKey, program: string, priority_fee_credits: number, fee_record?: RecordPlaintext | null, url?: string | null, imports?: object | null, fee_proving_key?: ProvingKey | null, fee_verifying_key?: VerifyingKey | null, offline_query?: OfflineQuery | null): Promise<Transaction>; /** * Estimate the fee for a program deployment * * Disclaimer: Fee estimation is experimental and may not represent a correct estimate on any current or future network * * @param program The source code of the program being deployed * @param imports (optional) Provide a list of imports to use for the deployment fee estimation * in the form of a javascript object where the keys are a string of the program name and the values * are a string representing the program source code \{ "hello.aleo": "hello.aleo source code" \} * @returns {u64} */ static estimateDeploymentFee(program: string, imports?: object | null): Promise<bigint>; /** * Estimate the component of the deployment cost which comes from the fee for the program name. * Note that this cost does not represent the entire cost of deployment. It is additional to * the cost of the size (in bytes) of the deployment. * * Disclaimer: Fee estimation is experimental and may not represent a correct estimate on any current or future network * * @param name The name of the program to be deployed * @returns {u64} */ static estimateProgramNameCost(name: string): bigint; /** * Execute an arbitrary function locally * * @param {PrivateKey} private_key The private key of the sender * @param {string} program The source code of the program being executed * @param {string} function The name of the function to execute * @param {Array} inputs A javascript array of inputs to the function * @param {boolean} prove_execution If true, the execution will be proven and an execution object * containing the proof and the encrypted inputs and outputs needed to verify the proof offline * will be returned. * @param {boolean} cache Cache the proving and verifying keys in the Execution response. * If this is set to 'true' the keys synthesized will be stored in the Execution Response * and the `ProvingKey` and `VerifyingKey` can be retrieved from the response via the `.getKeys()` * method. * @param {Object | undefined} imports (optional) Provide a list of imports to use for the function execution in the * form of a javascript object where the keys are a string of the program name and the values * are a string representing the program source code \{ "hello.aleo": "hello.aleo source code" \} * @param {ProvingKey | undefined} proving_key (optional) Provide a verifying key to use for the function execution * @param {VerifyingKey | undefined} verifying_key (optional) Provide a verifying key to use for the function execution */ static executeFunctionOffline(private_key: PrivateKey, program: string, _function: string, inputs: Array<any>, prove_execution: boolean, cache: boolean, imports?: object | null, proving_key?: ProvingKey | null, verifying_key?: VerifyingKey | null, url?: string | null, offline_query?: OfflineQuery | null): Promise<ExecutionResponse>; /** * Execute Aleo function and create an Aleo execution transaction * * @param private_key The private key of the sender * @param program The source code of the program being executed * @param function The name of the function to execute * @param inputs A javascript array of inputs to the function * @param priority_fee_credits The optional priority fee to be paid for the transaction * @param fee_record The record to spend the fee from * @param url The url of the Aleo network node to send the transaction to * If this is set to 'true' the keys synthesized (or passed in as optional parameters via the * `proving_key` and `verifying_key` arguments) will be stored in the ProgramManager's memory * and used for subsequent transactions. If this is set to 'false' the proving and verifying * keys will be deallocated from memory after the transaction is executed. * @param imports (optional) Provide a list of imports to use for the function execution in the * form of a javascript object where the keys are a string of the program name and the values * are a string representing the program source code \{ "hello.aleo": "hello.aleo source code" \} * @param proving_key (optional) Provide a verifying key to use for the function execution * @param verifying_key (optional) Provide a verifying key to use for the function execution * @param fee_proving_key (optional) Provide a proving key to use for the fee execution * @param fee_verifying_key (optional) Provide a verifying key to use for the fee execution * @returns {Transaction} */ static buildExecutionTransaction(private_key: PrivateKey, program: string, _function: string, inputs: Array<any>, priority_fee_credits: number, fee_record?: RecordPlaintext | null, url?: string | null, imports?: object | null, proving_key?: ProvingKey | null, verifying_key?: VerifyingKey | null, fee_proving_key?: ProvingKey | null, fee_verifying_key?: VerifyingKey | null, offline_query?: OfflineQuery | null): Promise<Transaction>; /** * Estimate Fee for Aleo function execution. Note if "cache" is set to true, the proving and * verifying keys will be stored in the ProgramManager's memory and used for subsequent * program executions. * * Disclaimer: Fee estimation is experimental and may not represent a correct estimate on any current or future network * * @param private_key The private key of the sender * @param program The source code of the program to estimate the execution fee for * @param function The name of the function to execute * @param inputs A javascript array of inputs to the function * @param url The url of the Aleo network node to send the transaction to * @param imports (optional) Provide a list of imports to use for the fee estimation in the * form of a javascript object where the keys are a string of the program name and the values * are a string representing the program source code \{ "hello.aleo": "hello.aleo source code" \} * @param proving_key (optional) Provide a verifying key to use for the fee estimation * @param verifying_key (optional) Provide a verifying key to use for the fee estimation * @returns {u64} Fee in microcredits */ static estimateExecutionFee(private_key: PrivateKey, program: string, _function: string, inputs: Array<any>, url?: string | null, imports?: object | null, proving_key?: ProvingKey | null, verifying_key?: VerifyingKey | null, offline_query?: OfflineQuery | null): Promise<bigint>; /** * Estimate the finalize fee component for executing a function. This fee is additional to the * size of the execution of the program in bytes. If the function does not have a finalize * step, then the finalize fee is 0. * * Disclaimer: Fee estimation is experimental and may not represent a correct estimate on any current or future network * * @param program The program containing the function to estimate the finalize fee for * @param function The function to estimate the finalize fee for * @returns {u64} Fee in microcredits */ static estimateFinalizeFee(program: string, _function: string): bigint; /** * Join two records together to create a new record with an amount of credits equal to the sum * of the credits of the two original records * * @param private_key The private key of the sender * @param record_1 The first record to combine * @param record_2 The second record to combine * @param priority_fee_credits The opptional priority fee to be paid for the transaction * @param fee_record The record to spend the fee from * @param url The url of the Aleo network node to send the transaction to * @param join_proving_key (optional) Provide a proving key to use for the join function * @param join_verifying_key (optional) Provide a verifying key to use for the join function * @param fee_proving_key (optional) Provide a proving key to use for the fee execution * @param fee_verifying_key (optional) Provide a verifying key to use for the fee execution * @returns {Transaction} Transaction object */ static buildJoinTransaction(private_key: PrivateKey, record_1: RecordPlaintext, record_2: RecordPlaintext, priority_fee_credits: number, fee_record?: RecordPlaintext | null, url?: string | null, join_proving_key?: ProvingKey | null, join_verifying_key?: VerifyingKey | null, fee_proving_key?: ProvingKey | null, fee_verifying_key?: VerifyingKey | null, offline_query?: OfflineQuery | null): Promise<Transaction>; /** * Split an Aleo credits record into two separate records. This function does not require a fee. * * @param private_key The private key of the sender * @param split_amount The amount of the credit split. This amount will be subtracted from the * value of the record and two new records will be created with the split amount and the remainder * @param amount_record The record to split * @param url The url of the Aleo network node to send the transaction to * @param split_proving_key (optional) Provide a proving key to use for the split function * @param split_verifying_key (optional) Provide a verifying key to use for the split function * @returns {Transaction} Transaction object */ static buildSplitTransaction(private_key: PrivateKey, split_amount: number, amount_record: RecordP