Skip to content

Commit f923e17

Browse files
authored
Merge pull request #1116 from ProvableHQ/rr/add-merkle-tree-support
[Feature] Support for Merkle exclusion proofs
2 parents 012e9f9 + 6b21468 commit f923e17

File tree

11 files changed

+10641
-14588
lines changed

11 files changed

+10641
-14588
lines changed

docs/api_reference/sdk-src_function-key-provider.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,30 @@ const [transferPublicProvingKey, transferPublicVerifyingKey] = await keyProvider
201201

202202
---
203203

204+
### `transferPublicKeys() ► Promise.<FunctionKeyPair>`
205+
206+
![modifier: public](images/badges/modifier-public.svg)
207+
208+
Returns the proving and verifying keys for the transfer_public function.
209+
210+
Parameters | Type | Description
211+
--- | --- | ---
212+
__*return*__ | `Promise.<FunctionKeyPair>` | *Proving and verifying keys for the transfer_public function*
213+
214+
---
215+
216+
### `inclusionKeys() ► Promise.<FunctionKeyPair>`
217+
218+
![modifier: public](images/badges/modifier-public.svg)
219+
220+
Returns the proving and verifying keys for the inclusion proof.
221+
222+
Parameters | Type | Description
223+
--- | --- | ---
224+
__*return*__ | `Promise.<FunctionKeyPair>` | *Proving and verifying keys for the inclusion proof.*
225+
226+
---
227+
204228
### `joinKeys() ► Promise.<FunctionKeyPair>`
205229

206230
![modifier: public](images/badges/modifier-public.svg)
@@ -427,6 +451,30 @@ const [transferPublicProvingKey, transferPublicVerifyingKey] = await keyProvider
427451

428452
---
429453

454+
### `transferPublicKeys() ► Promise.<FunctionKeyPair>`
455+
456+
![modifier: public](images/badges/modifier-public.svg)
457+
458+
Returns the proving and verifying keys for the transfer_public function.
459+
460+
Parameters | Type | Description
461+
--- | --- | ---
462+
__*return*__ | `Promise.<FunctionKeyPair>` | *Proving and verifying keys for the transfer_public function*
463+
464+
---
465+
466+
### `inclusionKeys() ► Promise.<FunctionKeyPair>`
467+
468+
![modifier: public](images/badges/modifier-public.svg)
469+
470+
Returns the proving and verifying keys for the inclusion proof.
471+
472+
Parameters | Type | Description
473+
--- | --- | ---
474+
__*return*__ | `Promise.<FunctionKeyPair>` | *Proving and verifying keys for the inclusion proof.*
475+
476+
---
477+
430478
### `joinKeys() ► Promise.<FunctionKeyPair>`
431479

432480
![modifier: public](images/badges/modifier-public.svg)

docs/api_reference/sdk-src_offline-key-provider.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,18 @@ __*return*__ | `Promise.<FunctionKeyPair>` | *Proving and verifying keys for the
521521

522522
---
523523

524+
### `inclusionKeys() ► Promise.<FunctionKeyPair>`
525+
526+
![modifier: public](images/badges/modifier-public.svg)
527+
528+
Get the inclusion prover keys from. The keys must be cached prior to calling this method for it to work.
529+
530+
Parameters | Type | Description
531+
--- | --- | ---
532+
__*return*__ | `Promise.<FunctionKeyPair>` | *Proving and verifying keys for the inclusion prover*
533+
534+
---
535+
524536
### `joinKeys() ► Promise.<FunctionKeyPair>`
525537

526538
![modifier: public](images/badges/modifier-public.svg)
@@ -646,6 +658,20 @@ __provingKey__ | `undefined` | **
646658

647659
---
648660

661+
### `insertInclusionKeys(provingKey)`
662+
663+
![modifier: public](images/badges/modifier-public.svg)
664+
665+
Insert the proving and verifying keys for the inclusion prover into the cache. Only the proving key needs
666+
to be inserted, the verifying key is automatically inserted by the SDK. This function will automatically check
667+
that the keys match the expected checksum for the inclusion prover.
668+
669+
Parameters | Type | Description
670+
--- | --- | ---
671+
__provingKey__ | `undefined` | **
672+
673+
---
674+
649675
### `insertJoinKeys(provingKey)`
650676

