@babylonlabs-io/ts-sdk 0.67.0 → 0.68.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. package/dist/PeginManager--2R3T2S8.js +1458 -0
  2. package/dist/PeginManager--2R3T2S8.js.map +1 -0
  3. package/dist/PeginManager-CKWq8ouZ.cjs +2 -0
  4. package/dist/PeginManager-CKWq8ouZ.cjs.map +1 -0
  5. package/dist/{batchPoll-cIxrSLLJ.js → batchPoll-Cjj1du0i.js} +372 -421
  6. package/dist/batchPoll-Cjj1du0i.js.map +1 -0
  7. package/dist/batchPoll-REVZiE-M.cjs +2 -0
  8. package/dist/batchPoll-REVZiE-M.cjs.map +1 -0
  9. package/dist/{bitcoin-d9eaaZB_.js → bitcoin-Ch_jxnDa.js} +3 -3
  10. package/dist/{bitcoin-d9eaaZB_.js.map → bitcoin-Ch_jxnDa.js.map} +1 -1
  11. package/dist/{buildAndBroadcastRefund-C4LiPATK.js → buildAndBroadcastRefund-CpMDJ8up.js} +142 -150
  12. package/dist/buildAndBroadcastRefund-CpMDJ8up.js.map +1 -0
  13. package/dist/buildAndBroadcastRefund-DrXwxrW1.cjs +2 -0
  14. package/dist/buildAndBroadcastRefund-DrXwxrW1.cjs.map +1 -0
  15. package/dist/challengeAssert-BNQ8sToz.js +64 -0
  16. package/dist/challengeAssert-BNQ8sToz.js.map +1 -0
  17. package/dist/challengeAssert-BrpC3-cQ.cjs +2 -0
  18. package/dist/challengeAssert-BrpC3-cQ.cjs.map +1 -0
  19. package/dist/index.cjs +1 -1
  20. package/dist/index.js +246 -243
  21. package/dist/mempoolApi-EU1La9wk.cjs +2 -0
  22. package/dist/{mempoolApi-CXfr-L6x.cjs.map → mempoolApi-EU1La9wk.cjs.map} +1 -1
  23. package/dist/{mempoolApi-BxSINXIB.js → mempoolApi-_D-jvtj_.js} +191 -117
  24. package/dist/{mempoolApi-BxSINXIB.js.map → mempoolApi-_D-jvtj_.js.map} +1 -1
  25. package/dist/{noPayout-BaZGRLD2.js → noPayout-CXn-geIS.js} +3 -3
  26. package/dist/{noPayout-BaZGRLD2.js.map → noPayout-CXn-geIS.js.map} +1 -1
  27. package/dist/{noPayout-CnQ1WLtr.cjs → noPayout-Ox27Td9x.cjs} +2 -2
  28. package/dist/{noPayout-CnQ1WLtr.cjs.map → noPayout-Ox27Td9x.cjs.map} +1 -1
  29. package/dist/{onChainBtcPubkey-DeF4cKoO.js → onChainBtcPubkey-BAHZyKQL.js} +2 -2
  30. package/dist/{onChainBtcPubkey-DeF4cKoO.js.map → onChainBtcPubkey-BAHZyKQL.js.map} +1 -1
  31. package/dist/{parseFundingOutpoints-pBRE11Hr.js → parseFundingOutpoints-CO-f6IHK.js} +2 -2
  32. package/dist/{parseFundingOutpoints-pBRE11Hr.js.map → parseFundingOutpoints-CO-f6IHK.js.map} +1 -1
  33. package/dist/{reservation-B4i_PQhY.js → reservation-CBAvoF3U.js} +2 -2
  34. package/dist/{reservation-B4i_PQhY.js.map → reservation-CBAvoF3U.js.map} +1 -1
  35. package/dist/{signPsbtsWithFallback-Bb66DfY5.js → signPsbtsWithFallback-Bv79gLFe.js} +122 -100
  36. package/dist/signPsbtsWithFallback-Bv79gLFe.js.map +1 -0
  37. package/dist/signPsbtsWithFallback-DJ4kE9UI.cjs +2 -0
  38. package/dist/signPsbtsWithFallback-DJ4kE9UI.cjs.map +1 -0
  39. package/dist/tbv/core/clients/index.cjs +1 -1
  40. package/dist/tbv/core/clients/index.js +3 -3
  41. package/dist/tbv/core/clients/vault-provider/auth/__tests__/bip322P2wpkhVectors.d.ts +32 -0
  42. package/dist/tbv/core/clients/vault-provider/auth/__tests__/bip322P2wpkhVectors.d.ts.map +1 -0
  43. package/dist/tbv/core/clients/vault-provider/auth/__tests__/bip322Verify.test.d.ts +9 -6
  44. package/dist/tbv/core/clients/vault-provider/auth/__tests__/bip322Verify.test.d.ts.map +1 -1
  45. package/dist/tbv/core/clients/vault-provider/auth/bip322Verify.d.ts +45 -20
  46. package/dist/tbv/core/clients/vault-provider/auth/bip322Verify.d.ts.map +1 -1
  47. package/dist/tbv/core/deposit-terms/__tests__/depositTerms.test.d.ts +2 -0
  48. package/dist/tbv/core/deposit-terms/__tests__/depositTerms.test.d.ts.map +1 -0
  49. package/dist/tbv/core/deposit-terms/depositTerms.d.ts +41 -4
  50. package/dist/tbv/core/deposit-terms/depositTerms.d.ts.map +1 -1
  51. package/dist/tbv/core/deposit-terms/prePeginApproval.d.ts +10 -5
  52. package/dist/tbv/core/deposit-terms/prePeginApproval.d.ts.map +1 -1
  53. package/dist/tbv/core/index.cjs +1 -1
  54. package/dist/tbv/core/index.js +244 -241
  55. package/dist/tbv/core/managers/PayoutManager.d.ts +8 -2
  56. package/dist/tbv/core/managers/PayoutManager.d.ts.map +1 -1
  57. package/dist/tbv/core/managers/PeginManager.d.ts +7 -0
  58. package/dist/tbv/core/managers/PeginManager.d.ts.map +1 -1
  59. package/dist/tbv/core/managers/index.cjs +1 -1
  60. package/dist/tbv/core/managers/index.js +2 -2
  61. package/dist/tbv/core/managers/pegin/__tests__/verifyPopWitness.test.d.ts +11 -0
  62. package/dist/tbv/core/managers/pegin/__tests__/verifyPopWitness.test.d.ts.map +1 -0
  63. package/dist/tbv/core/managers/pegin/expandPerVaultSecrets.d.ts.map +1 -1
  64. package/dist/tbv/core/managers/pegin/index.d.ts +1 -0
  65. package/dist/tbv/core/managers/pegin/index.d.ts.map +1 -1
  66. package/dist/tbv/core/managers/pegin/verifyPopWitness.d.ts +21 -0
  67. package/dist/tbv/core/managers/pegin/verifyPopWitness.d.ts.map +1 -0
  68. package/dist/tbv/core/primitives/challengers.d.ts +31 -5
  69. package/dist/tbv/core/primitives/challengers.d.ts.map +1 -1
  70. package/dist/tbv/core/primitives/index.cjs +1 -1
  71. package/dist/tbv/core/primitives/index.d.ts +2 -0
  72. package/dist/tbv/core/primitives/index.d.ts.map +1 -1
  73. package/dist/tbv/core/primitives/index.js +43 -41
  74. package/dist/tbv/core/primitives/psbt/__tests__/helpers.d.ts +5 -0
  75. package/dist/tbv/core/primitives/psbt/__tests__/helpers.d.ts.map +1 -1
  76. package/dist/tbv/core/primitives/psbt/__tests__/verifyKeyPathSchnorrSignature.test.d.ts +12 -0
  77. package/dist/tbv/core/primitives/psbt/__tests__/verifyKeyPathSchnorrSignature.test.d.ts.map +1 -0
  78. package/dist/tbv/core/primitives/psbt/payout.d.ts +19 -7
  79. package/dist/tbv/core/primitives/psbt/payout.d.ts.map +1 -1
  80. package/dist/tbv/core/primitives/psbt/verifyKeyPathSchnorrSignature.d.ts +64 -0
  81. package/dist/tbv/core/primitives/psbt/verifyKeyPathSchnorrSignature.d.ts.map +1 -0
  82. package/dist/tbv/core/primitives/psbt/verifyP2wpkhEcdsaSignature.d.ts +40 -0
  83. package/dist/tbv/core/primitives/psbt/verifyP2wpkhEcdsaSignature.d.ts.map +1 -0
  84. package/dist/tbv/core/primitives/psbt/verifyScriptPathSchnorrSignature.d.ts +2 -1
  85. package/dist/tbv/core/primitives/psbt/verifyScriptPathSchnorrSignature.d.ts.map +1 -1
  86. package/dist/tbv/core/primitives/utils/__tests__/taproot.test.d.ts +13 -0
  87. package/dist/tbv/core/primitives/utils/__tests__/taproot.test.d.ts.map +1 -0
  88. package/dist/tbv/core/primitives/utils/taproot.d.ts +29 -0
  89. package/dist/tbv/core/primitives/utils/taproot.d.ts.map +1 -0
  90. package/dist/tbv/core/services/deposit/runDepositorPresignFlow.d.ts +2 -2
  91. package/dist/tbv/core/services/deposit/runDepositorPresignFlow.d.ts.map +1 -1
  92. package/dist/tbv/core/services/deposit/signDepositorGraph.d.ts.map +1 -1
  93. package/dist/tbv/core/services/index.cjs +1 -1
  94. package/dist/tbv/core/services/index.js +2 -2
  95. package/dist/tbv/core/utils/index.js +2 -2
  96. package/dist/tbv/core/utils/witness/witnessStack.d.ts +24 -0
  97. package/dist/tbv/core/utils/witness/witnessStack.d.ts.map +1 -0
  98. package/dist/tbv/core/vault-secrets/index.js +1 -1
  99. package/dist/tbv/index.cjs +1 -1
  100. package/dist/tbv/index.js +244 -241
  101. package/dist/testing/MockBitcoinWallet.d.ts +10 -1
  102. package/dist/testing/MockBitcoinWallet.d.ts.map +1 -1
  103. package/dist/testing/__tests__/MockBitcoinWallet.test.d.ts +2 -0
  104. package/dist/testing/__tests__/MockBitcoinWallet.test.d.ts.map +1 -0
  105. package/dist/testing/index.cjs +1 -1
  106. package/dist/testing/index.cjs.map +1 -1
  107. package/dist/testing/index.js +134 -47
  108. package/dist/testing/index.js.map +1 -1
  109. package/dist/testing/signBip322P2wpkhWitness.d.ts +20 -0
  110. package/dist/testing/signBip322P2wpkhWitness.d.ts.map +1 -0
  111. package/dist/{toRefundInputs-BY_fcvrv.js → toRefundInputs-9hv_6k0E.js} +6 -6
  112. package/dist/{toRefundInputs-BY_fcvrv.js.map → toRefundInputs-9hv_6k0E.js.map} +1 -1
  113. package/dist/{toRefundInputs-DYL9C-aG.cjs → toRefundInputs-D8sFs44p.cjs} +2 -2
  114. package/dist/{toRefundInputs-DYL9C-aG.cjs.map → toRefundInputs-D8sFs44p.cjs.map} +1 -1
  115. package/dist/verifyKeyPathSchnorrSignature-DCOzQkDf.cjs +2 -0
  116. package/dist/verifyKeyPathSchnorrSignature-DCOzQkDf.cjs.map +1 -0
  117. package/dist/verifyKeyPathSchnorrSignature-oGCUbjjZ.js +363 -0
  118. package/dist/verifyKeyPathSchnorrSignature-oGCUbjjZ.js.map +1 -0
  119. package/dist/verifyScriptPathSchnorrSignature-Dy9gF5RF.js +931 -0
  120. package/dist/verifyScriptPathSchnorrSignature-Dy9gF5RF.js.map +1 -0
  121. package/dist/verifyScriptPathSchnorrSignature-la8XOAFm.cjs +2 -0
  122. package/dist/verifyScriptPathSchnorrSignature-la8XOAFm.cjs.map +1 -0
  123. package/package.json +1 -1
  124. package/dist/PeginManager-BBl4xkWz.js +0 -1359
  125. package/dist/PeginManager-BBl4xkWz.js.map +0 -1
  126. package/dist/PeginManager-p-ajwSxG.cjs +0 -2
  127. package/dist/PeginManager-p-ajwSxG.cjs.map +0 -1
  128. package/dist/batchPoll-6L5oToGr.cjs +0 -2
  129. package/dist/batchPoll-6L5oToGr.cjs.map +0 -1
  130. package/dist/batchPoll-cIxrSLLJ.js.map +0 -1
  131. package/dist/buildAndBroadcastRefund-C4LiPATK.js.map +0 -1
  132. package/dist/buildAndBroadcastRefund-Daw5ZUKR.cjs +0 -2
  133. package/dist/buildAndBroadcastRefund-Daw5ZUKR.cjs.map +0 -1
  134. package/dist/challengeAssert-BFRE2DM-.cjs +0 -2
  135. package/dist/challengeAssert-BFRE2DM-.cjs.map +0 -1
  136. package/dist/challengeAssert-C7PzyJ7g.js +0 -75
  137. package/dist/challengeAssert-C7PzyJ7g.js.map +0 -1
  138. package/dist/mempoolApi-CXfr-L6x.cjs +0 -2
  139. package/dist/peginInput-Ci921gTl.cjs +0 -2
  140. package/dist/peginInput-Ci921gTl.cjs.map +0 -1
  141. package/dist/peginInput-HQPWZfly.js +0 -123
  142. package/dist/peginInput-HQPWZfly.js.map +0 -1
  143. package/dist/signPsbtsWithFallback-Bb66DfY5.js.map +0 -1
  144. package/dist/signPsbtsWithFallback-PTgWxsG3.cjs +0 -2
  145. package/dist/signPsbtsWithFallback-PTgWxsG3.cjs.map +0 -1
  146. package/dist/verifyScriptPathSchnorrSignature-DPAd_qke.cjs +0 -2
  147. package/dist/verifyScriptPathSchnorrSignature-DPAd_qke.cjs.map +0 -1
  148. package/dist/verifyScriptPathSchnorrSignature-i-koT139.js +0 -817
  149. package/dist/verifyScriptPathSchnorrSignature-i-koT139.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../../src/testing/MockBitcoinWallet.ts","../../src/testing/MockEthereumWallet.ts"],"sourcesContent":["import { sha256 } from \"@noble/hashes/sha2.js\";\nimport { Buffer } from \"buffer\";\n\nimport { BitcoinNetworks, type BitcoinNetwork } from \"../shared/wallets/interfaces\";\nimport type {\n BitcoinWallet,\n SignPsbtOptions,\n} from \"../shared/wallets/interfaces/BitcoinWallet\";\nimport { uint8ArrayToHex } from \"../tbv/core/primitives/utils/bitcoin\";\n\n/**\n * Configuration for MockBitcoinWallet.\n */\nexport interface MockBitcoinWalletConfig {\n publicKeyHex?: string;\n address?: string;\n network?: BitcoinNetwork;\n shouldFailSigning?: boolean;\n /**\n * Optional override for `deriveContextHash`. When omitted the mock\n * returns a deterministic 64-char lowercase hex string derived from\n * `(appName, context)` so tests can assert pass-through wiring\n * without pinning a specific value. Override to inject spec test\n * vectors or to simulate failure modes.\n */\n deriveContextHash?: (appName: string, context: string) => Promise<string>;\n}\n\n/**\n * Default `deriveContextHash` implementation: deterministic and\n * collision-resistant via SHA-256, so tests that assert pass-through\n * wiring (different `(appName, context)` → different output) hold\n * without flakes. Domain-separates the two inputs by length-prefixing\n * each as `len(name) || name || len(ctx) || ctx`, preventing\n * `(\"ab\", \"cd\")` from colliding with `(\"abc\", \"d\")`.\n */\nconst defaultDeriveContextHash = async (\n appName: string,\n context: string,\n): Promise<string> => {\n const enc = new TextEncoder();\n const nameBytes = enc.encode(appName);\n const ctxBytes = enc.encode(context);\n const buf = new Uint8Array(4 + nameBytes.length + 4 + ctxBytes.length);\n const view = new DataView(buf.buffer);\n view.setUint32(0, nameBytes.length);\n buf.set(nameBytes, 4);\n view.setUint32(4 + nameBytes.length, ctxBytes.length);\n buf.set(ctxBytes, 4 + nameBytes.length + 4);\n return uint8ArrayToHex(sha256(buf));\n};\n\nconst DEFAULT_CONFIG: Required<MockBitcoinWalletConfig> = {\n publicKeyHex:\n \"a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2\",\n address: \"tb1pqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqkx6jks\",\n network: BitcoinNetworks.SIGNET,\n shouldFailSigning: false,\n deriveContextHash: defaultDeriveContextHash,\n};\n\n/** Mock Bitcoin wallet for testing. */\nexport class MockBitcoinWallet implements BitcoinWallet {\n private config: Required<MockBitcoinWalletConfig>;\n\n constructor(config: MockBitcoinWalletConfig = {}) {\n this.config = {\n ...DEFAULT_CONFIG,\n ...(config.publicKeyHex ? { publicKeyHex: config.publicKeyHex } : {}),\n ...(config.address ? { address: config.address } : {}),\n ...(config.network !== undefined ? { network: config.network } : {}),\n ...(config.shouldFailSigning !== undefined\n ? { shouldFailSigning: config.shouldFailSigning }\n : {}),\n ...(config.deriveContextHash\n ? { deriveContextHash: config.deriveContextHash }\n : {}),\n };\n }\n\n async getPublicKeyHex(): Promise<string> {\n return this.config.publicKeyHex;\n }\n\n async getAddress(): Promise<string> {\n return this.config.address;\n }\n\n async signPsbt(\n psbtHex: string,\n _options?: SignPsbtOptions,\n ): Promise<string> {\n if (this.config.shouldFailSigning) {\n throw new Error(\"Mock signing failed\");\n }\n\n if (!psbtHex || psbtHex.length === 0) {\n throw new Error(\"Invalid PSBT: empty hex string\");\n }\n\n // In a real implementation, this would actually sign the PSBT\n // For the mock, we just return the input with a mock signature appended\n return psbtHex + \"deadbeef\";\n }\n\n async signPsbts(\n psbtsHexes: string[],\n _options?: SignPsbtOptions[],\n ): Promise<string[]> {\n const signedPsbts: string[] = [];\n for (const psbtHex of psbtsHexes) {\n const signedPsbt = await this.signPsbt(psbtHex);\n signedPsbts.push(signedPsbt);\n }\n return signedPsbts;\n }\n\n async signMessage(\n message: string,\n type: \"bip322-simple\" | \"ecdsa\",\n ): Promise<string> {\n if (this.config.shouldFailSigning) {\n throw new Error(\"Mock signing failed\");\n }\n\n if (!message || message.length === 0) {\n throw new Error(\"Invalid message: empty string\");\n }\n\n // In a real implementation, this would create a proper signature\n // For the mock, we return a base64-like mock signature\n const mockSignature = Buffer.from(\n `mock-signature-${type}-${message}-${this.config.publicKeyHex}`,\n ).toString(\"base64\");\n return mockSignature;\n }\n\n async getNetwork(): Promise<BitcoinNetwork> {\n return this.config.network;\n }\n\n async deriveContextHash(appName: string, context: string): Promise<string> {\n return this.config.deriveContextHash(appName, context);\n }\n\n /** Updates configuration for testing different scenarios. */\n updateConfig(updates: Partial<MockBitcoinWalletConfig>): void {\n this.config = {\n ...this.config,\n ...updates,\n };\n }\n\n /** Resets to default configuration. */\n reset(): void {\n this.config = { ...DEFAULT_CONFIG };\n }\n}\n","import { Buffer } from \"buffer\";\nimport type { Address, Hex } from \"viem\";\n\n/**\n * Configuration for MockEthereumWallet.\n */\nexport interface MockEthereumWalletConfig {\n address?: Address;\n chainId?: number;\n shouldFailOperations?: boolean;\n transactionDelay?: number;\n}\n\n/**\n * Mock Ethereum wallet for testing.\n *\n * Provides the subset of viem's WalletClient methods used by the SDK.\n * Can be passed to functions expecting a WalletClient for testing purposes.\n */\nexport class MockEthereumWallet {\n // Public properties matching viem's WalletClient structure\n account: { address: Address };\n chain: { id: number };\n\n private shouldFailOperations: boolean;\n private transactionDelay: number;\n private nonce: number = 0;\n\n constructor(config: MockEthereumWalletConfig = {}) {\n // Use lowercase addresses to avoid EIP-55 checksum validation issues\n this.account = {\n address:\n config.address ||\n (\"0x742d35cc6634c0532925a3b844bc9e7595f0beb0\" as Address),\n };\n\n this.chain = {\n id: config.chainId ?? 11155111, // Sepolia by default\n };\n\n this.shouldFailOperations = config.shouldFailOperations ?? false;\n this.transactionDelay = config.transactionDelay ?? 0;\n\n // Bind methods to preserve 'this' context when called\n this.signMessage = this.signMessage.bind(this);\n this.sendTransaction = this.sendTransaction.bind(this);\n }\n\n async signMessage(args: { message: string; account?: Address }): Promise<Hex> {\n const message = args.message;\n const account = args.account || this.account.address;\n\n if (this.shouldFailOperations) {\n throw new Error(\"Mock signing failed\");\n }\n\n if (!message || message.length === 0) {\n throw new Error(\"Invalid message: empty string\");\n }\n\n // Generate a deterministic mock signature\n const signatureData = `personal_sign:${message}-${account}-${this.chain.id}`;\n const signature = `0x${Buffer.from(signatureData)\n .toString(\"hex\")\n .slice(0, 130)\n .padEnd(130, \"0\")}` as Hex;\n return signature;\n }\n\n async sendTransaction(tx: {\n to: Address;\n data?: Hex;\n value?: bigint;\n gas?: bigint;\n account?: { address: Address };\n chain?: { id: number };\n }): Promise<Hex> {\n if (this.shouldFailOperations) {\n throw new Error(\"Mock transaction failed\");\n }\n\n if (!tx.to) {\n throw new Error(\"Invalid transaction: missing 'to' address\");\n }\n\n // Simulate network delay if configured\n if (this.transactionDelay > 0) {\n await new Promise((resolve) =>\n setTimeout(resolve, this.transactionDelay),\n );\n }\n\n // Generate a deterministic mock transaction hash\n this.nonce++;\n const txData = JSON.stringify({\n from: this.account.address,\n to: tx.to,\n value: tx.value?.toString() || \"0\",\n nonce: this.nonce,\n chainId: this.chain.id,\n });\n\n const hash = `0x${Buffer.from(txData)\n .toString(\"hex\")\n .slice(0, 64)\n .padEnd(64, \"0\")}` as Hex;\n return hash;\n }\n\n /** Updates configuration for testing different scenarios. */\n updateConfig(updates: Partial<MockEthereumWalletConfig>): void {\n if (updates.address !== undefined) {\n this.account.address = updates.address;\n }\n if (updates.chainId !== undefined) {\n this.chain.id = updates.chainId;\n }\n if (updates.shouldFailOperations !== undefined) {\n this.shouldFailOperations = updates.shouldFailOperations;\n }\n if (updates.transactionDelay !== undefined) {\n this.transactionDelay = updates.transactionDelay;\n }\n }\n\n /** Resets to default configuration and nonce. */\n reset(): void {\n this.account.address =\n \"0x742d35cc6634c0532925a3b844bc9e7595f0beb0\" as Address;\n this.chain.id = 11155111;\n this.shouldFailOperations = false;\n this.transactionDelay = 0;\n this.nonce = 0;\n }\n\n /** Returns current nonce for testing. */\n getCurrentNonce(): number {\n return this.nonce;\n }\n}\n"],"names":["defaultDeriveContextHash","appName","context","enc","nameBytes","ctxBytes","buf","view","uint8ArrayToHex","sha256","DEFAULT_CONFIG","BitcoinNetworks","MockBitcoinWallet","config","__publicField","psbtHex","_options","psbtsHexes","signedPsbts","signedPsbt","message","type","Buffer","updates","MockEthereumWallet","args","account","signatureData","tx","resolve","txData","_a"],"mappings":"sXAoCMA,EAA2B,M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,iBAAmB,EACxB,KAAK,MAAQ,CACf,CAGA,iBAA0B,CACxB,OAAO,KAAK,KACd,CACF"}
