@provablehq/sdk 0.9.16 → 0.9.18
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 +43 -3
- package/dist/mainnet/browser.d.ts +11 -4
- package/dist/mainnet/browser.js +460 -109
- 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 +217 -0
- package/dist/mainnet/keys/keystore/interface.d.ts +85 -0
- package/dist/mainnet/keys/provider/interface.d.ts +170 -0
- package/dist/mainnet/{function-key-provider.d.ts → keys/provider/memory.d.ts} +9 -167
- package/dist/mainnet/{offline-key-provider.d.ts → keys/provider/offline.d.ts} +6 -3
- package/dist/mainnet/keys/verifier/interface.d.ts +70 -0
- package/dist/mainnet/keys/verifier/memory.d.ts +37 -0
- package/dist/mainnet/models/keyHolder.d.ts +2 -0
- package/dist/mainnet/models/keyPair.d.ts +4 -0
- package/dist/mainnet/models/record-scanner/error.d.ts +1 -1
- package/dist/mainnet/models/record-scanner/revokeResult.d.ts +17 -0
- package/dist/mainnet/node.d.ts +1 -0
- package/dist/mainnet/node.js +399 -2
- package/dist/mainnet/node.js.map +1 -1
- package/dist/mainnet/program-manager.d.ts +4 -3
- package/dist/mainnet/record-scanner.d.ts +16 -0
- package/dist/mainnet/security.d.ts +24 -0
- package/dist/testnet/account.d.ts +43 -3
- package/dist/testnet/browser.d.ts +11 -4
- package/dist/testnet/browser.js +460 -109
- 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 +217 -0
- package/dist/testnet/keys/keystore/interface.d.ts +85 -0
- package/dist/testnet/keys/provider/interface.d.ts +170 -0
- package/dist/testnet/{function-key-provider.d.ts → keys/provider/memory.d.ts} +9 -167
- package/dist/testnet/{offline-key-provider.d.ts → keys/provider/offline.d.ts} +6 -3
- package/dist/testnet/keys/verifier/interface.d.ts +70 -0
- package/dist/testnet/keys/verifier/memory.d.ts +37 -0
- package/dist/testnet/models/keyHolder.d.ts +2 -0
- package/dist/testnet/models/keyPair.d.ts +4 -0
- package/dist/testnet/models/record-scanner/error.d.ts +1 -1
- package/dist/testnet/models/record-scanner/revokeResult.d.ts +17 -0
- package/dist/testnet/node.d.ts +1 -0
- package/dist/testnet/node.js +399 -2
- package/dist/testnet/node.js.map +1 -1
- package/dist/testnet/program-manager.d.ts +4 -3
- package/dist/testnet/record-scanner.d.ts +16 -0
- package/dist/testnet/security.d.ts +24 -0
- package/package.json +3 -3
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reason code for invalid locator validation failures.
|
|
3
|
+
* - `"reserved_name"`: Locator is empty or the reserved name `"."` or `".."`.
|
|
4
|
+
* - `"path_traversal"`: Locator contains `..`.
|
|
5
|
+
* - `"path_separator"`: Locator contains a path separator (`/`, `\`) or null byte.
|
|
6
|
+
*/
|
|
7
|
+
export type InvalidLocatorReason = "reserved_name" | "path_traversal" | "path_separator";
|
|
8
|
+
/**
|
|
9
|
+
* Error thrown when a key locator is invalid for filesystem use.
|
|
10
|
+
* Used to prevent path traversal and other filesystem injection when deriving paths from locators.
|
|
11
|
+
*
|
|
12
|
+
* @extends Error
|
|
13
|
+
*/
|
|
14
|
+
export declare class InvalidLocatorError extends Error {
|
|
15
|
+
readonly locator: string;
|
|
16
|
+
readonly reason: InvalidLocatorReason;
|
|
17
|
+
/**
|
|
18
|
+
* @param message - Human-readable description of the validation failure.
|
|
19
|
+
* @param locator - The invalid locator string that failed validation.
|
|
20
|
+
* @param reason - Machine-readable reason code for the failure.
|
|
21
|
+
*/
|
|
22
|
+
constructor(message: string, locator: string, reason: InvalidLocatorReason);
|
|
23
|
+
}
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import { FunctionKeyPair } from "../../models/keyPair.js";
|
|
2
|
+
import { KeyFingerprint } from "../verifier/interface.js";
|
|
3
|
+
import { KeyLocator, KeyStore } from "./interface.js";
|
|
4
|
+
import { ProvingKey, VerifyingKey } from "../../wasm.js";
|
|
5
|
+
export declare class LocalFileKeyStore implements KeyStore {
|
|
6
|
+
private directory;
|
|
7
|
+
private readonly keyVerifier;
|
|
8
|
+
/**
|
|
9
|
+
* Creates a new directory at the given path or CURRENTDIR/.aleo if none is provided to store keys.
|
|
10
|
+
* If a custom directory is passed and its last path segment is not ".aleo", ".aleo" is appended
|
|
11
|
+
* so keys are stored under that subdirectory (e.g. /home/project → /home/project/.aleo).
|
|
12
|
+
*
|
|
13
|
+
* @param {string} [directory] - Optional custom directory path for key storage. Defaults to ".aleo" in current working directory.
|
|
14
|
+
* @throws {Error} If directory creation fails.
|
|
15
|
+
*/
|
|
16
|
+
constructor(directory?: string);
|
|
17
|
+
/**
|
|
18
|
+
* Validates that a locator is a safe filesystem identifier.
|
|
19
|
+
*
|
|
20
|
+
* @private
|
|
21
|
+
* @param {string} locator - Unique identifier used to derive a metadata file path.
|
|
22
|
+
* @throws {InvalidLocatorError} If the locator could cause path traversal.
|
|
23
|
+
*/
|
|
24
|
+
private validateLocator;
|
|
25
|
+
/**
|
|
26
|
+
* Generates the path for a key metadata file based on the locator.
|
|
27
|
+
*
|
|
28
|
+
* @private
|
|
29
|
+
* @param {string} locator - Unique identifier for the key.
|
|
30
|
+
* @returns {string} Full filesystem path to the metadata file.
|
|
31
|
+
*/
|
|
32
|
+
private metadataPath;
|
|
33
|
+
/**
|
|
34
|
+
* Reads and parses the key fingerprint metadata from storage.
|
|
35
|
+
*
|
|
36
|
+
* @private
|
|
37
|
+
* @param {string} locator - Unique identifier for the key.
|
|
38
|
+
* @returns {Promise<KeyFingerprint | null>} The key fingerprint if found, null if file doesn't exist.
|
|
39
|
+
* @throws {Error} If file read fails for any reason other than not found.
|
|
40
|
+
*/
|
|
41
|
+
private readKeyMetadata;
|
|
42
|
+
/**
|
|
43
|
+
* Writes key fingerprint metadata to storage.
|
|
44
|
+
*
|
|
45
|
+
* @private
|
|
46
|
+
* @param {string} locator - Unique identifier for the key.
|
|
47
|
+
* @param {KeyFingerprint} metadata - Key fingerprint metadata to store.
|
|
48
|
+
* @returns {Promise<void>}
|
|
49
|
+
* @throws {Error} If directory creation or file write fails.
|
|
50
|
+
*/
|
|
51
|
+
private writeKeyMetadata;
|
|
52
|
+
private readFileOptional;
|
|
53
|
+
/**
|
|
54
|
+
* Atomically writes data to a file, ensuring the parent directories exist.
|
|
55
|
+
*
|
|
56
|
+
* @private
|
|
57
|
+
* @param {string} filepath - Full path to the file to write
|
|
58
|
+
* @param {Uint8Array} data - Binary data to write to the file
|
|
59
|
+
* @returns {Promise<void>} Resolves when write is complete
|
|
60
|
+
* @throws {Error} If directory creation or file write fails
|
|
61
|
+
*/
|
|
62
|
+
private writeFileAtomic;
|
|
63
|
+
/**
|
|
64
|
+
* Recursively removes all files and subdirectories under the given directory, then removes the directory itself.
|
|
65
|
+
* Uses fs.rm with recursive: true and force: true so that symbolic links are removed without following them,
|
|
66
|
+
* avoiding deletion of content outside the keystore.
|
|
67
|
+
*
|
|
68
|
+
* @private
|
|
69
|
+
* @param {string} dir - Directory path to clear
|
|
70
|
+
* @returns {Promise<void>} Resolves when clearing is complete
|
|
71
|
+
* @throws {Error} If directory removal fails for reasons other than non-existence
|
|
72
|
+
*/
|
|
73
|
+
private clearDirectory;
|
|
74
|
+
/**
|
|
75
|
+
* Retrieves the key bytes from storage and optionally verifies them against a fingerprint.
|
|
76
|
+
*
|
|
77
|
+
* @param {KeyLocator} locator - Object containing a locator string for the key + optional fingerprint for verification.
|
|
78
|
+
* @returns {Promise<Uint8Array | null>} The key bytes if found and verified (if fingerprint provided), null if not found.
|
|
79
|
+
* @throws {KeyVerificationError} If fingerprint verification fails.
|
|
80
|
+
* @example
|
|
81
|
+
* const keyBytes = await getKeyBytes({
|
|
82
|
+
* locator: 'transfer_private.prover.421e5a5',
|
|
83
|
+
* fingerprint: { checksum: '421e5a52f01a1eeb068bbf56d15e19477ff7290e4b988d1013e15563f2b77801', size: 116746954 }
|
|
84
|
+
* });
|
|
85
|
+
* if (keyBytes) {
|
|
86
|
+
* // Use the verified key bytes
|
|
87
|
+
* }
|
|
88
|
+
*/
|
|
89
|
+
getKeyBytes(locator: KeyLocator): Promise<Uint8Array | null>;
|
|
90
|
+
/**
|
|
91
|
+
* Retrieves and verifies a proving key from storage.
|
|
92
|
+
*
|
|
93
|
+
* @param {KeyLocator} locator - Object containing the proving key location and optional fingerprint.
|
|
94
|
+
* @returns {Promise<ProvingKey | null>} The proving key if found and verified, null if not found.
|
|
95
|
+
* @throws {KeyVerificationError} If fingerprint verification fails.
|
|
96
|
+
* @throws {Error} If key bytes cannot be parsed into a valid ProvingKey.
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* try {
|
|
100
|
+
* const key = await getProvingKey({
|
|
101
|
+
* locator: 'transfer_private.prover.421e5a5'
|
|
102
|
+
* });
|
|
103
|
+
* if (key) {
|
|
104
|
+
* // Use the verified proving key
|
|
105
|
+
* }
|
|
106
|
+
* } catch (err) {
|
|
107
|
+
* if (err instanceof KeyVerificationError) {
|
|
108
|
+
* // Handle verification failure.
|
|
109
|
+
* } else {
|
|
110
|
+
* // Handle key parsing error.
|
|
111
|
+
* }
|
|
112
|
+
* }
|
|
113
|
+
*/
|
|
114
|
+
getProvingKey(locator: KeyLocator): Promise<ProvingKey | null>;
|
|
115
|
+
/**
|
|
116
|
+
* Retrieves and verifies a verifying key from storage.
|
|
117
|
+
*
|
|
118
|
+
* @param {KeyLocator} locator - Object containing the verifying key location and optional fingerprint.
|
|
119
|
+
* @returns {Promise<VerifyingKey | null>} The verifying key if found and verified, null if not found.
|
|
120
|
+
* @throws {KeyVerificationError} If fingerprint verification fails.
|
|
121
|
+
* @throws {Error} If key bytes cannot be parsed into a valid VerifyingKey.
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* try {
|
|
125
|
+
* const key = await getVerifyingKey({
|
|
126
|
+
* locator: 'transfer_private.verifier.4ac2f71'
|
|
127
|
+
* });
|
|
128
|
+
* if (key) {
|
|
129
|
+
* // Use the verified verifying key
|
|
130
|
+
* }
|
|
131
|
+
* } catch (err) {
|
|
132
|
+
* if (err instanceof KeyVerificationError) {
|
|
133
|
+
* // Handle verification failure.
|
|
134
|
+
* } else {
|
|
135
|
+
* // Handle key parsing error.
|
|
136
|
+
* }
|
|
137
|
+
* }
|
|
138
|
+
*/
|
|
139
|
+
getVerifyingKey(locator: KeyLocator): Promise<VerifyingKey | null>;
|
|
140
|
+
/**
|
|
141
|
+
* Stores proving and verifying keys in key storage.
|
|
142
|
+
*
|
|
143
|
+
* @param {KeyLocator} proverLocator The unique locator for the desired proving key.
|
|
144
|
+
* @param {KeyLocator} verifierLocator The unique locator for the desired verifying key.
|
|
145
|
+
* @param {FunctionKeyPair} keys The proving and verifying keys.
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* const keys = await generateKeys();
|
|
149
|
+
* await setKeys(
|
|
150
|
+
* { locator: 'transfer_private.prover' },
|
|
151
|
+
* { locator: 'transfer_private.verifier' },
|
|
152
|
+
* keys
|
|
153
|
+
* );
|
|
154
|
+
*/
|
|
155
|
+
setKeys(proverLocator: KeyLocator, verifierLocator: KeyLocator, keys: FunctionKeyPair): Promise<void>;
|
|
156
|
+
/**
|
|
157
|
+
* Store a raw proving or verifying key in storage along with its fingerprint metadata for future verification.
|
|
158
|
+
*
|
|
159
|
+
* @param {Uint8Array} keyBytes The raw proving and verifying key bytes.
|
|
160
|
+
* @param {KeyLocator} locator The unique locator for the desired key pair.
|
|
161
|
+
* @returns {Promise<void>}
|
|
162
|
+
* @throws {Error} If computing key metadata or writing to storage fails
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* const keys = await generateKeys();
|
|
166
|
+
* await setKeyBytes(keys.provingKey.toBytes(), { locator: 'transfer_private.prover' });
|
|
167
|
+
*/
|
|
168
|
+
setKeyBytes(keyBytes: Uint8Array, locator: KeyLocator): Promise<void>;
|
|
169
|
+
/**
|
|
170
|
+
* Returns stored metadata for a key, if any.
|
|
171
|
+
*
|
|
172
|
+
* @param {string} locator The unique locator for the key.
|
|
173
|
+
* @returns {Promise<KeyFingerprint | null>} The stored fingerprint metadata for that locator, or null if none exists.
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* const metadata = await getKeyMetadata('transfer_private.prover.421e5a5');
|
|
177
|
+
* if (metadata) {
|
|
178
|
+
* // Use the stored metadata.
|
|
179
|
+
* }
|
|
180
|
+
*/
|
|
181
|
+
getKeyMetadata(locator: string): Promise<KeyFingerprint | null>;
|
|
182
|
+
/**
|
|
183
|
+
* Checks if a key exists at the specified locator path.
|
|
184
|
+
*
|
|
185
|
+
* @param {string} locator - Unique identifier for the key location.
|
|
186
|
+
* @returns {Promise<boolean>} True if key exists at location, false otherwise.
|
|
187
|
+
*
|
|
188
|
+
* @example
|
|
189
|
+
* const exists = await has('transfer_private.prover.421e5a5');
|
|
190
|
+
* if (exists) {
|
|
191
|
+
* // Key exists at location.
|
|
192
|
+
* } else {
|
|
193
|
+
* // Key does not exist at location.
|
|
194
|
+
* }
|
|
195
|
+
*/
|
|
196
|
+
has(locator: string): Promise<boolean>;
|
|
197
|
+
/**
|
|
198
|
+
* Deletes a key and its associated metadata from storage. Silently ignores errors if files don't exist.
|
|
199
|
+
*
|
|
200
|
+
* @param {string} locator - Unique identifier for the key to delete.
|
|
201
|
+
* @returns {Promise<void>}
|
|
202
|
+
*
|
|
203
|
+
* @example
|
|
204
|
+
* await delete('transfer_private.prover.421e5a5');
|
|
205
|
+
*/
|
|
206
|
+
delete(locator: string): Promise<void>;
|
|
207
|
+
/**
|
|
208
|
+
* Clears the key storage directory by recursively removing all files and subdirectories under it, then removes the keystore directory itself.
|
|
209
|
+
*
|
|
210
|
+
* @returns {Promise<void>}
|
|
211
|
+
* @throws {Error} If directory listing fails for reasons other than non-existence.
|
|
212
|
+
*
|
|
213
|
+
* @example
|
|
214
|
+
* await clear(); // Removes all files under the keystore directory.
|
|
215
|
+
*/
|
|
216
|
+
clear(): Promise<void>;
|
|
217
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { FunctionKeyPair } from "../../models/keyPair.js";
|
|
2
|
+
export type { InvalidLocatorReason } from "./error.js";
|
|
3
|
+
export { InvalidLocatorError } from "./error.js";
|
|
4
|
+
import { KeyFingerprint } from "../verifier/interface.js";
|
|
5
|
+
import { ProvingKey, VerifyingKey } from "../../wasm.js";
|
|
6
|
+
/**
|
|
7
|
+
* The key locator string and optional fingerprint to verify the integrity of the key.
|
|
8
|
+
*
|
|
9
|
+
* @property {string} locator - The unique identifier for the key.
|
|
10
|
+
* @property {KeyFingerprint} [fingerprint] - Optional fingerprint for verification.
|
|
11
|
+
*/
|
|
12
|
+
export interface KeyLocator {
|
|
13
|
+
locator: string;
|
|
14
|
+
fingerprint?: KeyFingerprint;
|
|
15
|
+
}
|
|
16
|
+
export interface KeyStore {
|
|
17
|
+
/**
|
|
18
|
+
* Returns the raw bytes of a proving or verifying key for a given locator.
|
|
19
|
+
*
|
|
20
|
+
* @param {KeyLocator} locator The unique locator for the desired key.
|
|
21
|
+
* @returns {Promise<Uint8Array | null>} The raw key bytes if they exist, or null if not found.
|
|
22
|
+
*/
|
|
23
|
+
getKeyBytes(locator: KeyLocator): Promise<Uint8Array | null>;
|
|
24
|
+
/**
|
|
25
|
+
* Returns the `ProvingKey` for a given locator.
|
|
26
|
+
*
|
|
27
|
+
* @param {KeyLocator} locator The unique locator for the desired `ProvingKey`.
|
|
28
|
+
*
|
|
29
|
+
* @returns {Promise<ProvingKey | null>} Returns the `ProvingKey` for the given locator if it exists or null if it does not.
|
|
30
|
+
*/
|
|
31
|
+
getProvingKey(locator: KeyLocator): Promise<ProvingKey | null>;
|
|
32
|
+
/**
|
|
33
|
+
* Returns the `VerifyingKey` for a given locator.
|
|
34
|
+
*
|
|
35
|
+
* @param {KeyLocator} locator The unique locator for the desired `VerifyingKey`.
|
|
36
|
+
*
|
|
37
|
+
* @returns {Promise<VerifyingKey | null>} Returns the `VerifyingKey` for the given locator if it exists or null if it does not exist.
|
|
38
|
+
*/
|
|
39
|
+
getVerifyingKey(locator: KeyLocator): Promise<VerifyingKey | null>;
|
|
40
|
+
/**
|
|
41
|
+
* Stores proving and verifying keys in key storage.
|
|
42
|
+
*
|
|
43
|
+
* @param {KeyLocator} proverLocator The unique locator for the desired proving key.
|
|
44
|
+
* @param {KeyLocator} verifierLocator The unique locator for the desired verifying key.
|
|
45
|
+
* @param {FunctionKeyPair} keys The proving and verifying keys.
|
|
46
|
+
*/
|
|
47
|
+
setKeys(proverLocator: KeyLocator, verifierLocator: KeyLocator, keys: FunctionKeyPair): Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* Store a raw proving or verifying key in storage along with its fingerprint metadata for future verification.
|
|
50
|
+
*
|
|
51
|
+
* @param {Uint8Array} keyBytes The raw proving and verifying key bytes.
|
|
52
|
+
* @param {KeyLocator} locator The unique locator for the desired key pair.
|
|
53
|
+
* @returns {Promise<void>}
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* const keys = await generateKeys();
|
|
57
|
+
* await setKeyBytes(keys.provingKey.toBytes(), { locator: 'transfer_private.prover' });
|
|
58
|
+
*/
|
|
59
|
+
setKeyBytes(keyBytes: Uint8Array, locator: KeyLocator): Promise<void>;
|
|
60
|
+
/**
|
|
61
|
+
* Returns stored metadata for a key, if any.
|
|
62
|
+
*
|
|
63
|
+
* @param {string} locator The unique locator for the key.
|
|
64
|
+
* @returns {Promise<KeyFingerprint | null>} The stored fingerprint for that locator, or null if none exists.
|
|
65
|
+
*/
|
|
66
|
+
getKeyMetadata(locator: string): Promise<KeyFingerprint | null>;
|
|
67
|
+
/**
|
|
68
|
+
* Determines if a given key exists or not.
|
|
69
|
+
*
|
|
70
|
+
* @param {string} locator The unique locator for the desired key.
|
|
71
|
+
* @returns {Promise<boolean>} True if the key exists, false otherwise.
|
|
72
|
+
*/
|
|
73
|
+
has(locator: string): Promise<boolean>;
|
|
74
|
+
/**
|
|
75
|
+
* Deletes a key and its metadata corresponding to a given locator.
|
|
76
|
+
*
|
|
77
|
+
* @param {string} locator The unique locator for the desired key.
|
|
78
|
+
* @returns {Promise<void>}
|
|
79
|
+
*/
|
|
80
|
+
delete(locator: string): Promise<void>;
|
|
81
|
+
/**
|
|
82
|
+
* Clears all keys in the keystore.
|
|
83
|
+
*/
|
|
84
|
+
clear(): Promise<void>;
|
|
85
|
+
}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { FunctionKeyPair } from "../../models/keyPair.js";
|
|
2
|
+
import { KeyStore } from "../keystore/interface.js";
|
|
3
|
+
/**
|
|
4
|
+
* Interface for key search parameters. This allows for arbitrary search parameters to be passed to key provider
|
|
5
|
+
* implementations.
|
|
6
|
+
*/
|
|
7
|
+
interface KeySearchParams {
|
|
8
|
+
[key: string]: any;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* KeyProvider interface. Enables the retrieval of public proving and verifying keys for Aleo Programs.
|
|
12
|
+
*/
|
|
13
|
+
interface FunctionKeyProvider {
|
|
14
|
+
/**
|
|
15
|
+
* Get bond_public function keys from the credits.aleo program
|
|
16
|
+
*
|
|
17
|
+
* @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the bond_public function
|
|
18
|
+
*/
|
|
19
|
+
bondPublicKeys(): Promise<FunctionKeyPair>;
|
|
20
|
+
/**
|
|
21
|
+
* Get bond_validator function keys from the credits.aleo program
|
|
22
|
+
*
|
|
23
|
+
* @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the bond_validator function
|
|
24
|
+
*/
|
|
25
|
+
bondValidatorKeys(): Promise<FunctionKeyPair>;
|
|
26
|
+
/**
|
|
27
|
+
* Cache a set of keys. This will overwrite any existing keys with the same keyId. The user can check if a keyId
|
|
28
|
+
* exists in the cache using the containsKeys method prior to calling this method if overwriting is not desired.
|
|
29
|
+
*
|
|
30
|
+
* @param {string} keyId access key for the cache
|
|
31
|
+
* @param {FunctionKeyPair} keys keys to cache
|
|
32
|
+
*/
|
|
33
|
+
cacheKeys(keyId: string, keys: FunctionKeyPair): void;
|
|
34
|
+
/**
|
|
35
|
+
* Get claim_unbond_public function keys from the credits.aleo program
|
|
36
|
+
*
|
|
37
|
+
* @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the claim_unbond_public function
|
|
38
|
+
*/
|
|
39
|
+
claimUnbondPublicKeys(): Promise<FunctionKeyPair>;
|
|
40
|
+
/**
|
|
41
|
+
* Get arbitrary function keys from a provider
|
|
42
|
+
*
|
|
43
|
+
* @param {KeySearchParams | undefined} params - Optional search parameters for the key provider
|
|
44
|
+
* @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the specified program
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* // Create a search object which implements the KeySearchParams interface
|
|
48
|
+
* class IndexDbSearch implements KeySearchParams {
|
|
49
|
+
* db: string
|
|
50
|
+
* keyId: string
|
|
51
|
+
* constructor(params: {db: string, keyId: string}) {
|
|
52
|
+
* this.db = params.db;
|
|
53
|
+
* this.keyId = params.keyId;
|
|
54
|
+
* }
|
|
55
|
+
* }
|
|
56
|
+
*
|
|
57
|
+
* // Create a new object which implements the KeyProvider interface
|
|
58
|
+
* class IndexDbKeyProvider implements FunctionKeyProvider {
|
|
59
|
+
* async functionKeys(params: KeySearchParams): Promise<FunctionKeyPair> {
|
|
60
|
+
* return new Promise((resolve, reject) => {
|
|
61
|
+
* const request = indexedDB.open(params.db, 1);
|
|
62
|
+
*
|
|
63
|
+
* request.onupgradeneeded = function(e) {
|
|
64
|
+
* const db = e.target.result;
|
|
65
|
+
* if (!db.objectStoreNames.contains('keys')) {
|
|
66
|
+
* db.createObjectStore('keys', { keyPath: 'id' });
|
|
67
|
+
* }
|
|
68
|
+
* };
|
|
69
|
+
*
|
|
70
|
+
* request.onsuccess = function(e) {
|
|
71
|
+
* const db = e.target.result;
|
|
72
|
+
* const transaction = db.transaction(["keys"], "readonly");
|
|
73
|
+
* const store = transaction.objectStore("keys");
|
|
74
|
+
* const request = store.get(params.keyId);
|
|
75
|
+
* request.onsuccess = function(e) {
|
|
76
|
+
* if (request.result) {
|
|
77
|
+
* resolve(request.result as FunctionKeyPair);
|
|
78
|
+
* } else {
|
|
79
|
+
* reject(new Error("Key not found"));
|
|
80
|
+
* }
|
|
81
|
+
* };
|
|
82
|
+
* request.onerror = function(e) { reject(new Error("Error fetching key")); };
|
|
83
|
+
* };
|
|
84
|
+
*
|
|
85
|
+
* request.onerror = function(e) { reject(new Error("Error opening database")); };
|
|
86
|
+
* });
|
|
87
|
+
* }
|
|
88
|
+
*
|
|
89
|
+
* // implement the other methods...
|
|
90
|
+
* }
|
|
91
|
+
*
|
|
92
|
+
*
|
|
93
|
+
* const keyProvider = new AleoKeyProvider();
|
|
94
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2");
|
|
95
|
+
* const recordProvider = new NetworkRecordProvider(account, networkClient);
|
|
96
|
+
*
|
|
97
|
+
* // Initialize a program manager with the key provider to automatically fetch keys for value transfers
|
|
98
|
+
* const programManager = new ProgramManager("https://api.provable.com/v2", keyProvider, recordProvider);
|
|
99
|
+
* programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
|
|
100
|
+
*
|
|
101
|
+
* // Keys can also be fetched manually
|
|
102
|
+
* const searchParams = new IndexDbSearch({db: "keys", keyId: "credits.aleo:transferPrivate"});
|
|
103
|
+
* const [transferPrivateProvingKey, transferPrivateVerifyingKey] = await keyProvider.functionKeys(searchParams);
|
|
104
|
+
*/
|
|
105
|
+
functionKeys(params?: KeySearchParams): Promise<FunctionKeyPair>;
|
|
106
|
+
/**
|
|
107
|
+
* Gets an object which implements the `KeyStore` interface for accessing proving and verifying
|
|
108
|
+
* keys directly from persistent storage.
|
|
109
|
+
*
|
|
110
|
+
* @returns {Promise<KeyStore | undefined>} The key store if available, or undefined.
|
|
111
|
+
*/
|
|
112
|
+
keyStore(): Promise<KeyStore | undefined>;
|
|
113
|
+
/**
|
|
114
|
+
* Get fee_private function keys from the credits.aleo program
|
|
115
|
+
*
|
|
116
|
+
* @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the fee_private function
|
|
117
|
+
*/
|
|
118
|
+
feePrivateKeys(): Promise<FunctionKeyPair>;
|
|
119
|
+
/**
|
|
120
|
+
* Get fee_public function keys from the credits.aleo program
|
|
121
|
+
*
|
|
122
|
+
* @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the fee_public function
|
|
123
|
+
*/
|
|
124
|
+
feePublicKeys(): Promise<FunctionKeyPair>;
|
|
125
|
+
/**
|
|
126
|
+
* Get keys for the inclusion proof.
|
|
127
|
+
*
|
|
128
|
+
* @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the inclusion proof
|
|
129
|
+
*/
|
|
130
|
+
inclusionKeys(): Promise<FunctionKeyPair>;
|
|
131
|
+
/**
|
|
132
|
+
* Get join function keys from the credits.aleo program
|
|
133
|
+
*
|
|
134
|
+
* @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the join function
|
|
135
|
+
*/
|
|
136
|
+
joinKeys(): Promise<FunctionKeyPair>;
|
|
137
|
+
/**
|
|
138
|
+
* Get split function keys from the credits.aleo program
|
|
139
|
+
*
|
|
140
|
+
* @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the split function
|
|
141
|
+
*/
|
|
142
|
+
splitKeys(): Promise<FunctionKeyPair>;
|
|
143
|
+
/**
|
|
144
|
+
* Get keys for a variant of the transfer function from the credits.aleo program
|
|
145
|
+
*
|
|
146
|
+
* @param {string} visibility Visibility of the transfer function (private, public, privateToPublic, publicToPrivate)
|
|
147
|
+
* @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the specified transfer function
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* // Create a new object which implements the KeyProvider interface
|
|
151
|
+
* const networkClient = new AleoNetworkClient("https://api.provable.com/v2");
|
|
152
|
+
* const keyProvider = new AleoKeyProvider();
|
|
153
|
+
* const recordProvider = new NetworkRecordProvider(account, networkClient);
|
|
154
|
+
*
|
|
155
|
+
* // Initialize a program manager with the key provider to automatically fetch keys for value transfers
|
|
156
|
+
* const programManager = new ProgramManager("https://api.provable.com/v2", keyProvider, recordProvider);
|
|
157
|
+
* programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
|
|
158
|
+
*
|
|
159
|
+
* // Keys can also be fetched manually
|
|
160
|
+
* const [transferPublicProvingKey, transferPublicVerifyingKey] = await keyProvider.transferKeys("public");
|
|
161
|
+
*/
|
|
162
|
+
transferKeys(visibility: string): Promise<FunctionKeyPair>;
|
|
163
|
+
/**
|
|
164
|
+
* Get unbond_public function keys from the credits.aleo program
|
|
165
|
+
*
|
|
166
|
+
* @returns {Promise<FunctionKeyPair>} Proving and verifying keys for the unbond_public function
|
|
167
|
+
*/
|
|
168
|
+
unBondPublicKeys(): Promise<FunctionKeyPair>;
|
|
169
|
+
}
|
|
170
|
+
export { FunctionKeyProvider, KeySearchParams };
|