@provablehq/sdk 0.6.13 → 0.7.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 (71) hide show
  1. package/README.md +16 -16
  2. package/dist/{account.d.ts → mainnet/account.d.ts} +3 -3
  3. package/dist/{index.d.ts → mainnet/browser.d.ts} +5 -4
  4. package/dist/mainnet/browser.js +3127 -0
  5. package/dist/mainnet/browser.js.map +1 -0
  6. package/dist/{function-key-provider.d.ts → mainnet/function-key-provider.d.ts} +57 -57
  7. package/dist/{network-client.d.ts → mainnet/network-client.d.ts} +26 -26
  8. package/dist/{node-polyfill.d.ts → mainnet/node-polyfill.d.ts} +1 -0
  9. package/dist/{node-polyfill.js → mainnet/node-polyfill.js} +1 -0
  10. package/dist/mainnet/node-polyfill.js.map +1 -0
  11. package/dist/mainnet/node.d.ts +2 -0
  12. package/dist/{node.js → mainnet/node.js} +3 -2
  13. package/dist/{node.js.map → mainnet/node.js.map} +1 -1
  14. package/dist/{offline-key-provider.d.ts → mainnet/offline-key-provider.d.ts} +22 -22
  15. package/dist/mainnet/polyfill/shared.d.ts +1 -0
  16. package/dist/{program-manager.d.ts → mainnet/program-manager.d.ts} +59 -59
  17. package/dist/{record-provider.d.ts → mainnet/record-provider.d.ts} +22 -22
  18. package/dist/{utils.d.ts → mainnet/utils.d.ts} +1 -0
  19. package/dist/{worker.d.ts → mainnet/worker.d.ts} +2 -1
  20. package/dist/mainnet/worker.js +78 -0
  21. package/dist/mainnet/worker.js.map +1 -0
  22. package/dist/testnet/account.d.ts +137 -0
  23. package/dist/testnet/browser.d.ts +53 -0
  24. package/dist/{index.js → testnet/browser.js} +197 -186
  25. package/dist/testnet/browser.js.map +1 -0
  26. package/dist/testnet/function-key-provider.d.ts +348 -0
  27. package/dist/testnet/managed-worker.d.ts +3 -0
  28. package/dist/testnet/models/block.d.ts +21 -0
  29. package/dist/testnet/models/confirmed_transaction.d.ts +6 -0
  30. package/dist/testnet/models/execution.d.ts +5 -0
  31. package/dist/testnet/models/input.d.ts +10 -0
  32. package/dist/testnet/models/output.d.ts +6 -0
  33. package/dist/testnet/models/transactionModel.d.ts +6 -0
  34. package/dist/testnet/models/transition.d.ts +13 -0
  35. package/dist/testnet/network-client.d.ts +267 -0
  36. package/dist/testnet/node-polyfill.d.ts +5 -0
  37. package/dist/testnet/node-polyfill.js +303 -0
  38. package/dist/testnet/node-polyfill.js.map +1 -0
  39. package/dist/testnet/node.d.ts +2 -0
  40. package/dist/testnet/node.js +12 -0
  41. package/dist/testnet/node.js.map +1 -0
  42. package/dist/testnet/offline-key-provider.d.ts +347 -0
  43. package/dist/testnet/polyfill/crypto.d.ts +1 -0
  44. package/dist/testnet/polyfill/fetch.d.ts +1 -0
  45. package/dist/testnet/polyfill/shared.d.ts +1 -0
  46. package/dist/testnet/polyfill/worker.d.ts +1 -0
  47. package/dist/testnet/polyfill/xmlhttprequest.d.ts +1 -0
  48. package/dist/testnet/program-manager.d.ts +636 -0
  49. package/dist/testnet/record-provider.d.ts +236 -0
  50. package/dist/testnet/utils.d.ts +3 -0
  51. package/dist/testnet/worker.d.ts +9 -0
  52. package/dist/testnet/worker.js +78 -0
  53. package/dist/testnet/worker.js.map +1 -0
  54. package/package.json +23 -13
  55. package/dist/index.js.map +0 -1
  56. package/dist/node-polyfill.js.map +0 -1
  57. package/dist/node.d.ts +0 -2
  58. package/dist/worker.js +0 -74
  59. package/dist/worker.js.map +0 -1
  60. /package/dist/{managed-worker.d.ts → mainnet/managed-worker.d.ts} +0 -0
  61. /package/dist/{models → mainnet/models}/block.d.ts +0 -0
  62. /package/dist/{models → mainnet/models}/confirmed_transaction.d.ts +0 -0
  63. /package/dist/{models → mainnet/models}/execution.d.ts +0 -0
  64. /package/dist/{models → mainnet/models}/input.d.ts +0 -0
  65. /package/dist/{models → mainnet/models}/output.d.ts +0 -0
  66. /package/dist/{models → mainnet/models}/transactionModel.d.ts +0 -0
  67. /package/dist/{models → mainnet/models}/transition.d.ts +0 -0
  68. /package/dist/{polyfill → mainnet/polyfill}/crypto.d.ts +0 -0
  69. /package/dist/{polyfill → mainnet/polyfill}/fetch.d.ts +0 -0
  70. /package/dist/{polyfill → mainnet/polyfill}/worker.d.ts +0 -0
  71. /package/dist/{polyfill → mainnet/polyfill}/xmlhttprequest.d.ts +0 -0
