@provablehq/veil-aleo-sdk 0.6.0 → 0.7.1
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 +171 -11
- package/dist/index.d.ts +153 -17
- package/dist/index.js +370 -26
- package/dist/index.js.map +1 -1
- package/dist/node.d.ts +34 -0
- package/dist/node.js +42 -0
- package/dist/node.js.map +1 -0
- package/dist/provableApi-C4bT37jI.d.ts +362 -0
- package/package.json +9 -5
package/README.md
CHANGED
|
@@ -31,27 +31,37 @@ const aleo = await loadNetwork('testnet')
|
|
|
31
31
|
// A record scanner so the wallet client can find the private records that
|
|
32
32
|
// program calls spend. The first requestRecords registers the view key with the
|
|
33
33
|
// service (one network round-trip); later calls reuse it.
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
consumerId: CONSUMER_ID,
|
|
37
|
-
apiKey: DPS_API_KEY, // authenticates + registers the view key for scanning
|
|
38
|
-
})
|
|
34
|
+
// `url` defaults to Provable's hosted scanner, so this needs no arguments.
|
|
35
|
+
const scanner = aleo.createRemoteScanner()
|
|
39
36
|
|
|
40
37
|
// A fully-wired client pair: an account from the private key, a public client
|
|
41
|
-
// for reads, and a wallet client with proving + the scanner attached.
|
|
38
|
+
// for reads, and a wallet client with proving + the scanner attached. The
|
|
39
|
+
// credential store holds one Provable API session shared by proving and
|
|
40
|
+
// scanning — it registers a consumer on the first run and reuses it after.
|
|
41
|
+
import { fileCredentialStore } from '@provablehq/veil-aleo-sdk/node'
|
|
42
|
+
|
|
42
43
|
const { publicClient, walletClient, account } = aleo.createAleoClient({
|
|
43
44
|
privateKey: PRIVATE_KEY,
|
|
44
45
|
networkUrl: 'https://api.provable.com/v2',
|
|
45
|
-
|
|
46
|
-
proverUrl: 'https://api.provable.com/prove/testnet',
|
|
47
|
-
apiKey: DPS_API_KEY,
|
|
48
|
-
consumerId: CONSUMER_ID,
|
|
46
|
+
credentialStore: fileCredentialStore('./.provable-credentials.json'),
|
|
49
47
|
records: scanner,
|
|
50
48
|
})
|
|
51
49
|
|
|
52
50
|
account.address // 'aleo1...'
|
|
53
51
|
```
|
|
54
52
|
|
|
53
|
+
No API key appears above: the store registers a Provable API consumer the first
|
|
54
|
+
time something needs one and reuses it from then on. Already hold credentials?
|
|
55
|
+
Pass `consumerId` and `apiKey` instead and drop the store — see
|
|
56
|
+
[Provable API credentials](#provable-api-credentials).
|
|
57
|
+
|
|
58
|
+
`proverUrl` is a base URL — the active network is appended, the same way the
|
|
59
|
+
record scanner's `url` works — so `switchChain` re-targets proving instead of
|
|
60
|
+
leaving it on the network the client started from. Do not include the network
|
|
61
|
+
segment yourself. It defaults to Provable's hosted prover
|
|
62
|
+
(`DEFAULT_PROVER_URL`) under delegated proving, so the option only needs setting
|
|
63
|
+
for a self-hosted one.
|
|
64
|
+
|
|
55
65
|
Pass `provingMode: 'local'` to prove in-process instead of delegating to a prover
|
|
56
66
|
service (drop `proverUrl`/`apiKey`/`consumerId`). The `walletClient` composes with
|
|
57
67
|
action packages the same way a wallet-backed client does:
|
|
@@ -60,10 +70,137 @@ action packages the same way a wallet-backed client does:
|
|
|
60
70
|
import { shieldSwapActions } from '@provablehq/shield-swap-sdk'
|
|
61
71
|
|
|
62
72
|
const client = walletClient.extend(
|
|
63
|
-
shieldSwapActions({ api: {
|
|
73
|
+
shieldSwapActions({ api: {} }),
|
|
64
74
|
)
|
|
65
75
|
```
|
|
66
76
|
|
|
77
|
+
## Provable API credentials
|
|
78
|
+
|
|
79
|
+
Delegated proving and the hosted record scanner both authenticate with a consumer
|
|
80
|
+
id and API key, which the SDK exchanges for short-lived JWTs. A client builds a
|
|
81
|
+
single session covering both services, so one credential mints one token instead
|
|
82
|
+
of each service minting its own.
|
|
83
|
+
|
|
84
|
+
Where that credential comes from is the only decision. Three options:
|
|
85
|
+
|
|
86
|
+
| | Use when | Registers? |
|
|
87
|
+
| --- | --- | --- |
|
|
88
|
+
| `fileCredentialStore(path)` from `/node` | Bots, scripts, servers, CI that can write to disk | On first run, then reuses |
|
|
89
|
+
| `consumerId` + `apiKey` | You already hold credentials — from a secret manager or env | Never |
|
|
90
|
+
| `memoryCredentialStore()` (the default) | Tests, ephemeral workers | Every process, key discarded at exit |
|
|
91
|
+
|
|
92
|
+
`memoryCredentialStore()` is what a client falls back to when given neither, so
|
|
93
|
+
delegated proving works with no configuration at all. It is only appropriate for
|
|
94
|
+
a single short run: the API issues each key exactly once, so a process that
|
|
95
|
+
registers into memory and runs again registers a second consumer nobody can
|
|
96
|
+
reclaim. Anything long-lived wants a persistent store.
|
|
97
|
+
|
|
98
|
+
The session resolves on the first prove or scan. `authenticateProvableApi()` does
|
|
99
|
+
it eagerly, which is worth doing at startup so a bad key fails before you have
|
|
100
|
+
built a transaction:
|
|
101
|
+
|
|
102
|
+
```ts
|
|
103
|
+
const { credentials, expiration, registered, applied } =
|
|
104
|
+
await walletClient.authenticateProvableApi()
|
|
105
|
+
|
|
106
|
+
applied // { proving: true, recordScanning: true }
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
`applied` reports which paths the session actually reaches. `recordScanning` is
|
|
110
|
+
`false` when the client was given a record provider it cannot share a session
|
|
111
|
+
with — any implementation other than the ones this package builds — in which case
|
|
112
|
+
that provider keeps using whatever credentials it was constructed with.
|
|
113
|
+
|
|
114
|
+
If you do not have credentials yet, register a consumer once. The API key is
|
|
115
|
+
issued exactly once and cannot be recovered, so persist it immediately:
|
|
116
|
+
|
|
117
|
+
```ts
|
|
118
|
+
import { registerProvableApi } from '@provablehq/veil-aleo-sdk'
|
|
119
|
+
|
|
120
|
+
const credentials = await registerProvableApi({ username: 'my-bot-42' })
|
|
121
|
+
await writeFile('creds.json', JSON.stringify(credentials), { mode: 0o600 })
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
A username is spent once. It is globally unique, the API exposes no endpoint that
|
|
125
|
+
reads a consumer back, and a duplicate registration answers 409 with nothing
|
|
126
|
+
usable in it — so a taken name cannot be traded for the credentials it belongs to.
|
|
127
|
+
The stored key is the only copy, which is the real reason to give a client a
|
|
128
|
+
persistent store rather than the in-memory default.
|
|
129
|
+
|
|
130
|
+
When a client registers for you, `username` chooses the name:
|
|
131
|
+
|
|
132
|
+
```ts
|
|
133
|
+
const { walletClient } = aleo.createAleoClient({
|
|
134
|
+
privateKey: PRIVATE_KEY,
|
|
135
|
+
networkUrl: 'https://api.provable.com/v2',
|
|
136
|
+
proverUrl: 'https://api.provable.com/prove',
|
|
137
|
+
credentialStore: fileCredentialStore('./.provable-credentials.json'),
|
|
138
|
+
username: 'my-bot-42', // or () => `bot-${shard}`, resolved at registration
|
|
139
|
+
})
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Supplied names are used verbatim, so the consumer is identifiable in your account
|
|
143
|
+
— and a collision fails with an error saying the name is taken rather than quietly
|
|
144
|
+
registering something else. Omit it and the name is derived from the account
|
|
145
|
+
address with a random suffix, which keeps the zero-configuration path working:
|
|
146
|
+
since a username cannot be reused, an account that lost its stored key still needs
|
|
147
|
+
to be able to register.
|
|
148
|
+
|
|
149
|
+
On Node, `fileCredentialStore` covers this. It writes with mode `0600`, treats a
|
|
150
|
+
missing file as "not registered yet", and reports a corrupt one rather than
|
|
151
|
+
registering over credentials that might still be recoverable by hand. It lives on
|
|
152
|
+
the `/node` subpath so the `node:fs` import never reaches a browser bundle:
|
|
153
|
+
|
|
154
|
+
```ts
|
|
155
|
+
import { fileCredentialStore } from '@provablehq/veil-aleo-sdk/node'
|
|
156
|
+
|
|
157
|
+
const { walletClient } = aleo.createAleoClient({
|
|
158
|
+
privateKey: PRIVATE_KEY,
|
|
159
|
+
networkUrl: 'https://api.provable.com/v2',
|
|
160
|
+
proverUrl: 'https://api.provable.com/prove',
|
|
161
|
+
credentialStore: fileCredentialStore('./.provable-credentials.json'),
|
|
162
|
+
records: scanner,
|
|
163
|
+
})
|
|
164
|
+
|
|
165
|
+
const { registered } = await walletClient.authenticateProvableApi()
|
|
166
|
+
registered // true on the first run, false afterward
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
Anywhere else, implement the two-method interface yourself — a keychain,
|
|
170
|
+
`localStorage`, IndexedDB, or a secret manager all satisfy it, and the SDK assumes
|
|
171
|
+
nothing about which:
|
|
172
|
+
|
|
173
|
+
```ts
|
|
174
|
+
import type { ProvableCredentialStore } from '@provablehq/veil-aleo-sdk'
|
|
175
|
+
|
|
176
|
+
const credentialStore: ProvableCredentialStore = {
|
|
177
|
+
load: () => {
|
|
178
|
+
const raw = localStorage.getItem('provable-credentials')
|
|
179
|
+
return raw ? JSON.parse(raw) : undefined // undefined → register
|
|
180
|
+
},
|
|
181
|
+
save: (c) => localStorage.setItem('provable-credentials', JSON.stringify(c)),
|
|
182
|
+
}
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
Two rules for a hand-written store. `load` MUST return `undefined` rather than
|
|
186
|
+
throw when nothing is stored, or resolution fails instead of registering. And
|
|
187
|
+
`save` must actually persist: it runs before the credentials are handed back
|
|
188
|
+
precisely so a failed write fails the call, since a swallowed one orphans a
|
|
189
|
+
consumer whose key cannot be reissued. That also means a genuinely read-only
|
|
190
|
+
environment should supply `consumerId`/`apiKey` directly rather than rely on
|
|
191
|
+
registration.
|
|
192
|
+
|
|
193
|
+
An explicit `consumerId`/`apiKey` pair takes precedence over the store, so an
|
|
194
|
+
operator can inject a rotated key or CI credentials without clearing persisted
|
|
195
|
+
state first.
|
|
196
|
+
|
|
197
|
+
One caveat on the mint itself: the API does not validate the consumer id against
|
|
198
|
+
the API key. A mismatched id still yields a working token, because the token's
|
|
199
|
+
issuer comes from the key. The mismatch surfaces later as a rejection from the
|
|
200
|
+
service you call — the record scanner reports it as `No credentials found for
|
|
201
|
+
given 'iss'`. Nothing in the mint path can catch that for you, so keep the pair
|
|
202
|
+
together.
|
|
203
|
+
|
|
67
204
|
The handle also exposes the pieces individually when the caller does not want the
|
|
68
205
|
full pair:
|
|
69
206
|
|
|
@@ -80,6 +217,29 @@ For local iteration without a live chain, `createDevnodeClient()` returns the
|
|
|
80
217
|
same client pair pointed at an Aleo Devnode instance with a pre-funded seeded
|
|
81
218
|
account.
|
|
82
219
|
|
|
220
|
+
## Provisioned API keys (edge gateway)
|
|
221
|
+
|
|
222
|
+
The edge gateway (`edge.provable.com`) runs a different auth model: no consumer
|
|
223
|
+
registration and no JWTs. An operator hands out an API key, and every request
|
|
224
|
+
carries it verbatim in an `X-API-Key` header. Configure it with `auth` instead
|
|
225
|
+
of the consumer options:
|
|
226
|
+
|
|
227
|
+
```ts
|
|
228
|
+
const { walletClient } = aleo.createAleoClient({
|
|
229
|
+
privateKey,
|
|
230
|
+
networkUrl: 'https://edge.provable.com/api/v2',
|
|
231
|
+
proverUrl: 'https://edge.provable.com/api/prove',
|
|
232
|
+
records: aleo.createRemoteScanner({ url: 'https://edge.provable.com/api/scanner' }),
|
|
233
|
+
auth: { mode: 'api-key', value: process.env.PROVABLE_API_KEY! },
|
|
234
|
+
})
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
The two models are mutually exclusive: combining `auth` with `apiKey`,
|
|
238
|
+
`consumerId`, `username`, `credentialStore`, or `session` throws at
|
|
239
|
+
construction. There is no session under keyed auth — nothing registers,
|
|
240
|
+
persists, or refreshes — so `authenticateProvableApi()` throws, and a 401
|
|
241
|
+
means the key is invalid or revoked, which only the operator can fix.
|
|
242
|
+
|
|
83
243
|
## WASM dependency
|
|
84
244
|
|
|
85
245
|
`@provablehq/sdk` ships the Aleo cryptography as WebAssembly, and this package
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { loadNetwork as loadNetwork$1 } from '@provablehq/sdk/dynamic.js';
|
|
2
2
|
export { DEVNODE_ADDR, DEVNODE_PRIVATE_KEY } from '@provablehq/veil-aleo-devnode';
|
|
3
|
-
import { LocalAccount,
|
|
3
|
+
import { LocalAccount, RecordProvider, StandaloneRecordScanner, PublicClient, WalletClient } from '@provablehq/veil-core';
|
|
4
|
+
import { P as ProvableSession, a as ProvableKeyedAuth, b as ProvingConfigWithSession, c as ProvableCredentialStore, d as ProvableWalletClient } from './provableApi-C4bT37jI.js';
|
|
5
|
+
export { A as AuthenticateProvableApiParameters, e as AuthenticateProvableApiReturnType, C as CreateProvableSessionOptions, f as ProvableApiActions, g as ProvableApiCredentials, h as ProvableJwt, i as ProvableSessionConsumers, R as RegisterProvableApiParameters, j as authenticateProvableApi, k as createProvableSession, m as memoryCredentialStore, p as provableApiActions, r as registerProvableApi } from './provableApi-C4bT37jI.js';
|
|
6
|
+
import '@provablehq/sdk';
|
|
4
7
|
|
|
5
8
|
/**
|
|
6
9
|
* Names the derivation-path convention used to turn a seed into Aleo keys.
|
|
@@ -162,6 +165,20 @@ declare function mnemonicToHDKey(mnemonic: string, options?: {
|
|
|
162
165
|
|
|
163
166
|
/** Networks supported by `@provablehq/sdk/dynamic.js`. */
|
|
164
167
|
type SupportedNetwork = 'mainnet' | 'testnet';
|
|
168
|
+
/**
|
|
169
|
+
* Base URL of Provable's hosted delegated proving service.
|
|
170
|
+
*
|
|
171
|
+
* The default `proverUrl` for `mode: 'delegated'`. A base, so the active network
|
|
172
|
+
* is appended — which is what lets `switchChain` re-target proving.
|
|
173
|
+
*/
|
|
174
|
+
declare const DEFAULT_PROVER_URL = "https://api.provable.com/prove";
|
|
175
|
+
/**
|
|
176
|
+
* Base URL of Provable's hosted Record Scanner Service.
|
|
177
|
+
*
|
|
178
|
+
* The default `url` for both scanner factories. A base — the SDK appends the
|
|
179
|
+
* network segment, which is what lets a scanner follow `switchChain`.
|
|
180
|
+
*/
|
|
181
|
+
declare const DEFAULT_SCANNER_URL = "https://api.provable.com/scanner";
|
|
165
182
|
type SdkModule = Awaited<ReturnType<typeof loadNetwork$1<'testnet'>>>;
|
|
166
183
|
/**
|
|
167
184
|
* A network-bound SDK handle. All functions on this handle use the binary
|
|
@@ -222,7 +239,26 @@ interface AleoSdk {
|
|
|
222
239
|
verifySignature(address: string, message: Uint8Array, signature: string): boolean;
|
|
223
240
|
/** Creates an `AleoNetworkClient` for direct SDK access. */
|
|
224
241
|
createNetworkClient(url: string): InstanceType<SdkModule['AleoNetworkClient']>;
|
|
225
|
-
/**
|
|
242
|
+
/**
|
|
243
|
+
* Creates a `ProvingConfig` for `createWalletClient({ proving })`.
|
|
244
|
+
*
|
|
245
|
+
* @param options.proverUrl Base URL of the delegated proving service — the
|
|
246
|
+
* network segment is appended, so do not include it. That is what lets
|
|
247
|
+
* `switchChain` re-target proving instead of leaving it on the network the
|
|
248
|
+
* client started from. A base that already ends in `/mainnet` or `/testnet`
|
|
249
|
+
* is re-targeted rather than doubled. Defaults to
|
|
250
|
+
* {@link DEFAULT_PROVER_URL} under `mode: 'delegated'`; unused under
|
|
251
|
+
* `mode: 'local'`, which reaches no prover.
|
|
252
|
+
* @param options.session Optional Provable API session. When present the
|
|
253
|
+
* configuration authenticates from it and withholds `apiKey`/`consumerId`
|
|
254
|
+
* from the prover client, so one party mints JWTs. The session is attached
|
|
255
|
+
* to the returned configuration, which is what lets
|
|
256
|
+
* `authenticateProvableApi` find it on a client.
|
|
257
|
+
* @param options.auth Optional provisioned-key auth for the edge gateway.
|
|
258
|
+
* Every proving request carries the key verbatim; nothing registers or
|
|
259
|
+
* mints, and a 401 is terminal. Mutually exclusive with `session`,
|
|
260
|
+
* `apiKey`, and `consumerId` — combining them throws.
|
|
261
|
+
*/
|
|
226
262
|
createProvingConfig(options: {
|
|
227
263
|
mode: 'delegated' | 'local';
|
|
228
264
|
networkUrl: string;
|
|
@@ -232,7 +268,9 @@ interface AleoSdk {
|
|
|
232
268
|
account?: LocalAccount<'privateKey'>;
|
|
233
269
|
confirmationTimeout?: number;
|
|
234
270
|
useFeeMaster?: boolean;
|
|
235
|
-
|
|
271
|
+
session?: ProvableSession;
|
|
272
|
+
auth?: ProvableKeyedAuth;
|
|
273
|
+
}): ProvingConfigWithSession;
|
|
236
274
|
/**
|
|
237
275
|
* Creates a record scanner backed by Provable's Record Scanner Service.
|
|
238
276
|
*
|
|
@@ -245,41 +283,131 @@ interface AleoSdk {
|
|
|
245
283
|
* against the new network and re-registers lazily on the next scan.
|
|
246
284
|
*
|
|
247
285
|
* @param options.url Base URL of the service (the SDK appends the network
|
|
248
|
-
* segment — do not include it).
|
|
249
|
-
* @param options.consumerId
|
|
286
|
+
* segment — do not include it). Defaults to {@link DEFAULT_SCANNER_URL}.
|
|
287
|
+
* @param options.consumerId Optional consumer id used for JWT refresh.
|
|
288
|
+
* Unnecessary when a `session` supplies the token. Required alongside
|
|
289
|
+
* `apiKey` otherwise — a JWT is minted from the pair, so half of it
|
|
290
|
+
* authenticates nothing and construction throws rather than 401ing later.
|
|
250
291
|
* @param options.apiKey Optional API key for the authenticated service
|
|
251
292
|
* (e.g. the hosted Provable RSS). Omit for an open/unauthenticated service.
|
|
293
|
+
* @param options.session Optional Provable API session to authenticate from,
|
|
294
|
+
* shared with delegated proving. `createAleoClient` supplies its own
|
|
295
|
+
* session through `setSession` on the returned provider, so a caller who
|
|
296
|
+
* passes the scanner to that factory does not need this.
|
|
252
297
|
* @param options.startBlock Optional block height to begin scanning from at
|
|
253
298
|
* registration. Defaults to 0 (full history).
|
|
299
|
+
* @param options.auth Optional provisioned-key auth for the edge gateway.
|
|
300
|
+
* Every scan carries the key verbatim; nothing registers or mints, and a
|
|
301
|
+
* 401 is terminal. Mutually exclusive with `session`, `apiKey`, and
|
|
302
|
+
* `consumerId` — combining them throws.
|
|
303
|
+
* @returns The provider, plus `setSession` and `setAuth` for a factory to
|
|
304
|
+
* share one credential source across proving and scanning after
|
|
305
|
+
* construction.
|
|
254
306
|
*/
|
|
255
|
-
createRemoteScanner(options
|
|
256
|
-
url
|
|
257
|
-
consumerId
|
|
307
|
+
createRemoteScanner(options?: {
|
|
308
|
+
url?: string;
|
|
309
|
+
consumerId?: string;
|
|
258
310
|
apiKey?: string;
|
|
311
|
+
session?: ProvableSession;
|
|
259
312
|
startBlock?: number;
|
|
260
|
-
|
|
313
|
+
auth?: ProvableKeyedAuth;
|
|
314
|
+
}): RecordProvider & {
|
|
315
|
+
setSession: (session: ProvableSession) => void;
|
|
316
|
+
setAuth: (auth: ProvableKeyedAuth) => void;
|
|
317
|
+
};
|
|
261
318
|
/**
|
|
262
319
|
* Creates a standalone record scanner with an explicit view key.
|
|
263
320
|
*
|
|
264
321
|
* Like {@link createRemoteScanner}, the first `requestRecords` registers the
|
|
265
322
|
* view key with the service (a network round-trip) to obtain the scanning UUID.
|
|
266
323
|
*
|
|
267
|
-
* @param options.url Base URL of the service (the SDK appends the network
|
|
268
|
-
*
|
|
324
|
+
* @param options.url Base URL of the service (the SDK appends the network
|
|
325
|
+
* segment). Defaults to {@link DEFAULT_SCANNER_URL}.
|
|
326
|
+
* @param options.consumerId Optional consumer id used for JWT refresh.
|
|
327
|
+
* Unnecessary when a `session` supplies the token. Required alongside
|
|
328
|
+
* `apiKey` otherwise — a JWT is minted from the pair, so half of it
|
|
329
|
+
* authenticates nothing and construction throws rather than 401ing later.
|
|
269
330
|
* @param options.viewKey The view key (`AViewKey1…`) to scan and decrypt with.
|
|
270
331
|
* @param options.apiKey Optional API key for the authenticated service. Omit
|
|
271
332
|
* for an open/unauthenticated service.
|
|
333
|
+
* @param options.session Optional Provable API session to authenticate from.
|
|
334
|
+
* Supplied at construction only — a standalone scanner is not pluggable
|
|
335
|
+
* into a wallet client, so nothing shares a session with it later.
|
|
272
336
|
* @param options.startBlock Optional block height to begin scanning from at
|
|
273
337
|
* registration. Defaults to 0 (full history).
|
|
338
|
+
* @param options.auth Optional provisioned-key auth for the edge gateway.
|
|
339
|
+
* Every scan carries the key verbatim; nothing registers or mints, and a
|
|
340
|
+
* 401 is terminal. Mutually exclusive with `session`, `apiKey`, and
|
|
341
|
+
* `consumerId` — combining them throws.
|
|
274
342
|
*/
|
|
275
343
|
createStandaloneScanner(options: {
|
|
276
|
-
url
|
|
277
|
-
consumerId
|
|
344
|
+
url?: string;
|
|
345
|
+
consumerId?: string;
|
|
278
346
|
viewKey: string;
|
|
279
347
|
apiKey?: string;
|
|
348
|
+
session?: ProvableSession;
|
|
280
349
|
startBlock?: number;
|
|
350
|
+
auth?: ProvableKeyedAuth;
|
|
281
351
|
}): StandaloneRecordScanner;
|
|
282
|
-
/**
|
|
352
|
+
/**
|
|
353
|
+
* Creates a fully-wired Aleo client from a private key and network URL.
|
|
354
|
+
*
|
|
355
|
+
* Builds one Provable API session from the credential options and shares it
|
|
356
|
+
* across delegated proving and record scanning, so a single
|
|
357
|
+
* `walletClient.authenticateProvableApi()` covers both. Omit the credential
|
|
358
|
+
* options for a client that authenticates neither.
|
|
359
|
+
*
|
|
360
|
+
* @param options.apiKey Optional Provable API key. Paired with `consumerId`,
|
|
361
|
+
* it seeds the session directly.
|
|
362
|
+
* @param options.consumerId Optional Provable API consumer id.
|
|
363
|
+
* @param options.proverUrl Base URL of the delegated proving service — the
|
|
364
|
+
* network segment is appended, so do not include it. That is what lets
|
|
365
|
+
* `switchChain` re-target proving. Defaults to {@link DEFAULT_PROVER_URL},
|
|
366
|
+
* since `provingMode` itself defaults to `'delegated'`; pass an override for
|
|
367
|
+
* a self-hosted prover.
|
|
368
|
+
* @param options.confirmationTimeout Milliseconds to wait for a submitted
|
|
369
|
+
* transaction to confirm. Defaults to 60_000 (one minute), which covers a
|
|
370
|
+
* healthy confirmation with room to spare; a transaction still absent after
|
|
371
|
+
* that is more often one the node never included than one about to land.
|
|
372
|
+
* Raise it for a congested network or a multi-transition call that takes
|
|
373
|
+
* longer to include, rather than treating a slow confirmation as a failure.
|
|
374
|
+
* @param options.username Optional handle to register a Provable API consumer
|
|
375
|
+
* under, used only when no credentials and no stored pair are available.
|
|
376
|
+
* A function is called lazily, at the moment registration happens. Defaults
|
|
377
|
+
* to a name derived from the account address plus a random suffix — the
|
|
378
|
+
* suffix matters because a username is spent once, so an account that lost
|
|
379
|
+
* its stored key must still be able to register. Supplying a fixed name
|
|
380
|
+
* makes the consumer identifiable but fails if that name is taken, since
|
|
381
|
+
* credentials cannot be recovered from a username.
|
|
382
|
+
* @param options.credentialStore Optional persistence for Provable API
|
|
383
|
+
* credentials. When neither `consumerId`/`apiKey` nor a stored pair is
|
|
384
|
+
* available, a consumer is registered under a name derived from the account
|
|
385
|
+
* address and saved here. Defaults to `memoryCredentialStore()`, which holds
|
|
386
|
+
* a registered consumer only for the life of the process — pass
|
|
387
|
+
* `fileCredentialStore` from `@provablehq/veil-aleo-sdk/node`, or any
|
|
388
|
+
* {@link ProvableCredentialStore}, for anything longer-lived. A client left
|
|
389
|
+
* fully unconfigured does not share its session with `records`, so a scanner
|
|
390
|
+
* aimed at an open service keeps needing no credential.
|
|
391
|
+
* @param options.session Optional pre-built session, for a caller that owns
|
|
392
|
+
* one already. Takes precedence over the credential options.
|
|
393
|
+
* @param options.auth Optional provisioned-key auth for the edge gateway.
|
|
394
|
+
* Selects the keyed model for the whole client: proving and scanning carry
|
|
395
|
+
* the key on every request, no session exists, and
|
|
396
|
+
* `authenticateProvableApi` throws since there is nothing to resolve.
|
|
397
|
+
* Mutually exclusive with every consumer option (`apiKey`, `consumerId`,
|
|
398
|
+
* `username`, `credentialStore`, `session`) — edge keys are handed out by
|
|
399
|
+
* an operator, not registered.
|
|
400
|
+
* @returns A public client, a wallet client carrying
|
|
401
|
+
* `authenticateProvableApi`, and the account.
|
|
402
|
+
*
|
|
403
|
+
* @example
|
|
404
|
+
* const scanner = aleo.createRemoteScanner({ url: SCANNER_URL })
|
|
405
|
+
* const { walletClient } = aleo.createAleoClient({
|
|
406
|
+
* privateKey, networkUrl, proverUrl, records: scanner, credentialStore: store,
|
|
407
|
+
* })
|
|
408
|
+
* const { credentials, registered } = await walletClient.authenticateProvableApi()
|
|
409
|
+
* if (registered) console.log('registered consumer', credentials.consumerId)
|
|
410
|
+
*/
|
|
283
411
|
createAleoClient(options: {
|
|
284
412
|
privateKey: string;
|
|
285
413
|
networkUrl: string;
|
|
@@ -288,16 +416,24 @@ interface AleoSdk {
|
|
|
288
416
|
apiKey?: string;
|
|
289
417
|
consumerId?: string;
|
|
290
418
|
useFeeMaster?: boolean;
|
|
419
|
+
confirmationTimeout?: number;
|
|
420
|
+
username?: string | (() => string);
|
|
421
|
+
credentialStore?: ProvableCredentialStore;
|
|
422
|
+
session?: ProvableSession;
|
|
423
|
+
auth?: ProvableKeyedAuth;
|
|
291
424
|
/**
|
|
292
425
|
* Record provider for `requestRecords`. Not wired by default — pass
|
|
293
426
|
* `aleo.createRemoteScanner(...)` or any
|
|
294
427
|
* custom `RecordProvider`. `requestRecords` throws with a setup hint
|
|
295
428
|
* when no provider is configured.
|
|
296
429
|
*/
|
|
297
|
-
records?: RecordProvider
|
|
430
|
+
records?: RecordProvider & {
|
|
431
|
+
setSession?: (session: ProvableSession) => void;
|
|
432
|
+
setAuth?: (auth: ProvableKeyedAuth) => void;
|
|
433
|
+
};
|
|
298
434
|
}): {
|
|
299
435
|
publicClient: PublicClient;
|
|
300
|
-
walletClient:
|
|
436
|
+
walletClient: ProvableWalletClient;
|
|
301
437
|
account: LocalAccount<'privateKey'>;
|
|
302
438
|
};
|
|
303
439
|
}
|
|
@@ -345,4 +481,4 @@ declare function createDevnodeClient(options?: {
|
|
|
345
481
|
account: LocalAccount<'privateKey'>;
|
|
346
482
|
};
|
|
347
483
|
|
|
348
|
-
export { type AleoDerivationId, type AleoSdk, BLS12377HDKey, LEGACY_PATH, STANDARD_PATH, type SupportedNetwork, createDevnodeClient, generateAccount, generateMnemonic, loadNetwork, mnemonicToHDKey, mnemonicToSeed, validateMnemonic, validateWord };
|
|
484
|
+
export { type AleoDerivationId, type AleoSdk, BLS12377HDKey, DEFAULT_PROVER_URL, DEFAULT_SCANNER_URL, LEGACY_PATH, ProvableCredentialStore, ProvableKeyedAuth, ProvableSession, ProvableWalletClient, ProvingConfigWithSession, STANDARD_PATH, type SupportedNetwork, createDevnodeClient, generateAccount, generateMnemonic, loadNetwork, mnemonicToHDKey, mnemonicToSeed, validateMnemonic, validateWord };
|