@asseteragmbh/wallet-connector 0.2.3 → 0.2.5

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.
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/protocol.ts","../src/provider.ts","../src/popup.ts","../src/onboarding.ts","../src/manage.ts"],"names":["request","copyAccountNames","accounts","active","POPUP_NAME","CLOSE_POLL_MS"],"mappings":";;;AAqEO,IAAM,gBAAA,GAAmB;AAGzB,IAAM,YAAA,GAAe;AAGrB,IAAM,YAAA,GAAe;AAGrB,IAAM,WAAA,GAAc;AAGpB,IAAM,aAAA,GAAgB,CAAC,sBAAsB;AAM7C,SAAS,aAAa,KAAA,EAAqC;AAChE,EAAA,OAAQ,aAAA,CAAqC,SAAS,KAAK,CAAA;AAC7D;AAGO,IAAM,cAAA,GAAiB;AAMvB,IAAM,iBAAA,GAAoB;AAAA,EAC/B,qBAAA;AAAA,EACA,cAAA;AAAA,EACA,aAAA;AAAA,EACA,4BAAA;AAAA,EACA,eAAA;AAAA,EACA,sBAAA;AAAA,EACA;AACF;AAIO,SAAS,kBAAkB,MAAA,EAA2C;AAC3E,EAAA,OAAQ,iBAAA,CAAwC,SAAS,MAAM,CAAA;AACjE;AAGO,IAAM,YAAA,GAAe;AAAA;AAAA,EAE1B,YAAA,EAAc,IAAA;AAAA;AAAA,EAEd,YAAA,EAAc,IAAA;AAAA;AAAA,EAEd,iBAAA,EAAmB,IAAA;AAAA;AAAA,EAEnB,YAAA,EAAc,IAAA;AAAA;AAAA,EAEd,iBAAA,EAAmB,IAAA;AAAA;AAAA,EAEnB,aAAA,EAAe,MAAA;AAAA;AAAA,EAEf,QAAA,EAAU;AACZ;AAqJA,SAAS,SAAS,KAAA,EAAkD;AAClE,EAAA,OAAO,OAAO,KAAA,KAAU,QAAA,IAAY,KAAA,KAAU,IAAA;AAChD;AAEA,SAAS,OAAA,CAAQ,OAAgB,MAAA,EAAkD;AACjF,EAAA,OAAO,QAAA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I,CAAA,EAAG;AAC3B,MAAA,MAAM,MAAA,GAA+B;AAAA,QACnC,UAAA,EAAY,KAAK,IAAA,CAAK,UAAA;AAAA,QACtB,QAAA,EAAU,KAAK,IAAA,CAAK,QAAA;AAAA,QACpB,iBAAA,EAAmB,KAAK,IAAA,CAAK;AAAA,OAC/B;AACA,MAAA,YAAA,GAAe,MAAA;AACf,MAAA,OAAA,CAAQ,aAAa,MAAM,CAAA;AAC3B,MAAA;AAAA,IACF;AACA,IAAA,IAAI,iBAAA,CAAkB,IAAI,CAAA,EAAG;AAC3B,MAAA,YAAA,GAAeA,iBAAAA,CAAiB,KAAK,IAAI,CAAA;AACzC,MAAA,OAAA,CAAQ,UAAA,GAAaA,iBAAAA,CAAiB,YAAY,CAAC,CAAA;AAAA,IACrD;AAAA,EACF;AAEA,EAAA,YAAA,CAAa,gBAAA,CAAiB,WAAW,SAAS,CAAA;AAClD,EAAA,UAAA,GAAa,YAAY,MAAM;AAC7B,IAAA,IAAI,WAAA,CAAY,QAAQ,OAAA,EAAQ;AAAA,EAClC,GAAGI,cAAa,CAAA;AAEhB,EAAA,OAAO;AAAA,IACL,KAAA;AAAA,IACA,MAAA;AAAA,IACA,cAAc,MAAM,YAAA;AAAA,IACpB,cAAc,MAAO,YAAA,KAAiB,MAAA,GAAY,MAAA,GAAYJ,kBAAiB,YAAY;AAAA,GAC7F;AACF","file":"index.cjs","sourcesContent":["/**\n * The pop-up protocol between a partner page (the opener) and the Assetera Wallet (the pop-up) — ADR-0054 D3/D4.\n *\n * This file is the CONTRACT. The connector in this package speaks the opener side; AsseteraWalletFront's\n * `/connect` page speaks the pop-up side and imports these types from `@asseteragmbh/wallet-connector/protocol`.\n * Change it only in a backwards-compatible way, or bump `PROTOCOL_VERSION` and support both on the wallet side:\n * partner sites upgrade on their own schedule.\n *\n * ## The handshake\n *\n * 1. The partner opens `${walletUrl}${CONNECT_PATH}?origin=<partner origin>&v=<version>` from a user click.\n * 2. The pop-up checks the claimed origin against its allowlist (D4). If listed, it posts `ready` to\n * `window.opener` with `targetOrigin` = that origin. The browser delivers it ONLY if the opener really is\n * that origin, so a page cannot claim someone else's origin and still hear the answer.\n * 3. The opener waits for `ready` from the wallet origin, then sends `request`s with `targetOrigin` = the wallet\n * origin. The pop-up accepts a message only when `event.origin` is the allowed origin from step 2 AND\n * `event.source === window.opener`, and answers with `targetOrigin` = that origin. Nothing else is accepted.\n *\n * ## Sign-in hint\n *\n * A partner may tell the wallet how the client signed in at the partner, through the optional `signIn` URL\n * parameter (`SIGN_IN_HINTS`). The hint only names an identity provider: the wallet checks it against its own\n * list, may ignore it and then falls back to its own login page. The hint never carries a token, an identity or\n * any other credential.\n *\n * ## Lifetime\n *\n * The pop-up is not guaranteed to stay open. The wallet site may close the `/connect` pop-up after it connected\n * or answered a request. The provider keeps the last `accounts` and `chainId` it saw, so the partner page still\n * looks connected after the pop-up closes, and it opens the pop-up again on the next request from a user click.\n * (ADR-0054, \"the wallet tab must stay open\", no longer holds.)\n *\n * ## Onboarding\n *\n * Onboarding is a second flow on the same wallet origin, for a partner that wants the client to get an Assetera\n * Wallet (a new one, or the one the client already has). The partner opens\n * `${walletUrl}${ONBOARD_PATH}?origin=<partner origin>&v=<version>&chain=<CAIP-2 chain id>[&add=1]` from a user\n * click. The pop-up checks the claimed origin against its partner list, signs the client in through SSO, runs the\n * wizard (accept the wallet terms, create the wallet) and then posts `onboarded` (or `onboard-cancelled`) to\n * `window.opener` with `targetOrigin` = the partner origin. `add=1` asks for one more wallet even when the client\n * already has one.\n *\n * After `onboarded` the pop-up STAYS OPEN and answers `request` messages for `personal_sign` by the onboarded\n * address (plus `eth_accounts` and `eth_chainId`), with the same `response` messages as `/connect`. That is how\n * the partner gets the ownership signature it needs to register the wallet with its own compliance service: the\n * wallet itself never calls a regulated service (ADR-0059 D3), and a second `window.open` after an asynchronous\n * step would be blocked by the browser. The partner closes the pop-up when it is done.\n *\n * The opener accepts messages only when `event.origin` is the wallet origin AND `event.source` is the pop-up\n * it opened. The wizard never returns a private key or a token, only the wallet address and signatures the\n * client approved.\n *\n * ## Manage\n *\n * The partner can open `${walletUrl}${MANAGE_PATH}?origin=<partner origin>&v=<version>[&lang=<locale>][&signIn=<hint>]`\n * from a user click, so the client can see and change the wallet accounts and the wallet security (passkeys,\n * authenticator app, recovery codes). The pop-up checks the claimed origin against its partner list, posts\n * `ready` to `window.opener` (the same message as `/connect`) and then posts `security` messages. It never\n * answers `request` messages.\n *\n * ## Account names\n *\n * While a pop-up is open it may also post `accounts` messages. Each entry names one account the client has\n * already shared with THIS partner, so the partner can show a name next to the address. The wallet never sends\n * an account the partner does not already know. A manage pop-up may send the message, and an onboarding pop-up\n * may send it after it reported the address. The message is only sent while a pop-up is open, never on request\n * of the partner. It carries no token and no other data.\n */\n\nexport const PROTOCOL_VERSION = 1 as const;\n\n/** The pop-up route on the wallet origin. */\nexport const CONNECT_PATH = \"/connect\";\n\n/** The onboarding wizard route on the wallet origin. */\nexport const ONBOARD_PATH = \"/onboard\";\n\n/** The manage wallet route on the wallet origin. */\nexport const MANAGE_PATH = \"/manage\";\n\n/** The identity providers a partner can name in the `signIn` hint. */\nexport const SIGN_IN_HINTS = [\"assetera-marketplace\"] as const;\n\n/** A named identity provider the wallet may use for a silent sign-in. */\nexport type SignInHint = (typeof SIGN_IN_HINTS)[number];\n\n/** True when `value` is one of {@link SIGN_IN_HINTS}. */\nexport function isSignInHint(value: unknown): value is SignInHint {\n return (SIGN_IN_HINTS as readonly unknown[]).includes(value);\n}\n\n/** Every message carries this prefix in `type`, so both sides can ignore unrelated `postMessage` traffic. */\nexport const MESSAGE_PREFIX = \"assetera-wallet:\" as const;\n\n/**\n * The EIP-1193 methods the pop-up answers (ADR-0054 D3). Anything else is refused with 4200. Read-only chain\n * calls (`eth_call`, `eth_getBalance`, …) do not go through the pop-up; wagmi sends them to its own transports.\n */\nexport const SUPPORTED_METHODS = [\n \"eth_requestAccounts\",\n \"eth_accounts\",\n \"eth_chainId\",\n \"wallet_switchEthereumChain\",\n \"personal_sign\",\n \"eth_signTypedData_v4\",\n \"eth_sendTransaction\",\n] as const;\n\nexport type SupportedMethod = (typeof SUPPORTED_METHODS)[number];\n\nexport function isSupportedMethod(method: string): method is SupportedMethod {\n return (SUPPORTED_METHODS as readonly string[]).includes(method);\n}\n\n/** EIP-1193 / EIP-1474 error codes the pop-up uses. */\nexport const RpcErrorCode = {\n /** The client rejected the request in the pop-up. */\n UserRejected: 4001,\n /** Not connected yet (no `eth_requestAccounts` approved in this pop-up). */\n Unauthorized: 4100,\n /** The method is not in SUPPORTED_METHODS. */\n UnsupportedMethod: 4200,\n /** The pop-up closed, or the wallet session ended. */\n Disconnected: 4900,\n /** `wallet_switchEthereumChain` to a chain the wallet does not offer. */\n UnrecognizedChain: 4902,\n /** Malformed params. */\n InvalidParams: -32602,\n /** Anything unexpected inside the wallet. */\n Internal: -32603,\n} as const;\n\nexport type RpcErrorCode = (typeof RpcErrorCode)[keyof typeof RpcErrorCode];\n\nexport interface RpcError {\n code: number;\n message: string;\n data?: unknown;\n}\n\n// --- pop-up → opener ---------------------------------------------------------------------------------\n\n/** The pop-up is loaded and accepts requests from this opener. */\nexport interface ReadyMessage {\n type: `${typeof MESSAGE_PREFIX}ready`;\n v: typeof PROTOCOL_VERSION;\n /** Shown to the partner for diagnostics only; the partner must not rely on it for anything. */\n walletVersion?: string;\n}\n\n/** The answer to one `request`, matched by `id`. Exactly one of `result` / `error`. */\nexport type ResponseMessage =\n | { type: `${typeof MESSAGE_PREFIX}response`; v: typeof PROTOCOL_VERSION; id: string; result: unknown }\n | { type: `${typeof MESSAGE_PREFIX}response`; v: typeof PROTOCOL_VERSION; id: string; error: RpcError };\n\n/** EIP-1193 provider events, forwarded to the partner. */\nexport type EventMessage =\n | {\n type: `${typeof MESSAGE_PREFIX}event`;\n v: typeof PROTOCOL_VERSION;\n event: \"accountsChanged\";\n data: `0x${string}`[];\n }\n | {\n type: `${typeof MESSAGE_PREFIX}event`;\n v: typeof PROTOCOL_VERSION;\n event: \"chainChanged\";\n data: `0x${string}`;\n }\n | {\n type: `${typeof MESSAGE_PREFIX}event`;\n v: typeof PROTOCOL_VERSION;\n event: \"disconnect\";\n data: RpcError;\n };\n\n/**\n * How well the client's Assetera Wallet is protected. The values are the ones the wallet site shows:\n *\n * - `add-factor`: there is no passkey and no authenticator app yet.\n * - `save-codes`: recovery codes exist, but the client has not confirmed saving them.\n * - `create-codes`: a factor exists, but there are no recovery codes.\n * - `protected`: a factor exists and the recovery codes are saved.\n * - `unknown`: the wallet could not read the state.\n */\nexport type WalletProtection = \"unknown\" | \"add-factor\" | \"save-codes\" | \"create-codes\" | \"protected\";\n\n/** The wallet security status sent by a manage (or connect) pop-up. */\nexport interface WalletSecurityStatus {\n /** Overall result, the same values the wallet site shows. */\n protection: WalletProtection;\n /** Passkeys registered for signing (Dynamic step-up), not sign-in factors. */\n passkeys: number;\n /** Authenticator apps (TOTP) registered for signing (Dynamic step-up). */\n authenticatorApps: number;\n}\n\n/**\n * The wallet reports the security status while a pop-up is open. The partner cannot ask for it. It never\n * carries a token, an identity or a credential.\n */\nexport interface SecurityMessage {\n type: `${typeof MESSAGE_PREFIX}security`;\n v: typeof PROTOCOL_VERSION;\n data: WalletSecurityStatus;\n}\n\n/** One account of the Assetera Wallet that the client already shared with this partner, with its name. */\nexport interface WalletAccountName {\n address: `0x${string}`;\n name: string;\n}\n\n/**\n * The wallet reports the names of the accounts the client already shared with this partner. The partner cannot\n * ask for it and the wallet never names an account the partner does not already know. It never carries a token\n * or any other data.\n */\nexport interface AccountsMessage {\n type: `${typeof MESSAGE_PREFIX}accounts`;\n v: typeof PROTOCOL_VERSION;\n data: WalletAccountName[];\n}\n\n/**\n * The onboarding wizard finished: the client accepted the wallet terms and has an Assetera Wallet on `chain`.\n * `created` is `true` when the wallet was created in this run, `false` when the wizard returned the client's\n * existing wallet. The wallet is not registered with any compliance service; that is the partner's step.\n */\nexport interface OnboardedMessage {\n type: `${typeof MESSAGE_PREFIX}onboarded`;\n v: typeof PROTOCOL_VERSION;\n address: `0x${string}`;\n chain: string;\n created: boolean;\n /**\n * @deprecated Sent by wallet versions that registered the wallet themselves (before ADR-0059). Ignored.\n */\n status?: \"approved\" | \"pending\";\n}\n\n/** The onboarding wizard did not produce a wallet. `message` is optional diagnostics for the partner. */\nexport interface OnboardCancelledMessage {\n type: `${typeof MESSAGE_PREFIX}onboard-cancelled`;\n v: typeof PROTOCOL_VERSION;\n reason: \"user\" | \"refused\" | \"error\";\n message?: string;\n}\n\nexport type WalletToPartnerMessage =\n | ReadyMessage\n | ResponseMessage\n | EventMessage\n | SecurityMessage\n | AccountsMessage\n | OnboardedMessage\n | OnboardCancelledMessage;\n\n// --- opener → pop-up ---------------------------------------------------------------------------------\n\nexport interface RequestMessage {\n type: `${typeof MESSAGE_PREFIX}request`;\n v: typeof PROTOCOL_VERSION;\n /** Unique per request within one connection; the response carries it back. */\n id: string;\n method: string;\n params?: unknown[] | Record<string, unknown>;\n}\n\n/** The partner disconnects (for example the user clicked \"Disconnect\" in the partner page). */\nexport interface DisconnectMessage {\n type: `${typeof MESSAGE_PREFIX}disconnect`;\n v: typeof PROTOCOL_VERSION;\n}\n\nexport type PartnerToWalletMessage = RequestMessage | DisconnectMessage;\n\n// --- guards ------------------------------------------------------------------------------------------\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null;\n}\n\nfunction hasType(value: unknown, suffix: string): value is Record<string, unknown> {\n return isRecord(value) && value.type === `${MESSAGE_PREFIX}${suffix}` && value.v === PROTOCOL_VERSION;\n}\n\nexport function isReadyMessage(value: unknown): value is ReadyMessage {\n return hasType(value, \"ready\");\n}\n\nexport function isResponseMessage(value: unknown): value is ResponseMessage {\n return (\n hasType(value, \"response\") &&\n typeof value.id === \"string\" &&\n (\"result\" in value || (isRecord(value.error) && typeof value.error.code === \"number\"))\n );\n}\n\nexport function isEventMessage(value: unknown): value is EventMessage {\n return (\n hasType(value, \"event\") &&\n (value.event === \"accountsChanged\" || value.event === \"chainChanged\" || value.event === \"disconnect\")\n );\n}\n\nconst WALLET_PROTECTIONS: readonly WalletProtection[] = [\n \"unknown\",\n \"add-factor\",\n \"save-codes\",\n \"create-codes\",\n \"protected\",\n];\n\n/** A factor count: a whole number, zero or more. */\nfunction isCount(value: unknown): value is number {\n return typeof value === \"number\" && Number.isInteger(value) && value >= 0;\n}\n\n/** True for a `security` message with a known `protection` value and whole, non-negative factor counts. */\nexport function isSecurityMessage(value: unknown): value is SecurityMessage {\n if (!hasType(value, \"security\")) return false;\n const data = value.data;\n return (\n isRecord(data) &&\n typeof data.protection === \"string\" &&\n (WALLET_PROTECTIONS as readonly string[]).includes(data.protection) &&\n isCount(data.passkeys) &&\n isCount(data.authenticatorApps)\n );\n}\n\n/** The largest number of accounts one `accounts` message may carry. */\nconst MAX_ACCOUNT_NAMES = 50;\n\n/** True when `value` has a control character: C0, DEL or C1. */\nfunction hasControlCharacter(value: string): boolean {\n for (const character of value) {\n const code = character.codePointAt(0) ?? 0;\n if (code <= 0x1f || (code >= 0x7f && code <= 0x9f)) return true;\n }\n return false;\n}\n\n/** A name: a string whose trimmed length is 1 to 64 and that has no control characters. */\nfunction isAccountName(value: unknown): value is string {\n if (typeof value !== \"string\") return false;\n if (hasControlCharacter(value)) return false;\n const trimmed = value.trim();\n return trimmed.length >= 1 && trimmed.length <= 64;\n}\n\n/** True for an `accounts` message with at most 50 named accounts. */\nexport function isAccountsMessage(value: unknown): value is AccountsMessage {\n if (!hasType(value, \"accounts\")) return false;\n const data = value.data;\n return (\n Array.isArray(data) &&\n data.length <= MAX_ACCOUNT_NAMES &&\n data.every(\n (entry: unknown) =>\n isRecord(entry) &&\n typeof entry.address === \"string\" &&\n EVM_ADDRESS_RE.test(entry.address) &&\n isAccountName(entry.name),\n )\n );\n}\n\nexport function isRequestMessage(value: unknown): value is RequestMessage {\n return hasType(value, \"request\") && typeof value.id === \"string\" && typeof value.method === \"string\";\n}\n\nexport function isDisconnectMessage(value: unknown): value is DisconnectMessage {\n return hasType(value, \"disconnect\");\n}\n\n/** `0x` followed by exactly 40 hexadecimal digits, the shape of an EVM address. */\nconst EVM_ADDRESS_RE = /^0x[0-9a-fA-F]{40}$/;\n\nexport function isOnboardedMessage(value: unknown): value is OnboardedMessage {\n return (\n hasType(value, \"onboarded\") &&\n typeof value.address === \"string\" &&\n EVM_ADDRESS_RE.test(value.address) &&\n typeof value.chain === \"string\" &&\n // `created` is new; an older wallet sent `status` instead and always created or reused a wallet.\n (typeof value.created === \"boolean\" || value.status === \"approved\" || value.status === \"pending\")\n );\n}\n\nexport function isOnboardCancelledMessage(value: unknown): value is OnboardCancelledMessage {\n return (\n hasType(value, \"onboard-cancelled\") &&\n (value.reason === \"user\" || value.reason === \"refused\" || value.reason === \"error\")\n );\n}\n\n/** A CAIP-2 EVM chain id, for example `eip155:80002` (Polygon Amoy) or `eip155:1` (mainnet). */\nexport function isCaip2EvmChain(value: string): boolean {\n return /^eip155:\\d{1,32}$/.test(value);\n}\n\n/**\n * The URL the partner opens. `partnerOrigin` is `window.location.origin` of the partner page. `signIn` adds the\n * optional sign-in hint; it is only a hint and the wallet may ignore it.\n */\nexport function connectUrl(walletUrl: string, partnerOrigin: string, signIn?: SignInHint): string {\n const url = new URL(CONNECT_PATH, walletUrl);\n url.searchParams.set(\"origin\", partnerOrigin);\n url.searchParams.set(\"v\", String(PROTOCOL_VERSION));\n if (signIn !== undefined) url.searchParams.set(\"signIn\", signIn);\n return url.toString();\n}\n\n/**\n * The URL the partner opens for the onboarding wizard. `partnerOrigin` is `window.location.origin` of the\n * partner page; `chain` is the CAIP-2 chain id the new wallet should be created on; `locale` is passed as `lang`\n * when the partner wants a specific wizard language. `signIn` adds the optional sign-in hint; it is only a hint\n * and the wallet may ignore it.\n */\nexport function onboardUrl(\n walletUrl: string,\n partnerOrigin: string,\n options: { chain: string; locale?: string; add?: boolean; signIn?: SignInHint },\n): string {\n const url = new URL(ONBOARD_PATH, walletUrl);\n url.searchParams.set(\"origin\", partnerOrigin);\n url.searchParams.set(\"v\", String(PROTOCOL_VERSION));\n url.searchParams.set(\"chain\", options.chain);\n if (options.locale !== undefined) url.searchParams.set(\"lang\", options.locale);\n if (options.add) url.searchParams.set(\"add\", \"1\");\n if (options.signIn !== undefined) url.searchParams.set(\"signIn\", options.signIn);\n return url.toString();\n}\n\n/**\n * The URL the partner opens to manage the wallet. `partnerOrigin` is `window.location.origin` of the partner\n * page. `locale` is passed as `lang` when the partner wants a specific language. `signIn` adds the optional\n * sign-in hint; it is only a hint and the wallet may ignore it.\n */\nexport function manageUrl(\n walletUrl: string,\n partnerOrigin: string,\n options: { locale?: string; signIn?: SignInHint } = {},\n): string {\n const url = new URL(MANAGE_PATH, walletUrl);\n url.searchParams.set(\"origin\", partnerOrigin);\n url.searchParams.set(\"v\", String(PROTOCOL_VERSION));\n if (options.locale !== undefined) url.searchParams.set(\"lang\", options.locale);\n if (options.signIn !== undefined) url.searchParams.set(\"signIn\", options.signIn);\n return url.toString();\n}\n","/**\n * EIP-1193 provider for the Assetera Wallet pop-up — the opener side of the ADR-0054 D3/D4 protocol.\n *\n * The provider owns a single pop-up (`window.open(connectUrl(...), \"assetera-wallet\", ...)`) and speaks the\n * wire format defined in `./protocol`. It never touches Dynamic, React, wagmi or viem, so a partner can use it\n * on its own or through the wagmi / RainbowKit adapters in this package.\n */\nimport {\n MESSAGE_PREFIX,\n PROTOCOL_VERSION,\n RpcErrorCode,\n connectUrl,\n isAccountsMessage,\n isEventMessage,\n isReadyMessage,\n isResponseMessage,\n isSecurityMessage,\n isSupportedMethod,\n type AccountsMessage,\n type DisconnectMessage,\n type EventMessage,\n type RequestMessage,\n type ResponseMessage,\n type SecurityMessage,\n type SignInHint,\n type WalletAccountName,\n type WalletSecurityStatus,\n} from \"./protocol\";\n\n/** Arguments accepted by `request`, mirroring EIP-1193. */\nexport interface RequestArguments {\n method: string;\n params?: unknown[] | Record<string, unknown>;\n}\n\n/** EIP-1193 provider events emitted by the pop-up, plus the wallet security status and account names. */\nexport type ProviderEvent =\n \"accountsChanged\" | \"chainChanged\" | \"connect\" | \"disconnect\" | \"assetera_security\" | \"assetera_accounts\";\n\n/**\n * Listener shape for EIP-1193 provider events. `never[]` accepts a listener with any concrete parameter list\n * (for example wagmi's `(accounts: string[]) => void`), while internal emission stays type-safe via a cast.\n */\nexport type ProviderListener = (...args: never[]) => void;\n\n/** The EIP-1193 surface returned by {@link createAsseteraWalletProvider}. */\nexport interface AsseteraWalletProvider {\n request(args: RequestArguments): Promise<unknown>;\n on(event: ProviderEvent, listener: ProviderListener): void;\n removeListener(event: ProviderEvent, listener: ProviderListener): void;\n disconnect(): void;\n /**\n * The last security status reported by a wallet pop-up, or `undefined` when none arrived yet. A closed pop-up\n * does not clear it.\n */\n lastSecurityStatus(): WalletSecurityStatus | undefined;\n /**\n * The last account names reported by a wallet pop-up, or `undefined` when none arrived yet. The returned list\n * is a copy. A closed pop-up does not clear it.\n */\n lastAccountNames(): WalletAccountName[] | undefined;\n /**\n * Open the pop-up NOW, inside the caller's click, for a signature that is sent later. Use it when the app must\n * wait for something (a firm quote, a fee) between the click and the signing request: without it, the request\n * would open the pop-up after an `await`, outside the click, and the browser would block it. A later\n * `request` reuses the pop-up. Synchronous; it never throws.\n */\n prepareSigning(): PreparedSigning;\n}\n\n/** The handle {@link AsseteraWalletProvider.prepareSigning} returns. */\nexport interface PreparedSigning {\n /** `false` when the browser blocked the pop-up. The caller should then ask for another click. */\n readonly opened: boolean;\n /**\n * Give the pop-up back when no request followed (the quote failed, the client cancelled). It closes the\n * pop-up only when THIS call opened it and no request was sent since; otherwise it does nothing. Safe to call\n * more than once.\n */\n release(): void;\n}\n\n/** Options for {@link createAsseteraWalletProvider}. */\nexport interface AsseteraWalletProviderOptions {\n /** Base URL of the wallet origin, e.g. `https://wallet.wallet-staging.assetera.com`. */\n walletUrl: string;\n /** Chain id used before the wallet reports one, and as the local `eth_chainId` fallback. */\n defaultChainId: number;\n /** `window.open` feature string. Defaults to `\"popup,width=420,height=720\"`. */\n popupFeatures?: string;\n /** Sign-in hint passed as `signIn`. Only a hint; the wallet may ignore it. */\n signIn?: SignInHint;\n}\n\n/**\n * EIP-1193 error carrying a JSON-RPC `code` (and optional `data`). This is what every rejected `request`\n * throws, so wagmi maps the wallet's `4001` / `4100` / `4200` / `4900` correctly.\n */\nexport class ProviderRpcError extends Error {\n readonly code: number;\n readonly data?: unknown;\n\n constructor(code: number, message: string, data?: unknown) {\n super(message);\n this.name = \"ProviderRpcError\";\n this.code = code;\n this.data = data;\n }\n}\n\nconst DEFAULT_POPUP_FEATURES = \"popup,width=420,height=720\";\nconst POPUP_NAME = \"assetera-wallet\";\nconst CLOSE_POLL_MS = 500;\n\n/** Methods that show the user a signature / transaction prompt, so the pop-up should be focused first. */\nconst SIGNING_METHODS: ReadonlySet<string> = new Set([\n \"personal_sign\",\n \"eth_signTypedData_v4\",\n \"eth_sendTransaction\",\n]);\n\ninterface PendingRequest {\n resolve: (value: unknown) => void;\n reject: (reason: unknown) => void;\n}\n\ninterface Deferred<T> {\n promise: Promise<T>;\n resolve: (value: T) => void;\n reject: (reason: unknown) => void;\n}\n\nfunction createDeferred<T>(): Deferred<T> {\n let resolve!: (value: T) => void;\n let reject!: (reason: unknown) => void;\n const promise = new Promise<T>((res, rej) => {\n resolve = res;\n reject = rej;\n });\n // The `ready` deferred is rejected when the pop-up closes even if no request is waiting on it; mark the\n // promise as handled so that rejection is not reported as an unhandled promise rejection.\n void promise.catch(() => {});\n return { promise, resolve, reject };\n}\n\nfunction toHexChainId(chainId: number): string {\n return `0x${chainId.toString(16)}`;\n}\n\n/**\n * Create the EIP-1193 provider that talks to the Assetera Wallet pop-up.\n *\n * Call `request` from a user gesture: `eth_requestAccounts` opens the pop-up synchronously (before any\n * `await`) so the browser treats it as part of the click and does not block it.\n */\nexport function createAsseteraWalletProvider(options: AsseteraWalletProviderOptions): AsseteraWalletProvider {\n const { defaultChainId } = options;\n const walletOrigin = new URL(options.walletUrl).origin;\n const popupFeatures = options.popupFeatures ?? DEFAULT_POPUP_FEATURES;\n\n let popup: Window | null = null;\n /** Resolves when the *current* pop-up posts `ready`. Replaced when a new pop-up is opened. */\n let ready = createDeferred<void>();\n let accounts: string[] = [];\n let chainIdHex: string | null = null;\n /** Set when the wallet itself told us the session ended (as opposed to the user merely closing the tab). */\n let walletDisconnected = false;\n /** The last security status a pop-up reported; kept when the pop-up closes. */\n let lastSecurity: WalletSecurityStatus | undefined;\n /** The last account names a pop-up reported; kept when the pop-up closes. */\n let lastAccountNameList: WalletAccountName[] | undefined;\n const pending = new Map<string, PendingRequest>();\n const listeners = new Map<ProviderEvent, Set<(...args: unknown[]) => void>>();\n let closeTimer: ReturnType<typeof setInterval> | null = null;\n /** Counts the requests that need the pop-up, so `prepareSigning().release()` knows whether one followed. */\n let requestsSent = 0;\n\n function currentChainId(): string {\n return chainIdHex ?? toHexChainId(defaultChainId);\n }\n\n function blockedError(): ProviderRpcError {\n return new ProviderRpcError(\n RpcErrorCode.Disconnected,\n \"The Assetera Wallet pop-up was blocked by the browser. The pop-up must be opened from a user click \" +\n \"(for example a button press) and then the request retried.\",\n );\n }\n\n function disconnectedError(message = \"The Assetera Wallet pop-up was closed.\"): ProviderRpcError {\n return new ProviderRpcError(RpcErrorCode.Disconnected, message);\n }\n\n function emit(event: ProviderEvent, ...args: unknown[]): void {\n const set = listeners.get(event);\n if (!set) return;\n for (const listener of set) {\n try {\n listener(...args);\n } catch (error) {\n console.error(`[assetera-wallet] listener for \"${event}\" threw`, error);\n }\n }\n }\n\n function addListener(event: ProviderEvent, listener: ProviderListener): void {\n let set = listeners.get(event);\n if (!set) {\n set = new Set<(...args: unknown[]) => void>();\n listeners.set(event, set);\n }\n set.add(listener as (...args: unknown[]) => void);\n }\n\n function removeEventListener(event: ProviderEvent, listener: ProviderListener): void {\n listeners.get(event)?.delete(listener as (...args: unknown[]) => void);\n }\n\n function stopClosePolling(): void {\n if (closeTimer !== null) {\n clearInterval(closeTimer);\n closeTimer = null;\n }\n }\n\n function startClosePolling(): void {\n if (closeTimer !== null) return;\n closeTimer = setInterval(() => {\n if (popup?.closed) handlePopupClosed();\n }, CLOSE_POLL_MS);\n }\n\n function rejectAllPending(error: ProviderRpcError): void {\n for (const request of pending.values()) request.reject(error);\n pending.clear();\n }\n\n /**\n * The pop-up was closed by the user (or the wallet app).\n *\n * We deliberately KEEP `accounts` / `chainIdHex` cached: the dApp stays \"connected\" in React state and does\n * not flicker back to a disconnected UI. Because a pop-up cannot be reopened without a user gesture, the next\n * signing request reopens it from the caller's click. `disconnect` is only emitted when the close actually\n * interrupted work (a request was pending) or when the wallet itself announced the disconnect.\n */\n function handlePopupClosed(): void {\n const hadPending = pending.size > 0;\n stopClosePolling();\n const closedPopup = popup;\n popup = null;\n const closedReady = ready;\n ready = createDeferred<void>();\n const error = disconnectedError();\n if (closedPopup) closedReady.reject(error);\n rejectAllPending(error);\n const shouldEmit = hadPending || walletDisconnected;\n walletDisconnected = false;\n if (shouldEmit) emit(\"disconnect\", error);\n }\n\n /**\n * Open the pop-up, or focus and reuse it when it is still around. Must stay synchronous (it is called before\n * any `await` in `request`) so it runs inside the caller's user activation.\n */\n function openPopup(): Window | null {\n if (popup && !popup.closed) {\n popup.focus();\n return popup;\n }\n if (typeof window === \"undefined\") return null;\n const opened = window.open(\n connectUrl(options.walletUrl, window.location.origin, options.signIn),\n POPUP_NAME,\n popupFeatures,\n );\n if (!opened) return null;\n popup = opened;\n ready = createDeferred<void>();\n walletDisconnected = false;\n startClosePolling();\n return opened;\n }\n\n function sendRequest(method: string, params?: RequestArguments[\"params\"]): Promise<unknown> {\n const active = popup;\n if (!active || active.closed) return Promise.reject(disconnectedError());\n const id = crypto.randomUUID();\n const message: RequestMessage = {\n type: `${MESSAGE_PREFIX}request`,\n v: PROTOCOL_VERSION,\n id,\n method,\n ...(params === undefined ? {} : { params }),\n };\n return new Promise<unknown>((resolve, reject) => {\n pending.set(id, { resolve, reject });\n active.postMessage(message, walletOrigin);\n });\n }\n\n function handleResponse(message: ResponseMessage): void {\n const request = pending.get(message.id);\n if (!request) return;\n pending.delete(message.id);\n if (\"error\" in message) {\n request.reject(new ProviderRpcError(message.error.code, message.error.message, message.error.data));\n } else {\n request.resolve(message.result);\n }\n }\n\n function handleEventMessage(message: EventMessage): void {\n if (message.event === \"accountsChanged\") {\n accounts = [...message.data];\n emit(\"accountsChanged\", [...accounts]);\n return;\n }\n if (message.event === \"chainChanged\") {\n chainIdHex = message.data;\n emit(\"chainChanged\", chainIdHex);\n return;\n }\n walletDisconnected = true;\n emit(\"disconnect\", new ProviderRpcError(message.data.code, message.data.message, message.data.data));\n }\n\n function handleSecurityMessage(message: SecurityMessage): void {\n lastSecurity = {\n protection: message.data.protection,\n passkeys: message.data.passkeys,\n authenticatorApps: message.data.authenticatorApps,\n };\n emit(\"assetera_security\", lastSecurity);\n }\n\n /** A copy of a list of named accounts, so callers never get the provider's own list. */\n function copyAccountNames(accounts: readonly WalletAccountName[]): WalletAccountName[] {\n return accounts.map((account) => ({ address: account.address, name: account.name }));\n }\n\n function handleAccountsMessage(message: AccountsMessage): void {\n lastAccountNameList = copyAccountNames(message.data);\n emit(\"assetera_accounts\", copyAccountNames(lastAccountNameList));\n }\n\n function onWindowMessage(event: MessageEvent): void {\n if (event.origin !== walletOrigin) return;\n if (popup === null || (event.source as unknown) !== popup) return;\n const data: unknown = event.data;\n if (isReadyMessage(data)) {\n ready.resolve(undefined);\n return;\n }\n if (isResponseMessage(data)) {\n handleResponse(data);\n return;\n }\n if (isSecurityMessage(data)) {\n handleSecurityMessage(data);\n return;\n }\n if (isAccountsMessage(data)) {\n handleAccountsMessage(data);\n return;\n }\n if (isEventMessage(data)) handleEventMessage(data);\n }\n\n if (typeof window !== \"undefined\") window.addEventListener(\"message\", onWindowMessage);\n\n function request({ method, params }: RequestArguments): Promise<unknown> {\n if (typeof window === \"undefined\") {\n return Promise.reject(\n new ProviderRpcError(\n RpcErrorCode.Disconnected,\n \"The Assetera Wallet provider can only run in a browser.\",\n ),\n );\n }\n // Read-only chain calls go through wagmi's own transports; the pop-up refuses everything else.\n if (!isSupportedMethod(method)) {\n return Promise.reject(\n new ProviderRpcError(\n RpcErrorCode.UnsupportedMethod,\n `The Assetera Wallet pop-up does not support the method \"${method}\".`,\n ),\n );\n }\n // Answered locally, without a pop-up, so wagmi can read the connection before the user clicks.\n if (method === \"eth_accounts\") return Promise.resolve([...accounts]);\n if (method === \"eth_chainId\") return Promise.resolve(currentChainId());\n\n // Opening the pop-up MUST happen synchronously, before the first `await`, to stay in the click.\n if (method === \"eth_requestAccounts\") {\n requestsSent += 1;\n const active = openPopup();\n if (!active) return Promise.reject(blockedError());\n return ready.promise\n .then(() => sendRequest(\"eth_requestAccounts\", params))\n .then((result) => {\n accounts = Array.isArray(result) ? (result as string[]) : [];\n emit(\"accountsChanged\", [...accounts]);\n emit(\"connect\", { chainId: currentChainId() });\n return [...accounts];\n });\n }\n\n // Every other supported method needs an approved connection.\n if (accounts.length === 0) {\n return Promise.reject(\n new ProviderRpcError(\n RpcErrorCode.Unauthorized,\n \"Connect to the Assetera Wallet first (eth_requestAccounts).\",\n ),\n );\n }\n requestsSent += 1;\n const active = openPopup();\n if (!active) return Promise.reject(blockedError());\n if (SIGNING_METHODS.has(method)) active.focus();\n return ready.promise.then(() => sendRequest(method, params));\n }\n\n function disconnect(): void {\n const active = popup;\n if (active && !active.closed) {\n const message: DisconnectMessage = {\n type: `${MESSAGE_PREFIX}disconnect`,\n v: PROTOCOL_VERSION,\n };\n active.postMessage(message, walletOrigin);\n active.close();\n }\n stopClosePolling();\n popup = null;\n const closedReady = ready;\n ready = createDeferred<void>();\n closedReady.reject(disconnectedError(\"Disconnected from the Assetera Wallet.\"));\n rejectAllPending(disconnectedError(\"Disconnected from the Assetera Wallet.\"));\n accounts = [];\n chainIdHex = null;\n walletDisconnected = false;\n emit(\"disconnect\", disconnectedError(\"Disconnected from the Assetera Wallet.\"));\n }\n\n function prepareSigning(): PreparedSigning {\n const existed = popup !== null && !popup.closed;\n const active = typeof window === \"undefined\" ? null : openPopup();\n if (!active) return { opened: false, release: () => {} };\n const sentAtPrepare = requestsSent;\n let released = false;\n return {\n opened: true,\n release() {\n if (released) return;\n released = true;\n // Only a pop-up this call opened, still open, with nothing sent or waiting since.\n if (existed || popup !== active || active.closed) return;\n if (requestsSent !== sentAtPrepare || pending.size > 0) return;\n active.close();\n handlePopupClosed();\n },\n };\n }\n\n function on(event: ProviderEvent, listener: ProviderListener): void {\n addListener(event, listener);\n }\n\n function removeListener(event: ProviderEvent, listener: ProviderListener): void {\n removeEventListener(event, listener);\n }\n\n /** The last security status a pop-up reported, kept even after the pop-up closed. */\n function lastSecurityStatus(): WalletSecurityStatus | undefined {\n return lastSecurity;\n }\n\n /** The last account names a pop-up reported, kept even after the pop-up closed. */\n function lastAccountNames(): WalletAccountName[] | undefined {\n return lastAccountNameList === undefined ? undefined : copyAccountNames(lastAccountNameList);\n }\n\n return {\n request,\n on,\n removeListener,\n disconnect,\n lastSecurityStatus,\n lastAccountNames,\n prepareSigning,\n };\n}\n","/**\n * Small helpers shared by the pop-up openers in this package. They are internal and are not part of the public\n * API through `index.ts`.\n */\n\n/** Default width, in pixels, of the onboarding and manage pop-ups. */\nexport const POPUP_WIDTH = 440;\n\n/** Default height, in pixels, of the onboarding and manage pop-ups. */\nexport const POPUP_HEIGHT = 760;\n\n/**\n * Build the centred `window.open` feature string for a pop-up of the default size. `win` is the opener window:\n * the pop-up is centred over it, and safe defaults are used when the browser does not expose the geometry.\n */\nexport function defaultPopupFeatures(win: Window): string {\n const screenX = Number.isFinite(win.screenX) ? win.screenX : 0;\n const screenY = Number.isFinite(win.screenY) ? win.screenY : 0;\n const outerWidth = Number.isFinite(win.outerWidth) ? win.outerWidth : POPUP_WIDTH;\n const outerHeight = Number.isFinite(win.outerHeight) ? win.outerHeight : POPUP_HEIGHT;\n const left = Math.max(0, Math.round(screenX + (outerWidth - POPUP_WIDTH) / 2));\n const top = Math.max(0, Math.round(screenY + (outerHeight - POPUP_HEIGHT) / 2));\n return `popup,width=${POPUP_WIDTH},height=${POPUP_HEIGHT},left=${left},top=${top}`;\n}\n","/**\n * Onboarding opener for the Assetera Wallet: the partner side of the `/onboard` wizard (AO-1274).\n *\n * A tied-agent bank site shows a \"Create an Assetera wallet\" button. On the click, this module opens the wallet\n * pop-up in onboarding mode synchronously (so the browser treats it as part of the click) and waits for the\n * wizard to post the new wallet address back. While the pop-up is open the partner page shows a dimming\n * overlay; the overlay is plain DOM (no React, no CSS files) so any partner can drop this in.\n *\n * The wallet's `/onboard` page is the pop-up side and speaks the same protocol in `./protocol`, but it uses the\n * message types and the `ONBOARD_PATH` from there, so the two sides cannot drift apart.\n */\nimport {\n MESSAGE_PREFIX,\n PROTOCOL_VERSION,\n RpcErrorCode,\n isAccountsMessage,\n isCaip2EvmChain,\n isOnboardCancelledMessage,\n isOnboardedMessage,\n isResponseMessage,\n onboardUrl,\n type OnboardCancelledMessage,\n type RequestMessage,\n type SignInHint,\n type WalletAccountName,\n} from \"./protocol\";\nimport { defaultPopupFeatures } from \"./popup\";\n\n/** Why {@link openAsseteraOnboarding} rejected. */\nexport type OnboardingErrorCode =\n \"popup_blocked\" | \"closed\" | \"cancelled\" | \"refused\" | \"failed\" | \"invalid_options\";\n\n/** Error thrown (well, rejected) by {@link openAsseteraOnboarding}. `code` is stable and safe to branch on. */\nexport class OnboardingError extends Error {\n readonly code: OnboardingErrorCode;\n\n constructor(code: OnboardingErrorCode, message: string) {\n super(message);\n this.name = \"OnboardingError\";\n this.code = code;\n }\n}\n\n/**\n * The client's Assetera Wallet, with the pop-up still open.\n *\n * The wallet is NOT registered with any compliance service. A regulated partner registers it itself, like any\n * other wallet: fetch a challenge for `address`, pass it to `signMessage`, send the signature to its compliance\n * service, then call `close()`. Always call `close()`: it closes the pop-up and removes the overlay.\n */\nexport interface OnboardingResult {\n address: `0x${string}`;\n chain: string;\n /** `true` when the wallet was created in this run, `false` when the client's existing wallet was returned. */\n created: boolean;\n /**\n * Ask the client to sign `message` (EIP-191 `personal_sign`) with this wallet in the open pop-up. Rejects with\n * `OnboardingError(\"cancelled\")` when the client declines, `\"closed\"` when the pop-up is gone, else `\"failed\"`.\n */\n signMessage: (message: string) => Promise<`0x${string}`>;\n /** Close the pop-up and remove the overlay. Safe to call more than once. */\n close: () => void;\n /**\n * The last account names the pop-up sent after it reported the address, or `undefined` when none arrived yet.\n * The returned list is a copy.\n */\n lastAccounts: () => WalletAccountName[] | undefined;\n}\n\n/** Text of the dimming overlay, all optional. Any key left out keeps its English default. */\nexport interface OverlayLabels {\n title?: string;\n body?: string;\n focus?: string;\n cancel?: string;\n blocked?: string;\n}\n\n/** Options for {@link openAsseteraOnboarding}. */\nexport interface OnboardingOptions {\n /** Base URL of the wallet origin, e.g. `https://wallet.wallet-staging.assetera.com`. */\n walletUrl: string;\n /** CAIP-2 chain id the new wallet should be created on, e.g. `eip155:80002`. An invalid value rejects with `invalid_options`. */\n chain: string;\n /** Wizard language passed as `lang`, e.g. `\"en\"` or `\"de\"`. */\n locale?: string;\n /** `window.open` feature string. Defaults to a centred `\"popup,width=440,height=760,left=…,top=…\"`. */\n popupFeatures?: string;\n /** `true` (default) shows the dimming overlay, `false` hides it, an object overrides its text. */\n overlay?: boolean | OverlayLabels;\n /** Only used in the overlay text, e.g. `\"Musterbank\"`. */\n partnerName?: string;\n /** Ask for one more wallet even when the client already has one (\"Create another Assetera Wallet\"). */\n addWallet?: boolean;\n /** Sign-in hint passed as `signIn`, e.g. `\"assetera-marketplace\"`. Only a hint; the wallet may ignore it. */\n signIn?: SignInHint;\n /** Called for every `accounts` message the pop-up sends after it reported the address. */\n onAccounts?: (accounts: WalletAccountName[]) => void;\n /** Injectable `window` for tests; defaults to `globalThis.window`. */\n window?: Window;\n}\n\nconst POPUP_NAME = \"assetera-wallet-onboarding\";\nconst CLOSE_POLL_MS = 500;\nconst OVERLAY_Z_INDEX = 2147483000;\n\nconst DEFAULT_LABELS: Required<OverlayLabels> = {\n title: \"Continue in the Assetera Wallet window\",\n body: \"A secure Assetera Wallet window is open. Follow the steps there. This page continues by itself when you are done.\",\n focus: \"Show the wallet window\",\n cancel: \"Cancel\",\n blocked: \"Your browser blocked the Assetera Wallet window. Allow pop-ups for this site and try again.\",\n};\n\ninterface OverlayHandlers {\n onFocus: () => void;\n onCancel: () => void;\n}\n\nfunction resolveLabels(options: OnboardingOptions): Required<OverlayLabels> {\n const overrides: OverlayLabels =\n typeof options.overlay === \"object\" && options.overlay !== null ? options.overlay : {};\n const partnerName = options.partnerName;\n const defaultBody = partnerName\n ? `A secure Assetera Wallet window is open for ${partnerName}. Follow the steps there. This page continues by itself when you are done.`\n : DEFAULT_LABELS.body;\n return {\n title: overrides.title ?? DEFAULT_LABELS.title,\n body: overrides.body ?? defaultBody,\n focus: overrides.focus ?? DEFAULT_LABELS.focus,\n cancel: overrides.cancel ?? DEFAULT_LABELS.cancel,\n blocked: overrides.blocked ?? DEFAULT_LABELS.blocked,\n };\n}\n\nfunction cancelCode(reason: OnboardCancelledMessage[\"reason\"]): OnboardingErrorCode {\n if (reason === \"user\") return \"cancelled\";\n if (reason === \"refused\") return \"refused\";\n return \"failed\";\n}\n\nfunction cancelMessage(reason: OnboardCancelledMessage[\"reason\"]): string {\n if (reason === \"user\") return \"The user cancelled the Assetera Wallet onboarding.\";\n if (reason === \"refused\") return \"The Assetera Wallet refused the onboarding.\";\n return \"The Assetera Wallet onboarding failed.\";\n}\n\n/** A copy of a list of named accounts, so callers never get the opener's own list. */\nfunction copyAccountNames(accounts: readonly WalletAccountName[]): WalletAccountName[] {\n return accounts.map((account) => ({ address: account.address, name: account.name }));\n}\n\n/**\n * Build the dimming overlay. Text is inserted with `textContent` only and every style is inline, so the\n * overlay cannot pick up partner CSS and cannot be scripted through an injected string.\n */\nfunction showOverlay(win: Window, labels: Required<OverlayLabels>, handlers: OverlayHandlers): HTMLElement {\n const doc = win.document;\n const root = doc.createElement(\"div\");\n root.setAttribute(\"role\", \"dialog\");\n root.setAttribute(\"aria-modal\", \"true\");\n root.setAttribute(\"data-assetera-onboarding-overlay\", \"\");\n root.style.cssText = [\n \"position: fixed\",\n \"inset: 0\",\n \"display: flex\",\n \"align-items: center\",\n \"justify-content: center\",\n \"padding: 24px\",\n \"box-sizing: border-box\",\n \"background: rgba(15,20,30,0.6)\",\n `z-index: ${OVERLAY_Z_INDEX}`,\n \"font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif\",\n ].join(\"; \");\n\n const card = doc.createElement(\"div\");\n card.style.cssText = [\n \"box-sizing: border-box\",\n \"width: 100%\",\n \"max-width: 420px\",\n \"border-radius: 16px\",\n \"padding: 24px\",\n \"background: #ffffff\",\n \"color: #101828\",\n \"box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35)\",\n ].join(\"; \");\n\n const title = doc.createElement(\"h2\");\n title.textContent = labels.title;\n title.style.cssText = \"margin: 0 0 10px; font-size: 18px; line-height: 1.3; font-weight: 600;\";\n\n const body = doc.createElement(\"p\");\n body.textContent = labels.body;\n body.style.cssText = \"margin: 0 0 20px; font-size: 14px; line-height: 1.5; color: #475467;\";\n\n const focus = doc.createElement(\"button\");\n focus.type = \"button\";\n focus.textContent = labels.focus;\n focus.style.cssText = [\n \"padding: 10px 16px\",\n \"border: 0\",\n \"border-radius: 10px\",\n \"background: #101828\",\n \"color: #ffffff\",\n \"font: inherit\",\n \"font-weight: 600\",\n \"cursor: pointer\",\n ].join(\"; \");\n focus.addEventListener(\"click\", handlers.onFocus);\n\n const cancel = doc.createElement(\"button\");\n cancel.type = \"button\";\n cancel.textContent = labels.cancel;\n cancel.style.cssText = [\n \"padding: 10px 16px\",\n \"border: 0\",\n \"border-radius: 10px\",\n \"background: transparent\",\n \"color: #475467\",\n \"font: inherit\",\n \"cursor: pointer\",\n ].join(\"; \");\n cancel.addEventListener(\"click\", handlers.onCancel);\n\n const actions = doc.createElement(\"div\");\n actions.style.cssText = \"display: flex; gap: 8px; align-items: center;\";\n actions.append(focus, cancel);\n\n card.append(title, body, actions);\n root.append(card);\n doc.body.append(root);\n return root;\n}\n\n/**\n * Open the Assetera Wallet onboarding wizard in a pop-up and resolve with the client's wallet, the pop-up still\n * open so the partner can ask for the ownership signature (see {@link OnboardingResult}).\n *\n * Call this from a user click (a button handler). `window.open` runs synchronously inside the call, before any\n * `await`, so the browser allows it; if the browser blocks the pop-up the promise rejects with\n * `OnboardingError(\"popup_blocked\")` and no overlay is shown.\n *\n * The promise rejects with `OnboardingError` and one of these codes: `invalid_options` (bad chain or wallet\n * URL), `popup_blocked`, `closed` (the pop-up was closed first), `cancelled` (the user cancelled in the wizard\n * or in the overlay), `refused` (the wallet refused the onboarding) or `failed` (anything else in the wallet).\n * After it resolved, the overlay stays until `close()`; closing the pop-up by hand also removes it. After it\n * reported the address the pop-up may send `accounts` messages; `onAccounts` receives each list and\n * `lastAccounts()` returns the last one.\n */\nexport function openAsseteraOnboarding(options: OnboardingOptions): Promise<OnboardingResult> {\n const requestedWindow = options.window ?? (typeof window === \"undefined\" ? undefined : window);\n if (!requestedWindow) {\n return Promise.reject(\n new OnboardingError(\"invalid_options\", \"The Assetera Wallet onboarding can only run in a browser.\"),\n );\n }\n // A non-optional alias so TypeScript keeps the narrowed type inside the callbacks below.\n const targetWindow: Window = requestedWindow;\n if (!isCaip2EvmChain(options.chain)) {\n return Promise.reject(\n new OnboardingError(\n \"invalid_options\",\n `\"${options.chain}\" is not a CAIP-2 EVM chain id (for example \"eip155:80002\").`,\n ),\n );\n }\n let walletOrigin: string;\n try {\n walletOrigin = new URL(options.walletUrl).origin;\n } catch {\n return Promise.reject(\n new OnboardingError(\"invalid_options\", `\"${options.walletUrl}\" is not a valid wallet URL.`),\n );\n }\n\n const labels = resolveLabels(options);\n const overlayEnabled = options.overlay !== false;\n\n // MUST stay synchronous, before the first await, so the pop-up runs inside the caller's user activation.\n const popup = targetWindow.open(\n onboardUrl(options.walletUrl, targetWindow.location.origin, {\n chain: options.chain,\n ...(options.locale === undefined ? {} : { locale: options.locale }),\n ...(options.addWallet ? { add: true } : {}),\n ...(options.signIn === undefined ? {} : { signIn: options.signIn }),\n }),\n POPUP_NAME,\n options.popupFeatures ?? defaultPopupFeatures(targetWindow),\n );\n\n if (!popup) {\n // Nothing was opened, so there is nothing to wait for and no overlay: the partner page stays usable.\n return Promise.reject(new OnboardingError(\"popup_blocked\", labels.blocked));\n }\n // A non-optional alias so TypeScript keeps the narrowed type inside the callbacks below.\n const activePopup: Window = popup;\n\n return new Promise<OnboardingResult>((resolve, reject) => {\n // Phase 1 waits for `onboarded`; phase 2 (after it) keeps the pop-up for signature requests until `close()`.\n let onboarded = false;\n let finished = false;\n let closeTimer: ReturnType<typeof setInterval> | null = null;\n let overlay: HTMLElement | null = null;\n const pending = new Map<\n string,\n { resolve: (signature: `0x${string}`) => void; reject: (error: OnboardingError) => void }\n >();\n\n function cleanup(): void {\n finished = true;\n targetWindow.removeEventListener(\"message\", onMessage);\n if (closeTimer !== null) {\n clearInterval(closeTimer);\n closeTimer = null;\n }\n overlay?.remove();\n overlay = null;\n }\n\n function failPending(error: OnboardingError): void {\n for (const entry of pending.values()) entry.reject(error);\n pending.clear();\n }\n\n function close(): void {\n if (finished) return;\n failPending(new OnboardingError(\"closed\", \"The Assetera Wallet window was closed.\"));\n cleanup();\n if (!activePopup.closed) activePopup.close();\n }\n\n function fail(error: OnboardingError): void {\n if (onboarded || finished) return;\n cleanup();\n reject(error);\n }\n\n function cancel(): void {\n if (onboarded) {\n close();\n return;\n }\n activePopup.close();\n fail(new OnboardingError(\"cancelled\", \"The user cancelled the Assetera Wallet onboarding.\"));\n }\n\n function signMessage(message: string): Promise<`0x${string}`> {\n if (finished || activePopup.closed) {\n return Promise.reject(new OnboardingError(\"closed\", \"The Assetera Wallet window was closed.\"));\n }\n const id = globalThis.crypto.randomUUID();\n const request: RequestMessage = {\n type: `${MESSAGE_PREFIX}request`,\n v: PROTOCOL_VERSION,\n id,\n method: \"personal_sign\",\n params: [message, address as `0x${string}`],\n };\n return new Promise((resolveSign, rejectSign) => {\n pending.set(id, { resolve: resolveSign, reject: rejectSign });\n activePopup.focus();\n activePopup.postMessage(request, walletOrigin);\n });\n }\n\n // Set with `onboarded`; `signMessage` is only handed out after that.\n let address: `0x${string}` | undefined;\n /** The last account names the pop-up sent after `onboarded`; kept until `close()`. */\n let lastAccountNameList: WalletAccountName[] | undefined;\n\n function onMessage(event: MessageEvent): void {\n // Trust rule: accept only the wallet origin AND the exact pop-up we opened. Ignore everything else.\n if (event.origin !== walletOrigin) return;\n if ((event.source as unknown) !== activePopup) return;\n const data: unknown = event.data;\n if (!onboarded) {\n if (isOnboardedMessage(data)) {\n onboarded = true;\n address = data.address;\n resolve({\n address: data.address,\n chain: data.chain,\n created: data.created ?? true,\n signMessage,\n close,\n lastAccounts: () =>\n lastAccountNameList === undefined ? undefined : copyAccountNames(lastAccountNameList),\n });\n return;\n }\n if (isOnboardCancelledMessage(data)) {\n fail(new OnboardingError(cancelCode(data.reason), data.message ?? cancelMessage(data.reason)));\n }\n return;\n }\n if (isAccountsMessage(data)) {\n lastAccountNameList = copyAccountNames(data.data);\n options.onAccounts?.(copyAccountNames(lastAccountNameList));\n return;\n }\n if (isResponseMessage(data)) {\n const entry = pending.get(data.id);\n if (!entry) return;\n pending.delete(data.id);\n if (\"error\" in data) {\n entry.reject(\n new OnboardingError(\n data.error.code === RpcErrorCode.UserRejected ? \"cancelled\" : \"failed\",\n data.error.message,\n ),\n );\n } else if (typeof data.result === \"string\" && /^0x[0-9a-fA-F]+$/.test(data.result)) {\n entry.resolve(data.result as `0x${string}`);\n } else {\n entry.reject(new OnboardingError(\"failed\", \"The Assetera Wallet returned no signature.\"));\n }\n }\n }\n\n targetWindow.addEventListener(\"message\", onMessage);\n closeTimer = setInterval(() => {\n if (!activePopup.closed) return;\n if (onboarded) {\n close();\n return;\n }\n fail(\n new OnboardingError(\"closed\", \"The Assetera Wallet window was closed before onboarding finished.\"),\n );\n }, CLOSE_POLL_MS);\n\n if (overlayEnabled) {\n overlay = showOverlay(targetWindow, labels, {\n onFocus: () => activePopup.focus(),\n onCancel: cancel,\n });\n }\n });\n}\n","/**\n * Manage-wallet opener for the Assetera Wallet: the partner side of the `/manage` pop-up (AO-1436).\n *\n * A partner page shows a \"Manage wallet\" button. On the click this module opens the wallet pop-up on the manage\n * route synchronously (so the browser treats it as part of the click). The client sees the wallet accounts and\n * the wallet security (passkeys, authenticator app, recovery codes) and can change them. The pop-up never\n * answers `request` messages; it posts `security` and `accounts` messages while it is open.\n */\nimport {\n isAccountsMessage,\n isSecurityMessage,\n manageUrl,\n type SignInHint,\n type WalletAccountName,\n type WalletSecurityStatus,\n} from \"./protocol\";\nimport { defaultPopupFeatures } from \"./popup\";\n\n/** Why {@link openAsseteraWalletManager} threw. */\nexport type ManagerErrorCode = \"popup_blocked\" | \"invalid_options\";\n\n/** Error thrown by {@link openAsseteraWalletManager}. `code` is stable and safe to branch on. */\nexport class ManagerError extends Error {\n readonly code: ManagerErrorCode;\n\n constructor(code: ManagerErrorCode, message: string) {\n super(message);\n this.name = \"ManagerError\";\n this.code = code;\n }\n}\n\n/** Options for {@link openAsseteraWalletManager}. */\nexport interface WalletManagerOptions {\n /** Base URL of the wallet origin, e.g. `https://wallet.wallet-staging.assetera.com`. */\n walletUrl: string;\n /** Sign-in hint passed as `signIn`, e.g. `\"assetera-marketplace\"`. Only a hint; the wallet may ignore it. */\n signIn?: SignInHint;\n /** Language passed as `lang`, e.g. `\"en\"` or `\"de\"`. */\n locale?: string;\n /** `window.open` feature string. Defaults to a centred `\"popup,width=440,height=760,left=…,top=…\"`. */\n popupFeatures?: string;\n /** Called for every `security` message from the pop-up. */\n onSecurity?: (status: WalletSecurityStatus) => void;\n /** Called for every `accounts` message from the pop-up. */\n onAccounts?: (accounts: WalletAccountName[]) => void;\n /** Injectable `window` for tests; defaults to `globalThis.window`. */\n window?: Window;\n}\n\n/** The open manage pop-up, controlled by the partner. */\nexport interface WalletManager {\n /** Close the pop-up and remove the listener and the close timer. Safe to call more than once. */\n close: () => void;\n /** Resolves when the pop-up is closed, by the partner or by the client. */\n closed: Promise<void>;\n /** The last security status the pop-up sent, or `undefined` when none arrived yet. */\n lastSecurity: () => WalletSecurityStatus | undefined;\n /** The last account names the pop-up sent, or `undefined` when none arrived yet. */\n lastAccounts: () => WalletAccountName[] | undefined;\n}\n\nconst POPUP_NAME = \"assetera-wallet-manage\";\nconst CLOSE_POLL_MS = 500;\n\n/**\n * Open the manage-wallet pop-up for the Assetera Wallet and return a handle to it.\n *\n * Call this from a user click (a button handler). `window.open` runs synchronously inside the call, before any\n * `await`, so the browser allows it; when the browser blocks the pop-up this throws `ManagerError` with code\n * `popup_blocked`.\n *\n * The pop-up checks the `origin` query parameter against the wallet's partner list, posts `ready` to\n * `window.opener` and then posts `security` and `accounts` messages. Messages are accepted only when they come\n * from the wallet origin AND from the pop-up that was opened here. The pop-up does not answer `request`\n * messages.\n */\nexport function openAsseteraWalletManager(options: WalletManagerOptions): WalletManager {\n const requestedWindow = options.window ?? (typeof window === \"undefined\" ? undefined : window);\n if (!requestedWindow) {\n throw new ManagerError(\"invalid_options\", \"The Assetera Wallet manager can only run in a browser.\");\n }\n // A non-optional alias so TypeScript keeps the narrowed type inside the callbacks below.\n const targetWindow: Window = requestedWindow;\n let walletOrigin: string;\n try {\n walletOrigin = new URL(options.walletUrl).origin;\n } catch {\n throw new ManagerError(\"invalid_options\", `\"${options.walletUrl}\" is not a valid wallet URL.`);\n }\n\n // MUST stay synchronous, before any await, so the pop-up runs inside the caller's user activation.\n const popup = targetWindow.open(\n manageUrl(options.walletUrl, targetWindow.location.origin, {\n ...(options.locale === undefined ? {} : { locale: options.locale }),\n ...(options.signIn === undefined ? {} : { signIn: options.signIn }),\n }),\n POPUP_NAME,\n options.popupFeatures ?? defaultPopupFeatures(targetWindow),\n );\n\n if (!popup) {\n throw new ManagerError(\n \"popup_blocked\",\n \"Your browser blocked the Assetera Wallet window. Allow pop-ups for this site and try again.\",\n );\n }\n // A non-optional alias so TypeScript keeps the narrowed type inside the callbacks below.\n const activePopup: Window = popup;\n\n let finished = false;\n let lastSecurity: WalletSecurityStatus | undefined;\n let lastAccounts: WalletAccountName[] | undefined;\n let closeTimer: ReturnType<typeof setInterval> | null = null;\n let resolveClosed!: () => void;\n const closed = new Promise<void>((resolve) => {\n resolveClosed = resolve;\n });\n\n function cleanup(): void {\n if (finished) return;\n finished = true;\n targetWindow.removeEventListener(\"message\", onMessage);\n if (closeTimer !== null) {\n clearInterval(closeTimer);\n closeTimer = null;\n }\n resolveClosed();\n }\n\n function close(): void {\n cleanup();\n if (!activePopup.closed) activePopup.close();\n }\n\n /** A copy of a list of named accounts, so callers never get the manager's own list. */\n function copyAccountNames(accounts: readonly WalletAccountName[]): WalletAccountName[] {\n return accounts.map((account) => ({ address: account.address, name: account.name }));\n }\n\n function onMessage(event: MessageEvent): void {\n // Trust rule: accept only the wallet origin AND the exact pop-up we opened. Ignore everything else.\n if (event.origin !== walletOrigin) return;\n if ((event.source as unknown) !== activePopup) return;\n const data: unknown = event.data;\n if (isSecurityMessage(data)) {\n const status: WalletSecurityStatus = {\n protection: data.data.protection,\n passkeys: data.data.passkeys,\n authenticatorApps: data.data.authenticatorApps,\n };\n lastSecurity = status;\n options.onSecurity?.(status);\n return;\n }\n if (isAccountsMessage(data)) {\n lastAccounts = copyAccountNames(data.data);\n options.onAccounts?.(copyAccountNames(lastAccounts));\n }\n }\n\n targetWindow.addEventListener(\"message\", onMessage);\n closeTimer = setInterval(() => {\n if (activePopup.closed) cleanup();\n }, CLOSE_POLL_MS);\n\n return {\n close,\n closed,\n lastSecurity: () => lastSecurity,\n lastAccounts: () => (lastAccounts === undefined ? undefined : copyAccountNames(lastAccounts)),\n };\n}\n"]}
1
+ {"version":3,"sources":["../src/protocol.ts","../src/provider.ts","../src/popup.ts","../src/onboarding.ts","../src/manage.ts"],"names":["request","copyAccountNames","accounts","sequence","active","POPUP_NAME","CLOSE_POLL_MS"],"mappings":";;;AAy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B,QAAA,EAAU,KAAK,IAAA,CAAK,QAAA;AAAA,QACpB,iBAAA,EAAmB,KAAK,IAAA,CAAK;AAAA,OAC/B;AACA,MAAA,YAAA,GAAe,MAAA;AACf,MAAA,OAAA,CAAQ,aAAa,MAAM,CAAA;AAC3B,MAAA;AAAA,IACF;AACA,IAAA,IAAI,iBAAA,CAAkB,IAAI,CAAA,EAAG;AAC3B,MAAA,YAAA,GAAeA,iBAAAA,CAAiB,KAAK,IAAI,CAAA;AACzC,MAAA,OAAA,CAAQ,UAAA,GAAaA,iBAAAA,CAAiB,YAAY,CAAC,CAAA;AAAA,IACrD;AAAA,EACF;AAEA,EAAA,YAAA,CAAa,gBAAA,CAAiB,WAAW,SAAS,CAAA;AAClD,EAAA,UAAA,GAAa,YAAY,MAAM;AAC7B,IAAA,IAAI,WAAA,CAAY,QAAQ,OAAA,EAAQ;AAAA,EAClC,GAAGK,cAAa,CAAA;AAEhB,EAAA,OAAO;AAAA,IACL,KAAA;AAAA,IACA,MAAA;AAAA,IACA,cAAc,MAAM,YAAA;AAAA,IACpB,cAAc,MAAO,YAAA,KAAiB,MAAA,GAAY,MAAA,GAAYL,kBAAiB,YAAY;AAAA,GAC7F;AACF","file":"index.cjs","sourcesContent":["/**\n * The pop-up protocol between a partner page (the opener) and the Assetera Wallet (the pop-up) — ADR-0054 D3/D4.\n *\n * This file is the CONTRACT. The connector in this package speaks the opener side; AsseteraWalletFront's\n * `/connect` page speaks the pop-up side and imports these types from `@asseteragmbh/wallet-connector/protocol`.\n * Change it only in a backwards-compatible way, or bump `PROTOCOL_VERSION` and support both on the wallet side:\n * partner sites upgrade on their own schedule.\n *\n * ## The handshake\n *\n * 1. The partner opens `${walletUrl}${CONNECT_PATH}?origin=<partner origin>&v=<version>` from a user click.\n * 2. The pop-up checks the claimed origin against its allowlist (D4). If listed, it posts `ready` to\n * `window.opener` with `targetOrigin` = that origin. The browser delivers it ONLY if the opener really is\n * that origin, so a page cannot claim someone else's origin and still hear the answer.\n * 3. The opener waits for `ready` from the wallet origin, then sends `request`s with `targetOrigin` = the wallet\n * origin. The pop-up accepts a message only when `event.origin` is the allowed origin from step 2 AND\n * `event.source === window.opener`, and answers with `targetOrigin` = that origin. Nothing else is accepted.\n *\n * ## Sign-in hint\n *\n * A partner may tell the wallet how the client signed in at the partner, through the optional `signIn` URL\n * parameter (`SIGN_IN_HINTS`). The hint only names an identity provider: the wallet checks it against its own\n * list, may ignore it and then falls back to its own login page. The hint never carries a token, an identity or\n * any other credential.\n *\n * ## Lifetime\n *\n * The pop-up is not guaranteed to stay open. The wallet site may close the `/connect` pop-up after it connected\n * or answered a request. The provider keeps the last `accounts` and `chainId` it saw, so the partner page still\n * looks connected after the pop-up closes, and it opens the pop-up again on the next request from a user click.\n * A partner that needs the same pop-up across several requests of one flow can hold it open with `hold`, see\n * below. (ADR-0054, \"the wallet tab must stay open\", no longer holds.)\n *\n * ## Hold\n *\n * The partner may send `hold` to a `/connect` pop-up. `hold: true` asks the wallet to stay open between\n * requests of one multi-step flow. `hold: false` ends the hold.\n *\n * The wallet accepts `hold` only under the same rule as `request`: `event.origin` is the verified partner origin\n * AND `event.source === window.opener`.\n *\n * `hold: true` is idempotent. Each one, and each request, restarts the `HOLD_MAX_MS` cap.\n *\n * After `hold: false` (or after the cap), the normal idle close applies: the wallet may close itself a short\n * time after the last answered request when nothing is pending.\n *\n * A hold never keeps a request open and never answers anything. It only stops the idle close.\n *\n * The partner sends `hold: true` again after each `ready` of a new pop-up while its hold is active.\n *\n * `/onboard` and `/manage` ignore `hold`.\n *\n * ## Onboarding\n *\n * Onboarding is a second flow on the same wallet origin, for a partner that wants the client to get an Assetera\n * Wallet (a new one, or the one the client already has). The partner opens\n * `${walletUrl}${ONBOARD_PATH}?origin=<partner origin>&v=<version>&chain=<CAIP-2 chain id>[&add=1]` from a user\n * click. The pop-up checks the claimed origin against its partner list, signs the client in through SSO, runs the\n * wizard (accept the wallet terms, create the wallet) and then posts `onboarded` (or `onboard-cancelled`) to\n * `window.opener` with `targetOrigin` = the partner origin. `add=1` asks for one more wallet even when the client\n * already has one.\n *\n * After `onboarded` the pop-up STAYS OPEN and answers `request` messages for `personal_sign` by the onboarded\n * address (plus `eth_accounts` and `eth_chainId`), with the same `response` messages as `/connect`. That is how\n * the partner gets the ownership signature it needs to register the wallet with its own compliance service: the\n * wallet itself never calls a regulated service (ADR-0059 D3), and a second `window.open` after an asynchronous\n * step would be blocked by the browser. The partner closes the pop-up when it is done.\n *\n * The opener accepts messages only when `event.origin` is the wallet origin AND `event.source` is the pop-up\n * it opened. The wizard never returns a private key or a token, only the wallet address and signatures the\n * client approved.\n *\n * ## Manage\n *\n * The partner can open `${walletUrl}${MANAGE_PATH}?origin=<partner origin>&v=<version>[&lang=<locale>][&signIn=<hint>]`\n * from a user click, so the client can see and change the wallet accounts and the wallet security (passkeys,\n * authenticator app, recovery codes). The pop-up checks the claimed origin against its partner list, posts\n * `ready` to `window.opener` (the same message as `/connect`) and then posts `security` messages. It never\n * answers `request` messages.\n *\n * ## Account names\n *\n * While a pop-up is open it may also post `accounts` messages. Each entry names one account the client has\n * already shared with THIS partner, so the partner can show a name next to the address. The wallet never sends\n * an account the partner does not already know. A manage pop-up may send the message, and an onboarding pop-up\n * may send it after it reported the address. The message is only sent while a pop-up is open, never on request\n * of the partner. It carries no token and no other data.\n */\n\nexport const PROTOCOL_VERSION = 1 as const;\n\n/** The pop-up route on the wallet origin. */\nexport const CONNECT_PATH = \"/connect\";\n\n/** The onboarding wizard route on the wallet origin. */\nexport const ONBOARD_PATH = \"/onboard\";\n\n/** The manage wallet route on the wallet origin. */\nexport const MANAGE_PATH = \"/manage\";\n\n/** The identity providers a partner can name in the `signIn` hint. */\nexport const SIGN_IN_HINTS = [\"assetera-marketplace\"] as const;\n\n/** A named identity provider the wallet may use for a silent sign-in. */\nexport type SignInHint = (typeof SIGN_IN_HINTS)[number];\n\n/** True when `value` is one of {@link SIGN_IN_HINTS}. */\nexport function isSignInHint(value: unknown): value is SignInHint {\n return (SIGN_IN_HINTS as readonly unknown[]).includes(value);\n}\n\n/** Every message carries this prefix in `type`, so both sides can ignore unrelated `postMessage` traffic. */\nexport const MESSAGE_PREFIX = \"assetera-wallet:\" as const;\n\n/**\n * The most time the wallet keeps a held pop-up open since the last `hold: true` message or the last request.\n * After it, the normal idle close applies again, so a hold that is never released cannot keep the window open\n * forever. Five minutes.\n */\nexport const HOLD_MAX_MS = 300_000;\n\n/**\n * The EIP-1193 methods the pop-up answers (ADR-0054 D3). Anything else is refused with 4200. Read-only chain\n * calls (`eth_call`, `eth_getBalance`, …) do not go through the pop-up; wagmi sends them to its own transports.\n */\nexport const SUPPORTED_METHODS = [\n \"eth_requestAccounts\",\n \"eth_accounts\",\n \"eth_chainId\",\n \"wallet_switchEthereumChain\",\n \"personal_sign\",\n \"eth_signTypedData_v4\",\n \"eth_sendTransaction\",\n] as const;\n\nexport type SupportedMethod = (typeof SUPPORTED_METHODS)[number];\n\nexport function isSupportedMethod(method: string): method is SupportedMethod {\n return (SUPPORTED_METHODS as readonly string[]).includes(method);\n}\n\n/** EIP-1193 / EIP-1474 error codes the pop-up uses. */\nexport const RpcErrorCode = {\n /** The client rejected the request in the pop-up. */\n UserRejected: 4001,\n /** Not connected yet (no `eth_requestAccounts` approved in this pop-up). */\n Unauthorized: 4100,\n /** The method is not in SUPPORTED_METHODS. */\n UnsupportedMethod: 4200,\n /** The pop-up closed, or the wallet session ended. */\n Disconnected: 4900,\n /** `wallet_switchEthereumChain` to a chain the wallet does not offer. */\n UnrecognizedChain: 4902,\n /** Malformed params. */\n InvalidParams: -32602,\n /** Anything unexpected inside the wallet. */\n Internal: -32603,\n} as const;\n\nexport type RpcErrorCode = (typeof RpcErrorCode)[keyof typeof RpcErrorCode];\n\nexport interface RpcError {\n code: number;\n message: string;\n data?: unknown;\n}\n\n// --- pop-up → opener ---------------------------------------------------------------------------------\n\n/** The pop-up is loaded and accepts requests from this opener. */\nexport interface ReadyMessage {\n type: `${typeof MESSAGE_PREFIX}ready`;\n v: typeof PROTOCOL_VERSION;\n /** Shown to the partner for diagnostics only; the partner must not rely on it for anything. */\n walletVersion?: string;\n}\n\n/** The answer to one `request`, matched by `id`. Exactly one of `result` / `error`. */\nexport type ResponseMessage =\n | { type: `${typeof MESSAGE_PREFIX}response`; v: typeof PROTOCOL_VERSION; id: string; result: unknown }\n | { type: `${typeof MESSAGE_PREFIX}response`; v: typeof PROTOCOL_VERSION; id: string; error: RpcError };\n\n/** EIP-1193 provider events, forwarded to the partner. */\nexport type EventMessage =\n | {\n type: `${typeof MESSAGE_PREFIX}event`;\n v: typeof PROTOCOL_VERSION;\n event: \"accountsChanged\";\n data: `0x${string}`[];\n }\n | {\n type: `${typeof MESSAGE_PREFIX}event`;\n v: typeof PROTOCOL_VERSION;\n event: \"chainChanged\";\n data: `0x${string}`;\n }\n | {\n type: `${typeof MESSAGE_PREFIX}event`;\n v: typeof PROTOCOL_VERSION;\n event: \"disconnect\";\n data: RpcError;\n };\n\n/**\n * How well the client's Assetera Wallet is protected. The values are the ones the wallet site shows:\n *\n * - `add-factor`: there is no passkey and no authenticator app yet.\n * - `save-codes`: recovery codes exist, but the client has not confirmed saving them.\n * - `create-codes`: a factor exists, but there are no recovery codes.\n * - `protected`: a factor exists and the recovery codes are saved.\n * - `unknown`: the wallet could not read the state.\n */\nexport type WalletProtection = \"unknown\" | \"add-factor\" | \"save-codes\" | \"create-codes\" | \"protected\";\n\n/** The wallet security status sent by a manage (or connect) pop-up. */\nexport interface WalletSecurityStatus {\n /** Overall result, the same values the wallet site shows. */\n protection: WalletProtection;\n /** Passkeys registered for signing (Dynamic step-up), not sign-in factors. */\n passkeys: number;\n /** Authenticator apps (TOTP) registered for signing (Dynamic step-up). */\n authenticatorApps: number;\n}\n\n/**\n * The wallet reports the security status while a pop-up is open. The partner cannot ask for it. It never\n * carries a token, an identity or a credential.\n */\nexport interface SecurityMessage {\n type: `${typeof MESSAGE_PREFIX}security`;\n v: typeof PROTOCOL_VERSION;\n data: WalletSecurityStatus;\n}\n\n/** One account of the Assetera Wallet that the client already shared with this partner, with its name. */\nexport interface WalletAccountName {\n address: `0x${string}`;\n name: string;\n}\n\n/**\n * The wallet reports the names of the accounts the client already shared with this partner. The partner cannot\n * ask for it and the wallet never names an account the partner does not already know. It never carries a token\n * or any other data.\n */\nexport interface AccountsMessage {\n type: `${typeof MESSAGE_PREFIX}accounts`;\n v: typeof PROTOCOL_VERSION;\n data: WalletAccountName[];\n}\n\n/**\n * The onboarding wizard finished: the client accepted the wallet terms and has an Assetera Wallet on `chain`.\n * `created` is `true` when the wallet was created in this run, `false` when the wizard returned the client's\n * existing wallet. The wallet is not registered with any compliance service; that is the partner's step.\n */\nexport interface OnboardedMessage {\n type: `${typeof MESSAGE_PREFIX}onboarded`;\n v: typeof PROTOCOL_VERSION;\n address: `0x${string}`;\n chain: string;\n created: boolean;\n /**\n * @deprecated Sent by wallet versions that registered the wallet themselves (before ADR-0059). Ignored.\n */\n status?: \"approved\" | \"pending\";\n}\n\n/** The onboarding wizard did not produce a wallet. `message` is optional diagnostics for the partner. */\nexport interface OnboardCancelledMessage {\n type: `${typeof MESSAGE_PREFIX}onboard-cancelled`;\n v: typeof PROTOCOL_VERSION;\n reason: \"user\" | \"refused\" | \"error\";\n message?: string;\n}\n\nexport type WalletToPartnerMessage =\n | ReadyMessage\n | ResponseMessage\n | EventMessage\n | SecurityMessage\n | AccountsMessage\n | OnboardedMessage\n | OnboardCancelledMessage;\n\n// --- opener → pop-up ---------------------------------------------------------------------------------\n\nexport interface RequestMessage {\n type: `${typeof MESSAGE_PREFIX}request`;\n v: typeof PROTOCOL_VERSION;\n /** Unique per request within one connection; the response carries it back. */\n id: string;\n method: string;\n params?: unknown[] | Record<string, unknown>;\n}\n\n/** The partner disconnects (for example the user clicked \"Disconnect\" in the partner page). */\nexport interface DisconnectMessage {\n type: `${typeof MESSAGE_PREFIX}disconnect`;\n v: typeof PROTOCOL_VERSION;\n}\n\n/**\n * The partner asks the wallet to keep the pop-up open between requests of one multi-step flow, or to stop\n * holding it. The wallet accepts it only from the verified partner origin and only from `window.opener`.\n */\nexport interface HoldMessage {\n type: `${typeof MESSAGE_PREFIX}hold`;\n v: typeof PROTOCOL_VERSION;\n /** `true`: keep the pop-up open between requests. `false`: the hold ends. */\n hold: boolean;\n}\n\nexport type PartnerToWalletMessage = RequestMessage | DisconnectMessage | HoldMessage;\n\n// --- guards ------------------------------------------------------------------------------------------\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null;\n}\n\nfunction hasType(value: unknown, suffix: string): value is Record<string, unknown> {\n return isRecord(value) && value.type === `${MESSAGE_PREFIX}${suffix}` && value.v === PROTOCOL_VERSION;\n}\n\nexport function isReadyMessage(value: unknown): value is ReadyMessage {\n return hasType(value, \"ready\");\n}\n\nexport function isResponseMessage(value: unknown): value is ResponseMessage {\n return (\n hasType(value, \"response\") &&\n typeof value.id === \"string\" &&\n (\"result\" in value || (isRecord(value.error) && typeof value.error.code === \"number\"))\n );\n}\n\nexport function isEventMessage(value: unknown): value is EventMessage {\n return (\n hasType(value, \"event\") &&\n (value.event === \"accountsChanged\" || value.event === \"chainChanged\" || value.event === \"disconnect\")\n );\n}\n\nconst WALLET_PROTECTIONS: readonly WalletProtection[] = [\n \"unknown\",\n \"add-factor\",\n \"save-codes\",\n \"create-codes\",\n \"protected\",\n];\n\n/** A factor count: a whole number, zero or more. */\nfunction isCount(value: unknown): value is number {\n return typeof value === \"number\" && Number.isInteger(value) && value >= 0;\n}\n\n/** True for a `security` message with a known `protection` value and whole, non-negative factor counts. */\nexport function isSecurityMessage(value: unknown): value is SecurityMessage {\n if (!hasType(value, \"security\")) return false;\n const data = value.data;\n return (\n isRecord(data) &&\n typeof data.protection === \"string\" &&\n (WALLET_PROTECTIONS as readonly string[]).includes(data.protection) &&\n isCount(data.passkeys) &&\n isCount(data.authenticatorApps)\n );\n}\n\n/** The largest number of accounts one `accounts` message may carry. */\nconst MAX_ACCOUNT_NAMES = 50;\n\n/** True when `value` has a control character: C0, DEL or C1. */\nfunction hasControlCharacter(value: string): boolean {\n for (const character of value) {\n const code = character.codePointAt(0) ?? 0;\n if (code <= 0x1f || (code >= 0x7f && code <= 0x9f)) return true;\n }\n return false;\n}\n\n/** A name: a string whose trimmed length is 1 to 64 and that has no control characters. */\nfunction isAccountName(value: unknown): value is string {\n if (typeof value !== \"string\") return false;\n if (hasControlCharacter(value)) return false;\n const trimmed = value.trim();\n return trimmed.length >= 1 && trimmed.length <= 64;\n}\n\n/** True for an `accounts` message with at most 50 named accounts. */\nexport function isAccountsMessage(value: unknown): value is AccountsMessage {\n if (!hasType(value, \"accounts\")) return false;\n const data = value.data;\n return (\n Array.isArray(data) &&\n data.length <= MAX_ACCOUNT_NAMES &&\n data.every(\n (entry: unknown) =>\n isRecord(entry) &&\n typeof entry.address === \"string\" &&\n EVM_ADDRESS_RE.test(entry.address) &&\n isAccountName(entry.name),\n )\n );\n}\n\nexport function isRequestMessage(value: unknown): value is RequestMessage {\n return hasType(value, \"request\") && typeof value.id === \"string\" && typeof value.method === \"string\";\n}\n\nexport function isDisconnectMessage(value: unknown): value is DisconnectMessage {\n return hasType(value, \"disconnect\");\n}\n\nexport function isHoldMessage(value: unknown): value is HoldMessage {\n return hasType(value, \"hold\") && typeof value.hold === \"boolean\";\n}\n\n/** `0x` followed by exactly 40 hexadecimal digits, the shape of an EVM address. */\nconst EVM_ADDRESS_RE = /^0x[0-9a-fA-F]{40}$/;\n\nexport function isOnboardedMessage(value: unknown): value is OnboardedMessage {\n return (\n hasType(value, \"onboarded\") &&\n typeof value.address === \"string\" &&\n EVM_ADDRESS_RE.test(value.address) &&\n typeof value.chain === \"string\" &&\n // `created` is new; an older wallet sent `status` instead and always created or reused a wallet.\n (typeof value.created === \"boolean\" || value.status === \"approved\" || value.status === \"pending\")\n );\n}\n\nexport function isOnboardCancelledMessage(value: unknown): value is OnboardCancelledMessage {\n return (\n hasType(value, \"onboard-cancelled\") &&\n (value.reason === \"user\" || value.reason === \"refused\" || value.reason === \"error\")\n );\n}\n\n/** A CAIP-2 EVM chain id, for example `eip155:80002` (Polygon Amoy) or `eip155:1` (mainnet). */\nexport function isCaip2EvmChain(value: string): boolean {\n return /^eip155:\\d{1,32}$/.test(value);\n}\n\n/**\n * The URL the partner opens. `partnerOrigin` is `window.location.origin` of the partner page. `signIn` adds the\n * optional sign-in hint; it is only a hint and the wallet may ignore it.\n */\nexport function connectUrl(walletUrl: string, partnerOrigin: string, signIn?: SignInHint): string {\n const url = new URL(CONNECT_PATH, walletUrl);\n url.searchParams.set(\"origin\", partnerOrigin);\n url.searchParams.set(\"v\", String(PROTOCOL_VERSION));\n if (signIn !== undefined) url.searchParams.set(\"signIn\", signIn);\n return url.toString();\n}\n\n/**\n * The URL the partner opens for the onboarding wizard. `partnerOrigin` is `window.location.origin` of the\n * partner page; `chain` is the CAIP-2 chain id the new wallet should be created on; `locale` is passed as `lang`\n * when the partner wants a specific wizard language. `signIn` adds the optional sign-in hint; it is only a hint\n * and the wallet may ignore it.\n */\nexport function onboardUrl(\n walletUrl: string,\n partnerOrigin: string,\n options: { chain: string; locale?: string; add?: boolean; signIn?: SignInHint },\n): string {\n const url = new URL(ONBOARD_PATH, walletUrl);\n url.searchParams.set(\"origin\", partnerOrigin);\n url.searchParams.set(\"v\", String(PROTOCOL_VERSION));\n url.searchParams.set(\"chain\", options.chain);\n if (options.locale !== undefined) url.searchParams.set(\"lang\", options.locale);\n if (options.add) url.searchParams.set(\"add\", \"1\");\n if (options.signIn !== undefined) url.searchParams.set(\"signIn\", options.signIn);\n return url.toString();\n}\n\n/**\n * The URL the partner opens to manage the wallet. `partnerOrigin` is `window.location.origin` of the partner\n * page. `locale` is passed as `lang` when the partner wants a specific language. `signIn` adds the optional\n * sign-in hint; it is only a hint and the wallet may ignore it.\n */\nexport function manageUrl(\n walletUrl: string,\n partnerOrigin: string,\n options: { locale?: string; signIn?: SignInHint } = {},\n): string {\n const url = new URL(MANAGE_PATH, walletUrl);\n url.searchParams.set(\"origin\", partnerOrigin);\n url.searchParams.set(\"v\", String(PROTOCOL_VERSION));\n if (options.locale !== undefined) url.searchParams.set(\"lang\", options.locale);\n if (options.signIn !== undefined) url.searchParams.set(\"signIn\", options.signIn);\n return url.toString();\n}\n","/**\n * EIP-1193 provider for the Assetera Wallet pop-up — the opener side of the ADR-0054 D3/D4 protocol.\n *\n * The provider owns a single pop-up (`window.open(connectUrl(...), \"assetera-wallet\", ...)`) and speaks the\n * wire format defined in `./protocol`. It never touches Dynamic, React, wagmi or viem, so a partner can use it\n * on its own or through the wagmi / RainbowKit adapters in this package.\n */\nimport {\n MESSAGE_PREFIX,\n PROTOCOL_VERSION,\n RpcErrorCode,\n connectUrl,\n isAccountsMessage,\n isEventMessage,\n isReadyMessage,\n isResponseMessage,\n isSecurityMessage,\n isSupportedMethod,\n type AccountsMessage,\n type DisconnectMessage,\n type EventMessage,\n type HoldMessage,\n type RequestMessage,\n type ResponseMessage,\n type SecurityMessage,\n type SignInHint,\n type WalletAccountName,\n type WalletSecurityStatus,\n} from \"./protocol\";\n\n/** Arguments accepted by `request`, mirroring EIP-1193. */\nexport interface RequestArguments {\n method: string;\n params?: unknown[] | Record<string, unknown>;\n}\n\n/** EIP-1193 provider events emitted by the pop-up, plus the wallet security status and account names. */\nexport type ProviderEvent =\n \"accountsChanged\" | \"chainChanged\" | \"connect\" | \"disconnect\" | \"assetera_security\" | \"assetera_accounts\";\n\n/**\n * Listener shape for EIP-1193 provider events. `never[]` accepts a listener with any concrete parameter list\n * (for example wagmi's `(accounts: string[]) => void`), while internal emission stays type-safe via a cast.\n */\nexport type ProviderListener = (...args: never[]) => void;\n\n/** The EIP-1193 surface returned by {@link createAsseteraWalletProvider}. */\nexport interface AsseteraWalletProvider {\n request(args: RequestArguments): Promise<unknown>;\n on(event: ProviderEvent, listener: ProviderListener): void;\n removeListener(event: ProviderEvent, listener: ProviderListener): void;\n disconnect(): void;\n /**\n * The last security status reported by a wallet pop-up, or `undefined` when none arrived yet. A closed pop-up\n * does not clear it.\n */\n lastSecurityStatus(): WalletSecurityStatus | undefined;\n /**\n * The last account names reported by a wallet pop-up, or `undefined` when none arrived yet. The returned list\n * is a copy. A closed pop-up does not clear it.\n */\n lastAccountNames(): WalletAccountName[] | undefined;\n /**\n * Open the pop-up NOW, inside the caller's click, for a signature that is sent later. Use it when the app must\n * wait for something (a firm quote, a fee) between the click and the signing request: without it, the request\n * would open the pop-up after an `await`, outside the click, and the browser would block it. A later\n * `request` reuses the pop-up. While no request has followed yet, the handle also holds the pop-up open (like\n * {@link holdPopup}), so a pop-up that is already counting down its idle close does not vanish during the\n * wait. The hold ends when the first request sent after this call settles (resolved or rejected), or on\n * `release()`, whichever comes first. Synchronous; it never throws.\n */\n prepareSigning(): PreparedSigning;\n /**\n * Open the pop-up NOW, inside the caller's click, and keep it open until `release()`.\n *\n * Use it when one user click starts several wallet requests with waits between them (approve a token, wait\n * for the approval to mine, sign the terms, send the transaction). The wallet normally closes the pop-up a\n * short time after the last answered request, and a request sent after that would open a new pop-up outside\n * a click, which the browser blocks. `holdPopup()` asks the wallet to keep the current pop-up open between\n * those requests. Call `release()` in a `finally` block.\n *\n * The hold is a request to the wallet, not a guarantee: an older wallet ignores the message, and the wallet\n * caps a hold at `HOLD_MAX_MS` (5 minutes) since the last hold or request. Keep a fallback for a closed\n * pop-up. Synchronous; it never throws.\n */\n holdPopup(): PopupHold;\n}\n\n/** The handle {@link AsseteraWalletProvider.prepareSigning} returns. */\nexport interface PreparedSigning {\n /** `false` when the browser blocked the pop-up. The caller should then ask for another click. */\n readonly opened: boolean;\n /**\n * Give the pop-up back when no request followed (the quote failed, the client cancelled). It ends the hold\n * this handle started and posts `hold: false` when no other hold is active. It closes the pop-up only when\n * THIS call opened it and no request was sent since; otherwise it does nothing. Safe to call more than once.\n */\n release(): void;\n}\n\n/** The handle {@link AsseteraWalletProvider.holdPopup} returns. */\nexport interface PopupHold {\n /** `false` when the browser blocked the pop-up. The caller should then ask for another click. */\n readonly opened: boolean;\n /**\n * End the hold. When no other hold is active the provider posts `hold: false` to the current pop-up. It\n * closes the pop-up only when this call opened it and no request was sent since; otherwise it does nothing.\n * Safe to call more than once.\n */\n release(): void;\n}\n\n/** Options for {@link createAsseteraWalletProvider}. */\nexport interface AsseteraWalletProviderOptions {\n /** Base URL of the wallet origin, e.g. `https://wallet.wallet-staging.assetera.com`. */\n walletUrl: string;\n /** Chain id used before the wallet reports one, and as the local `eth_chainId` fallback. */\n defaultChainId: number;\n /** `window.open` feature string. Defaults to `\"popup,width=420,height=720\"`. */\n popupFeatures?: string;\n /** Sign-in hint passed as `signIn`. Only a hint; the wallet may ignore it. */\n signIn?: SignInHint;\n}\n\n/**\n * EIP-1193 error carrying a JSON-RPC `code` (and optional `data`). This is what every rejected `request`\n * throws, so wagmi maps the wallet's `4001` / `4100` / `4200` / `4900` correctly.\n */\nexport class ProviderRpcError extends Error {\n readonly code: number;\n readonly data?: unknown;\n\n constructor(code: number, message: string, data?: unknown) {\n super(message);\n this.name = \"ProviderRpcError\";\n this.code = code;\n this.data = data;\n }\n}\n\nconst DEFAULT_POPUP_FEATURES = \"popup,width=420,height=720\";\nconst POPUP_NAME = \"assetera-wallet\";\nconst CLOSE_POLL_MS = 500;\n\n/** Methods that show the user a signature / transaction prompt, so the pop-up should be focused first. */\nconst SIGNING_METHODS: ReadonlySet<string> = new Set([\n \"personal_sign\",\n \"eth_signTypedData_v4\",\n \"eth_sendTransaction\",\n]);\n\ninterface PendingRequest {\n resolve: (value: unknown) => void;\n reject: (reason: unknown) => void;\n /** The value of `requestsSent` when this request was sent; orders it against `prepareSigning` holds. */\n sequence: number;\n}\n\ninterface Deferred<T> {\n promise: Promise<T>;\n resolve: (value: T) => void;\n reject: (reason: unknown) => void;\n}\n\nfunction createDeferred<T>(): Deferred<T> {\n let resolve!: (value: T) => void;\n let reject!: (reason: unknown) => void;\n const promise = new Promise<T>((res, rej) => {\n resolve = res;\n reject = rej;\n });\n // The `ready` deferred is rejected when the pop-up closes even if no request is waiting on it; mark the\n // promise as handled so that rejection is not reported as an unhandled promise rejection.\n void promise.catch(() => {});\n return { promise, resolve, reject };\n}\n\nfunction toHexChainId(chainId: number): string {\n return `0x${chainId.toString(16)}`;\n}\n\n/**\n * Create the EIP-1193 provider that talks to the Assetera Wallet pop-up.\n *\n * Call `request` from a user gesture: `eth_requestAccounts` opens the pop-up synchronously (before any\n * `await`) so the browser treats it as part of the click and does not block it.\n */\nexport function createAsseteraWalletProvider(options: AsseteraWalletProviderOptions): AsseteraWalletProvider {\n const { defaultChainId } = options;\n const walletOrigin = new URL(options.walletUrl).origin;\n const popupFeatures = options.popupFeatures ?? DEFAULT_POPUP_FEATURES;\n\n let popup: Window | null = null;\n /** Resolves when the *current* pop-up posts `ready`. Replaced when a new pop-up is opened. */\n let ready = createDeferred<void>();\n let accounts: string[] = [];\n let chainIdHex: string | null = null;\n /** Set when the wallet itself told us the session ended (as opposed to the user merely closing the tab). */\n let walletDisconnected = false;\n /** The last security status a pop-up reported; kept when the pop-up closes. */\n let lastSecurity: WalletSecurityStatus | undefined;\n /** The last account names a pop-up reported; kept when the pop-up closes. */\n let lastAccountNameList: WalletAccountName[] | undefined;\n const pending = new Map<string, PendingRequest>();\n const listeners = new Map<ProviderEvent, Set<(...args: unknown[]) => void>>();\n let closeTimer: ReturnType<typeof setInterval> | null = null;\n /** Counts the requests that need the pop-up, so `prepareSigning().release()` knows whether one followed. */\n let requestsSent = 0;\n /** True once the current pop-up posted `ready`. Reset when a new pop-up opens or the pop-up closes. */\n let popupReady = false;\n /** One token per active hold. A `Set`, so a double release or a `disconnect()` cannot make it negative. */\n const holds = new Set<symbol>();\n /** Hold tokens of `prepareSigning` handles, each with the `requestsSent` value when it was registered. */\n const preparedHolds = new Map<symbol, number>();\n\n function currentChainId(): string {\n return chainIdHex ?? toHexChainId(defaultChainId);\n }\n\n function blockedError(): ProviderRpcError {\n return new ProviderRpcError(\n RpcErrorCode.Disconnected,\n \"The Assetera Wallet pop-up was blocked by the browser. The pop-up must be opened from a user click \" +\n \"(for example a button press) and then the request retried.\",\n );\n }\n\n function disconnectedError(message = \"The Assetera Wallet pop-up was closed.\"): ProviderRpcError {\n return new ProviderRpcError(RpcErrorCode.Disconnected, message);\n }\n\n function emit(event: ProviderEvent, ...args: unknown[]): void {\n const set = listeners.get(event);\n if (!set) return;\n for (const listener of set) {\n try {\n listener(...args);\n } catch (error) {\n console.error(`[assetera-wallet] listener for \"${event}\" threw`, error);\n }\n }\n }\n\n function addListener(event: ProviderEvent, listener: ProviderListener): void {\n let set = listeners.get(event);\n if (!set) {\n set = new Set<(...args: unknown[]) => void>();\n listeners.set(event, set);\n }\n set.add(listener as (...args: unknown[]) => void);\n }\n\n function removeEventListener(event: ProviderEvent, listener: ProviderListener): void {\n listeners.get(event)?.delete(listener as (...args: unknown[]) => void);\n }\n\n /**\n * Tell the current pop-up whether to stay open between requests. Only a ready pop-up can receive the message;\n * a pop-up that is not ready yet gets it in the `ready` handler.\n */\n function postHold(hold: boolean): void {\n const active = popup;\n if (!active || active.closed || !popupReady) return;\n const message: HoldMessage = {\n type: `${MESSAGE_PREFIX}hold`,\n v: PROTOCOL_VERSION,\n hold,\n };\n active.postMessage(message, walletOrigin);\n }\n\n /** Register one hold token. A hold that starts the first hold asks the wallet to stay open. */\n function addHold(token: symbol): void {\n const wasEmpty = holds.size === 0;\n holds.add(token);\n if (wasEmpty) postHold(true);\n }\n\n /** Remove one hold token. Returns `true` when this ended the last hold. */\n function removeHold(token: symbol): boolean {\n if (!holds.delete(token)) return false;\n return holds.size === 0;\n }\n\n /**\n * A request settled. It ends every `prepareSigning` hold that was registered before that request was sent:\n * the pop-up may then idle-close normally again.\n */\n function endPreparedHolds(sequence: number): void {\n let emptied = false;\n for (const [token, registeredAt] of preparedHolds) {\n if (registeredAt >= sequence) continue;\n preparedHolds.delete(token);\n if (removeHold(token)) emptied = true;\n }\n if (emptied) postHold(false);\n }\n\n function stopClosePolling(): void {\n if (closeTimer !== null) {\n clearInterval(closeTimer);\n closeTimer = null;\n }\n }\n\n function startClosePolling(): void {\n if (closeTimer !== null) return;\n closeTimer = setInterval(() => {\n if (popup?.closed) handlePopupClosed();\n }, CLOSE_POLL_MS);\n }\n\n function rejectAllPending(error: ProviderRpcError): void {\n for (const request of pending.values()) {\n request.reject(error);\n endPreparedHolds(request.sequence);\n }\n pending.clear();\n }\n\n /**\n * The pop-up was closed by the user (or the wallet app).\n *\n * We deliberately KEEP `accounts` / `chainIdHex` cached: the dApp stays \"connected\" in React state and does\n * not flicker back to a disconnected UI. Because a pop-up cannot be reopened without a user gesture, the next\n * signing request reopens it from the caller's click. `disconnect` is only emitted when the close actually\n * interrupted work (a request was pending) or when the wallet itself announced the disconnect.\n */\n function handlePopupClosed(): void {\n const hadPending = pending.size > 0;\n stopClosePolling();\n const closedPopup = popup;\n popup = null;\n popupReady = false;\n const closedReady = ready;\n ready = createDeferred<void>();\n const error = disconnectedError();\n if (closedPopup) closedReady.reject(error);\n rejectAllPending(error);\n const shouldEmit = hadPending || walletDisconnected;\n walletDisconnected = false;\n if (shouldEmit) emit(\"disconnect\", error);\n }\n\n /**\n * Open the pop-up, or focus and reuse it when it is still around. Must stay synchronous (it is called before\n * any `await` in `request`) so it runs inside the caller's user activation.\n */\n function openPopup(): Window | null {\n if (popup && !popup.closed) {\n popup.focus();\n return popup;\n }\n if (typeof window === \"undefined\") return null;\n const opened = window.open(\n connectUrl(options.walletUrl, window.location.origin, options.signIn),\n POPUP_NAME,\n popupFeatures,\n );\n if (!opened) return null;\n popup = opened;\n popupReady = false;\n ready = createDeferred<void>();\n walletDisconnected = false;\n startClosePolling();\n return opened;\n }\n\n function sendRequest(\n method: string,\n params: RequestArguments[\"params\"],\n sequence: number,\n ): Promise<unknown> {\n const active = popup;\n if (!active || active.closed) return Promise.reject(disconnectedError());\n const id = crypto.randomUUID();\n const message: RequestMessage = {\n type: `${MESSAGE_PREFIX}request`,\n v: PROTOCOL_VERSION,\n id,\n method,\n ...(params === undefined ? {} : { params }),\n };\n return new Promise<unknown>((resolve, reject) => {\n pending.set(id, { resolve, reject, sequence });\n active.postMessage(message, walletOrigin);\n });\n }\n\n function handleResponse(message: ResponseMessage): void {\n const request = pending.get(message.id);\n if (!request) return;\n pending.delete(message.id);\n endPreparedHolds(request.sequence);\n if (\"error\" in message) {\n request.reject(new ProviderRpcError(message.error.code, message.error.message, message.error.data));\n } else {\n request.resolve(message.result);\n }\n }\n\n function handleEventMessage(message: EventMessage): void {\n if (message.event === \"accountsChanged\") {\n accounts = [...message.data];\n emit(\"accountsChanged\", [...accounts]);\n return;\n }\n if (message.event === \"chainChanged\") {\n chainIdHex = message.data;\n emit(\"chainChanged\", chainIdHex);\n return;\n }\n walletDisconnected = true;\n emit(\"disconnect\", new ProviderRpcError(message.data.code, message.data.message, message.data.data));\n }\n\n function handleSecurityMessage(message: SecurityMessage): void {\n lastSecurity = {\n protection: message.data.protection,\n passkeys: message.data.passkeys,\n authenticatorApps: message.data.authenticatorApps,\n };\n emit(\"assetera_security\", lastSecurity);\n }\n\n /** A copy of a list of named accounts, so callers never get the provider's own list. */\n function copyAccountNames(accounts: readonly WalletAccountName[]): WalletAccountName[] {\n return accounts.map((account) => ({ address: account.address, name: account.name }));\n }\n\n function handleAccountsMessage(message: AccountsMessage): void {\n lastAccountNameList = copyAccountNames(message.data);\n emit(\"assetera_accounts\", copyAccountNames(lastAccountNameList));\n }\n\n function onWindowMessage(event: MessageEvent): void {\n if (event.origin !== walletOrigin) return;\n if (popup === null || (event.source as unknown) !== popup) return;\n const data: unknown = event.data;\n if (isReadyMessage(data)) {\n popupReady = true;\n // A re-opened pop-up needs the hold again; the message is idempotent.\n if (holds.size > 0) postHold(true);\n ready.resolve(undefined);\n return;\n }\n if (isResponseMessage(data)) {\n handleResponse(data);\n return;\n }\n if (isSecurityMessage(data)) {\n handleSecurityMessage(data);\n return;\n }\n if (isAccountsMessage(data)) {\n handleAccountsMessage(data);\n return;\n }\n if (isEventMessage(data)) handleEventMessage(data);\n }\n\n if (typeof window !== \"undefined\") window.addEventListener(\"message\", onWindowMessage);\n\n function request({ method, params }: RequestArguments): Promise<unknown> {\n if (typeof window === \"undefined\") {\n return Promise.reject(\n new ProviderRpcError(\n RpcErrorCode.Disconnected,\n \"The Assetera Wallet provider can only run in a browser.\",\n ),\n );\n }\n // Read-only chain calls go through wagmi's own transports; the pop-up refuses everything else.\n if (!isSupportedMethod(method)) {\n return Promise.reject(\n new ProviderRpcError(\n RpcErrorCode.UnsupportedMethod,\n `The Assetera Wallet pop-up does not support the method \"${method}\".`,\n ),\n );\n }\n // Answered locally, without a pop-up, so wagmi can read the connection before the user clicks.\n if (method === \"eth_accounts\") return Promise.resolve([...accounts]);\n if (method === \"eth_chainId\") return Promise.resolve(currentChainId());\n\n // Opening the pop-up MUST happen synchronously, before the first `await`, to stay in the click.\n if (method === \"eth_requestAccounts\") {\n requestsSent += 1;\n const sequence = requestsSent;\n const active = openPopup();\n if (!active) return Promise.reject(blockedError());\n return ready.promise\n .then(() => sendRequest(\"eth_requestAccounts\", params, sequence))\n .then((result) => {\n accounts = Array.isArray(result) ? (result as string[]) : [];\n emit(\"accountsChanged\", [...accounts]);\n emit(\"connect\", { chainId: currentChainId() });\n return [...accounts];\n });\n }\n\n // Every other supported method needs an approved connection.\n if (accounts.length === 0) {\n return Promise.reject(\n new ProviderRpcError(\n RpcErrorCode.Unauthorized,\n \"Connect to the Assetera Wallet first (eth_requestAccounts).\",\n ),\n );\n }\n requestsSent += 1;\n const sequence = requestsSent;\n const active = openPopup();\n if (!active) return Promise.reject(blockedError());\n if (SIGNING_METHODS.has(method)) active.focus();\n return ready.promise.then(() => sendRequest(method, params, sequence));\n }\n\n function disconnect(): void {\n const active = popup;\n if (active && !active.closed) {\n const message: DisconnectMessage = {\n type: `${MESSAGE_PREFIX}disconnect`,\n v: PROTOCOL_VERSION,\n };\n active.postMessage(message, walletOrigin);\n active.close();\n }\n stopClosePolling();\n popup = null;\n popupReady = false;\n // The pop-up is gone; a hold would only be needed by a new pop-up, and the caller will open one itself.\n holds.clear();\n preparedHolds.clear();\n const closedReady = ready;\n ready = createDeferred<void>();\n closedReady.reject(disconnectedError(\"Disconnected from the Assetera Wallet.\"));\n rejectAllPending(disconnectedError(\"Disconnected from the Assetera Wallet.\"));\n accounts = [];\n chainIdHex = null;\n walletDisconnected = false;\n emit(\"disconnect\", disconnectedError(\"Disconnected from the Assetera Wallet.\"));\n }\n\n function prepareSigning(): PreparedSigning {\n const existed = popup !== null && !popup.closed;\n const active = typeof window === \"undefined\" ? null : openPopup();\n if (!active) return { opened: false, release: () => {} };\n const sentAtPrepare = requestsSent;\n // The prepared handle holds the pop-up until its first request settles, or until `release()`.\n const token = Symbol(\"assetera-wallet-prepare\");\n preparedHolds.set(token, sentAtPrepare);\n addHold(token);\n let released = false;\n return {\n opened: true,\n release() {\n if (released) return;\n released = true;\n preparedHolds.delete(token);\n const emptied = removeHold(token);\n // Only a pop-up this call opened, still open, with nothing sent or waiting since, and no other hold.\n const canClose =\n emptied &&\n !existed &&\n popup === active &&\n !active.closed &&\n requestsSent === sentAtPrepare &&\n pending.size === 0;\n if (canClose) {\n active.close();\n handlePopupClosed();\n return;\n }\n if (emptied) postHold(false);\n },\n };\n }\n\n function holdPopup(): PopupHold {\n const existed = popup !== null && !popup.closed;\n const active = typeof window === \"undefined\" ? null : openPopup();\n if (!active) return { opened: false, release: () => {} };\n const token = Symbol(\"assetera-wallet-hold\");\n const sentAtHold = requestsSent;\n // Adding the first token sends `hold: true` now when the pop-up is ready, otherwise in the `ready` handler.\n addHold(token);\n let released = false;\n return {\n opened: true,\n release() {\n if (released) return;\n released = true;\n const emptied = removeHold(token);\n // Only a pop-up this call opened, still open, with nothing sent or waiting since, and no other hold.\n const canClose =\n emptied &&\n !existed &&\n popup === active &&\n !active.closed &&\n requestsSent === sentAtHold &&\n pending.size === 0;\n if (canClose) {\n active.close();\n handlePopupClosed();\n return;\n }\n if (emptied) postHold(false);\n },\n };\n }\n\n function on(event: ProviderEvent, listener: ProviderListener): void {\n addListener(event, listener);\n }\n\n function removeListener(event: ProviderEvent, listener: ProviderListener): void {\n removeEventListener(event, listener);\n }\n\n /** The last security status a pop-up reported, kept even after the pop-up closed. */\n function lastSecurityStatus(): WalletSecurityStatus | undefined {\n return lastSecurity;\n }\n\n /** The last account names a pop-up reported, kept even after the pop-up closed. */\n function lastAccountNames(): WalletAccountName[] | undefined {\n return lastAccountNameList === undefined ? undefined : copyAccountNames(lastAccountNameList);\n }\n\n return {\n request,\n on,\n removeListener,\n disconnect,\n lastSecurityStatus,\n lastAccountNames,\n prepareSigning,\n holdPopup,\n };\n}\n","/**\n * Small helpers shared by the pop-up openers in this package. They are internal and are not part of the public\n * API through `index.ts`.\n */\n\n/** Default width, in pixels, of the onboarding and manage pop-ups. */\nexport const POPUP_WIDTH = 440;\n\n/** Default height, in pixels, of the onboarding and manage pop-ups. */\nexport const POPUP_HEIGHT = 760;\n\n/**\n * Build the centred `window.open` feature string for a pop-up of the default size. `win` is the opener window:\n * the pop-up is centred over it, and safe defaults are used when the browser does not expose the geometry.\n */\nexport function defaultPopupFeatures(win: Window): string {\n const screenX = Number.isFinite(win.screenX) ? win.screenX : 0;\n const screenY = Number.isFinite(win.screenY) ? win.screenY : 0;\n const outerWidth = Number.isFinite(win.outerWidth) ? win.outerWidth : POPUP_WIDTH;\n const outerHeight = Number.isFinite(win.outerHeight) ? win.outerHeight : POPUP_HEIGHT;\n const left = Math.max(0, Math.round(screenX + (outerWidth - POPUP_WIDTH) / 2));\n const top = Math.max(0, Math.round(screenY + (outerHeight - POPUP_HEIGHT) / 2));\n return `popup,width=${POPUP_WIDTH},height=${POPUP_HEIGHT},left=${left},top=${top}`;\n}\n","/**\n * Onboarding opener for the Assetera Wallet: the partner side of the `/onboard` wizard (AO-1274).\n *\n * A tied-agent bank site shows a \"Create an Assetera wallet\" button. On the click, this module opens the wallet\n * pop-up in onboarding mode synchronously (so the browser treats it as part of the click) and waits for the\n * wizard to post the new wallet address back. While the pop-up is open the partner page shows a dimming\n * overlay; the overlay is plain DOM (no React, no CSS files) so any partner can drop this in. A host can give\n * the overlay its colours and radii (`OverlayTheme`), render its own dialog (`overlay: false` plus\n * `onControls`), or do both.\n *\n * The wallet's `/onboard` page is the pop-up side and speaks the same protocol in `./protocol`, but it uses the\n * message types and the `ONBOARD_PATH` from there, so the two sides cannot drift apart.\n */\nimport {\n MESSAGE_PREFIX,\n PROTOCOL_VERSION,\n RpcErrorCode,\n isAccountsMessage,\n isCaip2EvmChain,\n isOnboardCancelledMessage,\n isOnboardedMessage,\n isResponseMessage,\n onboardUrl,\n type OnboardCancelledMessage,\n type RequestMessage,\n type SignInHint,\n type WalletAccountName,\n} from \"./protocol\";\nimport { defaultPopupFeatures } from \"./popup\";\n\n/** Why {@link openAsseteraOnboarding} rejected. */\nexport type OnboardingErrorCode =\n \"popup_blocked\" | \"closed\" | \"cancelled\" | \"refused\" | \"failed\" | \"invalid_options\";\n\n/** Error thrown (well, rejected) by {@link openAsseteraOnboarding}. `code` is stable and safe to branch on. */\nexport class OnboardingError extends Error {\n readonly code: OnboardingErrorCode;\n\n constructor(code: OnboardingErrorCode, message: string) {\n super(message);\n this.name = \"OnboardingError\";\n this.code = code;\n }\n}\n\n/**\n * The client's Assetera Wallet, with the pop-up still open.\n *\n * The wallet is NOT registered with any compliance service. A regulated partner registers it itself, like any\n * other wallet: fetch a challenge for `address`, pass it to `signMessage`, send the signature to its compliance\n * service, then call `close()`. Always call `close()`: it closes the pop-up and removes the overlay.\n */\nexport interface OnboardingResult {\n address: `0x${string}`;\n chain: string;\n /** `true` when the wallet was created in this run, `false` when the client's existing wallet was returned. */\n created: boolean;\n /**\n * Ask the client to sign `message` (EIP-191 `personal_sign`) with this wallet in the open pop-up. Rejects with\n * `OnboardingError(\"cancelled\")` when the client declines, `\"closed\"` when the pop-up is gone, else `\"failed\"`.\n */\n signMessage: (message: string) => Promise<`0x${string}`>;\n /** Close the pop-up and remove the overlay. Safe to call more than once. */\n close: () => void;\n /**\n * The last account names the pop-up sent after it reported the address, or `undefined` when none arrived yet.\n * The returned list is a copy.\n */\n lastAccounts: () => WalletAccountName[] | undefined;\n}\n\n/** Text of the dimming overlay, all optional. Any key left out keeps its English default. */\nexport interface OverlayLabels {\n title?: string;\n body?: string;\n focus?: string;\n cancel?: string;\n blocked?: string;\n}\n\n/**\n * Colours, radii and font of the dimming overlay, all optional. A key left out keeps the value of the base\n * palette picked by {@link OverlayTheme.scheme} (`\"light\"` unless the host asks for `\"dark\"`).\n *\n * Every value is applied to its own CSS property with `style.setProperty`, so a value can never smuggle in a\n * second declaration. A value the browser cannot parse is dropped and the rest of the overlay stays as it is.\n */\nexport interface OverlayTheme {\n /** Base palette the other keys override. Default `\"light\"`, which is today's look, unchanged. */\n scheme?: \"light\" | \"dark\";\n /** The dimming layer behind the card, a CSS colour. */\n backdrop?: string;\n /** The card background, a CSS colour. */\n surface?: string;\n /** The title colour, a CSS colour. */\n text?: string;\n /** The body text and the Cancel button, a CSS colour. */\n mutedText?: string;\n /** The \"show the wallet window\" button background, a CSS colour. */\n primary?: string;\n /** The \"show the wallet window\" button text, a CSS colour. */\n primaryText?: string;\n /** The card border, CSS `border` shorthand. Default `\"none\"`. */\n border?: string;\n /** The card corner radius, e.g. `\"36px\"`. */\n radius?: string;\n /** The button corner radius, e.g. `\"9999px\"`. */\n buttonRadius?: string;\n /** The overlay font, CSS `font-family`. */\n fontFamily?: string;\n}\n\n/** The text of the overlay plus its optional theme. A plain {@link OverlayLabels} object still works. */\nexport interface OverlayOptions extends OverlayLabels {\n theme?: OverlayTheme;\n}\n\n/**\n * Headless handles for the open onboarding run, handed to {@link OnboardingOptions.onControls} right after the\n * pop-up opened. They let a host with `overlay: false` render its own dialog. Both are safe no-ops after the\n * run finished.\n */\nexport interface OnboardingControls {\n /** Bring the wallet pop-up to the front. */\n focus(): void;\n /** Like the overlay's Cancel button: rejects with `cancelled` before the address arrived, else `close()`. */\n cancel(): void;\n}\n\n/** Options for {@link openAsseteraOnboarding}. */\nexport interface OnboardingOptions {\n /** Base URL of the wallet origin, e.g. `https://wallet.wallet-staging.assetera.com`. */\n walletUrl: string;\n /** CAIP-2 chain id the new wallet should be created on, e.g. `eip155:80002`. An invalid value rejects with `invalid_options`. */\n chain: string;\n /** Wizard language passed as `lang`, e.g. `\"en\"` or `\"de\"`. */\n locale?: string;\n /** `window.open` feature string. Defaults to a centred `\"popup,width=440,height=760,left=…,top=…\"`. */\n popupFeatures?: string;\n /** `true` (default) shows the dimming overlay, `false` hides it, an object overrides its text and theme. */\n overlay?: boolean | OverlayOptions;\n /**\n * Called once, synchronously, right after the pop-up opened, whether or not the overlay is shown. Lets a host\n * with `overlay: false` drive the run from its own dialog.\n */\n onControls?: (controls: OnboardingControls) => void;\n /** Only used in the overlay text, e.g. `\"Musterbank\"`. */\n partnerName?: string;\n /** Ask for one more wallet even when the client already has one (\"Create another Assetera Wallet\"). */\n addWallet?: boolean;\n /** Sign-in hint passed as `signIn`, e.g. `\"assetera-marketplace\"`. Only a hint; the wallet may ignore it. */\n signIn?: SignInHint;\n /** Called for every `accounts` message the pop-up sends after it reported the address. */\n onAccounts?: (accounts: WalletAccountName[]) => void;\n /** Injectable `window` for tests; defaults to `globalThis.window`. */\n window?: Window;\n}\n\nconst POPUP_NAME = \"assetera-wallet-onboarding\";\nconst CLOSE_POLL_MS = 500;\nconst OVERLAY_Z_INDEX = 2147483000;\n\nconst DEFAULT_LABELS: Required<OverlayLabels> = {\n title: \"Continue in the Assetera Wallet window\",\n body: \"A secure Assetera Wallet window is open. Follow the steps there. This page continues by itself when you are done.\",\n focus: \"Show the wallet window\",\n cancel: \"Cancel\",\n blocked: \"Your browser blocked the Assetera Wallet window. Allow pop-ups for this site and try again.\",\n};\n\ninterface OverlayHandlers {\n onFocus: () => void;\n onCancel: () => void;\n}\n\n/** Every theme key resolved, so the overlay builder always has a value to set. */\ntype ResolvedOverlayTheme = Required<OverlayTheme>;\n\n/** Today's look, so an existing host without a theme sees no change at all. */\nconst LIGHT_THEME: ResolvedOverlayTheme = {\n scheme: \"light\",\n backdrop: \"rgba(15,20,30,0.6)\",\n surface: \"#ffffff\",\n text: \"#101828\",\n mutedText: \"#475467\",\n primary: \"#101828\",\n primaryText: \"#ffffff\",\n border: \"none\",\n radius: \"16px\",\n buttonRadius: \"10px\",\n fontFamily: \"system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif\",\n};\n\n/** A neutral dark card for a dark host page. Text and buttons keep WCAG AA contrast on `surface`. */\nconst DARK_THEME: ResolvedOverlayTheme = {\n scheme: \"dark\",\n backdrop: \"rgba(8,10,14,0.72)\",\n surface: \"#1b1d24\",\n text: \"#f7f8fa\",\n mutedText: \"#9aa2b1\",\n primary: \"#ffffff\",\n primaryText: \"#101828\",\n border: \"1px solid rgba(255,255,255,0.14)\",\n radius: \"16px\",\n buttonRadius: \"10px\",\n fontFamily: \"system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif\",\n};\n\n/**\n * Pick the base palette by `scheme` (default `\"light\"`) and let every key the host gave us win over it. Keys the\n * host left out keep the preset value, so `{ scheme: \"dark\", primary: \"#7b61ff\" }` only changes the button.\n */\nfunction resolveTheme(theme: OverlayTheme | undefined): ResolvedOverlayTheme {\n const base = theme?.scheme === \"dark\" ? DARK_THEME : LIGHT_THEME;\n return {\n scheme: base.scheme,\n backdrop: theme?.backdrop ?? base.backdrop,\n surface: theme?.surface ?? base.surface,\n text: theme?.text ?? base.text,\n mutedText: theme?.mutedText ?? base.mutedText,\n primary: theme?.primary ?? base.primary,\n primaryText: theme?.primaryText ?? base.primaryText,\n border: theme?.border ?? base.border,\n radius: theme?.radius ?? base.radius,\n buttonRadius: theme?.buttonRadius ?? base.buttonRadius,\n fontFamily: theme?.fontFamily ?? base.fontFamily,\n };\n}\n\nfunction resolveLabels(options: OnboardingOptions): Required<OverlayLabels> {\n const overrides: OverlayLabels =\n typeof options.overlay === \"object\" && options.overlay !== null ? options.overlay : {};\n const partnerName = options.partnerName;\n const defaultBody = partnerName\n ? `A secure Assetera Wallet window is open for ${partnerName}. Follow the steps there. This page continues by itself when you are done.`\n : DEFAULT_LABELS.body;\n return {\n title: overrides.title ?? DEFAULT_LABELS.title,\n body: overrides.body ?? defaultBody,\n focus: overrides.focus ?? DEFAULT_LABELS.focus,\n cancel: overrides.cancel ?? DEFAULT_LABELS.cancel,\n blocked: overrides.blocked ?? DEFAULT_LABELS.blocked,\n };\n}\n\nfunction resolveThemeOption(options: OnboardingOptions): ResolvedOverlayTheme {\n const overlay: OverlayOptions =\n typeof options.overlay === \"object\" && options.overlay !== null ? options.overlay : {};\n return resolveTheme(overlay.theme);\n}\n\nfunction cancelCode(reason: OnboardCancelledMessage[\"reason\"]): OnboardingErrorCode {\n if (reason === \"user\") return \"cancelled\";\n if (reason === \"refused\") return \"refused\";\n return \"failed\";\n}\n\nfunction cancelMessage(reason: OnboardCancelledMessage[\"reason\"]): string {\n if (reason === \"user\") return \"The user cancelled the Assetera Wallet onboarding.\";\n if (reason === \"refused\") return \"The Assetera Wallet refused the onboarding.\";\n return \"The Assetera Wallet onboarding failed.\";\n}\n\n/** A copy of a list of named accounts, so callers never get the opener's own list. */\nfunction copyAccountNames(accounts: readonly WalletAccountName[]): WalletAccountName[] {\n return accounts.map((account) => ({ address: account.address, name: account.name }));\n}\n\n/**\n * Build the dimming overlay. Text is inserted with `textContent` only. The layout, the z-index and the shadow\n * are fixed inline; every colour, radius and font the host may set goes through `style.setProperty` on its own\n * property, so a host value can never add a second declaration and an unparseable value is simply dropped.\n */\nfunction showOverlay(\n win: Window,\n labels: Required<OverlayLabels>,\n theme: ResolvedOverlayTheme,\n handlers: OverlayHandlers,\n): HTMLElement {\n const doc = win.document;\n const root = doc.createElement(\"div\");\n root.setAttribute(\"role\", \"dialog\");\n root.setAttribute(\"aria-modal\", \"true\");\n root.setAttribute(\"data-assetera-onboarding-overlay\", \"\");\n root.style.cssText = [\n \"position: fixed\",\n \"inset: 0\",\n \"display: flex\",\n \"align-items: center\",\n \"justify-content: center\",\n \"padding: 24px\",\n \"box-sizing: border-box\",\n `z-index: ${OVERLAY_Z_INDEX}`,\n ].join(\"; \");\n root.style.setProperty(\"background-color\", theme.backdrop);\n root.style.setProperty(\"font-family\", theme.fontFamily);\n\n const card = doc.createElement(\"div\");\n card.style.cssText = [\n \"box-sizing: border-box\",\n \"width: 100%\",\n \"max-width: 420px\",\n \"padding: 24px\",\n \"box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35)\",\n ].join(\"; \");\n card.style.setProperty(\"background-color\", theme.surface);\n card.style.setProperty(\"color\", theme.text);\n card.style.setProperty(\"border\", theme.border);\n card.style.setProperty(\"border-radius\", theme.radius);\n\n const title = doc.createElement(\"h2\");\n title.textContent = labels.title;\n title.style.cssText = \"margin: 0 0 10px; font-size: 18px; line-height: 1.3; font-weight: 600;\";\n title.style.setProperty(\"color\", theme.text);\n\n const body = doc.createElement(\"p\");\n body.textContent = labels.body;\n body.style.cssText = \"margin: 0 0 20px; font-size: 14px; line-height: 1.5;\";\n body.style.setProperty(\"color\", theme.mutedText);\n\n const focus = doc.createElement(\"button\");\n focus.type = \"button\";\n focus.textContent = labels.focus;\n focus.style.cssText = [\n \"padding: 10px 16px\",\n \"border: 0\",\n \"font: inherit\",\n \"font-weight: 600\",\n \"cursor: pointer\",\n ].join(\"; \");\n focus.style.setProperty(\"background-color\", theme.primary);\n focus.style.setProperty(\"color\", theme.primaryText);\n focus.style.setProperty(\"border-radius\", theme.buttonRadius);\n focus.addEventListener(\"click\", handlers.onFocus);\n\n const cancel = doc.createElement(\"button\");\n cancel.type = \"button\";\n cancel.textContent = labels.cancel;\n cancel.style.cssText = [\n \"padding: 10px 16px\",\n \"border: 0\",\n \"border-radius: 10px\",\n \"background: transparent\",\n \"font: inherit\",\n \"cursor: pointer\",\n ].join(\"; \");\n cancel.style.setProperty(\"color\", theme.mutedText);\n cancel.style.setProperty(\"border-radius\", theme.buttonRadius);\n cancel.addEventListener(\"click\", handlers.onCancel);\n\n const actions = doc.createElement(\"div\");\n actions.style.cssText = \"display: flex; gap: 8px; align-items: center;\";\n actions.append(focus, cancel);\n\n card.append(title, body, actions);\n root.append(card);\n doc.body.append(root);\n return root;\n}\n\n/**\n * Open the Assetera Wallet onboarding wizard in a pop-up and resolve with the client's wallet, the pop-up still\n * open so the partner can ask for the ownership signature (see {@link OnboardingResult}).\n *\n * Call this from a user click (a button handler). `window.open` runs synchronously inside the call, before any\n * `await`, so the browser allows it; if the browser blocks the pop-up the promise rejects with\n * `OnboardingError(\"popup_blocked\")` and no overlay is shown.\n *\n * The promise rejects with `OnboardingError` and one of these codes: `invalid_options` (bad chain or wallet\n * URL), `popup_blocked`, `closed` (the pop-up was closed first), `cancelled` (the user cancelled in the wizard\n * or in the overlay), `refused` (the wallet refused the onboarding) or `failed` (anything else in the wallet).\n * After it resolved, the overlay stays until `close()`; closing the pop-up by hand also removes it. After it\n * reported the address the pop-up may send `accounts` messages; `onAccounts` receives each list and\n * `lastAccounts()` returns the last one.\n *\n * `overlay` accepts `true` (default), `false`, or an {@link OverlayOptions} object with the overlay text and an\n * {@link OverlayTheme}. With `overlay: false` a host can render its own dialog: {@link OnboardingOptions.onControls}\n * is called once, synchronously, right after the pop-up opened, and its `focus()` and `cancel()` behave like the\n * overlay buttons.\n */\nexport function openAsseteraOnboarding(options: OnboardingOptions): Promise<OnboardingResult> {\n const requestedWindow = options.window ?? (typeof window === \"undefined\" ? undefined : window);\n if (!requestedWindow) {\n return Promise.reject(\n new OnboardingError(\"invalid_options\", \"The Assetera Wallet onboarding can only run in a browser.\"),\n );\n }\n // A non-optional alias so TypeScript keeps the narrowed type inside the callbacks below.\n const targetWindow: Window = requestedWindow;\n if (!isCaip2EvmChain(options.chain)) {\n return Promise.reject(\n new OnboardingError(\n \"invalid_options\",\n `\"${options.chain}\" is not a CAIP-2 EVM chain id (for example \"eip155:80002\").`,\n ),\n );\n }\n let walletOrigin: string;\n try {\n walletOrigin = new URL(options.walletUrl).origin;\n } catch {\n return Promise.reject(\n new OnboardingError(\"invalid_options\", `\"${options.walletUrl}\" is not a valid wallet URL.`),\n );\n }\n\n const labels = resolveLabels(options);\n const theme = resolveThemeOption(options);\n const overlayEnabled = options.overlay !== false;\n\n // MUST stay synchronous, before the first await, so the pop-up runs inside the caller's user activation.\n const popup = targetWindow.open(\n onboardUrl(options.walletUrl, targetWindow.location.origin, {\n chain: options.chain,\n ...(options.locale === undefined ? {} : { locale: options.locale }),\n ...(options.addWallet ? { add: true } : {}),\n ...(options.signIn === undefined ? {} : { signIn: options.signIn }),\n }),\n POPUP_NAME,\n options.popupFeatures ?? defaultPopupFeatures(targetWindow),\n );\n\n if (!popup) {\n // Nothing was opened, so there is nothing to wait for and no overlay: the partner page stays usable.\n return Promise.reject(new OnboardingError(\"popup_blocked\", labels.blocked));\n }\n // A non-optional alias so TypeScript keeps the narrowed type inside the callbacks below.\n const activePopup: Window = popup;\n\n return new Promise<OnboardingResult>((resolve, reject) => {\n // Phase 1 waits for `onboarded`; phase 2 (after it) keeps the pop-up for signature requests until `close()`.\n let onboarded = false;\n let finished = false;\n let closeTimer: ReturnType<typeof setInterval> | null = null;\n let overlay: HTMLElement | null = null;\n const pending = new Map<\n string,\n { resolve: (signature: `0x${string}`) => void; reject: (error: OnboardingError) => void }\n >();\n\n function cleanup(): void {\n finished = true;\n targetWindow.removeEventListener(\"message\", onMessage);\n if (closeTimer !== null) {\n clearInterval(closeTimer);\n closeTimer = null;\n }\n overlay?.remove();\n overlay = null;\n }\n\n function failPending(error: OnboardingError): void {\n for (const entry of pending.values()) entry.reject(error);\n pending.clear();\n }\n\n function close(): void {\n if (finished) return;\n failPending(new OnboardingError(\"closed\", \"The Assetera Wallet window was closed.\"));\n cleanup();\n if (!activePopup.closed) activePopup.close();\n }\n\n function fail(error: OnboardingError): void {\n if (onboarded || finished) return;\n cleanup();\n reject(error);\n }\n\n function cancel(): void {\n if (onboarded) {\n close();\n return;\n }\n activePopup.close();\n fail(new OnboardingError(\"cancelled\", \"The user cancelled the Assetera Wallet onboarding.\"));\n }\n\n // Handed to `onControls` and used by the overlay buttons. Both stay no-ops once the run finished.\n const controls: OnboardingControls = {\n focus(): void {\n if (finished) return;\n activePopup.focus();\n },\n cancel(): void {\n if (finished) return;\n cancel();\n },\n };\n\n function signMessage(message: string): Promise<`0x${string}`> {\n if (finished || activePopup.closed) {\n return Promise.reject(new OnboardingError(\"closed\", \"The Assetera Wallet window was closed.\"));\n }\n const id = globalThis.crypto.randomUUID();\n const request: RequestMessage = {\n type: `${MESSAGE_PREFIX}request`,\n v: PROTOCOL_VERSION,\n id,\n method: \"personal_sign\",\n params: [message, address as `0x${string}`],\n };\n return new Promise((resolveSign, rejectSign) => {\n pending.set(id, { resolve: resolveSign, reject: rejectSign });\n activePopup.focus();\n activePopup.postMessage(request, walletOrigin);\n });\n }\n\n // Set with `onboarded`; `signMessage` is only handed out after that.\n let address: `0x${string}` | undefined;\n /** The last account names the pop-up sent after `onboarded`; kept until `close()`. */\n let lastAccountNameList: WalletAccountName[] | undefined;\n\n function onMessage(event: MessageEvent): void {\n // Trust rule: accept only the wallet origin AND the exact pop-up we opened. Ignore everything else.\n if (event.origin !== walletOrigin) return;\n if ((event.source as unknown) !== activePopup) return;\n const data: unknown = event.data;\n if (!onboarded) {\n if (isOnboardedMessage(data)) {\n onboarded = true;\n address = data.address;\n resolve({\n address: data.address,\n chain: data.chain,\n created: data.created ?? true,\n signMessage,\n close,\n lastAccounts: () =>\n lastAccountNameList === undefined ? undefined : copyAccountNames(lastAccountNameList),\n });\n return;\n }\n if (isOnboardCancelledMessage(data)) {\n fail(new OnboardingError(cancelCode(data.reason), data.message ?? cancelMessage(data.reason)));\n }\n return;\n }\n if (isAccountsMessage(data)) {\n lastAccountNameList = copyAccountNames(data.data);\n options.onAccounts?.(copyAccountNames(lastAccountNameList));\n return;\n }\n if (isResponseMessage(data)) {\n const entry = pending.get(data.id);\n if (!entry) return;\n pending.delete(data.id);\n if (\"error\" in data) {\n entry.reject(\n new OnboardingError(\n data.error.code === RpcErrorCode.UserRejected ? \"cancelled\" : \"failed\",\n data.error.message,\n ),\n );\n } else if (typeof data.result === \"string\" && /^0x[0-9a-fA-F]+$/.test(data.result)) {\n entry.resolve(data.result as `0x${string}`);\n } else {\n entry.reject(new OnboardingError(\"failed\", \"The Assetera Wallet returned no signature.\"));\n }\n }\n }\n\n targetWindow.addEventListener(\"message\", onMessage);\n closeTimer = setInterval(() => {\n if (!activePopup.closed) return;\n if (onboarded) {\n close();\n return;\n }\n fail(\n new OnboardingError(\"closed\", \"The Assetera Wallet window was closed before onboarding finished.\"),\n );\n }, CLOSE_POLL_MS);\n\n if (overlayEnabled) {\n overlay = showOverlay(targetWindow, labels, theme, {\n onFocus: () => controls.focus(),\n onCancel: () => controls.cancel(),\n });\n }\n // After the overlay, so a host that renders its own dialog already sees it (or knows there is none). The\n // call is synchronous, like the `window.open` above: the promise settles only in a later tick.\n options.onControls?.(controls);\n });\n}\n","/**\n * Manage-wallet opener for the Assetera Wallet: the partner side of the `/manage` pop-up (AO-1436).\n *\n * A partner page shows a \"Manage wallet\" button. On the click this module opens the wallet pop-up on the manage\n * route synchronously (so the browser treats it as part of the click). The client sees the wallet accounts and\n * the wallet security (passkeys, authenticator app, recovery codes) and can change them. The pop-up never\n * answers `request` messages; it posts `security` and `accounts` messages while it is open.\n */\nimport {\n isAccountsMessage,\n isSecurityMessage,\n manageUrl,\n type SignInHint,\n type WalletAccountName,\n type WalletSecurityStatus,\n} from \"./protocol\";\nimport { defaultPopupFeatures } from \"./popup\";\n\n/** Why {@link openAsseteraWalletManager} threw. */\nexport type ManagerErrorCode = \"popup_blocked\" | \"invalid_options\";\n\n/** Error thrown by {@link openAsseteraWalletManager}. `code` is stable and safe to branch on. */\nexport class ManagerError extends Error {\n readonly code: ManagerErrorCode;\n\n constructor(code: ManagerErrorCode, message: string) {\n super(message);\n this.name = \"ManagerError\";\n this.code = code;\n }\n}\n\n/** Options for {@link openAsseteraWalletManager}. */\nexport interface WalletManagerOptions {\n /** Base URL of the wallet origin, e.g. `https://wallet.wallet-staging.assetera.com`. */\n walletUrl: string;\n /** Sign-in hint passed as `signIn`, e.g. `\"assetera-marketplace\"`. Only a hint; the wallet may ignore it. */\n signIn?: SignInHint;\n /** Language passed as `lang`, e.g. `\"en\"` or `\"de\"`. */\n locale?: string;\n /** `window.open` feature string. Defaults to a centred `\"popup,width=440,height=760,left=…,top=…\"`. */\n popupFeatures?: string;\n /** Called for every `security` message from the pop-up. */\n onSecurity?: (status: WalletSecurityStatus) => void;\n /** Called for every `accounts` message from the pop-up. */\n onAccounts?: (accounts: WalletAccountName[]) => void;\n /** Injectable `window` for tests; defaults to `globalThis.window`. */\n window?: Window;\n}\n\n/** The open manage pop-up, controlled by the partner. */\nexport interface WalletManager {\n /** Close the pop-up and remove the listener and the close timer. Safe to call more than once. */\n close: () => void;\n /** Resolves when the pop-up is closed, by the partner or by the client. */\n closed: Promise<void>;\n /** The last security status the pop-up sent, or `undefined` when none arrived yet. */\n lastSecurity: () => WalletSecurityStatus | undefined;\n /** The last account names the pop-up sent, or `undefined` when none arrived yet. */\n lastAccounts: () => WalletAccountName[] | undefined;\n}\n\nconst POPUP_NAME = \"assetera-wallet-manage\";\nconst CLOSE_POLL_MS = 500;\n\n/**\n * Open the manage-wallet pop-up for the Assetera Wallet and return a handle to it.\n *\n * Call this from a user click (a button handler). `window.open` runs synchronously inside the call, before any\n * `await`, so the browser allows it; when the browser blocks the pop-up this throws `ManagerError` with code\n * `popup_blocked`.\n *\n * The pop-up checks the `origin` query parameter against the wallet's partner list, posts `ready` to\n * `window.opener` and then posts `security` and `accounts` messages. Messages are accepted only when they come\n * from the wallet origin AND from the pop-up that was opened here. The pop-up does not answer `request`\n * messages.\n */\nexport function openAsseteraWalletManager(options: WalletManagerOptions): WalletManager {\n const requestedWindow = options.window ?? (typeof window === \"undefined\" ? undefined : window);\n if (!requestedWindow) {\n throw new ManagerError(\"invalid_options\", \"The Assetera Wallet manager can only run in a browser.\");\n }\n // A non-optional alias so TypeScript keeps the narrowed type inside the callbacks below.\n const targetWindow: Window = requestedWindow;\n let walletOrigin: string;\n try {\n walletOrigin = new URL(options.walletUrl).origin;\n } catch {\n throw new ManagerError(\"invalid_options\", `\"${options.walletUrl}\" is not a valid wallet URL.`);\n }\n\n // MUST stay synchronous, before any await, so the pop-up runs inside the caller's user activation.\n const popup = targetWindow.open(\n manageUrl(options.walletUrl, targetWindow.location.origin, {\n ...(options.locale === undefined ? {} : { locale: options.locale }),\n ...(options.signIn === undefined ? {} : { signIn: options.signIn }),\n }),\n POPUP_NAME,\n options.popupFeatures ?? defaultPopupFeatures(targetWindow),\n );\n\n if (!popup) {\n throw new ManagerError(\n \"popup_blocked\",\n \"Your browser blocked the Assetera Wallet window. Allow pop-ups for this site and try again.\",\n );\n }\n // A non-optional alias so TypeScript keeps the narrowed type inside the callbacks below.\n const activePopup: Window = popup;\n\n let finished = false;\n let lastSecurity: WalletSecurityStatus | undefined;\n let lastAccounts: WalletAccountName[] | undefined;\n let closeTimer: ReturnType<typeof setInterval> | null = null;\n let resolveClosed!: () => void;\n const closed = new Promise<void>((resolve) => {\n resolveClosed = resolve;\n });\n\n function cleanup(): void {\n if (finished) return;\n finished = true;\n targetWindow.removeEventListener(\"message\", onMessage);\n if (closeTimer !== null) {\n clearInterval(closeTimer);\n closeTimer = null;\n }\n resolveClosed();\n }\n\n function close(): void {\n cleanup();\n if (!activePopup.closed) activePopup.close();\n }\n\n /** A copy of a list of named accounts, so callers never get the manager's own list. */\n function copyAccountNames(accounts: readonly WalletAccountName[]): WalletAccountName[] {\n return accounts.map((account) => ({ address: account.address, name: account.name }));\n }\n\n function onMessage(event: MessageEvent): void {\n // Trust rule: accept only the wallet origin AND the exact pop-up we opened. Ignore everything else.\n if (event.origin !== walletOrigin) return;\n if ((event.source as unknown) !== activePopup) return;\n const data: unknown = event.data;\n if (isSecurityMessage(data)) {\n const status: WalletSecurityStatus = {\n protection: data.data.protection,\n passkeys: data.data.passkeys,\n authenticatorApps: data.data.authenticatorApps,\n };\n lastSecurity = status;\n options.onSecurity?.(status);\n return;\n }\n if (isAccountsMessage(data)) {\n lastAccounts = copyAccountNames(data.data);\n options.onAccounts?.(copyAccountNames(lastAccounts));\n }\n }\n\n targetWindow.addEventListener(\"message\", onMessage);\n closeTimer = setInterval(() => {\n if (activePopup.closed) cleanup();\n }, CLOSE_POLL_MS);\n\n return {\n close,\n closed,\n lastSecurity: () => lastSecurity,\n lastAccounts: () => (lastAccounts === undefined ? undefined : copyAccountNames(lastAccounts)),\n };\n}\n"]}
package/dist/index.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { SignInHint, WalletAccountName, WalletSecurityStatus } from './protocol.cjs';
2
- export { AccountsMessage, CONNECT_PATH, DisconnectMessage, EventMessage, MANAGE_PATH, MESSAGE_PREFIX, ONBOARD_PATH, OnboardCancelledMessage, OnboardedMessage, PROTOCOL_VERSION, PartnerToWalletMessage, ReadyMessage, RequestMessage, ResponseMessage, RpcError, RpcErrorCode, SIGN_IN_HINTS, SUPPORTED_METHODS, SecurityMessage, SupportedMethod, WalletProtection, WalletToPartnerMessage, connectUrl, isAccountsMessage, isCaip2EvmChain, isDisconnectMessage, isEventMessage, isOnboardCancelledMessage, isOnboardedMessage, isReadyMessage, isRequestMessage, isResponseMessage, isSecurityMessage, isSignInHint, isSupportedMethod, manageUrl, onboardUrl } from './protocol.cjs';
3
- export { A as AsseteraWalletProvider, a as AsseteraWalletProviderOptions, P as PreparedSigning, b as ProviderEvent, c as ProviderListener, d as ProviderRpcError, R as RequestArguments, e as createAsseteraWalletProvider } from './provider-CfVvuYbQ.cjs';
2
+ export { AccountsMessage, CONNECT_PATH, DisconnectMessage, EventMessage, HOLD_MAX_MS, HoldMessage, MANAGE_PATH, MESSAGE_PREFIX, ONBOARD_PATH, OnboardCancelledMessage, OnboardedMessage, PROTOCOL_VERSION, PartnerToWalletMessage, ReadyMessage, RequestMessage, ResponseMessage, RpcError, RpcErrorCode, SIGN_IN_HINTS, SUPPORTED_METHODS, SecurityMessage, SupportedMethod, WalletProtection, WalletToPartnerMessage, connectUrl, isAccountsMessage, isCaip2EvmChain, isDisconnectMessage, isEventMessage, isHoldMessage, isOnboardCancelledMessage, isOnboardedMessage, isReadyMessage, isRequestMessage, isResponseMessage, isSecurityMessage, isSignInHint, isSupportedMethod, manageUrl, onboardUrl } from './protocol.cjs';
3
+ export { A as AsseteraWalletProvider, a as AsseteraWalletProviderOptions, P as PopupHold, b as PreparedSigning, c as ProviderEvent, d as ProviderListener, e as ProviderRpcError, R as RequestArguments, f as createAsseteraWalletProvider } from './provider-BjOez2Q4.cjs';
4
4
 