1
+ {"version":3,"file":"index.cjs","sources":["../../src/testing/signBip322P2wpkhWitness.ts","../../src/testing/MockBitcoinWallet.ts","../../src/testing/MockEthereumWallet.ts"],"sourcesContent":["/**\n * Test-support BIP-322 \"simple\" P2WPKH signer.\n *\n * Produces the consensus-encoded two-item witness `[DER sig ‖ 0x01,\n * compressed pubkey]` that a Native SegWit software wallet returns for\n * `signMessage(..., \"bip322-simple\")`. The virtual to_spend/to_sign\n * construction follows the `bip322` crate 0.0.10 (`util.rs:18-85`) — the\n * same reference the production verifier\n * (`tbv/core/clients/vault-provider/auth/bip322Verify.ts`) mirrors, and\n * the BIP-322 official vectors pin.\n *\n * Test-only: never feed real key material to this module.\n */\n\nimport * as ecc from \"@bitcoin-js/tiny-secp256k1-asmjs\";\nimport { sha256 } from \"@noble/hashes/sha2.js\";\nimport { script as bscript, payments, Transaction } from \"bitcoinjs-lib\";\nimport { Buffer } from \"buffer\";\n\n/** BIP-322 message tag (BIP-340 tagged-hash style). */\nconst BIP322_TAG = \"BIP0322-signed-message\";\nconst SIGHASH_ALL = 0x01;\nconst ZERO_SATS = 0;\n/**\n * vaultd accepts only 71/72-byte encoded signatures (`bip322` crate 0.0.10\n * `verify.rs:141-153`); a short-DER signature (~0.8% of draws) is ground\n * away by re-signing with fresh entropy. 100 attempts bounds the failure\n * probability around 0.008^100.\n */\nconst MIN_ENCODED_SIG_BYTES = 71;\nconst MAX_SIGN_GRIND_ATTEMPTS = 100;\n\n// Wire fields of the virtual to_spend/to_sign transactions (`bip322`\n// crate 0.0.10 `util.rs:18-85`).\nconst BIP322_TX_VERSION = 0;\nconst BIP322_TX_LOCKTIME = 0;\nconst BIP322_INPUT_SEQUENCE = 0;\n/** to_spend prevout: all-zero 32-byte txid at index 0xFFFFFFFF (`util.rs:18-85`). */\nconst TO_SPEND_PREVOUT_TXID_BYTES = 32;\nconst TO_SPEND_PREVOUT_INDEX = 0xffffffff;\n/** to_sign spends to_spend's only output (`util.rs:18-85`). */\nconst TO_SPEND_OUTPUT_INDEX = 0;\nconst OP_0 = 0x00;\n/** Direct push of the 32-byte tagged message hash. */\nconst OP_PUSHBYTES_32 = 0x20;\nconst OP_RETURN = 0x6a;\n/** Consensus P2WPKH witness: exactly [signature, pubkey]. */\nconst P2WPKH_WITNESS_ITEMS = 2;\n/** Grinding: 32-byte extra-entropy buffer, attempt counter at offset 0. */\nconst GRIND_ENTROPY_BYTES = 32;\nconst GRIND_COUNTER_OFFSET = 0;\n\n/**\n * Sign `messageBytes` as a BIP-322 \"simple\" P2WPKH proof with `privateKey`\n * and return the consensus-encoded two-item witness\n * (`0x02 ‖ len ‖ sig ‖ 0x21 ‖ pubkey`).\n */\nexport function signBip322P2wpkhWitness(\n messageBytes: Uint8Array,\n privateKey: Uint8Array,\n): Uint8Array {\n const pubkey = ecc.pointFromScalar(privateKey, true);\n if (!pubkey) {\n throw new Error(\"signBip322P2wpkhWitness: invalid private key\");\n }\n\n // m_hash = SHA256( SHA256(tag) ‖ SHA256(tag) ‖ message )\n const tagHash = sha256(new TextEncoder().encode(BIP322_TAG));\n const messageHash = sha256(\n Buffer.concat([tagHash, tagHash, Buffer.from(messageBytes)]),\n );\n\n const p2wpkh = payments.p2wpkh({ pubkey: Buffer.from(pubkey) });\n if (!p2wpkh.output || !p2wpkh.hash) {\n throw new Error(\"signBip322P2wpkhWitness: could not derive P2WPKH script\");\n }\n\n // to_spend / to_sign per bip322 crate util.rs:18-85.\n const toSpend = new Transaction();\n toSpend.version = BIP322_TX_VERSION;\n toSpend.locktime = BIP322_TX_LOCKTIME;\n toSpend.addInput(\n Buffer.alloc(TO_SPEND_PREVOUT_TXID_BYTES, 0),\n TO_SPEND_PREVOUT_INDEX,\n BIP322_INPUT_SEQUENCE,\n Buffer.concat([\n Buffer.from([OP_0, OP_PUSHBYTES_32]),\n Buffer.from(messageHash),\n ]),\n );\n toSpend.addOutput(p2wpkh.output, ZERO_SATS);\n const toSign = new Transaction();\n toSign.version = BIP322_TX_VERSION;\n toSign.locktime = BIP322_TX_LOCKTIME;\n toSign.addInput(\n toSpend.getHash(),\n TO_SPEND_OUTPUT_INDEX,\n BIP322_INPUT_SEQUENCE,\n );\n toSign.addOutput(Buffer.from([OP_RETURN]), ZERO_SATS);\n\n // BIP-143 sighash with the standard P2WPKH scriptCode, value 0\n // (bip322 crate verify.rs:163-173).\n const scriptCode = payments.p2pkh({ hash: p2wpkh.hash }).output;\n if (!scriptCode) {\n throw new Error(\"signBip322P2wpkhWitness: could not build scriptCode\");\n }\n const sighash = toSign.hashForWitnessV0(\n 0,\n scriptCode,\n ZERO_SATS,\n SIGHASH_ALL,\n );\n\n let encodedSignature: Buffer | undefined;\n for (let attempt = 0; attempt < MAX_SIGN_GRIND_ATTEMPTS; attempt++) {\n const entropy = Buffer.alloc(GRIND_ENTROPY_BYTES, 0);\n entropy.writeUInt32LE(attempt, GRIND_COUNTER_OFFSET);\n // ecc.sign emits low-S (libsecp256k1), so 73-byte encodings can't occur.\n const candidate = bscript.signature.encode(\n Buffer.from(ecc.sign(sighash, privateKey, entropy)),\n SIGHASH_ALL,\n );\n if (candidate.length >= MIN_ENCODED_SIG_BYTES) {\n encodedSignature = candidate;\n break;\n }\n }\n if (!encodedSignature) {\n throw new Error(\n \"signBip322P2wpkhWitness: could not grind a 71/72-byte signature\",\n );\n }\n\n return Uint8Array.from([\n P2WPKH_WITNESS_ITEMS,\n encodedSignature.length,\n ...encodedSignature,\n pubkey.length,\n ...pubkey,\n ]);\n}\n","import * as ecc from \"@bitcoin-js/tiny-secp256k1-asmjs\";\nimport { sha256 } from \"@noble/hashes/sha2.js\";\nimport { Buffer } from \"buffer\";\n\nimport {\n BitcoinNetworks,\n type BitcoinNetwork,\n} from \"../shared/wallets/interfaces\";\nimport type {\n BitcoinWallet,\n SignPsbtOptions,\n} from \"../shared/wallets/interfaces/BitcoinWallet\";\nimport {\n canonicalizeBtcPubkey,\n uint8ArrayToHex,\n} from \"../tbv/core/primitives/utils/bitcoin\";\nimport { signBip322P2wpkhWitness } from \"./signBip322P2wpkhWitness\";\n\n/**\n * Configuration for MockBitcoinWallet.\n */\nexport interface MockBitcoinWalletConfig {\n publicKeyHex?: string;\n address?: string;\n network?: BitcoinNetwork;\n shouldFailSigning?: boolean;\n /**\n * 32-byte hex key `signMessage` signs BIP-322 proofs with. Defaults to\n * the privkey-1 test key, whose x-only pubkey is the default\n * `publicKeyHex` (the secp256k1 generator's x coordinate). PoP flows\n * verify the witness against `publicKeyHex`: overriding only this key\n * derives the matching `publicKeyHex`, and a divergent pair throws at\n * sign time. Test material only — never a real key.\n */\n privateKeyHex?: string;\n /**\n * Optional override for `deriveContextHash`. When omitted the mock\n * returns a deterministic 64-char lowercase hex string derived from\n * `(appName, context)` so tests can assert pass-through wiring\n * without pinning a specific value. Override to inject spec test\n * vectors or to simulate failure modes.\n */\n deriveContextHash?: (appName: string, context: string) => Promise<string>;\n}\n\n/**\n * Default `deriveContextHash` implementation: deterministic and\n * collision-resistant via SHA-256, so tests that assert pass-through\n * wiring (different `(appName, context)` → different output) hold\n * without flakes. Domain-separates the two inputs by length-prefixing\n * each as `len(name) || name || len(ctx) || ctx`, preventing\n * `(\"ab\", \"cd\")` from colliding with `(\"abc\", \"d\")`.\n */\nconst defaultDeriveContextHash = async (\n appName: string,\n context: string,\n): Promise<string> => {\n const enc = new TextEncoder();\n const nameBytes = enc.encode(appName);\n const ctxBytes = enc.encode(context);\n const buf = new Uint8Array(4 + nameBytes.length + 4 + ctxBytes.length);\n const view = new DataView(buf.buffer);\n view.setUint32(0, nameBytes.length);\n buf.set(nameBytes, 4);\n view.setUint32(4 + nameBytes.length, ctxBytes.length);\n buf.set(ctxBytes, 4 + nameBytes.length + 4);\n return uint8ArrayToHex(sha256(buf));\n};\n\n/** Privkey 1 — the test key `signMessage` signs with by default. */\nconst DEFAULT_PRIVATE_KEY_HEX = `${\"00\".repeat(31)}01`;\n\n/** Lowercase x-only pubkey of a 32-byte private key. */\nfunction xOnlyPubkeyHexOf(privateKeyHex: string): string {\n return uint8ArrayToHex(\n ecc.xOnlyPointFromScalar(\n Uint8Array.from(Buffer.from(privateKeyHex, \"hex\")),\n ),\n );\n}\n\nconst DEFAULT_CONFIG: Required<MockBitcoinWalletConfig> = {\n // x-only pubkey of DEFAULT_PRIVATE_KEY_HEX (the secp256k1 generator's x\n // coordinate), so the default wallet's PoP witnesses verify against it.\n publicKeyHex:\n \"79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798\",\n address: \"tb1pqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqkx6jks\",\n network: BitcoinNetworks.SIGNET,\n shouldFailSigning: false,\n privateKeyHex: DEFAULT_PRIVATE_KEY_HEX,\n deriveContextHash: defaultDeriveContextHash,\n};\n\n/** Mock Bitcoin wallet for testing. */\nexport class MockBitcoinWallet implements BitcoinWallet {\n private config: Required<MockBitcoinWalletConfig>;\n\n constructor(config: MockBitcoinWalletConfig = {}) {\n this.config = {\n ...DEFAULT_CONFIG,\n ...(config.publicKeyHex ? { publicKeyHex: config.publicKeyHex } : {}),\n ...(config.address ? { address: config.address } : {}),\n ...(config.network !== undefined ? { network: config.network } : {}),\n ...(config.shouldFailSigning !== undefined\n ? { shouldFailSigning: config.shouldFailSigning }\n : {}),\n ...(config.privateKeyHex ? { privateKeyHex: config.privateKeyHex } : {}),\n ...(config.deriveContextHash\n ? { deriveContextHash: config.deriveContextHash }\n : {}),\n };\n // A private-key override without a public key would otherwise sign\n // against the DEFAULT pubkey — derive the matching one instead.\n if (config.privateKeyHex && !config.publicKeyHex) {\n this.config.publicKeyHex = xOnlyPubkeyHexOf(config.privateKeyHex);\n }\n }\n\n async getPublicKeyHex(): Promise<string> {\n return this.config.publicKeyHex;\n }\n\n async getAddress(): Promise<string> {\n return this.config.address;\n }\n\n async signPsbt(psbtHex: string, _options?: SignPsbtOptions): Promise<string> {\n if (this.config.shouldFailSigning) {\n throw new Error(\"Mock signing failed\");\n }\n\n if (!psbtHex || psbtHex.length === 0) {\n throw new Error(\"Invalid PSBT: empty hex string\");\n }\n\n // In a real implementation, this would actually sign the PSBT\n // For the mock, we just return the input with a mock signature appended\n return psbtHex + \"deadbeef\";\n }\n\n async signPsbts(\n psbtsHexes: string[],\n _options?: SignPsbtOptions[],\n ): Promise<string[]> {\n const signedPsbts: string[] = [];\n for (const psbtHex of psbtsHexes) {\n const signedPsbt = await this.signPsbt(psbtHex);\n signedPsbts.push(signedPsbt);\n }\n return signedPsbts;\n }\n\n async signMessage(\n message: string,\n _type: \"bip322-simple\" | \"ecdsa\",\n ): Promise<string> {\n if (this.config.shouldFailSigning) {\n throw new Error(\"Mock signing failed\");\n }\n\n if (!message || message.length === 0) {\n throw new Error(\"Invalid message: empty string\");\n }\n\n // PoP flows verify the witness against `publicKeyHex`, so a divergent\n // key pair must fail loudly here, not as a confusing verify mismatch.\n const signingXOnlyHex = xOnlyPubkeyHexOf(this.config.privateKeyHex);\n let configuredXOnlyHex: string | undefined;\n try {\n configuredXOnlyHex = canonicalizeBtcPubkey(this.config.publicKeyHex);\n } catch {\n configuredXOnlyHex = undefined; // an unparseable key cannot match\n }\n if (configuredXOnlyHex !== signingXOnlyHex) {\n throw new Error(\n `MockBitcoinWallet.signMessage: privateKeyHex signs as x-only pubkey ` +\n `${signingXOnlyHex}, but publicKeyHex is ${this.config.publicKeyHex}. ` +\n `Pass a matching publicKeyHex/privateKeyHex pair.`,\n );\n }\n\n // The SDK cryptographically verifies what a wallet returns\n // (`verifyPopWitness`), so the mock signs a REAL BIP-322 P2WPKH witness\n // with its private key. The type is not consulted: PoP flows only ever\n // request \"bip322-simple\", and the interface tests assert shape only.\n const witness = signBip322P2wpkhWitness(\n new TextEncoder().encode(message),\n Uint8Array.from(Buffer.from(this.config.privateKeyHex, \"hex\")),\n );\n return `0x${uint8ArrayToHex(witness)}`;\n }\n\n async getNetwork(): Promise<BitcoinNetwork> {\n return this.config.network;\n }\n\n async deriveContextHash(appName: string, context: string): Promise<string> {\n return this.config.deriveContextHash(appName, context);\n }\n\n /** Updates configuration for testing different scenarios. */\n updateConfig(updates: Partial<MockBitcoinWalletConfig>): void {\n this.config = {\n ...this.config,\n ...updates,\n };\n }\n\n /** Resets to default configuration. */\n reset(): void {\n this.config = { ...DEFAULT_CONFIG };\n }\n}\n","import { Buffer } from \"buffer\";\nimport type { Address, Hex } from \"viem\";\n\n/**\n * Configuration for MockEthereumWallet.\n */\nexport interface MockEthereumWalletConfig {\n address?: Address;\n chainId?: number;\n shouldFailOperations?: boolean;\n transactionDelay?: number;\n}\n\n/**\n * Mock Ethereum wallet for testing.\n *\n * Provides the subset of viem's WalletClient methods used by the SDK.\n * Can be passed to functions expecting a WalletClient for testing purposes.\n */\nexport class MockEthereumWallet {\n // Public properties matching viem's WalletClient structure\n account: { address: Address };\n chain: { id: number };\n\n private shouldFailOperations: boolean;\n private transactionDelay: number;\n private nonce: number = 0;\n\n constructor(config: MockEthereumWalletConfig = {}) {\n // Use lowercase addresses to avoid EIP-55 checksum validation issues\n this.account = {\n address:\n config.address ||\n (\"0x742d35cc6634c0532925a3b844bc9e7595f0beb0\" as Address),\n };\n\n this.chain = {\n id: config.chainId ?? 11155111, // Sepolia by default\n };\n\n this.shouldFailOperations = config.shouldFailOperations ?? false;\n this.transactionDelay = config.transactionDelay ?? 0;\n\n // Bind methods to preserve 'this' context when called\n this.signMessage = this.signMessage.bind(this);\n this.sendTransaction = this.sendTransaction.bind(this);\n }\n\n async signMessage(args: { message: string; account?: Address }): Promise<Hex> {\n const message = args.message;\n const account = args.account || this.account.address;\n\n if (this.shouldFailOperations) {\n throw new Error(\"Mock signing failed\");\n }\n\n if (!message || message.length === 0) {\n throw new Error(\"Invalid message: empty string\");\n }\n\n // Generate a deterministic mock signature\n const signatureData = `personal_sign:${message}-${account}-${this.chain.id}`;\n const signature = `0x${Buffer.from(signatureData)\n .toString(\"hex\")\n .slice(0, 130)\n .padEnd(130, \"0\")}` as Hex;\n return signature;\n }\n\n async sendTransaction(tx: {\n to: Address;\n data?: Hex;\n value?: bigint;\n gas?: bigint;\n account?: { address: Address };\n chain?: { id: number };\n }): Promise<Hex> {\n if (this.shouldFailOperations) {\n throw new Error(\"Mock transaction failed\");\n }\n\n if (!tx.to) {\n throw new Error(\"Invalid transaction: missing 'to' address\");\n }\n\n // Simulate network delay if configured\n if (this.transactionDelay > 0) {\n await new Promise((resolve) =>\n setTimeout(resolve, this.transactionDelay),\n );\n }\n\n // Generate a deterministic mock transaction hash\n this.nonce++;\n const txData = JSON.stringify({\n from: this.account.address,\n to: tx.to,\n value: tx.value?.toString() || \"0\",\n nonce: this.nonce,\n chainId: this.chain.id,\n });\n\n const hash = `0x${Buffer.from(txData)\n .toString(\"hex\")\n .slice(0, 64)\n .padEnd(64, \"0\")}` as Hex;\n return hash;\n }\n\n /** Updates configuration for testing different scenarios. */\n updateConfig(updates: Partial<MockEthereumWalletConfig>): void {\n if (updates.address !== undefined) {\n this.account.address = updates.address;\n }\n if (updates.chainId !== undefined) {\n this.chain.id = updates.chainId;\n }\n if (updates.shouldFailOperations !== undefined) {\n this.shouldFailOperations = updates.shouldFailOperations;\n }\n if (updates.transactionDelay !== undefined) {\n this.transactionDelay = updates.transactionDelay;\n }\n }\n\n /** Resets to default configuration and nonce. */\n reset(): void {\n this.account.address =\n \"0x742d35cc6634c0532925a3b844bc9e7595f0beb0\" as Address;\n this.chain.id = 11155111;\n this.shouldFailOperations = false;\n this.transactionDelay = 0;\n this.nonce = 0;\n }\n\n /** Returns current nonce for testing. */\n getCurrentNonce(): number {\n return this.nonce;\n }\n}\n"],"names":["BIP322_TAG","SIGHASH_ALL","ZERO_SATS","MIN_ENCODED_SIG_BYTES","MAX_SIGN_GRIND_ATTEMPTS","BIP322_TX_VERSION","BIP322_TX_LOCKTIME","BIP322_INPUT_SEQUENCE","TO_SPEND_PREVOUT_TXID_BYTES","TO_SPEND_PREVOUT_INDEX","TO_SPEND_OUTPUT_INDEX","OP_0","OP_PUSHBYTES_32","OP_RETURN","P2WPKH_WITNESS_ITEMS","GRIND_ENTROPY_BYTES","GRIND_COUNTER_OFFSET","signBip322P2wpkhWitness","messageBytes","privateKey","pubkey","ecc","tagHash","sha256","messageHash","Buffer","p2wpkh","payments","toSpend","Transaction","toSign","scriptCode","sighash","encodedSignature","attempt","entropy","candidate","bscript","defaultDeriveContextHash","appName","context","enc","nameBytes","ctxBytes","buf","view","uint8ArrayToHex","DEFAULT_PRIVATE_KEY_HEX","xOnlyPubkeyHexOf","privateKeyHex","DEFAULT_CONFIG","BitcoinNetworks","MockBitcoinWallet","config","__publicField","psbtHex","_options","psbtsHexes","signedPsbts","signedPsbt","message","_type","signingXOnlyHex","configuredXOnlyHex","canonicalizeBtcPubkey","witness","updates","MockEthereumWallet","args","account","signatureData","tx","resolve","txData","_a"],"mappings":"ytBAoBMA,EAAa,yBACbC,EAAc,EACdC,EAAY,EAOZC,EAAwB,GACxBC,EAA0B,IAI1BC,EAAoB,EACpBC,EAAqB,EACrBC,EAAwB,EAExBC,EAA8B,GAC9BC,EAAyB,WAEzBC,EAAwB,EACxBC,EAAO,EAEPC,EAAkB,GAClBC,EAAY,IAEZC,EAAuB,EAEvBC,EAAsB,GACtBC,EAAuB,EAOtB,SAASC,EACdC,EACAC,EACY,CACZ,MAAMC,EAASC,EAAI,gBAAgBF,EAAY,EAAI,EACnD,GAAI,CAACC,EACH,MAAM,IAAI,MAAM,8CAA8C,EAIhE,MAAME,EAAUC,EAAAA,OAAO,IAAI,cAAc,OAAOvB,CAAU,CAAC,EACrDwB,EAAcD,EAAAA,OAClBE,EAAAA,OAAO,OAAO,CAACH,EAASA,EAASG,SAAO,KAAKP,CAAY,CAAC,CAAC,CAAA,EAGvDQ,EAASC,EAAAA,SAAS,OAAO,CAAE,OAAQF,SAAO,KAAKL,CAAM,EAAG,EAC9D,GAAI,CAACM,EAAO,QAAU,CAACA,EAA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AK,gBAAgB,CAAA,EAK7C,KAAK,QACL,MAAMC,EAAS,KAAK,UAAU,CAC5B,KAAM,KAAK,QAAQ,QACnB,GAAIF,EAAG,GACP,QAAOG,EAAAH,EAAG,QAAH,YAAAG,EAAU,aAAc,IAC/B,MAAO,KAAK,MACZ,QAAS,KAAK,MAAM,EAAA,CACrB,EAMD,MAJa,KAAKjD,EAAAA,OAAO,KAAKgD,CAAM,EACjC,SAAS,KAAK,EACd,MAAM,EAAG,EAAE,EACX,OAAO,GAAI,GAAG,CAAC,EAEpB,CAGA,aAAaP,EAAkD,CACzDA,EAAQ,UAAY,SACtB,KAAK,QAAQ,QAAUA,EAAQ,SAE7BA,EAAQ,UAAY,SACtB,KAAK,MAAM,GAAKA,EAAQ,SAEtBA,EAAQ,uBAAyB,SACnC,KAAK,qBAAuBA,EAAQ,sBAElCA,EAAQ,mBAAqB,SAC/B,KAAK,iBAAmBA,EAAQ,iBAEpC,CAGA,OAAc,CACZ,KAAK,QAAQ,QACX,6CACF,KAAK,MAAM,GAAK,SAChB,KAAK,qBAAuB,GAC5B,KAAK,iBAAmB,EACxB,KAAK,MAAQ,CACf,CAGA,iBAA0B,CACxB,OAAO,KAAK,KACd,CACF"}
@@ -1,31 +1,105 @@
1
- var d = Object.defineProperty;
2
- var l = (e, t, s) => t in e ? d(e, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : e[t] = s;
3
- var o = (e, t, s) => l(e, typeof t != "symbol" ? t + "" : t, s);
4
- import { s as g } from "../sha2-BYVxyZzX.js";
5
- import { Buffer as r } from "buffer";
6
- import { u } from "../bitcoin-d9eaaZB_.js";
7
- import { BitcoinNetworks as q } from "../shared/index.js";
8
- const f = async (e, t) => {
9
- const s = new TextEncoder(), n = s.encode(e), i = s.encode(t), a = new Uint8Array(4 + n.length + 4 + i.length), c = new DataView(a.buffer);
10
- return c.setUint32(0, n.length), a.set(n, 4), c.setUint32(4 + n.length, i.length), a.set(i, 4 + n.length + 4), u(g(a));
11
- }, h = {
12
- publicKeyHex: "a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2",
1
+ var v = Object.defineProperty;
2
+ var I = (r, t, e) => t in r ? v(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
3
+ var c = (r, t, e) => I(r, typeof t != "symbol" ? t + "" : t, e);
4
+ import * as g from "@bitcoin-js/tiny-secp256k1-asmjs";
5
+ import { s as p } from "../sha2-BYVxyZzX.js";
6
+ import { Buffer as o } from "buffer";
7
+ import { c as O, u as f } from "../bitcoin-Ch_jxnDa.js";
8
+ import { payments as E, Transaction as x, script as k } from "bitcoinjs-lib";
9
+ import { BitcoinNetworks as D } from "../shared/index.js";
10
+ const K = "BIP0322-signed-message", b = 1, u = 0, N = 71, F = 100, m = 0, _ = 0, H = 0, B = 32, U = 4294967295, C = 0, M = 0, A = 32, R = 106, W = 2, G = 32, X = 0;
11
+ function $(r, t) {
12
+ const e = g.pointFromScalar(t, !0);
13
+ if (!e)
14
+ throw new Error("signBip322P2wpkhWitness: invalid private key");
15
+ const n = p(new TextEncoder().encode(K)), s = p(
16
+ o.concat([n, n, o.from(r)])
17
+ ), i = E.p2wpkh({ pubkey: o.from(e) });
18
+ if (!i.output || !i.hash)
19
+ throw new Error("signBip322P2wpkhWitness: could not derive P2WPKH script");
20
+ const a = new x();
21
+ a.version = m, a.locktime = _, a.addInput(
22
+ o.alloc(B, 0),
23
+ U,
24
+ H,
25
+ o.concat([
26
+ o.from([M, A]),
27
+ o.from(s)
28
+ ])
29
+ ), a.addOutput(i.output, u);
30
+ const h = new x();
31
+ h.version = m, h.locktime = _, h.addInput(
32
+ a.getHash(),
33
+ C,
34
+ H
35
+ ), h.addOutput(o.from([R]), u);
36
+ const y = E.p2pkh({ hash: i.hash }).output;
37
+ if (!y)
38
+ throw new Error("signBip322P2wpkhWitness: could not build scriptCode");
39
+ const S = h.hashForWitnessV0(
40
+ 0,
41
+ y,
42
+ u,
43
+ b
44
+ );
45
+ let d;
46
+ for (let l = 0; l < F; l++) {
47
+ const w = o.alloc(G, 0);
48
+ w.writeUInt32LE(l, X);
49
+ const q = k.signature.encode(
50
+ o.from(g.sign(S, t, w)),
51
+ b
52
+ );
53
+ if (q.length >= N) {
54
+ d = q;
55
+ break;
56
+ }
57
+ }
58
+ if (!d)
59
+ throw new Error(
60
+ "signBip322P2wpkhWitness: could not grind a 71/72-byte signature"
61
+ );
62
+ return Uint8Array.from([
63
+ W,
64
+ d.length,
65
+ ...d,
66
+ e.length,
67
+ ...e
68
+ ]);
69
+ }
70
+ const L = async (r, t) => {
71
+ const e = new TextEncoder(), n = e.encode(r), s = e.encode(t), i = new Uint8Array(4 + n.length + 4 + s.length), a = new DataView(i.buffer);
72
+ return a.setUint32(0, n.length), i.set(n, 4), a.setUint32(4 + n.length, s.length), i.set(s, 4 + n.length + 4), f(p(i));
73
+ }, V = `${"00".repeat(31)}01`;
74
+ function T(r) {
75
+ return f(
76
+ g.xOnlyPointFromScalar(
77
+ Uint8Array.from(o.from(r, "hex"))
78
+ )
79
+ );
80
+ }
81
+ const P = {
82
+ // x-only pubkey of DEFAULT_PRIVATE_KEY_HEX (the secp256k1 generator's x
83
+ // coordinate), so the default wallet's PoP witnesses verify against it.
84
+ publicKeyHex: "79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",
13
85
  address: "tb1pqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqkx6jks",
14
- network: q.SIGNET,
86
+ network: D.SIGNET,
15
87
  shouldFailSigning: !1,
16
- deriveContextHash: f
88
+ privateKeyHex: V,
89
+ deriveContextHash: L
17
90
  };
18
- class x {
91
+ class tt {
19
92
  constructor(t = {}) {
20
- o(this, "config");
93
+ c(this, "config");
21
94
  this.config = {
22
- ...h,
95
+ ...P,
23
96
  ...t.publicKeyHex ? { publicKeyHex: t.publicKeyHex } : {},
24
97
  ...t.address ? { address: t.address } : {},
25
98
  ...t.network !== void 0 ? { network: t.network } : {},
26
99
  ...t.shouldFailSigning !== void 0 ? { shouldFailSigning: t.shouldFailSigning } : {},
100
+ ...t.privateKeyHex ? { privateKeyHex: t.privateKeyHex } : {},
27
101
  ...t.deriveContextHash ? { deriveContextHash: t.deriveContextHash } : {}
28
- };
102
+ }, t.privateKeyHex && !t.publicKeyHex && (this.config.publicKeyHex = T(t.privateKeyHex));
29
103
  }
30
104
  async getPublicKeyHex() {
31
105
  return this.config.publicKeyHex;
@@ -33,35 +107,48 @@ class x {
33
107
  async getAddress() {
34
108
  return this.config.address;
35
109
  }
36
- async signPsbt(t, s) {
110
+ async signPsbt(t, e) {
37
111
  if (this.config.shouldFailSigning)
38
112
  throw new Error("Mock signing failed");
39
113
  if (!t || t.length === 0)
40
114
  throw new Error("Invalid PSBT: empty hex string");
41
115
  return t + "deadbeef";
42
116
  }
43
- async signPsbts(t, s) {
117
+ async signPsbts(t, e) {
44
118
  const n = [];
45
- for (const i of t) {
46
- const a = await this.signPsbt(i);
47
- n.push(a);
119
+ for (const s of t) {
120
+ const i = await this.signPsbt(s);
121
+ n.push(i);
48
122
  }
49
123
  return n;
50
124
  }
51
- async signMessage(t, s) {
125
+ async signMessage(t, e) {
52
126
  if (this.config.shouldFailSigning)
53
127
  throw new Error("Mock signing failed");
54
128
  if (!t || t.length === 0)
55
129
  throw new Error("Invalid message: empty string");
56
- return r.from(
57
- `mock-signature-${s}-${t}-${this.config.publicKeyHex}`
58
- ).toString("base64");
130
+ const n = T(this.config.privateKeyHex);
131
+ let s;
132
+ try {
133
+ s = O(this.config.publicKeyHex);
134
+ } catch {
135
+ s = void 0;
136
+ }
137
+ if (s !== n)
138
+ throw new Error(
139
+ `MockBitcoinWallet.signMessage: privateKeyHex signs as x-only pubkey ${n}, but publicKeyHex is ${this.config.publicKeyHex}. Pass a matching publicKeyHex/privateKeyHex pair.`
140
+ );
141
+ const i = $(
142
+ new TextEncoder().encode(t),
143
+ Uint8Array.from(o.from(this.config.privateKeyHex, "hex"))
144
+ );
145
+ return `0x${f(i)}`;
59
146
  }
60
147
  async getNetwork() {
61
148
  return this.config.network;
62
149
  }
63
- async deriveContextHash(t, s) {
64
- return this.config.deriveContextHash(t, s);
150
+ async deriveContextHash(t, e) {
151
+ return this.config.deriveContextHash(t, e);
65
152
  }
66
153
  /** Updates configuration for testing different scenarios. */
67
154
  updateConfig(t) {
@@ -72,17 +159,17 @@ class x {
72
159
  }
73
160
  /** Resets to default configuration. */
74
161
  reset() {
75
- this.config = { ...h };
162
+ this.config = { ...P };
76
163
  }
77
164
  }
78
- class v {
165
+ class et {
79
166
  constructor(t = {}) {
80
167
  // Public properties matching viem's WalletClient structure
81
- o(this, "account");
82
- o(this, "chain");
83
- o(this, "shouldFailOperations");
84
- o(this, "transactionDelay");
85
- o(this, "nonce", 0);
168
+ c(this, "account");
169
+ c(this, "chain");
170
+ c(this, "shouldFailOperations");
171
+ c(this, "transactionDelay");
172
+ c(this, "nonce", 0);
86
173
  this.account = {
87
174
  address: t.address || "0x742d35cc6634c0532925a3b844bc9e7595f0beb0"
88
175
  }, this.chain = {
@@ -91,31 +178,31 @@ class v {
91
178
  }, this.shouldFailOperations = t.shouldFailOperations ?? !1, this.transactionDelay = t.transactionDelay ?? 0, this.signMessage = this.signMessage.bind(this), this.sendTransaction = this.sendTransaction.bind(this);
92
179
  }
93
180
  async signMessage(t) {
94
- const s = t.message, n = t.account || this.account.address;
181
+ const e = t.message, n = t.account || this.account.address;
95
182
  if (this.shouldFailOperations)
96
183
  throw new Error("Mock signing failed");
97
- if (!s || s.length === 0)
184
+ if (!e || e.length === 0)
98
185
  throw new Error("Invalid message: empty string");
99
- const i = `personal_sign:${s}-${n}-${this.chain.id}`;
100
- return `0x${r.from(i).toString("hex").slice(0, 130).padEnd(130, "0")}`;
186
+ const s = `personal_sign:${e}-${n}-${this.chain.id}`;
187
+ return `0x${o.from(s).toString("hex").slice(0, 130).padEnd(130, "0")}`;
101
188
  }
102
189
  async sendTransaction(t) {
103
- var i;
190
+ var s;
104
191
  if (this.shouldFailOperations)
105
192
  throw new Error("Mock transaction failed");
106
193
  if (!t.to)
107
194
  throw new Error("Invalid transaction: missing 'to' address");
108
195
  this.transactionDelay > 0 && await new Promise(
109
- (a) => setTimeout(a, this.transactionDelay)
196
+ (i) => setTimeout(i, this.transactionDelay)
110
197
  ), this.nonce++;
111
- const s = JSON.stringify({
198
+ const e = JSON.stringify({
112
199
  from: this.account.address,
113
200
  to: t.to,
114
- value: ((i = t.value) == null ? void 0 : i.toString()) || "0",
201
+ value: ((s = t.value) == null ? void 0 : s.toString()) || "0",
115
202
  nonce: this.nonce,
116
203
  chainId: this.chain.id
117
204
  });
118
- return `0x${r.from(s).toString("hex").slice(0, 64).padEnd(64, "0")}`;
205
+ return `0x${o.from(e).toString("hex").slice(0, 64).padEnd(64, "0")}`;
119
206
  }
120
207
  /** Updates configuration for testing different scenarios. */
121
208
  updateConfig(t) {
@@ -131,7 +218,7 @@ class v {
131
218
  }
132
219
  }
133
220
  export {
134
- x as MockBitcoinWallet,
135
- v as MockEthereumWallet
221
+ tt as MockBitcoinWallet,
222
+ et as MockEthereumWallet
136
223
  };
137
224
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/testing/MockBitcoinWallet.ts","../../src/testing/MockEthereumWallet.ts"],"sourcesContent":["import { sha256 } from \"@noble/hashes/sha2.js\";\nimport { Buffer } from \"buffer\";\n\nimport { BitcoinNetworks, type BitcoinNetwork } from \"../shared/wallets/interfaces\";\nimport type {\n BitcoinWallet,\n SignPsbtOptions,\n} from \"../shared/wallets/interfaces/BitcoinWallet\";\nimport { uint8ArrayToHex } from \"../tbv/core/primitives/utils/bitcoin\";\n\n/**\n * Configuration for MockBitcoinWallet.\n */\nexport interface MockBitcoinWalletConfig {\n publicKeyHex?: string;\n address?: string;\n network?: BitcoinNetwork;\n shouldFailSigning?: boolean;\n /**\n * Optional override for `deriveContextHash`. When omitted the mock\n * returns a deterministic 64-char lowercase hex string derived from\n * `(appName, context)` so tests can assert pass-through wiring\n * without pinning a specific value. Override to inject spec test\n * vectors or to simulate failure modes.\n */\n deriveContextHash?: (appName: string, context: string) => Promise<string>;\n}\n\n/**\n * Default `deriveContextHash` implementation: deterministic and\n * collision-resistant via SHA-256, so tests that assert pass-through\n * wiring (different `(appName, context)` → different output) hold\n * without flakes. Domain-separates the two inputs by length-prefixing\n * each as `len(name) || name || len(ctx) || ctx`, preventing\n * `(\"ab\", \"cd\")` from colliding with `(\"abc\", \"d\")`.\n */\nconst defaultDeriveContextHash = async (\n appName: string,\n context: string,\n): Promise<string> => {\n const enc = new TextEncoder();\n const nameBytes = enc.encode(appName);\n const ctxBytes = enc.encode(context);\n const buf = new Uint8Array(4 + nameBytes.length + 4 + ctxBytes.length);\n const view = new DataView(buf.buffer);\n view.setUint32(0, nameBytes.length);\n buf.set(nameBytes, 4);\n view.setUint32(4 + nameBytes.length, ctxBytes.length);\n buf.set(ctxBytes, 4 + nameBytes.length + 4);\n return uint8ArrayToHex(sha256(buf));\n};\n\nconst DEFAULT_CONFIG: Required<MockBitcoinWalletConfig> = {\n publicKeyHex:\n \"a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2\",\n address: \"tb1pqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqkx6jks\",\n network: BitcoinNetworks.SIGNET,\n shouldFailSigning: false,\n deriveContextHash: defaultDeriveContextHash,\n};\n\n/** Mock Bitcoin wallet for testing. */\nexport class MockBitcoinWallet implements BitcoinWallet {\n private config: Required<MockBitcoinWalletConfig>;\n\n constructor(config: MockBitcoinWalletConfig = {}) {\n this.config = {\n ...DEFAULT_CONFIG,\n ...(config.publicKeyHex ? { publicKeyHex: config.publicKeyHex } : {}),\n ...(config.address ? { address: config.address } : {}),\n ...(config.network !== undefined ? { network: config.network } : {}),\n ...(config.shouldFailSigning !== undefined\n ? { shouldFailSigning: config.shouldFailSigning }\n : {}),\n ...(config.deriveContextHash\n ? { deriveContextHash: config.deriveContextHash }\n : {}),\n };\n }\n\n async getPublicKeyHex(): Promise<string> {\n return this.config.publicKeyHex;\n }\n\n async getAddress(): Promise<string> {\n return this.config.address;\n }\n\n async signPsbt(\n psbtHex: string,\n _options?: SignPsbtOptions,\n ): Promise<string> {\n if (this.config.shouldFailSigning) {\n throw new Error(\"Mock signing failed\");\n }\n\n if (!psbtHex || psbtHex.length === 0) {\n throw new Error(\"Invalid PSBT: empty hex string\");\n }\n\n // In a real implementation, this would actually sign the PSBT\n // For the mock, we just return the input with a mock signature appended\n return psbtHex + \"deadbeef\";\n }\n\n async signPsbts(\n psbtsHexes: string[],\n _options?: SignPsbtOptions[],\n ): Promise<string[]> {\n const signedPsbts: string[] = [];\n for (const psbtHex of psbtsHexes) {\n const signedPsbt = await this.signPsbt(psbtHex);\n signedPsbts.push(signedPsbt);\n }\n return signedPsbts;\n }\n\n async signMessage(\n message: string,\n type: \"bip322-simple\" | \"ecdsa\",\n ): Promise<string> {\n if (this.config.shouldFailSigning) {\n throw new Error(\"Mock signing failed\");\n }\n\n if (!message || message.length === 0) {\n throw new Error(\"Invalid message: empty string\");\n }\n\n // In a real implementation, this would create a proper signature\n // For the mock, we return a base64-like mock signature\n const mockSignature = Buffer.from(\n `mock-signature-${type}-${message}-${this.config.publicKeyHex}`,\n ).toString(\"base64\");\n return mockSignature;\n }\n\n async getNetwork(): Promise<BitcoinNetwork> {\n return this.config.network;\n }\n\n async deriveContextHash(appName: string, context: string): Promise<string> {\n return this.config.deriveContextHash(appName, context);\n }\n\n /** Updates configuration for testing different scenarios. */\n updateConfig(updates: Partial<MockBitcoinWalletConfig>): void {\n this.config = {\n ...this.config,\n ...updates,\n };\n }\n\n /** Resets to default configuration. */\n reset(): void {\n this.config = { ...DEFAULT_CONFIG };\n }\n}\n","import { Buffer } from \"buffer\";\nimport type { Address, Hex } from \"viem\";\n\n/**\n * Configuration for MockEthereumWallet.\n */\nexport interface MockEthereumWalletConfig {\n address?: Address;\n chainId?: number;\n shouldFailOperations?: boolean;\n transactionDelay?: number;\n}\n\n/**\n * Mock Ethereum wallet for testing.\n *\n * Provides the subset of viem's WalletClient methods used by the SDK.\n * Can be passed to functions expecting a WalletClient for testing purposes.\n */\nexport class MockEthereumWallet {\n // Public properties matching viem's WalletClient structure\n account: { address: Address };\n chain: { id: number };\n\n private shouldFailOperations: boolean;\n private transactionDelay: number;\n private nonce: number = 0;\n\n constructor(config: MockEthereumWalletConfig = {}) {\n // Use lowercase addresses to avoid EIP-55 checksum validation issues\n this.account = {\n address:\n config.address ||\n (\"0x742d35cc6634c0532925a3b844bc9e7595f0beb0\" as Address),\n };\n\n this.chain = {\n id: config.chainId ?? 11155111, // Sepolia by default\n };\n\n this.shouldFailOperations = config.shouldFailOperations ?? false;\n this.transactionDelay = config.transactionDelay ?? 0;\n\n // Bind methods to preserve 'this' context when called\n this.signMessage = this.signMessage.bind(this);\n this.sendTransaction = this.sendTransaction.bind(this);\n }\n\n async signMessage(args: { message: string; account?: Address }): Promise<Hex> {\n const message = args.message;\n const account = args.account || this.account.address;\n\n if (this.shouldFailOperations) {\n throw new Error(\"Mock signing failed\");\n }\n\n if (!message || message.length === 0) {\n throw new Error(\"Invalid message: empty string\");\n }\n\n // Generate a deterministic mock signature\n const signatureData = `personal_sign:${message}-${account}-${this.chain.id}`;\n const signature = `0x${Buffer.from(signatureData)\n .toString(\"hex\")\n .slice(0, 130)\n .padEnd(130, \"0\")}` as Hex;\n return signature;\n }\n\n async sendTransaction(tx: {\n to: Address;\n data?: Hex;\n value?: bigint;\n gas?: bigint;\n account?: { address: Address };\n chain?: { id: number };\n }): Promise<Hex> {\n if (this.shouldFailOperations) {\n throw new Error(\"Mock transaction failed\");\n }\n\n if (!tx.to) {\n throw new Error(\"Invalid transaction: missing 'to' address\");\n }\n\n // Simulate network delay if configured\n if (this.transactionDelay > 0) {\n await new Promise((resolve) =>\n setTimeout(resolve, this.transactionDelay),\n );\n }\n\n // Generate a deterministic mock transaction hash\n this.nonce++;\n const txData = JSON.stringify({\n from: this.account.address,\n to: tx.to,\n value: tx.value?.toString() || \"0\",\n nonce: this.nonce,\n chainId: this.chain.id,\n });\n\n const hash = `0x${Buffer.from(txData)\n .toString(\"hex\")\n .slice(0, 64)\n .padEnd(64, \"0\")}` as Hex;\n return hash;\n }\n\n /** Updates configuration for testing different scenarios. */\n updateConfig(updates: Partial<MockEthereumWalletConfig>): void {\n if (updates.address !== undefined) {\n this.account.address = updates.address;\n }\n if (updates.chainId !== undefined) {\n this.chain.id = updates.chainId;\n }\n if (updates.shouldFailOperations !== undefined) {\n this.shouldFailOperations = updates.shouldFailOperations;\n }\n if (updates.transactionDelay !== undefined) {\n this.transactionDelay = updates.transactionDelay;\n }\n }\n\n /** Resets to default configuration and nonce. */\n reset(): void {\n this.account.address =\n \"0x742d35cc6634c0532925a3b844bc9e7595f0beb0\" as Address;\n this.chain.id = 11155111;\n this.shouldFailOperations = false;\n this.transactionDelay = 0;\n this.nonce = 0;\n }\n\n /** Returns current nonce for testing. */\n getCurrentNonce(): number {\n return this.nonce;\n }\n}\n"],"names":["defaultDeriveContextHash","appName","context","enc","nameBytes","ctxBytes","buf","view","uint8ArrayToHex","sha256","DEFAULT_CONFIG","BitcoinNetworks","MockBitcoinWallet","config","__publicField","psbtHex","_options","psbtsHexes","signedPsbts","signedPsbt","message","type","Buffer","updates","MockEthereumWallet","args","account","signatureData","tx","resolve","txData","_a"],"mappings":";;;;;;;AAoCA,MAAMA,IAA2B,OAC/BC,GACAC,MACoB;AACpB,QAAMC,IAAM,IAAI,YAAA,GACVC,IAAYD,EAAI,OAAOF,CAAO,GAC9BI,IAAWF,EAAI,OAAOD,CAAO,GAC7BI,IAAM,IAAI,WAAW,IAAIF,EAAU,SAAS,IAAIC,EAAS,MAAM,GAC/DE,IAAO,IAAI,SAASD,EAAI,MAAM;AACpC,SAAAC,EAAK,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BAElCA,EAAQ,qBAAqB,WAC/B,KAAK,mBAAmBA,EAAQ;AAAA,EAEpC;AAAA;AAAA,EAGA,QAAc;AACZ,SAAK,QAAQ,UACX,8CACF,KAAK,MAAM,KAAK,UAChB,KAAK,uBAAuB,IAC5B,KAAK,mBAAmB,GACxB,KAAK,QAAQ;AAAA,EACf;AAAA;AAAA,EAGA,kBAA0B;AACxB,WAAO,KAAK;AAAA,EACd;AACF;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/testing/signBip322P2wpkhWitness.ts","../../src/testing/MockBitcoinWallet.ts","../../src/testing/MockEthereumWallet.ts"],"sourcesContent":["/**\n * Test-support BIP-322 \"simple\" P2WPKH signer.\n *\n * Produces the consensus-encoded two-item witness `[DER sig ‖ 0x01,\n * compressed pubkey]` that a Native SegWit software wallet returns for\n * `signMessage(..., \"bip322-simple\")`. The virtual to_spend/to_sign\n * construction follows the `bip322` crate 0.0.10 (`util.rs:18-85`) — the\n * same reference the production verifier\n * (`tbv/core/clients/vault-provider/auth/bip322Verify.ts`) mirrors, and\n * the BIP-322 official vectors pin.\n *\n * Test-only: never feed real key material to this module.\n */\n\nimport * as ecc from \"@bitcoin-js/tiny-secp256k1-asmjs\";\nimport { sha256 } from \"@noble/hashes/sha2.js\";\nimport { script as bscript, payments, Transaction } from \"bitcoinjs-lib\";\nimport { Buffer } from \"buffer\";\n\n/** BIP-322 message tag (BIP-340 tagged-hash style). */\nconst BIP322_TAG = \"BIP0322-signed-message\";\nconst SIGHASH_ALL = 0x01;\nconst ZERO_SATS = 0;\n/**\n * vaultd accepts only 71/72-byte encoded signatures (`bip322` crate 0.0.10\n * `verify.rs:141-153`); a short-DER signature (~0.8% of draws) is ground\n * away by re-signing with fresh entropy. 100 attempts bounds the failure\n * probability around 0.008^100.\n */\nconst MIN_ENCODED_SIG_BYTES = 71;\nconst MAX_SIGN_GRIND_ATTEMPTS = 100;\n\n// Wire fields of the virtual to_spend/to_sign transactions (`bip322`\n// crate 0.0.10 `util.rs:18-85`).\nconst BIP322_TX_VERSION = 0;\nconst BIP322_TX_LOCKTIME = 0;\nconst BIP322_INPUT_SEQUENCE = 0;\n/** to_spend prevout: all-zero 32-byte txid at index 0xFFFFFFFF (`util.rs:18-85`). */\nconst TO_SPEND_PREVOUT_TXID_BYTES = 32;\nconst TO_SPEND_PREVOUT_INDEX = 0xffffffff;\n/** to_sign spends to_spend's only output (`util.rs:18-85`). */\nconst TO_SPEND_OUTPUT_INDEX = 0;\nconst OP_0 = 0x00;\n/** Direct push of the 32-byte tagged message hash. */\nconst OP_PUSHBYTES_32 = 0x20;\nconst OP_RETURN = 0x6a;\n/** Consensus P2WPKH witness: exactly [signature, pubkey]. */\nconst P2WPKH_WITNESS_ITEMS = 2;\n/** Grinding: 32-byte extra-entropy buffer, attempt counter at offset 0. */\nconst GRIND_ENTROPY_BYTES = 32;\nconst GRIND_COUNTER_OFFSET = 0;\n\n/**\n * Sign `messageBytes` as a BIP-322 \"simple\" P2WPKH proof with `privateKey`\n * and return the consensus-encoded two-item witness\n * (`0x02 ‖ len ‖ sig ‖ 0x21 ‖ pubkey`).\n */\nexport function signBip322P2wpkhWitness(\n messageBytes: Uint8Array,\n privateKey: Uint8Array,\n): Uint8Array {\n const pubkey = ecc.pointFromScalar(privateKey, true);\n if (!pubkey) {\n throw new Error(\"signBip322P2wpkhWitness: invalid private key\");\n }\n\n // m_hash = SHA256( SHA256(tag) ‖ SHA256(tag) ‖ message )\n const tagHash = sha256(new TextEncoder().encode(BIP322_TAG));\n const messageHash = sha256(\n Buffer.concat([tagHash, tagHash, Buffer.from(messageBytes)]),\n );\n\n const p2wpkh = payments.p2wpkh({ pubkey: Buffer.from(pubkey) });\n if (!p2wpkh.output || !p2wpkh.hash) {\n throw new Error(\"signBip322P2wpkhWitness: could not derive P2WPKH script\");\n }\n\n // to_spend / to_sign per bip322 crate util.rs:18-85.\n const toSpend = new Transaction();\n toSpend.version = BIP322_TX_VERSION;\n toSpend.locktime = BIP322_TX_LOCKTIME;\n toSpend.addInput(\n Buffer.alloc(TO_SPEND_PREVOUT_TXID_BYTES, 0),\n TO_SPEND_PREVOUT_INDEX,\n BIP322_INPUT_SEQUENCE,\n Buffer.concat([\n Buffer.from([OP_0, OP_PUSHBYTES_32]),\n Buffer.from(messageHash),\n ]),\n );\n toSpend.addOutput(p2wpkh.output, ZERO_SATS);\n const toSign = new Transaction();\n toSign.version = BIP322_TX_VERSION;\n toSign.locktime = BIP322_TX_LOCKTIME;\n toSign.addInput(\n toSpend.getHash(),\n TO_SPEND_OUTPUT_INDEX,\n BIP322_INPUT_SEQUENCE,\n );\n toSign.addOutput(Buffer.from([OP_RETURN]), ZERO_SATS);\n\n // BIP-143 sighash with the standard P2WPKH scriptCode, value 0\n // (bip322 crate verify.rs:163-173).\n const scriptCode = payments.p2pkh({ hash: p2wpkh.hash }).output;\n if (!scriptCode) {\n throw new Error(\"signBip322P2wpkhWitness: could not build scriptCode\");\n }\n const sighash = toSign.hashForWitnessV0(\n 0,\n scriptCode,\n ZERO_SATS,\n SIGHASH_ALL,\n );\n\n let encodedSignature: Buffer | undefined;\n for (let attempt = 0; attempt < MAX_SIGN_GRIND_ATTEMPTS; attempt++) {\n const entropy = Buffer.alloc(GRIND_ENTROPY_BYTES, 0);\n entropy.writeUInt32LE(attempt, GRIND_COUNTER_OFFSET);\n // ecc.sign emits low-S (libsecp256k1), so 73-byte encodings can't occur.\n const candidate = bscript.signature.encode(\n Buffer.from(ecc.sign(sighash, privateKey, entropy)),\n SIGHASH_ALL,\n );\n if (candidate.length >= MIN_ENCODED_SIG_BYTES) {\n encodedSignature = candidate;\n break;\n }\n }\n if (!encodedSignature) {\n throw new Error(\n \"signBip322P2wpkhWitness: could not grind a 71/72-byte signature\",\n );\n }\n\n return Uint8Array.from([\n P2WPKH_WITNESS_ITEMS,\n encodedSignature.length,\n ...encodedSignature,\n pubkey.length,\n ...pubkey,\n ]);\n}\n","import * as ecc from \"@bitcoin-js/tiny-secp256k1-asmjs\";\nimport { sha256 } from \"@noble/hashes/sha2.js\";\nimport { Buffer } from \"buffer\";\n\nimport {\n BitcoinNetworks,\n type BitcoinNetwork,\n} from \"../shared/wallets/interfaces\";\nimport type {\n BitcoinWallet,\n SignPsbtOptions,\n} from \"../shared/wallets/interfaces/BitcoinWallet\";\nimport {\n canonicalizeBtcPubkey,\n uint8ArrayToHex,\n} from \"../tbv/core/primitives/utils/bitcoin\";\nimport { signBip322P2wpkhWitness } from \"./signBip322P2wpkhWitness\";\n\n/**\n * Configuration for MockBitcoinWallet.\n */\nexport interface MockBitcoinWalletConfig {\n publicKeyHex?: string;\n address?: string;\n network?: BitcoinNetwork;\n shouldFailSigning?: boolean;\n /**\n * 32-byte hex key `signMessage` signs BIP-322 proofs with. Defaults to\n * the privkey-1 test key, whose x-only pubkey is the default\n * `publicKeyHex` (the secp256k1 generator's x coordinate). PoP flows\n * verify the witness against `publicKeyHex`: overriding only this key\n * derives the matching `publicKeyHex`, and a divergent pair throws at\n * sign time. Test material only — never a real key.\n */\n privateKeyHex?: string;\n /**\n * Optional override for `deriveContextHash`. When omitted the mock\n * returns a deterministic 64-char lowercase hex string derived from\n * `(appName, context)` so tests can assert pass-through wiring\n * without pinning a specific value. Override to inject spec test\n * vectors or to simulate failure modes.\n */\n deriveContextHash?: (appName: string, context: string) => Promise<string>;\n}\n\n/**\n * Default `deriveContextHash` implementation: deterministic and\n * collision-resistant via SHA-256, so tests that assert pass-through\n * wiring (different `(appName, context)` → different output) hold\n * without flakes. Domain-separates the two inputs by length-prefixing\n * each as `len(name) || name || len(ctx) || ctx`, preventing\n * `(\"ab\", \"cd\")` from colliding with `(\"abc\", \"d\")`.\n */\nconst defaultDeriveContextHash = async (\n appName: string,\n context: string,\n): Promise<string> => {\n const enc = new TextEncoder();\n const nameBytes = enc.encode(appName);\n const ctxBytes = enc.encode(context);\n const buf = new Uint8Array(4 + nameBytes.length + 4 + ctxBytes.length);\n const view = new DataView(buf.buffer);\n view.setUint32(0, nameBytes.length);\n buf.set(nameBytes, 4);\n view.setUint32(4 + nameBytes.length, ctxBytes.length);\n buf.set(ctxBytes, 4 + nameBytes.length + 4);\n return uint8ArrayToHex(sha256(buf));\n};\n\n/** Privkey 1 — the test key `signMessage` signs with by default. */\nconst DEFAULT_PRIVATE_KEY_HEX = `${\"00\".repeat(31)}01`;\n\n/** Lowercase x-only pubkey of a 32-byte private key. */\nfunction xOnlyPubkeyHexOf(privateKeyHex: string): string {\n return uint8ArrayToHex(\n ecc.xOnlyPointFromScalar(\n Uint8Array.from(Buffer.from(privateKeyHex, \"hex\")),\n ),\n );\n}\n\nconst DEFAULT_CONFIG: Required<MockBitcoinWalletConfig> = {\n // x-only pubkey of DEFAULT_PRIVATE_KEY_HEX (the secp256k1 generator's x\n // coordinate), so the default wallet's PoP witnesses verify against it.\n publicKeyHex:\n \"79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798\",\n address: \"tb1pqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqkx6jks\",\n network: BitcoinNetworks.SIGNET,\n shouldFailSigning: false,\n privateKeyHex: DEFAULT_PRIVATE_KEY_HEX,\n deriveContextHash: defaultDeriveContextHash,\n};\n\n/** Mock Bitcoin wallet for testing. */\nexport class MockBitcoinWallet implements BitcoinWallet {\n private config: Required<MockBitcoinWalletConfig>;\n\n constructor(config: MockBitcoinWalletConfig = {}) {\n this.config = {\n ...DEFAULT_CONFIG,\n ...(config.publicKeyHex ? { publicKeyHex: config.publicKeyHex } : {}),\n ...(config.address ? { address: config.address } : {}),\n ...(config.network !== undefined ? { network: config.network } : {}),\n ...(config.shouldFailSigning !== undefined\n ? { shouldFailSigning: config.shouldFailSigning }\n : {}),\n ...(config.privateKeyHex ? { privateKeyHex: config.privateKeyHex } : {}),\n ...(config.deriveContextHash\n ? { deriveContextHash: config.deriveContextHash }\n : {}),\n };\n // A private-key override without a public key would otherwise sign\n // against the DEFAULT pubkey — derive the matching one instead.\n if (config.privateKeyHex && !config.publicKeyHex) {\n this.config.publicKeyHex = xOnlyPubkeyHexOf(config.privateKeyHex);\n }\n }\n\n async getPublicKeyHex(): Promise<string> {\n return this.config.publicKeyHex;\n }\n\n async getAddress(): Promise<string> {\n return this.config.address;\n }\n\n async signPsbt(psbtHex: string, _options?: SignPsbtOptions): Promise<string> {\n if (this.config.shouldFailSigning) {\n throw new Error(\"Mock signing failed\");\n }\n\n if (!psbtHex || psbtHex.length === 0) {\n throw new Error(\"Invalid PSBT: empty hex string\");\n }\n\n // In a real implementation, this would actually sign the PSBT\n // For the mock, we just return the input with a mock signature appended\n return psbtHex + \"deadbeef\";\n }\n\n async signPsbts(\n psbtsHexes: string[],\n _options?: SignPsbtOptions[],\n ): Promise<string[]> {\n const signedPsbts: string[] = [];\n for (const psbtHex of psbtsHexes) {\n const signedPsbt = await this.signPsbt(psbtHex);\n signedPsbts.push(signedPsbt);\n }\n return signedPsbts;\n }\n\n async signMessage(\n message: string,\n _type: \"bip322-simple\" | \"ecdsa\",\n ): Promise<string> {\n if (this.config.shouldFailSigning) {\n throw new Error(\"Mock signing failed\");\n }\n\n if (!message || message.length === 0) {\n throw new Error(\"Invalid message: empty string\");\n }\n\n // PoP flows verify the witness against `publicKeyHex`, so a divergent\n // key pair must fail loudly here, not as a confusing verify mismatch.\n const signingXOnlyHex = xOnlyPubkeyHexOf(this.config.privateKeyHex);\n let configuredXOnlyHex: string | undefined;\n try {\n configuredXOnlyHex = canonicalizeBtcPubkey(this.config.publicKeyHex);\n } catch {\n configuredXOnlyHex = undefined; // an unparseable key cannot match\n }\n if (configuredXOnlyHex !== signingXOnlyHex) {\n throw new Error(\n `MockBitcoinWallet.signMessage: privateKeyHex signs as x-only pubkey ` +\n `${signingXOnlyHex}, but publicKeyHex is ${this.config.publicKeyHex}. ` +\n `Pass a matching publicKeyHex/privateKeyHex pair.`,\n );\n }\n\n // The SDK cryptographically verifies what a wallet returns\n // (`verifyPopWitness`), so the mock signs a REAL BIP-322 P2WPKH witness\n // with its private key. The type is not consulted: PoP flows only ever\n // request \"bip322-simple\", and the interface tests assert shape only.\n const witness = signBip322P2wpkhWitness(\n new TextEncoder().encode(message),\n Uint8Array.from(Buffer.from(this.config.privateKeyHex, \"hex\")),\n );\n return `0x${uint8ArrayToHex(witness)}`;\n }\n\n async getNetwork(): Promise<BitcoinNetwork> {\n return this.config.network;\n }\n\n async deriveContextHash(appName: string, context: string): Promise<string> {\n return this.config.deriveContextHash(appName, context);\n }\n\n /** Updates configuration for testing different scenarios. */\n updateConfig(updates: Partial<MockBitcoinWalletConfig>): void {\n this.config = {\n ...this.config,\n ...updates,\n };\n }\n\n /** Resets to default configuration. */\n reset(): void {\n this.config = { ...DEFAULT_CONFIG };\n }\n}\n","import { Buffer } from \"buffer\";\nimport type { Address, Hex } from \"viem\";\n\n/**\n * Configuration for MockEthereumWallet.\n */\nexport interface MockEthereumWalletConfig {\n address?: Address;\n chainId?: number;\n shouldFailOperations?: boolean;\n transactionDelay?: number;\n}\n\n/**\n * Mock Ethereum wallet for testing.\n *\n * Provides the subset of viem's WalletClient methods used by the SDK.\n * Can be passed to functions expecting a WalletClient for testing purposes.\n */\nexport class MockEthereumWallet {\n // Public properties matching viem's WalletClient structure\n account: { address: Address };\n chain: { id: number };\n\n private shouldFailOperations: boolean;\n private transactionDelay: number;\n private nonce: number = 0;\n\n constructor(config: MockEthereumWalletConfig = {}) {\n // Use lowercase addresses to avoid EIP-55 checksum validation issues\n this.account = {\n address:\n config.address ||\n (\"0x742d35cc6634c0532925a3b844bc9e7595f0beb0\" as Address),\n };\n\n this.chain = {\n id: config.chainId ?? 11155111, // Sepolia by default\n };\n\n this.shouldFailOperations = config.shouldFailOperations ?? false;\n this.transactionDelay = config.transactionDelay ?? 0;\n\n // Bind methods to preserve 'this' context when called\n this.signMessage = this.signMessage.bind(this);\n this.sendTransaction = this.sendTransaction.bind(this);\n }\n\n async signMessage(args: { message: string; account?: Address }): Promise<Hex> {\n const message = args.message;\n const account = args.account || this.account.address;\n\n if (this.shouldFailOperations) {\n throw new Error(\"Mock signing failed\");\n }\n\n if (!message || message.length === 0) {\n throw new Error(\"Invalid message: empty string\");\n }\n\n // Generate a deterministic mock signature\n const signatureData = `personal_sign:${message}-${account}-${this.chain.id}`;\n const signature = `0x${Buffer.from(signatureData)\n .toString(\"hex\")\n .slice(0, 130)\n .padEnd(130, \"0\")}` as Hex;\n return signature;\n }\n\n async sendTransaction(tx: {\n to: Address;\n data?: Hex;\n value?: bigint;\n gas?: bigint;\n account?: { address: Address };\n chain?: { id: number };\n }): Promise<Hex> {\n if (this.shouldFailOperations) {\n throw new Error(\"Mock transaction failed\");\n }\n\n if (!tx.to) {\n throw new Error(\"Invalid transaction: missing 'to' address\");\n }\n\n // Simulate network delay if configured\n if (this.transactionDelay > 0) {\n await new Promise((resolve) =>\n setTimeout(resolve, this.transactionDelay),\n );\n }\n\n // Generate a deterministic mock transaction hash\n this.nonce++;\n const txData = JSON.stringify({\n from: this.account.address,\n to: tx.to,\n value: tx.value?.toString() || \"0\",\n nonce: this.nonce,\n chainId: this.chain.id,\n });\n\n const hash = `0x${Buffer.from(txData)\n .toString(\"hex\")\n .slice(0, 64)\n .padEnd(64, \"0\")}` as Hex;\n return hash;\n }\n\n /** Updates configuration for testing different scenarios. */\n updateConfig(updates: Partial<MockEthereumWalletConfig>): void {\n if (updates.address !== undefined) {\n this.account.address = updates.address;\n }\n if (updates.chainId !== undefined) {\n this.chain.id = updates.chainId;\n }\n if (updates.shouldFailOperations !== undefined) {\n this.shouldFailOperations = updates.shouldFailOperations;\n }\n if (updates.transactionDelay !== undefined) {\n this.transactionDelay = updates.transactionDelay;\n }\n }\n\n /** Resets to default configuration and nonce. */\n reset(): void {\n this.account.address =\n \"0x742d35cc6634c0532925a3b844bc9e7595f0beb0\" as Address;\n this.chain.id = 11155111;\n this.shouldFailOperations = false;\n this.transactionDelay = 0;\n this.nonce = 0;\n }\n\n /** Returns current nonce for testing. */\n getCurrentNonce(): number {\n return this.nonce;\n }\n}\n"],"names":["BIP322_TAG","SIGHASH_ALL","ZERO_SATS","MIN_ENCODED_SIG_BYTES","MAX_SIGN_GRIND_ATTEMPTS","BIP322_TX_VERSION","BIP322_TX_LOCKTIME","BIP322_INPUT_SEQUENCE","TO_SPEND_PREVOUT_TXID_BYTES","TO_SPEND_PREVOUT_INDEX","TO_SPEND_OUTPUT_INDEX","OP_0","OP_PUSHBYTES_32","OP_RETURN","P2WPKH_WITNESS_ITEMS","GRIND_ENTROPY_BYTES","GRIND_COUNTER_OFFSET","signBip322P2wpkhWitness","messageBytes","privateKey","pubkey","ecc","tagHash","sha256","messageHash","Buffer","p2wpkh","payments","toSpend","Transaction","toSign","scriptCode","sighash","encodedSignature","attempt","entropy","candidate","bscript","defaultDeriveContextHash","appName","context","enc","nameBytes","ctxBytes","buf","view","uint8ArrayToHex","DEFAULT_PRIVATE_KEY_HEX","xOnlyPubkeyHexOf","privateKeyHex","DEFAULT_CONFIG","BitcoinNetworks","MockBitcoinWallet","config","__publicField","psbtHex","_options","psbtsHexes","signedPsbts","signedPsbt","message","_type","signingXOnlyHex","configuredXOnlyHex","canonicalizeBtcPubkey","witness","updates","MockEthereumWallet","args","account","signatureData","tx","resolve","txData","_a"],"mappings":";;;;;;;;;AAoBA,MAAMA,IAAa,0BACbC,IAAc,GACdC,IAAY,GAOZC,IAAwB,IACxBC,IAA0B,KAI1BC,IAAoB,GACpBC,IAAqB,GACrBC,IAAwB,GAExBC,IAA8B,IAC9BC,IAAyB,YAEzBC,IAAwB,GACxBC,IAAO,GAEPC,IAAkB,IAClBC,IAAY,KAEZC,IAAuB,GAEvBC,IAAsB,IACtBC,IAAuB;AAOtB,SAASC,EACdC,GACAC,GACY;AACZ,QAAMC,IAASC,EAAI,gBAAgBF,GAAY,EAAI;AACnD,MAAI,CAACC;AACH,UAAM,IAAI,MAAM,8CAA8C;AAIhE,QAAME,IAAUC,EAAO,IAAI,cAAc,OAAOvB,CAAU,CAAC,GACrDwB,IAAcD;AAA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UA,EAAQ,UAE7BA,EAAQ,YAAY,WACtB,KAAK,MAAM,KAAKA,EAAQ,UAEtBA,EAAQ,yBAAyB,WACnC,KAAK,uBAAuBA,EAAQ,uBAElCA,EAAQ,qBAAqB,WAC/B,KAAK,mBAAmBA,EAAQ;AAAA,EAEpC;AAAA;AAAA,EAGA,QAAc;AACZ,SAAK,QAAQ,UACX,8CACF,KAAK,MAAM,KAAK,UAChB,KAAK,uBAAuB,IAC5B,KAAK,mBAAmB,GACxB,KAAK,QAAQ;AAAA,EACf;AAAA;AAAA,EAGA,kBAA0B;AACxB,WAAO,KAAK;AAAA,EACd;AACF;"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Test-support BIP-322 "simple" P2WPKH signer.
3
+ *
4
+ * Produces the consensus-encoded two-item witness `[DER sig ‖ 0x01,
5
+ * compressed pubkey]` that a Native SegWit software wallet returns for
6
+ * `signMessage(..., "bip322-simple")`. The virtual to_spend/to_sign
7
+ * construction follows the `bip322` crate 0.0.10 (`util.rs:18-85`) — the
8
+ * same reference the production verifier
9
+ * (`tbv/core/clients/vault-provider/auth/bip322Verify.ts`) mirrors, and
10
+ * the BIP-322 official vectors pin.
11
+ *
12
+ * Test-only: never feed real key material to this module.
13
+ */
14
+ /**
15
+ * Sign `messageBytes` as a BIP-322 "simple" P2WPKH proof with `privateKey`
16
+ * and return the consensus-encoded two-item witness
17
+ * (`0x02 ‖ len ‖ sig ‖ 0x21 ‖ pubkey`).
18
+ */
19
+ export declare function signBip322P2wpkhWitness(messageBytes: Uint8Array, privateKey: Uint8Array): Uint8Array;
20
+ //# sourceMappingURL=signBip322P2wpkhWitness.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signBip322P2wpkhWitness.d.ts","sourceRoot":"","sources":["../../src/testing/signBip322P2wpkhWitness.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAwCH;;;;GAIG;AACH,wBAAgB,uBAAuB,CACrC,YAAY,EAAE,UAAU,EACxB,UAAU,EAAE,UAAU,GACrB,UAAU,CAiFZ"}
@@ -2,13 +2,13 @@ var J = Object.defineProperty;
2
2
  var X = (e, t, r) => t in e ? J(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
3
3
  var I = (e, t, r) => X(e, typeof t != "symbol" ? t + "" : t, r);
4
4
  import { s as G } from "./sha2-BYVxyZzX.js";
5
- import { a as F } from "./signPsbtsWithFallback-Bb66DfY5.js";
6
- import { b as Y, g as Z } from "./PeginManager-BBl4xkWz.js";
7
- import { s as P, h as ee, p as z, u as te, e as re } from "./bitcoin-d9eaaZB_.js";
5
+ import { a as F } from "./signPsbtsWithFallback-Bv79gLFe.js";
6
+ import { b as Y, g as Z } from "./PeginManager--2R3T2S8.js";
7
+ import { s as P, h as ee, p as z, u as te, e as re } from "./bitcoin-Ch_jxnDa.js";
8
8
  import { computeMinClaimValue as N, computeMinPeginFee as D, peginP2aAnchorOutput as U, getPrePeginHtlcConnectorInfo as ne, expandAuthAnchor as oe } from "@babylonlabs-io/babylon-tbv-rust-wasm";
9
- import { p as se, d as ae } from "./parseFundingOutpoints-pBRE11Hr.js";
9
+ import { p as se, d as ae } from "./parseFundingOutpoints-CO-f6IHK.js";
10
10
  import { Transaction as j } from "bitcoinjs-lib";
11
- import { h as ie, H as K } from "./verifyScriptPathSchnorrSignature-i-koT139.js";
11
+ import { i as ie, H as K } from "./verifyScriptPathSchnorrSignature-Dy9gF5RF.js";
12
12
  import { c as O } from "./fundPeginTransaction-B2wyjqp0.js";
13
13
  import { f as L } from "./waitForTransactionReceiptSmartAware-lobLm0q0.js";
14
14
  const W = "DepositTermsRejectedError";
@@ -453,4 +453,4 @@ export {
453
453
  ue as r,
454
454
  Me as t
455
455
  };
456
- //# sourceMappingURL=toRefundInputs-BY_fcvrv.js.map
456
+ //# sourceMappingURL=toRefundInputs-9hv_6k0E.js.map