@btc-vision/transaction 1.8.0-beta.1 → 1.8.0-beta.4

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 (765) hide show
  1. package/browser/_version.d.ts +1 -0
  2. package/browser/_version.d.ts.map +1 -0
  3. package/browser/abi/ABICoder.d.ts +1 -1
  4. package/browser/abi/ABICoder.d.ts.map +1 -0
  5. package/browser/branded/Branded.d.ts +4 -0
  6. package/browser/branded/Branded.d.ts.map +1 -0
  7. package/browser/btc-vision-bitcoin.js +12420 -3637
  8. package/browser/buffer/BinaryReader.d.ts +120 -1
  9. package/browser/buffer/BinaryReader.d.ts.map +1 -0
  10. package/browser/buffer/BinaryWriter.d.ts +51 -1
  11. package/browser/buffer/BinaryWriter.d.ts.map +1 -0
  12. package/browser/bytecode/Compressor.d.ts +12 -0
  13. package/browser/bytecode/Compressor.d.ts.map +1 -0
  14. package/browser/chain/ChainData.d.ts +2 -2
  15. package/browser/chain/ChainData.d.ts.map +1 -0
  16. package/browser/consensus/Consensus.d.ts +11 -3
  17. package/browser/consensus/Consensus.d.ts.map +1 -0
  18. package/browser/consensus/ConsensusConfig.d.ts +1 -0
  19. package/browser/consensus/ConsensusConfig.d.ts.map +1 -0
  20. package/browser/consensus/IConsensusConfig.d.ts +1 -0
  21. package/browser/consensus/IConsensusConfig.d.ts.map +1 -0
  22. package/browser/consensus/metadata/RoswellConsensus.d.ts +1 -0
  23. package/browser/consensus/metadata/RoswellConsensus.d.ts.map +1 -0
  24. package/browser/crypto/crypto.d.ts +1 -0
  25. package/browser/crypto/crypto.d.ts.map +1 -0
  26. package/browser/deterministic/AddressMap.d.ts +6 -1
  27. package/browser/deterministic/AddressMap.d.ts.map +1 -0
  28. package/browser/deterministic/AddressSet.d.ts +3 -1
  29. package/browser/deterministic/AddressSet.d.ts.map +1 -0
  30. package/browser/deterministic/CustomMap.d.ts +3 -1
  31. package/browser/deterministic/CustomMap.d.ts.map +1 -0
  32. package/browser/deterministic/DeterministicMap.d.ts +3 -1
  33. package/browser/deterministic/DeterministicMap.d.ts.map +1 -0
  34. package/browser/deterministic/DeterministicSet.d.ts +3 -1
  35. package/browser/deterministic/DeterministicSet.d.ts.map +1 -0
  36. package/browser/deterministic/ExtendedAddressMap.d.ts +7 -1
  37. package/browser/deterministic/ExtendedAddressMap.d.ts.map +1 -0
  38. package/browser/deterministic/FastMap.d.ts +7 -1
  39. package/browser/deterministic/FastMap.d.ts.map +1 -0
  40. package/browser/ecc/backend.d.ts +13 -0
  41. package/browser/ecc/backend.d.ts.map +1 -0
  42. package/browser/epoch/ChallengeSolution.d.ts +33 -1
  43. package/browser/epoch/ChallengeSolution.d.ts.map +1 -0
  44. package/browser/epoch/interfaces/IChallengeSolution.d.ts +14 -13
  45. package/browser/epoch/interfaces/IChallengeSolution.d.ts.map +1 -0
  46. package/browser/epoch/validator/EpochValidator.d.ts +37 -7
  47. package/browser/epoch/validator/EpochValidator.d.ts.map +1 -0
  48. package/browser/event/NetEvent.d.ts +1 -0
  49. package/browser/event/NetEvent.d.ts.map +1 -0
  50. package/browser/generators/AddressGenerator.d.ts +4 -3
  51. package/browser/generators/AddressGenerator.d.ts.map +1 -0
  52. package/browser/generators/Features.d.ts +1 -0
  53. package/browser/generators/Features.d.ts.map +1 -0
  54. package/browser/generators/Generator.d.ts +46 -10
  55. package/browser/generators/Generator.d.ts.map +1 -0
  56. package/browser/generators/MLDSAData.d.ts +1 -0
  57. package/browser/generators/MLDSAData.d.ts.map +1 -0
  58. package/browser/generators/builders/CalldataGenerator.d.ts +25 -4
  59. package/browser/generators/builders/CalldataGenerator.d.ts.map +1 -0
  60. package/browser/generators/builders/CustomGenerator.d.ts +13 -3
  61. package/browser/generators/builders/CustomGenerator.d.ts.map +1 -0
  62. package/browser/generators/builders/DeploymentGenerator.d.ts +15 -4
  63. package/browser/generators/builders/DeploymentGenerator.d.ts.map +1 -0
  64. package/browser/generators/builders/HashCommitmentGenerator.d.ts +164 -12
  65. package/browser/generators/builders/HashCommitmentGenerator.d.ts.map +1 -0
  66. package/browser/generators/builders/LegacyCalldataGenerator.d.ts +26 -4
  67. package/browser/generators/builders/LegacyCalldataGenerator.d.ts.map +1 -0
  68. package/browser/generators/builders/MultiSignGenerator.d.ts +6 -1
  69. package/browser/generators/builders/MultiSignGenerator.d.ts.map +1 -0
  70. package/browser/generators/builders/P2WDAGenerator.d.ts +42 -4
  71. package/browser/generators/builders/P2WDAGenerator.d.ts.map +1 -0
  72. package/browser/index.d.ts +1 -0
  73. package/browser/index.d.ts.map +1 -0
  74. package/browser/index.js +3602 -3203
  75. package/browser/keypair/Address.d.ts +283 -13
  76. package/browser/keypair/Address.d.ts.map +1 -0
  77. package/browser/keypair/AddressVerificator.d.ts +7 -6
  78. package/browser/keypair/AddressVerificator.d.ts.map +1 -0
  79. package/browser/keypair/EcKeyPair.d.ts +183 -21
  80. package/browser/keypair/EcKeyPair.d.ts.map +1 -0
  81. package/browser/keypair/MessageSigner.d.ts +17 -16
  82. package/browser/keypair/MessageSigner.d.ts.map +1 -0
  83. package/browser/keypair/Secp256k1PointDeriver.d.ts +55 -0
  84. package/browser/keypair/Secp256k1PointDeriver.d.ts.map +1 -0
  85. package/browser/keypair/Wallet.d.ts +27 -13
  86. package/browser/keypair/Wallet.d.ts.map +1 -0
  87. package/browser/keypair/interfaces/IWallet.d.ts +19 -0
  88. package/browser/keypair/interfaces/IWallet.d.ts.map +1 -0
  89. package/browser/metadata/ContractBaseMetadata.d.ts +10 -2
  90. package/browser/metadata/ContractBaseMetadata.d.ts.map +1 -0
  91. package/browser/mnemonic/BIPStandard.d.ts +59 -0
  92. package/browser/mnemonic/BIPStandard.d.ts.map +1 -0
  93. package/browser/mnemonic/Mnemonic.d.ts +15 -3
  94. package/browser/mnemonic/Mnemonic.d.ts.map +1 -0
  95. package/browser/mnemonic/MnemonicStrength.d.ts +6 -0
  96. package/browser/mnemonic/MnemonicStrength.d.ts.map +1 -0
  97. package/browser/network/ChainId.d.ts +1 -0
  98. package/browser/network/ChainId.d.ts.map +1 -0
  99. package/browser/noble-curves.js +920 -2966
  100. package/browser/noble-hashes.js +2067 -1038
  101. package/browser/opnet.d.ts +22 -1
  102. package/browser/opnet.d.ts.map +1 -0
  103. package/browser/p2wda/P2WDADetector.d.ts +36 -9
  104. package/browser/p2wda/P2WDADetector.d.ts.map +1 -0
  105. package/browser/polyfill/disposable.d.ts +16 -0
  106. package/browser/polyfill/disposable.d.ts.map +1 -0
  107. package/browser/signer/AddressRotation.d.ts +36 -0
  108. package/browser/signer/AddressRotation.d.ts.map +1 -0
  109. package/browser/signer/IRotationSigner.d.ts +27 -3
  110. package/browser/signer/IRotationSigner.d.ts.map +1 -0
  111. package/browser/signer/ParallelSignerAdapter.d.ts +14 -0
  112. package/browser/signer/ParallelSignerAdapter.d.ts.map +1 -0
  113. package/browser/signer/SignerUtils.d.ts +11 -4
  114. package/browser/signer/SignerUtils.d.ts.map +1 -0
  115. package/browser/signer/TweakedSigner.d.ts +28 -4
  116. package/browser/signer/TweakedSigner.d.ts.map +1 -0
  117. package/browser/transaction/ContractAddress.d.ts +2 -2
  118. package/browser/transaction/ContractAddress.d.ts.map +1 -0
  119. package/browser/transaction/TransactionFactory.d.ts +140 -2
  120. package/browser/transaction/TransactionFactory.d.ts.map +1 -0
  121. package/browser/transaction/browser/BrowserSignerBase.d.ts +12 -6
  122. package/browser/transaction/browser/BrowserSignerBase.d.ts.map +1 -0
  123. package/browser/transaction/browser/WalletNetworks.d.ts +1 -0
  124. package/browser/transaction/browser/WalletNetworks.d.ts.map +1 -0
  125. package/browser/transaction/browser/Web3Provider.d.ts +27 -0
  126. package/browser/transaction/browser/Web3Provider.d.ts.map +1 -0
  127. package/browser/transaction/browser/extensions/UnisatSigner.d.ts +9 -7
  128. package/browser/transaction/browser/extensions/UnisatSigner.d.ts.map +1 -0
  129. package/browser/transaction/browser/extensions/XverseSigner.d.ts +9 -7
  130. package/browser/transaction/browser/extensions/XverseSigner.d.ts.map +1 -0
  131. package/browser/transaction/browser/types/OPWallet.d.ts +10 -0
  132. package/browser/transaction/browser/types/OPWallet.d.ts.map +1 -0
  133. package/browser/transaction/browser/types/Unisat.d.ts +1 -0
  134. package/browser/transaction/browser/types/Unisat.d.ts.map +1 -0
  135. package/browser/transaction/browser/types/Xverse.d.ts +1 -0
  136. package/browser/transaction/browser/types/Xverse.d.ts.map +1 -0
  137. package/browser/transaction/builders/CancelTransaction.d.ts +29 -4
  138. package/browser/transaction/builders/CancelTransaction.d.ts.map +1 -0
  139. package/browser/transaction/builders/ChallengeSolutionTransaction.d.ts +1 -0
  140. package/browser/transaction/builders/ChallengeSolutionTransaction.d.ts.map +1 -0
  141. package/browser/transaction/builders/ConsolidatedInteractionTransaction.d.ts +137 -10
  142. package/browser/transaction/builders/ConsolidatedInteractionTransaction.d.ts.map +1 -0
  143. package/browser/transaction/builders/CustomScriptTransaction.d.ts +106 -6
  144. package/browser/transaction/builders/CustomScriptTransaction.d.ts.map +1 -0
  145. package/browser/transaction/builders/DeploymentTransaction.d.ts +116 -5
  146. package/browser/transaction/builders/DeploymentTransaction.d.ts.map +1 -0
  147. package/browser/transaction/builders/FundingTransaction.d.ts +4 -3
  148. package/browser/transaction/builders/FundingTransaction.d.ts.map +1 -0
  149. package/browser/transaction/builders/InteractionTransaction.d.ts +12 -3
  150. package/browser/transaction/builders/InteractionTransaction.d.ts.map +1 -0
  151. package/browser/transaction/builders/InteractionTransactionP2WDA.d.ts +56 -5
  152. package/browser/transaction/builders/InteractionTransactionP2WDA.d.ts.map +1 -0
  153. package/browser/transaction/builders/MultiSignTransaction.d.ts +125 -16
  154. package/browser/transaction/builders/MultiSignTransaction.d.ts.map +1 -0
  155. package/browser/transaction/builders/SharedInteractionTransaction.d.ts +103 -15
  156. package/browser/transaction/builders/SharedInteractionTransaction.d.ts.map +1 -0
  157. package/browser/transaction/builders/TransactionBuilder.d.ts +243 -14
  158. package/browser/transaction/builders/TransactionBuilder.d.ts.map +1 -0
  159. package/browser/transaction/enums/TransactionType.d.ts +1 -0
  160. package/browser/transaction/enums/TransactionType.d.ts.map +1 -0
  161. package/browser/transaction/interfaces/ICancelTransactionParameters.d.ts +2 -1
  162. package/browser/transaction/interfaces/ICancelTransactionParameters.d.ts.map +1 -0
  163. package/browser/transaction/interfaces/IConsolidatedTransactionParameters.d.ts +46 -3
  164. package/browser/transaction/interfaces/IConsolidatedTransactionParameters.d.ts.map +1 -0
  165. package/browser/transaction/interfaces/ICustomTransactionParameters.d.ts +6 -4
  166. package/browser/transaction/interfaces/ICustomTransactionParameters.d.ts.map +1 -0
  167. package/browser/transaction/interfaces/ITransactionParameters.d.ts +22 -10
  168. package/browser/transaction/interfaces/ITransactionParameters.d.ts.map +1 -0
  169. package/browser/transaction/interfaces/ITransactionResponses.d.ts +1 -0
  170. package/browser/transaction/interfaces/ITransactionResponses.d.ts.map +1 -0
  171. package/browser/transaction/interfaces/ITweakedTransactionData.d.ts +18 -5
  172. package/browser/transaction/interfaces/ITweakedTransactionData.d.ts.map +1 -0
  173. package/browser/transaction/interfaces/IWeb3ProviderTypes.d.ts +26 -0
  174. package/browser/transaction/interfaces/IWeb3ProviderTypes.d.ts.map +1 -0
  175. package/browser/transaction/interfaces/Tap.d.ts +4 -3
  176. package/browser/transaction/interfaces/Tap.d.ts.map +1 -0
  177. package/browser/transaction/mineable/IP2WSHAddress.d.ts +2 -1
  178. package/browser/transaction/mineable/IP2WSHAddress.d.ts.map +1 -0
  179. package/browser/transaction/mineable/TimelockGenerator.d.ts +12 -3
  180. package/browser/transaction/mineable/TimelockGenerator.d.ts.map +1 -0
  181. package/browser/transaction/offline/OfflineTransactionManager.d.ts +190 -9
  182. package/browser/transaction/offline/OfflineTransactionManager.d.ts.map +1 -0
  183. package/browser/transaction/offline/TransactionReconstructor.d.ts +53 -3
  184. package/browser/transaction/offline/TransactionReconstructor.d.ts.map +1 -0
  185. package/browser/transaction/offline/TransactionSerializer.d.ts +53 -2
  186. package/browser/transaction/offline/TransactionSerializer.d.ts.map +1 -0
  187. package/browser/transaction/offline/TransactionStateCapture.d.ts +64 -5
  188. package/browser/transaction/offline/TransactionStateCapture.d.ts.map +1 -0
  189. package/browser/transaction/offline/interfaces/ISerializableState.d.ts +71 -0
  190. package/browser/transaction/offline/interfaces/ISerializableState.d.ts.map +1 -0
  191. package/browser/transaction/offline/interfaces/ITypeSpecificData.d.ts +76 -0
  192. package/browser/transaction/offline/interfaces/ITypeSpecificData.d.ts.map +1 -0
  193. package/browser/transaction/psbt/PSBTTypes.d.ts +1 -0
  194. package/browser/transaction/psbt/PSBTTypes.d.ts.map +1 -0
  195. package/browser/transaction/shared/P2TR_MS.d.ts +11 -2
  196. package/browser/transaction/shared/P2TR_MS.d.ts.map +1 -0
  197. package/browser/transaction/shared/TweakedTransaction.d.ts +275 -33
  198. package/browser/transaction/shared/TweakedTransaction.d.ts.map +1 -0
  199. package/browser/transaction/utils/WitnessUtils.d.ts +7 -1
  200. package/browser/transaction/utils/WitnessUtils.d.ts.map +1 -0
  201. package/browser/utils/BitcoinUtils.d.ts +19 -0
  202. package/browser/utils/BitcoinUtils.d.ts.map +1 -0
  203. package/browser/utils/BufferHelper.d.ts +1 -0
  204. package/browser/utils/BufferHelper.d.ts.map +1 -0
  205. package/browser/utils/StringToBuffer.d.ts +1 -0
  206. package/browser/utils/StringToBuffer.d.ts.map +1 -0
  207. package/browser/utils/lengths.d.ts +1 -0
  208. package/browser/utils/lengths.d.ts.map +1 -0
  209. package/browser/utils/types.d.ts +1 -0
  210. package/browser/utils/types.d.ts.map +1 -0
  211. package/browser/utxo/OPNetLimitedProvider.d.ts +37 -1
  212. package/browser/utxo/OPNetLimitedProvider.d.ts.map +1 -0
  213. package/browser/utxo/interfaces/BroadcastResponse.d.ts +1 -0
  214. package/browser/utxo/interfaces/BroadcastResponse.d.ts.map +1 -0
  215. package/browser/utxo/interfaces/IUTXO.d.ts +11 -5
  216. package/browser/utxo/interfaces/IUTXO.d.ts.map +1 -0
  217. package/browser/vendors.js +13940 -9389
  218. package/browser/verification/TapscriptVerificator.d.ts +10 -8
  219. package/browser/verification/TapscriptVerificator.d.ts.map +1 -0
  220. package/build/_version.d.ts +1 -0
  221. package/build/_version.d.ts.map +1 -0
  222. package/build/_version.js +1 -0
  223. package/build/_version.js.map +1 -0
  224. package/build/abi/ABICoder.d.ts +1 -1
  225. package/build/abi/ABICoder.d.ts.map +1 -0
  226. package/build/abi/ABICoder.js +9 -10
  227. package/build/abi/ABICoder.js.map +1 -0
  228. package/build/branded/Branded.d.ts +4 -0
  229. package/build/branded/Branded.d.ts.map +1 -0
  230. package/build/branded/Branded.js +2 -0
  231. package/build/branded/Branded.js.map +1 -0
  232. package/build/buffer/BinaryReader.d.ts +121 -2
  233. package/build/buffer/BinaryReader.d.ts.map +1 -0
  234. package/build/buffer/BinaryReader.js +129 -5
  235. package/build/buffer/BinaryReader.js.map +1 -0
  236. package/build/buffer/BinaryWriter.d.ts +52 -2
  237. package/build/buffer/BinaryWriter.d.ts.map +1 -0
  238. package/build/buffer/BinaryWriter.js +62 -2
  239. package/build/buffer/BinaryWriter.js.map +1 -0
  240. package/build/bytecode/Compressor.d.ts +12 -0
  241. package/build/bytecode/Compressor.d.ts.map +1 -0
  242. package/build/bytecode/Compressor.js +17 -5
  243. package/build/bytecode/Compressor.js.map +1 -0
  244. package/build/chain/ChainData.d.ts +2 -2
  245. package/build/chain/ChainData.d.ts.map +1 -0
  246. package/build/chain/ChainData.js +35 -17
  247. package/build/chain/ChainData.js.map +1 -0
  248. package/build/consensus/Consensus.d.ts +11 -3
  249. package/build/consensus/Consensus.d.ts.map +1 -0
  250. package/build/consensus/Consensus.js +8 -0
  251. package/build/consensus/Consensus.js.map +1 -0
  252. package/build/consensus/ConsensusConfig.d.ts +2 -1
  253. package/build/consensus/ConsensusConfig.d.ts.map +1 -0
  254. package/build/consensus/ConsensusConfig.js +1 -0
  255. package/build/consensus/ConsensusConfig.js.map +1 -0
  256. package/build/consensus/IConsensusConfig.d.ts +1 -0
  257. package/build/consensus/IConsensusConfig.d.ts.map +1 -0
  258. package/build/consensus/IConsensusConfig.js +2 -1
  259. package/build/consensus/IConsensusConfig.js.map +1 -0
  260. package/build/consensus/metadata/RoswellConsensus.d.ts +2 -1
  261. package/build/consensus/metadata/RoswellConsensus.d.ts.map +1 -0
  262. package/build/consensus/metadata/RoswellConsensus.js +2 -0
  263. package/build/consensus/metadata/RoswellConsensus.js.map +1 -0
  264. package/build/crypto/crypto.d.ts +1 -0
  265. package/build/crypto/crypto.d.ts.map +1 -0
  266. package/build/crypto/crypto.js +1 -0
  267. package/build/crypto/crypto.js.map +1 -0
  268. package/build/deterministic/AddressMap.d.ts +6 -1
  269. package/build/deterministic/AddressMap.d.ts.map +1 -0
  270. package/build/deterministic/AddressMap.js +8 -0
  271. package/build/deterministic/AddressMap.js.map +1 -0
  272. package/build/deterministic/AddressSet.d.ts +3 -1
  273. package/build/deterministic/AddressSet.d.ts.map +1 -0
  274. package/build/deterministic/AddressSet.js +7 -0
  275. package/build/deterministic/AddressSet.js.map +1 -0
  276. package/build/deterministic/CustomMap.d.ts +3 -1
  277. package/build/deterministic/CustomMap.d.ts.map +1 -0
  278. package/build/deterministic/CustomMap.js +65 -47
  279. package/build/deterministic/CustomMap.js.map +1 -0
  280. package/build/deterministic/DeterministicMap.d.ts +4 -2
  281. package/build/deterministic/DeterministicMap.d.ts.map +1 -0
  282. package/build/deterministic/DeterministicMap.js +24 -27
  283. package/build/deterministic/DeterministicMap.js.map +1 -0
  284. package/build/deterministic/DeterministicSet.d.ts +3 -1
  285. package/build/deterministic/DeterministicSet.d.ts.map +1 -0
  286. package/build/deterministic/DeterministicSet.js +6 -0
  287. package/build/deterministic/DeterministicSet.js.map +1 -0
  288. package/build/deterministic/ExtendedAddressMap.d.ts +7 -1
  289. package/build/deterministic/ExtendedAddressMap.d.ts.map +1 -0
  290. package/build/deterministic/ExtendedAddressMap.js +18 -2
  291. package/build/deterministic/ExtendedAddressMap.js.map +1 -0
  292. package/build/deterministic/FastMap.d.ts +7 -1
  293. package/build/deterministic/FastMap.d.ts.map +1 -0
  294. package/build/deterministic/FastMap.js +7 -2
  295. package/build/deterministic/FastMap.js.map +1 -0
  296. package/build/ecc/backend.d.ts +13 -0
  297. package/build/ecc/backend.d.ts.map +1 -0
  298. package/build/ecc/backend.js +15 -0
  299. package/build/ecc/backend.js.map +1 -0
  300. package/build/epoch/ChallengeSolution.d.ts +34 -2
  301. package/build/epoch/ChallengeSolution.d.ts.map +1 -0
  302. package/build/epoch/ChallengeSolution.js +52 -0
  303. package/build/epoch/ChallengeSolution.js.map +1 -0
  304. package/build/epoch/interfaces/IChallengeSolution.d.ts +14 -13
  305. package/build/epoch/interfaces/IChallengeSolution.d.ts.map +1 -0
  306. package/build/epoch/interfaces/IChallengeSolution.js +2 -1
  307. package/build/epoch/interfaces/IChallengeSolution.js.map +1 -0
  308. package/build/epoch/validator/EpochValidator.d.ts +38 -8
  309. package/build/epoch/validator/EpochValidator.d.ts.map +1 -0
  310. package/build/epoch/validator/EpochValidator.js +45 -19
  311. package/build/epoch/validator/EpochValidator.js.map +1 -0
  312. package/build/event/NetEvent.d.ts +1 -0
  313. package/build/event/NetEvent.d.ts.map +1 -0
  314. package/build/event/NetEvent.js +3 -0
  315. package/build/event/NetEvent.js.map +1 -0
  316. package/build/generators/AddressGenerator.d.ts +4 -3
  317. package/build/generators/AddressGenerator.d.ts.map +1 -0
  318. package/build/generators/AddressGenerator.js +10 -3
  319. package/build/generators/AddressGenerator.js.map +1 -0
  320. package/build/generators/Features.d.ts +4 -3
  321. package/build/generators/Features.d.ts.map +1 -0
  322. package/build/generators/Features.js +1 -0
  323. package/build/generators/Features.js.map +1 -0
  324. package/build/generators/Generator.d.ts +47 -11
  325. package/build/generators/Generator.d.ts.map +1 -0
  326. package/build/generators/Generator.js +48 -12
  327. package/build/generators/Generator.js.map +1 -0
  328. package/build/generators/MLDSAData.d.ts +1 -0
  329. package/build/generators/MLDSAData.d.ts.map +1 -0
  330. package/build/generators/MLDSAData.js +1 -0
  331. package/build/generators/MLDSAData.js.map +1 -0
  332. package/build/generators/builders/CalldataGenerator.d.ts +27 -6
  333. package/build/generators/builders/CalldataGenerator.d.ts.map +1 -0
  334. package/build/generators/builders/CalldataGenerator.js +33 -4
  335. package/build/generators/builders/CalldataGenerator.js.map +1 -0
  336. package/build/generators/builders/CustomGenerator.d.ts +13 -3
  337. package/build/generators/builders/CustomGenerator.d.ts.map +1 -0
  338. package/build/generators/builders/CustomGenerator.js +11 -0
  339. package/build/generators/builders/CustomGenerator.js.map +1 -0
  340. package/build/generators/builders/DeploymentGenerator.d.ts +17 -6
  341. package/build/generators/builders/DeploymentGenerator.d.ts.map +1 -0
  342. package/build/generators/builders/DeploymentGenerator.js +18 -2
  343. package/build/generators/builders/DeploymentGenerator.js.map +1 -0
  344. package/build/generators/builders/HashCommitmentGenerator.d.ts +166 -14
  345. package/build/generators/builders/HashCommitmentGenerator.d.ts.map +1 -0
  346. package/build/generators/builders/HashCommitmentGenerator.js +193 -27
  347. package/build/generators/builders/HashCommitmentGenerator.js.map +1 -0
  348. package/build/generators/builders/LegacyCalldataGenerator.d.ts +27 -5
  349. package/build/generators/builders/LegacyCalldataGenerator.d.ts.map +1 -0
  350. package/build/generators/builders/LegacyCalldataGenerator.js +35 -5
  351. package/build/generators/builders/LegacyCalldataGenerator.js.map +1 -0
  352. package/build/generators/builders/MultiSignGenerator.d.ts +6 -1
  353. package/build/generators/builders/MultiSignGenerator.d.ts.map +1 -0
  354. package/build/generators/builders/MultiSignGenerator.js +20 -10
  355. package/build/generators/builders/MultiSignGenerator.js.map +1 -0
  356. package/build/generators/builders/P2WDAGenerator.d.ts +44 -6
  357. package/build/generators/builders/P2WDAGenerator.d.ts.map +1 -0
  358. package/build/generators/builders/P2WDAGenerator.js +41 -2
  359. package/build/generators/builders/P2WDAGenerator.js.map +1 -0
  360. package/build/index.d.ts +1 -0
  361. package/build/index.d.ts.map +1 -0
  362. package/build/index.js +1 -0
  363. package/build/index.js.map +1 -0
  364. package/build/keypair/Address.d.ts +284 -14
  365. package/build/keypair/Address.d.ts.map +1 -0
  366. package/build/keypair/Address.js +447 -129
  367. package/build/keypair/Address.js.map +1 -0
  368. package/build/keypair/AddressVerificator.d.ts +7 -6
  369. package/build/keypair/AddressVerificator.d.ts.map +1 -0
  370. package/build/keypair/AddressVerificator.js +6 -5
  371. package/build/keypair/AddressVerificator.js.map +1 -0
  372. package/build/keypair/EcKeyPair.d.ts +185 -23
  373. package/build/keypair/EcKeyPair.d.ts.map +1 -0
  374. package/build/keypair/EcKeyPair.js +223 -54
  375. package/build/keypair/EcKeyPair.js.map +1 -0
  376. package/build/keypair/MessageSigner.d.ts +18 -17
  377. package/build/keypair/MessageSigner.d.ts.map +1 -0
  378. package/build/keypair/MessageSigner.js +34 -25
  379. package/build/keypair/MessageSigner.js.map +1 -0
  380. package/build/keypair/Secp256k1PointDeriver.d.ts +55 -0
  381. package/build/keypair/Secp256k1PointDeriver.d.ts.map +1 -0
  382. package/build/keypair/Secp256k1PointDeriver.js +66 -0
  383. package/build/keypair/Secp256k1PointDeriver.js.map +1 -0
  384. package/build/keypair/Wallet.d.ts +29 -15
  385. package/build/keypair/Wallet.d.ts.map +1 -0
  386. package/build/keypair/Wallet.js +48 -14
  387. package/build/keypair/Wallet.js.map +1 -0
  388. package/build/keypair/interfaces/IWallet.d.ts +19 -0
  389. package/build/keypair/interfaces/IWallet.d.ts.map +1 -0
  390. package/build/keypair/interfaces/IWallet.js +1 -0
  391. package/build/keypair/interfaces/IWallet.js.map +1 -0
  392. package/build/metadata/ContractBaseMetadata.d.ts +10 -2
  393. package/build/metadata/ContractBaseMetadata.d.ts.map +1 -0
  394. package/build/metadata/ContractBaseMetadata.js +10 -1
  395. package/build/metadata/ContractBaseMetadata.js.map +1 -0
  396. package/build/mnemonic/BIPStandard.d.ts +59 -0
  397. package/build/mnemonic/BIPStandard.d.ts.map +1 -0
  398. package/build/mnemonic/BIPStandard.js +59 -0
  399. package/build/mnemonic/BIPStandard.js.map +1 -0
  400. package/build/mnemonic/Mnemonic.d.ts +16 -4
  401. package/build/mnemonic/Mnemonic.d.ts.map +1 -0
  402. package/build/mnemonic/Mnemonic.js +36 -8
  403. package/build/mnemonic/Mnemonic.js.map +1 -0
  404. package/build/mnemonic/MnemonicStrength.d.ts +6 -0
  405. package/build/mnemonic/MnemonicStrength.d.ts.map +1 -0
  406. package/build/mnemonic/MnemonicStrength.js +6 -0
  407. package/build/mnemonic/MnemonicStrength.js.map +1 -0
  408. package/build/network/ChainId.d.ts +1 -0
  409. package/build/network/ChainId.d.ts.map +1 -0
  410. package/build/network/ChainId.js +1 -0
  411. package/build/network/ChainId.js.map +1 -0
  412. package/build/opnet.d.ts +26 -3
  413. package/build/opnet.d.ts.map +1 -0
  414. package/build/opnet.js +23 -0
  415. package/build/opnet.js.map +1 -0
  416. package/build/p2wda/P2WDADetector.d.ts +38 -11
  417. package/build/p2wda/P2WDADetector.d.ts.map +1 -0
  418. package/build/p2wda/P2WDADetector.js +43 -10
  419. package/build/p2wda/P2WDADetector.js.map +1 -0
  420. package/build/polyfill/disposable.d.ts +16 -0
  421. package/build/polyfill/disposable.d.ts.map +1 -0
  422. package/build/polyfill/disposable.js +23 -0
  423. package/build/polyfill/disposable.js.map +1 -0
  424. package/build/signer/AddressRotation.d.ts +37 -1
  425. package/build/signer/AddressRotation.d.ts.map +1 -0
  426. package/build/signer/AddressRotation.js +16 -0
  427. package/build/signer/AddressRotation.js.map +1 -0
  428. package/build/signer/IRotationSigner.d.ts +27 -3
  429. package/build/signer/IRotationSigner.d.ts.map +1 -0
  430. package/build/signer/IRotationSigner.js +2 -1
  431. package/build/signer/IRotationSigner.js.map +1 -0
  432. package/build/signer/ParallelSignerAdapter.d.ts +14 -0
  433. package/build/signer/ParallelSignerAdapter.d.ts.map +1 -0
  434. package/build/signer/ParallelSignerAdapter.js +51 -0
  435. package/build/signer/ParallelSignerAdapter.js.map +1 -0
  436. package/build/signer/SignerUtils.d.ts +11 -4
  437. package/build/signer/SignerUtils.d.ts.map +1 -0
  438. package/build/signer/SignerUtils.js +16 -0
  439. package/build/signer/SignerUtils.js.map +1 -0
  440. package/build/signer/TweakedSigner.d.ts +28 -4
  441. package/build/signer/TweakedSigner.d.ts.map +1 -0
  442. package/build/signer/TweakedSigner.js +24 -6
  443. package/build/signer/TweakedSigner.js.map +1 -0
  444. package/build/transaction/ContractAddress.d.ts +2 -2
  445. package/build/transaction/ContractAddress.d.ts.map +1 -0
  446. package/build/transaction/ContractAddress.js +4 -8
  447. package/build/transaction/ContractAddress.js.map +1 -0
  448. package/build/transaction/TransactionFactory.d.ts +147 -9
  449. package/build/transaction/TransactionFactory.d.ts.map +1 -0
  450. package/build/transaction/TransactionFactory.js +145 -26
  451. package/build/transaction/TransactionFactory.js.map +1 -0
  452. package/build/transaction/browser/BrowserSignerBase.d.ts +12 -6
  453. package/build/transaction/browser/BrowserSignerBase.d.ts.map +1 -0
  454. package/build/transaction/browser/BrowserSignerBase.js +7 -0
  455. package/build/transaction/browser/BrowserSignerBase.js.map +1 -0
  456. package/build/transaction/browser/WalletNetworks.d.ts +1 -0
  457. package/build/transaction/browser/WalletNetworks.d.ts.map +1 -0
  458. package/build/transaction/browser/WalletNetworks.js +1 -0
  459. package/build/transaction/browser/WalletNetworks.js.map +1 -0
  460. package/build/transaction/browser/Web3Provider.d.ts +30 -3
  461. package/build/transaction/browser/Web3Provider.d.ts.map +1 -0
  462. package/build/transaction/browser/Web3Provider.js +1 -0
  463. package/build/transaction/browser/Web3Provider.js.map +1 -0
  464. package/build/transaction/browser/extensions/UnisatSigner.d.ts +11 -9
  465. package/build/transaction/browser/extensions/UnisatSigner.d.ts.map +1 -0
  466. package/build/transaction/browser/extensions/UnisatSigner.js +27 -17
  467. package/build/transaction/browser/extensions/UnisatSigner.js.map +1 -0
  468. package/build/transaction/browser/extensions/XverseSigner.d.ts +10 -8
  469. package/build/transaction/browser/extensions/XverseSigner.d.ts.map +1 -0
  470. package/build/transaction/browser/extensions/XverseSigner.js +25 -15
  471. package/build/transaction/browser/extensions/XverseSigner.js.map +1 -0
  472. package/build/transaction/browser/types/OPWallet.d.ts +12 -2
  473. package/build/transaction/browser/types/OPWallet.d.ts.map +1 -0
  474. package/build/transaction/browser/types/OPWallet.js +4 -0
  475. package/build/transaction/browser/types/OPWallet.js.map +1 -0
  476. package/build/transaction/browser/types/Unisat.d.ts +2 -1
  477. package/build/transaction/browser/types/Unisat.d.ts.map +1 -0
  478. package/build/transaction/browser/types/Unisat.js +2 -0
  479. package/build/transaction/browser/types/Unisat.js.map +1 -0
  480. package/build/transaction/browser/types/Xverse.d.ts +1 -0
  481. package/build/transaction/browser/types/Xverse.d.ts.map +1 -0
  482. package/build/transaction/browser/types/Xverse.js +1 -0
  483. package/build/transaction/browser/types/Xverse.js.map +1 -0
  484. package/build/transaction/builders/CancelTransaction.d.ts +31 -6
  485. package/build/transaction/builders/CancelTransaction.d.ts.map +1 -0
  486. package/build/transaction/builders/CancelTransaction.js +116 -33
  487. package/build/transaction/builders/CancelTransaction.js.map +1 -0
  488. package/build/transaction/builders/ChallengeSolutionTransaction.d.ts +1 -0
  489. package/build/transaction/builders/ChallengeSolutionTransaction.d.ts.map +1 -0
  490. package/build/transaction/builders/ChallengeSolutionTransaction.js +88 -0
  491. package/build/transaction/builders/ChallengeSolutionTransaction.js.map +1 -0
  492. package/build/transaction/builders/ConsolidatedInteractionTransaction.d.ts +140 -13
  493. package/build/transaction/builders/ConsolidatedInteractionTransaction.d.ts.map +1 -0
  494. package/build/transaction/builders/ConsolidatedInteractionTransaction.js +197 -20
  495. package/build/transaction/builders/ConsolidatedInteractionTransaction.js.map +1 -0
  496. package/build/transaction/builders/CustomScriptTransaction.d.ts +108 -8
  497. package/build/transaction/builders/CustomScriptTransaction.d.ts.map +1 -0
  498. package/build/transaction/builders/CustomScriptTransaction.js +176 -39
  499. package/build/transaction/builders/CustomScriptTransaction.js.map +1 -0
  500. package/build/transaction/builders/DeploymentTransaction.d.ts +120 -9
  501. package/build/transaction/builders/DeploymentTransaction.d.ts.map +1 -0
  502. package/build/transaction/builders/DeploymentTransaction.js +194 -51
  503. package/build/transaction/builders/DeploymentTransaction.js.map +1 -0
  504. package/build/transaction/builders/FundingTransaction.d.ts +5 -4
  505. package/build/transaction/builders/FundingTransaction.d.ts.map +1 -0
  506. package/build/transaction/builders/FundingTransaction.js +15 -8
  507. package/build/transaction/builders/FundingTransaction.js.map +1 -0
  508. package/build/transaction/builders/InteractionTransaction.d.ts +14 -5
  509. package/build/transaction/builders/InteractionTransaction.d.ts.map +1 -0
  510. package/build/transaction/builders/InteractionTransaction.js +18 -5
  511. package/build/transaction/builders/InteractionTransaction.js.map +1 -0
  512. package/build/transaction/builders/InteractionTransactionP2WDA.d.ts +58 -7
  513. package/build/transaction/builders/InteractionTransactionP2WDA.d.ts.map +1 -0
  514. package/build/transaction/builders/InteractionTransactionP2WDA.js +95 -18
  515. package/build/transaction/builders/InteractionTransactionP2WDA.js.map +1 -0
  516. package/build/transaction/builders/MultiSignTransaction.d.ts +126 -17
  517. package/build/transaction/builders/MultiSignTransaction.d.ts.map +1 -0
  518. package/build/transaction/builders/MultiSignTransaction.js +201 -76
  519. package/build/transaction/builders/MultiSignTransaction.js.map +1 -0
  520. package/build/transaction/builders/SharedInteractionTransaction.d.ts +106 -18
  521. package/build/transaction/builders/SharedInteractionTransaction.d.ts.map +1 -0
  522. package/build/transaction/builders/SharedInteractionTransaction.js +158 -40
  523. package/build/transaction/builders/SharedInteractionTransaction.js.map +1 -0
  524. package/build/transaction/builders/TransactionBuilder.d.ts +249 -19
  525. package/build/transaction/builders/TransactionBuilder.d.ts.map +1 -0
  526. package/build/transaction/builders/TransactionBuilder.js +377 -60
  527. package/build/transaction/builders/TransactionBuilder.js.map +1 -0
  528. package/build/transaction/enums/TransactionType.d.ts +1 -0
  529. package/build/transaction/enums/TransactionType.d.ts.map +1 -0
  530. package/build/transaction/enums/TransactionType.js +1 -0
  531. package/build/transaction/enums/TransactionType.js.map +1 -0
  532. package/build/transaction/interfaces/ICancelTransactionParameters.d.ts +3 -2
  533. package/build/transaction/interfaces/ICancelTransactionParameters.d.ts.map +1 -0
  534. package/build/transaction/interfaces/ICancelTransactionParameters.js +1 -0
  535. package/build/transaction/interfaces/ICancelTransactionParameters.js.map +1 -0
  536. package/build/transaction/interfaces/IConsolidatedTransactionParameters.d.ts +48 -5
  537. package/build/transaction/interfaces/IConsolidatedTransactionParameters.d.ts.map +1 -0
  538. package/build/transaction/interfaces/IConsolidatedTransactionParameters.js +1 -0
  539. package/build/transaction/interfaces/IConsolidatedTransactionParameters.js.map +1 -0
  540. package/build/transaction/interfaces/ICustomTransactionParameters.d.ts +7 -5
  541. package/build/transaction/interfaces/ICustomTransactionParameters.d.ts.map +1 -0
  542. package/build/transaction/interfaces/ICustomTransactionParameters.js +1 -0
  543. package/build/transaction/interfaces/ICustomTransactionParameters.js.map +1 -0
  544. package/build/transaction/interfaces/ITransactionParameters.d.ts +27 -15
  545. package/build/transaction/interfaces/ITransactionParameters.d.ts.map +1 -0
  546. package/build/transaction/interfaces/ITransactionParameters.js +1 -0
  547. package/build/transaction/interfaces/ITransactionParameters.js.map +1 -0
  548. package/build/transaction/interfaces/ITransactionResponses.d.ts +3 -2
  549. package/build/transaction/interfaces/ITransactionResponses.d.ts.map +1 -0
  550. package/build/transaction/interfaces/ITransactionResponses.js +1 -0
  551. package/build/transaction/interfaces/ITransactionResponses.js.map +1 -0
  552. package/build/transaction/interfaces/ITweakedTransactionData.d.ts +21 -8
  553. package/build/transaction/interfaces/ITweakedTransactionData.d.ts.map +1 -0
  554. package/build/transaction/interfaces/ITweakedTransactionData.js +1 -0
  555. package/build/transaction/interfaces/ITweakedTransactionData.js.map +1 -0
  556. package/build/transaction/interfaces/IWeb3ProviderTypes.d.ts +29 -3
  557. package/build/transaction/interfaces/IWeb3ProviderTypes.d.ts.map +1 -0
  558. package/build/transaction/interfaces/IWeb3ProviderTypes.js +2 -1
  559. package/build/transaction/interfaces/IWeb3ProviderTypes.js.map +1 -0
  560. package/build/transaction/interfaces/Tap.d.ts +4 -3
  561. package/build/transaction/interfaces/Tap.d.ts.map +1 -0
  562. package/build/transaction/interfaces/Tap.js +1 -0
  563. package/build/transaction/interfaces/Tap.js.map +1 -0
  564. package/build/transaction/mineable/IP2WSHAddress.d.ts +2 -1
  565. package/build/transaction/mineable/IP2WSHAddress.d.ts.map +1 -0
  566. package/build/transaction/mineable/IP2WSHAddress.js +1 -0
  567. package/build/transaction/mineable/IP2WSHAddress.js.map +1 -0
  568. package/build/transaction/mineable/TimelockGenerator.d.ts +13 -4
  569. package/build/transaction/mineable/TimelockGenerator.d.ts.map +1 -0
  570. package/build/transaction/mineable/TimelockGenerator.js +12 -3
  571. package/build/transaction/mineable/TimelockGenerator.js.map +1 -0
  572. package/build/transaction/offline/OfflineTransactionManager.d.ts +193 -12
  573. package/build/transaction/offline/OfflineTransactionManager.d.ts.map +1 -0
  574. package/build/transaction/offline/OfflineTransactionManager.js +192 -8
  575. package/build/transaction/offline/OfflineTransactionManager.js.map +1 -0
  576. package/build/transaction/offline/TransactionReconstructor.d.ts +56 -6
  577. package/build/transaction/offline/TransactionReconstructor.d.ts.map +1 -0
  578. package/build/transaction/offline/TransactionReconstructor.js +111 -75
  579. package/build/transaction/offline/TransactionReconstructor.js.map +1 -0
  580. package/build/transaction/offline/TransactionSerializer.d.ts +54 -3
  581. package/build/transaction/offline/TransactionSerializer.d.ts.map +1 -0
  582. package/build/transaction/offline/TransactionSerializer.js +206 -95
  583. package/build/transaction/offline/TransactionSerializer.js.map +1 -0
  584. package/build/transaction/offline/TransactionStateCapture.d.ts +66 -7
  585. package/build/transaction/offline/TransactionStateCapture.d.ts.map +1 -0
  586. package/build/transaction/offline/TransactionStateCapture.js +124 -60
  587. package/build/transaction/offline/TransactionStateCapture.js.map +1 -0
  588. package/build/transaction/offline/interfaces/ISerializableState.d.ts +72 -1
  589. package/build/transaction/offline/interfaces/ISerializableState.d.ts.map +1 -0
  590. package/build/transaction/offline/interfaces/ISerializableState.js +10 -1
  591. package/build/transaction/offline/interfaces/ISerializableState.js.map +1 -0
  592. package/build/transaction/offline/interfaces/ITypeSpecificData.d.ts +77 -1
  593. package/build/transaction/offline/interfaces/ITypeSpecificData.d.ts.map +1 -0
  594. package/build/transaction/offline/interfaces/ITypeSpecificData.js +19 -0
  595. package/build/transaction/offline/interfaces/ITypeSpecificData.js.map +1 -0
  596. package/build/transaction/psbt/PSBTTypes.d.ts +1 -0
  597. package/build/transaction/psbt/PSBTTypes.d.ts.map +1 -0
  598. package/build/transaction/psbt/PSBTTypes.js +1 -0
  599. package/build/transaction/psbt/PSBTTypes.js.map +1 -0
  600. package/build/transaction/shared/P2TR_MS.d.ts +11 -2
  601. package/build/transaction/shared/P2TR_MS.d.ts.map +1 -0
  602. package/build/transaction/shared/P2TR_MS.js +10 -0
  603. package/build/transaction/shared/P2TR_MS.js.map +1 -0
  604. package/build/transaction/shared/TweakedTransaction.d.ts +281 -38
  605. package/build/transaction/shared/TweakedTransaction.d.ts.map +1 -0
  606. package/build/transaction/shared/TweakedTransaction.js +576 -114
  607. package/build/transaction/shared/TweakedTransaction.js.map +1 -0
  608. package/build/transaction/utils/WitnessUtils.d.ts +7 -1
  609. package/build/transaction/utils/WitnessUtils.d.ts.map +1 -0
  610. package/build/transaction/utils/WitnessUtils.js +17 -3
  611. package/build/transaction/utils/WitnessUtils.js.map +1 -0
  612. package/build/tsconfig.build.tsbuildinfo +1 -1
  613. package/build/utils/BitcoinUtils.d.ts +19 -0
  614. package/build/utils/BitcoinUtils.d.ts.map +1 -0
  615. package/build/utils/BitcoinUtils.js +19 -0
  616. package/build/utils/BitcoinUtils.js.map +1 -0
  617. package/build/utils/BufferHelper.d.ts +2 -1
  618. package/build/utils/BufferHelper.d.ts.map +1 -0
  619. package/build/utils/BufferHelper.js +38 -32
  620. package/build/utils/BufferHelper.js.map +1 -0
  621. package/build/utils/StringToBuffer.d.ts +1 -0
  622. package/build/utils/StringToBuffer.d.ts.map +1 -0
  623. package/build/utils/StringToBuffer.js +1 -0
  624. package/build/utils/StringToBuffer.js.map +1 -0
  625. package/build/utils/lengths.d.ts +1 -0
  626. package/build/utils/lengths.d.ts.map +1 -0
  627. package/build/utils/lengths.js +1 -0
  628. package/build/utils/lengths.js.map +1 -0
  629. package/build/utils/types.d.ts +1 -0
  630. package/build/utils/types.d.ts.map +1 -0
  631. package/build/utils/types.js +2 -1
  632. package/build/utils/types.js.map +1 -0
  633. package/build/utxo/OPNetLimitedProvider.d.ts +39 -3
  634. package/build/utxo/OPNetLimitedProvider.d.ts.map +1 -0
  635. package/build/utxo/OPNetLimitedProvider.js +41 -3
  636. package/build/utxo/OPNetLimitedProvider.js.map +1 -0
  637. package/build/utxo/interfaces/BroadcastResponse.d.ts +1 -0
  638. package/build/utxo/interfaces/BroadcastResponse.d.ts.map +1 -0
  639. package/build/utxo/interfaces/BroadcastResponse.js +1 -0
  640. package/build/utxo/interfaces/BroadcastResponse.js.map +1 -0
  641. package/build/utxo/interfaces/IUTXO.d.ts +13 -7
  642. package/build/utxo/interfaces/IUTXO.d.ts.map +1 -0
  643. package/build/utxo/interfaces/IUTXO.js +1 -0
  644. package/build/utxo/interfaces/IUTXO.js.map +1 -0
  645. package/build/verification/TapscriptVerificator.d.ts +12 -10
  646. package/build/verification/TapscriptVerificator.d.ts.map +1 -0
  647. package/build/verification/TapscriptVerificator.js +28 -38
  648. package/build/verification/TapscriptVerificator.js.map +1 -0
  649. package/eslint.config.js +0 -1
  650. package/package.json +16 -39
  651. package/src/abi/ABICoder.ts +0 -13
  652. package/src/branded/Branded.ts +5 -0
  653. package/src/buffer/BinaryReader.ts +7 -7
  654. package/src/buffer/BinaryWriter.ts +29 -24
  655. package/src/bytecode/Compressor.ts +1 -1
  656. package/src/chain/ChainData.ts +34 -27
  657. package/src/consensus/ConsensusConfig.ts +1 -1
  658. package/src/consensus/IConsensusConfig.ts +0 -17
  659. package/src/consensus/metadata/RoswellConsensus.ts +1 -17
  660. package/src/crypto/crypto-browser.js +3 -4
  661. package/src/deterministic/AddressMap.ts +5 -1
  662. package/src/deterministic/AddressSet.ts +5 -1
  663. package/src/deterministic/CustomMap.ts +6 -2
  664. package/src/deterministic/DeterministicMap.ts +8 -4
  665. package/src/deterministic/DeterministicSet.ts +6 -2
  666. package/src/deterministic/ExtendedAddressMap.ts +9 -4
  667. package/src/deterministic/FastMap.ts +9 -5
  668. package/src/ecc/backend.ts +17 -0
  669. package/src/epoch/ChallengeSolution.ts +3 -3
  670. package/src/epoch/interfaces/IChallengeSolution.ts +13 -13
  671. package/src/epoch/validator/EpochValidator.ts +24 -43
  672. package/src/generators/AddressGenerator.ts +6 -6
  673. package/src/generators/Features.ts +3 -3
  674. package/src/generators/Generator.ts +42 -26
  675. package/src/generators/builders/CalldataGenerator.ts +26 -24
  676. package/src/generators/builders/CustomGenerator.ts +4 -4
  677. package/src/generators/builders/DeploymentGenerator.ts +25 -23
  678. package/src/generators/builders/HashCommitmentGenerator.ts +31 -31
  679. package/src/generators/builders/LegacyCalldataGenerator.ts +26 -24
  680. package/src/generators/builders/MultiSignGenerator.ts +12 -12
  681. package/src/generators/builders/P2WDAGenerator.ts +10 -10
  682. package/src/keypair/Address.ts +115 -72
  683. package/src/keypair/AddressVerificator.ts +16 -147
  684. package/src/keypair/EcKeyPair.ts +109 -118
  685. package/src/keypair/MessageSigner.ts +70 -150
  686. package/src/keypair/Wallet.ts +59 -240
  687. package/src/metadata/ContractBaseMetadata.ts +2 -2
  688. package/src/mnemonic/Mnemonic.ts +32 -221
  689. package/src/opnet.ts +12 -6
  690. package/src/p2wda/P2WDADetector.ts +23 -72
  691. package/src/polyfill/disposable.ts +29 -0
  692. package/src/signer/AddressRotation.ts +1 -1
  693. package/src/signer/IRotationSigner.ts +3 -3
  694. package/src/signer/ParallelSignerAdapter.ts +59 -0
  695. package/src/signer/SignerUtils.ts +4 -4
  696. package/src/signer/TweakedSigner.ts +28 -13
  697. package/src/transaction/ContractAddress.ts +3 -7
  698. package/src/transaction/TransactionFactory.ts +28 -50
  699. package/src/transaction/browser/BrowserSignerBase.ts +12 -6
  700. package/src/transaction/browser/Web3Provider.ts +3 -3
  701. package/src/transaction/browser/extensions/UnisatSigner.ts +52 -48
  702. package/src/transaction/browser/extensions/XverseSigner.ts +55 -38
  703. package/src/transaction/browser/types/OPWallet.ts +2 -2
  704. package/src/transaction/browser/types/Unisat.ts +1 -1
  705. package/src/transaction/builders/CancelTransaction.ts +59 -24
  706. package/src/transaction/builders/ChallengeSolutionTransaction.ts +3 -3
  707. package/src/transaction/builders/ConsolidatedInteractionTransaction.ts +39 -34
  708. package/src/transaction/builders/CustomScriptTransaction.ts +79 -56
  709. package/src/transaction/builders/DeploymentTransaction.ts +82 -63
  710. package/src/transaction/builders/FundingTransaction.ts +11 -11
  711. package/src/transaction/builders/InteractionTransaction.ts +10 -10
  712. package/src/transaction/builders/InteractionTransactionP2WDA.ts +38 -40
  713. package/src/transaction/builders/MultiSignTransaction.ts +68 -61
  714. package/src/transaction/builders/SharedInteractionTransaction.ts +81 -57
  715. package/src/transaction/builders/TransactionBuilder.ts +101 -79
  716. package/src/transaction/interfaces/ICancelTransactionParameters.ts +2 -2
  717. package/src/transaction/interfaces/IConsolidatedTransactionParameters.ts +5 -5
  718. package/src/transaction/interfaces/ICustomTransactionParameters.ts +5 -5
  719. package/src/transaction/interfaces/ITransactionParameters.ts +15 -15
  720. package/src/transaction/interfaces/ITransactionResponses.ts +2 -2
  721. package/src/transaction/interfaces/ITweakedTransactionData.ts +17 -8
  722. package/src/transaction/interfaces/IWeb3ProviderTypes.ts +3 -3
  723. package/src/transaction/interfaces/Tap.ts +3 -3
  724. package/src/transaction/mineable/IP2WSHAddress.ts +1 -1
  725. package/src/transaction/mineable/TimelockGenerator.ts +19 -12
  726. package/src/transaction/offline/OfflineTransactionManager.ts +22 -23
  727. package/src/transaction/offline/TransactionReconstructor.ts +83 -91
  728. package/src/transaction/offline/TransactionSerializer.ts +151 -101
  729. package/src/transaction/offline/TransactionStateCapture.ts +83 -79
  730. package/src/transaction/offline/interfaces/ISerializableState.ts +1 -1
  731. package/src/transaction/offline/interfaces/ITypeSpecificData.ts +1 -1
  732. package/src/transaction/shared/P2TR_MS.ts +4 -4
  733. package/src/transaction/shared/TweakedTransaction.ts +326 -124
  734. package/src/transaction/utils/WitnessUtils.ts +18 -9
  735. package/src/utils/BufferHelper.ts +39 -37
  736. package/src/utxo/OPNetLimitedProvider.ts +7 -7
  737. package/src/utxo/interfaces/IUTXO.ts +7 -7
  738. package/src/verification/TapscriptVerificator.ts +73 -86
  739. package/test/address-rotation.test.ts +24 -24
  740. package/test/address.test.ts +12 -12
  741. package/test/addressmap.test.ts +30 -30
  742. package/test/binary-reader-writer.test.ts +8 -8
  743. package/test/browser/offline-transaction.test.ts +2206 -0
  744. package/test/browser/parallel-signing.test.ts +316 -0
  745. package/test/browser/setup.ts +11 -0
  746. package/test/browser/transaction-signing.test.ts +416 -0
  747. package/test/buffer-helper.test.ts +287 -0
  748. package/test/derivePath.test.ts +4 -3
  749. package/test/disposable.test.ts +279 -0
  750. package/test/fastmap-setall.test.ts +1 -1
  751. package/test/fastmap.test.ts +3 -3
  752. package/test/messagesigner-mldsa.test.ts +3 -3
  753. package/test/messagesigner-schnorr.test.ts +9 -9
  754. package/test/offline-transaction.test.ts +461 -288
  755. package/test/old/FastBigIntMap.ts +3 -3
  756. package/test/oldfastmap.test.ts +6 -6
  757. package/test/transaction-builders.test.ts +321 -0
  758. package/tsconfig.base.json +34 -18
  759. package/tsconfig.browser.json +15 -0
  760. package/tsconfig.json +3 -8
  761. package/vite.config.browser.ts +4 -5
  762. package/vitest.config.browser.ts +68 -0
  763. package/vitest.config.ts +1 -1
  764. package/browser/valibot.js +0 -4948
  765. package/tsconfig.webpack.json +0 -18
