@provablehq/sdk 0.9.18 → 0.10.0
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/browser.d.ts +6 -4
- package/dist/mainnet/browser.js +394 -16
- package/dist/mainnet/browser.js.map +1 -1
- package/dist/mainnet/external-signing.d.ts +76 -0
- package/dist/mainnet/keys/keystore/error.d.ts +5 -4
- package/dist/mainnet/keys/keystore/file.d.ts +64 -104
- package/dist/mainnet/keys/keystore/interface.d.ts +106 -30
- package/dist/mainnet/models/external-signing.d.ts +123 -0
- package/dist/mainnet/models/input/inputJSON.d.ts +1 -0
- package/dist/mainnet/models/input/inputObject.d.ts +1 -0
- package/dist/mainnet/models/output/outputJSON.d.ts +1 -0
- package/dist/mainnet/models/output/outputObject.d.ts +1 -0
- package/dist/mainnet/network-client.d.ts +1 -0
- package/dist/mainnet/node.js +112 -138
- package/dist/mainnet/node.js.map +1 -1
- package/dist/mainnet/program-manager.d.ts +100 -4
- package/dist/mainnet/record-scanner.d.ts +1 -0
- package/dist/mainnet/wasm.d.ts +1 -1
- package/dist/testnet/browser.d.ts +6 -4
- package/dist/testnet/browser.js +394 -16
- package/dist/testnet/browser.js.map +1 -1
- package/dist/testnet/external-signing.d.ts +76 -0
- package/dist/testnet/keys/keystore/error.d.ts +5 -4
- package/dist/testnet/keys/keystore/file.d.ts +64 -104
- package/dist/testnet/keys/keystore/interface.d.ts +106 -30
- package/dist/testnet/models/external-signing.d.ts +123 -0
- package/dist/testnet/models/input/inputJSON.d.ts +1 -0
- package/dist/testnet/models/input/inputObject.d.ts +1 -0
- package/dist/testnet/models/output/outputJSON.d.ts +1 -0
- package/dist/testnet/models/output/outputObject.d.ts +1 -0
- package/dist/testnet/network-client.d.ts +1 -0
- package/dist/testnet/node.js +112 -138
- package/dist/testnet/node.js.map +1 -1
- package/dist/testnet/program-manager.d.ts +100 -4
- package/dist/testnet/record-scanner.d.ts +1 -0
- package/dist/testnet/wasm.d.ts +1 -1
- package/package.json +2 -2
- package/dist/mainnet/models/keyHolder.d.ts +0 -2
- package/dist/testnet/models/keyHolder.d.ts +0 -2
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { ExecutionRequest } from "./wasm.js";
|
|
2
|
+
import type { ExternalSigningInput, ExternalSigningOptions, ExecutionRequestParams, InputStrategy } from "./models/external-signing.js";
|
|
3
|
+
export * from "./models/external-signing.js";
|
|
4
|
+
/**
|
|
5
|
+
* Build an ExecutionRequest from externally signed data.
|
|
6
|
+
*
|
|
7
|
+
* The `strategy` parameter determines how record input IDs are resolved:
|
|
8
|
+
* - `{ recordViewKeys?, gammas? }` — explicit record view keys and gammas
|
|
9
|
+
* - `{ viewKey, gammas? }` — derive record view keys from a ViewKey
|
|
10
|
+
* - `{ inputIds }` — pre-computed input IDs (Field or [Field, Group, Field, Field, Field] tuples)
|
|
11
|
+
*
|
|
12
|
+
* @throws {Error} If `strategy` is not a valid `InputStrategy` variant.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* // With explicit record view keys
|
|
16
|
+
* buildExecutionRequestFromExternallySignedData(
|
|
17
|
+
* { programId, functionName, inputs, inputTypes, signature, tvk, signer, skTag },
|
|
18
|
+
* { recordViewKeys: [...], gammas: [...] },
|
|
19
|
+
* );
|
|
20
|
+
*
|
|
21
|
+
* // With a view key
|
|
22
|
+
* buildExecutionRequestFromExternallySignedData(
|
|
23
|
+
* { programId, functionName, inputs, inputTypes, signature, tvk, signer, skTag },
|
|
24
|
+
* { viewKey: "AViewKey1..." },
|
|
25
|
+
* );
|
|
26
|
+
*
|
|
27
|
+
* // With pre-computed input IDs
|
|
28
|
+
* buildExecutionRequestFromExternallySignedData(
|
|
29
|
+
* { programId, functionName, inputs, inputTypes, signature, tvk, signer, skTag },
|
|
30
|
+
* { inputIds: [...] },
|
|
31
|
+
* );
|
|
32
|
+
*/
|
|
33
|
+
export declare function buildExecutionRequestFromExternallySignedData(params: ExecutionRequestParams, strategy?: InputStrategy): ExecutionRequest;
|
|
34
|
+
/**
|
|
35
|
+
* Computes the function ID and serialized input data for a program function call.
|
|
36
|
+
* Used by external signing wallets and other applications that need publicly computable inputs
|
|
37
|
+
* for building a signed execution request (e.g. before calling {@link ExecutionRequest.sign}).
|
|
38
|
+
*
|
|
39
|
+
* The optional `outputFormat` field controls how field elements are returned:
|
|
40
|
+
* - `"string"` (default) — human-readable strings like `"123field"`
|
|
41
|
+
* - `"bytes"` — raw little-endian `Uint8Array`s
|
|
42
|
+
*
|
|
43
|
+
* @param {ExternalSigningOptions} options - Program name, function name, inputs, input_types, root flag, an optional program checksum, an optional view key, and an optional output format.
|
|
44
|
+
* @throws Throws if parsing the program ID, function name, or inputs fails or if the inputs do not match the type signatures passed in the input_types parameter.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* // String output (default)
|
|
48
|
+
* const result = await computeExternalSigningInputs({
|
|
49
|
+
* programName: "credits.aleo",
|
|
50
|
+
* functionName: "transfer_public",
|
|
51
|
+
* inputs: ["aleo1...", "100u64"],
|
|
52
|
+
* inputTypes: ["address.public", "u64.public"],
|
|
53
|
+
* isRoot: true,
|
|
54
|
+
* });
|
|
55
|
+
* result.functionId; // string
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* // Bytes output
|
|
59
|
+
* const result = await computeExternalSigningInputs({
|
|
60
|
+
* programName: "credits.aleo",
|
|
61
|
+
* functionName: "transfer_public",
|
|
62
|
+
* inputs: ["aleo1...", "100u64"],
|
|
63
|
+
* inputTypes: ["address.public", "u64.public"],
|
|
64
|
+
* isRoot: true,
|
|
65
|
+
* outputFormat: "bytes",
|
|
66
|
+
* });
|
|
67
|
+
* result.functionId; // Uint8Array
|
|
68
|
+
*
|
|
69
|
+
* @returns {ExternalSigningInput} A JSON object for inputs to external signing algorithms.
|
|
70
|
+
*/
|
|
71
|
+
export declare function computeExternalSigningInputs(options: ExternalSigningOptions & {
|
|
72
|
+
outputFormat: "bytes";
|
|
73
|
+
}): Promise<ExternalSigningInput<"bytes">>;
|
|
74
|
+
export declare function computeExternalSigningInputs(options: ExternalSigningOptions & {
|
|
75
|
+
outputFormat?: "string";
|
|
76
|
+
}): Promise<ExternalSigningInput<"string">>;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Reason code for invalid locator validation failures.
|
|
3
|
-
* - `"reserved_name"`:
|
|
4
|
-
* - `"path_traversal"`:
|
|
5
|
-
* - `"path_separator"`:
|
|
3
|
+
* - `"reserved_name"`: A locator component is empty or `"."`.
|
|
4
|
+
* - `"path_traversal"`: A locator component contains `..`.
|
|
5
|
+
* - `"path_separator"`: A locator component contains a path separator (`/`, `\`) or null byte.
|
|
6
|
+
* - `"negative_value"`: A numeric locator field (edition, amendment, recordInputPosition) is not a non-negative integer.
|
|
6
7
|
*/
|
|
7
|
-
export type InvalidLocatorReason = "reserved_name" | "path_traversal" | "path_separator";
|
|
8
|
+
export type InvalidLocatorReason = "reserved_name" | "path_traversal" | "path_separator" | "negative_value";
|
|
8
9
|
/**
|
|
9
10
|
* Error thrown when a key locator is invalid for filesystem use.
|
|
10
11
|
* Used to prevent path traversal and other filesystem injection when deriving paths from locators.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { FunctionKeyPair } from "../../models/keyPair.js";
|
|
2
2
|
import { KeyFingerprint } from "../verifier/interface.js";
|
|
3
|
-
import { KeyLocator, KeyStore } from "./interface.js";
|
|
3
|
+
import { KeyLocator, KeyStore, ProvingKeyLocator, VerifyingKeyLocator } from "./interface.js";
|
|
4
4
|
import { ProvingKey, VerifyingKey } from "../../wasm.js";
|
|
5
5
|
export declare class LocalFileKeyStore implements KeyStore {
|
|
6
6
|
private directory;
|
|
@@ -15,13 +15,45 @@ export declare class LocalFileKeyStore implements KeyStore {
|
|
|
15
15
|
*/
|
|
16
16
|
constructor(directory?: string);
|
|
17
17
|
/**
|
|
18
|
-
* Validates
|
|
18
|
+
* Validates a single locator component for unsafe filesystem characters.
|
|
19
19
|
*
|
|
20
20
|
* @private
|
|
21
|
-
* @param {string}
|
|
22
|
-
* @
|
|
21
|
+
* @param {string} value - The component value to validate.
|
|
22
|
+
* @param {string} label - Label for error messages (e.g. "program", "functionName").
|
|
23
|
+
* @throws {InvalidLocatorError} If the value is empty, contains traversal sequences, path separators, or null bytes.
|
|
23
24
|
*/
|
|
24
|
-
private
|
|
25
|
+
private validateComponent;
|
|
26
|
+
/**
|
|
27
|
+
* Validates that a numeric locator field is not negative.
|
|
28
|
+
*
|
|
29
|
+
* @private
|
|
30
|
+
* @param {number} value - The numeric value to validate.
|
|
31
|
+
* @param {string} label - Label for error messages (e.g. "edition", "amendment").
|
|
32
|
+
* @throws {InvalidLocatorError} If the value is negative.
|
|
33
|
+
*/
|
|
34
|
+
private validateNonNegative;
|
|
35
|
+
/**
|
|
36
|
+
* Serializes a {@link KeyLocator} to a filesystem-safe flat string, validating components first.
|
|
37
|
+
*
|
|
38
|
+
* For prover/verifier keys: `{program}.{functionName}.e{edition}.a{amendment}.{network}.{keyType}`
|
|
39
|
+
* For translation keys: `{program}.{functionName}.e{edition}.a{amendment}.{network}.translation.{recordName}.{recordInputPosition}`
|
|
40
|
+
*
|
|
41
|
+
* Note: The optional `checksum` field is excluded — it is used for integrity verification only
|
|
42
|
+
* (via {@link checksumToFingerprint}) and is not part of the key identity.
|
|
43
|
+
*
|
|
44
|
+
* @private
|
|
45
|
+
* @param {KeyLocator} locator - The key locator.
|
|
46
|
+
* @returns {string} A dot-delimited string safe for use as a filename.
|
|
47
|
+
* @throws {InvalidLocatorError} If any component contains unsafe characters.
|
|
48
|
+
*/
|
|
49
|
+
private serializeLocator;
|
|
50
|
+
/**
|
|
51
|
+
* Converts an optional checksum string from a locator into a KeyFingerprint
|
|
52
|
+
* suitable for the key verifier, using the actual key byte length for size.
|
|
53
|
+
*
|
|
54
|
+
* @private
|
|
55
|
+
*/
|
|
56
|
+
private checksumToFingerprint;
|
|
25
57
|
/**
|
|
26
58
|
* Generates the path for a key metadata file based on the locator.
|
|
27
59
|
*
|
|
@@ -72,146 +104,74 @@ export declare class LocalFileKeyStore implements KeyStore {
|
|
|
72
104
|
*/
|
|
73
105
|
private clearDirectory;
|
|
74
106
|
/**
|
|
75
|
-
* Retrieves the key bytes from storage and optionally verifies them
|
|
107
|
+
* Retrieves the key bytes from storage and optionally verifies them.
|
|
76
108
|
*
|
|
77
|
-
* @param {KeyLocator} locator -
|
|
78
|
-
* @returns {Promise<Uint8Array | null>} The key bytes if found and verified
|
|
79
|
-
* @throws {KeyVerificationError} If
|
|
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
|
-
* }
|
|
109
|
+
* @param {KeyLocator} locator - The key locator with optional checksum for verification.
|
|
110
|
+
* @returns {Promise<Uint8Array | null>} The key bytes if found and verified, null if not found.
|
|
111
|
+
* @throws {KeyVerificationError} If verification fails.
|
|
88
112
|
*/
|
|
89
113
|
getKeyBytes(locator: KeyLocator): Promise<Uint8Array | null>;
|
|
90
114
|
/**
|
|
91
115
|
* Retrieves and verifies a proving key from storage.
|
|
92
116
|
*
|
|
93
|
-
* @param {
|
|
117
|
+
* @param {ProvingKeyLocator} locator - The proving key locator.
|
|
94
118
|
* @returns {Promise<ProvingKey | null>} The proving key if found and verified, null if not found.
|
|
95
|
-
* @throws {KeyVerificationError} If
|
|
119
|
+
* @throws {KeyVerificationError} If verification fails.
|
|
96
120
|
* @throws {Error} If key bytes cannot be parsed into a valid ProvingKey.
|
|
97
|
-
|
|
98
|
-
|
|
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>;
|
|
121
|
+
*/
|
|
122
|
+
getProvingKey(locator: ProvingKeyLocator): Promise<ProvingKey | null>;
|
|
115
123
|
/**
|
|
116
124
|
* Retrieves and verifies a verifying key from storage.
|
|
117
125
|
*
|
|
118
|
-
* @param {
|
|
126
|
+
* @param {VerifyingKeyLocator} locator - The verifying key locator.
|
|
119
127
|
* @returns {Promise<VerifyingKey | null>} The verifying key if found and verified, null if not found.
|
|
120
|
-
* @throws {KeyVerificationError} If
|
|
128
|
+
* @throws {KeyVerificationError} If verification fails.
|
|
121
129
|
* @throws {Error} If key bytes cannot be parsed into a valid VerifyingKey.
|
|
122
|
-
|
|
123
|
-
|
|
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>;
|
|
130
|
+
*/
|
|
131
|
+
getVerifyingKey(locator: VerifyingKeyLocator): Promise<VerifyingKey | null>;
|
|
140
132
|
/**
|
|
141
133
|
* Stores proving and verifying keys in key storage.
|
|
142
134
|
*
|
|
143
|
-
* @param {
|
|
144
|
-
* @param {
|
|
135
|
+
* @param {ProvingKeyLocator} proverLocator The locator for the proving key.
|
|
136
|
+
* @param {VerifyingKeyLocator} verifierLocator The locator for the verifying key.
|
|
145
137
|
* @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
138
|
*/
|
|
155
|
-
setKeys(proverLocator:
|
|
139
|
+
setKeys(proverLocator: ProvingKeyLocator, verifierLocator: VerifyingKeyLocator, keys: FunctionKeyPair): Promise<void>;
|
|
156
140
|
/**
|
|
157
|
-
* Store a raw
|
|
141
|
+
* Store a raw key in storage along with its fingerprint metadata for future verification.
|
|
158
142
|
*
|
|
159
|
-
* @param {Uint8Array} keyBytes The raw
|
|
160
|
-
* @param {KeyLocator} locator The unique locator for the
|
|
143
|
+
* @param {Uint8Array} keyBytes The raw key bytes.
|
|
144
|
+
* @param {KeyLocator} locator The unique locator for the key.
|
|
161
145
|
* @returns {Promise<void>}
|
|
162
146
|
* @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
147
|
*/
|
|
168
148
|
setKeyBytes(keyBytes: Uint8Array, locator: KeyLocator): Promise<void>;
|
|
169
149
|
/**
|
|
170
150
|
* Returns stored metadata for a key, if any.
|
|
171
151
|
*
|
|
172
|
-
* @param {
|
|
173
|
-
* @returns {Promise<KeyFingerprint | null>} The stored fingerprint metadata
|
|
174
|
-
*
|
|
175
|
-
* @example
|
|
176
|
-
* const metadata = await getKeyMetadata('transfer_private.prover.421e5a5');
|
|
177
|
-
* if (metadata) {
|
|
178
|
-
* // Use the stored metadata.
|
|
179
|
-
* }
|
|
152
|
+
* @param {KeyLocator} locator The unique locator for the key.
|
|
153
|
+
* @returns {Promise<KeyFingerprint | null>} The stored fingerprint metadata, or null if none exists.
|
|
180
154
|
*/
|
|
181
|
-
getKeyMetadata(locator:
|
|
155
|
+
getKeyMetadata(locator: KeyLocator): Promise<KeyFingerprint | null>;
|
|
182
156
|
/**
|
|
183
|
-
* Checks if a key exists
|
|
157
|
+
* Checks if a key exists for the given locator.
|
|
184
158
|
*
|
|
185
|
-
* @param {
|
|
186
|
-
* @returns {Promise<boolean>} True if key exists
|
|
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
|
-
* }
|
|
159
|
+
* @param {KeyLocator} locator - The unique key locator.
|
|
160
|
+
* @returns {Promise<boolean>} True if key exists, false otherwise.
|
|
195
161
|
*/
|
|
196
|
-
has(locator:
|
|
162
|
+
has(locator: KeyLocator): Promise<boolean>;
|
|
197
163
|
/**
|
|
198
164
|
* Deletes a key and its associated metadata from storage. Silently ignores errors if files don't exist.
|
|
199
165
|
*
|
|
200
|
-
* @param {
|
|
166
|
+
* @param {KeyLocator} locator - The unique key locator.
|
|
201
167
|
* @returns {Promise<void>}
|
|
202
|
-
*
|
|
203
|
-
* @example
|
|
204
|
-
* await delete('transfer_private.prover.421e5a5');
|
|
205
168
|
*/
|
|
206
|
-
delete(locator:
|
|
169
|
+
delete(locator: KeyLocator): Promise<void>;
|
|
207
170
|
/**
|
|
208
171
|
* Clears the key storage directory by recursively removing all files and subdirectories under it, then removes the keystore directory itself.
|
|
209
172
|
*
|
|
210
173
|
* @returns {Promise<void>}
|
|
211
174
|
* @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
175
|
*/
|
|
216
176
|
clear(): Promise<void>;
|
|
217
177
|
}
|
|
@@ -4,18 +4,100 @@ export { InvalidLocatorError } from "./error.js";
|
|
|
4
4
|
import { KeyFingerprint } from "../verifier/interface.js";
|
|
5
5
|
import { ProvingKey, VerifyingKey } from "../../wasm.js";
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* Discriminates the type of key a locator refers to.
|
|
8
|
+
*/
|
|
9
|
+
export type KeyType = "prover" | "verifier" | "translation";
|
|
10
|
+
/**
|
|
11
|
+
* Shared fields for all function key locators.
|
|
12
|
+
*
|
|
13
|
+
* @property {string} program - The program name (e.g. "credits.aleo").
|
|
14
|
+
* @property {string} functionName - The function name (e.g. "transfer_private").
|
|
15
|
+
* @property {number} edition - The program edition (u16). Incremented when a program is re-deployed.
|
|
16
|
+
* @property {number} amendment - The program amendment. Reserved for future protocol-level amendments; defaults to 0.
|
|
17
|
+
* @property {string} network - The network name (e.g. "mainnet", "testnet").
|
|
18
|
+
* @property {string} [checksum] - Optional SHA-256 checksum for key verification. Used for integrity verification only; not part of the key identity or serialized form.
|
|
19
|
+
*/
|
|
20
|
+
export interface BaseFunctionKeyLocator {
|
|
21
|
+
program: string;
|
|
22
|
+
functionName: string;
|
|
23
|
+
edition: number;
|
|
24
|
+
amendment: number;
|
|
25
|
+
network: string;
|
|
26
|
+
checksum?: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Locator for a proving key.
|
|
30
|
+
*/
|
|
31
|
+
export interface ProvingKeyLocator extends BaseFunctionKeyLocator {
|
|
32
|
+
keyType: "prover";
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Locator for a verifying key.
|
|
36
|
+
*/
|
|
37
|
+
export interface VerifyingKeyLocator extends BaseFunctionKeyLocator {
|
|
38
|
+
keyType: "verifier";
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Locator for a translation key, which requires additional record information.
|
|
8
42
|
*
|
|
9
|
-
* @property {string}
|
|
10
|
-
* @property {
|
|
43
|
+
* @property {string} recordName - The name of the record associated with the translation key.
|
|
44
|
+
* @property {number} recordInputPosition - The position of the record input in the function signature.
|
|
11
45
|
*/
|
|
12
|
-
export interface
|
|
13
|
-
|
|
14
|
-
|
|
46
|
+
export interface TranslationKeyLocator extends BaseFunctionKeyLocator {
|
|
47
|
+
keyType: "translation";
|
|
48
|
+
recordName: string;
|
|
49
|
+
recordInputPosition: number;
|
|
15
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* A locator that uniquely identifies a function's proving, verifying, or translation key.
|
|
53
|
+
* Discriminated on the {@link KeyType} field.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* const prover: KeyLocator = { program: "credits.aleo", functionName: "transfer_private", edition: 1, amendment: 0, network: "mainnet", keyType: "prover" };
|
|
57
|
+
* const verifier: KeyLocator = { program: "credits.aleo", functionName: "transfer_private", edition: 1, amendment: 0, network: "mainnet", keyType: "verifier" };
|
|
58
|
+
*/
|
|
59
|
+
export type KeyLocator = ProvingKeyLocator | VerifyingKeyLocator | TranslationKeyLocator;
|
|
60
|
+
/**
|
|
61
|
+
* Creates a {@link ProvingKeyLocator}.
|
|
62
|
+
*
|
|
63
|
+
* @param {string} program - The program name (e.g. "credits.aleo").
|
|
64
|
+
* @param {string} functionName - The function name (e.g. "transfer_private").
|
|
65
|
+
* @param {number} [edition=1] - The program edition.
|
|
66
|
+
* @param {number} [amendment=0] - The program amendment.
|
|
67
|
+
* @param {string} [network] - The network name. Defaults to the build-time network.
|
|
68
|
+
* @param {string} [checksum] - Optional SHA-256 checksum for key verification.
|
|
69
|
+
* @returns {ProvingKeyLocator}
|
|
70
|
+
*/
|
|
71
|
+
export declare function provingKeyLocator(program: string, functionName: string, edition?: number, amendment?: number, network?: string, checksum?: string): ProvingKeyLocator;
|
|
72
|
+
/**
|
|
73
|
+
* Creates a {@link VerifyingKeyLocator}.
|
|
74
|
+
*
|
|
75
|
+
* @param {string} program - The program name (e.g. "credits.aleo").
|
|
76
|
+
* @param {string} functionName - The function name (e.g. "transfer_private").
|
|
77
|
+
* @param {number} [edition=1] - The program edition.
|
|
78
|
+
* @param {number} [amendment=0] - The program amendment.
|
|
79
|
+
* @param {string} [network] - The network name. Defaults to the build-time network.
|
|
80
|
+
* @param {string} [checksum] - Optional SHA-256 checksum for key verification.
|
|
81
|
+
* @returns {VerifyingKeyLocator}
|
|
82
|
+
*/
|
|
83
|
+
export declare function verifyingKeyLocator(program: string, functionName: string, edition?: number, amendment?: number, network?: string, checksum?: string): VerifyingKeyLocator;
|
|
84
|
+
/**
|
|
85
|
+
* Creates a {@link TranslationKeyLocator}.
|
|
86
|
+
*
|
|
87
|
+
* @param {string} program - The program name (e.g. "credits.aleo").
|
|
88
|
+
* @param {string} functionName - The function name (e.g. "transfer_private").
|
|
89
|
+
* @param {string} recordName - The record name associated with the translation key.
|
|
90
|
+
* @param {number} recordInputPosition - The record input position in the function signature.
|
|
91
|
+
* @param {number} [edition=1] - The program edition.
|
|
92
|
+
* @param {number} [amendment=0] - The program amendment.
|
|
93
|
+
* @param {string} [network] - The network name. Defaults to the build-time network.
|
|
94
|
+
* @param {string} [checksum] - Optional SHA-256 checksum for key verification.
|
|
95
|
+
* @returns {TranslationKeyLocator}
|
|
96
|
+
*/
|
|
97
|
+
export declare function translationKeyLocator(program: string, functionName: string, recordName: string, recordInputPosition: number, edition?: number, amendment?: number, network?: string, checksum?: string): TranslationKeyLocator;
|
|
16
98
|
export interface KeyStore {
|
|
17
99
|
/**
|
|
18
|
-
* Returns the raw bytes of a
|
|
100
|
+
* Returns the raw bytes of a key for a given locator.
|
|
19
101
|
*
|
|
20
102
|
* @param {KeyLocator} locator The unique locator for the desired key.
|
|
21
103
|
* @returns {Promise<Uint8Array | null>} The raw key bytes if they exist, or null if not found.
|
|
@@ -24,60 +106,54 @@ export interface KeyStore {
|
|
|
24
106
|
/**
|
|
25
107
|
* Returns the `ProvingKey` for a given locator.
|
|
26
108
|
*
|
|
27
|
-
* @param {
|
|
28
|
-
*
|
|
109
|
+
* @param {ProvingKeyLocator} locator The unique locator for the desired `ProvingKey`.
|
|
29
110
|
* @returns {Promise<ProvingKey | null>} Returns the `ProvingKey` for the given locator if it exists or null if it does not.
|
|
30
111
|
*/
|
|
31
|
-
getProvingKey(locator:
|
|
112
|
+
getProvingKey(locator: ProvingKeyLocator): Promise<ProvingKey | null>;
|
|
32
113
|
/**
|
|
33
114
|
* Returns the `VerifyingKey` for a given locator.
|
|
34
115
|
*
|
|
35
|
-
* @param {
|
|
36
|
-
*
|
|
116
|
+
* @param {VerifyingKeyLocator} locator The unique locator for the desired `VerifyingKey`.
|
|
37
117
|
* @returns {Promise<VerifyingKey | null>} Returns the `VerifyingKey` for the given locator if it exists or null if it does not exist.
|
|
38
118
|
*/
|
|
39
|
-
getVerifyingKey(locator:
|
|
119
|
+
getVerifyingKey(locator: VerifyingKeyLocator): Promise<VerifyingKey | null>;
|
|
40
120
|
/**
|
|
41
121
|
* Stores proving and verifying keys in key storage.
|
|
42
122
|
*
|
|
43
|
-
* @param {
|
|
44
|
-
* @param {
|
|
123
|
+
* @param {ProvingKeyLocator} proverLocator The locator for the proving key.
|
|
124
|
+
* @param {VerifyingKeyLocator} verifierLocator The locator for the verifying key.
|
|
45
125
|
* @param {FunctionKeyPair} keys The proving and verifying keys.
|
|
46
126
|
*/
|
|
47
|
-
setKeys(proverLocator:
|
|
127
|
+
setKeys(proverLocator: ProvingKeyLocator, verifierLocator: VerifyingKeyLocator, keys: FunctionKeyPair): Promise<void>;
|
|
48
128
|
/**
|
|
49
|
-
* Store a raw
|
|
129
|
+
* Store a raw key in storage along with its fingerprint metadata for future verification.
|
|
50
130
|
*
|
|
51
|
-
* @param {Uint8Array} keyBytes The raw
|
|
52
|
-
* @param {KeyLocator} locator The unique locator for the desired key
|
|
131
|
+
* @param {Uint8Array} keyBytes The raw key bytes.
|
|
132
|
+
* @param {KeyLocator} locator The unique locator for the desired key.
|
|
53
133
|
* @returns {Promise<void>}
|
|
54
|
-
*
|
|
55
|
-
* @example
|
|
56
|
-
* const keys = await generateKeys();
|
|
57
|
-
* await setKeyBytes(keys.provingKey.toBytes(), { locator: 'transfer_private.prover' });
|
|
58
134
|
*/
|
|
59
135
|
setKeyBytes(keyBytes: Uint8Array, locator: KeyLocator): Promise<void>;
|
|
60
136
|
/**
|
|
61
137
|
* Returns stored metadata for a key, if any.
|
|
62
138
|
*
|
|
63
|
-
* @param {
|
|
64
|
-
* @returns {Promise<KeyFingerprint | null>} The stored fingerprint for that
|
|
139
|
+
* @param {KeyLocator} locator The unique locator for the key.
|
|
140
|
+
* @returns {Promise<KeyFingerprint | null>} The stored fingerprint for that key, or null if none exists.
|
|
65
141
|
*/
|
|
66
|
-
getKeyMetadata(locator:
|
|
142
|
+
getKeyMetadata(locator: KeyLocator): Promise<KeyFingerprint | null>;
|
|
67
143
|
/**
|
|
68
144
|
* Determines if a given key exists or not.
|
|
69
145
|
*
|
|
70
|
-
* @param {
|
|
146
|
+
* @param {KeyLocator} locator The unique locator for the key.
|
|
71
147
|
* @returns {Promise<boolean>} True if the key exists, false otherwise.
|
|
72
148
|
*/
|
|
73
|
-
has(locator:
|
|
149
|
+
has(locator: KeyLocator): Promise<boolean>;
|
|
74
150
|
/**
|
|
75
151
|
* Deletes a key and its metadata corresponding to a given locator.
|
|
76
152
|
*
|
|
77
|
-
* @param {
|
|
153
|
+
* @param {KeyLocator} locator The unique locator for the key.
|
|
78
154
|
* @returns {Promise<void>}
|
|
79
155
|
*/
|
|
80
|
-
delete(locator:
|
|
156
|
+
delete(locator: KeyLocator): Promise<void>;
|
|
81
157
|
/**
|
|
82
158
|
* Clears all keys in the keystore.
|
|
83
159
|
*/
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { Address, Field, Group, Signature, ViewKey } from "../wasm.js";
|
|
2
|
+
/** A Field, a string representation, or raw LE bytes. */
|
|
3
|
+
export type FieldLike = Field | string | Uint8Array;
|
|
4
|
+
/** A Group, a Field (x-coordinate), a string representation, or raw LE bytes. */
|
|
5
|
+
export type GroupLike = Group | Field | string | Uint8Array;
|
|
6
|
+
/** A ViewKey, a string representation, or raw LE bytes. */
|
|
7
|
+
export type ViewKeyLike = ViewKey | string | Uint8Array;
|
|
8
|
+
/** A Signature, a string representation, or raw LE bytes. */
|
|
9
|
+
export type SignatureLike = Signature | string | Uint8Array;
|
|
10
|
+
/** An Address, a string representation, or raw LE bytes. */
|
|
11
|
+
export type AddressLike = Address | string | Uint8Array;
|
|
12
|
+
/** An input ID is either a single Field-like (public/private) or a 5-tuple (record) with flexible deserialization. */
|
|
13
|
+
export type InputID = FieldLike | [FieldLike, GroupLike, FieldLike, FieldLike, FieldLike];
|
|
14
|
+
export declare function toField(value: FieldLike): Field;
|
|
15
|
+
export declare function toGroup(value: GroupLike): Group;
|
|
16
|
+
export declare function toViewKey(value: ViewKeyLike): ViewKey;
|
|
17
|
+
export declare function toSignature(value: SignatureLike): Signature;
|
|
18
|
+
export declare function toAddress(value: AddressLike): Address;
|
|
19
|
+
/** Output format discriminant for `computeExternalSigningInputs`. */
|
|
20
|
+
export type OutputFormat = "string" | "bytes";
|
|
21
|
+
/** Maps an {@link OutputFormat} to the concrete field-element representation. */
|
|
22
|
+
export type FieldOutput<F extends OutputFormat> = F extends "bytes" ? Uint8Array : string;
|
|
23
|
+
/**
|
|
24
|
+
* Type surrounding the input to an external signing request.
|
|
25
|
+
*
|
|
26
|
+
* The generic parameter `F` controls whether field elements are serialised as
|
|
27
|
+
* human-readable strings (`"string"`, the default) or raw little-endian bytes
|
|
28
|
+
* (`"bytes"`).
|
|
29
|
+
*
|
|
30
|
+
* @property {string} signingInputType - The type of signing input being requested.
|
|
31
|
+
* @property {FieldOutput<F>} index - The index of the output represented as an Ed/BLS-377 base field element.
|
|
32
|
+
* @property {FieldOutput<F>[]} data - The data represented as Ed/BLS-377 base field elements.
|
|
33
|
+
* @property {string} [name] - The name of the record being requested.
|
|
34
|
+
* @property {FieldOutput<F>} [h] - The h value of the record represented as an Ed/BLS-377 base field element.
|
|
35
|
+
* @property {FieldOutput<F>} [tag] - The tag of the record represented as an Ed/BLS-377 base field element.
|
|
36
|
+
* @property {FieldOutput<F>} [recordViewKey] - The record view key (present for record inputs when viewKey was provided).
|
|
37
|
+
*/
|
|
38
|
+
export interface RequestSignInput<F extends OutputFormat = "string"> {
|
|
39
|
+
signingInputType: "constant" | "public" | "private" | "record" | "external_record" | "dynamic_record";
|
|
40
|
+
index: FieldOutput<F>;
|
|
41
|
+
data: FieldOutput<F>[];
|
|
42
|
+
name?: string;
|
|
43
|
+
h?: FieldOutput<F>;
|
|
44
|
+
tag?: FieldOutput<F>;
|
|
45
|
+
recordViewKey?: FieldOutput<F>;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Type representing the output of an external signing request.
|
|
49
|
+
*
|
|
50
|
+
* The generic parameter `F` controls whether field elements are serialised as
|
|
51
|
+
* human-readable strings (`"string"`, the default) or raw little-endian bytes
|
|
52
|
+
* (`"bytes"`).
|
|
53
|
+
*
|
|
54
|
+
* @property {FieldOutput<F>} functionId - The function ID as Ed/BLS-377 base field element(s).
|
|
55
|
+
* @property {boolean} isRoot - Whether this is a top-level transition.
|
|
56
|
+
* @property {RequestSignInput<F>[]} requestInputs - The inputs to the function being executed.
|
|
57
|
+
* @property {FieldOutput<F>} [checksum] - The Ed/BLS-377 base field representation of the program checksum.
|
|
58
|
+
* @property {string} [signer] - The signer address string (present when viewKey was provided).
|
|
59
|
+
* @property {string} [skTag] - The tag secret key string (present when viewKey was provided).
|
|
60
|
+
*/
|
|
61
|
+
export interface ExternalSigningInput<F extends OutputFormat = "string"> {
|
|
62
|
+
functionId: FieldOutput<F>;
|
|
63
|
+
isRoot: boolean;
|
|
64
|
+
requestInputs: RequestSignInput<F>[];
|
|
65
|
+
checksum?: FieldOutput<F>;
|
|
66
|
+
signer?: string;
|
|
67
|
+
skTag?: string;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Type representing the options for pre-computing the inputs to an external signing request.
|
|
71
|
+
*
|
|
72
|
+
* @property {string} programName - The name of the program containing the function to execute.
|
|
73
|
+
* @property {string} functionName - The name of the function to execute within the program.
|
|
74
|
+
* @property {string[]} inputs - The inputs to the function being executed.
|
|
75
|
+
* @property {string[]} inputTypes - The input types of the function (e.g. ["address.public", "u64.public"]).
|
|
76
|
+
* @property {boolean} isRoot - Whether this transition is the first transition being executed in a transaction.
|
|
77
|
+
* @property {FieldLike} [checksum] - The optional checksum of the program.
|
|
78
|
+
* @property {ViewKeyLike} [viewKey] - The optional view key used to derive signer and skTag.
|
|
79
|
+
* @property {OutputFormat} [outputFormat] - Controls whether field elements are serialised as strings (default) or Uint8Arrays.
|
|
80
|
+
*/
|
|
81
|
+
export interface ExternalSigningOptions {
|
|
82
|
+
programName: string;
|
|
83
|
+
functionName: string;
|
|
84
|
+
inputs: string[];
|
|
85
|
+
inputTypes: string[];
|
|
86
|
+
isRoot: boolean;
|
|
87
|
+
checksum?: FieldLike | null;
|
|
88
|
+
viewKey?: ViewKeyLike | null;
|
|
89
|
+
outputFormat?: OutputFormat;
|
|
90
|
+
}
|
|
91
|
+
/** Common parameters shared by all `buildExecutionRequest` variants. */
|
|
92
|
+
export interface ExecutionRequestParams {
|
|
93
|
+
programId: string;
|
|
94
|
+
functionName: string;
|
|
95
|
+
inputs: string[];
|
|
96
|
+
inputTypes: string[];
|
|
97
|
+
signature: SignatureLike;
|
|
98
|
+
tvk: FieldLike;
|
|
99
|
+
signer: AddressLike;
|
|
100
|
+
skTag: FieldLike;
|
|
101
|
+
}
|
|
102
|
+
/** Provide explicit record view keys and gammas. */
|
|
103
|
+
export interface RecordViewKeyStrategy {
|
|
104
|
+
recordViewKeys?: FieldLike[];
|
|
105
|
+
gammas?: GroupLike[];
|
|
106
|
+
}
|
|
107
|
+
/** Provide a view key to derive record view keys internally. */
|
|
108
|
+
export interface ViewKeyStrategy {
|
|
109
|
+
viewKey: ViewKeyLike;
|
|
110
|
+
gammas?: GroupLike[];
|
|
111
|
+
}
|
|
112
|
+
/** Provide pre-computed input IDs directly. */
|
|
113
|
+
export interface InputIdStrategy {
|
|
114
|
+
inputIds: InputID[];
|
|
115
|
+
}
|
|
116
|
+
/** Determines how record input IDs are resolved when building an ExecutionRequest. */
|
|
117
|
+
export type InputStrategy = RecordViewKeyStrategy | ViewKeyStrategy | InputIdStrategy;
|
|
118
|
+
/** Returns `true` if the strategy provides a `viewKey` for deriving record view keys. */
|
|
119
|
+
export declare function isViewKeyStrategy(r: InputStrategy): r is ViewKeyStrategy;
|
|
120
|
+
/** Returns `true` if the strategy provides pre-computed `inputIds`. */
|
|
121
|
+
export declare function isInputIdStrategy(r: InputStrategy): r is InputIdStrategy;
|
|
122
|
+
/** Returns `true` if the strategy provides explicit `recordViewKeys` (or is the default empty variant). */
|
|
123
|
+
export declare function isRecordViewKeyStrategy(r: InputStrategy): r is RecordViewKeyStrategy;
|