@provablehq/sdk 0.9.7 → 0.9.9

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 (31) hide show
  1. package/dist/mainnet/browser.d.ts +8 -2
  2. package/dist/mainnet/browser.js +140 -73
  3. package/dist/mainnet/browser.js.map +1 -1
  4. package/dist/mainnet/models/record-provider/encryptedRecord.d.ts +58 -0
  5. package/dist/mainnet/models/record-provider/ownedRecord.d.ts +60 -0
  6. package/dist/mainnet/models/record-provider/recordSearchParams.d.ts +19 -0
  7. package/dist/mainnet/models/record-scanner/ownedFilter.d.ts +24 -0
  8. package/dist/mainnet/models/record-scanner/ownedRecordsResponseFilter.d.ts +42 -0
  9. package/dist/mainnet/models/record-scanner/recordsFilter.d.ts +35 -0
  10. package/dist/mainnet/models/record-scanner/recordsResponseFilter.d.ts +38 -0
  11. package/dist/mainnet/models/record-scanner/registrationRequest.d.ts +13 -0
  12. package/dist/mainnet/models/record-scanner/registrationResponse.d.ts +15 -0
  13. package/dist/mainnet/network-client.d.ts +29 -4
  14. package/dist/mainnet/program-manager.d.ts +4 -2
  15. package/dist/mainnet/record-provider.d.ts +106 -68
  16. package/dist/testnet/browser.d.ts +8 -2
  17. package/dist/testnet/browser.js +140 -73
  18. package/dist/testnet/browser.js.map +1 -1
  19. package/dist/testnet/models/record-provider/encryptedRecord.d.ts +58 -0
  20. package/dist/testnet/models/record-provider/ownedRecord.d.ts +60 -0
  21. package/dist/testnet/models/record-provider/recordSearchParams.d.ts +19 -0
  22. package/dist/testnet/models/record-scanner/ownedFilter.d.ts +24 -0
  23. package/dist/testnet/models/record-scanner/ownedRecordsResponseFilter.d.ts +42 -0
  24. package/dist/testnet/models/record-scanner/recordsFilter.d.ts +35 -0
  25. package/dist/testnet/models/record-scanner/recordsResponseFilter.d.ts +38 -0
  26. package/dist/testnet/models/record-scanner/registrationRequest.d.ts +13 -0
  27. package/dist/testnet/models/record-scanner/registrationResponse.d.ts +15 -0
  28. package/dist/testnet/network-client.d.ts +29 -4
  29. package/dist/testnet/program-manager.d.ts +4 -2
  30. package/dist/testnet/record-provider.d.ts +106 -68
  31. package/package.json +2 -2
@@ -1,13 +1,9 @@
1
- import { RecordPlaintext } from "./wasm.js";
2
1
  import { Account } from "./account.js";
3
2
  import { AleoNetworkClient } from "./network-client.js";
4
- /**
5
- * Interface for record search parameters. This allows for arbitrary search parameters to be passed to record provider
6
- * implementations.
7
- */
8
- interface RecordSearchParams {
9
- [key: string]: any;
10
- }
3
+ import { EncryptedRecord } from "./models/record-provider/encryptedRecord.js";
4
+ import { OwnedRecord } from "./models/record-provider/ownedRecord.js";
5
+ import { RecordSearchParams } from "./models/record-provider/recordSearchParams.js";
6
+ import { RecordsResponseFilter } from "./models/record-scanner/recordsResponseFilter.js";
11
7
  /**
12
8
  * Interface for a record provider. A record provider is used to find records for use in deployment and execution
13
9
  * transactions on the Aleo Network. A default implementation is provided by the NetworkRecordProvider class. However,
@@ -15,61 +11,80 @@ interface RecordSearchParams {
15
11
  * implementing this interface.
16
12
  */