@@ -1,11 +1,18 @@
1
1
  import { Logger } from '@btc-vision/logger';
2
- import { address as bitAddress, crypto as bitCrypto, getFinalScripts, isP2A, isP2MS, isP2PK, isP2PKH, isP2SHScript, isP2TR, isP2WPKH, isP2WSHScript, isUnknownSegwitVersion, opcodes, payments, PaymentType, script, toXOnly, varuint, } from '@btc-vision/bitcoin';
3
- import { TweakedSigner } from '../../signer/TweakedSigner.js';
2
+ import { address as bitAddress, crypto as bitCrypto, fromHex, getFinalScripts, isP2A, isP2MS, isP2PK, isP2PKH, isP2SHScript, isP2TR, isP2WPKH, isP2WSHScript, isUnknownSegwitVersion, opcodes, payments, PaymentType, Psbt, script, toXOnly, Transaction, varuint, } from '@btc-vision/bitcoin';
3
+ import { isUniversalSigner, TweakedSigner } from '../../signer/TweakedSigner.js';
4
+ import {} from '@btc-vision/ecpair';
5
+ import { UnisatSigner } from '../browser/extensions/UnisatSigner.js';
4
6
  import { canSignNonTaprootInput, isTaprootInput, pubkeyInScript, } from '../../signer/SignerUtils.js';