5
5
  /**
6
6
  * Onboarding opener for the Assetera Wallet: the partner side of the `/onboard` wizard (AO-1274).
@@ -8,7 +8,9 @@ export { A as AsseteraWalletProvider, a as AsseteraWalletProviderOptions, P as P
8
8
  * A tied-agent bank site shows a "Create an Assetera wallet" button. On the click, this module opens the wallet
9
9
  * pop-up in onboarding mode synchronously (so the browser treats it as part of the click) and waits for the
10
10
  * wizard to post the new wallet address back. While the pop-up is open the partner page shows a dimming
11
- * overlay; the overlay is plain DOM (no React, no CSS files) so any partner can drop this in.
11
+ * overlay; the overlay is plain DOM (no React, no CSS files) so any partner can drop this in. A host can give
12
+ * the overlay its colours and radii (`OverlayTheme`), render its own dialog (`overlay: false` plus
13
+ * `onControls`), or do both.
12
14
  *
13
15
  * The wallet's `/onboard` page is the pop-up side and speaks the same protocol in `./protocol`, but it uses the
14
16
  * message types and the `ONBOARD_PATH` from there, so the two sides cannot drift apart.
@@ -54,6 +56,52 @@ interface OverlayLabels {
54
56
  cancel?: string;
55
57
  blocked?: string;
56
58
  }
59
+ /**
60
+ * Colours, radii and font of the dimming overlay, all optional. A key left out keeps the value of the base
61
+ * palette picked by {@link OverlayTheme.scheme} (`"light"` unless the host asks for `"dark"`).
62
+ *
63
+ * Every value is applied to its own CSS property with `style.setProperty`, so a value can never smuggle in a
64
+ * second declaration. A value the browser cannot parse is dropped and the rest of the overlay stays as it is.
65
+ */
66
+ interface OverlayTheme {
67
+ /** Base palette the other keys override. Default `"light"`, which is today's look, unchanged. */
68
+ scheme?: "light" | "dark";
69
+ /** The dimming layer behind the card, a CSS colour. */
70
+ backdrop?: string;
71
+ /** The card background, a CSS colour. */
72
+ surface?: string;
73
+ /** The title colour, a CSS colour. */
74
+ text?: string;
75
+ /** The body text and the Cancel button, a CSS colour. */
76
+ mutedText?: string;
77
+ /** The "show the wallet window" button background, a CSS colour. */
78
+ primary?: string;
79
+ /** The "show the wallet window" button text, a CSS colour. */
80
+ primaryText?: string;
81
+ /** The card border, CSS `border` shorthand. Default `"none"`. */
82
+ border?: string;
83
+ /** The card corner radius, e.g. `"36px"`. */
84
+ radius?: string;
85
+ /** The button corner radius, e.g. `"9999px"`. */
86
+ buttonRadius?: string;
87
+ /** The overlay font, CSS `font-family`. */
88
+ fontFamily?: string;
89
+ }
90
+ /** The text of the overlay plus its optional theme. A plain {@link OverlayLabels} object still works. */
91
+ interface OverlayOptions extends OverlayLabels {
92
+ theme?: OverlayTheme;
93
+ }
94
+ /**
95
+ * Headless handles for the open onboarding run, handed to {@link OnboardingOptions.onControls} right after the
96
+ * pop-up opened. They let a host with `overlay: false` render its own dialog. Both are safe no-ops after the
97
+ * run finished.
98
+ */
99
+ interface OnboardingControls {
100
+ /** Bring the wallet pop-up to the front. */
101
+ focus(): void;
102
+ /** Like the overlay's Cancel button: rejects with `cancelled` before the address arrived, else `close()`. */
103
+ cancel(): void;
104
+ }
57
105
  /** Options for {@link openAsseteraOnboarding}. */