17
13
  interface RecordProvider {
18
- account: Account;
19
14
  /**
20
- * Find a credits.aleo record with a given number of microcredits from the chosen provider
15
+ * The account used to search for records.
16
+ */
17
+ account?: Account;
18
+ /**
19
+ * Find encrypted records from the chosen provider.
20
+ *
21
+ * @param {RecordSearchParams} recordsFilter The filter used to find the records.
22
+ * @param {RecordsResponseFilter} responseFilter The filter used to filter the response.
23
+ * @returns {Promise<EncryptedRecord[]>} The encrypted records.
24
+ */
25
+ encryptedRecords(recordsFilter: RecordSearchParams, responseFilter?: RecordsResponseFilter): Promise<EncryptedRecord[]>;
26
+ /**
27
+ * Check if a list of serial numbers exist in the chosen provider.
21
28
  *
22
- * @param {number} microcredits The number of microcredits to search for
23
- * @param {boolean} unspent Whether or not the record is unspent
24
- * @param {string[]} nonces Nonces of records already found so they are not found again
25
- * @param {RecordSearchParams} searchParameters Additional parameters to search for
26
- * @returns {Promise<RecordPlaintext>} The record if found, otherwise an error
29
+ * @param {string[]} serialNumbers The serial numbers to check.
30
+ * @returns {Promise<Record<string, boolean>>} Map of Aleo Record serial numbers and whether they appeared in any inputs on chain. If boolean corresponding to the Serial Number has a true value, that Record is considered spent by the Aleo Network.
31
+ */
32
+ checkSerialNumbers(serialNumbers: string[]): Promise<Record<string, boolean>>;
33
+ /**
34
+ * Check if a list of tags exist in the chosen provider.
35
+ *
36
+ * @param {string[]} tags The tags to check.
37
+ * @returns {Promise<Record<string, boolean>>} Map of Aleo Record tags and whether they appeared in any inputs on chain. If boolean corresponding to the tag has a true value, that Record is considered spent by the Aleo Network.
38
+ */
39
+ checkTags(tags: string[]): Promise<Record<string, boolean>>;
40
+ /**
41
+ * Find a credits.aleo record with a given number of microcredits from the chosen provider.
42
+ *
43
+ * @param {number} microcredits The number of microcredits to search for.
44
+ * @param {RecordSearchParams} searchParameters Additional parameters to search for.
45
+ * @returns {Promise<OwnedRecord>} The record if one is found.
27
46
  *
28
47
  * @example
29
48
  * // A class implementing record provider can be used to find a record with a given number of microcredits
30
- * const record = await recordProvider.findCreditsRecord(5000, true, []);
49
+ * const record = await recordProvider.findCreditsRecord(5000, { unspent: true, nonces: [] });
31
50
  *
32
51
  * // When a record is found but not yet used, its nonce should be added to the nonces array so that it is not
33
52
  * // found again if a subsequent search is performed
34
- * const record2 = await recordProvider.findCreditsRecord(5000, true, [record.nonce()]);
53
+ * const record2 = await recordProvider.findCreditsRecord(5000, { unspent: true, nonces: [record.nonce()] });
35
54
  *
36
55
  * // When the program manager is initialized with the record provider it will be used to find automatically find
37
56
  * // fee records and amount records for value transfers so that they do not need to be specified manually
38
57
  * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider);
39
58
  * programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
40
59
  */
41
- findCreditsRecord(microcredits: number, unspent: boolean, nonces?: string[], searchParameters?: RecordSearchParams): Promise<RecordPlaintext>;
60
+ findCreditsRecord(microcredits: number, searchParameters: RecordSearchParams): Promise<OwnedRecord>;
42
61
  /**
43
62
  * Find a list of credit.aleo records with a given number of microcredits from the chosen provider
44
63
  *
45
- * @param {number} microcreditAmounts A list of separate microcredit amounts to search for (e.g. [5000, 100000])
46
- * @param {boolean} unspent Whether or not the record is unspent
47
- * @param {string[]} nonces Nonces of records already found so that they are not found again
48
- * @param {RecordSearchParams} searchParameters Additional parameters to search for
49
- * @returns {Promise<RecordPlaintext[]>} A list of records with a value greater or equal to the amounts specified if such records exist, otherwise an error
64
+ * @param {number[]} microcreditAmounts A list of separate microcredit amounts to search for (e.g. [5000, 100000]).
65
+ * @param {RecordSearchParams} searchParameters Additional parameters to search for.
66
+ * @returns {Promise<OwnedRecord[]>} A list of records with a value greater or equal to the amounts specified if such records exist, otherwise an error.
50
67
  *
51
68
  * @example
52
69
  * // A class implementing record provider can be used to find a record with a given number of microcredits
53
- * const records = await recordProvider.findCreditsRecords([5000, 5000], true, []);
70
+ * const records = await recordProvider.findCreditsRecords([5000, 5000], { unspent: true, nonces: [] });
54
71
  *
55
72
  * // When a record is found but not yet used, it's nonce should be added to the nonces array so that it is not
56
73
  * // found again if a subsequent search is performed
57
74
  * const nonces = [];
58
75
  * records.forEach(record => { nonces.push(record.nonce()) });
59
- * const records2 = await recordProvider.findCreditsRecord(5000, true, nonces);
76
+ * const records2 = await recordProvider.findCreditsRecord(5000, { unspent: true, nonces });
60
77
  *
61
78
  * // When the program manager is initialized with the record provider it will be used to find automatically find
62
79
  * // fee records and amount records for value transfers so that they do not need to be specified manually
63
80
  * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider);
64
81
  * programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
65
82
  */
66
- findCreditsRecords(microcreditAmounts: number[], unspent: boolean, nonces?: string[], searchParameters?: RecordSearchParams): Promise<RecordPlaintext[]>;
83
+ findCreditsRecords(microcreditAmounts: number[], searchParameters: RecordSearchParams): Promise<OwnedRecord[]>;
67
84
  /**
68
85
  * Find an arbitrary record
69
- * @param {boolean} unspent Whether or not the record is unspent
70
- * @param {string[]} nonces Nonces of records already found so that they are not found again
71
- * @param {RecordSearchParams} searchParameters Additional parameters to search for
72
- * @returns {Promise<RecordPlaintext>} The record if found, otherwise an error
86
+ * @param {RecordSearchParams} searchParameters Additional parameters to search for.
87
+ * @returns {Promise<OwnedRecord>} The record if found, otherwise an error.
73
88
  *
74
89
  * @example
75
90
  * // The RecordSearchParams interface can be used to create parameters for custom record searches which can then
@@ -82,28 +97,40 @@ interface RecordProvider {
82
97
  * amount: number;
83
98
  * program: string;
84
99
  * recordName: string;
85
- * constructor(startHeight: number, endHeight: number, credits: number, maxRecords: number, programName: string, recordName: string) {
100
+ * nonces: string[];
101
+ * unspent: boolean;
102
+ * constructor(
103
+ * startHeight: number,
104
+ * endHeight: number,
105
+ * credits: number,
106
+ * maxRecords: number,
107
+ * programName: string,
108
+ * recordName: string,
109
+ * nonces: string[],
110
+ * unspent: boolean
111
+ * ) {
86
112
  * this.startHeight = startHeight;
87
113
  * this.endHeight = endHeight;
88
114
  * this.amount = amount;
89
115
  * this.program = programName;
90
116
  * this.recordName = recordName;
117
+ * this.nonces = nonces;
118
+ * this.unspent = unspent;
91
119
  * }
92
120
  * }
93
121
  *
94
- * const params = new CustomRecordSearch(0, 100, 5000, "credits.aleo", "credits");
122
+ * const params = new CustomRecordSearch(0, 100, 5000, "credits.aleo", "credits", [], true);
95
123
  *
96
- * const record = await recordProvider.findRecord(true, [], params);
124
+ * const record = await recordProvider.findRecord(params);
97
125
  */
98
- findRecord(unspent: boolean, nonces?: string[], searchParameters?: RecordSearchParams): Promise<RecordPlaintext>;
126
+ findRecord(searchParameters: RecordSearchParams): Promise<OwnedRecord>;
99
127
  /**
100
128
  * Find multiple records from arbitrary programs
101
129
  *
102
- * @param {boolean} unspent Whether or not the record is unspent
103
- * @param {string[]} nonces Nonces of records already found so that they are not found again
104
- * @param {RecordSearchParams} searchParameters Additional parameters to search for
105
- * @returns {Promise<RecordPlaintext>} The record if found, otherwise an error
130
+ * @param {RecordSearchParams} searchParameters Additional parameters to search for.
131
+ * @returns {Promise<OwnedRecord[]>} The records if found, otherwise an error.
106
132
  *
133
+ * @example
107
134
  * // The RecordSearchParams interface can be used to create parameters for custom record searches which can then
108
135
  * // be passed to the record provider. An example of how this would be done for the credits.aleo program is shown
109
136
  * // below.
@@ -111,24 +138,35 @@ interface RecordProvider {
111
138
  * class CustomRecordSearch implements RecordSearchParams {
112
139
  * startHeight: number;
113
140
  * endHeight: number;
114
- * amount: number;
115
- * maxRecords: number;
116
- * programName: string;
141
+ * credits: number;
142
+ * program: string;
117
143
  * recordName: string;
118
- * constructor(startHeight: number, endHeight: number, credits: number, maxRecords: number, programName: string, recordName: string) {
144
+ * nonces: string[];
145
+ * unspent: boolean;
146
+ * constructor(
147
+ * startHeight: number,
148
+ * endHeight: number,
149
+ * credits: number,
150
+ * maxRecords: number,
151
+ * programName: string,
152
+ * recordName: string,
153
+ * nonces: string[],
154
+ * unspent: boolean
155
+ * ) {
119
156
  * this.startHeight = startHeight;
120
157
  * this.endHeight = endHeight;
121
- * this.amount = amount;
122
- * this.maxRecords = maxRecords;
123
- * this.programName = programName;
158
+ * this.credits = credits;
159
+ * this.program = programName;
124
160
  * this.recordName = recordName;
161
+ * this.nonces = nonces;
162
+ * this.unspent = unspent;
125
163
  * }
126
164
  * }
127
165
  *
128
166
  * const params = new CustomRecordSearch(0, 100, 5000, 2, "credits.aleo", "credits");
129
167
  * const records = await recordProvider.findRecord(true, [], params);
130
168
  */
131
- findRecords(unspent: boolean, nonces?: string[], searchParameters?: RecordSearchParams): Promise<RecordPlaintext[]>;
169
+ findRecords(searchParameters: RecordSearchParams): Promise<OwnedRecord[]>;
132
170
  }