5
7
  import { witnessStackToScriptWitness } from '../utils/WitnessUtils.js';
6
- import { Buffer } from 'buffer';
7
8
  import { P2WDADetector } from '../../p2wda/P2WDADetector.js';
8
9
  import { MessageSigner } from '../../keypair/MessageSigner.js';
10
+ import {} from '../../signer/AddressRotation.js';
11
+ import { prepareSigningTasks, applySignaturesToPsbt, WorkerSigningPool, } from '@btc-vision/bitcoin/workers';
12
+ import { toTweakedParallelKeyPair } from '../../signer/ParallelSignerAdapter.js';
13
+ /**
14
+ * The transaction sequence
15
+ */
9
16
  export var TransactionSequence;
10
17
  (function (TransactionSequence) {
11
18
  TransactionSequence[TransactionSequence["REPLACE_BY_FEE"] = 4294967293] = "REPLACE_BY_FEE";
@@ -16,70 +23,112 @@ export var CSVModes;
16
23
  CSVModes[CSVModes["BLOCKS"] = 0] = "BLOCKS";
17
24
  CSVModes[CSVModes["TIMESTAMPS"] = 1] = "TIMESTAMPS";
18
25
  })(CSVModes || (CSVModes = {}));
26
+ /**
27
+ * @description PSBT Transaction processor.
28
+ * */
19
29
  export class TweakedTransaction extends Logger {
30
+ logColor = '#00ffe1';
31
+ finalized = false;
32
+ /**
33
+ * @description Was the transaction signed?
34
+ */
35
+ signer;
36
+ /**
37
+ * @description Tweaked signer
38
+ */
39
+ tweakedSigner;
40
+ /**
41
+ * @description The network of the transaction
42
+ */
43
+ network;
44
+ /**
45
+ * @description Was the transaction signed?
46
+ */
47
+ signed = false;
48
+ /**
49
+ * @description The sighash types of the transaction
50
+ * @protected
51
+ */
52
+ sighashTypes;
53
+ /**
54
+ * @description The script data of the transaction
55
+ */
56
+ scriptData = null;
57
+ /**
58
+ * @description The tap data of the transaction
59
+ */
60
+ tapData = null;
61
+ /**
62
+ * @description The inputs of the transaction
63
+ */
64
+ inputs = [];
65
+ /**
66
+ * @description The sequence of the transaction
67
+ * @protected
68
+ */
69
+ sequence = TransactionSequence.REPLACE_BY_FEE;
70
+ /**
71
+ * The tap leaf script
72
+ * @protected
73
+ */
74
+ tapLeafScript = null;
75
+ /**
76
+ * Add a non-witness utxo to the transaction
77
+ * @protected
78
+ */
79
+ nonWitnessUtxo;
80
+ /**
81
+ * Is the transaction being generated inside a browser?
82
+ * @protected
83
+ */
84
+ isBrowser = false;
85
+ /**
86
+ * Track which inputs contain CSV scripts
87
+ * @protected
88
+ */
89
+ csvInputIndices = new Set();
90
+ anchorInputIndices = new Set();
91
+ regenerated = false;
92
+ ignoreSignatureErrors = false;
93
+ noSignatures = false;
94
+ unlockScript;
95
+ txVersion = 2;
96
+ _mldsaSigner = null;
97
+ _hashedPublicKey = null;
98
+ /**
99
+ * Whether address rotation mode is enabled.
100
+ * When true, each UTXO can be signed by a different signer.
101
+ */
102
+ addressRotationEnabled = false;
103
+ /**
104
+ * Map of addresses to their respective signers for address rotation mode.
105
+ */
106
+ signerMap = new Map();
107
+ /**
108
+ * Map of input indices to their signers (resolved from UTXOs or signerMap).
109
+ * Populated during input addition.
110
+ */
111
+ inputSignerMap = new Map();
112
+ /**
113
+ * Cache of tweaked signers per input for address rotation mode.
114
+ */
115
+ tweakedSignerCache = new Map();
116
+ /**
117
+ * Parallel signing configuration using worker threads.
118
+ * When set, key-path taproot inputs are signed in parallel via workers.
119
+ */
120
+ parallelSigningConfig;
20
121
  constructor(data) {
21
122
  super();
22
- this.logColor = '#00ffe1';
23
- this.finalized = false;
24
- this.signed = false;
25
- this.scriptData = null;
26
- this.tapData = null;
27
- this.inputs = [];
28
- this.sequence = TransactionSequence.REPLACE_BY_FEE;
29
- this.tapLeafScript = null;
30
- this.isBrowser = false;
31
- this.csvInputIndices = new Set();
32
- this.anchorInputIndices = new Set();
33
- this.regenerated = false;
34
- this.ignoreSignatureErrors = false;
35
- this.noSignatures = false;
36
- this.txVersion = 2;
37
- this._mldsaSigner = null;
38
- this._hashedPublicKey = null;
39
- this.addressRotationEnabled = false;
40
- this.signerMap = new Map();
41
- this.inputSignerMap = new Map();
42
- this.tweakedSignerCache = new Map();
43
- this.customFinalizerP2SH = (inputIndex, input, scriptA, isSegwit, isP2SH, isP2WSH) => {
44
- const inputDecoded = this.inputs[inputIndex];
45
- if (isP2SH && input.partialSig && inputDecoded && inputDecoded.redeemScript) {
46
- const signatures = input.partialSig.map((sig) => sig.signature) || [];
47
- const scriptSig = script.compile([...signatures, inputDecoded.redeemScript]);
48
- return {
49
- finalScriptSig: scriptSig,
50
- finalScriptWitness: undefined,
51
- };
52
- }
53
- if (this.anchorInputIndices.has(inputIndex)) {
54
- return {
55
- finalScriptSig: undefined,
56
- finalScriptWitness: Buffer.from([0]),
57
- };
58
- }
59
- if (isP2WSH && isSegwit && input.witnessScript) {
60
- if (!input.partialSig || input.partialSig.length === 0) {
61
- throw new Error(`No signatures for P2WSH input #${inputIndex}`);
62
- }
63
- const isP2WDA = P2WDADetector.isP2WDAWitnessScript(input.witnessScript);
64
- if (isP2WDA) {
65
- return this.finalizeSecondaryP2WDA(inputIndex, input);
66
- }
67
- const isCSVInput = this.csvInputIndices.has(inputIndex);
68
- if (isCSVInput) {
69
- const witnessStack = [input.partialSig[0].signature, input.witnessScript];
70
- return {
71
- finalScriptSig: undefined,
72
- finalScriptWitness: witnessStackToScriptWitness(witnessStack),
73
- };
74
- }
75
- }
76
- return getFinalScripts(inputIndex, input, scriptA, isSegwit, isP2SH, isP2WSH, true, this.unlockScript);
77
- };
78
123
  this.signer = data.signer;
79
124
  this.network = data.network;
80
125
  this.noSignatures = data.noSignatures || false;
81
- this.nonWitnessUtxo = data.nonWitnessUtxo;
82
- this.unlockScript = data.unlockScript;
126
+ if (data.nonWitnessUtxo !== undefined) {
127
+ this.nonWitnessUtxo = data.nonWitnessUtxo;
128
+ }
129
+ if (data.unlockScript !== undefined) {
130
+ this.unlockScript = data.unlockScript;
131
+ }
83
132
  this.isBrowser = typeof window !== 'undefined';
84
133
  if (data.txVersion) {
85
134
  this.txVersion = data.txVersion;
@@ -88,27 +137,55 @@ export class TweakedTransaction extends Logger {
88
137
  this._mldsaSigner = data.mldsaSigner;
89
138
  this._hashedPublicKey = MessageSigner.sha256(this._mldsaSigner.publicKey);
90
139
  }
140
+ // Initialize address rotation
91
141
  if (data.addressRotation?.enabled) {
92
142
  this.addressRotationEnabled = true;
93
143
  this.signerMap = data.addressRotation.signerMap;
94
144
  }
145
+ if (data.parallelSigning) {
146
+ this.parallelSigningConfig = data.parallelSigning;
147
+ }
148
+ }
149
+ [Symbol.dispose]() {
150
+ this.inputs.length = 0;
151
+ this.scriptData = null;
152
+ this.tapData = null;
153
+ this.tapLeafScript = null;
154
+ delete this.tweakedSigner;
155
+ this.csvInputIndices.clear();
156
+ this.anchorInputIndices.clear();
157
+ this.inputSignerMap.clear();
158
+ this.tweakedSignerCache.clear();
159
+ delete this.parallelSigningConfig;
95
160
  }
161
+ /**
162
+ * Get the MLDSA signer
163
+ * @protected
164
+ */
96
165
  get mldsaSigner() {
97
166
  if (!this._mldsaSigner) {
98
167
  throw new Error('MLDSA Signer is not set');
99
168
  }
100
169
  return this._mldsaSigner;
101
170
  }
171
+ /**
172
+ * Get the hashed public key
173
+ * @protected
174
+ */
102
175
  get hashedPublicKey() {
103
176
  if (!this._hashedPublicKey) {
104
177
  throw new Error('Hashed public key is not set');
105
178
  }
106
179
  return this._hashedPublicKey;
107
180
  }
181
+ /**
182
+ * Read witnesses
183
+ * @protected
184
+ */
108
185
  static readScriptWitnessToWitnessStack(buffer) {
109
186
  let offset = 0;
110
187
  function readSlice(n) {
111
- const slice = Buffer.from(buffer.subarray(offset, offset + n));
188
+ const slice = new Uint8Array(buffer.subarray(offset, offset + n));
112
189
  offset += n;
113
190
  return slice;
114
191
  }
@@ -131,17 +208,33 @@ export class TweakedTransaction extends Logger {
131
208
  }
132
209
  return readVector();
133
210
  }
134
- static preEstimateTaprootTransactionFees(feeRate, numInputs, numOutputs, numWitnessElements, witnessElementSize, emptyWitness, taprootControlWitnessSize = 32n, taprootScriptSize = 139n) {
211
+ /**
212
+ * Pre-estimate the transaction fees for a Taproot transaction
213
+ * @param {bigint} feeRate - The fee rate in satoshis per virtual byte
214
+ * @param {bigint} numInputs - The number of inputs
215
+ * @param {bigint} numOutputs - The number of outputs
216
+ * @param {bigint} numWitnessElements - The number of witness elements (e.g., number of control blocks and witnesses)
217
+ * @param {bigint} witnessElementSize - The average size of each witness element in bytes
218
+ * @param {bigint} emptyWitness - The amount of empty witnesses
219
+ * @param {bigint} [taprootControlWitnessSize=139n] - The size of the control block witness in bytes
220
+ * @param {bigint} [taprootScriptSize=32n] - The size of the taproot script in bytes
221
+ * @returns {bigint} - The estimated transaction fees
222
+ */
223
+ static preEstimateTaprootTransactionFees(feeRate, // satoshis per virtual byte
224
+ numInputs, numOutputs, numWitnessElements, witnessElementSize, emptyWitness, taprootControlWitnessSize = 32n, taprootScriptSize = 139n) {
135
225
  const txHeaderSize = 10n;
136
226
  const inputBaseSize = 41n;
137
227
  const outputSize = 68n;
138
- const taprootWitnessBaseSize = 1n;
228
+ const taprootWitnessBaseSize = 1n; // Base witness size per input (without signatures and control blocks)
229
+ // Base transaction size (excluding witness data)
139
230
  const baseTxSize = txHeaderSize + inputBaseSize * numInputs + outputSize * numOutputs;
231
+ // Witness data size for Taproot
140
232
  const witnessSize = numInputs * taprootWitnessBaseSize +
141
233
  numWitnessElements * witnessElementSize +
142
234
  taprootControlWitnessSize * numInputs +
143
235
  taprootScriptSize * numInputs +
144
236
  emptyWitness;
237
+ // Total weight and virtual size
145
238
  const weight = baseTxSize * 3n + (baseTxSize + witnessSize);
146
239
  const vSize = weight / 4n;
147
240
  return vSize * feeRate;
@@ -151,6 +244,12 @@ export class TweakedTransaction extends Logger {
151
244
  input.sighashType = sighashTypes[0];
152
245
  transaction.signInput(i, signer, sighashTypes.length ? sighashTypes : undefined);
153
246
  }
247
+ /**
248
+ * Calculate the sign hash number
249
+ * @description Calculates the sign hash
250
+ * @protected
251
+ * @returns {number}
252
+ */
154
253
  static calculateSignHash(sighashTypes) {
155
254
  if (!sighashTypes) {
156
255
  throw new Error('Sighash types are required');
@@ -161,54 +260,98 @@ export class TweakedTransaction extends Logger {
161
260
  }
162
261
  return signHash || 0;
163
262
  }
263
+ /**
264
+ * Check if address rotation mode is enabled.
265
+ */
164
266
  isAddressRotationEnabled() {
165
267
  return this.addressRotationEnabled;
166
268
  }
167
269
  ignoreSignatureError() {
168
270
  this.ignoreSignatureErrors = true;
169
271
  }
272
+ /**
273
+ * @description Returns the script address
274
+ * @returns {string}
275
+ */
170
276
  getScriptAddress() {
171
277
  if (!this.scriptData || !this.scriptData.address) {
172
278
  throw new Error('Tap data is required');
173
279
  }
174
280
  return this.scriptData.address;
175
281
  }
282
+ /**
283
+ * @description Returns the transaction
284
+ * @returns {Transaction}
285
+ */
176
286
  getTransaction() {
177
287
  return this.transaction.extractTransaction(false);
178
288
  }
289
+ /**
290
+ * @description Returns the tap address
291
+ * @returns {string}
292
+ * @throws {Error} - If tap data is not set
293
+ */
179
294
  getTapAddress() {
180
295
  if (!this.tapData || !this.tapData.address) {
181
296
  throw new Error('Tap data is required');
182
297
  }
183
298
  return this.tapData.address;
184
299
  }
300
+ /**
301
+ * @description Disables replace by fee on the transaction
302
+ */
185
303
  disableRBF() {
186
304
  if (this.signed)
187
305
  throw new Error('Transaction is already signed');
188
306
  this.sequence = TransactionSequence.FINAL;
189
307
  for (const input of this.inputs) {
308
+ // This would disable CSV! You need to check if the input has CSV
190
309
  if (this.csvInputIndices.has(this.inputs.indexOf(input))) {
191
310
  continue;
192
311
  }
193
312
  input.sequence = TransactionSequence.FINAL;
194
313
  }
195
314
  }
315
+ /**
316
+ * Get the tweaked hash
317
+ * @private
318
+ *
319
+ * @returns {Buffer | undefined} The tweaked hash
320
+ */
196
321
  getTweakerHash() {
197
322
  return this.tapData?.hash;
198
323
  }
199
- preEstimateTransactionFees(feeRate, numInputs, numOutputs, numSignatures, numPubkeys) {
324
+ /**
325
+ * Pre-estimate the transaction fees
326
+ * @param {bigint} feeRate - The fee rate
327
+ * @param {bigint} numInputs - The number of inputs
328
+ * @param {bigint} numOutputs - The number of outputs
329
+ * @param {bigint} numSignatures - The number of signatures
330
+ * @param {bigint} numPubkeys - The number of public keys
331
+ * @returns {bigint} - The estimated transaction fees
332
+ */
333
+ preEstimateTransactionFees(feeRate, // satoshis per byte
334
+ numInputs, numOutputs, numSignatures, numPubkeys) {
200
335
  const txHeaderSize = 10n;
201
336
  const inputBaseSize = 41n;
202
337
  const outputSize = 68n;
203
338
  const signatureSize = 144n;
204
339
  const pubkeySize = 34n;
340
+ // Base transaction size (excluding witness data)
205
341
  const baseTxSize = txHeaderSize + inputBaseSize * numInputs + outputSize * numOutputs;
342
+ // Witness data size
206
343
  const redeemScriptSize = 1n + numPubkeys * (1n + pubkeySize) + 1n + numSignatures;
207
344
  const witnessSize = numSignatures * signatureSize + numPubkeys * pubkeySize + redeemScriptSize;
345
+ // Total weight and virtual size
208
346
  const weight = baseTxSize * 3n + (baseTxSize + witnessSize);
209
347
  const vSize = weight / 4n;
210
348
  return vSize * feeRate;
211
349
  }
350
+ /**
351
+ * Get the signer for a specific input index.
352
+ * Returns the input-specific signer if in rotation mode, otherwise the default signer.
353
+ * @param inputIndex - The index of the input
354
+ */
212
355
  getSignerForInput(inputIndex) {
213
356
  if (this.addressRotationEnabled) {
214
357
  const inputSigner = this.inputSignerMap.get(inputIndex);
@@ -218,14 +361,22 @@ export class TweakedTransaction extends Logger {
218
361
  }
219
362
  return this.signer;
220
363
  }
364
+ /**
365
+ * Register a signer for a specific input index.
366
+ * Called during UTXO processing to map each input to its signer.
367
+ * @param inputIndex - The index of the input
368
+ * @param utxo - The UTXO being added
369
+ */
221
370
  registerInputSigner(inputIndex, utxo) {
222
371
  if (!this.addressRotationEnabled) {
223
372
  return;
224
373
  }
374
+ // Priority 1: UTXO has an explicit signer attached
225
375
  if (utxo.signer) {
226
376
  this.inputSignerMap.set(inputIndex, utxo.signer);
227
377
  return;
228
378
  }
379
+ // Priority 2: Look up signer from signerMap by address
229
380
  const address = utxo.scriptPubKey?.address;
230
381
  if (address && this.signerMap.has(address)) {
231
382
  const signer = this.signerMap.get(address);
@@ -234,19 +385,33 @@ export class TweakedTransaction extends Logger {
234
385
  return;
235
386
  }
236
387
  }
388
+ // Fallback: Use default signer (no entry in inputSignerMap)
237
389
  }
390
+ /**
391
+ * Get the x-only public key for a specific input's signer.
392
+ * Used for taproot inputs in address rotation mode.
393
+ * @param inputIndex - The index of the input
394
+ */
238
395
  internalPubKeyToXOnlyForInput(inputIndex) {
239
396
  const signer = this.getSignerForInput(inputIndex);
240
- return toXOnly(Buffer.from(signer.publicKey));
397
+ return toXOnly(signer.publicKey);
241
398
  }
399
+ /**
400
+ * Get the tweaked signer for a specific input.
401
+ * Caches the result for efficiency.
402
+ * @param inputIndex - The index of the input
403
+ * @param useTweakedHash - Whether to use the tweaked hash
404
+ */
242
405
  getTweakedSignerForInput(inputIndex, useTweakedHash = false) {
243
406
  if (!this.addressRotationEnabled) {
407
+ // Fall back to original behavior
244
408
  if (useTweakedHash) {
245
409
  this.tweakSigner();
246
410
  return this.tweakedSigner;
247
411
  }
248
412
  return this.getTweakedSigner(useTweakedHash);
249
413
  }
414
+ // Check cache
250
415
  const cacheKey = inputIndex * 2 + (useTweakedHash ? 1 : 0);
251
416
  if (this.tweakedSignerCache.has(cacheKey)) {
252
417
  return this.tweakedSignerCache.get(cacheKey);
@@ -263,6 +428,11 @@ export class TweakedTransaction extends Logger {
263
428
  name: PaymentType.P2TR,
264
429
  };
265
430
  }
431
+ /**
432
+ * Generates the script address.
433
+ * @protected
434
+ * @returns {Payment}
435
+ */
266
436
  generateScriptAddress() {
267
437
  return {
268
438
  internalPubkey: this.internalPubKeyToXOnly(),
@@ -270,9 +440,24 @@ export class TweakedTransaction extends Logger {
270
440
  name: PaymentType.P2TR,
271
441
  };
272
442
  }
443
+ /**
444
+ * Returns the signer key.
445
+ * @protected
446
+ * @returns {Signer | UniversalSigner}
447
+ */
273
448
  getSignerKey() {
274
449
  return this.signer;
275
450
  }
451
+ /**
452
+ * Signs an input of the transaction.
453
+ * @param {Psbt} transaction - The transaction to sign
454
+ * @param {PsbtInput} input - The input to sign
455
+ * @param {number} i - The index of the input
456
+ * @param {Signer} signer - The signer to use
457
+ * @param {boolean} [reverse=false] - Should the input be signed in reverse
458
+ * @param {boolean} [errored=false] - Was there an error
459
+ * @protected
460
+ */
276
461
  async signInput(transaction, input, i, signer, reverse = false, errored = false) {
277
462
  if (this.anchorInputIndices.has(i))
278
463
  return;
@@ -294,6 +479,7 @@ export class TweakedTransaction extends Logger {
294
479
  }
295
480
  }
296
481
  else {
482
+ // Non-Taproot input
297
483
  if (!reverse ? canSignNonTaprootInput(input, publicKey) : true) {
298
484
  try {
299
485
  await this.signNonTaprootInput(signer, transaction, i);
@@ -327,6 +513,12 @@ export class TweakedTransaction extends Logger {
327
513
  }
328
514
  return result;
329
515
  }
516
+ /**
517
+ * Signs all the inputs of the transaction.
518
+ * @param {Psbt} transaction - The transaction to sign
519
+ * @protected
520
+ * @returns {Promise<void>}
521
+ */
330
522
  async signInputs(transaction) {
331
523
  if ('multiSignPsbt' in this.signer) {
332
524
  await this.signInputsWalletBased(transaction);
@@ -335,26 +527,23 @@ export class TweakedTransaction extends Logger {
335
527
  await this.signInputsNonWalletBased(transaction);
336
528
  }
337
529
  async signInputsNonWalletBased(transaction) {
338
- const txs = transaction.data.inputs;
339
- const batchSize = 20;
340
- const batches = this.splitArray(txs, batchSize);
341
530
  if (!this.noSignatures) {
342
- for (let i = 0; i < batches.length; i++) {
343
- const batch = batches[i];
344
- const promises = [];
345
- const offset = i * batchSize;
346
- for (let j = 0; j < batch.length; j++) {
347
- const index = offset + j;
348
- const input = batch[j];
349
- try {
350
- const inputSigner = this.getSignerForInput(index);
351
- promises.push(this.signInput(transaction, input, index, inputSigner));
352
- }
353
- catch (e) {
354
- this.log(`Failed to sign input ${index}: ${e.stack}`);
531
+ if (this.canUseParallelSigning && isUniversalSigner(this.signer)) {
532
+ let parallelSignedIndices = new Set();
533
+ try {
534
+ const result = await this.signKeyPathInputsParallel(transaction);
535
+ if (result.success) {
536
+ parallelSignedIndices = new Set(result.signatures.keys());
355
537
  }
356
538
  }
357
- await Promise.all(promises);
539
+ catch (e) {
540
+ this.error(`Parallel signing failed, falling back to sequential: ${e.message}`);
541
+ }
542
+ // Sign remaining inputs (script-path, non-taproot, etc.) sequentially
543
+ await this.signRemainingInputsSequential(transaction, parallelSignedIndices);
544
+ }
545
+ else {
546
+ await this.signInputsSequential(transaction);
358
547
  }
359
548
  }
360
549
  for (let i = 0; i < transaction.data.inputs.length; i++) {
@@ -362,35 +551,189 @@ export class TweakedTransaction extends Logger {
362
551
  }
363
552
  this.finalized = true;
364
553
  }
554
+ /**
555
+ * Signs all inputs sequentially in batches of 20.
556
+ * This is the original signing logic, used as fallback when parallel signing is unavailable.
557
+ */
558
+ async signInputsSequential(transaction) {
559
+ const txs = transaction.data.inputs;
560
+ const batchSize = 20;
561
+ const batches = this.splitArray(txs, batchSize);
562
+ for (let i = 0; i < batches.length; i++) {
563
+ const batch = batches[i];
564
+ const promises = [];
565
+ const offset = i * batchSize;
566
+ for (let j = 0; j < batch.length; j++) {
567
+ const index = offset + j;
568
+ const input = batch[j];
569
+ try {
570
+ // Use per-input signer in address rotation mode
571
+ const inputSigner = this.getSignerForInput(index);
572
+ promises.push(this.signInput(transaction, input, index, inputSigner));
573
+ }
574
+ catch (e) {
575
+ this.log(`Failed to sign input ${index}: ${e.stack}`);
576
+ }
577
+ }
578
+ await Promise.all(promises);
579
+ }
580
+ }
581
+ /**
582
+ * Signs inputs that were not handled by parallel signing.
583
+ * After parallel key-path signing, script-path taproot inputs, non-taproot inputs,
584
+ * and any inputs that failed parallel signing need sequential signing.
585
+ */
586
+ async signRemainingInputsSequential(transaction, signedIndices) {
587
+ const txs = transaction.data.inputs;
588
+ const unsignedIndices = [];
589
+ for (let i = 0; i < txs.length; i++) {
590
+ if (!signedIndices.has(i)) {
591
+ unsignedIndices.push(i);
592
+ }
593
+ }
594
+ if (unsignedIndices.length === 0)
595
+ return;
596
+ const batchSize = 20;
597
+ const batches = this.splitArray(unsignedIndices, batchSize);
598
+ for (const batch of batches) {
599
+ const promises = [];
600
+ for (const index of batch) {
601
+ const input = txs[index];
602
+ try {
603
+ const inputSigner = this.getSignerForInput(index);
604
+ promises.push(this.signInput(transaction, input, index, inputSigner));
605
+ }
606
+ catch (e) {
607
+ this.log(`Failed to sign input ${index}: ${e.stack}`);
608
+ }
609
+ }
610
+ await Promise.all(promises);
611
+ }
612
+ }
613
+ /**
614
+ * Converts the public key to x-only.
615
+ * @protected
616
+ * @returns {Buffer}
617
+ */
365
618
  internalPubKeyToXOnly() {
366
- return toXOnly(Buffer.from(this.signer.publicKey));
619
+ return toXOnly(this.signer.publicKey);
367
620
  }
621
+ /**
622
+ * Internal init.
623
+ * @protected
624
+ */
368
625
  internalInit() {
369
626
  this.scriptData = payments.p2tr(this.generateScriptAddress());
370
627
  this.tapData = payments.p2tr(this.generateTapData());
371
628
  }
629
+ /**
630
+ * Tweak the signer for the interaction
631
+ * @protected
632
+ */
372
633
  tweakSigner() {
373
634
  if (this.tweakedSigner)
374
635
  return;
375
- this.tweakedSigner = this.getTweakedSigner(true);
636
+ // tweaked p2tr signer.
637
+ const tweaked = this.getTweakedSigner(true);
638
+ if (tweaked !== undefined) {
639
+ this.tweakedSigner = tweaked;
640
+ }
376
641
  }
642
+ /**
643
+ * Get the tweaked signer
644
+ * @private
645
+ * @returns {UniversalSigner} The tweaked signer
646
+ */
377
647
  getTweakedSigner(useTweakedHash = false, signer = this.signer) {
378
648
  const settings = {
379
649
  network: this.network,
380
650
  };
381
651
  if (useTweakedHash) {
382
- settings.tweakHash = this.getTweakerHash();
652
+ const tweakHash = this.getTweakerHash();
653
+ if (tweakHash !== undefined) {
654
+ settings.tweakHash = tweakHash;
655
+ }
383
656
  }
384
- if (!('privateKey' in signer)) {
657
+ if (!isUniversalSigner(signer)) {
385
658
  return;
386
659
  }
387
660
  return TweakedSigner.tweakSigner(signer, settings);
388
661
  }
662
+ /**
663
+ * Whether parallel signing can be used for this transaction.
664
+ * Requires parallelSigningConfig and excludes browser, address rotation, and no-signature modes.
665
+ */
666
+ get canUseParallelSigning() {
667
+ return (!!this.parallelSigningConfig &&
668
+ !this.addressRotationEnabled &&
669
+ !this.noSignatures);
670
+ }
671
+ /**
672
+ * Signs key-path taproot inputs in parallel using worker threads.
673
+ * @param transaction - The PSBT to sign
674
+ * @param excludeIndices - Input indices to skip (e.g., script-path inputs already signed)
675
+ * @returns The parallel signing result
676
+ */
677
+ async signKeyPathInputsParallel(transaction, excludeIndices) {
678
+ const signer = this.signer;
679
+ // Get the tweaked signer for key-path
680
+ const tweakedSigner = this.getTweakedSigner(true);
681
+ if (!tweakedSigner) {
682
+ throw new Error('Cannot create tweaked signer for parallel signing');
683
+ }
684
+ // Create hybrid adapter: untweaked pubkey (for PSBT matching) + tweaked privkey
685
+ const adapter = toTweakedParallelKeyPair(signer, tweakedSigner);
686
+ // Prepare tasks from PSBT
687
+ const allTasks = prepareSigningTasks(transaction, adapter);
688
+ // Filter out excluded indices
689
+ const tasks = excludeIndices
690
+ ? allTasks.filter((t) => !excludeIndices.has(t.inputIndex))
691
+ : allTasks;
692
+ if (tasks.length === 0) {
693
+ return {
694
+ success: true,
695
+ signatures: new Map(),
696
+ errors: new Map(),
697
+ durationMs: 0,
698
+ };
699
+ }
700
+ // Get or create pool
701
+ let pool;
702
+ let shouldShutdown = false;
703
+ if (this.parallelSigningConfig instanceof WorkerSigningPool) {
704
+ pool = this.parallelSigningConfig;
705
+ }
706
+ else {
707
+ pool = WorkerSigningPool.getInstance(this.parallelSigningConfig);
708
+ if (!pool.isPreservingWorkers)
709
+ shouldShutdown = true;
710
+ }
711
+ try {
712
+ await pool.initialize();
713
+ const result = await pool.signBatch(tasks, adapter);
714
+ if (result.success) {
715
+ applySignaturesToPsbt(transaction, result, adapter);
716
+ }
717
+ else {
718
+ const errorEntries = [...result.errors.entries()];
719
+ const errorMsg = errorEntries
720
+ .map(([idx, err]) => `Input ${idx}: ${err}`)
721
+ .join(', ');
722
+ this.error(`Parallel signing had errors: ${errorMsg}`);
723
+ }
724
+ return result;
725
+ }
726
+ finally {
727
+ if (shouldShutdown)
728
+ await pool.shutdown();
729
+ }
730
+ }
389
731
  generateP2SHRedeemScript(customWitnessScript) {
390
732
  const p2wsh = payments.p2wsh({
391
733
  redeem: { output: customWitnessScript },
392
734
  network: this.network,
393
735
  });
736
+ // Step 2: Wrap the P2WSH inside a P2SH (Pay-to-Script-Hash)
394
737
  const p2sh = payments.p2sh({
395
738
  redeem: p2wsh,
396
739
  network: this.network,
@@ -413,11 +756,12 @@ export class TweakedTransaction extends Logger {
413
756
  opcodes.OP_EQUAL,
414
757
  ]);
415
758
  const p2wsh = payments.p2wsh({
416
- redeem: { output: redeemScript },
759
+ redeem: { output: redeemScript }, // Use the custom redeem script
417
760
  network: this.network,
418
761
  });
762
+ // Step 3: Wrap the P2WSH in a P2SH
419
763
  const p2sh = payments.p2sh({
420
- redeem: p2wsh,
764
+ redeem: p2wsh, // The P2WSH is wrapped inside the P2SH
421
765
  network: this.network,
422
766
  });
423
767
  const address = bitAddress.fromOutputScript(outputScript, this.network);
@@ -430,12 +774,11 @@ export class TweakedTransaction extends Logger {
430
774
  return;
431
775
  }
432
776
  generateP2SHP2PKHRedeemScript(inputAddr, inputIndex) {
777
+ // Use per-input signer in address rotation mode
433
778
  const signer = this.addressRotationEnabled && inputIndex !== undefined
434
779
  ? this.getSignerForInput(inputIndex)
435
780
  : this.signer;
436
- const pubkey = Buffer.isBuffer(signer.publicKey)
437
- ? signer.publicKey
438
- : Buffer.from(signer.publicKey, 'hex');
781
+ const pubkey = signer.publicKey;
439
782
  const w = payments.p2wpkh({
440
783
  pubkey: pubkey,
441
784
  network: this.network,
@@ -457,40 +800,60 @@ export class TweakedTransaction extends Logger {
457
800
  }
458
801
  return;
459
802
  }
803
+ /**
804
+ * Generate the PSBT input extended, supporting various script types
805
+ * @param {UTXO} utxo The UTXO
806
+ * @param {number} i The index of the input
807
+ * @param {UTXO} _extra Extra UTXO
808
+ * @protected
809
+ * @returns {PsbtInputExtended} The PSBT input extended
810
+ */
460
811
  generatePsbtInputExtended(utxo, i, _extra = false) {
461
- const scriptPub = Buffer.from(utxo.scriptPubKey.hex, 'hex');
812
+ const scriptPub = fromHex(utxo.scriptPubKey.hex);
462
813
  const input = {
463
814
  hash: utxo.transactionId,
464
815
  index: utxo.outputIndex,
465
816
  sequence: this.sequence,
466
817
  witnessUtxo: {
467
- value: Number(utxo.value),
818
+ value: utxo.value,
468
819
  script: scriptPub,
469
820
  },
470
821
  };
822
+ // Handle P2PKH (Legacy)
471
823
  if (isP2PKH(scriptPub)) {
824
+ // Legacy input requires nonWitnessUtxo
472
825
  if (utxo.nonWitnessUtxo) {
473
- input.nonWitnessUtxo = Buffer.isBuffer(utxo.nonWitnessUtxo)
474
- ? utxo.nonWitnessUtxo
475
- : Buffer.from(utxo.nonWitnessUtxo, 'hex');
826
+ //delete input.witnessUtxo;
827
+ input.nonWitnessUtxo =
828
+ utxo.nonWitnessUtxo instanceof Uint8Array
829
+ ? utxo.nonWitnessUtxo
830
+ : fromHex(utxo.nonWitnessUtxo);
476
831
  }
477
832
  else {
478
833
  throw new Error('Missing nonWitnessUtxo for P2PKH UTXO');
479
834
  }
480
835
  }
836
+ // Handle P2WPKH (SegWit)
481
837
  else if (isP2WPKH(scriptPub) || isUnknownSegwitVersion(scriptPub)) {
838
+ // No redeemScript required for pure P2WPKH
839
+ // witnessUtxo is enough, no nonWitnessUtxo needed.
482
840
  }
841
+ // Handle P2WSH (SegWit)
483
842
  else if (isP2WSHScript(scriptPub)) {
484
843
  this.processP2WSHInput(utxo, input, i);
485
844
  }
845
+ // Handle P2SH (Can be legacy or wrapping segwit)
486
846
  else if (isP2SHScript(scriptPub)) {
847
+ // Redeem script is required for P2SH
487
848
  let redeemScriptBuf;
488
849
  if (utxo.redeemScript) {
489
- redeemScriptBuf = Buffer.isBuffer(utxo.redeemScript)
490
- ? utxo.redeemScript
491
- : Buffer.from(utxo.redeemScript, 'hex');
850
+ redeemScriptBuf =
851
+ utxo.redeemScript instanceof Uint8Array
852
+ ? utxo.redeemScript
853
+ : fromHex(utxo.redeemScript);
492
854
  }
493
855
  else {
856
+ // Attempt to generate a redeem script if missing
494
857
  if (!utxo.scriptPubKey.address) {
495
858
  throw new Error('Missing redeemScript and no address to regenerate it for P2SH UTXO');
496
859
  }
@@ -501,6 +864,7 @@ export class TweakedTransaction extends Logger {
501
864
  redeemScriptBuf = legacyScripts.redeemScript;
502
865
  }
503
866
  input.redeemScript = redeemScriptBuf;
867
+ // Check if redeemScript is wrapping segwit (like P2SH-P2WPKH or P2SH-P2WSH)
504
868
  const payment = payments.p2sh({ redeem: { output: input.redeemScript } });
505
869
  if (!payment.redeem) {
506
870
  throw new Error('Failed to extract redeem script from P2SH UTXO');
@@ -510,27 +874,39 @@ export class TweakedTransaction extends Logger {
510
874
  throw new Error('Failed to extract redeem output from P2SH UTXO');
511
875
  }
512
876
  if (utxo.nonWitnessUtxo) {
513
- input.nonWitnessUtxo = Buffer.isBuffer(utxo.nonWitnessUtxo)
514
- ? utxo.nonWitnessUtxo
515
- : Buffer.from(utxo.nonWitnessUtxo, 'hex');
877
+ input.nonWitnessUtxo =
878
+ utxo.nonWitnessUtxo instanceof Uint8Array
879
+ ? utxo.nonWitnessUtxo
880
+ : fromHex(utxo.nonWitnessUtxo);
516
881
  }
517
882
  if (isP2WPKH(redeemOutput)) {
518
- Reflect.deleteProperty(input, 'nonWitnessUtxo');
883
+ // P2SH-P2WPKH
884
+ // Use witnessUtxo + redeemScript
885
+ Reflect.deleteProperty(input, 'nonWitnessUtxo'); // ensure we do NOT have nonWitnessUtxo
886
+ // witnessScript is not needed
519
887
  }
520
888
  else if (isP2WSHScript(redeemOutput)) {
521
- Reflect.deleteProperty(input, 'nonWitnessUtxo');
889
+ // P2SH-P2WSH
890
+ // Use witnessUtxo + redeemScript + witnessScript
891
+ Reflect.deleteProperty(input, 'nonWitnessUtxo'); // ensure we do NOT have nonWitnessUtxo
522
892
  this.processP2WSHInput(utxo, input, i);
523
893
  }
524
894
  else {
525
- Reflect.deleteProperty(input, 'witnessUtxo');
895
+ // Legacy P2SH
896
+ // Use nonWitnessUtxo
897
+ Reflect.deleteProperty(input, 'witnessUtxo'); // ensure we do NOT have witnessUtxo
526
898
  }
527
899
  }
900
+ // Handle P2TR (Taproot)
528
901
  else if (isP2TR(scriptPub)) {
902
+ // Taproot inputs do not require nonWitnessUtxo, witnessUtxo is sufficient.
903
+ // If there's a configured sighash type
529
904
  if (this.sighashTypes) {
530
905
  const inputSign = TweakedTransaction.calculateSignHash(this.sighashTypes);
531
906
  if (inputSign)
532
907
  input.sighashType = inputSign;
533
908
  }
909
+ // Taproot internal key - use per-input signer in address rotation mode
534
910
  if (this.addressRotationEnabled) {
535
911
  input.tapInternalKey = this.internalPubKeyToXOnlyForInput(i);
536
912
  }
@@ -539,15 +915,19 @@ export class TweakedTransaction extends Logger {
539
915
  input.tapInternalKey = this.internalPubKeyToXOnly();
540
916
  }
541
917
  }
918
+ // Handle P2A (Any SegWit version, future versions)
542
919
  else if (isP2A(scriptPub)) {
543
920
  this.anchorInputIndices.add(i);
544
921
  input.isPayToAnchor = true;
545
922
  }
923
+ // Handle P2PK (legacy) or P2MS (bare multisig)
546
924
  else if (isP2PK(scriptPub) || isP2MS(scriptPub)) {
925
+ // These are legacy scripts, need nonWitnessUtxo
547
926
  if (utxo.nonWitnessUtxo) {
548
- input.nonWitnessUtxo = Buffer.isBuffer(utxo.nonWitnessUtxo)
549
- ? utxo.nonWitnessUtxo
550
- : Buffer.from(utxo.nonWitnessUtxo, 'hex');
927
+ input.nonWitnessUtxo =
928
+ utxo.nonWitnessUtxo instanceof Uint8Array
929
+ ? utxo.nonWitnessUtxo
930
+ : fromHex(utxo.nonWitnessUtxo);
551
931
  }
552
932
  else {
553
933
  throw new Error('Missing nonWitnessUtxo for P2PK or P2MS UTXO');
@@ -557,6 +937,7 @@ export class TweakedTransaction extends Logger {
557
937
  this.error(`Unknown or unsupported script type for output: ${utxo.scriptPubKey.hex}`);
558
938
  }
559
939
  if (i === 0) {
940
+ // TapLeafScript if available
560
941
  if (this.tapLeafScript) {
561
942
  input.tapLeafScript = [this.tapLeafScript];
562
943
  }
@@ -564,21 +945,38 @@ export class TweakedTransaction extends Logger {
564
945
  input.nonWitnessUtxo = this.nonWitnessUtxo;
565
946
  }
566
947
  }
948
+ /*if (utxo.nonWitnessUtxo && extra) {
949
+ const witness = Buffer.isBuffer(utxo.nonWitnessUtxo)
950
+ ? utxo.nonWitnessUtxo
951
+ : typeof utxo.nonWitnessUtxo === 'string'
952
+ ? Buffer.from(utxo.nonWitnessUtxo, 'hex')
953
+ : (utxo.nonWitnessUtxo as unknown) instanceof Uint8Array
954
+ ? Buffer.from(utxo.nonWitnessUtxo)
955
+ : undefined;
956
+
957
+ input.nonWitnessUtxo = witness;
958
+ }*/
567
959
  return input;
568
960
  }
569
961
  processP2WSHInput(utxo, input, i) {
962
+ // P2WSH requires a witnessScript
570
963
  if (!utxo.witnessScript) {
964
+ // Can't just invent a witnessScript out of thin air. If not provided, it's an error.
571
965
  throw new Error('Missing witnessScript for P2WSH UTXO');
572
966
  }
573
- input.witnessScript = Buffer.isBuffer(utxo.witnessScript)
574
- ? utxo.witnessScript
575
- : Buffer.from(utxo.witnessScript, 'hex');
967
+ input.witnessScript =
968
+ utxo.witnessScript instanceof Uint8Array
969
+ ? utxo.witnessScript
970
+ : fromHex(utxo.witnessScript);
971
+ // No nonWitnessUtxo needed for segwit
576
972
  const decompiled = script.decompile(input.witnessScript);
577
973
  if (decompiled && this.isCSVScript(decompiled)) {
578
974
  const decompiled = script.decompile(input.witnessScript);
579
975
  if (decompiled && this.isCSVScript(decompiled)) {
580
976
  this.csvInputIndices.add(i);
977
+ // Extract CSV value from witness script
581
978
  const csvBlocks = this.extractCSVBlocks(decompiled);
979
+ // Use the setCSVSequence method to properly set the sequence
582
980
  input.sequence = this.setCSVSequence(csvBlocks, this.sequence);
583
981
  }
584
982
  }
@@ -599,6 +997,47 @@ export class TweakedTransaction extends Logger {
599
997
  extractCSVValue(sequence) {
600
998
  return sequence & 0x0000ffff;
601
999
  }
1000
+ customFinalizerP2SH = (inputIndex, input, scriptA, isSegwit, isP2SH, isP2WSH, _canRunChecks) => {
1001
+ const inputDecoded = this.inputs[inputIndex];
1002
+ if (isP2SH && input.partialSig && inputDecoded && inputDecoded.redeemScript) {
1003
+ const signatures = input.partialSig.map((sig) => sig.signature) || [];
1004
+ const scriptSig = script.compile([...signatures, inputDecoded.redeemScript]);
1005
+ return {
1006
+ finalScriptSig: scriptSig,
1007
+ finalScriptWitness: undefined,
1008
+ };
1009
+ }
1010
+ if (this.anchorInputIndices.has(inputIndex)) {
1011
+ return {
1012
+ finalScriptSig: undefined,
1013
+ finalScriptWitness: Uint8Array.from([0]),
1014
+ };
1015
+ }
1016
+ if (isP2WSH && isSegwit && input.witnessScript) {
1017
+ if (!input.partialSig || input.partialSig.length === 0) {
1018
+ throw new Error(`No signatures for P2WSH input #${inputIndex}`);
1019
+ }
1020
+ const isP2WDA = P2WDADetector.isP2WDAWitnessScript(input.witnessScript);
1021
+ if (isP2WDA) {
1022
+ return this.finalizeSecondaryP2WDA(inputIndex, input);
1023
+ }
1024
+ // Check if this is a CSV input
1025
+ const isCSVInput = this.csvInputIndices.has(inputIndex);
1026
+ if (isCSVInput) {
1027
+ // For CSV P2WSH, the witness stack should be: [signature, witnessScript]
1028
+ const witnessStack = [input.partialSig[0].signature, input.witnessScript];
1029
+ return {
1030
+ finalScriptSig: undefined,
1031
+ finalScriptWitness: witnessStackToScriptWitness(witnessStack),
1032
+ };
1033
+ }
1034
+ // For non-CSV P2WSH, use default finalization
1035
+ }
1036
+ return getFinalScripts(inputIndex, input, scriptA, isSegwit, isP2SH, isP2WSH, true, this.unlockScript);
1037
+ };
1038
+ /**
1039
+ * Finalize secondary P2WDA inputs with empty data
1040
+ */
602
1041
  finalizeSecondaryP2WDA(inputIndex, input) {
603
1042
  if (!input.partialSig || input.partialSig.length === 0) {
604
1043
  throw new Error(`No signature for P2WDA input #${inputIndex}`);
@@ -614,7 +1053,9 @@ export class TweakedTransaction extends Logger {
614
1053
  }
615
1054
  async signInputsWalletBased(transaction) {
616
1055
  const signer = this.signer;
1056
+ // then, we sign all the remaining inputs with the wallet signer.
617
1057
  await signer.multiSignPsbt([transaction]);
1058
+ // Then, we finalize every input.
618
1059
  for (let i = 0; i < transaction.data.inputs.length; i++) {
619
1060
  transaction.finalizeInput(i, this.customFinalizerP2SH.bind(this));
620
1061
  }
@@ -630,28 +1071,44 @@ export class TweakedTransaction extends Logger {
630
1071
  if (csvBlocks > 0xffff) {
631
1072
  throw new Error(`CSV blocks ${csvBlocks} exceeds maximum of 65,535`);
632
1073
  }
1074
+ // Layout of nSequence field (32 bits) when CSV is active (bit 31 = 0):
1075
+ // Bit 31: Must be 0 (CSV enable flag)
1076
+ // Bits 23-30: Unused by BIP68 (available for custom use)
1077
+ // Bit 22: Time flag (0 = blocks, 1 = time)
1078
+ // Bits 16-21: Unused by BIP68 (available for custom use)
1079
+ // Bits 0-15: CSV lock-time value
1080
+ // Extract the time flag if it's set in csvBlocks
633
1081
  const isTimeBased = (csvBlocks & (1 << 22)) !== 0;
1082
+ // Start with the CSV value
634
1083
  let sequence = csvBlocks & 0x0000ffff;
1084
+ // Preserve the time flag if set
635
1085
  if (isTimeBased) {
636
1086
  sequence |= 1 << 22;
637
1087
  }
638
1088
  if (currentSequence === TransactionSequence.REPLACE_BY_FEE) {
1089
+ // Set bit 25 as our explicit RBF flag
1090
+ // This is in the unused range (bits 23-30) when CSV is active
639
1091
  sequence |= 1 << 25;
1092
+ // We could use other unused bits for version/features
1093
+ // sequence |= (1 << 26); // Could indicate tx flags if we wanted
640
1094
  }
1095
+ // Final safety check: ensure bit 31 is 0 (CSV enabled)
641
1096
  sequence = sequence & 0x7fffffff;
642
1097
  return sequence;
643
1098
  }
644
1099
  getCSVType(csvValue) {
1100
+ // Bit 22 determines if it's time-based (1) or block-based (0)
645
1101
  return csvValue & (1 << 22) ? CSVModes.TIMESTAMPS : CSVModes.BLOCKS;
646
1102
  }
647
1103
  extractCSVBlocks(decompiled) {
648
1104
  for (let i = 0; i < decompiled.length; i++) {
649
1105
  if (decompiled[i] === opcodes.OP_CHECKSEQUENCEVERIFY && i > 0) {
650
1106
  const csvValue = decompiled[i - 1];
651
- if (Buffer.isBuffer(csvValue)) {
1107
+ if (csvValue instanceof Uint8Array) {
652
1108
  return script.number.decode(csvValue);
653
1109
  }
654
1110
  else if (typeof csvValue === 'number') {
1111
+ // Handle OP_N directly
655
1112
  if (csvValue === opcodes.OP_0 || csvValue === opcodes.OP_FALSE) {
656
1113
  return 0;
657
1114
  }
@@ -662,6 +1119,8 @@ export class TweakedTransaction extends Logger {
662
1119
  return csvValue - opcodes.OP_1 + 1;
663
1120
  }
664
1121
  else {
1122
+ // For other numbers, they should have been Buffers
1123
+ // This shouldn't happen in properly decompiled scripts
665
1124
  throw new Error(`Unexpected raw number in script: ${csvValue}`);
666
1125
  }
667
1126
  }
@@ -703,8 +1162,10 @@ export class TweakedTransaction extends Logger {
703
1162
  }
704
1163
  isTaprootScriptSpend(input, publicKey) {
705
1164
  if (input.tapLeafScript && input.tapLeafScript.length > 0) {
1165
+ // Check if the signer's public key is involved in any tapLeafScript
706
1166
  for (const tapLeafScript of input.tapLeafScript) {
707
1167
  if (pubkeyInScript(publicKey, tapLeafScript.script)) {
1168
+ // The public key is in the script; it's a script spend
708
1169
  return true;
709
1170
  }
710
1171
  }
@@ -721,7 +1182,7 @@ export class TweakedTransaction extends Logger {
721
1182
  }
722
1183
  }
723
1184
  else {
724
- transaction.signTaprootInput(i, signer);
1185
+ transaction.signTaprootInput(i, signer); //tapLeafHash
725
1186
  }
726
1187
  }
727
1188
  async signNonTaprootInput(signer, transaction, i) {
@@ -733,3 +1194,4 @@ export class TweakedTransaction extends Logger {
733
1194
  }
734
1195
  }
735
1196
  }
1197
+ //# sourceMappingURL=TweakedTransaction.js.map