58
106
  interface OnboardingOptions {
59
107
  /** Base URL of the wallet origin, e.g. `https://wallet.wallet-staging.assetera.com`. */
@@ -64,8 +112,13 @@ interface OnboardingOptions {
64
112
  locale?: string;
65
113
  /** `window.open` feature string. Defaults to a centred `"popup,width=440,height=760,left=…,top=…"`. */
66
114
  popupFeatures?: string;
67
- /** `true` (default) shows the dimming overlay, `false` hides it, an object overrides its text. */
68
- overlay?: boolean | OverlayLabels;
115
+ /** `true` (default) shows the dimming overlay, `false` hides it, an object overrides its text and theme. */
116
+ overlay?: boolean | OverlayOptions;
117
+ /**
118
+ * Called once, synchronously, right after the pop-up opened, whether or not the overlay is shown. Lets a host
119
+ * with `overlay: false` drive the run from its own dialog.
120
+ */
121
+ onControls?: (controls: OnboardingControls) => void;
69
122
  /** Only used in the overlay text, e.g. `"Musterbank"`. */
70
123
  partnerName?: string;
71
124
  /** Ask for one more wallet even when the client already has one ("Create another Assetera Wallet"). */
@@ -91,6 +144,11 @@ interface OnboardingOptions {
91
144
  * After it resolved, the overlay stays until `close()`; closing the pop-up by hand also removes it. After it
92
145
  * reported the address the pop-up may send `accounts` messages; `onAccounts` receives each list and
93
146
  * `lastAccounts()` returns the last one.
147
+ *
148
+ * `overlay` accepts `true` (default), `false`, or an {@link OverlayOptions} object with the overlay text and an
149
+ * {@link OverlayTheme}. With `overlay: false` a host can render its own dialog: {@link OnboardingOptions.onControls}
150
+ * is called once, synchronously, right after the pop-up opened, and its `focus()` and `cancel()` behave like the
151
+ * overlay buttons.
94
152
  */
95
153
  declare function openAsseteraOnboarding(options: OnboardingOptions): Promise<OnboardingResult>;
96
154
 
@@ -152,4 +210,4 @@ interface WalletManager {
152
210
  */
153
211
  declare function openAsseteraWalletManager(options: WalletManagerOptions): WalletManager;
154
212
 
155
- export { ManagerError, type ManagerErrorCode, OnboardingError, type OnboardingErrorCode, type OnboardingOptions, type OnboardingResult, type OverlayLabels, SignInHint, WalletAccountName, type WalletManager, type WalletManagerOptions, WalletSecurityStatus, openAsseteraOnboarding, openAsseteraWalletManager };
213
+ export { ManagerError, type ManagerErrorCode, type OnboardingControls, OnboardingError, type OnboardingErrorCode, type OnboardingOptions, type OnboardingResult, type OverlayLabels, type OverlayOptions, type OverlayTheme, SignInHint, WalletAccountName, type WalletManager, type WalletManagerOptions, WalletSecurityStatus, openAsseteraOnboarding, openAsseteraWalletManager };