@invisi-labs/sdk 1.1.5 → 1.1.6

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.
Files changed (45) hide show
  1. package/dist/{operation-types-DIazgS2d.d.cts → NoteOutput-DRkVnwlx.d.cts} +140 -17
  2. package/dist/{operation-types-D7I405FX.d.ts → NoteOutput-DpDC6T2O.d.ts} +140 -17
  3. package/dist/broadcaster-preparation-QVL62KM6.js +128 -0
  4. package/dist/broadcaster-preparation-QVL62KM6.js.map +1 -0
  5. package/dist/{chunk-BE52B32Z.js → chunk-4SD3MW6N.js} +846 -1625
  6. package/dist/chunk-4SD3MW6N.js.map +1 -0
  7. package/dist/chunk-FL4TIGWW.js +1781 -0
  8. package/dist/chunk-FL4TIGWW.js.map +1 -0
  9. package/dist/{chunk-4HMM7ZKY.js → chunk-QC6TQR3R.js} +8 -8
  10. package/dist/chunk-QC6TQR3R.js.map +1 -0
  11. package/dist/ethers.cjs +7 -7
  12. package/dist/ethers.cjs.map +1 -1
  13. package/dist/ethers.d.cts +3 -3
  14. package/dist/ethers.d.ts +3 -3
  15. package/dist/ethers.js +1 -1
  16. package/dist/index.cjs +4520 -2902
  17. package/dist/index.cjs.map +1 -1
  18. package/dist/index.d.cts +273 -25
  19. package/dist/index.d.ts +273 -25
  20. package/dist/index.js +459 -52
  21. package/dist/index.js.map +1 -1
  22. package/dist/indexeddb.cjs +5812 -4570
  23. package/dist/indexeddb.cjs.map +1 -1
  24. package/dist/indexeddb.d.cts +2 -2
  25. package/dist/indexeddb.d.ts +2 -2
  26. package/dist/indexeddb.js +3 -2
  27. package/dist/indexeddb.js.map +1 -1
  28. package/dist/memory.cjs +5868 -4626
  29. package/dist/memory.cjs.map +1 -1
  30. package/dist/memory.d.cts +3 -3
  31. package/dist/memory.d.ts +3 -3
  32. package/dist/memory.js +3 -2
  33. package/dist/sqlite.cjs +5812 -4570
  34. package/dist/sqlite.cjs.map +1 -1
  35. package/dist/sqlite.d.cts +2 -2
  36. package/dist/sqlite.d.ts +2 -2
  37. package/dist/sqlite.js +3 -2
  38. package/dist/sqlite.js.map +1 -1
  39. package/dist/{state-AUnz7TG7.d.cts → state-C4HZFotm.d.cts} +1 -1
  40. package/dist/{state-AUnz7TG7.d.ts → state-C4HZFotm.d.ts} +1 -1
  41. package/dist/{store-BMN8kd0c.d.ts → store-8aBhnbGr.d.ts} +1 -1
  42. package/dist/{store-Cz75STRl.d.cts → store-YrbXb6CY.d.cts} +1 -1
  43. package/package.json +5 -5
  44. package/dist/chunk-4HMM7ZKY.js.map +0 -1
  45. package/dist/chunk-BE52B32Z.js.map +0 -1
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/explicit-preparation.ts","../src/PreparedTransaction.ts","../src/Invisi.ts","../src/AddressRegistry.ts","../src/index.ts","../src/ProtocolRpcClient.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 {\n store: _store,\n coinSelector: _selector,\n authorization: _authorization,\n viewing: _viewing,\n signer: _signer,\n fundingSigner: _fundingSigner,\n ...capabilities\n } = 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 };\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 proveOperation,\n walletSigningRequest,\n acceptWalletSignature,\n fundingSigningRequest,\n acceptFundingSignature,\n} from \"./session/operation-execution\";\nimport { MissingCapabilityError, type AuthorizedStatement } from \"@invisi-labs/core\";\nimport { normalizeFunding, type TransactionCall } from \"@invisi-labs/protocol\";\nimport type { Prover, ProofBundle } from \"@invisi-labs/prover\";\nimport type {\n OperationPlan,\n OperationRuntime,\n OperationAggregateMember,\n SavedOperation,\n TransactionProveOptions,\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\" | \"authorization\">;\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 /** Public EIP-712 request; signing transport and key custody belong to the caller. */\n async exportWalletAuthorization(options: { signal?: AbortSignal } = {}) {\n options.signal?.throwIfAborted();\n this.current();\n check(\n requiresAuthorization(this.#saved.plan),\n \"operation does not require wallet authorization\"\n );\n check(\n [\"prepared\", \"authorized\"].includes(this.status),\n \"operation is not awaiting wallet authorization\"\n );\n return walletSigningRequest(this.#saved.plan);\n }\n\n /** Attach an external EOA signature, retaining its witness only at the private proving boundary. */\n async withWalletSignature(\n signature: string,\n options: { signal?: AbortSignal } = {}\n ): Promise<PreparedTransaction> {\n options.signal?.throwIfAborted();\n this.current();\n check(\n requiresAuthorization(this.#saved.plan),\n \"operation does not require wallet authorization\"\n );\n check(\n [\"prepared\", \"authorized\"].includes(this.status),\n \"operation is not awaiting wallet authorization\"\n );\n const authorization = await acceptWalletSignature(this.#saved.plan, signature);\n return this.stage(\n \"wallet authorization\",\n [\"prepared\", \"authorized\"],\n async () => ({ status: \"authorized\", authorization }),\n options.signal\n );\n }\n\n /** Export only after proving when the funding authorization binds an actual proof hash. */\n async exportFundingAuthorization(options: { signal?: AbortSignal } = {}) {\n options.signal?.throwIfAborted();\n this.current();\n check(\n this.status === (this.kind === \"shield\" ? \"prepared\" : \"proved\"),\n \"operation is not awaiting funding authorization or proof\"\n );\n const request = await fundingSigningRequest(this.#saved, this.#runtime);\n options.signal?.throwIfAborted();\n this.current();\n return request;\n }\n\n /** Verify an external signature against this handle's own frozen operation. */\n async withFundingSignature(\n signature: string,\n options: { signal?: AbortSignal } = {}\n ): Promise<PreparedTransaction> {\n options.signal?.throwIfAborted();\n this.current();\n check(\n this.status === (this.kind === \"shield\" ? \"prepared\" : \"proved\"),\n \"operation is not awaiting funding authorization or proof\"\n );\n const verified = await acceptFundingSignature(this.#saved, signature, this.#runtime);\n return this.stage(\n \"funding authorization\",\n this.kind === \"shield\" ? [\"prepared\"] : [\"proved\"],\n async (saved) => {\n saved.plan.funding.signature = verified;\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 async prove(options?: TransactionProveOptions): Promise<PreparedTransaction>;\n async prove(backend: Prover, options?: TransactionProveOptions): Promise<PreparedTransaction>;\n async prove(\n backendOrOptions: Prover | TransactionProveOptions = {},\n suppliedOptions: TransactionProveOptions = {}\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 /** 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 type { WalletSessionInfrastructure } from \"./session/operation-types\";\nimport { prepareWithErrors } from \"./errors\";\nimport { copyGasBenchmarks } from \"./gas-estimation\";\nimport { explicitPreparation } from \"./explicit-preparation\";\nimport type { PreparedTransaction } from \"./PreparedTransaction\";\nimport type {\n TransactionIdentity,\n ExplicitTransferPreparation,\n ExplicitShieldPreparation,\n ExplicitCreateCreditPreparation,\n ExplicitDrawCreditPreparation,\n ExplicitTopUpCreditPreparation,\n ExplicitCancelCreditPreparation,\n} from \"./explicit-types\";\nimport { ProtocolRpcClient } from \"@invisi-labs/rpc\";\nimport type { Provider } from \"ethers\";\nimport {\n EthersChainReader,\n EthersFundingVerifier,\n EthersAddressResolver,\n} from \"./integrations/ethers\";\nimport { MissingCapabilityError, PublicWallet, ReceivingAddress } from \"@invisi-labs/core\";\nimport { AddressRegistry } from \"./AddressRegistry\";\nimport type { RegistrationPreparation, RegistrationOperation } from \"@invisi-labs/protocol\";\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. */\ntype InvisiInfrastructure = Omit<\n WalletSessionInfrastructure,\n | \"wallet\"\n | \"protocol\"\n | \"namespace\"\n | \"viewing\"\n | \"authorization\"\n | \"chainReader\"\n | \"signer\"\n | \"fundingSigner\"\n> & {\n /** Recipient discovery source; defaults to protocol-rpc. An explicit addressResolver takes precedence. */\n addressLookup?: \"chain\" | \"protocol-rpc\";\n provider?: Provider;\n chainReader?: ChainReader;\n};\n\nexport type InvisiOptions = InvisiInfrastructure;\n\n/** Public wallet and registry-specific inputs; signing remains external. */\nexport type RegistrationPreparationOptions = Pick<RegistrationPreparation, \"update\" | \"deadline\"> &\n Pick<TransactionIdentity, \"wallet\">;\n\n/** Wallet identity and session permissions; shared infrastructure belongs to InvisiOptions. */\nexport type ConnectionOptions = Pick<\n WalletSessionOptions,\n \"wallet\" | \"protocol\" | \"namespace\" | \"viewing\" | \"authorization\" | \"signer\" | \"fundingSigner\"\n>;\n\n/** A neutral composition entry point; every resolved instance owns an independent session. */\nexport class Invisi {\n readonly #options: InvisiInfrastructure;\n\n constructor(options: InvisiOptions = {}) {\n if (\"ciphertextCodecs\" in options || \"envelopeVersion\" in options) {\n throw new Error(\n \"SDK envelope versions are fixed; encode application payload bytes externally\"\n );\n }\n if (\"signer\" in options || \"fundingSigner\" in options) {\n throw new Error(\n \"Invisi does not accept signer defaults; export a signing request and attach the external signature\"\n );\n }\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 = [\n \"wallet\",\n \"protocol\",\n \"namespace\",\n \"viewing\",\n \"authorization\",\n \"signer\",\n \"fundingSigner\",\n ];\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, addressLookup = \"protocol-rpc\", ...runtime } = combined;\n if (\n addressLookup !== undefined &&\n addressLookup !== \"chain\" &&\n addressLookup !== \"protocol-rpc\"\n ) {\n throw new Error(\"Invalid recipient address lookup source\");\n }\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 const registry = selected.protocol.deployment.registry;\n const fundingVerifier =\n combined.fundingVerifier ??\n (provider\n ? new EthersFundingVerifier(provider, selected.protocol.context.chainId)\n : undefined);\n let addressResolver = combined.addressResolver;\n if (!addressResolver && registry) {\n if (addressLookup === \"protocol-rpc\") {\n const rpc = runtime.protocolRpc;\n addressResolver = async (identity) => {\n if (!(rpc instanceof ProtocolRpcClient)) {\n throw new MissingCapabilityError(\"Protocol RPC recipient discovery\");\n }\n const discovered = await rpc.getDeployment(selected.protocol.context.chainId);\n const expected = selected.protocol.deployment;\n if (\n discovered.protocol.address !== expected.protocol.address ||\n discovered.protocol.runtimeCodeHash !== expected.protocol.runtimeCodeHash ||\n discovered.protocol.fromBlock !== expected.protocol.fromBlock ||\n discovered.registry?.address !== registry.address ||\n discovered.registry.runtimeCodeHash !== registry.runtimeCodeHash ||\n discovered.registry.fromBlock !== registry.fromBlock\n )\n throw new Error(\"Recipient registry deployment pins mismatch\");\n const registration = await rpc.getReceivingAddress(identity);\n return registration\n ? ReceivingAddress.parse(registration.receivingAddress).getReceivingKeys()\n : null;\n };\n } else if (provider) {\n addressResolver = new EthersAddressResolver(\n provider,\n {\n chainId: selected.protocol.context.chainId,\n registryAddress: registry.address,\n },\n registry.runtimeCodeHash\n ).lookup;\n }\n }\n return {\n ...runtime,\n chainReader: reader,\n ...(fundingVerifier ? { fundingVerifier } : {}),\n ...(addressResolver ? { addressResolver } : {}),\n protocol: selected.protocol,\n } as WalletSessionOptions;\n }\n\n /** Discover the selected chain's registry and prepare an independent signing request. */\n async prepareRegistration(\n options: RegistrationPreparationOptions\n ): Promise<RegistrationOperation> {\n return prepareWithErrors(\"prepareRegistration\", async () => {\n for (const key of Object.keys(options)) {\n if (![\"wallet\", \"update\", \"deadline\"].includes(key)) {\n throw new Error(`Unknown registration option: ${key}`);\n }\n }\n this.assertPublicIdentity(options);\n const selected = { ...options };\n const { provider, protocolRpc } = this.#options;\n if (!provider) throw new MissingCapabilityError(\"ethers provider\");\n if (!(protocolRpc instanceof ProtocolRpcClient)) {\n throw new MissingCapabilityError(\"Protocol RPC deployment discovery\");\n }\n const chainId = (await provider.getNetwork()).chainId;\n const deployment = await protocolRpc.getDeployment(chainId);\n if (!deployment.registry) {\n throw new MissingCapabilityError(\"receiving-key registry deployment\");\n }\n const registry = new AddressRegistry(\n { chainId, registryAddress: deployment.registry.address },\n { expectedRuntimeCodeHash: deployment.registry.runtimeCodeHash }\n );\n return registry.prepareRegistration({ ...selected, provider });\n });\n }\n\n private assertPublicIdentity(options: Pick<TransactionIdentity, \"wallet\">): void {\n const { wallet } = options;\n if (\n !(wallet instanceof PublicWallet) ||\n [\"getViewer\", \"getDetector\", \"exportAuthorization\"].some((key) => key in wallet)\n ) {\n throw new Error(\n \"Independent preparation requires a PublicWallet without private capabilities\"\n );\n }\n for (const key of [\"authorization\", \"signer\", \"fundingSigner\", \"viewing\"]) {\n if (key in options)\n throw new Error(`Independent preparation does not accept capability: ${key}`);\n }\n }\n\n private resolveExplicit(options: TransactionIdentity): Promise<WalletSessionOptions> {\n this.assertPublicIdentity(options);\n return this.resolve({ wallet: options.wallet, protocol: options.protocol });\n }\n\n async prepareTransfer(options: ExplicitTransferPreparation): Promise<PreparedTransaction> {\n return prepareWithErrors(\"prepareTransfer\", async () => {\n const { wallet, protocol, ...input } = options;\n const request = structuredClone(input);\n const runtime = await this.resolveExplicit(options);\n const preparation = explicitPreparation(runtime, request, request.tokenAddress);\n return preparation.prepareTransfer(request);\n });\n }\n async prepareShield(options: ExplicitShieldPreparation): Promise<PreparedTransaction> {\n return prepareWithErrors(\"prepareShield\", async () => {\n const { wallet, protocol, ...input } = options;\n const request = structuredClone(input);\n const runtime = await this.resolveExplicit(options);\n const preparation = explicitPreparation(runtime, {}, request.tokenAddress);\n return preparation.prepareShield(request);\n });\n }\n async prepareCreateCredit(\n options: ExplicitCreateCreditPreparation\n ): Promise<PreparedTransaction> {\n return prepareWithErrors(\"prepareCreateCredit\", async () => {\n const { wallet, protocol, ...input } = options;\n const request = structuredClone(input);\n const runtime = await this.resolveExplicit(options);\n const preparation = explicitPreparation(runtime, request, request.tokenAddress);\n return preparation.prepareCreateCredit(request);\n });\n }\n async prepareDrawCredit(options: ExplicitDrawCreditPreparation): Promise<PreparedTransaction> {\n return prepareWithErrors(\"prepareDrawCredit\", async () => {\n const { wallet, protocol, ...input } = options;\n const request = structuredClone(input);\n const runtime = await this.resolveExplicit(options);\n const preparation = explicitPreparation(runtime, request, request.tokenAddress);\n return preparation.prepareDrawCredit(request);\n });\n }\n async prepareTopUpCredit(\n options: ExplicitTopUpCreditPreparation\n ): Promise<PreparedTransaction> {\n return prepareWithErrors(\"prepareTopUpCredit\", async () => {\n const { wallet, protocol, ...input } = options;\n const request = structuredClone(input);\n const runtime = await this.resolveExplicit(options);\n const preparation = explicitPreparation(runtime, request, request.tokenAddress);\n return preparation.prepareTopUpCredit(request);\n });\n }\n async prepareCancelCredit(\n options: ExplicitCancelCreditPreparation\n ): Promise<PreparedTransaction> {\n return prepareWithErrors(\"prepareCancelCredit\", async () => {\n const { wallet, protocol, ...input } = options;\n const request = structuredClone(input);\n const runtime = await this.resolveExplicit(options);\n const preparation = explicitPreparation(runtime, request, request.tokenAddress);\n return preparation.prepareCancelCredit(request);\n });\n }\n\n toJSON() {\n return { invisi: true };\n }\n [Symbol.for(\"nodejs.util.inspect.custom\")]() {\n return this.toJSON();\n }\n}\n","import { prepareWithErrors } from \"./errors\";\nimport 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 return prepareWithErrors(\"prepareRegistration\", async () => {\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}\n","export { InvisiError } from \"./errors\";\nexport type { InvisiErrorCode, InvisiErrorDetails } from \"./errors\";\nexport { Invisi } from \"./Invisi\";\nexport type { InvisiOptions, ConnectionOptions, RegistrationPreparationOptions } from \"./Invisi\";\nexport {\n fundsV1,\n creditV1,\n decodeDeliveryHeader,\n Wallet,\n PublicWallet,\n ViewingCapability,\n Detector,\n NullifierCapability,\n WalletAuthorization,\n MissingCapabilityError,\n Disclosure,\n encodeMemo,\n decodeMemoText,\n MAX_MEMO_BYTES,\n computeCreditNullifier,\n creditPeriods,\n} from \"@invisi-labs/core\";\nexport type {\n Address,\n Hex,\n Memo,\n FundsDataV1,\n CreditDataV1,\n Note,\n CreditNote,\n CreditPolicy,\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 WalletHistory,\n HistoryOptions,\n OutgoingHistoryEntry,\n IncomingHistoryEntry,\n RefreshOptions,\n RefreshResult,\n WalletStore,\n WalletScope,\n WalletState,\n BalanceSnapshot,\n WalletSessionOptions,\n PaymentOutput,\n TransferPreparation,\n TransactionExecution,\n TransactionProveOptions,\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, RegisteredReceivingAddress } 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 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\nexport type { SigningRequest } from \"@invisi-labs/core\";\n\n// Stateless recovery for applications that supply canonical receipts without a wallet store.\nexport { readProtocolLogs } from \"./session/receipt-logs\";\nexport { decryptCandidates } from \"./session/discovery\";\nexport type { DeliveryEventLog, DiscoveredNote, DiscoveredCredit } from \"./session/discovery\";\n\nexport type {\n ProtocolOutput,\n ProtocolTransactionUpdates,\n ProtocolCreditTransition,\n} from \"@invisi-labs/rpc\";\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 {\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;;;ACQ3B,SAAS,8BAAwD;AACjE,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,EAC5B;AAAA,EACA,IAAI,OAAO;AACP,WAAO,KAAK,OAAO,KAAK;AAAA,EAC5B;AAAA,EACA,cAAc;AACV,WAAO;AAAA,MACH,KAAK,OAAO;AAAA,MACZ,KAAK,SAAS,QAAQ;AAAA,MACtB,KAAK,SAAS,QAAQ;AAAA,IAC1B;AAAA,EACJ;AAAA,EACA,UAAU;AACN,WAAO,iBAAiB,KAAK,OAAO,MAAM,KAAK,MAAM;AAAA,EACzD;AAAA,EACQ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E;AAAA,UACzD,KAAK;AAAA,UACL;AAAA,QACJ;AAAA,MACJ;AACA,YAAM,MAAM,IAAI,WAAW,KAAK,UAAU,MAAM;AAChD,UAAI,CAAC,IAAI;AACT,UAAI,IAAI,IAAI,CAAC;AACb,UAAI,IAAI,WAAW,EAAE;AACrB,aAAO;AAAA,IACX,UAAE;AACE,YAAM,KAAK,CAAC;AAAA,IAChB;AAAA,EACJ;AAAA,EACA,MAAM,OACF,MACA,SACoB;AACpB,QAAI,KAAK,SAAS,MAAM,KAAK,CAAC,MAAM;AAChC,YAAM,IAAI,MAAM,qCAAqC;AACzD,QAAI;AACJ,QAAI;AACA,cAAQ,IAAI;AAAA,QACR,MAAM,OAAO,OAAO;AAAA,UAChB;AAAA,YACI,MAAM;AAAA,YACN,IAAI,WAAW,KAAK,KAAK,SAAS,GAAG,EAAE,CAAC;AAAA,YACxC,gBAAgB,KAAK,IAAI,OAAO;AAAA,UACpC;AAAA,UACA,KAAK;AAAA,UACL,WAAW,KAAK,KAAK,SAAS,EAAE,CAAC;AAAA,QACrC;AAAA,MACJ;AAAA,IACJ,QAAQ;AACJ,YAAM,IAAI,MAAM,qCAAqC;AAAA,IACzD;AACA,QAAI;AACA,aAAO,iBAAiB,KAAK;AAAA,IACjC,UAAE;AACE,YAAM,KAAK,CAAC;AAAA,IAChB;AAAA,EACJ;AAAA,EACA,SAAS;AACL,WAAO,EAAE,mBAAmB,cAAc;AAAA,EAC9C;AAAA,EACA,CAAC,uBAAO,IAAI,4BAA4B,CAAC,IAAI;AACzC,WAAO,KAAK,OAAO;AAAA,EACvB;AACJ;","names":["MissingCapabilityError","MissingCapabilityError","PublicWallet","MissingCapabilityError","ProtocolRpcClient"]}
1
+ {"version":3,"sources":["../src/explicit-preparation.ts","../src/PreparedTransaction.ts","../src/Invisi.ts","../src/AddressRegistry.ts","../src/index.ts","../src/Protocol.ts","../src/broadcaster/index.ts","../src/ProtocolRpcClient.ts","../src/BroadcasterRegistry.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.ownerAddress !== options.wallet.ownerAddress\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 ownerAddress: options.wallet.ownerAddress,\n };\n const {\n store: _store,\n coinSelector: _selector,\n authorization: _authorization,\n viewing: _viewing,\n signer: _signer,\n fundingSigner: _fundingSigner,\n ...capabilities\n } = 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 };\n const reprepare = (intent: import(\"./broadcaster-preparation\").PreparationIntent) =>\n import(\"./broadcaster-preparation\").then(({ prepareIntent }) =>\n prepareIntent(\n {\n ...runtime,\n explicitInputs: true,\n ...(data.changeAddress ? { changeAddress: data.changeAddress } : {}),\n readInventory: async () => structuredClone(inventory),\n complete: async (plan) => plan,\n },\n intent\n )\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, reprepare }, plan),\n });\n}\n","import { estimateGasReference } from \"./gas-estimation\";\nimport {\n proveOperation,\n walletSigningRequest,\n acceptWalletSignature,\n fundingSigningRequest,\n acceptFundingSignature,\n} from \"./session/operation-execution\";\nimport { MissingCapabilityError, type AuthorizedStatement } from \"@invisi-labs/core\";\nimport { normalizeFunding, type TransactionCall } from \"@invisi-labs/protocol\";\nimport type { Prover, ProofBundle } from \"@invisi-labs/prover\";\nimport type {\n OperationPlan,\n OperationRuntime,\n OperationAggregateMember,\n SavedOperation,\n TransactionProveOptions,\n} from \"./session/operation-types\";\nimport type { OperationStatus } from \"./session/state\";\nimport {\n encodeOperation,\n exportBroadcasterIntent,\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\" | \"authorization\"> & {\n reprepare?: (\n intent: import(\"./broadcaster-preparation\").PreparationIntent\n ) => Promise<OperationPlan>;\n};\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 broadcasterQuote() {\n return this.#saved.broadcasterQuote\n ? structuredClone(this.#saved.broadcasterQuote)\n : undefined;\n }\n async withBroadcaster(\n client: import(\"./broadcaster\").BroadcasterClient,\n options: import(\"./broadcaster-preparation\").WithBroadcasterOptions\n ): Promise<PreparedTransaction> {\n this.current();\n check(\n this.status === \"prepared\" && this.#runtime.reprepare,\n \"broadcaster must attach to an unsigned prepared transaction\"\n );\n const { prepareBroadcasterPlan } = await import(\"./broadcaster-preparation\");\n const selected = await prepareBroadcasterPlan(\n this.#saved.plan,\n this.#runtime.reprepare,\n client,\n options\n );\n return new PreparedTransaction(\n this.#runtime,\n { plan: selected.plan, broadcasterQuote: selected.quote, 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 /** Obtain a firm quote before signing. This intent contains no private inputs or witness. */\n async exportBroadcasterIntent() {\n this.current();\n check(\n [\"prepared\", \"authorized\"].includes(this.status),\n \"quote intent requires a prepared transaction\"\n );\n return exportBroadcasterIntent(this.#saved.plan);\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 /** Public EIP-712 request; signing transport and key custody belong to the caller. */\n async exportWalletAuthorization(options: { signal?: AbortSignal } = {}) {\n options.signal?.throwIfAborted();\n this.current();\n check(\n requiresAuthorization(this.#saved.plan),\n \"operation does not require wallet authorization\"\n );\n check(\n [\"prepared\", \"authorized\"].includes(this.status),\n \"operation is not awaiting wallet authorization\"\n );\n return walletSigningRequest(this.#saved.plan);\n }\n\n /** Attach an external EOA signature, retaining its witness only at the private proving boundary. */\n async withWalletSignature(\n signature: string,\n options: { signal?: AbortSignal } = {}\n ): Promise<PreparedTransaction> {\n options.signal?.throwIfAborted();\n this.current();\n check(\n requiresAuthorization(this.#saved.plan),\n \"operation does not require wallet authorization\"\n );\n check(\n [\"prepared\", \"authorized\"].includes(this.status),\n \"operation is not awaiting wallet authorization\"\n );\n const authorization = await acceptWalletSignature(this.#saved.plan, signature);\n return this.stage(\n \"wallet authorization\",\n [\"prepared\", \"authorized\"],\n async () => ({ status: \"authorized\", authorization }),\n options.signal\n );\n }\n\n /** Export only after proving when the funding authorization binds an actual proof hash. */\n async exportFundingAuthorization(options: { signal?: AbortSignal } = {}) {\n options.signal?.throwIfAborted();\n this.current();\n check(\n this.status === (this.kind === \"shield\" ? \"prepared\" : \"proved\"),\n \"operation is not awaiting funding authorization or proof\"\n );\n const request = await fundingSigningRequest(this.#saved, this.#runtime);\n options.signal?.throwIfAborted();\n this.current();\n return request;\n }\n\n /** Verify an external signature against this handle's own frozen operation. */\n async withFundingSignature(\n signature: string,\n options: { signal?: AbortSignal } = {}\n ): Promise<PreparedTransaction> {\n options.signal?.throwIfAborted();\n this.current();\n check(\n this.status === (this.kind === \"shield\" ? \"prepared\" : \"proved\"),\n \"operation is not awaiting funding authorization or proof\"\n );\n const verified = await acceptFundingSignature(this.#saved, signature, this.#runtime);\n return this.stage(\n \"funding authorization\",\n this.kind === \"shield\" ? [\"prepared\"] : [\"proved\"],\n async (saved) => {\n saved.plan.funding.signature = verified;\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 async prove(options?: TransactionProveOptions): Promise<PreparedTransaction>;\n async prove(backend: Prover, options?: TransactionProveOptions): Promise<PreparedTransaction>;\n async prove(\n backendOrOptions: Prover | TransactionProveOptions = {},\n suppliedOptions: TransactionProveOptions = {}\n ): Promise<PreparedTransaction> {\n const options = { ...(\"prove\" in backendOrOptions ? suppliedOptions : backendOrOptions) };\n check(\n !this.#saved.broadcasterQuote || options.execution !== \"aggregate\",\n \"a broadcaster quote requires direct execution\"\n );\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 /** 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 { configureRecipientInfrastructure } from \"./recipient-infrastructure\";\nimport type { WalletSessionInfrastructure } from \"./session/operation-types\";\nimport { prepareWithErrors } from \"./errors\";\nimport { copyGasBenchmarks } from \"./gas-estimation\";\nimport { explicitPreparation } from \"./explicit-preparation\";\nimport type { PreparedTransaction } from \"./PreparedTransaction\";\nimport type {\n TransactionIdentity,\n ExplicitTransferPreparation,\n ExplicitShieldPreparation,\n ExplicitCreateCreditPreparation,\n ExplicitDrawCreditPreparation,\n ExplicitTopUpCreditPreparation,\n ExplicitCancelCreditPreparation,\n} from \"./explicit-types\";\nimport { ProtocolRpcClient } from \"@invisi-labs/rpc\";\nimport type { Provider } from \"ethers\";\nimport { EthersChainReader, EthersFundingVerifier } from \"./integrations/ethers\";\nimport { MissingCapabilityError, PublicWallet } from \"@invisi-labs/core\";\nimport { AddressRegistry } from \"./AddressRegistry\";\nimport type { RegistrationPreparation, RegistrationOperation } from \"@invisi-labs/protocol\";\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. */\ntype InvisiInfrastructure = Omit<\n WalletSessionInfrastructure,\n | \"wallet\"\n | \"protocol\"\n | \"namespace\"\n | \"viewing\"\n | \"authorization\"\n | \"chainReader\"\n | \"signer\"\n | \"fundingSigner\"\n> & {\n provider?: Provider;\n chainReader?: ChainReader;\n};\n\nexport type InvisiOptions = InvisiInfrastructure;\n\n/** Public wallet and registry-specific inputs; signing remains external. */\nexport type RegistrationPreparationOptions = Pick<RegistrationPreparation, \"update\" | \"deadline\"> &\n Pick<TransactionIdentity, \"wallet\">;\n\n/** Owner address and session permissions; shared infrastructure belongs to InvisiOptions. */\nexport type ConnectionOptions = Pick<\n WalletSessionOptions,\n \"wallet\" | \"protocol\" | \"namespace\" | \"viewing\" | \"authorization\" | \"signer\" | \"fundingSigner\"\n>;\n\n/** A neutral composition entry point; every resolved instance owns an independent session. */\nexport class Invisi {\n readonly #options: InvisiInfrastructure;\n\n constructor(options: InvisiOptions = {}) {\n if (\"addressLookup\" in options || \"addressResolver\" in options)\n throw new TypeError(\n \"Recipient lookup belongs to each EVM output; caller resolver injection is not supported\"\n );\n if (\"ciphertextCodecs\" in options || \"envelopeVersion\" in options) {\n throw new Error(\n \"SDK envelope versions are fixed; encode application payload bytes externally\"\n );\n }\n if (\"signer\" in options || \"fundingSigner\" in options) {\n throw new Error(\n \"Invisi does not accept signer defaults; export a signing request and attach the external signature\"\n );\n }\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 = [\n \"wallet\",\n \"protocol\",\n \"namespace\",\n \"viewing\",\n \"authorization\",\n \"signer\",\n \"fundingSigner\",\n ];\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, ...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 const fundingVerifier =\n combined.fundingVerifier ??\n (provider\n ? new EthersFundingVerifier(provider, selected.protocol.context.chainId)\n : undefined);\n return configureRecipientInfrastructure({\n ...runtime,\n ...(provider ? { provider } : {}),\n chainReader: reader,\n ...(fundingVerifier ? { fundingVerifier } : {}),\n protocol: selected.protocol,\n } as WalletSessionOptions);\n }\n\n /** Discover the selected chain's registry and prepare an independent signing request. */\n async prepareRegistration(\n options: RegistrationPreparationOptions\n ): Promise<RegistrationOperation> {\n return prepareWithErrors(\"prepareRegistration\", async () => {\n for (const key of Object.keys(options)) {\n if (![\"wallet\", \"update\", \"deadline\"].includes(key)) {\n throw new Error(`Unknown registration option: ${key}`);\n }\n }\n this.assertPublicIdentity(options);\n const selected = { ...options };\n const { provider, protocolRpc } = this.#options;\n if (!provider) throw new MissingCapabilityError(\"ethers provider\");\n if (!(protocolRpc instanceof ProtocolRpcClient)) {\n throw new MissingCapabilityError(\"Protocol RPC deployment discovery\");\n }\n const chainId = (await provider.getNetwork()).chainId;\n const deployment = await protocolRpc.getDeployment(chainId);\n if (!deployment.registry) {\n throw new MissingCapabilityError(\"receiving-key registry deployment\");\n }\n const registry = new AddressRegistry(\n { chainId, registryAddress: deployment.registry.address },\n { expectedRuntimeCodeHash: deployment.registry.runtimeCodeHash }\n );\n return registry.prepareRegistration({ ...selected, provider });\n });\n }\n\n private assertPublicIdentity(options: Pick<TransactionIdentity, \"wallet\">): void {\n const { wallet } = options;\n if (\n !(wallet instanceof PublicWallet) ||\n [\"getViewer\", \"getDetector\", \"exportAuthorization\"].some((key) => key in wallet)\n ) {\n throw new Error(\n \"Independent preparation requires a PublicWallet without private capabilities\"\n );\n }\n for (const key of [\"authorization\", \"signer\", \"fundingSigner\", \"viewing\"]) {\n if (key in options)\n throw new Error(`Independent preparation does not accept capability: ${key}`);\n }\n }\n\n private resolveExplicit(options: TransactionIdentity): Promise<WalletSessionOptions> {\n this.assertPublicIdentity(options);\n return this.resolve({ wallet: options.wallet, protocol: options.protocol });\n }\n\n async prepareTransfer(options: ExplicitTransferPreparation): Promise<PreparedTransaction> {\n return prepareWithErrors(\"prepareTransfer\", async () => {\n const { wallet, protocol, ...input } = options;\n const request = structuredClone(input);\n const runtime = await this.resolveExplicit(options);\n const preparation = explicitPreparation(runtime, request, request.tokenAddress);\n return preparation.prepareTransfer(request);\n });\n }\n async prepareShield(options: ExplicitShieldPreparation): Promise<PreparedTransaction> {\n return prepareWithErrors(\"prepareShield\", async () => {\n const { wallet, protocol, ...input } = options;\n const request = structuredClone(input);\n const runtime = await this.resolveExplicit(options);\n const preparation = explicitPreparation(runtime, {}, request.tokenAddress);\n return preparation.prepareShield(request);\n });\n }\n async prepareCreateCredit(\n options: ExplicitCreateCreditPreparation\n ): Promise<PreparedTransaction> {\n return prepareWithErrors(\"prepareCreateCredit\", async () => {\n const { wallet, protocol, ...input } = options;\n const request = structuredClone(input);\n const runtime = await this.resolveExplicit(options);\n const preparation = explicitPreparation(runtime, request, request.tokenAddress);\n return preparation.prepareCreateCredit(request);\n });\n }\n async prepareDrawCredit(options: ExplicitDrawCreditPreparation): Promise<PreparedTransaction> {\n return prepareWithErrors(\"prepareDrawCredit\", async () => {\n const { wallet, protocol, ...input } = options;\n const request = structuredClone(input);\n const runtime = await this.resolveExplicit(options);\n const preparation = explicitPreparation(runtime, request, request.tokenAddress);\n return preparation.prepareDrawCredit(request);\n });\n }\n async prepareTopUpCredit(\n options: ExplicitTopUpCreditPreparation\n ): Promise<PreparedTransaction> {\n return prepareWithErrors(\"prepareTopUpCredit\", async () => {\n const { wallet, protocol, ...input } = options;\n const request = structuredClone(input);\n const runtime = await this.resolveExplicit(options);\n const preparation = explicitPreparation(runtime, request, request.tokenAddress);\n return preparation.prepareTopUpCredit(request);\n });\n }\n async prepareCancelCredit(\n options: ExplicitCancelCreditPreparation\n ): Promise<PreparedTransaction> {\n return prepareWithErrors(\"prepareCancelCredit\", async () => {\n const { wallet, protocol, ...input } = options;\n const request = structuredClone(input);\n const runtime = await this.resolveExplicit(options);\n const preparation = explicitPreparation(runtime, request, request.tokenAddress);\n return preparation.prepareCancelCredit(request);\n });\n }\n\n toJSON() {\n return { invisi: true };\n }\n [Symbol.for(\"nodejs.util.inspect.custom\")]() {\n return this.toJSON();\n }\n}\n","import { prepareWithErrors } from \"./errors\";\nimport 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 return prepareWithErrors(\"prepareRegistration\", async () => {\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}\n","export { NoteOutput } from \"./NoteOutput\";\nexport type { NoteOutputContext, NoteOutputOptions, NoteOutputRecipient } from \"./NoteOutput\";\nexport { InvisiError } from \"./errors\";\nexport type { InvisiErrorCode, InvisiErrorDetails } from \"./errors\";\nexport { Invisi } from \"./Invisi\";\nexport type { InvisiOptions, ConnectionOptions, RegistrationPreparationOptions } from \"./Invisi\";\nexport {\n fundsV1,\n creditV1,\n decodeDeliveryHeader,\n Wallet,\n PublicWallet,\n ViewingCapability,\n Detector,\n NullifierCapability,\n WalletAuthorization,\n MissingCapabilityError,\n Disclosure,\n encodeMemo,\n decodeMemoText,\n MAX_MEMO_BYTES,\n computeCreditNullifier,\n creditPeriods,\n} from \"@invisi-labs/core\";\nexport type {\n Address,\n Hex,\n Memo,\n FundsDataV1,\n CreditDataV1,\n Note,\n CreditNote,\n CreditPolicy,\n CreditDeliveryState,\n ReceivingKeys,\n WalletAuthorizationProvider,\n CreditOpening,\n DisclosureOutput,\n DisclosureExport,\n DisclosureResult,\n} from \"@invisi-labs/core\";\nexport { RegistrationOperation } from \"@invisi-labs/protocol\";\nexport { Protocol } from \"./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 WalletHistory,\n HistoryOptions,\n OutgoingHistoryEntry,\n IncomingHistoryEntry,\n RefreshOptions,\n RefreshResult,\n WalletStore,\n WalletScope,\n WalletState,\n BalanceSnapshot,\n WalletSessionOptions,\n TransferPreparation,\n TransactionExecution,\n TransactionProveOptions,\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, MAX_UPDATE_BLOCKS } from \"@invisi-labs/rpc\";\nexport type { ProtocolDeployment, RegisteredReceivingAddress } from \"@invisi-labs/rpc\";\nexport { ProtocolRpcClient } from \"./ProtocolRpcClient\";\nexport { AddressRegistry } from \"./AddressRegistry\";\nexport { BroadcasterRegistry } from \"./BroadcasterRegistry\";\nexport type {\n BroadcasterRegistryOptions,\n BroadcasterRegistration,\n RegisteredBroadcaster,\n} from \"./BroadcasterRegistry\";\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 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\nexport type { SigningRequest } from \"@invisi-labs/core\";\n\n// Stateless recovery for applications that supply canonical receipts without a wallet store.\nexport { readProtocolLogs } from \"./session/receipt-logs\";\nexport { decryptCandidates } from \"./session/discovery\";\nexport type { DeliveryEventLog, DiscoveredNote, DiscoveredCredit } from \"./session/discovery\";\n\nexport type {\n ProtocolOutput,\n ProtocolTransactionUpdates,\n ProtocolCreditTransition,\n} from \"@invisi-labs/rpc\";\n\nexport * from \"./broadcaster\";\n\nexport type { WithBroadcasterOptions, BroadcasterFeeSource } from \"./broadcaster-preparation\";\n","import { Protocol as BaseProtocol } from \"@invisi-labs/protocol\";\nimport type { ProtocolRpcClient } from \"@invisi-labs/rpc\";\nimport { getAddress, type Provider } from \"ethers\";\nimport { BroadcasterClient } from \"./broadcaster\";\n\nconst sources = new WeakMap<Protocol, Pick<ProtocolRpcClient, \"getBroadcasters\">>();\n\n/** Deployment operations and token-compatible broadcaster discovery. */\nexport class Protocol extends BaseProtocol {\n static override async fromRpc(\n rpc: Pick<ProtocolRpcClient, \"getDeployment\"> &\n Partial<Pick<ProtocolRpcClient, \"getBroadcasters\">>,\n provider: Provider,\n options: { signal?: AbortSignal } = {}\n ): Promise<Protocol> {\n const verified = await BaseProtocol.fromRpc(rpc, provider, options);\n const protocol = new Protocol({ deployment: verified.deployment });\n if (rpc.getBroadcasters)\n sources.set(protocol, rpc as Pick<ProtocolRpcClient, \"getBroadcasters\">);\n return protocol;\n }\n\n /** Returns enabled services that answer a token fee probe; final quotes are checked by prepared. */\n async getBroadcasters(options: { tokenAddress: string }): Promise<BroadcasterClient[]> {\n const token = getAddress(options.tokenAddress);\n if (!this.deployment.broadcasterRegistry)\n throw new Error(\"broadcaster registry is not configured\");\n const rpc = sources.get(this);\n if (!rpc) throw new Error(\"broadcaster discovery requires Protocol.fromRpc\");\n const clients: BroadcasterClient[] = [];\n let after: `0x${string}` | undefined;\n let block: Awaited<ReturnType<ProtocolRpcClient[\"getBroadcasters\"]>>[\"block\"] | undefined;\n const seen = new Set<string>();\n do {\n const page = await rpc.getBroadcasters({\n enabled: true,\n limit: 100,\n ...(after ? { after } : {}),\n ...(block ? { block } : {}),\n });\n block ??= page.block;\n const compatible = await Promise.all(\n page.broadcasters.map(async (entry) => {\n if (!entry.enabled) return undefined;\n try {\n const client = new BroadcasterClient(entry);\n await client.fee(token);\n return client;\n } catch {\n return undefined;\n }\n })\n );\n clients.push(\n ...compatible.filter((client): client is BroadcasterClient => client !== undefined)\n );\n after = page.next;\n if (after && seen.has(after)) throw new Error(\"repeated broadcaster pagination cursor\");\n if (after) seen.add(after);\n } while (after);\n return clients;\n }\n}\n","import { AbiCoder, getAddress, Interface, keccak256, verifyTypedData } from \"ethers\";\nimport { invisiProtocolAbi } from \"@invisi-labs/protocol/contracts\";\n\nexport const broadcasterQuoteTypes = {\n Quote: [\n { name: \"token\", type: \"address\" },\n { name: \"feeRecipient\", type: \"address\" },\n { name: \"feeAmount\", type: \"uint256\" },\n { name: \"deadline\", type: \"uint256\" },\n { name: \"maxGas\", type: \"uint256\" },\n { name: \"requestHash\", type: \"bytes32\" },\n ],\n};\nexport interface BroadcasterQuote {\n token: string;\n feeRecipient: string;\n feeAmount: string;\n deadline: string;\n maxGas: string;\n requestHash: string;\n}\nexport interface SignedBroadcasterQuote {\n quote: BroadcasterQuote;\n signature: string;\n context?: { chainId: bigint; protocol: string };\n}\nexport interface BroadcasterTrust {\n chainId: bigint;\n protocol: string;\n signer: string;\n}\nexport function broadcasterQuoteDomain(trust: BroadcasterTrust) {\n return {\n name: \"InvisiBroadcaster\",\n version: \"1\",\n chainId: trust.chainId,\n verifyingContract: getAddress(trust.protocol),\n };\n}\nconst supportedMethods = [\"transact\", \"shield\", \"createCredit\", \"topUpCredit\", \"cancelCredit\"];\nconst intentAbi = invisiProtocolAbi.filter(\n (item) =>\n item.type === \"function\" &&\n supportedMethods.includes(item.name) &&\n (item.name !== \"transact\" || item.inputs[1]?.type === \"tuple\")\n);\nexport const broadcasterTransactInterface = new Interface(intentAbi);\n/** Decode a canonical supported direct public intent. Draw, registry and aggregates are excluded. */\nexport function decodeBroadcasterIntent(data: string) {\n const parsed = broadcasterTransactInterface.parseTransaction({ data });\n if (!parsed || !supportedMethods.includes(parsed.name))\n throw new Error(\"unsupported broadcaster method\");\n const fragment = parsed.fragment;\n const decoded = parsed.args;\n if (\n broadcasterTransactInterface.encodeFunctionData(fragment, decoded).toLowerCase() !==\n data.toLowerCase()\n )\n throw new Error(\"noncanonical broadcaster calldata\");\n const method = parsed.name;\n const raw = method === \"transact\" ? decoded[1] : undefined;\n const params =\n raw?.params ??\n (method === \"shield\"\n ? decoded[0]\n : method === \"topUpCredit\"\n ? decoded[1].creation\n : decoded[1]);\n const funding =\n raw?.funding ??\n (method === \"shield\"\n ? decoded[3]\n : [\"createCredit\", \"topUpCredit\"].includes(method)\n ? decoded[3]\n : undefined);\n const deliveries =\n raw?.deliveries ??\n (method === \"shield\"\n ? decoded[2]\n : [\"createCredit\", \"topUpCredit\"].includes(method)\n ? decoded[2]\n : []);\n return {\n fragment,\n method,\n args: decoded,\n proof: method === \"shield\" ? \"0x\" : (decoded[0] as string),\n request: { params, funding, deliveries },\n };\n}\n/** Domain-separated final public intent: omit only proof bytes and funding.signature. */\nexport function broadcasterRequestHash(data: string): string {\n const { fragment, method, args } = decodeBroadcasterIntent(data);\n const copy = (value: unknown): unknown => (Array.isArray(value) ? value.map(copy) : value);\n const canonical = copy(args) as unknown[];\n if (method !== \"shield\") canonical[0] = \"0x\";\n if (method === \"transact\") ((canonical[1] as unknown[])[2] as unknown[])[4] = \"0x\";\n else if (method !== \"cancelCredit\") (canonical[3] as unknown[])[4] = \"0x\";\n const calldata = broadcasterTransactInterface.encodeFunctionData(fragment, canonical);\n return keccak256(\n AbiCoder.defaultAbiCoder().encode(\n [\"string\", \"string\", \"bytes\"],\n [\"InvisiBroadcasterIntentV1\", method, calldata]\n )\n );\n}\nexport function verifyBroadcasterQuote(\n signed: SignedBroadcasterQuote,\n trust: BroadcasterTrust,\n data: string,\n now = BigInt(Math.floor(Date.now() / 1000))\n) {\n const { quote } = signed;\n const { request } = decodeBroadcasterIntent(data);\n const p = request.params;\n if (\n quote.requestHash !== broadcasterRequestHash(data) ||\n getAddress(quote.token) !== getAddress(p.token) ||\n getAddress(quote.feeRecipient) !== getAddress(p.feeRecipient) ||\n BigInt(quote.feeAmount) !== p.feeAmount ||\n BigInt(quote.deadline) > p.deadline ||\n BigInt(quote.deadline) < now ||\n BigInt(quote.maxGas) <= 0n ||\n BigInt(quote.feeAmount) <= 0n ||\n BigInt(quote.feeAmount) >= 1n << 128n\n )\n throw new Error(\"quote does not match final intent or bounds\");\n if (\n getAddress(\n verifyTypedData(\n broadcasterQuoteDomain(trust),\n broadcasterQuoteTypes,\n quote,\n signed.signature\n )\n ) !== getAddress(trust.signer)\n )\n throw new Error(\"untrusted quote signature\");\n return quote;\n}\nexport interface BroadcasterStatus {\n id: string;\n state: \"pending\" | \"submitted\" | \"confirmed\" | \"reverted\" | \"uncertain\";\n transactionHash?: string;\n}\nfunction checkedStatus(value: unknown, id: string): BroadcasterStatus {\n const status = value as BroadcasterStatus;\n if (\n !status ||\n status.id !== id ||\n ![\"pending\", \"submitted\", \"confirmed\", \"reverted\", \"uncertain\"].includes(status.state) ||\n (status.transactionHash !== undefined &&\n !/^0x[0-9a-fA-F]{64}$/.test(status.transactionHash))\n )\n throw new Error(\"invalid broadcaster status\");\n return status;\n}\nexport type BroadcasterTransport = (request: {\n jsonrpc: \"2.0\";\n id: number;\n method: string;\n params: unknown;\n}) => Promise<unknown>;\nexport interface BroadcasterConfiguration {\n endpoint: string;\n quoteSigner: string;\n feeRecipient: string;\n}\nexport class BroadcasterClient {\n readonly configuration: Readonly<BroadcasterConfiguration>;\n readonly url: string;\n readonly transport: BroadcasterTransport;\n private requestId = 0;\n constructor(configuration: BroadcasterConfiguration, transport?: BroadcasterTransport) {\n this.configuration = Object.freeze({\n endpoint: configuration.endpoint,\n quoteSigner: getAddress(configuration.quoteSigner),\n feeRecipient: getAddress(configuration.feeRecipient),\n });\n if (\n BigInt(this.configuration.quoteSigner) === 0n ||\n BigInt(this.configuration.feeRecipient) === 0n\n )\n throw new Error(\"invalid broadcaster configuration\");\n this.url = configuration.endpoint;\n const base = new URL(this.url);\n if (base.protocol !== \"https:\" || base.username || base.password)\n throw new Error(\"broadcaster requires HTTPS\");\n\n this.transport =\n transport ??\n (async (request) => {\n const response = await fetch(base, {\n redirect: \"error\",\n method: \"POST\",\n body: JSON.stringify(request),\n headers: { \"content-type\": \"application/json\" },\n signal: AbortSignal.timeout(30000),\n });\n if (!response.ok) throw new Error(`Broadcaster HTTP ${response.status}`);\n if (!response.body) throw new Error(\"empty broadcaster response\");\n const reader = response.body.getReader();\n const chunks: Uint8Array[] = [];\n let size = 0;\n try {\n while (true) {\n const result = await reader.read();\n if (result.done) break;\n size += result.value.length;\n if (size > 65536) throw new Error(\"broadcaster response too large\");\n chunks.push(result.value);\n }\n } finally {\n await reader.cancel();\n }\n const bytes = new Uint8Array(size);\n let offset = 0;\n for (const chunk of chunks) {\n bytes.set(chunk, offset);\n offset += chunk.length;\n }\n return JSON.parse(new TextDecoder().decode(bytes));\n });\n }\n private async call(method: string, params: unknown): Promise<unknown> {\n const id = ++this.requestId;\n const response = (await this.transport({\n jsonrpc: \"2.0\",\n id,\n method,\n params: [params],\n })) as {\n jsonrpc?: string;\n id?: unknown;\n result?: unknown;\n error?: { code?: unknown; message?: unknown };\n };\n if (\n !response ||\n response.jsonrpc !== \"2.0\" ||\n response.id !== id ||\n Object.hasOwn(response, \"result\") === Object.hasOwn(response, \"error\")\n )\n throw new Error(\"invalid broadcaster JSON-RPC response\");\n if (response.error) {\n if (\n !Number.isInteger(response.error.code) ||\n typeof response.error.message !== \"string\"\n )\n throw new Error(\"invalid broadcaster JSON-RPC error\");\n throw new BroadcasterRpcError(response.error.code as number, response.error.message);\n }\n return response.result;\n }\n async fee(\n token: string,\n data?: string\n ): Promise<{ feeRecipient: string; feeAmount: string; maxGas: string }> {\n const fee = (await this.call(\"broadcaster_getFee\", {\n token: getAddress(token),\n ...(data ? { data } : {}),\n })) as {\n feeRecipient: string;\n feeAmount: string;\n maxGas: string;\n };\n if (\n !fee ||\n getAddress(fee.feeRecipient) !== this.configuration.feeRecipient ||\n !/^\\d+$/.test(fee.feeAmount) ||\n BigInt(fee.feeAmount) <= 0n ||\n BigInt(fee.feeAmount) >= 1n << 128n ||\n !/^\\d+$/.test(fee.maxGas) ||\n BigInt(fee.maxGas) <= 0n\n )\n throw new Error(\"invalid broadcaster fee\");\n return fee;\n }\n async quote(\n data: string,\n context: { chainId: bigint; protocol: string }\n ): Promise<SignedBroadcasterQuote> {\n const signed = (await this.call(\"broadcaster_getQuote\", {\n data,\n })) as SignedBroadcasterQuote;\n verifyBroadcasterQuote(\n signed,\n { ...context, signer: this.configuration.quoteSigner },\n data\n );\n if (getAddress(signed.quote.feeRecipient) !== this.configuration.feeRecipient)\n throw new Error(\"unregistered fee recipient\");\n return { quote: signed.quote, signature: signed.signature, context: { ...context } };\n }\n async submit(\n data: string,\n signed: SignedBroadcasterQuote,\n idempotencyKey: string\n ): Promise<BroadcasterStatus> {\n if (!signed.context) throw new Error(\"missing verified quote context\");\n verifyBroadcasterQuote(\n signed,\n { ...signed.context, signer: this.configuration.quoteSigner },\n data,\n 0n\n );\n if (getAddress(signed.quote.feeRecipient) !== this.configuration.feeRecipient)\n throw new Error(\"unregistered fee recipient\");\n return checkedStatus(\n await this.call(\"broadcaster_submitTransaction\", {\n data,\n quote: signed.quote,\n signature: signed.signature,\n idempotencyKey,\n }),\n idempotencyKey\n );\n }\n async status(id: string): Promise<BroadcasterStatus> {\n return checkedStatus(await this.call(\"broadcaster_getTransactionStatus\", { id }), id);\n }\n}\nexport class BroadcasterRpcError extends Error {\n constructor(\n readonly code: number,\n message: string\n ) {\n super(message);\n this.name = \"BroadcasterRpcError\";\n }\n}\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 { getAddress, Interface, keccak256, type Provider } from \"ethers\";\nimport { broadcasterRegistryAbi, type Address, type Hex } from \"@invisi-labs/protocol/contracts\";\nimport type { TransactionCall } from \"@invisi-labs/protocol\";\n\nexport interface BroadcasterRegistration {\n endpoint: string;\n metadataURI?: string;\n quoteSigner: Address;\n feeRecipient: Address;\n}\n\nexport interface RegisteredBroadcaster extends Required<BroadcasterRegistration> {\n operator: Address;\n enabled: boolean;\n}\n\nexport interface BroadcasterRegistryOptions {\n provider: Provider;\n address: Address;\n chainId: bigint;\n fromBlock: number;\n runtimeCodeHash: string;\n /** Maximum blocks per getLogs request. Defaults to 2,000. */\n blockRange?: number;\n}\n\nconst abi = new Interface(broadcasterRegistryAbi);\n\nfunction address(value: string): Address {\n const normalized = getAddress(value) as Address;\n if (BigInt(normalized) === 0n) throw new Error(\"zero broadcaster address\");\n return normalized;\n}\n\n/** Optional on-chain discovery. Registry entries do not authorize spending or endorse operators. */\nexport class BroadcasterRegistry {\n readonly address: Address;\n readonly #options: Readonly<BroadcasterRegistryOptions>;\n\n constructor(options: BroadcasterRegistryOptions) {\n this.address = address(options.address);\n const blockRange = options.blockRange ?? 2_000;\n if (\n options.chainId <= 0n ||\n !Number.isSafeInteger(options.fromBlock) ||\n options.fromBlock < 0 ||\n !Number.isSafeInteger(blockRange) ||\n blockRange < 1 ||\n blockRange > 100_000 ||\n !/^0x[0-9a-fA-F]{64}$/.test(options.runtimeCodeHash)\n )\n throw new Error(\"invalid broadcaster registry configuration\");\n this.#options = Object.freeze({ ...options, blockRange });\n }\n\n prepareRegistration(registration: BroadcasterRegistration): TransactionCall {\n const { endpoint, metadataURI = \"\" } = registration;\n if (\n !endpoint.startsWith(\"https://\") ||\n endpoint.length <= 8 ||\n endpoint.length > 2048 ||\n /[^\\x21-\\x7e]/.test(endpoint)\n )\n throw new Error(\"broadcaster endpoint must be a printable HTTPS URI\");\n // Parse locally for a useful error; the registry additionally enforces its byte limits.\n const url = new URL(endpoint);\n if (!url.hostname || url.username || url.password) {\n throw new Error(\"broadcaster HTTPS endpoint must not include credentials\");\n }\n if (metadataURI.length > 2048 || /[^\\x21-\\x7e]/.test(metadataURI)) {\n throw new Error(\"invalid broadcaster metadata URI\");\n }\n return this.call(\"setBroadcaster\", [\n endpoint,\n metadataURI,\n address(registration.quoteSigner),\n address(registration.feeRecipient),\n ]);\n }\n\n prepareAvailability(enabled: boolean): TransactionCall {\n return this.call(\"setEnabled\", [enabled]);\n }\n\n private call(name: string, args: readonly unknown[]): TransactionCall {\n return { to: this.address, data: abi.encodeFunctionData(name, args) as Hex, value: 0n };\n }\n\n private async validate(): Promise<void> {\n const { provider, chainId, runtimeCodeHash } = this.#options;\n if ((await provider.getNetwork()).chainId !== chainId) {\n throw new Error(\"broadcaster registry chain mismatch\");\n }\n if (\n keccak256(await provider.getCode(this.address)).toLowerCase() !==\n runtimeCodeHash.toLowerCase()\n ) {\n throw new Error(\"broadcaster registry runtime code mismatch\");\n }\n }\n\n async get(operator: Address): Promise<RegisteredBroadcaster> {\n await this.validate();\n return this.read(address(operator));\n }\n\n private async read(operator: Address): Promise<RegisteredBroadcaster> {\n const result = await this.#options.provider.call(this.call(\"broadcasterOf\", [operator]));\n const [entry] = abi.decodeFunctionResult(\"broadcasterOf\", result);\n return {\n operator,\n endpoint: entry.endpoint,\n metadataURI: entry.metadataURI,\n quoteSigner: address(entry.quoteSigner),\n feeRecipient: address(entry.feeRecipient),\n enabled: entry.enabled,\n };\n }\n\n /** Discover event operators, then read their latest entry; disabled services remain explicit. */\n async discover(\n options: { toBlock?: number; signal?: AbortSignal } = {}\n ): Promise<RegisteredBroadcaster[]> {\n const { provider, fromBlock, blockRange } = this.#options;\n options.signal?.throwIfAborted();\n await this.validate();\n const toBlock = options.toBlock ?? (await provider.getBlockNumber());\n if (!Number.isSafeInteger(toBlock) || toBlock < fromBlock) {\n throw new Error(\"invalid broadcaster discovery block range\");\n }\n const operators = new Set<Address>();\n for (let start = fromBlock; start <= toBlock;) {\n options.signal?.throwIfAborted();\n const end = Math.min(start + blockRange! - 1, toBlock);\n const logs = await provider.getLogs({\n address: this.address,\n topics: [abi.getEvent(\"BroadcasterSet\")!.topicHash],\n fromBlock: start,\n toBlock: end,\n });\n for (const log of logs) {\n if (getAddress(log.address) !== this.address)\n throw new Error(\"registry event address mismatch\");\n const event = abi.parseLog(log);\n if (!event || event.name !== \"BroadcasterSet\")\n throw new Error(\"invalid registry event\");\n operators.add(address(event.args.operator));\n }\n start = end + 1;\n }\n const entries: RegisteredBroadcaster[] = [];\n for (const operator of operators) {\n options.signal?.throwIfAborted();\n entries.push(await this.read(operator));\n }\n return entries;\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;;;ACQ3B,SAAS,8BAAwD;AACjE,SAAS,wBAA8C;AAmBvD,SAAS,MAAM,IAAa,SAA6B;AACrD,MAAI,CAAC,GAAI,OAAM,IAAI,MAAM,OAAO;AACpC;AASO,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,mBAAmB;AACf,WAAO,KAAK,OAAO,mBACb,gBAAgB,KAAK,OAAO,gBAAgB,IAC5C;AAAA,EACV;AAAA,EACA,MAAM,gBACF,QACA,SAC4B;AAC5B,SAAK,QAAQ;AACb;AAAA,MACI,KAAK,WAAW,cAAc,KAAK,SAAS;AAAA,MAC5C;AAAA,IACJ;AACA,UAAM,EAAE,uBAAuB,IAAI,MAAM,OAAO,uCAA2B;AAC3E,UAAM,WAAW,MAAM;AAAA,MACnB,KAAK,OAAO;AAAA,MACZ,KAAK,SAAS;AAAA,MACd;AAAA,MACA;AAAA,IACJ;AACA,WAAO,IAAI;AAAA,MAC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AAAA,QACR,MAAM,OAAO,OAAO;AAAA,UAChB;AAAA,YACI,MAAM;AAAA,YACN,IAAI,WAAW,KAAK,KAAK,SAAS,GAAG,EAAE,CAAC;AAAA,YACxC,gBAAgB,KAAK,IAAI,OAAO;AAAA,UACpC;AAAA,UACA,KAAK;AAAA,UACL,WAAW,KAAK,KAAK,SAAS,EAAE,CAAC;AAAA,QACrC;AAAA,MACJ;AAAA,IACJ,QAAQ;AACJ,YAAM,IAAI,MAAM,qCAAqC;AAAA,IACzD;AACA,QAAI;AACA,aAAO,iBAAiB,KAAK;AAAA,IACjC,UAAE;AACE,YAAM,KAAK,CAAC;AAAA,IAChB;AAAA,EACJ;AAAA,EACA,SAAS;AACL,WAAO,EAAE,mBAAmB,cAAc;AAAA,EAC9C;AAAA,EACA,CAAC,uBAAO,IAAI,4BAA4B,CAAC,IAAI;AACzC,WAAO,KAAK,OAAO;AAAA,EACvB;AACJ;","names":["MissingCapabilityError","MissingCapabilityError","PublicWallet","MissingCapabilityError","getAddress","getAddress","getAddress","ProtocolRpcClient","getAddress","Interface","keccak256"]}