@qntx/wallet-engine 0.12.0 → 0.14.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.
Files changed (81) hide show
  1. package/README.md +1057 -20
  2. package/dist/apps-fiat24.d.mts +202 -0
  3. package/dist/apps-fiat24.mjs +1378 -0
  4. package/dist/apps-fiat24.mjs.map +1 -0
  5. package/dist/apps-hyperliquid.d.mts +549 -0
  6. package/dist/apps-hyperliquid.mjs +2742 -0
  7. package/dist/apps-hyperliquid.mjs.map +1 -0
  8. package/dist/apps-polymarket.d.mts +729 -0
  9. package/dist/apps-polymarket.mjs +3786 -0
  10. package/dist/apps-polymarket.mjs.map +1 -0
  11. package/dist/apps.d.mts +136 -0
  12. package/dist/apps.mjs +535 -0
  13. package/dist/apps.mjs.map +1 -0
  14. package/dist/connect-BY1C5ZRI.mjs +210 -0
  15. package/dist/connect-BY1C5ZRI.mjs.map +1 -0
  16. package/dist/connect.d.mts +17 -9
  17. package/dist/connect.mjs +3 -185
  18. package/dist/controller-DpNVHVsj.d.mts +2295 -0
  19. package/dist/controller-rMnaxKAH.mjs +46 -0
  20. package/dist/controller-rMnaxKAH.mjs.map +1 -0
  21. package/dist/decimal-COJ4g8qy.mjs +38 -0
  22. package/dist/decimal-COJ4g8qy.mjs.map +1 -0
  23. package/dist/eligibility-BfM9ybYZ.mjs +48 -0
  24. package/dist/eligibility-BfM9ybYZ.mjs.map +1 -0
  25. package/dist/engine-Dic_kkEr.d.mts +1829 -0
  26. package/dist/errors-B8W-hoYW.d.mts +7 -0
  27. package/dist/errors-horUy5k1.mjs +24 -0
  28. package/dist/errors-horUy5k1.mjs.map +1 -0
  29. package/dist/gateway-contract.d.mts +3 -362
  30. package/dist/gateway-contract.mjs +1531 -81
  31. package/dist/gateway-contract.mjs.map +1 -1
  32. package/dist/idb.d.mts +5 -0
  33. package/dist/idb.mjs +122 -46
  34. package/dist/idb.mjs.map +1 -1
  35. package/dist/index-vBgfOFIh.d.mts +2227 -0
  36. package/dist/index.d.mts +58 -515
  37. package/dist/index.mjs +22314 -4901
  38. package/dist/index.mjs.map +1 -1
  39. package/dist/json-BDwV38cj.mjs +15 -0
  40. package/dist/json-BDwV38cj.mjs.map +1 -0
  41. package/dist/link-Ceq8Dggp.mjs +139 -0
  42. package/dist/link-Ceq8Dggp.mjs.map +1 -0
  43. package/dist/primitives-DbSHLZKq.mjs +31 -0
  44. package/dist/primitives-DbSHLZKq.mjs.map +1 -0
  45. package/dist/push-message-AQuzoNFY.d.mts +84 -0
  46. package/dist/push-message-kbnH1A5w.mjs +142 -0
  47. package/dist/push-message-kbnH1A5w.mjs.map +1 -0
  48. package/dist/push.d.mts +13 -0
  49. package/dist/push.mjs +70 -0
  50. package/dist/push.mjs.map +1 -0
  51. package/dist/qr.d.mts +292 -0
  52. package/dist/qr.mjs +1725 -0
  53. package/dist/qr.mjs.map +1 -0
  54. package/dist/registry-CbtwcxkX.mjs +374 -0
  55. package/dist/registry-CbtwcxkX.mjs.map +1 -0
  56. package/dist/risk-DyABgg4W.mjs +757 -0
  57. package/dist/risk-DyABgg4W.mjs.map +1 -0
  58. package/dist/session-CNJFLarP.mjs +18 -0
  59. package/dist/session-CNJFLarP.mjs.map +1 -0
  60. package/dist/socket-ChG9JRT_.mjs +110 -0
  61. package/dist/socket-ChG9JRT_.mjs.map +1 -0
  62. package/dist/spi-BrTw5s98.d.mts +3 -0
  63. package/dist/timer-Cdk5rGM2.mjs +43 -0
  64. package/dist/timer-Cdk5rGM2.mjs.map +1 -0
  65. package/dist/types-BpvioFGo.d.mts +258 -0
  66. package/dist/types-DbftVZ3I.mjs +90 -0
  67. package/dist/types-DbftVZ3I.mjs.map +1 -0
  68. package/dist/walletconnect.d.mts +86 -0
  69. package/dist/walletconnect.mjs +1507 -0
  70. package/dist/walletconnect.mjs.map +1 -0
  71. package/dist/webln-BgrtPXpG.mjs +2593 -0
  72. package/dist/webln-BgrtPXpG.mjs.map +1 -0
  73. package/dist/webln-Bllk_xJ2.d.mts +666 -0
  74. package/package.json +94 -19
  75. package/dist/connect.mjs.map +0 -1
  76. package/dist/errors-DpkJneDe.d.mts +0 -1696
  77. package/dist/registry-Deo5WQe1.d.mts +0 -25
  78. package/dist/registry-wYrcuFNc.mjs +0 -99
  79. package/dist/registry-wYrcuFNc.mjs.map +0 -1
  80. package/dist/webln-DzsI7jVb.mjs +0 -3629
  81. package/dist/webln-DzsI7jVb.mjs.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apps-fiat24.mjs","names":["groupKey","isEvmAddress","NETWORK","REFUSED","arbitrum"],"sources":["../src/apps/fiat24/errors.ts","../src/apps/fiat24/account.ts","../src/apps/fiat24/enable.ts","../src/apps/fiat24/flows.ts","../src/apps/fiat24/live.ts","../src/apps/fiat24/owner.ts","../src/apps/fiat24/rpc.ts","../src/apps/fiat24/signer.ts","../src/apps/fiat24/sessions.ts","../src/apps/fiat24/app.ts"],"sourcesContent":["/**\n * The Fiat24 provider error. `category` is the closed union the host branches on; `code` is the\n * SDK's own closed `Fiat24ErrorCode`, set only when the failure came out of `@qntx/fiat24`\n * (`category: \"protocol\"`) — the SDK's messages are fixed English templates, so they pass through\n * verbatim. No `cause` is ever attached: nothing an SDK error was built from — requests, results,\n * grants or signatures — may ride along.\n */\nimport { isFiat24Error } from \"@qntx/fiat24/core\";\nimport type { Fiat24ErrorCode } from \"@qntx/fiat24/core\";\n\n/** Fiat24 provider error categories — never carry request payloads or secrets. */\nexport type Fiat24AppErrorCategory =\n /** The vault is locked — the group address cannot be resolved; nothing was read. */\n | \"unlock-required\"\n /** The group's app status is not `enabled`. */\n | \"not-enabled\"\n /** The call needs the group's owned live Fiat24 account and it has none. */\n | \"no-account\"\n /** No `api.fiat24.com` fetch was injected — API-backed features are off. */\n | \"api-unavailable\"\n /** An enablement flow is already running for the group — wait or cancel it. */\n | \"busy\"\n /** The jurisdiction allows only winding positions down — no new exposure. */\n | \"close-only\"\n /** A flow's transaction is still `sending`/`submitted`/`unknown` — no start or discard. */\n | \"flow-unresolved\"\n /** The flow id is neither persisted nor an in-memory draft. */\n | \"unknown-flow\"\n /** The read could not be completed (endpoint down, malformed answer) — a retry may succeed. */\n | \"unavailable\"\n /** A caller input fails validation before any request. */\n | \"invalid-input\"\n /**\n * The SDK reported the failure — `code` carries its closed `Fiat24ErrorCode` (`rpc-error`,\n * `invalid-rpc-response`, `contract-revert`, …); `contract-changed` is a state, not an error.\n */\n | \"protocol\";\n\nexport class Fiat24AppError extends Error {\n readonly category: Fiat24AppErrorCategory;\n /** The SDK's closed error code — set on `protocol` only. */\n readonly code?: Fiat24ErrorCode;\n\n constructor(\n category: Fiat24AppErrorCategory,\n message: string,\n options?: { readonly code?: Fiat24ErrorCode },\n ) {\n super(message);\n this.name = \"Fiat24AppError\";\n this.category = category;\n if (options?.code !== undefined) {\n this.code = options.code;\n }\n }\n}\n\n/**\n * One funnel for every failure out of the provider: `Fiat24AppError` passes through, an SDK\n * `Fiat24Error` becomes `protocol` with its code and fixed message, and anything else — a viem or\n * transport error whose message may embed URLs, params or results — collapses to a fixed\n * `unavailable`.\n */\nexport const fromSdk = (error: unknown): Fiat24AppError => {\n if (error instanceof Fiat24AppError) {\n return error;\n }\n if (isFiat24Error(error)) {\n return new Fiat24AppError(\"protocol\", error.message, { code: error.code });\n }\n return new Fiat24AppError(\"unavailable\", \"the fiat24 chain read failed\");\n};\n","import type { Client } from \"viem\";\n\n/**\n * The group's Fiat24 account read: `loadAccount` over the cross-checked client — `deployment` is\n * never passed, so the SDK's pinned-deployment verification stays on (`verifiedBlock` asserts the\n * EIP-1967 slots of every contract the reads touch). A `contract-changed` drift is a state, not an\n * error: writes must fail closed while the deployment disagrees with the pin. Every other SDK\n * failure maps through `fromSdk` — fixed messages, no `cause`, the closed `code` carried.\n */\nimport { isFiat24Error } from \"@qntx/fiat24/core\";\nimport type { AccountStatus } from \"@qntx/fiat24/core\";\nimport { loadAccount } from \"@qntx/fiat24/flows\";\nimport type { AccountView } from \"@qntx/fiat24/flows\";\n\nimport type { AppGroup } from \"../spi.ts\";\nimport { fromSdk } from \"./errors.ts\";\nimport type { Fiat24Owner } from \"./owner.ts\";\n\n/** What a group's account read settles to — the SDK `AccountView` carried verbatim. */\nexport type Fiat24AccountState =\n | { readonly status: \"no-account\"; readonly owner: `0x${string}` }\n | {\n readonly status: AccountStatus | \"stale\";\n readonly owner: `0x${string}`;\n readonly view: Exclude<AccountView, { readonly step: \"no-account\" }>;\n }\n | {\n /** The pinned deployment drifted — every write must fail closed until it settles. */\n readonly status: \"contract-changed\";\n readonly owner: `0x${string}`;\n };\n\nexport type Fiat24AccountRead = (group: AppGroup) => Promise<Fiat24AccountState>;\n\nexport function createFiat24Account(options: {\n readonly owner: Fiat24Owner;\n readonly client: Client;\n}): Fiat24AccountRead {\n return async (group) => {\n let owner: `0x${string}`;\n try {\n owner = await options.owner(group);\n } catch (error) {\n throw fromSdk(error);\n }\n let view: AccountView;\n try {\n view = await loadAccount({ client: options.client }, { owner });\n } catch (error) {\n if (isFiat24Error(error) && error.code === \"contract-changed\") {\n return { status: \"contract-changed\", owner };\n }\n throw fromSdk(error);\n }\n return view.step === \"no-account\"\n ? { status: \"no-account\", owner }\n : { status: view.step, owner, view };\n };\n}\n","/**\n * The Fiat24 `AppProvider`: enablement is one storage record per group — `enabled` holding the\n * bytes of `{}`. There is no server-side enrollment to run and no request is ever opened:\n * `enable`/`renew` need the terms flag, write the record and settle `enabled`; `disable` deletes\n * it; `reconcile` derives the status from the record alone. The `revoke` option of `disable` has\n * nothing to reach — a group account's server-side state is the user's KYC relationship with the\n * issuer, not an app credential, so revoke is a no-op.\n */\nimport type { Client } from \"viem\";\n\nimport { getAllowances } from \"@qntx/fiat24/chain\";\nimport { CURRENCIES } from \"@qntx/fiat24/core\";\nimport type { Currency } from \"@qntx/fiat24/core\";\nimport { arbitrum } from \"@qntx/fiat24/deployments\";\n\nimport { EngineStoreError } from \"../spi.ts\";\nimport type { AppAuthority, AppFlow, AppGroup, AppProvider, AppStorage } from \"../spi.ts\";\nimport type { Fiat24AccountRead } from \"./account.ts\";\nimport { Fiat24AppError, fromSdk } from \"./errors.ts\";\nimport type { Fiat24Owner } from \"./owner.ts\";\n\n/** The group's enablement record — presence IS the fact; the payload is deliberately empty. */\nconst RECORD = \"enabled\";\n\n/** `getAllowances`' deposit-side keys in order. */\nconst DEPOSIT_ASSETS: ReadonlyArray<Currency | \"USDC\"> = [...CURRENCIES, \"USDC\"];\nconst ENABLED_BYTES = new TextEncoder().encode(\"{}\");\n\nconst errorOf = (error: unknown): { category: string; message: string } =>\n error instanceof Fiat24AppError\n ? { category: error.category, message: error.message }\n : { category: \"unavailable\", message: \"the fiat24 enablement write failed\" };\n\n/** Run `body`; a stale flow stops writing but a thrown error still surfaces to the caller. */\nconst guard = async (flow: AppFlow, body: () => Promise<void>): Promise<void> => {\n try {\n await body();\n } catch (error) {\n if (!flow.stale()) {\n flow.write({ error: errorOf(error), requestId: undefined });\n }\n throw error;\n }\n};\n\nexport function createFiat24Enable(options: {\n readonly storage: AppStorage;\n /** Disable cleanup — ends the group's session, drops its drafts, rejects its open requests. */\n readonly onDisable: (group: AppGroup) => void;\n /**\n * The group's reconcile pass — `reconcile` runs per group only after init opened the store, so\n * this is the earliest point persisted flows can be read.\n */\n readonly onEnabled: (group: AppGroup) => void;\n /** The group's owner EOA — the address the flows' approvals sit on. */\n readonly owner: Fiat24Owner;\n /** The corroborated Arbitrum One client every Fiat24 chain read goes through. */\n readonly client: Client;\n /** The group's account read — a `no-account` group holds no flow-granted allowance. */\n readonly account: Fiat24AccountRead;\n}): AppProvider {\n const enabled = async (group: AppGroup): Promise<boolean> =>\n (await options.storage.get(group, RECORD)) !== undefined;\n\n const enable = async (group: AppGroup, flow: AppFlow): Promise<void> => {\n if (flow.current().status !== \"enabling\") {\n flow.write({ status: \"enabling\", error: undefined });\n }\n if (!flow.current().termsAcknowledged) {\n throw new Fiat24AppError(\"invalid-input\", \"Fiat24 terms have not been acknowledged\");\n }\n await options.storage.put(group, RECORD, ENABLED_BYTES);\n flow.write({ status: \"enabled\", error: undefined });\n };\n\n return {\n error: (category, message) => new Fiat24AppError(category, message),\n groups: options.storage.groups,\n reconcile: async (group, flow) => {\n let hasRecord: boolean;\n try {\n hasRecord = await enabled(group);\n } catch (error) {\n /* A locked/closed store leaves the state untouched — the lock itself cleared it. */\n if (error instanceof EngineStoreError && error.code === \"closed\") {\n return;\n }\n throw error;\n }\n flow.write({ status: hasRecord ? \"enabled\" : \"disabled\", error: undefined });\n if (hasRecord) {\n options.onEnabled(group);\n }\n },\n enable: async (group, flow) => guard(flow, async () => enable(group, flow)),\n /* There is nothing to rotate — `renew` is exactly `enable`. */\n renew: async (group, flow) => guard(flow, async () => enable(group, flow)),\n disable: async (group, _options, flow) =>\n guard(flow, async () => {\n await options.storage.delete(group, RECORD);\n options.onDisable(group);\n flow.write({ status: \"disabled\", error: undefined });\n }),\n cancel: async (_group, flow) => {\n flow.write({ status: \"disabled\", error: undefined });\n await Promise.resolve();\n },\n authorities: async (group): Promise<ReadonlyArray<AppAuthority>> => {\n const state = await options.account(group);\n if (state.status === \"no-account\") {\n return [];\n }\n /* The §6.1 approve pairs, read live: cash×card caps, cash/USDC×deposit, F24×account —\n ordinary owner-EOA allowances the approvals inventory revokes. */\n const allowances = await getAllowances(options.client, { owner: state.owner }).catch(\n (error: unknown) => {\n throw fromSdk(error);\n },\n );\n const UINT256_MAX = 2n ** 256n - 1n;\n const rows: AppAuthority[] = [];\n const row = (holder: string, asset: string, amount: bigint): void => {\n if (amount <= 0n) {\n return;\n }\n rows.push({\n kind: \"token-allowance\",\n network: \"eip155:42161\",\n account: state.owner,\n holder,\n asset,\n ...(amount === UINT256_MAX ? {} : { limit: amount.toString() }),\n revoke: \"approvals\",\n });\n };\n for (const currency of CURRENCIES) {\n row(arbitrum.card.proxy, arbitrum.tokens[currency].proxy, allowances.card[currency]);\n }\n for (const asset of DEPOSIT_ASSETS) {\n row(\n arbitrum.deposit.proxy,\n asset === \"USDC\" ? arbitrum.usdc : arbitrum.tokens[asset].proxy,\n allowances.deposit[asset],\n );\n }\n row(arbitrum.account.proxy, arbitrum.f24.address, allowances.account.F24);\n return rows;\n },\n };\n}\n","/**\n * The Fiat24 resumable flows over the app's SPI: state starts through the SDK, persists as\n * `flow/<id>` (`encodeFlowState` text — untrusted on the way back in, re-decoded per advance), and\n * advances one-at-a-time per group through the layer-1 client and the request-pipeline signer.\n * Payout drafts hold payee PII so they stay in a memory-only map until the first `advancePayout`\n * verifies them into a persisted `verified` state. Sessions and the public api are optional\n * `FlowDeps` — the SDK refuses with its own codes when a flow needs one the host never wired.\n * Reconcile never sends: it enqueues advances only for records whose last phase is\n * `sending`/`submitted`/`unknown`, the three phases where the SDK's `advanceTx` polls and never\n * reaches `readyPhase` (flows/tx.ts gates the signer behind `phase === \"ready\"` or no record).\n */\nimport { bytesToHex } from \"viem\";\nimport type { Client } from \"viem\";\n\nimport type { Fiat24Api } from \"@qntx/fiat24/api\";\nimport type { PayoutSettlement } from \"@qntx/fiat24/chain\";\nimport type { Currency, PayoutCurrency, Recipient } from \"@qntx/fiat24/core\";\nimport { isFiat24Error } from \"@qntx/fiat24/core\";\nimport {\n advanceCard,\n advanceExchange,\n advanceOnboarding,\n advancePayout,\n advanceTopUp,\n advanceTransfer,\n decodeFlowState,\n encodeFlowState,\n loadPayoutSettlement,\n startCardOperation,\n startCardSetup,\n startExchange,\n startOnboarding,\n startPayout,\n startTopUp,\n startTransfer,\n} from \"@qntx/fiat24/flows\";\nimport type {\n CardOperation,\n FlowDeps,\n FlowState,\n PayoutDraft,\n PayoutTarget,\n TxPhase,\n} from \"@qntx/fiat24/flows\";\nimport type { Wallet } from \"@qntx/wallet\";\n\nimport type {\n AppAvailability,\n AppGroup,\n AppGroupState,\n AppRequests,\n AppStorage,\n EngineLogger,\n SetTimer,\n} from \"../spi.ts\";\nimport type { Fiat24AccountRead } from \"./account.ts\";\nimport { Fiat24AppError, fromSdk } from \"./errors.ts\";\nimport type { Fiat24Owner } from \"./owner.ts\";\nimport type { createFiat24Sessions } from \"./sessions.ts\";\nimport type { Fiat24Refusal } from \"./signer.ts\";\n\n/**\n * The record name the enable provider writes — a flow reads it to gate reconcile before\n * `groupState` is derived (the unlock hook runs before `init`).\n */\nconst ENABLED = \"enabled\";\nconst FLOW_PREFIX = \"flow/\";\n/** The reconcile cadence — the same 15 s the account live view polls at. */\nconst FIAT24_RECONCILE_MS = 15_000;\n/** Reconcile-only phases — `advanceTx` in these polls receipts/nonces and can never sign. */\nconst UNRESOLVED: ReadonlySet<TxPhase> = new Set([\"sending\", \"submitted\", \"unknown\"]);\n\n/**\n * Whether the state's next move must reach api.fiat24.com — read off the SDK's own dispatch: a\n * payout `draft` with a `bank`/`swiss-qr` target (`verifyTarget` → `checkedSession`,\n * flows/payout.ts:313 — contact targets skip the session); a card `ready` with no chain leg\n * (`advanceApiWrite` → `checkedSession`, flows/card.ts:438,256) or a `tx`/`confirmed` whose last\n * record is a `main` write; onboarding `tourist`/`kyc` (`api.kycStatus`, flows/onboarding.ts:313).\n * The one reach it cannot see statically — a card `ready` with a chain leg (cap or set-cap), where\n * the write follows only when the allowance already matches — throws `session-required` in the SDK\n * and the advance catch maps it to the same `api-unavailable`.\n */\nconst needsApi = (state: FlowState | PayoutDraft): boolean => {\n switch (state.flow) {\n case \"payout\":\n return state.step === \"draft\" && state.target.kind !== \"contact\";\n case \"card\":\n if (state.step === \"tx\" || state.step === \"confirmed\") {\n return state.txs.at(-1)?.purpose === \"main\";\n }\n return (\n state.step === \"ready\" && state.cap === undefined && state.operation.kind !== \"set-cap\"\n );\n case \"onboarding\":\n return state.step === \"tourist\" || state.step === \"kyc\";\n default:\n return false;\n }\n};\n\nexport type Fiat24FlowEntry = {\n readonly id: string;\n readonly state: FlowState | PayoutDraft;\n /** What the signer reported during this `advance` — memory only, never persisted. */\n readonly refusal?: Fiat24Refusal;\n};\n\n/**\n * A `list` entry: a decodable flow state, or `{ invalid: true }` for a persisted record that no\n * longer decodes — it can never be reconciled, `start` stays `flow-unresolved` while one exists (it\n * cannot be proven not to be `sending`), `discard` removes it, and `advance`/`reconcile` on it is a\n * `protocol` `invalid-state`.\n */\nexport type Fiat24Flow = Fiat24FlowEntry | { readonly id: string; readonly invalid: true };\n\nexport type Fiat24FlowInput =\n | {\n readonly flow: \"transfer\";\n readonly currency: Currency;\n readonly amount: bigint;\n readonly to: Recipient;\n }\n | {\n readonly flow: \"exchange\";\n readonly side: \"exact-in\" | \"exact-out\";\n readonly from: Currency;\n readonly to: Currency;\n readonly amount: bigint;\n }\n | {\n readonly flow: \"payout\";\n readonly currency: PayoutCurrency;\n readonly amount: bigint;\n readonly target: PayoutTarget;\n }\n | { readonly flow: \"top-up\"; readonly output: Currency; readonly usdcAmount: bigint }\n | { readonly flow: \"onboarding\"; readonly tokenId: bigint; readonly payment: \"f24\" | \"eth\" }\n | {\n readonly flow: \"card-setup\";\n readonly cap: { readonly currency: Currency; readonly amount: bigint };\n }\n | { readonly flow: \"card\"; readonly operation: CardOperation };\n\nexport type Fiat24Flows = {\n /** The group's persisted flows plus its in-memory payout drafts. */\n readonly list: (group: AppGroup) => Promise<ReadonlyArray<Fiat24Flow>>;\n readonly start: (group: AppGroup, input: Fiat24FlowInput) => Promise<Fiat24FlowEntry>;\n /** One advance at a time per group — concurrent calls queue behind the running one. */\n readonly advance: (group: AppGroup, id: string) => Promise<Fiat24FlowEntry>;\n readonly discard: (group: AppGroup, id: string) => Promise<void>;\n readonly payoutSettlement: (\n group: AppGroup,\n id: string,\n ) => Promise<PayoutSettlement & { readonly txid: string }>;\n};\n\ntype Sessions = ReturnType<typeof createFiat24Sessions>;\n\nconst groupKey = (group: AppGroup): string => `${group.walletId}/${group.groupIndex}`;\n\nconst text = new TextEncoder();\nconst read = new TextDecoder();\n\nconst lastPhase = (state: FlowState): TxPhase | undefined => state.txs.at(-1)?.phase;\n\nexport function createFiat24Flows(options: {\n readonly wallet: Wallet;\n readonly requests: AppRequests;\n readonly storage: AppStorage;\n readonly random: (bytes: number) => Uint8Array;\n readonly setTimer: SetTimer;\n readonly logger: EngineLogger;\n readonly availability: () => AppAvailability | undefined;\n readonly groupState: (group: AppGroup) => AppGroupState | undefined;\n readonly client: Client;\n readonly owner: Fiat24Owner;\n readonly account: Fiat24AccountRead;\n readonly api: Fiat24Api | undefined;\n readonly sessions: Sessions;\n}): {\n readonly flows: Fiat24Flows;\n /** Re-arms the 15 s poll when the host's visibility flag is set — the flag survives a lock. */\n readonly unlock: () => void;\n /** Starts/stops the 15 s reconcile poll; `setVisible(false)` stops it. */\n readonly setVisible: (visible: boolean) => void;\n /** The provider-reconcile hook: one reconcile pass for this group, never sends. */\n readonly reconcileGroup: (group: AppGroup) => Promise<void>;\n /** Vault lock — drafts are PII and sessions are bearer grants; both die here. */\n readonly lock: () => void;\n /** Ends the group's session, drops its drafts and rejects its still-open requests. */\n readonly dropGroup: (group: AppGroup) => void;\n /** `dropGroup` for every tracked group whose walletId is no longer in the snapshot. */\n readonly dropMissing: (wallets: ReadonlySet<string>) => void;\n readonly close: () => void;\n} {\n const { storage, requests } = options;\n /** Per-group serial advance queue — the SDK forbids concurrent advances of one group. */\n const queue = new Map<string, Promise<unknown>>();\n /** Payout drafts by group — payee PII never touches storage. */\n const drafts = new Map<string, Map<string, PayoutDraft>>();\n /** Every group the flows module has touched — the wallet-removal sweep's candidates. */\n const known = new Map<string, AppGroup>();\n let visible = false;\n let timer: (() => void) | undefined;\n let polling = false;\n\n const unlocked = (): boolean => options.wallet.getSnapshot().vault === \"unlocked\";\n\n const requireUnlocked = (): void => {\n if (!unlocked()) {\n throw new Fiat24AppError(\"unlock-required\", \"unlock the vault to use the Fiat24 app\");\n }\n };\n\n const requireEnabled = (group: AppGroup): void => {\n requireUnlocked();\n if (options.groupState(group)?.status !== \"enabled\") {\n throw new Fiat24AppError(\"not-enabled\", \"enable the Fiat24 app for this group first\");\n }\n };\n\n const enabledRecord = async (group: AppGroup): Promise<boolean> => {\n try {\n return (await storage.get(group, ENABLED)) !== undefined;\n } catch {\n return false;\n }\n };\n\n const draftsOf = (group: AppGroup): Map<string, PayoutDraft> => {\n const key = groupKey(group);\n known.set(key, group);\n let groupDrafts = drafts.get(key);\n if (groupDrafts === undefined) {\n groupDrafts = new Map();\n drafts.set(key, groupDrafts);\n }\n return groupDrafts;\n };\n\n const persisted = async (\n group: AppGroup,\n ): Promise<ReadonlyArray<{ id: string; state: FlowState } | { id: string; invalid: true }>> => {\n known.set(groupKey(group), group);\n const listed = await storage.list(group);\n const names = listed.filter((name) => name.startsWith(FLOW_PREFIX));\n const records = await Promise.all(names.map(async (name) => storage.get(group, name)));\n const out: Array<{ id: string; state: FlowState } | { id: string; invalid: true }> = [];\n for (const [index, bytes] of records.entries()) {\n const id = (names[index] ?? \"\").slice(FLOW_PREFIX.length);\n if (bytes === undefined) {\n continue;\n }\n try {\n out.push({ id, state: decodeFlowState(read.decode(bytes)) });\n } catch {\n /* Persisted bytes are untrusted — an undecodable record is reported, not fatal. */\n out.push({ id, invalid: true });\n }\n }\n return out;\n };\n\n /**\n * A sending/unknown last record blocks a replacement start — the SDK never resends it. An\n * undecodable record blocks too: it cannot be proven not to be sending, so it fails closed.\n */\n const requireResolved = async (group: AppGroup): Promise<void> => {\n for (const record of await persisted(group)) {\n if (\n \"invalid\" in record ||\n lastPhase(record.state) === \"sending\" ||\n lastPhase(record.state) === \"unknown\"\n ) {\n throw new Fiat24AppError(\n \"flow-unresolved\",\n \"a Fiat24 transaction is still sending — reconcile it before starting another\",\n );\n }\n }\n };\n\n /** The group's owned live tokenId — payout and card flows cannot run without it. */\n const tokenIdOf = async (group: AppGroup): Promise<bigint> => {\n const account = await options.account(group);\n if (account.status !== \"live\" || !account.view.account.ownsToken) {\n throw new Fiat24AppError(\"no-account\", \"the group owns no live Fiat24 account\");\n }\n return account.view.account.tokenId;\n };\n\n const requireAvailable = (): void => {\n const availability = options.availability();\n if (availability === \"close-only\") {\n throw new Fiat24AppError(\"close-only\", \"Fiat24 is close-only in this jurisdiction\");\n }\n if (availability !== \"available\") {\n throw new Fiat24AppError(\"unavailable\", \"Fiat24 availability is unknown\");\n }\n };\n\n const persist = async (group: AppGroup, id: string, state: FlowState): Promise<void> => {\n await storage.put(group, `${FLOW_PREFIX}${id}`, text.encode(encodeFlowState(state)));\n };\n\n const persistFromSdk = async (group: AppGroup, id: string, state: FlowState): Promise<void> => {\n try {\n await persist(group, id, state);\n } catch (error) {\n throw fromSdk(error);\n }\n };\n\n const start = async (group: AppGroup, input: Fiat24FlowInput): Promise<Fiat24FlowEntry> => {\n requireEnabled(group);\n const owner = await options.owner(group);\n if (input.flow === \"onboarding\" || input.flow === \"top-up\") {\n requireAvailable();\n }\n await requireResolved(group);\n let state: FlowState | PayoutDraft;\n try {\n switch (input.flow) {\n case \"transfer\":\n state = startTransfer({\n owner,\n currency: input.currency,\n amount: input.amount,\n to: input.to,\n });\n break;\n case \"exchange\":\n state = startExchange({\n owner,\n side: input.side,\n from: input.from,\n to: input.to,\n amount: input.amount,\n });\n break;\n case \"payout\":\n state = startPayout({\n owner,\n tokenId: await tokenIdOf(group),\n currency: input.currency,\n amount: input.amount,\n target: input.target,\n });\n break;\n case \"top-up\":\n state = startTopUp({ owner, output: input.output, usdcAmount: input.usdcAmount });\n break;\n case \"onboarding\":\n state = startOnboarding({ owner, tokenId: input.tokenId, payment: input.payment });\n break;\n case \"card-setup\":\n state = startCardSetup({ owner, tokenId: await tokenIdOf(group), cap: input.cap });\n break;\n case \"card\":\n state = startCardOperation({\n owner,\n tokenId: await tokenIdOf(group),\n operation: input.operation,\n });\n break;\n }\n } catch (error) {\n throw fromSdk(error);\n }\n const id = bytesToHex(options.random(8)).slice(2);\n if (state.flow === \"payout\" && state.step === \"draft\") {\n draftsOf(group).set(id, state);\n } else {\n await persist(group, id, state);\n }\n return { id, state };\n };\n\n /** The advance deps for one state — signer, persistence, and the optional session/api. */\n const depsFor = async (\n group: AppGroup,\n id: string,\n state: FlowState | PayoutDraft,\n capture: { refusal?: Fiat24Refusal },\n ): Promise<FlowDeps> => {\n const owner = await options.owner(group);\n const tokenId = \"tokenId\" in state ? state.tokenId : undefined;\n const signer = options.sessions.signer({\n group,\n owner,\n ...(tokenId === undefined ? {} : { tokenId }),\n refused: (reason) => {\n capture.refusal = reason;\n },\n });\n const deps: {\n client: FlowDeps[\"client\"];\n signer: FlowDeps[\"signer\"];\n persist: FlowDeps[\"persist\"];\n session?: NonNullable<FlowDeps[\"session\"]>;\n api?: NonNullable<FlowDeps[\"api\"]>;\n } = {\n client: options.client,\n signer,\n persist: async (next) => persistFromSdk(group, id, next),\n };\n if ((state.flow === \"payout\" || state.flow === \"card\") && tokenId !== undefined) {\n const session = await options.sessions.sdk(group, tokenId);\n if (session !== undefined) {\n deps.session = session;\n }\n }\n if (state.flow === \"onboarding\" && options.api !== undefined) {\n deps.api = options.api;\n }\n return deps;\n };\n\n const advanceOnce = async (group: AppGroup, id: string): Promise<Fiat24FlowEntry> => {\n const draft = draftsOf(group).get(id);\n let state: FlowState | PayoutDraft;\n let persistedId = false;\n if (draft === undefined) {\n const bytes = await storage.get(group, `${FLOW_PREFIX}${id}`);\n if (bytes === undefined) {\n throw new Fiat24AppError(\"unknown-flow\", \"unknown Fiat24 flow\");\n }\n try {\n state = decodeFlowState(read.decode(bytes));\n } catch (error) {\n throw fromSdk(error);\n }\n persistedId = true;\n } else {\n state = draft;\n }\n /* Refused before any SDK call: the state's next move reaches api.fiat24.com and none is\n wired. An in-flight chain record (approve `sending`, mint `submitted`) is never in this\n table — its advance polls the chain, not the API. */\n if (options.api === undefined && needsApi(state)) {\n throw new Fiat24AppError(\"api-unavailable\", \"the fiat24 api is not configured\");\n }\n const capture: { refusal?: Fiat24Refusal } = {};\n let next: FlowState;\n try {\n const deps = await depsFor(group, id, state, capture);\n switch (state.flow) {\n case \"transfer\":\n next = await advanceTransfer(deps, state);\n break;\n case \"exchange\":\n next = await advanceExchange(deps, state);\n break;\n case \"payout\":\n next = await advancePayout(deps, state);\n break;\n case \"card\":\n next = await advanceCard(deps, state);\n break;\n case \"onboarding\":\n next = await advanceOnboarding(deps, state);\n break;\n case \"top-up\":\n next = await advanceTopUp(deps, state);\n break;\n }\n } catch (error) {\n /* The one API reach `needsApi` cannot see: a card `ready` whose chain leg reads satisfied\n falls into `advanceApiWrite` mid-advance. `session-required` can only mean no session was\n wired (depsFor opens one whenever `options.api` exists) — it is `api-unavailable`. */\n if (isFiat24Error(error) && error.code === \"session-required\") {\n throw new Fiat24AppError(\"api-unavailable\", \"the fiat24 api is not configured\");\n }\n throw fromSdk(error);\n }\n if (!persistedId) {\n /* A draft's first advance produced the verified state — persist it and drop the PII. */\n draftsOf(group).delete(id);\n }\n return {\n id,\n state: next,\n ...(capture.refusal === undefined ? {} : { refusal: capture.refusal }),\n };\n };\n\n /** Serialises the group's advances; `enabledBy` is the gate at run time, not enqueue time. */\n const enqueue = async (\n group: AppGroup,\n run: () => Promise<Fiat24FlowEntry>,\n ): Promise<Fiat24FlowEntry> => {\n const key = groupKey(group);\n const tail = queue.get(key) ?? Promise.resolve();\n // oxlint-disable-next-line promise/prefer-await-to-then -- the tail chain is the serialisation, not an await site\n const next = tail.then(run, run);\n queue.set(\n key,\n // oxlint-disable-next-line promise/prefer-await-to-then -- the stored tail swallows so one failure frees the queue\n next.catch(() => undefined),\n );\n return next;\n };\n\n const advance = async (group: AppGroup, id: string): Promise<Fiat24FlowEntry> =>\n enqueue(group, async () => {\n requireEnabled(group);\n return advanceOnce(group, id);\n });\n\n /** Reconcile advance — gated on the storage record, safe before `init` derives groupState. */\n const reconcileAdvance = async (group: AppGroup, id: string): Promise<Fiat24FlowEntry> =>\n enqueue(group, async () => {\n requireUnlocked();\n if (!(await enabledRecord(group))) {\n throw new Fiat24AppError(\"not-enabled\", \"enable the Fiat24 app for this group first\");\n }\n return advanceOnce(group, id);\n });\n\n const discard = async (group: AppGroup, id: string): Promise<void> => {\n requireEnabled(group);\n const draft = draftsOf(group).get(id);\n if (draft !== undefined) {\n draftsOf(group).delete(id);\n return;\n }\n const bytes = await storage.get(group, `${FLOW_PREFIX}${id}`);\n if (bytes === undefined) {\n throw new Fiat24AppError(\"unknown-flow\", \"unknown Fiat24 flow\");\n }\n let state: FlowState;\n try {\n state = decodeFlowState(read.decode(bytes));\n } catch {\n /* An undecodable record can never reconcile — drop it; the host should have the user check\n the account's activity first. */\n await storage.delete(group, `${FLOW_PREFIX}${id}`);\n return;\n }\n const phase = lastPhase(state);\n if (phase !== undefined && UNRESOLVED.has(phase)) {\n throw new Fiat24AppError(\n \"flow-unresolved\",\n \"a Fiat24 transaction is still sending — reconcile it before discarding\",\n );\n }\n await storage.delete(group, `${FLOW_PREFIX}${id}`);\n };\n\n const payoutSettlement = async (\n group: AppGroup,\n id: string,\n ): Promise<PayoutSettlement & { readonly txid: string }> => {\n requireEnabled(group);\n const bytes = await storage.get(group, `${FLOW_PREFIX}${id}`);\n if (bytes === undefined) {\n throw new Fiat24AppError(\"unknown-flow\", \"unknown Fiat24 flow\");\n }\n let state: FlowState;\n try {\n state = decodeFlowState(read.decode(bytes));\n } catch (error) {\n throw fromSdk(error);\n }\n if (state.flow !== \"payout\") {\n throw new Fiat24AppError(\"invalid-input\", \"the flow is not a payout\");\n }\n try {\n return await loadPayoutSettlement({ client: options.client }, state);\n } catch (error) {\n throw fromSdk(error);\n }\n };\n\n /** (group, id) pairs with a reconcile advance already queued or running — never enqueued twice. */\n const inflight = new Set<string>();\n\n /**\n * One reconcile pass over the group's persisted flows — never sends. Driven by the provider's\n * `reconcile` (which runs per group once the store is open at init) and by the 15 s poll.\n */\n const reconcileGroup = async (group: AppGroup): Promise<void> => {\n if (!unlocked()) {\n return;\n }\n try {\n if (!(await enabledRecord(group))) {\n return;\n }\n } catch {\n return;\n }\n let records: ReadonlyArray<{ id: string; state: FlowState } | { id: string; invalid: true }>;\n try {\n records = await persisted(group);\n } catch (error) {\n warn(group, error);\n return;\n }\n for (const record of records) {\n if (\"invalid\" in record) {\n options.logger.warn(\"fiat24 reconcile skipped an undecodable flow\", {\n category: \"protocol\",\n code: \"invalid-state\",\n });\n continue;\n }\n const phase = lastPhase(record.state);\n if (phase === undefined || !UNRESOLVED.has(phase)) {\n continue;\n }\n const inflightKey = `${groupKey(group)}:${record.id}`;\n if (inflight.has(inflightKey)) {\n continue;\n }\n inflight.add(inflightKey);\n /* oxlint-disable promise/prefer-await-to-then -- reconcile is fire-and-forget behind the\n serial queue; settle and cleanup run detached */\n void reconcileAdvance(group, record.id)\n .catch((error: unknown) => warn(group, error))\n .finally(() => {\n inflight.delete(inflightKey);\n });\n /* oxlint-enable promise/prefer-await-to-then */\n }\n };\n\n /** One reconcile pass over every group's persisted flows — never sends. */\n const reconcilePass = async (): Promise<void> => {\n if (!unlocked()) {\n return;\n }\n let groups: ReadonlyArray<AppGroup>;\n try {\n groups = await storage.groups();\n } catch {\n return;\n }\n await Promise.all(groups.map(async (group) => reconcileGroup(group)));\n };\n\n const warn = (group: AppGroup, error: unknown): void => {\n const category = error instanceof Fiat24AppError ? error.category : \"protocol\";\n const code = error instanceof Fiat24AppError ? error.code : undefined;\n options.logger.warn(`fiat24 reconcile ${groupKey(group)} failed`, { category, code });\n };\n\n const poll = async (): Promise<void> => {\n polling = true;\n try {\n await reconcilePass();\n } finally {\n polling = false;\n timer =\n visible && unlocked()\n ? options.setTimer(FIAT24_RECONCILE_MS, () => void poll())\n : undefined;\n }\n };\n\n const dropGroup = (group: AppGroup): void => {\n options.sessions.end(group);\n drafts.delete(groupKey(group));\n for (const id of options.sessions.openedIds(group)) {\n try {\n requests.reject(id);\n } catch {\n /* the request already settled — nothing left to reject */\n }\n }\n };\n\n return {\n flows: {\n list: async (group) => {\n requireEnabled(group);\n const out: Fiat24Flow[] = [];\n for (const record of await persisted(group)) {\n out.push(record);\n }\n for (const [id, state] of draftsOf(group)) {\n out.push({ id, state });\n }\n return out;\n },\n start,\n advance,\n discard,\n payoutSettlement,\n },\n reconcileGroup,\n unlock: () => {\n /* The pre-init reconcile pass lives in the provider's `reconcile` — it runs once the store\n is open. This hook only re-arms the poll; `visible` is the host's flag, kept across lock. */\n if (visible && timer === undefined && !polling) {\n timer = options.setTimer(FIAT24_RECONCILE_MS, () => void poll());\n }\n },\n setVisible: (next) => {\n visible = next;\n if (visible && unlocked() && timer === undefined && !polling) {\n // oxlint-disable-next-line promise/prefer-await-to-then -- the visibility hook is synchronous\n void poll().catch(() => undefined);\n } else if (!visible && timer !== undefined) {\n timer();\n timer = undefined;\n }\n },\n lock: () => {\n /* The host's visibility flag is kept — unlock re-arms the poll without another setVisible. */\n if (timer !== undefined) {\n timer();\n timer = undefined;\n }\n drafts.clear();\n options.sessions.endAll();\n },\n dropGroup,\n dropMissing: (wallets) => {\n const groups = new Map<string, AppGroup>(known);\n for (const group of options.sessions.tracked()) {\n groups.set(groupKey(group), group);\n }\n for (const group of groups.values()) {\n if (!wallets.has(group.walletId)) {\n dropGroup(group);\n }\n }\n },\n close: () => {\n visible = false;\n if (timer !== undefined) {\n timer();\n timer = undefined;\n }\n drafts.clear();\n options.sessions.endAll();\n },\n };\n}\n","import type { Fiat24ErrorCode } from \"@qntx/fiat24/core\";\n/**\n * Live Fiat24 account views: one poller per open view re-reads `account(group)` every\n * {@link FIAT24_POLL_MS} on the injected one-shot timer — the next run arms only after the read\n * settles, so runs never overlap. Polling happens only while the host holds `setVisible(true)` AND\n * the vault is unlocked (the `setVisible` convention of the prices/assets controllers); a vault\n * lock — the app instance's `lock` hook — stops every view and clears its data (a locked vault\n * holds no account data, same rule as the hyperliquid account views), `unlock` resumes whatever is\n * still visible. A failed read keeps the last data and reports `stale` + the mapped error;\n * `close()` on a view or on the app stops it for good and drops the data.\n */\nimport type { Wallet } from \"@qntx/wallet\";\n\nimport type { AppGroup, SetTimer } from \"../spi.ts\";\nimport type { Fiat24AccountRead, Fiat24AccountState } from \"./account.ts\";\nimport { fromSdk } from \"./errors.ts\";\nimport type { Fiat24AppErrorCategory } from \"./errors.ts\";\n\n/** The pacing the SDK README gives for advancing an in-flight flow — reused for account polls. */\nexport const FIAT24_POLL_MS = 15_000;\n\n/** What a live view reports — `data` is kept while `stale`, never past a lock or a close. */\nexport type Fiat24LiveState = {\n readonly status: \"loading\" | \"live\" | \"stale\";\n readonly data: Fiat24AccountState | undefined;\n readonly updatedAt: number | undefined;\n /** The last read failure, mapped — `protocol` carries the SDK's closed `code`. */\n readonly error?:\n | {\n readonly category: Fiat24AppErrorCategory;\n readonly code?: Fiat24ErrorCode | undefined;\n }\n | undefined;\n};\n\nexport type Fiat24LiveView = {\n readonly getState: () => Fiat24LiveState;\n /** Listener on every state change; returns an unsubscribe. */\n readonly subscribe: (listener: (state: Fiat24LiveState) => void) => () => void;\n /** Stops this view's polling — account data does not outlive the view. */\n readonly close: () => Promise<void>;\n};\n\ntype View = {\n readonly group: AppGroup;\n state: Fiat24LiveState;\n listeners: Set<(state: Fiat24LiveState) => void>;\n closed: boolean;\n cancel: (() => void) | undefined;\n polling: boolean;\n};\n\nconst CLEARED: Fiat24LiveState = {\n status: \"stale\",\n data: undefined,\n updatedAt: undefined,\n};\n\nexport function createFiat24Live(options: {\n readonly account: Fiat24AccountRead;\n readonly wallet: Wallet;\n readonly setTimer: SetTimer;\n readonly now: () => number;\n}): {\n readonly view: (group: AppGroup) => Fiat24LiveView;\n readonly setVisible: (visible: boolean) => void;\n readonly unlock: () => Promise<void>;\n readonly lock: () => void;\n readonly close: () => void;\n} {\n const views = new Set<View>();\n let visible = false;\n let locked = false;\n let closedAll = false;\n\n const emit = (view: View): void => {\n for (const listener of view.listeners) {\n listener(view.state);\n }\n };\n\n const set = (view: View, next: Fiat24LiveState): void => {\n view.state = next;\n emit(view);\n };\n\n const active = (view: View): boolean =>\n !closedAll &&\n !view.closed &&\n visible &&\n !locked &&\n options.wallet.getSnapshot().vault === \"unlocked\";\n\n const arm = (view: View): void => {\n if (view.cancel !== undefined || !active(view)) {\n return;\n }\n view.cancel = options.setTimer(FIAT24_POLL_MS, () => {\n view.cancel = undefined;\n void poll(view);\n });\n };\n\n const poll = async (view: View): Promise<void> => {\n if (view.polling || !active(view)) {\n return;\n }\n view.polling = true;\n try {\n const data = await options.account(view.group);\n /* A hide or a lock that landed mid-read already marked the view — the answer is dropped,\n not applied over the cleared state. */\n if (active(view)) {\n set(view, { status: \"live\", data, updatedAt: options.now(), error: undefined });\n }\n } catch (error) {\n if (active(view)) {\n const mapped = fromSdk(error);\n set(view, {\n status: \"stale\",\n data: view.state.data,\n updatedAt: view.state.updatedAt,\n error: { category: mapped.category, code: mapped.code },\n });\n }\n } finally {\n view.polling = false;\n arm(view);\n }\n };\n\n /** Cancel the pending tick and drop the account data — lock and close share this. */\n const clearView = (view: View): void => {\n view.cancel?.();\n view.cancel = undefined;\n set(view, CLEARED);\n };\n\n return {\n view: (group) => {\n const view: View = {\n group,\n state: { status: \"loading\", data: undefined, updatedAt: undefined },\n listeners: new Set(),\n closed: false,\n cancel: undefined,\n polling: false,\n };\n views.add(view);\n void poll(view);\n return {\n getState: () => view.state,\n subscribe: (listener) => {\n view.listeners.add(listener);\n return () => {\n view.listeners.delete(listener);\n };\n },\n close: async () => {\n if (view.closed) {\n return;\n }\n view.closed = true;\n views.delete(view);\n clearView(view);\n await Promise.resolve();\n },\n };\n },\n setVisible: (next) => {\n if (next === visible) {\n return;\n }\n visible = next;\n for (const view of views) {\n if (visible) {\n void poll(view);\n } else {\n view.cancel?.();\n view.cancel = undefined;\n /* The view stops refreshing — its data is kept but can no longer be called live. */\n set(view, { ...view.state, status: \"stale\" });\n }\n }\n },\n unlock: async () => {\n locked = false;\n for (const view of views) {\n void poll(view);\n }\n await Promise.resolve();\n },\n lock: () => {\n locked = true;\n for (const view of views) {\n clearView(view);\n }\n },\n close: () => {\n closedAll = true;\n for (const view of views) {\n view.closed = true;\n clearView(view);\n }\n views.clear();\n },\n };\n}\n","/**\n * The group's Fiat24 owner: its `evm.bip44` address on Arbitrum One — the address every Fiat24 read\n * and every request is scoped to (the same derivation polymarket's `signerOf` performs on Polygon).\n * A locked vault maps to `unlock-required`; every other failure collapses to a fixed `unavailable`\n * through `fromSdk` — kernel error messages never reach the host.\n */\nimport { WalletError } from \"@qntx/wallet\";\nimport type { ChainsApi } from \"@qntx/wallet/chains\";\n\nimport type { AppGroup } from \"../spi.ts\";\nimport { Fiat24AppError, fromSdk } from \"./errors.ts\";\n\nconst isEvmAddress = (address: string): address is `0x${string}` =>\n /^0x[0-9a-fA-F]{40}$/.test(address);\n\nexport type Fiat24Owner = (group: AppGroup) => Promise<`0x${string}`>;\n\nexport function createFiat24Owner(account: ChainsApi[\"account\"]): Fiat24Owner {\n return async (group) => {\n let resolved;\n try {\n resolved = await account({\n walletId: group.walletId,\n groupIndex: group.groupIndex,\n template: \"evm.bip44\",\n network: \"eip155:42161\",\n });\n } catch (error) {\n /* A lock landing between the store read and this derivation is the same gate — the\n session close is event-ordered, so a kernel `locked` still maps to unlock-required. */\n if (error instanceof WalletError && error.code === \"locked\") {\n throw new Fiat24AppError(\"unlock-required\", \"the vault is locked\");\n }\n throw fromSdk(error);\n }\n if (!(\"address\" in resolved) || !isEvmAddress(resolved.address)) {\n throw new Fiat24AppError(\"unavailable\", \"the group has no EVM address\");\n }\n return resolved.address;\n };\n}\n","/**\n * The viem `Client` the Fiat24 SDK reads Arbitrum One (`eip155:42161`) through: the engine's\n * primary endpoint corroborated by the independent one, under the same rules the engine's own\n * transaction reads follow.\n *\n * A second upstream decides corroboration per call: `independentClient` `available` → every read\n * runs on both endpoints; `not-needed`/`unavailable` → the primary alone. Rules:\n *\n * - Method allow-list of exactly what the SDK 0.1.0 issues (its `viem/actions` imports); anything\n * else refuses.\n * - `eth_chainId` must answer `0xa4b1` on every queried endpoint.\n * - `eth_blockNumber` returns the LOWER head, so the block the SDK then pins exists on both.\n * - `eth_call`/`eth_getStorageAt`/`eth_getTransactionCount`/`eth_getBlockByNumber` at an explicit hex\n * block, and `eth_getLogs` over a numeric range: both endpoints must agree — normalised results\n * are compared and any disagreement fails (a missing block on one side IS a disagreement). A\n * block read at any other tag refuses (the SDK always pins an explicit block).\n * - `eth_getTransactionCount` at `\"pending\"`/`\"latest\"` returns the HIGHER answer — the engine's\n * nonce rule (`transactions/evm.ts` `prepareSpec`).\n * - `eth_getTransactionReceipt`/`eth_getTransactionByHash`: a null on EITHER endpoint answers null —\n * conservative, so the SDK's reconcile can never turn a one-sided gap into a false `not-sent`\n * (`flows/tx.ts` `byNonce` in the SDK); two non-null answers are compared on the binding\n * projection.\n * - An erroring independent endpoint fails the call (fail closed) — the same rule polymarket's\n * `locate` follows. The primary's error propagates verbatim: it may carry revert data the SDK\n * decodes into `contract-revert`.\n * - No batching and no retries: a corroboration failure must never re-fire the read pair.\n *\n * Every error thrown here is a plain `Error` with a fixed message — the SDK maps them to\n * `rpc-error`; params, results and endpoint details never enter a message.\n */\nimport { createClient, custom } from \"viem\";\nimport type { Client } from \"viem\";\nimport { arbitrum } from \"viem/chains\";\n\nimport type { AppNetworks } from \"../spi.ts\";\n\nconst NETWORK = \"eip155:42161\";\n/** `numberToHex(42161)` — what every endpoint must answer for `eth_chainId`. */\nconst ARBITRUM_ONE = \"0xa4b1\";\n\ntype Call = { readonly method: string; readonly params?: unknown };\n\nconst MISMATCH = \"the rpc endpoints disagree\";\nconst MALFORMED = \"the rpc endpoint returned a malformed result\";\nconst UNPINNED = \"fiat24 rpc reads must pin an explicit block\";\nconst REFUSED = \"fiat24 rpc method not allowed\";\n\nconst isObject = (value: unknown): value is Record<string, unknown> =>\n typeof value === \"object\" && value !== null;\n\n/** Params shaped as an array — `Array.isArray` on `unknown` would narrow to `any[]`. */\nconst isArgs = (value: unknown): value is ReadonlyArray<unknown> => Array.isArray(value);\n\n/** An explicit block quantity — never a named tag. */\nconst isBlock = (value: unknown): value is string =>\n typeof value === \"string\" && /^0x[0-9a-fA-F]+$/.test(value);\n\nconst hexBig = (value: unknown): bigint | undefined => (isBlock(value) ? BigInt(value) : undefined);\n\nconst quantity = (value: unknown): bigint => {\n const parsed = hexBig(value);\n if (parsed === undefined) {\n throw new Error(MALFORMED);\n }\n return parsed;\n};\n\n/** Hex-string fields compare case-insensitively; anything else by identity. */\nconst fieldEq = (a: unknown, b: unknown): boolean =>\n typeof a === \"string\" && typeof b === \"string\" ? a.toLowerCase() === b.toLowerCase() : a === b;\n\nconst sameLog = (a: unknown, b: unknown): boolean => {\n if (!isObject(a) || !isObject(b)) {\n return false;\n }\n const topicsA = a[\"topics\"];\n const topicsB = b[\"topics\"];\n return (\n fieldEq(a[\"address\"], b[\"address\"]) &&\n Array.isArray(topicsA) &&\n Array.isArray(topicsB) &&\n topicsA.length === topicsB.length &&\n topicsA.every((topic, i) => fieldEq(topic, topicsB[i])) &&\n fieldEq(a[\"data\"], b[\"data\"]) &&\n hexBig(a[\"blockNumber\"]) === hexBig(b[\"blockNumber\"]) &&\n fieldEq(a[\"blockHash\"], b[\"blockHash\"]) &&\n fieldEq(a[\"transactionHash\"], b[\"transactionHash\"]) &&\n hexBig(a[\"logIndex\"]) === hexBig(b[\"logIndex\"]) &&\n a[\"removed\"] === b[\"removed\"]\n );\n};\n\nconst sameLogs = (a: unknown, b: unknown): boolean =>\n Array.isArray(a) &&\n Array.isArray(b) &&\n a.length === b.length &&\n a.every((log, i) => sameLog(log, b[i]));\n\nconst RECEIPT_FIELDS = [\n \"transactionHash\",\n \"blockHash\",\n \"blockNumber\",\n \"status\",\n \"from\",\n \"to\",\n] as const;\n\n/** A receipt compares on the binding projection plus its normalised logs. */\nconst sameReceipt = (a: unknown, b: unknown): boolean =>\n isObject(a) &&\n isObject(b) &&\n RECEIPT_FIELDS.every((name) =>\n name === \"blockNumber\" ? hexBig(a[name]) === hexBig(b[name]) : fieldEq(a[name], b[name]),\n ) &&\n sameLogs(a[\"logs\"], b[\"logs\"]);\n\nconst TX_QUANTITY_FIELDS = [\"nonce\", \"value\", \"blockNumber\"] as const;\nconst TX_HEX_FIELDS = [\"hash\", \"from\", \"to\", \"input\", \"blockHash\"] as const;\n\nconst sameTransaction = (a: unknown, b: unknown): boolean =>\n isObject(a) &&\n isObject(b) &&\n TX_QUANTITY_FIELDS.every((name) => hexBig(a[name]) === hexBig(b[name])) &&\n TX_HEX_FIELDS.every((name) => fieldEq(a[name], b[name]));\n\nconst sameBlock = (a: unknown, b: unknown): boolean =>\n isObject(a) &&\n isObject(b) &&\n fieldEq(a[\"hash\"], b[\"hash\"]) &&\n hexBig(a[\"number\"]) === hexBig(b[\"number\"]) &&\n hexBig(a[\"timestamp\"]) === hexBig(b[\"timestamp\"]);\n\nconst SECOND_FAILED: unique symbol = Symbol(\"independent-failed\");\n\n/** `other` is set exactly when a second upstream corroborated the read. */\ntype Answers = {\n readonly result: unknown;\n readonly other: { readonly value: unknown } | undefined;\n};\n\n/**\n * `createFiat24Client` — the cross-checked Arbitrum One client handed to every SDK read. The\n * primary is `networks.client(NETWORK)`; `networks.independentClient(NETWORK)` is resolved per\n * request so a mid-session endpoint change takes effect on the next read.\n */\nexport function createFiat24Client(networks: AppNetworks): Client {\n const primary = networks.client(NETWORK);\n\n /** Both endpoints, or the primary alone; an independent failure fails closed. */\n const both = async (call: Call): Promise<Answers> => {\n const independent = networks.independentClient(NETWORK);\n if (independent.kind !== \"available\") {\n return { result: await primary.transport.request(call), other: undefined };\n }\n /* Both fire together; the primary's failure propagates verbatim (its revert data reaches the\n SDK's decoder) while a corroborator failure fails the whole call closed. */\n const corroborate = async (): Promise<unknown> => {\n try {\n return await independent.client.transport.request(call);\n } catch {\n return SECOND_FAILED;\n }\n };\n const pending = corroborate();\n const result = await primary.transport.request(call);\n const other = await pending;\n if (other === SECOND_FAILED) {\n throw new Error(\"the second rpc endpoint failed\");\n }\n return { result, other: { value: other } };\n };\n\n /** One answer corroborated byte-exact (hex compare is case-insensitive). */\n const equal = async (call: Call): Promise<unknown> => {\n const { result, other } = await both(call);\n if (other !== undefined && !fieldEq(result, other.value)) {\n throw new Error(MISMATCH);\n }\n return result;\n };\n\n const chainId = async (call: Call): Promise<unknown> => {\n const { result, other } = await both(call);\n if (\n !fieldEq(result, ARBITRUM_ONE) ||\n (other !== undefined && !fieldEq(other.value, ARBITRUM_ONE))\n ) {\n throw new Error(\"the rpc endpoint answered a different chain\");\n }\n return result;\n };\n\n const blockNumber = async (call: Call): Promise<unknown> => {\n const { result, other } = await both(call);\n if (other === undefined) {\n return result;\n }\n return quantity(result) <= quantity(other.value) ? result : other.value;\n };\n\n const transactionCount = async (call: Call, tag: unknown): Promise<unknown> => {\n if (tag === \"pending\" || tag === \"latest\") {\n const { result, other } = await both(call);\n if (other === undefined) {\n return result;\n }\n return quantity(result) >= quantity(other.value) ? result : other.value;\n }\n if (!isBlock(tag)) {\n throw new Error(UNPINNED);\n }\n const { result, other } = await both(call);\n if (other !== undefined && hexBig(result) !== hexBig(other.value)) {\n throw new Error(MISMATCH);\n }\n return result;\n };\n\n const logs = async (call: Call): Promise<unknown> => {\n const { result, other } = await both(call);\n if (!Array.isArray(result)) {\n throw new TypeError(MALFORMED);\n }\n if (other !== undefined && !sameLogs(result, other.value)) {\n throw new Error(MISMATCH);\n }\n return result;\n };\n\n /** A block both endpoints must serve identically: one side missing it is a disagreement. */\n const block = async (call: Call): Promise<unknown> => {\n const { result, other } = await both(call);\n if (other === undefined) {\n return result;\n }\n if (result === null || other.value === null || !sameBlock(result, other.value)) {\n throw new Error(MISMATCH);\n }\n return result;\n };\n\n /** A null on either side answers null — never a false absence on the reconcile path. */\n const nullable = async (\n call: Call,\n same: (a: unknown, b: unknown) => boolean,\n ): Promise<unknown> => {\n const { result, other } = await both(call);\n if (other === undefined) {\n return result;\n }\n if (result === null || other.value === null) {\n return null;\n }\n if (!same(result, other.value)) {\n throw new Error(MISMATCH);\n }\n return result;\n };\n\n const request = async ({ method, params }: Call): Promise<unknown> => {\n const call = { method, params };\n const args = isArgs(params) ? params : [];\n switch (method) {\n case \"eth_chainId\":\n return chainId(call);\n case \"eth_blockNumber\":\n return blockNumber(call);\n case \"eth_call\":\n if (!isBlock(args[1])) {\n throw new Error(UNPINNED);\n }\n return equal(call);\n case \"eth_getStorageAt\":\n if (!isBlock(args[2])) {\n throw new Error(UNPINNED);\n }\n return equal(call);\n case \"eth_getTransactionCount\":\n return transactionCount(call, args[1]);\n case \"eth_getBlockByNumber\":\n if (!isBlock(args[0])) {\n throw new Error(UNPINNED);\n }\n return block(call);\n case \"eth_getLogs\": {\n const [filter] = args;\n if (!isObject(filter) || !isBlock(filter[\"fromBlock\"]) || !isBlock(filter[\"toBlock\"])) {\n throw new Error(UNPINNED);\n }\n return logs(call);\n }\n case \"eth_getTransactionReceipt\":\n return nullable(call, sameReceipt);\n case \"eth_getTransactionByHash\":\n return nullable(call, sameTransaction);\n default:\n throw new Error(REFUSED);\n }\n };\n\n /* `ccipRead: false`: a revert during an `eth_call` must reach the SDK's decoder, never\n dereference an OffchainLookup pointer through the ambient fetch. `retryCount: 0` keeps a\n failed corroboration from re-firing the read pair. */\n return createClient({\n chain: arbitrum,\n transport: custom({ request }, { retryCount: 0 }),\n ccipRead: false,\n });\n}\n","/**\n * The SDK's `Fiat24Signer` over the engine's request pipeline. `sendTransaction` opens an app\n * request carrying the SDK's exact `to`/`data`/`value` and pins the SDK-chosen `nonce`: the engine\n * rebuilds the transaction with fresh fees but refuses — `NonceConflictError`, before anything is\n * shown — when the sender's next free nonce differs. A refusal surfaces to the SDK only while it\n * can prove nothing was broadcast: an outcome that ended before the `signed` stage — mapped to a\n * `Fiat24Refusal` — becomes `Fiat24Error(\"signer-rejected\")` (the SDK returns the record to\n * `ready`); a request that reached `signed` gets a plain non-rejection error so the SDK records\n * `unknown` and reconciles by nonce rather than risking a second send. `signSessionGrant` does the\n * same for `evm.fiat24-session`: the grant is validated against the SDK's own `sessionLabel`/\n * `sessionMessage` and the chain decoder's `fiat24SessionMessage` before any request opens. No call\n * data, hashes, grants or signatures ever enter an error message, `opened`/`refused` or the\n * returned values beyond what the SDK contract itself returns.\n */\nimport { bytesToHex, isAddressEqual, isHash } from \"viem\";\nimport type { Address, Hash, Hex } from \"viem\";\n\nimport { sessionLabel, sessionMessage } from \"@qntx/fiat24/api\";\nimport { Fiat24Error } from \"@qntx/fiat24/core\";\nimport type { Fiat24SessionGrant, Fiat24Signer, Fiat24TransactionRequest } from \"@qntx/fiat24/core\";\nimport { arbitrum } from \"@qntx/fiat24/deployments\";\nimport { fiat24SessionMessage } from \"@qntx/wallet-chains/evm\";\n\nimport { NonceConflictError, RequestEndedError } from \"../spi.ts\";\nimport type { AppGroup, AppRequests, SignatureResult } from \"../spi.ts\";\n\nconst NETWORK = \"eip155:42161\";\nconst CHAIN_ID = 42161;\n\n/** Every contract address the SDK's call builders may target on the pinned deployment. */\nconst CALL_TARGETS: ReadonlySet<string> = new Set(\n [\n arbitrum.account.proxy,\n ...Object.values(arbitrum.tokens).map((token) => token.proxy),\n arbitrum.deposit.proxy,\n arbitrum.card.proxy,\n arbitrum.priceList.proxy,\n arbitrum.f24Sales.proxy,\n arbitrum.f24.address,\n arbitrum.usdc,\n ].map((address) => address.toLowerCase()),\n);\n\n/**\n * Why a signer call refused without producing a request or a signature — the app's flow surface\n * reports it to the caller; it never carries request payloads.\n */\nexport type Fiat24Refusal =\n /** The user rejected the request. */\n | \"rejected\"\n /** The request's TTL elapsed before approval. */\n | \"expired\"\n /** The vault locked or the account group changed while the request was open. */\n | \"invalidated\"\n /** The request failed before the `signed` stage — nothing was broadcast. */\n | \"failed-before-signing\"\n /** The sender's next free nonce differs from the nonce the SDK chose. */\n | \"nonce-conflict\"\n /** `prepare` threw for another reason — nothing was shown. */\n | \"prepare-failed\"\n /** The call itself fails validation — no request was opened. */\n | \"invalid-call\";\n\ntype Requests = Pick<AppRequests, \"prepare\" | \"outcome\">;\n\nconst accountRef = (group: AppGroup) => ({\n kind: \"hd\" as const,\n walletId: group.walletId,\n groupIndex: group.groupIndex,\n template: \"evm.bip44\" as const,\n});\n\nconst REFUSED = \"the request was refused\";\nconst PREPARE_FAILED = \"the transaction could not be prepared\";\nconst SESSION_FAILED = \"the session grant could not be prepared\";\n\nconst rejected = (message: string): Fiat24Error => new Fiat24Error(\"signer-rejected\", message);\n\nconst refusalOf = (stage: RequestEndedError[\"stage\"]): Fiat24Refusal =>\n stage === \"failed\" ? \"failed-before-signing\" : stage;\n\nconst isTransactionOutcome = (outcome: unknown): outcome is { readonly hash: string } =>\n typeof outcome === \"object\" &&\n outcome !== null &&\n \"hash\" in outcome &&\n typeof outcome.hash === \"string\" &&\n isHash(outcome.hash);\n\nconst isSessionOutcome = (outcome: unknown): outcome is SignatureResult =>\n typeof outcome === \"object\" &&\n outcome !== null &&\n \"kind\" in outcome &&\n outcome.kind === \"evm.fiat24-session\" &&\n \"signature\" in outcome &&\n outcome.signature instanceof Uint8Array &&\n outcome.signature.length === 65;\n\nexport const createFiat24Signer = (options: {\n readonly requests: Requests;\n readonly group: AppGroup;\n /** The group's `evm.bip44` address on Arbitrum One — the only `from` the signer accepts. */\n readonly owner: Address;\n /** The Fiat24 account this signer may grant sessions for; grants are refused without it. */\n readonly tokenId?: bigint;\n /** A request opened for this signer — the app records it for display. */\n readonly opened: (requestId: string) => void;\n /** The signer refused before producing a result — the app records the reason. */\n readonly refused: (reason: Fiat24Refusal) => void;\n}): Fiat24Signer => {\n const { requests, group, owner, opened, refused } = options;\n\n const invalid = (message: string): never => {\n refused(\"invalid-call\");\n throw rejected(message);\n };\n\n const sendTransaction = async (request: Fiat24TransactionRequest): Promise<Hash> => {\n if (request.chainId !== CHAIN_ID) {\n invalid(\"the call is for another chain\");\n }\n if (!isAddressEqual(request.from, owner)) {\n invalid(\"the call is not from this account\");\n }\n if (!CALL_TARGETS.has(request.to.toLowerCase())) {\n invalid(\"the call targets an unknown contract\");\n }\n if (!Number.isSafeInteger(request.nonce) || request.nonce < 0) {\n invalid(\"the call carries an invalid nonce\");\n }\n const account = accountRef(group);\n let pending: Awaited<ReturnType<Requests[\"prepare\"]>>;\n try {\n pending = await requests.prepare({\n method: \"evm-sign\",\n account,\n network: NETWORK,\n request: {\n kind: \"evm.transaction\",\n network: NETWORK,\n account,\n /* The pipeline rebuilds nonce and fees; the skeleton only carries `to`/`data`/`value`\n (plus a zero gas floor) — `nonce` pins the nonce the build must land on. */\n tx: {\n type: \"eip1559\",\n chainId: CHAIN_ID,\n nonce: 0,\n gas: \"0x0\",\n to: request.to,\n value: `0x${request.value.toString(16)}`,\n data: request.data,\n accessList: [],\n maxFeePerGas: \"0x0\",\n maxPriorityFeePerGas: \"0x0\",\n },\n },\n nonce: request.nonce,\n });\n } catch (error) {\n refused(error instanceof NonceConflictError ? \"nonce-conflict\" : \"prepare-failed\");\n throw rejected(PREPARE_FAILED);\n }\n opened(pending.id);\n let outcome: unknown;\n try {\n outcome = await requests.outcome(pending.id);\n } catch (error) {\n if (error instanceof RequestEndedError) {\n if (!error.signed) {\n refused(refusalOf(error.stage));\n throw rejected(REFUSED);\n }\n /* Past `signed` the signature may already be broadcast — a non-rejection error so the\n SDK records `unknown` and reconciles by nonce instead of sending again. */\n throw new Error(\"the request was signed but its outcome is unknown\", { cause: error });\n }\n throw error;\n }\n if (isTransactionOutcome(outcome)) {\n const hash = outcome.hash.toLowerCase();\n if (isHash(hash)) {\n return hash;\n }\n }\n throw new Error(\"the request ended without a transaction hash\");\n };\n\n const signSessionGrant = async (grant: Fiat24SessionGrant): Promise<Hex> => {\n const tokenId = options.tokenId ?? invalid(\"the session grant does not match this account\");\n const sessionArgs = { chainId: CHAIN_ID as 42161, tokenId, deadline: grant.deadline };\n if (\n grant.chainId !== CHAIN_ID ||\n grant.tokenId !== tokenId ||\n grant.deadline < 1n ||\n grant.deadline > BigInt(Number.MAX_SAFE_INTEGER) ||\n grant.hash !== sessionLabel(sessionArgs) ||\n grant.message !== sessionMessage(sessionArgs) ||\n grant.message !== fiat24SessionMessage(CHAIN_ID, tokenId.toString(10), Number(grant.deadline))\n ) {\n invalid(\"the session grant does not match this account\");\n }\n const account = accountRef(group);\n let pending: Awaited<ReturnType<Requests[\"prepare\"]>>;\n try {\n pending = await requests.prepare({\n method: \"evm-sign\",\n account,\n network: NETWORK,\n request: {\n kind: \"evm.fiat24-session\",\n network: NETWORK,\n account,\n tokenId: tokenId.toString(10),\n deadline: Number(grant.deadline),\n },\n });\n } catch {\n refused(\"prepare-failed\");\n throw rejected(SESSION_FAILED);\n }\n opened(pending.id);\n let outcome: unknown;\n try {\n outcome = await requests.outcome(pending.id);\n } catch (error) {\n if (error instanceof RequestEndedError) {\n refused(refusalOf(error.stage));\n throw rejected(REFUSED);\n }\n throw error;\n }\n if (isSessionOutcome(outcome)) {\n return bytesToHex(outcome.signature);\n }\n throw new Error(\"the request ended without a signature\");\n };\n\n return { address: owner, sendTransaction, signSessionGrant };\n};\n","/**\n * Per-group Fiat24 API sessions and the request bookkeeping every signer of the group shares. A\n * session is a lazy in-memory `Fiat24Session` — the SDK grants on the first secured call and a\n * grant is a bearer credential, so sessions live only here and `end`/`endAll` are the lock, disable\n * and wallet-removal paths' whole cleanup. The `opened` sets record every request id the group's\n * signers opened so `disable` can reject whatever is still awaiting approval. No grant, label or\n * signature is ever stored, logged or put in an error.\n */\nimport type {\n Card,\n Fiat24Api,\n Fiat24Session,\n Profile,\n TransactionPage,\n TransactionQuery,\n} from \"@qntx/fiat24/api\";\n\nimport type { AppGroup, AppRequests } from \"../spi.ts\";\nimport { Fiat24AppError } from \"./errors.ts\";\nimport type { Fiat24Owner } from \"./owner.ts\";\nimport { createFiat24Signer } from \"./signer.ts\";\nimport type { Fiat24Refusal } from \"./signer.ts\";\n\n/** The read-only slice of `Fiat24Session` the app surfaces — writes stay inside flows. */\nexport type Fiat24SecuredReads = {\n readonly profile: () => Promise<Profile>;\n readonly cards: () => Promise<ReadonlyArray<Card>>;\n /** The 5-minute Marqeta display token for the host's card widget. */\n readonly cardDisplayToken: (externalId: string) => Promise<string>;\n readonly transactions: (query: TransactionQuery) => Promise<TransactionPage>;\n /** Ends the grant — the next secured call of this group opens a fresh session. */\n readonly end: () => void;\n};\n\nconst groupKey = (group: AppGroup): string => `${group.walletId}/${group.groupIndex}`;\n\nexport function createFiat24Sessions(options: {\n readonly requests: Pick<AppRequests, \"prepare\" | \"outcome\">;\n readonly owner: Fiat24Owner;\n readonly api: Fiat24Api | undefined;\n}): {\n /** The group's session for `tokenId`, opened lazily — `undefined` without an api client. */\n readonly sdk: (group: AppGroup, tokenId: bigint) => Promise<Fiat24Session | undefined>;\n /** The read-only secured surface — `undefined` without an api client. */\n readonly reads: (group: AppGroup, tokenId: bigint) => Fiat24SecuredReads | undefined;\n /** A fresh signer for `group` — its opened ids land in the group's bookkeeping. */\n readonly signer: (args: {\n group: AppGroup;\n owner: `0x${string}`;\n tokenId?: bigint;\n opened?: (id: string) => void;\n refused?: (reason: Fiat24Refusal) => void;\n }) => ReturnType<typeof createFiat24Signer>;\n /** Every request id the group's signers reported open — for the disable reject pass. */\n readonly openedIds: (group: AppGroup) => ReadonlySet<string>;\n /** Every group the sessions module has seen — the wallet-removal sweep's candidates. */\n readonly tracked: () => ReadonlyArray<AppGroup>;\n /** Ends the group's session. */\n readonly end: (group: AppGroup) => void;\n /** Ends every session — the vault lock path. */\n readonly endAll: () => void;\n} {\n const sessions = new Map<string, Fiat24Session>();\n const opened = new Map<string, Set<string>>();\n const known = new Map<string, AppGroup>();\n\n const openedIdsOf = (group: AppGroup): Set<string> => {\n const key = groupKey(group);\n known.set(key, group);\n let ids = opened.get(key);\n if (ids === undefined) {\n ids = new Set();\n opened.set(key, ids);\n }\n return ids;\n };\n\n const sdk = async (group: AppGroup, tokenId: bigint): Promise<Fiat24Session | undefined> => {\n if (options.api === undefined) {\n return undefined;\n }\n const key = groupKey(group);\n known.set(key, group);\n let session = sessions.get(key);\n if (session === undefined) {\n const owner = await options.owner(group);\n session = options.api.openSession({\n tokenId,\n signer: {\n address: owner,\n signSessionGrant: signer({ group, owner, tokenId }).signSessionGrant,\n },\n });\n sessions.set(key, session);\n }\n return session;\n };\n\n const signer = ({\n group,\n owner,\n tokenId,\n opened: onOpened,\n refused,\n }: {\n group: AppGroup;\n owner: `0x${string}`;\n tokenId?: bigint;\n opened?: (id: string) => void;\n refused?: (reason: Fiat24Refusal) => void;\n }) => {\n known.set(groupKey(group), group);\n const ids = openedIdsOf(group);\n return createFiat24Signer({\n requests: {\n prepare: options.requests.prepare,\n outcome: async (id) => {\n try {\n return await options.requests.outcome(id);\n } finally {\n /* A settled request is no longer open — disable/removal must not reject it. */\n ids.delete(id);\n }\n },\n },\n group,\n owner,\n ...(tokenId === undefined ? {} : { tokenId }),\n opened: (id) => {\n ids.add(id);\n onOpened?.(id);\n },\n refused: (reason) => refused?.(reason),\n });\n };\n\n return {\n sdk,\n reads: (group, tokenId) => {\n if (options.api === undefined) {\n return undefined;\n }\n const read = async <T>(body: (session: Fiat24Session) => Promise<T>): Promise<T> => {\n const session = await sdk(group, tokenId);\n if (session === undefined) {\n throw new Fiat24AppError(\"api-unavailable\", \"the fiat24 api is not configured\");\n }\n return body(session);\n };\n return {\n profile: async () => read(async (session) => session.profile()),\n cards: async () => read(async (session) => session.cards()),\n cardDisplayToken: async (externalId) =>\n read(async (session) => session.cardDisplayToken(externalId)),\n transactions: async (query) => read(async (session) => session.transactions(query)),\n end: () => {\n sessions.get(groupKey(group))?.end();\n sessions.delete(groupKey(group));\n },\n };\n },\n signer,\n openedIds: (group) => openedIdsOf(group),\n tracked: () => [...known.values()],\n end: (group) => {\n const key = groupKey(group);\n sessions.get(key)?.end();\n sessions.delete(key);\n },\n endAll: () => {\n for (const session of sessions.values()) {\n session.end();\n }\n sessions.clear();\n },\n };\n}\n","/**\n * The Fiat24 app definition: `fiat24()` returns the `AppDefinition` `createApps` builds over the\n * shared `AppContext` — the account read over the cross-checked Arbitrum One client, the visible-\n * and-unlocked live view, the enablement record machine, the resumable flows, the secured-read\n * sessions and the public REST reads. `enableWhen` allows `close-only`: a restricted jurisdiction\n * may still need the read surface to wind positions down. The REST api at api.fiat24.com has no\n * CORS and is reachable only through the host-injected `config.fetch` — `context.fetch` is never a\n * fallback. A wallet removal drops its groups' sessions, drafts and open requests; the group's\n * persisted flow records are pruned by the generic store cleanup with everything else.\n */\nimport { createFiat24Api } from \"@qntx/fiat24/api\";\nimport type {\n Fiat24Api,\n Bank,\n Banks,\n Countries,\n CountryCities,\n PaymentPurpose,\n Rate,\n RatePair,\n} from \"@qntx/fiat24/api\";\nimport { kycUrl } from \"@qntx/fiat24/flows\";\n\nimport type { AppContext, AppDefinition, AppGroup } from \"../spi.ts\";\nimport { createFiat24Account } from \"./account.ts\";\nimport type { Fiat24AccountState } from \"./account.ts\";\nimport { createFiat24Enable } from \"./enable.ts\";\nimport { Fiat24AppError, fromSdk } from \"./errors.ts\";\nimport { createFiat24Flows } from \"./flows.ts\";\nimport type { Fiat24Flows } from \"./flows.ts\";\nimport { createFiat24Live } from \"./live.ts\";\nimport type { Fiat24LiveView } from \"./live.ts\";\nimport { createFiat24Owner } from \"./owner.ts\";\nimport { createFiat24Client } from \"./rpc.ts\";\nimport { createFiat24Sessions } from \"./sessions.ts\";\nimport type { Fiat24SecuredReads } from \"./sessions.ts\";\n\n/** The host's config — `fetch` is for api.fiat24.com only; nothing else may use it. */\nexport type Fiat24Config = {\n readonly fetch?: typeof globalThis.fetch;\n};\n\n/** The unauthenticated Fiat24 REST reads — every one needs the injected fetch. */\nexport type Fiat24PublicReads = {\n readonly rates: () => Promise<Readonly<Partial<Record<RatePair, Rate>>>>;\n readonly paymentPurposes: () => Promise<ReadonlyArray<PaymentPurpose>>;\n readonly countries: () => Promise<Countries>;\n readonly countryCities: () => Promise<CountryCities>;\n readonly banks: () => Promise<Banks>;\n readonly bankByIban: (iban: string) => Promise<Bank>;\n /** The host's Sumsub KYC link — a pure URL build, no fetch needed. */\n readonly kycUrl: (walletProviderId?: bigint) => string;\n};\n\n/** The Fiat24 surface `createApps` returns under `fiat24`. */\nexport type Fiat24App = {\n /** The group's Fiat24 account — the SDK view over the pinned, corroborated deployment. */\n readonly account: (group: AppGroup) => Promise<Fiat24AccountState>;\n /** A 15 s account view — polls only while `setVisible(true)` and the vault is unlocked. */\n readonly live: (group: AppGroup) => Fiat24LiveView;\n /** The host's visibility signal — account and reconcile polling run only while visible. */\n readonly setVisible: (visible: boolean) => void;\n /** The resumable flows — state persisted per group, one advance at a time. */\n readonly flows: Fiat24Flows;\n /** The group's secured REST reads — the session grant is minted on first call. */\n readonly session: (group: AppGroup) => Fiat24SecuredReads;\n /** The unauthenticated REST reads. */\n readonly api: Fiat24PublicReads;\n};\n\nexport function fiat24(config: Fiat24Config = {}): AppDefinition<\"fiat24\", Fiat24App> {\n if (config.fetch !== undefined && typeof config.fetch !== \"function\") {\n throw new Error(\"the fiat24 api fetch must be a function\");\n }\n return {\n id: \"fiat24\",\n /* `close-only` enables too — a restricted jurisdiction still reads and winds down. */\n enableWhen: [\"available\", \"close-only\"],\n create: (context: AppContext) => {\n const owner = createFiat24Owner(context.account);\n const client = createFiat24Client(context.networks);\n const account = createFiat24Account({ owner, client });\n const live = createFiat24Live({\n account,\n wallet: context.wallet,\n setTimer: context.setTimer,\n now: context.now,\n });\n const api =\n config.fetch === undefined\n ? undefined\n : createFiat24Api({ fetch: config.fetch, now: context.now });\n const sessions = createFiat24Sessions({ requests: context.requests, owner, api });\n const flows = createFiat24Flows({\n wallet: context.wallet,\n requests: context.requests,\n storage: context.storage,\n random: context.random,\n setTimer: context.setTimer,\n logger: context.logger,\n availability: context.availability,\n groupState: context.groupState,\n client,\n owner,\n account,\n api,\n sessions,\n });\n const requireApi = (): Fiat24Api => {\n if (api === undefined) {\n throw new Fiat24AppError(\n \"api-unavailable\",\n \"no api.fiat24.com fetch was injected — the Fiat24 REST api is off\",\n );\n }\n return api;\n };\n /** Api.fiat24.com answers are untrusted — the SDK validates and we normalize its errors. */\n const call = async <T>(body: (api: Fiat24Api) => Promise<T>): Promise<T> => {\n try {\n return await body(requireApi());\n } catch (error) {\n throw fromSdk(error);\n }\n };\n const publicReads: Fiat24PublicReads = {\n rates: async () => call(async (a) => a.rates()),\n paymentPurposes: async () => call(async (a) => a.paymentPurposes()),\n countries: async () => call(async (a) => a.countries()),\n countryCities: async () => call(async (a) => a.countryCities()),\n banks: async () => call(async (a) => a.banks()),\n bankByIban: async (iban) => call(async (a) => a.bankByIban(iban)),\n kycUrl: (walletProviderId) => kycUrl(walletProviderId),\n };\n\n /** The group's tokenId once it has an owned live account — the session's identity. */\n const session = (group: AppGroup): Fiat24SecuredReads => {\n const gated = async (): Promise<Fiat24SecuredReads> => {\n if (context.wallet.getSnapshot().vault !== \"unlocked\") {\n throw new Fiat24AppError(\"unlock-required\", \"unlock the vault to use the Fiat24 app\");\n }\n if (context.groupState(group)?.status !== \"enabled\") {\n throw new Fiat24AppError(\"not-enabled\", \"enable the Fiat24 app for this group first\");\n }\n requireApi();\n const state = await account(group);\n if (state.status !== \"live\" || !state.view.account.ownsToken) {\n throw new Fiat24AppError(\"no-account\", \"the group owns no live Fiat24 account\");\n }\n const reads = sessions.reads(group, state.view.account.tokenId);\n if (reads === undefined) {\n throw new Fiat24AppError(\n \"api-unavailable\",\n \"no api.fiat24.com fetch was injected — the Fiat24 REST api is off\",\n );\n }\n return reads;\n };\n /** Secured answers are untrusted too — every error normalizes through `fromSdk`. */\n const secured = async <T>(body: (reads: Fiat24SecuredReads) => Promise<T>): Promise<T> => {\n try {\n return await body(await gated());\n } catch (error) {\n throw fromSdk(error);\n }\n };\n return {\n profile: async () => secured(async (reads) => reads.profile()),\n cards: async () => secured(async (reads) => reads.cards()),\n cardDisplayToken: async (externalId) =>\n secured(async (reads) => reads.cardDisplayToken(externalId)),\n transactions: async (query) => secured(async (reads) => reads.transactions(query)),\n end: () => sessions.end(group),\n };\n };\n\n /* A removed wallet's groups must not keep bearer sessions, PII drafts or open requests. */\n const unsubscribe = context.wallet.subscribe(() => {\n const wallets = new Set(\n context.wallet.getSnapshot().wallets.map((wallet) => wallet.walletId),\n );\n flows.dropMissing(wallets);\n });\n\n const appApi: Fiat24App = {\n account,\n live: live.view,\n setVisible: (visible) => {\n live.setVisible(visible);\n flows.setVisible(visible);\n },\n flows: flows.flows,\n session,\n api: publicReads,\n };\n return {\n api: appApi,\n provider: createFiat24Enable({\n storage: context.storage,\n onDisable: flows.dropGroup,\n onEnabled: (group) => void flows.reconcileGroup(group),\n owner,\n client,\n account,\n }),\n unlock: async () => {\n await live.unlock();\n flows.unlock();\n },\n lock: () => {\n live.lock();\n flows.lock();\n },\n close: () => {\n unsubscribe();\n live.close();\n flows.close();\n },\n };\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAsCA,IAAa,iBAAb,cAAoC,MAAM;CACxC;;CAEA;CAEA,YACE,UACA,SACA,SACA;EACA,MAAM,OAAO;EACb,KAAK,OAAO;EACZ,KAAK,WAAW;EAChB,IAAI,SAAS,SAAS,KAAA,GACpB,KAAK,OAAO,QAAQ;CAExB;AACF;;;;;;;AAQA,MAAa,WAAW,UAAmC;CACzD,IAAI,iBAAiB,gBACnB,OAAO;CAET,IAAI,cAAc,KAAK,GACrB,OAAO,IAAI,eAAe,YAAY,MAAM,SAAS,EAAE,MAAM,MAAM,KAAK,CAAC;CAE3E,OAAO,IAAI,eAAe,eAAe,8BAA8B;AACzE;;;;;;;;;ACrCA,SAAgB,oBAAoB,SAGd;CACpB,OAAO,OAAO,UAAU;EACtB,IAAI;EACJ,IAAI;GACF,QAAQ,MAAM,QAAQ,MAAM,KAAK;EACnC,SAAS,OAAO;GACd,MAAM,QAAQ,KAAK;EACrB;EACA,IAAI;EACJ,IAAI;GACF,OAAO,MAAM,YAAY,EAAE,QAAQ,QAAQ,OAAO,GAAG,EAAE,MAAM,CAAC;EAChE,SAAS,OAAO;GACd,IAAI,cAAc,KAAK,KAAK,MAAM,SAAS,oBACzC,OAAO;IAAE,QAAQ;IAAoB;GAAM;GAE7C,MAAM,QAAQ,KAAK;EACrB;EACA,OAAO,KAAK,SAAS,eACjB;GAAE,QAAQ;GAAc;EAAM,IAC9B;GAAE,QAAQ,KAAK;GAAM;GAAO;EAAK;CACvC;AACF;;;ACpCA,MAAM,SAAS;;AA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