@provablehq/veil-aleo-sdk 0.9.0 → 0.11.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 +49 -159
- package/dist/index.d.ts +89 -64
- package/dist/index.js +155 -101
- package/dist/index.js.map +1 -1
- package/dist/node.d.ts +1 -1
- package/dist/{provableApi-C4bT37jI.d.ts → provableApi-BTVe8yl5.d.ts} +105 -138
- package/package.json +5 -5
package/dist/node.d.ts
CHANGED
|
@@ -2,15 +2,16 @@ import { ProvingConfig, Client, WalletActions, RecordProvider } from '@provableh
|
|
|
2
2
|
import { ApiAuthConfig } from '@provablehq/sdk';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* Credentials
|
|
5
|
+
* Credentials for the legacy JWT model of the Provable API.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* JWTs.
|
|
7
|
+
* Optional everywhere: the default gateway needs no consumer and mints no JWT.
|
|
8
|
+
* A caller who targets a legacy gateway such as `api.provable.com` passes the
|
|
9
|
+
* pair and the session mints short-lived JWTs from it at that gateway. Nothing
|
|
10
|
+
* registers new consumers anymore. A provisioned key for the default gateway
|
|
11
|
+
* goes through {@link ProvableKeyedAuth} instead.
|
|
10
12
|
*
|
|
11
13
|
* @property consumerId Consumer id. Forms the path segment when minting JWTs.
|
|
12
|
-
* @property apiKey API key.
|
|
13
|
-
* afterward, so a caller MUST persist it.
|
|
14
|
+
* @property apiKey API key. Sent as `X-Provable-API-Key` on the mint.
|
|
14
15
|
*/
|
|
15
16
|
type ProvableApiCredentials = {
|
|
16
17
|
consumerId: string;
|
|
@@ -20,14 +21,12 @@ type ProvableApiCredentials = {
|
|
|
20
21
|
* Persists Provable API credentials between runs.
|
|
21
22
|
*
|
|
22
23
|
* Implemented by the caller — a file, a keychain, `localStorage`, or a secret
|
|
23
|
-
* manager are all valid
|
|
24
|
-
*
|
|
25
|
-
*
|
|
24
|
+
* manager are all valid. A session reads through `load` on first use and never
|
|
25
|
+
* writes: nothing registers anymore, so `save` is only called by callers who
|
|
26
|
+
* seed a store themselves.
|
|
26
27
|
*
|
|
27
|
-
* @property load Reads stored credentials
|
|
28
|
-
*
|
|
29
|
-
* @property save Writes credentials. The API key is unrecoverable if this
|
|
30
|
-
* write is lost, so a failure here should propagate rather than be swallowed.
|
|
28
|
+
* @property load Reads stored credentials, or `undefined` when none are held.
|
|
29
|
+
* @property save Writes credentials. Only reached by a caller seeding the store.
|
|
31
30
|
*
|
|
32
31
|
* @example
|
|
33
32
|
* const store: ProvableCredentialStore = {
|
|
@@ -42,46 +41,36 @@ type ProvableCredentialStore = {
|
|
|
42
41
|
/**
|
|
43
42
|
* Builds a credential store that keeps credentials for the life of the process.
|
|
44
43
|
*
|
|
45
|
-
* The default when a client is given no credentials and no store
|
|
46
|
-
*
|
|
47
|
-
* touches no storage.
|
|
48
|
-
*
|
|
49
|
-
* A consumer registered into this store is lost when the process exits, and its
|
|
50
|
-
* API key is issued once — so a process that registers here and runs again
|
|
51
|
-
* registers a second consumer that nobody can reclaim. Anything longer-lived
|
|
52
|
-
* than a single run belongs in a persistent store: `fileCredentialStore` from
|
|
53
|
-
* `@provablehq/veil-aleo-sdk/node`, or a caller-supplied
|
|
54
|
-
* {@link ProvableCredentialStore}.
|
|
44
|
+
* The default when a client is given no credentials and no store. Suited to any
|
|
45
|
+
* runtime, since it touches no storage.
|
|
55
46
|
*
|
|
56
47
|
* @param initial Optional credentials to start with, so a caller can seed the
|
|
57
|
-
* store from an environment variable
|
|
48
|
+
* store from an environment variable.
|
|
58
49
|
* @returns A store backed by a closure variable.
|
|
59
50
|
*
|
|
60
51
|
* @example
|
|
61
52
|
* const store = memoryCredentialStore()
|
|
62
|
-
* // or seeded
|
|
53
|
+
* // or seeded:
|
|
63
54
|
* const seeded = memoryCredentialStore({ consumerId, apiKey })
|
|
64
55
|
*/
|
|
65
56
|
declare function memoryCredentialStore(initial?: ProvableApiCredentials): ProvableCredentialStore;
|
|
66
57
|
/**
|
|
67
|
-
* Provisioned-key authentication for the
|
|
58
|
+
* Provisioned-key authentication for the Provable API gateway.
|
|
68
59
|
*
|
|
69
60
|
* The keyed variant of the Provable SDK's `ApiAuthConfig`, derived rather
|
|
70
61
|
* than restated so the two cannot drift — values of this type pass straight
|
|
71
62
|
* into the SDK's `RecordScanner` and delegated proving as their `auth`
|
|
72
63
|
* option, where the SDK applies the header default (`DEFAULT_API_KEY_HEADER`).
|
|
73
64
|
*
|
|
74
|
-
* The
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
* and only the operator can issue a replacement.
|
|
65
|
+
* The gateway is unauthenticated by default, so a key is optional. When an
|
|
66
|
+
* operator hands one out, every request carries it verbatim in a header.
|
|
67
|
+
* Nothing registers, persists, or refreshes, and a rejected request (401)
|
|
68
|
+
* means the key is invalid or revoked — retrying cannot help, and only the
|
|
69
|
+
* operator can issue a replacement.
|
|
80
70
|
*
|
|
81
71
|
* Mutually exclusive with the session options (`credentials`, `store`,
|
|
82
|
-
* `username`, `session`): those
|
|
83
|
-
*
|
|
84
|
-
* construction.
|
|
72
|
+
* `username`, `session`): those belong to the legacy JWT model. Combining
|
|
73
|
+
* them throws at construction.
|
|
85
74
|
*
|
|
86
75
|
* @example
|
|
87
76
|
* const auth: ProvableKeyedAuth = { mode: 'api-key', value: process.env.PROVABLE_API_KEY! }
|
|
@@ -108,7 +97,7 @@ type ProvableJwt = {
|
|
|
108
97
|
* The consumers a session has been wired into.
|
|
109
98
|
*
|
|
110
99
|
* Reported by {@link authenticateProvableApi} so a caller can tell which paths
|
|
111
|
-
* one
|
|
100
|
+
* one client's session reaches.
|
|
112
101
|
*
|
|
113
102
|
* @property proving Whether a proving configuration carries this session.
|
|
114
103
|
* @property recordScanning Whether a record provider carries this session.
|
|
@@ -118,25 +107,23 @@ type ProvableSessionConsumers = {
|
|
|
118
107
|
recordScanning: boolean;
|
|
119
108
|
};
|
|
120
109
|
/**
|
|
121
|
-
* A
|
|
110
|
+
* A Provable API session: the configured credentials plus a cached, refreshing JWT.
|
|
122
111
|
*
|
|
123
112
|
* Built by `createProvingConfig`, `createRemoteScanner`, and
|
|
124
113
|
* `createAleoClient` from the credential options they are given — a caller
|
|
125
|
-
* configures credentials and does not construct this directly.
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
*
|
|
114
|
+
* configures credentials and does not construct this directly. With a
|
|
115
|
+
* credential pair and a legacy gateway to mint at, the session mints and
|
|
116
|
+
* refreshes JWTs; otherwise it is inert, since the default gateway needs
|
|
117
|
+
* nothing.
|
|
118
|
+
*
|
|
119
|
+
* @property registeredConsumer Always false; nothing registers anymore.
|
|
120
|
+
* @property getCredentials Resolves the supplied or stored credentials, or
|
|
121
|
+
* `undefined` when the client holds none.
|
|
122
|
+
* @property getJwt Returns a JWT valid for at least the expiry margin, minting
|
|
123
|
+
* or refreshing as needed, or `undefined` when there are no credentials, no
|
|
124
|
+
* legacy gateway to mint at, or the gateway answered the mint with 404.
|
|
136
125
|
* @property consumers Which consumers carry this session. Advisory reporting;
|
|
137
|
-
* nothing reads it to make decisions.
|
|
138
|
-
* provider is wired to a client, so sharing one session across several
|
|
139
|
-
* clients under-reports rather than claiming a path a given client lacks.
|
|
126
|
+
* nothing reads it to make decisions.
|
|
140
127
|
* @property attach Records that a consumer now carries this session. Called by
|
|
141
128
|
* the factories during wiring.
|
|
142
129
|
*/
|
|
@@ -144,24 +131,19 @@ type ProvableSession = {
|
|
|
144
131
|
registeredConsumer: () => boolean;
|
|
145
132
|
getCredentials: (options?: {
|
|
146
133
|
username?: string;
|
|
147
|
-
}) => Promise<ProvableApiCredentials>;
|
|
134
|
+
}) => Promise<ProvableApiCredentials | undefined>;
|
|
148
135
|
getJwt: (options?: {
|
|
149
136
|
forceRefresh?: boolean;
|
|
150
|
-
}) => Promise<ProvableJwt>;
|
|
137
|
+
}) => Promise<ProvableJwt | undefined>;
|
|
151
138
|
consumers: ProvableSessionConsumers;
|
|
152
139
|
attach: (consumer: keyof ProvableSessionConsumers) => void;
|
|
153
140
|
};
|
|
154
141
|
/**
|
|
155
142
|
* Options for {@link registerProvableApi}.
|
|
156
143
|
*
|
|
157
|
-
* @property username Handle
|
|
158
|
-
*
|
|
159
|
-
* @property
|
|
160
|
-
* `https://api.provable.com`. Applies when targeting a non-production
|
|
161
|
-
* deployment.
|
|
162
|
-
* @property transport Optional fetch-compatible transport for the request.
|
|
163
|
-
* Defaults to the global `fetch`. Applies when a caller intercepts or
|
|
164
|
-
* instruments HTTP — a proxy, a recorder, a test stub.
|
|
144
|
+
* @property username Handle the retired flow registered under. Ignored.
|
|
145
|
+
* @property baseUrl Ignored; kept so existing calls compile.
|
|
146
|
+
* @property transport Ignored; kept so existing calls compile.
|
|
165
147
|
*/
|
|
166
148
|
type RegisterProvableApiParameters = {
|
|
167
149
|
username: string;
|
|
@@ -171,21 +153,18 @@ type RegisterProvableApiParameters = {
|
|
|
171
153
|
/**
|
|
172
154
|
* Options for {@link createProvableSession}.
|
|
173
155
|
*
|
|
174
|
-
* @property credentials Optional credentials to
|
|
175
|
-
* over `store`, so an operator can inject a rotated
|
|
176
|
-
*
|
|
177
|
-
* @property store Optional
|
|
178
|
-
*
|
|
179
|
-
* @property
|
|
180
|
-
*
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
* @property
|
|
184
|
-
* `
|
|
185
|
-
*
|
|
186
|
-
* registration and JWT minting. Defaults to the global `fetch`. Applies
|
|
187
|
-
* when a caller intercepts or instruments HTTP — a proxy, a recorder, a
|
|
188
|
-
* test stub.
|
|
156
|
+
* @property credentials Optional credentials to mint from. Take precedence
|
|
157
|
+
* over `store`, so an operator can inject a rotated pair without clearing
|
|
158
|
+
* persisted state first.
|
|
159
|
+
* @property store Optional store to read credentials from. Never written.
|
|
160
|
+
* @property username Ignored; nothing registers anymore.
|
|
161
|
+
* @property baseUrl Optional root of a legacy gateway that serves `/jwts`,
|
|
162
|
+
* such as `https://api.provable.com`. Without it the session mints nothing,
|
|
163
|
+
* because the default gateway has no JWT route. The factories derive it from
|
|
164
|
+
* the prover or scanner URL the caller configured.
|
|
165
|
+
* @property transport Optional fetch-compatible transport for the mint.
|
|
166
|
+
* Defaults to the global `fetch`. Applies when a caller intercepts or
|
|
167
|
+
* instruments HTTP — a proxy, a recorder, a test stub.
|
|
189
168
|
*/
|
|
190
169
|
type CreateProvableSessionOptions = {
|
|
191
170
|
credentials?: ProvableApiCredentials;
|
|
@@ -197,11 +176,10 @@ type CreateProvableSessionOptions = {
|
|
|
197
176
|
/**
|
|
198
177
|
* Options for {@link authenticateProvableApi}.
|
|
199
178
|
*
|
|
200
|
-
* @property username
|
|
201
|
-
* configuration yields no credentials. Overrides the name configured on the
|
|
202
|
-
* session.
|
|
179
|
+
* @property username Ignored; nothing registers anymore.
|
|
203
180
|
* @property forceRefresh Mint a fresh JWT even when the cached one is still
|
|
204
181
|
* valid. Defaults to false. Applies when recovering from a rejected token.
|
|
182
|
+
* No effect without credentials.
|
|
205
183
|
*/
|
|
206
184
|
type AuthenticateProvableApiParameters = {
|
|
207
185
|
username?: string;
|
|
@@ -210,20 +188,17 @@ type AuthenticateProvableApiParameters = {
|
|
|
210
188
|
/**
|
|
211
189
|
* Result of {@link authenticateProvableApi}.
|
|
212
190
|
*
|
|
213
|
-
* @property credentials The
|
|
214
|
-
*
|
|
191
|
+
* @property credentials The credentials the client was configured with, or
|
|
192
|
+
* `undefined` when it holds none.
|
|
215
193
|
* @property expiration Expiry of the minted JWT, as milliseconds since the
|
|
216
|
-
* Unix epoch.
|
|
217
|
-
* @property registered
|
|
218
|
-
*
|
|
219
|
-
*
|
|
220
|
-
* when the client was given a record provider that cannot accept a session —
|
|
221
|
-
* any implementation other than the ones this package builds — in which case
|
|
222
|
-
* that provider keeps using the credentials it was constructed with.
|
|
194
|
+
* Unix epoch, or `undefined` when nothing mints one.
|
|
195
|
+
* @property registered Always false; nothing registers anymore.
|
|
196
|
+
* @property applied Which paths the client's session reaches. All false for a
|
|
197
|
+
* keyed client or a client built without a session.
|
|
223
198
|
*/
|
|
224
199
|
type AuthenticateProvableApiReturnType = {
|
|
225
|
-
credentials: ProvableApiCredentials;
|
|
226
|
-
expiration: number;
|
|
200
|
+
credentials: ProvableApiCredentials | undefined;
|
|
201
|
+
expiration: number | undefined;
|
|
227
202
|
registered: boolean;
|
|
228
203
|
applied: ProvableSessionConsumers;
|
|
229
204
|
};
|
|
@@ -276,79 +251,71 @@ type ProvingConfigWithSession = ProvingConfig & {
|
|
|
276
251
|
keyedAuth?: ProvableKeyedAuth | undefined;
|
|
277
252
|
};
|
|
278
253
|
/**
|
|
279
|
-
*
|
|
280
|
-
*
|
|
281
|
-
* Unauthenticated — this is the call that issues the credentials everything
|
|
282
|
-
* else authenticates with. Hits the network.
|
|
254
|
+
* Formerly registered a Provable API consumer. Now a no-op.
|
|
283
255
|
*
|
|
284
|
-
*
|
|
285
|
-
*
|
|
286
|
-
* nothing usable in it — so a taken name cannot be traded for the credentials it
|
|
287
|
-
* belongs to, and the only remedy is the stored key or a different name.
|
|
256
|
+
* The default gateway needs no consumer, and the legacy gateway issues no new
|
|
257
|
+
* ones through this SDK. Resolves without contacting the network.
|
|
288
258
|
*
|
|
289
|
-
* @
|
|
290
|
-
*
|
|
291
|
-
*
|
|
292
|
-
* @
|
|
293
|
-
*
|
|
294
|
-
* and key.
|
|
259
|
+
* @deprecated Consumer registration is retired. Remove the call; pass a
|
|
260
|
+
* consumer pair the caller already holds, or a provisioned key through
|
|
261
|
+
* `auth`.
|
|
262
|
+
* @param params Ignored.
|
|
263
|
+
* @returns `undefined`.
|
|
295
264
|
*
|
|
296
265
|
* @example
|
|
297
266
|
* const credentials = await registerProvableApi({ username: 'my-bot-42' })
|
|
298
|
-
*
|
|
267
|
+
* // credentials is undefined
|
|
299
268
|
*/
|
|
300
|
-
declare function registerProvableApi(params: RegisterProvableApiParameters): Promise<ProvableApiCredentials>;
|
|
269
|
+
declare function registerProvableApi(params: RegisterProvableApiParameters): Promise<ProvableApiCredentials | undefined>;
|
|
301
270
|
/**
|
|
302
|
-
* Builds a Provable API session that
|
|
303
|
-
*
|
|
304
|
-
* Credentials
|
|
305
|
-
*
|
|
306
|
-
* single-
|
|
307
|
-
*
|
|
308
|
-
* `
|
|
309
|
-
*
|
|
310
|
-
*
|
|
311
|
-
*
|
|
271
|
+
* Builds a Provable API session that mints JWTs from the credentials it is given.
|
|
272
|
+
*
|
|
273
|
+
* Credentials come from `credentials` or, failing that, from the store. With a
|
|
274
|
+
* pair and a `baseUrl` the session mints a JWT on first use and refreshes it
|
|
275
|
+
* near expiry, single-flighting concurrent mints so a cold client that proves
|
|
276
|
+
* and scans together mints once. Without either it is inert: `getJwt` resolves
|
|
277
|
+
* to `undefined` and nothing is requested, because the default gateway needs
|
|
278
|
+
* no token. A root that answers the mint with 404 has no JWT route — a devnode,
|
|
279
|
+
* a self-hosted edge — and the session goes inert from then on rather than
|
|
280
|
+
* failing a client that never needed a token. Nothing registers a consumer in
|
|
281
|
+
* any case.
|
|
282
|
+
*
|
|
283
|
+
* @param options Credential source, legacy mint root, and transport.
|
|
312
284
|
* @returns A session for `createProvingConfig`, `createRemoteScanner`, and
|
|
313
285
|
* `createAleoClient` to share.
|
|
314
286
|
*
|
|
315
287
|
* @example
|
|
316
|
-
* const session = createProvableSession({
|
|
317
|
-
*
|
|
288
|
+
* const session = createProvableSession({
|
|
289
|
+
* credentials: { consumerId, apiKey },
|
|
290
|
+
* baseUrl: 'https://api.provable.com',
|
|
291
|
+
* })
|
|
292
|
+
* const jwt = await session.getJwt()
|
|
318
293
|
*/
|
|
319
294
|
declare function createProvableSession(options?: CreateProvableSessionOptions): ProvableSession;
|
|
320
295
|
/**
|
|
321
296
|
* Resolves the Provable API session backing delegated proving and record scanning.
|
|
322
297
|
*
|
|
323
|
-
*
|
|
324
|
-
*
|
|
325
|
-
*
|
|
326
|
-
*
|
|
327
|
-
*
|
|
328
|
-
* credential failures before a transaction is built, and returns a newly issued
|
|
329
|
-
* API key at the one moment it is recoverable.
|
|
330
|
-
*
|
|
331
|
-
* Hits the network: registration on first run, plus one JWT mint.
|
|
298
|
+
* With a credential pair aimed at a legacy gateway this mints the JWT eagerly,
|
|
299
|
+
* so a bad key fails before a transaction is built, and reports the expiry.
|
|
300
|
+
* Otherwise it is a no-op: the default gateway needs no token, so a keyed,
|
|
301
|
+
* credential-less, or default-gateway client resolves immediately with no
|
|
302
|
+
* expiry. Never throws for lack of a session, and never registers a consumer.
|
|
332
303
|
*
|
|
333
|
-
* @param client
|
|
334
|
-
*
|
|
335
|
-
* @
|
|
336
|
-
*
|
|
337
|
-
*
|
|
338
|
-
* @throws When the client has no Provable API session configured, or when
|
|
339
|
-
* registration or minting fails.
|
|
304
|
+
* @param client Any client.
|
|
305
|
+
* @param params Optional forced refresh; `username` is ignored.
|
|
306
|
+
* @returns The configured credentials or `undefined`, the JWT expiry or
|
|
307
|
+
* `undefined`, `registered` false, and which paths the session reaches.
|
|
308
|
+
* @throws When a configured pair fails to mint.
|
|
340
309
|
*
|
|
341
310
|
* @example
|
|
342
|
-
* const {
|
|
343
|
-
* if (registered) await store.save(credentials)
|
|
311
|
+
* const { expiration, applied } = await client.authenticateProvableApi()
|
|
344
312
|
*/
|
|
345
313
|
declare function authenticateProvableApi(client: Client, params?: AuthenticateProvableApiParameters): Promise<AuthenticateProvableApiReturnType>;
|
|
346
314
|
/**
|
|
347
315
|
* Builds the Provable API auth decorator for `client.extend()`.
|
|
348
316
|
*
|
|
349
317
|
* `createAleoClient` applies this already. Applies directly when composing a
|
|
350
|
-
* client by hand from `createWalletClient` and a proving configuration
|
|
351
|
-
* with credentials.
|
|
318
|
+
* client by hand from `createWalletClient` and a proving configuration.
|
|
352
319
|
*
|
|
353
320
|
* @returns A decorator: pass it to `client.extend(...)`.
|
|
354
321
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@provablehq/veil-aleo-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.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": {
|
|
@@ -33,16 +33,16 @@
|
|
|
33
33
|
"access": "public"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"@provablehq/veil-core": ">=0.
|
|
37
|
-
"@provablehq/veil-aleo-devnode": ">=0.
|
|
36
|
+
"@provablehq/veil-core": ">=0.11.0 <1.0.0",
|
|
37
|
+
"@provablehq/veil-aleo-devnode": ">=0.11.0 <1.0.0"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@noble/hashes": "^1.7.2",
|
|
41
|
-
"@provablehq/sdk": "^0.11.
|
|
41
|
+
"@provablehq/sdk": "^0.11.10",
|
|
42
42
|
"@scure/bip39": "^1.4.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@provablehq/veil-leo": "0.
|
|
45
|
+
"@provablehq/veil-leo": "0.11.0"
|
|
46
46
|
},
|
|
47
47
|
"scripts": {
|
|
48
48
|
"build": "tsup",
|