@qntx/wallet-chains 0.4.0 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"message-AfNel4WZ.mjs","names":[],"sources":["../src/bitcoin/networks.ts","../src/bitcoin/message.ts"],"sourcesContent":["import { NETWORK, TEST_NETWORK } from \"@scure/btc-signer/utils.js\";\n/**\n * Bip122 CAIP-2 networks = `bip122:` + the first 32 hex chars of the genesis hash, verified against\n * Bitcoin Core `src/kernel/chainparams.cpp` (assert(consensus.hashGenesisBlock == ...) per network\n * class).\n */\n\nimport { ChainError } from \"../index.ts\";\n\nexport type BitcoinNetwork = {\n readonly caip2: string;\n readonly genesis: string;\n readonly params: typeof NETWORK;\n readonly coinType: 0 | 1;\n /** BIP-32 extended-key version bytes: `xpub`/`xprv` on mainnet, `tpub`/`tprv` elsewhere. */\n readonly bip32: { readonly public: number; readonly private: number };\n};\n\nconst MAINNET_BIP32 = { public: 0x0488b21e, private: 0x0488ade4 } as const;\nconst TESTNET_BIP32 = { public: 0x043587cf, private: 0x04358394 } as const;\n\n// btc-signer ships mainnet and testnet parameters only; regtest shares testnet's version bytes but\n// uses the `bcrt` bech32 prefix.\nconst REGTEST_NETWORK: typeof NETWORK = { ...TEST_NETWORK, bech32: \"bcrt\" };\n\nconst NETWORKS: ReadonlyArray<BitcoinNetwork> = Object.freeze([\n {\n caip2: \"bip122:000000000019d6689c085ae165831e93\",\n genesis: \"000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f\",\n params: NETWORK,\n coinType: 0,\n bip32: MAINNET_BIP32,\n },\n {\n caip2: \"bip122:00000000da84f2bafbbc53dee25a72ae\",\n genesis: \"00000000da84f2bafbbc53dee25a72ae507ff4914b867c565be350b0da8bf043\",\n params: TEST_NETWORK,\n coinType: 1,\n bip32: TESTNET_BIP32,\n },\n {\n caip2: \"bip122:00000008819873e925422c1ff0f99f7c\",\n genesis: \"00000008819873e925422c1ff0f99f7cc9bbb232af63a077a480a3633bee1ef6\",\n params: TEST_NETWORK,\n coinType: 1,\n bip32: TESTNET_BIP32,\n },\n {\n caip2: \"bip122:0f9188f13cb7b2c71f2a335e3a4fc328\",\n genesis: \"0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206\",\n params: REGTEST_NETWORK,\n coinType: 1,\n bip32: TESTNET_BIP32,\n },\n] as const);\n\nexport const BITCOIN_NETWORKS: Readonly<Record<string, BitcoinNetwork>> = Object.freeze(\n Object.fromEntries(NETWORKS.map((n) => [n.caip2, n])),\n);\n\nexport const bitcoinNetwork = (caip2: string): BitcoinNetwork => {\n const net = BITCOIN_NETWORKS[caip2];\n if (net === undefined) {\n throw new ChainError(\"unsupported\", `unknown bitcoin network: ${caip2}`);\n }\n return net;\n};\n","import { secp256k1 } from \"@noble/curves/secp256k1.js\";\n/**\n * BIP-322 message signing (\"simple\" + legacy) built on btc-signer primitives.\n * https://github.com/bitcoin/bips/blob/master/bip-0322.mediawiki\n */\nimport { sha256 } from \"@noble/hashes/sha2.js\";\nimport { SigHash, Transaction } from \"@scure/btc-signer/transaction.js\";\n\nimport { ChainError } from \"../index.ts\";\n\nconst utf8 = (s: string): Uint8Array => new TextEncoder().encode(s);\n\nconst BIP322_TAG = \"BIP0322-signed-message\";\nconst LEGACY_MAGIC = utf8(\"Bitcoin Signed Message:\\n\");\n\nconst concat = (...parts: ReadonlyArray<Uint8Array>): Uint8Array => {\n const out = new Uint8Array(parts.reduce((n, p) => n + p.length, 0));\n let o = 0;\n for (const p of parts) {\n out.set(p, o);\n o += p.length;\n }\n return out;\n};\n\n/** CompactSize length prefix (values here are always < 253). */\nconst varint = (n: number): Uint8Array => Uint8Array.of(n);\n\nconst pushData = (data: Uint8Array): Uint8Array => concat(varint(data.length), data);\n\nconst u32le = (n: number): Uint8Array =>\n Uint8Array.of(\n n % 256,\n Math.floor(n / 256) % 256,\n Math.floor(n / 65536) % 256,\n Math.floor(n / 16777216) % 256,\n );\n\nconst u64le = (n: bigint): Uint8Array => {\n const out = new Uint8Array(8);\n let v = n;\n for (let i = 0; i < 8; i++) {\n out[i] = Number(v % 256n);\n v /= 256n;\n }\n return out;\n};\n\n/** BIP340 tagged hash: sha256(sha256(tag) || sha256(tag) || m). */\nconst bip322MessageHash = (message: string): Uint8Array => {\n const tag = sha256(utf8(BIP322_TAG));\n return sha256(concat(tag, tag, utf8(message)));\n};\n\n/**\n * Serialized to_spend tx per BIP-322: version 0, one input spending the zero prevout with the\n * message-hash scriptSig, one output paying the message's scriptPubKey. Returns txid (hash256d,\n * big-endian display order).\n */\nconst toSpend = (\n scriptPubKey: Uint8Array,\n messageHash: Uint8Array,\n): { txid: Uint8Array; raw: Uint8Array } => {\n const scriptSig = concat(Uint8Array.of(0x00), pushData(messageHash));\n const raw = concat(\n u32le(0),\n varint(1),\n new Uint8Array(32),\n u32le(0xffffffff),\n pushData(scriptSig),\n u32le(0),\n varint(1),\n u64le(0n),\n pushData(scriptPubKey),\n u32le(0),\n );\n const txid = sha256(sha256(raw));\n return { txid, raw };\n};\n\n/**\n * Display-order (big-endian) txid of the BIP-322 to_spend transaction — exported for vector\n * verification.\n */\nexport const bip322ToSpendTxid = (scriptPubKey: Uint8Array, message: string): Uint8Array =>\n Uint8Array.from([...toSpend(scriptPubKey, bip322MessageHash(message)).txid].reverse());\n\nconst BASE64 = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\";\nconst b64 = (i: number): string => BASE64[i] ?? \"\";\nconst base64 = (bytes: Uint8Array): string => {\n const c = b64;\n let out = \"\";\n for (let i = 0; i < bytes.length; i += 3) {\n const b0 = bytes[i] ?? 0;\n const b1 = bytes[i + 1] ?? 0;\n const b2 = bytes[i + 2] ?? 0;\n out += c(Math.floor(b0 / 4)) + c((b0 % 4) * 16 + Math.floor(b1 / 16));\n out += i + 1 < bytes.length ? c((b1 % 16) * 4 + Math.floor(b2 / 64)) : \"=\";\n out += i + 2 < bytes.length ? c(b2 % 64) : \"=\";\n }\n return out;\n};\n\n/**\n * Signs the BIP-322 to_sign input through a btc-signer Transaction and returns the `smp`-prefixed\n * base64 witness encoding. `scriptPubKey` is the message address's output script (P2WPKH or P2TR).\n */\nexport const signBip322Simple = (\n message: string,\n scriptPubKey: Uint8Array,\n privateKey: Uint8Array,\n auxRand: (n: number) => Uint8Array,\n): string => {\n const hash = bip322MessageHash(message);\n const { txid } = toSpend(scriptPubKey, hash);\n const tx = new Transaction({ version: 0, lockTime: 0, allowUnknownOutputs: true });\n const pub = secp256k1.getPublicKey(privateKey, true);\n tx.addInput({\n txid,\n index: 0,\n sequence: 0,\n witnessUtxo: { script: scriptPubKey, amount: 0n },\n bip32Derivation: [[pub, { fingerprint: 0, path: [] }]],\n ...(scriptPubKey[0] === 0x51 ? { tapInternalKey: pub.slice(1) } : {}),\n });\n tx.addOutput({ script: Uint8Array.of(0x6a), amount: 0n });\n const isTaproot = scriptPubKey[0] === 0x51;\n const ok = tx.signIdx(\n privateKey,\n 0,\n isTaproot ? [SigHash.DEFAULT, SigHash.ALL] : [SigHash.ALL],\n auxRand(0),\n );\n if (!ok) {\n throw new ChainError(\"invalid-request\", \"key cannot sign this BIP-322 input\");\n }\n tx.finalizeIdx(0);\n const witness = tx.getInput(0).finalScriptWitness;\n if (witness === undefined) {\n throw new ChainError(\"invalid-request\", \"BIP-322 input produced no witness\");\n }\n const raw = concat(varint(witness.length), ...witness.map(pushData));\n return `smp${base64(raw)}`;\n};\n\n/**\n * Legacy \"Bitcoin Signed Message\" compact signature for P2PKH addresses: base64(1-byte header +\n * 64-byte compact ECDSA sig), header = 27 + recovery + 4 (compressed pubkey).\n */\nexport const signLegacyMessage = (message: string, privateKey: Uint8Array): string => {\n const data = concat(pushData(LEGACY_MAGIC), pushData(utf8(message)));\n const hash = sha256(sha256(data));\n const recovered = secp256k1.sign(hash, privateKey, { lowS: true, format: \"recovered\" });\n const header = 27 + (recovered[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,KAAA,GACd,MAAM,IAAI,WAAW,mBAAmB,mCAAmC;CAE7E,MAAM,MAAM,OAAO,OAAO,QAAQ,MAAM,GAAG,GAAG,QAAQ,IAAI,QAAQ,CAAC;CACnE,OAAO,MAAM,OAAO,GAAG;AACzB;;;;;AAMA,MAAa,qBAAqB,SAAiB,eAAmC;CACpF,MAAM,OAAO,OAAO,SAAS,YAAY,GAAG,SAAS,KAAK,OAAO,CAAC,CAAC;CACnE,MAAM,OAAO,OAAO,OAAO,IAAI,CAAC;CAChC,MAAM,YAAY,UAAU,KAAK,MAAM,YAAY;EAAE,MAAM;EAAM,QAAQ;CAAY,CAAC;CACtF,MAAM,SAAS,MAAM,UAAU,MAAM,KAAK;CAC1C,OAAO,OAAO,OAAO,WAAW,GAAG,MAAM,GAAG,UAAU,MAAM,CAAC,CAAC,CAAC;AACjE"}
1
+ {"version":3,"file":"message-DtIS0ZWB.mjs","names":[],"sources":["../src/bitcoin/networks.ts","../src/bitcoin/message.ts"],"sourcesContent":["import { NETWORK, TEST_NETWORK } from \"@scure/btc-signer/utils.js\";\n/**\n * Bip122 CAIP-2 networks = `bip122:` + the first 32 hex chars of the genesis hash, verified against\n * Bitcoin Core `src/kernel/chainparams.cpp` (assert(consensus.hashGenesisBlock == ...) per network\n * class).\n */\n\nimport { ChainError } from \"../index.ts\";\n\nexport type BitcoinNetwork = {\n readonly caip2: string;\n readonly genesis: string;\n readonly params: typeof NETWORK;\n readonly coinType: 0 | 1;\n /** BIP-32 extended-key version bytes: `xpub`/`xprv` on mainnet, `tpub`/`tprv` elsewhere. */\n readonly bip32: { readonly public: number; readonly private: number };\n};\n\nconst MAINNET_BIP32 = { public: 0x0488b21e, private: 0x0488ade4 } as const;\nconst TESTNET_BIP32 = { public: 0x043587cf, private: 0x04358394 } as const;\n\n// btc-signer ships mainnet and testnet parameters only; regtest shares testnet's version bytes but\n// uses the `bcrt` bech32 prefix.\nconst REGTEST_NETWORK: typeof NETWORK = { ...TEST_NETWORK, bech32: \"bcrt\" };\n\nconst NETWORKS: ReadonlyArray<BitcoinNetwork> = Object.freeze([\n {\n caip2: \"bip122:000000000019d6689c085ae165831e93\",\n genesis: \"000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f\",\n params: NETWORK,\n coinType: 0,\n bip32: MAINNET_BIP32,\n },\n {\n caip2: \"bip122:00000000da84f2bafbbc53dee25a72ae\",\n genesis: \"00000000da84f2bafbbc53dee25a72ae507ff4914b867c565be350b0da8bf043\",\n params: TEST_NETWORK,\n coinType: 1,\n bip32: TESTNET_BIP32,\n },\n {\n caip2: \"bip122:00000008819873e925422c1ff0f99f7c\",\n genesis: \"00000008819873e925422c1ff0f99f7cc9bbb232af63a077a480a3633bee1ef6\",\n params: TEST_NETWORK,\n coinType: 1,\n bip32: TESTNET_BIP32,\n },\n {\n caip2: \"bip122:0f9188f13cb7b2c71f2a335e3a4fc328\",\n genesis: \"0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206\",\n params: REGTEST_NETWORK,\n coinType: 1,\n bip32: TESTNET_BIP32,\n },\n] as const);\n\nexport const BITCOIN_NETWORKS: Readonly<Record<string, BitcoinNetwork>> = Object.freeze(\n Object.fromEntries(NETWORKS.map((n) => [n.caip2, n])),\n);\n\nexport const bitcoinNetwork = (caip2: string): BitcoinNetwork => {\n const net = BITCOIN_NETWORKS[caip2];\n if (net === undefined) {\n throw new ChainError(\"unsupported\", `unknown bitcoin network: ${caip2}`);\n }\n return net;\n};\n","import { secp256k1 } from \"@noble/curves/secp256k1.js\";\n/**\n * BIP-322 message signing (\"simple\" + legacy) built on btc-signer primitives.\n * https://github.com/bitcoin/bips/blob/master/bip-0322.mediawiki\n */\nimport { sha256 } from \"@noble/hashes/sha2.js\";\nimport { SigHash, Transaction } from \"@scure/btc-signer/transaction.js\";\n\nimport { ChainError } from \"../index.ts\";\n\nconst utf8 = (s: string): Uint8Array => new TextEncoder().encode(s);\n\nconst BIP322_TAG = \"BIP0322-signed-message\";\nconst LEGACY_MAGIC = utf8(\"Bitcoin Signed Message:\\n\");\n\nconst concat = (...parts: ReadonlyArray<Uint8Array>): Uint8Array => {\n const out = new Uint8Array(parts.reduce((n, p) => n + p.length, 0));\n let o = 0;\n for (const p of parts) {\n out.set(p, o);\n o += p.length;\n }\n return out;\n};\n\n/** CompactSize length prefix (values here are always < 253). */\nconst varint = (n: number): Uint8Array => Uint8Array.of(n);\n\nconst pushData = (data: Uint8Array): Uint8Array => concat(varint(data.length), data);\n\nconst u32le = (n: number): Uint8Array =>\n Uint8Array.of(\n n % 256,\n Math.floor(n / 256) % 256,\n Math.floor(n / 65536) % 256,\n Math.floor(n / 16777216) % 256,\n );\n\nconst u64le = (n: bigint): Uint8Array => {\n const out = new Uint8Array(8);\n let v = n;\n for (let i = 0; i < 8; i++) {\n out[i] = Number(v % 256n);\n v /= 256n;\n }\n return out;\n};\n\n/** BIP340 tagged hash: sha256(sha256(tag) || sha256(tag) || m). */\nconst bip322MessageHash = (message: string): Uint8Array => {\n const tag = sha256(utf8(BIP322_TAG));\n return sha256(concat(tag, tag, utf8(message)));\n};\n\n/**\n * Serialized to_spend tx per BIP-322: version 0, one input spending the zero prevout with the\n * message-hash scriptSig, one output paying the message's scriptPubKey. Returns txid (hash256d,\n * big-endian display order).\n */\nconst toSpend = (\n scriptPubKey: Uint8Array,\n messageHash: Uint8Array,\n): { txid: Uint8Array; raw: Uint8Array } => {\n const scriptSig = concat(Uint8Array.of(0x00), pushData(messageHash));\n const raw = concat(\n u32le(0),\n varint(1),\n new Uint8Array(32),\n u32le(0xffffffff),\n pushData(scriptSig),\n u32le(0),\n varint(1),\n u64le(0n),\n pushData(scriptPubKey),\n u32le(0),\n );\n const txid = sha256(sha256(raw));\n return { txid, raw };\n};\n\n/**\n * Display-order (big-endian) txid of the BIP-322 to_spend transaction — exported for vector\n * verification.\n */\nexport const bip322ToSpendTxid = (scriptPubKey: Uint8Array, message: string): Uint8Array =>\n Uint8Array.from([...toSpend(scriptPubKey, bip322MessageHash(message)).txid].reverse());\n\nconst BASE64 = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\";\nconst b64 = (i: number): string => BASE64[i] ?? \"\";\nconst base64 = (bytes: Uint8Array): string => {\n const c = b64;\n let out = \"\";\n for (let i = 0; i < bytes.length; i += 3) {\n const b0 = bytes[i] ?? 0;\n const b1 = bytes[i + 1] ?? 0;\n const b2 = bytes[i + 2] ?? 0;\n out += c(Math.floor(b0 / 4)) + c((b0 % 4) * 16 + Math.floor(b1 / 16));\n out += i + 1 < bytes.length ? c((b1 % 16) * 4 + Math.floor(b2 / 64)) : \"=\";\n out += i + 2 < bytes.length ? c(b2 % 64) : \"=\";\n }\n return out;\n};\n\n/**\n * Signs the BIP-322 to_sign input through a btc-signer Transaction and returns the `smp`-prefixed\n * base64 witness encoding. `scriptPubKey` is the message address's output script (P2WPKH or P2TR).\n */\nexport const signBip322Simple = (\n message: string,\n scriptPubKey: Uint8Array,\n privateKey: Uint8Array,\n auxRand: (n: number) => Uint8Array,\n): string => {\n const hash = bip322MessageHash(message);\n const { txid } = toSpend(scriptPubKey, hash);\n const tx = new Transaction({ version: 0, lockTime: 0, allowUnknownOutputs: true });\n const pub = secp256k1.getPublicKey(privateKey, true);\n tx.addInput({\n txid,\n index: 0,\n sequence: 0,\n witnessUtxo: { script: scriptPubKey, amount: 0n },\n bip32Derivation: [[pub, { fingerprint: 0, path: [] }]],\n ...(scriptPubKey[0] === 0x51 ? { tapInternalKey: pub.slice(1) } : {}),\n });\n tx.addOutput({ script: Uint8Array.of(0x6a), amount: 0n });\n const isTaproot = scriptPubKey[0] === 0x51;\n const ok = tx.signIdx(\n privateKey,\n 0,\n isTaproot ? [SigHash.DEFAULT, SigHash.ALL] : [SigHash.ALL],\n auxRand(0),\n );\n if (!ok) {\n throw new ChainError(\"invalid-request\", \"key cannot sign this BIP-322 input\");\n }\n tx.finalizeIdx(0);\n const witness = tx.getInput(0).finalScriptWitness;\n if (witness === undefined) {\n throw new ChainError(\"invalid-request\", \"BIP-322 input produced no witness\");\n }\n const raw = concat(varint(witness.length), ...witness.map(pushData));\n return `smp${base64(raw)}`;\n};\n\n/**\n * Legacy \"Bitcoin Signed Message\" compact signature for P2PKH addresses: base64(1-byte header +\n * 64-byte compact ECDSA sig), header = 27 + recovery + 4 (compressed pubkey).\n */\nexport const signLegacyMessage = (message: string, privateKey: Uint8Array): string => {\n const data = concat(pushData(LEGACY_MAGIC), pushData(utf8(message)));\n const hash = sha256(sha256(data));\n const recovered = secp256k1.sign(hash, privateKey, { lowS: true, format: \"recovered\" });\n const header = 27 + (recovered[0] ?? 0) + 4;\n return base64(concat(Uint8Array.of(header), recovered.slice(1)));\n};\n"],"mappings":";;;;;;;;;;;AAkBA,MAAM,gBAAgB;CAAE,QAAQ;CAAY,SAAS;AAAW;AAChE,MAAM,gBAAgB;CAAE,QAAQ;CAAY,SAAS;AAAW;AAIhE,MAAM,kBAAkC;CAAE,GAAG;CAAc,QAAQ;AAAO;AAE1E,MAAM,WAA0C,OAAO,OAAO;CAC5D;EACE,OAAO;EACP,SAAS;EACT,QAAQ;EACR,UAAU;EACV,OAAO;CACT;CACA;EACE,OAAO;EACP,SAAS;EACT,QAAQ;EACR,UAAU;EACV,OAAO;CACT;CACA;EACE,OAAO;EACP,SAAS;EACT,QAAQ;EACR,UAAU;EACV,OAAO;CACT;CACA;EACE,OAAO;EACP,SAAS;EACT,QAAQ;EACR,UAAU;EACV,OAAO;CACT;AACF,CAAU;AAEV,MAAa,mBAA6D,OAAO,OAC/E,OAAO,YAAY,SAAS,KAAK,MAAM,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CACtD;AAEA,MAAa,kBAAkB,UAAkC;CAC/D,MAAM,MAAM,iBAAiB;CAC7B,IAAI,QAAQ,KAAA,GACV,MAAM,IAAI,WAAW,eAAe,4BAA4B,OAAO;CAEzE,OAAO;AACT;;;;;;;ACxDA,MAAM,QAAQ,MAA0B,IAA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M,CAAC,EAAE,IAAI,CAAC;CACrE,CAAC;CACD,GAAG,UAAU;EAAE,QAAQ,WAAW,GAAG,GAAI;EAAG,QAAQ;CAAG,CAAC;CACxD,MAAM,YAAY,aAAa,OAAO;CAOtC,IAAI,CANO,GAAG,QACZ,YACA,GACA,YAAY,CAAC,QAAQ,SAAS,QAAQ,GAAG,IAAI,CAAC,QAAQ,GAAG,GACzD,QAAQ,CAAC,CAEL,GACJ,MAAM,IAAI,WAAW,mBAAmB,oCAAoC;CAE9E,GAAG,YAAY,CAAC;CAChB,MAAM,UAAU,GAAG,SAAS,CAAC,CAAC,CAAC;CAC/B,IAAI,YAAY,KAAA,GACd,MAAM,IAAI,WAAW,mBAAmB,mCAAmC;CAE7E,MAAM,MAAM,OAAO,OAAO,QAAQ,MAAM,GAAG,GAAG,QAAQ,IAAI,QAAQ,CAAC;CACnE,OAAO,MAAM,OAAO,GAAG;AACzB;;;;;AAMA,MAAa,qBAAqB,SAAiB,eAAmC;CACpF,MAAM,OAAO,OAAO,SAAS,YAAY,GAAG,SAAS,KAAK,OAAO,CAAC,CAAC;CACnE,MAAM,OAAO,OAAO,OAAO,IAAI,CAAC;CAChC,MAAM,YAAY,UAAU,KAAK,MAAM,YAAY;EAAE,MAAM;EAAM,QAAQ;CAAY,CAAC;CACtF,MAAM,SAAS,MAAM,UAAU,MAAM,KAAK;CAC1C,OAAO,OAAO,OAAO,WAAW,GAAG,MAAM,GAAG,UAAU,MAAM,CAAC,CAAC,CAAC;AACjE"}
@@ -1,5 +1,5 @@
1
1
  import { ChainError } from "./index.mjs";
