@qntx/wallet 0.13.0 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +145 -22
- package/dist/backup-CLzMs8DP.mjs +51 -0
- package/dist/backup-CLzMs8DP.mjs.map +1 -0
- package/dist/card.d.mts +12 -0
- package/dist/card.mjs +119 -0
- package/dist/card.mjs.map +1 -0
- package/dist/{chains-B-FmFmuV.d.mts → chains-u1M0CWkT.d.mts} +148 -31
- package/dist/chains.d.mts +11 -4
- package/dist/chains.mjs +19 -67
- package/dist/chains.mjs.map +1 -1
- package/dist/{channel-BLwce5hh.mjs → channel-BCZXU3pt.mjs} +105 -44
- package/dist/channel-BCZXU3pt.mjs.map +1 -0
- package/dist/check-C1fUpgva.mjs +193 -0
- package/dist/check-C1fUpgva.mjs.map +1 -0
- package/dist/{core-DaRwkTaV.mjs → core-Cx7p-0nG.mjs} +99 -19
- package/dist/core-Cx7p-0nG.mjs.map +1 -0
- package/dist/hardware-BL6zvhQh.d.mts +107 -0
- package/dist/hardware.d.mts +81 -0
- package/dist/hardware.mjs +446 -0
- package/dist/hardware.mjs.map +1 -0
- package/dist/host.d.mts +27 -19
- package/dist/host.mjs +440 -164
- package/dist/host.mjs.map +1 -1
- package/dist/{index-CEhrd0Pl.d.mts → index-UclKfprm.d.mts} +269 -19
- package/dist/index.d.mts +5 -3
- package/dist/index.mjs +3 -33
- package/dist/{internal-CAKfHjIg.mjs → internal-DwCus_Ws.mjs} +1 -6
- package/dist/internal-DwCus_Ws.mjs.map +1 -0
- package/dist/nostr.d.mts +2 -2
- package/dist/nostr.mjs +14 -14
- package/dist/nostr.mjs.map +1 -1
- package/dist/{protocol-fXHXJguP.mjs → protocol-DLE6lHmP.mjs} +475 -49
- package/dist/protocol-DLE6lHmP.mjs.map +1 -0
- package/dist/protocol.d.mts +5 -4
- package/dist/protocol.mjs +3 -3
- package/dist/secret-CbjbY5-f.mjs +25 -0
- package/dist/secret-CbjbY5-f.mjs.map +1 -0
- package/dist/sessions.d.mts +52 -0
- package/dist/sessions.mjs +71 -0
- package/dist/sessions.mjs.map +1 -0
- package/dist/spark.d.mts +3 -3
- package/dist/spark.mjs +5 -8
- package/dist/spark.mjs.map +1 -1
- package/dist/types-CRnacSqJ.d.mts +390 -0
- package/dist/types.d.mts +2 -2
- package/dist/types.mjs +7 -1
- package/dist/types.mjs.map +1 -1
- package/package.json +27 -13
- package/dist/channel-BLwce5hh.mjs.map +0 -1
- package/dist/core-DaRwkTaV.mjs.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/dist/internal-CAKfHjIg.mjs.map +0 -1
- package/dist/protocol-fXHXJguP.mjs.map +0 -1
- package/dist/secret-CcjyF8D3.mjs +0 -205
- package/dist/secret-CcjyF8D3.mjs.map +0 -1
- package/dist/types-cAQAJBLi.d.mts +0 -260
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol-DLE6lHmP.mjs","names":["evmAddress","opId"],"sources":["../src/protocol/backup.ts","../src/protocol/chains.ts","../src/protocol/card.ts","../src/protocol/hardware.ts","../src/protocol/nostr.ts","../src/protocol/sessions.ts","../src/protocol/spark.ts","../src/protocol/index.ts"],"sourcesContent":["/**\n * Backup-envelope wire validators (design/backup.mdx): the strict structural shape the kernel and\n * the host-side `parseBackupHeader` share — version 3, bounded fields, `obj` rejects unknown keys.\n * Cryptographic checks (the payload tag, factor unwrap) stay in the kernel; these rules only shape\n * the JSON.\n */\nimport { safeTime } from \"./core.ts\";\nimport type { Validator } from \"./validate.ts\";\nimport { arr, int, literal, obj, opt, str, union } from \"./validate.ts\";\n\nconst MAX_FACTOR_CHARS = 512;\nconst MAX_STRING_BYTES = 64_000;\nconst MAX_PAYLOAD_CHARS = 1_400_000; // ~1 MiB of sealed bytes in base64url\nconst MAX_ENVELOPE_CHARS = 4_000_000;\n\nexport type BackupEnvelopeFactor =\n | { readonly kind: \"passkey\"; readonly credentialId: string; readonly sealedBek: string }\n | {\n readonly kind: \"password\";\n /**\n * Argon2id, RFC 9106 second recommended option; fixed, recorded so the file says how to open\n * it.\n */\n readonly kdf: \"argon2id\";\n readonly memoryKiB: 65_536;\n readonly passes: 3;\n readonly lanes: 4;\n readonly salt: string;\n readonly sealedBek: string;\n };\n\nexport type BackupEnvelopeWire = {\n readonly version: 3;\n readonly createdAt: number;\n /** Raw JSON text — authenticated by the payload tag before it is parsed. */\n readonly header: string;\n readonly factors: ReadonlyArray<BackupEnvelopeFactor>;\n readonly payload: string;\n};\n\n/** One public factor entry — shared by the envelope and the retained `backup-key` header. */\nexport const backupEnvelopeFactor: Validator<BackupEnvelopeFactor> = union(\n obj({\n kind: literal(\"passkey\"),\n credentialId: str(MAX_FACTOR_CHARS),\n sealedBek: str(MAX_FACTOR_CHARS),\n }),\n obj({\n kind: literal(\"password\"),\n kdf: literal(\"argon2id\"),\n memoryKiB: literal(65_536),\n passes: literal(3),\n lanes: literal(4),\n salt: str(128),\n sealedBek: str(MAX_FACTOR_CHARS),\n }),\n);\n\nexport const backupEnvelope: Validator<BackupEnvelopeWire> = obj({\n version: literal(3),\n createdAt: int(0, Number.MAX_SAFE_INTEGER),\n header: str(MAX_STRING_BYTES),\n factors: arr(backupEnvelopeFactor, 5, 1),\n payload: str(MAX_PAYLOAD_CHARS),\n});\n\nexport type BackupHeaderWallet = {\n readonly walletId: string;\n readonly origin: \"mnemonic\" | \"passkey\";\n readonly words: 12 | 15 | 18 | 21 | 24;\n /** The wallet has a BIP-39 passphrase; it is never part of the payload. */\n readonly passphrase?: true;\n};\n\nexport type BackupHeaderKey = {\n readonly keyId: string;\n readonly family: \"evm\" | \"solana\" | \"bitcoin\" | \"tron\";\n};\n\nexport type BackupHeaderWire = {\n readonly wallets: ReadonlyArray<BackupHeaderWallet>;\n /** Imported keys carried by the payload; absent when there are none. */\n readonly keys?: ReadonlyArray<BackupHeaderKey>;\n};\n\nexport const backupHeader: Validator<BackupHeaderWire> = obj({\n wallets: arr(\n obj({\n walletId: str(128),\n origin: union(literal(\"mnemonic\"), literal(\"passkey\")),\n words: union(literal(12), literal(15), literal(18), literal(21), literal(24)),\n passphrase: opt(literal(true)),\n }),\n 1000,\n ),\n keys: opt(\n arr(\n obj({\n keyId: str(16, /^[0-9a-f]{16}$/),\n family: union(literal(\"evm\"), literal(\"solana\"), literal(\"bitcoin\"), literal(\"tron\")),\n }),\n 256,\n ),\n ),\n});\n\n/** The whole-envelope text bound — `backup.update` results and `backup.restore` params use it. */\nexport const backupEnvelopeText: Validator<string> = str(MAX_ENVELOPE_CHARS);\n\n/** The status/snapshot summary of a retained backup key — public data only. */\nexport type BackupInfo = {\n readonly id: string; // 32 lowercase hex, HKDF over the BEK\n readonly factors: ReadonlyArray<\"passkey\" | \"password\">;\n readonly createdAt: number;\n};\n\nexport const backupInfo: Validator<BackupInfo> = obj({\n id: str(32, /^[0-9a-f]{32}$/),\n factors: arr(union(literal(\"passkey\"), literal(\"password\")), 5, 1),\n createdAt: safeTime,\n});\n","/**\n * The chains module's method table and wire validators. `wallet.accounts` derives the public\n * account for a template at the wallet's group index — the EVM/Solana/TRON arm returns the address;\n * the Bitcoin arm returns the account xpub plus the master fingerprint and account path (both\n * needed to build the PSBT `bip32Derivation` entries later). The protocol is free of\n *\n * @qntx/wallet-chains imports; template names and path shapes are declared here.\n */\nimport type { VerifyFactor, MethodSpec } from \"./core.ts\";\nimport { verifier, groupIndex, walletId } from \"./core.ts\";\nimport type { Validator } from \"./validate.ts\";\nimport { arr, bool, bytes, int, literal, obj, opt, str, union } from \"./validate.ts\";\n\nexport type ChainTemplate =\n | \"evm.bip44\"\n | \"solana.bip44-change\"\n | \"tron.bip44\"\n | \"btc.bip44\"\n | \"btc.bip49\"\n | \"btc.bip84\"\n | \"btc.bip86\";\n\nexport type ChainAccountsParams = {\n readonly walletId: string;\n readonly groupIndex: number;\n readonly template: ChainTemplate;\n readonly network: string;\n};\n\nexport type ChainAccount =\n | {\n readonly template: \"evm.bip44\";\n readonly network: string;\n readonly address: string;\n /** The serving entry passed an on-device check — always true for seed-custody wallets. */\n readonly confirmed: boolean;\n }\n | {\n readonly template: \"solana.bip44-change\";\n readonly network: string;\n readonly address: string;\n readonly confirmed: boolean;\n }\n | {\n readonly template: \"tron.bip44\";\n readonly network: string;\n readonly address: string;\n readonly confirmed: boolean;\n }\n | {\n readonly template: \"btc.bip44\" | \"btc.bip49\" | \"btc.bip84\" | \"btc.bip86\";\n readonly network: string;\n readonly xpub: string;\n /** Master-key fingerprint as 8 lowercase hex chars (PSBT bip32Derivation). */\n readonly fingerprint: string;\n /** Account derivation path, e.g. \"m/84'/0'/0'\". */\n readonly path: string;\n /** Highest proven change-chain index — the sealed mark the change scan reaches beyond. */\n readonly changeMark: number;\n readonly confirmed: boolean;\n };\n\nexport const template: Validator<ChainTemplate> = union(\n literal(\"evm.bip44\"),\n literal(\"solana.bip44-change\"),\n literal(\"tron.bip44\"),\n union(literal(\"btc.bip44\"), literal(\"btc.bip49\"), literal(\"btc.bip84\")),\n literal(\"btc.bip86\"),\n);\n\nconst btcTemplate = union(\n literal(\"btc.bip44\"),\n literal(\"btc.bip49\"),\n literal(\"btc.bip84\"),\n literal(\"btc.bip86\"),\n);\n\nexport const caip2: Validator<string> = str(200, /^[a-z0-9-]{3,64}:[0-9a-zA-Z-]{1,128}$/);\nconst addressResult = (\n t: \"evm.bip44\" | \"solana.bip44-change\" | \"tron.bip44\",\n address: Validator<string> = str(128, /^[0-9a-zA-Z-]{20,128}$/),\n): Validator<ChainAccount> =>\n obj({ template: literal(t), network: caip2, address, confirmed: bool });\n\nexport type AccountRef =\n | {\n readonly kind: \"hd\";\n readonly walletId: string;\n readonly groupIndex: number;\n readonly template: ChainTemplate;\n }\n | {\n readonly kind: \"imported\";\n readonly keyId: string;\n readonly family: \"evm\" | \"solana\" | \"bitcoin\" | \"tron\";\n };\n\nexport type EvmAccessListEntryWire = {\n readonly address: string;\n readonly storageKeys: ReadonlyArray<string>;\n};\n\ntype EvmTransactionBase = {\n readonly chainId: number;\n readonly nonce: number;\n readonly gas: string;\n readonly value: string;\n readonly data: string;\n readonly to?: string;\n};\n\nexport type EvmTransactionWire =\n | (EvmTransactionBase & { readonly type: \"legacy\"; readonly gasPrice: string })\n | (EvmTransactionBase & {\n readonly type: \"eip2930\";\n readonly gasPrice: string;\n readonly accessList: ReadonlyArray<EvmAccessListEntryWire>;\n })\n | (EvmTransactionBase & {\n readonly type: \"eip1559\";\n readonly maxFeePerGas: string;\n readonly maxPriorityFeePerGas: string;\n readonly accessList: ReadonlyArray<EvmAccessListEntryWire>;\n })\n | (EvmTransactionBase & {\n readonly type: \"eip7702\";\n readonly to: string;\n readonly maxFeePerGas: string;\n readonly maxPriorityFeePerGas: string;\n readonly accessList: ReadonlyArray<EvmAccessListEntryWire>;\n readonly authorization: { readonly address: string };\n });\n\n/** `chain.sign`'s request — the wire mirror of @qntx/wallet-chains `SignRequest`. */\nexport type ChainSignRequest =\n | {\n readonly kind: \"evm.transaction\";\n readonly network: string;\n readonly account: AccountRef;\n readonly tx: EvmTransactionWire;\n }\n | {\n readonly kind: \"evm.personal-message\";\n readonly network: string;\n readonly account: AccountRef;\n readonly message: Uint8Array;\n }\n | {\n readonly kind: \"evm.fiat24-session\";\n readonly network: string;\n readonly account: AccountRef;\n /** The Fiat24 account token's decimal id. */\n readonly tokenId: string;\n /** Session expiry, Unix seconds. */\n readonly deadline: number;\n }\n | {\n readonly kind: \"evm.typed-data\";\n readonly network: string;\n readonly account: AccountRef;\n readonly typedData: string;\n }\n | {\n readonly kind: \"solana.transaction\";\n readonly network: string;\n readonly account: AccountRef;\n readonly message: Uint8Array;\n readonly lookupTables?: ReadonlyArray<{\n readonly address: string;\n readonly addresses: ReadonlyArray<string>;\n }>;\n }\n | {\n readonly kind: \"solana.message\";\n readonly network: string;\n readonly account: AccountRef;\n readonly message: Uint8Array;\n readonly format: \"raw\";\n }\n | {\n readonly kind: \"bitcoin.psbt\";\n readonly network: string;\n /** The wallet group whose keys sign; each signed input names its template. */\n readonly account: {\n readonly kind: \"hd\";\n readonly walletId: string;\n readonly groupIndex: number;\n };\n /** Who built this request — only \"internal\" requests may raise the change mark. */\n readonly origin: \"internal\" | \"external\";\n readonly psbt: Uint8Array;\n readonly sign: ReadonlyArray<{\n readonly index: number;\n readonly template: \"btc.bip44\" | \"btc.bip49\" | \"btc.bip84\" | \"btc.bip86\";\n }>;\n }\n | {\n readonly kind: \"bitcoin.message\";\n readonly network: string;\n readonly account: AccountRef;\n readonly address: string;\n readonly message: string;\n readonly format: \"bip322-simple\" | \"legacy\";\n readonly change: 0 | 1;\n readonly index: number;\n }\n | {\n readonly kind: \"tron.transaction\";\n readonly network: string;\n readonly account: AccountRef;\n readonly rawData: Uint8Array;\n }\n | {\n readonly kind: \"tron.message\";\n readonly network: string;\n readonly account: AccountRef;\n readonly message: Uint8Array;\n }\n | {\n readonly kind: \"tron.typed-data\";\n readonly network: string;\n readonly account: AccountRef;\n /** The canonical TIP-712 document, as JSON text. */\n readonly typedData: string;\n };\n\nexport type ChainSignResult =\n | { readonly kind: \"evm.transaction\"; readonly signedTransaction: Uint8Array }\n | {\n readonly kind: \"evm.personal-message\" | \"evm.fiat24-session\" | \"evm.typed-data\";\n readonly signature: Uint8Array;\n }\n | { readonly kind: \"solana.transaction\" | \"solana.message\"; readonly signature: Uint8Array }\n | { readonly kind: \"bitcoin.psbt\"; readonly signedPsbt: Uint8Array }\n | { readonly kind: \"bitcoin.message\"; readonly signature: string }\n | {\n readonly kind: \"tron.transaction\" | \"tron.message\" | \"tron.typed-data\";\n readonly signature: Uint8Array;\n };\n\nexport type ChainSignParams = { readonly request: ChainSignRequest; readonly verify: VerifyFactor };\n\nconst accountRef: Validator<AccountRef> = union(\n obj({ kind: literal(\"hd\"), walletId, groupIndex, template }),\n obj({\n kind: literal(\"imported\"),\n keyId: str(64, /^[0-9a-f]{8,64}$/),\n family: union(literal(\"evm\"), literal(\"solana\"), literal(\"bitcoin\"), literal(\"tron\")),\n }),\n);\n\nconst hexQuantity = str(66, /^0x[0-9a-fA-F]+$/);\nconst hexData = str(40000, /^0x[0-9a-fA-F]*$/);\nconst evmAddress = str(42, /^0x[0-9a-fA-F]{40}$/);\nconst solanaAddress = str(44, /^[1-9A-HJ-NP-Za-km-z]{32,44}$/);\nconst bitcoinAddress = str(90, /^(bc1|tb1|bcrt1|[13mn2])[a-zA-Z0-9]{4,87}$/);\nconst safeInt = int(0, 9007199254740991);\nconst accessList = arr(\n obj({ address: evmAddress, storageKeys: arr(str(66, /^0x[0-9a-fA-F]{64}$/), 256) }),\n 256,\n);\nconst txBase = {\n chainId: safeInt,\n nonce: safeInt,\n gas: hexQuantity,\n value: hexQuantity,\n data: hexData,\n to: opt(evmAddress),\n};\nconst evmTx: Validator<EvmTransactionWire> = union(\n obj({ ...txBase, type: literal(\"legacy\"), gasPrice: hexQuantity }),\n obj({ ...txBase, type: literal(\"eip2930\"), gasPrice: hexQuantity, accessList }),\n obj({\n ...txBase,\n type: literal(\"eip1559\"),\n maxFeePerGas: hexQuantity,\n maxPriorityFeePerGas: hexQuantity,\n accessList,\n }),\n obj({\n ...txBase,\n type: literal(\"eip7702\"),\n to: evmAddress,\n maxFeePerGas: hexQuantity,\n maxPriorityFeePerGas: hexQuantity,\n accessList,\n authorization: obj({ address: evmAddress }),\n }),\n);\n\nexport const signRequest: Validator<ChainSignRequest> = union(\n obj({ kind: literal(\"evm.transaction\"), network: caip2, account: accountRef, tx: evmTx }),\n obj({\n kind: literal(\"evm.personal-message\"),\n network: caip2,\n account: accountRef,\n message: bytes(0, 65536),\n }),\n obj({\n kind: literal(\"evm.fiat24-session\"),\n network: caip2,\n account: accountRef,\n tokenId: str(78, /^[1-9][0-9]{0,77}$/),\n deadline: int(1, 9007199254740991),\n }),\n obj({\n kind: literal(\"evm.typed-data\"),\n network: caip2,\n account: accountRef,\n typedData: str(1048576),\n }),\n obj({\n kind: literal(\"solana.transaction\"),\n network: caip2,\n account: accountRef,\n message: bytes(1, 4096),\n lookupTables: opt(arr(obj({ address: solanaAddress, addresses: arr(solanaAddress, 256) }), 64)),\n }),\n obj({\n kind: literal(\"solana.message\"),\n network: caip2,\n account: accountRef,\n message: bytes(1, 65536),\n format: literal(\"raw\"),\n }),\n obj({\n kind: literal(\"bitcoin.psbt\"),\n network: caip2,\n account: obj({ kind: literal(\"hd\"), walletId, groupIndex }),\n origin: union(literal(\"internal\"), literal(\"external\")),\n psbt: bytes(1, 131072),\n sign: arr(obj({ index: int(0, 1024), template: btcTemplate }), 1024),\n }),\n obj({\n kind: literal(\"bitcoin.message\"),\n network: caip2,\n account: accountRef,\n address: bitcoinAddress,\n message: str(1048576),\n format: union(literal(\"bip322-simple\"), literal(\"legacy\")),\n change: union(literal(0), literal(1)),\n index: int(0, 2147483647),\n }),\n obj({\n kind: literal(\"tron.transaction\"),\n network: caip2,\n account: accountRef,\n // java-tron TRANSACTION_MAX_BYTE_SIZE is 500 KiB.\n rawData: bytes(1, 512000),\n }),\n obj({\n kind: literal(\"tron.message\"),\n network: caip2,\n account: accountRef,\n message: bytes(1, 65536),\n }),\n obj({\n kind: literal(\"tron.typed-data\"),\n network: caip2,\n account: accountRef,\n typedData: str(1048576),\n }),\n);\n\nexport const signResult: Validator<ChainSignResult> = union(\n obj({ kind: literal(\"evm.transaction\"), signedTransaction: bytes(1, 65536) }),\n obj({\n kind: union(\n literal(\"evm.personal-message\"),\n literal(\"evm.fiat24-session\"),\n literal(\"evm.typed-data\"),\n ),\n signature: bytes(65, 65),\n }),\n obj({\n kind: union(literal(\"solana.transaction\"), literal(\"solana.message\")),\n signature: bytes(64, 64),\n }),\n obj({ kind: literal(\"bitcoin.psbt\"), signedPsbt: bytes(1, 131072) }),\n obj({ kind: literal(\"bitcoin.message\"), signature: str(512) }),\n obj({\n kind: union(literal(\"tron.transaction\"), literal(\"tron.message\"), literal(\"tron.typed-data\")),\n signature: bytes(65, 65),\n }),\n);\n\nexport const chainAccount: Validator<ChainAccount> = union(\n addressResult(\"evm.bip44\"),\n addressResult(\"solana.bip44-change\"),\n addressResult(\"tron.bip44\", str(34, /^T[1-9A-HJ-NP-Za-km-z]{33}$/)),\n obj({\n template: union(\n literal(\"btc.bip44\"),\n literal(\"btc.bip49\"),\n literal(\"btc.bip84\"),\n literal(\"btc.bip86\"),\n ),\n network: caip2,\n xpub: str(111, /^[a-zA-Z0-9]{111}$/),\n fingerprint: str(8, /^[0-9a-f]{8}$/),\n path: str(11, /^m\\/[0-9'/]+$/),\n confirmed: bool,\n changeMark: int(0, 2147483647),\n }),\n);\n\n/**\n * A node `chain.exportAccount` can serve: the EVM account xpub (`m/44'/60'/0'`, MetaMask's\n * crypto-hdkey), a group's signing leaf, or a Bitcoin account xpub (`m/p'/coin'/group'`).\n */\nexport type ChainExportNode =\n | { readonly kind: \"evm.account\" }\n | {\n readonly kind: \"leaf\";\n readonly template: \"evm.bip44\" | \"tron.bip44\" | \"solana.bip44-change\";\n }\n | {\n readonly kind: \"btc.account\";\n readonly template: \"btc.bip44\" | \"btc.bip49\" | \"btc.bip84\" | \"btc.bip86\";\n readonly network: string;\n };\n\nexport type ChainExportParams = {\n readonly walletId: string;\n readonly groupIndex: number;\n readonly nodes: ReadonlyArray<ChainExportNode>;\n readonly verify: VerifyFactor;\n /**\n * Acknowledge exporting nodes a device never confirmed on-screen — the prompt shows one danger\n * row per unconfirmed node. Absent, an unconfirmed node refuses with `approval-required`.\n */\n readonly acknowledgeUnconfirmed?: true;\n};\n\nexport type ChainExportedKey = {\n readonly node: ChainExportNode;\n readonly path: string;\n readonly curve: \"secp256k1\" | \"ed25519\";\n readonly publicKey: Uint8Array;\n /** 32 bytes — present iff the node is an account (evm.account / btc.account). */\n readonly chainCode?: Uint8Array;\n /** 8 lowercase hex chars — present iff `chainCode` is. */\n readonly parentFingerprint?: string;\n};\n\nexport type ChainExportResult = {\n /** Master-key fingerprint as 8 lowercase hex chars. */\n readonly fingerprint: string;\n /** One key per requested node, in the same order. */\n readonly keys: ReadonlyArray<ChainExportedKey>;\n};\n\nexport const exportNode: Validator<ChainExportNode> = union(\n obj({ kind: literal(\"evm.account\") }),\n obj({\n kind: literal(\"leaf\"),\n template: union(literal(\"evm.bip44\"), literal(\"tron.bip44\"), literal(\"solana.bip44-change\")),\n }),\n obj({ kind: literal(\"btc.account\"), template: btcTemplate, network: caip2 }),\n);\n\nconst fingerprint = str(8, /^[0-9a-f]{8}$/);\n\nconst exportedKey: Validator<ChainExportedKey> = obj({\n node: exportNode,\n path: str(32, /^m\\/[0-9'/]+$/),\n curve: union(literal(\"secp256k1\"), literal(\"ed25519\")),\n publicKey: union(bytes(33), bytes(32)),\n chainCode: opt(bytes(32)),\n parentFingerprint: opt(fingerprint),\n});\n\nexport const CHAINS_METHODS: {\n readonly \"wallet.accounts\": MethodSpec<ChainAccountsParams, ChainAccount>;\n readonly \"chain.sign\": MethodSpec<ChainSignParams, ChainSignResult>;\n readonly \"chain.exportAccount\": MethodSpec<ChainExportParams, ChainExportResult>;\n} = {\n \"wallet.accounts\": {\n session: true,\n presence: false,\n params: obj({ walletId, groupIndex, template, network: caip2 }),\n result: chainAccount,\n },\n \"chain.sign\": {\n session: true,\n presence: true,\n params: obj({ request: signRequest, verify: verifier }),\n result: signResult,\n },\n \"chain.exportAccount\": {\n session: true,\n presence: true,\n params: obj({\n walletId,\n groupIndex,\n nodes: arr(exportNode, 4, 1),\n verify: verifier,\n acknowledgeUnconfirmed: opt(literal(true)),\n }),\n result: obj({ fingerprint, keys: arr(exportedKey, 4, 1) }),\n },\n};\n","import type { ChainAccount, ChainSignRequest, ChainSignResult, ChainTemplate } from \"./chains.ts\";\nimport { caip2, chainAccount, signRequest, signResult, template } from \"./chains.ts\";\nimport type { MethodSpec, VerifyFactor } from \"./core.ts\";\nimport { cardId, groupIndex, verifier, walletId } from \"./core.ts\";\n/**\n * The `card.*` command surface: every operation that drives a qntx card is one long-running kernel\n * operation (`card.begin` returns an op id, `card.step` polls the next step, `card.cancel` aborts).\n * A step asks the host for access-code input or a card tap; `done` carries the operation's result.\n * APDUs and access-code bytes never appear here — they stay inside the kernel/reader boundary.\n */\nimport type { NullValue, Validator } from \"./validate.ts\";\nimport { ValidationError, arr, int, literal, obj, opt, str, union } from \"./validate.ts\";\n\nexport type CardInputPurpose =\n | \"access-code\"\n | \"new-access-code\"\n | \"confirm-access-code\"\n | \"short-id\";\n\nexport type CardTapReason = \"any\" | \"source\" | \"target\" | \"member\" | \"retry\";\n\n/** The next thing the host must do for the operation to advance; `done` ends the poll loop. */\nexport type CardStep =\n | {\n readonly kind: \"input\";\n readonly purpose: CardInputPurpose;\n /** Short id (`XXXX-XXXX`) of the card the input belongs to, when the op knows it. */\n readonly card?: string;\n /** Access-code tries left, when the card just reported a failure. */\n readonly remaining?: number;\n }\n | {\n readonly kind: \"tap\";\n readonly reason: CardTapReason;\n /** Short id (`XXXX-XXXX`) of the card to tap, when the op knows it. */\n readonly card?: string;\n /** The response takes seconds; the host must keep the card on the reader. */\n readonly hold?: true;\n }\n | { readonly kind: \"done\"; readonly result: CardOpResult };\n\nexport type CardOperation =\n | { readonly kind: \"status\" }\n | { readonly kind: \"add\"; readonly groups?: number }\n | {\n readonly kind: \"accounts\";\n readonly walletId: string;\n readonly groupIndex: number;\n readonly templates: ReadonlyArray<ChainTemplate>;\n readonly network: string;\n }\n | { readonly kind: \"health\"; readonly walletId: string }\n | { readonly kind: \"change-access\"; readonly walletId: string; readonly remember?: true }\n | {\n readonly kind: \"erase\";\n readonly walletId: string;\n readonly card: string;\n readonly last?: true;\n }\n | {\n readonly kind: \"create\";\n readonly cards: number;\n readonly source:\n | { readonly kind: \"generate\" }\n | { readonly kind: \"wallet\"; readonly walletId: string };\n readonly groups?: number;\n readonly remember?: true;\n }\n | { readonly kind: \"transfer\"; readonly walletId: string }\n | {\n readonly kind: \"reseal\";\n readonly walletId: string;\n readonly card: string;\n readonly member?: string;\n }\n | { readonly kind: \"sign\"; readonly request: ChainSignRequest; readonly remember?: true }\n | { readonly kind: \"forget-access\"; readonly walletId: string };\n\nexport type CardOpResult =\n | {\n readonly kind: \"status\";\n readonly life: \"blank\" | \"loaded\";\n readonly tries: number;\n readonly walletId?: string;\n }\n | { readonly kind: \"sign\"; readonly result: ChainSignResult }\n | { readonly kind: \"accounts\"; readonly accounts: ReadonlyArray<ChainAccount> }\n | { readonly kind: \"add\"; readonly walletId: string }\n | { readonly kind: \"health\"; readonly walletId: string }\n | { readonly kind: \"change-access\"; readonly walletId: string }\n | { readonly kind: \"erase\"; readonly walletId: string }\n | { readonly kind: \"create\"; readonly walletId: string }\n | { readonly kind: \"transfer\"; readonly walletId: string }\n | { readonly kind: \"reseal\"; readonly walletId: string }\n | { readonly kind: \"forget-access\"; readonly walletId: string };\n\n/** `XXXX-XXXX` — the short id printed on a card and shown in prompts. */\nconst shortId = str(9, /^[0-9A-F]{4}-[0-9A-F]{4}$/);\n\nconst opId = str(32, /^[0-9a-f]{32}$/);\n\n/** Rejects a list whose entries repeat — the protocol requires distinct templates. */\nconst distinct = <T>(validator: Validator<ReadonlyArray<T>>): Validator<ReadonlyArray<T>> => {\n return (value) => {\n const list = validator(value);\n if (new Set(list).size !== list.length) {\n throw new ValidationError();\n }\n return list;\n };\n};\n\nconst cardOperation: Validator<CardOperation> = union(\n obj({ kind: literal(\"status\") }),\n obj({ kind: literal(\"add\"), groups: opt(int(1, 20)) }),\n obj({\n kind: literal(\"accounts\"),\n walletId,\n groupIndex,\n templates: distinct(arr(template, 7, 1)),\n network: caip2,\n }),\n obj({ kind: literal(\"health\"), walletId }),\n obj({ kind: literal(\"change-access\"), walletId, remember: opt(literal(true)) }),\n obj({ kind: literal(\"erase\"), walletId, card: cardId, last: opt(literal(true)) }),\n obj({\n kind: literal(\"create\"),\n cards: int(1, 3),\n source: union(obj({ kind: literal(\"generate\") }), obj({ kind: literal(\"wallet\"), walletId })),\n groups: opt(int(1, 20)),\n remember: opt(literal(true)),\n }),\n obj({ kind: literal(\"transfer\"), walletId }),\n obj({ kind: literal(\"reseal\"), walletId, card: cardId, member: opt(cardId) }),\n obj({ kind: literal(\"sign\"), request: signRequest, remember: opt(literal(true)) }),\n obj({ kind: literal(\"forget-access\"), walletId }),\n);\n\nconst cardOpResult: Validator<CardOpResult> = union(\n obj({\n kind: literal(\"status\"),\n life: union(literal(\"blank\"), literal(\"loaded\")),\n tries: int(0, 10),\n walletId: opt(walletId),\n }),\n obj({ kind: literal(\"sign\"), result: signResult }),\n obj({ kind: literal(\"accounts\"), accounts: arr(chainAccount, 64) }),\n obj({ kind: literal(\"add\"), walletId }),\n obj({ kind: literal(\"health\"), walletId }),\n obj({ kind: literal(\"change-access\"), walletId }),\n obj({ kind: literal(\"erase\"), walletId }),\n obj({ kind: literal(\"create\"), walletId }),\n obj({ kind: literal(\"transfer\"), walletId }),\n obj({ kind: literal(\"reseal\"), walletId }),\n obj({ kind: literal(\"forget-access\"), walletId }),\n);\n\nconst cardStep: Validator<CardStep> = union(\n obj({\n kind: literal(\"input\"),\n purpose: union(\n literal(\"access-code\"),\n literal(\"new-access-code\"),\n literal(\"confirm-access-code\"),\n literal(\"short-id\"),\n ),\n card: opt(shortId),\n remaining: opt(int(0, 10)),\n }),\n obj({\n kind: literal(\"tap\"),\n reason: union(\n literal(\"any\"),\n literal(\"source\"),\n literal(\"target\"),\n literal(\"member\"),\n literal(\"retry\"),\n ),\n card: opt(shortId),\n hold: opt(literal(true)),\n }),\n obj({ kind: literal(\"done\"), result: cardOpResult }),\n);\n\nexport type CardBeginParams = { readonly op: CardOperation; readonly verify?: VerifyFactor };\nexport type CardStepParams = { readonly opId: string };\n\nexport const CARD_METHODS: {\n readonly \"card.begin\": MethodSpec<CardBeginParams, { opId: string; step: CardStep }>;\n readonly \"card.step\": MethodSpec<CardStepParams, CardStep>;\n readonly \"card.cancel\": MethodSpec<CardStepParams, NullValue>;\n} = {\n \"card.begin\": {\n session: true,\n presence: true,\n params: obj({ op: cardOperation, verify: opt(verifier) }),\n result: obj({ opId, step: cardStep }),\n },\n \"card.step\": {\n session: true,\n presence: true,\n params: obj({ opId }),\n result: cardStep,\n },\n \"card.cancel\": {\n session: true,\n presence: false,\n params: obj({ opId }),\n result: literal(null),\n },\n};\n","/**\n * The hardware-signer method table and wire types. `hardware.begin` starts one device operation —\n * pair, accounts, sign or verify-address — and runs it until the device needs a host exchange;\n * `hardware.step` answers the pending exchange and runs to the next one; `hardware.cancel` drops\n * the operation. One operation at a time: a new `begin` discards the previous one.\n *\n * The kernel produces logical requests and parses the answers; the host only moves the frames — a\n * QR payload is a UR type plus CBOR, `message` is one logical message on a byte pipe, `compare`\n * asks the user to check an address on the device itself. Everything a device returns is untrusted\n * and re-validated in the kernel.\n */\nimport type { HardwareDevice, WalletInfo } from \"../types.ts\";\nimport type { ChainAccount, ChainSignRequest, ChainSignResult, ChainTemplate } from \"./chains.ts\";\nimport { caip2, chainAccount, signRequest, signResult, template } from \"./chains.ts\";\nimport type { MethodSpec, VerifyFactor } from \"./core.ts\";\nimport { groupIndex, hardwareDevice, verifier, walletId, walletInfo } from \"./core.ts\";\nimport type { NullValue, Validator } from \"./validate.ts\";\nimport { arr, bool, bytes, int, literal, nullValue, obj, opt, str, union } from \"./validate.ts\";\n\nexport type { HardwareDevice } from \"../types.ts\";\n\nexport type QrPayload = { readonly type: string; readonly cbor: Uint8Array };\n\nexport type DeviceRequest =\n | { readonly kind: \"qr\"; readonly show?: QrPayload; readonly scan: ReadonlyArray<string> }\n | { readonly kind: \"message\"; readonly data: Uint8Array }\n | { readonly kind: \"compare\"; readonly address: string; readonly path: string };\n\nexport type DeviceResponse =\n | { readonly kind: \"qr\"; readonly ur: QrPayload }\n | { readonly kind: \"message\"; readonly data: Uint8Array }\n | { readonly kind: \"compare\"; readonly matched: boolean };\n\nexport type DeviceDisplay = \"clear\" | \"blind\";\n\n/** The host transport for one device operation. */\nexport type DeviceIo = {\n /**\n * Carries one kernel-produced exchange: show `request.show` / send `request.data`, then resolve\n * with what the device answered. Rejecting aborts the operation.\n */\n readonly exchange: (\n request: DeviceRequest,\n context: { readonly device: HardwareDevice; readonly display?: DeviceDisplay },\n ) => Promise<DeviceResponse>;\n};\n\nexport type HardwareOperation =\n | { readonly kind: \"pair\"; readonly device: HardwareDevice }\n | {\n readonly kind: \"accounts\";\n readonly walletId: string;\n readonly groupIndex: number;\n readonly templates: ReadonlyArray<ChainTemplate>;\n readonly network: string;\n }\n | {\n readonly kind: \"sign\";\n readonly request: ChainSignRequest;\n /**\n * Acknowledge sending to a key the device never confirmed on-screen — the prompt shows a\n * danger row for the output. Absent, such a send refuses with `approval-required`.\n */\n readonly acknowledgeUnconfirmed?: true;\n }\n | {\n readonly kind: \"verify-address\";\n readonly walletId: string;\n readonly groupIndex: number;\n readonly template: ChainTemplate;\n readonly network: string;\n /** The Bitcoin receive-address index; meaningful only for btc.* templates. */\n readonly index?: number;\n };\n\nexport type HardwareResult =\n | { readonly kind: \"pair\"; readonly wallet: WalletInfo }\n | { readonly kind: \"accounts\"; readonly accounts: ReadonlyArray<ChainAccount> }\n | { readonly kind: \"sign\"; readonly result: ChainSignResult }\n | {\n readonly kind: \"verify-address\";\n readonly address: string;\n readonly method: \"device\" | \"compare\";\n };\n\nexport type HardwareStep =\n | {\n readonly kind: \"exchange\";\n readonly device: HardwareDevice;\n readonly request: DeviceRequest;\n readonly display?: DeviceDisplay;\n }\n | { readonly kind: \"done\"; readonly result: HardwareResult };\n\nconst UR_TYPE = /^[a-z0-9-]{1,64}$/;\nconst DERIVATION_PATH = /^m(\\/[0-9]+'?){1,10}$/;\n\nconst qrPayload: Validator<QrPayload> = obj({\n type: str(64, UR_TYPE),\n cbor: bytes(1, 262_144),\n});\n\nconst deviceRequest: Validator<DeviceRequest> = union(\n obj({ kind: literal(\"qr\"), show: opt(qrPayload), scan: arr(str(64, UR_TYPE), 4, 1) }),\n obj({ kind: literal(\"message\"), data: bytes(1, 65_536) }),\n obj({\n kind: literal(\"compare\"),\n address: str(128, /^.+$/),\n path: str(128, DERIVATION_PATH),\n }),\n);\n\nconst deviceResponse: Validator<DeviceResponse> = union(\n obj({ kind: literal(\"qr\"), ur: qrPayload }),\n obj({ kind: literal(\"message\"), data: bytes(1, 65_536) }),\n obj({ kind: literal(\"compare\"), matched: bool }),\n);\n\nconst deviceDisplay: Validator<DeviceDisplay> = union(literal(\"clear\"), literal(\"blind\"));\n\nconst hardwareOperation: Validator<HardwareOperation> = union(\n obj({ kind: literal(\"pair\"), device: hardwareDevice }),\n obj({\n kind: literal(\"accounts\"),\n walletId,\n groupIndex,\n templates: arr(template, 7, 1),\n network: caip2,\n }),\n obj({\n kind: literal(\"sign\"),\n request: signRequest,\n acknowledgeUnconfirmed: opt(literal(true)),\n }),\n obj({\n kind: literal(\"verify-address\"),\n walletId,\n groupIndex,\n template,\n network: caip2,\n index: opt(int(0, 0x7fffffff)),\n }),\n);\n\nconst hardwareResult: Validator<HardwareResult> = union(\n obj({ kind: literal(\"pair\"), wallet: walletInfo }),\n obj({ kind: literal(\"accounts\"), accounts: arr(chainAccount, 64) }),\n obj({ kind: literal(\"sign\"), result: signResult }),\n obj({\n kind: literal(\"verify-address\"),\n address: str(128, /^.+$/),\n method: union(literal(\"device\"), literal(\"compare\")),\n }),\n);\n\nconst hardwareStep: Validator<HardwareStep> = union(\n obj({\n kind: literal(\"exchange\"),\n device: hardwareDevice,\n request: deviceRequest,\n display: opt(deviceDisplay),\n }),\n obj({ kind: literal(\"done\"), result: hardwareResult }),\n);\n\nconst opId: Validator<string> = str(32, /^[0-9a-f]{32}$/);\n\nexport const HARDWARE_METHODS: {\n readonly \"hardware.begin\": MethodSpec<\n { readonly op: HardwareOperation; readonly verify?: VerifyFactor },\n { readonly opId: string; readonly step: HardwareStep }\n >;\n readonly \"hardware.step\": MethodSpec<\n { readonly opId: string; readonly response: DeviceResponse },\n HardwareStep\n >;\n readonly \"hardware.cancel\": MethodSpec<{ readonly opId: string }, NullValue>;\n} = {\n \"hardware.begin\": {\n session: true,\n presence: true,\n params: obj({ op: hardwareOperation, verify: opt(verifier) }),\n result: obj({ opId, step: hardwareStep }),\n },\n \"hardware.step\": {\n session: true,\n presence: true,\n params: obj({ opId, response: deviceResponse }),\n result: hardwareStep,\n },\n \"hardware.cancel\": {\n session: true,\n presence: false,\n params: obj({ opId }),\n result: nullValue,\n },\n};\n","/**\n * The nostr module's method table and wire validators. The protocol stays free of @qntx/nostr\n * imports — even types — so the event shapes it validates are declared here structurally; a\n * type-level test in packages/wallet/tests pins them assignable to and from @qntx/nostr's\n * Event/UnsignedEvent/Rumor.\n */\nimport type { DerivedNostrKey, NostrKeyInfo, WalletErrorCode } from \"../types.ts\";\nimport {\n verifier,\n identityIndex,\n MAX_BATCH,\n MAX_SNAPSHOT_ITEMS,\n MAX_TAG_ITEM,\n MAX_TAG_ITEMS,\n MAX_TAGS,\n MAX_TEXT,\n publicKey,\n safeTime,\n walletErrorCode,\n walletId,\n} from \"./core.ts\";\nimport type { VerifyFactor, MethodSpec } from \"./core.ts\";\nimport type { NullValue, Validator } from \"./validate.ts\";\nimport { arr, bytes, int, literal, nullValue, obj, opt, str, union } from \"./validate.ts\";\n\n/**\n * The unsigned event input the kernel signs. `pubkey` is optional: callers may omit it and the\n * kernel fills the signing key's own. Structurally compatible with @qntx/nostr's UnsignedEvent.\n */\nexport type UnsignedEventInput = {\n readonly kind: number;\n readonly created_at: number;\n readonly tags: ReadonlyArray<ReadonlyArray<string>>;\n readonly content: string;\n readonly pubkey?: string;\n};\n\n/** The signed event the kernel returns — the Nostr event minus `id`-less forms. */\nexport type SignedEvent = {\n readonly id: string;\n readonly pubkey: string;\n readonly sig: string;\n readonly kind: number;\n readonly created_at: number;\n readonly tags: ReadonlyArray<ReadonlyArray<string>>;\n readonly content: string;\n};\n\n/** A NIP-59 rumor: an unsigned event carrying a computed `id` but no `sig`. */\nexport type Rumor = {\n readonly id: string;\n readonly pubkey: string;\n readonly kind: number;\n readonly created_at: number;\n readonly tags: ReadonlyArray<ReadonlyArray<string>>;\n readonly content: string;\n};\n\nexport type NostrExportFormat =\n | { readonly kind: \"nsec\" }\n | { readonly kind: \"ncryptsec\"; readonly password: Uint8Array };\n\nexport type UnwrapResult = { readonly ok: Rumor } | { readonly err: WalletErrorCode };\n\nconst hex128: Validator<string> = str(128, /^[0-9a-f]{128}$/);\n\nconst nostrKeyRef = obj({ kind: literal(\"derived\"), walletId, index: identityIndex });\n\nexport const nostrKeyInfo: Validator<NostrKeyInfo> = obj({\n ref: nostrKeyRef,\n publicKey,\n createdAt: safeTime,\n});\n\n/** The nostr section of the status payload, composed by protocol/index.ts. */\nexport const nostrStatus: Validator<{ readonly keys: ReadonlyArray<NostrKeyInfo> }> = obj({\n keys: arr(nostrKeyInfo, MAX_SNAPSHOT_ITEMS),\n});\n\nconst derivedNostrKey: Validator<DerivedNostrKey> = obj({ index: identityIndex, publicKey });\n\nconst tags: Validator<ReadonlyArray<ReadonlyArray<string>>> = arr(\n arr(str(MAX_TAG_ITEM), MAX_TAG_ITEMS),\n MAX_TAGS,\n);\n\nconst signEventInput: Validator<UnsignedEventInput> = obj({\n kind: int(0, 65535),\n created_at: safeTime,\n tags,\n content: str(MAX_TEXT),\n pubkey: opt(publicKey),\n});\n\nconst signedEvent: Validator<SignedEvent> = obj({\n id: publicKey,\n pubkey: publicKey,\n sig: hex128,\n kind: int(0, 65535),\n created_at: safeTime,\n tags,\n content: str(MAX_TEXT),\n});\n\nconst rumor: Validator<Rumor> = obj({\n id: publicKey,\n pubkey: publicKey,\n kind: int(0, 65535),\n created_at: safeTime,\n tags,\n content: str(MAX_TEXT),\n});\n\nconst nostrExportFormat: Validator<NostrExportFormat> = union(\n obj({ kind: literal(\"nsec\") }),\n obj({ kind: literal(\"ncryptsec\"), password: bytes(1, 1024) }),\n);\n\nconst textParams = obj({ publicKey, peer: publicKey, text: str(MAX_TEXT) });\nconst textResult = str(MAX_TEXT * 4);\n\nexport const NOSTR_METHODS: {\n readonly \"nostr.discover\": MethodSpec<\n { readonly walletId: string; readonly from: number; readonly count: number },\n { readonly keys: ReadonlyArray<DerivedNostrKey> }\n >;\n readonly \"nostr.deriveKey\": MethodSpec<\n { readonly walletId: string; readonly index: number },\n NostrKeyInfo\n >;\n readonly \"nostr.removeKey\": MethodSpec<{ readonly publicKey: string }, NullValue>;\n readonly \"nostr.exportKey\": MethodSpec<\n {\n readonly verify: VerifyFactor;\n readonly publicKey: string;\n readonly format: NostrExportFormat;\n },\n Uint8Array\n >;\n readonly \"nostr.signEvent\": MethodSpec<\n { readonly publicKey: string; readonly event: UnsignedEventInput },\n SignedEvent\n >;\n readonly \"nostr.nip04Encrypt\": MethodSpec<\n { readonly publicKey: string; readonly peer: string; readonly text: string },\n string\n >;\n readonly \"nostr.nip04Decrypt\": MethodSpec<\n { readonly publicKey: string; readonly peer: string; readonly text: string },\n string\n >;\n readonly \"nostr.nip44Encrypt\": MethodSpec<\n { readonly publicKey: string; readonly peer: string; readonly text: string },\n string\n >;\n readonly \"nostr.nip44Decrypt\": MethodSpec<\n { readonly publicKey: string; readonly peer: string; readonly text: string },\n string\n >;\n readonly \"nostr.syncKey\": MethodSpec<\n { readonly walletId: string },\n { readonly publicKey: string }\n >;\n readonly \"nostr.syncSign\": MethodSpec<\n { readonly walletId: string; readonly event: UnsignedEventInput },\n SignedEvent\n >;\n readonly \"nostr.syncEncrypt\": MethodSpec<\n { readonly walletId: string; readonly text: string },\n string\n >;\n readonly \"nostr.syncDecrypt\": MethodSpec<\n { readonly walletId: string; readonly text: string },\n string\n >;\n readonly \"nostr.unwrapGiftWraps\": MethodSpec<\n { readonly publicKey: string; readonly events: ReadonlyArray<SignedEvent> },\n { readonly results: ReadonlyArray<UnwrapResult> }\n >;\n} = {\n \"nostr.discover\": {\n session: true,\n presence: false,\n params: obj({ walletId, from: identityIndex, count: int(1, 20) }),\n result: obj({ keys: arr(derivedNostrKey, 20) }),\n },\n \"nostr.deriveKey\": {\n session: true,\n presence: false,\n params: obj({ walletId, index: identityIndex }),\n result: nostrKeyInfo,\n },\n \"nostr.removeKey\": {\n session: true,\n presence: true,\n params: obj({ publicKey }),\n result: nullValue,\n },\n \"nostr.exportKey\": {\n session: true,\n presence: true,\n params: obj({ verify: verifier, publicKey, format: nostrExportFormat }),\n result: bytes(16, 4096),\n },\n \"nostr.signEvent\": {\n session: true,\n presence: false,\n params: obj({ publicKey, event: signEventInput }),\n result: signedEvent,\n },\n \"nostr.nip04Encrypt\": { session: true, presence: false, params: textParams, result: textResult },\n \"nostr.nip04Decrypt\": { session: true, presence: false, params: textParams, result: textResult },\n \"nostr.nip44Encrypt\": { session: true, presence: false, params: textParams, result: textResult },\n \"nostr.nip44Decrypt\": { session: true, presence: false, params: textParams, result: textResult },\n \"nostr.unwrapGiftWraps\": {\n session: true,\n presence: false,\n params: obj({ publicKey, events: arr(signedEvent, MAX_BATCH) }),\n result: obj({\n results: arr(union(obj({ ok: rumor }), obj({ err: walletErrorCode })), MAX_BATCH),\n }),\n },\n \"nostr.syncKey\": {\n session: true,\n presence: false,\n params: obj({ walletId }),\n result: obj({ publicKey }),\n },\n \"nostr.syncSign\": {\n session: true,\n presence: false,\n params: obj({ walletId, event: signEventInput }),\n result: signedEvent,\n },\n \"nostr.syncEncrypt\": {\n session: true,\n presence: false,\n params: obj({ walletId, text: str(MAX_TEXT) }),\n result: textResult,\n },\n \"nostr.syncDecrypt\": {\n session: true,\n presence: false,\n params: obj({ walletId, text: str(MAX_TEXT * 4) }),\n result: textResult,\n },\n};\n","/**\n * The sessions module's method table: `session-key` records — a secp256k1 key the kernel generates,\n * stores under the vault, and uses to sign the document its scheme defines on behalf of one HD\n * account. The wire types are generic strings; the per-scheme types live in `SessionSchemes`.\n *\n * The kernel validates the scheme's params strictly inside `sessions.sign` — a params-layer\n * validation failure answers `integrity` (the protocol-wide rule for a malformed envelope), while\n * malformed params are a domain check that must answer `invalid-input` — the same split\n * `wallet.importMnemonic` uses for a bad mnemonic.\n */\nimport type { HyperliquidL1Params, HyperliquidNetwork } from \"@qntx/wallet-chains/evm\";\n\nimport type { MethodSpec, VerifyFactor } from \"./core.ts\";\nimport { groupIndex, safeTime, verifier, walletId } from \"./core.ts\";\nimport type { NullValue, ProtocolValue, Validator } from \"./validate.ts\";\nimport { arr, bool, bytes, nullValue, obj, str } from \"./validate.ts\";\n\n/* The Hyperliquid L1 wire types live in @qntx/wallet-chains/evm — the one definition the kernel's\n scheme encoder and the chain decoders share; protocol re-exports them so the method table's\n names stay stable. */\nexport type {\n HyperliquidL1Action,\n HyperliquidL1Order,\n HyperliquidL1Params,\n HyperliquidNetwork,\n} from \"@qntx/wallet-chains/evm\";\n\n/** One asset's cumulative size cap inside `HyperliquidAgentLimits.assets`. */\nexport type HyperliquidAssetLimit = {\n readonly asset: number;\n /** Canonical positive decimal — the size buys and sells on `asset` may charge in total. */\n readonly size: string;\n};\n\n/**\n * The limits a `hyperliquid-l1-agent` session is approved under — `notional` is the quote budget\n * BUY orders charge (Σ max(price, triggerPx) × size, in each market's quote currency: perp ids are\n * quoted in USDC, spot ids in each pair's own quote token), `maxLeverage` caps `updateLeverage`,\n * and `assets` lists 1..16 entries strictly ascending by asset id (0..99999 — builder-deployed\n * HIP-3 perps start at 100000 and stay out of scope), each with the cumulative size cap buys and\n * sells share. The kernel strictly validates them at create and charges every signed order into\n * `spent`; past a budget it answers `limit-exceeded`. The kernel cannot know a market price, so a\n * sell is bounded by its asset's `size`, never by a self-declared `p`.\n */\nexport type HyperliquidAgentLimits = {\n /** Canonical positive decimal (the scheme's `positive` grammar), at most 1e15. */\n readonly notional: string;\n readonly maxLeverage: number;\n readonly assets: ReadonlyArray<HyperliquidAssetLimit>;\n};\n\n/**\n * What a `hyperliquid-l1-agent` record has charged: `notional` is the buy-charged quote total and\n * `size[i]` the cumulative size charged against `limits.assets[i]` — buys and sells, reduce-only or\n * not.\n */\nexport type HyperliquidAgentSpent = {\n /** Canonical decimal (≤ 16 fractional digits) — always ≤ `limits.notional`. */\n readonly notional: string;\n readonly size: ReadonlyArray<string>;\n};\n\n/**\n * The session schemes this kernel knows — its key set equals the kernel's `SESSION_SCHEMES` table:\n * a missing or extra entry fails the table's mapped-type emit.\n */\nexport type SessionSchemes = {\n readonly \"hyperliquid-l1-agent\": {\n readonly scope: HyperliquidNetwork;\n readonly params: HyperliquidL1Params;\n readonly limits: HyperliquidAgentLimits;\n readonly spent: HyperliquidAgentSpent;\n };\n};\nexport type SessionSchemeId = keyof SessionSchemes;\n\nexport type SessionInfo = {\n /** EIP-55 address of the session key. */\n readonly address: string;\n /** The record's scheme — possibly one this build does not know. */\n readonly scheme: string;\n /** Whether this build's kernel can sign with the record's scheme. */\n readonly supported: boolean;\n readonly walletId: string;\n readonly groupIndex: number;\n /** EIP-55 address of the HD account at m/44'/60'/0'/0/groupIndex the session signs for. */\n readonly owner: string;\n /** The scheme's opaque scope (a `HyperliquidNetwork` for hyperliquid-l1-agent). */\n readonly scope: string;\n readonly name: string;\n /** Wall-clock ms after which the kernel refuses to sign; the platform enforces it too. */\n readonly validUntil: number;\n readonly createdAt: number;\n /**\n * The limits the session was approved under — the scheme's canonical JSON object for metered\n * schemes, `null` when the record carries none (a scheme this build does not know, or one that\n * declares no metering).\n */\n readonly limits: ProtocolValue;\n /**\n * The charged metering — the scheme's canonical JSON object, `null` when the record carries none\n * (a scheme this build does not know, or one that declares no metering).\n */\n readonly spent: ProtocolValue;\n};\n\nconst schemeId = str(32, /^[a-z][a-z0-9-]{1,31}$/);\nconst scope = str(64, /^[A-Za-z0-9._:-]{1,64}$/);\nconst evmAddress = str(42, /^0x[0-9a-fA-F]{40}$/);\n\n/* Pass-through for `sessions.sign`'s `params`, `sessions.create`'s `limits` and the `limits` a\n session record reports: the strict check is the scheme's validator inside the kernel's handler,\n where malformed values answer `invalid-input`; a params-layer rejection would answer\n `integrity`. The envelope's isProtocolValue gate already certified the value, so the\n pass-through is sound. */\nconst paramsValue: Validator<ProtocolValue> = (value) =>\n // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- see the comment above\n value as ProtocolValue;\n\nconst sessionInfo: Validator<SessionInfo> = obj({\n address: evmAddress,\n scheme: schemeId,\n supported: bool,\n walletId,\n groupIndex,\n owner: evmAddress,\n scope,\n name: str(16, /^[A-Za-z0-9._-]{1,16}$/),\n validUntil: safeTime,\n createdAt: safeTime,\n /* Opaque across schemes — the kernel revalidates it against the scheme's limits grammar before\n it is stored, so an arbitrary JSON value (or null) is safe to surface here. */\n limits: paramsValue,\n /* Opaque like `limits` — a metered record's spent is the scheme's canonical JSON object, and an\n unmetered record surfaces null. */\n spent: paramsValue,\n});\n\nexport const SESSIONS_METHODS: {\n readonly \"sessions.create\": MethodSpec<\n {\n readonly scheme: string;\n readonly owner: { readonly walletId: string; readonly groupIndex: number };\n readonly scope: string;\n readonly name: string;\n readonly validUntil: number;\n readonly limits: ProtocolValue;\n readonly verify: VerifyFactor;\n },\n { readonly address: string }\n >;\n readonly \"sessions.list\": MethodSpec<NullValue, ReadonlyArray<SessionInfo>>;\n readonly \"sessions.delete\": MethodSpec<{ readonly address: string }, NullValue>;\n readonly \"sessions.open\": MethodSpec<\n { readonly address: string; readonly verify: VerifyFactor },\n NullValue\n >;\n readonly \"sessions.sign\": MethodSpec<\n {\n readonly scheme: string;\n readonly address: string;\n readonly params: ProtocolValue;\n },\n { readonly signature: Uint8Array }\n >;\n} = {\n \"sessions.create\": {\n session: true,\n presence: true,\n /* `limits` passes through like `params` — the scheme's own strict validator runs inside the\n kernel, where a malformed value answers `invalid-input`, not `integrity`. */\n params: obj({\n scheme: schemeId,\n owner: obj({ walletId, groupIndex }),\n scope,\n name: str(16, /^[A-Za-z0-9._-]{1,16}$/),\n validUntil: safeTime,\n limits: paramsValue,\n verify: verifier,\n }),\n result: obj({ address: evmAddress }),\n },\n \"sessions.list\": {\n session: true,\n presence: false,\n params: nullValue,\n result: arr(sessionInfo, 64),\n },\n \"sessions.delete\": {\n session: true,\n presence: true,\n params: obj({ address: evmAddress }),\n result: nullValue,\n },\n \"sessions.open\": {\n session: true,\n presence: true,\n params: obj({ address: evmAddress, verify: verifier }),\n result: nullValue,\n },\n \"sessions.sign\": {\n session: true,\n /* Deliberately not presence-bearing: a compromised main runtime must not be able to keep the\n vault unlocked forever by placing orders (design.md §协议). */\n presence: false,\n params: obj({\n scheme: schemeId,\n address: evmAddress,\n params: paramsValue,\n }),\n result: obj({ signature: bytes(65, 65) }),\n },\n};\n","/**\n * The spark module's method table and wire validators. The protocol stays free of @qntx/spark\n * imports — even types — so the signer shapes it validates are declared here structurally; a\n * type-level test in packages/wallet/tests pins them assignable to and from @qntx/spark/signer's\n * types.\n *\n * Every method carries `account` — walletId/groupIndex/network — and is session-gated but not\n * presence-bearing (signer work must not hold a session open). List params are capped at MAX_BATCH;\n * the leaf lists of prepareTransfer/prepareClaim are capped at the signer's own 256.\n */\nimport { verifier, groupIndex, MAX_BATCH, safeTime, walletId } from \"./core.ts\";\nimport type { VerifyFactor, MethodSpec } from \"./core.ts\";\nimport type { Validator } from \"./validate.ts\";\nimport {\n arr,\n bytes,\n int,\n literal,\n obj,\n opt,\n record,\n str,\n union,\n ValidationError,\n} from \"./validate.ts\";\n\n/** The Spark network the account's signer runs on — identical to @qntx/spark's SparkNetwork. */\nexport type SparkNetwork = \"mainnet\" | \"regtest\";\n\n/** The wallet+group+network triple every spark.* request addresses a pooled signer by. */\nexport type SparkAccountRef = {\n readonly walletId: string;\n readonly groupIndex: number;\n readonly network: SparkNetwork;\n};\n\nexport type SparkLeafKey =\n | { readonly type: \"leaf\"; readonly leafId: string }\n | { readonly type: \"static-deposit\"; readonly index: number };\n\nexport type SparkKey =\n | SparkLeafKey\n | { readonly type: \"received\"; readonly ciphertext: Uint8Array };\n\nexport type SigningCommitment = {\n readonly hiding: Uint8Array;\n readonly binding: Uint8Array;\n};\n\nexport type OperatorCommitment = {\n readonly identifier: string;\n readonly commitment: SigningCommitment;\n};\n\nexport type SigningTarget = {\n readonly transaction: Uint8Array;\n readonly inputIndex: number;\n readonly prevouts: ReadonlyArray<{\n script: Uint8Array;\n amount: number;\n }>;\n};\n\nexport type FrostSignJob = {\n readonly key: SparkKey;\n readonly target: SigningTarget;\n readonly verifyingKey: Uint8Array;\n readonly commitment: SigningCommitment;\n readonly operatorCommitments: ReadonlyArray<OperatorCommitment>;\n readonly adaptorPublicKey?: Uint8Array;\n /** Connector-refund proof pair — see `FrostSignJob.exit` in @qntx/spark/signer. */\n readonly exit?: {\n readonly connectorTx: Uint8Array;\n readonly exitTx: Uint8Array;\n };\n};\n\nexport type FrostAggregateJob = {\n readonly key: SparkKey;\n readonly target: SigningTarget;\n readonly verifyingKey: Uint8Array;\n readonly commitment: SigningCommitment;\n readonly signatureShare: Uint8Array;\n readonly operators: ReadonlyArray<{\n readonly identifier: string;\n readonly commitment: SigningCommitment;\n readonly signatureShare: Uint8Array;\n readonly publicKey: Uint8Array;\n }>;\n readonly adaptorPublicKey?: Uint8Array;\n};\n\nexport type StaticDepositClaimStatement = {\n readonly kind: \"static-deposit-claim\";\n readonly network: SparkNetwork;\n readonly txid: Uint8Array;\n readonly vout: number;\n readonly creditAmountSats: number;\n readonly sspSignature: Uint8Array;\n};\n\nexport type IdentityStatement =\n | { readonly kind: \"so-challenge\"; readonly challenge: Uint8Array }\n | { readonly kind: \"ssp-challenge\"; readonly protectedChallenge: string }\n | { readonly kind: \"transfer-package\"; readonly transferId: string; readonly package: Uint8Array }\n | { readonly kind: \"claim-package\"; readonly transferId: string; readonly package: Uint8Array }\n | StaticDepositClaimStatement\n | {\n readonly kind: \"static-deposit-refund\";\n readonly network: SparkNetwork;\n readonly txid: Uint8Array;\n readonly vout: number;\n readonly amount: number;\n readonly target: SigningTarget;\n }\n | {\n readonly kind: \"watchtower-recovery\";\n readonly network: SparkNetwork;\n readonly leafId: string;\n readonly target: SigningTarget;\n }\n | { readonly kind: \"spark-invoice\"; readonly invoice: Uint8Array }\n | { readonly kind: \"token-transaction\"; readonly partialTransaction: Uint8Array }\n | {\n readonly kind: \"lightning-address\";\n readonly action: \"register\";\n readonly domain: string;\n readonly username: string;\n readonly description: string;\n readonly timestamp: number;\n }\n | {\n readonly kind: \"lightning-address\";\n readonly action: \"unregister\";\n readonly domain: string;\n readonly username: string;\n readonly timestamp: number;\n };\n\nexport type PrepareTransferRequest = {\n readonly transferId: string;\n readonly leaves: ReadonlyArray<{\n readonly leafId: string;\n readonly key: SparkLeafKey;\n readonly receiverIdentityPublicKey: Uint8Array;\n }>;\n};\n\nexport type PreparedTransferLeaf = {\n readonly leafId: string;\n readonly newPublicKey: Uint8Array;\n readonly secretCipher: Uint8Array;\n readonly signature: Uint8Array;\n};\n\nexport type PreparedTransfer = {\n readonly operatorPackages: Record<string, Uint8Array>;\n readonly leaves: ReadonlyArray<PreparedTransferLeaf>;\n};\n\nexport type PrepareClaimRequest = {\n readonly transferId: string;\n readonly leaves: ReadonlyArray<{\n readonly leafId: string;\n readonly secretCipher: Uint8Array;\n }>;\n};\n\nexport type PreparedClaim = {\n readonly operatorPackages: Record<string, Uint8Array>;\n};\n\nexport type PreparedLightningReceive = {\n readonly paymentHash: Uint8Array;\n readonly operatorPackages: Record<string, Uint8Array>;\n};\n\nexport type HtlcTimeoutSignRequest = {\n readonly transaction: Uint8Array;\n readonly inputIndex: number;\n readonly prevoutAmountSats: number;\n readonly paymentHash: Uint8Array;\n readonly hashLockPublicKey: Uint8Array;\n};\n\nexport type StaticDepositClaimRequest = {\n readonly index: number;\n readonly statement: StaticDepositClaimStatement;\n};\n\nexport type StaticDepositClaimResult = {\n readonly encryptedSecretKey: Uint8Array;\n readonly signature: Uint8Array;\n};\n\n// Field bounds. Where @qntx/spark/signer constrains a value the same rule is mirrored (64-hex\n// identifiers, 32/33/64-byte keys and signatures, 1..MAX_BATCH counts); where it leaves a value\n// unbounded (leafId/transferId are hashed as UTF-8, ciphertexts and protobuf blobs are bytes) the\n// protocol still needs a size — the MAX_REQUEST_BYTES envelope cap makes these generous bounds\n// sufficient rather than security-critical.\nconst MAX_LEAVES = 256;\nconst MAX_OPERATORS = 16;\nconst MAX_PACKAGE_BYTES = 1_048_576;\nconst MAX_TX_BYTES = 1_048_576;\nconst MAX_PREVOUTS = 1024;\nconst MAX_SCRIPT_BYTES = 16_384;\nconst MAX_CIPHERTEXT_BYTES = 4096;\nconst MAX_SATS = 2_100_000_000_000_000; // 21M BTC in sats\n\nconst network: Validator<SparkNetwork> = union(literal(\"mainnet\"), literal(\"regtest\"));\nconst account: Validator<SparkAccountRef> = obj({ walletId, groupIndex, network });\n\nconst identifier: Validator<string> = str(64, /^[0-9a-f]{64}$/);\nconst leafId: Validator<string> = str(64);\nconst transferId: Validator<string> = str(64);\nconst bytes32: Validator<Uint8Array> = bytes(32);\nconst bytes33: Validator<Uint8Array> = bytes(33);\nconst bytes64: Validator<Uint8Array> = bytes(64);\nconst ciphertext: Validator<Uint8Array> = bytes(1, MAX_CIPHERTEXT_BYTES);\nconst sats: Validator<number> = int(0, MAX_SATS);\n\nconst sparkLeafKey: Validator<SparkLeafKey> = union(\n obj({ type: literal(\"leaf\"), leafId }),\n obj({ type: literal(\"static-deposit\"), index: int(0, 0x7fffffff) }),\n);\n\nconst sparkKey: Validator<SparkKey> = union(\n obj({ type: literal(\"leaf\"), leafId }),\n obj({ type: literal(\"static-deposit\"), index: int(0, 0x7fffffff) }),\n obj({ type: literal(\"received\"), ciphertext }),\n);\n\nconst signingCommitment: Validator<SigningCommitment> = obj({\n hiding: bytes33,\n binding: bytes33,\n});\n\nconst operatorCommitment: Validator<OperatorCommitment> = obj({\n identifier,\n commitment: signingCommitment,\n});\n\nconst signingTarget: Validator<SigningTarget> = obj({\n transaction: bytes(1, MAX_TX_BYTES),\n inputIndex: int(0, 0x7fffffff),\n prevouts: arr(obj({ script: bytes(0, MAX_SCRIPT_BYTES), amount: sats }), MAX_PREVOUTS),\n});\n\nconst adaptorPublicKey = opt(union(bytes(0), bytes(33)));\n\nconst frostSignJob: Validator<FrostSignJob> = obj({\n key: sparkKey,\n target: signingTarget,\n verifyingKey: bytes33,\n commitment: signingCommitment,\n operatorCommitments: arr(operatorCommitment, MAX_OPERATORS),\n adaptorPublicKey,\n exit: opt(obj({ connectorTx: bytes(1, MAX_TX_BYTES), exitTx: bytes(1, MAX_TX_BYTES) })),\n});\n\nconst frostAggregateJob: Validator<FrostAggregateJob> = obj({\n key: sparkKey,\n target: signingTarget,\n verifyingKey: bytes33,\n commitment: signingCommitment,\n signatureShare: bytes32,\n operators: arr(\n obj({\n identifier,\n commitment: signingCommitment,\n signatureShare: bytes32,\n publicKey: bytes33,\n }),\n MAX_OPERATORS,\n ),\n adaptorPublicKey,\n});\n\nconst staticDepositClaimStatement: Validator<StaticDepositClaimStatement> = obj({\n kind: literal(\"static-deposit-claim\"),\n network,\n txid: bytes32,\n vout: int(0, 0x7fffffff),\n creditAmountSats: sats,\n sspSignature: bytes(1, 1024),\n});\n\nconst identityStatement: Validator<IdentityStatement> = union(\n obj({ kind: literal(\"so-challenge\"), challenge: bytes(1, 4096) }),\n obj({ kind: literal(\"ssp-challenge\"), protectedChallenge: str(8192) }),\n obj({\n kind: literal(\"transfer-package\"),\n transferId,\n package: bytes(1, MAX_PACKAGE_BYTES),\n }),\n obj({\n kind: literal(\"claim-package\"),\n transferId,\n package: bytes(1, MAX_PACKAGE_BYTES),\n }),\n staticDepositClaimStatement,\n obj({\n kind: literal(\"static-deposit-refund\"),\n network,\n txid: bytes32,\n vout: int(0, 0x7fffffff),\n amount: sats,\n target: signingTarget,\n }),\n obj({\n kind: literal(\"watchtower-recovery\"),\n network,\n leafId,\n target: signingTarget,\n }),\n obj({ kind: literal(\"spark-invoice\"), invoice: bytes(1, 65_536) }),\n obj({ kind: literal(\"token-transaction\"), partialTransaction: bytes(1, MAX_PACKAGE_BYTES) }),\n obj({\n kind: literal(\"lightning-address\"),\n action: literal(\"register\"),\n domain: str(253),\n username: str(64, /^[a-z0-9\\-_.+]{1,64}$/u),\n description: str(512),\n timestamp: safeTime,\n }),\n obj({\n kind: literal(\"lightning-address\"),\n action: literal(\"unregister\"),\n domain: str(253),\n username: str(64, /^[a-z0-9\\-_.+]{1,64}$/u),\n timestamp: safeTime,\n }),\n);\n\nconst htlcTimeoutRequest: Validator<HtlcTimeoutSignRequest> = obj({\n transaction: bytes(1, MAX_TX_BYTES),\n inputIndex: int(0, 0x7fffffff),\n prevoutAmountSats: sats,\n paymentHash: bytes32,\n hashLockPublicKey: bytes33,\n});\n\nconst prepareTransferRequest: Validator<PrepareTransferRequest> = obj({\n transferId,\n leaves: arr(\n obj({ leafId, key: sparkLeafKey, receiverIdentityPublicKey: bytes33 }),\n MAX_LEAVES,\n 1,\n ),\n});\n\nconst preparedTransfer: Validator<PreparedTransfer> = obj({\n operatorPackages: record(identifier, bytes(1, MAX_PACKAGE_BYTES), MAX_OPERATORS),\n leaves: arr(\n obj({\n leafId,\n newPublicKey: bytes33,\n secretCipher: ciphertext,\n signature: bytes64,\n }),\n MAX_LEAVES,\n ),\n});\n\nconst prepareClaimRequest: Validator<PrepareClaimRequest> = obj({\n transferId,\n leaves: arr(obj({ leafId, secretCipher: ciphertext }), MAX_LEAVES, 1),\n});\n\nconst preparedClaim: Validator<PreparedClaim> = obj({\n operatorPackages: record(identifier, bytes(1, MAX_PACKAGE_BYTES), MAX_OPERATORS),\n});\n\nconst preparedLightningReceive: Validator<PreparedLightningReceive> = obj({\n paymentHash: bytes32,\n operatorPackages: record(identifier, bytes(1, MAX_PACKAGE_BYTES), MAX_OPERATORS),\n});\n\nconst staticDepositClaimRequest: Validator<StaticDepositClaimRequest> = obj({\n index: int(0, 0x7fffffff),\n statement: staticDepositClaimStatement,\n});\n\nconst staticDepositClaimResult: Validator<StaticDepositClaimResult> = obj({\n encryptedSecretKey: bytes(1, MAX_CIPHERTEXT_BYTES),\n signature: bytes(64, 128),\n});\n\n/**\n * The intent a `spark.approve` registers — kernel-decoded before the host ever displays it. `token`\n * receivers' amounts are canonical decimal strings in the u128 range.\n */\ntype SparkOutflowIntent =\n | {\n readonly kind: \"exit\";\n readonly address: string;\n readonly amountSats: number;\n readonly maxFeeSats: number;\n }\n | {\n readonly kind: \"onchain\";\n readonly address: string;\n readonly maxFeeSats: number;\n }\n | {\n readonly kind: \"token\";\n readonly tokenIdentifier: Uint8Array;\n readonly receivers: ReadonlyArray<{\n readonly ownerPublicKey: Uint8Array;\n readonly amount: string;\n }>;\n };\n\nexport type SparkApproveIntent =\n | {\n readonly kind: \"transfer\";\n readonly receivers: ReadonlyArray<{\n readonly identityPublicKey: Uint8Array;\n readonly amountSats: number;\n }>;\n }\n | {\n readonly kind: \"lightning\";\n readonly invoice: string;\n readonly amountSats?: number;\n readonly maxFeeSats: number;\n }\n | SparkOutflowIntent;\n\n/**\n * What `spark.approve` returns: the kernel's own decode of the intent — receivers and amounts, the\n * invoice's payment hash and amount, or the exit/onchain destination — never host-provided text.\n */\nexport type SparkApprovalSummary =\n | {\n readonly kind: \"transfer\";\n readonly receivers: ReadonlyArray<{\n readonly identityPublicKey: Uint8Array;\n readonly amountSats: number;\n }>;\n }\n | {\n readonly kind: \"lightning\";\n readonly paymentHash: Uint8Array;\n readonly invoiceAmountSats?: number;\n readonly maxFeeSats: number;\n }\n | SparkOutflowIntent;\n\n// sats amounts are bounded by the protocol's safe-integer contract; u128 token amounts\n// travel as canonical decimal strings.\nconst satsAmount = (): Validator<number> => int(0, Number.MAX_SAFE_INTEGER);\nconst U128_MAX = 340282366920938463463374607431768211455n;\n// Canonical decimal u128: \"0\" or no leading zeros, at most 2^128 − 1.\nconst decimalU128: Validator<string> = (value) => {\n if (\n typeof value !== \"string\" ||\n value.length > 39 ||\n !/^(?:0|[1-9][0-9]*)$/.test(value) ||\n BigInt(value) > U128_MAX\n ) {\n throw new ValidationError();\n }\n return value;\n};\nconst outflowIntents = [\n obj({\n kind: literal(\"exit\"),\n address: str(128),\n amountSats: satsAmount(),\n maxFeeSats: satsAmount(),\n }),\n obj({\n kind: literal(\"onchain\"),\n address: str(128),\n maxFeeSats: satsAmount(),\n }),\n obj({\n kind: literal(\"token\"),\n tokenIdentifier: bytes(32),\n receivers: arr(obj({ ownerPublicKey: bytes(33), amount: decimalU128 }), 256, 1),\n }),\n] as const;\n\nconst approveIntent: Validator<SparkApproveIntent> = union(\n obj({\n kind: literal(\"transfer\"),\n receivers: arr(obj({ identityPublicKey: bytes(33), amountSats: satsAmount() }), 256, 1),\n }),\n obj({\n kind: literal(\"lightning\"),\n invoice: str(4096),\n amountSats: opt(satsAmount()),\n maxFeeSats: satsAmount(),\n }),\n ...outflowIntents,\n);\n\nconst approvalSummary: Validator<SparkApprovalSummary> = union(\n obj({\n kind: literal(\"transfer\"),\n receivers: arr(obj({ identityPublicKey: bytes(33), amountSats: satsAmount() }), 256, 1),\n }),\n obj({\n kind: literal(\"lightning\"),\n paymentHash: bytes(32),\n invoiceAmountSats: opt(satsAmount()),\n maxFeeSats: satsAmount(),\n }),\n ...outflowIntents,\n);\n\nexport const SPARK_METHODS: {\n readonly \"spark.identityPublicKey\": MethodSpec<{ readonly account: SparkAccountRef }, Uint8Array>;\n readonly \"spark.publicKeys\": MethodSpec<\n { readonly account: SparkAccountRef; readonly keys: ReadonlyArray<SparkLeafKey> },\n ReadonlyArray<Uint8Array>\n >;\n readonly \"spark.receivedPublicKeys\": MethodSpec<\n { readonly account: SparkAccountRef; readonly ciphertexts: ReadonlyArray<Uint8Array> },\n ReadonlyArray<Uint8Array>\n >;\n readonly \"spark.newCommitments\": MethodSpec<\n { readonly account: SparkAccountRef; readonly count: number },\n ReadonlyArray<SigningCommitment>\n >;\n readonly \"spark.signFrost\": MethodSpec<\n { readonly account: SparkAccountRef; readonly jobs: ReadonlyArray<FrostSignJob> },\n ReadonlyArray<Uint8Array>\n >;\n readonly \"spark.aggregateFrost\": MethodSpec<\n { readonly account: SparkAccountRef; readonly jobs: ReadonlyArray<FrostAggregateJob> },\n ReadonlyArray<Uint8Array>\n >;\n readonly \"spark.signIdentity\": MethodSpec<\n { readonly account: SparkAccountRef; readonly statement: IdentityStatement },\n Uint8Array\n >;\n readonly \"spark.signKeySpend\": MethodSpec<\n {\n readonly account: SparkAccountRef;\n readonly key: SparkKey;\n readonly target: SigningTarget;\n },\n Uint8Array\n >;\n readonly \"spark.signHtlcTimeout\": MethodSpec<\n { readonly account: SparkAccountRef; readonly request: HtlcTimeoutSignRequest },\n Uint8Array\n >;\n readonly \"spark.prepareTransfer\": MethodSpec<\n { readonly account: SparkAccountRef; readonly request: PrepareTransferRequest },\n PreparedTransfer\n >;\n readonly \"spark.prepareClaim\": MethodSpec<\n { readonly account: SparkAccountRef; readonly request: PrepareClaimRequest },\n PreparedClaim\n >;\n readonly \"spark.prepareLightningReceive\": MethodSpec<\n { readonly account: SparkAccountRef },\n PreparedLightningReceive\n >;\n readonly \"spark.claimStaticDeposit\": MethodSpec<\n { readonly account: SparkAccountRef; readonly request: StaticDepositClaimRequest },\n StaticDepositClaimResult\n >;\n readonly \"spark.approve\": MethodSpec<\n {\n readonly account: SparkAccountRef;\n readonly intent: SparkApproveIntent;\n readonly verify: VerifyFactor;\n },\n SparkApprovalSummary\n >;\n} = {\n \"spark.identityPublicKey\": {\n session: true,\n presence: false,\n params: obj({ account }),\n result: bytes33,\n },\n \"spark.publicKeys\": {\n session: true,\n presence: false,\n params: obj({ account, keys: arr(sparkLeafKey, MAX_BATCH) }),\n result: arr(bytes33, MAX_BATCH),\n },\n \"spark.receivedPublicKeys\": {\n session: true,\n presence: false,\n params: obj({ account, ciphertexts: arr(ciphertext, MAX_BATCH) }),\n result: arr(bytes33, MAX_BATCH),\n },\n \"spark.newCommitments\": {\n session: true,\n presence: false,\n params: obj({ account, count: int(1, MAX_BATCH) }),\n result: arr(signingCommitment, MAX_BATCH),\n },\n \"spark.signFrost\": {\n session: true,\n presence: false,\n params: obj({ account, jobs: arr(frostSignJob, MAX_BATCH) }),\n result: arr(bytes32, MAX_BATCH),\n },\n \"spark.aggregateFrost\": {\n session: true,\n presence: false,\n params: obj({ account, jobs: arr(frostAggregateJob, MAX_BATCH) }),\n result: arr(bytes64, MAX_BATCH),\n },\n \"spark.signIdentity\": {\n session: true,\n presence: false,\n params: obj({ account, statement: identityStatement }),\n result: bytes(64, 128),\n },\n \"spark.signKeySpend\": {\n session: true,\n presence: false,\n params: obj({ account, key: sparkKey, target: signingTarget }),\n result: bytes64,\n },\n \"spark.signHtlcTimeout\": {\n session: true,\n presence: false,\n params: obj({ account, request: htlcTimeoutRequest }),\n result: bytes64,\n },\n \"spark.prepareTransfer\": {\n session: true,\n presence: false,\n params: obj({ account, request: prepareTransferRequest }),\n result: preparedTransfer,\n },\n \"spark.prepareClaim\": {\n session: true,\n presence: false,\n params: obj({ account, request: prepareClaimRequest }),\n result: preparedClaim,\n },\n \"spark.prepareLightningReceive\": {\n session: true,\n presence: false,\n params: obj({ account }),\n result: preparedLightningReceive,\n },\n \"spark.claimStaticDeposit\": {\n session: true,\n presence: false,\n params: obj({ account, request: staticDepositClaimRequest }),\n result: staticDepositClaimResult,\n },\n \"spark.approve\": {\n session: true,\n presence: true,\n params: obj({ account, intent: approveIntent, verify: verifier }),\n result: approvalSummary,\n },\n};\n","/**\n * Secret-area wire protocol (design/impl/wallet-e0.mdx \"协议与传输\"). Shared by the kernel and the main\n * runtime: the kernel validates every request, the host validates every response. Web/Node carry\n * ProtocolValue via structured clone; the RN host encodes the same values as CBOR.\n *\n * This file is the method-table composition point: `METHODS` spreads the core table\n * (protocol/core.ts) and the nostr module's table (protocol/nostr.ts), and the status result\n * validator composes the core sections with each module's status section.\n */\nimport type { LockReason, StatusPayload, WalletErrorCode } from \"../types.ts\";\nimport { backupInfo } from \"./backup.ts\";\n// oxlint-disable-next-line unicorn/prefer-export-from -- the table is composed locally AND re-exported\nimport { CARD_METHODS } from \"./card.ts\";\nimport { CHAINS_METHODS } from \"./chains.ts\";\nimport {\n CORE_METHODS,\n factorInfo,\n keyInfo,\n MAX_SNAPSHOT_ITEMS,\n safeTime,\n walletErrorCode,\n walletInfo,\n} from \"./core.ts\";\nimport type { MethodSpec } from \"./core.ts\";\n// oxlint-disable-next-line unicorn/prefer-export-from -- the table is composed locally AND re-exported\nimport { HARDWARE_METHODS } from \"./hardware.ts\";\n// oxlint-disable-next-line unicorn/prefer-export-from -- the table is composed locally AND re-exported\nimport { NOSTR_METHODS, nostrStatus } from \"./nostr.ts\";\n// oxlint-disable-next-line unicorn/prefer-export-from -- the table is composed locally AND re-exported\nimport { SESSIONS_METHODS } from \"./sessions.ts\";\n// oxlint-disable-next-line unicorn/prefer-export-from -- the table is composed locally AND re-exported\nimport { SPARK_METHODS } from \"./spark.ts\";\nimport { arr, bool, literal, nullValue, obj, opt, str, union } from \"./validate.ts\";\nimport type { NullValue, ProtocolValue, Validator } from \"./validate.ts\";\n\nexport type { WalletErrorCode } from \"../types.ts\";\n\nexport const PROTOCOL_VERSION = 3;\n\n/**\n * Responses to requests whose `id` cannot be parsed (malformed envelope) carry id 0. Main-side\n * request ids start at 1, so a `0` is never a real pending request.\n */\nexport const UNATTRIBUTED_ID = 0;\n\n/**\n * Param field names whose bytes are secrets: the kernel consumes and wipes them, so each must own\n * its memory.\n */\nexport const SECRET_FIELDS = [\n \"password\",\n \"prf\",\n \"prfWallet\",\n \"prfBackup\",\n \"mnemonic\",\n \"passphrase\",\n \"secret\",\n \"answers\",\n] as const;\n\nexport type { NullValue } from \"./validate.ts\";\nexport type { ProtocolValue } from \"./validate.ts\";\n\nexport type Request = {\n readonly v: typeof PROTOCOL_VERSION;\n readonly id: number;\n readonly method: string;\n readonly session?: string;\n readonly params: ProtocolValue;\n};\n\nexport type ErrorPayload = {\n readonly code: WalletErrorCode;\n readonly retryAt?: number; // only for \"rate-limited\"\n /** Platform diagnostic `\"<domain>:<code>\"` — sanitized at the producer, never free text. */\n readonly detail?: string;\n};\n\nexport type Response =\n | { readonly v: typeof PROTOCOL_VERSION; readonly id: number; readonly ok: ProtocolValue }\n | { readonly v: typeof PROTOCOL_VERSION; readonly id: number; readonly err: ErrorPayload };\n\nexport type KernelEvent =\n | {\n readonly v: typeof PROTOCOL_VERSION;\n readonly event: \"status\";\n readonly status: StatusPayload;\n }\n | { readonly v: typeof PROTOCOL_VERSION; readonly event: \"locked\"; readonly reason: LockReason }\n | {\n /** The kernel is (true) / is no longer (false) waiting on a system verification prompt. */\n readonly v: typeof PROTOCOL_VERSION;\n readonly event: \"ceremony\";\n readonly active: boolean;\n };\n\n/**\n * The worst-case encoded size of one request, enforced by both sides: the host refuses to post a\n * request over the cap and the kernel answers an oversized raw request with `invalid-input`.\n * Responses are not capped.\n */\nexport const MAX_REQUEST_BYTES = 1_048_576;\n\n/**\n * Upper-bound byte weight of a protocol value: a string costs `length * 3` (worst-case UTF-8), a\n * Uint8Array its `byteLength`, every scalar and every array element 8, and every object key\n * `key.length * 3 + 8` plus its value. Iterative — a deeply nested value cannot overflow the stack\n * — and stops once the running total passes MAX_REQUEST_BYTES, the only comparison callers make, so\n * oversized values are rejected without walking the whole value.\n */\nexport function requestBytes(value: ProtocolValue): number {\n let total = 0;\n const stack: ProtocolValue[] = [value];\n while (stack.length > 0) {\n if (total > MAX_REQUEST_BYTES) {\n return total;\n }\n const item = stack.pop();\n if (item === undefined) {\n continue;\n }\n if (typeof item === \"string\") {\n total += item.length * 3;\n } else if (item instanceof Uint8Array) {\n total += item.byteLength;\n } else if (item === null || typeof item === \"boolean\" || typeof item === \"number\") {\n total += 8;\n } else if (Array.isArray(item)) {\n // Array.isArray widens the readonly member to any[] — re-annotate the element domain.\n const elements: ReadonlyArray<ProtocolValue> = item;\n total += elements.length * 8;\n for (const element of elements) {\n stack.push(element);\n }\n } else {\n for (const [key, child] of Object.entries(item)) {\n total += key.length * 3 + 8;\n stack.push(child);\n }\n }\n }\n return total;\n}\n\n/**\n * Deep check that a structured-cloned value is a strict ProtocolValue. Structured clone keeps\n * shared references, so the value may be a graph: every object and array is checked once however\n * often it is referenced — a shared reference serializes once and must not expand on every walk —\n * and one that contains itself (a cycle, which can never be a protocol value) is rejected.\n * Iterative — a deeply nested value cannot overflow the stack.\n */\nexport function isProtocolValue(value: unknown): value is ProtocolValue {\n const checked = new Set<unknown>();\n // The containers on the path to the current node: meeting one again is a cycle.\n const open = new Set<unknown>();\n const stack: Array<{ readonly value: unknown } | { readonly close: unknown }> = [{ value }];\n while (stack.length > 0) {\n const frame = stack.pop();\n if (frame === undefined) {\n break;\n }\n if (\"close\" in frame) {\n open.delete(frame.close);\n continue;\n }\n const item = frame.value;\n switch (typeof item) {\n case \"boolean\":\n case \"string\":\n continue;\n case \"number\":\n if (!Number.isSafeInteger(item)) {\n return false;\n }\n continue;\n case \"object\":\n break;\n default:\n return false;\n }\n if (item === null || item instanceof Uint8Array) {\n continue;\n }\n if (open.has(item)) {\n return false;\n }\n if (checked.has(item)) {\n continue;\n }\n if (!Array.isArray(item) && Object.getPrototypeOf(item) !== Object.prototype) {\n return false;\n }\n checked.add(item);\n open.add(item);\n stack.push({ close: item });\n for (const child of Array.isArray(item) ? item : Object.values(item)) {\n stack.push({ value: child });\n }\n }\n return true;\n}\n\n/** The status payload: core sections plus one object section per protocol module. */\nconst statusPayload: Validator<StatusPayload> = obj({\n protocol: literal(PROTOCOL_VERSION),\n vault: union(\n literal(\"uninitialized\"),\n literal(\"locked\"),\n literal(\"unlocked\"),\n literal(\"corrupted\"),\n literal(\"unsupported\"),\n literal(\"unavailable\"),\n ),\n factors: arr(factorInfo, MAX_SNAPSHOT_ITEMS),\n appLock: bool,\n verification: union(literal(\"available\"), literal(\"unavailable\")),\n wallets: arr(walletInfo, MAX_SNAPSHOT_ITEMS),\n nostr: nostrStatus,\n importedKeys: arr(keyInfo, MAX_SNAPSHOT_ITEMS),\n backup: union(backupInfo, nullValue),\n blindSigning: bool,\n});\n\n// The explicit annotation is the composition contract: a key missing from either table fails\n// declaration emit, and a duplicated key fails assignability (the spread's type for that key\n// cannot satisfy the intersection).\nexport const METHODS: {\n readonly status: MethodSpec<NullValue, StatusPayload>;\n} & typeof CORE_METHODS &\n typeof CARD_METHODS &\n typeof NOSTR_METHODS &\n typeof CHAINS_METHODS &\n typeof SPARK_METHODS &\n typeof SESSIONS_METHODS &\n typeof HARDWARE_METHODS = {\n status: {\n session: false,\n presence: false,\n params: nullValue,\n result: statusPayload,\n },\n ...CORE_METHODS,\n ...CARD_METHODS,\n ...CHAINS_METHODS,\n ...NOSTR_METHODS,\n ...SPARK_METHODS,\n ...SESSIONS_METHODS,\n ...HARDWARE_METHODS,\n};\n\n// A method name must live in exactly one table: an overlap violates the never constraint.\ntype AssertNever<T extends never> = T;\nexport type MethodTablesDisjoint = [\n AssertNever<keyof typeof CORE_METHODS & keyof typeof CARD_METHODS>,\n AssertNever<keyof typeof CORE_METHODS & keyof typeof NOSTR_METHODS>,\n AssertNever<keyof typeof CORE_METHODS & keyof typeof SPARK_METHODS>,\n AssertNever<keyof typeof CARD_METHODS & keyof typeof NOSTR_METHODS>,\n AssertNever<keyof typeof CARD_METHODS & keyof typeof CHAINS_METHODS>,\n AssertNever<keyof typeof CARD_METHODS & keyof typeof SPARK_METHODS>,\n AssertNever<keyof typeof CARD_METHODS & keyof typeof SESSIONS_METHODS>,\n AssertNever<keyof typeof NOSTR_METHODS & keyof typeof SPARK_METHODS>,\n AssertNever<keyof typeof SESSIONS_METHODS & keyof typeof CORE_METHODS>,\n AssertNever<keyof typeof SESSIONS_METHODS & keyof typeof NOSTR_METHODS>,\n AssertNever<keyof typeof SESSIONS_METHODS & keyof typeof CHAINS_METHODS>,\n AssertNever<keyof typeof SESSIONS_METHODS & keyof typeof SPARK_METHODS>,\n AssertNever<keyof typeof HARDWARE_METHODS & keyof typeof CORE_METHODS>,\n AssertNever<keyof typeof HARDWARE_METHODS & keyof typeof NOSTR_METHODS>,\n AssertNever<keyof typeof HARDWARE_METHODS & keyof typeof CHAINS_METHODS>,\n AssertNever<keyof typeof HARDWARE_METHODS & keyof typeof SPARK_METHODS>,\n AssertNever<keyof typeof HARDWARE_METHODS & keyof typeof SESSIONS_METHODS>,\n AssertNever<keyof typeof HARDWARE_METHODS & keyof typeof CARD_METHODS>,\n];\n\nexport type MethodName = keyof typeof METHODS;\nexport type ParamsOf<M extends MethodName> = ReturnType<(typeof METHODS)[M][\"params\"]>;\nexport type ResultOf<M extends MethodName> = ReturnType<(typeof METHODS)[M][\"result\"]>;\n\nconst lockReason: Validator<LockReason> = union(\n literal(\"cold-start\"),\n literal(\"user\"),\n literal(\"idle\"),\n literal(\"background\"),\n literal(\"expired\"),\n literal(\"crashed\"),\n literal(\"invalidated\"),\n);\n\nconst errorPayload = obj({\n code: walletErrorCode,\n retryAt: opt(safeTime),\n detail: opt(str(80, /^[A-Za-z0-9_.:-]+$/)),\n});\n\n/** Host-side validators: `kernelEvent` covers the push messages. */\nexport const kernelEvent: Validator<KernelEvent> = union(\n obj({ v: literal(PROTOCOL_VERSION), event: literal(\"status\"), status: statusPayload }),\n obj({ v: literal(PROTOCOL_VERSION), event: literal(\"locked\"), reason: lockReason }),\n obj({ v: literal(PROTOCOL_VERSION), event: literal(\"ceremony\"), active: bool }),\n);\n\n/** Validates the `err` payload of a response; `ok` is checked against `METHODS[m].result`. */\nexport const responseError: Validator<{\n code: WalletErrorCode;\n retryAt?: number | undefined;\n detail?: string | undefined;\n}> = errorPayload;\n\nexport { CARD_METHODS, HARDWARE_METHODS, NOSTR_METHODS, SESSIONS_METHODS, SPARK_METHODS };\nexport type {\n DeviceDisplay,\n DeviceRequest,\n DeviceResponse,\n HardwareDevice,\n HardwareOperation,\n HardwareResult,\n HardwareStep,\n QrPayload,\n} from \"./hardware.ts\";\nexport type {\n CardBeginParams,\n CardInputPurpose,\n CardOperation,\n CardOpResult,\n CardStep,\n CardStepParams,\n CardTapReason,\n} from \"./card.ts\";\nexport type {\n HyperliquidAgentLimits,\n HyperliquidAgentSpent,\n HyperliquidAssetLimit,\n HyperliquidL1Action,\n HyperliquidL1Order,\n HyperliquidL1Params,\n HyperliquidNetwork,\n SessionInfo,\n SessionSchemes,\n SessionSchemeId,\n} from \"./sessions.ts\";\nexport { CHAINS_METHODS } from \"./chains.ts\";\nexport type {\n ChainAccount,\n ChainAccountsParams,\n ChainExportedKey,\n ChainExportNode,\n ChainExportParams,\n ChainExportResult,\n ChainSignRequest,\n ChainSignResult,\n ChainTemplate,\n} from \"./chains.ts\";\nexport { CORE_METHODS, walletErrorCode } from \"./core.ts\";\nexport type { MethodSpec } from \"./core.ts\";\nexport {\n backupEnvelope,\n backupEnvelopeFactor,\n backupEnvelopeText,\n backupHeader,\n backupInfo,\n} from \"./backup.ts\";\nexport type {\n BackupFactor,\n BackupUnlockFactor,\n CreatedResult,\n CreateWithPasskeyParams,\n Factor,\n RestoreWithPasskeyParams,\n VerifyFactor,\n} from \"./core.ts\";\nexport { verifier } from \"./core.ts\";\nexport type {\n BackupEnvelopeFactor,\n BackupEnvelopeWire,\n BackupHeaderKey,\n BackupHeaderWallet,\n BackupHeaderWire,\n BackupInfo,\n} from \"./backup.ts\";\nexport type {\n NostrExportFormat,\n Rumor,\n SignedEvent,\n UnsignedEventInput,\n UnwrapResult,\n} from \"./nostr.ts\";\nexport type {\n FrostAggregateJob,\n SparkApprovalSummary,\n SparkApproveIntent,\n FrostSignJob,\n HtlcTimeoutSignRequest,\n IdentityStatement,\n OperatorCommitment,\n PrepareClaimRequest,\n PreparedClaim,\n PreparedLightningReceive,\n PreparedTransfer,\n PreparedTransferLeaf,\n PrepareTransferRequest,\n SigningCommitment,\n SigningTarget,\n SparkAccountRef,\n SparkKey,\n SparkLeafKey,\n SparkNetwork,\n StaticDepositClaimRequest,\n StaticDepositClaimResult,\n StaticDepositClaimStatement,\n} from \"./spark.ts\";\nexport {\n ValidationError,\n arr,\n bool,\n bytes,\n int,\n literal,\n nullValue,\n obj,\n opt,\n record,\n str,\n union,\n validate,\n type Validator,\n} from \"./validate.ts\";\n"],"mappings":";;;;;;;;AAUA,MAAM,mBAAmB;AACzB,MAAM,mBAAmB;AACzB,MAAM,oBAAoB;AAC1B,MAAM,qBAAqB;;AA4B3B,MAAa,uBAAwD,MACnE,IAAI;CACF,MAAM,QAAQ,SAAS;CACvB,cAAc,IAAI,gBAAgB;CAClC,WAAW,IAAI,gBAAgB;AACjC,CAAC,GACD,IAAI;CACF,MAAM,QAAQ,UAAU;CACxB,K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B;AAEA,MAAM,eAAe,IAAI;CACvB,MAAM;CACN,SAAS,IAAI,QAAQ;CACrB,QAAQ,IAAI,IAAI,IAAI,oBAAoB,CAAC;AAC3C,CAAC;;AAGD,MAAa,cAAsC,MACjD,IAAI;CAAE,GAAG,QAAA,CAAwB;CAAG,OAAO,QAAQ,QAAQ;CAAG,QAAQ;AAAc,CAAC,GACrF,IAAI;CAAE,GAAG,QAAA,CAAwB;CAAG,OAAO,QAAQ,QAAQ;CAAG,QAAQ;AAAW,CAAC,GAClF,IAAI;CAAE,GAAG,QAAA,CAAwB;CAAG,OAAO,QAAQ,UAAU;CAAG,QAAQ;AAAK,CAAC,CAChF;;AAGA,MAAa,gBAIR"}
|
package/dist/protocol.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { A as
|
|
3
|
-
import { $ as
|
|
4
|
-
|
|
1
|
+
import { N as WalletErrorCode, p as HardwareDevice } from "./types-CRnacSqJ.mjs";
|
|
2
|
+
import { A as literal, C as ProtocolValue, D as bool, E as arr, F as str, I as union, L as validate, M as obj, N as opt, O as bytes, P as record, S as NullValue, T as Validator, _ as MethodSpec, a as ChainExportParams, b as verifier, c as ChainSignRequest, d as BackupFactor, f as BackupUnlockFactor, g as Factor, h as CreatedResult, i as ChainExportNode, j as nullValue, k as int, l as ChainSignResult, m as CreateWithPasskeyParams, n as ChainAccount, o as ChainExportResult, p as CORE_METHODS, r as ChainAccountsParams, s as ChainExportedKey, t as CHAINS_METHODS, u as ChainTemplate, v as RestoreWithPasskeyParams, w as ValidationError, x as walletErrorCode, y as VerifyFactor } from "./chains-u1M0CWkT.mjs";
|
|
3
|
+
import { $ as HyperliquidAgentSpent, A as FrostSignJob, B as SPARK_METHODS, C as BackupInfo, D as backupHeader, E as backupEnvelopeText, F as PrepareTransferRequest, G as SparkApproveIntent, H as SigningTarget, I as PreparedClaim, J as SparkNetwork, K as SparkKey, L as PreparedLightningReceive, M as IdentityStatement, N as OperatorCommitment, O as backupInfo, P as PrepareClaimRequest, Q as HyperliquidAgentLimits, R as PreparedTransfer, S as BackupHeaderWire, St as CardTapReason, T as backupEnvelopeFactor, U as SparkAccountRef, V as SigningCommitment, W as SparkApprovalSummary, X as StaticDepositClaimResult, Y as StaticDepositClaimRequest, Z as StaticDepositClaimStatement, _ as responseError, _t as CardInputPurpose, a as MethodName, at as SESSIONS_METHODS, b as BackupHeaderKey, bt as CardStep, c as ParamsOf, ct as SessionSchemes, d as ResultOf, dt as Rumor, et as HyperliquidAssetLimit, f as SECRET_FIELDS, ft as SignedEvent, g as requestBytes, gt as CardBeginParams, h as kernelEvent, ht as CARD_METHODS, i as METHODS, it as HyperliquidNetwork, j as HtlcTimeoutSignRequest, k as FrostAggregateJob, l as Request, lt as NOSTR_METHODS, m as isProtocolValue, mt as UnwrapResult, n as KernelEvent, nt as HyperliquidL1Order, o as MethodTablesDisjoint, ot as SessionInfo, p as UNATTRIBUTED_ID, pt as UnsignedEventInput, q as SparkLeafKey, r as MAX_REQUEST_BYTES, rt as HyperliquidL1Params, s as PROTOCOL_VERSION, st as SessionSchemeId, t as ErrorPayload, tt as HyperliquidL1Action, u as Response, ut as NostrExportFormat, v as BackupEnvelopeFactor, vt as CardOpResult, w as backupEnvelope, x as BackupHeaderWallet, xt as CardStepParams, y as BackupEnvelopeWire, yt as CardOperation, z as PreparedTransferLeaf } from "./index-UclKfprm.mjs";
|
|
4
|
+
import { a as HARDWARE_METHODS, c as HardwareStep, i as DeviceResponse, l as QrPayload, o as HardwareOperation, r as DeviceRequest, s as HardwareResult, t as DeviceDisplay } from "./hardware-BL6zvhQh.mjs";
|
|
5
|
+
export { type BackupEnvelopeFactor, type BackupEnvelopeWire, type BackupFactor, type BackupHeaderKey, type BackupHeaderWallet, type BackupHeaderWire, type BackupInfo, type BackupUnlockFactor, CARD_METHODS, CHAINS_METHODS, CORE_METHODS, type CardBeginParams, type CardInputPurpose, type CardOpResult, type CardOperation, type CardStep, type CardStepParams, type CardTapReason, type ChainAccount, type ChainAccountsParams, type ChainExportNode, type ChainExportParams, type ChainExportResult, type ChainExportedKey, type ChainSignRequest, type ChainSignResult, type ChainTemplate, type CreateWithPasskeyParams, type CreatedResult, type DeviceDisplay, type DeviceRequest, type DeviceResponse, ErrorPayload, type Factor, type FrostAggregateJob, type FrostSignJob, HARDWARE_METHODS, type HardwareDevice, type HardwareOperation, type HardwareResult, type HardwareStep, type HtlcTimeoutSignRequest, type HyperliquidAgentLimits, type HyperliquidAgentSpent, type HyperliquidAssetLimit, type HyperliquidL1Action, type HyperliquidL1Order, type HyperliquidL1Params, type HyperliquidNetwork, type IdentityStatement, KernelEvent, MAX_REQUEST_BYTES, METHODS, MethodName, type MethodSpec, MethodTablesDisjoint, NOSTR_METHODS, type NostrExportFormat, type NullValue, type OperatorCommitment, PROTOCOL_VERSION, ParamsOf, type PrepareClaimRequest, type PrepareTransferRequest, type PreparedClaim, type PreparedLightningReceive, type PreparedTransfer, type PreparedTransferLeaf, type ProtocolValue, type QrPayload, Request, Response, type RestoreWithPasskeyParams, ResultOf, type Rumor, SECRET_FIELDS, SESSIONS_METHODS, SPARK_METHODS, type SessionInfo, type SessionSchemeId, type SessionSchemes, type SignedEvent, type SigningCommitment, type SigningTarget, type SparkAccountRef, type SparkApprovalSummary, type SparkApproveIntent, type SparkKey, type SparkLeafKey, type SparkNetwork, type StaticDepositClaimRequest, type StaticDepositClaimResult, type StaticDepositClaimStatement, UNATTRIBUTED_ID, type UnsignedEventInput, type UnwrapResult, ValidationError, type Validator, type VerifyFactor, type WalletErrorCode, arr, backupEnvelope, backupEnvelopeFactor, backupEnvelopeText, backupHeader, backupInfo, bool, bytes, int, isProtocolValue, kernelEvent, literal, nullValue, obj, opt, record, requestBytes, responseError, str, union, validate, verifier, walletErrorCode };
|
package/dist/protocol.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { C as
|
|
2
|
-
import { a as
|
|
3
|
-
export { CHAINS_METHODS, CORE_METHODS, MAX_REQUEST_BYTES, METHODS, NOSTR_METHODS, PROTOCOL_VERSION, SPARK_METHODS, UNATTRIBUTED_ID, ValidationError, arr, backupEnvelope, backupEnvelopeFactor, backupEnvelopeText, backupHeader, backupInfo, bool, bytes, int, isProtocolValue, kernelEvent, literal, nullValue, obj, opt, record, requestBytes, responseError, str, union, validate, walletErrorCode };
|
|
1
|
+
import { A as validate, C as literal, D as record, E as opt, O as str, S as int, T as obj, b as bool, h as walletErrorCode, k as union, m as verifier, t as CORE_METHODS, v as ValidationError, w as nullValue, x as bytes, y as arr } from "./core-Cx7p-0nG.mjs";
|
|
2
|
+
import { _ as backupEnvelopeFactor, a as UNATTRIBUTED_ID, b as backupInfo, c as requestBytes, d as SESSIONS_METHODS, f as NOSTR_METHODS, g as backupEnvelope, h as CHAINS_METHODS, i as SECRET_FIELDS, l as responseError, m as CARD_METHODS, n as METHODS, o as isProtocolValue, p as HARDWARE_METHODS, r as PROTOCOL_VERSION, s as kernelEvent, t as MAX_REQUEST_BYTES, u as SPARK_METHODS, v as backupEnvelopeText, y as backupHeader } from "./protocol-DLE6lHmP.mjs";
|
|
3
|
+
export { CARD_METHODS, CHAINS_METHODS, CORE_METHODS, HARDWARE_METHODS, MAX_REQUEST_BYTES, METHODS, NOSTR_METHODS, PROTOCOL_VERSION, SECRET_FIELDS, SESSIONS_METHODS, SPARK_METHODS, UNATTRIBUTED_ID, ValidationError, arr, backupEnvelope, backupEnvelopeFactor, backupEnvelopeText, backupHeader, backupInfo, bool, bytes, int, isProtocolValue, kernelEvent, literal, nullValue, obj, opt, record, requestBytes, responseError, str, union, validate, verifier, walletErrorCode };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { WalletError } from "./types.mjs";
|
|
2
|
+
// src/secret.ts
|
|
3
|
+
/**
|
|
4
|
+
* One-shot secret bytes handed to the app: `read` returns them exactly once, `wipe` zeroes them.
|
|
5
|
+
* The second `read` fails closed.
|
|
6
|
+
*/
|
|
7
|
+
var SingleUseSecret = class {
|
|
8
|
+
bytes;
|
|
9
|
+
constructor(bytes) {
|
|
10
|
+
this.bytes = bytes;
|
|
11
|
+
}
|
|
12
|
+
read() {
|
|
13
|
+
const { bytes } = this;
|
|
14
|
+
if (bytes === void 0) throw new WalletError("invalid-input", "secret already read or wiped");
|
|
15
|
+
this.bytes = void 0;
|
|
16
|
+
return bytes;
|
|
17
|
+
}
|
|
18
|
+
wipe() {
|
|
19
|
+
this.bytes?.fill(0);
|
|
20
|
+
this.bytes = void 0;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
export { SingleUseSecret as t };
|
|
24
|
+
|
|
25
|
+
//# sourceMappingURL=secret-CbjbY5-f.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secret-CbjbY5-f.mjs","names":[],"sources":["../src/secret.ts"],"sourcesContent":["import { WalletError } from \"./types.ts\";\nimport type { ExportedSecret } from \"./types.ts\";\n\n/**\n * One-shot secret bytes handed to the app: `read` returns them exactly once, `wipe` zeroes them.\n * The second `read` fails closed.\n */\nexport class SingleUseSecret implements ExportedSecret {\n private bytes: Uint8Array | undefined;\n\n constructor(bytes: Uint8Array) {\n this.bytes = bytes;\n }\n\n read(): Uint8Array {\n const { bytes } = this;\n if (bytes === undefined) {\n throw new WalletError(\"invalid-input\", \"secret already read or wiped\");\n }\n this.bytes = undefined;\n return bytes;\n }\n\n wipe(): void {\n this.bytes?.fill(0);\n this.bytes = undefined;\n }\n}\n"],"mappings":";;;;;;AAOA,IAAa,kBAAb,MAAuD;CACrD;CAEA,YAAY,OAAmB;EAC7B,KAAK,QAAQ;CACf;CAEA,OAAmB;EACjB,MAAM,EAAE,UAAU;EAClB,IAAI,UAAU,KAAA,GACZ,MAAM,IAAI,YAAY,iBAAiB,8BAA8B;EAEvE,KAAK,QAAQ,KAAA;EACb,OAAO;CACT;CAEA,OAAa;EACX,KAAK,OAAO,KAAK,CAAC;EAClB,KAAK,QAAQ,KAAA;CACf;AACF"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { A as VerifyFactor, j as Wallet } from "./types-CRnacSqJ.mjs";
|
|
2
|
+
import { Q as HyperliquidAgentLimits, ct as SessionSchemes, it as HyperliquidNetwork, nt as HyperliquidL1Order, ot as SessionInfo, rt as HyperliquidL1Params, st as SessionSchemeId, tt as HyperliquidL1Action } from "./index-UclKfprm.mjs";
|
|
3
|
+
export type SessionsApi = {
|
|
4
|
+
/**
|
|
5
|
+
* Creates a secp256k1 session key inside the enclave for one HD account and returns its EIP-55
|
|
6
|
+
* address. The kernel refuses an unknown scheme (`unsupported`), a validity window past the
|
|
7
|
+
* scheme's maximum TTL (`invalid-input`) and a scope the scheme rejects (`invalid-input`). A
|
|
8
|
+
* scheme that moves value requires `limits` and `verify`: the kernel shows the approved limits in
|
|
9
|
+
* its own verification prompt, the session starts opened, and it must be opened again after every
|
|
10
|
+
* lock. On a React Native host with the app lock off it answers `app-lock-required`.
|
|
11
|
+
*/
|
|
12
|
+
readonly create: <K extends SessionSchemeId>(params: {
|
|
13
|
+
readonly scheme: K;
|
|
14
|
+
readonly owner: {
|
|
15
|
+
readonly walletId: string;
|
|
16
|
+
readonly groupIndex: number;
|
|
17
|
+
};
|
|
18
|
+
readonly scope: SessionSchemes[K]["scope"];
|
|
19
|
+
readonly name: string;
|
|
20
|
+
readonly validUntil: number;
|
|
21
|
+
readonly limits: SessionSchemes[K]["limits"];
|
|
22
|
+
readonly verify: VerifyFactor;
|
|
23
|
+
}) => Promise<string>;
|
|
24
|
+
/** Every session key the vault holds, across wallets, groups and schemes. */
|
|
25
|
+
readonly list: () => Promise<ReadonlyArray<SessionInfo>>;
|
|
26
|
+
/**
|
|
27
|
+
* Re-approves a value-moving session after a lock: the kernel shows the session's limits and
|
|
28
|
+
* remaining budget in its verification prompt and re-opens it in memory until the next lock.
|
|
29
|
+
* `sign` answers `approval-required` until this succeeds.
|
|
30
|
+
*/
|
|
31
|
+
readonly open: (address: string, verify: VerifyFactor) => Promise<void>;
|
|
32
|
+
/** Destroys the session key at `address` — nothing can sign with it again. */
|
|
33
|
+
readonly delete: (address: string) => Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Signs the scheme's document with the session key at `address` and returns the 65-byte r‖s‖v
|
|
36
|
+
* signature. The kernel builds the exact document from `params` — the host never supplies one —
|
|
37
|
+
* and refuses once `validUntil` has passed, when the scheme is not the record's, or the vault is
|
|
38
|
+
* locked. A value-moving session must first be opened (`approval-required`) and every signature
|
|
39
|
+
* charges the action against its approved limits (`limit-exceeded`); on a React Native host with
|
|
40
|
+
* the app lock off it answers `app-lock-required`. The host then verifies what came back: it
|
|
41
|
+
* rebuilds the document the record's scope implies, recovers the signer, and answers `integrity`
|
|
42
|
+
* unless the signature is the session key's over exactly that document.
|
|
43
|
+
*/
|
|
44
|
+
readonly sign: <K extends SessionSchemeId>(params: {
|
|
45
|
+
readonly scheme: K;
|
|
46
|
+
readonly address: string;
|
|
47
|
+
readonly params: SessionSchemes[K]["params"];
|
|
48
|
+
}) => Promise<Uint8Array>;
|
|
49
|
+
};
|
|
50
|
+
export declare function sessions(wallet: Wallet): SessionsApi;
|
|
51
|
+
export type { HyperliquidAgentLimits, HyperliquidL1Action, HyperliquidL1Order, HyperliquidL1Params, HyperliquidNetwork, SessionInfo, SessionSchemeId, SessionSchemes };
|
|
52
|
+
//# sourceMappingURL=sessions.d.mts.map
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { t as internalsOf } from "./internal-DwCus_Ws.mjs";
|
|
2
|
+
import { r as integrity } from "./channel-BCZXU3pt.mjs";
|
|
3
|
+
import { hyperliquidL1Document, recoverEvmSigner } from "@qntx/wallet-chains/evm";
|
|
4
|
+
// src/sessions/index.ts
|
|
5
|
+
/**
|
|
6
|
+
* The sessions module of @qntx/wallet: `sessions(wallet)` returns the wallet's session-key API —
|
|
7
|
+
* management of the kernel-held secp256k1 session keys and their scheme-defined signatures. The API
|
|
8
|
+
* is memoized per wallet so repeated calls return the same object (stable React identity); a
|
|
9
|
+
* foreign object is rejected because only a Wallet from this package holds a registered channel.
|
|
10
|
+
*/
|
|
11
|
+
const SCHEME_DOCUMENTS = { "hyperliquid-l1-agent": (params, scope) => scope === "Mainnet" || scope === "Testnet" ? hyperliquidL1Document(params, scope) : void 0 };
|
|
12
|
+
function createSessionsApi(internals) {
|
|
13
|
+
return {
|
|
14
|
+
create: async (params) => {
|
|
15
|
+
const { address } = await internals.withVerifying(async () => internals.secretCall("sessions.create", async (wire) => ({
|
|
16
|
+
...params,
|
|
17
|
+
verify: await internals.resolveVerifyFactor(params.verify, wire)
|
|
18
|
+
})));
|
|
19
|
+
return address;
|
|
20
|
+
},
|
|
21
|
+
list: async () => internals.call("sessions.list", null),
|
|
22
|
+
open: async (address, verify) => {
|
|
23
|
+
await internals.withVerifying(async () => internals.secretCall("sessions.open", async (wire) => ({
|
|
24
|
+
address,
|
|
25
|
+
verify: await internals.resolveVerifyFactor(verify, wire)
|
|
26
|
+
})));
|
|
27
|
+
},
|
|
28
|
+
delete: async (address) => {
|
|
29
|
+
await internals.call("sessions.delete", { address });
|
|
30
|
+
},
|
|
31
|
+
sign: async (params) => {
|
|
32
|
+
const { signature } = await internals.call("sessions.sign", params);
|
|
33
|
+
const record = (await internals.call("sessions.list", null)).find((r) => r.address.toLowerCase() === params.address.toLowerCase());
|
|
34
|
+
if (record === void 0) throw integrity("sessions.sign answered for an address with no session");
|
|
35
|
+
if (record.scheme !== params.scheme) throw integrity("sessions.sign answered under a different scheme");
|
|
36
|
+
const document = SCHEME_DOCUMENTS[params.scheme](params.params, record.scope);
|
|
37
|
+
if (document === void 0) throw integrity("sessions.sign answered for a scope the scheme rejects");
|
|
38
|
+
let signer;
|
|
39
|
+
try {
|
|
40
|
+
signer = recoverEvmSigner({
|
|
41
|
+
kind: "evm.typed-data",
|
|
42
|
+
network: "eip155:1337",
|
|
43
|
+
account: {
|
|
44
|
+
kind: "hd",
|
|
45
|
+
walletId: record.walletId,
|
|
46
|
+
groupIndex: record.groupIndex,
|
|
47
|
+
template: "evm.bip44"
|
|
48
|
+
},
|
|
49
|
+
typedData: document
|
|
50
|
+
}, { signature });
|
|
51
|
+
} catch {
|
|
52
|
+
throw integrity("sessions.sign signature does not verify");
|
|
53
|
+
}
|
|
54
|
+
if (signer.toLowerCase() !== params.address.toLowerCase()) throw integrity("sessions.sign signature is not the session key's");
|
|
55
|
+
return signature;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
const apis = /* @__PURE__ */ new WeakMap();
|
|
60
|
+
function sessions(wallet) {
|
|
61
|
+
const internals = internalsOf(wallet);
|
|
62
|
+
let api = apis.get(wallet);
|
|
63
|
+
if (api === void 0) {
|
|
64
|
+
api = createSessionsApi(internals);
|
|
65
|
+
apis.set(wallet, api);
|
|
66
|
+
}
|
|
67
|
+
return api;
|
|
68
|
+
}
|
|
69
|
+
export { sessions };
|
|
70
|
+
|
|
71
|
+
//# sourceMappingURL=sessions.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sessions.mjs","names":[],"sources":["../src/sessions/index.ts"],"sourcesContent":["/**\n * The sessions module of @qntx/wallet: `sessions(wallet)` returns the wallet's session-key API —\n * management of the kernel-held secp256k1 session keys and their scheme-defined signatures. The API\n * is memoized per wallet so repeated calls return the same object (stable React identity); a\n * foreign object is rejected because only a Wallet from this package holds a registered channel.\n */\nimport { hyperliquidL1Document, recoverEvmSigner } from \"@qntx/wallet-chains/evm\";\n\nimport { integrity } from \"../channel.ts\";\nimport { internalsOf } from \"../internal.ts\";\nimport type { WalletInternals } from \"../internal.ts\";\nimport type { SessionInfo, SessionSchemeId, SessionSchemes } from \"../protocol/index.ts\";\nimport type { VerifyFactor, Wallet } from \"../types.ts\";\n\nexport type {\n HyperliquidAgentLimits,\n HyperliquidL1Action,\n HyperliquidL1Order,\n HyperliquidL1Params,\n HyperliquidNetwork,\n SessionInfo,\n SessionSchemeId,\n SessionSchemes,\n} from \"../protocol/index.ts\";\n\nexport type SessionsApi = {\n /**\n * Creates a secp256k1 session key inside the enclave for one HD account and returns its EIP-55\n * address. The kernel refuses an unknown scheme (`unsupported`), a validity window past the\n * scheme's maximum TTL (`invalid-input`) and a scope the scheme rejects (`invalid-input`). A\n * scheme that moves value requires `limits` and `verify`: the kernel shows the approved limits in\n * its own verification prompt, the session starts opened, and it must be opened again after every\n * lock. On a React Native host with the app lock off it answers `app-lock-required`.\n */\n readonly create: <K extends SessionSchemeId>(params: {\n readonly scheme: K;\n readonly owner: { readonly walletId: string; readonly groupIndex: number };\n readonly scope: SessionSchemes[K][\"scope\"];\n readonly name: string;\n readonly validUntil: number;\n readonly limits: SessionSchemes[K][\"limits\"];\n readonly verify: VerifyFactor;\n }) => Promise<string>;\n /** Every session key the vault holds, across wallets, groups and schemes. */\n readonly list: () => Promise<ReadonlyArray<SessionInfo>>;\n /**\n * Re-approves a value-moving session after a lock: the kernel shows the session's limits and\n * remaining budget in its verification prompt and re-opens it in memory until the next lock.\n * `sign` answers `approval-required` until this succeeds.\n */\n readonly open: (address: string, verify: VerifyFactor) => Promise<void>;\n /** Destroys the session key at `address` — nothing can sign with it again. */\n readonly delete: (address: string) => Promise<void>;\n /**\n * Signs the scheme's document with the session key at `address` and returns the 65-byte r‖s‖v\n * signature. The kernel builds the exact document from `params` — the host never supplies one —\n * and refuses once `validUntil` has passed, when the scheme is not the record's, or the vault is\n * locked. A value-moving session must first be opened (`approval-required`) and every signature\n * charges the action against its approved limits (`limit-exceeded`); on a React Native host with\n * the app lock off it answers `app-lock-required`. The host then verifies what came back: it\n * rebuilds the document the record's scope implies, recovers the signer, and answers `integrity`\n * unless the signature is the session key's over exactly that document.\n */\n readonly sign: <K extends SessionSchemeId>(params: {\n readonly scheme: K;\n readonly address: string;\n readonly params: SessionSchemes[K][\"params\"];\n }) => Promise<Uint8Array>;\n};\n\n/* The document each scheme signs for `params` under `scope` — `undefined` when the scope is not\n one the scheme admits, so a record whose scope no longer fits cannot smuggle a signature. */\nconst SCHEME_DOCUMENTS: {\n readonly [K in SessionSchemeId]: (\n params: SessionSchemes[K][\"params\"],\n scope: string,\n ) => string | undefined;\n} = {\n \"hyperliquid-l1-agent\": (params, scope) =>\n scope === \"Mainnet\" || scope === \"Testnet\" ? hyperliquidL1Document(params, scope) : undefined,\n};\n\nfunction createSessionsApi(internals: WalletInternals): SessionsApi {\n return {\n create: async (params) => {\n const { address } = await internals.withVerifying(async () =>\n internals.secretCall(\"sessions.create\", async (wire) => ({\n ...params,\n verify: await internals.resolveVerifyFactor(params.verify, wire),\n })),\n );\n return address;\n },\n list: async () => internals.call(\"sessions.list\", null),\n open: async (address, verify) => {\n await internals.withVerifying(async () =>\n internals.secretCall(\"sessions.open\", async (wire) => ({\n address,\n verify: await internals.resolveVerifyFactor(verify, wire),\n })),\n );\n },\n delete: async (address) => {\n await internals.call(\"sessions.delete\", { address });\n },\n sign: async (params) => {\n const { signature } = await internals.call(\"sessions.sign\", params);\n const records = await internals.call(\"sessions.list\", null);\n const record = records.find((r) => r.address.toLowerCase() === params.address.toLowerCase());\n if (record === undefined) {\n throw integrity(\"sessions.sign answered for an address with no session\");\n }\n if (record.scheme !== params.scheme) {\n throw integrity(\"sessions.sign answered under a different scheme\");\n }\n const document = SCHEME_DOCUMENTS[params.scheme](params.params, record.scope);\n if (document === undefined) {\n throw integrity(\"sessions.sign answered for a scope the scheme rejects\");\n }\n let signer: string;\n try {\n signer = recoverEvmSigner(\n {\n kind: \"evm.typed-data\",\n network: \"eip155:1337\",\n account: {\n kind: \"hd\",\n walletId: record.walletId,\n groupIndex: record.groupIndex,\n template: \"evm.bip44\",\n },\n typedData: document,\n },\n { signature },\n );\n } catch {\n throw integrity(\"sessions.sign signature does not verify\");\n }\n if (signer.toLowerCase() !== params.address.toLowerCase()) {\n throw integrity(\"sessions.sign signature is not the session key's\");\n }\n return signature;\n },\n };\n}\n\nconst apis = new WeakMap<Wallet, SessionsApi>();\n\nexport function sessions(wallet: Wallet): SessionsApi {\n const internals = internalsOf(wallet);\n let api = apis.get(wallet);\n if (api === undefined) {\n api = createSessionsApi(internals);\n apis.set(wallet, api);\n }\n return api;\n}\n"],"mappings":";;;;;;;;;;AAwEA,MAAM,mBAKF,EACF,yBAAyB,QAAQ,UAC/B,UAAU,aAAa,UAAU,YAAY,sBAAsB,QAAQ,KAAK,IAAI,KAAA,EACxF;AAEA,SAAS,kBAAkB,WAAyC;CAClE,OAAO;EACL,QAAQ,OAAO,WAAW;GACxB,MAAM,EAAE,YAAY,MAAM,UAAU,cAAc,YAChD,UAAU,WAAW,mBAAmB,OAAO,UAAU;IACvD,GAAG;IACH,QAAQ,MAAM,UAAU,oBAAoB,OAAO,QAAQ,IAAI;GACjE,EAAE,CACJ;GACA,OAAO;EACT;EACA,MAAM,YAAY,UAAU,KAAK,iBAAiB,IAAI;EACtD,MAAM,OAAO,SAAS,WAAW;GAC/B,MAAM,UAAU,cAAc,YAC5B,UAAU,WAAW,iBAAiB,OAAO,UAAU;IACrD;IACA,QAAQ,MAAM,UAAU,oBAAoB,QAAQ,IAAI;GAC1D,EAAE,CACJ;EACF;EACA,QAAQ,OAAO,YAAY;GACzB,MAAM,UAAU,KAAK,mBAAmB,EAAE,QAAQ,CAAC;EACrD;EACA,MAAM,OAAO,WAAW;GACtB,MAAM,EAAE,cAAc,MAAM,UAAU,KAAK,iBAAiB,MAAM;GAElE,MAAM,UAAS,MADO,UAAU,KAAK,iBAAiB,IAAI,EAAA,CACnC,MAAM,MAAM,EAAE,QAAQ,YAAY,MAAM,OAAO,QAAQ,YAAY,CAAC;GAC3F,IAAI,WAAW,KAAA,GACb,MAAM,UAAU,uDAAuD;GAEzE,IAAI,OAAO,WAAW,OAAO,QAC3B,MAAM,UAAU,iDAAiD;GAEnE,MAAM,WAAW,iBAAiB,OAAO,OAAO,CAAC,OAAO,QAAQ,OAAO,KAAK;GAC5E,IAAI,aAAa,KAAA,GACf,MAAM,UAAU,uDAAuD;GAEzE,IAAI;GACJ,IAAI;IACF,SAAS,iBACP;KACE,MAAM;KACN,SAAS;KACT,SAAS;MACP,MAAM;MACN,UAAU,OAAO;MACjB,YAAY,OAAO;MACnB,UAAU;KACZ;KACA,WAAW;IACb,GACA,EAAE,UAAU,CACd;GACF,QAAQ;IACN,MAAM,UAAU,yCAAyC;GAC3D;GACA,IAAI,OAAO,YAAY,MAAM,OAAO,QAAQ,YAAY,GACtD,MAAM,UAAU,kDAAkD;GAEpE,OAAO;EACT;CACF;AACF;AAEA,MAAM,uBAAO,IAAI,QAA6B;AAE9C,SAAgB,SAAS,QAA6B;CACpD,MAAM,YAAY,YAAY,MAAM;CACpC,IAAI,MAAM,KAAK,IAAI,MAAM;CACzB,IAAI,QAAQ,KAAA,GAAW;EACrB,MAAM,kBAAkB,SAAS;EACjC,KAAK,IAAI,QAAQ,GAAG;CACtB;CACA,OAAO;AACT"}
|
package/dist/spark.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { A as VerifyFactor, j as Wallet } from "./types-CRnacSqJ.mjs";
|
|
2
|
+
import { G as SparkApproveIntent, U as SparkAccountRef, W as SparkApprovalSummary } from "./index-UclKfprm.mjs";
|
|
3
3
|
import { SparkSigner, SparkSigner as SparkSigner$1 } from "@qntx/spark/signer";
|
|
4
4
|
type SparkApi = {
|
|
5
5
|
/**
|
|
@@ -18,7 +18,7 @@ type SparkApi = {
|
|
|
18
18
|
readonly approve: (params: {
|
|
19
19
|
readonly account: SparkAccountRef;
|
|
20
20
|
readonly intent: SparkApproveIntent;
|
|
21
|
-
readonly verify:
|
|
21
|
+
readonly verify: VerifyFactor;
|
|
22
22
|
}) => Promise<SparkApprovalSummary>;
|
|
23
23
|
};
|
|
24
24
|
export declare function spark(wallet: Wallet): SparkApi;
|
package/dist/spark.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { WalletError } from "./types.mjs";
|
|
2
|
-
import { t as internalsOf } from "./internal-
|
|
2
|
+
import { t as internalsOf } from "./internal-DwCus_Ws.mjs";
|
|
3
3
|
// src/spark/wire.ts
|
|
4
4
|
function bad(what) {
|
|
5
5
|
throw new WalletError("invalid-input", `spark: unexpected ${what}`);
|
|
@@ -276,13 +276,10 @@ function proxySigner(account, internals) {
|
|
|
276
276
|
function createSparkApi(internals) {
|
|
277
277
|
return {
|
|
278
278
|
signer: (ref) => proxySigner(ref, internals),
|
|
279
|
-
approve: async (params) => internals.withVerifying(async () => {
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
verify
|
|
284
|
-
});
|
|
285
|
-
})
|
|
279
|
+
approve: async (params) => internals.withVerifying(async () => internals.secretCall("spark.approve", async (wire) => ({
|
|
280
|
+
...params,
|
|
281
|
+
verify: await internals.resolveVerifyFactor(params.verify, wire)
|
|
282
|
+
})))
|
|
286
283
|
};
|
|
287
284
|
}
|
|
288
285
|
const apis = /* @__PURE__ */ new WeakMap();
|