@provablehq/sdk 0.7.2 → 0.7.4

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 (94) hide show
  1. package/README.md +3 -3
  2. package/package.json +1 -1
  3. package/dist/mainnet/account.d.ts +0 -137
  4. package/dist/mainnet/browser.d.ts +0 -26
  5. package/dist/mainnet/browser.js +0 -934
  6. package/dist/mainnet/browser.js.map +0 -1
  7. package/dist/mainnet/constants.d.ts +0 -34
  8. package/dist/mainnet/function-key-provider.d.ts +0 -349
  9. package/dist/mainnet/managed-worker.d.ts +0 -3
  10. package/dist/mainnet/models/blockJSON.d.ts +0 -21
  11. package/dist/mainnet/models/confirmed_transaction.d.ts +0 -6
  12. package/dist/mainnet/models/deploy.d.ts +0 -5
  13. package/dist/mainnet/models/executionJSON.d.ts +0 -5
  14. package/dist/mainnet/models/functionObject.d.ts +0 -7
  15. package/dist/mainnet/models/input/inputJSON.d.ts +0 -13
  16. package/dist/mainnet/models/input/inputObject.d.ts +0 -15
  17. package/dist/mainnet/models/output/outputJSON.d.ts +0 -6
  18. package/dist/mainnet/models/output/outputObject.d.ts +0 -17
  19. package/dist/mainnet/models/plaintext/array.d.ts +0 -3
  20. package/dist/mainnet/models/plaintext/literal.d.ts +0 -1
  21. package/dist/mainnet/models/plaintext/plaintext.d.ts +0 -4
  22. package/dist/mainnet/models/plaintext/struct.d.ts +0 -5
  23. package/dist/mainnet/models/transaction/transactionJSON.d.ts +0 -6
  24. package/dist/mainnet/models/transaction/transactionSummary.d.ts +0 -11
  25. package/dist/mainnet/models/transition/transitionJSON.d.ts +0 -13
  26. package/dist/mainnet/models/transition/transitionObject.d.ts +0 -15
  27. package/dist/mainnet/network-client.d.ts +0 -359
  28. package/dist/mainnet/node-polyfill.d.ts +0 -5
  29. package/dist/mainnet/node-polyfill.js +0 -304
  30. package/dist/mainnet/node-polyfill.js.map +0 -1
  31. package/dist/mainnet/node.d.ts +0 -2
  32. package/dist/mainnet/node.js +0 -13
  33. package/dist/mainnet/node.js.map +0 -1
  34. package/dist/mainnet/offline-key-provider.d.ts +0 -348
  35. package/dist/mainnet/polyfill/crypto.d.ts +0 -1
  36. package/dist/mainnet/polyfill/fetch.d.ts +0 -1
  37. package/dist/mainnet/polyfill/shared.d.ts +0 -1
  38. package/dist/mainnet/polyfill/worker.d.ts +0 -1
  39. package/dist/mainnet/polyfill/xmlhttprequest.d.ts +0 -1
  40. package/dist/mainnet/program-manager-DAqdrsXx.js +0 -2356
  41. package/dist/mainnet/program-manager-DAqdrsXx.js.map +0 -1
  42. package/dist/mainnet/program-manager.d.ts +0 -640
  43. package/dist/mainnet/record-provider.d.ts +0 -236
  44. package/dist/mainnet/utils.d.ts +0 -4
  45. package/dist/mainnet/wasm.d.ts +0 -1
  46. package/dist/mainnet/worker.d.ts +0 -9
  47. package/dist/mainnet/worker.js +0 -78
  48. package/dist/mainnet/worker.js.map +0 -1
  49. package/dist/testnet/account.d.ts +0 -137
  50. package/dist/testnet/browser.d.ts +0 -26
  51. package/dist/testnet/browser.js +0 -934
  52. package/dist/testnet/browser.js.map +0 -1
  53. package/dist/testnet/constants.d.ts +0 -34
  54. package/dist/testnet/function-key-provider.d.ts +0 -349
  55. package/dist/testnet/managed-worker.d.ts +0 -3
  56. package/dist/testnet/models/blockJSON.d.ts +0 -21
  57. package/dist/testnet/models/confirmed_transaction.d.ts +0 -6
  58. package/dist/testnet/models/deploy.d.ts +0 -5
  59. package/dist/testnet/models/executionJSON.d.ts +0 -5
  60. package/dist/testnet/models/functionObject.d.ts +0 -7
  61. package/dist/testnet/models/input/inputJSON.d.ts +0 -13
  62. package/dist/testnet/models/input/inputObject.d.ts +0 -15
  63. package/dist/testnet/models/output/outputJSON.d.ts +0 -6
  64. package/dist/testnet/models/output/outputObject.d.ts +0 -17
  65. package/dist/testnet/models/plaintext/array.d.ts +0 -3
  66. package/dist/testnet/models/plaintext/literal.d.ts +0 -1
  67. package/dist/testnet/models/plaintext/plaintext.d.ts +0 -4
  68. package/dist/testnet/models/plaintext/struct.d.ts +0 -5
  69. package/dist/testnet/models/transaction/transactionJSON.d.ts +0 -6
  70. package/dist/testnet/models/transaction/transactionSummary.d.ts +0 -11
  71. package/dist/testnet/models/transition/transitionJSON.d.ts +0 -13
  72. package/dist/testnet/models/transition/transitionObject.d.ts +0 -15
  73. package/dist/testnet/network-client.d.ts +0 -359
  74. package/dist/testnet/node-polyfill.d.ts +0 -5
  75. package/dist/testnet/node-polyfill.js +0 -304
  76. package/dist/testnet/node-polyfill.js.map +0 -1
  77. package/dist/testnet/node.d.ts +0 -2
  78. package/dist/testnet/node.js +0 -13
  79. package/dist/testnet/node.js.map +0 -1
  80. package/dist/testnet/offline-key-provider.d.ts +0 -348
  81. package/dist/testnet/polyfill/crypto.d.ts +0 -1
  82. package/dist/testnet/polyfill/fetch.d.ts +0 -1
  83. package/dist/testnet/polyfill/shared.d.ts +0 -1
  84. package/dist/testnet/polyfill/worker.d.ts +0 -1
  85. package/dist/testnet/polyfill/xmlhttprequest.d.ts +0 -1
  86. package/dist/testnet/program-manager-DWPt87ls.js +0 -2356
  87. package/dist/testnet/program-manager-DWPt87ls.js.map +0 -1
  88. package/dist/testnet/program-manager.d.ts +0 -640
  89. package/dist/testnet/record-provider.d.ts +0 -236
  90. package/dist/testnet/utils.d.ts +0 -4
  91. package/dist/testnet/wasm.d.ts +0 -1
  92. package/dist/testnet/worker.d.ts +0 -9
  93. package/dist/testnet/worker.js +0 -78
  94. package/dist/testnet/worker.js.map +0 -1