651677
![modifier: public](images/badges/modifier-public.svg)
@@ -873,6 +899,18 @@ __*return*__ | `Promise.<FunctionKeyPair>` | *Proving and verifying keys for the
873899

874900
---
875901

902+
### `inclusionKeys() ► Promise.<FunctionKeyPair>`
903+
904+
![modifier: public](images/badges/modifier-public.svg)
905+
906+
Get the inclusion prover keys from. The keys must be cached prior to calling this method for it to work.
907+
908+
Parameters | Type | Description
909+
--- | --- | ---
910+
__*return*__ | `Promise.<FunctionKeyPair>` | *Proving and verifying keys for the inclusion prover*
911+
912+
---
913+
876914
### `joinKeys() ► Promise.<FunctionKeyPair>`
877915

878916
![modifier: public](images/badges/modifier-public.svg)
@@ -998,6 +1036,20 @@ __provingKey__ | `undefined` | **
9981036

9991037
---
10001038

1039+
### `insertInclusionKeys(provingKey)`
1040+
1041+
![modifier: public](images/badges/modifier-public.svg)
1042+
1043+
Insert the proving and verifying keys for the inclusion prover into the cache. Only the proving key needs
1044+
to be inserted, the verifying key is automatically inserted by the SDK. This function will automatically check
1045+
that the keys match the expected checksum for the inclusion prover.
1046+
1047+
Parameters | Type | Description
1048+
--- | --- | ---
1049+
__provingKey__ | `undefined` | **
1050+
1051+
---
1052+
10011053
### `insertJoinKeys(provingKey)`
10021054

10031055
![modifier: public](images/badges/modifier-public.svg)

docs/api_reference/sdk-src_program-manager.md

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,15 +1253,23 @@ assert(isValid);
12531253

12541254
---
12551255

1256-
### `createProgramFromSource(program) ► Program`
1256+
### `createProgramFromSource(executionResponse, imports, importedVerifyingKeys, program) ► boolean`
12571257

12581258
![modifier: public](images/badges/modifier-public.svg)
12591259

1260-
Create a program object from a program&#x27;s source code
1260+
Set the inclusion key bytes.
12611261

