@invisi-labs/sdk 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,572 @@
1
+ import {
2
+ DisclosureVerifier,
3
+ Operation,
4
+ TransactionPreparation,
5
+ WalletSession,
6
+ authorizeOperation,
7
+ copyGasBenchmarks,
8
+ defineGasBenchmarks,
9
+ deserializeState,
10
+ encodeOperation,
11
+ estimateGasReference,
12
+ operationPreview,
13
+ positiveAmount,
14
+ proveOperation,
15
+ publicProof,
16
+ requiresAuthorization,
17
+ sameStatement,
18
+ serializeState,
19
+ signOperationFunding,
20
+ statement,
21
+ walletBalance
22
+ } from "./chunk-T246CYQ7.js";
23
+ import {
24
+ EthersAddressResolver,
25
+ EthersChainReader,
26
+ EthersFundingSigner,
27
+ EthersFundingVerifier
28
+ } from "./chunk-NAEEEZMH.js";
29
+
30
+ // src/explicit-preparation.ts
31
+ import { getAddress } from "ethers";
32
+
33
+ // src/PreparedTransaction.ts
34
+ import {
35
+ MissingCapabilityError
36
+ } from "@invisi-labs/core";
37
+ import { normalizeFunding } from "@invisi-labs/protocol";
38
+ function check(ok, message) {
39
+ if (!ok) throw new Error(message);
40
+ }
41
+ var PreparedTransaction = class _PreparedTransaction {
42
+ #runtime;
43
+ #saved;
44
+ #authorization;
45
+ #lifecycle;
46
+ status;
47
+ constructor(runtime, saved, status, lifecycle, authorization) {
48
+ this.#runtime = runtime;
49
+ this.#saved = structuredClone(saved);
50
+ this.#lifecycle = lifecycle;
51
+ this.#authorization = authorization;
52
+ this.status = status;
53
+ Object.freeze(this);
54
+ }
55
+ static prepare(runtime, plan) {
56
+ return new _PreparedTransaction(
57
+ runtime,
58
+ { plan: structuredClone(plan), generation: 0 },
59
+ "prepared",
60
+ { generation: 0, busy: false }
61
+ );
62
+ }
63
+ get id() {
64
+ return this.#saved.plan.id;
65
+ }
66
+ get kind() {
67
+ return this.#saved.plan.kind;
68
+ }
69
+ estimateGas() {
70
+ return estimateGasReference(
71
+ this.#saved.plan,
72
+ this.#runtime.options.protocol,
73
+ this.#runtime.options.gasBenchmarks
74
+ );
75
+ }
76
+ preview() {
77
+ return operationPreview(this.#saved.plan, this.status);
78
+ }
79
+ current() {
80
+ check(
81
+ !this.#lifecycle.busy && this.#lifecycle.generation === this.#saved.generation,
82
+ "stale transaction handle or active worker"
83
+ );
84
+ }
85
+ async stage(stage, allowed, work, signal) {
86
+ signal?.throwIfAborted();
87
+ this.current();
88
+ check(allowed.includes(this.status), `invalid transaction stage for ${stage}`);
89
+ this.#lifecycle.busy = true;
90
+ const saved = structuredClone(this.#saved);
91
+ try {
92
+ const next = await work(saved);
93
+ signal?.throwIfAborted();
94
+ saved.generation++;
95
+ this.#lifecycle.generation = saved.generation;
96
+ return new _PreparedTransaction(
97
+ this.#runtime,
98
+ saved,
99
+ next.status,
100
+ this.#lifecycle,
101
+ next.authorization ?? this.#authorization
102
+ );
103
+ } finally {
104
+ this.#lifecycle.busy = false;
105
+ }
106
+ }
107
+ async authorize(providerOrOptions = {}, suppliedOptions = {}) {
108
+ const options = "authorize" in providerOrOptions ? suppliedOptions : providerOrOptions;
109
+ const provider = "authorize" in providerOrOptions ? providerOrOptions : this.#runtime.authorization();
110
+ check(
111
+ requiresAuthorization(this.#saved.plan),
112
+ "operation does not require wallet authorization"
113
+ );
114
+ const selectedProvider = provider;
115
+ check(
116
+ provider.walletIdentity === this.#runtime.scope.walletIdentity,
117
+ "wallet authorization capability mismatch"
118
+ );
119
+ return this.stage(
120
+ "wallet authorization",
121
+ ["prepared", "authorized"],
122
+ async (saved) => {
123
+ const authorization = await authorizeOperation(saved.plan, selectedProvider);
124
+ return { status: "authorized", authorization };
125
+ },
126
+ options.signal
127
+ );
128
+ }
129
+ async prove(backendOrOptions = {}, suppliedOptions = {}) {
130
+ const options = "prove" in backendOrOptions ? suppliedOptions : backendOrOptions;
131
+ const plan = this.#saved.plan;
132
+ check(plan.kind !== "shield", "shield requires no proof");
133
+ if (requiresAuthorization(plan)) {
134
+ check(
135
+ this.#authorization,
136
+ "local wallet authorization required; authorize again after recovery"
137
+ );
138
+ }
139
+ const prover = "prove" in backendOrOptions ? backendOrOptions : this.#runtime.options.prover;
140
+ if (!prover) {
141
+ throw new MissingCapabilityError("prover");
142
+ }
143
+ return this.stage(
144
+ "proof",
145
+ requiresAuthorization(plan) ? ["authorized"] : ["prepared"],
146
+ async (saved) => {
147
+ const p = saved.plan;
148
+ saved.proof = await proveOperation(
149
+ this.#runtime.options.protocol,
150
+ p,
151
+ this.#authorization,
152
+ prover,
153
+ options
154
+ );
155
+ if (p.fundingMode === "signature") {
156
+ return { status: "proved" };
157
+ }
158
+ if (p.statement?.target !== "noir-recursive") {
159
+ saved.call = await this.encode(saved);
160
+ }
161
+ return { status: "ready" };
162
+ },
163
+ options.signal
164
+ );
165
+ }
166
+ encode(saved) {
167
+ return encodeOperation(saved);
168
+ }
169
+ async authorizeFunding(signerOrOptions = {}, suppliedOptions = {}) {
170
+ const options = "signTypedData" in signerOrOptions ? suppliedOptions : signerOrOptions;
171
+ const suppliedSigner = "signTypedData" in signerOrOptions ? signerOrOptions : void 0;
172
+ const p = this.#saved.plan;
173
+ check(p.fundingMode === "signature", "operation does not require a funding signature");
174
+ check(p.kind === "shield" || this.#saved.proof, "proof must precede funding authorization");
175
+ const signer = suppliedSigner ?? this.#runtime.options.fundingSigner;
176
+ if (!signer) {
177
+ throw new MissingCapabilityError("EVM funding signer");
178
+ }
179
+ check(
180
+ signer.address.toLowerCase() === p.funding.payer.toLowerCase(),
181
+ "funding signer is not the payer"
182
+ );
183
+ return this.stage(
184
+ "funding authorization",
185
+ p.kind === "shield" ? ["prepared"] : ["proved"],
186
+ async (saved) => {
187
+ saved.plan.funding.signature = await signOperationFunding(
188
+ saved,
189
+ signer,
190
+ this.#runtime.options.fundingVerifier
191
+ );
192
+ if (saved.plan.statement?.target !== "noir-recursive") {
193
+ saved.call = await this.encode(saved);
194
+ }
195
+ return { status: "ready" };
196
+ },
197
+ options.signal
198
+ );
199
+ }
200
+ /** Shield caller funding needs no wallet signing or proof; this step only encodes its frozen request. */
201
+ async ready() {
202
+ check(
203
+ this.kind === "shield" && this.#saved.plan.fundingMode === "caller",
204
+ "operation needs authorization or proof first"
205
+ );
206
+ return this.stage("encoding", ["prepared"], async (saved) => {
207
+ saved.call = await this.encode(saved);
208
+ return { status: "ready" };
209
+ });
210
+ }
211
+ async exportTransaction() {
212
+ this.current();
213
+ check(
214
+ this.#saved.plan.statement?.target !== "noir-recursive",
215
+ "recursive operations must be exported as aggregate members"
216
+ );
217
+ check(this.status === "ready" && this.#saved.call, "transaction is not ready");
218
+ return structuredClone(this.#saved.call);
219
+ }
220
+ exportProof() {
221
+ this.current();
222
+ check(this.#saved.proof, "transaction has no proof");
223
+ return publicProof(this.#saved.proof);
224
+ }
225
+ exportAggregateMember() {
226
+ this.current();
227
+ const saved = this.#saved, plan = saved.plan;
228
+ check(
229
+ this.status === "ready" && plan.params && saved.proof && plan.statement?.target === "noir-recursive" && plan.statement.circuitName === "transact_user_slots14",
230
+ "ready recursive slots14 transaction required"
231
+ );
232
+ sameStatement(saved.proof, statement(plan));
233
+ check(
234
+ saved.proof.proofHex.length === 2 + 458 * 64,
235
+ "recursive member proof must have 458 fields"
236
+ );
237
+ return {
238
+ bundle: publicProof(saved.proof),
239
+ statement: structuredClone(plan.statement),
240
+ context: { ...plan.context },
241
+ request: {
242
+ params: structuredClone(plan.params),
243
+ deliveries: plan.outputs.map((output) => structuredClone(output.delivery)),
244
+ funding: normalizeFunding(plan.funding)
245
+ }
246
+ };
247
+ }
248
+ toJSON() {
249
+ return { transaction: true, id: this.id, kind: this.kind, status: this.status };
250
+ }
251
+ [/* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom")]() {
252
+ return this.toJSON();
253
+ }
254
+ };
255
+
256
+ // src/explicit-preparation.ts
257
+ function explicitPreparation(options, data, tokenAddress) {
258
+ if (!options.chainReader) throw new Error("chain reader required");
259
+ const inputs = structuredClone(data.inputs ?? []);
260
+ const credits = structuredClone(data.creditInputs ?? []);
261
+ const inventory = { notes: {}, credits: {}, reservations: {} };
262
+ const context = options.protocol.context;
263
+ function position(input) {
264
+ if (typeof input.treeId !== "bigint" || input.treeId < 0n || input.treeId >= 1n << 256n || !Number.isInteger(input.leafIndex) || input.leafIndex < 0 || input.leafIndex >= 65536)
265
+ throw new Error("invalid explicit input position");
266
+ }
267
+ for (const input of inputs) {
268
+ position(input);
269
+ positiveAmount(input.note.amount);
270
+ if (inventory.notes[input.commitment]) throw new Error("duplicate explicit note input");
271
+ if (input.note.chainId !== context.chainId || input.note.protocolAddress !== BigInt(context.protocolAddress) || input.note.walletIdentity !== options.wallet.walletIdentity)
272
+ throw new Error("explicit note identity or deployment mismatch");
273
+ inventory.notes[input.commitment] = { ...input, spent: "unspent" };
274
+ }
275
+ for (const input of credits) {
276
+ position(input);
277
+ if (input.role !== "owner" && input.role !== "spender")
278
+ throw new Error("invalid explicit Credit role");
279
+ const key = input.commitment + ":" + input.role;
280
+ if (inventory.credits[key]) throw new Error("duplicate explicit Credit input");
281
+ inventory.credits[key] = { ...input, spent: "unspent" };
282
+ }
283
+ const scope = {
284
+ ...context,
285
+ namespace: "explicit",
286
+ walletIdentity: options.wallet.walletIdentity
287
+ };
288
+ const { store: _store, coinSelector: _selector, ...capabilities } = options;
289
+ if (inputs.some((input) => input.note.tokenAddress !== BigInt(getAddress(tokenAddress))))
290
+ throw new Error("explicit note token mismatch");
291
+ const runtime = {
292
+ options: { ...capabilities, protocol: options.protocol.forToken(tokenAddress) },
293
+ reader: options.chainReader,
294
+ scope,
295
+ authorization: () => options.authorization ?? options.wallet.exportAuthorization()
296
+ };
297
+ return new TransactionPreparation({
298
+ ...runtime,
299
+ explicitInputs: true,
300
+ ...data.changeAddress ? { changeAddress: data.changeAddress } : {},
301
+ readInventory: async () => structuredClone(inventory),
302
+ complete: async (plan) => PreparedTransaction.prepare(runtime, plan)
303
+ });
304
+ }
305
+
306
+ // src/Invisi.ts
307
+ import { ProtocolRpcClient } from "@invisi-labs/rpc";
308
+ import { MissingCapabilityError as MissingCapabilityError2 } from "@invisi-labs/core";
309
+ var Invisi = class {
310
+ #options;
311
+ constructor(options = {}) {
312
+ this.#options = {
313
+ ...options,
314
+ ...options.gasBenchmarks ? { gasBenchmarks: copyGasBenchmarks(options.gasBenchmarks) } : {}
315
+ };
316
+ Object.freeze(this);
317
+ }
318
+ async connect(options) {
319
+ return new WalletSession(await this.resolve(options));
320
+ }
321
+ async resolve(options) {
322
+ const allowed = ["wallet", "protocol", "namespace", "viewing", "authorization"];
323
+ for (const key of Object.keys(options)) {
324
+ if (!allowed.includes(key))
325
+ throw new Error(
326
+ `Unknown connection option: ${key}; configure infrastructure on Invisi`
327
+ );
328
+ }
329
+ const selected = { ...options };
330
+ const combined = { ...this.#options, ...selected };
331
+ const { provider, signer, ...runtime } = combined;
332
+ const reader = combined.chainReader ?? (provider ? new EthersChainReader(provider) : void 0);
333
+ if (!reader) throw new MissingCapabilityError2("chain reader");
334
+ if (provider && (await provider.getNetwork()).chainId !== selected.protocol.context.chainId)
335
+ throw new Error("provider deployment chain mismatch");
336
+ await selected.protocol.validateDeployment(reader);
337
+ if (runtime.protocolRpc instanceof ProtocolRpcClient) {
338
+ runtime.protocolRpc = runtime.protocolRpc.withReader(reader);
339
+ }
340
+ if (signer) {
341
+ if (!provider) throw new MissingCapabilityError2("provider for signer");
342
+ if (!signer.provider) throw new Error("signer must be connected to a provider");
343
+ if ((await signer.provider.getNetwork()).chainId !== selected.protocol.context.chainId)
344
+ throw new Error("signer-provider deployment chain mismatch");
345
+ }
346
+ const registry = selected.protocol.deployment.registry;
347
+ const fundingSigner = combined.fundingSigner ?? (signer ? await EthersFundingSigner.create(signer, selected.protocol.context.chainId) : void 0);
348
+ const fundingVerifier = combined.fundingVerifier ?? (provider ? new EthersFundingVerifier(provider, selected.protocol.context.chainId) : void 0);
349
+ const addressResolver = combined.addressResolver ?? (provider && registry ? new EthersAddressResolver(
350
+ provider,
351
+ {
352
+ chainId: selected.protocol.context.chainId,
353
+ registryAddress: registry.address
354
+ },
355
+ registry.runtimeCodeHash
356
+ ).lookup : void 0);
357
+ return {
358
+ ...runtime,
359
+ chainReader: reader,
360
+ ...signer ? { signer } : {},
361
+ ...fundingSigner ? { fundingSigner } : {},
362
+ ...fundingVerifier ? { fundingVerifier } : {},
363
+ ...addressResolver ? { addressResolver } : {},
364
+ protocol: selected.protocol
365
+ };
366
+ }
367
+ async prepareTransfer(options) {
368
+ const { wallet, protocol, ...input } = options;
369
+ const request = structuredClone(input);
370
+ const runtime = await this.resolve({ wallet, protocol });
371
+ const preparation = explicitPreparation(runtime, request, request.tokenAddress);
372
+ return preparation.prepareTransfer(request);
373
+ }
374
+ async prepareWithdraw(options) {
375
+ const { wallet, protocol, ...input } = options;
376
+ const request = structuredClone(input);
377
+ const runtime = await this.resolve({ wallet, protocol });
378
+ const preparation = explicitPreparation(runtime, request, request.tokenAddress);
379
+ return preparation.prepareWithdraw(request);
380
+ }
381
+ async prepareSweep(options) {
382
+ const { wallet, protocol, ...input } = options;
383
+ const request = structuredClone(input);
384
+ const runtime = await this.resolve({ wallet, protocol });
385
+ const preparation = explicitPreparation(runtime, request, request.tokenAddress);
386
+ return preparation.prepareSweep(request);
387
+ }
388
+ async prepareShield(options) {
389
+ const { wallet, protocol, ...input } = options;
390
+ const request = structuredClone(input);
391
+ const runtime = await this.resolve({ wallet, protocol });
392
+ const preparation = explicitPreparation(runtime, {}, request.tokenAddress);
393
+ return preparation.prepareShield(request);
394
+ }
395
+ async prepareCreateCredit(options) {
396
+ const { wallet, protocol, ...input } = options;
397
+ const request = structuredClone(input);
398
+ const runtime = await this.resolve({ wallet, protocol });
399
+ const preparation = explicitPreparation(runtime, request, request.tokenAddress);
400
+ return preparation.prepareCreateCredit(request);
401
+ }
402
+ async prepareDrawCredit(options) {
403
+ const { wallet, protocol, ...input } = options;
404
+ const request = structuredClone(input);
405
+ const runtime = await this.resolve({ wallet, protocol });
406
+ const preparation = explicitPreparation(runtime, request, request.tokenAddress);
407
+ return preparation.prepareDrawCredit(request);
408
+ }
409
+ async prepareTopUpCredit(options) {
410
+ const { wallet, protocol, ...input } = options;
411
+ const request = structuredClone(input);
412
+ const runtime = await this.resolve({ wallet, protocol });
413
+ const preparation = explicitPreparation(runtime, request, request.tokenAddress);
414
+ return preparation.prepareTopUpCredit(request);
415
+ }
416
+ async prepareCancelCredit(options) {
417
+ const { wallet, protocol, ...input } = options;
418
+ const request = structuredClone(input);
419
+ const runtime = await this.resolve({ wallet, protocol });
420
+ const preparation = explicitPreparation(runtime, request, request.tokenAddress);
421
+ return preparation.prepareCancelCredit(request);
422
+ }
423
+ toJSON() {
424
+ return { invisi: true };
425
+ }
426
+ [/* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom")]() {
427
+ return this.toJSON();
428
+ }
429
+ };
430
+
431
+ // src/index.ts
432
+ import {
433
+ Wallet,
434
+ ViewingCapability,
435
+ Detector,
436
+ NullifierCapability,
437
+ WalletAuthorization,
438
+ MissingCapabilityError as MissingCapabilityError3,
439
+ Disclosure
440
+ } from "@invisi-labs/core";
441
+ import { Protocol, RegistrationOperation } from "@invisi-labs/protocol";
442
+ import { ProtocolRpcError } from "@invisi-labs/rpc";
443
+
444
+ // src/ProtocolRpcClient.ts
445
+ import { ProtocolRpcClient as RpcClient } from "@invisi-labs/rpc";
446
+ var ProtocolRpcClient2 = class extends RpcClient {
447
+ withProvider(provider) {
448
+ return this.withReader(new EthersChainReader(provider));
449
+ }
450
+ };
451
+
452
+ // src/AddressRegistry.ts
453
+ import { AddressRegistry as Registry } from "@invisi-labs/protocol";
454
+ var AddressRegistry = class extends Registry {
455
+ prepareRegistration(options) {
456
+ if ("provider" in options) {
457
+ const { provider, ...preparation } = options;
458
+ return super.prepareRegistration({
459
+ ...preparation,
460
+ reader: new EthersChainReader(provider)
461
+ });
462
+ }
463
+ return super.prepareRegistration(options);
464
+ }
465
+ };
466
+
467
+ // src/integrations/encrypted-codec.ts
468
+ var EncryptedWalletCodec = class _EncryptedWalletCodec {
469
+ #key;
470
+ constructor(key) {
471
+ this.#key = key;
472
+ }
473
+ static fromKey(key) {
474
+ if (key.type !== "secret" || key.algorithm.name !== "AES-GCM" || key.algorithm.length !== 256 || !key.usages.includes("encrypt") || !key.usages.includes("decrypt"))
475
+ throw new Error("wallet record key must support AES-256-GCM encryption and decryption");
476
+ return new _EncryptedWalletCodec(key);
477
+ }
478
+ static async fromBytes(key) {
479
+ if (key.length !== 32) throw new Error("wallet record encryption requires 32 key bytes");
480
+ const copy = Uint8Array.from(key);
481
+ try {
482
+ return _EncryptedWalletCodec.fromKey(
483
+ await crypto.subtle.importKey("raw", copy, { name: "AES-GCM" }, false, [
484
+ "encrypt",
485
+ "decrypt"
486
+ ])
487
+ );
488
+ } finally {
489
+ copy.fill(0);
490
+ }
491
+ }
492
+ aad(context) {
493
+ if (!Number.isSafeInteger(context.revision) || context.revision < 1)
494
+ throw new Error("invalid encrypted record revision");
495
+ return new TextEncoder().encode(
496
+ `Invisi.WalletRecord.v1\0${context.revision}\0${context.key}`
497
+ );
498
+ }
499
+ async encode(state, context) {
500
+ const iv = crypto.getRandomValues(new Uint8Array(12)), plain = Uint8Array.from(serializeState(state));
501
+ try {
502
+ const encrypted = new Uint8Array(
503
+ await crypto.subtle.encrypt(
504
+ { name: "AES-GCM", iv, additionalData: this.aad(context) },
505
+ this.#key,
506
+ plain
507
+ )
508
+ );
509
+ const out = new Uint8Array(13 + encrypted.length);
510
+ out[0] = 1;
511
+ out.set(iv, 1);
512
+ out.set(encrypted, 13);
513
+ return out;
514
+ } finally {
515
+ plain.fill(0);
516
+ }
517
+ }
518
+ async decode(data, context) {
519
+ if (data.length < 29 || data[0] !== 1)
520
+ throw new Error("wallet record authentication failed");
521
+ let plain;
522
+ try {
523
+ plain = new Uint8Array(
524
+ await crypto.subtle.decrypt(
525
+ {
526
+ name: "AES-GCM",
527
+ iv: Uint8Array.from(data.subarray(1, 13)),
528
+ additionalData: this.aad(context)
529
+ },
530
+ this.#key,
531
+ Uint8Array.from(data.subarray(13))
532
+ )
533
+ );
534
+ } catch {
535
+ throw new Error("wallet record authentication failed");
536
+ }
537
+ try {
538
+ return deserializeState(plain);
539
+ } finally {
540
+ plain.fill(0);
541
+ }
542
+ }
543
+ toJSON() {
544
+ return { walletRecordCodec: "AES-256-GCM" };
545
+ }
546
+ [/* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom")]() {
547
+ return this.toJSON();
548
+ }
549
+ };
550
+ export {
551
+ AddressRegistry,
552
+ Detector,
553
+ Disclosure,
554
+ DisclosureVerifier,
555
+ EncryptedWalletCodec,
556
+ Invisi,
557
+ MissingCapabilityError3 as MissingCapabilityError,
558
+ NullifierCapability,
559
+ Operation,
560
+ PreparedTransaction,
561
+ Protocol,
562
+ ProtocolRpcClient2 as ProtocolRpcClient,
563
+ ProtocolRpcError,
564
+ RegistrationOperation,
565
+ ViewingCapability,
566
+ Wallet,
567
+ WalletAuthorization,
568
+ WalletSession,
569
+ defineGasBenchmarks,
570
+ walletBalance
571
+ };
572
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/explicit-preparation.ts","../src/PreparedTransaction.ts","../src/Invisi.ts","../src/index.ts","../src/ProtocolRpcClient.ts","../src/AddressRegistry.ts","../src/integrations/encrypted-codec.ts"],"sourcesContent":["import { getAddress } from \"ethers\";\nimport type { CreditInput, NoteInput } from \"./explicit-types\";\nimport { PreparedTransaction } from \"./PreparedTransaction\";\nimport { positiveAmount } from \"./session/prepare-common\";\nimport { TransactionPreparation } from \"./session/transaction-preparation\";\nimport type { PreparationInventory, WalletSessionOptions } from \"./session/operation-types\";\n\n/** Only explicitly supplied records participate. No store or automatic coin selection. */\nexport function explicitPreparation(\n options: WalletSessionOptions,\n data: {\n inputs?: readonly NoteInput[];\n creditInputs?: readonly CreditInput[];\n changeAddress?: string;\n },\n tokenAddress: `0x${string}`\n) {\n if (!options.chainReader) throw new Error(\"chain reader required\");\n const inputs = structuredClone(data.inputs ?? []);\n const credits = structuredClone(data.creditInputs ?? []);\n const inventory: PreparationInventory = { notes: {}, credits: {}, reservations: {} };\n const context = options.protocol.context;\n function position(input: NoteInput | CreditInput) {\n if (\n typeof input.treeId !== \"bigint\" ||\n input.treeId < 0n ||\n input.treeId >= 1n << 256n ||\n !Number.isInteger(input.leafIndex) ||\n input.leafIndex < 0 ||\n input.leafIndex >= 65536\n )\n throw new Error(\"invalid explicit input position\");\n }\n for (const input of inputs) {\n position(input);\n positiveAmount(input.note.amount);\n if (inventory.notes[input.commitment]) throw new Error(\"duplicate explicit note input\");\n if (\n input.note.chainId !== context.chainId ||\n input.note.protocolAddress !== BigInt(context.protocolAddress) ||\n input.note.walletIdentity !== options.wallet.walletIdentity\n )\n throw new Error(\"explicit note identity or deployment mismatch\");\n inventory.notes[input.commitment] = { ...input, spent: \"unspent\" };\n }\n for (const input of credits) {\n position(input);\n if (input.role !== \"owner\" && input.role !== \"spender\")\n throw new Error(\"invalid explicit Credit role\");\n const key = input.commitment + \":\" + input.role;\n if (inventory.credits[key]) throw new Error(\"duplicate explicit Credit input\");\n inventory.credits[key] = { ...input, spent: \"unspent\" };\n }\n const scope = {\n ...context,\n namespace: \"explicit\",\n walletIdentity: options.wallet.walletIdentity,\n };\n const { store: _store, coinSelector: _selector, ...capabilities } = options;\n\n if (inputs.some((input) => input.note.tokenAddress !== BigInt(getAddress(tokenAddress))))\n throw new Error(\"explicit note token mismatch\");\n const runtime = {\n options: { ...capabilities, protocol: options.protocol.forToken(tokenAddress) },\n reader: options.chainReader!,\n scope,\n authorization: () => options.authorization ?? options.wallet.exportAuthorization(),\n };\n return new TransactionPreparation<PreparedTransaction>({\n ...runtime,\n explicitInputs: true,\n ...(data.changeAddress ? { changeAddress: data.changeAddress } : {}),\n readInventory: async () => structuredClone(inventory),\n complete: async (plan) => PreparedTransaction.prepare(runtime, plan),\n });\n}\n","import { estimateGasReference } from \"./gas-estimation\";\nimport {\n authorizeOperation,\n proveOperation,\n signOperationFunding,\n} from \"./session/operation-execution\";\nimport {\n MissingCapabilityError,\n type AuthorizedStatement,\n type WalletAuthorizationProvider,\n} from \"@invisi-labs/core\";\nimport { normalizeFunding, type TransactionCall } from \"@invisi-labs/protocol\";\nimport type { Prover, ProverOptions, ProofBundle } from \"@invisi-labs/prover\";\nimport type {\n FundingSigner,\n OperationPlan,\n OperationRuntime,\n OperationAggregateMember,\n SavedOperation,\n} from \"./session/operation-types\";\nimport type { OperationStatus } from \"./session/state\";\nimport {\n encodeOperation,\n publicProof,\n requiresAuthorization,\n statement,\n} from \"./session/operation-protocol\";\nimport { sameStatement } from \"./session/proof-integrity\";\nimport { operationPreview } from \"./session/operation-preview\";\nfunction check(ok: unknown, message: string): asserts ok {\n if (!ok) throw new Error(message);\n}\n\ntype Runtime = Omit<OperationRuntime, \"store\">;\ntype Lifecycle = { generation: number; busy: boolean };\n/** An immutable, local transaction handle. No wallet inventory, reservations or persistence. */\nexport class PreparedTransaction {\n readonly #runtime: Runtime;\n readonly #saved: SavedOperation;\n readonly #authorization: AuthorizedStatement | undefined;\n readonly #lifecycle: Lifecycle;\n readonly status: OperationStatus;\n private constructor(\n runtime: Runtime,\n saved: SavedOperation,\n status: OperationStatus,\n lifecycle: Lifecycle,\n authorization?: AuthorizedStatement\n ) {\n this.#runtime = runtime;\n this.#saved = structuredClone(saved);\n this.#lifecycle = lifecycle;\n this.#authorization = authorization;\n this.status = status;\n Object.freeze(this);\n }\n static prepare(runtime: Runtime, plan: OperationPlan): PreparedTransaction {\n return new PreparedTransaction(\n runtime,\n { plan: structuredClone(plan), generation: 0 },\n \"prepared\",\n { generation: 0, busy: false }\n );\n }\n get id() {\n return this.#saved.plan.id;\n }\n get kind() {\n return this.#saved.plan.kind;\n }\n estimateGas() {\n return estimateGasReference(\n this.#saved.plan,\n this.#runtime.options.protocol,\n this.#runtime.options.gasBenchmarks\n );\n }\n preview() {\n return operationPreview(this.#saved.plan, this.status);\n }\n private current() {\n check(\n !this.#lifecycle.busy && this.#lifecycle.generation === this.#saved.generation,\n \"stale transaction handle or active worker\"\n );\n }\n private async stage(\n stage: string,\n allowed: OperationStatus[],\n work: (\n saved: SavedOperation\n ) => Promise<{ status: OperationStatus; authorization?: AuthorizedStatement }>,\n signal?: AbortSignal\n ): Promise<PreparedTransaction> {\n signal?.throwIfAborted();\n this.current();\n check(allowed.includes(this.status), `invalid transaction stage for ${stage}`);\n this.#lifecycle.busy = true;\n const saved = structuredClone(this.#saved);\n try {\n const next = await work(saved);\n signal?.throwIfAborted();\n saved.generation++;\n this.#lifecycle.generation = saved.generation;\n return new PreparedTransaction(\n this.#runtime,\n saved,\n next.status,\n this.#lifecycle,\n next.authorization ?? this.#authorization\n );\n } finally {\n this.#lifecycle.busy = false;\n }\n }\n async authorize(options?: { signal?: AbortSignal }): Promise<PreparedTransaction>;\n async authorize(\n provider: WalletAuthorizationProvider,\n options?: { signal?: AbortSignal }\n ): Promise<PreparedTransaction>;\n async authorize(\n providerOrOptions: WalletAuthorizationProvider | { signal?: AbortSignal } = {},\n suppliedOptions: { signal?: AbortSignal } = {}\n ): Promise<PreparedTransaction> {\n const options = \"authorize\" in providerOrOptions ? suppliedOptions : providerOrOptions;\n const provider =\n \"authorize\" in providerOrOptions ? providerOrOptions : this.#runtime.authorization();\n check(\n requiresAuthorization(this.#saved.plan),\n \"operation does not require wallet authorization\"\n );\n const selectedProvider = provider;\n check(\n provider.walletIdentity === this.#runtime.scope.walletIdentity,\n \"wallet authorization capability mismatch\"\n );\n return this.stage(\n \"wallet authorization\",\n [\"prepared\", \"authorized\"],\n async (saved) => {\n const authorization = await authorizeOperation(saved.plan, selectedProvider);\n return { status: \"authorized\", authorization };\n },\n options.signal\n );\n }\n\n async prove(options?: ProverOptions): Promise<PreparedTransaction>;\n async prove(backend: Prover, options?: ProverOptions): Promise<PreparedTransaction>;\n async prove(\n backendOrOptions: Prover | ProverOptions = {},\n suppliedOptions: ProverOptions = {}\n ): Promise<PreparedTransaction> {\n const options = \"prove\" in backendOrOptions ? suppliedOptions : backendOrOptions;\n const plan = this.#saved.plan;\n check(plan.kind !== \"shield\", \"shield requires no proof\");\n if (requiresAuthorization(plan)) {\n check(\n this.#authorization,\n \"local wallet authorization required; authorize again after recovery\"\n );\n }\n const prover =\n \"prove\" in backendOrOptions ? backendOrOptions : this.#runtime.options.prover;\n if (!prover) {\n throw new MissingCapabilityError(\"prover\");\n }\n return this.stage(\n \"proof\",\n requiresAuthorization(plan) ? [\"authorized\"] : [\"prepared\"],\n async (saved) => {\n const p = saved.plan;\n saved.proof = await proveOperation(\n this.#runtime.options.protocol,\n p,\n this.#authorization,\n prover,\n options\n );\n if (p.fundingMode === \"signature\") {\n return { status: \"proved\" };\n }\n if (p.statement?.target !== \"noir-recursive\") {\n saved.call = await this.encode(saved);\n }\n return { status: \"ready\" };\n },\n options.signal\n );\n }\n\n private encode(saved: SavedOperation): Promise<TransactionCall> {\n return encodeOperation(saved);\n }\n\n async authorizeFunding(options?: { signal?: AbortSignal }): Promise<PreparedTransaction>;\n async authorizeFunding(\n signer: FundingSigner,\n options?: { signal?: AbortSignal }\n ): Promise<PreparedTransaction>;\n async authorizeFunding(\n signerOrOptions: FundingSigner | { signal?: AbortSignal } = {},\n suppliedOptions: { signal?: AbortSignal } = {}\n ): Promise<PreparedTransaction> {\n const options = \"signTypedData\" in signerOrOptions ? suppliedOptions : signerOrOptions;\n const suppliedSigner = \"signTypedData\" in signerOrOptions ? signerOrOptions : undefined;\n const p = this.#saved.plan;\n check(p.fundingMode === \"signature\", \"operation does not require a funding signature\");\n check(p.kind === \"shield\" || this.#saved.proof, \"proof must precede funding authorization\");\n const signer = suppliedSigner ?? this.#runtime.options.fundingSigner;\n if (!signer) {\n throw new MissingCapabilityError(\"EVM funding signer\");\n }\n check(\n signer.address.toLowerCase() === p.funding.payer!.toLowerCase(),\n \"funding signer is not the payer\"\n );\n return this.stage(\n \"funding authorization\",\n p.kind === \"shield\" ? [\"prepared\"] : [\"proved\"],\n async (saved) => {\n saved.plan.funding.signature = await signOperationFunding(\n saved,\n signer,\n this.#runtime.options.fundingVerifier\n );\n if (saved.plan.statement?.target !== \"noir-recursive\") {\n saved.call = await this.encode(saved);\n }\n return { status: \"ready\" };\n },\n options.signal\n );\n }\n\n /** Shield caller funding needs no wallet signing or proof; this step only encodes its frozen request. */\n async ready(): Promise<PreparedTransaction> {\n check(\n this.kind === \"shield\" && this.#saved.plan.fundingMode === \"caller\",\n \"operation needs authorization or proof first\"\n );\n return this.stage(\"encoding\", [\"prepared\"], async (saved) => {\n saved.call = await this.encode(saved);\n return { status: \"ready\" };\n });\n }\n\n async exportTransaction(): Promise<TransactionCall> {\n this.current();\n check(\n this.#saved.plan.statement?.target !== \"noir-recursive\",\n \"recursive operations must be exported as aggregate members\"\n );\n check(this.status === \"ready\" && this.#saved.call, \"transaction is not ready\");\n return structuredClone(this.#saved.call);\n }\n exportProof(): ProofBundle {\n this.current();\n check(this.#saved.proof, \"transaction has no proof\");\n return publicProof(this.#saved.proof);\n }\n exportAggregateMember(): OperationAggregateMember {\n this.current();\n const saved = this.#saved,\n plan = saved.plan;\n check(\n this.status === \"ready\" &&\n plan.params &&\n saved.proof &&\n plan.statement?.target === \"noir-recursive\" &&\n plan.statement.circuitName === \"transact_user_slots14\",\n \"ready recursive slots14 transaction required\"\n );\n sameStatement(saved.proof, statement(plan));\n check(\n saved.proof.proofHex.length === 2 + 458 * 64,\n \"recursive member proof must have 458 fields\"\n );\n return {\n bundle: publicProof(saved.proof),\n statement: structuredClone(plan.statement),\n context: { ...plan.context },\n request: {\n params: structuredClone(plan.params),\n deliveries: plan.outputs.map((output) => structuredClone(output.delivery)),\n funding: normalizeFunding(plan.funding),\n },\n };\n }\n toJSON() {\n return { transaction: true, id: this.id, kind: this.kind, status: this.status };\n }\n [Symbol.for(\"nodejs.util.inspect.custom\")]() {\n return this.toJSON();\n }\n}\n","import { copyGasBenchmarks } from \"./gas-estimation\";\nimport { explicitPreparation } from \"./explicit-preparation\";\nimport type { PreparedTransaction } from \"./PreparedTransaction\";\nimport type {\n ExplicitTransferPreparation,\n ExplicitWithdrawalPreparation,\n ExplicitSweepPreparation,\n ExplicitShieldPreparation,\n ExplicitCreateCreditPreparation,\n ExplicitDrawCreditPreparation,\n ExplicitTopUpCreditPreparation,\n ExplicitCancelCreditPreparation,\n} from \"./explicit-types\";\nimport { ProtocolRpcClient } from \"@invisi-labs/rpc\";\nimport type { Provider, Signer } from \"ethers\";\nimport {\n EthersChainReader,\n EthersFundingSigner,\n EthersFundingVerifier,\n EthersAddressResolver,\n} from \"./integrations/ethers\";\nimport { MissingCapabilityError } from \"@invisi-labs/core\";\nimport { Protocol, type ChainReader } from \"@invisi-labs/protocol\";\nimport { WalletSession, type WalletSessionOptions } from \"./session\";\n\n/** Compose independent Chain RPC and indexed Protocol RPC with local wallet capabilities. */\nexport type InvisiOptions = Omit<\n WalletSessionOptions,\n \"wallet\" | \"protocol\" | \"namespace\" | \"viewing\" | \"authorization\" | \"chainReader\"\n> & {\n provider?: Provider;\n signer?: Signer;\n chainReader?: ChainReader;\n};\n\n/** Wallet identity and session permissions; shared infrastructure belongs to InvisiOptions. */\nexport type ConnectionOptions = Pick<\n WalletSessionOptions,\n \"wallet\" | \"protocol\" | \"namespace\" | \"viewing\" | \"authorization\"\n>;\n\n/** A neutral composition entry point; every resolved instance owns an independent session. */\nexport class Invisi {\n readonly #options: InvisiOptions;\n\n constructor(options: InvisiOptions = {}) {\n this.#options = {\n ...options,\n ...(options.gasBenchmarks\n ? { gasBenchmarks: copyGasBenchmarks(options.gasBenchmarks) }\n : {}),\n };\n Object.freeze(this);\n }\n\n async connect(options: ConnectionOptions): Promise<WalletSession> {\n return new WalletSession(await this.resolve(options));\n }\n private async resolve(options: ConnectionOptions): Promise<WalletSessionOptions> {\n // Snapshot session permissions before the first network request.\n const allowed = [\"wallet\", \"protocol\", \"namespace\", \"viewing\", \"authorization\"];\n for (const key of Object.keys(options)) {\n if (!allowed.includes(key))\n throw new Error(\n `Unknown connection option: ${key}; configure infrastructure on Invisi`\n );\n }\n const selected = { ...options };\n const combined = { ...this.#options, ...selected };\n const { provider, signer, ...runtime } = combined;\n const reader =\n combined.chainReader ?? (provider ? new EthersChainReader(provider) : undefined);\n if (!reader) throw new MissingCapabilityError(\"chain reader\");\n if (provider && (await provider.getNetwork()).chainId !== selected.protocol.context.chainId)\n throw new Error(\"provider deployment chain mismatch\");\n await selected.protocol.validateDeployment(reader);\n if (runtime.protocolRpc instanceof ProtocolRpcClient) {\n runtime.protocolRpc = runtime.protocolRpc.withReader(reader);\n }\n if (signer) {\n if (!provider) throw new MissingCapabilityError(\"provider for signer\");\n if (!signer.provider) throw new Error(\"signer must be connected to a provider\");\n if ((await signer.provider.getNetwork()).chainId !== selected.protocol.context.chainId)\n throw new Error(\"signer-provider deployment chain mismatch\");\n }\n const registry = selected.protocol.deployment.registry;\n const fundingSigner =\n combined.fundingSigner ??\n (signer\n ? await EthersFundingSigner.create(signer, selected.protocol.context.chainId)\n : undefined);\n const fundingVerifier =\n combined.fundingVerifier ??\n (provider\n ? new EthersFundingVerifier(provider, selected.protocol.context.chainId)\n : undefined);\n const addressResolver =\n combined.addressResolver ??\n (provider && registry\n ? new EthersAddressResolver(\n provider,\n {\n chainId: selected.protocol.context.chainId,\n registryAddress: registry.address,\n },\n registry.runtimeCodeHash\n ).lookup\n : undefined);\n return {\n ...runtime,\n chainReader: reader,\n ...(signer ? { signer } : {}),\n ...(fundingSigner ? { fundingSigner } : {}),\n ...(fundingVerifier ? { fundingVerifier } : {}),\n ...(addressResolver ? { addressResolver } : {}),\n protocol: selected.protocol,\n };\n }\n\n async prepareTransfer(options: ExplicitTransferPreparation): Promise<PreparedTransaction> {\n const { wallet, protocol, ...input } = options;\n const request = structuredClone(input);\n const runtime = await this.resolve({ wallet, protocol });\n const preparation = explicitPreparation(runtime, request, request.tokenAddress);\n return preparation.prepareTransfer(request);\n }\n async prepareWithdraw(options: ExplicitWithdrawalPreparation): Promise<PreparedTransaction> {\n const { wallet, protocol, ...input } = options;\n const request = structuredClone(input);\n const runtime = await this.resolve({ wallet, protocol });\n const preparation = explicitPreparation(runtime, request, request.tokenAddress);\n return preparation.prepareWithdraw(request);\n }\n async prepareSweep(options: ExplicitSweepPreparation): Promise<PreparedTransaction> {\n const { wallet, protocol, ...input } = options;\n const request = structuredClone(input);\n const runtime = await this.resolve({ wallet, protocol });\n const preparation = explicitPreparation(runtime, request, request.tokenAddress);\n return preparation.prepareSweep(request);\n }\n async prepareShield(options: ExplicitShieldPreparation): Promise<PreparedTransaction> {\n const { wallet, protocol, ...input } = options;\n const request = structuredClone(input);\n const runtime = await this.resolve({ wallet, protocol });\n const preparation = explicitPreparation(runtime, {}, request.tokenAddress);\n return preparation.prepareShield(request);\n }\n async prepareCreateCredit(\n options: ExplicitCreateCreditPreparation\n ): Promise<PreparedTransaction> {\n const { wallet, protocol, ...input } = options;\n const request = structuredClone(input);\n const runtime = await this.resolve({ wallet, protocol });\n const preparation = explicitPreparation(runtime, request, request.tokenAddress);\n return preparation.prepareCreateCredit(request);\n }\n async prepareDrawCredit(options: ExplicitDrawCreditPreparation): Promise<PreparedTransaction> {\n const { wallet, protocol, ...input } = options;\n const request = structuredClone(input);\n const runtime = await this.resolve({ wallet, protocol });\n const preparation = explicitPreparation(runtime, request, request.tokenAddress);\n return preparation.prepareDrawCredit(request);\n }\n async prepareTopUpCredit(\n options: ExplicitTopUpCreditPreparation\n ): Promise<PreparedTransaction> {\n const { wallet, protocol, ...input } = options;\n const request = structuredClone(input);\n const runtime = await this.resolve({ wallet, protocol });\n const preparation = explicitPreparation(runtime, request, request.tokenAddress);\n return preparation.prepareTopUpCredit(request);\n }\n async prepareCancelCredit(\n options: ExplicitCancelCreditPreparation\n ): Promise<PreparedTransaction> {\n const { wallet, protocol, ...input } = options;\n const request = structuredClone(input);\n const runtime = await this.resolve({ wallet, protocol });\n const preparation = explicitPreparation(runtime, request, request.tokenAddress);\n return preparation.prepareCancelCredit(request);\n }\n\n toJSON() {\n return { invisi: true };\n }\n [Symbol.for(\"nodejs.util.inspect.custom\")]() {\n return this.toJSON();\n }\n}\n","export { Invisi } from \"./Invisi\";\nexport type { InvisiOptions, ConnectionOptions } from \"./Invisi\";\nexport {\n Wallet,\n ViewingCapability,\n Detector,\n NullifierCapability,\n WalletAuthorization,\n MissingCapabilityError,\n Disclosure,\n} from \"@invisi-labs/core\";\nexport type {\n Address,\n Hex,\n Note,\n CreditNote,\n CreditDeliveryState,\n ReceivingKeys,\n WalletAuthorizationProvider,\n CreditOpening,\n DisclosureOutput,\n DisclosureExport,\n DisclosureResult,\n} from \"@invisi-labs/core\";\nexport { Protocol, RegistrationOperation } from \"@invisi-labs/protocol\";\nexport type {\n ChainReader,\n ProtocolDataProvider,\n ProtocolDataStatus,\n ProtocolUpdates,\n ProtocolUpdateRange,\n TransactionCall,\n CanonicalBlock,\n CanonicalReceipt,\n Membership,\n RegistryReader,\n ProtocolOptions,\n TokenProtocol,\n TokenProtocolOptions,\n FactoryReader,\n AddressRegistryOptions,\n RegistryContext,\n TransactionContext,\n} from \"@invisi-labs/protocol\";\nexport { WalletSession, Operation, walletBalance, DisclosureVerifier } from \"./session\";\nexport type {\n RefreshOptions,\n RefreshResult,\n WalletStore,\n WalletScope,\n WalletState,\n BalanceSnapshot,\n WalletSessionOptions,\n TransferPreparation,\n WithdrawalPreparation,\n SweepPreparation,\n ShieldPreparation,\n CreateCreditPreparation,\n DrawCreditPreparation,\n TopUpCreditPreparation,\n CancelCreditPreparation,\n FundingSigner,\n FundingAuthorizationVerifier,\n FundingTypedData,\n FundingSource,\n CoinSelector,\n OperationStatus,\n OperationAggregateMember,\n DisclosureReference,\n DisclosureReader,\n DisclosureVerifierOptions,\n DisclosureEvidence,\n VerifiedDisclosure,\n} from \"./session\";\nexport type {\n Prover,\n ProverOptions,\n ProofBundle,\n ProofStatement,\n AggregatorCapability,\n AggregateMember,\n} from \"@invisi-labs/prover\";\n\nexport { ProtocolRpcError } from \"@invisi-labs/rpc\";\nexport type { ProtocolDeployment } from \"@invisi-labs/rpc\";\nexport { ProtocolRpcClient } from \"./ProtocolRpcClient\";\nexport { AddressRegistry } from \"./AddressRegistry\";\nexport type {\n ProtocolRpcClientOptions,\n ProtocolRpcReader,\n ProtocolRpcConnectionOptions,\n ProtocolRpcChain,\n} from \"@invisi-labs/rpc\";\n\nexport { EncryptedWalletCodec } from \"./integrations/encrypted-codec\";\n\nexport { PreparedTransaction } from \"./PreparedTransaction\";\nexport type {\n NoteInput,\n CreditInput,\n TransactionIdentity,\n ExplicitTransferPreparation,\n ExplicitWithdrawalPreparation,\n ExplicitSweepPreparation,\n ExplicitShieldPreparation,\n ExplicitCreateCreditPreparation,\n ExplicitDrawCreditPreparation,\n ExplicitTopUpCreditPreparation,\n ExplicitCancelCreditPreparation,\n} from \"./explicit-types\";\n\nexport type { SessionTransactionOptions } from \"./session/WalletSession\";\n\nexport type {\n GasBenchmarkProfile,\n GasBenchmarkShape,\n GasBenchmarkDeployment,\n GasBenchmarkCircuit,\n GasBenchmarkSample,\n GasReference,\n} from \"./gas-estimation\";\n\nexport { defineGasBenchmarks } from \"./gas-estimation\";\n","import type { Provider } from \"ethers\";\nimport { ProtocolRpcClient as RpcClient } from \"@invisi-labs/rpc\";\nimport { EthersChainReader } from \"./integrations/ethers\";\n\n/** Protocol RPC transport with ethers provider integration for independent chain checks. */\nexport class ProtocolRpcClient extends RpcClient {\n withProvider(provider: Provider): RpcClient {\n return this.withReader(new EthersChainReader(provider));\n }\n}\n","import type { Provider } from \"ethers\";\nimport { AddressRegistry as Registry, type RegistrationPreparation } from \"@invisi-labs/protocol\";\nimport { EthersChainReader } from \"./integrations/ethers\";\n\n/** Registry operations accept the application's existing ethers provider. */\nexport class AddressRegistry extends Registry {\n override prepareRegistration(\n options:\n | RegistrationPreparation\n | (Omit<RegistrationPreparation, \"reader\"> & { provider: Provider })\n ) {\n if (\"provider\" in options) {\n const { provider, ...preparation } = options;\n return super.prepareRegistration({\n ...preparation,\n reader: new EthersChainReader(provider),\n });\n }\n return super.prepareRegistration(options);\n }\n}\n","import {\n serializeState,\n deserializeState,\n type WalletState,\n type WalletRecordCodec,\n} from \"../session\";\n/** Caller-owned, nonextractable AES-GCM key. The SDK does not persist the key. */\nexport class EncryptedWalletCodec implements WalletRecordCodec {\n readonly #key: CryptoKey;\n private constructor(key: CryptoKey) {\n this.#key = key;\n }\n static fromKey(key: CryptoKey): EncryptedWalletCodec {\n if (\n key.type !== \"secret\" ||\n key.algorithm.name !== \"AES-GCM\" ||\n (key.algorithm as AesKeyAlgorithm).length !== 256 ||\n !key.usages.includes(\"encrypt\") ||\n !key.usages.includes(\"decrypt\")\n )\n throw new Error(\"wallet record key must support AES-256-GCM encryption and decryption\");\n return new EncryptedWalletCodec(key);\n }\n static async fromBytes(key: Uint8Array): Promise<EncryptedWalletCodec> {\n if (key.length !== 32) throw new Error(\"wallet record encryption requires 32 key bytes\");\n const copy = Uint8Array.from(key);\n try {\n return EncryptedWalletCodec.fromKey(\n await crypto.subtle.importKey(\"raw\", copy, { name: \"AES-GCM\" }, false, [\n \"encrypt\",\n \"decrypt\",\n ])\n );\n } finally {\n copy.fill(0);\n }\n }\n private aad(context: { key: string; revision: number }): Uint8Array<ArrayBuffer> {\n if (!Number.isSafeInteger(context.revision) || context.revision < 1)\n throw new Error(\"invalid encrypted record revision\");\n return new TextEncoder().encode(\n `Invisi.WalletRecord.v1\\0${context.revision}\\0${context.key}`\n );\n }\n async encode(\n state: WalletState,\n context: { key: string; revision: number }\n ): Promise<Uint8Array> {\n const iv = crypto.getRandomValues(new Uint8Array(12)),\n plain = Uint8Array.from(serializeState(state));\n try {\n const encrypted = new Uint8Array(\n await crypto.subtle.encrypt(\n { name: \"AES-GCM\", iv, additionalData: this.aad(context) },\n this.#key,\n plain\n )\n );\n const out = new Uint8Array(13 + encrypted.length);\n out[0] = 1;\n out.set(iv, 1);\n out.set(encrypted, 13);\n return out;\n } finally {\n plain.fill(0);\n }\n }\n async decode(\n data: Uint8Array,\n context: { key: string; revision: number }\n ): Promise<WalletState> {\n if (data.length < 29 || data[0] !== 1)\n throw new Error(\"wallet record authentication failed\");\n let plain: Uint8Array;\n try {\n plain = new Uint8Array(\n await crypto.subtle.decrypt(\n {\n name: \"AES-GCM\",\n iv: Uint8Array.from(data.subarray(1, 13)),\n additionalData: this.aad(context),\n },\n this.#key,\n Uint8Array.from(data.subarray(13))\n )\n );\n } catch {\n throw new Error(\"wallet record authentication failed\");\n }\n try {\n return deserializeState(plain);\n } finally {\n plain.fill(0);\n }\n }\n toJSON() {\n return { walletRecordCodec: \"AES-256-GCM\" };\n }\n [Symbol.for(\"nodejs.util.inspect.custom\")]() {\n return this.toJSON();\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,kBAAkB;;;ACM3B;AAAA,EACI;AAAA,OAGG;AACP,SAAS,wBAA8C;AAkBvD,SAAS,MAAM,IAAa,SAA6B;AACrD,MAAI,CAAC,GAAI,OAAM,IAAI,MAAM,OAAO;AACpC;AAKO,IAAM,sBAAN,MAAM,qBAAoB;AAAA,EACpB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACD,YACJ,SACA,OACA,QACA,WACA,eACF;AACE,SAAK,WAAW;AAChB,SAAK,SAAS,gBAAgB,KAAK;AACnC,SAAK,aAAa;AAClB,SAAK,iBAAiB;AACtB,SAAK,SAAS;AACd,WAAO,OAAO,IAAI;AAAA,EACtB;AAAA,EACA,OAAO,QAAQ,SAAkB,MAA0C;AACvE,WAAO,IAAI;AAAA,MACP;AAAA,MACA,EAAE,MAAM,gBAAgB,IAAI,GAAG,YAAY,EAAE;AAAA,MAC7C;AAAA,MACA,EAAE,YAAY,GAAG,MAAM,MAAM;AAAA,IACjC;AAAA,EACJ;AAAA,EACA,IAAI,KAAK;AACL,WAAO,KAAK,OAAO,KAAK;AAAA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