@provablehq/sdk 0.6.13 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/README.md +20 -20
  2. package/dist/{account.d.ts → mainnet/account.d.ts} +10 -10
  3. package/dist/mainnet/browser.d.ts +20 -0
  4. package/dist/mainnet/browser.js +934 -0
  5. package/dist/mainnet/browser.js.map +1 -0
  6. package/dist/mainnet/constants.d.ts +34 -0
  7. package/dist/{function-key-provider.d.ts → mainnet/function-key-provider.d.ts} +58 -57
  8. package/dist/{network-client.d.ts → mainnet/network-client.d.ts} +29 -26
  9. package/dist/{node-polyfill.d.ts → mainnet/node-polyfill.d.ts} +1 -0
  10. package/dist/{node-polyfill.js → mainnet/node-polyfill.js} +1 -0
  11. package/dist/mainnet/node-polyfill.js.map +1 -0
  12. package/dist/mainnet/node.d.ts +2 -0
  13. package/dist/mainnet/node.js +13 -0
  14. package/dist/{node.js.map → mainnet/node.js.map} +1 -1
  15. package/dist/{offline-key-provider.d.ts → mainnet/offline-key-provider.d.ts} +23 -22
  16. package/dist/mainnet/polyfill/shared.d.ts +1 -0
  17. package/dist/mainnet/program-manager-6a377210.js +2200 -0
  18. package/dist/mainnet/program-manager-6a377210.js.map +1 -0
  19. package/dist/{program-manager.d.ts → mainnet/program-manager.d.ts} +63 -59
  20. package/dist/{record-provider.d.ts → mainnet/record-provider.d.ts} +22 -22
  21. package/dist/{utils.d.ts → mainnet/utils.d.ts} +2 -0
  22. package/dist/mainnet/wasm.d.ts +1 -0
  23. package/dist/{worker.d.ts → mainnet/worker.d.ts} +2 -1
  24. package/dist/mainnet/worker.js +78 -0
  25. package/dist/mainnet/worker.js.map +1 -0
  26. package/dist/testnet/account.d.ts +137 -0
  27. package/dist/testnet/browser.d.ts +20 -0
  28. package/dist/testnet/browser.js +934 -0
  29. package/dist/testnet/browser.js.map +1 -0
  30. package/dist/testnet/constants.d.ts +34 -0
  31. package/dist/testnet/function-key-provider.d.ts +349 -0
  32. package/dist/testnet/managed-worker.d.ts +3 -0
  33. package/dist/testnet/models/block.d.ts +21 -0
  34. package/dist/testnet/models/confirmed_transaction.d.ts +6 -0
  35. package/dist/testnet/models/execution.d.ts +5 -0
  36. package/dist/testnet/models/input.d.ts +10 -0
  37. package/dist/testnet/models/output.d.ts +6 -0
  38. package/dist/testnet/models/transactionModel.d.ts +6 -0
  39. package/dist/testnet/models/transition.d.ts +13 -0
  40. package/dist/testnet/network-client.d.ts +270 -0
  41. package/dist/testnet/node-polyfill.d.ts +5 -0
  42. package/dist/testnet/node-polyfill.js +303 -0
  43. package/dist/testnet/node-polyfill.js.map +1 -0
  44. package/dist/testnet/node.d.ts +2 -0
  45. package/dist/testnet/node.js +13 -0
  46. package/dist/testnet/node.js.map +1 -0
  47. package/dist/testnet/offline-key-provider.d.ts +348 -0
  48. package/dist/testnet/polyfill/crypto.d.ts +1 -0
  49. package/dist/testnet/polyfill/fetch.d.ts +1 -0
  50. package/dist/testnet/polyfill/shared.d.ts +1 -0
  51. package/dist/testnet/polyfill/worker.d.ts +1 -0
  52. package/dist/testnet/polyfill/xmlhttprequest.d.ts +1 -0
  53. package/dist/{index.js → testnet/program-manager-97ade0e6.js} +362 -1278
  54. package/dist/testnet/program-manager-97ade0e6.js.map +1 -0
  55. package/dist/testnet/program-manager.d.ts +640 -0
  56. package/dist/testnet/record-provider.d.ts +236 -0
  57. package/dist/testnet/utils.d.ts +4 -0
  58. package/dist/testnet/wasm.d.ts +1 -0
  59. package/dist/testnet/worker.d.ts +9 -0
  60. package/dist/testnet/worker.js +78 -0
  61. package/dist/testnet/worker.js.map +1 -0
  62. package/package.json +23 -13
  63. package/dist/index.d.ts +0 -52
  64. package/dist/index.js.map +0 -1
  65. package/dist/node-polyfill.js.map +0 -1
  66. package/dist/node.d.ts +0 -2
  67. package/dist/node.js +0 -11
  68. package/dist/worker.js +0 -74
  69. package/dist/worker.js.map +0 -1
  70. /package/dist/{managed-worker.d.ts → mainnet/managed-worker.d.ts} +0 -0
  71. /package/dist/{models → mainnet/models}/block.d.ts +0 -0
  72. /package/dist/{models → mainnet/models}/confirmed_transaction.d.ts +0 -0
  73. /package/dist/{models → mainnet/models}/execution.d.ts +0 -0
  74. /package/dist/{models → mainnet/models}/input.d.ts +0 -0
  75. /package/dist/{models → mainnet/models}/output.d.ts +0 -0
  76. /package/dist/{models → mainnet/models}/transactionModel.d.ts +0 -0
  77. /package/dist/{models → mainnet/models}/transition.d.ts +0 -0
  78. /package/dist/{polyfill → mainnet/polyfill}/crypto.d.ts +0 -0
  79. /package/dist/{polyfill → mainnet/polyfill}/fetch.d.ts +0 -0
  80. /package/dist/{polyfill → mainnet/polyfill}/worker.d.ts +0 -0
  81. /package/dist/{polyfill → mainnet/polyfill}/xmlhttprequest.d.ts +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser.js","sources":["../../src/account.ts","../../src/offline-key-provider.ts","../../src/record-provider.ts","../../src/managed-worker.ts","../../src/browser.ts"],"sourcesContent":["import {\n Address,\n PrivateKey,\n Signature,\n ViewKey,\n PrivateKeyCiphertext,\n RecordCiphertext,\n} from \"./wasm\";\n\ninterface AccountParam {\n privateKey?: string;\n seed?: Uint8Array;\n}\n\n/**\n * Key Management class. Enables the creation of a new Aleo Account, importation of an existing account from\n * an existing private key or seed, and message signing and verification functionality.\n *\n * An Aleo Account is generated from a randomly generated seed (number) from which an account private key, view key,\n * and a public account address are derived. The private key lies at the root of an Aleo account. It is a highly\n * sensitive secret and should be protected as it allows for creation of Aleo Program executions and arbitrary value\n * transfers. The View Key allows for decryption of a user's activity on the blockchain. The Address is the public\n * address to which other users of Aleo can send Aleo credits and other records to. This class should only be used\n * environments where the safety of the underlying key material can be assured.\n *\n * @example\n * // Create a new account\n * const myRandomAccount = new Account();\n *\n * // Create an account from a randomly generated seed\n * const seed = new Uint8Array([94, 91, 52, 251, 240, 230, 226, 35, 117, 253, 224, 210, 175, 13, 205, 120, 155, 214, 7, 169, 66, 62, 206, 50, 188, 40, 29, 122, 40, 250, 54, 18]);\n * const mySeededAccount = new Account({seed: seed});\n *\n * // Create an account from an existing private key\n * const myExistingAccount = new Account({privateKey: 'myExistingPrivateKey'})\n *\n * // Sign a message\n * const hello_world = Uint8Array.from([104, 101, 108, 108, 111 119, 111, 114, 108, 100])\n * const signature = myRandomAccount.sign(hello_world)\n *\n * // Verify a signature\n * myRandomAccount.verify(hello_world, signature)\n */\nexport class Account {\n _privateKey: PrivateKey;\n _viewKey: ViewKey;\n _address: Address;\n\n constructor(params: AccountParam = {}) {\n try {\n this._privateKey = this.privateKeyFromParams(params);\n } catch (e) {\n console.error(\"Wrong parameter\", e);\n throw new Error(\"Wrong Parameter\");\n }\n this._viewKey = ViewKey.from_private_key(this._privateKey);\n this._address = Address.from_private_key(this._privateKey);\n }\n\n /**\n * Attempts to create an account from a private key ciphertext\n * @param {PrivateKeyCiphertext | string} ciphertext\n * @param {string} password\n * @returns {PrivateKey}\n *\n * @example\n * const ciphertext = PrivateKey.newEncrypted(\"password\");\n * const account = Account.fromCiphertext(ciphertext, \"password\");\n */\n public static fromCiphertext(ciphertext: PrivateKeyCiphertext | string, password: string) {\n try {\n ciphertext = (typeof ciphertext === \"string\") ? PrivateKeyCiphertext.fromString(ciphertext) : ciphertext;\n const _privateKey = PrivateKey.fromPrivateKeyCiphertext(ciphertext, password);\n return new Account({ privateKey: _privateKey.to_string() });\n } catch(e) {\n throw new Error(\"Wrong password or invalid ciphertext\");\n }\n }\n\n private privateKeyFromParams(params: AccountParam) {\n if (params.seed) {\n return PrivateKey.from_seed_unchecked(params.seed);\n }\n if (params.privateKey) {\n return PrivateKey.from_string(params.privateKey);\n }\n return new PrivateKey();\n }\n\n privateKey() {\n return this._privateKey;\n }\n\n viewKey() {\n return this._viewKey;\n }\n\n address() {\n return this._address;\n }\n\n toString() {\n return this.address().to_string()\n }\n\n /**\n * Encrypt the account's private key with a password\n * @param {string} ciphertext\n * @returns {PrivateKeyCiphertext}\n *\n * @example\n * const account = new Account();\n * const ciphertext = account.encryptAccount(\"password\");\n */\n encryptAccount(password: string) {\n return this._privateKey.toCiphertext(password);\n }\n\n /**\n * Decrypts a Record in ciphertext form into plaintext\n * @param {string} ciphertext\n * @returns {Record}\n *\n * @example\n * const account = new Account();\n * const record = account.decryptRecord(\"record1ciphertext\");\n */\n decryptRecord(ciphertext: string) {\n return this._viewKey.decrypt(ciphertext);\n }\n\n /**\n * Decrypts an array of Records in ciphertext form into plaintext\n * @param {string[]} ciphertexts\n * @returns {Record[]}\n *\n * @example\n * const account = new Account();\n * const record = account.decryptRecords([\"record1ciphertext\", \"record2ciphertext\"]);\n */\n decryptRecords(ciphertexts: string[]) {\n return ciphertexts.map((ciphertext) => this._viewKey.decrypt(ciphertext));\n }\n\n /**\n * Determines whether the account owns a ciphertext record\n * @param {RecordCipherText | string} ciphertext\n * @returns {boolean}\n *\n * @example\n * // Create a connection to the Aleo network and an account\n * const connection = new AleoNetworkClient(\"https://api.explorer.provable.com/v1\");\n * const account = Account.fromCiphertext(\"ciphertext\", \"password\");\n *\n * // Get a record from the network\n * const record = connection.getBlock(1234);\n * const recordCipherText = record.transactions[0].execution.transitions[0].id;\n *\n * // Check if the account owns the record\n * if account.ownsRecord(recordCipherText) {\n * // Then one can do something like:\n * // Decrypt the record and check if it's spent\n * // Store the record in a local database\n * // Etc.\n * }\n */\n ownsRecordCiphertext(ciphertext: RecordCiphertext | string) {\n if (typeof ciphertext === 'string') {\n try {\n const ciphertextObject = RecordCiphertext.fromString(ciphertext);\n return ciphertextObject.isOwner(this._viewKey);\n }\n catch (e) {\n return false;\n }\n }\n else {\n return ciphertext.isOwner(this._viewKey);\n }\n }\n\n /**\n * Signs a message with the account's private key.\n * Returns a Signature.\n *\n * @param {Uint8Array} message\n * @returns {Signature}\n *\n * @example\n * const account = new Account();\n * const message = Uint8Array.from([104, 101, 108, 108, 111 119, 111, 114, 108, 100])\n * account.sign(message);\n */\n sign(message: Uint8Array) {\n return this._privateKey.sign(message);\n }\n\n /**\n * Verifies the Signature on a message.\n *\n * @param {Uint8Array} message\n * @param {Signature} signature\n * @returns {boolean}\n *\n * @example\n * const account = new Account();\n * const message = Uint8Array.from([104, 101, 108, 108, 111 119, 111, 114, 108, 100])\n * const signature = account.sign(message);\n * account.verify(message, signature);\n */\n verify(message: Uint8Array, signature: Signature) {\n return this._address.verify(message, signature);\n }\n\n}\n","import {\n CachedKeyPair,\n FunctionKeyPair,\n FunctionKeyProvider,\n KeySearchParams,\n} from \"./function-key-provider\";\n\nimport {\n ProvingKey,\n VerifyingKey,\n} from \"./wasm\";\n\nimport {\n CREDITS_PROGRAM_KEYS,\n PRIVATE_TRANSFER,\n PRIVATE_TO_PUBLIC_TRANSFER,\n PUBLIC_TRANSFER,\n PUBLIC_TO_PRIVATE_TRANSFER,\n PUBLIC_TRANSFER_AS_SIGNER,\n} from \"./constants\";\n\n/**\n * Search parameters for the offline key provider. This class implements the KeySearchParams interface and includes\n * a convenience method for creating a new instance of this class for each function of the credits.aleo program.\n *\n * @example\n * // If storing a key for a custom program function\n * offlineSearchParams = new OfflineSearchParams(\"myprogram.aleo/myfunction\");\n *\n * // If storing a key for a credits.aleo program function\n * bondPublicKeyParams = OfflineSearchParams.bondPublicKeyParams();\n */\nclass OfflineSearchParams implements KeySearchParams {\n cacheKey: string | undefined;\n verifyCreditsKeys: boolean | undefined;\n\n /**\n * Create a new OfflineSearchParams instance.\n *\n * @param {string} cacheKey - Key used to store the local function proving & verifying keys. This should be stored\n * under the naming convention \"programName/functionName\" (i.e. \"myprogram.aleo/myfunction\")\n * @param {boolean} verifyCreditsKeys - Whether to verify the keys against the credits.aleo program,\n * defaults to false, but should be set to true if using keys from the credits.aleo program\n */\n constructor(cacheKey: string, verifyCreditsKeys = false) {\n this.cacheKey = cacheKey;\n this.verifyCreditsKeys = verifyCreditsKeys;\n }\n\n /**\n * Create a new OfflineSearchParams instance for the bond_public function of the credits.aleo program.\n */\n static bondPublicKeyParams(): OfflineSearchParams {\n return new OfflineSearchParams(CREDITS_PROGRAM_KEYS.bond_public.locator, true);\n }\n\n /**\n * Create a new OfflineSearchParams instance for the bond_validator function of the credits.aleo program.\n */\n static bondValidatorKeyParams(): OfflineSearchParams {\n return new OfflineSearchParams(CREDITS_PROGRAM_KEYS.bond_validator.locator, true);\n }\n\n /**\n * Create a new OfflineSearchParams instance for the claim_unbond_public function of the\n */\n static claimUnbondPublicKeyParams(): OfflineSearchParams {\n return new OfflineSearchParams(CREDITS_PROGRAM_KEYS.claim_unbond_public.locator, true);\n }\n\n /**\n * Create a new OfflineSearchParams instance for the fee_private function of the credits.aleo program.\n */\n static feePrivateKeyParams(): OfflineSearchParams {\n return new OfflineSearchParams(CREDITS_PROGRAM_KEYS.fee_private.locator, true);\n }\n\n /**\n * Create a new OfflineSearchParams instance for the fee_public function of the credits.aleo program.\n */\n static feePublicKeyParams(): OfflineSearchParams {\n return new OfflineSearchParams(CREDITS_PROGRAM_KEYS.fee_public.locator, true);\n }\n\n /**\n * Create a new OfflineSearchParams instance for the inclusion prover function.\n */\n static inclusionKeyParams(): OfflineSearchParams {\n return new OfflineSearchParams(CREDITS_PROGRAM_KEYS.inclusion.locator, true);\n }\n\n /**\n * Create a new OfflineSearchParams instance for the join function of the credits.aleo program.\n */\n static joinKeyParams(): OfflineSearchParams {\n return new OfflineSearchParams(CREDITS_PROGRAM_KEYS.join.locator, true);\n }\n\n /**\n * Create a new OfflineSearchParams instance for the set_validator_state function of the credits.aleo program.\n */\n static setValidatorStateKeyParams(): OfflineSearchParams {\n return new OfflineSearchParams(CREDITS_PROGRAM_KEYS.set_validator_state.locator, true);\n }\n\n /**\n * Create a new OfflineSearchParams instance for the split function of the credits.aleo program.\n */\n static splitKeyParams(): OfflineSearchParams {\n return new OfflineSearchParams(CREDITS_PROGRAM_KEYS.split.locator, true);\n }\n\n /**\n * Create a new OfflineSearchParams instance for the transfer_private function of the credits.aleo program.\n */\n static transferPrivateKeyParams(): OfflineSearchParams {\n return new OfflineSearchParams(CREDITS_PROGRAM_KEYS.transfer_private.locator, true);\n }\n\n /**\n * Create a new OfflineSearchParams instance for the transfer_private_to_public function of the credits.aleo program.\n */\n static transferPrivateToPublicKeyParams(): OfflineSearchParams {\n return new OfflineSearchParams(CREDITS_PROGRAM_KEYS.transfer_private_to_public.locator, true);\n }\n\n /**\n * Create a new OfflineSearchParams instance for the transfer_public function of the credits.aleo program.\n */\n static transferPublicKeyParams(): OfflineSearchParams {\n return new OfflineSearchParams(CREDITS_PROGRAM_KEYS.transfer_public.locator, true);\n }\n\n /**\n * Create a new OfflineSearchParams instance for the transfer_public_as_signer function of the credits.aleo program.\n */\n static transferPublicAsSignerKeyParams(): OfflineSearchParams {\n return new OfflineSearchParams(CREDITS_PROGRAM_KEYS.transfer_public_as_signer.locator, true);\n }\n\n /**\n * Create a new OfflineSearchParams instance for the transfer_public_to_private function of the credits.aleo program.\n */\n static transferPublicToPrivateKeyParams(): OfflineSearchParams {\n return new OfflineSearchParams(CREDITS_PROGRAM_KEYS.transfer_public_to_private.locator, true);\n }\n\n /**\n * Create a new OfflineSearchParams instance for the unbond_public function of the credits.aleo program.\n */\n static unbondPublicKeyParams(): OfflineSearchParams {\n return new OfflineSearchParams(CREDITS_PROGRAM_KEYS.unbond_public.locator, true);\n }\n}\n\n/**\n * A key provider meant for building transactions offline on devices such as hardware wallets. This key provider is not\n * able to contact the internet for key material and instead relies on the user to insert Aleo function proving &\n * verifying keys from local storage prior to usage.\n *\n * @example\n * // Create an offline program manager\n * const programManager = new ProgramManager();\n *\n * // Create a temporary account for the execution of the program\n * const account = new Account();\n * programManager.setAccount(account);\n *\n * // Create the proving keys from the key bytes on the offline machine\n * console.log(\"Creating proving keys from local key files\");\n * const program = \"program hello_hello.aleo; function hello: input r0 as u32.public; input r1 as u32.private; add r0 r1 into r2; output r2 as u32.private;\";\n * const myFunctionProver = await getLocalKey(\"/path/to/my/function/hello_hello.prover\");\n * const myFunctionVerifier = await getLocalKey(\"/path/to/my/function/hello_hello.verifier\");\n * const feePublicProvingKeyBytes = await getLocalKey(\"/path/to/credits.aleo/feePublic.prover\");\n *\n * myFunctionProvingKey = ProvingKey.fromBytes(myFunctionProver);\n * myFunctionVerifyingKey = VerifyingKey.fromBytes(myFunctionVerifier);\n * const feePublicProvingKey = ProvingKey.fromBytes(feePublicKeyBytes);\n *\n * // Create an offline key provider\n * console.log(\"Creating offline key provider\");\n * const offlineKeyProvider = new OfflineKeyProvider();\n *\n * // Cache the keys\n * // Cache the proving and verifying keys for the custom hello function\n * OfflineKeyProvider.cacheKeys(\"hello_hello.aleo/hello\", myFunctionProvingKey, myFunctionVerifyingKey);\n *\n * // Cache the proving key for the fee_public function (the verifying key is automatically cached)\n * OfflineKeyProvider.insertFeePublicKey(feePublicProvingKey);\n *\n * // Create an offline query using the latest state root in order to create the inclusion proof\n * const offlineQuery = new OfflineQuery(\"latestStateRoot\");\n *\n * // Insert the key provider into the program manager\n * programManager.setKeyProvider(offlineKeyProvider);\n *\n * // Create the offline search params\n * const offlineSearchParams = new OfflineSearchParams(\"hello_hello.aleo/hello\");\n *\n * // Create the offline transaction\n * const offlineExecuteTx = <Transaction>await this.buildExecutionTransaction(\"hello_hello.aleo\", \"hello\", 1, false, [\"5u32\", \"5u32\"], undefined, offlineSearchParams, undefined, undefined, undefined, undefined, offlineQuery, program);\n *\n * // Broadcast the transaction later on a machine with internet access\n * const networkClient = new AleoNetworkClient(\"https://api.explorer.provable.com/v1\");\n * const txId = await networkClient.broadcastTransaction(offlineExecuteTx);\n */\nclass OfflineKeyProvider implements FunctionKeyProvider {\n cache: Map<string, CachedKeyPair>;\n\n constructor() {\n this.cache = new Map<string, CachedKeyPair>();\n }\n\n /**\n * Get bond_public function keys from the credits.aleo program. The keys must be cached prior to calling this\n * method for it to work.\n *\n * @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the bond_public function\n */\n bondPublicKeys(): Promise<FunctionKeyPair> {\n return this.functionKeys(OfflineSearchParams.bondPublicKeyParams());\n };\n\n /**\n * Get bond_validator function keys from the credits.aleo program. The keys must be cached prior to calling this\n * method for it to work.\n *\n * @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the bond_public function\n */\n bondValidatorKeys(): Promise<FunctionKeyPair> {\n return this.functionKeys(OfflineSearchParams.bondValidatorKeyParams());\n };\n\n\n /**\n * Cache a set of keys. This will overwrite any existing keys with the same keyId. The user can check if a keyId\n * exists in the cache using the containsKeys method prior to calling this method if overwriting is not desired.\n *\n * @param {string} keyId access key for the cache\n * @param {FunctionKeyPair} keys keys to cache\n */\n cacheKeys(keyId: string, keys: FunctionKeyPair): void {\n const [provingKey, verifyingKey] = keys;\n this.cache.set(keyId, [provingKey.toBytes(), verifyingKey.toBytes()]);\n };\n\n /**\n * Get unbond_public function keys from the credits.aleo program. The keys must be cached prior to calling this\n * method for it to work.\n *\n * @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the unbond_public function\n */\n claimUnbondPublicKeys(): Promise<FunctionKeyPair> {\n return this.functionKeys(OfflineSearchParams.claimUnbondPublicKeyParams());\n };\n\n /**\n * Get arbitrary function key from the offline key provider cache.\n *\n * @param {KeySearchParams | undefined} params - Optional search parameters for the key provider\n * @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the specified program\n *\n * @example\n * /// First cache the keys from local offline resources\n * const offlineKeyProvider = new OfflineKeyProvider();\n * const myFunctionVerifyingKey = VerifyingKey.fromString(\"verifier...\");\n * const myFunctionProvingKeyBytes = await readBinaryFile('./resources/myfunction.prover');\n * const myFunctionProvingKey = ProvingKey.fromBytes(myFunctionProvingKeyBytes);\n *\n * /// Cache the keys for future use with a memorable locator\n * offlineKeyProvider.cacheKeys(\"myprogram.aleo/myfunction\", [myFunctionProvingKey, myFunctionVerifyingKey]);\n *\n * /// When they're needed, retrieve the keys from the cache\n *\n * /// First create a search parameter object with the same locator used to cache the keys\n * const keyParams = new OfflineSearchParams(\"myprogram.aleo/myfunction\");\n *\n * /// Then retrieve the keys\n * const [myFunctionProver, myFunctionVerifier] = await offlineKeyProvider.functionKeys(keyParams);\n */\n functionKeys(params?: KeySearchParams): Promise<FunctionKeyPair> {\n return new Promise((resolve, reject) => {\n if (params === undefined) {\n reject(new Error(\"No search parameters provided, cannot retrieve keys\"));\n } else {\n const keyId = params.cacheKey;\n const verifyCreditsKeys = params.verifyCreditsKeys;\n if (this.cache.has(keyId)) {\n const [provingKeyBytes, verifyingKeyBytes] = this.cache.get(keyId) as CachedKeyPair;\n const provingKey = ProvingKey.fromBytes(provingKeyBytes);\n const verifyingKey = VerifyingKey.fromBytes(verifyingKeyBytes);\n if (verifyCreditsKeys) {\n const keysMatchExpected = this.verifyCreditsKeys(keyId, provingKey, verifyingKey)\n if (!keysMatchExpected) {\n reject (new Error(`Cached keys do not match expected keys for ${keyId}`));\n }\n }\n resolve([provingKey, verifyingKey]);\n } else {\n reject(new Error(\"Keys not found in cache for \" + keyId));\n }\n }\n });\n };\n\n /**\n * Determines if the keys for a given credits function match the expected keys.\n *\n * @returns {boolean} Whether the keys match the expected keys\n */\n verifyCreditsKeys(locator: string, provingKey: ProvingKey, verifyingKey: VerifyingKey): boolean {\n switch (locator) {\n case CREDITS_PROGRAM_KEYS.bond_public.locator:\n return provingKey.isBondPublicProver() && verifyingKey.isBondPublicVerifier();\n case CREDITS_PROGRAM_KEYS.claim_unbond_public.locator:\n return provingKey.isClaimUnbondPublicProver() && verifyingKey.isClaimUnbondPublicVerifier();\n case CREDITS_PROGRAM_KEYS.fee_private.locator:\n return provingKey.isFeePrivateProver() && verifyingKey.isFeePrivateVerifier();\n case CREDITS_PROGRAM_KEYS.fee_public.locator:\n return provingKey.isFeePublicProver() && verifyingKey.isFeePublicVerifier();\n case CREDITS_PROGRAM_KEYS.inclusion.locator:\n return provingKey.isInclusionProver() && verifyingKey.isInclusionVerifier();\n case CREDITS_PROGRAM_KEYS.join.locator:\n return provingKey.isJoinProver() && verifyingKey.isJoinVerifier();\n case CREDITS_PROGRAM_KEYS.set_validator_state.locator:\n return provingKey.isSetValidatorStateProver() && verifyingKey.isSetValidatorStateVerifier();\n case CREDITS_PROGRAM_KEYS.split.locator:\n return provingKey.isSplitProver() && verifyingKey.isSplitVerifier();\n case CREDITS_PROGRAM_KEYS.transfer_private.locator:\n return provingKey.isTransferPrivateProver() && verifyingKey.isTransferPrivateVerifier();\n case CREDITS_PROGRAM_KEYS.transfer_private_to_public.locator:\n return provingKey.isTransferPrivateToPublicProver() && verifyingKey.isTransferPrivateToPublicVerifier();\n case CREDITS_PROGRAM_KEYS.transfer_public.locator:\n return provingKey.isTransferPublicProver() && verifyingKey.isTransferPublicVerifier();\n case CREDITS_PROGRAM_KEYS.transfer_public_to_private.locator:\n return provingKey.isTransferPublicToPrivateProver() && verifyingKey.isTransferPublicToPrivateVerifier();\n case CREDITS_PROGRAM_KEYS.unbond_public.locator:\n return provingKey.isUnbondPublicProver() && verifyingKey.isUnbondPublicVerifier();\n default:\n return false;\n }\n }\n\n /**\n * Get fee_private function keys from the credits.aleo program. The keys must be cached prior to calling this\n * method for it to work.\n *\n * @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the join function\n */\n feePrivateKeys(): Promise<FunctionKeyPair> {\n return this.functionKeys(OfflineSearchParams.feePrivateKeyParams());\n };\n\n /**\n * Get fee_public function keys from the credits.aleo program. The keys must be cached prior to calling this\n * method for it to work.\n *\n * @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the join function\n */\n feePublicKeys(): Promise<FunctionKeyPair> {\n return this.functionKeys(OfflineSearchParams.feePublicKeyParams());\n };\n\n /**\n * Get join function keys from the credits.aleo program. The keys must be cached prior to calling this\n * method for it to work.\n *\n * @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the join function\n */\n joinKeys(): Promise<FunctionKeyPair> {\n return this.functionKeys(OfflineSearchParams.joinKeyParams());\n };\n\n /**\n * Get split function keys from the credits.aleo program. The keys must be cached prior to calling this\n * method for it to work.\n *\n * @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the join function\n */\n splitKeys(): Promise<FunctionKeyPair> {\n return this.functionKeys(OfflineSearchParams.splitKeyParams());\n };\n\n /**\n * Get keys for a variant of the transfer function from the credits.aleo program.\n *\n *\n * @param {string} visibility Visibility of the transfer function (private, public, privateToPublic, publicToPrivate)\n * @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the specified transfer function\n *\n * @example\n * // Create a new OfflineKeyProvider\n * const offlineKeyProvider = new OfflineKeyProvider();\n *\n * // Cache the keys for future use with the official locator\n * const transferPublicProvingKeyBytes = await readBinaryFile('./resources/transfer_public.prover.a74565e');\n * const transferPublicProvingKey = ProvingKey.fromBytes(transferPublicProvingKeyBytes);\n *\n * // Cache the transfer_public keys for future use with the OfflinKeyProvider's convenience method for\n * // transfer_public (the verifying key will be cached automatically)\n * offlineKeyProvider.insertTransferPublicKeys(transferPublicProvingKey);\n *\n * /// When they're needed, retrieve the keys from the cache\n * const [transferPublicProvingKey, transferPublicVerifyingKey] = await keyProvider.transferKeys(\"public\");\n */\n transferKeys(visibility: string): Promise<FunctionKeyPair> {\n if (PRIVATE_TRANSFER.has(visibility)) {\n return this.functionKeys(OfflineSearchParams.transferPrivateKeyParams());\n } else if (PRIVATE_TO_PUBLIC_TRANSFER.has(visibility)) {\n return this.functionKeys(OfflineSearchParams.transferPrivateToPublicKeyParams());\n } else if (PUBLIC_TRANSFER.has(visibility)) {\n return this.functionKeys(OfflineSearchParams.transferPublicKeyParams());\n } else if (PUBLIC_TRANSFER_AS_SIGNER.has(visibility)) {\n return this.functionKeys(OfflineSearchParams.transferPublicAsSignerKeyParams());\n } else if (PUBLIC_TO_PRIVATE_TRANSFER.has(visibility)) {\n return this.functionKeys(OfflineSearchParams.transferPublicToPrivateKeyParams());\n } else {\n throw new Error(\"Invalid visibility type\");\n }\n };\n\n /**\n * Get unbond_public function keys from the credits.aleo program\n *\n * @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the join function\n */\n async unBondPublicKeys(): Promise<FunctionKeyPair> {\n return this.functionKeys(OfflineSearchParams.unbondPublicKeyParams());\n };\n\n /**\n * Insert the proving and verifying keys for the bond_public function into the cache. Only the proving key needs\n * to be inserted, the verifying key is automatically inserted by the SDK. This function will automatically check\n * that the keys match the expected checksum for bond_public before inserting them into the cache.\n *\n * @param provingKey\n */\n insertBondPublicKeys(provingKey: ProvingKey) {\n if (provingKey.isBondPublicProver()) {\n this.cache.set(CREDITS_PROGRAM_KEYS.bond_public.locator, [provingKey.toBytes(), VerifyingKey.bondPublicVerifier().toBytes()]);\n } else {\n throw new Error(\"Attempted to insert invalid proving keys for bond_public\");\n }\n }\n\n /**\n * Insert the proving and verifying keys for the claim_unbond_public function into the cache. Only the proving key needs\n * to be inserted, the verifying key is automatically inserted by the SDK. This function will automatically check\n * that the keys match the expected checksum for claim_unbond_public before inserting them into the cache.\n *\n * @param provingKey\n */\n insertClaimUnbondPublicKeys(provingKey: ProvingKey) {\n if (provingKey.isClaimUnbondPublicProver()) {\n this.cache.set(CREDITS_PROGRAM_KEYS.claim_unbond_public.locator, [provingKey.toBytes(), VerifyingKey.claimUnbondPublicVerifier().toBytes()]);\n } else {\n throw new Error(\"Attempted to insert invalid proving keys for claim_unbond_public\");\n }\n }\n\n /**\n * Insert the proving and verifying keys for the fee_private function into the cache. Only the proving key needs\n * to be inserted, the verifying key is automatically inserted by the SDK. This function will automatically check\n * that the keys match the expected checksum for fee_private before inserting them into the cache.\n *\n * @param provingKey\n */\n insertFeePrivateKeys(provingKey: ProvingKey) {\n if (provingKey.isFeePrivateProver()) {\n this.cache.set(CREDITS_PROGRAM_KEYS.fee_private.locator, [provingKey.toBytes(), VerifyingKey.feePrivateVerifier().toBytes()]);\n } else {\n throw new Error(\"Attempted to insert invalid proving keys for fee_private\");\n }\n }\n\n /**\n * Insert the proving and verifying keys for the fee_public function into the cache. Only the proving key needs\n * to be inserted, the verifying key is automatically inserted by the SDK. This function will automatically check\n * that the keys match the expected checksum for fee_public before inserting them into the cache.\n *\n * @param provingKey\n */\n insertFeePublicKeys(provingKey: ProvingKey) {\n if (provingKey.isFeePublicProver()) {\n this.cache.set(CREDITS_PROGRAM_KEYS.fee_public.locator, [provingKey.toBytes(), VerifyingKey.feePublicVerifier().toBytes()]);\n } else {\n throw new Error(\"Attempted to insert invalid proving keys for fee_public\");\n }\n }\n\n /**\n * Insert the proving and verifying keys for the join function into the cache. Only the proving key needs\n * to be inserted, the verifying key is automatically inserted by the SDK. This function will automatically check\n * that the keys match the expected checksum for join before inserting them into the cache.\n *\n * @param provingKey\n */\n insertJoinKeys(provingKey: ProvingKey) {\n if (provingKey.isJoinProver()) {\n this.cache.set(CREDITS_PROGRAM_KEYS.join.locator, [provingKey.toBytes(), VerifyingKey.joinVerifier().toBytes()]);\n } else {\n throw new Error(\"Attempted to insert invalid proving keys for join\");\n }\n }\n\n /**\n * Insert the proving and verifying keys for the set_validator_state function into the cache. Only the proving key needs\n * to be inserted, the verifying key is automatically inserted by the SDK. This function will automatically check\n * that the keys match the expected checksum for set_validator_state before inserting them into the cache.\n *\n * @param provingKey\n */\n insertSetValidatorStateKeys(provingKey: ProvingKey) {\n if (provingKey.isSetValidatorStateProver()) {\n this.cache.set(CREDITS_PROGRAM_KEYS.set_validator_state.locator, [provingKey.toBytes(), VerifyingKey.setValidatorStateVerifier().toBytes()]);\n } else {\n throw new Error(\"Attempted to insert invalid proving keys for set_validator_state\");\n }\n }\n\n /**\n * Insert the proving and verifying keys for the split function into the cache. Only the proving key needs\n * to be inserted, the verifying key is automatically inserted by the SDK. This function will automatically check\n * that the keys match the expected checksum for split before inserting them into the cache.\n *\n * @param provingKey\n */\n insertSplitKeys(provingKey: ProvingKey) {\n if (provingKey.isSplitProver()) {\n this.cache.set(CREDITS_PROGRAM_KEYS.split.locator, [provingKey.toBytes(), VerifyingKey.splitVerifier().toBytes()]);\n } else {\n throw new Error(\"Attempted to insert invalid proving keys for split\");\n }\n }\n\n /**\n * Insert the proving and verifying keys for the transfer_private function into the cache. Only the proving key needs\n * to be inserted, the verifying key is automatically inserted by the SDK. This function will automatically check\n * that the keys match the expected checksum for transfer_private before inserting them into the cache.\n *\n * @param provingKey\n */\n insertTransferPrivateKeys(provingKey: ProvingKey) {\n if (provingKey.isTransferPrivateProver()) {\n this.cache.set(CREDITS_PROGRAM_KEYS.transfer_private.locator, [provingKey.toBytes(), VerifyingKey.transferPrivateVerifier().toBytes()]);\n } else {\n throw new Error(\"Attempted to insert invalid proving keys for transfer_private\");\n }\n }\n\n /**\n * Insert the proving and verifying keys for the transfer_private_to_public function into the cache. Only the proving key needs\n * to be inserted, the verifying key is automatically inserted by the SDK. This function will automatically check\n * that the keys match the expected checksum for transfer_private_to_public before inserting them into the cache.\n *\n * @param provingKey\n */\n insertTransferPrivateToPublicKeys(provingKey: ProvingKey) {\n if (provingKey.isTransferPrivateToPublicProver()) {\n this.cache.set(CREDITS_PROGRAM_KEYS.transfer_private_to_public.locator, [provingKey.toBytes(), VerifyingKey.transferPrivateToPublicVerifier().toBytes()]);\n } else {\n throw new Error(\"Attempted to insert invalid proving keys for transfer_private_to_public\");\n }\n }\n\n /**\n * Insert the proving and verifying keys for the transfer_public function into the cache. Only the proving key needs\n * to be inserted, the verifying key is automatically inserted by the SDK. This function will automatically check\n * that the keys match the expected checksum for transfer_public before inserting them into the cache.\n *\n * @param provingKey\n */\n insertTransferPublicKeys(provingKey: ProvingKey) {\n if (provingKey.isTransferPublicProver()) {\n this.cache.set(CREDITS_PROGRAM_KEYS.transfer_public.locator, [provingKey.toBytes(), VerifyingKey.transferPublicVerifier().toBytes()]);\n } else {\n throw new Error(\"Attempted to insert invalid proving keys for transfer_public\");\n }\n }\n\n /**\n * Insert the proving and verifying keys for the transfer_public_to_private function into the cache. Only the proving key needs\n * to be inserted, the verifying key is automatically inserted by the SDK. This function will automatically check\n * that the keys match the expected checksum for transfer_public_to_private before inserting them into the cache.\n *\n * @param provingKey\n */\n insertTransferPublicToPrivateKeys(provingKey: ProvingKey) {\n if (provingKey.isTransferPublicToPrivateProver()) {\n this.cache.set(CREDITS_PROGRAM_KEYS.transfer_public_to_private.locator, [provingKey.toBytes(), VerifyingKey.transferPublicToPrivateVerifier().toBytes()]);\n } else {\n throw new Error(\"Attempted to insert invalid proving keys for transfer_public_to_private\");\n }\n }\n\n insertUnbondPublicKeys(provingKey: ProvingKey) {\n if (provingKey.isUnbondPublicProver()) {\n this.cache.set(CREDITS_PROGRAM_KEYS.unbond_public.locator, [provingKey.toBytes(), VerifyingKey.unbondPublicVerifier().toBytes()]);\n } else {\n throw new Error(\"Attempted to insert invalid proving keys for unbond_public\");\n }\n }\n}\n\n\nexport {OfflineKeyProvider, OfflineSearchParams}\n","import { RecordPlaintext } from \"./wasm\";\nimport { logAndThrow } from \"./utils\";\nimport { Account } from \"./account\";\nimport { AleoNetworkClient } from \"./network-client\";\n\n/**\n * Interface for record search parameters. This allows for arbitrary search parameters to be passed to record provider\n * implementations.\n */\ninterface RecordSearchParams {\n [key: string]: any; // This allows for arbitrary keys with any type values\n}\n\n/**\n * Interface for a record provider. A record provider is used to find records for use in deployment and execution\n * transactions on the Aleo Network. A default implementation is provided by the NetworkRecordProvider class. However,\n * a custom implementation can be provided (say if records are synced locally to a database from the network) by\n * implementing this interface.\n */\ninterface RecordProvider {\n account: Account\n\n /**\n * Find a credits.aleo record with a given number of microcredits from the chosen provider\n *\n * @param {number} microcredits The number of microcredits to search for\n * @param {boolean} unspent Whether or not the record is unspent\n * @param {string[]} nonces Nonces of records already found so they are not found again\n * @param {RecordSearchParams} searchParameters Additional parameters to search for\n * @returns {Promise<RecordPlaintext>} The record if found, otherwise an error\n *\n * @example\n * // A class implementing record provider can be used to find a record with a given number of microcredits\n * const record = await recordProvider.findCreditsRecord(5000, true, []);\n *\n * // When a record is found but not yet used, its nonce should be added to the nonces array so that it is not\n * // found again if a subsequent search is performed\n * const record2 = await recordProvider.findCreditsRecord(5000, true, [record.nonce()]);\n *\n * // When the program manager is initialized with the record provider it will be used to find automatically find\n * // fee records and amount records for value transfers so that they do not need to be specified manually\n * const programManager = new ProgramManager(\"https://api.explorer.provable.com/v1\", keyProvider, recordProvider);\n * programManager.transfer(1, \"aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at\", \"public\", 0.5);\n */\n findCreditsRecord(microcredits: number, unspent: boolean, nonces?: string[], searchParameters?: RecordSearchParams): Promise<RecordPlaintext>;\n\n /**\n * Find a list of credit.aleo records with a given number of microcredits from the chosen provider\n *\n * @param {number} microcreditAmounts A list of separate microcredit amounts to search for (e.g. [5000, 100000])\n * @param {boolean} unspent Whether or not the record is unspent\n * @param {string[]} nonces Nonces of records already found so that they are not found again\n * @param {RecordSearchParams} searchParameters Additional parameters to search for\n * @returns {Promise<RecordPlaintext[]>} A list of records with a value greater or equal to the amounts specified if such records exist, otherwise an error\n *\n * @example\n * // A class implementing record provider can be used to find a record with a given number of microcredits\n * const records = await recordProvider.findCreditsRecords([5000, 5000], true, []);\n *\n * // When a record is found but not yet used, it's nonce should be added to the nonces array so that it is not\n * // found again if a subsequent search is performed\n * const nonces = [];\n * records.forEach(record => { nonces.push(record.nonce()) });\n * const records2 = await recordProvider.findCreditsRecord(5000, true, nonces);\n *\n * // When the program manager is initialized with the record provider it will be used to find automatically find\n * // fee records and amount records for value transfers so that they do not need to be specified manually\n * const programManager = new ProgramManager(\"https://api.explorer.provable.com/v1\", keyProvider, recordProvider);\n * programManager.transfer(1, \"aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at\", \"public\", 0.5);\n */\n findCreditsRecords(microcreditAmounts: number[], unspent: boolean, nonces?: string[], searchParameters?: RecordSearchParams): Promise<RecordPlaintext[]>;\n\n /**\n * Find an arbitrary record\n * @param {boolean} unspent Whether or not the record is unspent\n * @param {string[]} nonces Nonces of records already found so that they are not found again\n * @param {RecordSearchParams} searchParameters Additional parameters to search for\n * @returns {Promise<RecordPlaintext>} The record if found, otherwise an error\n *\n * @example\n * // The RecordSearchParams interface can be used to create parameters for custom record searches which can then\n * // be passed to the record provider. An example of how this would be done for the credits.aleo program is shown\n * // below.\n *\n * class CustomRecordSearch implements RecordSearchParams {\n * startHeight: number;\n * endHeight: number;\n * amount: number;\n * program: string;\n * recordName: string;\n * constructor(startHeight: number, endHeight: number, credits: number, maxRecords: number, programName: string, recordName: string) {\n * this.startHeight = startHeight;\n * this.endHeight = endHeight;\n * this.amount = amount;\n * this.program = programName;\n * this.recordName = recordName;\n * }\n * }\n *\n * const params = new CustomRecordSearch(0, 100, 5000, \"credits.aleo\", \"credits\");\n *\n * const record = await recordProvider.findRecord(true, [], params);\n */\n findRecord(unspent: boolean, nonces?: string[], searchParameters?: RecordSearchParams): Promise<RecordPlaintext>;\n\n /**\n * Find multiple records from arbitrary programs\n *\n * @param {boolean} unspent Whether or not the record is unspent\n * @param {string[]} nonces Nonces of records already found so that they are not found again\n * @param {RecordSearchParams} searchParameters Additional parameters to search for\n * @returns {Promise<RecordPlaintext>} The record if found, otherwise an error\n *\n * // The RecordSearchParams interface can be used to create parameters for custom record searches which can then\n * // be passed to the record provider. An example of how this would be done for the credits.aleo program is shown\n * // below.\n *\n * class CustomRecordSearch implements RecordSearchParams {\n * startHeight: number;\n * endHeight: number;\n * amount: number;\n * maxRecords: number;\n * programName: string;\n * recordName: string;\n * constructor(startHeight: number, endHeight: number, credits: number, maxRecords: number, programName: string, recordName: string) {\n * this.startHeight = startHeight;\n * this.endHeight = endHeight;\n * this.amount = amount;\n * this.maxRecords = maxRecords;\n * this.programName = programName;\n * this.recordName = recordName;\n * }\n * }\n *\n * const params = new CustomRecordSearch(0, 100, 5000, 2, \"credits.aleo\", \"credits\");\n * const records = await recordProvider.findRecord(true, [], params);\n */\n findRecords(unspent: boolean, nonces?: string[], searchParameters?: RecordSearchParams): Promise<RecordPlaintext[]>;\n}\n\n/**\n * A record provider implementation that uses the official Aleo API to find records for usage in program execution and\n * deployment, wallet functionality, and other use cases.\n */\nclass NetworkRecordProvider implements RecordProvider {\n account: Account;\n networkClient: AleoNetworkClient;\n constructor(account: Account, networkClient: AleoNetworkClient) {\n this.account = account;\n this.networkClient = networkClient;\n }\n\n /**\n * Set the account used to search for records\n *\n * @param {Account} account The account to use for searching for records\n */\n setAccount(account: Account) {\n this.account = account;\n }\n\n /**\n * Find a list of credit records with a given number of microcredits by via the official Aleo API\n *\n * @param {number[]} microcredits The number of microcredits to search for\n * @param {boolean} unspent Whether or not the record is unspent\n * @param {string[]} nonces Nonces of records already found so that they are not found again\n * @param {RecordSearchParams} searchParameters Additional parameters to search for\n * @returns {Promise<RecordPlaintext>} The record if found, otherwise an error\n *\n * @example\n * // Create a new NetworkRecordProvider\n * const networkClient = new AleoNetworkClient(\"https://api.explorer.provable.com/v1\");\n * const keyProvider = new AleoKeyProvider();\n * const recordProvider = new NetworkRecordProvider(account, networkClient);\n *\n * // The record provider can be used to find records with a given number of microcredits\n * const record = await recordProvider.findCreditsRecord(5000, true, []);\n *\n * // When a record is found but not yet used, it's nonce should be added to the nonces parameter so that it is not\n * // found again if a subsequent search is performed\n * const records = await recordProvider.findCreditsRecords(5000, true, [record.nonce()]);\n *\n * // When the program manager is initialized with the record provider it will be used to find automatically find\n * // fee records and amount records for value transfers so that they do not need to be specified manually\n * const programManager = new ProgramManager(\"https://api.explorer.provable.com/v1\", keyProvider, recordProvider);\n * programManager.transfer(1, \"aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at\", \"public\", 0.5);\n *\n * */\n async findCreditsRecords(microcredits: number[], unspent: boolean, nonces?: string[], searchParameters?: RecordSearchParams): Promise<RecordPlaintext[]> {\n let startHeight = 0;\n let endHeight = 0;\n\n if (searchParameters) {\n if (\"startHeight\" in searchParameters && typeof searchParameters[\"endHeight\"] == \"number\") {\n startHeight = searchParameters[\"startHeight\"];\n }\n\n if (\"endHeight\" in searchParameters && typeof searchParameters[\"endHeight\"] == \"number\") {\n endHeight = searchParameters[\"endHeight\"];\n }\n }\n\n // If the end height is not specified, use the current block height\n if (endHeight == 0) {\n const end = await this.networkClient.getLatestHeight();\n endHeight = end;\n }\n\n // If the start height is greater than the end height, throw an error\n if (startHeight >= endHeight) {\n logAndThrow(\"Start height must be less than end height\");\n }\n\n return await this.networkClient.findUnspentRecords(startHeight, endHeight, this.account.privateKey(), microcredits, undefined, nonces);\n }\n\n /**\n * Find a credit record with a given number of microcredits by via the official Aleo API\n *\n * @param {number} microcredits The number of microcredits to search for\n * @param {boolean} unspent Whether or not the record is unspent\n * @param {string[]} nonces Nonces of records already found so that they are not found again\n * @param {RecordSearchParams} searchParameters Additional parameters to search for\n * @returns {Promise<RecordPlaintext>} The record if found, otherwise an error\n *\n * @example\n * // Create a new NetworkRecordProvider\n * const networkClient = new AleoNetworkClient(\"https://api.explorer.provable.com/v1\");\n * const keyProvider = new AleoKeyProvider();\n * const recordProvider = new NetworkRecordProvider(account, networkClient);\n *\n * // The record provider can be used to find records with a given number of microcredits\n * const record = await recordProvider.findCreditsRecord(5000, true, []);\n *\n * // When a record is found but not yet used, it's nonce should be added to the nonces parameter so that it is not\n * // found again if a subsequent search is performed\n * const records = await recordProvider.findCreditsRecords(5000, true, [record.nonce()]);\n *\n * // When the program manager is initialized with the record provider it will be used to find automatically find\n * // fee records and amount records for value transfers so that they do not need to be specified manually\n * const programManager = new ProgramManager(\"https://api.explorer.provable.com/v1\", keyProvider, recordProvider);\n * programManager.transfer(1, \"aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at\", \"public\", 0.5);\n */\n async findCreditsRecord(microcredits: number, unspent: boolean, nonces?: string[], searchParameters?: RecordSearchParams): Promise<RecordPlaintext> {\n let records = null;\n\n try {\n records = await this.findCreditsRecords([microcredits], unspent, nonces, searchParameters);\n } catch (e) {}\n\n if (records && records.length > 0) {\n return records[0];\n }\n\n console.error(\"Record not found with error:\", records);\n throw new Error(\"Record not found\");\n }\n\n /**\n * Find an arbitrary record. WARNING: This function is not implemented yet and will throw an error.\n */\n async findRecord(unspent: boolean, nonces?: string[], searchParameters?: RecordSearchParams): Promise<RecordPlaintext> {\n throw new Error(\"Method not implemented.\");\n }\n\n /**\n * Find multiple arbitrary records. WARNING: This function is not implemented yet and will throw an error.\n */\n async findRecords(unspent: boolean, nonces?: string[], searchParameters?: RecordSearchParams): Promise<RecordPlaintext[]> {\n throw new Error(\"Method not implemented.\");\n }\n\n}\n\n/**\n * BlockHeightSearch is a RecordSearchParams implementation that allows for searching for records within a given\n * block height range.\n *\n * @example\n * // Create a new BlockHeightSearch\n * const params = new BlockHeightSearch(89995, 99995);\n *\n * // Create a new NetworkRecordProvider\n * const networkClient = new AleoNetworkClient(\"https://api.explorer.provable.com/v1\");\n * const keyProvider = new AleoKeyProvider();\n * const recordProvider = new NetworkRecordProvider(account, networkClient);\n *\n * // The record provider can be used to find records with a given number of microcredits and the block height search\n * // can be used to find records within a given block height range\n * const record = await recordProvider.findCreditsRecord(5000, true, [], params);\n *\n */\nclass BlockHeightSearch implements RecordSearchParams {\n startHeight: number;\n endHeight: number;\n constructor(startHeight: number, endHeight: number) {\n this.startHeight = startHeight;\n this.endHeight = endHeight;\n }\n}\n\nexport { BlockHeightSearch, NetworkRecordProvider, RecordProvider, RecordSearchParams};\n","// Experimental example where SDK manages worker\n\nimport { wrap } from \"comlink\";\nimport { WorkerAPI } from './worker';\n\nlet singletonWorker: WorkerAPI | null = null;\n\nconst createAleoWorker = (): WorkerAPI => {\n if (!singletonWorker) {\n const worker = new Worker(new URL(\"worker.js\", import.meta.url), {\n type: \"module\",\n });\n singletonWorker = wrap<WorkerAPI>(worker);\n }\n return singletonWorker;\n};\n\nexport { createAleoWorker };","import \"./polyfill/shared\";\n\nimport { Account } from \"./account\";\nimport { AleoNetworkClient, ProgramImports } from \"./network-client\";\nimport { Block } from \"./models/block\";\nimport { Execution } from \"./models/execution\";\nimport { Input } from \"./models/input\";\nimport { Output } from \"./models/output\";\nimport { TransactionModel } from \"./models/transactionModel\";\nimport { Transition } from \"./models/transition\";\nimport {\n AleoKeyProvider,\n AleoKeyProviderParams,\n AleoKeyProviderInitParams,\n CachedKeyPair,\n FunctionKeyPair,\n FunctionKeyProvider,\n KeySearchParams,\n} from \"./function-key-provider\";\nimport {\n OfflineKeyProvider,\n OfflineSearchParams\n} from \"./offline-key-provider\";\nimport {\n BlockHeightSearch,\n NetworkRecordProvider,\n RecordProvider,\n RecordSearchParams,\n} from \"./record-provider\";\n\n// @TODO: This function is no longer needed, remove it.\nasync function initializeWasm() {\n console.warn(\"initializeWasm is deprecated, you no longer need to use it\");\n}\n\nexport { createAleoWorker } from \"./managed-worker\";\n\nexport { ProgramManager } from \"./program-manager\";\n\nexport { logAndThrow } from \"./utils\";\n\nexport {\n Address,\n Execution as FunctionExecution,\n ExecutionResponse,\n Field,\n OfflineQuery,\n PrivateKey,\n PrivateKeyCiphertext,\n Program,\n ProgramManager as ProgramManagerBase,\n ProvingKey,\n RecordCiphertext,\n RecordPlaintext,\n Signature,\n Transaction,\n VerifyingKey,\n ViewKey,\n initThreadPool,\n verifyFunctionExecution,\n} from \"./wasm\";\n\nexport { initializeWasm };\n\nexport {\n Key,\n CREDITS_PROGRAM_KEYS,\n KEY_STORE,\n PRIVATE_TRANSFER,\n PRIVATE_TO_PUBLIC_TRANSFER,\n PRIVATE_TRANSFER_TYPES,\n PUBLIC_TRANSFER,\n PUBLIC_TRANSFER_AS_SIGNER,\n PUBLIC_TO_PRIVATE_TRANSFER,\n VALID_TRANSFER_TYPES,\n} from \"./constants\";\n\nexport {\n Account,\n AleoKeyProvider,\n AleoKeyProviderParams,\n AleoKeyProviderInitParams,\n AleoNetworkClient,\n Block,\n BlockHeightSearch,\n CachedKeyPair,\n Execution,\n FunctionKeyPair,\n FunctionKeyProvider,\n Input,\n KeySearchParams,\n NetworkRecordProvider,\n ProgramImports,\n OfflineKeyProvider,\n OfflineSearchParams,\n Output,\n RecordProvider,\n RecordSearchParams,\n TransactionModel,\n Transition,\n};\n"],"names":[],"mappings":";;;;;;;AAcA;;;;;;;;;;;;;;;;;;;;;;;;;;;;A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AA,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;AAC/B,QAAA,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;KAC9B;AACJ;;AC5SD;AAKA,IAAI,eAAe,GAAqB,IAAI,CAAC;AAEvC,MAAA,gBAAgB,GAAG,MAAgB;IACrC,IAAI,CAAC,eAAe,EAAE;AAClB,QAAA,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,GAAG,CAAC,WAAW,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;AAC7D,YAAA,IAAI,EAAE,QAAQ;AACjB,SAAA,CAAC,CAAC;AACH,QAAA,eAAe,GAAG,IAAI,CAAY,MAAM,CAAC,CAAC;KAC7C;AACD,IAAA,OAAO,eAAe,CAAC;AAC3B;;ACeA;AACA,eAAe,cAAc,GAAA;AACzB,IAAA,OAAO,CAAC,IAAI,CAAC,4DAA4D,CAAC,CAAC;AAC/E;;;;"}