133
171
  /**
134
172
  * A record provider implementation that uses the official Aleo API to find records for usage in program execution and
@@ -141,17 +179,15 @@ declare class NetworkRecordProvider implements RecordProvider {
141
179
  /**
142
180
  * Set the account used to search for records
143
181
  *
144
- * @param {Account} account The account to use for searching for records
182
+ * @param {Account} account The account used to use for searching for records.
145
183
  */
146
184
  setAccount(account: Account): void;
147
185
  /**
148
186
  * Find a list of credit records with a given number of microcredits by via the official Aleo API
149
187
  *
150
- * @param {number[]} microcredits The number of microcredits to search for
151
- * @param {boolean} unspent Whether or not the record is unspent
152
- * @param {string[]} nonces Nonces of records already found so that they are not found again
153
- * @param {RecordSearchParams} searchParameters Additional parameters to search for
154
- * @returns {Promise<RecordPlaintext>} The record if found, otherwise an error
188
+ * @param {number[]} microcredits The number of microcredits to search for.
189
+ * @param {RecordSearchParams} searchParameters Additional parameters to search for.
190
+ * @returns {Promise<OwnedRecord[]>} The records if found, otherwise an error.
155
191
  *
156
192
  * @example
157
193
  * // Create a new NetworkRecordProvider
@@ -160,11 +196,11 @@ declare class NetworkRecordProvider implements RecordProvider {
160
196
  * const recordProvider = new NetworkRecordProvider(account, networkClient);
161
197
  *
162
198
  * // The record provider can be used to find records with a given number of microcredits
163
- * const record = await recordProvider.findCreditsRecord(5000, true, []);
199
+ * const record = await recordProvider.findCreditsRecord(5000, { unspent: true, nonces: [] });
164
200
  *
165
201
  * // When a record is found but not yet used, it's nonce should be added to the nonces parameter so that it is not
166
202
  * // found again if a subsequent search is performed
167
- * const records = await recordProvider.findCreditsRecords(5000, true, [record.nonce()]);
203
+ * const records = await recordProvider.findCreditsRecords(5000, { unspent: true, nonces: [record.nonce()] });
168
204
  *
169
205
  * // When the program manager is initialized with the record provider it will be used to find automatically find
170
206
  * // fee records and amount records for value transfers so that they do not need to be specified manually
@@ -172,15 +208,13 @@ declare class NetworkRecordProvider implements RecordProvider {
172
208
  * programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
173
209
  *
174
210
  * */
