@dynamic-labs-wallet/aleo 0.0.0 → 0.0.331

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/package.json CHANGED
@@ -1 +1,34 @@
1
- { "name": "@dynamic-labs-wallet/aleo", "version": "0.0.0" }
1
+ {
2
+ "name": "@dynamic-labs-wallet/aleo",
3
+ "version": "0.0.331",
4
+ "license": "MIT",
5
+ "type": "module",
6
+ "dependencies": {
7
+ "@dynamic-labs-wallet/browser": "0.0.331",
8
+ "@dynamic-labs-wallet/core": "0.0.331",
9
+ "@provablehq/sdk": "0.10.4"
10
+ },
11
+ "publishConfig": {
12
+ "access": "public"
13
+ },
14
+ "nx": {
15
+ "sourceRoot": "packages/aleo/src",
16
+ "projectType": "library",
17
+ "name": "aleo",
18
+ "targets": {
19
+ "build": {}
20
+ }
21
+ },
22
+ "main": "./index.cjs.js",
23
+ "module": "./index.esm.js",
24
+ "types": "./index.esm.d.ts",
25
+ "exports": {
26
+ "./package.json": "./package.json",
27
+ ".": {
28
+ "types": "./index.esm.d.ts",
29
+ "import": "./index.esm.js",
30
+ "require": "./index.cjs.js",
31
+ "default": "./index.esm.js"
32
+ }
33
+ }
34
+ }
@@ -0,0 +1,359 @@
1
+ import { DynamicWalletClient, type DynamicWalletClientInternalOptions, type DynamicWalletClientProps, type RequestWithElevatedAccessToken, type ThresholdSignatureScheme } from '@dynamic-labs-wallet/browser';
2
+ export declare class DynamicAleoWalletClient extends DynamicWalletClient {
3
+ readonly chainName = "ALEO";
4
+ constructor({ environmentId, authToken, baseApiUrl, baseMPCRelayApiUrl, storageKey, debug, featureFlags, authMode, sdkVersion, forwardMPCClient, logger, }: DynamicWalletClientProps, internalOptions?: DynamicWalletClientInternalOptions);
5
+ createWalletAccount({ thresholdSignatureScheme, password, onError, signedSessionId, }: {
6
+ thresholdSignatureScheme: ThresholdSignatureScheme;
7
+ password?: string;
8
+ onError?: (error: Error) => void;
9
+ signedSessionId: string;
10
+ }): Promise<{
11
+ accountAddress: string;
12
+ publicKeyHex: string;
13
+ rawPublicKey: Uint8Array;
14
+ }>;
15
+ signMessage(_args: {
16
+ message: string;
17
+ accountAddress: string;
18
+ password?: string;
19
+ signedSessionId: string;
20
+ mfaToken?: string;
21
+ elevatedAccessToken?: string;
22
+ }): Promise<string>;
23
+ signTransaction(args: {
24
+ accountAddress: string;
25
+ signedSessionId: string;
26
+ }): Promise<string>;
27
+ exportPrivateKey({ accountAddress, password, signedSessionId, mfaToken, elevatedAccessToken, }: RequestWithElevatedAccessToken<{
28
+ accountAddress: string;
29
+ password?: string;
30
+ signedSessionId: string;
31
+ mfaToken?: string;
32
+ }>): Promise<string>;
33
+ importPrivateKey(_args: {
34
+ privateKey: string;
35
+ chainName: string;
36
+ thresholdSignatureScheme: ThresholdSignatureScheme;
37
+ password?: string;
38
+ signedSessionId: string;
39
+ onError?: (error: Error) => void;
40
+ }): Promise<{
41
+ accountAddress: string;
42
+ publicKeyHex: string;
43
+ rawPublicKey: Uint8Array;
44
+ }>;
45
+ getAleoWallets(): Promise<any>;
46
+ /**
47
+ * Runs the Aleo signRequest MPC ceremony for the given structured payload.
48
+ * The payload is Sodot's `EdBls12377RequestSignPayload` shape:
49
+ * { function_id, is_root, program_checksum, inputs: [...] }.
50
+ * Returns the signed request with { signature, tvk, signer, gammas? } which
51
+ * the caller passes to `buildExecutionRequestFromExternallySignedData` to
52
+ * produce an ExecutionRequest for proving via Provable DPS.
53
+ */
54
+ signAleoRequest({ accountAddress, payload, password, signedSessionId, mfaToken, elevatedAccessToken, }: RequestWithElevatedAccessToken<{
55
+ accountAddress: string;
56
+ payload: unknown;
57
+ password?: string;
58
+ signedSessionId: string;
59
+ mfaToken?: string;
60
+ }>): Promise<unknown>;
61
+ /**
62
+ * LocalStorage key for caching the per-account Aleo view key in the iframe.
63
+ * Scoped to iframe origin — the DApp cannot read this via same-origin policy.
64
+ */
65
+ private getViewKeyCacheStorageKey;
66
+ /**
67
+ * Returns the Aleo view key for the given account. On first call runs the
68
+ * asymmetric exportViewKey MPC ceremony (client receives, server gets
69
+ * nothing) and caches the result in iframe localStorage. Subsequent calls
70
+ * return the cached value. View key never leaves the iframe — it is NOT
71
+ * postMessage'd to the DApp.
72
+ */
73
+ exportViewKey({ accountAddress, password, signedSessionId, mfaToken, elevatedAccessToken, }: RequestWithElevatedAccessToken<{
74
+ accountAddress: string;
75
+ password?: string;
76
+ signedSessionId: string;
77
+ mfaToken?: string;
78
+ }>): Promise<string>;
79
+ /**
80
+ * Convert a Provable `ExternalSigningInput<'bytes'>` into the Sodot
81
+ * EdBls12377 signing payload shape. Mirrors the playground helper.
82
+ * All Uint8Array fields are preserved — this shape is passed directly to
83
+ * `mpcSigner.signRequest` locally. For HTTP transport, use
84
+ * `encodePayloadForTransport` to hex-encode the byte fields.
85
+ */
86
+ private toRequestSignPayload;
87
+ /**
88
+ * Hex-encode the Uint8Array fields of an EdBls12377 signing payload so it
89
+ * can travel through JSON HTTP without loss. Mirror of
90
+ * `decodeAleoSigningPayload` in wallet-service — both sides must agree on
91
+ * the wire format so the MPC ceremony sees identical byte arrays.
92
+ */
93
+ private encodePayloadForTransport;
94
+ /**
95
+ * Fetches the on-chain `program_checksum` for a deployed program and
96
+ * returns it as a 32-byte `Uint8Array` ready to feed into
97
+ * `computeExternalSigningInputs({ checksum })` and Sodot's
98
+ * `signRequest` payload (`program_checksum` field).
99
+ *
100
+ * Why we need this: the Aleo VM's external-signing path checks the
101
+ * program checksum for any program that has a constructor. Constructor-
102
+ * less programs (`credits.aleo`, `token_registry.aleo`) deploy without a
103
+ * `program_checksum` field and work with `checksum: null`. Programs with
104
+ * a constructor (USAD/USDCx Tier-3 stablecoins, any custom program)
105
+ * trip a hardcoded `"Program ID must be credits.aleo"` error in the WASM
106
+ * unless a real checksum is supplied.
107
+ *
108
+ * Returns `null` when the deployment has no checksum (constructor-less);
109
+ * caller is expected to pass that `null` through to `signRequest`.
110
+ *
111
+ * Source: the deployment transaction's `deployment.program_checksum`
112
+ * field, returned as a 32-element array of `<n>u8` literals (e.g.
113
+ * `["207u8", "221u8", ...]`).
114
+ */
115
+ private getProgramChecksum;
116
+ /**
117
+ * Computes (or returns from cache) the Sealance Merkle exclusion proof
118
+ * for `accountAddress` against the given freezelist program's tree.
119
+ *
120
+ * The Sealance flow proves the sender is *not* on the freeze list. Recipe:
121
+ * 1. Fetch the BigInt-string tree at
122
+ * `/v2/{network}/programs/{freezelist}/compliance/freeze-list`.
123
+ * 2. `tree[tree.length - 1]` is the Merkle root.
124
+ * 3. `convertTreeToBigInt` → `getLeafIndices(addr)` → 2× `getSiblingPath`
125
+ * → `formatMerkleProof` produces the formatted `[MerkleProof; 2u32]` literal.
126
+ *
127
+ * Cached per (accountAddress, freezelistProgram, root). On the next spend
128
+ * we only refetch the tree and rebuild when the root has changed.
129
+ */
130
+ private getSealanceProof;
131
+ /**
132
+ * Full Aleo transaction flow:
133
+ * viewKey (MPC exported, cached) → computeExternalSigningInputs
134
+ * → Sodot signAleoRequest MPC ceremony
135
+ * → buildExecutionRequestFromExternallySignedData
136
+ * → Provable DPS submitProvingRequest (computes ZK proof + broadcasts)
137
+ *
138
+ * Handles both non-record functions (transfer_public) and record-consuming
139
+ * functions (transfer_private, join, transfer_public_to_private).
140
+ *
141
+ * For Sealance-compliant tier-3 stablecoins (USAD, USDCx), the iframe also
142
+ * auto-fetches/computes the Merkle exclusion proof and appends it to
143
+ * `inputs`/`inputTypes` when the program/function pair calls for it. The
144
+ * caller passes the same shape as a credits.aleo transfer.
145
+ *
146
+ * @param broadcast - if true, DPS broadcasts the transaction and returns a
147
+ * txId. If false, DPS returns the proving response and the caller
148
+ * decides what to do with it.
149
+ */
150
+ proveTransaction({ accountAddress, programId, functionName, inputs, inputTypes, broadcast, password, signedSessionId, mfaToken, elevatedAccessToken, chainId, }: RequestWithElevatedAccessToken<{
151
+ accountAddress: string;
152
+ programId: string;
153
+ functionName: string;
154
+ inputs: string[];
155
+ inputTypes: string[];
156
+ broadcast?: boolean;
157
+ password?: string;
158
+ signedSessionId: string;
159
+ mfaToken?: string;
160
+ /** Aleo network id (`'0'` mainnet, `'1'` testnet, or numeric). The
161
+ * authoritative signal for which network the user is on; used to
162
+ * pick the SDK build, the Feemaster policy, and the proving
163
+ * endpoints. Falls back to `networkFromProgramId(programId)` when
164
+ * unset — that's lossy for `credits.aleo` (same name on both
165
+ * networks), so callers should always pass `chainId` for credits
166
+ * flows. */
167
+ chainId?: string | number;
168
+ }>): Promise<{
169
+ txId?: string;
170
+ provingResponse?: unknown;
171
+ }>;
172
+ /**
173
+ * Sealance auto-injection. For tier-3 stablecoin transfer functions that
174
+ * require a freeze-list exclusion proof, append the formatted
175
+ * `[MerkleProof; 2u32].private` literal to inputs/inputTypes. Programs
176
+ * not in the registry / function not requiring proof → pass-through.
177
+ */
178
+ private injectSealanceProofIfNeeded;
179
+ /**
180
+ * Derive the program-checksum `Field` snarkVM's external-signing path
181
+ * needs for non-credits programs. `credits.aleo` is special-cased in the
182
+ * WASM and works with `null`. Other programs: fetch the on-chain 32-byte
183
+ * checksum, expand bytes → bits LE, truncate to `Field::SIZE_IN_DATA_BITS`
184
+ * (252 for Fr), and call `Field.fromBitsLe` — mirrors snarkVM's own
185
+ * `Stack::program_checksum_as_field`.
186
+ */
187
+ private deriveProgramChecksumField;
188
+ /**
189
+ * Build the proving request — feemaster path when ANF covers the
190
+ * (programId, functionName), user-paid fallback otherwise. Feemaster
191
+ * failures fall through silently so a transient policy/quota issue
192
+ * doesn't block the user; they just pay the fee themselves.
193
+ */
194
+ private buildProvingRequest;
195
+ /**
196
+ * Feemaster-sponsored proving request. Builds the user authorization via
197
+ * the WASM-direct ProgramManager static (no private key needed — the
198
+ * request is already MPC-signed), exchanges it with the Feemaster for a
199
+ * `feeAuthorization`, and returns the bundled `ProvingRequest`.
200
+ */
201
+ private buildFeemasterProvingRequest;
202
+ /**
203
+ * Standalone Feemaster coverage check for any (programId, functionName)
204
+ * pair on the connector-selected network. Used by the widget to decide
205
+ * whether a user-paid confirmation modal is needed before triggering a
206
+ * shield/send/join. Resolves the network from the caller-supplied
207
+ * `chainId`; defaults to testnet when omitted (mirrors `resolveAleoNetwork`).
208
+ *
209
+ * Never throws — returns `false` on any policy fetch failure so callers
210
+ * can default to "show modal" rather than silently shielding.
211
+ */
212
+ isFeemasterCovered({ programId, functionName, chainId, }: {
213
+ programId: string;
214
+ functionName: string;
215
+ chainId?: string | number;
216
+ }): Promise<boolean>;
217
+ /**
218
+ * Cached ProgramManager per Aleo network. The SDK ships separate
219
+ * mainnet/testnet builds (`@provablehq/sdk/{mainnet,testnet}.js`) that
220
+ * export network-specific class identities — `ExecutionRequest`,
221
+ * `ProvingRequest`, etc. each network's prebundle has its own constructor.
222
+ * `provingRequest` validates `executionRequest instanceof ExecutionRequest`
223
+ * against the manager's own SDK build, so a manager constructed from the
224
+ * testnet build will reject a mainnet-built executionRequest (silently
225
+ * falling into the no-executionRequest branch and throwing a misleading
226
+ * "No private key provided" error). Caching per network keeps both
227
+ * builds available and ensures the manager and the executionRequest
228
+ * always come from the same SDK build.
229
+ */
230
+ private readonly programManagersByNetwork;
231
+ /**
232
+ * Lazy-load the network-matching `@provablehq/sdk` build, instantiate a
233
+ * ProgramManager, and cache it. The Provable WASM bundle is ~20MB, so
234
+ * we avoid loading it eagerly at iframe init; both networks' bundles
235
+ * load on first use of each.
236
+ */
237
+ protected getProgramManager(network: 'testnet' | 'mainnet'): Promise<unknown>;
238
+ /**
239
+ * Cached RecordScanner instances per Aleo network. Each entry talks to a
240
+ * single network's scanner endpoint with a single network-specific SDK
241
+ * build (`@provablehq/sdk/{testnet,mainnet}.js`). Per-wallet identity is
242
+ * via the scanner UUID cached in walletStateStorage (also keyed by
243
+ * network). Scanner credentials (apiKey, consumerId) are shared across
244
+ * networks. The SDK handles JWT refresh automatically.
245
+ */
246
+ private readonly scannersByNetwork;
247
+ /**
248
+ * Cached `FeemasterClient` per Aleo network. Each instance holds an in-
249
+ * memory policy cache (5 min TTL) and delegates HTTP work to the
250
+ * inherited `this.apiClient` — the same `DynamicApiClient` every other
251
+ * iframe→redcoast call uses. So baseApiUrl, auth headers, traceContext
252
+ * propagation, etc. all come from the existing plumbing for free.
253
+ */
254
+ private readonly feemasterClients;
255
+ private getFeemasterClient;
256
+ /**
257
+ * In-memory cache of program checksums keyed by `${network}:${programId}`.
258
+ * The Aleo VM's external-signing path requires a non-null `program_checksum`
259
+ * for any program with a constructor (i.e. anything other than credits.aleo
260
+ * in our universe). The checksum is immutable for a given deployed program
261
+ * edition, so we fetch once per session and reuse. Persistence not needed —
262
+ * a single network round-trip on first use is cheap.
263
+ */
264
+ private readonly programChecksumCache;
265
+ /**
266
+ * Single-flight guard for `findOwnedRecords`, keyed by accountAddress.
267
+ * The widget's Shielded tab + the demo's "List my records" button can fire
268
+ * concurrent record scans on the same wallet; without dedup, multiple
269
+ * findRecords calls race against a stale cached UUID and serially trip
270
+ * UUIDErrors. With dedup, all concurrent callers await the same in-flight
271
+ * promise and the recovery path runs at most once.
272
+ */
273
+ private readonly pendingFindOwnedRecords;
274
+ /**
275
+ * Lazy-init RecordScanner for the given Aleo network using the shared
276
+ * Provable consumer credentials (VITE_ALEO_SCANNER_API_KEY +
277
+ * VITE_ALEO_SCANNER_CONSUMER_ID in iframe env). Scanner calls and JWT
278
+ * refresh both route through the Vite dev proxy `/aleo-api/*` to work
279
+ * around Provable's CORS 401 on preflight.
280
+ *
281
+ * The Provable SDK ships separate `testnet.js` / `mainnet.js` builds
282
+ * (verified in `node_modules/@provablehq/sdk/package.json#exports`). Each
283
+ * build pins the chain endpoints to that network, so the right scanner
284
+ * comes from importing the matching build. We cache an instance per
285
+ * network on `this.scannersByNetwork`; toggling networks at runtime is
286
+ * a Map lookup, no teardown.
287
+ */
288
+ protected getRecordScanner(network: 'testnet' | 'mainnet'): Promise<unknown>;
289
+ /**
290
+ * List all Aleo records owned by this wallet across every program (credits,
291
+ * custom tokens, etc.). Uses Provable's hosted RecordScanner with our shared
292
+ * consumer; per-wallet scanner UUID is cached in iframe IndexedDB
293
+ * (walletStateStorage) so subsequent calls skip the register step.
294
+ *
295
+ * Each returned record carries `program_name` + `record_name` so callers
296
+ * can classify by token. Credits records additionally get a `microcredits`
297
+ * field parsed in-iframe for convenience (public WASM primitive). Other
298
+ * tokens are returned as-is — the caller is responsible for amount parsing
299
+ * per program schema.
300
+ *
301
+ * Records are decrypted locally in the iframe via view-key only.
302
+ * Spent-tracking filters out locally-known spent nonces (records we
303
+ * consumed in our own proveTransaction calls, before the scanner has
304
+ * re-indexed).
305
+ */
306
+ findOwnedRecords(params: RequestWithElevatedAccessToken<{
307
+ accountAddress: string;
308
+ password?: string;
309
+ signedSessionId: string;
310
+ mfaToken?: string;
311
+ /** Aleo network id (`'0'` mainnet, `'1'` testnet, or numeric).
312
+ * Routes the scan to the matching scanner instance + walletState
313
+ * cache bucket. Omit to default to testnet. */
314
+ chainId?: string | number;
315
+ }>): Promise<{
316
+ records: unknown[];
317
+ }>;
318
+ private findOwnedRecordsInner;
319
+ /**
320
+ * Loads the network-specific Provable SDK build and surfaces a clear
321
+ * error log to the iframe console when WASM init fails (so the failure
322
+ * is debuggable; the throw still propagates).
323
+ */
324
+ private loadAleoSdkOrThrow;
325
+ /**
326
+ * Reads the per-(account, network) wallet state from IndexedDB. Errors
327
+ * are logged and rethrown — a wedged IDB blocks the find-records flow
328
+ * entirely, so silent fallback isn't safe here.
329
+ */
330
+ private loadWalletStateOrThrow;
331
+ /**
332
+ * Provable's RecordScanner can throw a `UUIDError` for several reasons —
333
+ * cached UUID expired server-side, consumer key rotated, scanner instance
334
+ * stale after a JWT refresh blip. Recovery: drop the cached scanner
335
+ * instance + cached UUID, re-register, retry up to twice. After that the
336
+ * problem isn't UUID-related and we surface the underlying error.
337
+ */
338
+ private findRecordsWithUuidRetry;
339
+ /**
340
+ * Wraps the encrypted view key and registers it with the scanner.
341
+ * `registerEncrypted` (not `register`) ensures the view key crosses the
342
+ * wire encrypted; same pattern Provable's `example-autojoin` uses.
343
+ */
344
+ private registerScannerWallet;
345
+ /**
346
+ * Decrypt the record's ciphertext locally (when missing) and surface
347
+ * `microcredits` / `amount` as decimal strings so the DApp side can
348
+ * display balances without needing the Provable WASM in its own bundle.
349
+ * Mutates the record in place — same contract the original loop had.
350
+ */
351
+ private enrichOwnedRecord;
352
+ /**
353
+ * Local spent-nonce filter — protects against the race where we've
354
+ * broadcast a record-spending transaction but the scanner hasn't indexed
355
+ * the spend yet.
356
+ */
357
+ private filterUnspentRecords;
358
+ }
359
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,mBAAmB,EAInB,KAAK,kCAAkC,EACvC,KAAK,wBAAwB,EAC7B,KAAK,8BAA8B,EACnC,KAAK,wBAAwB,EAC9B,MAAM,8BAA8B,CAAC;AA0GtC,qBAAa,uBAAwB,SAAQ,mBAAmB;IAC9D,QAAQ,CAAC,SAAS,UAAU;gBAG1B,EACE,aAAa,EACb,SAAS,EACT,UAAU,EACV,kBAAkB,EAClB,UAAU,EACV,KAAK,EACL,YAAY,EACZ,QAA0B,EAC1B,UAAU,EACV,gBAAgB,EAChB,MAAM,GACP,EAAE,wBAAwB,EAC3B,eAAe,CAAC,EAAE,kCAAkC;IAoBhD,mBAAmB,CAAC,EACxB,wBAAwB,EACxB,QAAoB,EACpB,OAAO,EACP,eAAe,GAChB,EAAE;QACD,wBAAwB,EAAE,wBAAwB,CAAC;QACnD,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;QACjC,eAAe,EAAE,MAAM,CAAC;KACzB,GAAG,OAAO,CAAC;QACV,cAAc,EAAE,MAAM,CAAC;QACvB,YAAY,EAAE,MAAM,CAAC;QACrB,YAAY,EAAE,UAAU,CAAC;KAC1B,CAAC;IAoFI,W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QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,eAAe,EAAE,MAAM,CAAC;QACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB;;wDAEgD;QAChD,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;KAC3B,CAAC,GACD,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,EAAE,CAAA;KAAE,CAAC;YAsBpB,qBAAqB;IAyDnC;;;;OAIG;YACW,kBAAkB;IAahC;;;;OAIG;YACW,sBAAsB;IAepC;;;;;;OAMG;YACW,wBAAwB;IAyDtC;;;;OAIG;YACW,qBAAqB;IA+BnC;;;;;OAKG;IACH,OAAO,CAAC,iBAAiB;IAqCzB;;;;OAIG;IACH,OAAO,CAAC,oBAAoB;CAgB7B"}
@@ -0,0 +1,20 @@
1
+ export declare const ERROR_KEYGEN_FAILED = "Error with Aleo keygen";
2
+ export declare const ERROR_CREATE_WALLET_ACCOUNT = "Error creating Aleo wallet account";
3
+ export declare const ERROR_ACCOUNT_ADDRESS_REQUIRED = "Account address is required";
4
+ export declare const ERROR_EXPORT_PRIVATE_KEY = "Error exporting Aleo private key";
5
+ export declare const ERROR_IMPORT_PRIVATE_KEY_NOT_SUPPORTED = "Aleo importPrivateKey is not supported yet";
6
+ export declare const ERROR_SIGN_MESSAGE_NOT_SUPPORTED = "Aleo signMessage is not supported yet \u2014 pending arbitrary-bytes EdBls12377 signing";
7
+ export declare const ERROR_SIGN_TRANSACTION_NOT_SUPPORTED = "Aleo signTransaction is not supported yet \u2014 coming in Phase 2";
8
+ export declare const ALEO_NETWORKS: {
9
+ readonly MAINNET: "mainnet";
10
+ readonly TESTNET: "testnet";
11
+ };
12
+ /**
13
+ * Default Provable Delegated Proving Service endpoint.
14
+ * Used by `submitProvingRequest` — Provable computes the ZK proof on their
15
+ * accelerator hardware and (optionally) broadcasts. No API key required for
16
+ * testnet during Phase 2.
17
+ */
18
+ export declare const DEFAULT_PROVABLE_PROVER_URI = "https://accelerate.provable.com";
19
+ export type AleoNetwork = (typeof ALEO_NETWORKS)[keyof typeof ALEO_NETWORKS];
20
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/client/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,mBAAmB,2BAA2B,CAAC;AAC5D,eAAO,MAAM,2BAA2B,uCAAuC,CAAC;AAChF,eAAO,MAAM,8BAA8B,gCAAgC,CAAC;AAC5E,eAAO,MAAM,wBAAwB,qCAAqC,CAAC;AAC3E,eAAO,MAAM,sCAAsC,+CAA+C,CAAC;AACnG,eAAO,MAAM,gCAAgC,4FACyC,CAAC;AACvF,eAAO,MAAM,oCAAoC,uEAAkE,CAAC;AAEpH,eAAO,MAAM,aAAa;;;CAGhB,CAAC;AAEX;;;;;GAKG;AACH,eAAO,MAAM,2BAA2B,oCAAoC,CAAC;AAE7E,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,OAAO,aAAa,CAAC,CAAC"}
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Iframe-side Feemaster surface used by `proveTransaction`.
3
+ *
4
+ * Earlier versions made `fetch()` calls to ANF directly with a hardcoded
5
+ * Bearer key shipped in the iframe bundle. As of Phase A1 the iframe goes
6
+ * through redcoast (which holds the ANF key server-side) — and by reusing
7
+ * the existing `DynamicApiClient` in `@dynamic-labs-wallet/core`, all the
8
+ * baseApiUrl / Authorization-header / retry plumbing is shared with the
9
+ * other waas redcoast endpoints (`exportAleoViewKey`, `signAleoRequest`,
10
+ * etc.).
11
+ *
12
+ * This file is now a thin wrapper that:
13
+ * - holds the network the iframe is bound to
14
+ * - keeps a 5-min in-memory policy cache (matches the previous behaviour)
15
+ * - delegates HTTP work to `DynamicApiClient`
16
+ *
17
+ * Surface kept identical (`fetchPolicy`, `isCovered`, `requestFeeAuthorization`)
18
+ * so call sites in `proveTransaction` don't change.
19
+ */
20
+ import type { DynamicApiClient } from '@dynamic-labs-wallet/core';
21
+ export interface FeemasterPolicyEntry {
22
+ program_id: string;
23
+ /** `null` (or absent) means all functions on the program are sponsored. */
24
+ allowed_functions?: string[] | null;
25
+ }
26
+ export interface FeemasterPolicy {
27
+ /** `null` means all programs are sponsored (wildcard). */
28
+ allowed_programs: FeemasterPolicyEntry[] | null;
29
+ }
30
+ export type FeemasterNetwork = 'mainnet' | 'testnet';
31
+ export declare class FeemasterClient {
32
+ private readonly apiClient;
33
+ private readonly network;
34
+ private policyCache;
35
+ constructor(args: {
36
+ apiClient: DynamicApiClient;
37
+ network: FeemasterNetwork;
38
+ });
39
+ /** Fetches the Feemaster policy for the configured network. Cached for
40
+ * 5 minutes; pass `force: true` after a quota-exhausted response. */
41
+ fetchPolicy(force?: boolean): Promise<FeemasterPolicy>;
42
+ /** Returns true when the configured network's policy permits sponsoring
43
+ * `(programId, functionName)`. Never throws — returns false on any
44
+ * policy fetch failure so callers can fall back to user-paid. */
45
+ isCovered(programId: string, functionName: string): Promise<boolean>;
46
+ /** Forwards a user-signed Aleo Authorization to ANF (via redcoast) and
47
+ * returns the corresponding `feeAuthorization` for bundling into a
48
+ * ProvingRequest. Throws on quota / service errors so the caller falls
49
+ * back to user-paid fees. */
50
+ requestFeeAuthorization(params: {
51
+ /** User Authorization serialized via `Authorization.toString()`. */
52
+ authorizationString: string;
53
+ priorityFee?: number;
54
+ }): Promise<{
55
+ feeAuthorizationString: string;
56
+ }>;
57
+ }
58
+ //# sourceMappingURL=feemasterClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"feemasterClient.d.ts","sourceRoot":"","sources":["../../src/client/feemasterClient.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAElE,MAAM,WAAW,oBAAoB;IACnC,UAAU,EAAE,MAAM,CAAC;IACnB,2EAA2E;IAC3E,iBAAiB,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;CACrC;AAED,MAAM,WAAW,eAAe;IAC9B,0DAA0D;IAC1D,gBAAgB,EAAE,oBAAoB,EAAE,GAAG,IAAI,CAAC;CACjD;AAED,MAAM,MAAM,gBAAgB,GAAG,SAAS,GAAG,SAAS,CAAC;AAIrD,qBAAa,eAAe;IAC1B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAmB;IAC7C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAmB;IAC3C,OAAO,CAAC,WAAW,CAA8D;gBAErE,IAAI,EAAE;QAAE,SAAS,EAAE,gBAAgB,CAAC;QAAC,OAAO,EAAE,gBAAgB,CAAA;KAAE;IAK5E;0EACsE;IAChE,WAAW,CAAC,KAAK,UAAQ,GAAG,OAAO,CAAC,eAAe,CAAC;IAW1D;;sEAEkE;IAC5D,SAAS,CAAC,SAAS,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAwB1E;;;kCAG8B;IACxB,uBAAuB,CAAC,MAAM,EAAE;QACpC,oEAAoE;QACpE,mBAAmB,EAAE,MAAM,CAAC;QAC5B,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB,GAAG,OAAO,CAAC;QAAE,sBAAsB,EAAE,MAAM,CAAA;KAAE,CAAC;CAQhD"}
@@ -0,0 +1,2 @@
1
+ export * from './client.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC"}
@@ -0,0 +1,85 @@
1
+ /**
2
+ * Iframe-side RecordScanner that mirrors the Provable SDK's surface but
3
+ * routes every HTTP call through redcoast. This is the Phase A2 swap —
4
+ * before this, the iframe held a hardcoded scanner apiKey + consumerId;
5
+ * now those credentials live in redcoast env vars and the iframe
6
+ * authenticates via the user's Dynamic JWT (handled by `DynamicApiClient`).
7
+ *
8
+ * What stays in the iframe:
9
+ * - The `crypto_box_seal` wrap of the view key (`encryptRegistrationRequest`
10
+ * from the Provable SDK). The view key plaintext never leaves the
11
+ * iframe; only its encrypted form crosses the wire.
12
+ *
13
+ * What now lives in redcoast:
14
+ * - The Provable Bearer apiKey + consumerId.
15
+ * - JWT lifecycle (the SDK used to manage this in the browser; redcoast
16
+ * manages it server-side now and the iframe is unaware).
17
+ *
18
+ * The class signature intentionally matches the parts of `sdk.RecordScanner`
19
+ * the iframe consumes (`registerEncrypted`, `findRecords`) so the rest of
20
+ * `DynamicAleoWalletClient.findOwnedRecordsInner` doesn't change.
21
+ */
22
+ import type { DynamicApiClient } from '@dynamic-labs-wallet/core';
23
+ export type RedcoastRecordScannerNetwork = 'mainnet' | 'testnet';
24
+ interface ProvableSdkLike {
25
+ /** `encryptRegistrationRequest(public_key: string, viewKey: ViewKey, start: number) → ciphertext (base64).`
26
+ * Exported by both `@provablehq/sdk/testnet.js` and `mainnet.js`. */
27
+ encryptRegistrationRequest: (publicKey: string, viewKey: unknown, start: number) => string;
28
+ }
29
+ export type RegisterResult = {
30
+ ok: true;
31
+ data: {
32
+ uuid: string;
33
+ } & Record<string, unknown>;
34
+ } | {
35
+ ok: false;
36
+ status?: number;
37
+ error?: {
38
+ message?: string;
39
+ };
40
+ };
41
+ export type FindRecordsFilter = {
42
+ uuid: string;
43
+ decrypt?: boolean;
44
+ unspent?: boolean;
45
+ filter?: Record<string, unknown>;
46
+ };
47
+ export declare class RedcoastRecordScanner {
48
+ private readonly apiClient;
49
+ private readonly network;
50
+ private readonly sdk;
51
+ constructor(args: {
52
+ apiClient: DynamicApiClient;
53
+ network: RedcoastRecordScannerNetwork;
54
+ /** Network-specific Provable SDK build. Used only for the
55
+ * `encryptRegistrationRequest` helper (libsodium `crypto_box_seal`).
56
+ * Must be the same network as `network`. */
57
+ sdk: ProvableSdkLike;
58
+ });
59
+ /**
60
+ * Registers an encrypted view key with the scanner. Mirrors
61
+ * `sdk.RecordScanner.registerEncrypted(viewKey, startBlock)`:
62
+ *
63
+ * 1. GET `/scanner/pubkey` → ephemeral public key
64
+ * 2. Wrap `(viewKey, startBlock)` via libsodium `crypto_box_seal`
65
+ * 3. POST `/scanner/register` with `{ key_id, ciphertext }`
66
+ *
67
+ * Returns the SDK-shaped Result so callers don't have to change.
68
+ */
69
+ registerEncrypted(viewKey: unknown, startBlock: number): Promise<RegisterResult>;
70
+ /**
71
+ * Find owned records by uuid. Mirrors the subset of
72
+ * `sdk.RecordScanner.findRecords(filter)` the iframe consumes.
73
+ *
74
+ * The SDK's filter shape is `{ uuid, decrypt, unspent, filter, ... }`.
75
+ * We forward it verbatim. Records returned are still encrypted on
76
+ * the wire; the caller (`DynamicAleoWalletClient.findOwnedRecordsInner`)
77
+ * decrypts them locally with the view key — same as before A2, just
78
+ * with a different transport underneath.
79
+ */
80
+ findRecords(filter: FindRecordsFilter): Promise<unknown[]>;
81
+ /** Optional but useful for parity with the SDK; not currently called. */
82
+ revoke(uuid: string): Promise<Record<string, unknown>>;
83
+ }
84
+ export {};
85
+ //# sourceMappingURL=redcoastRecordScanner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"redcoastRecordScanner.d.ts","sourceRoot":"","sources":["../../src/client/redcoastRecordScanner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAElE,MAAM,MAAM,4BAA4B,GAAG,SAAS,GAAG,SAAS,CAAC;AAEjE,UAAU,eAAe;IACvB;0EACsE;IACtE,0BAA0B,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;CAC5F;AAED,MAAM,MAAM,cAAc,GACtB;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,MAAM,CAAC,M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