@provablehq/sdk 0.10.2 → 0.10.4
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.
- package/dist/dynamic/browser.cjs +12 -0
- package/dist/dynamic/browser.d.cts +8 -0
- package/dist/dynamic/browser.d.ts +2 -2
- package/dist/dynamic/node.cjs +12 -0
- package/dist/dynamic/node.d.cts +8 -0
- package/dist/dynamic/node.d.ts +2 -2
- package/dist/mainnet/account.d.cts +347 -0
- package/dist/mainnet/browser.cjs +8530 -0
- package/dist/mainnet/browser.cjs.map +1 -0
- package/dist/mainnet/browser.d.cts +72 -0
- package/dist/mainnet/browser.d.ts +3 -3
- package/dist/mainnet/browser.js +78 -32
- package/dist/mainnet/browser.js.map +1 -1
- package/dist/mainnet/constants.d.cts +40 -0
- package/dist/mainnet/external-signing.d.cts +76 -0
- package/dist/mainnet/integrations/sealance/merkle-tree.d.cts +192 -0
- package/dist/mainnet/keys/keystore/error.d.cts +24 -0
- package/dist/mainnet/keys/keystore/file.d.cts +177 -0
- package/dist/mainnet/keys/keystore/interface.d.cts +161 -0
- package/dist/mainnet/keys/provider/interface.d.cts +170 -0
- package/dist/mainnet/keys/provider/memory.d.cts +213 -0
- package/dist/mainnet/keys/provider/memory.d.ts +6 -2
- package/dist/mainnet/keys/provider/offline.d.cts +365 -0
- package/dist/mainnet/keys/verifier/interface.d.cts +70 -0
- package/dist/mainnet/keys/verifier/memory.d.cts +37 -0
- package/dist/mainnet/keys/verifier/memory.d.ts +1 -1
- package/dist/mainnet/models/authorization.d.cts +6 -0
- package/dist/mainnet/models/authorization.d.ts +2 -2
- package/dist/mainnet/models/blockJSON.d.cts +33 -0
- package/dist/mainnet/models/confirmed_transaction.d.cts +9 -0
- package/dist/mainnet/models/cryptoBoxPubkey.d.cts +4 -0
- package/dist/mainnet/models/deployment/deploymentJSON.d.cts +6 -0
- package/dist/mainnet/models/deployment/deploymentObject.d.cts +6 -0
- package/dist/mainnet/models/encryptedProvingRequest.d.cts +4 -0
- package/dist/mainnet/models/execution/executionJSON.d.cts +11 -0
- package/dist/mainnet/models/execution/executionObject.d.cts +11 -0
- package/dist/mainnet/models/external-signing.d.cts +123 -0
- package/dist/mainnet/models/finalizeJSON.d.cts +6 -0
- package/dist/mainnet/models/functionInput.d.cts +7 -0
- package/dist/mainnet/models/functionObject.d.cts +8 -0
- package/dist/mainnet/models/imports.d.cts +7 -0
- package/dist/mainnet/models/input/inputJSON.d.cts +10 -0
- package/dist/mainnet/models/input/inputObject.d.cts +15 -0
- package/dist/mainnet/models/inputID.d.cts +4 -0
- package/dist/mainnet/models/keyPair.d.cts +4 -0
- package/dist/mainnet/models/output/outputJSON.d.cts +7 -0
- package/dist/mainnet/models/output/outputObject.d.cts +18 -0
- package/dist/mainnet/models/owner/ownerJSON.d.cts +4 -0
- package/dist/mainnet/models/owner/ownerObject.d.cts +5 -0
- package/dist/mainnet/models/plaintext/array.d.cts +3 -0
- package/dist/mainnet/models/plaintext/literal.d.cts +1 -0
- package/dist/mainnet/models/plaintext/plaintext.d.cts +5 -0
- package/dist/mainnet/models/plaintext/struct.d.cts +5 -0
- package/dist/mainnet/models/provingRequest.d.cts +6 -0
- package/dist/mainnet/models/provingRequest.d.ts +1 -1
- package/dist/mainnet/models/provingResponse.d.cts +51 -0
- package/dist/mainnet/models/ratification.d.cts +4 -0
- package/dist/mainnet/models/record-provider/encryptedRecord.d.cts +58 -0
- package/dist/mainnet/models/record-provider/ownedRecord.d.cts +60 -0
- package/dist/mainnet/models/record-provider/recordSearchParams.d.cts +19 -0
- package/dist/mainnet/models/record-scanner/encryptedRecordsResult.d.cts +7 -0
- package/dist/mainnet/models/record-scanner/encryptedRegistrationRequest.d.cts +8 -0
- package/dist/mainnet/models/record-scanner/error.d.cts +47 -0
- package/dist/mainnet/models/record-scanner/error.d.ts +1 -1
- package/dist/mainnet/models/record-scanner/ownedFilter.d.cts +22 -0
- package/dist/mainnet/models/record-scanner/ownedFilter.d.ts +3 -3
- package/dist/mainnet/models/record-scanner/ownedRecordsResponseFilter.d.cts +42 -0
- package/dist/mainnet/models/record-scanner/ownedRecordsResult.d.cts +13 -0
- package/dist/mainnet/models/record-scanner/recordsFilter.d.cts +35 -0
- package/dist/mainnet/models/record-scanner/recordsFilter.d.ts +2 -2
- package/dist/mainnet/models/record-scanner/recordsResponseFilter.d.cts +42 -0
- package/dist/mainnet/models/record-scanner/registrationRequest.d.cts +13 -0
- package/dist/mainnet/models/record-scanner/registrationResponse.d.cts +13 -0
- package/dist/mainnet/models/record-scanner/registrationResult.d.cts +9 -0
- package/dist/mainnet/models/record-scanner/revokeResult.d.cts +17 -0
- package/dist/mainnet/models/record-scanner/serialNumbersResult.d.cts +15 -0
- package/dist/mainnet/models/record-scanner/statusResponse.d.cts +13 -0
- package/dist/mainnet/models/record-scanner/statusResult.d.cts +13 -0
- package/dist/mainnet/models/record-scanner/tagsResult.d.cts +12 -0
- package/dist/mainnet/models/request.d.cts +14 -0
- package/dist/mainnet/models/request.d.ts +1 -1
- package/dist/mainnet/models/solution.d.cts +14 -0
- package/dist/mainnet/models/transaction/transactionJSON.d.cts +11 -0
- package/dist/mainnet/models/transaction/transactionObject.d.cts +14 -0
- package/dist/mainnet/models/transition/transitionJSON.d.cts +13 -0
- package/dist/mainnet/models/transition/transitionObject.d.cts +15 -0
- package/dist/mainnet/network-client.d.cts +850 -0
- package/dist/mainnet/network-client.d.ts +3 -0
- package/dist/mainnet/node-polyfill.cjs +238 -0
- package/dist/mainnet/node-polyfill.cjs.map +1 -0
- package/dist/mainnet/node-polyfill.d.cts +5 -0
- package/dist/mainnet/node-polyfill.js +1 -1
- package/dist/mainnet/node-polyfill.js.map +1 -1
- package/dist/mainnet/node.cjs +686 -0
- package/dist/mainnet/node.cjs.map +1 -0
- package/dist/mainnet/node.d.cts +3 -0
- package/dist/mainnet/node.js +2 -2
- package/dist/mainnet/polyfill/crypto.d.cts +1 -0
- package/dist/mainnet/polyfill/fetch.d.cts +1 -0
- package/dist/mainnet/polyfill/shared.d.cts +1 -0
- package/dist/mainnet/polyfill/worker.d.cts +1 -0
- package/dist/mainnet/polyfill/xmlhttprequest.d.cts +1 -0
- package/dist/mainnet/program-manager.d.cts +1600 -0
- package/dist/mainnet/program-manager.d.ts +13 -1
- package/dist/mainnet/record-provider.d.cts +274 -0
- package/dist/mainnet/record-scanner.d.cts +371 -0
- package/dist/mainnet/record-scanner.d.ts +9 -6
- package/dist/mainnet/security.d.cts +62 -0
- package/dist/mainnet/security.d.ts +5 -5
- package/dist/mainnet/utils.d.cts +23 -0
- package/dist/mainnet/utils.d.ts +10 -2
- package/dist/mainnet/wasm.d.cts +1 -0
- package/dist/testnet/account.d.cts +347 -0
- package/dist/testnet/browser.cjs +8530 -0
- package/dist/testnet/browser.cjs.map +1 -0
- package/dist/testnet/browser.d.cts +72 -0
- package/dist/testnet/browser.d.ts +3 -3
- package/dist/testnet/browser.js +78 -32
- package/dist/testnet/browser.js.map +1 -1
- package/dist/testnet/constants.d.cts +40 -0
- package/dist/testnet/external-signing.d.cts +76 -0
- package/dist/testnet/integrations/sealance/merkle-tree.d.cts +192 -0
- package/dist/testnet/keys/keystore/error.d.cts +24 -0
- package/dist/testnet/keys/keystore/file.d.cts +177 -0
- package/dist/testnet/keys/keystore/interface.d.cts +161 -0
- package/dist/testnet/keys/provider/interface.d.cts +170 -0
- package/dist/testnet/keys/provider/memory.d.cts +213 -0
- package/dist/testnet/keys/provider/memory.d.ts +6 -2
- package/dist/testnet/keys/provider/offline.d.cts +365 -0
- package/dist/testnet/keys/verifier/interface.d.cts +70 -0
- package/dist/testnet/keys/verifier/memory.d.cts +37 -0
- package/dist/testnet/keys/verifier/memory.d.ts +1 -1
- package/dist/testnet/models/authorization.d.cts +6 -0
- package/dist/testnet/models/authorization.d.ts +2 -2
- package/dist/testnet/models/blockJSON.d.cts +33 -0
- package/dist/testnet/models/confirmed_transaction.d.cts +9 -0
- package/dist/testnet/models/cryptoBoxPubkey.d.cts +4 -0
- package/dist/testnet/models/deployment/deploymentJSON.d.cts +6 -0
- package/dist/testnet/models/deployment/deploymentObject.d.cts +6 -0
- package/dist/testnet/models/encryptedProvingRequest.d.cts +4 -0
- package/dist/testnet/models/execution/executionJSON.d.cts +11 -0
- package/dist/testnet/models/execution/executionObject.d.cts +11 -0
- package/dist/testnet/models/external-signing.d.cts +123 -0
- package/dist/testnet/models/finalizeJSON.d.cts +6 -0
- package/dist/testnet/models/functionInput.d.cts +7 -0
- package/dist/testnet/models/functionObject.d.cts +8 -0
- package/dist/testnet/models/imports.d.cts +7 -0
- package/dist/testnet/models/input/inputJSON.d.cts +10 -0
- package/dist/testnet/models/input/inputObject.d.cts +15 -0
- package/dist/testnet/models/inputID.d.cts +4 -0
- package/dist/testnet/models/keyPair.d.cts +4 -0
- package/dist/testnet/models/output/outputJSON.d.cts +7 -0
- package/dist/testnet/models/output/outputObject.d.cts +18 -0
- package/dist/testnet/models/owner/ownerJSON.d.cts +4 -0
- package/dist/testnet/models/owner/ownerObject.d.cts +5 -0
- package/dist/testnet/models/plaintext/array.d.cts +3 -0
- package/dist/testnet/models/plaintext/literal.d.cts +1 -0
- package/dist/testnet/models/plaintext/plaintext.d.cts +5 -0
- package/dist/testnet/models/plaintext/struct.d.cts +5 -0
- package/dist/testnet/models/provingRequest.d.cts +6 -0
- package/dist/testnet/models/provingRequest.d.ts +1 -1
- package/dist/testnet/models/provingResponse.d.cts +51 -0
- package/dist/testnet/models/ratification.d.cts +4 -0
- package/dist/testnet/models/record-provider/encryptedRecord.d.cts +58 -0
- package/dist/testnet/models/record-provider/ownedRecord.d.cts +60 -0
- package/dist/testnet/models/record-provider/recordSearchParams.d.cts +19 -0
- package/dist/testnet/models/record-scanner/encryptedRecordsResult.d.cts +7 -0
- package/dist/testnet/models/record-scanner/encryptedRegistrationRequest.d.cts +8 -0
- package/dist/testnet/models/record-scanner/error.d.cts +47 -0
- package/dist/testnet/models/record-scanner/error.d.ts +1 -1
- package/dist/testnet/models/record-scanner/ownedFilter.d.cts +22 -0
- package/dist/testnet/models/record-scanner/ownedFilter.d.ts +3 -3
- package/dist/testnet/models/record-scanner/ownedRecordsResponseFilter.d.cts +42 -0
- package/dist/testnet/models/record-scanner/ownedRecordsResult.d.cts +13 -0
- package/dist/testnet/models/record-scanner/recordsFilter.d.cts +35 -0
- package/dist/testnet/models/record-scanner/recordsFilter.d.ts +2 -2
- package/dist/testnet/models/record-scanner/recordsResponseFilter.d.cts +42 -0
- package/dist/testnet/models/record-scanner/registrationRequest.d.cts +13 -0
- package/dist/testnet/models/record-scanner/registrationResponse.d.cts +13 -0
- package/dist/testnet/models/record-scanner/registrationResult.d.cts +9 -0
- package/dist/testnet/models/record-scanner/revokeResult.d.cts +17 -0
- package/dist/testnet/models/record-scanner/serialNumbersResult.d.cts +15 -0
- package/dist/testnet/models/record-scanner/statusResponse.d.cts +13 -0
- package/dist/testnet/models/record-scanner/statusResult.d.cts +13 -0
- package/dist/testnet/models/record-scanner/tagsResult.d.cts +12 -0
- package/dist/testnet/models/request.d.cts +14 -0
- package/dist/testnet/models/request.d.ts +1 -1
- package/dist/testnet/models/solution.d.cts +14 -0
- package/dist/testnet/models/transaction/transactionJSON.d.cts +11 -0
- package/dist/testnet/models/transaction/transactionObject.d.cts +14 -0
- package/dist/testnet/models/transition/transitionJSON.d.cts +13 -0
- package/dist/testnet/models/transition/transitionObject.d.cts +15 -0
- package/dist/testnet/network-client.d.cts +850 -0
- package/dist/testnet/network-client.d.ts +3 -0
- package/dist/testnet/node-polyfill.cjs +238 -0
- package/dist/testnet/node-polyfill.cjs.map +1 -0
- package/dist/testnet/node-polyfill.d.cts +5 -0
- package/dist/testnet/node-polyfill.js +1 -1
- package/dist/testnet/node-polyfill.js.map +1 -1
- package/dist/testnet/node.cjs +686 -0
- package/dist/testnet/node.cjs.map +1 -0
- package/dist/testnet/node.d.cts +3 -0
- package/dist/testnet/node.js +2 -2
- package/dist/testnet/polyfill/crypto.d.cts +1 -0
- package/dist/testnet/polyfill/fetch.d.cts +1 -0
- package/dist/testnet/polyfill/shared.d.cts +1 -0
- package/dist/testnet/polyfill/worker.d.cts +1 -0
- package/dist/testnet/polyfill/xmlhttprequest.d.cts +1 -0
- package/dist/testnet/program-manager.d.cts +1600 -0
- package/dist/testnet/program-manager.d.ts +13 -1
- package/dist/testnet/record-provider.d.cts +274 -0
- package/dist/testnet/record-scanner.d.cts +371 -0
- package/dist/testnet/record-scanner.d.ts +9 -6
- package/dist/testnet/security.d.cts +62 -0
- package/dist/testnet/security.d.ts +5 -5
- package/dist/testnet/utils.d.cts +23 -0
- package/dist/testnet/utils.d.ts +10 -2
- package/dist/testnet/wasm.d.cts +1 -0
- package/package.json +51 -9
|
@@ -1585,4 +1585,16 @@ declare function verifyProof(options: VerificationOptions): boolean;
|
|
|
1585
1585
|
* });
|
|
1586
1586
|
*/
|
|
1587
1587
|
declare function verifyBatchProof(options: BatchVerificationOptions): boolean;
|
|
1588
|
-
|
|
1588
|
+
/**
|
|
1589
|
+
* Get the checksum of an Aleo program.
|
|
1590
|
+
*
|
|
1591
|
+
* @param {string | Program} program Program string or Program object
|
|
1592
|
+
* @returns {Uint8Array} The keccak256 checksum of the program as a 32-byte Uint8Array
|
|
1593
|
+
*
|
|
1594
|
+
* @example
|
|
1595
|
+
* import { programChecksum } from "@provablehq/sdk/mainnet.js";
|
|
1596
|
+
*
|
|
1597
|
+
* const checksum = programChecksum("program foo.aleo; ...");
|
|
1598
|
+
*/
|
|
1599
|
+
declare function programChecksum(program: string | Program): Uint8Array;
|
|
1600
|
+
export { ProgramManager, AuthorizationOptions, FeeAuthorizationOptions, ExecuteOptions, ProvingRequestOptions, ExternalSigningOptions, VerificationOptions, BatchVerificationOptions, inputsToFields, verifyProof, verifyBatchProof, programChecksum };
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
import { Account } from "./account.js";
|
|
2
|
+
import { AleoNetworkClient } from "./network-client.js";
|
|
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";
|
|
7
|
+
/**
|
|
8
|
+
* Interface for a record provider. A record provider is used to find records for use in deployment and execution
|
|
9
|
+
* transactions on the Aleo Network. A default implementation is provided by the NetworkRecordProvider class. However,
|
|
10
|
+
* a custom implementation can be provided (say if records are synced locally to a database from the network) by
|
|
11
|
+
* implementing this interface.
|
|
12
|
+
*/
|
|
13
|
+
interface RecordProvider {
|
|
14
|
+
/**
|
|
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.
|
|
28
|
+
*
|
|
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.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* // A class implementing record provider can be used to find a record with a given number of microcredits
|
|
49
|
+
* const record = await recordProvider.findCreditsRecord(5000, { unspent: true, nonces: [] });
|
|
50
|
+
*
|
|
51
|
+
* // When a record is found but not yet used, its nonce should be added to the nonces array so that it is not
|
|
52
|
+
* // found again if a subsequent search is performed
|
|
53
|
+
* const record2 = await recordProvider.findCreditsRecord(5000, { unspent: true, nonces: [record.nonce()] });
|
|
54
|
+
*
|
|
55
|
+
* // When the program manager is initialized with the record provider it will be used to find automatically find
|
|
56
|
+
* // fee records and amount records for value transfers so that they do not need to be specified manually
|
|
57
|
+
* const programManager = new ProgramManager("https://api.provable.com/v2", keyProvider, recordProvider);
|
|
58
|
+
* programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
|
|
59
|
+
*/
|
|
60
|
+
findCreditsRecord(microcredits: number, searchParameters: RecordSearchParams): Promise<OwnedRecord>;
|
|
61
|
+
/**
|
|
62
|
+
* Find a list of credit.aleo records with a given number of microcredits from the chosen provider
|
|
63
|
+
*
|
|
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.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* // A class implementing record provider can be used to find a record with a given number of microcredits
|
|
70
|
+
* const records = await recordProvider.findCreditsRecords([5000, 5000], { unspent: true, nonces: [] });
|
|
71
|
+
*
|
|
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
|
|
73
|
+
* // found again if a subsequent search is performed
|
|
74
|
+
* const nonces = [];
|
|
75
|
+
* records.forEach(record => { nonces.push(record.nonce()) });
|
|
76
|
+
* const records2 = await recordProvider.findCreditsRecord(5000, { unspent: true, nonces });
|
|
77
|
+
*
|
|
78
|
+
* // When the program manager is initialized with the record provider it will be used to find automatically find
|
|
79
|
+
* // fee records and amount records for value transfers so that they do not need to be specified manually
|
|
80
|
+
* const programManager = new ProgramManager("https://api.provable.com/v2", keyProvider, recordProvider);
|
|
81
|
+
* programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
|
|
82
|
+
*/
|
|
83
|
+
findCreditsRecords(microcreditAmounts: number[], searchParameters: RecordSearchParams): Promise<OwnedRecord[]>;
|
|
84
|
+
/**
|
|
85
|
+
* Find an arbitrary record
|
|
86
|
+
* @param {RecordSearchParams} searchParameters Additional parameters to search for.
|
|
87
|
+
* @returns {Promise<OwnedRecord>} The record if found, otherwise an error.
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* // The RecordSearchParams interface can be used to create parameters for custom record searches which can then
|
|
91
|
+
* // be passed to the record provider. An example of how this would be done for the credits.aleo program is shown
|
|
92
|
+
* // below.
|
|
93
|
+
*
|
|
94
|
+
* class CustomRecordSearch implements RecordSearchParams {
|
|
95
|
+
* startHeight: number;
|
|
96
|
+
* endHeight: number;
|
|
97
|
+
* amount: number;
|
|
98
|
+
* program: string;
|
|
99
|
+
* 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
|
+
* ) {
|
|
112
|
+
* this.startHeight = startHeight;
|
|
113
|
+
* this.endHeight = endHeight;
|
|
114
|
+
* this.amount = amount;
|
|
115
|
+
* this.program = programName;
|
|
116
|
+
* this.recordName = recordName;
|
|
117
|
+
* this.nonces = nonces;
|
|
118
|
+
* this.unspent = unspent;
|
|
119
|
+
* }
|
|
120
|
+
* }
|
|
121
|
+
*
|
|
122
|
+
* const params = new CustomRecordSearch(0, 100, 5000, "credits.aleo", "credits", [], true);
|
|
123
|
+
*
|
|
124
|
+
* const record = await recordProvider.findRecord(params);
|
|
125
|
+
*/
|
|
126
|
+
findRecord(searchParameters: RecordSearchParams): Promise<OwnedRecord>;
|
|
127
|
+
/**
|
|
128
|
+
* Find multiple records from arbitrary programs
|
|
129
|
+
*
|
|
130
|
+
* @param {RecordSearchParams} searchParameters Additional parameters to search for.
|
|
131
|
+
* @returns {Promise<OwnedRecord[]>} The records if found, otherwise an error.
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* // The RecordSearchParams interface can be used to create parameters for custom record searches which can then
|
|
135
|
+
* // be passed to the record provider. An example of how this would be done for the credits.aleo program is shown
|
|
136
|
+
* // below.
|
|
137
|
+
*
|
|
138
|
+
* class CustomRecordSearch implements RecordSearchParams {
|
|
139
|
+
* startHeight: number;
|
|
140
|
+
* endHeight: number;
|
|
141
|
+
* credits: number;
|
|
142
|
+
* program: string;
|
|
143
|
+
* 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
|
+
* ) {
|
|
156
|
+
* this.startHeight = startHeight;
|
|
157
|
+
* this.endHeight = endHeight;
|
|
158
|
+
* this.credits = credits;
|
|
159
|
+
* this.program = programName;
|
|
160
|
+
* this.recordName = recordName;
|
|
161
|
+
* this.nonces = nonces;
|
|
162
|
+
* this.unspent = unspent;
|
|
163
|
+
* }
|
|
164
|
+
* }
|
|
165
|
+
*
|
|
166
|
+
* const params = new CustomRecordSearch(0, 100, 5000, 2, "credits.aleo", "credits");
|
|
167
|
+
* const records = await recordProvider.findRecord(true, [], params);
|
|
168
|
+
*/
|
|
169
|
+
findRecords(searchParameters: RecordSearchParams): Promise<OwnedRecord[]>;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* A record provider implementation that uses the official Aleo API to find records for usage in program execution and
|
|
173
|
+
* deployment, wallet functionality, and other use cases.
|
|
174
|
+
*/
|
|
175
|
+
declare class NetworkRecordProvider implements RecordProvider {
|
|
176
|
+
account: Account;
|
|
177
|
+
networkClient: AleoNetworkClient;
|
|
178
|
+
constructor(account: Account, networkClient: AleoNetworkClient);
|
|
179
|
+
/**
|
|
180
|
+
* Set the account used to search for records
|
|
181
|
+
*
|
|
182
|
+
* @param {Account} account The account used to use for searching for records.
|
|
183
|
+
*/
|
|
184
|
+
setAccount(account: Account): void;
|
|
185
|
+
/**
|
|
186
|
+
* Find a list of credit records with a given number of microcredits by via the official Aleo API
|
|
187
|
+
*
|
|
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.
|
|
191
|
+
*
|
|
192
|
+
* @example
|
|
193
|
+
* // Create a new NetworkRecordProvider
|
|
194
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2");
|
|
195
|
+
* const keyProvider = new AleoKeyProvider();
|
|
196
|
+
* const recordProvider = new NetworkRecordProvider(account, networkClient);
|
|
197
|
+
*
|
|
198
|
+
* // The record provider can be used to find records with a given number of microcredits
|
|
199
|
+
* const record = await recordProvider.findCreditsRecord(5000, { unspent: true, nonces: [] });
|
|
200
|
+
*
|
|
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
|
|
202
|
+
* // found again if a subsequent search is performed
|
|
203
|
+
* const records = await recordProvider.findCreditsRecords(5000, { unspent: true, nonces: [record.nonce()] });
|
|
204
|
+
*
|
|
205
|
+
* // When the program manager is initialized with the record provider it will be used to find automatically find
|
|
206
|
+
* // fee records and amount records for value transfers so that they do not need to be specified manually
|
|
207
|
+
* const programManager = new ProgramManager("https://api.provable.com/v2", keyProvider, recordProvider);
|
|
208
|
+
* programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
|
|
209
|
+
*
|
|
210
|
+
* */
|
|
211
|
+
findCreditsRecords(microcredits: number[], searchParameters: RecordSearchParams): Promise<OwnedRecord[]>;
|
|
212
|
+
/**
|
|
213
|
+
* Find a credit record with a given number of microcredits by via the official Aleo API
|
|
214
|
+
*
|
|
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.
|
|
218
|
+
*
|
|
219
|
+
* @example
|
|
220
|
+
* // Create a new NetworkRecordProvider
|
|
221
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2");
|
|
222
|
+
* const keyProvider = new AleoKeyProvider();
|
|
223
|
+
* const recordProvider = new NetworkRecordProvider(account, networkClient);
|
|
224
|
+
*
|
|
225
|
+
* // The record provider can be used to find records with a given number of microcredits
|
|
226
|
+
* const record = await recordProvider.findCreditsRecord(5000, { unspent: true, nonces: [] });
|
|
227
|
+
*
|
|
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
|
|
229
|
+
* // found again if a subsequent search is performed
|
|
230
|
+
* const records = await recordProvider.findCreditsRecords(5000, { unspent: true, nonces: [record.nonce()] });
|
|
231
|
+
*
|
|
232
|
+
* // When the program manager is initialized with the record provider it will be used to find automatically find
|
|
233
|
+
* // fee records and amount records for value transfers so that they do not need to be specified manually
|
|
234
|
+
* const programManager = new ProgramManager("https://api.provable.com/v2", keyProvider, recordProvider);
|
|
235
|
+
* programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
|
|
236
|
+
*/
|
|
237
|
+
findCreditsRecord(microcredits: number, searchParameters: RecordSearchParams): Promise<OwnedRecord>;
|
|
238
|
+
/**
|
|
239
|
+
* Find an arbitrary record. WARNING: This function is not implemented yet and will throw an error.
|
|
240
|
+
*/
|
|
241
|
+
findRecord(searchParameters: RecordSearchParams): Promise<OwnedRecord>;
|
|
242
|
+
/**
|
|
243
|
+
* Find multiple records from a specified program.
|
|
244
|
+
*/
|
|
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>>;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* BlockHeightSearch is a RecordSearchParams implementation that allows for searching for records within a given
|
|
252
|
+
* block height range.
|
|
253
|
+
*
|
|
254
|
+
* @example
|
|
255
|
+
* // Create a new BlockHeightSearch
|
|
256
|
+
* const params = new BlockHeightSearch(89995, 99995);
|
|
257
|
+
*
|
|
258
|
+
* // Create a new NetworkRecordProvider
|
|
259
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2");
|
|
260
|
+
* const keyProvider = new AleoKeyProvider();
|
|
261
|
+
* const recordProvider = new NetworkRecordProvider(account, networkClient);
|
|
262
|
+
*
|
|
263
|
+
* // The record provider can be used to find records with a given number of microcredits and the block height search
|
|
264
|
+
* // can be used to find records within a given block height range
|
|
265
|
+
* const record = await recordProvider.findCreditsRecord(5000, { unspent: true, nonces: [], ...params });
|
|
266
|
+
*
|
|
267
|
+
*/
|
|
268
|
+
declare class BlockHeightSearch implements RecordSearchParams {
|
|
269
|
+
startHeight: number;
|
|
270
|
+
endHeight: number;
|
|
271
|
+
unspent: boolean;
|
|
272
|
+
constructor(startHeight: number, endHeight: number, unspent?: boolean);
|
|
273
|
+
}
|
|
274
|
+
export { BlockHeightSearch, NetworkRecordProvider, RecordProvider, };
|
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
import { TransportFunction } from "./utils.js";
|
|
2
|
+
import { EncryptedRecord } from "./models/record-provider/encryptedRecord.js";
|
|
3
|
+
import { CryptoBoxPubKey } from "./models/cryptoBoxPubkey.js";
|
|
4
|
+
import { OwnedFilter } from "./models/record-scanner/ownedFilter.js";
|
|
5
|
+
import { OwnedRecord } from "./models/record-provider/ownedRecord.js";
|
|
6
|
+
import { RecordProvider } from "./record-provider.js";
|
|
7
|
+
import { Field, ViewKey } from "./wasm.js";
|
|
8
|
+
import { RecordsFilter } from "./models/record-scanner/recordsFilter.js";
|
|
9
|
+
import { RegisterResult } from "./models/record-scanner/registrationResult.js";
|
|
10
|
+
import { RevokeResult } from "./models/record-scanner/revokeResult.js";
|
|
11
|
+
import { TagsResult } from "./models/record-scanner/tagsResult.js";
|
|
12
|
+
import { SerialNumbersResult } from "./models/record-scanner/serialNumbersResult.js";
|
|
13
|
+
import { StatusResult } from "./models/record-scanner/statusResult.js";
|
|
14
|
+
import { OwnedRecordsResult } from "./models/record-scanner/ownedRecordsResult.js";
|
|
15
|
+
import { EncryptedRecordsResult } from "./models/record-scanner/encryptedRecordsResult.js";
|
|
16
|
+
import { Account } from "./account.js";
|
|
17
|
+
/**
|
|
18
|
+
* JWT data for optional authentication with the record scanning service (e.g. Provable API).
|
|
19
|
+
*
|
|
20
|
+
* @property {string} jwt The JWT token string.
|
|
21
|
+
* @property {number} expiration Expiration time as a Unix timestamp (e.g. in milliseconds).
|
|
22
|
+
*/
|
|
23
|
+
export interface RecordScannerJWTData {
|
|
24
|
+
jwt: string;
|
|
25
|
+
expiration: number;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Configuration for the record scanner.
|
|
29
|
+
*
|
|
30
|
+
* @property {string} url Base URL of the record scanning service (network path is appended by the SDK).
|
|
31
|
+
* @property {string | { header: string, value: string }} [apiKey] API key as a string or as a custom header name and value.
|
|
32
|
+
* @property {string} [consumerId] Required for JWT refresh when using authenticated record scanner (e.g. Provable API).
|
|
33
|
+
* @property {RecordScannerJWTData} [jwtData] Optional JWT for auth. If omitted and apiKey + consumerId are set, JWT is refreshed when needed.
|
|
34
|
+
* @property {ViewKey[]} [viewKeys] Optional view keys to use for local scanning and decryption.
|
|
35
|
+
* @property {Account} [account] Optional account to use for local scanning and decryption.
|
|
36
|
+
* @property {boolean} [cacheViewKeysOnRegister] Cache view keys in memory for faster scanning upon register.
|
|
37
|
+
* @property {boolean} [autoReRegister] If true, on 422 from /owned attempt one re-register via registerEncrypted (when a view key is in viewKeys or account) and retry once. Default false.
|
|
38
|
+
* @property {boolean} [decryptEnabled] If true, enable decryption of owned records (e.g. for use with the decrypt method). This is REQUIRED for findCreditsRecord/findCreditsRecords to work properly. Further the ViewKey matching the UUID must be stored in the RecordScanner object to perform decryption. Default false.
|
|
39
|
+
*/
|
|
40
|
+
export interface RecordScannerOptions {
|
|
41
|
+
url: string;
|
|
42
|
+
apiKey?: string | {
|
|
43
|
+
header: string;
|
|
44
|
+
value: string;
|
|
45
|
+
};
|
|
46
|
+
consumerId?: string;
|
|
47
|
+
jwtData?: RecordScannerJWTData;
|
|
48
|
+
viewKeys?: ViewKey[];
|
|
49
|
+
account?: Account;
|
|
50
|
+
cacheViewKeysOnRegister?: boolean;
|
|
51
|
+
autoReRegister?: boolean;
|
|
52
|
+
decryptEnabled?: boolean;
|
|
53
|
+
transport?: TransportFunction;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* RecordScanner is a RecordProvider implementation that uses Provable's confidential record scanning service to find
|
|
57
|
+
* records.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* const account = new Account({ privateKey: 'APrivateKey1...' });
|
|
61
|
+
*
|
|
62
|
+
* const recordScanner = new RecordScanner({ url: "https://record-scanner.aleo.org" });
|
|
63
|
+
* recordScanner.setAccount(account);
|
|
64
|
+
* recordScanner.setApiKey("example-api-key");
|
|
65
|
+
* const result = await recordScanner.register(viewKey, 0);
|
|
66
|
+
* if (result.ok) { const uuid = result.data.uuid; }
|
|
67
|
+
*
|
|
68
|
+
* const filter = {
|
|
69
|
+
* uuid,
|
|
70
|
+
* filter: {
|
|
71
|
+
* program: "credits.aleo",
|
|
72
|
+
* records: ["credits"],
|
|
73
|
+
* },
|
|
74
|
+
* responseFilter: {
|
|
75
|
+
* commitment: true,
|
|
76
|
+
* owner: true,
|
|
77
|
+
* tag: true,
|
|
78
|
+
* tag?: boolean;
|
|
79
|
+
* sender: true,
|
|
80
|
+
* spent: true,
|
|
81
|
+
* record_ciphertext: true,
|
|
82
|
+
* block_height: true;
|
|
83
|
+
* block_timestamp: true;
|
|
84
|
+
* output_index: true;
|
|
85
|
+
* record_name: true;
|
|
86
|
+
* function_name: true;
|
|
87
|
+
* program_name: true;
|
|
88
|
+
* transition_id: true;
|
|
89
|
+
* transaction_id: true;
|
|
90
|
+
* transaction_index: true;
|
|
91
|
+
* transition_index: true;
|
|
92
|
+
* },
|
|
93
|
+
* unspent: true,
|
|
94
|
+
* };
|
|
95
|
+
*
|
|
96
|
+
* const records = await recordScanner.findRecords(filter);
|
|
97
|
+
*/
|
|
98
|
+
declare class RecordScanner implements RecordProvider {
|
|
99
|
+
readonly cacheViewKeysOnRegister?: boolean;
|
|
100
|
+
readonly url: string;
|
|
101
|
+
private readonly baseUrl;
|
|
102
|
+
private apiKey?;
|
|
103
|
+
private consumerId?;
|
|
104
|
+
private jwtData?;
|
|
105
|
+
private uuid?;
|
|
106
|
+
private viewKeys?;
|
|
107
|
+
private autoReRegister?;
|
|
108
|
+
private decryptEnabled?;
|
|
109
|
+
transport: TransportFunction;
|
|
110
|
+
account?: Account | undefined;
|
|
111
|
+
/**
|
|
112
|
+
* @param {RecordScannerOptions} options Configuration for the record scanner.
|
|
113
|
+
*/
|
|
114
|
+
constructor(options: RecordScannerOptions);
|
|
115
|
+
/**
|
|
116
|
+
* Set the API key to use for the record scanner.
|
|
117
|
+
*
|
|
118
|
+
* @param {string | { header: string, value: string }} apiKey The API key to use for the record scanner.
|
|
119
|
+
*/
|
|
120
|
+
setApiKey(apiKey: string | {
|
|
121
|
+
header: string;
|
|
122
|
+
value: string;
|
|
123
|
+
}): void;
|
|
124
|
+
/**
|
|
125
|
+
* Set the consumer ID used for JWT refresh when using authenticated record scanner (e.g. Provable API).
|
|
126
|
+
*
|
|
127
|
+
* @param {string} consumerId The consumer ID to use for JWT refresh.
|
|
128
|
+
*/
|
|
129
|
+
setConsumerId(consumerId: string): void;
|
|
130
|
+
/**
|
|
131
|
+
* Set JWT data for authentication. Optional; when not set, JWT can be refreshed from apiKey + consumerId if provided.
|
|
132
|
+
*
|
|
133
|
+
* @param {RecordScannerJWTData | undefined} jwtData The JWT data to use, or undefined to clear.
|
|
134
|
+
*/
|
|
135
|
+
setJwtData(jwtData: RecordScannerJWTData | undefined): void;
|
|
136
|
+
/**
|
|
137
|
+
* Set whether /owned should automatically re-register on 422 (when a view key for the UUID is in viewKeys or account) and retry once.
|
|
138
|
+
*
|
|
139
|
+
* @param {boolean} enabled Whether to enable auto re-register on 422.
|
|
140
|
+
*/
|
|
141
|
+
setAutoReRegister(enabled: boolean): void;
|
|
142
|
+
/**
|
|
143
|
+
* Set whether decryption of owned records is enabled (e.g. for use with the decrypt method).
|
|
144
|
+
*
|
|
145
|
+
* @param {boolean} enabled Whether to enable decryption of owned records received from the scanner using the `owned` or any `findRecords` methods.
|
|
146
|
+
*/
|
|
147
|
+
setDecryptEnabled(enabled: boolean): void;
|
|
148
|
+
/**
|
|
149
|
+
* Add a view key to the record scanner for usage in local decryption. This is REQUIRED for findCreditsRecord/findCreditsRecords to work properly.
|
|
150
|
+
*
|
|
151
|
+
* @param {ViewKey} viewKey The view key to add.
|
|
152
|
+
*/
|
|
153
|
+
addViewKey(viewKey: ViewKey): void;
|
|
154
|
+
/**
|
|
155
|
+
* Remove a view key from the record scanner.
|
|
156
|
+
*
|
|
157
|
+
* @param {string} uuid The uuid of the view key to remove.
|
|
158
|
+
*/
|
|
159
|
+
removeViewKey(uuid: string): void;
|
|
160
|
+
/**
|
|
161
|
+
* Return the view key for the given record-scanner UUID if one is configured
|
|
162
|
+
* (in viewKeys or as the account's view key). Used to decide if re-registration on 422 is possible.
|
|
163
|
+
*
|
|
164
|
+
* @param {string} uuid The record-scanner UUID to look up.
|
|
165
|
+
* @returns {ViewKey | undefined} The view key for that UUID, or undefined.
|
|
166
|
+
*/
|
|
167
|
+
private getViewKeyForUuid;
|
|
168
|
+
/**
|
|
169
|
+
* Set the primary account for the record scanner.
|
|
170
|
+
*
|
|
171
|
+
* @param {Account} account The account to set as the primary account.
|
|
172
|
+
*/
|
|
173
|
+
setAccount(account: Account): void;
|
|
174
|
+
/**
|
|
175
|
+
* Refreshes the JWT by making a POST request to /jwts/{consumer_id}. Used when authentication is required.
|
|
176
|
+
*
|
|
177
|
+
* @param {string} apiKey The API key to use for the refresh request.
|
|
178
|
+
* @param {string} consumerId The consumer ID for the JWT endpoint.
|
|
179
|
+
* @returns {Promise<RecordScannerJWTData>} The new JWT data.
|
|
180
|
+
*/
|
|
181
|
+
private refreshJwt;
|
|
182
|
+
/**
|
|
183
|
+
* Returns auth headers (e.g. Authorization with JWT). Refreshes JWT if expired and apiKey + consumerId are set. Empty when auth is not configured.
|
|
184
|
+
*
|
|
185
|
+
* @returns {Promise<Record<string, string>>} Auth headers to add to requests, or empty object when not configured.
|
|
186
|
+
*/
|
|
187
|
+
private getAuthHeaders;
|
|
188
|
+
/**
|
|
189
|
+
* Set the UUID for the record scanner.
|
|
190
|
+
*
|
|
191
|
+
* @param {Field | ViewKey} keyMaterial The UUID to use for the record scanner. If a ViewKey is provided, the UUID will be computed from the key.
|
|
192
|
+
*/
|
|
193
|
+
setUuid(keyMaterial: Field | ViewKey): void;
|
|
194
|
+
/**
|
|
195
|
+
* If the error is a RecordScannerRequestError (from request()), return a RecordScannerFailure result;
|
|
196
|
+
* otherwise re-throw the error.
|
|
197
|
+
*
|
|
198
|
+
* @param {unknown} err The error from a failed request (e.g. from request() or from a catch after calling it).
|
|
199
|
+
* @returns {RecordScannerFailure} When err is RecordScannerRequestError.
|
|
200
|
+
* @throws Re-throws err when it is not a RecordScannerRequestError.
|
|
201
|
+
*/
|
|
202
|
+
private handleRequestError;
|
|
203
|
+
/**
|
|
204
|
+
* Register the account with the record scanning service (unencrypted POST /register). Does not throw if a valid error response from the record scanner is received; returns a result object instead.
|
|
205
|
+
*
|
|
206
|
+
* @param {ViewKey} viewKey The view key to register.
|
|
207
|
+
* @param {number} startBlock The block height to start scanning from.
|
|
208
|
+
* @returns {Promise<RegisterResult>} `{ ok: true, data }` on success, or `{ ok: false, status, error }` on failure.
|
|
209
|
+
*/
|
|
210
|
+
register(viewKey: ViewKey, startBlock: number): Promise<RegisterResult>;
|
|
211
|
+
/**
|
|
212
|
+
* Fetches an ephemeral public key from the record scanning service for use with registerEncrypted.
|
|
213
|
+
* Follows the same pattern as the delegated proving service /pubkey endpoint.
|
|
214
|
+
*
|
|
215
|
+
* @returns {Promise<CryptoBoxPubKey>} The service's ephemeral public key and key_id.
|
|
216
|
+
*/
|
|
217
|
+
getPubkey(): Promise<CryptoBoxPubKey>;
|
|
218
|
+
/**
|
|
219
|
+
* Registers the account with the record scanning service using the encrypted flow: 1. fetches an ephemeral public key from /pubkey - 2. encrypts the registration request (view key + start block) - 3. POSTs to /register/encrypted. Does not HTTP error on a proper error response from the record scanner; returns a result object instead.
|
|
220
|
+
*
|
|
221
|
+
* @param {ViewKey} viewKey The view key to register.
|
|
222
|
+
* @param {number} startBlock The block height to start scanning from.
|
|
223
|
+
* @returns {Promise<RegisterResult>} `{ ok: true, data }` on success, or `{ ok: false, status, error }` on failure.
|
|
224
|
+
*/
|
|
225
|
+
registerEncrypted(viewKey: ViewKey, startBlock: number): Promise<RegisterResult>;
|
|
226
|
+
/**
|
|
227
|
+
* Remove all local scanner state associated with the given UUID (stored uuid, viewKeys entry, account if it matches).
|
|
228
|
+
* Called after a successful revoke so the scanner does not retain view keys or account for a revoked registration.
|
|
229
|
+
*/
|
|
230
|
+
private clearLocalStateForUuid;
|
|
231
|
+
/**
|
|
232
|
+
* Revoke the account registration with the record scanning service (POST /revoke). On success, also removes
|
|
233
|
+
* all local state for that UUID: the stored UUID (if it matches), the view key for that UUID, and the
|
|
234
|
+
* account (if its view key corresponds to that UUID).
|
|
235
|
+
*
|
|
236
|
+
* @param {string | Field | undefined} uuid The UUID to revoke. If omitted, uses the UUID configured on the scanner.
|
|
237
|
+
* @returns {Promise<RevokeResult>} `{ ok: true, data: { status } }` on success, or `{ ok: false, status, error }` on failure.
|
|
238
|
+
* @throws {UUIDError} When no UUID is configured and none provided, or when the UUID string is invalid.
|
|
239
|
+
*/
|
|
240
|
+
revoke(uuid?: string | Field): Promise<RevokeResult>;
|
|
241
|
+
/**
|
|
242
|
+
* Get encrypted records from the record scanning service. This is a safe variant of /records/encrypted that returns
|
|
243
|
+
* a result instead of throwing on HTTP error.
|
|
244
|
+
*
|
|
245
|
+
* @param {RecordsFilter} recordsFilter The filter to use to find the records and filter the response.
|
|
246
|
+
* @returns {Promise<EncryptedRecordsResult>} The encrypted records or an error if the request failed.
|
|
247
|
+
*/
|
|
248
|
+
encrypted(recordsFilter: RecordsFilter): Promise<EncryptedRecordsResult>;
|
|
249
|
+
/**
|
|
250
|
+
* Get encrypted records from the record scanning service.
|
|
251
|
+
*
|
|
252
|
+
* @param {RecordsFilter} recordsFilter The filter to use to find the records and filter the response.
|
|
253
|
+
* @returns {Promise<EncryptedRecord[]>} The encrypted records.
|
|
254
|
+
*/
|
|
255
|
+
encryptedRecords(recordsFilter: RecordsFilter): Promise<EncryptedRecord[]>;
|
|
256
|
+
/**
|
|
257
|
+
* Check if serial numbers appear in any record inputs on-chain, indicating that the records they belong to have been spent. This is a safe variant of /records/sns that returns a result instead of throwing on HTTP error.
|
|
258
|
+
*
|
|
259
|
+
* @param {string[]} serialNumbers The serial numbers to check.
|
|
260
|
+
* @returns {Promise<SerialNumbersResult>} Map of Aleo Record serial numbers and whether they appeared in any inputs on chain. If a boolean corresponding to the Serial Number has a true value, that Record is considered spent by the Aleo Network.
|
|
261
|
+
*/
|
|
262
|
+
serialNumbers(serialNumbers: string[]): Promise<SerialNumbersResult>;
|
|
263
|
+
/**
|
|
264
|
+
* Check if serial numbers appear in any record inputs on-chain, indicating that the records they belong to have been spent.
|
|
265
|
+
*
|
|
266
|
+
* @param {string[]} serialNumbers The serial numbers to check.
|
|
267
|
+
* @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.
|
|
268
|
+
*/
|
|
269
|
+
checkSerialNumbers(serialNumbers: string[]): Promise<Record<string, boolean>>;
|
|
270
|
+
/**
|
|
271
|
+
* Check if tags appear in any record inputs on-chain, indicating that the records they belong to have been spent. This is a safe variant of /records/tags that returns a result instead of throwing on HTTP error.
|
|
272
|
+
*
|
|
273
|
+
* *
|
|
274
|
+
* @param {string[]} tags The tags to check.
|
|
275
|
+
* @returns {Promise<TagsResult>} Map of Aleo Record tags and whether they appeared in any inputs on chain. If a boolean corresponding to the tag has a true value, that Record is considered spent by the Aleo Network.
|
|
276
|
+
*/
|
|
277
|
+
tags(tags: string[]): Promise<TagsResult>;
|
|
278
|
+
/**
|
|
279
|
+
* Check if tags appear in any record inputs on-chain, indicating that the records they belong to have been spent.
|
|
280
|
+
*
|
|
281
|
+
* @param {string[]} tags The tags to check.
|
|
282
|
+
* @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.
|
|
283
|
+
*/
|
|
284
|
+
checkTags(tags: string[]): Promise<Record<string, boolean>>;
|
|
285
|
+
/**
|
|
286
|
+
* Check the scan completion job status for a specific UUID.
|
|
287
|
+
*
|
|
288
|
+
* @param {string | Field | undefined} uuid The UUID of the job to check. If no UUID is provided as input, the UUID configured for the scanner will be used.
|
|
289
|
+
* @returns {Promise<StatusResult>} The status of the job or an error if the job could not be found.
|
|
290
|
+
*/
|
|
291
|
+
status(uuid?: string | Field): Promise<StatusResult>;
|
|
292
|
+
/**
|
|
293
|
+
* Find a record in the record scanning service.
|
|
294
|
+
*
|
|
295
|
+
* @param {OwnedFilter} searchParameters The filter to use to find the record.
|
|
296
|
+
* @returns {Promise<OwnedRecord>} The record.
|
|
297
|
+
*/
|
|
298
|
+
findRecord(searchParameters: OwnedFilter): Promise<OwnedRecord>;
|
|
299
|
+
/**
|
|
300
|
+
* Get owned records. Throws if the UUID passed in the OwnedFilter is invalid or is not configured in the record scanner otherwise returns the RESTFUL response from the record scanner.
|
|
301
|
+
*
|
|
302
|
+
* @param {OwnedFilter} filter The OwnedFilter used to specify the subset of owned records to select.
|
|
303
|
+
* @returns {Promise<OwnedRecordsResult>} Record belonging to the uuid passed in the filter or set on the Record Scanner.
|
|
304
|
+
*/
|
|
305
|
+
owned(filter: OwnedFilter): Promise<OwnedRecordsResult>;
|
|
306
|
+
/**
|
|
307
|
+
* Find records using the record scanning service.
|
|
308
|
+
*
|
|
309
|
+
* @param {OwnedFilter} searchParameters The filter to use to find the records.
|
|
310
|
+
* @returns {Promise<OwnedRecord[]>} The records.
|
|
311
|
+
*/
|
|
312
|
+
findRecords(searchParameters: OwnedFilter): Promise<OwnedRecord[]>;
|
|
313
|
+
/**
|
|
314
|
+
* Get RecordPlaintext from an OwnedRecord by parsing record_plaintext (trimmed). Returns null if missing or parse fails. Does not decrypt; decryption is handled only in owned().
|
|
315
|
+
*/
|
|
316
|
+
private getPlaintext;
|
|
317
|
+
/**
|
|
318
|
+
* For each owned record provided, attempt to decrypt with the given view key. On success, sets record_plaintext on that record to the decrypted plaintext string. Records that fail to decrypt (e.g. wrong view key) or have no record_ciphertext are left unchanged.
|
|
319
|
+
*
|
|
320
|
+
* @param {ViewKey} viewKey The view key to use for decryption.
|
|
321
|
+
* @param {OwnedRecord[]} records The owned records to decrypt (mutated in place).
|
|
322
|
+
*/
|
|
323
|
+
decrypt(viewKey: ViewKey, records: OwnedRecord[]): void;
|
|
324
|
+
/**
|
|
325
|
+
* Find a credits.aleo record in the record scanning service.
|
|
326
|
+
*
|
|
327
|
+
* @param {number} microcredits The amount of microcredits to find.
|
|
328
|
+
* @param {OwnedFilter} searchParameters The filter to use to find the record.
|
|
329
|
+
* @returns {Promise<OwnedRecord>} The record.
|
|
330
|
+
*/
|
|
331
|
+
findCreditsRecord(microcredits: number, searchParameters: OwnedFilter): Promise<OwnedRecord>;
|
|
332
|
+
/**
|
|
333
|
+
* Find credits records greater than or equal to the specified amounts using the record scanning service.
|
|
334
|
+
*
|
|
335
|
+
* @param {number[]} microcreditAmounts The amounts of microcredits to find.
|
|
336
|
+
* @param {OwnedFilter} searchParameters The filter to use to find the records.
|
|
337
|
+
* @returns {Promise<OwnedRecord[]>} The records
|
|
338
|
+
*/
|
|
339
|
+
findCreditsRecords(microcreditAmounts: number[], searchParameters: OwnedFilter): Promise<OwnedRecord[]>;
|
|
340
|
+
/**
|
|
341
|
+
* Wrapper function to make a request to the record scanning service and handle any errors. Optionally adds JWT Authorization header when consumerId/jwtData (or apiKey+consumerId) are configured.
|
|
342
|
+
*
|
|
343
|
+
* @param {Request} req The request to make.
|
|
344
|
+
* @returns {Promise<Response>} The response when the request succeeds.
|
|
345
|
+
* @throws {RecordScannerRequestError} When the server returns a non-2xx status (e.g. 4xx, 5xx).
|
|
346
|
+
* @throws Re-throws any error from fetch (e.g. network failure) or from getAuthHeaders().
|
|
347
|
+
*/
|
|
348
|
+
private request;
|
|
349
|
+
/**
|
|
350
|
+
* Compute the record scanner UUID for a view key.
|
|
351
|
+
*
|
|
352
|
+
* @param {ViewKey} viewKey The view key to compute the UUID for.
|
|
353
|
+
* @returns {Field} The computed UUID corresponding to the view key.
|
|
354
|
+
*/
|
|
355
|
+
computeUUID(viewKey: ViewKey): Field;
|
|
356
|
+
/**
|
|
357
|
+
* Validate a UUID string to ensure it represents a valid Aleo Record Scanner UUID.
|
|
358
|
+
*
|
|
359
|
+
* @param {string} uuid The UUID to validate.
|
|
360
|
+
* @returns {boolean} Whether the UUID is valid.
|
|
361
|
+
*/
|
|
362
|
+
uuidIsValid(uuid: string): boolean;
|
|
363
|
+
/**
|
|
364
|
+
* Get the uuid for the filter, first by extracting the UUID from the filter, then falling back to the uuid configured within the record scanner.
|
|
365
|
+
*
|
|
366
|
+
* @param {OwnedFilter} filter The filter to extract the UUID from.
|
|
367
|
+
* @returns {string | undefined} The UUID for the filter, or undefined if the filter does not contain a UUID.
|
|
368
|
+
*/
|
|
369
|
+
private getUUID;
|
|
370
|
+
}
|
|
371
|
+
export { RecordScanner };
|