175
- findCreditsRecords(microcredits: number[], unspent: boolean, nonces?: string[], searchParameters?: RecordSearchParams): Promise<RecordPlaintext[]>;
211
+ findCreditsRecords(microcredits: number[], searchParameters: RecordSearchParams): Promise<OwnedRecord[]>;
176
212
  /**
177
213
  * Find a credit record with a given number of microcredits by via the official Aleo API
178
214
  *
179
- * @param {number} microcredits The number of microcredits to search for
180
- * @param {boolean} unspent Whether or not the record is unspent
181
- * @param {string[]} nonces Nonces of records already found so that they are not found again
182
- * @param {RecordSearchParams} searchParameters Additional parameters to search for
183
- * @returns {Promise<RecordPlaintext>} The record if found, otherwise an error
215
+ * @param {number} microcredits The number of microcredits to search for.
216
+ * @param {RecordSearchParams} searchParameters Additional parameters to search for.
217
+ * @returns {Promise<OwnedRecord>} The record if found, otherwise an error.
184
218
  *
185
219
  * @example
186
220
  * // Create a new NetworkRecordProvider
@@ -189,26 +223,29 @@ declare class NetworkRecordProvider implements RecordProvider {
189
223
  * const recordProvider = new NetworkRecordProvider(account, networkClient);
190
224
  *
191
225
  * // The record provider can be used to find records with a given number of microcredits
192
- * const record = await recordProvider.findCreditsRecord(5000, true, []);
226
+ * const record = await recordProvider.findCreditsRecord(5000, { unspent: true, nonces: [] });
193
227
  *
194
228
  * // When a record is found but not yet used, it's nonce should be added to the nonces parameter so that it is not
195
229
  * // found again if a subsequent search is performed
196
- * const records = await recordProvider.findCreditsRecords(5000, true, [record.nonce()]);
230
+ * const records = await recordProvider.findCreditsRecords(5000, { unspent: true, nonces: [record.nonce()] });
197
231
  *
198
232
  * // When the program manager is initialized with the record provider it will be used to find automatically find
199
233
  * // fee records and amount records for value transfers so that they do not need to be specified manually
200
234
  * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider);
201
235
  * programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
202
236
  */
