@provablehq/sdk 0.7.5 → 0.8.0

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 (78) hide show
  1. package/README.md +3 -3
  2. package/dist/mainnet/browser.d.ts +23 -8
  3. package/dist/mainnet/browser.js +3 -3
  4. package/dist/mainnet/browser.js.map +1 -1
  5. package/dist/mainnet/constants.d.ts +1 -1
  6. package/dist/mainnet/models/{block.d.ts → blockJSON.d.ts} +3 -3
  7. package/dist/mainnet/models/confirmed_transaction.d.ts +8 -5
  8. package/dist/mainnet/models/deployment/deploymentJSON.d.ts +6 -0
  9. package/dist/mainnet/models/deployment/deploymentObject.d.ts +6 -0
  10. package/dist/mainnet/models/execution/executionJSON.d.ts +11 -0
  11. package/dist/mainnet/models/execution/executionObject.d.ts +11 -0
  12. package/dist/mainnet/models/finalizeJSON.d.ts +6 -0
  13. package/dist/mainnet/models/functionObject.d.ts +8 -0
  14. package/dist/mainnet/models/input/inputJSON.d.ts +9 -0
  15. package/dist/mainnet/models/input/inputObject.d.ts +14 -0
  16. package/dist/mainnet/models/output/outputJSON.d.ts +6 -0
  17. package/dist/mainnet/models/output/outputObject.d.ts +17 -0
  18. package/dist/mainnet/models/owner/ownerJSON.d.ts +4 -0
  19. package/dist/mainnet/models/owner/ownerObject.d.ts +5 -0
  20. package/dist/mainnet/models/plaintext/array.d.ts +3 -0
  21. package/dist/mainnet/models/plaintext/literal.d.ts +1 -0
  22. package/dist/mainnet/models/plaintext/plaintext.d.ts +5 -0
  23. package/dist/mainnet/models/plaintext/struct.d.ts +5 -0
  24. package/dist/mainnet/models/transaction/transactionJSON.d.ts +11 -0
  25. package/dist/mainnet/models/transaction/transactionObject.d.ts +14 -0
  26. package/dist/mainnet/models/transition/transitionJSON.d.ts +13 -0
  27. package/dist/mainnet/models/transition/transitionObject.d.ts +15 -0
  28. package/dist/mainnet/network-client.d.ts +120 -32
  29. package/dist/mainnet/node.js +2 -2
  30. package/dist/mainnet/{program-manager-a25c2f23.js → program-manager-D6bnpC8Y.js} +168 -30
  31. package/dist/mainnet/program-manager-D6bnpC8Y.js.map +1 -0
  32. package/dist/mainnet/wasm.d.ts +1 -1
  33. package/dist/mainnet/worker.js +1 -1
  34. package/dist/testnet/browser.d.ts +23 -8
  35. package/dist/testnet/browser.js +3 -3
  36. package/dist/testnet/browser.js.map +1 -1
  37. package/dist/testnet/constants.d.ts +1 -1
  38. package/dist/testnet/models/{block.d.ts → blockJSON.d.ts} +3 -3
  39. package/dist/testnet/models/confirmed_transaction.d.ts +8 -5
  40. package/dist/testnet/models/deployment/deploymentJSON.d.ts +6 -0
  41. package/dist/testnet/models/deployment/deploymentObject.d.ts +6 -0
  42. package/dist/testnet/models/execution/executionJSON.d.ts +11 -0
  43. package/dist/testnet/models/execution/executionObject.d.ts +11 -0
  44. package/dist/testnet/models/finalizeJSON.d.ts +6 -0
  45. package/dist/testnet/models/functionObject.d.ts +8 -0
  46. package/dist/testnet/models/input/inputJSON.d.ts +9 -0
  47. package/dist/testnet/models/input/inputObject.d.ts +14 -0
  48. package/dist/testnet/models/output/outputJSON.d.ts +6 -0
  49. package/dist/testnet/models/output/outputObject.d.ts +17 -0
  50. package/dist/testnet/models/owner/ownerJSON.d.ts +4 -0
  51. package/dist/testnet/models/owner/ownerObject.d.ts +5 -0
  52. package/dist/testnet/models/plaintext/array.d.ts +3 -0
  53. package/dist/testnet/models/plaintext/literal.d.ts +1 -0
  54. package/dist/testnet/models/plaintext/plaintext.d.ts +5 -0
  55. package/dist/testnet/models/plaintext/struct.d.ts +5 -0
  56. package/dist/testnet/models/transaction/transactionJSON.d.ts +11 -0
  57. package/dist/testnet/models/transaction/transactionObject.d.ts +14 -0
  58. package/dist/testnet/models/transition/transitionJSON.d.ts +13 -0
  59. package/dist/testnet/models/transition/transitionObject.d.ts +15 -0
  60. package/dist/testnet/network-client.d.ts +120 -32
  61. package/dist/testnet/node.js +2 -2
  62. package/dist/testnet/{program-manager-4e9a7ef4.js → program-manager-DePEqzhz.js} +168 -30
  63. package/dist/testnet/program-manager-DePEqzhz.js.map +1 -0
  64. package/dist/testnet/wasm.d.ts +1 -1
  65. package/dist/testnet/worker.js +1 -1
  66. package/package.json +7 -7
  67. package/dist/mainnet/models/execution.d.ts +0 -5
  68. package/dist/mainnet/models/input.d.ts +0 -10
  69. package/dist/mainnet/models/output.d.ts +0 -6
  70. package/dist/mainnet/models/transactionModel.d.ts +0 -6
  71. package/dist/mainnet/models/transition.d.ts +0 -13
  72. package/dist/mainnet/program-manager-a25c2f23.js.map +0 -1
  73. package/dist/testnet/models/execution.d.ts +0 -5
  74. package/dist/testnet/models/input.d.ts +0 -10
  75. package/dist/testnet/models/output.d.ts +0 -6
  76. package/dist/testnet/models/transactionModel.d.ts +0 -6
  77. package/dist/testnet/models/transition.d.ts +0 -13
  78. package/dist/testnet/program-manager-4e9a7ef4.js.map +0 -1
