@atomicfinance/bitcoin-wallet-provider 4.2.8 → 4.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (226) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/.turbo/turbo-lint$colon$fix.log +4 -0
  3. package/.turbo/turbo-lint.log +5 -0
  4. package/.turbo/turbo-test.log +0 -0
  5. package/.yalc/@node-dlc/core/.nyc_output/687a3c14-9765-45fd-a1fe-f7db3d56fee4.json +1 -0
  6. package/.yalc/@node-dlc/core/.nyc_output/processinfo/687a3c14-9765-45fd-a1fe-f7db3d56fee4.json +1 -0
  7. package/.yalc/@node-dlc/core/.nyc_output/processinfo/index.json +1 -0
  8. package/.yalc/@node-dlc/core/README.md +11 -0
  9. package/.yalc/@node-dlc/core/__tests__/core.spec.ts +7 -0
  10. package/.yalc/@node-dlc/core/__tests__/dlc/CETCalculator.spec.ts +1029 -0
  11. package/.yalc/@node-dlc/core/__tests__/dlc/CoinSelect.spec.ts +179 -0
  12. package/.yalc/@node-dlc/core/__tests__/dlc/PolynomialPayoutCurve.spec.ts +345 -0
  13. package/.yalc/@node-dlc/core/__tests__/dlc/TxBuilder.spec.ts +424 -0
  14. package/.yalc/@node-dlc/core/__tests__/dlc/finance/Builder.spec.ts +492 -0
  15. package/.yalc/@node-dlc/core/__tests__/dlc/finance/CoveredCall.spec.ts +112 -0
  16. package/.yalc/@node-dlc/core/__tests__/dlc/finance/CsoInfo.spec.ts +1124 -0
  17. package/.yalc/@node-dlc/core/__tests__/dlc/finance/LongCall.spec.ts +55 -0
  18. package/.yalc/@node-dlc/core/__tests__/dlc/finance/LongPut.spec.ts +55 -0
  19. package/.yalc/@node-dlc/core/__tests__/dlc/finance/OptionInfo.spec.ts +226 -0
  20. package/.yalc/@node-dlc/core/__tests__/dlc/finance/ShortPut.spec.ts +62 -0
  21. package/.yalc/@node-dlc/core/__tests__/tsconfig.json +8 -0
  22. package/.yalc/@node-dlc/core/__tests__/utils/precision.spec.ts +40 -0
  23. package/.yalc/@node-dlc/core/coverage/lcov-report/base.css +224 -0
  24. package/.yalc/@node-dlc/core/coverage/lcov-report/block-navigation.js +79 -0
  25. package/.yalc/@node-dlc/core/coverage/lcov-report/favicon.png +0 -0
  26. package/.yalc/@node-dlc/core/coverage/lcov-report/index.html +171 -0
  27. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/AsyncProcessingQueue.ts.html +269 -0
  28. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/Base32.ts.html +86 -0
  29. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/BigIntUtils.ts.html +86 -0
  30. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/BitField.ts.html +86 -0
  31. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/ChannelId.ts.html +86 -0
  32. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/LinkedList.ts.html +413 -0
  33. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/LinkedListNode.ts.html +122 -0
  34. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/Queue.ts.html +188 -0
  35. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/ShortChannelId.ts.html +86 -0
  36. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/ShortChannelIdUtils.ts.html +107 -0
  37. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/CETCalculator.ts.html +1430 -0
  38. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/CoinSelect.ts.html +431 -0
  39. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/HyperbolaPayoutCurve.ts.html +644 -0
  40. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/PolynomialPayoutCurve.ts.html +878 -0
  41. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/TxBuilder.ts.html +1088 -0
  42. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/TxFinalizer.ts.html +731 -0
  43. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/Builder.ts.html +2270 -0
  44. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/CoveredCall.ts.html +410 -0
  45. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/CsoInfo.ts.html +1574 -0
  46. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/LinearPayout.ts.html +362 -0
  47. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/LongCall.ts.html +302 -0
  48. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/LongPut.ts.html +302 -0
  49. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/OptionInfo.ts.html +626 -0
  50. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/ShortPut.ts.html +305 -0
  51. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/index.html +216 -0
  52. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/index.html +186 -0
  53. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/index.html +261 -0
  54. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/index.ts.html +278 -0
  55. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/ChannelId.ts.html +242 -0
  56. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/ChannelKeys.ts.html +407 -0
  57. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/CommitmentNumber.ts.html +362 -0
  58. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/CommitmentSecret.ts.html +203 -0
  59. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/CommitmentSecretStore.ts.html +332 -0
  60. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/Htlc.ts.html +236 -0
  61. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/HtlcDirection.ts.html +131 -0
  62. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/ScriptFactory.ts.html +530 -0
  63. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/TxFactory.ts.html +1094 -0
  64. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/index.html +231 -0
  65. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/utils/BigIntUtils.ts.html +272 -0
  66. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/utils/Precision.ts.html +149 -0
  67. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/utils/index.html +126 -0
  68. package/.yalc/@node-dlc/core/coverage/lcov-report/prettify.css +1 -0
  69. package/.yalc/@node-dlc/core/coverage/lcov-report/prettify.js +2 -0
  70. package/.yalc/@node-dlc/core/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  71. package/.yalc/@node-dlc/core/coverage/lcov-report/sorter.js +170 -0
  72. package/.yalc/@node-dlc/core/coverage/lcov.info +2426 -0
  73. package/.yalc/@node-dlc/core/dist/AsyncProcessingQueue.d.ts +22 -0
  74. package/.yalc/@node-dlc/core/dist/AsyncProcessingQueue.js +55 -0
  75. package/.yalc/@node-dlc/core/dist/AsyncProcessingQueue.js.map +1 -0
  76. package/.yalc/@node-dlc/core/dist/Base32.d.ts +1 -0
  77. package/.yalc/@node-dlc/core/dist/Base32.js +7 -0
  78. package/.yalc/@node-dlc/core/dist/Base32.js.map +1 -0
  79. package/.yalc/@node-dlc/core/dist/BigIntUtils.d.ts +1 -0
  80. package/.yalc/@node-dlc/core/dist/BigIntUtils.js +8 -0
  81. package/.yalc/@node-dlc/core/dist/BigIntUtils.js.map +1 -0
  82. package/.yalc/@node-dlc/core/dist/BitField.d.ts +1 -0
  83. package/.yalc/@node-dlc/core/dist/BitField.js +7 -0
  84. package/.yalc/@node-dlc/core/dist/BitField.js.map +1 -0
  85. package/.yalc/@node-dlc/core/dist/ChannelId.d.ts +1 -0
  86. package/.yalc/@node-dlc/core/dist/ChannelId.js +7 -0
  87. package/.yalc/@node-dlc/core/dist/ChannelId.js.map +1 -0
  88. package/.yalc/@node-dlc/core/dist/LinkedList.d.ts +30 -0
  89. package/.yalc/@node-dlc/core/dist/LinkedList.js +104 -0
  90. package/.yalc/@node-dlc/core/dist/LinkedList.js.map +1 -0
  91. package/.yalc/@node-dlc/core/dist/LinkedListNode.d.ts +9 -0
  92. package/.yalc/@node-dlc/core/dist/LinkedListNode.js +15 -0
  93. package/.yalc/@node-dlc/core/dist/LinkedListNode.js.map +1 -0
  94. package/.yalc/@node-dlc/core/dist/Queue.d.ts +22 -0
  95. package/.yalc/@node-dlc/core/dist/Queue.js +38 -0
  96. package/.yalc/@node-dlc/core/dist/Queue.js.map +1 -0
  97. package/.yalc/@node-dlc/core/dist/ShortChannelId.d.ts +1 -0
  98. package/.yalc/@node-dlc/core/dist/ShortChannelId.js +7 -0
  99. package/.yalc/@node-dlc/core/dist/ShortChannelId.js.map +1 -0
  100. package/.yalc/@node-dlc/core/dist/ShortChannelIdUtils.d.ts +1 -0
  101. package/.yalc/@node-dlc/core/dist/ShortChannelIdUtils.js +12 -0
  102. package/.yalc/@node-dlc/core/dist/ShortChannelIdUtils.js.map +1 -0
  103. package/.yalc/@node-dlc/core/dist/dlc/CETCalculator.d.ts +50 -0
  104. package/.yalc/@node-dlc/core/dist/dlc/CETCalculator.js +332 -0
  105. package/.yalc/@node-dlc/core/dist/dlc/CETCalculator.js.map +1 -0
  106. package/.yalc/@node-dlc/core/dist/dlc/CoinSelect.d.ts +23 -0
  107. package/.yalc/@node-dlc/core/dist/dlc/CoinSelect.js +77 -0
  108. package/.yalc/@node-dlc/core/dist/dlc/CoinSelect.js.map +1 -0
  109. package/.yalc/@node-dlc/core/dist/dlc/HyperbolaPayoutCurve.d.ts +20 -0
  110. package/.yalc/@node-dlc/core/dist/dlc/HyperbolaPayoutCurve.js +117 -0
  111. package/.yalc/@node-dlc/core/dist/dlc/HyperbolaPayoutCurve.js.map +1 -0
  112. package/.yalc/@node-dlc/core/dist/dlc/PayoutCurve.d.ts +5 -0
  113. package/.yalc/@node-dlc/core/dist/dlc/PayoutCurve.js +3 -0
  114. package/.yalc/@node-dlc/core/dist/dlc/PayoutCurve.js.map +1 -0
  115. package/.yalc/@node-dlc/core/dist/dlc/PolynomialPayoutCurve.d.ts +52 -0
  116. package/.yalc/@node-dlc/core/dist/dlc/PolynomialPayoutCurve.js +173 -0
  117. package/.yalc/@node-dlc/core/dist/dlc/PolynomialPayoutCurve.js.map +1 -0
  118. package/.yalc/@node-dlc/core/dist/dlc/TxBuilder.d.ts +55 -0
  119. package/.yalc/@node-dlc/core/dist/dlc/TxBuilder.js +217 -0
  120. package/.yalc/@node-dlc/core/dist/dlc/TxBuilder.js.map +1 -0
  121. package/.yalc/@node-dlc/core/dist/dlc/TxFinalizer.d.ts +40 -0
  122. package/.yalc/@node-dlc/core/dist/dlc/TxFinalizer.js +146 -0
  123. package/.yalc/@node-dlc/core/dist/dlc/TxFinalizer.js.map +1 -0
  124. package/.yalc/@node-dlc/core/dist/dlc/finance/Builder.d.ts +193 -0
  125. package/.yalc/@node-dlc/core/dist/dlc/finance/Builder.js +422 -0
  126. package/.yalc/@node-dlc/core/dist/dlc/finance/Builder.js.map +1 -0
  127. package/.yalc/@node-dlc/core/dist/dlc/finance/CoveredCall.d.ts +13 -0
  128. package/.yalc/@node-dlc/core/dist/dlc/finance/CoveredCall.js +67 -0
  129. package/.yalc/@node-dlc/core/dist/dlc/finance/CoveredCall.js.map +1 -0
  130. package/.yalc/@node-dlc/core/dist/dlc/finance/CsoInfo.d.ts +114 -0
  131. package/.yalc/@node-dlc/core/dist/dlc/finance/CsoInfo.js +290 -0
  132. package/.yalc/@node-dlc/core/dist/dlc/finance/CsoInfo.js.map +1 -0
  133. package/.yalc/@node-dlc/core/dist/dlc/finance/LinearPayout.d.ts +6 -0
  134. package/.yalc/@node-dlc/core/dist/dlc/finance/LinearPayout.js +79 -0
  135. package/.yalc/@node-dlc/core/dist/dlc/finance/LinearPayout.js.map +1 -0
  136. package/.yalc/@node-dlc/core/dist/dlc/finance/LongCall.d.ts +13 -0
  137. package/.yalc/@node-dlc/core/dist/dlc/finance/LongCall.js +47 -0
  138. package/.yalc/@node-dlc/core/dist/dlc/finance/LongCall.js.map +1 -0
  139. package/.yalc/@node-dlc/core/dist/dlc/finance/LongPut.d.ts +13 -0
  140. package/.yalc/@node-dlc/core/dist/dlc/finance/LongPut.js +47 -0
  141. package/.yalc/@node-dlc/core/dist/dlc/finance/LongPut.js.map +1 -0
  142. package/.yalc/@node-dlc/core/dist/dlc/finance/OptionInfo.d.ts +20 -0
  143. package/.yalc/@node-dlc/core/dist/dlc/finance/OptionInfo.js +101 -0
  144. package/.yalc/@node-dlc/core/dist/dlc/finance/OptionInfo.js.map +1 -0
  145. package/.yalc/@node-dlc/core/dist/dlc/finance/ShortPut.d.ts +12 -0
  146. package/.yalc/@node-dlc/core/dist/dlc/finance/ShortPut.js +46 -0
  147. package/.yalc/@node-dlc/core/dist/dlc/finance/ShortPut.js.map +1 -0
  148. package/.yalc/@node-dlc/core/dist/index.d.ts +39 -0
  149. package/.yalc/@node-dlc/core/dist/index.js +78 -0
  150. package/.yalc/@node-dlc/core/dist/index.js.map +1 -0
  151. package/.yalc/@node-dlc/core/dist/lightning/ChannelId.d.ts +31 -0
  152. package/.yalc/@node-dlc/core/dist/lightning/ChannelId.js +52 -0
  153. package/.yalc/@node-dlc/core/dist/lightning/ChannelId.js.map +1 -0
  154. package/.yalc/@node-dlc/core/dist/lightning/ChannelKeys.d.ts +55 -0
  155. package/.yalc/@node-dlc/core/dist/lightning/ChannelKeys.js +105 -0
  156. package/.yalc/@node-dlc/core/dist/lightning/ChannelKeys.js.map +1 -0
  157. package/.yalc/@node-dlc/core/dist/lightning/CommitmentNumber.d.ts +55 -0
  158. package/.yalc/@node-dlc/core/dist/lightning/CommitmentNumber.js +76 -0
  159. package/.yalc/@node-dlc/core/dist/lightning/CommitmentNumber.js.map +1 -0
  160. package/.yalc/@node-dlc/core/dist/lightning/CommitmentSecret.d.ts +26 -0
  161. package/.yalc/@node-dlc/core/dist/lightning/CommitmentSecret.js +44 -0
  162. package/.yalc/@node-dlc/core/dist/lightning/CommitmentSecret.js.map +1 -0
  163. package/.yalc/@node-dlc/core/dist/lightning/CommitmentSecretStore.d.ts +41 -0
  164. package/.yalc/@node-dlc/core/dist/lightning/CommitmentSecretStore.js +79 -0
  165. package/.yalc/@node-dlc/core/dist/lightning/CommitmentSecretStore.js.map +1 -0
  166. package/.yalc/@node-dlc/core/dist/lightning/Htlc.d.ts +46 -0
  167. package/.yalc/@node-dlc/core/dist/lightning/Htlc.js +46 -0
  168. package/.yalc/@node-dlc/core/dist/lightning/Htlc.js.map +1 -0
  169. package/.yalc/@node-dlc/core/dist/lightning/HtlcDirection.d.ts +16 -0
  170. package/.yalc/@node-dlc/core/dist/lightning/HtlcDirection.js +21 -0
  171. package/.yalc/@node-dlc/core/dist/lightning/HtlcDirection.js.map +1 -0
  172. package/.yalc/@node-dlc/core/dist/lightning/ScriptFactory.d.ts +76 -0
  173. package/.yalc/@node-dlc/core/dist/lightning/ScriptFactory.js +102 -0
  174. package/.yalc/@node-dlc/core/dist/lightning/ScriptFactory.js.map +1 -0
  175. package/.yalc/@node-dlc/core/dist/lightning/TxFactory.d.ts +83 -0
  176. package/.yalc/@node-dlc/core/dist/lightning/TxFactory.js +222 -0
  177. package/.yalc/@node-dlc/core/dist/lightning/TxFactory.js.map +1 -0
  178. package/.yalc/@node-dlc/core/dist/utils/BigIntUtils.d.ts +9 -0
  179. package/.yalc/@node-dlc/core/dist/utils/BigIntUtils.js +59 -0
  180. package/.yalc/@node-dlc/core/dist/utils/BigIntUtils.js.map +1 -0
  181. package/.yalc/@node-dlc/core/dist/utils/Precision.d.ts +13 -0
  182. package/.yalc/@node-dlc/core/dist/utils/Precision.js +28 -0
  183. package/.yalc/@node-dlc/core/dist/utils/Precision.js.map +1 -0
  184. package/.yalc/@node-dlc/core/lib/AsyncProcessingQueue.ts +63 -0
  185. package/.yalc/@node-dlc/core/lib/Base32.ts +2 -0
  186. package/.yalc/@node-dlc/core/lib/BigIntUtils.ts +2 -0
  187. package/.yalc/@node-dlc/core/lib/BitField.ts +2 -0
  188. package/.yalc/@node-dlc/core/lib/ChannelId.ts +2 -0
  189. package/.yalc/@node-dlc/core/lib/LinkedList.ts +111 -0
  190. package/.yalc/@node-dlc/core/lib/LinkedListNode.ts +14 -0
  191. package/.yalc/@node-dlc/core/lib/Queue.ts +36 -0
  192. package/.yalc/@node-dlc/core/lib/ShortChannelId.ts +2 -0
  193. package/.yalc/@node-dlc/core/lib/ShortChannelIdUtils.ts +9 -0
  194. package/.yalc/@node-dlc/core/lib/dlc/CETCalculator.ts +450 -0
  195. package/.yalc/@node-dlc/core/lib/dlc/CoinSelect.ts +117 -0
  196. package/.yalc/@node-dlc/core/lib/dlc/HyperbolaPayoutCurve.ts +188 -0
  197. package/.yalc/@node-dlc/core/lib/dlc/PayoutCurve.ts +6 -0
  198. package/.yalc/@node-dlc/core/lib/dlc/PolynomialPayoutCurve.ts +266 -0
  199. package/.yalc/@node-dlc/core/lib/dlc/TxBuilder.ts +336 -0
  200. package/.yalc/@node-dlc/core/lib/dlc/TxFinalizer.ts +217 -0
  201. package/.yalc/@node-dlc/core/lib/dlc/finance/Builder.ts +730 -0
  202. package/.yalc/@node-dlc/core/lib/dlc/finance/CoveredCall.ts +110 -0
  203. package/.yalc/@node-dlc/core/lib/dlc/finance/CsoInfo.ts +498 -0
  204. package/.yalc/@node-dlc/core/lib/dlc/finance/LinearPayout.ts +94 -0
  205. package/.yalc/@node-dlc/core/lib/dlc/finance/LongCall.ts +74 -0
  206. package/.yalc/@node-dlc/core/lib/dlc/finance/LongPut.ts +74 -0
  207. package/.yalc/@node-dlc/core/lib/dlc/finance/OptionInfo.ts +182 -0
  208. package/.yalc/@node-dlc/core/lib/dlc/finance/ShortPut.ts +75 -0
  209. package/.yalc/@node-dlc/core/lib/index.ts +66 -0
  210. package/.yalc/@node-dlc/core/lib/lightning/ChannelId.ts +54 -0
  211. package/.yalc/@node-dlc/core/lib/lightning/ChannelKeys.ts +109 -0
  212. package/.yalc/@node-dlc/core/lib/lightning/CommitmentNumber.ts +94 -0
  213. package/.yalc/@node-dlc/core/lib/lightning/CommitmentSecret.ts +41 -0
  214. package/.yalc/@node-dlc/core/lib/lightning/CommitmentSecretStore.ts +84 -0
  215. package/.yalc/@node-dlc/core/lib/lightning/Htlc.ts +52 -0
  216. package/.yalc/@node-dlc/core/lib/lightning/HtlcDirection.ts +17 -0
  217. package/.yalc/@node-dlc/core/lib/lightning/ScriptFactory.ts +150 -0
  218. package/.yalc/@node-dlc/core/lib/lightning/TxFactory.ts +338 -0
  219. package/.yalc/@node-dlc/core/lib/utils/BigIntUtils.ts +64 -0
  220. package/.yalc/@node-dlc/core/lib/utils/Precision.ts +23 -0
  221. package/.yalc/@node-dlc/core/package.json +38 -0
  222. package/.yalc/@node-dlc/core/tsconfig.json +8 -0
  223. package/.yalc/@node-dlc/core/yalc.sig +1 -0
  224. package/CHANGELOG.md +23 -0
  225. package/package.json +7 -7
  226. package/yalc.lock +10 -0
