@provablehq/veil-aleo-sdk 0.5.0 → 0.7.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/README.md +148 -11
- package/dist/index.d.ts +126 -17
- package/dist/index.js +274 -22
- package/dist/index.js.map +1 -1
- package/dist/node.d.ts +33 -0
- package/dist/node.js +42 -0
- package/dist/node.js.map +1 -0
- package/dist/provableApi-DsStWMOJ.d.ts +322 -0
- package/package.json +9 -5
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
import { ProvingConfig, Client, WalletActions, RecordProvider } from '@provablehq/veil-core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Credentials issued by the Provable API for a registered consumer.
|
|
5
|
+
*
|
|
6
|
+
* Authenticate delegated proving and the hosted Record Scanner Service. The
|
|
7
|
+
* pair is minted by {@link registerProvableApi} and exchanged for short-lived
|
|
8
|
+
* JWTs.
|
|
9
|
+
*
|
|
10
|
+
* @property consumerId Consumer id. Forms the path segment when minting JWTs.
|
|
11
|
+
* @property apiKey API key. Returned once at registration and unrecoverable
|
|
12
|
+
* afterward, so a caller MUST persist it.
|
|
13
|
+
*/
|
|
14
|
+
type ProvableApiCredentials = {
|
|
15
|
+
consumerId: string;
|
|
16
|
+
apiKey: string;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Persists Provable API credentials between runs.
|
|
20
|
+
*
|
|
21
|
+
* Implemented by the caller — a file, a keychain, `localStorage`, or a secret
|
|
22
|
+
* manager are all valid, and the choice belongs to the runtime rather than to
|
|
23
|
+
* the SDK. A session reads through `load` on first use and writes through
|
|
24
|
+
* `save` exactly once, immediately after registering a new consumer.
|
|
25
|
+
*
|
|
26
|
+
* @property load Reads stored credentials. Returning `undefined` means no
|
|
27
|
+
* consumer is registered yet and triggers registration.
|
|
28
|
+
* @property save Writes credentials. The API key is unrecoverable if this
|
|
29
|
+
* write is lost, so a failure here should propagate rather than be swallowed.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* const store: ProvableCredentialStore = {
|
|
33
|
+
* load: async () => JSON.parse(await readFile(path, 'utf8')).provableApi,
|
|
34
|
+
* save: async (c) => writeFile(path, JSON.stringify({ provableApi: c }), { mode: 0o600 }),
|
|
35
|
+
* }
|
|
36
|
+
*/
|
|
37
|
+
type ProvableCredentialStore = {
|
|
38
|
+
load: () => Promise<ProvableApiCredentials | undefined> | ProvableApiCredentials | undefined;
|
|
39
|
+
save: (credentials: ProvableApiCredentials) => Promise<void> | void;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Builds a credential store that keeps credentials for the life of the process.
|
|
43
|
+
*
|
|
44
|
+
* The default when a client is given no credentials and no store, and the right
|
|
45
|
+
* choice for tests and short-lived workers. Suited to any runtime, since it
|
|
46
|
+
* touches no storage.
|
|
47
|
+
*
|
|
48
|
+
* A consumer registered into this store is lost when the process exits, and its
|
|
49
|
+
* API key is issued once — so a process that registers here and runs again
|
|
50
|
+
* registers a second consumer that nobody can reclaim. Anything longer-lived
|
|
51
|
+
* than a single run belongs in a persistent store: `fileCredentialStore` from
|
|
52
|
+
* `@provablehq/veil-aleo-sdk/node`, or a caller-supplied
|
|
53
|
+
* {@link ProvableCredentialStore}.
|
|
54
|
+
*
|
|
55
|
+
* @param initial Optional credentials to start with, so a caller can seed the
|
|
56
|
+
* store from an environment variable and skip registration.
|
|
57
|
+
* @returns A store backed by a closure variable.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* const store = memoryCredentialStore()
|
|
61
|
+
* // or seeded, in which case nothing registers:
|
|
62
|
+
* const seeded = memoryCredentialStore({ consumerId, apiKey })
|
|
63
|
+
*/
|
|
64
|
+
declare function memoryCredentialStore(initial?: ProvableApiCredentials): ProvableCredentialStore;
|
|
65
|
+
/**
|
|
66
|
+
* A minted Provable API JWT and its expiry.
|
|
67
|
+
*
|
|
68
|
+
* Structurally identical to the Provable SDK's `JWTData` and
|
|
69
|
+
* `RecordScannerJWTData`, so a value of this type passes directly as their
|
|
70
|
+
* `jwtData` option.
|
|
71
|
+
*
|
|
72
|
+
* @property jwt The `Authorization` header value, verbatim as issued by the
|
|
73
|
+
* API (Bearer-prefixed).
|
|
74
|
+
* @property expiration Expiry as milliseconds since the Unix epoch.
|
|
75
|
+
*/
|
|
76
|
+
type ProvableJwt = {
|
|
77
|
+
jwt: string;
|
|
78
|
+
expiration: number;
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* The consumers a session has been wired into.
|
|
82
|
+
*
|
|
83
|
+
* Reported by {@link authenticateProvableApi} so a caller can tell which paths
|
|
84
|
+
* one authentication call actually covers.
|
|
85
|
+
*
|
|
86
|
+
* @property proving Whether a proving configuration carries this session.
|
|
87
|
+
* @property recordScanning Whether a record provider carries this session.
|
|
88
|
+
*/
|
|
89
|
+
type ProvableSessionConsumers = {
|
|
90
|
+
proving: boolean;
|
|
91
|
+
recordScanning: boolean;
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* A live Provable API session: consumer credentials plus a cached, refreshing JWT.
|
|
95
|
+
*
|
|
96
|
+
* Built by `createProvingConfig`, `createRemoteScanner`, and
|
|
97
|
+
* `createAleoClient` from the credential options they are given — a caller
|
|
98
|
+
* configures credentials and does not construct this directly. Sharing one
|
|
99
|
+
* session across delegated proving and record scanning means a single minted
|
|
100
|
+
* JWT and a single refresh policy for both.
|
|
101
|
+
*
|
|
102
|
+
* @property registeredConsumer Reports whether this session registered a new
|
|
103
|
+
* consumer rather than loading an existing one. Only meaningful after
|
|
104
|
+
* credentials have resolved.
|
|
105
|
+
* @property getCredentials Resolves the credentials, registering on first use
|
|
106
|
+
* when neither direct credentials nor a store supply them.
|
|
107
|
+
* @property getJwt Returns a JWT valid for at least the expiry margin,
|
|
108
|
+
* minting or refreshing as needed.
|
|
109
|
+
* @property consumers Which consumers carry this session. Advisory reporting;
|
|
110
|
+
* nothing reads it to make decisions. `recordScanning` is set where a record
|
|
111
|
+
* provider is wired to a client, so sharing one session across several
|
|
112
|
+
* clients under-reports rather than claiming a path a given client lacks.
|
|
113
|
+
* @property attach Records that a consumer now carries this session. Called by
|
|
114
|
+
* the factories during wiring.
|
|
115
|
+
*/
|
|
116
|
+
type ProvableSession = {
|
|
117
|
+
registeredConsumer: () => boolean;
|
|
118
|
+
getCredentials: (options?: {
|
|
119
|
+
username?: string;
|
|
120
|
+
}) => Promise<ProvableApiCredentials>;
|
|
121
|
+
getJwt: (options?: {
|
|
122
|
+
forceRefresh?: boolean;
|
|
123
|
+
}) => Promise<ProvableJwt>;
|
|
124
|
+
consumers: ProvableSessionConsumers;
|
|
125
|
+
attach: (consumer: keyof ProvableSessionConsumers) => void;
|
|
126
|
+
};
|
|
127
|
+
/**
|
|
128
|
+
* Options for {@link registerProvableApi}.
|
|
129
|
+
*
|
|
130
|
+
* @property username Handle for the consumer. Globally unique across the
|
|
131
|
+
* Provable API, so a taken name fails the call.
|
|
132
|
+
* @property baseUrl Optional Provable API root. Defaults to
|
|
133
|
+
* `https://api.provable.com`. Applies when targeting a non-production
|
|
134
|
+
* deployment.
|
|
135
|
+
*/
|
|
136
|
+
type RegisterProvableApiParameters = {
|
|
137
|
+
username: string;
|
|
138
|
+
baseUrl?: string;
|
|
139
|
+
};
|
|
140
|
+
/**
|
|
141
|
+
* Options for {@link createProvableSession}.
|
|
142
|
+
*
|
|
143
|
+
* @property credentials Optional credentials to use directly. Take precedence
|
|
144
|
+
* over `store`, so an operator can inject a rotated or CI-provided pair
|
|
145
|
+
* without clearing persisted state first.
|
|
146
|
+
* @property store Optional persistence for credentials across runs. Omit for a
|
|
147
|
+
* consumer that lives only as long as the process.
|
|
148
|
+
* @property username Optional handle to register under when neither
|
|
149
|
+
* `credentials` nor `store` yields a pair. A function is called lazily, so a
|
|
150
|
+
* caller can derive the name from an account address that is not known at
|
|
151
|
+
* configuration time. Required only if registration may happen.
|
|
152
|
+
* @property baseUrl Optional Provable API root. Defaults to
|
|
153
|
+
* `https://api.provable.com`.
|
|
154
|
+
*/
|
|
155
|
+
type CreateProvableSessionOptions = {
|
|
156
|
+
credentials?: ProvableApiCredentials;
|
|
157
|
+
store?: ProvableCredentialStore;
|
|
158
|
+
username?: string | (() => string);
|
|
159
|
+
baseUrl?: string;
|
|
160
|
+
};
|
|
161
|
+
/**
|
|
162
|
+
* Options for {@link authenticateProvableApi}.
|
|
163
|
+
*
|
|
164
|
+
* @property username Optional handle to register under when the client's
|
|
165
|
+
* configuration yields no credentials. Overrides the name configured on the
|
|
166
|
+
* session.
|
|
167
|
+
* @property forceRefresh Mint a fresh JWT even when the cached one is still
|
|
168
|
+
* valid. Defaults to false. Applies when recovering from a rejected token.
|
|
169
|
+
*/
|
|
170
|
+
type AuthenticateProvableApiParameters = {
|
|
171
|
+
username?: string;
|
|
172
|
+
forceRefresh?: boolean;
|
|
173
|
+
};
|
|
174
|
+
/**
|
|
175
|
+
* Result of {@link authenticateProvableApi}.
|
|
176
|
+
*
|
|
177
|
+
* @property credentials The resolved consumer credentials. Worth persisting
|
|
178
|
+
* when `registered` is true — the API key is unrecoverable afterward.
|
|
179
|
+
* @property expiration Expiry of the minted JWT, as milliseconds since the
|
|
180
|
+
* Unix epoch.
|
|
181
|
+
* @property registered Whether this call registered a new consumer rather than
|
|
182
|
+
* loading an existing one.
|
|
183
|
+
* @property applied Which paths the session reaches. `recordScanning` is false
|
|
184
|
+
* when the client was given a record provider that cannot accept a session —
|
|
185
|
+
* any implementation other than the ones this package builds — in which case
|
|
186
|
+
* that provider keeps using the credentials it was constructed with.
|
|
187
|
+
*/
|
|
188
|
+
type AuthenticateProvableApiReturnType = {
|
|
189
|
+
credentials: ProvableApiCredentials;
|
|
190
|
+
expiration: number;
|
|
191
|
+
registered: boolean;
|
|
192
|
+
applied: ProvableSessionConsumers;
|
|
193
|
+
};
|
|
194
|
+
/**
|
|
195
|
+
* The Provable API authentication action, merged into a client by `extend`.
|
|
196
|
+
*
|
|
197
|
+
* @property authenticateProvableApi Resolves the client's Provable API session.
|
|
198
|
+
*/
|
|
199
|
+
type ProvableApiActions = {
|
|
200
|
+
authenticateProvableApi: (params?: AuthenticateProvableApiParameters) => Promise<AuthenticateProvableApiReturnType>;
|
|
201
|
+
};
|
|
202
|
+
/**
|
|
203
|
+
* A wallet client carrying the Provable API authentication action.
|
|
204
|
+
*
|
|
205
|
+
* Composed inside the client's action set rather than intersected onto
|
|
206
|
+
* `WalletClient`, so a caller who extends further — adding DEX actions, for
|
|
207
|
+
* example — keeps `authenticateProvableApi` in the resulting type. `extend`
|
|
208
|
+
* carries forward only what sits in the action set, so an outer intersection
|
|
209
|
+
* would be dropped on the next call.
|
|
210
|
+
*
|
|
211
|
+
* The wallet half is restated rather than derived. `Omit<WalletClient, keyof
|
|
212
|
+
* Client>` reads better and was tried first, but `keyof Client` resolves to
|
|
213
|
+
* `never` against core's built declarations — so the Omit keeps every base field,
|
|
214
|
+
* violates the `Extended` constraint, and silently collapses to a type missing
|
|
215
|
+
* every wallet action. It typechecks against core's source and fails only for
|
|
216
|
+
* consumers, which is the worst place to find out.
|
|
217
|
+
*
|
|
218
|
+
* Keep this in step if core changes what a wallet client carries; a
|
|
219
|
+
* `WalletClientActions` export from core would remove the duplication safely.
|
|
220
|
+
*/
|
|
221
|
+
type ProvableWalletClient = Client<WalletActions & {
|
|
222
|
+
recordProvider: RecordProvider | undefined;
|
|
223
|
+
} & ProvableApiActions>;
|
|
224
|
+
/**
|
|
225
|
+
* A proving configuration carrying the Provable API session.
|
|
226
|
+
*
|
|
227
|
+
* `createProvingConfig` returns this shape. Core types `Client.proving` as the
|
|
228
|
+
* bare {@link ProvingConfig} and never reads binding-specific fields — `url` and
|
|
229
|
+
* `apiKey` already travel the same way — so the session rides along without a
|
|
230
|
+
* core change, and {@link authenticateProvableApi} narrows to read it.
|
|
231
|
+
*
|
|
232
|
+
* @property session The session shared with record scanning, or `undefined`
|
|
233
|
+
* when the client was configured without credentials.
|
|
234
|
+
*/
|
|
235
|
+
type ProvingConfigWithSession = ProvingConfig & {
|
|
236
|
+
session?: ProvableSession | undefined;
|
|
237
|
+
};
|
|
238
|
+
/**
|
|
239
|
+
* Registers a Provable API consumer and returns its credentials.
|
|
240
|
+
*
|
|
241
|
+
* Unauthenticated — this is the call that issues the credentials everything
|
|
242
|
+
* else authenticates with. Hits the network.
|
|
243
|
+
*
|
|
244
|
+
* A username is spent once. It is globally unique, the API exposes no endpoint
|
|
245
|
+
* that reads a consumer back, and a duplicate registration answers 409 with
|
|
246
|
+
* nothing usable in it — so a taken name cannot be traded for the credentials it
|
|
247
|
+
* belongs to, and the only remedy is the stored key or a different name.
|
|
248
|
+
*
|
|
249
|
+
* @param params Handle to register under, and optionally a non-default API root.
|
|
250
|
+
* @returns The consumer id and API key. The key is shown only here, so the
|
|
251
|
+
* caller MUST persist it.
|
|
252
|
+
* @throws When the username is already registered, when registration returns any
|
|
253
|
+
* other non-2xx status, or when the response body does not carry a consumer id
|
|
254
|
+
* and key.
|
|
255
|
+
*
|
|
256
|
+
* @example
|
|
257
|
+
* const credentials = await registerProvableApi({ username: 'my-bot-42' })
|
|
258
|
+
* await writeFile('creds.json', JSON.stringify(credentials))
|
|
259
|
+
*/
|
|
260
|
+
declare function registerProvableApi(params: RegisterProvableApiParameters): Promise<ProvableApiCredentials>;
|
|
261
|
+
/**
|
|
262
|
+
* Builds a Provable API session that resolves credentials and refreshes its JWT.
|
|
263
|
+
*
|
|
264
|
+
* Credentials resolve on first use — supplied directly, else loaded from the
|
|
265
|
+
* store, else registered and saved. Registration and minting are each
|
|
266
|
+
* single-flighted, so a cold client that proves and scans concurrently
|
|
267
|
+
* registers once and mints once. Pure and local until the first
|
|
268
|
+
* `getCredentials` or `getJwt` call.
|
|
269
|
+
*
|
|
270
|
+
* @param options Credential source, optional persistence, and the name to
|
|
271
|
+
* register under.
|
|
272
|
+
* @returns A session for `createProvingConfig`, `createRemoteScanner`, and
|
|
273
|
+
* `createAleoClient` to share.
|
|
274
|
+
*
|
|
275
|
+
* @example
|
|
276
|
+
* const session = createProvableSession({ store, username: 'my-bot-42' })
|
|
277
|
+
* const { jwt } = await session.getJwt()
|
|
278
|
+
*/
|
|
279
|
+
declare function createProvableSession(options?: CreateProvableSessionOptions): ProvableSession;
|
|
280
|
+
/**
|
|
281
|
+
* Resolves the Provable API session backing delegated proving and record scanning.
|
|
282
|
+
*
|
|
283
|
+
* Registers a consumer when the client's configuration yields none, mints a
|
|
284
|
+
* JWT, and leaves both on the session the client's proving configuration and
|
|
285
|
+
* record provider already hold — so proving and scanning authenticate from then
|
|
286
|
+
* on without further setup. Optional: the first prove or scan resolves the same
|
|
287
|
+
* session lazily. Calling it explicitly front-loads registration, surfaces
|
|
288
|
+
* credential failures before a transaction is built, and returns a newly issued
|
|
289
|
+
* API key at the one moment it is recoverable.
|
|
290
|
+
*
|
|
291
|
+
* Hits the network: registration on first run, plus one JWT mint.
|
|
292
|
+
*
|
|
293
|
+
* @param client A client whose proving configuration carries Provable API
|
|
294
|
+
* credentials or a credential store.
|
|
295
|
+
* @param params Optional registration name and forced refresh.
|
|
296
|
+
* @returns The credentials, the JWT expiry, whether a consumer was registered,
|
|
297
|
+
* and which paths the session reaches.
|
|
298
|
+
* @throws When the client has no Provable API session configured, or when
|
|
299
|
+
* registration or minting fails.
|
|
300
|
+
*
|
|
301
|
+
* @example
|
|
302
|
+
* const { credentials, registered } = await client.authenticateProvableApi()
|
|
303
|
+
* if (registered) await store.save(credentials)
|
|
304
|
+
*/
|
|
305
|
+
declare function authenticateProvableApi(client: Client, params?: AuthenticateProvableApiParameters): Promise<AuthenticateProvableApiReturnType>;
|
|
306
|
+
/**
|
|
307
|
+
* Builds the Provable API auth decorator for `client.extend()`.
|
|
308
|
+
*
|
|
309
|
+
* `createAleoClient` applies this already. Applies directly when composing a
|
|
310
|
+
* client by hand from `createWalletClient` and a proving configuration built
|
|
311
|
+
* with credentials.
|
|
312
|
+
*
|
|
313
|
+
* @returns A decorator: pass it to `client.extend(...)`.
|
|
314
|
+
*
|
|
315
|
+
* @example
|
|
316
|
+
* const client = createWalletClient({ account, transport, proving })
|
|
317
|
+
* .extend(provableApiActions())
|
|
318
|
+
* await client.authenticateProvableApi()
|
|
319
|
+
*/
|
|
320
|
+
declare function provableApiActions(): (client: Client) => ProvableApiActions;
|
|
321
|
+
|
|
322
|
+
export { type AuthenticateProvableApiParameters as A, type CreateProvableSessionOptions as C, type ProvableSession as P, type RegisterProvableApiParameters as R, type ProvingConfigWithSession as a, type ProvableCredentialStore as b, type ProvableWalletClient as c, type AuthenticateProvableApiReturnType as d, type ProvableApiActions as e, type ProvableApiCredentials as f, type ProvableJwt as g, type ProvableSessionConsumers as h, authenticateProvableApi as i, createProvableSession as j, memoryCredentialStore as m, provableApiActions as p, registerProvableApi as r };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@provablehq/veil-aleo-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Local signing and proving for the Veil Aleo SDK, backed by the Provable SDK.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -16,6 +16,10 @@
|
|
|
16
16
|
".": {
|
|
17
17
|
"types": "./dist/index.d.ts",
|
|
18
18
|
"import": "./dist/index.js"
|
|
19
|
+
},
|
|
20
|
+
"./node": {
|
|
21
|
+
"types": "./dist/node.d.ts",
|
|
22
|
+
"import": "./dist/node.js"
|
|
19
23
|
}
|
|
20
24
|
},
|
|
21
25
|
"sideEffects": false,
|
|
@@ -29,16 +33,16 @@
|
|
|
29
33
|
"access": "public"
|
|
30
34
|
},
|
|
31
35
|
"peerDependencies": {
|
|
32
|
-
"@provablehq/veil-core": "
|
|
33
|
-
"@provablehq/veil-aleo-devnode": "
|
|
36
|
+
"@provablehq/veil-core": ">=0.6.0 <1.0.0",
|
|
37
|
+
"@provablehq/veil-aleo-devnode": ">=0.6.0 <1.0.0"
|
|
34
38
|
},
|
|
35
39
|
"dependencies": {
|
|
36
40
|
"@noble/hashes": "^1.7.2",
|
|
37
|
-
"@provablehq/sdk": "^0.11.
|
|
41
|
+
"@provablehq/sdk": "^0.11.6",
|
|
38
42
|
"@scure/bip39": "^1.4.0"
|
|
39
43
|
},
|
|
40
44
|
"devDependencies": {
|
|
41
|
-
"@provablehq/veil-leo": "0.
|
|
45
|
+
"@provablehq/veil-leo": "0.7.0"
|
|
42
46
|
},
|
|
43
47
|
"scripts": {
|
|
44
48
|
"build": "tsup",
|