203
- findCreditsRecord(microcredits: number, unspent: boolean, nonces?: string[], searchParameters?: RecordSearchParams): Promise<RecordPlaintext>;
237
+ findCreditsRecord(microcredits: number, searchParameters: RecordSearchParams): Promise<OwnedRecord>;
204
238
  /**
205
239
  * Find an arbitrary record. WARNING: This function is not implemented yet and will throw an error.
206
240
  */
207
- findRecord(unspent: boolean, nonces?: string[], searchParameters?: RecordSearchParams): Promise<RecordPlaintext>;
241
+ findRecord(searchParameters: RecordSearchParams): Promise<OwnedRecord>;
208
242
  /**
209
243
  * Find multiple records from a specified program.
210
244
  */
211
- findRecords(unspent: boolean, nonces?: string[], searchParameters?: RecordSearchParams): Promise<RecordPlaintext[]>;
245
+ findRecords(searchParameters: RecordSearchParams): Promise<OwnedRecord[]>;
246
+ encryptedRecords(recordsFilter: RecordSearchParams, responseFilter?: RecordsResponseFilter): Promise<EncryptedRecord[]>;
247
+ checkSerialNumbers(serialNumbers: string[]): Promise<Record<string, boolean>>;
248
+ checkTags(tags: string[]): Promise<Record<string, boolean>>;
212
249
  }
213
250
  /**
214
251
  * BlockHeightSearch is a RecordSearchParams implementation that allows for searching for records within a given
@@ -225,12 +262,13 @@ declare class NetworkRecordProvider implements RecordProvider {
225
262
  *
226
263
  * // The record provider can be used to find records with a given number of microcredits and the block height search
227
264
  * // can be used to find records within a given block height range
228
- * const record = await recordProvider.findCreditsRecord(5000, true, [], params);
265
+ * const record = await recordProvider.findCreditsRecord(5000, { unspent: true, nonces: [], ...params });
229
266
  *
230
267
  */
231
268
  declare class BlockHeightSearch implements RecordSearchParams {
232
269
  startHeight: number;
233
270
  endHeight: number;
234
- constructor(startHeight: number, endHeight: number);
271
+ unspent: boolean;
272
+ constructor(startHeight: number, endHeight: number, unspent?: boolean);
235
273
  }
236
- export { BlockHeightSearch, NetworkRecordProvider, RecordProvider, RecordSearchParams };
274
+ export { BlockHeightSearch, NetworkRecordProvider, RecordProvider, };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@provablehq/sdk",
3
- "version": "0.9.7",
3
+ "version": "0.9.9",
4
4
  "description": "A Software Development Kit (SDK) for Zero-Knowledge Transactions",
5
5
  "collaborators": [
6
6
  "The Provable Team"
@@ -47,7 +47,7 @@
47
47
  },
48
48
  "homepage": "https://github.com/ProvableHQ/sdk#readme",
49
49
  "dependencies": {
50
- "@provablehq/wasm": "^0.9.7",
50
+ "@provablehq/wasm": "^0.9.9",
51
51
  "comlink": "^4.4.2",
52
52
  "core-js": "^3.40.0",
53
53
  "mime": "^4.0.6",