12621262
Parameters | Type | Description
12631263
--- | --- | ---
1264+
__executionResponse__ | `executionResponse` | *The response from an offline function execution (via the &#x60;programManager.run&#x60; method)*
1265+
__imports__ | `ImportedPrograms` | *The imported programs used in the execution. Specified as { &quot;programName&quot;: &quot;programSourceCode&quot;, ... }*
1266+
__importedVerifyingKeys__ | `ImportedVerifyingKeys` | *The verifying keys in the execution. Specified as { &quot;programName&quot;: [[&quot;functionName&quot;, &quot;verifyingKey&quot;], ...], ... }*
12641267
__program__ | `string` | *Program source code*
1268+
__*return*__ | `boolean` | *True if the proof is valid, false otherwise
1269+
1270+
1271+
/**
1272+
Create a program object from a program&#x27;s source code*
12651273
__*return*__ | [Program](sdk-src_wasm.md) | *The program object*
12661274

12671275
---
@@ -2521,15 +2529,23 @@ assert(isValid);
25212529

25222530
---
25232531

2524-
### `createProgramFromSource(program) ► Program`
2532+
### `createProgramFromSource(executionResponse, imports, importedVerifyingKeys, program) ► boolean`
25252533

25262534
![modifier: public](images/badges/modifier-public.svg)
25272535

2528-
Create a program object from a program&#x27;s source code
2536+
Set the inclusion key bytes.
25292537

25302538
Parameters | Type | Description
25312539
--- | --- | ---
2540+
__executionResponse__ | `executionResponse` | *The response from an offline function execution (via the &#x60;programManager.run&#x60; method)*
2541+
__imports__ | `ImportedPrograms` | *The imported programs used in the execution. Specified as { &quot;programName&quot;: &quot;programSourceCode&quot;, ... }*
2542+
__importedVerifyingKeys__ | `ImportedVerifyingKeys` | *The verifying keys in the execution. Specified as { &quot;programName&quot;: [[&quot;functionName&quot;, &quot;verifyingKey&quot;], ...], ... }*
25322543
__program__ | `string` | *Program source code*
2544+
__*return*__ | `boolean` | *True if the proof is valid, false otherwise
2545+
2546+
2547+
/**
2548+
Create a program object from a program&#x27;s source code*
25332549
__*return*__ | [Program](sdk-src_wasm.md) | *The program object*
25342550

25352551
---

docs/api_reference/sdk-src_record-provider.md

Lines changed: 30 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,21 @@ Set the account used to search for records
2121

2222
Parameters | Type | Description
2323
--- | --- | ---
24-
__account__ | [Account](sdk-src_account.md) | *The account to use for searching for records*
24+
__account__ | [Account](sdk-src_account.md) | *The account used to use for searching for records.*
2525

2626
---
2727

28-
### `findCreditsRecords(microcredits, unspent, nonces, searchParameters) ► Promise.<RecordPlaintext>`
28+
### `findCreditsRecords(microcredits, searchParameters) ► Promise.<Array.<OwnedRecord>>`
2929

3030
![modifier: public](images/badges/modifier-public.svg)
3131

3232
Find a list of credit records with a given number of microcredits by via the official Aleo API
3333

3434
Parameters | Type | Description
3535
--- | --- | ---
36-
__microcredits__ | `Array.<number>` | *The number of microcredits to search for*
37-
__unspent__ | `boolean` | *Whether or not the record is unspent*
38-
__nonces__ | `Array.<string>` | *Nonces of records already found so that they are not found again*
39-
__searchParameters__ | `RecordSearchParams` | *Additional parameters to search for*
40-
__*return*__ | `Promise.<RecordPlaintext>` | *The record if found, otherwise an error*
36+
__microcredits__ | `Array.<number>` | *The number of microcredits to search for.*
37+
__searchParameters__ | `RecordSearchParams` | *Additional parameters to search for.*
38+
__*return*__ | `Promise.<Array.<OwnedRecord>>` | *The records if found, otherwise an error.*
4139

4240
#### Examples
4341

@@ -48,11 +46,11 @@ const keyProvider = new AleoKeyProvider();
4846
const recordProvider = new NetworkRecordProvider(account, networkClient);
4947

5048
// The record provider can be used to find records with a given number of microcredits
51-
const record = await recordProvider.findCreditsRecord(5000, true, []);
49+
const record = await recordProvider.findCreditsRecord(5000, { unspent: true, nonces: [] });
5250

5351
// When a record is found but not yet used, it's nonce should be added to the nonces parameter so that it is not
5452
// found again if a subsequent search is performed
55-
const records = await recordProvider.findCreditsRecords(5000, true, [record.nonce()]);
53+
const records = await recordProvider.findCreditsRecords(5000, { unspent: true, nonces: [record.nonce()] });
5654

5755
// When the program manager is initialized with the record provider it will be used to find automatically find
5856
// fee records and amount records for value transfers so that they do not need to be specified manually
@@ -62,19 +60,17 @@ programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwn
6260

6361
---
6462

65-
### `findCreditsRecord(microcredits, unspent, nonces, searchParameters) ► Promise.<RecordPlaintext>`
63+
### `findCreditsRecord(microcredits, searchParameters) ► Promise.<OwnedRecord>`
6664

6765
![modifier: public](images/badges/modifier-public.svg)
6866

6967
Find a credit record with a given number of microcredits by via the official Aleo API
7068

7169
Parameters | Type | Description
7270
--- | --- | ---
73-
__microcredits__ | `number` | *The number of microcredits to search for*
74-
__unspent__ | `boolean` | *Whether or not the record is unspent*
75-
__nonces__ | `Array.<string>` | *Nonces of records already found so that they are not found again*
76-
__searchParameters__ | `RecordSearchParams` | *Additional parameters to search for*
77-
__*return*__ | `Promise.<RecordPlaintext>` | *The record if found, otherwise an error*
71+
__microcredits__ | `number` | *The number of microcredits to search for.*
72+
__searchParameters__ | `RecordSearchParams` | *Additional parameters to search for.*
73+
__*return*__ | `Promise.<OwnedRecord>` | *The record if found, otherwise an error.*
7874

7975
#### Examples
8076

@@ -85,11 +81,11 @@ const keyProvider = new AleoKeyProvider();
8581
const recordProvider = new NetworkRecordProvider(account, networkClient);
8682

8783
// The record provider can be used to find records with a given number of microcredits
88-
const record = await recordProvider.findCreditsRecord(5000, true, []);
84+
const record = await recordProvider.findCreditsRecord(5000, { unspent: true, nonces: [] });
8985

9086
// When a record is found but not yet used, it's nonce should be added to the nonces parameter so that it is not
9187
// found again if a subsequent search is performed
92-
const records = await recordProvider.findCreditsRecords(5000, true, [record.nonce()]);
88+
const records = await recordProvider.findCreditsRecords(5000, { unspent: true, nonces: [record.nonce()] });
9389

9490
// When the program manager is initialized with the record provider it will be used to find automatically find
9591
// fee records and amount records for value transfers so that they do not need to be specified manually
@@ -123,23 +119,21 @@ Set the account used to search for records
123119

124120
Parameters | Type | Description
125121
--- | --- | ---
126-
__account__ | [Account](sdk-src_account.md) | *The account to use for searching for records*
122+
__account__ | [Account](sdk-src_account.md) | *The account used to use for searching for records.*
127123

128124
---
129125

130-
### `findCreditsRecords(microcredits, unspent, nonces, searchParameters) ► Promise.<RecordPlaintext>`
126+
### `findCreditsRecords(microcredits, searchParameters) ► Promise.<Array.<OwnedRecord>>`
131127

132128
![modifier: public](images/badges/modifier-public.svg)
133129

134130
Find a list of credit records with a given number of microcredits by via the official Aleo API
135131

136132
Parameters | Type | Description
137133
--- | --- | ---
138-
__microcredits__ | `Array.<number>` | *The number of microcredits to search for*
139-
__unspent__ | `boolean` | *Whether or not the record is unspent*
140-
__nonces__ | `Array.<string>` | *Nonces of records already found so that they are not found again*
141-
__searchParameters__ | `RecordSearchParams` | *Additional parameters to search for*
142-
__*return*__ | `Promise.<RecordPlaintext>` | *The record if found, otherwise an error*
134+
__microcredits__ | `Array.<number>` | *The number of microcredits to search for.*
135+
__searchParameters__ | `RecordSearchParams` | *Additional parameters to search for.*
136+
__*return*__ | `Promise.<Array.<OwnedRecord>>` | *The records if found, otherwise an error.*
143137

144138
#### Examples
145139

@@ -150,11 +144,11 @@ const keyProvider = new AleoKeyProvider();
150144
const recordProvider = new NetworkRecordProvider(account, networkClient);
151145

152146
// The record provider can be used to find records with a given number of microcredits
153-
const record = await recordProvider.findCreditsRecord(5000, true, []);
147+
const record = await recordProvider.findCreditsRecord(5000, { unspent: true, nonces: [] });
154148

155149
// When a record is found but not yet used, it's nonce should be added to the nonces parameter so that it is not
156150
// found again if a subsequent search is performed
157-
const records = await recordProvider.findCreditsRecords(5000, true, [record.nonce()]);
151+
const records = await recordProvider.findCreditsRecords(5000, { unspent: true, nonces: [record.nonce()] });
158152

159153
// When the program manager is initialized with the record provider it will be used to find automatically find
160154
// fee records and amount records for value transfers so that they do not need to be specified manually
@@ -164,19 +158,17 @@ programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwn
164158

165159
---
166160

167-
### `findCreditsRecord(microcredits, unspent, nonces, searchParameters) ► Promise.<RecordPlaintext>`
161+
### `findCreditsRecord(microcredits, searchParameters) ► Promise.<OwnedRecord>`
168162

169163
![modifier: public](images/badges/modifier-public.svg)
170164

171165
Find a credit record with a given number of microcredits by via the official Aleo API
172166

173167
Parameters | Type | Description
174168
--- | --- | ---
175-
__microcredits__ | `number` | *The number of microcredits to search for*
176-
__unspent__ | `boolean` | *Whether or not the record is unspent*
177-
__nonces__ | `Array.<string>` | *Nonces of records already found so that they are not found again*
178-
__searchParameters__ | `RecordSearchParams` | *Additional parameters to search for*
179-
__*return*__ | `Promise.<RecordPlaintext>` | *The record if found, otherwise an error*
169+
__microcredits__ | `number` | *The number of microcredits to search for.*
170+
__searchParameters__ | `RecordSearchParams` | *Additional parameters to search for.*
171+
__*return*__ | `Promise.<OwnedRecord>` | *The record if found, otherwise an error.*
180172

181173
#### Examples
182174

@@ -187,11 +179,11 @@ const keyProvider = new AleoKeyProvider();
187179
const recordProvider = new NetworkRecordProvider(account, networkClient);
188180

189181
// The record provider can be used to find records with a given number of microcredits
190-
const record = await recordProvider.findCreditsRecord(5000, true, []);
182+
const record = await recordProvider.findCreditsRecord(5000, { unspent: true, nonces: [] });
191183

192184
// When a record is found but not yet used, it's nonce should be added to the nonces parameter so that it is not
193185
// found again if a subsequent search is performed
194-
const records = await recordProvider.findCreditsRecords(5000, true, [record.nonce()]);
186+
const records = await recordProvider.findCreditsRecords(5000, { unspent: true, nonces: [record.nonce()] });
195187

196188
// When the program manager is initialized with the record provider it will be used to find automatically find
197189
// fee records and amount records for value transfers so that they do not need to be specified manually
@@ -201,31 +193,27 @@ programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwn
201193

202194
---
203195

204-
### `findRecord(unspent, nonces, searchParameters) ► Promise.<RecordPlaintext>`
196+
### `findRecord(searchParameters) ► Promise.<OwnedRecord>`
205197

206198
![modifier: public](images/badges/modifier-public.svg)
207199

208200
Find an arbitrary record. WARNING: This function is not implemented yet and will throw an error.
209201

210202
Parameters | Type | Description
211203
--- | --- | ---
212-
__unspent__ | `boolean` | **
213-
__nonces__ | `Array` | **
214204
__searchParameters__ | `RecordSearchParams` | **
215-
__*return*__ | `Promise.<RecordPlaintext>` | **
205+
__*return*__ | `Promise.<OwnedRecord>` | **
216206

217207
---
218208

219-
### `findRecords(unspent, nonces, searchParameters) ► Promise.<Array>`
209+
### `findRecords(searchParameters) ► Promise.<Array>`
220210

221211
![modifier: public](images/badges/modifier-public.svg)
222212

223213
Find multiple records from a specified program.
224214

225215
Parameters | Type | Description
226216
--- | --- | ---
227-
__unspent__ | `boolean` | **
228-
__nonces__ | `Array` | **
229217
__searchParameters__ | `RecordSearchParams` | **
230218
__*return*__ | `Promise.<Array>` | **
231219

@@ -249,5 +237,5 @@ const recordProvider = new NetworkRecordProvider(account, networkClient);
249237

250238
// The record provider can be used to find records with a given number of microcredits and the block height search
251239
// can be used to find records within a given block height range
252-
const record = await recordProvider.findCreditsRecord(5000, true, [], params);
240+
const record = await recordProvider.findCreditsRecord(5000, { unspent: true, nonces: [], ...params });
253241
```

0 commit comments

Comments
 (0)