@babylonlabs-io/ts-sdk 0.71.0 → 0.71.1

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 (94) hide show
  1. package/dist/PeginManager-Bn8FxM35.cjs +2 -0
  2. package/dist/{PeginManager-BIKAnZ-X.cjs.map → PeginManager-Bn8FxM35.cjs.map} +1 -1
  3. package/dist/{PeginManager-Byvmccdd.js → PeginManager-C3ojNTlv.js} +6 -6
  4. package/dist/{PeginManager-Byvmccdd.js.map → PeginManager-C3ojNTlv.js.map} +1 -1
  5. package/dist/{buildAndBroadcastReclaim-C0TdwO2M.js → buildAndBroadcastReclaim-YvWDRAN8.js} +492 -489
  6. package/dist/{buildAndBroadcastReclaim-C0TdwO2M.js.map → buildAndBroadcastReclaim-YvWDRAN8.js.map} +1 -1
  7. package/dist/buildAndBroadcastReclaim-zfjDI5__.cjs +2 -0
  8. package/dist/{buildAndBroadcastReclaim-kRx7-o2y.cjs.map → buildAndBroadcastReclaim-zfjDI5__.cjs.map} +1 -1
  9. package/dist/index.cjs +1 -1
  10. package/dist/index.js +227 -226
  11. package/dist/{mempoolApi-CRNMOsbC.js → mempoolApi-CKD_IbrM.js} +32 -33
  12. package/dist/mempoolApi-CKD_IbrM.js.map +1 -0
  13. package/dist/mempoolApi-DronQ5xn.cjs +2 -0
  14. package/dist/mempoolApi-DronQ5xn.cjs.map +1 -0
  15. package/dist/noPayout-DpGRzidi.js +353 -0
  16. package/dist/noPayout-DpGRzidi.js.map +1 -0
  17. package/dist/noPayout-zEifyecV.cjs +2 -0
  18. package/dist/noPayout-zEifyecV.cjs.map +1 -0
  19. package/dist/{primeVpAuth-tEXx9TGx.cjs → primeVpAuth-Cjq6qFHq.cjs} +2 -2
  20. package/dist/primeVpAuth-Cjq6qFHq.cjs.map +1 -0
  21. package/dist/{primeVpAuth-D1qbOkhb.js → primeVpAuth-tLRjdHwZ.js} +2 -2
  22. package/dist/primeVpAuth-tLRjdHwZ.js.map +1 -0
  23. package/dist/{signPsbtsWithFallback-BjXdnI0X.js → signPsbtsWithFallback-CCFTzE0o.js} +3 -3
  24. package/dist/{signPsbtsWithFallback-BjXdnI0X.js.map → signPsbtsWithFallback-CCFTzE0o.js.map} +1 -1
  25. package/dist/{signPsbtsWithFallback-zOQWokmk.cjs → signPsbtsWithFallback-CrkvpSJz.cjs} +2 -2
  26. package/dist/{signPsbtsWithFallback-zOQWokmk.cjs.map → signPsbtsWithFallback-CrkvpSJz.cjs.map} +1 -1
  27. package/dist/signing-BJ3X66b-.cjs +2 -0
  28. package/dist/signing-BJ3X66b-.cjs.map +1 -0
  29. package/dist/signing-Cm-McVR2.js +22 -0
  30. package/dist/signing-Cm-McVR2.js.map +1 -0
  31. package/dist/tbv/core/clients/eth/types.d.ts +0 -2
  32. package/dist/tbv/core/clients/eth/types.d.ts.map +1 -1
  33. package/dist/tbv/core/clients/eth/vault-registry-reader.d.ts.map +1 -1
  34. package/dist/tbv/core/clients/index.cjs +1 -1
  35. package/dist/tbv/core/clients/index.js +2 -2
  36. package/dist/tbv/core/clients/mempool/mempoolApi.d.ts +9 -1
  37. package/dist/tbv/core/clients/mempool/mempoolApi.d.ts.map +1 -1
  38. package/dist/tbv/core/index.cjs +1 -1
  39. package/dist/tbv/core/index.js +222 -221
  40. package/dist/tbv/core/managers/index.cjs +1 -1
  41. package/dist/tbv/core/managers/index.js +2 -2
  42. package/dist/tbv/core/primitives/index.cjs +1 -1
  43. package/dist/tbv/core/primitives/index.d.ts +2 -0
  44. package/dist/tbv/core/primitives/index.d.ts.map +1 -1
  45. package/dist/tbv/core/primitives/index.js +23 -22
  46. package/dist/tbv/core/primitives/psbt/__tests__/finalizeScriptPathWithSignatures.test.d.ts +11 -0
  47. package/dist/tbv/core/primitives/psbt/__tests__/finalizeScriptPathWithSignatures.test.d.ts.map +1 -0
  48. package/dist/tbv/core/primitives/psbt/finalizeScriptPathWithSignatures.d.ts +52 -0
  49. package/dist/tbv/core/primitives/psbt/finalizeScriptPathWithSignatures.d.ts.map +1 -0
  50. package/dist/tbv/core/primitives/psbt/reclaim.d.ts +23 -1
  51. package/dist/tbv/core/primitives/psbt/reclaim.d.ts.map +1 -1
  52. package/dist/tbv/core/services/index.cjs +1 -1
  53. package/dist/tbv/core/services/index.js +2 -2
  54. package/dist/tbv/core/services/reclaim/__tests__/buildAndBroadcastReclaim.walletPsbt.test.d.ts +14 -0
  55. package/dist/tbv/core/services/reclaim/__tests__/buildAndBroadcastReclaim.walletPsbt.test.d.ts.map +1 -0
  56. package/dist/tbv/core/services/reclaim/buildAndBroadcastReclaim.d.ts +14 -2
  57. package/dist/tbv/core/services/reclaim/buildAndBroadcastReclaim.d.ts.map +1 -1
  58. package/dist/tbv/core/services/refund/buildAndBroadcastRefund.d.ts.map +1 -1
  59. package/dist/tbv/core/utils/index.cjs +1 -1
  60. package/dist/tbv/core/utils/index.js +13 -13
  61. package/dist/tbv/index.cjs +1 -1
  62. package/dist/tbv/index.js +222 -221
  63. package/dist/toRefundInputs-CY9u84U9.cjs +2 -0
  64. package/dist/{toRefundInputs-Bdtz8p27.cjs.map → toRefundInputs-CY9u84U9.cjs.map} +1 -1
  65. package/dist/{toRefundInputs-CgXMcHrk.js → toRefundInputs-Df1vi23S.js} +5 -5
  66. package/dist/{toRefundInputs-CgXMcHrk.js.map → toRefundInputs-Df1vi23S.js.map} +1 -1
  67. package/dist/{verifyScriptPathSchnorrSignature-mzYCzaSy.cjs → verifyScriptPathSchnorrSignature-BfNUSgA7.cjs} +2 -2
  68. package/dist/{verifyScriptPathSchnorrSignature-mzYCzaSy.cjs.map → verifyScriptPathSchnorrSignature-BfNUSgA7.cjs.map} +1 -1
  69. package/dist/{verifyScriptPathSchnorrSignature-ZAZfFJ6S.js → verifyScriptPathSchnorrSignature-Ciq_xZhw.js} +5 -4
  70. package/dist/{verifyScriptPathSchnorrSignature-ZAZfFJ6S.js.map → verifyScriptPathSchnorrSignature-Ciq_xZhw.js.map} +1 -1
  71. package/dist/waitForTransactionReceiptSmartAware-DpQ69ySe.cjs +2 -0
  72. package/dist/waitForTransactionReceiptSmartAware-DpQ69ySe.cjs.map +1 -0
  73. package/dist/{waitForTransactionReceiptSmartAware-B6oYRdFO.js → waitForTransactionReceiptSmartAware-z3Xfmo44.js} +42 -47
  74. package/dist/waitForTransactionReceiptSmartAware-z3Xfmo44.js.map +1 -0
  75. package/package.json +1 -1
  76. package/dist/PeginManager-BIKAnZ-X.cjs +0 -2
  77. package/dist/buildAndBroadcastReclaim-kRx7-o2y.cjs +0 -2
  78. package/dist/mempoolApi-BQllf-ji.cjs +0 -2
  79. package/dist/mempoolApi-BQllf-ji.cjs.map +0 -1
  80. package/dist/mempoolApi-CRNMOsbC.js.map +0 -1
  81. package/dist/noPayout--lxo7qe4.js +0 -300
  82. package/dist/noPayout--lxo7qe4.js.map +0 -1
  83. package/dist/noPayout-CegnEwfp.cjs +0 -2
  84. package/dist/noPayout-CegnEwfp.cjs.map +0 -1
  85. package/dist/primeVpAuth-D1qbOkhb.js.map +0 -1
  86. package/dist/primeVpAuth-tEXx9TGx.cjs.map +0 -1
  87. package/dist/signing-Bnsro0hE.cjs +0 -2
  88. package/dist/signing-Bnsro0hE.cjs.map +0 -1
  89. package/dist/signing-DaLvGwQe.js +0 -16
  90. package/dist/signing-DaLvGwQe.js.map +0 -1
  91. package/dist/toRefundInputs-Bdtz8p27.cjs +0 -2
  92. package/dist/waitForTransactionReceiptSmartAware-B6oYRdFO.js.map +0 -1
  93. package/dist/waitForTransactionReceiptSmartAware-Ct7LPwPI.cjs +0 -2
  94. package/dist/waitForTransactionReceiptSmartAware-Ct7LPwPI.cjs.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"file":"waitForTransactionReceiptSmartAware-Ct7LPwPI.cjs","sources":["../src/tbv/core/utils/fee/peginFeeMath.ts","../src/tbv/core/utils/utxo/selectUtxos.ts","../src/tbv/core/utils/transaction/btcTxHash.ts","../src/tbv/core/utils/btc/scriptType.ts","../src/tbv/core/utils/btc/psbtInputFields.ts","../src/tbv/core/utils/eth/waitForTransactionReceiptSmartAware.ts"],"sourcesContent":["/**\n * Pre-PegIn fee math primitives used by both UTXO selection and\n * transaction funding so they make bit-identical decisions about base\n * fee, change-output fee, and whether to emit change at all.\n *\n * Dust handling matches the wallet-side check in\n * `babylon-vault crates/btc-wallet-remote/src/client.rs` (dust-change\n * rejection): a change output is emitted only when the post-fee residual\n * exceeds DUST_THRESHOLD (546 sats). Broader fee-estimation behaviors\n * (output sizing, safety margins) are NOT cross-stack guarantees — see\n * JS-vs-Rust parity fixtures in `__tests__/peginFeeMath.test.ts` for the\n * invariants we pin.\n */\n\nimport {\n DUST_THRESHOLD,\n MAX_NON_LEGACY_OUTPUT_SIZE,\n P2TR_INPUT_SIZE,\n rateBasedTxBufferFee,\n TX_BUFFER_SIZE_OVERHEAD,\n} from \"./constants\";\n\nexport interface ComputeBaseFeeParams {\n numInputs: number;\n /**\n * Number of outputs in the unfunded transaction (HTLC vault outputs +\n * CPFP anchor + optional auth-anchor OP_RETURN). Excludes the change\n * output — `applyChangeOutputPolicy` adds the change-output fee\n * separately.\n */\n numOutputs: number;\n feeRate: number;\n}\n\n/**\n * Compute the base fee (sats) for a Pre-PegIn transaction with no change\n * output, including the low-fee-rate buffer.\n *\n * Used as the starting point by `applyChangeOutputPolicy`, which then\n * decides whether to add the incremental change-output fee.\n */\nexport function computePeginBaseFeeSats(\n params: ComputeBaseFeeParams,\n): bigint {\n const { numInputs, numOutputs, feeRate } = params;\n if (!Number.isInteger(numInputs) || numInputs < 0) {\n throw new Error(\n `computePeginBaseFeeSats: numInputs must be a non-negative integer, got ${numInputs}`,\n );\n }\n if (!Number.isInteger(numOutputs) || numOutputs < 1) {\n throw new Error(\n `computePeginBaseFeeSats: numOutputs must be a positive integer, got ${numOutputs}`,\n );\n }\n const txVsize =\n numInputs * P2TR_INPUT_SIZE +\n numOutputs * MAX_NON_LEGACY_OUTPUT_SIZE +\n TX_BUFFER_SIZE_OVERHEAD;\n return (\n BigInt(Math.ceil(txVsize * feeRate)) +\n BigInt(rateBasedTxBufferFee(feeRate))\n );\n}\n\n/**\n * Incremental fee (sats) for adding one P2TR-sized change output at the\n * given fee rate. Does NOT include the low-fee-rate buffer — that is part\n * of the base fee, paid once per transaction.\n */\nexport function computeChangeOutputFeeSats(feeRate: number): bigint {\n return BigInt(Math.ceil(MAX_NON_LEGACY_OUTPUT_SIZE * feeRate));\n}\n\nexport interface ApplyChangeOutputPolicyParams {\n totalInputValue: bigint;\n peginAmount: bigint;\n baseFee: bigint;\n changeOutputFee: bigint;\n}\n\nexport interface ChangeOutputPolicyResult {\n /** Final transaction fee (sats). */\n fee: bigint;\n /**\n * Final change amount (sats). 0n when no change output is emitted.\n * When `emitChangeOutput` is false, the would-be change is paid to\n * miners as part of `fee` — i.e. it is dust by policy.\n */\n changeAmount: bigint;\n /** Whether the funded transaction must include a change output. */\n emitChangeOutput: boolean;\n}\n\n/**\n * Apply the change-output dust policy: emit a change output iff the\n * post-change-output-fee residual strictly exceeds DUST_THRESHOLD.\n *\n * Returns `{ fee, changeAmount, emitChangeOutput }` so the selector and\n * funder both end up with the same fee and same change decision for the\n * same inputs.\n *\n * Inputs:\n * - `totalInputValue`: sum of selected UTXO values\n * - `peginAmount`: amount being pegged in\n * - `baseFee`: fee assuming no change output (from `computePeginBaseFeeSats`)\n * - `changeOutputFee`: incremental fee for adding one change output\n * (from `computeChangeOutputFeeSats`)\n *\n * @throws If `totalInputValue < peginAmount + baseFee` (insufficient funds\n * even before considering change). Callers that need to surface\n * \"insufficient funds\" with their own error wording should check the\n * precondition themselves before invoking this.\n */\nexport function applyChangeOutputPolicy(\n params: ApplyChangeOutputPolicyParams,\n): ChangeOutputPolicyResult {\n const { totalInputValue, peginAmount, baseFee, changeOutputFee } = params;\n\n const residualBeforeChange = totalInputValue - peginAmount - baseFee;\n if (residualBeforeChange < 0n) {\n throw new Error(\n `applyChangeOutputPolicy: insufficient funds (need ${peginAmount + baseFee} sats, have ${totalInputValue})`,\n );\n }\n\n const residualWithChangeOutput = residualBeforeChange - changeOutputFee;\n if (residualWithChangeOutput > DUST_THRESHOLD) {\n return {\n fee: baseFee + changeOutputFee,\n changeAmount: residualWithChangeOutput,\n emitChangeOutput: true,\n };\n }\n\n // Dust-revert: the would-be change is below (or equal to) the dust\n // threshold once the change-output fee is paid, so we omit the change\n // output and let the residual go to miners. The reported `fee` is the\n // ACTUAL on-wire fee — `baseFee + residualBeforeChange` — not just\n // `baseFee`, otherwise fee displays would under-report by up to\n // (changeOutputFee + DUST_THRESHOLD) sats whenever dust gets absorbed.\n return {\n fee: baseFee + residualBeforeChange,\n changeAmount: 0n,\n emitChangeOutput: false,\n };\n}\n\nexport interface ComputeMaxDepositParams {\n numInputs: number;\n /**\n * Number of outputs in the unfunded transaction. Use the worst-case\n * count for the use case being budgeted (e.g. max-batch with\n * auth-anchor) — `computeMaxDeposit` is intentionally an UPPER BOUND\n * and assumes no change output.\n */\n numOutputs: number;\n totalBalance: bigint;\n feeRate: number;\n}\n\n/**\n * Compute the maximum depositable amount (sats) given a fixed-cost\n * sweep: every UTXO is spent, no change output is emitted, fee is the\n * base fee for the requested input/output count.\n *\n * Returns null when `totalBalance <= 0n`. Returns 0n if the base fee\n * alone exceeds the balance.\n */\nexport function computeMaxDeposit(\n params: ComputeMaxDepositParams,\n): bigint | null {\n const { numInputs, numOutputs, totalBalance, feeRate } = params;\n if (totalBalance <= 0n) return null;\n const fee = computePeginBaseFeeSats({ numInputs, numOutputs, feeRate });\n const max = totalBalance - fee;\n return max > 0n ? max : 0n;\n}\n","/**\n * UTXO selection utilities for peg-in transactions.\n * Follows btc-staking-ts methodology with iterative fee calculation.\n */\n\nimport { script as bitcoinScript } from \"bitcoinjs-lib\";\nimport { Buffer } from \"buffer\";\n\nimport { BTC_DUST_SAT, DUST_THRESHOLD } from \"../fee/constants\";\nimport {\n applyChangeOutputPolicy,\n computeChangeOutputFeeSats,\n computePeginBaseFeeSats,\n} from \"../fee/peginFeeMath\";\n\n/**\n * Unspent Transaction Output (UTXO) for funding peg-in transactions.\n */\nexport interface UTXO {\n /**\n * Transaction ID of the UTXO (64-char hex without 0x prefix).\n */\n txid: string;\n\n /**\n * Output index within the transaction.\n */\n vout: number;\n\n /**\n * Value in satoshis.\n */\n value: number;\n\n /**\n * Script public key hex.\n */\n scriptPubKey: string;\n}\n\nexport interface UTXOSelectionResult {\n selectedUTXOs: UTXO[];\n totalValue: bigint;\n fee: bigint;\n changeAmount: bigint;\n}\n\n/**\n * Assert that no two UTXOs share the same txid:vout outpoint.\n * Duplicates from a buggy or compromised UTXO source would produce\n * an invalid Bitcoin transaction that double-spends the same outpoint.\n */\nfunction assertNoDuplicateUtxos(utxos: UTXO[]): void {\n const seen = new Set<string>();\n for (const utxo of utxos) {\n const key = `${utxo.txid.toLowerCase()}:${utxo.vout}`;\n if (seen.has(key)) {\n throw new Error(\n `Duplicate UTXO detected: ${utxo.txid}:${utxo.vout}. ` +\n `This indicates a data integrity issue with the UTXO source.`,\n );\n }\n seen.add(key);\n }\n}\n\n/**\n * Selects UTXOs to fund a peg-in transaction with iterative fee calculation.\n *\n * This function implements the btc-staking-ts approach:\n * 1. Filter UTXOs for script validity (no minimum value filter)\n * 2. Sort by value (largest first) to minimize number of inputs\n * 3. Iteratively add UTXOs and recalculate fee until we have enough\n *\n * The fee recalculation is critical because:\n * - Each UTXO added increases transaction size → increases fee\n * - More fee needed might require another UTXO\n * - Change output detection affects fee (adds output size if needed)\n *\n * @param availableUTXOs - All available UTXOs from wallet\n * @param peginAmount - Amount to peg in (satoshis)\n * @param feeRate - Fee rate (sat/vbyte)\n * @param numOutputs - Number of outputs in the unfunded transaction (HTLC + CPFP anchor, before change)\n * @returns Selected UTXOs, total value, calculated fee, and change amount\n * @throws Error if insufficient funds or no valid UTXOs\n */\nexport function selectUtxosForPegin(\n availableUTXOs: UTXO[],\n peginAmount: bigint,\n feeRate: number,\n numOutputs: number,\n): UTXOSelectionResult {\n if (!Number.isInteger(numOutputs) || numOutputs < 1) {\n throw new Error(\n `Invalid numOutputs: expected a positive integer, got ${numOutputs}`,\n );\n }\n\n if (availableUTXOs.length === 0) {\n throw new Error(\"Insufficient funds: no UTXOs available\");\n }\n\n assertNoDuplicateUtxos(availableUTXOs);\n\n // Filter for script validity ONLY (matching btc-staking-ts approach)\n // No minimum value filter - we accept any UTXO with valid script\n const validUTXOs = availableUTXOs.filter((utxo) => {\n const script = Buffer.from(utxo.scriptPubKey, \"hex\");\n const decompiledScript = bitcoinScript.decompile(script);\n return !!decompiledScript;\n });\n\n if (validUTXOs.length === 0) {\n throw new Error(\n \"Insufficient funds: no valid UTXOs available (all have invalid scripts)\",\n );\n }\n\n // Sort by value: HIGHEST to LOWEST (use big UTXOs first)\n // Use spread to avoid mutating the original array\n const sortedUTXOs = [...validUTXOs].sort((a, b) => b.value - a.value);\n\n const selectedUTXOs: UTXO[] = [];\n let accumulatedValue = 0n;\n let estimatedFee = 0n;\n\n // Iteratively select UTXOs, recalculating the fee through the shared\n // `applyChangeOutputPolicy` helper so the selector and the funder\n // agree on (fee, change output emission, change amount) for the same\n // inputs. Without that, the funder can omit a change output the\n // selector charged for — silent depositor overpayment at the dust\n // boundary.\n for (const utxo of sortedUTXOs) {\n selectedUTXOs.push(utxo);\n accumulatedValue += BigInt(utxo.value);\n\n const baseFee = computePeginBaseFeeSats({\n numInputs: selectedUTXOs.length,\n numOutputs,\n feeRate,\n });\n const changeOutputFee = computeChangeOutputFeeSats(feeRate);\n\n if (accumulatedValue < peginAmount + baseFee) {\n estimatedFee = baseFee;\n continue;\n }\n\n const policy = applyChangeOutputPolicy({\n totalInputValue: accumulatedValue,\n peginAmount,\n baseFee,\n changeOutputFee,\n });\n\n return {\n selectedUTXOs,\n totalValue: accumulatedValue,\n fee: policy.fee,\n changeAmount: policy.changeAmount,\n };\n }\n\n // If we get here, we don't have enough funds\n throw new Error(\n `Insufficient funds: need ${peginAmount + estimatedFee} sats (${peginAmount} pegin + ${estimatedFee} fee), have ${accumulatedValue} sats`,\n );\n}\n\n/**\n * Checks if change amount is above dust threshold.\n *\n * @param changeAmount - Change amount in satoshis\n * @returns true if change should be added as output, false if it should go to miners\n */\nexport function shouldAddChangeOutput(changeAmount: bigint): boolean {\n return changeAmount > DUST_THRESHOLD;\n}\n\n/**\n * Gets the dust threshold value.\n *\n * @returns Dust threshold in satoshis\n */\nexport function getDustThreshold(): number {\n return BTC_DUST_SAT;\n}\n","/**\n * Bitcoin Transaction Hash Utilities\n *\n * Provides utilities for calculating Bitcoin transaction hashes in a way that matches\n * the contract's BtcUtils.hashBtcTx() implementation.\n */\n\nimport { Transaction } from \"bitcoinjs-lib\";\nimport type { Hex } from \"viem\";\n\n/**\n * Calculate Bitcoin transaction hash\n *\n * This matches the contract's BtcUtils.hashBtcTx() implementation:\n * 1. Double SHA256 the transaction bytes\n * 2. Reverse the byte order (Bitcoin convention)\n *\n * The resulting hash is used as the unique vault identifier in the BTCVaultRegistry contract.\n *\n * @param txHex - Transaction hex (with or without 0x prefix)\n * @returns The transaction hash as Hex (with 0x prefix)\n */\nexport function calculateBtcTxHash(txHex: string): Hex {\n // Remove 0x prefix if present\n const cleanHex = txHex.startsWith(\"0x\") ? txHex.slice(2) : txHex;\n\n // Use bitcoinjs-lib to calculate transaction ID (already does double SHA256 + reverse)\n const tx = Transaction.fromHex(cleanHex);\n const txid = tx.getId();\n\n // Return with 0x prefix to match Ethereum hex format\n return `0x${txid}` as Hex;\n}\n","/**\n * Bitcoin Script Type Detection\n *\n * Utilities to detect Bitcoin script types for proper PSBT input construction.\n *\n * @module utils/btc/scriptType\n */\n\n/**\n * Bitcoin script types.\n */\nexport enum BitcoinScriptType {\n P2PKH = \"P2PKH\",\n P2SH = \"P2SH\",\n P2WPKH = \"P2WPKH\",\n P2WSH = \"P2WSH\",\n P2TR = \"P2TR\",\n UNKNOWN = \"UNKNOWN\",\n}\n\n/**\n * Detect the type of a Bitcoin script.\n *\n * @param scriptPubKey - The script public key buffer\n * @returns The detected script type\n *\n * @example\n * ```typescript\n * const scriptType = getScriptType(Buffer.from(scriptPubKeyHex, 'hex'));\n * if (scriptType === BitcoinScriptType.P2TR) {\n * // Handle Taproot input\n * }\n * ```\n */\nexport function getScriptType(scriptPubKey: Buffer): BitcoinScriptType {\n const length = scriptPubKey.length;\n\n // P2PKH: OP_DUP OP_HASH160 <20 bytes> OP_EQUALVERIFY OP_CHECKSIG (25 bytes)\n if (\n length === 25 &&\n scriptPubKey[0] === 0x76 && // OP_DUP\n scriptPubKey[1] === 0xa9 && // OP_HASH160\n scriptPubKey[2] === 0x14 && // Push 20 bytes\n scriptPubKey[23] === 0x88 && // OP_EQUALVERIFY\n scriptPubKey[24] === 0xac // OP_CHECKSIG\n ) {\n return BitcoinScriptType.P2PKH;\n }\n\n // P2SH: OP_HASH160 <20 bytes> OP_EQUAL (23 bytes)\n if (\n length === 23 &&\n scriptPubKey[0] === 0xa9 && // OP_HASH160\n scriptPubKey[1] === 0x14 && // Push 20 bytes\n scriptPubKey[22] === 0x87 // OP_EQUAL\n ) {\n return BitcoinScriptType.P2SH;\n }\n\n // P2WPKH: OP_0 <20 bytes> (22 bytes)\n if (\n length === 22 &&\n scriptPubKey[0] === 0x00 && // OP_0\n scriptPubKey[1] === 0x14 // Push 20 bytes\n ) {\n return BitcoinScriptType.P2WPKH;\n }\n\n // P2WSH: OP_0 <32 bytes> (34 bytes)\n if (\n length === 34 &&\n scriptPubKey[0] === 0x00 && // OP_0\n scriptPubKey[1] === 0x20 // Push 32 bytes\n ) {\n return BitcoinScriptType.P2WSH;\n }\n\n // P2TR (Taproot): OP_1 <32 bytes> (34 bytes)\n if (\n length === 34 &&\n scriptPubKey[0] === 0x51 && // OP_1\n scriptPubKey[1] === 0x20 // Push 32 bytes\n ) {\n return BitcoinScriptType.P2TR;\n }\n\n return BitcoinScriptType.UNKNOWN;\n}\n\n","/**\n * PSBT Input Field Construction\n *\n * Constructs the correct PSBT input fields for a given UTXO based on its script type.\n *\n * @module utils/btc/psbtInputFields\n */\n\nimport { Buffer } from \"buffer\";\n\nimport { BitcoinScriptType, getScriptType } from \"./scriptType\";\n\n/**\n * PSBT input fields for supported script types (P2TR, P2WPKH, P2WSH).\n */\nexport interface PsbtInputFields {\n witnessUtxo?: {\n script: Buffer;\n value: number;\n };\n witnessScript?: Buffer;\n tapInternalKey?: Buffer;\n}\n\n/**\n * UTXO information for PSBT construction.\n *\n * Only supports Taproot (P2TR) and native SegWit (P2WPKH, P2WSH) script types.\n */\nexport interface UtxoForPsbt {\n /** Transaction ID of the UTXO */\n txid: string;\n /** Output index (vout) of the UTXO */\n vout: number;\n /** Value of the UTXO in satoshis */\n value: number;\n /** ScriptPubKey of the UTXO (hex string) */\n scriptPubKey: string;\n /** Witness script (required for P2WSH) */\n witnessScript?: string;\n}\n\n/**\n * Get PSBT input fields for a given UTXO based on its script type.\n *\n * Only supports Taproot (P2TR) and native SegWit (P2WPKH, P2WSH) script types.\n *\n * @param utxo - The unspent transaction output to process\n * @param publicKeyNoCoord - The x-only public key (32 bytes) for Taproot signing\n * @returns PSBT input fields object containing the necessary data\n * @throws Error if required input data is missing or unsupported script type\n */\nexport function getPsbtInputFields(\n utxo: UtxoForPsbt,\n publicKeyNoCoord?: Buffer,\n): PsbtInputFields {\n const scriptPubKey = Buffer.from(utxo.scriptPubKey, \"hex\");\n const type = getScriptType(scriptPubKey);\n\n switch (type) {\n case BitcoinScriptType.P2WPKH: {\n return {\n witnessUtxo: {\n script: scriptPubKey,\n value: utxo.value,\n },\n };\n }\n\n case BitcoinScriptType.P2WSH: {\n if (!utxo.witnessScript) {\n throw new Error(\"Missing witnessScript for P2WSH input\");\n }\n return {\n witnessUtxo: {\n script: scriptPubKey,\n value: utxo.value,\n },\n witnessScript: Buffer.from(utxo.witnessScript, \"hex\"),\n };\n }\n\n case BitcoinScriptType.P2TR: {\n if (publicKeyNoCoord && publicKeyNoCoord.length !== 32) {\n throw new Error(\n `Invalid tapInternalKey length: expected 32 bytes, got ${publicKeyNoCoord.length}`,\n );\n }\n return {\n witnessUtxo: {\n script: scriptPubKey,\n value: utxo.value,\n },\n // tapInternalKey is needed for Taproot signing\n ...(publicKeyNoCoord && { tapInternalKey: publicKeyNoCoord }),\n };\n }\n\n default:\n throw new Error(`Unsupported script type: ${type}`);\n }\n}\n\n","/**\n * Smart-account-aware wrapper around viem's `waitForTransactionReceipt`.\n *\n * Externally Owned Accounts (EOAs) — wallets controlled by a single private\n * key, e.g. MetaMask or a hardware wallet. `eth_sendTransaction` returns a real\n * Ethereum tx hash, which viem can poll directly. This wrapper delegates\n * unchanged for them.\n *\n * Smart-contract accounts (e.g. Safe multisigs) — the wallet address is a\n * deployed contract that decides whether to accept a transaction. WalletConnect's\n * `eth_sendTransaction` returns a `safeTxHash` (an EIP-712 hash of the\n * *proposal*) rather than a real tx hash, and the proposal is held in Safe's\n * off-chain Transaction Service until quorum signs and executes it. We poll\n * that service for the proposal until execution, then wait for receipt on the\n * real Ethereum tx hash exposed in the service's response.\n *\n * The two are told apart by `eth_getCode`, but NOT by \"empty vs non-empty\":\n * an EIP-7702 delegated EOA reports `0xef0100 ‖ <delegate address>` and is\n * still an EOA — it signs and submits its own transactions, so\n * `eth_sendTransaction` returns a real tx hash. MetaMask upgrades accounts to\n * smart accounts this way by default, and treating one as a Safe means polling\n * the Transaction Service for a hash that is not a `safeTxHash`: a permanent\n * 404 that reads as \"proposal not yet indexed\" and hangs for the full poll\n * budget on a transaction that already succeeded. Delegation designators are\n * therefore classified as EOAs. As a backstop for any wallet that behaves this\n * way in future, a 404 from the Transaction Service is also checked against the\n * node: if it knows the hash as a real transaction, we were never waiting on a\n * proposal and switch to waiting for that transaction's receipt.\n *\n * @module utils/eth\n */\n\nimport type { Address, Hash, PublicClient, TransactionReceipt } from \"viem\";\n\n/**\n * Chains where the Safe Transaction Service is supported by this utility.\n * Extend the map as more Safe-enabled chains are needed.\n */\nconst SAFE_TX_SERVICE_BASE_URLS: Record<number, string> = {\n 1: \"https://safe-transaction-mainnet.safe.global\",\n 11155111: \"https://safe-transaction-sepolia.safe.global\",\n};\n\nconst DEFAULT_SAFE_POLL_INTERVAL_MS = 5_000;\nconst DEFAULT_SAFE_POLL_TIMEOUT_MS = 4 * 60 * 60 * 1_000;\nconst SAFE_TX_SERVICE_FETCH_TIMEOUT_MS = 10_000;\n\n/** Safe Transaction Service route for one multisig-transaction proposal. */\nconst SAFE_MULTISIG_TX_PATH = \"/api/v1/multisig-transactions\";\n/** The service answers 404 both for an unindexed proposal and an unknown Safe. */\nconst SAFE_TX_SERVICE_NOT_FOUND = 404;\n/** Statuses at or above this are server-side, so worth retrying. */\nconst SAFE_TX_SERVICE_SERVER_ERROR = 500;\n\n/** Two hex characters encode one byte in an `eth_getCode` result. */\nconst HEX_CHARS_PER_BYTE = 2;\n\n/**\n * EIP-7702 delegation designator: an EOA that has delegated its code to a\n * contract reports exactly `0xef0100 ‖ <20-byte delegate address>` from\n * `eth_getCode` (EIP-7702 §\"Delegation Designation\"). Both the prefix and the\n * exact length are checked so ordinary contract bytecode that merely happens to\n * start with these bytes is not mistaken for a delegation.\n */\nconst EIP_7702_DELEGATION_PREFIX = \"0xef0100\";\nconst EIP_7702_DELEGATION_ADDRESS_BYTES = 20;\nconst EIP_7702_DELEGATION_CODE_LENGTH =\n EIP_7702_DELEGATION_PREFIX.length +\n HEX_CHARS_PER_BYTE * EIP_7702_DELEGATION_ADDRESS_BYTES;\n\n/**\n * True when `eth_getCode` reports an EIP-7702 delegation designator rather than\n * a deployed contract. Such an account is still an EOA for our purposes: it\n * signs and submits its own transactions, so the hash we hold is a real tx hash.\n */\nfunction isEip7702DelegatedEoa(code: string): boolean {\n return (\n code.length === EIP_7702_DELEGATION_CODE_LENGTH &&\n code.toLowerCase().startsWith(EIP_7702_DELEGATION_PREFIX)\n );\n}\n\nexport interface WaitForTransactionReceiptSmartAwareParams {\n publicClient: PublicClient;\n walletAddress: Address;\n hash: Hash;\n /**\n * Forwarded to viem verbatim.\n *\n * MUST NOT be used as a finality/reorg gate. viem fetches the receipt once\n * and then only compares block numbers against that cached copy — it never\n * re-checks that the receipt's block is still canonical, so it resolves\n * happily for a transaction that has been reorged out. Setting this buys a\n * delay, not a guarantee. For peg-in registration finality use\n * `waitForPeginRegistrationDepth`, which re-reads live contract state on\n * every poll.\n */\n confirmations?: number;\n /**\n * Forwarded to viem on the EOA (externally owned account) path, and on the\n * fallback where a supposed smart account turns out to submit its own\n * transactions — that is the EOA case too, however we arrived at it.\n *\n * Ignored only while waiting on a genuine Safe proposal, whose budget is\n * safePollTimeoutMs. It is not forwarded to the receipt wait that follows a\n * proposal's execution either: viem's own default applies there (180s as of\n * viem 2.38.2), so that wait is bounded too — a sufficiently slow node still\n * raises WaitForTransactionReceiptTimeoutError, just on viem's uniform bound\n * rather than on a caller's shorter one.\n */\n timeout?: number;\n /** Total budget for waiting on Safe quorum + execution. Default 4h. */\n safePollTimeoutMs?: number;\n /** Poll cadence against the Safe Transaction Service. Default 5s. */\n safePollIntervalMs?: number;\n}\n\nexport async function waitForTransactionReceiptSmartAware(\n params: WaitForTransactionReceiptSmartAwareParams,\n): Promise<TransactionReceipt> {\n const {\n publicClient,\n walletAddress,\n hash,\n confirmations,\n timeout,\n safePollTimeoutMs = DEFAULT_SAFE_POLL_TIMEOUT_MS,\n safePollIntervalMs = DEFAULT_SAFE_POLL_INTERVAL_MS,\n } = params;\n\n const code = await publicClient.getCode({ address: walletAddress });\n // An EIP-7702 delegated EOA has non-empty code but still submits its own\n // transactions, so it belongs on the EOA path — see the module docblock.\n const isSmartAccount =\n code !== undefined && code !== \"0x\" && !isEip7702DelegatedEoa(code);\n\n if (!isSmartAccount) {\n return publicClient.waitForTransactionReceipt({\n hash,\n confirmations,\n timeout,\n });\n }\n\n const chainId = await publicClient.getChainId();\n const outcome = await pollSafeTransactionServiceUntilExecuted({\n chainId,\n publicClient,\n safeTxHash: hash,\n pollIntervalMs: safePollIntervalMs,\n timeoutMs: safePollTimeoutMs,\n });\n\n // The wallet turned out to submit its own transactions, so this is the EOA\n // case after all — including the caller's `timeout`, which only ever meant to\n // be ignored while waiting on a genuine Safe proposal.\n if (outcome.kind === \"not-a-proposal\") {\n return publicClient.waitForTransactionReceipt({\n hash,\n confirmations,\n timeout,\n });\n }\n\n return publicClient.waitForTransactionReceipt({\n hash: outcome.transactionHash,\n confirmations,\n });\n}\n\n/**\n * How the Safe path ended. The two outcomes are not interchangeable, so they are\n * distinguished rather than both collapsing to a bare hash: `executed` is a real\n * Safe proposal that reached quorum, while `not-a-proposal` means the wallet was\n * never a Safe and we are really on the EOA path — which decides whether the\n * caller's `timeout` applies to the receipt wait that follows.\n */\ntype SafePollOutcome =\n | { kind: \"executed\"; transactionHash: Hash }\n | { kind: \"not-a-proposal\" };\n\ninterface SafeMultisigTransaction {\n isExecuted: boolean;\n isSuccessful: boolean | null;\n transactionHash: Hash | null;\n}\n\n/**\n * Decide whether a 404 from the Transaction Service means \"proposal not indexed\n * yet\" or \"this hash was never a proposal at all\".\n *\n * The Safe indexer cannot answer that: a genuine Safe and its freshly-submitted\n * proposal are both absent from it for a while, so its 404 proves nothing. The\n * NODE can. A `safeTxHash` is an EIP-712 digest of a proposal and is never a\n * transaction on chain, so if the node knows the hash as a real transaction then\n * this was never a proposal and we are on the wrong path entirely.\n *\n * Returns true only on that positive identification. Anything else — the node\n * has not seen it yet, or the lookup fails — is inconclusive and leaves the\n * caller polling, which is the correct behaviour for a Safe that is simply\n * still being indexed.\n */\nasync function hashIsRealTransaction(\n publicClient: PublicClient,\n hash: Hash,\n): Promise<boolean> {\n const transaction = await publicClient\n .getTransaction({ hash })\n .catch(() => null);\n return transaction !== null;\n}\n\nasync function pollSafeTransactionServiceUntilExecuted({\n chainId,\n publicClient,\n safeTxHash,\n pollIntervalMs,\n timeoutMs,\n}: {\n chainId: number;\n publicClient: PublicClient;\n safeTxHash: Hash;\n pollIntervalMs: number;\n timeoutMs: number;\n}): Promise<SafePollOutcome> {\n const baseUrl = SAFE_TX_SERVICE_BASE_URLS[chainId];\n if (!baseUrl) {\n throw new Error(\n `Safe Transaction Service not configured for chainId ${chainId}. ` +\n `Connected wallet appears to be a smart-contract account, but this ` +\n `chain is not in the supported list. Either connect an EOA or extend ` +\n `SAFE_TX_SERVICE_BASE_URLS in waitForTransactionReceiptSmartAware.ts.`,\n );\n }\n\n const url = `${baseUrl}${SAFE_MULTISIG_TX_PATH}/${safeTxHash}/`;\n const deadline = Date.now() + timeoutMs;\n\n while (Date.now() < deadline) {\n const controller = new AbortController();\n const fetchTimeoutId = setTimeout(\n () => controller.abort(),\n SAFE_TX_SERVICE_FETCH_TIMEOUT_MS,\n );\n\n let response: Response;\n try {\n response = await fetch(url, { signal: controller.signal });\n } catch (err) {\n // Transient failure (AbortError on per-request timeout, DNS hiccup,\n // connection reset, etc.). Log and continue to the next poll iteration\n // instead of consuming the entire safePollTimeoutMs budget on one blip.\n // The outer `while (Date.now() < deadline)` is what enforces the overall\n // budget; this catch deliberately preserves it.\n console.warn(\n `Safe Transaction Service request failed (will retry in ${pollIntervalMs}ms): ` +\n (err instanceof Error ? err.message : String(err)),\n );\n await sleep(pollIntervalMs);\n continue;\n } finally {\n clearTimeout(fetchTimeoutId);\n }\n\n if (response.ok) {\n const data = (await response.json()) as SafeMultisigTransaction;\n if (data.isExecuted) {\n if (data.isSuccessful === false) {\n throw new Error(\n `Safe transaction ${safeTxHash} was executed on chain but reverted. ` +\n `Check the Safe queue UI for details.`,\n );\n }\n if (data.transactionHash) {\n return { kind: \"executed\", transactionHash: data.transactionHash };\n }\n }\n } else if (response.status === SAFE_TX_SERVICE_NOT_FOUND) {\n // Usually \"proposal not indexed yet\", so keep polling. But the very same\n // 404 appears when the hash is not a safeTxHash at all — the case that\n // used to burn the whole budget on an already-mined transaction. Ask the\n // node: if it knows this hash, it is a real transaction, so stop treating\n // it as a proposal and let the caller wait on it directly.\n if (await hashIsRealTransaction(publicClient, safeTxHash)) {\n console.warn(\n `${safeTxHash} is a real transaction, not a Safe proposal — the ` +\n `connected wallet submits its own transactions despite reporting ` +\n `contract bytecode. Waiting for its receipt directly.`,\n );\n return { kind: \"not-a-proposal\" };\n }\n } else if (response.status >= SAFE_TX_SERVICE_SERVER_ERROR) {\n // Transient server error — same treatment as a hung connection: log and retry.\n console.warn(\n `Safe Transaction Service returned ${response.status} for ${safeTxHash}; retrying in ${pollIntervalMs}ms.`,\n );\n } else {\n // Other 4xx (403, 410, etc.) is likely permanent — surface immediately.\n throw new Error(\n `Safe Transaction Service returned ${response.status} for ${safeTxHash}.`,\n );\n }\n\n await sleep(pollIntervalMs);\n }\n\n throw new Error(\n `Timed out after ${timeoutMs}ms waiting for Safe transaction ${safeTxHash} ` +\n `to reach quorum and execute. The proposal is still pending in the Safe ` +\n `queue — co-signers must sign and execute it before the dApp can proceed.`,\n );\n}\n\nfunction sleep(ms: number): Promise<void> {\n return new Promise((resolve) => {\n setTimeout(resolve, ms);\n });\n}\n"],"names":["computePeginBaseFeeSats","params","numInputs","numOutputs","feeRate","txVsize","P2TR_INPUT_SIZE","MAX_NON_LEGACY_OUTPUT_SIZE","TX_BUFFER_SIZE_OVERHEAD","rateBasedTxBufferFee","computeChangeOutputFeeSats","applyChangeOutputPolicy","totalInputValue","peginAmount","baseFee","changeOutputFee","residualBeforeChange","residualWithChangeOutput","DUST_THRESHOLD","computeMaxDeposit","totalBalance","fee","max","assertNoDuplicateUtxos","utxos","seen","utxo","key","selectUtxosForPegin","availableUTXOs","validUTXOs","script","Buffer","bitcoinScript","sortedUTXOs","a","b","selectedUTXOs","accumulatedValue","estimatedFee","policy","shouldAddChangeOutput","changeAmount","getDustThreshold","BTC_DUST_SAT","calculateBtcTxHash","txHex","cleanHex","Transaction","BitcoinScriptType","getScriptType","scriptPubKey","length","getPsbtInputFields","publicKeyNoCoord","type","SAFE_TX_SERVICE_BASE_URLS","DEFAULT_SAFE_POLL_INTERVAL_MS","DEFAULT_SAFE_POLL_TIMEOUT_MS","SAFE_TX_SERVICE_FETCH_TIMEOUT_MS","SAFE_MULTISIG_TX_PATH","SAFE_TX_SERVICE_NOT_FOUND","SAFE_TX_SERVICE_SERVER_ERROR","HEX_CHARS_PER_BYTE","EIP_7702_DELEGATION_PREFIX","EIP_7702_DELEGATION_ADDRESS_BYTES","EIP_7702_DELEGATION_CODE_LENGTH","isEip7702DelegatedEoa","code","waitForTransactionReceiptSmartAware","publicClient","walletAddress","hash","confirmations","timeout","safePollTimeoutMs","safePollIntervalMs","chainId","outcome","pollSafeTransactionServiceUntilExecuted","hashIsRealTransaction","safeTxHash","pollIntervalMs","timeoutMs","baseUrl","url","deadline","controller","fetchTimeoutId","response","err","sleep","data","ms","resolve"],"mappings":"mHAyCO,SAASA,EACdC,EACQ,CACR,KAAM,CAAE,UAAAC,EAAW,WAAAC,EAAY,QAAAC,CAAA,EAAYH,EAC3C,GAAI,CAAC,OAAO,UAAUC,CAAS,GAAKA,EAAY,EAC9C,MAAM,IAAI,MACR,0EAA0EA,CAAS,EAAA,EAGvF,GAAI,CAAC,OAAO,UAAUC,CAAU,GAAKA,EAAa,EAChD,MAAM,IAAI,MACR,uEAAuEA,CAAU,EAAA,EAGrF,MAAME,EACJH,EAAYI,EAAAA,gBACZH,EAAaI,EAAAA,2BACbC,EAAAA,wBACF,OACE,OAAO,KAAK,KAAKH,EAAUD,CAAO,CAAC,EACnC,OAAOK,uBAAqBL,CAAO,CAAC,CAExC,CAOO,SAASM,EAA2BN,EAAyB,CAClE,OAAO,OAAO,KAAK,KAAKG,EAAAA,2BAA6BH,CAAO,CAAC,CAC/D,CA0CO,SAASO,EACdV,EAC0B,CAC1B,KAAM,CAAE,gBAAAW,EAAiB,YAAAC,EAAa,QAAAC,EAAS,gBAAAC,GAAoBd,EAE7De,EAAuBJ,EAAkBC,EAAcC,EAC7D,GAAIE,EAAuB,GACzB,MAAM,IAAI,MACR,qDAAqDH,EAAcC,CAAO,eAAeF,CAAe,GAAA,EAI5G,MAAMK,EAA2BD,EAAuBD,EACxD,OAAIE,EAA2BC,EAAAA,eACt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