@@ -0,0 +1,347 @@
1
+ import { FunctionKeyProvider, KeySearchParams, FunctionKeyPair, CachedKeyPair, ProvingKey, VerifyingKey } from "./browser";
2
+ /**
3
+ * Search parameters for the offline key provider. This class implements the KeySearchParams interface and includes
4
+ * a convenience method for creating a new instance of this class for each function of the credits.aleo program.
5
+ *
6
+ * @example
7
+ * // If storing a key for a custom program function
8
+ * offlineSearchParams = new OfflineSearchParams("myprogram.aleo/myfunction");
9
+ *
10
+ * // If storing a key for a credits.aleo program function
11
+ * bondPublicKeyParams = OfflineSearchParams.bondPublicKeyParams();
12
+ */
13
+ declare class OfflineSearchParams implements KeySearchParams {
14
+ cacheKey: string | undefined;
15
+ verifyCreditsKeys: boolean | undefined;
16
+ /**
17
+ * Create a new OfflineSearchParams instance.
18
+ *
19
+ * @param {string} cacheKey - Key used to store the local function proving & verifying keys. This should be stored
20
+ * under the naming convention "programName/functionName" (i.e. "myprogram.aleo/myfunction")
21
+ * @param {boolean} verifyCreditsKeys - Whether to verify the keys against the credits.aleo program,
22
+ * defaults to false, but should be set to true if using keys from the credits.aleo program
23
+ */
24
+ constructor(cacheKey: string, verifyCreditsKeys?: boolean);
25
+ /**
26
+ * Create a new OfflineSearchParams instance for the bond_public function of the credits.aleo program.
27
+ */
28
+ static bondPublicKeyParams(): OfflineSearchParams;
29
+ /**
30
+ * Create a new OfflineSearchParams instance for the bond_validator function of the credits.aleo program.
31
+ */
32
+ static bondValidatorKeyParams(): OfflineSearchParams;
33
+ /**
34
+ * Create a new OfflineSearchParams instance for the claim_unbond_public function of the
35
+ */
36
+ static claimUnbondPublicKeyParams(): OfflineSearchParams;
37
+ /**
38
+ * Create a new OfflineSearchParams instance for the fee_private function of the credits.aleo program.
39
+ */
40
+ static feePrivateKeyParams(): OfflineSearchParams;
41
+ /**
42
+ * Create a new OfflineSearchParams instance for the fee_public function of the credits.aleo program.
43
+ */
44
+ static feePublicKeyParams(): OfflineSearchParams;
45
+ /**
46
+ * Create a new OfflineSearchParams instance for the inclusion prover function.
47
+ */
48
+ static inclusionKeyParams(): OfflineSearchParams;
49
+ /**
50
+ * Create a new OfflineSearchParams instance for the join function of the credits.aleo program.
51
+ */
52
+ static joinKeyParams(): OfflineSearchParams;
53
+ /**
54
+ * Create a new OfflineSearchParams instance for the set_validator_state function of the credits.aleo program.
55
+ */
56
+ static setValidatorStateKeyParams(): OfflineSearchParams;
57
+ /**
58
+ * Create a new OfflineSearchParams instance for the split function of the credits.aleo program.
59
+ */
60
+ static splitKeyParams(): OfflineSearchParams;
61
+ /**
62
+ * Create a new OfflineSearchParams instance for the transfer_private function of the credits.aleo program.
63
+ */
64
+ static transferPrivateKeyParams(): OfflineSearchParams;
65
+ /**
66
+ * Create a new OfflineSearchParams instance for the transfer_private_to_public function of the credits.aleo program.
67
+ */
68
+ static transferPrivateToPublicKeyParams(): OfflineSearchParams;
69
+ /**
70
+ * Create a new OfflineSearchParams instance for the transfer_public function of the credits.aleo program.
71
+ */
72
+ static transferPublicKeyParams(): OfflineSearchParams;
73
+ /**
74
+ * Create a new OfflineSearchParams instance for the transfer_public_as_signer function of the credits.aleo program.
75
+ */
76
+ static transferPublicAsSignerKeyParams(): OfflineSearchParams;
77
+ /**
78
+ * Create a new OfflineSearchParams instance for the transfer_public_to_private function of the credits.aleo program.
79
+ */
80
+ static transferPublicToPrivateKeyParams(): OfflineSearchParams;
81
+ /**
82
+ * Create a new OfflineSearchParams instance for the unbond_public function of the credits.aleo program.
83
+ */
84
+ static unbondPublicKeyParams(): OfflineSearchParams;
85
+ }
86
+ /**
87
+ * A key provider meant for building transactions offline on devices such as hardware wallets. This key provider is not
88
+ * able to contact the internet for key material and instead relies on the user to insert Aleo function proving &
89
+ * verifying keys from local storage prior to usage.
90
+ *
91
+ * @example
92
+ * // Create an offline program manager
93
+ * const programManager = new ProgramManager();
94
+ *
95
+ * // Create a temporary account for the execution of the program
96
+ * const account = new Account();
97
+ * programManager.setAccount(account);
98
+ *
99
+ * // Create the proving keys from the key bytes on the offline machine
100
+ * console.log("Creating proving keys from local key files");
101
+ * 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;";
102
+ * const myFunctionProver = await getLocalKey("/path/to/my/function/hello_hello.prover");
103
+ * const myFunctionVerifier = await getLocalKey("/path/to/my/function/hello_hello.verifier");
104
+ * const feePublicProvingKeyBytes = await getLocalKey("/path/to/credits.aleo/feePublic.prover");
105
+ *
106
+ * myFunctionProvingKey = ProvingKey.fromBytes(myFunctionProver);
107
+ * myFunctionVerifyingKey = VerifyingKey.fromBytes(myFunctionVerifier);
108
+ * const feePublicProvingKey = ProvingKey.fromBytes(feePublicKeyBytes);
109
+ *
110
+ * // Create an offline key provider
111
+ * console.log("Creating offline key provider");
112
+ * const offlineKeyProvider = new OfflineKeyProvider();
113
+ *
114
+ * // Cache the keys
115
+ * // Cache the proving and verifying keys for the custom hello function
116
+ * OfflineKeyProvider.cacheKeys("hello_hello.aleo/hello", myFunctionProvingKey, myFunctionVerifyingKey);
117
+ *
118
+ * // Cache the proving key for the fee_public function (the verifying key is automatically cached)
119
+ * OfflineKeyProvider.insertFeePublicKey(feePublicProvingKey);
120
+ *
121
+ * // Create an offline query using the latest state root in order to create the inclusion proof
122
+ * const offlineQuery = new OfflineQuery("latestStateRoot");
123
+ *
124
+ * // Insert the key provider into the program manager
125
+ * programManager.setKeyProvider(offlineKeyProvider);
126
+ *
127
+ * // Create the offline search params
128
+ * const offlineSearchParams = new OfflineSearchParams("hello_hello.aleo/hello");
129
+ *
130
+ * // Create the offline transaction
131
+ * const offlineExecuteTx = <Transaction>await this.buildExecutionTransaction("hello_hello.aleo", "hello", 1, false, ["5u32", "5u32"], undefined, offlineSearchParams, undefined, undefined, undefined, undefined, offlineQuery, program);
132
+ *
133
+ * // Broadcast the transaction later on a machine with internet access
134
+ * const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1");
135
+ * const txId = await networkClient.broadcastTransaction(offlineExecuteTx);
136
+ */
137
+ declare class OfflineKeyProvider implements FunctionKeyProvider {
138
+ cache: Map<string, CachedKeyPair>;
139
+ constructor();
140
+ /**
141
+ * Get bond_public function keys from the credits.aleo program. The keys must be cached prior to calling this
142
+ * method for it to work.
143
+ *
144
+ * @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the bond_public function
145
+ */
146
+ bondPublicKeys(): Promise<FunctionKeyPair>;
147
+ /**
148
+ * Get bond_validator function keys from the credits.aleo program. The keys must be cached prior to calling this
149
+ * method for it to work.
150
+ *
151
+ * @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the bond_public function
152
+ */
153
+ bondValidatorKeys(): Promise<FunctionKeyPair>;
154
+ /**
155
+ * Cache a set of keys. This will overwrite any existing keys with the same keyId. The user can check if a keyId
156
+ * exists in the cache using the containsKeys method prior to calling this method if overwriting is not desired.
157
+ *
158
+ * @param {string} keyId access key for the cache
159
+ * @param {FunctionKeyPair} keys keys to cache
160
+ */
161
+ cacheKeys(keyId: string, keys: FunctionKeyPair): void;
162
+ /**
163
+ * Get unbond_public function keys from the credits.aleo program. The keys must be cached prior to calling this
164
+ * method for it to work.
165
+ *
166
+ * @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the unbond_public function
167
+ */
168
+ claimUnbondPublicKeys(): Promise<FunctionKeyPair>;
169
+ /**
170
+ * Get arbitrary function key from the offline key provider cache.
171
+ *
172
+ * @param {KeySearchParams | undefined} params - Optional search parameters for the key provider
173
+ * @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the specified program
174
+ *
175
+ * @example
176
+ * /// First cache the keys from local offline resources
177
+ * const offlineKeyProvider = new OfflineKeyProvider();
178
+ * const myFunctionVerifyingKey = VerifyingKey.fromString("verifier...");
179
+ * const myFunctionProvingKeyBytes = await readBinaryFile('./resources/myfunction.prover');
180
+ * const myFunctionProvingKey = ProvingKey.fromBytes(myFunctionProvingKeyBytes);
181
+ *
182
+ * /// Cache the keys for future use with a memorable locator
183
+ * offlineKeyProvider.cacheKeys("myprogram.aleo/myfunction", [myFunctionProvingKey, myFunctionVerifyingKey]);
184
+ *
185
+ * /// When they're needed, retrieve the keys from the cache
186
+ *
187
+ * /// First create a search parameter object with the same locator used to cache the keys
188
+ * const keyParams = new OfflineSearchParams("myprogram.aleo/myfunction");
189
+ *
190
+ * /// Then retrieve the keys
191
+ * const [myFunctionProver, myFunctionVerifier] = await offlineKeyProvider.functionKeys(keyParams);
192
+ */
193
+ functionKeys(params?: KeySearchParams): Promise<FunctionKeyPair>;
194
+ /**
195
+ * Determines if the keys for a given credits function match the expected keys.
196
+ *
197
+ * @returns {boolean} Whether the keys match the expected keys
198
+ */
199
+ verifyCreditsKeys(locator: string, provingKey: ProvingKey, verifyingKey: VerifyingKey): boolean;
200
+ /**
201
+ * Get fee_private function keys from the credits.aleo program. The keys must be cached prior to calling this
202
+ * method for it to work.
203
+ *
204
+ * @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the join function
205
+ */
206
+ feePrivateKeys(): Promise<FunctionKeyPair>;
207
+ /**
208
+ * Get fee_public function keys from the credits.aleo program. The keys must be cached prior to calling this
209
+ * method for it to work.
210
+ *
211
+ * @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the join function
212
+ */
213
+ feePublicKeys(): Promise<FunctionKeyPair>;
214
+ /**
215
+ * Get join function keys from the credits.aleo program. The keys must be cached prior to calling this
216
+ * method for it to work.
217
+ *
218
+ * @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the join function
219
+ */
220
+ joinKeys(): Promise<FunctionKeyPair>;
221
+ /**
222
+ * Get split function keys from the credits.aleo program. The keys must be cached prior to calling this
223
+ * method for it to work.
224
+ *
225
+ * @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the join function
226
+ */
227
+ splitKeys(): Promise<FunctionKeyPair>;
228
+ /**
229
+ * Get keys for a variant of the transfer function from the credits.aleo program.
230
+ *
231
+ *
232
+ * @param {string} visibility Visibility of the transfer function (private, public, privateToPublic, publicToPrivate)
233
+ * @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the specified transfer function
234
+ *
235
+ * @example
236
+ * // Create a new OfflineKeyProvider
237
+ * const offlineKeyProvider = new OfflineKeyProvider();
238
+ *
239
+ * // Cache the keys for future use with the official locator
240
+ * const transferPublicProvingKeyBytes = await readBinaryFile('./resources/transfer_public.prover.a74565e');
241
+ * const transferPublicProvingKey = ProvingKey.fromBytes(transferPublicProvingKeyBytes);
242
+ *
243
+ * // Cache the transfer_public keys for future use with the OfflinKeyProvider's convenience method for
244
+ * // transfer_public (the verifying key will be cached automatically)
245
+ * offlineKeyProvider.insertTransferPublicKeys(transferPublicProvingKey);
246
+ *
247
+ * /// When they're needed, retrieve the keys from the cache
248
+ * const [transferPublicProvingKey, transferPublicVerifyingKey] = await keyProvider.transferKeys("public");
249
+ */
250
+ transferKeys(visibility: string): Promise<FunctionKeyPair>;
251
+ /**
252
+ * Get unbond_public function keys from the credits.aleo program
253
+ *
254
+ * @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the join function
255
+ */
256
+ unBondPublicKeys(): Promise<FunctionKeyPair>;
257
+ /**
258
+ * Insert the proving and verifying keys for the bond_public function into the cache. Only the proving key needs
259
+ * to be inserted, the verifying key is automatically inserted by the SDK. This function will automatically check
260
+ * that the keys match the expected checksum for bond_public before inserting them into the cache.
261
+ *
262
+ * @param provingKey
263
+ */
264
+ insertBondPublicKeys(provingKey: ProvingKey): void;
265
+ /**
266
+ * Insert the proving and verifying keys for the claim_unbond_public function into the cache. Only the proving key needs
267
+ * to be inserted, the verifying key is automatically inserted by the SDK. This function will automatically check
268
+ * that the keys match the expected checksum for claim_unbond_public before inserting them into the cache.
269
+ *
270
+ * @param provingKey
271
+ */
272
+ insertClaimUnbondPublicKeys(provingKey: ProvingKey): void;
273
+ /**
274
+ * Insert the proving and verifying keys for the fee_private function into the cache. Only the proving key needs
275
+ * to be inserted, the verifying key is automatically inserted by the SDK. This function will automatically check
276
+ * that the keys match the expected checksum for fee_private before inserting them into the cache.
277
+ *
278
+ * @param provingKey
279
+ */
280
+ insertFeePrivateKeys(provingKey: ProvingKey): void;
281
+ /**
282
+ * Insert the proving and verifying keys for the fee_public function into the cache. Only the proving key needs
283
+ * to be inserted, the verifying key is automatically inserted by the SDK. This function will automatically check
284
+ * that the keys match the expected checksum for fee_public before inserting them into the cache.
285
+ *
286
+ * @param provingKey
287
+ */
288
+ insertFeePublicKeys(provingKey: ProvingKey): void;
289
+ /**
290
+ * Insert the proving and verifying keys for the join function into the cache. Only the proving key needs
291
+ * to be inserted, the verifying key is automatically inserted by the SDK. This function will automatically check
292
+ * that the keys match the expected checksum for join before inserting them into the cache.
293
+ *
294
+ * @param provingKey
295
+ */
296
+ insertJoinKeys(provingKey: ProvingKey): void;
297
+ /**
298
+ * Insert the proving and verifying keys for the set_validator_state function into the cache. Only the proving key needs
299
+ * to be inserted, the verifying key is automatically inserted by the SDK. This function will automatically check
300
+ * that the keys match the expected checksum for set_validator_state before inserting them into the cache.
301
+ *
302
+ * @param provingKey
303
+ */
304
+ insertSetValidatorStateKeys(provingKey: ProvingKey): void;
305
+ /**
306
+ * Insert the proving and verifying keys for the split function into the cache. Only the proving key needs
307
+ * to be inserted, the verifying key is automatically inserted by the SDK. This function will automatically check
308
+ * that the keys match the expected checksum for split before inserting them into the cache.
309
+ *
310
+ * @param provingKey
311
+ */
312
+ insertSplitKeys(provingKey: ProvingKey): void;
313
+ /**
314
+ * Insert the proving and verifying keys for the transfer_private function into the cache. Only the proving key needs
315
+ * to be inserted, the verifying key is automatically inserted by the SDK. This function will automatically check
316
+ * that the keys match the expected checksum for transfer_private before inserting them into the cache.
317
+ *
318
+ * @param provingKey
319
+ */
320
+ insertTransferPrivateKeys(provingKey: ProvingKey): void;
321
+ /**
322
+ * Insert the proving and verifying keys for the transfer_private_to_public function into the cache. Only the proving key needs
323
+ * to be inserted, the verifying key is automatically inserted by the SDK. This function will automatically check
324
+ * that the keys match the expected checksum for transfer_private_to_public before inserting them into the cache.
325
+ *
326
+ * @param provingKey
327
+ */
328
+ insertTransferPrivateToPublicKeys(provingKey: ProvingKey): void;
329
+ /**
330
+ * Insert the proving and verifying keys for the transfer_public function into the cache. Only the proving key needs
331
+ * to be inserted, the verifying key is automatically inserted by the SDK. This function will automatically check
332
+ * that the keys match the expected checksum for transfer_public before inserting them into the cache.
333
+ *
334
+ * @param provingKey
335
+ */
336
+ insertTransferPublicKeys(provingKey: ProvingKey): void;
337
+ /**
338
+ * Insert the proving and verifying keys for the transfer_public_to_private function into the cache. Only the proving key needs
339
+ * to be inserted, the verifying key is automatically inserted by the SDK. This function will automatically check
340
+ * that the keys match the expected checksum for transfer_public_to_private before inserting them into the cache.
341
+ *
342
+ * @param provingKey
343
+ */
344
+ insertTransferPublicToPrivateKeys(provingKey: ProvingKey): void;
345
+ insertUnbondPublicKeys(provingKey: ProvingKey): void;
346
+ }
347
+ export { OfflineKeyProvider, OfflineSearchParams };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ import "core-js/proposals/json-parse-with-source.js";
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};