@provablehq/sdk 0.9.16-rc → 0.9.17
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/mainnet/account.d.ts +18 -3
- package/dist/mainnet/browser.d.ts +26 -7
- package/dist/mainnet/browser.js +1198 -248
- package/dist/mainnet/browser.js.map +1 -1
- package/dist/mainnet/keys/keystore/error.d.ts +23 -0
- package/dist/mainnet/keys/keystore/file.d.ts +207 -13
- package/dist/mainnet/keys/keystore/interface.d.ts +85 -0
- package/dist/mainnet/keys/provider/interface.d.ts +170 -0
- package/dist/{testnet/keys/provider/function-key-provider.d.ts → mainnet/keys/provider/memory.d.ts} +14 -180
- package/dist/{testnet/keys/provider/offline-key-provider.d.ts → mainnet/keys/provider/offline.d.ts} +4 -4
- package/dist/mainnet/keys/verifier/interface.d.ts +70 -0
- package/dist/mainnet/keys/verifier/memory.d.ts +37 -0
- package/dist/mainnet/models/cryptoBoxPubkey.d.ts +4 -0
- package/dist/mainnet/models/encryptedProvingRequest.d.ts +4 -0
- package/dist/mainnet/models/provingResponse.d.ts +48 -2
- package/dist/mainnet/models/record-scanner/encryptedRecordsResult.d.ts +7 -0
- package/dist/mainnet/models/record-scanner/encryptedRegistrationRequest.d.ts +8 -0
- package/dist/mainnet/models/record-scanner/error.d.ts +47 -0
- package/dist/mainnet/models/record-scanner/ownedFilter.d.ts +0 -2
- package/dist/mainnet/models/record-scanner/ownedRecordsResult.d.ts +13 -0
- package/dist/mainnet/models/record-scanner/registrationResponse.d.ts +0 -2
- package/dist/mainnet/models/record-scanner/registrationResult.d.ts +9 -0
- package/dist/mainnet/models/record-scanner/revokeResult.d.ts +17 -0
- package/dist/mainnet/models/record-scanner/serialNumbersResult.d.ts +15 -0
- package/dist/mainnet/models/record-scanner/statusResult.d.ts +13 -0
- package/dist/mainnet/models/record-scanner/tagsResult.d.ts +12 -0
- package/dist/mainnet/network-client.d.ts +81 -35
- package/dist/mainnet/node.js +345 -75
- package/dist/mainnet/node.js.map +1 -1
- package/dist/mainnet/program-manager.d.ts +54 -48
- package/dist/mainnet/record-provider.d.ts +7 -7
- package/dist/mainnet/record-scanner.d.ts +247 -31
- package/dist/mainnet/security.d.ts +38 -0
- package/dist/mainnet/utils.d.ts +1 -0
- package/dist/testnet/account.d.ts +18 -3
- package/dist/testnet/browser.d.ts +26 -7
- package/dist/testnet/browser.js +1198 -248
- package/dist/testnet/browser.js.map +1 -1
- package/dist/testnet/keys/keystore/error.d.ts +23 -0
- package/dist/testnet/keys/keystore/file.d.ts +207 -13
- package/dist/testnet/keys/keystore/interface.d.ts +85 -0
- package/dist/testnet/keys/provider/interface.d.ts +170 -0
- package/dist/{mainnet/keys/provider/function-key-provider.d.ts → testnet/keys/provider/memory.d.ts} +14 -180
- package/dist/{mainnet/keys/provider/offline-key-provider.d.ts → testnet/keys/provider/offline.d.ts} +4 -4
- package/dist/testnet/keys/verifier/interface.d.ts +70 -0
- package/dist/testnet/keys/verifier/memory.d.ts +37 -0
- package/dist/testnet/models/cryptoBoxPubkey.d.ts +4 -0
- package/dist/testnet/models/encryptedProvingRequest.d.ts +4 -0
- package/dist/testnet/models/provingResponse.d.ts +48 -2
- package/dist/testnet/models/record-scanner/encryptedRecordsResult.d.ts +7 -0
- package/dist/testnet/models/record-scanner/encryptedRegistrationRequest.d.ts +8 -0
- package/dist/testnet/models/record-scanner/error.d.ts +47 -0
- package/dist/testnet/models/record-scanner/ownedFilter.d.ts +0 -2
- package/dist/testnet/models/record-scanner/ownedRecordsResult.d.ts +13 -0
- package/dist/testnet/models/record-scanner/registrationResponse.d.ts +0 -2
- package/dist/testnet/models/record-scanner/registrationResult.d.ts +9 -0
- package/dist/testnet/models/record-scanner/revokeResult.d.ts +17 -0
- package/dist/testnet/models/record-scanner/serialNumbersResult.d.ts +15 -0
- package/dist/testnet/models/record-scanner/statusResult.d.ts +13 -0
- package/dist/testnet/models/record-scanner/tagsResult.d.ts +12 -0
- package/dist/testnet/network-client.d.ts +81 -35
- package/dist/testnet/node.js +345 -75
- package/dist/testnet/node.js.map +1 -1
- package/dist/testnet/program-manager.d.ts +54 -48
- package/dist/testnet/record-provider.d.ts +7 -7
- package/dist/testnet/record-scanner.d.ts +247 -31
- package/dist/testnet/security.d.ts +38 -0
- package/dist/testnet/utils.d.ts +1 -0
- package/package.json +4 -3
- package/dist/mainnet/keys/keystore/keystore.d.ts +0 -81
- package/dist/mainnet/keys/keystore/memory.d.ts +0 -8
- package/dist/testnet/keys/keystore/keystore.d.ts +0 -81
- package/dist/testnet/keys/keystore/memory.d.ts +0 -8
package/dist/{testnet/keys/provider/function-key-provider.d.ts → mainnet/keys/provider/memory.d.ts}
RENAMED
|
@@ -1,19 +1,13 @@
|
|
|
1
|
-
import { Key } from "../../constants";
|
|
2
|
-
import { CachedKeyPair, FunctionKeyPair } from "../../models/keyPair";
|
|
3
|
-
import {
|
|
4
|
-
import { ProvingKey, VerifyingKey } from "../../wasm";
|
|
1
|
+
import { Key } from "../../constants.js";
|
|
2
|
+
import { CachedKeyPair, FunctionKeyPair } from "../../models/keyPair.js";
|
|
3
|
+
import { FunctionKeyProvider, KeySearchParams } from "./interface";
|
|
4
|
+
import { ProvingKey, VerifyingKey } from "../../wasm.js";
|
|
5
|
+
import { KeyStore } from "../keystore/interface.js";
|
|
5
6
|
type AleoKeyProviderInitParams = {
|
|
6
7
|
proverUri?: string;
|
|
7
8
|
verifierUri?: string;
|
|
8
9
|
cacheKey?: string;
|
|
9
10
|
};
|
|
10
|
-
/**
|
|
11
|
-
* Interface for record search parameters. This allows for arbitrary search parameters to be passed to record provider
|
|
12
|
-
* implementations.
|
|
13
|
-
*/
|
|
14
|
-
interface KeySearchParams {
|
|
15
|
-
[key: string]: any;
|
|
16
|
-
}
|
|
17
11
|
/**
|
|
18
12
|
* AleoKeyProviderParams search parameter for the AleoKeyProvider. It allows for the specification of a proverUri and
|
|
19
13
|
* verifierUri to fetch keys via HTTP from a remote resource as well as a unique cacheKey to store the keys in memory.
|
|
@@ -39,168 +33,8 @@ declare class AleoKeyProviderParams implements KeySearchParams {
|
|
|
39
33
|
});
|
|
40
34
|
}
|
|
41
35
|
/**
|
|
42
|
-
*
|
|
43
|
-
|
|
44
|
-
interface FunctionKeyProvider {
|
|
45
|
-
/**
|
|
46
|
-
* Get bond_public function keys from the credits.aleo program
|
|
47
|
-
*
|
|
48
|
-
* @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the bond_public function
|
|
49
|
-
*/
|
|
50
|
-
bondPublicKeys(): Promise<FunctionKeyPair>;
|
|
51
|
-
/**
|
|
52
|
-
* Get bond_validator function keys from the credits.aleo program
|
|
53
|
-
*
|
|
54
|
-
* @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the bond_validator function
|
|
55
|
-
*/
|
|
56
|
-
bondValidatorKeys(): Promise<FunctionKeyPair>;
|
|
57
|
-
/**
|
|
58
|
-
* Cache a set of keys. This will overwrite any existing keys with the same keyId. The user can check if a keyId
|
|
59
|
-
* exists in the cache using the containsKeys method prior to calling this method if overwriting is not desired.
|
|
60
|
-
*
|
|
61
|
-
* @param {string} keyId access key for the cache
|
|
62
|
-
* @param {FunctionKeyPair} keys keys to cache
|
|
63
|
-
*/
|
|
64
|
-
cacheKeys(keyId: string, keys: FunctionKeyPair): void;
|
|
65
|
-
/**
|
|
66
|
-
* Get unbond_public function keys from the credits.aleo program
|
|
67
|
-
*
|
|
68
|
-
* @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the unbond_public function
|
|
69
|
-
*/
|
|
70
|
-
claimUnbondPublicKeys(): Promise<FunctionKeyPair>;
|
|
71
|
-
/**
|
|
72
|
-
* Get arbitrary function keys from a provider
|
|
73
|
-
*
|
|
74
|
-
* @param {KeySearchParams | undefined} params - Optional search parameters for the key provider
|
|
75
|
-
* @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the specified program
|
|
76
|
-
*
|
|
77
|
-
* @example
|
|
78
|
-
* // Create a search object which implements the KeySearchParams interface
|
|
79
|
-
* class IndexDbSearch implements KeySearchParams {
|
|
80
|
-
* db: string
|
|
81
|
-
* keyId: string
|
|
82
|
-
* constructor(params: {db: string, keyId: string}) {
|
|
83
|
-
* this.db = params.db;
|
|
84
|
-
* this.keyId = params.keyId;
|
|
85
|
-
* }
|
|
86
|
-
* }
|
|
87
|
-
*
|
|
88
|
-
* // Create a new object which implements the KeyProvider interface
|
|
89
|
-
* class IndexDbKeyProvider implements FunctionKeyProvider {
|
|
90
|
-
* async functionKeys(params: KeySearchParams): Promise<FunctionKeyPair> {
|
|
91
|
-
* return new Promise((resolve, reject) => {
|
|
92
|
-
* const request = indexedDB.open(params.db, 1);
|
|
93
|
-
*
|
|
94
|
-
* request.onupgradeneeded = function(e) {
|
|
95
|
-
* const db = e.target.result;
|
|
96
|
-
* if (!db.objectStoreNames.contains('keys')) {
|
|
97
|
-
* db.createObjectStore('keys', { keyPath: 'id' });
|
|
98
|
-
* }
|
|
99
|
-
* };
|
|
100
|
-
*
|
|
101
|
-
* request.onsuccess = function(e) {
|
|
102
|
-
* const db = e.target.result;
|
|
103
|
-
* const transaction = db.transaction(["keys"], "readonly");
|
|
104
|
-
* const store = transaction.objectStore("keys");
|
|
105
|
-
* const request = store.get(params.keyId);
|
|
106
|
-
* request.onsuccess = function(e) {
|
|
107
|
-
* if (request.result) {
|
|
108
|
-
* resolve(request.result as FunctionKeyPair);
|
|
109
|
-
* } else {
|
|
110
|
-
* reject(new Error("Key not found"));
|
|
111
|
-
* }
|
|
112
|
-
* };
|
|
113
|
-
* request.onerror = function(e) { reject(new Error("Error fetching key")); };
|
|
114
|
-
* };
|
|
115
|
-
*
|
|
116
|
-
* request.onerror = function(e) { reject(new Error("Error opening database")); };
|
|
117
|
-
* });
|
|
118
|
-
* }
|
|
119
|
-
*
|
|
120
|
-
* // implement the other methods...
|
|
121
|
-
* }
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
* const keyProvider = new AleoKeyProvider();
|
|
125
|
-
* const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1");
|
|
126
|
-
* const recordProvider = new NetworkRecordProvider(account, networkClient);
|
|
127
|
-
*
|
|
128
|
-
* // Initialize a program manager with the key provider to automatically fetch keys for value transfers
|
|
129
|
-
* const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider);
|
|
130
|
-
* programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
|
|
131
|
-
*
|
|
132
|
-
* // Keys can also be fetched manually
|
|
133
|
-
* const searchParams = new IndexDbSearch({db: "keys", keyId: "credits.aleo:transferPrivate"});
|
|
134
|
-
* const [transferPrivateProvingKey, transferPrivateVerifyingKey] = await keyProvider.functionKeys(searchParams);
|
|
135
|
-
*/
|
|
136
|
-
functionKeys(params?: KeySearchParams): Promise<FunctionKeyPair>;
|
|
137
|
-
/**
|
|
138
|
-
* Gets an object which implements the `KeyStore` interface key store object for accessing proving and verifying
|
|
139
|
-
* keys directly from persistent storage.
|
|
140
|
-
*
|
|
141
|
-
* @return {KeyStore}
|
|
142
|
-
*/
|
|
143
|
-
keyStore(): Promise<KeyStore | undefined>;
|
|
144
|
-
/**
|
|
145
|
-
* Get fee_private function keys from the credits.aleo program
|
|
146
|
-
*
|
|
147
|
-
* @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the join function
|
|
148
|
-
*/
|
|
149
|
-
feePrivateKeys(): Promise<FunctionKeyPair>;
|
|
150
|
-
/**
|
|
151
|
-
* Get fee_public function keys from the credits.aleo program
|
|
152
|
-
*
|
|
153
|
-
* @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the join function
|
|
154
|
-
*/
|
|
155
|
-
feePublicKeys(): Promise<FunctionKeyPair>;
|
|
156
|
-
/**
|
|
157
|
-
* Get keys for the inclusion proof.
|
|
158
|
-
*
|
|
159
|
-
* @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the join function
|
|
160
|
-
*/
|
|
161
|
-
inclusionKeys(): Promise<FunctionKeyPair>;
|
|
162
|
-
/**
|
|
163
|
-
* Get join function keys from the credits.aleo program
|
|
164
|
-
*
|
|
165
|
-
* @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the join function
|
|
166
|
-
*/
|
|
167
|
-
joinKeys(): Promise<FunctionKeyPair>;
|
|
168
|
-
/**
|
|
169
|
-
* Get split function keys from the credits.aleo program
|
|
170
|
-
*
|
|
171
|
-
* @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the join function
|
|
172
|
-
*/
|
|
173
|
-
splitKeys(): Promise<FunctionKeyPair>;
|
|
174
|
-
/**
|
|
175
|
-
* Get keys for a variant of the transfer function from the credits.aleo program
|
|
176
|
-
*
|
|
177
|
-
* @param {string} visibility Visibility of the transfer function (private, public, privateToPublic, publicToPrivate)
|
|
178
|
-
* @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the specified transfer function
|
|
179
|
-
*
|
|
180
|
-
* @example
|
|
181
|
-
* // Create a new object which implements the KeyProvider interface
|
|
182
|
-
* const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1");
|
|
183
|
-
* const keyProvider = new AleoKeyProvider();
|
|
184
|
-
* const recordProvider = new NetworkRecordProvider(account, networkClient);
|
|
185
|
-
*
|
|
186
|
-
* // Initialize a program manager with the key provider to automatically fetch keys for value transfers
|
|
187
|
-
* const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider);
|
|
188
|
-
* programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
|
|
189
|
-
*
|
|
190
|
-
* // Keys can also be fetched manually
|
|
191
|
-
* const [transferPublicProvingKey, transferPublicVerifyingKey] = await keyProvider.transferKeys("public");
|
|
192
|
-
*/
|
|
193
|
-
transferKeys(visibility: string): Promise<FunctionKeyPair>;
|
|
194
|
-
/**
|
|
195
|
-
* Get unbond_public function keys from the credits.aleo program
|
|
196
|
-
*
|
|
197
|
-
* @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the join function
|
|
198
|
-
*/
|
|
199
|
-
unBondPublicKeys(): Promise<FunctionKeyPair>;
|
|
200
|
-
}
|
|
201
|
-
/**
|
|
202
|
-
* AleoKeyProvider class. Implements the KeyProvider interface. Enables the retrieval of Aleo program proving and
|
|
203
|
-
* verifying keys for the credits.aleo program over http from official Aleo sources and storing and retrieving function
|
|
36
|
+
* AleoKeyProvider class. Implements the FunctionKeyProvider interface. Enables the retrieval of Aleo program proving and
|
|
37
|
+
* verifying keys for the credits.aleo program over HTTP from official Aleo sources and storing and retrieving function
|
|
204
38
|
* keys from a local memory cache.
|
|
205
39
|
*/
|
|
206
40
|
declare class AleoKeyProvider implements FunctionKeyProvider {
|
|
@@ -257,12 +91,12 @@ declare class AleoKeyProvider implements FunctionKeyProvider {
|
|
|
257
91
|
*
|
|
258
92
|
* @example
|
|
259
93
|
* // Create a new object which implements the KeyProvider interface
|
|
260
|
-
* const networkClient = new AleoNetworkClient("https://api.
|
|
94
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2");
|
|
261
95
|
* const keyProvider = new AleoKeyProvider();
|
|
262
96
|
* const recordProvider = new NetworkRecordProvider(account, networkClient);
|
|
263
97
|
*
|
|
264
98
|
* // Initialize a program manager with the key provider to automatically fetch keys for value transfers
|
|
265
|
-
* const programManager = new ProgramManager("https://api.
|
|
99
|
+
* const programManager = new ProgramManager("https://api.provable.com/v2", keyProvider, recordProvider);
|
|
266
100
|
* programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
|
|
267
101
|
*
|
|
268
102
|
* // Keys can also be fetched manually using the key provider
|
|
@@ -281,12 +115,12 @@ declare class AleoKeyProvider implements FunctionKeyProvider {
|
|
|
281
115
|
*
|
|
282
116
|
* @example
|
|
283
117
|
* // Create a new AleoKeyProvider object
|
|
284
|
-
* const networkClient = new AleoNetworkClient("https://api.
|
|
118
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2");
|
|
285
119
|
* const keyProvider = new AleoKeyProvider();
|
|
286
120
|
* const recordProvider = new NetworkRecordProvider(account, networkClient);
|
|
287
121
|
*
|
|
288
122
|
* // Initialize a program manager with the key provider to automatically fetch keys for value transfers
|
|
289
|
-
* const programManager = new ProgramManager("https://api.
|
|
123
|
+
* const programManager = new ProgramManager("https://api.provable.com/v2", keyProvider, recordProvider);
|
|
290
124
|
* programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
|
|
291
125
|
*
|
|
292
126
|
* // Keys can also be fetched manually
|
|
@@ -316,12 +150,12 @@ declare class AleoKeyProvider implements FunctionKeyProvider {
|
|
|
316
150
|
*
|
|
317
151
|
* @example
|
|
318
152
|
* // Create a new AleoKeyProvider
|
|
319
|
-
* const networkClient = new AleoNetworkClient("https://api.
|
|
153
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2");
|
|
320
154
|
* const keyProvider = new AleoKeyProvider();
|
|
321
155
|
* const recordProvider = new NetworkRecordProvider(account, networkClient);
|
|
322
156
|
*
|
|
323
157
|
* // Initialize a program manager with the key provider to automatically fetch keys for value transfers
|
|
324
|
-
* const programManager = new ProgramManager("https://api.
|
|
158
|
+
* const programManager = new ProgramManager("https://api.provable.com/v2", keyProvider, recordProvider);
|
|
325
159
|
* programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
|
|
326
160
|
*
|
|
327
161
|
* // Keys can also be fetched manually
|
|
@@ -372,4 +206,4 @@ declare class AleoKeyProvider implements FunctionKeyProvider {
|
|
|
372
206
|
getVerifyingKey(verifierUri: string): Promise<VerifyingKey>;
|
|
373
207
|
unBondPublicKeys(): Promise<FunctionKeyPair>;
|
|
374
208
|
}
|
|
375
|
-
export { AleoKeyProvider,
|
|
209
|
+
export { AleoKeyProvider, AleoKeyProviderInitParams, AleoKeyProviderParams };
|
package/dist/{testnet/keys/provider/offline-key-provider.d.ts → mainnet/keys/provider/offline.d.ts}
RENAMED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { FunctionKeyProvider, KeySearchParams } from "./
|
|
1
|
+
import { FunctionKeyProvider, KeySearchParams } from "./interface.js";
|
|
2
2
|
import { CachedKeyPair, FunctionKeyPair } from "../../models/keyPair.js";
|
|
3
3
|
import { ProvingKey, VerifyingKey } from "../../wasm.js";
|
|
4
|
-
import { KeyStore } from "../keystore/
|
|
4
|
+
import { KeyStore } from "../keystore/interface.js";
|
|
5
5
|
/**
|
|
6
6
|
* Search parameters for the offline key provider. This class implements the KeySearchParams interface and includes
|
|
7
7
|
* a convenience method for creating a new instance of this class for each function of the credits.aleo program.
|
|
@@ -34,7 +34,7 @@ declare class OfflineSearchParams implements KeySearchParams {
|
|
|
34
34
|
*/
|
|
35
35
|
static bondValidatorKeyParams(): OfflineSearchParams;
|
|
36
36
|
/**
|
|
37
|
-
* Create a new OfflineSearchParams instance for the claim_unbond_public function of the
|
|
37
|
+
* Create a new OfflineSearchParams instance for the claim_unbond_public function of the credits.aleo program.
|
|
38
38
|
*/
|
|
39
39
|
static claimUnbondPublicKeyParams(): OfflineSearchParams;
|
|
40
40
|
/**
|
|
@@ -134,7 +134,7 @@ declare class OfflineSearchParams implements KeySearchParams {
|
|
|
134
134
|
* const offlineExecuteTx = <Transaction>await this.buildExecutionTransaction("hello_hello.aleo", "hello", 1, false, ["5u32", "5u32"], undefined, offlineSearchParams, undefined, undefined, undefined, undefined, offlineQuery, program);
|
|
135
135
|
*
|
|
136
136
|
* // Broadcast the transaction later on a machine with internet access
|
|
137
|
-
* const networkClient = new AleoNetworkClient("https://api.
|
|
137
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2");
|
|
138
138
|
* const txId = await networkClient.broadcastTransaction(offlineExecuteTx);
|
|
139
139
|
*/
|
|
140
140
|
declare class OfflineKeyProvider implements FunctionKeyProvider {
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fingerprint for a proving and verifying key that includes the checksum of the bytes and size in number of bytes.
|
|
3
|
+
*
|
|
4
|
+
* @property {string} checksum - SHA-256 checksum of the key bytes.
|
|
5
|
+
* @property {number} size - Size of the key in number of bytes.
|
|
6
|
+
*/
|
|
7
|
+
export interface KeyFingerprint {
|
|
8
|
+
checksum: string;
|
|
9
|
+
size: number;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Options for verifying the integrity of proving and verifying keys. An identifier to allow the interface to find key metadata and/or the desired metadata to verify must be passed in.
|
|
13
|
+
*
|
|
14
|
+
* @property {Uint8Array} keyBytes - The raw bytes of the cryptographic key.
|
|
15
|
+
* @property {string} [locator] - Optional identifier or path indicating where the key or KeyFingerprint might be stored.
|
|
16
|
+
* @property {KeyFingerprint} [fingerprint] - Optional metadata containing the key's expected checksum and size for verification purposes.
|
|
17
|
+
*/
|
|
18
|
+
export interface KeyMetadata {
|
|
19
|
+
keyBytes: Uint8Array;
|
|
20
|
+
locator?: string;
|
|
21
|
+
fingerprint?: KeyFingerprint;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Error thrown when there is a mismatch between expected and actual key metadata.
|
|
25
|
+
* This can occur during verification of either the checksum or size of a key.
|
|
26
|
+
*
|
|
27
|
+
* @extends Error
|
|
28
|
+
*/
|
|
29
|
+
export declare class KeyVerificationError extends Error {
|
|
30
|
+
readonly locator: string;
|
|
31
|
+
readonly field: "checksum" | "size";
|
|
32
|
+
readonly expected: string;
|
|
33
|
+
readonly actual: string;
|
|
34
|
+
/**
|
|
35
|
+
* Creates a new KeyVerificationError instance (error.name is "ChecksumMismatchError").
|
|
36
|
+
*
|
|
37
|
+
* @param {string} locator - The key locator where the mismatch occurred.
|
|
38
|
+
* @param {"checksum" | "size"} field - The field that failed verification (either "checksum" or "size").
|
|
39
|
+
* @param {string} expected - The expected value of the field.
|
|
40
|
+
* @param {string} actual - The actual value encountered.
|
|
41
|
+
*/
|
|
42
|
+
constructor(locator: string, field: "checksum" | "size", expected: string, actual: string);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Computes the SHA-256 checksum of a given set of bytes.
|
|
46
|
+
*
|
|
47
|
+
* @param {Uint8Array} bytes - The bytes to compute the checksum of.
|
|
48
|
+
*/
|
|
49
|
+
export declare function sha256Hex(bytes: Uint8Array): Promise<string>;
|
|
50
|
+
/**
|
|
51
|
+
* Verifies key-pair metadata (checksums and sizes) against raw bytes in order to ensure the correct keypair is used.
|
|
52
|
+
* Implementations throw {@link KeyVerificationError} when verification fails.
|
|
53
|
+
*/
|
|
54
|
+
export interface KeyVerifier {
|
|
55
|
+
/**
|
|
56
|
+
* Computes and optionally stores key metadata. If keyFingerprint is provided, verifies against it.
|
|
57
|
+
* @param {KeyMetadata} keyMetadata - Object containing key bytes and optional verification data.
|
|
58
|
+
* @throws {KeyVerificationError} When provided keyFingerprint doesn't match computed values.
|
|
59
|
+
* @returns {Promise<KeyFingerprint>} Computed key metadata.
|
|
60
|
+
*/
|
|
61
|
+
computeKeyMetadata(keyMetadata: KeyMetadata): Promise<KeyFingerprint>;
|
|
62
|
+
/**
|
|
63
|
+
* Verifies prover bytes against key metadata (size + checksum).
|
|
64
|
+
*
|
|
65
|
+
* @param {KeyMetadata} keyMetadata - Object containing the key bytes, an optional locator and optional metadata for verification.
|
|
66
|
+
* @throws {KeyVerificationError} when size or checksum does not match.
|
|
67
|
+
* @returns {Promise<void>} Promise that resolves when verification succeeds.
|
|
68
|
+
*/
|
|
69
|
+
verifyKeyBytes(keyMetadata: KeyMetadata): Promise<void>;
|
|
70
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { KeyVerifier, KeyFingerprint, KeyMetadata } from "./interface";
|
|
2
|
+
/**
|
|
3
|
+
* In-memory implementation of KeyVerifier that stores and verifies key fingerprints.
|
|
4
|
+
* Provides functionality to compute and verify cryptographic checksums of keys, storing them
|
|
5
|
+
* in memory for subsequent verification. This implementation is primarily used for testing
|
|
6
|
+
* and development purposes where persistence is not required.
|
|
7
|
+
*
|
|
8
|
+
* Key features:
|
|
9
|
+
* - Computes SHA-256 checksums and sizes for key bytes.
|
|
10
|
+
* - Stores key fingerprints in memory using string locators.
|
|
11
|
+
* - Verifies key bytes against stored or provided fingerprints.
|
|
12
|
+
*
|
|
13
|
+
* @implements {KeyVerifier}
|
|
14
|
+
*/
|
|
15
|
+
export declare class MemKeyVerifier implements KeyVerifier {
|
|
16
|
+
private keyStore;
|
|
17
|
+
/**
|
|
18
|
+
* Computes and optionally stores key metadata. If a keyFingerprint is provided, this function will verify the computed checksum against it before storing it.
|
|
19
|
+
*
|
|
20
|
+
* @param {KeyMetadata} keyMetadata - Object containing key bytes and optional verification data.
|
|
21
|
+
* @throws {KeyVerificationError} When provided keyFingerprint doesn't match computed values.
|
|
22
|
+
* @returns {Promise<KeyFingerprint>} Computed key metadata.
|
|
23
|
+
*/
|
|
24
|
+
computeKeyMetadata(keyMetadata: KeyMetadata): Promise<KeyFingerprint>;
|
|
25
|
+
/**
|
|
26
|
+
* Verifies key bytes against stored or provided metadata. Follows a priority verification scheme:
|
|
27
|
+
* 1. If KeyFingerprint is provided in the metadata, this method verifies against that first.
|
|
28
|
+
* 2. If a locator is provided, attempts to verify against stored fingerprint.
|
|
29
|
+
* 3. If neither is available, throws an error.
|
|
30
|
+
*
|
|
31
|
+
* @param {KeyMetadata} keyMetadata - Object containing the key bytes and optional verification metadata.
|
|
32
|
+
* @throws {Error} When neither fingerprint nor valid locator is provided for verification.
|
|
33
|
+
* @throws {KeyVerificationError} When size or checksum verification fails.
|
|
34
|
+
* @returns {Promise<void>} Promise that resolves when verification succeeds.
|
|
35
|
+
*/
|
|
36
|
+
verifyKeyBytes(keyMetadata: KeyMetadata): Promise<void>;
|
|
37
|
+
}
|
|
@@ -1,5 +1,51 @@
|
|
|
1
|
-
import { TransactionJSON } from "./transaction/transactionJSON";
|
|
1
|
+
import { TransactionJSON } from "./transaction/transactionJSON.js";
|
|
2
|
+
/** HTTP status and optional message from snarkOS broadcast (Accepted/Rejected variants). */
|
|
3
|
+
export interface BroadcastResponse {
|
|
4
|
+
status_code: bigint | number;
|
|
5
|
+
message?: string;
|
|
6
|
+
}
|
|
7
|
+
/** Result of the optional broadcast step. Discriminated by `status`. */
|
|
8
|
+
export type BroadcastResult = {
|
|
9
|
+
status: "Accepted";
|
|
10
|
+
status_code: bigint | number;
|
|
11
|
+
message?: string;
|
|
12
|
+
} | {
|
|
13
|
+
status: "Rejected";
|
|
14
|
+
status_code: bigint | number;
|
|
15
|
+
message?: string;
|
|
16
|
+
} | {
|
|
17
|
+
status: "Failed";
|
|
18
|
+
message: string;
|
|
19
|
+
} | {
|
|
20
|
+
status: "Skipped";
|
|
21
|
+
};
|
|
22
|
+
/** Success response body for POST /prove (HTTP 200). */
|
|
2
23
|
export interface ProvingResponse {
|
|
3
24
|
transaction: TransactionJSON;
|
|
4
|
-
|
|
25
|
+
broadcast_result: BroadcastResult;
|
|
26
|
+
}
|
|
27
|
+
/** Error response body for POST /prove (HTTP 400, 500, 503). Same shape for all error cases. */
|
|
28
|
+
export interface ProveApiErrorBody {
|
|
29
|
+
message: string;
|
|
30
|
+
}
|
|
31
|
+
/** Error thrown on prove API failure; `status` is set for retry logic (e.g. retryWithBackoff checks error.status >= 500). */
|
|
32
|
+
export interface ProvingRequestError extends Error {
|
|
33
|
+
status?: number;
|
|
34
|
+
}
|
|
35
|
+
/** Success variant of a proving request result. */
|
|
36
|
+
export interface ProvingSuccess {
|
|
37
|
+
ok: true;
|
|
38
|
+
data: ProvingResponse;
|
|
39
|
+
}
|
|
40
|
+
/** Failure variant of a proving request result (HTTP 400, 500, 503). */
|
|
41
|
+
export interface ProvingFailure {
|
|
42
|
+
ok: false;
|
|
43
|
+
status: number;
|
|
44
|
+
error: ProveApiErrorBody;
|
|
5
45
|
}
|
|
46
|
+
/** Result of a proving request. Type used to give callers the ability to self-handle errors. */
|
|
47
|
+
export type ProvingResult = ProvingSuccess | ProvingFailure;
|
|
48
|
+
/** Type guard: value is a ProvingResponse. */
|
|
49
|
+
export declare function isProvingResponse(value: unknown): value is ProvingResponse;
|
|
50
|
+
/** Type guard: value is a ProveApiErrorBody. */
|
|
51
|
+
export declare function isProveApiErrorBody(value: unknown): value is ProveApiErrorBody;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { RecordScannerFailure } from "./error.js";
|
|
2
|
+
import type { EncryptedRecord } from "../record-provider/encryptedRecord.js";
|
|
3
|
+
export interface EncryptedRecordsSuccess {
|
|
4
|
+
ok: true;
|
|
5
|
+
data: EncryptedRecord[];
|
|
6
|
+
}
|
|
7
|
+
export type EncryptedRecordsResult = EncryptedRecordsSuccess | RecordScannerFailure;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { OwnedFilter } from "./ownedFilter";
|
|
2
|
+
/**
|
|
3
|
+
* Error thrown when a record scanner request fails (e.g. /register, /register/encrypted).
|
|
4
|
+
* Includes HTTP status so callers can handle 422 vs 500 etc.
|
|
5
|
+
*/
|
|
6
|
+
export declare class RecordScannerRequestError extends Error {
|
|
7
|
+
readonly status: number;
|
|
8
|
+
constructor(message: string, status: number);
|
|
9
|
+
}
|
|
10
|
+
/** Error thrown when findCreditsRecord or findCreditsRecords is called but decryption is not enabled on the record scanner. */
|
|
11
|
+
export declare class DecryptionNotEnabledError extends Error {
|
|
12
|
+
readonly filter?: OwnedFilter;
|
|
13
|
+
constructor(message: string, filter?: OwnedFilter);
|
|
14
|
+
}
|
|
15
|
+
/** Error thrown when findCreditsRecord or findCreditsRecords is called but no view key for the UUID is stored in viewKeys or the account. */
|
|
16
|
+
export declare class ViewKeyNotStoredError extends Error {
|
|
17
|
+
readonly uuid?: string;
|
|
18
|
+
readonly filter?: OwnedFilter;
|
|
19
|
+
constructor(message: string, uuid?: string, filter?: OwnedFilter);
|
|
20
|
+
}
|
|
21
|
+
/** Error thrown when no record matches the supplied search filter (e.g. findCreditsRecord / findCreditsRecords). */
|
|
22
|
+
export declare class RecordNotFoundError extends Error {
|
|
23
|
+
readonly filter?: OwnedFilter;
|
|
24
|
+
constructor(message: string, filter?: OwnedFilter);
|
|
25
|
+
}
|
|
26
|
+
/** Error thrown when no UUID is configured, the UUID is invalid, or a record scanner request fails due to an invalid UUID/response. */
|
|
27
|
+
export declare class UUIDError extends Error {
|
|
28
|
+
readonly uuid?: string;
|
|
29
|
+
readonly filter?: OwnedFilter;
|
|
30
|
+
constructor(message: string, uuid?: string, filter?: OwnedFilter);
|
|
31
|
+
}
|
|
32
|
+
/** General error payload returned from record-scanner endpoints on failure. */
|
|
33
|
+
export interface RecordScannerErrorBody {
|
|
34
|
+
/** Raw error text returned by the service. */
|
|
35
|
+
message: string;
|
|
36
|
+
/** HTTP status code from the response. */
|
|
37
|
+
status: number;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Failure variant shared by record-scanner result types.
|
|
41
|
+
* Use with a success interface to form a discriminated union (e.g. Success | RecordScannerFailure).
|
|
42
|
+
*/
|
|
43
|
+
export interface RecordScannerFailure {
|
|
44
|
+
ok: false;
|
|
45
|
+
status: number;
|
|
46
|
+
error: RecordScannerErrorBody;
|
|
47
|
+
}
|
|
@@ -8,7 +8,6 @@ import { OwnedRecordsResponseFilter } from "./ownedRecordsResponseFilter";
|
|
|
8
8
|
* const ownedFilter: OwnedFilter = {
|
|
9
9
|
* unspent: true,
|
|
10
10
|
* nonces: ["3077450429259593211617823051143573281856129402760267155982965992208217472983group"],
|
|
11
|
-
* decrypt: true,
|
|
12
11
|
* filter: {
|
|
13
12
|
* program: "credits.aleo",
|
|
14
13
|
* record: "credits",
|
|
@@ -16,7 +15,6 @@ import { OwnedRecordsResponseFilter } from "./ownedRecordsResponseFilter";
|
|
|
16
15
|
* }
|
|
17
16
|
*/
|
|
18
17
|
export interface OwnedFilter extends RecordSearchParams {
|
|
19
|
-
decrypt?: boolean;
|
|
20
18
|
filter?: RecordsFilter;
|
|
21
19
|
responseFilter?: OwnedRecordsResponseFilter;
|
|
22
20
|
unspent?: boolean;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { RecordScannerFailure } from "./error.js";
|
|
2
|
+
import type { OwnedRecord } from "../record-provider/ownedRecord.js";
|
|
3
|
+
/**
|
|
4
|
+
* Success variant of ownedRecords() result.
|
|
5
|
+
*
|
|
6
|
+
* @property ok - Whether the request was successful, always true for this interface variant.
|
|
7
|
+
* @property data - List of owned records corresponding to the filter used.
|
|
8
|
+
*/
|
|
9
|
+
export interface OwnedRecordsSuccess {
|
|
10
|
+
ok: true;
|
|
11
|
+
data: OwnedRecord[];
|
|
12
|
+
}
|
|
13
|
+
export type OwnedRecordsResult = OwnedRecordsSuccess | RecordScannerFailure;
|
|
@@ -4,12 +4,10 @@
|
|
|
4
4
|
* @example
|
|
5
5
|
* const registrationResponse: RegistrationResponse = {
|
|
6
6
|
* uuid: "5291249998620209321712738612705518874926462927543783711572375085855029172391field",
|
|
7
|
-
* job_id: "3019177021147406178755252788128212930359855601860174268911518336835545087409field",
|
|
8
7
|
* status: "pending",
|
|
9
8
|
* }
|
|
10
9
|
*/
|
|
11
10
|
export interface RegistrationResponse {
|
|
12
11
|
uuid: string;
|
|
13
|
-
job_id?: string;
|
|
14
12
|
status?: string;
|
|
15
13
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { RecordScannerFailure } from "./error.js";
|
|
2
|
+
import type { RegistrationResponse } from "./registrationResponse.js";
|
|
3
|
+
/** Success variant of registration result. */
|
|
4
|
+
export interface RegisterSuccess {
|
|
5
|
+
ok: true;
|
|
6
|
+
data: RegistrationResponse;
|
|
7
|
+
}
|
|
8
|
+
/** Result of register() and registerEncrypted(); never throws on HTTP error. */
|
|
9
|
+
export type RegisterResult = RegisterSuccess | RecordScannerFailure;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { RecordScannerFailure } from "./error.js";
|
|
2
|
+
/**
|
|
3
|
+
* Response from the record scanning service's revoke endpoint on success.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* const revokeResponse: RevokeResponse = { status: "OK" };
|
|
7
|
+
*/
|
|
8
|
+
export interface RevokeResponse {
|
|
9
|
+
status: string;
|
|
10
|
+
}
|
|
11
|
+
/** Success variant of revoke result. */
|
|
12
|
+
export interface RevokeSuccess {
|
|
13
|
+
ok: true;
|
|
14
|
+
data: RevokeResponse;
|
|
15
|
+
}
|
|
16
|
+
/** Result of revoke(); never throws on HTTP error. */
|
|
17
|
+
export type RevokeResult = RevokeSuccess | RecordScannerFailure;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { RecordScannerFailure } from "./error.js";
|
|
2
|
+
/**
|
|
3
|
+
* Success variant of serialNumbers() result.
|
|
4
|
+
*
|
|
5
|
+
* @property ok - Whether the request was successful, always true for this interface.
|
|
6
|
+
* @property data - A map of serial numbers to whether they are owned by the account.
|
|
7
|
+
*/
|
|
8
|
+
export interface SerialNumbersSuccess {
|
|
9
|
+
ok: true;
|
|
10
|
+
data: Record<string, boolean>;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Success or failure variant of serialNumbers() result.
|
|
14
|
+
*/
|
|
15
|
+
export type SerialNumbersResult = SerialNumbersSuccess | RecordScannerFailure;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { RecordScannerFailure } from "./error.js";
|
|
2
|
+
import type { StatusResponse } from "./statusResponse.js";
|
|
3
|
+
/**
|
|
4
|
+
* Success variant of status() result.
|
|
5
|
+
*
|
|
6
|
+
* @property ok - Whether the request was successful, always true for this interface variant.
|
|
7
|
+
* @property data - StatusResponse returned by the server.
|
|
8
|
+
*/
|
|
9
|
+
export interface StatusSuccess {
|
|
10
|
+
ok: true;
|
|
11
|
+
data: StatusResponse;
|
|
12
|
+
}
|
|
13
|
+
export type StatusResult = StatusSuccess | RecordScannerFailure;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { RecordScannerFailure } from "./error.js";
|
|
2
|
+
/**
|
|
3
|
+
* Success variant of tags() result.
|
|
4
|
+
*
|
|
5
|
+
* @property ok - Whether the request was successful, always true for this interface variant.
|
|
6
|
+
* @property data - A map of tags to whether they are owned by the account.
|
|
7
|
+
*/
|
|
8
|
+
export interface TagsSuccess {
|
|
9
|
+
ok: true;
|
|
10
|
+
data: Record<string, boolean>;
|
|
11
|
+
}
|
|
12
|
+
export type TagsResult = TagsSuccess | RecordScannerFailure;
|