@@ -1,7 +1,8 @@
1
1
  import { Account } from "./account";
2
- import { Block } from "./models/block";
3
- import { TransactionModel } from "./models/transactionModel";
4
- import { Program, RecordPlaintext, PrivateKey, Transaction } from "./wasm";
2
+ import { BlockJSON } from "./models/blockJSON";
3
+ import { TransactionJSON } from "./models/transaction/transactionJSON";
4
+ import { Plaintext, Program, RecordPlaintext, PrivateKey, Transaction } from "./wasm";
5
+ import { ConfirmedTransactionJSON } from "./models/confirmed_transaction";
5
6
  type ProgramImports = {
6
7
  [key: string]: string | Program;
7
8
  };
@@ -52,9 +53,23 @@ declare class AleoNetworkClient {
52
53
  * @param host
53
54
  */
54
55
  setHost(host: string): void;
56
+ /**
57
+ * Fetches data from the Aleo network and returns it as a JSON object.
58
+ *
59
+ * @param url
60
+ */
55
61
  fetchData<Type>(url?: string): Promise<Type>;
56
62
  /**
57
- * Attempts to find unspent records in the Aleo blockchain for a specified private key
63
+ * Fetches data from the Aleo network and returns it as an unparsed string.
64
+ *
65
+ * This method should be used when it is desired to reconstitute data returned
66
+ * from the network into a WASM object.
67
+ *
68
+ * @param url
69
+ */
70
+ fetchRaw(url?: string): Promise<string>;
71
+ /**
72
+ * Attempts to find unspent records in the Aleo blockchain for a specified private key.
58
73
  * @param {number} startHeight - The height at which to start searching for unspent records
59
74
  * @param {number} endHeight - The height at which to stop searching for unspent records
60
75
  * @param {string | PrivateKey} privateKey - The private key to use to find unspent records
@@ -78,58 +93,65 @@ declare class AleoNetworkClient {
78
93
  */
79
94
  findUnspentRecords(startHeight: number, endHeight: number | undefined, privateKey: string | PrivateKey | undefined, amounts: number[] | undefined, maxMicrocredits?: number | undefined, nonces?: string[] | undefined): Promise<Array<RecordPlaintext>>;
80
95
  /**
81
- * Returns the contents of the block at the specified block height
96
+ * Returns the contents of the block at the specified block height.
82
97
  *
83
98
  * @param {number} height
84
99
  * @example
85
100
  * const block = networkClient.getBlock(1234);
86
101
  */
87
- getBlock(height: number): Promise<Block>;
102
+ getBlock(height: number): Promise<BlockJSON>;
88
103
  /**
89
- * Returns a range of blocks between the specified block heights
104
+ * Returns a range of blocks between the specified block heights.
90
105
  *
91
106
  * @param {number} start
92
107
  * @param {number} end
93
108
  * @example
94
109
  * const blockRange = networkClient.getBlockRange(2050, 2100);
95
110
  */
96
- getBlockRange(start: number, end: number): Promise<Array<Block>>;
111
+ getBlockRange(start: number, end: number): Promise<Array<BlockJSON>>;
97
112
  /**
98
- * Returns the deployment transaction id associated with the specified program
113
+ * Returns the deployment transaction id associated with the specified program.
99
114
  *
100
115
  * @param {Program | string} program
101
- * @returns {TransactionModel}
116
+ * @returns {TransactionJSON}
102
117
  */
103
118
  getDeploymentTransactionIDForProgram(program: Program | string): Promise<string>;
104
119
  /**
105
- * Returns the deployment transaction associated with a specified program
120
+ * Returns the deployment transaction associated with a specified program.
106
121
  *
107
122
  * @param {Program | string} program
108
- * @returns {TransactionModel}
123
+ * @returns {TransactionJSON}
109
124
  */
110
- getDeploymentTransactionForProgram(program: Program | string): Promise<TransactionModel>;
125
+ getDeploymentTransactionForProgram(program: Program | string): Promise<TransactionJSON>;
111
126
  /**
112
- * Returns the contents of the latest block
127
+ * Returns the deployment transaction associated with a specified program as a wasm object.
128
+ *
129
+ * @param {Program | string} program
130
+ * @returns {TransactionJSON}
131
+ */
132
+ getDeploymentTransactioObjectnForProgram(program: Program | string): Promise<Transaction>;
133
+ /**
134
+ * Returns the contents of the latest block.
113
135
  *
114
136
  * @example
115
137
  * const latestHeight = networkClient.getLatestBlock();
116
138
  */
117
- getLatestBlock(): Promise<Block>;
139
+ getLatestBlock(): Promise<BlockJSON>;
118
140
  /**
119
- * Returns the latest committee
141
+ * Returns the latest committee.
120
142
  *
121
143
  * @returns {Promise<object>} A javascript object containing the latest committee
122
144
  */
123
145
  getLatestCommittee(): Promise<object>;
124
146
  /**
125
- * Returns the latest block height
147
+ * Returns the latest block height.
126
148
  *
127
149
  * @example
128
150
  * const latestHeight = networkClient.getLatestHeight();
129
151
  */
130
152
  getLatestHeight(): Promise<number>;
131
153
  /**
132
- * Returns the source code of a program given a program ID
154
+ * Returns the source code of a program given a program ID.
133
155
  *
134
156
  * @param {string} programId The program ID of a program deployed to the Aleo Network
135
157
  * @return {Promise<string>} Source code of the program
@@ -141,7 +163,7 @@ declare class AleoNetworkClient {
141
163
  */
142
164
  getProgram(programId: string): Promise<string>;
143
165
  /**
144
- * Returns a program object from a program ID or program source code
166
+ * Returns a program object from a program ID or program source code.
145
167
  *
146
168
  * @param {string} inputProgram The program ID or program source code of a program deployed to the Aleo Network
147
169
  * @return {Promise<Program>} Source code of the program
@@ -185,7 +207,7 @@ declare class AleoNetworkClient {
185
207
  */
186
208
  getProgramImports(inputProgram: Program | string): Promise<ProgramImports>;
187
209
  /**
188
- * Get a list of the program names that a program imports
210
+ * Get a list of the program names that a program imports.
189
211
  *
190
212
  * @param {Program | string} inputProgram - The program id or program source code to get the imports of
191
213
  * @returns {string[]} - The list of program names that the program imports
@@ -197,7 +219,7 @@ declare class AleoNetworkClient {
197
219
  */
198
220
  getProgramImportNames(inputProgram: Program | string): Promise<string[]>;
199
221
  /**
200
- * Returns the names of the mappings of a program
222
+ * Returns the names of the mappings of a program.
201
223
  *
202
224
  * @param {string} programId - The program ID to get the mappings of (e.g. "credits.aleo")
203
225
  * @example
@@ -207,11 +229,11 @@ declare class AleoNetworkClient {
207
229
  */
208
230
  getProgramMappingNames(programId: string): Promise<Array<string>>;
209
231
  /**
210
- * Returns the value of a program's mapping for a specific key
232
+ * Returns the value of a program's mapping for a specific key.
211
233
  *
212
234
  * @param {string} programId - The program ID to get the mapping value of (e.g. "credits.aleo")
213
235
  * @param {string} mappingName - The name of the mapping to get the value of (e.g. "account")
214
- * @param {string} key - The key of the mapping to get the value of (e.g. "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px")
236
+ * @param {string | Plaintext} key - The key of the mapping to get the value of (e.g. "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px")
215
237
  * @return {Promise<string>} String representation of the value of the mapping
216
238
  *
217
239
  * @example
@@ -220,37 +242,97 @@ declare class AleoNetworkClient {
220
242
  * const expectedValue = "0u64";
221
243
  * assert.equal(mappingValue, expectedValue);
222
244
  */
223
- getProgramMappingValue(programId: string, mappingName: string, key: string): Promise<string>;
245
+ getProgramMappingValue(programId: string, mappingName: string, key: string | Plaintext): Promise<string>;
224
246
  /**
225
- * Returns the latest state/merkle root of the Aleo blockchain
247
+ * Returns the value of a mapping as a wasm Plaintext object. Returning an
248
+ * object in this format allows it to be converted to a Js type and for its
249
+ * internal members to be inspected if it's a struct or array.
250
+ *
251
+ * @example
252
+ * // Get the bond state as an account.
253
+ * const unbondedState = networkClient.getMappingPlaintext("credits.aleo", "bonded", "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px");
254
+ *
255
+ * // Get the two members of the object individually.
256
+ * const validator = unbondedState.getMember("validator");
257
+ * const microcredits = unbondedState.getMember("microcredits");
258
+ *
259
+ * // Ensure the expected values are correct.
260
+ * assert.equal(validator, "aleo1u6940v5m0fzud859xx2c9tj2gjg6m5qrd28n636e6fdd2akvfcgqs34mfd");
261
+ * assert.equal(microcredits, BigInt("9007199254740991"));
262
+ *
263
+ * // Get a JS object representation of the unbonded state.
264
+ * const unbondedStateObject = unbondedState.toObject();
265
+ *
266
+ * const expectedState = {
267
+ * validator: "aleo1u6940v5m0fzud859xx2c9tj2gjg6m5qrd28n636e6fdd2akvfcgqs34mfd",
268
+ * microcredits: BigInt("9007199254740991")
269
+ * };
270
+ * assert.equal(unbondedState, expectedState);
271
+ *
272
+ * @param {string} programId - The program ID to get the mapping value of (e.g. "credits.aleo")
273
+ * @param {string} mappingName - The name of the mapping to get the value of (e.g. "account")
274
+ * @param {string | Plaintext} key - The key of the mapping to get the value of (e.g. "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px")
275
+ *
276
+ * @return {Promise<string>} String representation of the value of the mapping
277
+ */
278
+ getProgramMappingPlaintext(programId: string, mappingName: string, key: string | Plaintext): Promise<Plaintext>;
279
+ /**
280
+ * Returns the latest state/merkle root of the Aleo blockchain.
226
281
  *
227
282
  * @example
228
283
  * const stateRoot = networkClient.getStateRoot();
229
284
  */
230
285
  getStateRoot(): Promise<string>;
231
286
  /**
232
- * Returns a transaction by its unique identifier
287
+ * Returns a transaction by its unique identifier.
233
288
  *
234
289
  * @param {string} id
235
290
  * @example
236
291
  * const transaction = networkClient.getTransaction("at1handz9xjrqeynjrr0xay4pcsgtnczdksz3e584vfsgaz0dh0lyxq43a4wj");
237
292
  */
238
- getTransaction(id: string): Promise<TransactionModel>;
293
+ getTransaction(transactionId: string): Promise<TransactionJSON>;
294
+ /**
295
+ * Returns a transaction as a wasm object. Getting a transaction of this type will allow the ability for the inputs,
296
+ * outputs, and records to be searched for and displayed.
297
+ *
298
+ * @example
299
+ * const transactionObject = networkClient.getTransaction("at1handz9xjrqeynjrr0xay4pcsgtnczdksz3e584vfsgaz0dh0lyxq43a4wj");
300
+ * // Get the transaction inputs as a JS array.
301
+ * const transactionOutputs = transactionObject.inputs(true);
302
+ *
303
+ * // Get the transaction outputs as a JS object.
304
+ * const transactionInputs = transactionObject.outputs(true);
305
+ *
306
+ * // Get any records generated in transitions in the transaction as a JS object.
307
+ * const records = transactionObject.records();
308
+ *
309
+ * // Get the transaction type.
310
+ * const transactionType = transactionObject.transactionType();
311
+ * assert.equal(transactionType, "Execute");
312
+ *
313
+ * // Get a JS representation of all inputs, outputs, and transaction metadata.
314
+ * const transactionSummary = transactionObject.summary();
315
+ *
316
+ * @param {string} transactionId
317
+ * @example
318
+ * const transaction = networkClient.getTransactionObject("at1handz9xjrqeynjrr0xay4pcsgtnczdksz3e584vfsgaz0dh0lyxq43a4wj");
319
+ */
320
+ getTransactionObject(transactionId: string): Promise<Transaction>;
239
321
  /**
240
- * Returns the transactions present at the specified block height
322
+ * Returns the transactions present at the specified block height.
241
323
  *
242
324
  * @param {number} height
243
325
  * @example
244
326
  * const transactions = networkClient.getTransactions(654);
245
327
  */
246
- getTransactions(height: number): Promise<Array<TransactionModel>>;
328
+ getTransactions(height: number): Promise<Array<ConfirmedTransactionJSON>>;
247
329
  /**
248
- * Returns the transactions in the memory pool.
330
+ * Returns the transactions in the memory pool. This method requires access to a validator's REST API.
249
331
  *
250
332
  * @example
251
333
  * const transactions = networkClient.getTransactionsInMempool();
252
334
  */
253
- getTransactionsInMempool(): Promise<Array<TransactionModel>>;
335
+ getTransactionsInMempool(): Promise<Array<TransactionJSON>>;
254
336
  /**
255
337
  * Returns the transition ID of the transition corresponding to the ID of the input or output.
256
338
  * @param {string} inputOrOutputID - ID of the input or output.
@@ -260,11 +342,17 @@ declare class AleoNetworkClient {
260
342
  */
261
343
  getTransitionId(inputOrOutputID: string): Promise<string>;
262
344
  /**
263
- * Submit an execute or deployment transaction to the Aleo network
345
+ * Submit an execute or deployment transaction to the Aleo network.
264
346
  *
265
347
  * @param {Transaction | string} transaction - The transaction to submit to the network
266
348
  * @returns {string} - The transaction id of the submitted transaction or the resulting error
267
349
  */
268
350
  submitTransaction(transaction: Transaction | string): Promise<string>;
351
+ /**
352
+ * Submit a solution to the Aleo network.
353
+ *
354
+ * @param {string} solution The string representation of the solution desired to be submitted to the network.
355
+ */
356
+ submitSolution(solution: string): Promise<string>;
269
357
  }
