@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
@@ -1,197 +1,20 @@
1
- import { ViewKey, Address, PrivateKeyCiphertext, PrivateKey, RecordCiphertext, Program, Transaction, ProvingKey, VerifyingKey, ProgramManager as ProgramManager$1, RecordPlaintext, verifyFunctionExecution, Metadata } from '@provablehq/wasm';
2
- export { Address, ExecutionResponse, Field, Execution as FunctionExecution, OfflineQuery, PrivateKey, PrivateKeyCiphertext, Program, ProgramManager as ProgramManagerBase, ProvingKey, RecordCiphertext, RecordPlaintext, Signature, Transaction, VerifyingKey, ViewKey, initThreadPool, verifyFunctionExecution } from '@provablehq/wasm';
3
- import { wrap } from 'comlink';
1
+ import { PrivateKey, RecordCiphertext, Program, Transaction, Metadata, VerifyingKey, ProvingKey, ProgramManager as ProgramManager$1, RecordPlaintext, verifyFunctionExecution } from '@provablehq/wasm/testnet.js';
4
2
 
5
- /**
6
- * Key Management class. Enables the creation of a new Aleo Account, importation of an existing account from
7
- * an existing private key or seed, and message signing and verification functionality.
8
- *
9
- * An Aleo Account is generated from a randomly generated seed (number) from which an account private key, view key,
10
- * and a public account address are derived. The private key lies at the root of an Aleo account. It is a highly
11
- * sensitive secret and should be protected as it allows for creation of Aleo Program executions and arbitrary value
12
- * transfers. The View Key allows for decryption of a user's activity on the blockchain. The Address is the public
13
- * address to which other users of Aleo can send Aleo credits and other records to. This class should only be used
14
- * environments where the safety of the underlying key material can be assured.
15
- *
16
- * @example
17
- * // Create a new account
18
- * const myRandomAccount = new Account();
19
- *
20
- * // Create an account from a randomly generated seed
21
- * 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]);
22
- * const mySeededAccount = new Account({seed: seed});
23
- *
24
- * // Create an account from an existing private key
25
- * const myExistingAccount = new Account({privateKey: 'myExistingPrivateKey'})
26
- *
27
- * // Sign a message
28
- * const hello_world = Uint8Array.from([104, 101, 108, 108, 111 119, 111, 114, 108, 100])
29
- * const signature = myRandomAccount.sign(hello_world)
30
- *
31
- * // Verify a signature
32
- * myRandomAccount.verify(hello_world, signature)
33
- */
34
- class Account {
35
- _privateKey;
36
- _viewKey;
37
- _address;
38
- constructor(params = {}) {
39
- try {
40
- this._privateKey = this.privateKeyFromParams(params);
41
- }
42
- catch (e) {
43
- console.error("Wrong parameter", e);
44
- throw new Error("Wrong Parameter");
45
- }
46
- this._viewKey = ViewKey.from_private_key(this._privateKey);
47
- this._address = Address.from_private_key(this._privateKey);
48
- }
49
- /**
50
- * Attempts to create an account from a private key ciphertext
51
- * @param {PrivateKeyCiphertext | string} ciphertext
52
- * @param {string} password
53
- * @returns {PrivateKey | Error}
54
- *
55
- * @example
56
- * const ciphertext = PrivateKey.newEncrypted("password");
57
- * const account = Account.fromCiphertext(ciphertext, "password");
58
- */
59
- static fromCiphertext(ciphertext, password) {
60
- try {
61
- ciphertext = (typeof ciphertext === "string") ? PrivateKeyCiphertext.fromString(ciphertext) : ciphertext;
62
- const _privateKey = PrivateKey.fromPrivateKeyCiphertext(ciphertext, password);
63
- return new Account({ privateKey: _privateKey.to_string() });
64
- }
65
- catch (e) {
66
- throw new Error("Wrong password or invalid ciphertext");
67
- }
68
- }
69
- privateKeyFromParams(params) {
70
- if (params.seed) {
71
- return PrivateKey.from_seed_unchecked(params.seed);
72
- }
73
- if (params.privateKey) {
74
- return PrivateKey.from_string(params.privateKey);
75
- }
76
- return new PrivateKey();
77
- }
78
- privateKey() {
79
- return this._privateKey;
80
- }
81
- viewKey() {
82
- return this._viewKey;
83
- }
84
- address() {
85
- return this._address;
86
- }
87
- toString() {
88
- return this.address().to_string();
89
- }
90
- /**
91
- * Encrypt the account's private key with a password
92
- * @param {string} ciphertext
93
- * @returns {PrivateKeyCiphertext}
94
- *
95
- * @example
96
- * const account = new Account();
97
- * const ciphertext = account.encryptAccount("password");
98
- */
99
- encryptAccount(password) {
100
- return this._privateKey.toCiphertext(password);
101
- }
102
- /**
103
- * Decrypts a Record in ciphertext form into plaintext
104
- * @param {string} ciphertext
105
- * @returns {Record}
106
- *
107
- * @example
108
- * const account = new Account();
109
- * const record = account.decryptRecord("record1ciphertext");
110
- */
111
- decryptRecord(ciphertext) {
112
- return this._viewKey.decrypt(ciphertext);
113
- }
114
- /**
115
- * Decrypts an array of Records in ciphertext form into plaintext
116
- * @param {string[]} ciphertexts
117
- * @returns {Record[]}
118
- *
119
- * @example
120
- * const account = new Account();
121
- * const record = account.decryptRecords(["record1ciphertext", "record2ciphertext"]);
122
- */
123
- decryptRecords(ciphertexts) {
124
- return ciphertexts.map((ciphertext) => this._viewKey.decrypt(ciphertext));
125
- }
126
- /**
127
- * Determines whether the account owns a ciphertext record
128
- * @param {RecordCipherText | string} ciphertext
129
- * @returns {boolean}
130
- *
131
- * @example
132
- * // Create a connection to the Aleo network and an account
133
- * const connection = new NodeConnection("vm.aleo.org/api");
134
- * const account = Account.fromCiphertext("ciphertext", "password");
135
- *
136
- * // Get a record from the network
137
- * const record = connection.getBlock(1234);
138
- * const recordCipherText = record.transactions[0].execution.transitions[0].id;
139
- *
140
- * // Check if the account owns the record
141
- * if account.ownsRecord(recordCipherText) {
142
- * // Then one can do something like:
143
- * // Decrypt the record and check if it's spent
144
- * // Store the record in a local database
145
- * // Etc.
146
- * }
147
- */
148
- ownsRecordCiphertext(ciphertext) {
149
- if (typeof ciphertext === 'string') {
150
- try {
151
- const ciphertextObject = RecordCiphertext.fromString(ciphertext);
152
- return ciphertextObject.isOwner(this._viewKey);
153
- }
154
- catch (e) {
155
- return false;
156
- }
3
+ function logAndThrow(message) {
4
+ console.error(message);
5
+ throw new Error(message);
6
+ }
7
+ function parseJSON(json) {
8
+ function revive(key, value, context) {
9
+ if (Number.isInteger(value)) {
10
+ return BigInt(context.source);
157
11
  }
158
12
  else {
159
- return ciphertext.isOwner(this._viewKey);
13
+ return value;
160
14
  }
161
15
  }
162
- /**
163
- * Signs a message with the account's private key.
164
- * Returns a Signature.
165
- *
166
- * @param {Uint8Array} message
167
- * @returns {Signature}
168
- *
169
- * @example
170
- * const account = new Account();
171
- * const message = Uint8Array.from([104, 101, 108, 108, 111 119, 111, 114, 108, 100])
172
- * account.sign(message);
173
- */
174
- sign(message) {
175
- return this._privateKey.sign(message);
176
- }
177
- /**
178
- * Verifies the Signature on a message.
179
- *
180
- * @param {Uint8Array} message
181
- * @param {Signature} signature
182
- * @returns {boolean}
183
- *
184
- * @example
185
- * const account = new Account();
186
- * const message = Uint8Array.from([104, 101, 108, 108, 111 119, 111, 114, 108, 100])
187
- * const signature = account.sign(message);
188
- * account.verify(message, signature);
189
- */
190
- verify(message, signature) {
191
- return this._address.verify(message, signature);
192
- }
16
+ return JSON.parse(json, revive);
193
17
  }
194
-
195
18
  async function get(url, options) {
196
19
  const response = await fetch(url, options);
197
20
  if (!response.ok) {
@@ -218,7 +41,7 @@ async function post(url, options) {
218
41
  * const localNetworkClient = new AleoNetworkClient("http://localhost:3030");
219
42
  *
220
43
  * // Connection to a public beacon node
221
- * const publicnetworkClient = new AleoNetworkClient("https://api.explorer.aleo.org/v1");
44
+ * const publicnetworkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1");
222
45
  */
223
46
  class AleoNetworkClient {
224
47
  host;
@@ -232,7 +55,7 @@ class AleoNetworkClient {
232
55
  else {
233
56
  this.headers = {
234
57
  // This is replaced by the actual version by a Rollup plugin
235
- "X-Aleo-SDK-Version": "0.6.12",
58
+ "X-Aleo-SDK-Version": "0.7.0",
236
59
  };
237
60
  }
238
61
  }
@@ -270,7 +93,8 @@ class AleoNetworkClient {
270
93
  const response = await get(this.host + url, {
271
94
  headers: this.headers
272
95
  });
273
- return await response.json();
96
+ const text = await response.text();
97
+ return parseJSON(text);
274
98
  }
275
99
  catch (error) {
276
100
  throw new Error("Error fetching data.");
@@ -365,49 +189,63 @@ class AleoNetworkClient {
365
189
  // Get 50 blocks (or the difference between the start and end if less than 50)
366
190
  const blocks = await this.getBlockRange(start, end);
367
191
  end = start;
368
- if (!(blocks instanceof Error)) {
369
- // Iterate through blocks to find unspent records
370
- for (let i = 0; i < blocks.length; i++) {
371
- const block = blocks[i];
372
- const transactions = block.transactions;
373
- if (!(typeof transactions === "undefined")) {
374
- for (let j = 0; j < transactions.length; j++) {
375
- const confirmedTransaction = transactions[j];
376
- // Search for unspent records in execute transactions of credits.aleo
377
- if (confirmedTransaction.type == "execute") {
378
- const transaction = confirmedTransaction.transaction;
379
- if (transaction.execution && !(typeof transaction.execution.transitions == "undefined")) {
380
- for (let k = 0; k < transaction.execution.transitions.length; k++) {
381
- const transition = transaction.execution.transitions[k];
382
- // Only search for unspent records in credits.aleo (for now)
383
- if (transition.program !== "credits.aleo") {
384
- continue;
385
- }
386
- if (!(typeof transition.outputs == "undefined")) {
387
- for (let l = 0; l < transition.outputs.length; l++) {
388
- const output = transition.outputs[l];
389
- if (output.type === "record") {
390
- try {
391
- // Create a wasm record ciphertext object from the found output
392
- const record = RecordCiphertext.fromString(output.value);
393
- // Determine if the record is owned by the specified view key
394
- if (record.isOwner(viewKey)) {
395
- // Decrypt the record and get the serial number
396
- const recordPlaintext = record.decrypt(viewKey);
397
- // If the record has already been found, skip it
398
- const nonce = recordPlaintext.nonce();
399
- if (nonces.includes(nonce)) {
400
- continue;
401
- }
402
- // Otherwise record the nonce that has been found
403
- const serialNumber = recordPlaintext.serialNumberString(resolvedPrivateKey, "credits.aleo", "credits");
404
- // Attempt to see if the serial number is spent
405
- try {
406
- await this.getTransitionId(serialNumber);
192
+ // Iterate through blocks to find unspent records
193
+ for (let i = 0; i < blocks.length; i++) {
194
+ const block = blocks[i];
195
+ const transactions = block.transactions;
196
+ if (!(typeof transactions === "undefined")) {
197
+ for (let j = 0; j < transactions.length; j++) {
198
+ const confirmedTransaction = transactions[j];
199
+ // Search for unspent records in execute transactions of credits.aleo
200
+ if (confirmedTransaction.type == "execute") {
201
+ const transaction = confirmedTransaction.transaction;
202
+ if (transaction.execution && !(typeof transaction.execution.transitions == "undefined")) {
203
+ for (let k = 0; k < transaction.execution.transitions.length; k++) {
204
+ const transition = transaction.execution.transitions[k];
205
+ // Only search for unspent records in credits.aleo (for now)
206
+ if (transition.program !== "credits.aleo") {
207
+ continue;
208
+ }
209
+ if (!(typeof transition.outputs == "undefined")) {
210
+ for (let l = 0; l < transition.outputs.length; l++) {
211
+ const output = transition.outputs[l];
212
+ if (output.type === "record") {
213
+ try {
214
+ // Create a wasm record ciphertext object from the found output
215
+ const record = RecordCiphertext.fromString(output.value);
216
+ // Determine if the record is owned by the specified view key
217
+ if (record.isOwner(viewKey)) {
218
+ // Decrypt the record and get the serial number
219
+ const recordPlaintext = record.decrypt(viewKey);
220
+ // If the record has already been found, skip it
221
+ const nonce = recordPlaintext.nonce();
222
+ if (nonces.includes(nonce)) {
223
+ continue;
224
+ }
225
+ // Otherwise record the nonce that has been found
226
+ const serialNumber = recordPlaintext.serialNumberString(resolvedPrivateKey, "credits.aleo", "credits");
227
+ // Attempt to see if the serial number is spent
228
+ try {
229
+ await this.getTransitionId(serialNumber);
230
+ }
231
+ catch (error) {
232
+ // If it's not found, add it to the list of unspent records
233
+ if (!amounts) {
234
+ records.push(recordPlaintext);
235
+ // If the user specified a maximum number of microcredits, check if the search has found enough
236
+ if (typeof maxMicrocredits === "number") {
237
+ totalRecordValue += recordPlaintext.microcredits();
238
+ // Exit if the search has found the amount specified
239
+ if (totalRecordValue >= BigInt(maxMicrocredits)) {
240
+ return records;
241
+ }
242
+ }
407
243
  }
408
- catch (error) {
409
- // If it's not found, add it to the list of unspent records
410
- if (!amounts) {
244
+ // If the user specified a list of amounts, check if the search has found them
245
+ if (!(typeof amounts === "undefined") && amounts.length > 0) {
246
+ let amounts_found = 0;
247
+ if (recordPlaintext.microcredits() > amounts[amounts_found]) {
248
+ amounts_found += 1;
411
249
  records.push(recordPlaintext);
412
250
  // If the user specified a maximum number of microcredits, check if the search has found enough
413
251
  if (typeof maxMicrocredits === "number") {
@@ -417,31 +255,15 @@ class AleoNetworkClient {
417
255
  return records;
418
256
  }
419
257
  }
420
- }
421
- // If the user specified a list of amounts, check if the search has found them
422
- if (!(typeof amounts === "undefined") && amounts.length > 0) {
423
- let amounts_found = 0;
424
- if (recordPlaintext.microcredits() > amounts[amounts_found]) {
425
- amounts_found += 1;
426
- records.push(recordPlaintext);
427
- // If the user specified a maximum number of microcredits, check if the search has found enough
428
- if (typeof maxMicrocredits === "number") {
429
- totalRecordValue += recordPlaintext.microcredits();
430
- // Exit if the search has found the amount specified
431
- if (totalRecordValue >= BigInt(maxMicrocredits)) {
432
- return records;
433
- }
434
- }
435
- if (records.length >= amounts.length) {
436
- return records;
437
- }
258
+ if (records.length >= amounts.length) {
259
+ return records;
438
260
  }
439
261
  }
440
262
  }
441
263
  }
442
264
  }
443
- catch (error) {
444
- }
265
+ }
266
+ catch (error) {
445
267
  }
446
268
  }
447
269
  }
@@ -495,7 +317,7 @@ class AleoNetworkClient {
495
317
  return await this.fetchData("/blocks?start=" + start + "&end=" + end);
496
318
  }
497
319
  catch (error) {
498
- const errorMessage = "Error fetching blocks between " + start + " and " + end + ".";
320
+ const errorMessage = `Error fetching blocks between ${start} and ${end}.`;
499
321
  throw new Error(errorMessage);
500
322
  }
501
323
  }
@@ -503,7 +325,7 @@ class AleoNetworkClient {
503
325
  * Returns the deployment transaction id associated with the specified program
504
326
  *
505
327
  * @param {Program | string} program
506
- * @returns {TransactionModel | Error}
328
+ * @returns {TransactionModel}
507
329
  */
508
330
  async getDeploymentTransactionIDForProgram(program) {
509
331
  if (program instanceof Program) {
@@ -521,7 +343,7 @@ class AleoNetworkClient {
521
343
  * Returns the deployment transaction associated with a specified program
522
344
  *
523
345
  * @param {Program | string} program
524
- * @returns {TransactionModel | Error}
346
+ * @returns {TransactionModel}
525
347
  */
526
348
  async getDeploymentTransactionForProgram(program) {
527
349
  try {
@@ -540,7 +362,7 @@ class AleoNetworkClient {
540
362
  */
541
363
  async getLatestBlock() {
542
364
  try {
543
- return await this.fetchData("/latest/block");
365
+ return await this.fetchData("/block/latest");
544
366
  }
545
367
  catch (error) {
546
368
  throw new Error("Error fetching latest block.");
@@ -567,7 +389,7 @@ class AleoNetworkClient {
567
389
  */
568
390
  async getLatestHeight() {
569
391
  try {
570
- return await this.fetchData("/latest/height");
392
+ return Number(await this.fetchData("/block/height/latest"));
571
393
  }
572
394
  catch (error) {
573
395
  throw new Error("Error fetching latest height.");
@@ -596,7 +418,7 @@ class AleoNetworkClient {
596
418
  * Returns a program object from a program ID or program source code
597
419
  *
598
420
  * @param {string} inputProgram The program ID or program source code of a program deployed to the Aleo Network
599
- * @return {Promise<Program | Error>} Source code of the program
421
+ * @return {Promise<Program>} Source code of the program
600
422
  *
601
423
  * @example
602
424
  * const programID = "hello_hello.aleo";
@@ -671,7 +493,7 @@ class AleoNetworkClient {
671
493
  return imports;
672
494
  }
673
495
  catch (error) {
674
- throw logAndThrow("Error fetching program imports: " + error);
496
+ logAndThrow("Error fetching program imports: " + error.message);
675
497
  }
676
498
  }
677
499
  /**
@@ -691,7 +513,7 @@ class AleoNetworkClient {
691
513
  return program.getImports();
692
514
  }
693
515
  catch (error) {
694
- throw new Error("Error fetching program imports with error: " + error);
516
+ throw new Error("Error fetching program imports with error: " + error.message);
695
517
  }
696
518
  }
697
519
  /**
@@ -741,7 +563,7 @@ class AleoNetworkClient {
741
563
  */
742
564
  async getStateRoot() {
743
565
  try {
744
- return await this.fetchData("/latest/stateRoot");
566
+ return await this.fetchData("/stateRoot/latest");
745
567
  }
746
568
  catch (error) {
747
569
  throw new Error("Error fetching Aleo state root");
@@ -810,7 +632,7 @@ class AleoNetworkClient {
810
632
  * Submit an execute or deployment transaction to the Aleo network
811
633
  *
812
634
  * @param {Transaction | string} transaction - The transaction to submit to the network
813
- * @returns {string | Error} - The transaction id of the submitted transaction or the resulting error
635
+ * @returns {string} - The transaction id of the submitted transaction or the resulting error
814
636
  */
815
637
  async submitTransaction(transaction) {
816
638
  const transaction_string = transaction instanceof Transaction ? transaction.toString() : transaction;
@@ -822,7 +644,8 @@ class AleoNetworkClient {
822
644
  }),
823
645
  });
824
646
  try {
825
- return await response.json();
647
+ const text = await response.text();
648
+ return parseJSON(text);
826
649
  }
827
650
  catch (error) {
828
651
  throw new Error(`Error posting transaction. Aleo network response: ${error.message}`);
@@ -834,6 +657,100 @@ class AleoNetworkClient {
834
657
  }
835
658
  }
836
659
 
660
+ const KEY_STORE = Metadata.baseUrl();
661
+ function convert(metadata) {
662
+ // This looks up the method name in VerifyingKey
663
+ const verifyingKey = VerifyingKey[metadata.verifyingKey];
664
+ if (!verifyingKey) {
665
+ throw new Error("Invalid method name: " + metadata.verifyingKey);
666
+ }
667
+ return {
668
+ name: metadata.name,
669
+ locator: metadata.locator,
670
+ prover: metadata.prover,
671
+ verifier: metadata.verifier,
672
+ verifyingKey,
673
+ };
674
+ }
675
+ const CREDITS_PROGRAM_KEYS = {
676
+ bond_public: convert(Metadata.bond_public()),
677
+ bond_validator: convert(Metadata.bond_validator()),
678
+ claim_unbond_public: convert(Metadata.claim_unbond_public()),
679
+ fee_private: convert(Metadata.fee_private()),
680
+ fee_public: convert(Metadata.fee_public()),
681
+ inclusion: convert(Metadata.inclusion()),
682
+ join: convert(Metadata.join()),
683
+ set_validator_state: convert(Metadata.set_validator_state()),
684
+ split: convert(Metadata.split()),
685
+ transfer_private: convert(Metadata.transfer_private()),
686
+ transfer_private_to_public: convert(Metadata.transfer_private_to_public()),
687
+ transfer_public: convert(Metadata.transfer_public()),
688
+ transfer_public_as_signer: convert(Metadata.transfer_public_as_signer()),
689
+ transfer_public_to_private: convert(Metadata.transfer_public_to_private()),
690
+ unbond_public: convert(Metadata.unbond_public()),
691
+ getKey: function (key) {
692
+ if (this.hasOwnProperty(key)) {
693
+ return this[key];
694
+ }
695
+ else {
696
+ throw new Error(`Key "${key}" not found.`);
697
+ }
698
+ }
699
+ };
700
+ const PRIVATE_TRANSFER_TYPES = new Set([
701
+ "transfer_private",
702
+ "private",
703
+ "transferPrivate",
704
+ "transfer_private_to_public",
705
+ "privateToPublic",
706
+ "transferPrivateToPublic",
707
+ ]);
708
+ const VALID_TRANSFER_TYPES = new Set([
709
+ "transfer_private",
710
+ "private",
711
+ "transferPrivate",
712
+ "transfer_private_to_public",
713
+ "privateToPublic",
714
+ "transferPrivateToPublic",
715
+ "transfer_public",
716
+ "transfer_public_as_signer",
717
+ "public",
718
+ "public_as_signer",
719
+ "transferPublic",
720
+ "transferPublicAsSigner",
721
+ "transfer_public_to_private",
722
+ "publicToPrivate",
723
+ "publicAsSigner",
724
+ "transferPublicToPrivate",
725
+ ]);
726
+ const PRIVATE_TRANSFER = new Set([
727
+ "private",
728
+ "transfer_private",
729
+ "transferPrivate",
730
+ ]);
731
+ const PRIVATE_TO_PUBLIC_TRANSFER = new Set([
732
+ "private_to_public",
733
+ "privateToPublic",
734
+ "transfer_private_to_public",
735
+ "transferPrivateToPublic",
736
+ ]);
737
+ const PUBLIC_TRANSFER = new Set([
738
+ "public",
739
+ "transfer_public",
740
+ "transferPublic",
741
+ ]);
742
+ const PUBLIC_TRANSFER_AS_SIGNER = new Set([
743
+ "public_as_signer",
744
+ "transfer_public_as_signer",
745
+ "transferPublicAsSigner",
746
+ ]);
747
+ const PUBLIC_TO_PRIVATE_TRANSFER = new Set([
748
+ "public_to_private",
749
+ "publicToPrivate",
750
+ "transfer_public_to_private",
751
+ "transferPublicToPrivate",
752
+ ]);
753
+
837
754
  /**
838
755
  * AleoKeyProviderParams search parameter for the AleoKeyProvider. It allows for the specification of a proverUri and
839
756
  * verifierUri to fetch keys via HTTP from a remote resource as well as a unique cacheKey to store the keys in memory.
@@ -874,7 +791,7 @@ class AleoKeyProvider {
874
791
  return new Uint8Array(data);
875
792
  }
876
793
  catch (error) {
877
- throw new Error("Error fetching data." + error);
794
+ throw new Error("Error fetching data." + error.message);
878
795
  }
879
796
  }
880
797
  constructor() {
@@ -929,7 +846,7 @@ class AleoKeyProvider {
929
846
  * Get a set of keys from the cache
930
847
  * @param keyId keyId of a proving and verifying key pair
931
848
  *
932
- * @returns {FunctionKeyPair | Error} Proving and verifying keys for the specified program
849
+ * @returns {FunctionKeyPair} Proving and verifying keys for the specified program
933
850
  */
934
851
  getKeys(keyId) {
935
852
  console.debug(`Checking if key exists in cache. KeyId: ${keyId}`);
@@ -938,23 +855,23 @@ class AleoKeyProvider {
938
855
  return [ProvingKey.fromBytes(provingKeyBytes), VerifyingKey.fromBytes(verifyingKeyBytes)];
939
856
  }
940
857
  else {
941
- return new Error("Key not found in cache.");
858
+ throw new Error("Key not found in cache.");
942
859
  }
943
860
  }
944
861
  /**
945
862
  * Get arbitrary function keys from a provider
946
863
  *
947
864
  * @param {KeySearchParams} params parameters for the key search in form of: {proverUri: string, verifierUri: string, cacheKey: string}
948
- * @returns {Promise<FunctionKeyPair | Error>} Proving and verifying keys for the specified program
865
+ * @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the specified program
949
866
  *
950
867
  * @example
951
868
  * // Create a new object which implements the KeyProvider interface
952
- * const networkClient = new AleoNetworkClient("https://api.explorer.aleo.org/v1");
869
+ * const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1");
953
870
  * const keyProvider = new AleoKeyProvider();
954
871
  * const recordProvider = new NetworkRecordProvider(account, networkClient);
955
872
  *
956
873
  * // Initialize a program manager with the key provider to automatically fetch keys for value transfers
957
- * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, recordProvider);
874
+ * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider);
958
875
  * programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
959
876
  *
960
877
  * // Keys can also be fetched manually using the key provider
@@ -968,9 +885,7 @@ class AleoKeyProvider {
968
885
  let cacheKey;
969
886
  if ("name" in params && typeof params["name"] == "string") {
970
887
  let key = CREDITS_PROGRAM_KEYS.getKey(params["name"]);
971
- if (!(key instanceof Error)) {
972
- return this.fetchCreditsKeys(key);
973
- }
888
+ return this.fetchCreditsKeys(key);
974
889
  }
975
890
  if ("proverUri" in params && typeof params["proverUri"] == "string") {
976
891
  proverUrl = params["proverUri"];
@@ -988,7 +903,7 @@ class AleoKeyProvider {
988
903
  return this.getKeys(cacheKey);
989
904
  }
990
905
  }
991
- throw Error("Invalid parameters provided, must provide either a cacheKey and/or a proverUrl and a verifierUrl");
906
+ throw new Error("Invalid parameters provided, must provide either a cacheKey and/or a proverUrl and a verifierUrl");
992
907
  }
993
908
  /**
994
909
  * Returns the proving and verifying keys for a specified program from a specified url.
@@ -997,16 +912,16 @@ class AleoKeyProvider {
997
912
  * @param {string} proverUrl Url the verifying key
998
913
  * @param {string} cacheKey Key to store the keys in the cache
999
914
  *
1000
- * @returns {Promise<FunctionKeyPair | Error>} Proving and verifying keys for the specified program
915
+ * @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the specified program
1001
916
  *
1002
917
  * @example
1003
918
  * // Create a new AleoKeyProvider object
1004
- * const networkClient = new AleoNetworkClient("https://api.explorer.aleo.org/v1");
919
+ * const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1");
1005
920
  * const keyProvider = new AleoKeyProvider();
1006
921
  * const recordProvider = new NetworkRecordProvider(account, networkClient);
1007
922
  *
1008
923
  * // Initialize a program manager with the key provider to automatically fetch keys for value transfers
1009
- * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, recordProvider);
924
+ * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider);
1010
925
  * programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
1011
926
  *
1012
927
  * // Keys can also be fetched manually
@@ -1043,7 +958,7 @@ class AleoKeyProvider {
1043
958
  }
1044
959
  }
1045
960
  catch (error) {
1046
- throw new Error(`Error: ${error} fetching fee proving and verifying keys from ${proverUrl} and ${verifierUrl}.`);
961
+ throw new Error(`Error: ${error.message} fetching fee proving and verifying keys from ${proverUrl} and ${verifierUrl}.`);
1047
962
  }
1048
963
  }
1049
964
  /***
@@ -1052,7 +967,7 @@ class AleoKeyProvider {
1052
967
  * @param proverUrl
1053
968
  * @param cacheKey
1054
969
  *
1055
- * @returns {Promise<ProvingKey | Error>} Proving key for the specified program
970
+ * @returns {Promise<ProvingKey>} Proving key for the specified program
1056
971
  */
1057
972
  async fetchProvingKey(proverUrl, cacheKey) {
1058
973
  try {
@@ -1077,7 +992,7 @@ class AleoKeyProvider {
1077
992
  }
1078
993
  }
1079
994
  catch (error) {
1080
- throw new Error(`Error: ${error} fetching fee proving keys from ${proverUrl}`);
995
+ throw new Error(`Error: ${error.message} fetching fee proving keys from ${proverUrl}`);
1081
996
  }
1082
997
  }
1083
998
  async fetchCreditsKeys(key) {
@@ -1092,882 +1007,153 @@ class AleoKeyProvider {
1092
1007
  }
1093
1008
  else {
1094
1009
  const keyPair = this.cache.get(key.locator);
1095
- return [ProvingKey.fromBytes(keyPair[0]), VerifyingKey.fromBytes(keyPair[1])];
1096
- }
1097
- }
1098
- catch (error) {
1099
- throw new Error(`Error: fetching credits.aleo keys: ${error}`);
1100
- }
1101
- }
1102
- async bondPublicKeys() {
1103
- return this.fetchCreditsKeys(CREDITS_PROGRAM_KEYS.bond_public);
1104
- }
1105
- bondValidatorKeys() {
1106
- return this.fetchCreditsKeys(CREDITS_PROGRAM_KEYS.bond_validator);
1107
- }
1108
- claimUnbondPublicKeys() {
1109
- return this.fetchCreditsKeys(CREDITS_PROGRAM_KEYS.claim_unbond_public);
1110
- }
1111
- /**
1112
- * Returns the proving and verifying keys for the transfer functions in the credits.aleo program
1113
- * @param {string} visibility Visibility of the transfer function
1114
- * @returns {Promise<FunctionKeyPair | Error>} Proving and verifying keys for the transfer functions
1115
- *
1116
- * @example
1117
- * // Create a new AleoKeyProvider
1118
- * const networkClient = new AleoNetworkClient("https://api.explorer.aleo.org/v1");
1119
- * const keyProvider = new AleoKeyProvider();
1120
- * const recordProvider = new NetworkRecordProvider(account, networkClient);
1121
- *
1122
- * // Initialize a program manager with the key provider to automatically fetch keys for value transfers
1123
- * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, recordProvider);
1124
- * programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
1125
- *
1126
- * // Keys can also be fetched manually
1127
- * const [transferPublicProvingKey, transferPublicVerifyingKey] = await keyProvider.transferKeys("public");
1128
- */
1129
- async transferKeys(visibility) {
1130
- if (PRIVATE_TRANSFER.has(visibility)) {
1131
- return await this.fetchCreditsKeys(CREDITS_PROGRAM_KEYS.transfer_private);
1132
- }
1133
- else if (PRIVATE_TO_PUBLIC_TRANSFER.has(visibility)) {
1134
- return await this.fetchCreditsKeys(CREDITS_PROGRAM_KEYS.transfer_private_to_public);
1135
- }
1136
- else if (PUBLIC_TRANSFER.has(visibility)) {
1137
- return await this.fetchCreditsKeys(CREDITS_PROGRAM_KEYS.transfer_public);
1138
- }
1139
- else if (PUBLIC_TRANSFER_AS_SIGNER.has(visibility)) {
1140
- return await this.fetchCreditsKeys(CREDITS_PROGRAM_KEYS.transfer_public_as_signer);
1141
- }
1142
- else if (PUBLIC_TO_PRIVATE_TRANSFER.has(visibility)) {
1143
- return await this.fetchCreditsKeys(CREDITS_PROGRAM_KEYS.transfer_public_to_private);
1144
- }
1145
- else {
1146
- throw new Error("Invalid visibility type");
1147
- }
1148
- }
1149
- /**
1150
- * Returns the proving and verifying keys for the join function in the credits.aleo program
1151
- *
1152
- * @returns {Promise<FunctionKeyPair | Error>} Proving and verifying keys for the join function
1153
- */
1154
- async joinKeys() {
1155
- return await this.fetchCreditsKeys(CREDITS_PROGRAM_KEYS.join);
1156
- }
1157
- /**
1158
- * Returns the proving and verifying keys for the split function in the credits.aleo program
1159
- *
1160
- * @returns {Promise<FunctionKeyPair | Error>} Proving and verifying keys for the split function
1161
- * */
1162
- async splitKeys() {
1163
- return await this.fetchCreditsKeys(CREDITS_PROGRAM_KEYS.split);
1164
- }
1165
- /**
1166
- * Returns the proving and verifying keys for the fee_private function in the credits.aleo program
1167
- *
1168
- * @returns {Promise<FunctionKeyPair | Error>} Proving and verifying keys for the fee function
1169
- */
1170
- async feePrivateKeys() {
1171
- return await this.fetchCreditsKeys(CREDITS_PROGRAM_KEYS.fee_private);
1172
- }
1173
- /**
1174
- * Returns the proving and verifying keys for the fee_public function in the credits.aleo program
1175
- *
1176
- * @returns {Promise<FunctionKeyPair | Error>} Proving and verifying keys for the fee function
1177
- */
1178
- async feePublicKeys() {
1179
- return await this.fetchCreditsKeys(CREDITS_PROGRAM_KEYS.fee_public);
1180
- }
1181
- /**
1182
- * Gets a verifying key. If the verifying key is for a credits.aleo function, get it from the wasm cache otherwise
1183
- *
1184
- * @returns {Promise<VerifyingKey | Error>} Verifying key for the function
1185
- */
1186
- // attempt to fetch it from the network
1187
- async getVerifyingKey(verifierUri) {
1188
- switch (verifierUri) {
1189
- case CREDITS_PROGRAM_KEYS.bond_public.verifier:
1190
- return CREDITS_PROGRAM_KEYS.bond_public.verifyingKey();
1191
- case CREDITS_PROGRAM_KEYS.bond_validator.verifier:
1192
- return CREDITS_PROGRAM_KEYS.bond_validator.verifyingKey();
1193
- case CREDITS_PROGRAM_KEYS.claim_unbond_public.verifier:
1194
- return CREDITS_PROGRAM_KEYS.claim_unbond_public.verifyingKey();
1195
- case CREDITS_PROGRAM_KEYS.fee_private.verifier:
1196
- return CREDITS_PROGRAM_KEYS.fee_private.verifyingKey();
1197
- case CREDITS_PROGRAM_KEYS.fee_public.verifier:
1198
- return CREDITS_PROGRAM_KEYS.fee_public.verifyingKey();
1199
- case CREDITS_PROGRAM_KEYS.inclusion.verifier:
1200
- return CREDITS_PROGRAM_KEYS.inclusion.verifyingKey();
1201
- case CREDITS_PROGRAM_KEYS.join.verifier:
1202
- return CREDITS_PROGRAM_KEYS.join.verifyingKey();
1203
- case CREDITS_PROGRAM_KEYS.set_validator_state.verifier:
1204
- return CREDITS_PROGRAM_KEYS.set_validator_state.verifyingKey();
1205
- case CREDITS_PROGRAM_KEYS.split.verifier:
1206
- return CREDITS_PROGRAM_KEYS.split.verifyingKey();
1207
- case CREDITS_PROGRAM_KEYS.transfer_private.verifier:
1208
- return CREDITS_PROGRAM_KEYS.transfer_private.verifyingKey();
1209
- case CREDITS_PROGRAM_KEYS.transfer_private_to_public.verifier:
1210
- return CREDITS_PROGRAM_KEYS.transfer_private_to_public.verifyingKey();
1211
- case CREDITS_PROGRAM_KEYS.transfer_public.verifier:
1212
- return CREDITS_PROGRAM_KEYS.transfer_public.verifyingKey();
1213
- case CREDITS_PROGRAM_KEYS.transfer_public_as_signer.verifier:
1214
- return CREDITS_PROGRAM_KEYS.transfer_public_as_signer.verifyingKey();
1215
- case CREDITS_PROGRAM_KEYS.transfer_public_to_private.verifier:
1216
- return CREDITS_PROGRAM_KEYS.transfer_public_to_private.verifyingKey();
1217
- case CREDITS_PROGRAM_KEYS.unbond_public.verifier:
1218
- return CREDITS_PROGRAM_KEYS.unbond_public.verifyingKey();
1219
- default:
1220
- try {
1221
- /// Try to fetch the verifying key from the network as a string
1222
- const response = await get(verifierUri);
1223
- const text = await response.text();
1224
- return VerifyingKey.fromString(text);
1225
- }
1226
- catch (e) {
1227
- /// If that fails, try to fetch the verifying key from the network as bytes
1228
- try {
1229
- return VerifyingKey.fromBytes(await this.fetchBytes(verifierUri));
1230
- }
1231
- catch (inner) {
1232
- return new Error("Invalid verifying key. Error: " + inner);
1233
- }
1234
- }
1235
- }
1236
- }
1237
- unBondPublicKeys() {
1238
- return this.fetchCreditsKeys(CREDITS_PROGRAM_KEYS.unbond_public);
1239
- }
1240
- }
1241
-
1242
- /**
1243
- * Search parameters for the offline key provider. This class implements the KeySearchParams interface and includes
1244
- * a convenience method for creating a new instance of this class for each function of the credits.aleo program.
1245
- *
1246
- * @example
1247
- * // If storing a key for a custom program function
1248
- * offlineSearchParams = new OfflineSearchParams("myprogram.aleo/myfunction");
1249
- *
1250
- * // If storing a key for a credits.aleo program function
1251
- * bondPublicKeyParams = OfflineSearchParams.bondPublicKeyParams();
1252
- */
1253
- class OfflineSearchParams {
1254
- cacheKey;
1255
- verifyCreditsKeys;
1256
- /**
1257
- * Create a new OfflineSearchParams instance.
1258
- *
1259
- * @param {string} cacheKey - Key used to store the local function proving & verifying keys. This should be stored
1260
- * under the naming convention "programName/functionName" (i.e. "myprogram.aleo/myfunction")
1261
- * @param {boolean} verifyCreditsKeys - Whether to verify the keys against the credits.aleo program,
1262
- * defaults to false, but should be set to true if using keys from the credits.aleo program
1263
- */
1264
- constructor(cacheKey, verifyCreditsKeys = false) {
1265
- this.cacheKey = cacheKey;
1266
- this.verifyCreditsKeys = verifyCreditsKeys;
1267
- }
1268
- /**
1269
- * Create a new OfflineSearchParams instance for the bond_public function of the credits.aleo program.
1270
- */
1271
- static bondPublicKeyParams() {
1272
- return new OfflineSearchParams(CREDITS_PROGRAM_KEYS.bond_public.locator, true);
1273
- }
1274
- /**
1275
- * Create a new OfflineSearchParams instance for the bond_validator function of the credits.aleo program.
1276
- */
1277
- static bondValidatorKeyParams() {
1278
- return new OfflineSearchParams(CREDITS_PROGRAM_KEYS.bond_validator.locator, true);
1279
- }
1280
- /**
1281
- * Create a new OfflineSearchParams instance for the claim_unbond_public function of the
1282
- */
1283
- static claimUnbondPublicKeyParams() {
1284
- return new OfflineSearchParams(CREDITS_PROGRAM_KEYS.claim_unbond_public.locator, true);
1285
- }
1286
- /**
1287
- * Create a new OfflineSearchParams instance for the fee_private function of the credits.aleo program.
1288
- */
1289
- static feePrivateKeyParams() {
1290
- return new OfflineSearchParams(CREDITS_PROGRAM_KEYS.fee_private.locator, true);
1291
- }
1292
- /**
1293
- * Create a new OfflineSearchParams instance for the fee_public function of the credits.aleo program.
1294
- */
1295
- static feePublicKeyParams() {
1296
- return new OfflineSearchParams(CREDITS_PROGRAM_KEYS.fee_public.locator, true);
1297
- }
1298
- /**
1299
- * Create a new OfflineSearchParams instance for the inclusion prover function.
1300
- */
1301
- static inclusionKeyParams() {
1302
- return new OfflineSearchParams(CREDITS_PROGRAM_KEYS.inclusion.locator, true);
1303
- }
1304
- /**
1305
- * Create a new OfflineSearchParams instance for the join function of the credits.aleo program.
1306
- */
1307
- static joinKeyParams() {
1308
- return new OfflineSearchParams(CREDITS_PROGRAM_KEYS.join.locator, true);
1309
- }
1310
- /**
1311
- * Create a new OfflineSearchParams instance for the set_validator_state function of the credits.aleo program.
1312
- */
1313
- static setValidatorStateKeyParams() {
1314
- return new OfflineSearchParams(CREDITS_PROGRAM_KEYS.set_validator_state.locator, true);
1315
- }
1316
- /**
1317
- * Create a new OfflineSearchParams instance for the split function of the credits.aleo program.
1318
- */
1319
- static splitKeyParams() {
1320
- return new OfflineSearchParams(CREDITS_PROGRAM_KEYS.split.locator, true);
1321
- }
1322
- /**
1323
- * Create a new OfflineSearchParams instance for the transfer_private function of the credits.aleo program.
1324
- */
1325
- static transferPrivateKeyParams() {
1326
- return new OfflineSearchParams(CREDITS_PROGRAM_KEYS.transfer_private.locator, true);
1327
- }
1328
- /**
1329
- * Create a new OfflineSearchParams instance for the transfer_private_to_public function of the credits.aleo program.
1330
- */
1331
- static transferPrivateToPublicKeyParams() {
1332
- return new OfflineSearchParams(CREDITS_PROGRAM_KEYS.transfer_private_to_public.locator, true);
1333
- }
1334
- /**
1335
- * Create a new OfflineSearchParams instance for the transfer_public function of the credits.aleo program.
1336
- */
1337
- static transferPublicKeyParams() {
1338
- return new OfflineSearchParams(CREDITS_PROGRAM_KEYS.transfer_public.locator, true);
1339
- }
1340
- /**
1341
- * Create a new OfflineSearchParams instance for the transfer_public_as_signer function of the credits.aleo program.
1342
- */
1343
- static transferPublicAsSignerKeyParams() {
1344
- return new OfflineSearchParams(CREDITS_PROGRAM_KEYS.transfer_public_as_signer.locator, true);
1345
- }
1346
- /**
1347
- * Create a new OfflineSearchParams instance for the transfer_public_to_private function of the credits.aleo program.
1348
- */
1349
- static transferPublicToPrivateKeyParams() {
1350
- return new OfflineSearchParams(CREDITS_PROGRAM_KEYS.transfer_public_to_private.locator, true);
1351
- }
1352
- /**
1353
- * Create a new OfflineSearchParams instance for the unbond_public function of the credits.aleo program.
1354
- */
1355
- static unbondPublicKeyParams() {
1356
- return new OfflineSearchParams(CREDITS_PROGRAM_KEYS.unbond_public.locator, true);
1357
- }
1358
- }
1359
- /**
1360
- * A key provider meant for building transactions offline on devices such as hardware wallets. This key provider is not
1361
- * able to contact the internet for key material and instead relies on the user to insert Aleo function proving &
1362
- * verifying keys from local storage prior to usage.
1363
- *
1364
- * @example
1365
- * // Create an offline program manager
1366
- * const programManager = new ProgramManager();
1367
- *
1368
- * // Create a temporary account for the execution of the program
1369
- * const account = new Account();
1370
- * programManager.setAccount(account);
1371
- *
1372
- * // Create the proving keys from the key bytes on the offline machine
1373
- * console.log("Creating proving keys from local key files");
1374
- * 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;";
1375
- * const myFunctionProver = await getLocalKey("/path/to/my/function/hello_hello.prover");
1376
- * const myFunctionVerifier = await getLocalKey("/path/to/my/function/hello_hello.verifier");
1377
- * const feePublicProvingKeyBytes = await getLocalKey("/path/to/credits.aleo/feePublic.prover");
1378
- *
1379
- * myFunctionProvingKey = ProvingKey.fromBytes(myFunctionProver);
1380
- * myFunctionVerifyingKey = VerifyingKey.fromBytes(myFunctionVerifier);
1381
- * const feePublicProvingKey = ProvingKey.fromBytes(feePublicKeyBytes);
1382
- *
1383
- * // Create an offline key provider
1384
- * console.log("Creating offline key provider");
1385
- * const offlineKeyProvider = new OfflineKeyProvider();
1386
- *
1387
- * // Cache the keys
1388
- * // Cache the proving and verifying keys for the custom hello function
1389
- * OfflineKeyProvider.cacheKeys("hello_hello.aleo/hello", myFunctionProvingKey, myFunctionVerifyingKey);
1390
- *
1391
- * // Cache the proving key for the fee_public function (the verifying key is automatically cached)
1392
- * OfflineKeyProvider.insertFeePublicKey(feePublicProvingKey);
1393
- *
1394
- * // Create an offline query using the latest state root in order to create the inclusion proof
1395
- * const offlineQuery = new OfflineQuery("latestStateRoot");
1396
- *
1397
- * // Insert the key provider into the program manager
1398
- * programManager.setKeyProvider(offlineKeyProvider);
1399
- *
1400
- * // Create the offline search params
1401
- * const offlineSearchParams = new OfflineSearchParams("hello_hello.aleo/hello");
1402
- *
1403
- * // Create the offline transaction
1404
- * const offlineExecuteTx = <Transaction>await this.buildExecutionTransaction("hello_hello.aleo", "hello", 1, false, ["5u32", "5u32"], undefined, offlineSearchParams, undefined, undefined, undefined, undefined, offlineQuery, program);
1405
- *
1406
- * // Broadcast the transaction later on a machine with internet access
1407
- * const networkClient = new AleoNetworkClient("https://api.explorer.aleo.org/v1");
1408
- * const txId = await networkClient.broadcastTransaction(offlineExecuteTx);
1409
- */
1410
- class OfflineKeyProvider {
1411
- cache;
1412
- constructor() {
1413
- this.cache = new Map();
1414
- }
1415
- /**
1416
- * Get bond_public function keys from the credits.aleo program. The keys must be cached prior to calling this
1417
- * method for it to work.
1418
- *
1419
- * @returns {Promise<FunctionKeyPair | Error>} Proving and verifying keys for the bond_public function
1420
- */
1421
- bondPublicKeys() {
1422
- return this.functionKeys(OfflineSearchParams.bondPublicKeyParams());
1423
- }
1424
- ;
1425
- /**
1426
- * Get bond_validator function keys from the credits.aleo program. The keys must be cached prior to calling this
1427
- * method for it to work.
1428
- *
1429
- * @returns {Promise<FunctionKeyPair | Error>} Proving and verifying keys for the bond_public function
1430
- */
1431
- bondValidatorKeys() {
1432
- return this.functionKeys(OfflineSearchParams.bondValidatorKeyParams());
1433
- }
1434
- ;
1435
- /**
1436
- * Cache a set of keys. This will overwrite any existing keys with the same keyId. The user can check if a keyId
1437
- * exists in the cache using the containsKeys method prior to calling this method if overwriting is not desired.
1438
- *
1439
- * @param {string} keyId access key for the cache
1440
- * @param {FunctionKeyPair} keys keys to cache
1441
- */
1442
- cacheKeys(keyId, keys) {
1443
- const [provingKey, verifyingKey] = keys;
1444
- this.cache.set(keyId, [provingKey.toBytes(), verifyingKey.toBytes()]);
1445
- }
1446
- ;
1447
- /**
1448
- * Get unbond_public function keys from the credits.aleo program. The keys must be cached prior to calling this
1449
- * method for it to work.
1450
- *
1451
- * @returns {Promise<FunctionKeyPair | Error>} Proving and verifying keys for the unbond_public function
1452
- */
1453
- claimUnbondPublicKeys() {
1454
- return this.functionKeys(OfflineSearchParams.claimUnbondPublicKeyParams());
1455
- }
1456
- ;
1457
- /**
1458
- * Get arbitrary function key from the offline key provider cache.
1459
- *
1460
- * @param {KeySearchParams | undefined} params - Optional search parameters for the key provider
1461
- * @returns {Promise<FunctionKeyPair | Error>} Proving and verifying keys for the specified program
1462
- *
1463
- * @example
1464
- * /// First cache the keys from local offline resources
1465
- * const offlineKeyProvider = new OfflineKeyProvider();
1466
- * const myFunctionVerifyingKey = VerifyingKey.fromString("verifier...");
1467
- * const myFunctionProvingKeyBytes = await readBinaryFile('./resources/myfunction.prover');
1468
- * const myFunctionProvingKey = ProvingKey.fromBytes(myFunctionProvingKeyBytes);
1469
- *
1470
- * /// Cache the keys for future use with a memorable locator
1471
- * offlineKeyProvider.cacheKeys("myprogram.aleo/myfunction", [myFunctionProvingKey, myFunctionVerifyingKey]);
1472
- *
1473
- * /// When they're needed, retrieve the keys from the cache
1474
- *
1475
- * /// First create a search parameter object with the same locator used to cache the keys
1476
- * const keyParams = new OfflineSearchParams("myprogram.aleo/myfunction");
1477
- *
1478
- * /// Then retrieve the keys
1479
- * const [myFunctionProver, myFunctionVerifier] = await offlineKeyProvider.functionKeys(keyParams);
1480
- */
1481
- functionKeys(params) {
1482
- return new Promise((resolve, reject) => {
1483
- if (params === undefined) {
1484
- reject(new Error("No search parameters provided, cannot retrieve keys"));
1485
- }
1486
- else {
1487
- const keyId = params.cacheKey;
1488
- const verifyCreditsKeys = params.verifyCreditsKeys;
1489
- if (this.cache.has(keyId)) {
1490
- const [provingKeyBytes, verifyingKeyBytes] = this.cache.get(keyId);
1491
- const provingKey = ProvingKey.fromBytes(provingKeyBytes);
1492
- const verifyingKey = VerifyingKey.fromBytes(verifyingKeyBytes);
1493
- if (verifyCreditsKeys) {
1494
- const keysMatchExpected = this.verifyCreditsKeys(keyId, provingKey, verifyingKey);
1495
- if (!keysMatchExpected) {
1496
- reject(new Error(`Cached keys do not match expected keys for ${keyId}`));
1497
- }
1498
- }
1499
- resolve([provingKey, verifyingKey]);
1500
- }
1501
- else {
1502
- reject(new Error("Keys not found in cache for " + keyId));
1503
- }
1504
- }
1505
- });
1506
- }
1507
- ;
1508
- /**
1509
- * Determines if the keys for a given credits function match the expected keys.
1510
- *
1511
- * @returns {boolean} Whether the keys match the expected keys
1512
- */
1513
- verifyCreditsKeys(locator, provingKey, verifyingKey) {
1514
- switch (locator) {
1515
- case CREDITS_PROGRAM_KEYS.bond_public.locator:
1516
- return provingKey.isBondPublicProver() && verifyingKey.isBondPublicVerifier();
1517
- case CREDITS_PROGRAM_KEYS.claim_unbond_public.locator:
1518
- return provingKey.isClaimUnbondPublicProver() && verifyingKey.isClaimUnbondPublicVerifier();
1519
- case CREDITS_PROGRAM_KEYS.fee_private.locator:
1520
- return provingKey.isFeePrivateProver() && verifyingKey.isFeePrivateVerifier();
1521
- case CREDITS_PROGRAM_KEYS.fee_public.locator:
1522
- return provingKey.isFeePublicProver() && verifyingKey.isFeePublicVerifier();
1523
- case CREDITS_PROGRAM_KEYS.inclusion.locator:
1524
- return provingKey.isInclusionProver() && verifyingKey.isInclusionVerifier();
1525
- case CREDITS_PROGRAM_KEYS.join.locator:
1526
- return provingKey.isJoinProver() && verifyingKey.isJoinVerifier();
1527
- case CREDITS_PROGRAM_KEYS.set_validator_state.locator:
1528
- return provingKey.isSetValidatorStateProver() && verifyingKey.isSetValidatorStateVerifier();
1529
- case CREDITS_PROGRAM_KEYS.split.locator:
1530
- return provingKey.isSplitProver() && verifyingKey.isSplitVerifier();
1531
- case CREDITS_PROGRAM_KEYS.transfer_private.locator:
1532
- return provingKey.isTransferPrivateProver() && verifyingKey.isTransferPrivateVerifier();
1533
- case CREDITS_PROGRAM_KEYS.transfer_private_to_public.locator:
1534
- return provingKey.isTransferPrivateToPublicProver() && verifyingKey.isTransferPrivateToPublicVerifier();
1535
- case CREDITS_PROGRAM_KEYS.transfer_public.locator:
1536
- return provingKey.isTransferPublicProver() && verifyingKey.isTransferPublicVerifier();
1537
- case CREDITS_PROGRAM_KEYS.transfer_public_to_private.locator:
1538
- return provingKey.isTransferPublicToPrivateProver() && verifyingKey.isTransferPublicToPrivateVerifier();
1539
- case CREDITS_PROGRAM_KEYS.unbond_public.locator:
1540
- return provingKey.isUnbondPublicProver() && verifyingKey.isUnbondPublicVerifier();
1541
- default:
1542
- return false;
1543
- }
1544
- }
1545
- /**
1546
- * Get fee_private function keys from the credits.aleo program. The keys must be cached prior to calling this
1547
- * method for it to work.
1548
- *
1549
- * @returns {Promise<FunctionKeyPair | Error>} Proving and verifying keys for the join function
1550
- */
1551
- feePrivateKeys() {
1552
- return this.functionKeys(OfflineSearchParams.feePrivateKeyParams());
1553
- }
1554
- ;
1555
- /**
1556
- * Get fee_public function keys from the credits.aleo program. The keys must be cached prior to calling this
1557
- * method for it to work.
1558
- *
1559
- * @returns {Promise<FunctionKeyPair | Error>} Proving and verifying keys for the join function
1560
- */
1561
- feePublicKeys() {
1562
- return this.functionKeys(OfflineSearchParams.feePublicKeyParams());
1563
- }
1564
- ;
1565
- /**
1566
- * Get join function keys from the credits.aleo program. The keys must be cached prior to calling this
1567
- * method for it to work.
1568
- *
1569
- * @returns {Promise<FunctionKeyPair | Error>} Proving and verifying keys for the join function
1570
- */
1571
- joinKeys() {
1572
- return this.functionKeys(OfflineSearchParams.joinKeyParams());
1573
- }
1574
- ;
1575
- /**
1576
- * Get split function keys from the credits.aleo program. The keys must be cached prior to calling this
1577
- * method for it to work.
1578
- *
1579
- * @returns {Promise<FunctionKeyPair | Error>} Proving and verifying keys for the join function
1580
- */
1581
- splitKeys() {
1582
- return this.functionKeys(OfflineSearchParams.splitKeyParams());
1583
- }
1584
- ;
1585
- /**
1586
- * Get keys for a variant of the transfer function from the credits.aleo program.
1587
- *
1588
- *
1589
- * @param {string} visibility Visibility of the transfer function (private, public, privateToPublic, publicToPrivate)
1590
- * @returns {Promise<FunctionKeyPair | Error>} Proving and verifying keys for the specified transfer function
1591
- *
1592
- * @example
1593
- * // Create a new OfflineKeyProvider
1594
- * const offlineKeyProvider = new OfflineKeyProvider();
1595
- *
1596
- * // Cache the keys for future use with the official locator
1597
- * const transferPublicProvingKeyBytes = await readBinaryFile('./resources/transfer_public.prover.a74565e');
1598
- * const transferPublicProvingKey = ProvingKey.fromBytes(transferPublicProvingKeyBytes);
1599
- *
1600
- * // Cache the transfer_public keys for future use with the OfflinKeyProvider's convenience method for
1601
- * // transfer_public (the verifying key will be cached automatically)
1602
- * offlineKeyProvider.insertTransferPublicKeys(transferPublicProvingKey);
1603
- *
1604
- * /// When they're needed, retrieve the keys from the cache
1605
- * const [transferPublicProvingKey, transferPublicVerifyingKey] = await keyProvider.transferKeys("public");
1606
- */
1607
- transferKeys(visibility) {
1608
- if (PRIVATE_TRANSFER.has(visibility)) {
1609
- return this.functionKeys(OfflineSearchParams.transferPrivateKeyParams());
1610
- }
1611
- else if (PRIVATE_TO_PUBLIC_TRANSFER.has(visibility)) {
1612
- return this.functionKeys(OfflineSearchParams.transferPrivateToPublicKeyParams());
1613
- }
1614
- else if (PUBLIC_TRANSFER.has(visibility)) {
1615
- return this.functionKeys(OfflineSearchParams.transferPublicKeyParams());
1616
- }
1617
- else if (PUBLIC_TRANSFER_AS_SIGNER.has(visibility)) {
1618
- return this.functionKeys(OfflineSearchParams.transferPublicAsSignerKeyParams());
1619
- }
1620
- else if (PUBLIC_TO_PRIVATE_TRANSFER.has(visibility)) {
1621
- return this.functionKeys(OfflineSearchParams.transferPublicToPrivateKeyParams());
1622
- }
1623
- else {
1624
- throw new Error("Invalid visibility type");
1625
- }
1626
- }
1627
- ;
1628
- /**
1629
- * Get unbond_public function keys from the credits.aleo program
1630
- *
1631
- * @returns {Promise<FunctionKeyPair | Error>} Proving and verifying keys for the join function
1632
- */
1633
- async unBondPublicKeys() {
1634
- return this.functionKeys(OfflineSearchParams.unbondPublicKeyParams());
1635
- }
1636
- ;
1637
- /**
1638
- * Insert the proving and verifying keys for the bond_public function into the cache. Only the proving key needs
1639
- * to be inserted, the verifying key is automatically inserted by the SDK. This function will automatically check
1640
- * that the keys match the expected checksum for bond_public before inserting them into the cache.
1641
- *
1642
- * @param provingKey
1643
- */
1644
- insertBondPublicKeys(provingKey) {
1645
- if (provingKey.isBondPublicProver()) {
1646
- this.cache.set(CREDITS_PROGRAM_KEYS.bond_public.locator, [provingKey.toBytes(), VerifyingKey.bondPublicVerifier().toBytes()]);
1647
- }
1648
- else {
1649
- throw new Error("Attempted to insert invalid proving keys for bond_public");
1650
- }
1651
- }
1652
- /**
1653
- * Insert the proving and verifying keys for the claim_unbond_public function into the cache. Only the proving key needs
1654
- * to be inserted, the verifying key is automatically inserted by the SDK. This function will automatically check
1655
- * that the keys match the expected checksum for claim_unbond_public before inserting them into the cache.
1656
- *
1657
- * @param provingKey
1658
- */
1659
- insertClaimUnbondPublicKeys(provingKey) {
1660
- if (provingKey.isClaimUnbondPublicProver()) {
1661
- this.cache.set(CREDITS_PROGRAM_KEYS.claim_unbond_public.locator, [provingKey.toBytes(), VerifyingKey.claimUnbondPublicVerifier().toBytes()]);
1662
- }
1663
- else {
1664
- throw new Error("Attempted to insert invalid proving keys for claim_unbond_public");
1665
- }
1666
- }
1667
- /**
1668
- * Insert the proving and verifying keys for the fee_private function into the cache. Only the proving key needs
1669
- * to be inserted, the verifying key is automatically inserted by the SDK. This function will automatically check
1670
- * that the keys match the expected checksum for fee_private before inserting them into the cache.
1671
- *
1672
- * @param provingKey
1673
- */
1674
- insertFeePrivateKeys(provingKey) {
1675
- if (provingKey.isFeePrivateProver()) {
1676
- this.cache.set(CREDITS_PROGRAM_KEYS.fee_private.locator, [provingKey.toBytes(), VerifyingKey.feePrivateVerifier().toBytes()]);
1677
- }
1678
- else {
1679
- throw new Error("Attempted to insert invalid proving keys for fee_private");
1680
- }
1681
- }
1682
- /**
1683
- * Insert the proving and verifying keys for the fee_public function into the cache. Only the proving key needs
1684
- * to be inserted, the verifying key is automatically inserted by the SDK. This function will automatically check
1685
- * that the keys match the expected checksum for fee_public before inserting them into the cache.
1686
- *
1687
- * @param provingKey
1688
- */
1689
- insertFeePublicKeys(provingKey) {
1690
- if (provingKey.isFeePublicProver()) {
1691
- this.cache.set(CREDITS_PROGRAM_KEYS.fee_public.locator, [provingKey.toBytes(), VerifyingKey.feePublicVerifier().toBytes()]);
1692
- }
1693
- else {
1694
- throw new Error("Attempted to insert invalid proving keys for fee_public");
1695
- }
1696
- }
1697
- /**
1698
- * Insert the proving and verifying keys for the join function into the cache. Only the proving key needs
1699
- * to be inserted, the verifying key is automatically inserted by the SDK. This function will automatically check
1700
- * that the keys match the expected checksum for join before inserting them into the cache.
1701
- *
1702
- * @param provingKey
1703
- */
1704
- insertJoinKeys(provingKey) {
1705
- if (provingKey.isJoinProver()) {
1706
- this.cache.set(CREDITS_PROGRAM_KEYS.join.locator, [provingKey.toBytes(), VerifyingKey.joinVerifier().toBytes()]);
1707
- }
1708
- else {
1709
- throw new Error("Attempted to insert invalid proving keys for join");
1710
- }
1711
- }
1712
- /**
1713
- * Insert the proving and verifying keys for the set_validator_state function into the cache. Only the proving key needs
1714
- * to be inserted, the verifying key is automatically inserted by the SDK. This function will automatically check
1715
- * that the keys match the expected checksum for set_validator_state before inserting them into the cache.
1716
- *
1717
- * @param provingKey
1718
- */
1719
- insertSetValidatorStateKeys(provingKey) {
1720
- if (provingKey.isSetValidatorStateProver()) {
1721
- this.cache.set(CREDITS_PROGRAM_KEYS.set_validator_state.locator, [provingKey.toBytes(), VerifyingKey.setValidatorStateVerifier().toBytes()]);
1722
- }
1723
- else {
1724
- throw new Error("Attempted to insert invalid proving keys for set_validator_state");
1725
- }
1726
- }
1727
- /**
1728
- * Insert the proving and verifying keys for the split function into the cache. Only the proving key needs
1729
- * to be inserted, the verifying key is automatically inserted by the SDK. This function will automatically check
1730
- * that the keys match the expected checksum for split before inserting them into the cache.
1731
- *
1732
- * @param provingKey
1733
- */
1734
- insertSplitKeys(provingKey) {
1735
- if (provingKey.isSplitProver()) {
1736
- this.cache.set(CREDITS_PROGRAM_KEYS.split.locator, [provingKey.toBytes(), VerifyingKey.splitVerifier().toBytes()]);
1737
- }
1738
- else {
1739
- throw new Error("Attempted to insert invalid proving keys for split");
1740
- }
1741
- }
1742
- /**
1743
- * Insert the proving and verifying keys for the transfer_private function into the cache. Only the proving key needs
1744
- * to be inserted, the verifying key is automatically inserted by the SDK. This function will automatically check
1745
- * that the keys match the expected checksum for transfer_private before inserting them into the cache.
1746
- *
1747
- * @param provingKey
1748
- */
1749
- insertTransferPrivateKeys(provingKey) {
1750
- if (provingKey.isTransferPrivateProver()) {
1751
- this.cache.set(CREDITS_PROGRAM_KEYS.transfer_private.locator, [provingKey.toBytes(), VerifyingKey.transferPrivateVerifier().toBytes()]);
1010
+ return [ProvingKey.fromBytes(keyPair[0]), VerifyingKey.fromBytes(keyPair[1])];
1011
+ }
1752
1012
  }
1753
- else {
1754
- throw new Error("Attempted to insert invalid proving keys for transfer_private");
1013
+ catch (error) {
1014
+ throw new Error(`Error: fetching credits.aleo keys: ${error.message}`);
1755
1015
  }
1756
1016
  }
1757
- /**
1758
- * Insert the proving and verifying keys for the transfer_private_to_public function into the cache. Only the proving key needs
1759
- * to be inserted, the verifying key is automatically inserted by the SDK. This function will automatically check
1760
- * that the keys match the expected checksum for transfer_private_to_public before inserting them into the cache.
1761
- *
1762
- * @param provingKey
1763
- */
1764
- insertTransferPrivateToPublicKeys(provingKey) {
1765
- if (provingKey.isTransferPrivateToPublicProver()) {
1766
- this.cache.set(CREDITS_PROGRAM_KEYS.transfer_private_to_public.locator, [provingKey.toBytes(), VerifyingKey.transferPrivateToPublicVerifier().toBytes()]);
1767
- }
1768
- else {
1769
- throw new Error("Attempted to insert invalid proving keys for transfer_private_to_public");
1770
- }
1017
+ async bondPublicKeys() {
1018
+ return this.fetchCreditsKeys(CREDITS_PROGRAM_KEYS.bond_public);
1019
+ }
1020
+ bondValidatorKeys() {
1021
+ return this.fetchCreditsKeys(CREDITS_PROGRAM_KEYS.bond_validator);
1022
+ }
1023
+ claimUnbondPublicKeys() {
1024
+ return this.fetchCreditsKeys(CREDITS_PROGRAM_KEYS.claim_unbond_public);
1771
1025
  }
1772
1026
  /**
1773
- * Insert the proving and verifying keys for the transfer_public function into the cache. Only the proving key needs
1774
- * to be inserted, the verifying key is automatically inserted by the SDK. This function will automatically check
1775
- * that the keys match the expected checksum for transfer_public before inserting them into the cache.
1027
+ * Returns the proving and verifying keys for the transfer functions in the credits.aleo program
1028
+ * @param {string} visibility Visibility of the transfer function
1029
+ * @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the transfer functions
1030
+ *
1031
+ * @example
1032
+ * // Create a new AleoKeyProvider
1033
+ * const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1");
1034
+ * const keyProvider = new AleoKeyProvider();
1035
+ * const recordProvider = new NetworkRecordProvider(account, networkClient);
1036
+ *
1037
+ * // Initialize a program manager with the key provider to automatically fetch keys for value transfers
1038
+ * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider);
1039
+ * programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
1776
1040
  *
1777
- * @param provingKey
1041
+ * // Keys can also be fetched manually
1042
+ * const [transferPublicProvingKey, transferPublicVerifyingKey] = await keyProvider.transferKeys("public");
1778
1043
  */
1779
- insertTransferPublicKeys(provingKey) {
1780
- if (provingKey.isTransferPublicProver()) {
1781
- this.cache.set(CREDITS_PROGRAM_KEYS.transfer_public.locator, [provingKey.toBytes(), VerifyingKey.transferPublicVerifier().toBytes()]);
1044
+ async transferKeys(visibility) {
1045
+ if (PRIVATE_TRANSFER.has(visibility)) {
1046
+ return await this.fetchCreditsKeys(CREDITS_PROGRAM_KEYS.transfer_private);
1782
1047
  }
1783
- else {
1784
- throw new Error("Attempted to insert invalid proving keys for transfer_public");
1048
+ else if (PRIVATE_TO_PUBLIC_TRANSFER.has(visibility)) {
1049
+ return await this.fetchCreditsKeys(CREDITS_PROGRAM_KEYS.transfer_private_to_public);
1785
1050
  }
1786
- }
1787
- /**
1788
- * Insert the proving and verifying keys for the transfer_public_to_private function into the cache. Only the proving key needs
1789
- * to be inserted, the verifying key is automatically inserted by the SDK. This function will automatically check
1790
- * that the keys match the expected checksum for transfer_public_to_private before inserting them into the cache.
1791
- *
1792
- * @param provingKey
1793
- */
1794
- insertTransferPublicToPrivateKeys(provingKey) {
1795
- if (provingKey.isTransferPublicToPrivateProver()) {
1796
- this.cache.set(CREDITS_PROGRAM_KEYS.transfer_public_to_private.locator, [provingKey.toBytes(), VerifyingKey.transferPublicToPrivateVerifier().toBytes()]);
1051
+ else if (PUBLIC_TRANSFER.has(visibility)) {
1052
+ return await this.fetchCreditsKeys(CREDITS_PROGRAM_KEYS.transfer_public);
1797
1053
  }
1798
- else {
1799
- throw new Error("Attempted to insert invalid proving keys for transfer_public_to_private");
1054
+ else if (PUBLIC_TRANSFER_AS_SIGNER.has(visibility)) {
1055
+ return await this.fetchCreditsKeys(CREDITS_PROGRAM_KEYS.transfer_public_as_signer);
1800
1056
  }
1801
- }
1802
- insertUnbondPublicKeys(provingKey) {
1803
- if (provingKey.isUnbondPublicProver()) {
1804
- this.cache.set(CREDITS_PROGRAM_KEYS.unbond_public.locator, [provingKey.toBytes(), VerifyingKey.unbondPublicVerifier().toBytes()]);
1057
+ else if (PUBLIC_TO_PRIVATE_TRANSFER.has(visibility)) {
1058
+ return await this.fetchCreditsKeys(CREDITS_PROGRAM_KEYS.transfer_public_to_private);
1805
1059
  }
1806
1060
  else {
1807
- throw new Error("Attempted to insert invalid proving keys for unbond_public");
1061
+ throw new Error("Invalid visibility type");
1808
1062
  }
1809
1063
  }
1810
- }
1811
-
1812
- /**
1813
- * A record provider implementation that uses the official Aleo API to find records for usage in program execution and
1814
- * deployment, wallet functionality, and other use cases.
1815
- */
1816
- class NetworkRecordProvider {
1817
- account;
1818
- networkClient;
1819
- constructor(account, networkClient) {
1820
- this.account = account;
1821
- this.networkClient = networkClient;
1822
- }
1823
1064
  /**
1824
- * Set the account used to search for records
1065
+ * Returns the proving and verifying keys for the join function in the credits.aleo program
1825
1066
  *
1826
- * @param {Account} account The account to use for searching for records
1067
+ * @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the join function
1827
1068
  */
1828
- setAccount(account) {
1829
- this.account = account;
1069
+ async joinKeys() {
1070
+ return await this.fetchCreditsKeys(CREDITS_PROGRAM_KEYS.join);
1830
1071
  }
1831
1072
  /**
1832
- * Find a list of credit records with a given number of microcredits by via the official Aleo API
1833
- *
1834
- * @param {number[]} microcredits The number of microcredits to search for
1835
- * @param {boolean} unspent Whether or not the record is unspent
1836
- * @param {string[]} nonces Nonces of records already found so that they are not found again
1837
- * @param {RecordSearchParams} searchParameters Additional parameters to search for
1838
- * @returns {Promise<RecordPlaintext | Error>} The record if found, otherwise an error
1839
- *
1840
- * @example
1841
- * // Create a new NetworkRecordProvider
1842
- * const networkClient = new AleoNetworkClient("https://api.explorer.aleo.org/v1");
1843
- * const keyProvider = new AleoKeyProvider();
1844
- * const recordProvider = new NetworkRecordProvider(account, networkClient);
1845
- *
1846
- * // The record provider can be used to find records with a given number of microcredits
1847
- * const record = await recordProvider.findCreditsRecord(5000, true, []);
1848
- *
1849
- * // When a record is found but not yet used, it's nonce should be added to the nonces parameter so that it is not
1850
- * // found again if a subsequent search is performed
1851
- * const records = await recordProvider.findCreditsRecords(5000, true, [record.nonce()]);
1852
- *
1853
- * // When the program manager is initialized with the record provider it will be used to find automatically find
1854
- * // fee records and amount records for value transfers so that they do not need to be specified manually
1855
- * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, recordProvider);
1856
- * programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
1073
+ * Returns the proving and verifying keys for the split function in the credits.aleo program
1857
1074
  *
1075
+ * @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the split function
1858
1076
  * */
1859
- async findCreditsRecords(microcredits, unspent, nonces, searchParameters) {
1860
- let startHeight = 0;
1861
- let endHeight = 0;
1862
- if (searchParameters) {
1863
- if ("startHeight" in searchParameters && typeof searchParameters["endHeight"] == "number") {
1864
- startHeight = searchParameters["startHeight"];
1865
- }
1866
- if ("endHeight" in searchParameters && typeof searchParameters["endHeight"] == "number") {
1867
- endHeight = searchParameters["endHeight"];
1868
- }
1869
- }
1870
- // If the end height is not specified, use the current block height
1871
- if (endHeight == 0) {
1872
- const end = await this.networkClient.getLatestHeight();
1873
- if (end instanceof Error) {
1874
- throw logAndThrow("Unable to get current block height from the network");
1875
- }
1876
- endHeight = end;
1877
- }
1878
- // If the start height is greater than the end height, throw an error
1879
- if (startHeight >= endHeight) {
1880
- throw logAndThrow("Start height must be less than end height");
1881
- }
1882
- return await this.networkClient.findUnspentRecords(startHeight, endHeight, this.account.privateKey(), microcredits, undefined, nonces);
1077
+ async splitKeys() {
1078
+ return await this.fetchCreditsKeys(CREDITS_PROGRAM_KEYS.split);
1883
1079
  }
1884
1080
  /**
1885
- * Find a credit record with a given number of microcredits by via the official Aleo API
1886
- *
1887
- * @param {number} microcredits The number of microcredits to search for
1888
- * @param {boolean} unspent Whether or not the record is unspent
1889
- * @param {string[]} nonces Nonces of records already found so that they are not found again
1890
- * @param {RecordSearchParams} searchParameters Additional parameters to search for
1891
- * @returns {Promise<RecordPlaintext | Error>} The record if found, otherwise an error
1892
- *
1893
- * @example
1894
- * // Create a new NetworkRecordProvider
1895
- * const networkClient = new AleoNetworkClient("https://api.explorer.aleo.org/v1");
1896
- * const keyProvider = new AleoKeyProvider();
1897
- * const recordProvider = new NetworkRecordProvider(account, networkClient);
1898
- *
1899
- * // The record provider can be used to find records with a given number of microcredits
1900
- * const record = await recordProvider.findCreditsRecord(5000, true, []);
1901
- *
1902
- * // When a record is found but not yet used, it's nonce should be added to the nonces parameter so that it is not
1903
- * // found again if a subsequent search is performed
1904
- * const records = await recordProvider.findCreditsRecords(5000, true, [record.nonce()]);
1081
+ * Returns the proving and verifying keys for the fee_private function in the credits.aleo program
1905
1082
  *
1906
- * // When the program manager is initialized with the record provider it will be used to find automatically find
1907
- * // fee records and amount records for value transfers so that they do not need to be specified manually
1908
- * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, recordProvider);
1909
- * programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
1083
+ * @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the fee function
1910
1084
  */
1911
- async findCreditsRecord(microcredits, unspent, nonces, searchParameters) {
1912
- const records = await this.findCreditsRecords([microcredits], unspent, nonces, searchParameters);
1913
- if (!(records instanceof Error) && records.length > 0) {
1914
- return records[0];
1915
- }
1916
- console.error("Record not found with error:", records);
1917
- return new Error("Record not found");
1085
+ async feePrivateKeys() {
1086
+ return await this.fetchCreditsKeys(CREDITS_PROGRAM_KEYS.fee_private);
1918
1087
  }
1919
1088
  /**
1920
- * Find an arbitrary record. WARNING: This function is not implemented yet and will throw an error.
1089
+ * Returns the proving and verifying keys for the fee_public function in the credits.aleo program
1090
+ *
1091
+ * @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the fee function
1921
1092
  */
1922
- async findRecord(unspent, nonces, searchParameters) {
1923
- throw new Error("Method not implemented.");
1093
+ async feePublicKeys() {
1094
+ return await this.fetchCreditsKeys(CREDITS_PROGRAM_KEYS.fee_public);
1924
1095
  }
1925
1096
  /**
1926
- * Find multiple arbitrary records. WARNING: This function is not implemented yet and will throw an error.
1097
+ * Gets a verifying key. If the verifying key is for a credits.aleo function, get it from the wasm cache otherwise
1098
+ *
1099
+ * @returns {Promise<VerifyingKey>} Verifying key for the function
1927
1100
  */
1928
- async findRecords(unspent, nonces, searchParameters) {
1929
- throw new Error("Method not implemented.");
1101
+ // attempt to fetch it from the network
1102
+ async getVerifyingKey(verifierUri) {
1103
+ switch (verifierUri) {
1104
+ case CREDITS_PROGRAM_KEYS.bond_public.verifier:
1105
+ return CREDITS_PROGRAM_KEYS.bond_public.verifyingKey();
1106
+ case CREDITS_PROGRAM_KEYS.bond_validator.verifier:
1107
+ return CREDITS_PROGRAM_KEYS.bond_validator.verifyingKey();
1108
+ case CREDITS_PROGRAM_KEYS.claim_unbond_public.verifier:
1109
+ return CREDITS_PROGRAM_KEYS.claim_unbond_public.verifyingKey();
1110
+ case CREDITS_PROGRAM_KEYS.fee_private.verifier:
1111
+ return CREDITS_PROGRAM_KEYS.fee_private.verifyingKey();
1112
+ case CREDITS_PROGRAM_KEYS.fee_public.verifier:
1113
+ return CREDITS_PROGRAM_KEYS.fee_public.verifyingKey();
1114
+ case CREDITS_PROGRAM_KEYS.inclusion.verifier:
1115
+ return CREDITS_PROGRAM_KEYS.inclusion.verifyingKey();
1116
+ case CREDITS_PROGRAM_KEYS.join.verifier:
1117
+ return CREDITS_PROGRAM_KEYS.join.verifyingKey();
1118
+ case CREDITS_PROGRAM_KEYS.set_validator_state.verifier:
1119
+ return CREDITS_PROGRAM_KEYS.set_validator_state.verifyingKey();
1120
+ case CREDITS_PROGRAM_KEYS.split.verifier:
1121
+ return CREDITS_PROGRAM_KEYS.split.verifyingKey();
1122
+ case CREDITS_PROGRAM_KEYS.transfer_private.verifier:
1123
+ return CREDITS_PROGRAM_KEYS.transfer_private.verifyingKey();
1124
+ case CREDITS_PROGRAM_KEYS.transfer_private_to_public.verifier:
1125
+ return CREDITS_PROGRAM_KEYS.transfer_private_to_public.verifyingKey();
1126
+ case CREDITS_PROGRAM_KEYS.transfer_public.verifier:
1127
+ return CREDITS_PROGRAM_KEYS.transfer_public.verifyingKey();
1128
+ case CREDITS_PROGRAM_KEYS.transfer_public_as_signer.verifier:
1129
+ return CREDITS_PROGRAM_KEYS.transfer_public_as_signer.verifyingKey();
1130
+ case CREDITS_PROGRAM_KEYS.transfer_public_to_private.verifier:
1131
+ return CREDITS_PROGRAM_KEYS.transfer_public_to_private.verifyingKey();
1132
+ case CREDITS_PROGRAM_KEYS.unbond_public.verifier:
1133
+ return CREDITS_PROGRAM_KEYS.unbond_public.verifyingKey();
1134
+ default:
1135
+ try {
1136
+ /// Try to fetch the verifying key from the network as a string
1137
+ const response = await get(verifierUri);
1138
+ const text = await response.text();
1139
+ return VerifyingKey.fromString(text);
1140
+ }
1141
+ catch (e) {
1142
+ /// If that fails, try to fetch the verifying key from the network as bytes
1143
+ try {
1144
+ return VerifyingKey.fromBytes(await this.fetchBytes(verifierUri));
1145
+ }
1146
+ catch (inner) {
1147
+ throw new Error("Invalid verifying key. Error: " + inner.message);
1148
+ }
1149
+ }
1150
+ }
1930
1151
  }
1931
- }
1932
- /**
1933
- * BlockHeightSearch is a RecordSearchParams implementation that allows for searching for records within a given
1934
- * block height range.
1935
- *
1936
- * @example
1937
- * // Create a new BlockHeightSearch
1938
- * const params = new BlockHeightSearch(89995, 99995);
1939
- *
1940
- * // Create a new NetworkRecordProvider
1941
- * const networkClient = new AleoNetworkClient("https://api.explorer.aleo.org/v1");
1942
- * const keyProvider = new AleoKeyProvider();
1943
- * const recordProvider = new NetworkRecordProvider(account, networkClient);
1944
- *
1945
- * // The record provider can be used to find records with a given number of microcredits and the block height search
1946
- * // can be used to find records within a given block height range
1947
- * const record = await recordProvider.findCreditsRecord(5000, true, [], params);
1948
- *
1949
- */
1950
- class BlockHeightSearch {
1951
- startHeight;
1952
- endHeight;
1953
- constructor(startHeight, endHeight) {
1954
- this.startHeight = startHeight;
1955
- this.endHeight = endHeight;
1152
+ unBondPublicKeys() {
1153
+ return this.fetchCreditsKeys(CREDITS_PROGRAM_KEYS.unbond_public);
1956
1154
  }
1957
1155
  }
1958
1156
 
1959
- // Experimental example where SDK manages worker
1960
- let singletonWorker = null;
1961
- const createAleoWorker = () => {
1962
- if (!singletonWorker) {
1963
- const worker = new Worker(new URL("worker.js", import.meta.url), {
1964
- type: "module",
1965
- });
1966
- singletonWorker = wrap(worker);
1967
- }
1968
- return singletonWorker;
1969
- };
1970
-
1971
1157
  /**
1972
1158
  * The ProgramManager class is used to execute and deploy programs on the Aleo network and create value transfers.
1973
1159
  */
@@ -1984,7 +1170,7 @@ class ProgramManager {
1984
1170
  * @param { RecordProvider | undefined } recordProvider A record provider that implements {@link RecordProvider} interface
1985
1171
  */
1986
1172
  constructor(host, keyProvider, recordProvider) {
1987
- this.host = host ? host : 'https://api.explorer.aleo.org/v1';
1173
+ this.host = host ? host : 'https://api.explorer.provable.com/v1';
1988
1174
  this.networkClient = new AleoNetworkClient(this.host);
1989
1175
  this.keyProvider = keyProvider ? keyProvider : new AleoKeyProvider();
1990
1176
  this.recordProvider = recordProvider;
@@ -2032,17 +1218,17 @@ class ProgramManager {
2032
1218
  * pay the deployment fee
2033
1219
  * @param {string | RecordPlaintext | undefined} feeRecord Optional Fee record to use for the transaction
2034
1220
  * @param {PrivateKey | undefined} privateKey Optional private key to use for the transaction
2035
- * @returns {string | Error} The transaction id of the deployed program or a failure message from the network
1221
+ * @returns {string} The transaction id of the deployed program or a failure message from the network
2036
1222
  *
2037
1223
  * @example
2038
1224
  * // Create a new NetworkClient, KeyProvider, and RecordProvider
2039
- * const networkClient = new AleoNetworkClient("https://api.explorer.aleo.org/v1");
1225
+ * const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1");
2040
1226
  * const keyProvider = new AleoKeyProvider();
2041
1227
  * const recordProvider = new NetworkRecordProvider(account, networkClient);
2042
1228
  *
2043
1229
  * // Initialize a program manager with the key provider to automatically fetch keys for deployments
2044
1230
  * const program = "program hello_hello.aleo;\n\nfunction hello:\n input r0 as u32.public;\n input r1 as u32.private;\n add r0 r1 into r2;\n output r2 as u32.private;\n";
2045
- * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, recordProvider);
1231
+ * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider);
2046
1232
  *
2047
1233
  * // Define a fee in credits
2048
1234
  * const fee = 1.2;
@@ -2070,7 +1256,7 @@ class ProgramManager {
2070
1256
  }
2071
1257
  }
2072
1258
  catch (e) {
2073
- throw logAndThrow(`Error validating program: ${e}`);
1259
+ logAndThrow(`Error validating program: ${e.message}`);
2074
1260
  }
2075
1261
  // Get the private key from the account if it is not provided in the parameters
2076
1262
  let deploymentPrivateKey = privateKey;
@@ -2085,7 +1271,7 @@ class ProgramManager {
2085
1271
  feeRecord = privateFee ? await this.getCreditsRecord(fee, [], feeRecord, recordSearchParams) : undefined;
2086
1272
  }
2087
1273
  catch (e) {
2088
- throw logAndThrow(`Error finding fee record. Record finder response: '${e}'. Please ensure you're connected to a valid Aleo network and a record with enough balance exists.`);
1274
+ logAndThrow(`Error finding fee record. Record finder response: '${e.message}'. Please ensure you're connected to a valid Aleo network and a record with enough balance exists.`);
2089
1275
  }
2090
1276
  // Get the proving and verifying keys from the key provider
2091
1277
  let feeKeys;
@@ -2093,7 +1279,7 @@ class ProgramManager {
2093
1279
  feeKeys = privateFee ? await this.keyProvider.feePrivateKeys() : await this.keyProvider.feePublicKeys();
2094
1280
  }
2095
1281
  catch (e) {
2096
- throw logAndThrow(`Error finding fee keys. Key finder response: '${e}'. Please ensure your key provider is configured correctly.`);
1282
+ logAndThrow(`Error finding fee keys. Key finder response: '${e.message}'. Please ensure your key provider is configured correctly.`);
2097
1283
  }
2098
1284
  const [feeProvingKey, feeVerifyingKey] = feeKeys;
2099
1285
  // Resolve the program imports if they exist
@@ -2102,7 +1288,7 @@ class ProgramManager {
2102
1288
  imports = await this.networkClient.getProgramImports(program);
2103
1289
  }
2104
1290
  catch (e) {
2105
- throw logAndThrow(`Error finding program imports. Network response: '${e}'. Please ensure you're connected to a valid Aleo network and the program is deployed to the network.`);
1291
+ logAndThrow(`Error finding program imports. Network response: '${e.message}'. Please ensure you're connected to a valid Aleo network and the program is deployed to the network.`);
2106
1292
  }
2107
1293
  // Build a deployment transaction and submit it to the network
2108
1294
  const tx = await ProgramManager$1.buildDeploymentTransaction(deploymentPrivateKey, program, fee, feeRecord, this.host, imports, feeProvingKey, feeVerifyingKey);
@@ -2112,17 +1298,17 @@ class ProgramManager {
2112
1298
  * Builds an execution transaction for submission to the Aleo network.
2113
1299
  *
2114
1300
  * @param {ExecuteOptions} options - The options for the execution transaction.
2115
- * @returns {Promise<Transaction | Error>} - A promise that resolves to the transaction or an error.
1301
+ * @returns {Promise<Transaction>} - A promise that resolves to the transaction or an error.
2116
1302
  *
2117
1303
  * @example
2118
1304
  * // Create a new NetworkClient, KeyProvider, and RecordProvider using official Aleo record, key, and network providers
2119
- * const networkClient = new AleoNetworkClient("https://api.explorer.aleo.org/v1");
1305
+ * const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1");
2120
1306
  * const keyProvider = new AleoKeyProvider();
2121
1307
  * keyProvider.useCache = true;
2122
1308
  * const recordProvider = new NetworkRecordProvider(account, networkClient);
2123
1309
  *
2124
1310
  * // Initialize a program manager with the key provider to automatically fetch keys for executions
2125
- * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, recordProvider);
1311
+ * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider);
2126
1312
  *
2127
1313
  * // Build and execute the transaction
2128
1314
  * const transaction = await programManager.buildExecutionTransaction({
@@ -2149,7 +1335,7 @@ class ProgramManager {
2149
1335
  program = (await this.networkClient.getProgram(programName));
2150
1336
  }
2151
1337
  catch (e) {
2152
- throw logAndThrow(`Error finding ${programName}. Network response: '${e}'. Please ensure you're connected to a valid Aleo network the program is deployed to the network.`);
1338
+ logAndThrow(`Error finding ${programName}. Network response: '${e.message}'. Please ensure you're connected to a valid Aleo network the program is deployed to the network.`);
2153
1339
  }
2154
1340
  }
2155
1341
  else if (program instanceof Program) {
@@ -2168,7 +1354,7 @@ class ProgramManager {
2168
1354
  feeRecord = privateFee ? await this.getCreditsRecord(fee, [], feeRecord, recordSearchParams) : undefined;
2169
1355
  }
2170
1356
  catch (e) {
2171
- throw logAndThrow(`Error finding fee record. Record finder response: '${e}'. Please ensure you're connected to a valid Aleo network and a record with enough balance exists.`);
1357
+ logAndThrow(`Error finding fee record. Record finder response: '${e.message}'. Please ensure you're connected to a valid Aleo network and a record with enough balance exists.`);
2172
1358
  }
2173
1359
  // Get the fee proving and verifying keys from the key provider
2174
1360
  let feeKeys;
@@ -2176,7 +1362,7 @@ class ProgramManager {
2176
1362
  feeKeys = privateFee ? await this.keyProvider.feePrivateKeys() : await this.keyProvider.feePublicKeys();
2177
1363
  }
2178
1364
  catch (e) {
2179
- throw logAndThrow(`Error finding fee keys. Key finder response: '${e}'. Please ensure your key provider is configured correctly.`);
1365
+ logAndThrow(`Error finding fee keys. Key finder response: '${e.message}'. Please ensure your key provider is configured correctly.`);
2180
1366
  }
2181
1367
  const [feeProvingKey, feeVerifyingKey] = feeKeys;
2182
1368
  // If the function proving and verifying keys are not provided, attempt to find them using the key provider
@@ -2195,7 +1381,7 @@ class ProgramManager {
2195
1381
  imports = await this.networkClient.getProgramImports(programName);
2196
1382
  }
2197
1383
  catch (e) {
2198
- throw logAndThrow(`Error finding program imports. Network response: '${e}'. Please ensure you're connected to a valid Aleo network and the program is deployed to the network.`);
1384
+ logAndThrow(`Error finding program imports. Network response: '${e.message}'. Please ensure you're connected to a valid Aleo network and the program is deployed to the network.`);
2199
1385
  }
2200
1386
  }
2201
1387
  // Build an execution transaction and submit it to the network
@@ -2205,17 +1391,17 @@ class ProgramManager {
2205
1391
  * Builds an execution transaction for submission to the Aleo network.
2206
1392
  *
2207
1393
  * @param {ExecuteOptions} options - The options for the execution transaction.
2208
- * @returns {Promise<Transaction | Error>} - A promise that resolves to the transaction or an error.
1394
+ * @returns {Promise<Transaction>} - A promise that resolves to the transaction or an error.
2209
1395
  *
2210
1396
  * @example
2211
1397
  * // Create a new NetworkClient, KeyProvider, and RecordProvider using official Aleo record, key, and network providers
2212
- * const networkClient = new AleoNetworkClient("https://api.explorer.aleo.org/v1");
1398
+ * const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1");
2213
1399
  * const keyProvider = new AleoKeyProvider();
2214
1400
  * keyProvider.useCache = true;
2215
1401
  * const recordProvider = new NetworkRecordProvider(account, networkClient);
2216
1402
  *
2217
1403
  * // Initialize a program manager with the key provider to automatically fetch keys for executions
2218
- * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, recordProvider);
1404
+ * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider);
2219
1405
  *
2220
1406
  * // Build and execute the transaction
2221
1407
  * const transaction = await programManager.execute({
@@ -2247,7 +1433,7 @@ class ProgramManager {
2247
1433
  * @param {VerifyingKey | undefined} verifyingKey Optional verifying key to use for the transaction
2248
1434
  * @param {PrivateKey | undefined} privateKey Optional private key to use for the transaction
2249
1435
  * @param {OfflineQuery | undefined} offlineQuery Optional offline query if creating transactions in an offline environment
2250
- * @returns {Promise<string | Error>}
1436
+ * @returns {Promise<string>}
2251
1437
  *
2252
1438
  * @example
2253
1439
  * import { Account, Program } from '@provablehq/sdk';
@@ -2301,7 +1487,7 @@ class ProgramManager {
2301
1487
  * @param {RecordPlaintext | string | undefined} feeRecord Fee record to use for the join transaction
2302
1488
  * @param {PrivateKey | undefined} privateKey Private key to use for the join transaction
2303
1489
  * @param {OfflineQuery | undefined} offlineQuery Optional offline query if creating transactions in an offline environment
2304
- * @returns {Promise<string | Error>}
1490
+ * @returns {Promise<string>}
2305
1491
  */
2306
1492
  async join(recordOne, recordTwo, fee, privateFee, recordSearchParams, feeRecord, privateKey, offlineQuery) {
2307
1493
  // Get the private key from the account if it is not provided in the parameters
@@ -2320,7 +1506,7 @@ class ProgramManager {
2320
1506
  joinKeys = await this.keyProvider.joinKeys();
2321
1507
  }
2322
1508
  catch (e) {
2323
- throw logAndThrow(`Error finding fee keys. Key finder response: '${e}'. Please ensure your key provider is configured correctly.`);
1509
+ logAndThrow(`Error finding fee keys. Key finder response: '${e.message}'. Please ensure your key provider is configured correctly.`);
2324
1510
  }
2325
1511
  const [feeProvingKey, feeVerifyingKey] = feeKeys;
2326
1512
  const [joinProvingKey, joinVerifyingKey] = joinKeys;
@@ -2329,7 +1515,7 @@ class ProgramManager {
2329
1515
  feeRecord = privateFee ? await this.getCreditsRecord(fee, [], feeRecord, recordSearchParams) : undefined;
2330
1516
  }
2331
1517
  catch (e) {
2332
- throw logAndThrow(`Error finding fee record. Record finder response: '${e}'. Please ensure you're connected to a valid Aleo network and a record with enough balance exists.`);
1518
+ logAndThrow(`Error finding fee record. Record finder response: '${e.message}'. Please ensure you're connected to a valid Aleo network and a record with enough balance exists.`);
2333
1519
  }
2334
1520
  // Validate the records provided are valid plaintext records
2335
1521
  try {
@@ -2337,7 +1523,7 @@ class ProgramManager {
2337
1523
  recordTwo = recordTwo instanceof RecordPlaintext ? recordTwo : RecordPlaintext.fromString(recordTwo);
2338
1524
  }
2339
1525
  catch (e) {
2340
- throw logAndThrow('Records provided are not valid. Please ensure they are valid plaintext records.');
1526
+ logAndThrow('Records provided are not valid. Please ensure they are valid plaintext records.');
2341
1527
  }
2342
1528
  // Build an execution transaction and submit it to the network
2343
1529
  const tx = await ProgramManager$1.buildJoinTransaction(executionPrivateKey, recordOne, recordTwo, fee, feeRecord, this.host, joinProvingKey, joinVerifyingKey, feeProvingKey, feeVerifyingKey, offlineQuery);
@@ -2350,17 +1536,17 @@ class ProgramManager {
2350
1536
  * @param {RecordPlaintext | string} amountRecord Amount record to use for the split transaction
2351
1537
  * @param {PrivateKey | undefined} privateKey Optional private key to use for the split transaction
2352
1538
  * @param {OfflineQuery | undefined} offlineQuery Optional offline query if creating transactions in an offline environment
2353
- * @returns {Promise<string | Error>}
1539
+ * @returns {Promise<string>}
2354
1540
  *
2355
1541
  * @example
2356
1542
  * // Create a new NetworkClient, KeyProvider, and RecordProvider
2357
- * const networkClient = new AleoNetworkClient("https://api.explorer.aleo.org/v1");
1543
+ * const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1");
2358
1544
  * const keyProvider = new AleoKeyProvider();
2359
1545
  * const recordProvider = new NetworkRecordProvider(account, networkClient);
2360
1546
  *
2361
1547
  * // Initialize a program manager with the key provider to automatically fetch keys for executions
2362
1548
  * const programName = "hello_hello.aleo";
2363
- * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, recordProvider);
1549
+ * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider);
2364
1550
  * const record = "{ owner: aleo184vuwr5u7u0ha5f5k44067dd2uaqewxx6pe5ltha5pv99wvhfqxqv339h4.private, microcredits: 45000000u64.private, _nonce: 4106205762862305308495708971985748592380064201230396559307556388725936304984group.public}"
2365
1551
  * const tx_id = await programManager.split(25000000, record);
2366
1552
  * const transaction = await programManager.networkClient.getTransaction(tx_id);
@@ -2380,7 +1566,7 @@ class ProgramManager {
2380
1566
  splitKeys = await this.keyProvider.splitKeys();
2381
1567
  }
2382
1568
  catch (e) {
2383
- throw logAndThrow(`Error finding fee keys. Key finder response: '${e}'. Please ensure your key provider is configured correctly.`);
1569
+ logAndThrow(`Error finding fee keys. Key finder response: '${e.message}'. Please ensure your key provider is configured correctly.`);
2384
1570
  }
2385
1571
  const [splitProvingKey, splitVerifyingKey] = splitKeys;
2386
1572
  // Validate the record to be split
@@ -2388,7 +1574,7 @@ class ProgramManager {
2388
1574
  amountRecord = amountRecord instanceof RecordPlaintext ? amountRecord : RecordPlaintext.fromString(amountRecord);
2389
1575
  }
2390
1576
  catch (e) {
2391
- throw logAndThrow("Record provided is not valid. Please ensure it is a valid plaintext record.");
1577
+ logAndThrow("Record provided is not valid. Please ensure it is a valid plaintext record.");
2392
1578
  }
2393
1579
  // Build an execution transaction and submit it to the network
2394
1580
  const tx = await ProgramManager$1.buildSplitTransaction(executionPrivateKey, splitAmount, amountRecord, this.host, splitProvingKey, splitVerifyingKey, offlineQuery);
@@ -2402,7 +1588,7 @@ class ProgramManager {
2402
1588
  * @param inputs {Array<string>} Sample inputs to the function
2403
1589
  * @param privateKey {PrivateKey | undefined} Optional private key to use for the key synthesis
2404
1590
  *
2405
- * @returns {Promise<FunctionKeyPair | Error>}
1591
+ * @returns {Promise<FunctionKeyPair>}
2406
1592
  */
2407
1593
  async synthesizeKeys(program, function_id, inputs, privateKey) {
2408
1594
  // Resolve the program imports if they exist
@@ -2423,7 +1609,7 @@ class ProgramManager {
2423
1609
  return [keyPair.provingKey(), keyPair.verifyingKey()];
2424
1610
  }
2425
1611
  catch (e) {
2426
- throw logAndThrow(`Could not synthesize keys - error ${e}. Please ensure the program is valid and the inputs are correct.`);
1612
+ logAndThrow(`Could not synthesize keys - error ${e.message}. Please ensure the program is valid and the inputs are correct.`);
2427
1613
  }
2428
1614
  }
2429
1615
  /**
@@ -2440,17 +1626,17 @@ class ProgramManager {
2440
1626
  * @param {RecordPlaintext | string} feeRecord Optional fee record to use for the transfer
2441
1627
  * @param {PrivateKey | undefined} privateKey Optional private key to use for the transfer transaction
2442
1628
  * @param {OfflineQuery | undefined} offlineQuery Optional offline query if creating transactions in an offline environment
2443
- * @returns {Promise<string | Error>} The transaction id of the transfer transaction
1629
+ * @returns {Promise<string>} The transaction id of the transfer transaction
2444
1630
  *
2445
1631
  * @example
2446
1632
  * // Create a new NetworkClient, KeyProvider, and RecordProvider
2447
- * const networkClient = new AleoNetworkClient("https://api.explorer.aleo.org/v1");
1633
+ * const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1");
2448
1634
  * const keyProvider = new AleoKeyProvider();
2449
1635
  * const recordProvider = new NetworkRecordProvider(account, networkClient);
2450
1636
  *
2451
1637
  * // Initialize a program manager with the key provider to automatically fetch keys for executions
2452
1638
  * const programName = "hello_hello.aleo";
2453
- * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, recordProvider);
1639
+ * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider);
2454
1640
  * await programManager.initialize();
2455
1641
  * const tx_id = await programManager.transfer(1, "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px", "private", 0.2)
2456
1642
  * const transaction = await programManager.networkClient.getTransaction(tx_id);
@@ -2474,7 +1660,7 @@ class ProgramManager {
2474
1660
  transferKeys = await this.keyProvider.transferKeys(transferType);
2475
1661
  }
2476
1662
  catch (e) {
2477
- throw logAndThrow(`Error finding fee keys. Key finder response: '${e}'. Please ensure your key provider is configured correctly.`);
1663
+ logAndThrow(`Error finding fee keys. Key finder response: '${e.message}'. Please ensure your key provider is configured correctly.`);
2478
1664
  }
2479
1665
  const [feeProvingKey, feeVerifyingKey] = feeKeys;
2480
1666
  const [transferProvingKey, transferVerifyingKey] = transferKeys;
@@ -2493,7 +1679,7 @@ class ProgramManager {
2493
1679
  feeRecord = privateFee ? await this.getCreditsRecord(fee, nonces, feeRecord, recordSearchParams) : undefined;
2494
1680
  }
2495
1681
  catch (e) {
2496
- throw logAndThrow(`Error finding fee record. Record finder response: '${e}'. Please ensure you're connected to a valid Aleo network and a record with enough balance exists.`);
1682
+ logAndThrow(`Error finding fee record. Record finder response: '${e.message}'. Please ensure you're connected to a valid Aleo network and a record with enough balance exists.`);
2497
1683
  }
2498
1684
  // Build an execution transaction and submit it to the network
2499
1685
  return await ProgramManager$1.buildTransferTransaction(executionPrivateKey, amount, recipient, transferType, amountRecord, fee, feeRecord, this.host, transferProvingKey, transferVerifyingKey, feeProvingKey, feeVerifyingKey, offlineQuery);
@@ -2512,7 +1698,7 @@ class ProgramManager {
2512
1698
  * @param {RecordPlaintext | string} feeRecord Optional fee record to use for the transfer
2513
1699
  * @param {PrivateKey | undefined} privateKey Optional private key to use for the transfer transaction
2514
1700
  * @param {OfflineQuery | undefined} offlineQuery Optional offline query if creating transactions in an offline environment
2515
- * @returns {Promise<string | Error>} The transaction id of the transfer transaction
1701
+ * @returns {Promise<string>} The transaction id of the transfer transaction
2516
1702
  */
2517
1703
  async buildTransferPublicTransaction(amount, recipient, fee, privateKey, offlineQuery) {
2518
1704
  return this.buildTransferTransaction(amount, recipient, "public", fee, false, undefined, undefined, undefined, privateKey, offlineQuery);
@@ -2531,7 +1717,7 @@ class ProgramManager {
2531
1717
  * @param {RecordPlaintext | string} feeRecord Optional fee record to use for the transfer
2532
1718
  * @param {PrivateKey | undefined} privateKey Optional private key to use for the transfer transaction
2533
1719
  * @param {OfflineQuery | undefined} offlineQuery Optional offline query if creating transactions in an offline environment
2534
- * @returns {Promise<string | Error>} The transaction id of the transfer transaction
1720
+ * @returns {Promise<string>} The transaction id of the transfer transaction
2535
1721
  */
2536
1722
  async buildTransferPublicAsSignerTransaction(amount, recipient, fee, privateKey, offlineQuery) {
2537
1723
  return this.buildTransferTransaction(amount, recipient, "public", fee, false, undefined, undefined, undefined, privateKey, offlineQuery);
@@ -2550,16 +1736,16 @@ class ProgramManager {
2550
1736
  * @param {RecordPlaintext | string} feeRecord Optional fee record to use for the transfer
2551
1737
  * @param {PrivateKey | undefined} privateKey Optional private key to use for the transfer transaction
2552
1738
  * @param {OfflineQuery | undefined} offlineQuery Optional offline query if creating transactions in an offline environment
2553
- * @returns {Promise<string | Error>} The transaction id of the transfer transaction
1739
+ * @returns {Promise<string>} The transaction id of the transfer transaction
2554
1740
  *
2555
1741
  * @example
2556
1742
  * // Create a new NetworkClient, KeyProvider, and RecordProvider
2557
- * const networkClient = new AleoNetworkClient("https://api.explorer.aleo.org/v1");
1743
+ * const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1");
2558
1744
  * const keyProvider = new AleoKeyProvider();
2559
1745
  * const recordProvider = new NetworkRecordProvider(account, networkClient);
2560
1746
  *
2561
1747
  * // Initialize a program manager with the key provider to automatically fetch keys for executions
2562
- * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, recordProvider);
1748
+ * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider);
2563
1749
  * await programManager.initialize();
2564
1750
  * const tx_id = await programManager.transfer(1, "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px", "private", 0.2)
2565
1751
  * const transaction = await programManager.networkClient.getTransaction(tx_id);
@@ -2577,7 +1763,7 @@ class ProgramManager {
2577
1763
  * keyProvider.useCache = true;
2578
1764
  *
2579
1765
  * // Create a new ProgramManager with the key that will be used to bond credits
2580
- * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, undefined);
1766
+ * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, undefined);
2581
1767
  * programManager.setAccount(new Account("YourPrivateKey"));
2582
1768
  *
2583
1769
  * // Create the bonding transaction object for later submission
@@ -2625,7 +1811,7 @@ class ProgramManager {
2625
1811
  * keyProvider.useCache = true;
2626
1812
  *
2627
1813
  * // Create a new ProgramManager with the key that will be used to bond credits
2628
- * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, undefined);
1814
+ * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, undefined);
2629
1815
  * programManager.setAccount(new Account("YourPrivateKey"));
2630
1816
  *
2631
1817
  * // Create the bonding transaction
@@ -2655,7 +1841,7 @@ class ProgramManager {
2655
1841
  * keyProvider.useCache = true;
2656
1842
  *
2657
1843
  * // Create a new ProgramManager with the key that will be used to bond credits
2658
- * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, undefined);
1844
+ * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, undefined);
2659
1845
  * programManager.setAccount(new Account("YourPrivateKey"));
2660
1846
  *
2661
1847
  * // Create the bond validator transaction object for later use.
@@ -2704,7 +1890,7 @@ class ProgramManager {
2704
1890
  * keyProvider.useCache = true;
2705
1891
  *
2706
1892
  * // Create a new ProgramManager with the key that will be used to bond credits
2707
- * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, undefined);
1893
+ * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, undefined);
2708
1894
  * programManager.setAccount(new Account("YourPrivateKey"));
2709
1895
  *
2710
1896
  * // Create the bonding transaction
@@ -2731,7 +1917,7 @@ class ProgramManager {
2731
1917
  * @param {string} staker_address - The address of the staker who is unbonding the credits.
2732
1918
  * @param {number} amount - The amount of credits to unbond (scaled by 1,000,000).
2733
1919
  * @param {Partial<ExecuteOptions>} options - Override default execution options.
2734
- * @returns {Promise<Transaction | Error>} - A promise that resolves to the transaction or an error message.
1920
+ * @returns {Promise<Transaction>} - A promise that resolves to the transaction or an error message.
2735
1921
  *
2736
1922
  * @example
2737
1923
  * // Create a keyProvider to handle key management.
@@ -2739,7 +1925,7 @@ class ProgramManager {
2739
1925
  * keyProvider.useCache = true;
2740
1926
  *
2741
1927
  * // Create a new ProgramManager with the key that will be used to unbond credits.
2742
- * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, undefined);
1928
+ * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, undefined);
2743
1929
  * const tx = await programManager.buildUnbondPublicTransaction("aleo1jx8s4dvjepculny4wfrzwyhs3tlyv65r58ns3g6q2gm2esh7ps8sqy9s5j", 2000000);
2744
1930
  * console.log(tx);
2745
1931
  *
@@ -2773,7 +1959,7 @@ class ProgramManager {
2773
1959
  * keyProvider.useCache = true;
2774
1960
  *
2775
1961
  * // Create a new ProgramManager with the key that will be used to bond credits
2776
- * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, undefined);
1962
+ * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, undefined);
2777
1963
  * programManager.setAccount(new Account("YourPrivateKey"));
2778
1964
  *
2779
1965
  * // Create the bonding transaction and send it to the network
@@ -2798,7 +1984,7 @@ class ProgramManager {
2798
1984
  *
2799
1985
  * @param {string} staker_address - The address of the staker who is claiming the credits.
2800
1986
  * @param {Partial<ExecuteOptions>} options - Override default execution options.
2801
- * @returns {Promise<Transaction | Error>} - A promise that resolves to the transaction or an error message.
1987
+ * @returns {Promise<Transaction>} - A promise that resolves to the transaction or an error message.
2802
1988
  *
2803
1989
  * @example
2804
1990
  * // Create a keyProvider to handle key management
@@ -2806,7 +1992,7 @@ class ProgramManager {
2806
1992
  * keyProvider.useCache = true;
2807
1993
  *
2808
1994
  * // Create a new ProgramManager with the key that will be used to claim unbonded credits.
2809
- * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, undefined);
1995
+ * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, undefined);
2810
1996
  *
2811
1997
  * // Create the claim unbonded transaction object for later use.
2812
1998
  * const tx = await programManager.buildClaimUnbondPublicTransaction("aleo1jx8s4dvjepculny4wfrzwyhs3tlyv65r58ns3g6q2gm2esh7ps8sqy9s5j");
@@ -2842,7 +2028,7 @@ class ProgramManager {
2842
2028
  * keyProvider.useCache = true;
2843
2029
  *
2844
2030
  * // Create a new ProgramManager with the key that will be used to bond credits
2845
- * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, undefined);
2031
+ * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, undefined);
2846
2032
  * programManager.setAccount(new Account("YourPrivateKey"));
2847
2033
  *
2848
2034
  * // Create the bonding transaction
@@ -2873,7 +2059,7 @@ class ProgramManager {
2873
2059
  * keyProvider.useCache = true;
2874
2060
  *
2875
2061
  * // Create a new ProgramManager with the key that will be used to bond credits
2876
- * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, undefined);
2062
+ * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, undefined);
2877
2063
  * programManager.setAccount(new Account("ValidatorPrivateKey"));
2878
2064
  *
2879
2065
  * // Create the bonding transaction
@@ -2920,7 +2106,7 @@ class ProgramManager {
2920
2106
  * keyProvider.useCache = true;
2921
2107
  *
2922
2108
  * // Create a new ProgramManager with the key that will be used to bond credits
2923
- * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, undefined);
2109
+ * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, undefined);
2924
2110
  * programManager.setAccount(new Account("ValidatorPrivateKey"));
2925
2111
  *
2926
2112
  * // Create the bonding transaction
@@ -2957,7 +2143,7 @@ class ProgramManager {
2957
2143
  * Create a program object from a program's source code
2958
2144
  *
2959
2145
  * @param {string} program Program source code
2960
- * @returns {Program | Error} The program object
2146
+ * @returns {Program} The program object
2961
2147
  */
2962
2148
  createProgramFromSource(program) {
2963
2149
  return Program.fromString(program);
@@ -2995,7 +2181,7 @@ class ProgramManager {
2995
2181
  return (await recordProvider.findCreditsRecord(amount, true, nonces, params));
2996
2182
  }
2997
2183
  catch (e) {
2998
- throw logAndThrow(`Error finding fee record. Record finder response: '${e}'. Please ensure you're connected to a valid Aleo network and a record with enough balance exists.`);
2184
+ logAndThrow(`Error finding fee record. Record finder response: '${e.message}'. Please ensure you're connected to a valid Aleo network and a record with enough balance exists.`);
2999
2185
  }
3000
2186
  }
3001
2187
  }
@@ -3010,107 +2196,5 @@ function validateTransferType(transferType) {
3010
2196
  logAndThrow(`Invalid transfer type '${transferType}'. Valid transfer types are 'private', 'privateToPublic', 'public', and 'publicToPrivate'.`);
3011
2197
  }
3012
2198
 
3013
- const KEY_STORE = Metadata.baseUrl();
3014
- function convert(metadata) {
3015
- // This looks up the method name in VerifyingKey
3016
- const verifyingKey = VerifyingKey[metadata.verifyingKey];
3017
- if (!verifyingKey) {
3018
- throw new Error("Invalid method name: " + metadata.verifyingKey);
3019
- }
3020
- return {
3021
- name: metadata.name,
3022
- locator: metadata.locator,
3023
- prover: metadata.prover,
3024
- verifier: metadata.verifier,
3025
- verifyingKey,
3026
- };
3027
- }
3028
- const CREDITS_PROGRAM_KEYS = {
3029
- bond_public: convert(Metadata.bond_public()),
3030
- bond_validator: convert(Metadata.bond_validator()),
3031
- claim_unbond_public: convert(Metadata.claim_unbond_public()),
3032
- fee_private: convert(Metadata.fee_private()),
3033
- fee_public: convert(Metadata.fee_public()),
3034
- inclusion: convert(Metadata.inclusion()),
3035
- join: convert(Metadata.join()),
3036
- set_validator_state: convert(Metadata.set_validator_state()),
3037
- split: convert(Metadata.split()),
3038
- transfer_private: convert(Metadata.transfer_private()),
3039
- transfer_private_to_public: convert(Metadata.transfer_private_to_public()),
3040
- transfer_public: convert(Metadata.transfer_public()),
3041
- transfer_public_as_signer: convert(Metadata.transfer_public_as_signer()),
3042
- transfer_public_to_private: convert(Metadata.transfer_public_to_private()),
3043
- unbond_public: convert(Metadata.unbond_public()),
3044
- getKey: function (key) {
3045
- if (this.hasOwnProperty(key)) {
3046
- return this[key];
3047
- }
3048
- else {
3049
- return new Error(`Key "${key}" not found.`);
3050
- }
3051
- }
3052
- };
3053
- const PRIVATE_TRANSFER_TYPES = new Set([
3054
- "transfer_private",
3055
- "private",
3056
- "transferPrivate",
3057
- "transfer_private_to_public",
3058
- "privateToPublic",
3059
- "transferPrivateToPublic",
3060
- ]);
3061
- const VALID_TRANSFER_TYPES = new Set([
3062
- "transfer_private",
3063
- "private",
3064
- "transferPrivate",
3065
- "transfer_private_to_public",
3066
- "privateToPublic",
3067
- "transferPrivateToPublic",
3068
- "transfer_public",
3069
- "transfer_public_as_signer",
3070
- "public",
3071
- "public_as_signer",
3072
- "transferPublic",
3073
- "transferPublicAsSigner",
3074
- "transfer_public_to_private",
3075
- "publicToPrivate",
3076
- "publicAsSigner",
3077
- "transferPublicToPrivate",
3078
- ]);
3079
- const PRIVATE_TRANSFER = new Set([
3080
- "private",
3081
- "transfer_private",
3082
- "transferPrivate",
3083
- ]);
3084
- const PRIVATE_TO_PUBLIC_TRANSFER = new Set([
3085
- "private_to_public",
3086
- "privateToPublic",
3087
- "transfer_private_to_public",
3088
- "transferPrivateToPublic",
3089
- ]);
3090
- const PUBLIC_TRANSFER = new Set([
3091
- "public",
3092
- "transfer_public",
3093
- "transferPublic",
3094
- ]);
3095
- const PUBLIC_TRANSFER_AS_SIGNER = new Set([
3096
- "public_as_signer",
3097
- "transfer_public_as_signer",
3098
- "transferPublicAsSigner",
3099
- ]);
3100
- const PUBLIC_TO_PRIVATE_TRANSFER = new Set([
3101
- "public_to_private",
3102
- "publicToPrivate",
3103
- "transfer_public_to_private",
3104
- "transferPublicToPrivate",
3105
- ]);
3106
- function logAndThrow(message) {
3107
- console.error(message);
3108
- throw message;
3109
- }
3110
- // @TODO: This function is no longer needed, remove it.
3111
- async function initializeWasm() {
3112
- console.warn("initializeWasm is deprecated, you no longer need to use it");
3113
- }
3114
-
3115
- export { Account, AleoKeyProvider, AleoKeyProviderParams, AleoNetworkClient, BlockHeightSearch, CREDITS_PROGRAM_KEYS, KEY_STORE, NetworkRecordProvider, OfflineKeyProvider, OfflineSearchParams, PRIVATE_TO_PUBLIC_TRANSFER, PRIVATE_TRANSFER, PRIVATE_TRANSFER_TYPES, PUBLIC_TO_PRIVATE_TRANSFER, PUBLIC_TRANSFER, PUBLIC_TRANSFER_AS_SIGNER, ProgramManager, VALID_TRANSFER_TYPES, createAleoWorker, initializeWasm, logAndThrow };
3116
- //# sourceMappingURL=index.js.map
2199
+ export { AleoKeyProvider as A, CREDITS_PROGRAM_KEYS as C, KEY_STORE as K, ProgramManager as P, VALID_TRANSFER_TYPES as V, AleoKeyProviderParams as a, AleoNetworkClient as b, PRIVATE_TRANSFER as c, PRIVATE_TO_PUBLIC_TRANSFER as d, PRIVATE_TRANSFER_TYPES as e, PUBLIC_TRANSFER as f, PUBLIC_TRANSFER_AS_SIGNER as g, PUBLIC_TO_PRIVATE_TRANSFER as h, logAndThrow as l };
2200
+ //# sourceMappingURL=program-manager-97ade0e6.js.map