@@ -0,0 +1,424 @@
1
+ import { Value } from '@node-dlc/bitcoin';
2
+ import {
3
+ DlcAcceptWithoutSigs,
4
+ DlcOffer,
5
+ FundingInput,
6
+ } from '@node-dlc/messaging';
7
+ import { expect } from 'chai';
8
+
9
+ import { BatchDlcTxBuilder, DlcTxBuilder, DUST_LIMIT } from '../../lib';
10
+
11
+ describe('TxBuilder', () => {
12
+ // Helper function to create test FundingInput
13
+ const createTestFundingInput = (
14
+ value: bigint,
15
+ serialId = 1,
16
+ maxWitnessLen = 108,
17
+ ): FundingInput => {
18
+ // Create proper transaction hex with correct output value encoding
19
+ // Based on working format from existing tests
20
+ const valueBuffer = Buffer.allocUnsafe(8);
21
+ valueBuffer.writeBigUInt64LE(value, 0);
22
+ const valueHex = valueBuffer.toString('hex');
23
+
24
+ // Use a working transaction format: version + input + outputs + locktime
25
+ const prevTxHex =
26
+ '02000000' + // version
27
+ '01' + // num inputs
28
+ 'f58f85b356ad5bb5b6d0ef3eb863be8a6cb95e08e1e9e92885b4b22e7e51eb9d' + // input txid
29
+ '00000000' + // input vout
30
+ '00' + // script sig length
31
+ 'ffffffff' + // sequence
32
+ '01' + // num outputs
33
+ valueHex + // output value (8 bytes, little endian)
34
+ '2200201234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef' + // P2WSH script
35
+ '00000000'; // locktime
36
+
37
+ return FundingInput.fromJSON({
38
+ inputSerialId: serialId,
39
+ prevTx: prevTxHex,
40
+ prevTxVout: 0,
41
+ sequence: 4294967295,
42
+ maxWitnessLen,
43
+ redeemScript: '',
44
+ });
45
+ };
46
+
47
+ // Helper function to create test DlcOffer
48
+ const createTestDlcOffer = (
49
+ offerCollateral: bigint,
50
+ fundingInputs: FundingInput[],
51
+ feeRate = BigInt(1),
52
+ ): DlcOffer => {
53
+ const offer = new DlcOffer();
54
+ offer.offerCollateral = offerCollateral;
55
+ offer.fundingInputs = fundingInputs;
56
+ offer.feeRatePerVb = feeRate;
57
+ // Valid compressed public key (Bitcoin Generator Point)
58
+ offer.fundingPubkey = Buffer.from(
59
+ '0279BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798',
60
+ 'hex',
61
+ );
62
+ offer.payoutSpk = Buffer.from(
63
+ '0014' + Buffer.alloc(20).toString('hex'),
64
+ 'hex',
65
+ );
66
+ offer.changeSpk = Buffer.from(
67
+ '0014' + Buffer.alloc(20).toString('hex'),
68
+ 'hex',
69
+ );
70
+ offer.fundOutputSerialId = BigInt(1);
71
+ offer.payoutSerialId = BigInt(2);
72
+ offer.changeSerialId = BigInt(3);
73
+ return offer;
74
+ };
75
+
76
+ // Helper function to create test DlcAccept
77
+ const createTestDlcAccept = (
78
+ acceptCollateral: bigint,
79
+ fundingInputs: FundingInput[] = [],
80
+ ): DlcAcceptWithoutSigs => {
81
+ return new DlcAcceptWithoutSigs(
82
+ 1, // protocolVersion
83
+ Buffer.alloc(32), // temporaryContractId
84
+ acceptCollateral,
85
+ // Valid compressed public key (different from offer)
86
+ Buffer.from(
87
+ '02F9308A019258C31049344F85F89D5229B531C845836F99B08601F113BCE036F9',
88
+ 'hex',
89
+ ),
90
+ Buffer.from('0014' + Buffer.alloc(20).toString('hex'), 'hex'), // payoutSpk
91
+ BigInt(4), // payoutSerialId
92
+ fundingInputs,
93
+ Buffer.from('0014' + Buffer.alloc(20).toString('hex'), 'hex'), // changeSpk
94
+ BigInt(5), // changeSerialId
95
+ );
96
+ };
97
+
98
+ describe('DUST_LIMIT', () => {
99
+ it('should export the dust limit constant', () => {
100
+ expect(DUST_LIMIT).to.equal(BigInt(1000));
101
+ });
102
+ });
103
+
104
+ describe('BatchDlcTxBuilder.calculateMaxCollateral', () => {
105
+ it('should calculate maximum collateral for single input', () => {
106
+ const fundingInputs = [createTestFundingInput(BigInt(1000000))];
107
+ const feeRate = BigInt(1);
108
+
109
+ const maxCollateral = BatchDlcTxBuilder.calculateMaxCollateral(
110
+ fundingInputs,
111
+ feeRate,
112
+ 1,
113
+ );
114
+
115
+ // Should be input value minus fees
116
+ expect(Number(maxCollateral)).to.be.greaterThan(0);
117
+ expect(Number(maxCollateral)).to.be.lessThan(1000000);
118
+ });
119
+
120
+ it('should calculate maximum collateral for multiple inputs', () => {
121
+ const fundingInputs = [
122
+ createTestFundingInput(BigInt(500000)),
123
+ createTestFundingInput(BigInt(300000), 2),
124
+ ];
125
+ const feeRate = BigInt(1);
126
+
127
+ const maxCollateral = BatchDlcTxBuilder.calculateMaxCollateral(
128
+ fundingInputs,
129
+ feeRate,
130
+ 1,
131
+ );
132
+
133
+ // Should be total input value minus fees
134
+ expect(Number(maxCollateral)).to.be.greaterThan(0);
135
+ expect(Number(maxCollateral)).to.be.lessThan(800000);
136
+ });
137
+
138
+ it('should account for higher fee rates', () => {
139
+ const fundingInputs = [createTestFundingInput(BigInt(1000000))];
140
+ const lowFeeRate = BigInt(1);
141
+ const highFeeRate = BigInt(10);
142
+
143
+ const maxCollateralLowFee = BatchDlcTxBuilder.calculateMaxCollateral(
144
+ fundingInputs,
145
+ lowFeeRate,
146
+ 1,
147
+ );
148
+ const maxCollateralHighFee = BatchDlcTxBuilder.calculateMaxCollateral(
149
+ fundingInputs,
150
+ highFeeRate,
151
+ 1,
152
+ );
153
+
154
+ // Higher fee rate should result in lower max collateral
155
+ expect(Number(maxCollateralHighFee)).to.be.lessThan(
156
+ Number(maxCollateralLowFee),
157
+ );
158
+ });
159
+
160
+ it('should account for multiple contracts', () => {
161
+ const fundingInputs = [createTestFundingInput(BigInt(1000000))];
162
+ const feeRate = BigInt(1);
163
+
164
+ const maxCollateralSingle = BatchDlcTxBuilder.calculateMaxCollateral(
165
+ fundingInputs,
166
+ feeRate,
167
+ 1,
168
+ );
169
+ const maxCollateralMultiple = BatchDlcTxBuilder.calculateMaxCollateral(
170
+ fundingInputs,
171
+ feeRate,
172
+ 3,
173
+ );
174
+
175
+ // Multiple contracts should result in lower max collateral due to higher fees
176
+ expect(Number(maxCollateralMultiple)).to.be.lessThan(
177
+ Number(maxCollateralSingle),
178
+ );
179
+ });
180
+
181
+ it('should return zero when fees exceed input value', () => {
182
+ const fundingInputs = [createTestFundingInput(BigInt(100))]; // Very small input
183
+ const feeRate = BigInt(1000); // Very high fee rate
184
+
185
+ const maxCollateral = BatchDlcTxBuilder.calculateMaxCollateral(
186
+ fundingInputs,
187
+ feeRate,
188
+ 1,
189
+ );
190
+
191
+ expect(maxCollateral).to.equal(BigInt(0));
192
+ });
193
+
194
+ it('should handle empty funding inputs', () => {
195
+ const fundingInputs: FundingInput[] = [];
196
+ const feeRate = BigInt(1);
197
+
198
+ const maxCollateral = BatchDlcTxBuilder.calculateMaxCollateral(
199
+ fundingInputs,
200
+ feeRate,
201
+ 1,
202
+ );
203
+
204
+ expect(maxCollateral).to.equal(BigInt(0));
205
+ });
206
+ });
207
+
208
+ describe('BatchDlcTxBuilder.buildFundingTransaction - Dust Filtering', () => {
209
+ it('should create change outputs when above dust threshold', () => {
210
+ // Create inputs with sufficient value for both collateral and change
211
+ const offerInput = createTestFundingInput(BigInt(1010000)); // 1.01 BTC in sats
212
+ const acceptInput = createTestFundingInput(BigInt(1005000), 2); // 1.005 BTC in sats
213
+
214
+ const offer = createTestDlcOffer(BigInt(1000000), [offerInput]); // 1 BTC collateral
215
+ const accept = createTestDlcAccept(BigInt(1000000), [acceptInput]); // 1 BTC collateral
216
+
217
+ const builder = new BatchDlcTxBuilder([offer], [accept]);
218
+ const tx = builder.buildFundingTransaction();
219
+
220
+ // Should have 3 outputs: funding output + 2 change outputs
221
+ expect(tx.outputs.length).to.equal(3);
222
+
223
+ // Verify all outputs have value above zero
224
+ tx.outputs.forEach((output) => {
225
+ expect(Number(output.value.sats)).to.be.greaterThan(0);
226
+ });
227
+ });
228
+
229
+ it('should filter out dust change outputs', () => {
230
+ // Create inputs that result in dust change
231
+ const offerInput = createTestFundingInput(BigInt(1000500)); // Just above collateral + fees
232
+ const acceptInput = createTestFundingInput(BigInt(1000300), 2); // Just above collateral + fees
233
+
234
+ const offer = createTestDlcOffer(BigInt(1000000), [offerInput]); // 1 BTC collateral
235
+ const accept = createTestDlcAccept(BigInt(1000000), [acceptInput]); // 1 BTC collateral
236
+
237
+ const builder = new BatchDlcTxBuilder([offer], [accept]);
238
+ const tx = builder.buildFundingTransaction();
239
+
240
+ // Should have only 1 output: just the funding output (no change outputs due to dust)
241
+ expect(tx.outputs.length).to.be.lessThan(3);
242
+ expect(tx.outputs.length).to.be.at.least(1);
243
+
244
+ // The funding output should be present
245
+ const fundingOutputValue = tx.outputs[0].value.sats;
246
+ expect(Number(fundingOutputValue)).to.be.greaterThan(2000000); // Should contain both collaterals + future fees
247
+ });
248
+
249
+ it('should handle exact amount scenarios (no change)', () => {
250
+ // Use calculateMaxCollateral to determine exact amounts
251
+ const offerInput = createTestFundingInput(BigInt(1000000));
252
+ const maxCollateral = BatchDlcTxBuilder.calculateMaxCollateral(
253
+ [offerInput],
254
+ BigInt(1),
255
+ 1,
256
+ );
257
+
258
+ const offer = createTestDlcOffer(maxCollateral, [offerInput]);
259
+ const accept = createTestDlcAccept(BigInt(0), []); // Single-funded DLC
260
+
261
+ const builder = new BatchDlcTxBuilder([offer], [accept]);
262
+ const tx = builder.buildFundingTransaction();
263
+
264
+ // Should have only 1 output: the funding output
265
+ expect(tx.outputs.length).to.equal(1);
266
+
267
+ // Verify the funding output value
268
+ const fundingOutputValue = tx.outputs[0].value.sats;
269
+ expect(Number(fundingOutputValue)).to.be.greaterThan(0);
270
+ });
271
+
272
+ it('should handle mixed scenarios (one party has change, other has dust)', () => {
273
+ // Offer has significant change, accept has dust change
274
+ const offerInput = createTestFundingInput(BigInt(1050000)); // Large change
275
+ const acceptInput = createTestFundingInput(BigInt(1000300), 2); // Dust change
276
+
277
+ const offer = createTestDlcOffer(BigInt(1000000), [offerInput]);
278
+ const accept = createTestDlcAccept(BigInt(1000000), [acceptInput]);
279
+
280
+ const builder = new BatchDlcTxBuilder([offer], [accept]);
281
+ const tx = builder.buildFundingTransaction();
282
+
283
+ // Should have 2 outputs: funding output + offer change output (accept change filtered)
284
+ expect(tx.outputs.length).to.equal(2);
285
+
286
+ // Find the change output (not the largest one which should be funding)
287
+ const sortedOutputs = tx.outputs.sort((a, b) =>
288
+ Number(b.value.sats - a.value.sats),
289
+ );
290
+ const changeOutput = sortedOutputs[1];
291
+
292
+ // Verify change output is above dust threshold
293
+ expect(Number(changeOutput.value.sats)).to.be.at.least(
294
+ Number(DUST_LIMIT),
295
+ );
296
+ });
297
+ });
298
+
299
+ describe('BatchDlcTxBuilder.buildFundingTransaction - Error Handling', () => {
300
+ it('should throw error when offerer has insufficient funds', () => {
301
+ const offerInput = createTestFundingInput(BigInt(500000)); // Insufficient
302
+ const acceptInput = createTestFundingInput(BigInt(1000000), 2);
303
+
304
+ const offer = createTestDlcOffer(BigInt(1000000), [offerInput]); // Requires more than input
305
+ const accept = createTestDlcAccept(BigInt(500000), [acceptInput]);
306
+
307
+ const builder = new BatchDlcTxBuilder([offer], [accept]);
308
+
309
+ expect(() => builder.buildFundingTransaction()).to.throw(
310
+ /Insufficient funds for offerer/,
311
+ );
312
+ });
313
+
314
+ it('should throw error when accepter has insufficient funds', () => {
315
+ const offerInput = createTestFundingInput(BigInt(1000000));
316
+ const acceptInput = createTestFundingInput(BigInt(300000), 2); // Insufficient
317
+
318
+ const offer = createTestDlcOffer(BigInt(500000), [offerInput]);
319
+ const accept = createTestDlcAccept(BigInt(1000000), [acceptInput]); // Requires more than input
320
+
321
+ const builder = new BatchDlcTxBuilder([offer], [accept]);
322
+
323
+ expect(() => builder.buildFundingTransaction()).to.throw(
324
+ /Insufficient funds for accepter/,
325
+ );
326
+ });
327
+
328
+ it('should provide clear error messages with actual values', () => {
329
+ const offerInput = createTestFundingInput(BigInt(500000));
330
+ const offer = createTestDlcOffer(BigInt(1000000), [offerInput]);
331
+ const accept = createTestDlcAccept(BigInt(0), []);
332
+
333
+ const builder = new BatchDlcTxBuilder([offer], [accept]);
334
+
335
+ try {
336
+ builder.buildFundingTransaction();
337
+ expect.fail('Should have thrown an error');
338
+ } catch (error) {
339
+ expect(error.message).to.include('need');
340
+ expect(error.message).to.include('have');
341
+ expect(error.message).to.include('500000');
342
+ }
343
+ });
344
+ });
345
+
346
+ describe('DlcTxBuilder', () => {
347
+ it('should build funding transaction for single DLC', () => {
348
+ const offerInput = createTestFundingInput(BigInt(1000000));
349
+ const acceptInput = createTestFundingInput(BigInt(1000000), 2);
350
+
351
+ const offer = createTestDlcOffer(BigInt(500000), [offerInput]);
352
+ const accept = createTestDlcAccept(BigInt(500000), [acceptInput]);
353
+
354
+ const builder = new DlcTxBuilder(offer, accept);
355
+ const tx = builder.buildFundingTransaction();
356
+
357
+ expect(tx.outputs.length).to.be.at.least(1);
358
+ expect(tx.inputs.length).to.equal(2);
359
+ });
360
+ });
361
+
362
+ describe('Integration Tests', () => {
363
+ it('should handle DLC splicing scenario with exact amounts', () => {
364
+ // Simulate splicing: use a DLC funding output + additional UTXO
365
+ const dlcFundingInput = createTestFundingInput(BigInt(970332)); // Existing DLC output
366
+ const additionalInput = createTestFundingInput(BigInt(100000), 2); // Additional UTXO
367
+
368
+ const totalInputs = [dlcFundingInput, additionalInput];
369
+ const maxCollateral = BatchDlcTxBuilder.calculateMaxCollateral(
370
+ totalInputs,
371
+ BigInt(1),
372
+ 1,
373
+ );
374
+
375
+ // Create offer using exact max collateral (no change scenario)
376
+ const offer = createTestDlcOffer(maxCollateral, totalInputs);
377
+ const accept = createTestDlcAccept(BigInt(0), []); // Single-funded
378
+
379
+ const builder = new BatchDlcTxBuilder([offer], [accept]);
380
+ const tx = builder.buildFundingTransaction();
381
+
382
+ // Should successfully create transaction with no change outputs
383
+ expect(tx.outputs.length).to.equal(1); // Only funding output
384
+ expect(tx.inputs.length).to.equal(2); // Both inputs used
385
+
386
+ // Verify the transaction balances
387
+ const totalInputValue = BigInt(970332) + BigInt(100000);
388
+ const outputValue = tx.outputs[0].value.sats;
389
+
390
+ // Output should be less than input (due to fees) but close
391
+ expect(Number(outputValue)).to.be.lessThan(Number(totalInputValue));
392
+ expect(Number(outputValue)).to.be.greaterThan(
393
+ Number(totalInputValue - BigInt(10000)),
394
+ ); // Reasonable fee range
395
+ });
396
+
397
+ it('should handle batch DLC scenarios', () => {
398
+ const offerInput1 = createTestFundingInput(BigInt(500000));
399
+ const offerInput2 = createTestFundingInput(BigInt(500000), 2);
400
+ const acceptInput = createTestFundingInput(BigInt(800000), 3);
401
+
402
+ const offer1 = createTestDlcOffer(BigInt(400000), [
403
+ offerInput1,
404
+ offerInput2,
405
+ ]);
406
+ const offer2 = createTestDlcOffer(BigInt(400000), [
407
+ offerInput1,
408
+ offerInput2,
409
+ ]);
410
+ const accept1 = createTestDlcAccept(BigInt(300000), [acceptInput]);
411
+ const accept2 = createTestDlcAccept(BigInt(300000), [acceptInput]);
412
+
413
+ const builder = new BatchDlcTxBuilder(
414
+ [offer1, offer2],
415
+ [accept1, accept2],
416
+ );
417
+ const tx = builder.buildFundingTransaction();
418
+
419
+ // Should have 2 funding outputs + change outputs (if any)
420
+ expect(tx.outputs.length).to.be.at.least(2);
421
+ expect(tx.inputs.length).to.equal(3); // All unique inputs
422
+ });
423
+ });
424
+ });