@provablehq/sdk 0.9.16 → 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.
Files changed (39) hide show
  1. package/dist/mainnet/browser.d.ts +10 -3
  2. package/dist/mainnet/browser.js +251 -32
  3. package/dist/mainnet/browser.js.map +1 -1
  4. package/dist/mainnet/keys/keystore/error.d.ts +23 -0
  5. package/dist/mainnet/keys/keystore/file.d.ts +217 -0
  6. package/dist/mainnet/keys/keystore/interface.d.ts +85 -0
  7. package/dist/mainnet/keys/provider/interface.d.ts +170 -0
  8. package/dist/mainnet/{function-key-provider.d.ts → keys/provider/memory.d.ts} +9 -167
  9. package/dist/mainnet/{offline-key-provider.d.ts → keys/provider/offline.d.ts} +6 -3
  10. package/dist/mainnet/keys/verifier/interface.d.ts +70 -0
  11. package/dist/mainnet/keys/verifier/memory.d.ts +37 -0
  12. package/dist/mainnet/models/keyPair.d.ts +4 -0
  13. package/dist/mainnet/models/record-scanner/error.d.ts +1 -1
  14. package/dist/mainnet/models/record-scanner/revokeResult.d.ts +17 -0
  15. package/dist/mainnet/node.d.ts +1 -0
  16. package/dist/mainnet/node.js +399 -2
  17. package/dist/mainnet/node.js.map +1 -1
  18. package/dist/mainnet/program-manager.d.ts +2 -1
  19. package/dist/mainnet/record-scanner.d.ts +16 -0
  20. package/dist/testnet/browser.d.ts +10 -3
  21. package/dist/testnet/browser.js +251 -32
  22. package/dist/testnet/browser.js.map +1 -1
  23. package/dist/testnet/keys/keystore/error.d.ts +23 -0
  24. package/dist/testnet/keys/keystore/file.d.ts +217 -0
  25. package/dist/testnet/keys/keystore/interface.d.ts +85 -0
  26. package/dist/testnet/keys/provider/interface.d.ts +170 -0
  27. package/dist/testnet/{function-key-provider.d.ts → keys/provider/memory.d.ts} +9 -167
  28. package/dist/testnet/{offline-key-provider.d.ts → keys/provider/offline.d.ts} +6 -3
  29. package/dist/testnet/keys/verifier/interface.d.ts +70 -0
  30. package/dist/testnet/keys/verifier/memory.d.ts +37 -0
  31. package/dist/testnet/models/keyPair.d.ts +4 -0
  32. package/dist/testnet/models/record-scanner/error.d.ts +1 -1
  33. package/dist/testnet/models/record-scanner/revokeResult.d.ts +17 -0
  34. package/dist/testnet/node.d.ts +1 -0
  35. package/dist/testnet/node.js +399 -2
  36. package/dist/testnet/node.js.map +1 -1
  37. package/dist/testnet/program-manager.d.ts +2 -1
  38. package/dist/testnet/record-scanner.d.ts +16 -0
  39. package/package.json +3 -3
@@ -1,19 +1,13 @@
1
- import { Key } from "./constants.js";
2
- import { ProvingKey, VerifyingKey } from "./wasm.js";
3
- type FunctionKeyPair = [ProvingKey, VerifyingKey];
4
- type CachedKeyPair = [Uint8Array, Uint8Array];
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,161 +33,8 @@ declare class AleoKeyProviderParams implements KeySearchParams {
39
33
  });
40
34
  }
41
35
  /**
42
- * KeyProvider interface. Enables the retrieval of public proving and verifying keys for Aleo Programs.
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.provable.com/v2");
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.provable.com/v2", 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
- * Get fee_private function keys from the credits.aleo program
139
- *
140
- * @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the join function
141
- */
142
- feePrivateKeys(): Promise<FunctionKeyPair>;
143
- /**
144
- * Get fee_public function keys from the credits.aleo program
145
- *
146
- * @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the join function
147
- */
148
- feePublicKeys(): Promise<FunctionKeyPair>;
149
- /**
150
- * Get keys for the inclusion proof.
151
- *
152
- * @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the join function
153
- */
154
- inclusionKeys(): Promise<FunctionKeyPair>;
155
- /**
156
- * Get join function keys from the credits.aleo program
157
- *
158
- * @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the join function
159
- */
160
- joinKeys(): Promise<FunctionKeyPair>;
161
- /**
162
- * Get split function keys from the credits.aleo program
163
- *
164
- * @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the join function
165
- */
166
- splitKeys(): Promise<FunctionKeyPair>;
167
- /**
168
- * Get keys for a variant of the transfer function from the credits.aleo program
169
- *
170
- * @param {string} visibility Visibility of the transfer function (private, public, privateToPublic, publicToPrivate)
171
- * @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the specified transfer function
172
- *
173
- * @example
174
- * // Create a new object which implements the KeyProvider interface
175
- * const networkClient = new AleoNetworkClient("https://api.provable.com/v2");
176
- * const keyProvider = new AleoKeyProvider();
177
- * const recordProvider = new NetworkRecordProvider(account, networkClient);
178
- *
179
- * // Initialize a program manager with the key provider to automatically fetch keys for value transfers
180
- * const programManager = new ProgramManager("https://api.provable.com/v2", keyProvider, recordProvider);
181
- * programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
182
- *
183
- * // Keys can also be fetched manually
184
- * const [transferPublicProvingKey, transferPublicVerifyingKey] = await keyProvider.transferKeys("public");
185
- */
186
- transferKeys(visibility: string): Promise<FunctionKeyPair>;
187
- /**
188
- * Get unbond_public function keys from the credits.aleo program
189
- *
190
- * @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the join function
191
- */
192
- unBondPublicKeys(): Promise<FunctionKeyPair>;
193
- }
194
- /**
195
- * AleoKeyProvider class. Implements the KeyProvider interface. Enables the retrieval of Aleo program proving and
196
- * 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
197
38
  * keys from a local memory cache.
198
39
  */