2
- import { t as ed25519 } from "./ed25519-DUtI5nWr.mjs";
2
+ import { ed25519 } from "@noble/curves/ed25519.js";
3
3
  //#region src/solana/sign.ts
4
4
  /**
5
5
  * /solana/sign — deterministic Ed25519 signing over the compiled message or raw offchain bytes.
package/dist/solana.d.mts CHANGED
@@ -20,9 +20,9 @@ export declare function solanaAddressFromPublicKey(pubkey: Uint8Array): string;
20
20
  //#endregion
21
21
  //#region src/solana/tokens.d.ts
22
22
  /**
23
- * Built-in SPL token table, keyed by `network` then mint address. Intentionally EMPTY in this layer
24
- * — real entries need official-source review (C6). Tests exercise the known-mint path through an
25
- * internal table parameter that is not exported from the package entry points.
23
+ * Built-in SPL token table, keyed by `network` then mint address. An entry makes a
24
+ * `transferChecked` `full`-verifiable (WD-065), so every entry must come from the issuer's own
25
+ * published list; the source is recorded per issuer below.
26
26
  */
27
27
  type SolanaToken = {
28
28
  readonly symbol: string;
@@ -41,6 +41,50 @@ export declare const decodeSolana: (request: Extract<SignRequest, {
41
41
  kind: "solana.transaction";
42
42
  }>, signer: string, table?: SolanaTokenTable) => DisplayIntent;
43
43
  //#endregion
44
+ //#region src/solana/token2022.d.ts
45
+ /** SPL Token-2022 mint-account TLV extension type numbers (spl-token-2022 `ExtensionType`). */
46
+ export declare const EXT: {
47
+ readonly transferFeeConfig: 1;
48
+ readonly confidentialTransferMint: 4;
49
+ readonly defaultAccountState: 6;
50
+ readonly nonTransferable: 9;
51
+ readonly cpiGuard: 11;
52
+ readonly permanentDelegate: 12;
53
+ readonly transferHook: 14;
54
+ readonly confidentialTransferFee: 16;
55
+ readonly confidentialTransferFeeAmount: 17;
56
+ };
57
+ type MintExtensionSummary = {
58
+ /** The current-epoch fee from TransferFeeConfig (basis points and the maximum fee), if set. */
59
+ readonly transferFee?: {
60
+ readonly basisPoints: number;
61
+ readonly maximumFee: bigint;
62
+ };
63
+ readonly transferHook?: {
64
+ readonly programId: Uint8Array;
65
+ };
66
+ readonly permanentDelegate?: {
67
+ readonly delegate: Uint8Array;
68
+ };
69
+ readonly nonTransferable?: boolean;
70
+ /** True when a ConfidentialTransfer extension is present — confidential amounts are not supported. */
71
+ readonly confidential?: boolean;
72
+ /** Extension type numbers we do not parse (informational). */
73
+ readonly unknown?: ReadonlyArray<number>;
74
+ };
75
+ /**
76
+ * Parse the extension region of a full Token-2022 mint account. The account is the 82-byte mint
77
+ * base, zero padding up to byte 165, the account-type byte (`1` = Mint) at 165, then the TLV region
78
+ * at 166 — each entry `u16 type, u16 len, len bytes`. Returns a typed summary; extensions this
79
+ * layer does not read are reported by type number in `unknown` rather than parsed.
80
+ */
81
+ export declare const parseMintExtensions: (data: Uint8Array, epoch: bigint) => MintExtensionSummary;
82
+ /**
83
+ * Net amount a recipient gets after the current-epoch transfer fee, `amt − min(amt*bps/10000,
84
+ * max)`.
85
+ */
86
+ export declare const netAfterTransferFee: (amount: bigint, bps: number, max: bigint) => bigint;
87
+ //#endregion
44
88
  //#region src/solana/message.d.ts
45
89
  type CompiledIx = {
46
90
  readonly programAddressIndex: number;
@@ -74,5 +118,5 @@ export declare const verifySolanaSignature: (message: Uint8Array, signature: Uin
74
118
  */
75
119
  export declare const normalizeSolana: (request: unknown, signer: string) => SignRequest;
76
120
  //#endregion
77
- export type { SolanaTokenTable };
121
+ export type { MintExtensionSummary, SolanaTokenTable };
78
122
  //# sourceMappingURL=solana.d.mts.map
package/dist/solana.mjs CHANGED
@@ -1,8 +1,8 @@
1
1
  import { ChainError } from "./index.mjs";
2
- import { t as ed25519 } from "./ed25519-DUtI5nWr.mjs";
3
2
  import { address, getAddressDecoder, getAddressEncoder } from "@solana/addresses";
4
3
  import { getCompiledTransactionMessageDecoder } from "@solana/transaction-messages";
5
4
  import { getU32Decoder, getU64Decoder } from "@solana/codecs";
5
+ import { ed25519 } from "@noble/curves/ed25519.js";
6
6
  //#region src/solana/ids.ts
7
7
  /** Well-known Solana program ids (base58, 32 bytes) — frozen constants. */
8
8
  const PROGRAM_IDS = Object.freeze({
@@ -109,15 +109,30 @@ const validateLookupTables = (tables) => {
109
109
  if (tables === void 0) return;
110
110
  for (const table of tables) if (!isSolanaAddress(table.address) || !table.addresses.every(isSolanaAddress)) throw new ChainError("invalid-address", "lookup table entries must be base58 32-byte addresses");
111
111
  };
112
- const solanaTokenTable = Object.freeze({});
112
+ //#endregion
113
+ //#region src/solana/tokens.ts
114
+ const USDC = Object.freeze({
115
+ symbol: "USDC",
116
+ decimals: 6,
117
+ name: "USD Coin"
118
+ });
119
+ const USDT = Object.freeze({
120
+ symbol: "USDT",
121
+ decimals: 6,
122
+ name: "Tether USD"
123
+ });
124
+ const solanaTokenTable = Object.freeze({ "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp": Object.freeze({
125
+ EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v: USDC,
126
+ Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB: USDT
127
+ }) });
113
128
  const lookupSolanaToken = (table, network, mint) => table[network]?.[mint];
114
129
  //#endregion
115
130
  //#region src/solana/decode.ts
116
131
  const LAMPORTS_ASSET = "lamports";
117
132
  const u32 = getU32Decoder();
118
- const u64 = getU64Decoder();
133
+ const u64$1 = getU64Decoder();
119
134
  const u32le = (data, offset) => u32.decode(data, offset);
120
- const u64le = (data, offset) => u64.decode(data, offset);
135
+ const u64le = (data, offset) => u64$1.decode(data, offset);
121
136
  /**
122
137
  * Classifies one instruction by program + discriminator/layout. Exact-length checks keep
123
138
  * non-canonical encodings out of the `full` class.
@@ -255,6 +270,82 @@ const decodeTransaction = (request, signer, table) => {
255
270
  const verifiabilitySolana = (request, signer, table = solanaTokenTable) => decodeSolana(request, signer, table).verifiability;
256
271
  const decodeSolana = (request, signer, table = solanaTokenTable) => decodeTransaction(request, signer, table);
257
272
  //#endregion
273
+ //#region src/solana/token2022.ts
274
+ /** SPL Token-2022 mint-account TLV extension type numbers (spl-token-2022 `ExtensionType`). */
275
+ const EXT = {
276
+ transferFeeConfig: 1,
277
+ confidentialTransferMint: 4,
278
+ defaultAccountState: 6,
279
+ nonTransferable: 9,
280
+ cpiGuard: 11,
281
+ permanentDelegate: 12,
282
+ transferHook: 14,
283
+ confidentialTransferFee: 16,
284
+ confidentialTransferFeeAmount: 17
285
+ };
286
+ const u64 = (v) => new DataView(v.buffer, v.byteOffset, 8).getBigUint64(0, true);
287
+ const u16 = (v) => new DataView(v.buffer, v.byteOffset, 2).getUint16(0, true);
288
+ const ACCOUNT_TYPE_MINT = 1;
289
+ const TYPE_OFFSET = 165;
290
+ /**
291
+ * Parse the extension region of a full Token-2022 mint account. The account is the 82-byte mint
292
+ * base, zero padding up to byte 165, the account-type byte (`1` = Mint) at 165, then the TLV region
293
+ * at 166 — each entry `u16 type, u16 len, len bytes`. Returns a typed summary; extensions this
294
+ * layer does not read are reported by type number in `unknown` rather than parsed.
295
+ */
296
+ const parseMintExtensions = (data, epoch) => {
297
+ if (data.length <= 166 || data[TYPE_OFFSET] !== ACCOUNT_TYPE_MINT) return {};
298
+ const tlv = data.subarray(166);
299
+ const out = { unknown: [] };
300
+ let offset = 0;
301
+ while (offset + 2 <= tlv.length) {
302
+ const type = u16(tlv.subarray(offset, offset + 2));
303
+ if (type === 0) break;
304
+ if (offset + 4 > tlv.length) throw new ChainError("invalid-request", `mint extension ${type} truncated`);
305
+ const len = u16(tlv.subarray(offset + 2, offset + 4));
306
+ offset += 4;
307
+ if (offset + len > tlv.length) throw new ChainError("invalid-request", `mint extension ${type} truncated`);
308
+ const body = tlv.subarray(offset, offset + len);
309
+ offset += len;
310
+ if (type === EXT.transferFeeConfig && len >= 108) {
311
+ const olderMax = u64(body.subarray(80));
312
+ const olderBps = u16(body.subarray(88));
313
+ const newerEpoch = u64(body.subarray(90));
314
+ const newerMax = u64(body.subarray(98));
315
+ const newerBps = u16(body.subarray(106));
316
+ const active = newerEpoch <= epoch ? {
317
+ bps: newerBps,
318
+ max: newerMax
319
+ } : {
320
+ bps: olderBps,
321
+ max: olderMax
322
+ };
323
+ if (active.bps !== 0 || active.max !== 0n) out.transferFee = {
324
+ basisPoints: active.bps,
325
+ maximumFee: active.max
326
+ };
327
+ } else if (type === EXT.transferHook && len >= 64) out.transferHook = { programId: body.subarray(32, 64) };
328
+ else if (type === EXT.permanentDelegate && len >= 32) {
329
+ const delegate = body.subarray(0, 32);
330
+ if (delegate.some((b) => b !== 0)) out.permanentDelegate = { delegate };
331
+ } else if (type === EXT.nonTransferable) out.nonTransferable = true;
332
+ else if (type === EXT.confidentialTransferMint || type === EXT.confidentialTransferFee || type === EXT.confidentialTransferFeeAmount) out.confidential = true;
333
+ else out.unknown.push(type);
334
+ }
335
+ return out.unknown.length === 0 ? out : {
336
+ ...out,
337
+ unknown: out.unknown
338
+ };
339
+ };
340
+ /**
341
+ * Net amount a recipient gets after the current-epoch transfer fee, `amt − min(amt*bps/10000,
342
+ * max)`.
343
+ */
344
+ const netAfterTransferFee = (amount, bps, max) => {
345
+ const fee = amount * BigInt(bps) / 10000n;
346
+ return amount - (fee > max ? max : fee);
347
+ };
348
+ //#endregion
258
349
  //#region src/solana/verify.ts
259
350
  /**
260
351
  * Ed25519 signature verification for `chain.sign` results: the host checks the kernel's 64-byte
@@ -350,6 +441,6 @@ const normalizeSolana = (request, signer) => {
350
441
  throw new ChainError("unsupported", `unsupported sign request kind: ${request["kind"]}`);
351
442
  };
352
443
  //#endregion
353
- export { PROGRAM_IDS, SOLANA_NETWORKS, decodeSolana, isSolanaAddress, normalizeSolana, parseCompiledMessage, solanaAddressFromPublicKey, solanaTokenTable, verifiabilitySolana, verifySolanaSignature };
444
+ export { EXT, PROGRAM_IDS, SOLANA_NETWORKS, decodeSolana, isSolanaAddress, netAfterTransferFee, normalizeSolana, parseCompiledMessage, parseMintExtensions, solanaAddressFromPublicKey, solanaTokenTable, verifiabilitySolana, verifySolanaSignature };
354
445
 
355
446
  //# sourceMappingURL=solana.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"solana.mjs","names":["decoder","isRecord"],"sources":["../src/solana/ids.ts","../src/solana/message.ts","../src/solana/tokens.ts","../src/solana/decode.ts","../src/solana/verify.ts","../src/solana/index.ts"],"sourcesContent":["import { getAddressDecoder } from \"@solana/addresses\";\n\nimport { ChainError } from \"../index.ts\";\n\n/** Well-known Solana program ids (base58, 32 bytes) — frozen constants. */\nexport const PROGRAM_IDS: Readonly<{\n system: string;\n computeBudget: string;\n associatedToken: string;\n token: string;\n token2022: string;\n stake: string;\n}> = Object.freeze({\n system: \"11111111111111111111111111111111\",\n computeBudget: \"ComputeBudget111111111111111111111111111111\",\n associatedToken: \"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL\",\n token: \"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA\",\n token2022: \"TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb\",\n stake: \"Stake11111111111111111111111111111111111111\",\n});\n\n/**\n * CAIP-2 ids the wallet knows. The wire message itself carries no network marker — `network` is the\n * only declaration and cannot be proven from the bytes.\n */\nexport const SOLANA_NETWORKS: ReadonlyArray<string> = Object.freeze([\n \"solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp\",\n \"solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1\",\n] as const);\n\nconst BASE58 = /^[1-9A-HJ-NP-Za-km-z]{32,44}$/;\n\nexport const isSolanaAddress = (value: string): boolean => BASE58.test(value);\n\nconst decoder = getAddressDecoder();\n\n/** Base58-encoded address for a 32-byte ed25519 public key. */\nexport function solanaAddressFromPublicKey(pubkey: Uint8Array): string {\n if (pubkey.length !== 32) {\n throw new ChainError(\"invalid-address\", \"expected a 32-byte ed25519 public key\");\n }\n return decoder.decode(pubkey);\n}\n","import { getCompiledTransactionMessageDecoder } from \"@solana/transaction-messages\";\n\nimport { ChainError } from \"../index.ts\";\nimport { isSolanaAddress } from \"./ids.ts\";\n\nexport const SOLANA_TRANSACTION_MAX_BYTES = 1232;\n\nexport type CompiledIx = {\n readonly programAddressIndex: number;\n readonly accountIndices: ReadonlyArray<number>;\n readonly data: Uint8Array;\n};\n\nexport type ParsedSolanaMessage = {\n readonly version: \"legacy\" | 0;\n readonly numRequiredSignatures: number;\n readonly staticAccounts: ReadonlyArray<string>;\n readonly instructions: ReadonlyArray<CompiledIx>;\n readonly lookupCount: number;\n readonly lookupAddresses: ReadonlyArray<string>;\n};\n\nconst decoder = getCompiledTransactionMessageDecoder();\n\n/**\n * Decodes a compiled wire message; rejects trailing bytes and the 1232-byte transaction limit. The\n * fee payer is `staticAccounts[0]` — every valid transaction signs it.\n */\nexport const parseCompiledMessage = (bytes: Uint8Array): ParsedSolanaMessage => {\n if (bytes.length > SOLANA_TRANSACTION_MAX_BYTES) {\n throw new ChainError(\"invalid-request\", \"compiled message exceeds the 1232-byte limit\");\n }\n if (bytes.length === 0) {\n throw new ChainError(\"invalid-request\", \"compiled message is empty\");\n }\n let decoded: unknown;\n try {\n decoded = decoder.decode(bytes);\n } catch {\n throw new ChainError(\"invalid-request\", \"compiled message failed to decode\");\n }\n const message = asCompiledMessage(decoded);\n const staticAccounts = [...message.staticAccounts];\n const lookups = message.addressTableLookups;\n return {\n version: message.version,\n numRequiredSignatures: message.numSignerAccounts,\n staticAccounts,\n instructions: message.instructions,\n lookupCount: lookups.length,\n lookupAddresses: lookups.map((l) => l.lookupTableAddress),\n };\n};\n\ntype CompiledMessage = {\n readonly version: \"legacy\" | 0;\n readonly numSignerAccounts: number;\n readonly staticAccounts: ReadonlyArray<string>;\n readonly instructions: ReadonlyArray<CompiledIx>;\n readonly addressTableLookups: ReadonlyArray<{\n readonly lookupTableAddress: string;\n readonly readonlyIndexes: ReadonlyArray<number>;\n readonly writableIndexes: ReadonlyArray<number>;\n }>;\n};\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === \"object\" && value !== null && !Array.isArray(value);\n\nconst isStringArray = (value: unknown): value is ReadonlyArray<string> =>\n Array.isArray(value) && value.every((v) => typeof v === \"string\");\n\nconst isNumberArray = (value: unknown): value is ReadonlyArray<number> =>\n Array.isArray(value) && value.every((v) => typeof v === \"number\");\n\nconst isArrayLike = (value: unknown): value is { readonly length: number } =>\n isRecord(value) && typeof value[\"length\"] === \"number\";\n\nconst isIx = (value: unknown): value is CompiledIx =>\n isRecord(value) &&\n typeof value[\"programAddressIndex\"] === \"number\" &&\n (value[\"accountIndices\"] === undefined ||\n isNumberArray(value[\"accountIndices\"]) ||\n isArrayLike(value[\"accountIndices\"])) &&\n value[\"data\"] instanceof Uint8Array;\n\nconst isLookup = (\n value: unknown,\n): value is {\n lookupTableAddress: string;\n readonlyIndexes: ReadonlyArray<number> | Uint8Array;\n writableIndexes: ReadonlyArray<number> | Uint8Array;\n} =>\n isRecord(value) &&\n typeof value[\"lookupTableAddress\"] === \"string\" &&\n (isNumberArray(value[\"readonlyIndexes\"]) || value[\"readonlyIndexes\"] instanceof Uint8Array) &&\n (isNumberArray(value[\"writableIndexes\"]) || value[\"writableIndexes\"] instanceof Uint8Array);\n\nconst asCompiledMessage = (value: unknown): CompiledMessage => {\n if (!isRecord(value) || !isRecord(value[\"header\"])) {\n throw new ChainError(\"invalid-request\", \"compiled message failed to decode\");\n }\n const { header } = value;\n const { staticAccounts } = value;\n const { instructions } = value;\n const lookups = value[\"addressTableLookups\"];\n if (\n typeof header[\"numSignerAccounts\"] !== \"number\" ||\n !isStringArray(staticAccounts) ||\n !Array.isArray(instructions) ||\n !instructions.every(isIx) ||\n (lookups !== undefined && (!Array.isArray(lookups) || !lookups.every(isLookup)))\n ) {\n throw new ChainError(\"invalid-request\", \"compiled message failed to decode\");\n }\n const version = value[\"version\"] === 0 ? 0 : \"legacy\";\n const ixs = instructions.map((ix) => {\n if (!isIx(ix)) {\n throw new ChainError(\"invalid-request\", \"compiled message failed to decode\");\n }\n const indices = ix.accountIndices;\n return {\n programAddressIndex: ix.programAddressIndex,\n accountIndices: indices === undefined ? [] : [...indices],\n data: ix.data,\n };\n });\n const tables = (lookups ?? []).map((t) => {\n if (!isLookup(t)) {\n throw new ChainError(\"invalid-request\", \"compiled message failed to decode\");\n }\n return {\n lookupTableAddress: t.lookupTableAddress,\n readonlyIndexes: [...t.readonlyIndexes],\n writableIndexes: [...t.writableIndexes],\n };\n });\n return {\n version,\n numSignerAccounts: header[\"numSignerAccounts\"],\n staticAccounts,\n instructions: ixs,\n addressTableLookups: tables,\n };\n};\n\n/**\n * Resolves an account index across static accounts and (request-declared) lookup tables in the\n * compiled lookup order: writable entries then readable.\n */\nexport const resolveAccountIndex = (\n parsed: ParsedSolanaMessage,\n index: number,\n lookups: ReadonlyArray<{ address: string; addresses: ReadonlyArray<string> }> | undefined,\n): string | undefined => {\n if (index < parsed.staticAccounts.length) {\n return parsed.staticAccounts[index];\n }\n if (lookups === undefined) {\n return undefined;\n }\n let offset = index - parsed.staticAccounts.length;\n for (const table of lookups) {\n if (offset < table.addresses.length) {\n return table.addresses[offset];\n }\n offset -= table.addresses.length;\n }\n return undefined;\n};\n\n/** All declared lookup-table entries must be valid base58 32-byte addresses. */\nexport const validateLookupTables = (\n tables: ReadonlyArray<{ address: string; addresses: ReadonlyArray<string> }> | undefined,\n): void => {\n if (tables === undefined) {\n return;\n }\n for (const table of tables) {\n if (!isSolanaAddress(table.address) || !table.addresses.every(isSolanaAddress)) {\n throw new ChainError(\n \"invalid-address\",\n \"lookup table entries must be base58 32-byte addresses\",\n );\n }\n }\n};\n","/**\n * Built-in SPL token table, keyed by `network` then mint address. Intentionally EMPTY in this layer\n * — real entries need official-source review (C6). Tests exercise the known-mint path through an\n * internal table parameter that is not exported from the package entry points.\n */\n\nexport type SolanaToken = {\n readonly symbol: string;\n readonly decimals: number;\n readonly name?: string;\n};\n\nexport type SolanaTokenTable = Readonly<Record<string, Readonly<Record<string, SolanaToken>>>>;\n\nconst EMPTY_TABLE: SolanaTokenTable = Object.freeze({});\n\nexport const solanaTokenTable: SolanaTokenTable = EMPTY_TABLE;\n\nexport const lookupSolanaToken = (\n table: SolanaTokenTable,\n network: string,\n mint: string,\n): SolanaToken | undefined => table[network]?.[mint];\n","import { getU32Decoder, getU64Decoder } from \"@solana/codecs\";\n\nimport type {\n ApprovalChange,\n AssetFlow,\n DisplayIntent,\n SignRequest,\n Verifiability,\n} from \"../index.ts\";\nimport { PROGRAM_IDS } from \"./ids.ts\";\nimport { parseCompiledMessage, resolveAccountIndex } from \"./message.ts\";\nimport type { ParsedSolanaMessage } from \"./message.ts\";\nimport { lookupSolanaToken, solanaTokenTable } from \"./tokens.ts\";\nimport type { SolanaTokenTable } from \"./tokens.ts\";\n\nconst LAMPORTS_ASSET = \"lamports\";\n\nconst u32 = getU32Decoder();\nconst u64 = getU64Decoder();\nconst u32le = (data: Uint8Array, offset: number): number => u32.decode(data, offset);\nconst u64le = (data: Uint8Array, offset: number): bigint => u64.decode(data, offset);\n\ntype IxCall = {\n readonly kind:\n | \"system-transfer\"\n | \"cu-limit\"\n | \"cu-price\"\n | \"ata-create\"\n | \"ata-create-idempotent\"\n | \"token-transfer-checked\"\n | \"token-approve\"\n | \"stake\"\n | \"other\";\n readonly to?: string | undefined;\n readonly amount?: bigint | undefined;\n readonly decimals?: number | undefined;\n readonly mint?: string | undefined;\n readonly units?: number | undefined;\n readonly microLamports?: bigint | undefined;\n};\n\n/**\n * Classifies one instruction by program + discriminator/layout. Exact-length checks keep\n * non-canonical encodings out of the `full` class.\n */\nconst classifyIx = (\n parsed: ParsedSolanaMessage,\n ix: { programAddressIndex: number; accountIndices: ReadonlyArray<number>; data: Uint8Array },\n lookups: ReadonlyArray<{ address: string; addresses: ReadonlyArray<string> }> | undefined,\n): IxCall => {\n const program = resolveAccountIndex(parsed, ix.programAddressIndex, lookups);\n const { data } = ix;\n if (program === PROGRAM_IDS.system) {\n if (data.length === 12 && u32le(data, 0) === 2) {\n return {\n kind: \"system-transfer\",\n to: resolveAccountIndex(parsed, ix.accountIndices[1] ?? 0, lookups),\n amount: u64le(data, 4),\n };\n }\n return { kind: \"other\" };\n }\n if (program === PROGRAM_IDS.computeBudget) {\n if (data.length === 5 && data[0] === 2) {\n return { kind: \"cu-limit\", units: u32le(data, 1) };\n }\n if (data.length === 9 && data[0] === 3) {\n return { kind: \"cu-price\", microLamports: u64le(data, 1) };\n }\n return { kind: \"other\" };\n }\n if (program === PROGRAM_IDS.associatedToken) {\n if (data.length === 1 && data[0] === 0) {\n return { kind: \"ata-create\" };\n }\n if (data.length === 1 && data[0] === 1) {\n return { kind: \"ata-create-idempotent\" };\n }\n return { kind: \"other\" };\n }\n if (program === PROGRAM_IDS.token || program === PROGRAM_IDS.token2022) {\n if (data.length === 10 && data[0] === 12) {\n return {\n kind: \"token-transfer-checked\",\n amount: u64le(data, 1),\n decimals: data[9],\n to: resolveAccountIndex(parsed, ix.accountIndices[2] ?? 0, lookups),\n mint: resolveAccountIndex(parsed, ix.accountIndices[1] ?? 0, lookups),\n };\n }\n if (data.length === 9 && data[0] === 4) {\n return {\n kind: \"token-approve\",\n amount: u64le(data, 1),\n to: resolveAccountIndex(parsed, ix.accountIndices[1] ?? 0, lookups),\n };\n }\n return { kind: \"other\" };\n }\n if (program === PROGRAM_IDS.stake) {\n return { kind: \"stake\" };\n }\n return { kind: \"other\" };\n};\n\nconst FULL_KINDS = new Set([\n \"system-transfer\",\n \"cu-limit\",\n \"cu-price\",\n \"ata-create\",\n \"ata-create-idempotent\",\n]);\n\nconst classify = (\n parsed: ParsedSolanaMessage,\n calls: ReadonlyArray<IxCall>,\n network: string,\n table: SolanaTokenTable,\n): Verifiability => {\n if (parsed.lookupCount > 0) {\n return \"partial\";\n }\n let allFull = true;\n for (const call of calls) {\n if (call.kind === \"other\") {\n return \"opaque\";\n }\n if (call.kind === \"token-approve\" || call.kind === \"stake\") {\n allFull = false;\n }\n if (\n call.kind === \"token-transfer-checked\" &&\n lookupSolanaToken(table, network, call.mint ?? \"\") === undefined\n ) {\n allFull = false;\n }\n if (\n !FULL_KINDS.has(call.kind) &&\n call.kind !== \"token-transfer-checked\" &&\n call.kind !== \"token-approve\" &&\n call.kind !== \"stake\"\n ) {\n return \"opaque\";\n }\n }\n return allFull ? \"full\" : \"partial\";\n};\n\nconst feeLamports = (\n parsed: ParsedSolanaMessage,\n calls: ReadonlyArray<IxCall>,\n): bigint | undefined => {\n const limit = calls.find((c) => c.kind === \"cu-limit\")?.units;\n const price = calls.find((c) => c.kind === \"cu-price\")?.microLamports;\n if (limit === undefined || price === undefined) {\n return undefined;\n }\n const signatures = BigInt(parsed.numRequiredSignatures);\n return 5000n * signatures + (price * BigInt(limit) + 999_999n) / 1_000_000n;\n};\n\nconst decodeTransaction = (\n request: Extract<SignRequest, { kind: \"solana.transaction\" }>,\n signer: string,\n table: SolanaTokenTable,\n): DisplayIntent => {\n const parsed = parseCompiledMessage(request.message);\n const lookups = request.lookupTables?.map((t) => ({\n address: t.address,\n addresses: t.addresses,\n }));\n const calls = parsed.instructions.map((ix) => classifyIx(parsed, ix, lookups));\n const verifiability = classify(parsed, calls, request.network, table);\n const outflows: AssetFlow[] = [];\n const approvals: ApprovalChange[] = [];\n for (const call of calls) {\n if (call.kind === \"system-transfer\" && call.to !== undefined) {\n const [source] = parsed.staticAccounts;\n if (source === signer) {\n outflows.push({\n to: call.to,\n amount: { asset: LAMPORTS_ASSET, amount: (call.amount ?? 0n).toString(10) },\n verified: true,\n });\n }\n }\n if (call.kind === \"token-transfer-checked\") {\n const token = lookupSolanaToken(table, request.network, call.mint ?? \"\");\n outflows.push({\n to: call.to ?? \"\",\n amount: {\n asset: call.mint ?? \"\",\n amount: (call.amount ?? 0n).toString(10),\n ...(token === undefined ? {} : { symbol: token.symbol, decimals: token.decimals }),\n },\n verified: token !== undefined,\n });\n }\n if (call.kind === \"token-approve\") {\n approvals.push({\n asset: call.mint ?? \"\",\n spender: call.to ?? \"\",\n amount: (call.amount ?? 0n).toString(10),\n unlimited: false,\n verified: false,\n });\n }\n }\n const fee = feeLamports(parsed, calls);\n return {\n family: \"solana\",\n network: request.network,\n summary: outflows.length > 0 ? \"transfer\" : \"contract-call\",\n outflows,\n approvals,\n fee:\n fee === undefined ? undefined : { max: { asset: LAMPORTS_ASSET, amount: fee.toString(10) } },\n warnings: [],\n verifiability,\n };\n};\n\n/** What the signer can guarantee about this request (WD-065). */\nexport const verifiabilitySolana = (\n request: Extract<SignRequest, { kind: \"solana.transaction\" }>,\n signer: string,\n table: SolanaTokenTable = solanaTokenTable,\n): Verifiability => decodeSolana(request, signer, table).verifiability;\n\nexport const decodeSolana = (\n request: Extract<SignRequest, { kind: \"solana.transaction\" }>,\n signer: string,\n table: SolanaTokenTable = solanaTokenTable,\n): DisplayIntent => decodeTransaction(request, signer, table);\n","/**\n * Ed25519 signature verification for `chain.sign` results: the host checks the kernel's 64-byte\n * signature against the message and the account address returned by `wallet.accounts` — a wrong\n * signer fails closed.\n */\nimport { ed25519 } from \"@noble/curves/ed25519.js\";\nimport { address, getAddressEncoder } from \"@solana/addresses\";\n\n/** Whether `signature` is a valid ed25519 signature of `message` by the key behind `address`. */\nexport const verifySolanaSignature = (\n message: Uint8Array,\n signature: Uint8Array,\n accountAddress: string,\n): boolean => {\n if (signature.length !== 64) {\n return false;\n }\n try {\n return ed25519.verify(\n signature,\n message,\n new Uint8Array(getAddressEncoder().encode(address(accountAddress))),\n );\n } catch {\n return false;\n }\n};\n","import { ChainError } from \"../index.ts\";\nimport type { AccountRef, SignRequest } from \"../index.ts\";\nimport { SOLANA_NETWORKS, isSolanaAddress } from \"./ids.ts\";\nimport { parseCompiledMessage, validateLookupTables } from \"./message.ts\";\n\nexport {\n PROGRAM_IDS,\n SOLANA_NETWORKS,\n isSolanaAddress,\n solanaAddressFromPublicKey,\n} from \"./ids.ts\";\nexport { decodeSolana, verifiabilitySolana } from \"./decode.ts\";\nexport { parseCompiledMessage } from \"./message.ts\";\nexport { verifySolanaSignature } from \"./verify.ts\";\nexport type { SolanaTokenTable } from \"./tokens.ts\";\nexport { solanaTokenTable } from \"./tokens.ts\";\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === \"object\" && value !== null && !Array.isArray(value);\n\nconst isAccountRef = (value: unknown): value is AccountRef => {\n if (!isRecord(value) || typeof value[\"kind\"] !== \"string\") {\n return false;\n }\n if (value[\"kind\"] === \"hd\") {\n return (\n typeof value[\"walletId\"] === \"string\" &&\n typeof value[\"groupIndex\"] === \"number\" &&\n typeof value[\"template\"] === \"string\"\n );\n }\n return (\n value[\"kind\"] === \"imported\" &&\n typeof value[\"keyId\"] === \"string\" &&\n typeof value[\"family\"] === \"string\"\n );\n};\n\nconst solanaNetwork = (network: string): void => {\n if (!SOLANA_NETWORKS.includes(network)) {\n throw new ChainError(\"unsupported\", `unknown Solana network: ${network}`);\n }\n};\n\ntype LookupTable = {\n readonly address: string;\n readonly addresses: ReadonlyArray<string>;\n};\n\nconst validateLookupTablesRaw = (tables: unknown): ReadonlyArray<LookupTable> | undefined => {\n if (tables === undefined) {\n return undefined;\n }\n if (!Array.isArray(tables)) {\n throw new ChainError(\"unknown-field\", \"lookupTables must be an array\");\n }\n const parsed = tables.map((t): LookupTable => {\n if (!isRecord(t) || typeof t[\"address\"] !== \"string\" || !Array.isArray(t[\"addresses\"])) {\n throw new ChainError(\"unknown-field\", \"lookupTables entries must be { address, addresses }\");\n }\n const addresses = t[\"addresses\"].map((a): string => {\n if (typeof a !== \"string\") {\n throw new ChainError(\"invalid-address\", \"lookup table addresses must be strings\");\n }\n return a;\n });\n return { address: t[\"address\"], addresses };\n });\n validateLookupTables(parsed);\n return parsed;\n};\n\n/**\n * Normalizes a Solana sign request. `signer` is the fee payer the wallet is about to sign for — the\n * message must declare it as the first static account. A raw `solana.message` must not decode as a\n * transaction message (chains.mdx rule — a bytes-to-sign path that produces a transaction signature\n * is a wallet-drainer). Idempotent.\n */\nexport const normalizeSolana = (request: unknown, signer: string): SignRequest => {\n if (!isRecord(request) || typeof request[\"kind\"] !== \"string\") {\n throw new ChainError(\"invalid-request\", \"request must be an object with a kind\");\n }\n const { network } = request;\n const { account } = request;\n if (typeof network !== \"string\") {\n throw new ChainError(\"invalid-request\", \"request.network must be a string\");\n }\n if (!isAccountRef(account)) {\n throw new ChainError(\"invalid-request\", \"request.account must be an AccountRef\");\n }\n solanaNetwork(network);\n if (!isSolanaAddress(signer)) {\n throw new ChainError(\"invalid-address\", \"signer is not a base58 address\");\n }\n const { message } = request;\n if (!(message instanceof Uint8Array)) {\n throw new ChainError(\"invalid-request\", \"message must be bytes\");\n }\n if (request[\"kind\"] === \"solana.transaction\") {\n const lookupTables = validateLookupTablesRaw(request[\"lookupTables\"]);\n const parsed = parseCompiledMessage(message);\n const [feePayer] = parsed.staticAccounts;\n if (feePayer === undefined || feePayer !== signer) {\n throw new ChainError(\"fee-payer-mismatch\", \"signer is not the transaction fee payer\");\n }\n return {\n kind: \"solana.transaction\",\n network,\n account,\n message,\n ...(lookupTables === undefined\n ? {}\n : {\n lookupTables: (\n lookupTables as ReadonlyArray<{\n readonly address: string;\n readonly addresses: ReadonlyArray<string>;\n }>\n ).map((t) => ({ address: t.address, addresses: [...t.addresses] })),\n }),\n };\n }\n if (request[\"kind\"] === \"solana.message\") {\n const { format } = request;\n if (format !== \"raw\") {\n throw new ChainError(\n \"unsupported\",\n `solana.message format ${String(format)} is not supported`,\n );\n }\n let decodesAsTransaction = true;\n try {\n parseCompiledMessage(message);\n } catch {\n decodesAsTransaction = false;\n }\n if (decodesAsTransaction) {\n throw new ChainError(\n \"invalid-request\",\n \"solana.message payload decodes as a transaction message — use solana.transaction\",\n );\n }\n return { kind: \"solana.message\", network, account, message, format };\n }\n throw new ChainError(\"unsupported\", `unsupported sign request kind: ${request[\"kind\"]}`);\n};\n"],"mappings":";;;;;;;AAKA,MAAa,cAOR,OAAO,OAAO;CACjB,QAAQ;CACR,eAAe;CACf,iBAAiB;CACjB,OAAO;CACP,WAAW;CACX,OAAO;AACT,CAAC;;;;;AAMD,MAAa,kBAAyC,OAAO,OAAO,CAClE,2CACA,yCACF,CAAU;AAEV,MAAM,SAAS;AAEf,MAAa,mBAAmB,UAA2B,OAAO,KAAK,KAAK;AAE5E,MAAMA,YAAU,kBAAkB;;AAGlC,SAAgB,2BAA2B,QAA4B;CACrE,IAAI,OAAO,WAAW,IACpB,MAAM,IAAI,WAAW,mBAAmB,uCAAuC;CAEjF,OAAOA,UAAQ,OAAO,MAAM;AAC9B;ACpBA,MAAM,UAAU,qCAAqC;;;;;AAMrD,MAAa,wBAAwB,UAA2C;CAC9E,IA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B;EAC5C,MAAM,eAAe,wBAAwB,QAAQ,eAAe;EAEpE,MAAM,CAAC,YADQ,qBAAqB,OACZ,CAAC,CAAC;EAC1B,IAAI,aAAa,KAAA,KAAa,aAAa,QACzC,MAAM,IAAI,WAAW,sBAAsB,yCAAyC;EAEtF,OAAO;GACL,MAAM;GACN;GACA;GACA;GACA,GAAI,iBAAiB,KAAA,IACjB,CAAC,IACD,EACE,cACE,aAIA,KAAK,OAAO;IAAE,SAAS,EAAE;IAAS,WAAW,CAAC,GAAG,EAAE,SAAS;GAAE,EAAE,EACpE;EACN;CACF;CACA,IAAI,QAAQ,YAAY,kBAAkB;EACxC,MAAM,EAAE,WAAW;EACnB,IAAI,WAAW,OACb,MAAM,IAAI,WACR,eACA,yBAAyB,OAAO,MAAM,EAAE,kBAC1C;EAEF,IAAI,uBAAuB;EAC3B,IAAI;GACF,qBAAqB,OAAO;EAC9B,QAAQ;GACN,uBAAuB;EACzB;EACA,IAAI,sBACF,MAAM,IAAI,WACR,mBACA,kFACF;EAEF,OAAO;GAAE,MAAM;GAAkB;GAAS;GAAS;GAAS;EAAO;CACrE;CACA,MAAM,IAAI,WAAW,eAAe,kCAAkC,QAAQ,SAAS;AACzF"}
1
+ {"version":3,"file":"solana.mjs","names":["decoder","isRecord","u64"],"sources":["../src/solana/ids.ts","../src/solana/message.ts","../src/solana/tokens.ts","../src/solana/decode.ts","../src/solana/token2022.ts","../src/solana/verify.ts","../src/solana/index.ts"],"sourcesContent":["import { getAddressDecoder } from \"@solana/addresses\";\n\nimport { ChainError } from \"../index.ts\";\n\n/** Well-known Solana program ids (base58, 32 bytes) — frozen constants. */\nexport const PROGRAM_IDS: Readonly<{\n system: string;\n computeBudget: string;\n associatedToken: string;\n token: string;\n token2022: string;\n stake: string;\n}> = Object.freeze({\n system: \"11111111111111111111111111111111\",\n computeBudget: \"ComputeBudget111111111111111111111111111111\",\n associatedToken: \"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL\",\n token: \"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA\",\n token2022: \"TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb\",\n stake: \"Stake11111111111111111111111111111111111111\",\n});\n\n/**\n * CAIP-2 ids the wallet knows. The wire message itself carries no network marker — `network` is the\n * only declaration and cannot be proven from the bytes.\n */\nexport const SOLANA_NETWORKS: ReadonlyArray<string> = Object.freeze([\n \"solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp\",\n \"solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1\",\n] as const);\n\nconst BASE58 = /^[1-9A-HJ-NP-Za-km-z]{32,44}$/;\n\nexport const isSolanaAddress = (value: string): boolean => BASE58.test(value);\n\nconst decoder = getAddressDecoder();\n\n/** Base58-encoded address for a 32-byte ed25519 public key. */\nexport function solanaAddressFromPublicKey(pubkey: Uint8Array): string {\n if (pubkey.length !== 32) {\n throw new ChainError(\"invalid-address\", \"expected a 32-byte ed25519 public key\");\n }\n return decoder.decode(pubkey);\n}\n","import { getCompiledTransactionMessageDecoder } from \"@solana/transaction-messages\";\n\nimport { ChainError } from \"../index.ts\";\nimport { isSolanaAddress } from \"./ids.ts\";\n\nexport const SOLANA_TRANSACTION_MAX_BYTES = 1232;\n\nexport type CompiledIx = {\n readonly programAddressIndex: number;\n readonly accountIndices: ReadonlyArray<number>;\n readonly data: Uint8Array;\n};\n\nexport type ParsedSolanaMessage = {\n readonly version: \"legacy\" | 0;\n readonly numRequiredSignatures: number;\n readonly staticAccounts: ReadonlyArray<string>;\n readonly instructions: ReadonlyArray<CompiledIx>;\n readonly lookupCount: number;\n readonly lookupAddresses: ReadonlyArray<string>;\n};\n\nconst decoder = getCompiledTransactionMessageDecoder();\n\n/**\n * Decodes a compiled wire message; rejects trailing bytes and the 1232-byte transaction limit. The\n * fee payer is `staticAccounts[0]` — every valid transaction signs it.\n */\nexport const parseCompiledMessage = (bytes: Uint8Array): ParsedSolanaMessage => {\n if (bytes.length > SOLANA_TRANSACTION_MAX_BYTES) {\n throw new ChainError(\"invalid-request\", \"compiled message exceeds the 1232-byte limit\");\n }\n if (bytes.length === 0) {\n throw new ChainError(\"invalid-request\", \"compiled message is empty\");\n }\n let decoded: unknown;\n try {\n decoded = decoder.decode(bytes);\n } catch {\n throw new ChainError(\"invalid-request\", \"compiled message failed to decode\");\n }\n const message = asCompiledMessage(decoded);\n const staticAccounts = [...message.staticAccounts];\n const lookups = message.addressTableLookups;\n return {\n version: message.version,\n numRequiredSignatures: message.numSignerAccounts,\n staticAccounts,\n instructions: message.instructions,\n lookupCount: lookups.length,\n lookupAddresses: lookups.map((l) => l.lookupTableAddress),\n };\n};\n\ntype CompiledMessage = {\n readonly version: \"legacy\" | 0;\n readonly numSignerAccounts: number;\n readonly staticAccounts: ReadonlyArray<string>;\n readonly instructions: ReadonlyArray<CompiledIx>;\n readonly addressTableLookups: ReadonlyArray<{\n readonly lookupTableAddress: string;\n readonly readonlyIndexes: ReadonlyArray<number>;\n readonly writableIndexes: ReadonlyArray<number>;\n }>;\n};\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === \"object\" && value !== null && !Array.isArray(value);\n\nconst isStringArray = (value: unknown): value is ReadonlyArray<string> =>\n Array.isArray(value) && value.every((v) => typeof v === \"string\");\n\nconst isNumberArray = (value: unknown): value is ReadonlyArray<number> =>\n Array.isArray(value) && value.every((v) => typeof v === \"number\");\n\nconst isArrayLike = (value: unknown): value is { readonly length: number } =>\n isRecord(value) && typeof value[\"length\"] === \"number\";\n\nconst isIx = (value: unknown): value is CompiledIx =>\n isRecord(value) &&\n typeof value[\"programAddressIndex\"] === \"number\" &&\n (value[\"accountIndices\"] === undefined ||\n isNumberArray(value[\"accountIndices\"]) ||\n isArrayLike(value[\"accountIndices\"])) &&\n value[\"data\"] instanceof Uint8Array;\n\nconst isLookup = (\n value: unknown,\n): value is {\n lookupTableAddress: string;\n readonlyIndexes: ReadonlyArray<number> | Uint8Array;\n writableIndexes: ReadonlyArray<number> | Uint8Array;\n} =>\n isRecord(value) &&\n typeof value[\"lookupTableAddress\"] === \"string\" &&\n (isNumberArray(value[\"readonlyIndexes\"]) || value[\"readonlyIndexes\"] instanceof Uint8Array) &&\n (isNumberArray(value[\"writableIndexes\"]) || value[\"writableIndexes\"] instanceof Uint8Array);\n\nconst asCompiledMessage = (value: unknown): CompiledMessage => {\n if (!isRecord(value) || !isRecord(value[\"header\"])) {\n throw new ChainError(\"invalid-request\", \"compiled message failed to decode\");\n }\n const { header } = value;\n const { staticAccounts } = value;\n const { instructions } = value;\n const lookups = value[\"addressTableLookups\"];\n if (\n typeof header[\"numSignerAccounts\"] !== \"number\" ||\n !isStringArray(staticAccounts) ||\n !Array.isArray(instructions) ||\n !instructions.every(isIx) ||\n (lookups !== undefined && (!Array.isArray(lookups) || !lookups.every(isLookup)))\n ) {\n throw new ChainError(\"invalid-request\", \"compiled message failed to decode\");\n }\n const version = value[\"version\"] === 0 ? 0 : \"legacy\";\n const ixs = instructions.map((ix) => {\n if (!isIx(ix)) {\n throw new ChainError(\"invalid-request\", \"compiled message failed to decode\");\n }\n const indices = ix.accountIndices;\n return {\n programAddressIndex: ix.programAddressIndex,\n accountIndices: indices === undefined ? [] : [...indices],\n data: ix.data,\n };\n });\n const tables = (lookups ?? []).map((t) => {\n if (!isLookup(t)) {\n throw new ChainError(\"invalid-request\", \"compiled message failed to decode\");\n }\n return {\n lookupTableAddress: t.lookupTableAddress,\n readonlyIndexes: [...t.readonlyIndexes],\n writableIndexes: [...t.writableIndexes],\n };\n });\n return {\n version,\n numSignerAccounts: header[\"numSignerAccounts\"],\n staticAccounts,\n instructions: ixs,\n addressTableLookups: tables,\n };\n};\n\n/**\n * Resolves an account index across static accounts and (request-declared) lookup tables in the\n * compiled lookup order: writable entries then readable.\n */\nexport const resolveAccountIndex = (\n parsed: ParsedSolanaMessage,\n index: number,\n lookups: ReadonlyArray<{ address: string; addresses: ReadonlyArray<string> }> | undefined,\n): string | undefined => {\n if (index < parsed.staticAccounts.length) {\n return parsed.staticAccounts[index];\n }\n if (lookups === undefined) {\n return undefined;\n }\n let offset = index - parsed.staticAccounts.length;\n for (const table of lookups) {\n if (offset < table.addresses.length) {\n return table.addresses[offset];\n }\n offset -= table.addresses.length;\n }\n return undefined;\n};\n\n/** All declared lookup-table entries must be valid base58 32-byte addresses. */\nexport const validateLookupTables = (\n tables: ReadonlyArray<{ address: string; addresses: ReadonlyArray<string> }> | undefined,\n): void => {\n if (tables === undefined) {\n return;\n }\n for (const table of tables) {\n if (!isSolanaAddress(table.address) || !table.addresses.every(isSolanaAddress)) {\n throw new ChainError(\n \"invalid-address\",\n \"lookup table entries must be base58 32-byte addresses\",\n );\n }\n }\n};\n","/**\n * Built-in SPL token table, keyed by `network` then mint address. An entry makes a\n * `transferChecked` `full`-verifiable (WD-065), so every entry must come from the issuer's own\n * published list; the source is recorded per issuer below.\n */\n\nexport type SolanaToken = {\n readonly symbol: string;\n readonly decimals: number;\n readonly name?: string;\n};\n\nexport type SolanaTokenTable = Readonly<Record<string, Readonly<Record<string, SolanaToken>>>>;\n\n// Circle USDC on Solana mainnet (SPL Token program mint, 6 decimals), from\n// https://developers.circle.com/stablecoins/usdc-contract-addresses (reviewed 2026-10-30).\nconst USDC: SolanaToken = Object.freeze({ symbol: \"USDC\", decimals: 6, name: \"USD Coin\" });\n\n// Tether USDT on Solana mainnet (SPL Token program mint, 6 decimals), from\n// https://tether.to/en/supported-protocols/ (reviewed 2026-10-31).\nconst USDT: SolanaToken = Object.freeze({ symbol: \"USDT\", decimals: 6, name: \"Tether USD\" });\n\nexport const solanaTokenTable: SolanaTokenTable = Object.freeze({\n \"solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp\": Object.freeze({\n EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v: USDC,\n Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB: USDT,\n }),\n});\n\nexport const lookupSolanaToken = (\n table: SolanaTokenTable,\n network: string,\n mint: string,\n): SolanaToken | undefined => table[network]?.[mint];\n","import { getU32Decoder, getU64Decoder } from \"@solana/codecs\";\n\nimport type {\n ApprovalChange,\n AssetFlow,\n DisplayIntent,\n SignRequest,\n Verifiability,\n} from \"../index.ts\";\nimport { PROGRAM_IDS } from \"./ids.ts\";\nimport { parseCompiledMessage, resolveAccountIndex } from \"./message.ts\";\nimport type { ParsedSolanaMessage } from \"./message.ts\";\nimport { lookupSolanaToken, solanaTokenTable } from \"./tokens.ts\";\nimport type { SolanaTokenTable } from \"./tokens.ts\";\n\nconst LAMPORTS_ASSET = \"lamports\";\n\nconst u32 = getU32Decoder();\nconst u64 = getU64Decoder();\nconst u32le = (data: Uint8Array, offset: number): number => u32.decode(data, offset);\nconst u64le = (data: Uint8Array, offset: number): bigint => u64.decode(data, offset);\n\ntype IxCall = {\n readonly kind:\n | \"system-transfer\"\n | \"cu-limit\"\n | \"cu-price\"\n | \"ata-create\"\n | \"ata-create-idempotent\"\n | \"token-transfer-checked\"\n | \"token-approve\"\n | \"stake\"\n | \"other\";\n readonly to?: string | undefined;\n readonly amount?: bigint | undefined;\n readonly decimals?: number | undefined;\n readonly mint?: string | undefined;\n readonly units?: number | undefined;\n readonly microLamports?: bigint | undefined;\n};\n\n/**\n * Classifies one instruction by program + discriminator/layout. Exact-length checks keep\n * non-canonical encodings out of the `full` class.\n */\nconst classifyIx = (\n parsed: ParsedSolanaMessage,\n ix: { programAddressIndex: number; accountIndices: ReadonlyArray<number>; data: Uint8Array },\n lookups: ReadonlyArray<{ address: string; addresses: ReadonlyArray<string> }> | undefined,\n): IxCall => {\n const program = resolveAccountIndex(parsed, ix.programAddressIndex, lookups);\n const { data } = ix;\n if (program === PROGRAM_IDS.system) {\n if (data.length === 12 && u32le(data, 0) === 2) {\n return {\n kind: \"system-transfer\",\n to: resolveAccountIndex(parsed, ix.accountIndices[1] ?? 0, lookups),\n amount: u64le(data, 4),\n };\n }\n return { kind: \"other\" };\n }\n if (program === PROGRAM_IDS.computeBudget) {\n if (data.length === 5 && data[0] === 2) {\n return { kind: \"cu-limit\", units: u32le(data, 1) };\n }\n if (data.length === 9 && data[0] === 3) {\n return { kind: \"cu-price\", microLamports: u64le(data, 1) };\n }\n return { kind: \"other\" };\n }\n if (program === PROGRAM_IDS.associatedToken) {\n if (data.length === 1 && data[0] === 0) {\n return { kind: \"ata-create\" };\n }\n if (data.length === 1 && data[0] === 1) {\n return { kind: \"ata-create-idempotent\" };\n }\n return { kind: \"other\" };\n }\n if (program === PROGRAM_IDS.token || program === PROGRAM_IDS.token2022) {\n if (data.length === 10 && data[0] === 12) {\n return {\n kind: \"token-transfer-checked\",\n amount: u64le(data, 1),\n decimals: data[9],\n to: resolveAccountIndex(parsed, ix.accountIndices[2] ?? 0, lookups),\n mint: resolveAccountIndex(parsed, ix.accountIndices[1] ?? 0, lookups),\n };\n }\n if (data.length === 9 && data[0] === 4) {\n return {\n kind: \"token-approve\",\n amount: u64le(data, 1),\n to: resolveAccountIndex(parsed, ix.accountIndices[1] ?? 0, lookups),\n };\n }\n return { kind: \"other\" };\n }\n if (program === PROGRAM_IDS.stake) {\n return { kind: \"stake\" };\n }\n return { kind: \"other\" };\n};\n\nconst FULL_KINDS = new Set([\n \"system-transfer\",\n \"cu-limit\",\n \"cu-price\",\n \"ata-create\",\n \"ata-create-idempotent\",\n]);\n\nconst classify = (\n parsed: ParsedSolanaMessage,\n calls: ReadonlyArray<IxCall>,\n network: string,\n table: SolanaTokenTable,\n): Verifiability => {\n if (parsed.lookupCount > 0) {\n return \"partial\";\n }\n let allFull = true;\n for (const call of calls) {\n if (call.kind === \"other\") {\n return \"opaque\";\n }\n if (call.kind === \"token-approve\" || call.kind === \"stake\") {\n allFull = false;\n }\n if (\n call.kind === \"token-transfer-checked\" &&\n lookupSolanaToken(table, network, call.mint ?? \"\") === undefined\n ) {\n allFull = false;\n }\n if (\n !FULL_KINDS.has(call.kind) &&\n call.kind !== \"token-transfer-checked\" &&\n call.kind !== \"token-approve\" &&\n call.kind !== \"stake\"\n ) {\n return \"opaque\";\n }\n }\n return allFull ? \"full\" : \"partial\";\n};\n\nconst feeLamports = (\n parsed: ParsedSolanaMessage,\n calls: ReadonlyArray<IxCall>,\n): bigint | undefined => {\n const limit = calls.find((c) => c.kind === \"cu-limit\")?.units;\n const price = calls.find((c) => c.kind === \"cu-price\")?.microLamports;\n if (limit === undefined || price === undefined) {\n return undefined;\n }\n const signatures = BigInt(parsed.numRequiredSignatures);\n return 5000n * signatures + (price * BigInt(limit) + 999_999n) / 1_000_000n;\n};\n\nconst decodeTransaction = (\n request: Extract<SignRequest, { kind: \"solana.transaction\" }>,\n signer: string,\n table: SolanaTokenTable,\n): DisplayIntent => {\n const parsed = parseCompiledMessage(request.message);\n const lookups = request.lookupTables?.map((t) => ({\n address: t.address,\n addresses: t.addresses,\n }));\n const calls = parsed.instructions.map((ix) => classifyIx(parsed, ix, lookups));\n const verifiability = classify(parsed, calls, request.network, table);\n const outflows: AssetFlow[] = [];\n const approvals: ApprovalChange[] = [];\n for (const call of calls) {\n if (call.kind === \"system-transfer\" && call.to !== undefined) {\n const [source] = parsed.staticAccounts;\n if (source === signer) {\n outflows.push({\n to: call.to,\n amount: { asset: LAMPORTS_ASSET, amount: (call.amount ?? 0n).toString(10) },\n verified: true,\n });\n }\n }\n if (call.kind === \"token-transfer-checked\") {\n const token = lookupSolanaToken(table, request.network, call.mint ?? \"\");\n outflows.push({\n to: call.to ?? \"\",\n amount: {\n asset: call.mint ?? \"\",\n amount: (call.amount ?? 0n).toString(10),\n ...(token === undefined ? {} : { symbol: token.symbol, decimals: token.decimals }),\n },\n verified: token !== undefined,\n });\n }\n if (call.kind === \"token-approve\") {\n approvals.push({\n asset: call.mint ?? \"\",\n spender: call.to ?? \"\",\n amount: (call.amount ?? 0n).toString(10),\n unlimited: false,\n verified: false,\n });\n }\n }\n const fee = feeLamports(parsed, calls);\n return {\n family: \"solana\",\n network: request.network,\n summary: outflows.length > 0 ? \"transfer\" : \"contract-call\",\n outflows,\n approvals,\n fee:\n fee === undefined ? undefined : { max: { asset: LAMPORTS_ASSET, amount: fee.toString(10) } },\n warnings: [],\n verifiability,\n };\n};\n\n/** What the signer can guarantee about this request (WD-065). */\nexport const verifiabilitySolana = (\n request: Extract<SignRequest, { kind: \"solana.transaction\" }>,\n signer: string,\n table: SolanaTokenTable = solanaTokenTable,\n): Verifiability => decodeSolana(request, signer, table).verifiability;\n\nexport const decodeSolana = (\n request: Extract<SignRequest, { kind: \"solana.transaction\" }>,\n signer: string,\n table: SolanaTokenTable = solanaTokenTable,\n): DisplayIntent => decodeTransaction(request, signer, table);\n","import { ChainError } from \"../index.ts\";\n\n/** SPL Token-2022 mint-account TLV extension type numbers (spl-token-2022 `ExtensionType`). */\nexport const EXT = {\n transferFeeConfig: 1,\n confidentialTransferMint: 4,\n defaultAccountState: 6,\n nonTransferable: 9,\n cpiGuard: 11,\n permanentDelegate: 12,\n transferHook: 14,\n confidentialTransferFee: 16,\n confidentialTransferFeeAmount: 17,\n} as const;\n\nexport type MintExtensionSummary = {\n /** The current-epoch fee from TransferFeeConfig (basis points and the maximum fee), if set. */\n readonly transferFee?: { readonly basisPoints: number; readonly maximumFee: bigint };\n readonly transferHook?: { readonly programId: Uint8Array };\n readonly permanentDelegate?: { readonly delegate: Uint8Array };\n readonly nonTransferable?: boolean;\n /** True when a ConfidentialTransfer extension is present — confidential amounts are not supported. */\n readonly confidential?: boolean;\n /** Extension type numbers we do not parse (informational). */\n readonly unknown?: ReadonlyArray<number>;\n};\n\nconst u64 = (v: Uint8Array): bigint =>\n new DataView(v.buffer, v.byteOffset, 8).getBigUint64(0, true);\nconst u16 = (v: Uint8Array): number => new DataView(v.buffer, v.byteOffset, 2).getUint16(0, true);\n\nconst ACCOUNT_TYPE_MINT = 1;\nconst TYPE_OFFSET = 165;\n\n/**\n * Parse the extension region of a full Token-2022 mint account. The account is the 82-byte mint\n * base, zero padding up to byte 165, the account-type byte (`1` = Mint) at 165, then the TLV region\n * at 166 — each entry `u16 type, u16 len, len bytes`. Returns a typed summary; extensions this\n * layer does not read are reported by type number in `unknown` rather than parsed.\n */\nexport const parseMintExtensions = (data: Uint8Array, epoch: bigint): MintExtensionSummary => {\n if (data.length <= TYPE_OFFSET + 1 || data[TYPE_OFFSET] !== ACCOUNT_TYPE_MINT) {\n return {};\n }\n const tlv = data.subarray(TYPE_OFFSET + 1);\n const out: {\n transferFee?: { basisPoints: number; maximumFee: bigint };\n transferHook?: { programId: Uint8Array };\n permanentDelegate?: { delegate: Uint8Array };\n nonTransferable?: boolean;\n confidential?: boolean;\n unknown: number[];\n } = { unknown: [] };\n let offset = 0;\n while (offset + 2 <= tlv.length) {\n const type = u16(tlv.subarray(offset, offset + 2));\n // Uninitialized entries are a u16 marker only — the program stops scanning there and\n // treats the rest as unused space.\n if (type === 0) {\n break;\n }\n if (offset + 4 > tlv.length) {\n throw new ChainError(\"invalid-request\", `mint extension ${type} truncated`);\n }\n const len = u16(tlv.subarray(offset + 2, offset + 4));\n offset += 4;\n if (offset + len > tlv.length) {\n throw new ChainError(\"invalid-request\", `mint extension ${type} truncated`);\n }\n const body = tlv.subarray(offset, offset + len);\n offset += len;\n if (type === EXT.transferFeeConfig && len >= 108) {\n // OptionalNonZeroPubkey×2 (32 B each, zero = none) + u64 withheld + TransferFee×2\n // (18 B each: u64 epoch + u64 maximumFee + u16 basisPoints). The current-epoch fee is\n // the \"newer\" record once its activation epoch is reached, else the \"older\" one.\n const olderMax = u64(body.subarray(80));\n const olderBps = u16(body.subarray(88));\n const newerEpoch = u64(body.subarray(90));\n const newerMax = u64(body.subarray(98));\n const newerBps = u16(body.subarray(106));\n const active =\n newerEpoch <= epoch ? { bps: newerBps, max: newerMax } : { bps: olderBps, max: olderMax };\n if (active.bps !== 0 || active.max !== 0n) {\n out.transferFee = { basisPoints: active.bps, maximumFee: active.max };\n }\n } else if (type === EXT.transferHook && len >= 64) {\n // OptionalNonZeroPubkey authority (32) + program id (32).\n const programId = body.subarray(32, 64);\n out.transferHook = { programId };\n } else if (type === EXT.permanentDelegate && len >= 32) {\n // OptionalNonZeroPubkey delegate (32) — all-zero means none.\n const delegate = body.subarray(0, 32);\n if (delegate.some((b) => b !== 0)) {\n out.permanentDelegate = { delegate };\n }\n } else if (type === EXT.nonTransferable) {\n out.nonTransferable = true;\n } else if (\n type === EXT.confidentialTransferMint ||\n type === EXT.confidentialTransferFee ||\n type === EXT.confidentialTransferFeeAmount\n ) {\n out.confidential = true;\n } else {\n out.unknown.push(type);\n }\n }\n return out.unknown.length === 0 ? out : { ...out, unknown: out.unknown };\n};\n\n/**\n * Net amount a recipient gets after the current-epoch transfer fee, `amt − min(amt*bps/10000,\n * max)`.\n */\nexport const netAfterTransferFee = (amount: bigint, bps: number, max: bigint): bigint => {\n const fee = (amount * BigInt(bps)) / 10_000n;\n return amount - (fee > max ? max : fee);\n};\n","/**\n * Ed25519 signature verification for `chain.sign` results: the host checks the kernel's 64-byte\n * signature against the message and the account address returned by `wallet.accounts` — a wrong\n * signer fails closed.\n */\nimport { ed25519 } from \"@noble/curves/ed25519.js\";\nimport { address, getAddressEncoder } from \"@solana/addresses\";\n\n/** Whether `signature` is a valid ed25519 signature of `message` by the key behind `address`. */\nexport const verifySolanaSignature = (\n message: Uint8Array,\n signature: Uint8Array,\n accountAddress: string,\n): boolean => {\n if (signature.length !== 64) {\n return false;\n }\n try {\n return ed25519.verify(\n signature,\n message,\n new Uint8Array(getAddressEncoder().encode(address(accountAddress))),\n );\n } catch {\n return false;\n }\n};\n","import { ChainError } from \"../index.ts\";\nimport type { AccountRef, SignRequest } from \"../index.ts\";\nimport { SOLANA_NETWORKS, isSolanaAddress } from \"./ids.ts\";\nimport { parseCompiledMessage, validateLookupTables } from \"./message.ts\";\n\nexport {\n PROGRAM_IDS,\n SOLANA_NETWORKS,\n isSolanaAddress,\n solanaAddressFromPublicKey,\n} from \"./ids.ts\";\nexport { decodeSolana, verifiabilitySolana } from \"./decode.ts\";\nexport { EXT, parseMintExtensions, netAfterTransferFee } from \"./token2022.ts\";\nexport type { MintExtensionSummary } from \"./token2022.ts\";\nexport { parseCompiledMessage } from \"./message.ts\";\nexport { verifySolanaSignature } from \"./verify.ts\";\nexport type { SolanaTokenTable } from \"./tokens.ts\";\nexport { solanaTokenTable } from \"./tokens.ts\";\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === \"object\" && value !== null && !Array.isArray(value);\n\nconst isAccountRef = (value: unknown): value is AccountRef => {\n if (!isRecord(value) || typeof value[\"kind\"] !== \"string\") {\n return false;\n }\n if (value[\"kind\"] === \"hd\") {\n return (\n typeof value[\"walletId\"] === \"string\" &&\n typeof value[\"groupIndex\"] === \"number\" &&\n typeof value[\"template\"] === \"string\"\n );\n }\n return (\n value[\"kind\"] === \"imported\" &&\n typeof value[\"keyId\"] === \"string\" &&\n typeof value[\"family\"] === \"string\"\n );\n};\n\nconst solanaNetwork = (network: string): void => {\n if (!SOLANA_NETWORKS.includes(network)) {\n throw new ChainError(\"unsupported\", `unknown Solana network: ${network}`);\n }\n};\n\ntype LookupTable = {\n readonly address: string;\n readonly addresses: ReadonlyArray<string>;\n};\n\nconst validateLookupTablesRaw = (tables: unknown): ReadonlyArray<LookupTable> | undefined => {\n if (tables === undefined) {\n return undefined;\n }\n if (!Array.isArray(tables)) {\n throw new ChainError(\"unknown-field\", \"lookupTables must be an array\");\n }\n const parsed = tables.map((t): LookupTable => {\n if (!isRecord(t) || typeof t[\"address\"] !== \"string\" || !Array.isArray(t[\"addresses\"])) {\n throw new ChainError(\"unknown-field\", \"lookupTables entries must be { address, addresses }\");\n }\n const addresses = t[\"addresses\"].map((a): string => {\n if (typeof a !== \"string\") {\n throw new ChainError(\"invalid-address\", \"lookup table addresses must be strings\");\n }\n return a;\n });\n return { address: t[\"address\"], addresses };\n });\n validateLookupTables(parsed);\n return parsed;\n};\n\n/**\n * Normalizes a Solana sign request. `signer` is the fee payer the wallet is about to sign for — the\n * message must declare it as the first static account. A raw `solana.message` must not decode as a\n * transaction message (chains.mdx rule — a bytes-to-sign path that produces a transaction signature\n * is a wallet-drainer). Idempotent.\n */\nexport const normalizeSolana = (request: unknown, signer: string): SignRequest => {\n if (!isRecord(request) || typeof request[\"kind\"] !== \"string\") {\n throw new ChainError(\"invalid-request\", \"request must be an object with a kind\");\n }\n const { network } = request;\n const { account } = request;\n if (typeof network !== \"string\") {\n throw new ChainError(\"invalid-request\", \"request.network must be a string\");\n }\n if (!isAccountRef(account)) {\n throw new ChainError(\"invalid-request\", \"request.account must be an AccountRef\");\n }\n solanaNetwork(network);\n if (!isSolanaAddress(signer)) {\n throw new ChainError(\"invalid-address\", \"signer is not a base58 address\");\n }\n const { message } = request;\n if (!(message instanceof Uint8Array)) {\n throw new ChainError(\"invalid-request\", \"message must be bytes\");\n }\n if (request[\"kind\"] === \"solana.transaction\") {\n const lookupTables = validateLookupTablesRaw(request[\"lookupTables\"]);\n const parsed = parseCompiledMessage(message);\n const [feePayer] = parsed.staticAccounts;\n if (feePayer === undefined || feePayer !== signer) {\n throw new ChainError(\"fee-payer-mismatch\", \"signer is not the transaction fee payer\");\n }\n return {\n kind: \"solana.transaction\",\n network,\n account,\n message,\n ...(lookupTables === undefined\n ? {}\n : {\n lookupTables: (\n lookupTables as ReadonlyArray<{\n readonly address: string;\n readonly addresses: ReadonlyArray<string>;\n }>\n ).map((t) => ({ address: t.address, addresses: [...t.addresses] })),\n }),\n };\n }\n if (request[\"kind\"] === \"solana.message\") {\n const { format } = request;\n if (format !== \"raw\") {\n throw new ChainError(\n \"unsupported\",\n `solana.message format ${String(format)} is not supported`,\n );\n }\n let decodesAsTransaction = true;\n try {\n parseCompiledMessage(message);\n } catch {\n decodesAsTransaction = false;\n }\n if (decodesAsTransaction) {\n throw new ChainError(\n \"invalid-request\",\n \"solana.message payload decodes as a transaction message — use solana.transaction\",\n );\n }\n return { kind: \"solana.message\", network, account, message, format };\n }\n throw new ChainError(\"unsupported\", `unsupported sign request kind: ${request[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