@@ -0,0 +1,34 @@
1
+ import { VerifyingKey } from "./wasm";
2
+ export declare const KEY_STORE: any;
3
+ export interface Key {
4
+ name: string;
5
+ locator: string;
6
+ prover: string;
7
+ verifier: string;
8
+ verifyingKey: () => VerifyingKey;
9
+ }
10
+ export declare const CREDITS_PROGRAM_KEYS: {
11
+ bond_public: Key;
12
+ bond_validator: Key;
13
+ claim_unbond_public: Key;
14
+ fee_private: Key;
15
+ fee_public: Key;
16
+ inclusion: Key;
17
+ join: Key;
18
+ set_validator_state: Key;
19
+ split: Key;
20
+ transfer_private: Key;
21
+ transfer_private_to_public: Key;
22
+ transfer_public: Key;
23
+ transfer_public_as_signer: Key;
24
+ transfer_public_to_private: Key;
25
+ unbond_public: Key;
26
+ getKey: (key: string) => Key;
27
+ };
28
+ export declare const PRIVATE_TRANSFER_TYPES: Set<string>;
29
+ export declare const VALID_TRANSFER_TYPES: Set<string>;
30
+ export declare const PRIVATE_TRANSFER: Set<string>;
31
+ export declare const PRIVATE_TO_PUBLIC_TRANSFER: Set<string>;
32
+ export declare const PUBLIC_TRANSFER: Set<string>;
33
+ export declare const PUBLIC_TRANSFER_AS_SIGNER: Set<string>;
34
+ export declare const PUBLIC_TO_PRIVATE_TRANSFER: Set<string>;
@@ -0,0 +1,349 @@
1
+ import { Key } from "./constants";
2
+ import { ProvingKey, VerifyingKey } from "./wasm";
3
+ type FunctionKeyPair = [ProvingKey, VerifyingKey];
4
+ type CachedKeyPair = [Uint8Array, Uint8Array];
5
+ type AleoKeyProviderInitParams = {
6
+ proverUri?: string;
7
+ verifierUri?: string;
8
+ cacheKey?: string;
9
+ };
10
+ /**
11
+ * Interface for record search parameters. This allows for arbitrary search parameters to be passed to record provider
12
+ * implementations.
13
+ */
14
+ interface KeySearchParams {
15
+ [key: string]: any;
16
+ }
17
+ /**
18
+ * AleoKeyProviderParams search parameter for the AleoKeyProvider. It allows for the specification of a proverUri and
19
+ * verifierUri to fetch keys via HTTP from a remote resource as well as a unique cacheKey to store the keys in memory.
20
+ */
21
+ declare class AleoKeyProviderParams implements KeySearchParams {
22
+ name: string | undefined;
23
+ proverUri: string | undefined;
24
+ verifierUri: string | undefined;
25
+ cacheKey: string | undefined;
26
+ /**
27
+ * Create a new AleoKeyProviderParams object which implements the KeySearchParams interface. Users can optionally
28
+ * specify a url for the proverUri & verifierUri to fetch keys via HTTP from a remote resource as well as a unique
29
+ * cacheKey to store the keys in memory for future use. If no proverUri or verifierUri is specified, a cachekey must
30
+ * be provided.
31
+ *
32
+ * @param { AleoKeyProviderInitParams } params - Optional search parameters
33
+ */
34
+ constructor(params: {
35
+ proverUri?: string;
36
+ verifierUri?: string;
37
+ cacheKey?: string;
38
+ name?: string;
39
+ });
40
+ }
41
+ /**
42
+ * KeyProvider interface. Enables the retrieval of public proving and verifying keys for Aleo Programs.
43
+ */
44
+ interface FunctionKeyProvider {
45
+ /**
46
+ * Get bond_public function keys from the credits.aleo program
47
+ *
48
+ * @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the bond_public function
49
+ */
50
+ bondPublicKeys(): Promise<FunctionKeyPair>;
51
+ /**
52
+ * Get bond_validator function keys from the credits.aleo program
53
+ *
54
+ * @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the bond_validator function
55
+ */
56
+ bondValidatorKeys(): Promise<FunctionKeyPair>;
57
+ /**
58
+ * Cache a set of keys. This will overwrite any existing keys with the same keyId. The user can check if a keyId
59
+ * exists in the cache using the containsKeys method prior to calling this method if overwriting is not desired.
60
+ *
61
+ * @param {string} keyId access key for the cache
62
+ * @param {FunctionKeyPair} keys keys to cache
63
+ */
64
+ cacheKeys(keyId: string, keys: FunctionKeyPair): void;
65
+ /**
66
+ * Get unbond_public function keys from the credits.aleo program
67
+ *
68
+ * @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the unbond_public function
69
+ */
70
+ claimUnbondPublicKeys(): Promise<FunctionKeyPair>;
71
+ /**
72
+ * Get arbitrary function keys from a provider
73
+ *
74
+ * @param {KeySearchParams | undefined} params - Optional search parameters for the key provider
75
+ * @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the specified program
76
+ *
77
+ * @example
78
+ * // Create a search object which implements the KeySearchParams interface
79
+ * class IndexDbSearch implements KeySearchParams {
80
+ * db: string
81
+ * keyId: string
82
+ * constructor(params: {db: string, keyId: string}) {
83
+ * this.db = params.db;
84
+ * this.keyId = params.keyId;
85
+ * }
86
+ * }
87
+ *
88
+ * // Create a new object which implements the KeyProvider interface
89
+ * class IndexDbKeyProvider implements FunctionKeyProvider {
90
+ * async functionKeys(params: KeySearchParams): Promise<FunctionKeyPair> {
91
+ * return new Promise((resolve, reject) => {
92
+ * const request = indexedDB.open(params.db, 1);
93
+ *
94
+ * request.onupgradeneeded = function(e) {
95
+ * const db = e.target.result;
96
+ * if (!db.objectStoreNames.contains('keys')) {
97
+ * db.createObjectStore('keys', { keyPath: 'id' });
98
+ * }
99
+ * };
100
+ *
101
+ * request.onsuccess = function(e) {
102
+ * const db = e.target.result;
103
+ * const transaction = db.transaction(["keys"], "readonly");
104
+ * const store = transaction.objectStore("keys");
105
+ * const request = store.get(params.keyId);
106
+ * request.onsuccess = function(e) {
107
+ * if (request.result) {
108
+ * resolve(request.result as FunctionKeyPair);
109
+ * } else {
110
+ * reject(new Error("Key not found"));
111
+ * }
112
+ * };
113
+ * request.onerror = function(e) { reject(new Error("Error fetching key")); };
114
+ * };
115
+ *
116
+ * request.onerror = function(e) { reject(new Error("Error opening database")); };
117
+ * });
118
+ * }
119
+ *
120
+ * // implement the other methods...
121
+ * }
122
+ *
123
+ *
124
+ * const keyProvider = new AleoKeyProvider();
125
+ * const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1");
126
+ * const recordProvider = new NetworkRecordProvider(account, networkClient);
127
+ *
128
+ * // Initialize a program manager with the key provider to automatically fetch keys for value transfers
129
+ * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider);
130
+ * programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
131
+ *
132
+ * // Keys can also be fetched manually
133
+ * const searchParams = new IndexDbSearch({db: "keys", keyId: "credits.aleo:transferPrivate"});
134
+ * const [transferPrivateProvingKey, transferPrivateVerifyingKey] = await keyProvider.functionKeys(searchParams);
135
+ */
136
+ functionKeys(params?: KeySearchParams): Promise<FunctionKeyPair>;
137
+ /**
138
+ * Get fee_private function keys from the credits.aleo program
139
+ *
140
+ * @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the join function
141
+ */
142
+ feePrivateKeys(): Promise<FunctionKeyPair>;
143
+ /**
144
+ * Get fee_public function keys from the credits.aleo program
145
+ *
146
+ * @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the join function
147
+ */
148
+ feePublicKeys(): Promise<FunctionKeyPair>;
149
+ /**
150
+ * Get join function keys from the credits.aleo program
151
+ *
152
+ * @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the join function
153
+ */
154
+ joinKeys(): Promise<FunctionKeyPair>;
155
+ /**
156
+ * Get split function keys from the credits.aleo program
157
+ *
158
+ * @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the join function
159
+ */
160
+ splitKeys(): Promise<FunctionKeyPair>;
161
+ /**
162
+ * Get keys for a variant of the transfer function from the credits.aleo program
163
+ *
164
+ * @param {string} visibility Visibility of the transfer function (private, public, privateToPublic, publicToPrivate)
165
+ * @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the specified transfer function
166
+ *
167
+ * @example
168
+ * // Create a new object which implements the KeyProvider interface
169
+ * const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1");
170
+ * const keyProvider = new AleoKeyProvider();
171
+ * const recordProvider = new NetworkRecordProvider(account, networkClient);
172
+ *
173
+ * // Initialize a program manager with the key provider to automatically fetch keys for value transfers
174
+ * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider);
175
+ * programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
176
+ *
177
+ * // Keys can also be fetched manually
178
+ * const [transferPublicProvingKey, transferPublicVerifyingKey] = await keyProvider.transferKeys("public");
179
+ */
180
+ transferKeys(visibility: string): Promise<FunctionKeyPair>;
181
+ /**
182
+ * Get unbond_public function keys from the credits.aleo program
183
+ *
184
+ * @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the join function
185
+ */
186
+ unBondPublicKeys(): Promise<FunctionKeyPair>;
187
+ }
188
+ /**
189
+ * AleoKeyProvider class. Implements the KeyProvider interface. Enables the retrieval of Aleo program proving and
190
+ * verifying keys for the credits.aleo program over http from official Aleo sources and storing and retrieving function
191
+ * keys from a local memory cache.
192
+ */
193
+ declare class AleoKeyProvider implements FunctionKeyProvider {
194
+ cache: Map<string, CachedKeyPair>;
195
+ cacheOption: boolean;
196
+ keyUris: string;
197
+ fetchBytes(url?: string): Promise<Uint8Array>;
198
+ constructor();
199
+ /**
200
+ * Use local memory to store keys
201
+ *
202
+ * @param {boolean} useCache whether to store keys in local memory
203
+ */
204
+ useCache(useCache: boolean): void;
205
+ /**
206
+ * Clear the key cache
207
+ */
208
+ clearCache(): void;
209
+ /**
210
+ * Cache a set of keys. This will overwrite any existing keys with the same keyId. The user can check if a keyId
211
+ * exists in the cache using the containsKeys method prior to calling this method if overwriting is not desired.
212
+ *
213
+ * @param {string} keyId access key for the cache
214
+ * @param {FunctionKeyPair} keys keys to cache
215
+ */
216
+ cacheKeys(keyId: string, keys: FunctionKeyPair): void;
217
+ /**
218
+ * Determine if a keyId exists in the cache
219
+ *
220
+ * @param {string} keyId keyId of a proving and verifying key pair
221
+ * @returns {boolean} true if the keyId exists in the cache, false otherwise
222
+ */
223
+ containsKeys(keyId: string): boolean;
224
+ /**
225
+ * Delete a set of keys from the cache
226
+ *
227
+ * @param {string} keyId keyId of a proving and verifying key pair to delete from memory
228
+ * @returns {boolean} true if the keyId exists in the cache and was deleted, false if the key did not exist
229
+ */
230
+ deleteKeys(keyId: string): boolean;
231
+ /**
232
+ * Get a set of keys from the cache
233
+ * @param keyId keyId of a proving and verifying key pair
234
+ *
235
+ * @returns {FunctionKeyPair} Proving and verifying keys for the specified program
236
+ */
237
+ getKeys(keyId: string): FunctionKeyPair;
238
+ /**
239
+ * Get arbitrary function keys from a provider
240
+ *
241
+ * @param {KeySearchParams} params parameters for the key search in form of: {proverUri: string, verifierUri: string, cacheKey: string}
242
+ * @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the specified program
243
+ *
244
+ * @example
245
+ * // Create a new object which implements the KeyProvider interface
246
+ * const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1");
247
+ * const keyProvider = new AleoKeyProvider();
248
+ * const recordProvider = new NetworkRecordProvider(account, networkClient);
249
+ *
250
+ * // Initialize a program manager with the key provider to automatically fetch keys for value transfers
251
+ * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider);
252
+ * programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
253
+ *
254
+ * // Keys can also be fetched manually using the key provider
255
+ * const keySearchParams = { "cacheKey": "myProgram:myFunction" };
256
+ * const [transferPrivateProvingKey, transferPrivateVerifyingKey] = await keyProvider.functionKeys(keySearchParams);
257
+ */
258
+ functionKeys(params?: KeySearchParams): Promise<FunctionKeyPair>;
259
+ /**
260
+ * Returns the proving and verifying keys for a specified program from a specified url.
261
+ *
262
+ * @param {string} verifierUrl Url of the proving key
263
+ * @param {string} proverUrl Url the verifying key
264
+ * @param {string} cacheKey Key to store the keys in the cache
265
+ *
266
+ * @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the specified program
267
+ *
268
+ * @example
269
+ * // Create a new AleoKeyProvider object
270
+ * const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1");
271
+ * const keyProvider = new AleoKeyProvider();
272
+ * const recordProvider = new NetworkRecordProvider(account, networkClient);
273
+ *
274
+ * // Initialize a program manager with the key provider to automatically fetch keys for value transfers
275
+ * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider);
276
+ * programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
277
+ *
278
+ * // Keys can also be fetched manually
279
+ * const [transferPrivateProvingKey, transferPrivateVerifyingKey] = await keyProvider.fetchKeys(
280
+ * CREDITS_PROGRAM_KEYS.transfer_private.prover,
281
+ * CREDITS_PROGRAM_KEYS.transfer_private.verifier,
282
+ * );
283
+ */
284
+ fetchRemoteKeys(proverUrl: string, verifierUrl: string, cacheKey?: string): Promise<FunctionKeyPair>;
285
+ /***
286
+ * Fetches the proving key from a remote source.
287
+ *
288
+ * @param proverUrl
289
+ * @param cacheKey
290
+ *
291
+ * @returns {Promise<ProvingKey>} Proving key for the specified program
292
+ */
293
+ fetchProvingKey(proverUrl: string, cacheKey?: string): Promise<ProvingKey>;
294
+ fetchCreditsKeys(key: Key): Promise<FunctionKeyPair>;
295
+ bondPublicKeys(): Promise<FunctionKeyPair>;
296
+ bondValidatorKeys(): Promise<FunctionKeyPair>;
297
+ claimUnbondPublicKeys(): Promise<FunctionKeyPair>;
298
+ /**
299
+ * Returns the proving and verifying keys for the transfer functions in the credits.aleo program
300
+ * @param {string} visibility Visibility of the transfer function
301
+ * @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the transfer functions
302
+ *
303
+ * @example
304
+ * // Create a new AleoKeyProvider
305
+ * const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1");
306
+ * const keyProvider = new AleoKeyProvider();
307
+ * const recordProvider = new NetworkRecordProvider(account, networkClient);
308
+ *
309
+ * // Initialize a program manager with the key provider to automatically fetch keys for value transfers
310
+ * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider);
311
+ * programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
312
+ *
313
+ * // Keys can also be fetched manually
314
+ * const [transferPublicProvingKey, transferPublicVerifyingKey] = await keyProvider.transferKeys("public");
315
+ */
316
+ transferKeys(visibility: string): Promise<FunctionKeyPair>;
317
+ /**
318
+ * Returns the proving and verifying keys for the join function in the credits.aleo program
319
+ *
320
+ * @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the join function
321
+ */
322
+ joinKeys(): Promise<FunctionKeyPair>;
323
+ /**
324
+ * Returns the proving and verifying keys for the split function in the credits.aleo program
325
+ *
326
+ * @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the split function
327
+ * */
328
+ splitKeys(): Promise<FunctionKeyPair>;
329
+ /**
330
+ * Returns the proving and verifying keys for the fee_private function in the credits.aleo program
331
+ *
332
+ * @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the fee function
333
+ */
334
+ feePrivateKeys(): Promise<FunctionKeyPair>;
335
+ /**
336
+ * Returns the proving and verifying keys for the fee_public function in the credits.aleo program
337
+ *
338
+ * @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the fee function
339
+ */
340
+ feePublicKeys(): Promise<FunctionKeyPair>;
341
+ /**
342
+ * Gets a verifying key. If the verifying key is for a credits.aleo function, get it from the wasm cache otherwise
343
+ *
344
+ * @returns {Promise<VerifyingKey>} Verifying key for the function
345
+ */
346
+ getVerifyingKey(verifierUri: string): Promise<VerifyingKey>;
347
+ unBondPublicKeys(): Promise<FunctionKeyPair>;
348
+ }
349
+ export { AleoKeyProvider, AleoKeyProviderParams, AleoKeyProviderInitParams, CachedKeyPair, FunctionKeyPair, FunctionKeyProvider, KeySearchParams };
@@ -0,0 +1,3 @@
1
+ import { WorkerAPI } from './worker';
2
+ declare const createAleoWorker: () => WorkerAPI;
3
+ export { createAleoWorker };
@@ -0,0 +1,21 @@
1
+ import { ConfirmedTransaction } from "./confirmed_transaction";
2
+ export type Block = {
3
+ block_hash: string;
4
+ previous_hash: string;
5
+ header: Header;
6
+ transactions?: (ConfirmedTransaction)[];
7
+ signature: string;
8
+ };
9
+ export type Header = {
10
+ previous_state_root: string;
11
+ transactions_root: string;
12
+ metadata: Metadata;
13
+ };
14
+ export type Metadata = {
15
+ network: number;
16
+ round: number;
17
+ height: number;
18
+ coinbase_target: number;
19
+ proof_target: number;
20
+ timestamp: number;
21
+ };
@@ -0,0 +1,6 @@
1
+ import { TransactionModel } from "./transactionModel";
2
+ export type ConfirmedTransaction = {
3
+ type: string;
4
+ id: string;
5
+ transaction: TransactionModel;
6
+ };
@@ -0,0 +1,5 @@
1
+ import { Transition } from "./transition";
2
+ export type Execution = {
3
+ edition: number;
4
+ transitions?: (Transition)[];
5
+ };
@@ -0,0 +1,10 @@
1
+ export type Input = {
2
+ type: string;
3
+ id: string;
4
+ tag?: string;
5
+ origin?: Origin;
6
+ value?: string;
7
+ };
8
+ export type Origin = {
9
+ commitment: string;
10
+ };
@@ -0,0 +1,6 @@
1
+ export type Output = {
2
+ type: string;
3
+ id: string;
4
+ checksum: string;
5
+ value: string;
6
+ };
@@ -0,0 +1,6 @@
1
+ import { Execution } from "./execution";
2
+ export type TransactionModel = {
3
+ type: string;
4
+ id: string;
5
+ execution: Execution;
6
+ };
@@ -0,0 +1,13 @@
1
+ import { Input } from "./input";
2
+ import { Output } from "./output";
3
+ export type Transition = {
4
+ id: string;
5
+ program: string;
6
+ function: string;
7
+ inputs?: (Input)[];
8
+ outputs?: (Output)[];
9
+ proof: string;
10
+ tpk: string;
11
+ tcm: string;
12
+ fee: number;
13
+ };