199
40
  declare class AleoKeyProvider implements FunctionKeyProvider {
@@ -202,6 +43,7 @@ declare class AleoKeyProvider implements FunctionKeyProvider {
202
43
  keyUris: string;
203
44
  fetchBytes(url?: string): Promise<Uint8Array>;
204
45
  constructor();
46
+ keyStore(): Promise<KeyStore | undefined>;
205
47
  /**
206
48
  * Use local memory to store keys
207
49
  *
@@ -364,4 +206,4 @@ declare class AleoKeyProvider implements FunctionKeyProvider {
364
206
  getVerifyingKey(verifierUri: string): Promise<VerifyingKey>;
365
207
  unBondPublicKeys(): Promise<FunctionKeyPair>;
366
208
  }
367
- export { AleoKeyProvider, AleoKeyProviderParams, AleoKeyProviderInitParams, CachedKeyPair, FunctionKeyPair, FunctionKeyProvider, KeySearchParams };
209
+ export { AleoKeyProvider, AleoKeyProviderInitParams, AleoKeyProviderParams };
@@ -1,5 +1,7 @@
1
- import { CachedKeyPair, FunctionKeyPair, FunctionKeyProvider, KeySearchParams } from "./function-key-provider.js";
2
- import { ProvingKey, VerifyingKey } from "./wasm.js";
1
+ import { FunctionKeyProvider, KeySearchParams } from "./interface.js";
2
+ import { CachedKeyPair, FunctionKeyPair } from "../../models/keyPair.js";
3
+ import { ProvingKey, VerifyingKey } from "../../wasm.js";
4
+ import { KeyStore } from "../keystore/interface.js";
3
5
  /**
4
6
  * Search parameters for the offline key provider. This class implements the KeySearchParams interface and includes
5
7
  * a convenience method for creating a new instance of this class for each function of the credits.aleo program.
@@ -32,7 +34,7 @@ declare class OfflineSearchParams implements KeySearchParams {
32
34
  */
33
35
  static bondValidatorKeyParams(): OfflineSearchParams;
34
36
  /**
35
- * 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.
36
38
  */
37
39
  static claimUnbondPublicKeyParams(): OfflineSearchParams;
38
40
  /**
@@ -138,6 +140,7 @@ declare class OfflineSearchParams implements KeySearchParams {
138
140
  declare class OfflineKeyProvider implements FunctionKeyProvider {
139
141
  cache: Map<string, CachedKeyPair>;
140
142
  constructor();
143
+ keyStore(): Promise<KeyStore | undefined>;
141
144
  /**
142
145
  * Get bond_public function keys from the credits.aleo program. The keys must be cached prior to calling this
143
146
  * method for it to work.
@@ -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
+ }
@@ -0,0 +1,4 @@
1
+ import { ProvingKey, VerifyingKey } from "../wasm.js";
2
+ type FunctionKeyPair = [ProvingKey, VerifyingKey];
3
+ type CachedKeyPair = [Uint8Array, Uint8Array];
4
+ export { CachedKeyPair, FunctionKeyPair };
@@ -23,7 +23,7 @@ export declare class RecordNotFoundError extends Error {
23
23
  readonly filter?: OwnedFilter;
24
24
  constructor(message: string, filter?: OwnedFilter);
25
25
  }
26
- /** Error thrown when a record scanner request fails due to an invalid response. */
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
27
  export declare class UUIDError extends Error {
28
28
  readonly uuid?: string;
29
29
  readonly filter?: OwnedFilter;
@@ -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;
@@ -1,2 +1,3 @@
1
1
  import "./node-polyfill.js";
2
+ export { LocalFileKeyStore } from "./keys/keystore/file.js";
2
3
  export * from "./browser.js";