@@ -1,934 +0,0 @@
1
- import 'core-js/proposals/json-parse-with-source.js';
2
- import { ViewKey, Address, PrivateKeyCiphertext, PrivateKey, RecordCiphertext, ProvingKey, VerifyingKey } from '@provablehq/wasm/mainnet.js';
3
- export { Address, Ciphertext, ExecutionResponse, Field, Execution as FunctionExecution, Group, OfflineQuery, Plaintext, PrivateKey, PrivateKeyCiphertext, Program, ProgramManager as ProgramManagerBase, ProvingKey, RecordCiphertext, RecordPlaintext, Scalar, Signature, Transaction, Transition, VerifyingKey, ViewKey, initThreadPool, verifyFunctionExecution } from '@provablehq/wasm/mainnet.js';
4
- import { C as CREDITS_PROGRAM_KEYS, c as PRIVATE_TRANSFER, d as PRIVATE_TO_PUBLIC_TRANSFER, f as PUBLIC_TRANSFER, g as PUBLIC_TRANSFER_AS_SIGNER, h as PUBLIC_TO_PRIVATE_TRANSFER, l as logAndThrow } from './program-manager-DAqdrsXx.js';
5
- export { A as AleoKeyProvider, a as AleoKeyProviderParams, b as AleoNetworkClient, K as KEY_STORE, e as PRIVATE_TRANSFER_TYPES, P as ProgramManager, V as VALID_TRANSFER_TYPES } from './program-manager-DAqdrsXx.js';
6
- import { wrap } from 'comlink';
7
-
8
- /**
9
- * Key Management class. Enables the creation of a new Aleo Account, importation of an existing account from
10
- * an existing private key or seed, and message signing and verification functionality.
11
- *
12
- * An Aleo Account is generated from a randomly generated seed (number) from which an account private key, view key,
13
- * and a public account address are derived. The private key lies at the root of an Aleo account. It is a highly
14
- * sensitive secret and should be protected as it allows for creation of Aleo Program executions and arbitrary value
15
- * transfers. The View Key allows for decryption of a user's activity on the blockchain. The Address is the public
16
- * address to which other users of Aleo can send Aleo credits and other records to. This class should only be used
17
- * environments where the safety of the underlying key material can be assured.
18
- *
19
- * @example
20
- * // Create a new account
21
- * const myRandomAccount = new Account();
22
- *
23
- * // Create an account from a randomly generated seed
24
- * 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]);
25
- * const mySeededAccount = new Account({seed: seed});
26
- *
27
- * // Create an account from an existing private key
28
- * const myExistingAccount = new Account({privateKey: 'myExistingPrivateKey'})
29
- *
30
- * // Sign a message
31
- * const hello_world = Uint8Array.from([104, 101, 108, 108, 111 119, 111, 114, 108, 100])
32
- * const signature = myRandomAccount.sign(hello_world)
33
- *
34
- * // Verify a signature
35
- * myRandomAccount.verify(hello_world, signature)
36
- */
37
- class Account {
38
- _privateKey;
39
- _viewKey;
40
- _address;
41
- constructor(params = {}) {
42
- try {
43
- this._privateKey = this.privateKeyFromParams(params);
44
- }
45
- catch (e) {
46
- console.error("Wrong parameter", e);
47
- throw new Error("Wrong Parameter");
48
- }
49
- this._viewKey = ViewKey.from_private_key(this._privateKey);
50
- this._address = Address.from_private_key(this._privateKey);
51
- }
52
- /**
53
- * Attempts to create an account from a private key ciphertext
54
- * @param {PrivateKeyCiphertext | string} ciphertext
55
- * @param {string} password
56
- * @returns {PrivateKey}
57
- *
58
- * @example
59
- * const ciphertext = PrivateKey.newEncrypted("password");
60
- * const account = Account.fromCiphertext(ciphertext, "password");
61
- */
62
- static fromCiphertext(ciphertext, password) {
63
- try {
64
- ciphertext = (typeof ciphertext === "string") ? PrivateKeyCiphertext.fromString(ciphertext) : ciphertext;
65
- const _privateKey = PrivateKey.fromPrivateKeyCiphertext(ciphertext, password);
66
- return new Account({ privateKey: _privateKey.to_string() });
67
- }
68
- catch (e) {
69
- throw new Error("Wrong password or invalid ciphertext");
70
- }
71
- }
72
- privateKeyFromParams(params) {
73
- if (params.seed) {
74
- return PrivateKey.from_seed_unchecked(params.seed);
75
- }
76
- if (params.privateKey) {
77
- return PrivateKey.from_string(params.privateKey);
78
- }
79
- return new PrivateKey();
80
- }
81
- privateKey() {
82
- return this._privateKey;
83
- }
84
- viewKey() {
85
- return this._viewKey;
86
- }
87
- address() {
88
- return this._address;
89
- }
90
- toString() {
91
- return this.address().to_string();
92
- }
93
- /**
94
- * Encrypt the account's private key with a password
95
- * @param {string} ciphertext
96
- * @returns {PrivateKeyCiphertext}
97
- *
98
- * @example
99
- * const account = new Account();
100
- * const ciphertext = account.encryptAccount("password");
101
- */
102
- encryptAccount(password) {
103
- return this._privateKey.toCiphertext(password);
104
- }
105
- /**
106
- * Decrypts a Record in ciphertext form into plaintext
107
- * @param {string} ciphertext
108
- * @returns {Record}
109
- *
110
- * @example
111
- * const account = new Account();
112
- * const record = account.decryptRecord("record1ciphertext");
113
- */
114
- decryptRecord(ciphertext) {
115
- return this._viewKey.decrypt(ciphertext);
116
- }
117
- /**
118
- * Decrypts an array of Records in ciphertext form into plaintext
119
- * @param {string[]} ciphertexts
120
- * @returns {Record[]}
121
- *
122
- * @example
123
- * const account = new Account();
124
- * const record = account.decryptRecords(["record1ciphertext", "record2ciphertext"]);
125
- */
126
- decryptRecords(ciphertexts) {
127
- return ciphertexts.map((ciphertext) => this._viewKey.decrypt(ciphertext));
128
- }
129
- /**
130
- * Determines whether the account owns a ciphertext record
131
- * @param {RecordCipherText | string} ciphertext
132
- * @returns {boolean}
133
- *
134
- * @example
135
- * // Create a connection to the Aleo network and an account
136
- * const connection = new AleoNetworkClient("https://api.explorer.provable.com/v1");
137
- * const account = Account.fromCiphertext("ciphertext", "password");
138
- *
139
- * // Get a record from the network
140
- * const record = connection.getBlock(1234);
141
- * const recordCipherText = record.transactions[0].execution.transitions[0].id;
142
- *
143
- * // Check if the account owns the record
144
- * if account.ownsRecord(recordCipherText) {
145
- * // Then one can do something like:
146
- * // Decrypt the record and check if it's spent
147
- * // Store the record in a local database
148
- * // Etc.
149
- * }
150
- */
151
- ownsRecordCiphertext(ciphertext) {
152
- if (typeof ciphertext === 'string') {
153
- try {
154
- const ciphertextObject = RecordCiphertext.fromString(ciphertext);
155
- return ciphertextObject.isOwner(this._viewKey);
156
- }
157
- catch (e) {
158
- return false;
159
- }
160
- }
161
- else {
162
- return ciphertext.isOwner(this._viewKey);
163
- }
164
- }
165
- /**
166
- * Signs a message with the account's private key.
167
- * Returns a Signature.
168
- *
169
- * @param {Uint8Array} message
170
- * @returns {Signature}
171
- *
172
- * @example
173
- * const account = new Account();
174
- * const message = Uint8Array.from([104, 101, 108, 108, 111 119, 111, 114, 108, 100])
175
- * account.sign(message);
176
- */
177
- sign(message) {
178
- return this._privateKey.sign(message);
179
- }
180
- /**
181
- * Verifies the Signature on a message.
182
- *
183
- * @param {Uint8Array} message
184
- * @param {Signature} signature
185
- * @returns {boolean}
186
- *
187
- * @example
188
- * const account = new Account();
189
- * const message = Uint8Array.from([104, 101, 108, 108, 111 119, 111, 114, 108, 100])
190
- * const signature = account.sign(message);
191
- * account.verify(message, signature);
192
- */
193
- verify(message, signature) {
194
- return this._address.verify(message, signature);
195
- }
196
- }
197
-
198
- /**
199
- * Search parameters for the offline key provider. This class implements the KeySearchParams interface and includes
200
- * a convenience method for creating a new instance of this class for each function of the credits.aleo program.
201
- *
202
- * @example
203
- * // If storing a key for a custom program function
204
- * offlineSearchParams = new OfflineSearchParams("myprogram.aleo/myfunction");
205
- *
206
- * // If storing a key for a credits.aleo program function
207
- * bondPublicKeyParams = OfflineSearchParams.bondPublicKeyParams();
208
- */
209
- class OfflineSearchParams {
210
- cacheKey;
211
- verifyCreditsKeys;
212
- /**
213
- * Create a new OfflineSearchParams instance.
214
- *
215
- * @param {string} cacheKey - Key used to store the local function proving & verifying keys. This should be stored
216
- * under the naming convention "programName/functionName" (i.e. "myprogram.aleo/myfunction")
217
- * @param {boolean} verifyCreditsKeys - Whether to verify the keys against the credits.aleo program,
218
- * defaults to false, but should be set to true if using keys from the credits.aleo program
219
- */
220
- constructor(cacheKey, verifyCreditsKeys = false) {
221
- this.cacheKey = cacheKey;
222
- this.verifyCreditsKeys = verifyCreditsKeys;
223
- }
224
- /**
225
- * Create a new OfflineSearchParams instance for the bond_public function of the credits.aleo program.
226
- */
227
- static bondPublicKeyParams() {
228
- return new OfflineSearchParams(CREDITS_PROGRAM_KEYS.bond_public.locator, true);
229
- }
230
- /**
231
- * Create a new OfflineSearchParams instance for the bond_validator function of the credits.aleo program.
232
- */
233
- static bondValidatorKeyParams() {
234
- return new OfflineSearchParams(CREDITS_PROGRAM_KEYS.bond_validator.locator, true);
235
- }
236
- /**
237
- * Create a new OfflineSearchParams instance for the claim_unbond_public function of the
238
- */
239
- static claimUnbondPublicKeyParams() {
240
- return new OfflineSearchParams(CREDITS_PROGRAM_KEYS.claim_unbond_public.locator, true);
241
- }
242
- /**
243
- * Create a new OfflineSearchParams instance for the fee_private function of the credits.aleo program.
244
- */
245
- static feePrivateKeyParams() {
246
- return new OfflineSearchParams(CREDITS_PROGRAM_KEYS.fee_private.locator, true);
247
- }
248
- /**
249
- * Create a new OfflineSearchParams instance for the fee_public function of the credits.aleo program.
250
- */
251
- static feePublicKeyParams() {
252
- return new OfflineSearchParams(CREDITS_PROGRAM_KEYS.fee_public.locator, true);
253
- }
254
- /**
255
- * Create a new OfflineSearchParams instance for the inclusion prover function.
256
- */
257
- static inclusionKeyParams() {
258
- return new OfflineSearchParams(CREDITS_PROGRAM_KEYS.inclusion.locator, true);
259
- }
260
- /**
261
- * Create a new OfflineSearchParams instance for the join function of the credits.aleo program.
262
- */
263
- static joinKeyParams() {
264
- return new OfflineSearchParams(CREDITS_PROGRAM_KEYS.join.locator, true);
265
- }
266
- /**
267
- * Create a new OfflineSearchParams instance for the set_validator_state function of the credits.aleo program.
268
- */
269
- static setValidatorStateKeyParams() {
270
- return new OfflineSearchParams(CREDITS_PROGRAM_KEYS.set_validator_state.locator, true);
271
- }
272
- /**
273
- * Create a new OfflineSearchParams instance for the split function of the credits.aleo program.
274
- */
275
- static splitKeyParams() {
276
- return new OfflineSearchParams(CREDITS_PROGRAM_KEYS.split.locator, true);
277
- }
278
- /**
279
- * Create a new OfflineSearchParams instance for the transfer_private function of the credits.aleo program.
280
- */
281
- static transferPrivateKeyParams() {
282
- return new OfflineSearchParams(CREDITS_PROGRAM_KEYS.transfer_private.locator, true);
283
- }
284
- /**
285
- * Create a new OfflineSearchParams instance for the transfer_private_to_public function of the credits.aleo program.
286
- */
287
- static transferPrivateToPublicKeyParams() {
288
- return new OfflineSearchParams(CREDITS_PROGRAM_KEYS.transfer_private_to_public.locator, true);
289
- }
290
- /**
291
- * Create a new OfflineSearchParams instance for the transfer_public function of the credits.aleo program.
292
- */
293
- static transferPublicKeyParams() {
294
- return new OfflineSearchParams(CREDITS_PROGRAM_KEYS.transfer_public.locator, true);
295
- }
296
- /**
297
- * Create a new OfflineSearchParams instance for the transfer_public_as_signer function of the credits.aleo program.
298
- */
299
- static transferPublicAsSignerKeyParams() {
300
- return new OfflineSearchParams(CREDITS_PROGRAM_KEYS.transfer_public_as_signer.locator, true);
301
- }
302
- /**
303
- * Create a new OfflineSearchParams instance for the transfer_public_to_private function of the credits.aleo program.
304
- */
305
- static transferPublicToPrivateKeyParams() {
306
- return new OfflineSearchParams(CREDITS_PROGRAM_KEYS.transfer_public_to_private.locator, true);
307
- }
308
- /**
309
- * Create a new OfflineSearchParams instance for the unbond_public function of the credits.aleo program.
310
- */
311
- static unbondPublicKeyParams() {
312
- return new OfflineSearchParams(CREDITS_PROGRAM_KEYS.unbond_public.locator, true);
313
- }
314
- }
315
- /**
316
- * A key provider meant for building transactions offline on devices such as hardware wallets. This key provider is not
317
- * able to contact the internet for key material and instead relies on the user to insert Aleo function proving &
318
- * verifying keys from local storage prior to usage.
319
- *
320
- * @example
321
- * // Create an offline program manager
322
- * const programManager = new ProgramManager();
323
- *
324
- * // Create a temporary account for the execution of the program
325
- * const account = new Account();
326
- * programManager.setAccount(account);
327
- *
328
- * // Create the proving keys from the key bytes on the offline machine
329
- * console.log("Creating proving keys from local key files");
330
- * 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;";
331
- * const myFunctionProver = await getLocalKey("/path/to/my/function/hello_hello.prover");
332
- * const myFunctionVerifier = await getLocalKey("/path/to/my/function/hello_hello.verifier");
333
- * const feePublicProvingKeyBytes = await getLocalKey("/path/to/credits.aleo/feePublic.prover");
334
- *
335
- * myFunctionProvingKey = ProvingKey.fromBytes(myFunctionProver);
336
- * myFunctionVerifyingKey = VerifyingKey.fromBytes(myFunctionVerifier);
337
- * const feePublicProvingKey = ProvingKey.fromBytes(feePublicKeyBytes);
338
- *
339
- * // Create an offline key provider
340
- * console.log("Creating offline key provider");
341
- * const offlineKeyProvider = new OfflineKeyProvider();
342
- *
343
- * // Cache the keys
344
- * // Cache the proving and verifying keys for the custom hello function
345
- * OfflineKeyProvider.cacheKeys("hello_hello.aleo/hello", myFunctionProvingKey, myFunctionVerifyingKey);
346
- *
347
- * // Cache the proving key for the fee_public function (the verifying key is automatically cached)
348
- * OfflineKeyProvider.insertFeePublicKey(feePublicProvingKey);
349
- *
350
- * // Create an offline query using the latest state root in order to create the inclusion proof
351
- * const offlineQuery = new OfflineQuery("latestStateRoot");
352
- *
353
- * // Insert the key provider into the program manager
354
- * programManager.setKeyProvider(offlineKeyProvider);
355
- *
356
- * // Create the offline search params
357
- * const offlineSearchParams = new OfflineSearchParams("hello_hello.aleo/hello");
358
- *
359
- * // Create the offline transaction
360
- * const offlineExecuteTx = <Transaction>await this.buildExecutionTransaction("hello_hello.aleo", "hello", 1, false, ["5u32", "5u32"], undefined, offlineSearchParams, undefined, undefined, undefined, undefined, offlineQuery, program);
361
- *
362
- * // Broadcast the transaction later on a machine with internet access
363
- * const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1");
364
- * const txId = await networkClient.broadcastTransaction(offlineExecuteTx);
365
- */
366
- class OfflineKeyProvider {
367
- cache;
368
- constructor() {
369
- this.cache = new Map();
370
- }
371
- /**
372
- * Get bond_public function keys from the credits.aleo program. The keys must be cached prior to calling this
373
- * method for it to work.
374
- *
375
- * @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the bond_public function
376
- */
377
- bondPublicKeys() {
378
- return this.functionKeys(OfflineSearchParams.bondPublicKeyParams());
379
- }
380
- ;
381
- /**
382
- * Get bond_validator function keys from the credits.aleo program. The keys must be cached prior to calling this
383
- * method for it to work.
384
- *
385
- * @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the bond_public function
386
- */
387
- bondValidatorKeys() {
388
- return this.functionKeys(OfflineSearchParams.bondValidatorKeyParams());
389
- }
390
- ;
391
- /**
392
- * Cache a set of keys. This will overwrite any existing keys with the same keyId. The user can check if a keyId
393
- * exists in the cache using the containsKeys method prior to calling this method if overwriting is not desired.
394
- *
395
- * @param {string} keyId access key for the cache
396
- * @param {FunctionKeyPair} keys keys to cache
397
- */
398
- cacheKeys(keyId, keys) {
399
- const [provingKey, verifyingKey] = keys;
400
- this.cache.set(keyId, [provingKey.toBytes(), verifyingKey.toBytes()]);
401
- }
402
- ;
403
- /**
404
- * Get unbond_public function keys from the credits.aleo program. The keys must be cached prior to calling this
405
- * method for it to work.
406
- *
407
- * @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the unbond_public function
408
- */
409
- claimUnbondPublicKeys() {
410
- return this.functionKeys(OfflineSearchParams.claimUnbondPublicKeyParams());
411
- }
412
- ;
413
- /**
414
- * Get arbitrary function key from the offline key provider cache.
415
- *
416
- * @param {KeySearchParams | undefined} params - Optional search parameters for the key provider
417
- * @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the specified program
418
- *
419
- * @example
420
- * /// First cache the keys from local offline resources
421
- * const offlineKeyProvider = new OfflineKeyProvider();
422
- * const myFunctionVerifyingKey = VerifyingKey.fromString("verifier...");
423
- * const myFunctionProvingKeyBytes = await readBinaryFile('./resources/myfunction.prover');
424
- * const myFunctionProvingKey = ProvingKey.fromBytes(myFunctionProvingKeyBytes);
425
- *
426
- * /// Cache the keys for future use with a memorable locator
427
- * offlineKeyProvider.cacheKeys("myprogram.aleo/myfunction", [myFunctionProvingKey, myFunctionVerifyingKey]);
428
- *
429
- * /// When they're needed, retrieve the keys from the cache
430
- *
431
- * /// First create a search parameter object with the same locator used to cache the keys
432
- * const keyParams = new OfflineSearchParams("myprogram.aleo/myfunction");
433
- *
434
- * /// Then retrieve the keys
435
- * const [myFunctionProver, myFunctionVerifier] = await offlineKeyProvider.functionKeys(keyParams);
436
- */
437
- functionKeys(params) {
438
- return new Promise((resolve, reject) => {
439
- if (params === undefined) {
440
- reject(new Error("No search parameters provided, cannot retrieve keys"));
441
- }
442
- else {
443
- const keyId = params.cacheKey;
444
- const verifyCreditsKeys = params.verifyCreditsKeys;
445
- if (this.cache.has(keyId)) {
446
- const [provingKeyBytes, verifyingKeyBytes] = this.cache.get(keyId);
447
- const provingKey = ProvingKey.fromBytes(provingKeyBytes);
448
- const verifyingKey = VerifyingKey.fromBytes(verifyingKeyBytes);
449
- if (verifyCreditsKeys) {
450
- const keysMatchExpected = this.verifyCreditsKeys(keyId, provingKey, verifyingKey);
451
- if (!keysMatchExpected) {
452
- reject(new Error(`Cached keys do not match expected keys for ${keyId}`));
453
- }
454
- }
455
- resolve([provingKey, verifyingKey]);
456
- }
457
- else {
458
- reject(new Error("Keys not found in cache for " + keyId));
459
- }
460
- }
461
- });
462
- }
463
- ;
464
- /**
465
- * Determines if the keys for a given credits function match the expected keys.
466
- *
467
- * @returns {boolean} Whether the keys match the expected keys
468
- */
469
- verifyCreditsKeys(locator, provingKey, verifyingKey) {
470
- switch (locator) {
471
- case CREDITS_PROGRAM_KEYS.bond_public.locator:
472
- return provingKey.isBondPublicProver() && verifyingKey.isBondPublicVerifier();
473
- case CREDITS_PROGRAM_KEYS.claim_unbond_public.locator:
474
- return provingKey.isClaimUnbondPublicProver() && verifyingKey.isClaimUnbondPublicVerifier();
475
- case CREDITS_PROGRAM_KEYS.fee_private.locator:
476
- return provingKey.isFeePrivateProver() && verifyingKey.isFeePrivateVerifier();
477
- case CREDITS_PROGRAM_KEYS.fee_public.locator:
478
- return provingKey.isFeePublicProver() && verifyingKey.isFeePublicVerifier();
479
- case CREDITS_PROGRAM_KEYS.inclusion.locator:
480
- return provingKey.isInclusionProver() && verifyingKey.isInclusionVerifier();
481
- case CREDITS_PROGRAM_KEYS.join.locator:
482
- return provingKey.isJoinProver() && verifyingKey.isJoinVerifier();
483
- case CREDITS_PROGRAM_KEYS.set_validator_state.locator:
484
- return provingKey.isSetValidatorStateProver() && verifyingKey.isSetValidatorStateVerifier();
485
- case CREDITS_PROGRAM_KEYS.split.locator:
486
- return provingKey.isSplitProver() && verifyingKey.isSplitVerifier();
487
- case CREDITS_PROGRAM_KEYS.transfer_private.locator:
488
- return provingKey.isTransferPrivateProver() && verifyingKey.isTransferPrivateVerifier();
489
- case CREDITS_PROGRAM_KEYS.transfer_private_to_public.locator:
490
- return provingKey.isTransferPrivateToPublicProver() && verifyingKey.isTransferPrivateToPublicVerifier();
491
- case CREDITS_PROGRAM_KEYS.transfer_public.locator:
492
- return provingKey.isTransferPublicProver() && verifyingKey.isTransferPublicVerifier();
493
- case CREDITS_PROGRAM_KEYS.transfer_public_to_private.locator:
494
- return provingKey.isTransferPublicToPrivateProver() && verifyingKey.isTransferPublicToPrivateVerifier();
495
- case CREDITS_PROGRAM_KEYS.unbond_public.locator:
496
- return provingKey.isUnbondPublicProver() && verifyingKey.isUnbondPublicVerifier();
497
- default:
498
- return false;
499
- }
500
- }
501
- /**
502
- * Get fee_private function keys from the credits.aleo program. The keys must be cached prior to calling this
503
- * method for it to work.
504
- *
505
- * @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the join function
506
- */
507
- feePrivateKeys() {
508
- return this.functionKeys(OfflineSearchParams.feePrivateKeyParams());
509
- }
510
- ;
511
- /**
512
- * Get fee_public function keys from the credits.aleo program. The keys must be cached prior to calling this
513
- * method for it to work.
514
- *
515
- * @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the join function
516
- */
517
- feePublicKeys() {
518
- return this.functionKeys(OfflineSearchParams.feePublicKeyParams());
519
- }
520
- ;
521
- /**
522
- * Get join function keys from the credits.aleo program. The keys must be cached prior to calling this
523
- * method for it to work.
524
- *
525
- * @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the join function
526
- */
527
- joinKeys() {
528
- return this.functionKeys(OfflineSearchParams.joinKeyParams());
529
- }
530
- ;
531
- /**
532
- * Get split function keys from the credits.aleo program. The keys must be cached prior to calling this
533
- * method for it to work.
534
- *
535
- * @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the join function
536
- */
537
- splitKeys() {
538
- return this.functionKeys(OfflineSearchParams.splitKeyParams());
539
- }
540
- ;
541
- /**
542
- * Get keys for a variant of the transfer function from the credits.aleo program.
543
- *
544
- *
545
- * @param {string} visibility Visibility of the transfer function (private, public, privateToPublic, publicToPrivate)
546
- * @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the specified transfer function
547
- *
548
- * @example
549
- * // Create a new OfflineKeyProvider
550
- * const offlineKeyProvider = new OfflineKeyProvider();
551
- *
552
- * // Cache the keys for future use with the official locator
553
- * const transferPublicProvingKeyBytes = await readBinaryFile('./resources/transfer_public.prover.a74565e');
554
- * const transferPublicProvingKey = ProvingKey.fromBytes(transferPublicProvingKeyBytes);
555
- *
556
- * // Cache the transfer_public keys for future use with the OfflinKeyProvider's convenience method for
557
- * // transfer_public (the verifying key will be cached automatically)
558
- * offlineKeyProvider.insertTransferPublicKeys(transferPublicProvingKey);
559
- *
560
- * /// When they're needed, retrieve the keys from the cache
561
- * const [transferPublicProvingKey, transferPublicVerifyingKey] = await keyProvider.transferKeys("public");
562
- */
563
- transferKeys(visibility) {
564
- if (PRIVATE_TRANSFER.has(visibility)) {
565
- return this.functionKeys(OfflineSearchParams.transferPrivateKeyParams());
566
- }
567
- else if (PRIVATE_TO_PUBLIC_TRANSFER.has(visibility)) {
568
- return this.functionKeys(OfflineSearchParams.transferPrivateToPublicKeyParams());
569
- }
570
- else if (PUBLIC_TRANSFER.has(visibility)) {
571
- return this.functionKeys(OfflineSearchParams.transferPublicKeyParams());
572
- }
573
- else if (PUBLIC_TRANSFER_AS_SIGNER.has(visibility)) {
574
- return this.functionKeys(OfflineSearchParams.transferPublicAsSignerKeyParams());
575
- }
576
- else if (PUBLIC_TO_PRIVATE_TRANSFER.has(visibility)) {
577
- return this.functionKeys(OfflineSearchParams.transferPublicToPrivateKeyParams());
578
- }
579
- else {
580
- throw new Error("Invalid visibility type");
581
- }
582
- }
583
- ;
584
- /**
585
- * Get unbond_public function keys from the credits.aleo program
586
- *
587
- * @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the join function
588
- */
589
- async unBondPublicKeys() {
590
- return this.functionKeys(OfflineSearchParams.unbondPublicKeyParams());
591
- }
592
- ;
593
- /**
594
- * Insert the proving and verifying keys for the bond_public function into the cache. Only the proving key needs
595
- * to be inserted, the verifying key is automatically inserted by the SDK. This function will automatically check
596
- * that the keys match the expected checksum for bond_public before inserting them into the cache.
597
- *
598
- * @param provingKey
599
- */
600
- insertBondPublicKeys(provingKey) {
601
- if (provingKey.isBondPublicProver()) {
602
- this.cache.set(CREDITS_PROGRAM_KEYS.bond_public.locator, [provingKey.toBytes(), VerifyingKey.bondPublicVerifier().toBytes()]);
603
- }
604
- else {
605
- throw new Error("Attempted to insert invalid proving keys for bond_public");
606
- }
607
- }
608
- /**
609
- * Insert the proving and verifying keys for the claim_unbond_public function into the cache. Only the proving key needs
610
- * to be inserted, the verifying key is automatically inserted by the SDK. This function will automatically check
611
- * that the keys match the expected checksum for claim_unbond_public before inserting them into the cache.
612
- *
613
- * @param provingKey
614
- */
615
- insertClaimUnbondPublicKeys(provingKey) {
616
- if (provingKey.isClaimUnbondPublicProver()) {
617
- this.cache.set(CREDITS_PROGRAM_KEYS.claim_unbond_public.locator, [provingKey.toBytes(), VerifyingKey.claimUnbondPublicVerifier().toBytes()]);
618
- }
619
- else {
620
- throw new Error("Attempted to insert invalid proving keys for claim_unbond_public");
621
- }
622
- }
623
- /**
624
- * Insert the proving and verifying keys for the fee_private function into the cache. Only the proving key needs
625
- * to be inserted, the verifying key is automatically inserted by the SDK. This function will automatically check
626
- * that the keys match the expected checksum for fee_private before inserting them into the cache.
627
- *
628
- * @param provingKey
629
- */
630
- insertFeePrivateKeys(provingKey) {
631
- if (provingKey.isFeePrivateProver()) {
632
- this.cache.set(CREDITS_PROGRAM_KEYS.fee_private.locator, [provingKey.toBytes(), VerifyingKey.feePrivateVerifier().toBytes()]);
633
- }
634
- else {
635
- throw new Error("Attempted to insert invalid proving keys for fee_private");
636
- }
637
- }
638
- /**
639
- * Insert the proving and verifying keys for the fee_public function into the cache. Only the proving key needs
640
- * to be inserted, the verifying key is automatically inserted by the SDK. This function will automatically check
641
- * that the keys match the expected checksum for fee_public before inserting them into the cache.
642
- *
643
- * @param provingKey
644
- */
645
- insertFeePublicKeys(provingKey) {
646
- if (provingKey.isFeePublicProver()) {
647
- this.cache.set(CREDITS_PROGRAM_KEYS.fee_public.locator, [provingKey.toBytes(), VerifyingKey.feePublicVerifier().toBytes()]);
648
- }
649
- else {
650
- throw new Error("Attempted to insert invalid proving keys for fee_public");
651
- }
652
- }
653
- /**
654
- * Insert the proving and verifying keys for the join function into the cache. Only the proving key needs
655
- * to be inserted, the verifying key is automatically inserted by the SDK. This function will automatically check
656
- * that the keys match the expected checksum for join before inserting them into the cache.
657
- *
658
- * @param provingKey
659
- */
660
- insertJoinKeys(provingKey) {
661
- if (provingKey.isJoinProver()) {
662
- this.cache.set(CREDITS_PROGRAM_KEYS.join.locator, [provingKey.toBytes(), VerifyingKey.joinVerifier().toBytes()]);
663
- }
664
- else {
665
- throw new Error("Attempted to insert invalid proving keys for join");
666
- }
667
- }
668
- /**
669
- * Insert the proving and verifying keys for the set_validator_state function into the cache. Only the proving key needs
670
- * to be inserted, the verifying key is automatically inserted by the SDK. This function will automatically check
671
- * that the keys match the expected checksum for set_validator_state before inserting them into the cache.
672
- *
673
- * @param provingKey
674
- */
675
- insertSetValidatorStateKeys(provingKey) {
676
- if (provingKey.isSetValidatorStateProver()) {
677
- this.cache.set(CREDITS_PROGRAM_KEYS.set_validator_state.locator, [provingKey.toBytes(), VerifyingKey.setValidatorStateVerifier().toBytes()]);
678
- }
679
- else {
680
- throw new Error("Attempted to insert invalid proving keys for set_validator_state");
681
- }
682
- }
683
- /**
684
- * Insert the proving and verifying keys for the split function into the cache. Only the proving key needs
685
- * to be inserted, the verifying key is automatically inserted by the SDK. This function will automatically check
686
- * that the keys match the expected checksum for split before inserting them into the cache.
687
- *
688
- * @param provingKey
689
- */
690
- insertSplitKeys(provingKey) {
691
- if (provingKey.isSplitProver()) {
692
- this.cache.set(CREDITS_PROGRAM_KEYS.split.locator, [provingKey.toBytes(), VerifyingKey.splitVerifier().toBytes()]);
693
- }
694
- else {
695
- throw new Error("Attempted to insert invalid proving keys for split");
696
- }
697
- }
698
- /**
699
- * Insert the proving and verifying keys for the transfer_private function into the cache. Only the proving key needs
700
- * to be inserted, the verifying key is automatically inserted by the SDK. This function will automatically check
701
- * that the keys match the expected checksum for transfer_private before inserting them into the cache.
702
- *
703
- * @param provingKey
704
- */
705
- insertTransferPrivateKeys(provingKey) {
706
- if (provingKey.isTransferPrivateProver()) {
707
- this.cache.set(CREDITS_PROGRAM_KEYS.transfer_private.locator, [provingKey.toBytes(), VerifyingKey.transferPrivateVerifier().toBytes()]);
708
- }
709
- else {
710
- throw new Error("Attempted to insert invalid proving keys for transfer_private");
711
- }
712
- }
713
- /**
714
- * Insert the proving and verifying keys for the transfer_private_to_public function into the cache. Only the proving key needs
715
- * to be inserted, the verifying key is automatically inserted by the SDK. This function will automatically check
716
- * that the keys match the expected checksum for transfer_private_to_public before inserting them into the cache.
717
- *
718
- * @param provingKey
719
- */
720
- insertTransferPrivateToPublicKeys(provingKey) {
721
- if (provingKey.isTransferPrivateToPublicProver()) {
722
- this.cache.set(CREDITS_PROGRAM_KEYS.transfer_private_to_public.locator, [provingKey.toBytes(), VerifyingKey.transferPrivateToPublicVerifier().toBytes()]);
723
- }
724
- else {
725
- throw new Error("Attempted to insert invalid proving keys for transfer_private_to_public");
726
- }
727
- }
728
- /**
729
- * Insert the proving and verifying keys for the transfer_public function into the cache. Only the proving key needs
730
- * to be inserted, the verifying key is automatically inserted by the SDK. This function will automatically check
731
- * that the keys match the expected checksum for transfer_public before inserting them into the cache.
732
- *
733
- * @param provingKey
734
- */
735
- insertTransferPublicKeys(provingKey) {
736
- if (provingKey.isTransferPublicProver()) {
737
- this.cache.set(CREDITS_PROGRAM_KEYS.transfer_public.locator, [provingKey.toBytes(), VerifyingKey.transferPublicVerifier().toBytes()]);
738
- }
739
- else {
740
- throw new Error("Attempted to insert invalid proving keys for transfer_public");
741
- }
742
- }
743
- /**
744
- * Insert the proving and verifying keys for the transfer_public_to_private function into the cache. Only the proving key needs
745
- * to be inserted, the verifying key is automatically inserted by the SDK. This function will automatically check
746
- * that the keys match the expected checksum for transfer_public_to_private before inserting them into the cache.
747
- *
748
- * @param provingKey
749
- */
750
- insertTransferPublicToPrivateKeys(provingKey) {
751
- if (provingKey.isTransferPublicToPrivateProver()) {
752
- this.cache.set(CREDITS_PROGRAM_KEYS.transfer_public_to_private.locator, [provingKey.toBytes(), VerifyingKey.transferPublicToPrivateVerifier().toBytes()]);
753
- }
754
- else {
755
- throw new Error("Attempted to insert invalid proving keys for transfer_public_to_private");
756
- }
757
- }
758
- insertUnbondPublicKeys(provingKey) {
759
- if (provingKey.isUnbondPublicProver()) {
760
- this.cache.set(CREDITS_PROGRAM_KEYS.unbond_public.locator, [provingKey.toBytes(), VerifyingKey.unbondPublicVerifier().toBytes()]);
761
- }
762
- else {
763
- throw new Error("Attempted to insert invalid proving keys for unbond_public");
764
- }
765
- }
766
- }
767
-
768
- /**
769
- * A record provider implementation that uses the official Aleo API to find records for usage in program execution and
770
- * deployment, wallet functionality, and other use cases.
771
- */
772
- class NetworkRecordProvider {
773
- account;
774
- networkClient;
775
- constructor(account, networkClient) {
776
- this.account = account;
777
- this.networkClient = networkClient;
778
- }
779
- /**
780
- * Set the account used to search for records
781
- *
782
- * @param {Account} account The account to use for searching for records
783
- */
784
- setAccount(account) {
785
- this.account = account;
786
- }
787
- /**
788
- * Find a list of credit records with a given number of microcredits by via the official Aleo API
789
- *
790
- * @param {number[]} microcredits The number of microcredits to search for
791
- * @param {boolean} unspent Whether or not the record is unspent
792
- * @param {string[]} nonces Nonces of records already found so that they are not found again
793
- * @param {RecordSearchParams} searchParameters Additional parameters to search for
794
- * @returns {Promise<RecordPlaintext>} The record if found, otherwise an error
795
- *
796
- * @example
797
- * // Create a new NetworkRecordProvider
798
- * const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1");
799
- * const keyProvider = new AleoKeyProvider();
800
- * const recordProvider = new NetworkRecordProvider(account, networkClient);
801
- *
802
- * // The record provider can be used to find records with a given number of microcredits
803
- * const record = await recordProvider.findCreditsRecord(5000, true, []);
804
- *
805
- * // When a record is found but not yet used, it's nonce should be added to the nonces parameter so that it is not
806
- * // found again if a subsequent search is performed
807
- * const records = await recordProvider.findCreditsRecords(5000, true, [record.nonce()]);
808
- *
809
- * // When the program manager is initialized with the record provider it will be used to find automatically find
810
- * // fee records and amount records for value transfers so that they do not need to be specified manually
811
- * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider);
812
- * programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
813
- *
814
- * */
815
- async findCreditsRecords(microcredits, unspent, nonces, searchParameters) {
816
- let startHeight = 0;
817
- let endHeight = 0;
818
- if (searchParameters) {
819
- if ("startHeight" in searchParameters && typeof searchParameters["endHeight"] == "number") {
820
- startHeight = searchParameters["startHeight"];
821
- }
822
- if ("endHeight" in searchParameters && typeof searchParameters["endHeight"] == "number") {
823
- endHeight = searchParameters["endHeight"];
824
- }
825
- }
826
- // If the end height is not specified, use the current block height
827
- if (endHeight == 0) {
828
- const end = await this.networkClient.getLatestHeight();
829
- endHeight = end;
830
- }
831
- // If the start height is greater than the end height, throw an error
832
- if (startHeight >= endHeight) {
833
- logAndThrow("Start height must be less than end height");
834
- }
835
- return await this.networkClient.findUnspentRecords(startHeight, endHeight, this.account.privateKey(), microcredits, undefined, nonces);
836
- }
837
- /**
838
- * Find a credit record with a given number of microcredits by via the official Aleo API
839
- *
840
- * @param {number} microcredits The number of microcredits to search for
841
- * @param {boolean} unspent Whether or not the record is unspent
842
- * @param {string[]} nonces Nonces of records already found so that they are not found again
843
- * @param {RecordSearchParams} searchParameters Additional parameters to search for
844
- * @returns {Promise<RecordPlaintext>} The record if found, otherwise an error
845
- *
846
- * @example
847
- * // Create a new NetworkRecordProvider
848
- * const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1");
849
- * const keyProvider = new AleoKeyProvider();
850
- * const recordProvider = new NetworkRecordProvider(account, networkClient);
851
- *
852
- * // The record provider can be used to find records with a given number of microcredits
853
- * const record = await recordProvider.findCreditsRecord(5000, true, []);
854
- *
855
- * // When a record is found but not yet used, it's nonce should be added to the nonces parameter so that it is not
856
- * // found again if a subsequent search is performed
857
- * const records = await recordProvider.findCreditsRecords(5000, true, [record.nonce()]);
858
- *
859
- * // When the program manager is initialized with the record provider it will be used to find automatically find
860
- * // fee records and amount records for value transfers so that they do not need to be specified manually
861
- * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider);
862
- * programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
863
- */
864
- async findCreditsRecord(microcredits, unspent, nonces, searchParameters) {
865
- let records = null;
866
- try {
867
- records = await this.findCreditsRecords([microcredits], unspent, nonces, searchParameters);
868
- }
869
- catch (e) { }
870
- if (records && records.length > 0) {
871
- return records[0];
872
- }
873
- console.error("Record not found with error:", records);
874
- throw new Error("Record not found");
875
- }
876
- /**
877
- * Find an arbitrary record. WARNING: This function is not implemented yet and will throw an error.
878
- */
879
- async findRecord(unspent, nonces, searchParameters) {
880
- throw new Error("Method not implemented.");
881
- }
882
- /**
883
- * Find multiple arbitrary records. WARNING: This function is not implemented yet and will throw an error.
884
- */
885
- async findRecords(unspent, nonces, searchParameters) {
886
- throw new Error("Method not implemented.");
887
- }
888
- }
889
- /**
890
- * BlockHeightSearch is a RecordSearchParams implementation that allows for searching for records within a given
891
- * block height range.
892
- *
893
- * @example
894
- * // Create a new BlockHeightSearch
895
- * const params = new BlockHeightSearch(89995, 99995);
896
- *
897
- * // Create a new NetworkRecordProvider
898
- * const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1");
899
- * const keyProvider = new AleoKeyProvider();
900
- * const recordProvider = new NetworkRecordProvider(account, networkClient);
901
- *
902
- * // The record provider can be used to find records with a given number of microcredits and the block height search
903
- * // can be used to find records within a given block height range
904
- * const record = await recordProvider.findCreditsRecord(5000, true, [], params);
905
- *
906
- */
907
- class BlockHeightSearch {
908
- startHeight;
909
- endHeight;
910
- constructor(startHeight, endHeight) {
911
- this.startHeight = startHeight;
912
- this.endHeight = endHeight;
913
- }
914
- }
915
-
916
- // Experimental example where SDK manages worker
917
- let singletonWorker = null;
918
- const createAleoWorker = () => {
919
- if (!singletonWorker) {
920
- const worker = new Worker(new URL("worker.js", import.meta.url), {
921
- type: "module",
922
- });
923
- singletonWorker = wrap(worker);
924
- }
925
- return singletonWorker;
926
- };
927
-
928
- // @TODO: This function is no longer needed, remove it.
929
- async function initializeWasm() {
930
- console.warn("initializeWasm is deprecated, you no longer need to use it");
931
- }
932
-
933
- export { Account, BlockHeightSearch, CREDITS_PROGRAM_KEYS, NetworkRecordProvider, OfflineKeyProvider, OfflineSearchParams, PRIVATE_TO_PUBLIC_TRANSFER, PRIVATE_TRANSFER, PUBLIC_TO_PRIVATE_TRANSFER, PUBLIC_TRANSFER, PUBLIC_TRANSFER_AS_SIGNER, createAleoWorker, initializeWasm, logAndThrow };
934
- //# sourceMappingURL=browser.js.map