270
358
  export { AleoNetworkClient, AleoNetworkClientOptions, ProgramImports };
@@ -1,7 +1,7 @@
1
1
  import './node-polyfill.js';
2
2
  export { Account, BlockHeightSearch, NetworkRecordProvider, OfflineKeyProvider, OfflineSearchParams, createAleoWorker, initializeWasm } from './browser.js';
3
- export { A as AleoKeyProvider, a as AleoKeyProviderParams, b as AleoNetworkClient, C as CREDITS_PROGRAM_KEYS, K as KEY_STORE, d as PRIVATE_TO_PUBLIC_TRANSFER, c as PRIVATE_TRANSFER, e as PRIVATE_TRANSFER_TYPES, h as PUBLIC_TO_PRIVATE_TRANSFER, f as PUBLIC_TRANSFER, g as PUBLIC_TRANSFER_AS_SIGNER, P as ProgramManager, V as VALID_TRANSFER_TYPES, l as logAndThrow } from './program-manager-4e9a7ef4.js';
4
- 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/testnet.js';
3
+ export { A as AleoKeyProvider, a as AleoKeyProviderParams, b as AleoNetworkClient, C as CREDITS_PROGRAM_KEYS, K as KEY_STORE, d as PRIVATE_TO_PUBLIC_TRANSFER, c as PRIVATE_TRANSFER, e as PRIVATE_TRANSFER_TYPES, h as PUBLIC_TO_PRIVATE_TRANSFER, f as PUBLIC_TRANSFER, g as PUBLIC_TRANSFER_AS_SIGNER, P as ProgramManager, V as VALID_TRANSFER_TYPES, l as logAndThrow } from './program-manager-DePEqzhz.js';
4
+ export { Address, Ciphertext, ExecutionResponse, Field, Execution as FunctionExecution, Group, OfflineQuery, Plaintext, PrivateKey, PrivateKeyCiphertext, Program, ProgramManager as ProgramManagerBase, ProvingKey, RecordCiphertext, RecordPlaintext, Scalar, Signature, Transaction, Transition, VerifyingKey, ViewKey, initThreadPool, verifyFunctionExecution } from '@provablehq/wasm/testnet.js';
5
5
  import 'core-js/proposals/json-parse-with-source.js';
6
6
  import 'node:crypto';
7
7
  import 'node:fs';
@@ -1,4 +1,4 @@
1
- import { PrivateKey, RecordCiphertext, Program, Transaction, Metadata, VerifyingKey, ProvingKey, ProgramManager as ProgramManager$1, RecordPlaintext, verifyFunctionExecution } from '@provablehq/wasm/testnet.js';
1
+ import { PrivateKey, RecordCiphertext, Program, Plaintext, Transaction, Metadata, VerifyingKey, ProvingKey, ProgramManager as ProgramManager$1, RecordPlaintext, verifyFunctionExecution } from '@provablehq/wasm/testnet.js';
2
2
 
3
3
  function logAndThrow(message) {
4
4
  console.error(message);
@@ -55,7 +55,7 @@ class AleoNetworkClient {
55
55
  else {
56
56
  this.headers = {
57
57
  // This is replaced by the actual version by a Rollup plugin
58
- "X-Aleo-SDK-Version": "0.7.4",
58
+ "X-Aleo-SDK-Version": "0.8.0",
59
59
  };
60
60
  }
61
61
  }
@@ -88,20 +88,40 @@ class AleoNetworkClient {
88
88
  setHost(host) {
89
89
  this.host = host + "/testnet";
90
90
  }
91
+ /**
92
+ * Fetches data from the Aleo network and returns it as a JSON object.
93
+ *
94
+ * @param url
95
+ */
91
96
  async fetchData(url = "/") {
97
+ try {
98
+ return parseJSON(await this.fetchRaw(url));
99
+ }
100
+ catch (error) {
101
+ throw new Error("Error fetching data.");
102
+ }
103
+ }
104
+ /**
105
+ * Fetches data from the Aleo network and returns it as an unparsed string.
106
+ *
107
+ * This method should be used when it is desired to reconstitute data returned
108
+ * from the network into a WASM object.
109
+ *
110
+ * @param url
111
+ */
112
+ async fetchRaw(url = "/") {
92
113
  try {
93
114
  const response = await get(this.host + url, {
94
115
  headers: this.headers
95
116
  });
96
- const text = await response.text();
97
- return parseJSON(text);
117
+ return await response.text();
98
118
  }
99
119
  catch (error) {
100
120
  throw new Error("Error fetching data.");
101
121
  }
102
122
  }
103
123
  /**
104
- * Attempts to find unspent records in the Aleo blockchain for a specified private key
124
+ * Attempts to find unspent records in the Aleo blockchain for a specified private key.
105
125
  * @param {number} startHeight - The height at which to start searching for unspent records
106
126
  * @param {number} endHeight - The height at which to stop searching for unspent records
107
127
  * @param {string | PrivateKey} privateKey - The private key to use to find unspent records
@@ -289,7 +309,7 @@ class AleoNetworkClient {
289
309
  return records;
290
310
  }
291
311
  /**
292
- * Returns the contents of the block at the specified block height
312
+ * Returns the contents of the block at the specified block height.
293
313
  *
294
314
  * @param {number} height
295
315
  * @example
@@ -305,7 +325,7 @@ class AleoNetworkClient {
305
325
  }
306
326
  }
307
327
  /**
308
- * Returns a range of blocks between the specified block heights
328
+ * Returns a range of blocks between the specified block heights.
309
329
  *
310
330
  * @param {number} start
311
331
  * @param {number} end
@@ -322,10 +342,10 @@ class AleoNetworkClient {
322
342
  }
323
343
  }
324
344
  /**
325
- * Returns the deployment transaction id associated with the specified program
345
+ * Returns the deployment transaction id associated with the specified program.
326
346
  *
327
347
  * @param {Program | string} program
328
- * @returns {TransactionModel}
348
+ * @returns {TransactionJSON}
329
349
  */
330
350
  async getDeploymentTransactionIDForProgram(program) {
331
351
  if (program instanceof Program) {
@@ -340,10 +360,10 @@ class AleoNetworkClient {
340
360
  }
341
361
  }
342
362
  /**
343
- * Returns the deployment transaction associated with a specified program
363
+ * Returns the deployment transaction associated with a specified program.
344
364
  *
345
365
  * @param {Program | string} program
346
- * @returns {TransactionModel}
366
+ * @returns {TransactionJSON}
347
367
  */
348
368
  async getDeploymentTransactionForProgram(program) {
349
369
  try {
@@ -355,7 +375,22 @@ class AleoNetworkClient {
355
375
  }
356
376
  }
357
377
  /**
358
- * Returns the contents of the latest block
378
+ * Returns the deployment transaction associated with a specified program as a wasm object.
379
+ *
380
+ * @param {Program | string} program
381
+ * @returns {TransactionJSON}
382
+ */
383
+ async getDeploymentTransactioObjectnForProgram(program) {
384
+ try {
385
+ const transaction_id = await this.getDeploymentTransactionIDForProgram(program);
386
+ return await this.getTransactionObject(transaction_id);
387
+ }
388
+ catch (error) {
389
+ throw new Error("Error fetching deployment transaction for program.");
390
+ }
391
+ }
392
+ /**
393
+ * Returns the contents of the latest block.
359
394
  *
360
395
  * @example
361
396
  * const latestHeight = networkClient.getLatestBlock();
@@ -369,7 +404,7 @@ class AleoNetworkClient {
369
404
  }
370
405
  }
371
406
  /**
372
- * Returns the latest committee
407
+ * Returns the latest committee.
373
408
  *
374
409
  * @returns {Promise<object>} A javascript object containing the latest committee
375
410
  */
@@ -382,7 +417,7 @@ class AleoNetworkClient {
382
417
  }
383
418
  }
384
419
  /**
385
- * Returns the latest block height
420
+ * Returns the latest block height.
386
421
  *
387
422
  * @example
388
423
  * const latestHeight = networkClient.getLatestHeight();
@@ -396,7 +431,7 @@ class AleoNetworkClient {
396
431
  }
397
432
  }
398
433
  /**
399
- * Returns the source code of a program given a program ID
434
+ * Returns the source code of a program given a program ID.
400
435
  *
401
436
  * @param {string} programId The program ID of a program deployed to the Aleo Network
402
437
  * @return {Promise<string>} Source code of the program
@@ -415,7 +450,7 @@ class AleoNetworkClient {
415
450
  }
416
451
  }
417
452
  /**
418
- * Returns a program object from a program ID or program source code
453
+ * Returns a program object from a program ID or program source code.
419
454
  *
420
455
  * @param {string} inputProgram The program ID or program source code of a program deployed to the Aleo Network
421
456
  * @return {Promise<Program>} Source code of the program
@@ -497,7 +532,7 @@ class AleoNetworkClient {
497
532
  }
498
533
  }
499
534
  /**
500
- * Get a list of the program names that a program imports
535
+ * Get a list of the program names that a program imports.
501
536
  *
502
537
  * @param {Program | string} inputProgram - The program id or program source code to get the imports of
503
538
  * @returns {string[]} - The list of program names that the program imports
@@ -517,7 +552,7 @@ class AleoNetworkClient {
517
552
  }
518
553
  }
519
554
  /**
520
- * Returns the names of the mappings of a program
555
+ * Returns the names of the mappings of a program.
521
556
  *
522
557
  * @param {string} programId - The program ID to get the mappings of (e.g. "credits.aleo")
523
558
  * @example
@@ -534,11 +569,11 @@ class AleoNetworkClient {
534
569
  }
535
570
  }
536
571
  /**
537
- * Returns the value of a program's mapping for a specific key
572
+ * Returns the value of a program's mapping for a specific key.
538
573
  *
539
574
  * @param {string} programId - The program ID to get the mapping value of (e.g. "credits.aleo")
540
575
  * @param {string} mappingName - The name of the mapping to get the value of (e.g. "account")
541
- * @param {string} key - The key of the mapping to get the value of (e.g. "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px")
576
+ * @param {string | Plaintext} key - The key of the mapping to get the value of (e.g. "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px")
542
577
  * @return {Promise<string>} String representation of the value of the mapping
543
578
  *
544
579
  * @example
@@ -549,14 +584,57 @@ class AleoNetworkClient {
549
584
  */
550
585
  async getProgramMappingValue(programId, mappingName, key) {
551
586
  try {
552
- return await this.fetchData("/program/" + programId + "/mapping/" + mappingName + "/" + key);
587
+ const keyString = key instanceof Plaintext ? key.toString() : key;
588
+ return await this.fetchData("/program/" + programId + "/mapping/" + mappingName + "/" + keyString);
553
589
  }
554
590
  catch (error) {
555
591
  throw new Error("Error fetching mapping value - ensure the mapping exists and the key is correct");
556
592
  }
557
593
  }
558
594
  /**
559
- * Returns the latest state/merkle root of the Aleo blockchain
595
+ * Returns the value of a mapping as a wasm Plaintext object. Returning an
596
+ * object in this format allows it to be converted to a Js type and for its
597
+ * internal members to be inspected if it's a struct or array.
598
+ *
599
+ * @example
600
+ * // Get the bond state as an account.
601
+ * const unbondedState = networkClient.getMappingPlaintext("credits.aleo", "bonded", "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px");
602
+ *
603
+ * // Get the two members of the object individually.
604
+ * const validator = unbondedState.getMember("validator");
605
+ * const microcredits = unbondedState.getMember("microcredits");
606
+ *
607
+ * // Ensure the expected values are correct.
608
+ * assert.equal(validator, "aleo1u6940v5m0fzud859xx2c9tj2gjg6m5qrd28n636e6fdd2akvfcgqs34mfd");
609
+ * assert.equal(microcredits, BigInt("9007199254740991"));
610
+ *
611
+ * // Get a JS object representation of the unbonded state.
612
+ * const unbondedStateObject = unbondedState.toObject();
613
+ *
614
+ * const expectedState = {
615
+ * validator: "aleo1u6940v5m0fzud859xx2c9tj2gjg6m5qrd28n636e6fdd2akvfcgqs34mfd",
616
+ * microcredits: BigInt("9007199254740991")
617
+ * };
618
+ * assert.equal(unbondedState, expectedState);
619
+ *
620
+ * @param {string} programId - The program ID to get the mapping value of (e.g. "credits.aleo")
621
+ * @param {string} mappingName - The name of the mapping to get the value of (e.g. "account")
622
+ * @param {string | Plaintext} key - The key of the mapping to get the value of (e.g. "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px")
623
+ *
624
+ * @return {Promise<string>} String representation of the value of the mapping
625
+ */
626
+ async getProgramMappingPlaintext(programId, mappingName, key) {
627
+ try {
628
+ const keyString = key instanceof Plaintext ? key.toString() : key;
629
+ const value = await this.fetchRaw("/program/" + programId + "/mapping/" + mappingName + "/" + keyString);
630
+ return Plaintext.fromString(JSON.parse(value));
631
+ }
632
+ catch (error) {
633
+ throw new Error("Failed to fetch mapping value." + error);
634
+ }
635
+ }
636
+ /**
637
+ * Returns the latest state/merkle root of the Aleo blockchain.
560
638
  *
561
639
  * @example
562
640
  * const stateRoot = networkClient.getStateRoot();
@@ -570,22 +648,57 @@ class AleoNetworkClient {
570
648
  }
571
649
  }
572
650
  /**
573
- * Returns a transaction by its unique identifier
651
+ * Returns a transaction by its unique identifier.
574
652
  *
575
653
  * @param {string} id
576
654
  * @example
577
655
  * const transaction = networkClient.getTransaction("at1handz9xjrqeynjrr0xay4pcsgtnczdksz3e584vfsgaz0dh0lyxq43a4wj");
578
656
  */
579
- async getTransaction(id) {
657
+ async getTransaction(transactionId) {
658
+ try {
659
+ return await this.fetchData("/transaction/" + transactionId);
660
+ }
661
+ catch (error) {
662
+ throw new Error("Error fetching transaction.");
663
+ }
664
+ }
665
+ /**
666
+ * Returns a transaction as a wasm object. Getting a transaction of this type will allow the ability for the inputs,
667
+ * outputs, and records to be searched for and displayed.
668
+ *
669
+ * @example
670
+ * const transactionObject = networkClient.getTransaction("at1handz9xjrqeynjrr0xay4pcsgtnczdksz3e584vfsgaz0dh0lyxq43a4wj");
671
+ * // Get the transaction inputs as a JS array.
672
+ * const transactionOutputs = transactionObject.inputs(true);
673
+ *
674
+ * // Get the transaction outputs as a JS object.
675
+ * const transactionInputs = transactionObject.outputs(true);
676
+ *
677
+ * // Get any records generated in transitions in the transaction as a JS object.
678
+ * const records = transactionObject.records();
679
+ *
680
+ * // Get the transaction type.
681
+ * const transactionType = transactionObject.transactionType();
682
+ * assert.equal(transactionType, "Execute");
683
+ *
684
+ * // Get a JS representation of all inputs, outputs, and transaction metadata.
685
+ * const transactionSummary = transactionObject.summary();
686
+ *
687
+ * @param {string} transactionId
688
+ * @example
689
+ * const transaction = networkClient.getTransactionObject("at1handz9xjrqeynjrr0xay4pcsgtnczdksz3e584vfsgaz0dh0lyxq43a4wj");
690
+ */
691
+ async getTransactionObject(transactionId) {
580
692
  try {
581
- return await this.fetchData("/transaction/" + id);
693
+ const transaction = await this.fetchRaw("/transaction/" + transactionId);
694
+ return Transaction.fromString(transaction);
582
695
  }
583
696
  catch (error) {
584
697
  throw new Error("Error fetching transaction.");
585
698
  }
586
699
  }
587
700
  /**
588
- * Returns the transactions present at the specified block height
701
+ * Returns the transactions present at the specified block height.
589
702
  *
590
703
  * @param {number} height
591
704
  * @example
@@ -596,11 +709,11 @@ class AleoNetworkClient {
596
709
  return await this.fetchData("/block/" + height.toString() + "/transactions");
597
710
  }
598
711
  catch (error) {
599
- throw new Error("Error fetching transactions.");
712
+ throw new Error("Error fetching transactions. " + error);
600
713
  }
601
714
  }
602
715
  /**
603
- * Returns the transactions in the memory pool.
716
+ * Returns the transactions in the memory pool. This method requires access to a validator's REST API.
604
717
  *
605
718
  * @example
606
719
  * const transactions = networkClient.getTransactionsInMempool();
@@ -629,7 +742,7 @@ class AleoNetworkClient {
629
742
  }
630
743
  }
631
744
  /**
632
- * Submit an execute or deployment transaction to the Aleo network
745
+ * Submit an execute or deployment transaction to the Aleo network.
633
746
  *
634
747
  * @param {Transaction | string} transaction - The transaction to submit to the network
635
748
  * @returns {string} - The transaction id of the submitted transaction or the resulting error
@@ -655,6 +768,31 @@ class AleoNetworkClient {
655
768
  throw new Error(`Error posting transaction: No response received: ${error.message}`);
656
769
  }
657
770
  }
771
+ /**
772
+ * Submit a solution to the Aleo network.
773
+ *
774
+ * @param {string} solution The string representation of the solution desired to be submitted to the network.
775
+ */
776
+ async submitSolution(solution) {
777
+ try {
778
+ const response = await post(this.host + "/solution/broadcast", {
779
+ body: solution,
780
+ headers: Object.assign({}, this.headers, {
781
+ "Content-Type": "application/json",
782
+ }),
783
+ });
784
+ try {
785
+ const text = await response.text();
786
+ return parseJSON(text);
787
+ }
788
+ catch (error) {
789
+ throw new Error(`Error posting transaction. Aleo network response: ${error.message}`);
790
+ }
791
+ }
792
+ catch (error) {
793
+ throw new Error(`Error posting transaction: No response received: ${error.message}`);
794
+ }
795
+ }
658
796
  }
659
797
 
660
798
  const KEY_STORE = Metadata.baseUrl();
@@ -2197,4 +2335,4 @@ function validateTransferType(transferType) {
2197
2335
  }
2198
2336
 
2199
2337
  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-4e9a7ef4.js.map
2338
+ //# sourceMappingURL=program-manager-DePEqzhz.js.map