@atomicfinance/bitcoin-wallet-provider 4.2.6 → 4.2.8

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 +4 -5
  2. package/CHANGELOG.md +24 -0
  3. package/package.json +7 -7
  4. package/.turbo/turbo-lint$colon$fix.log +0 -4
  5. package/.turbo/turbo-lint.log +0 -5
  6. package/.turbo/turbo-test.log +0 -0
  7. package/.yalc/@node-dlc/core/.nyc_output/687a3c14-9765-45fd-a1fe-f7db3d56fee4.json +0 -1
  8. package/.yalc/@node-dlc/core/.nyc_output/processinfo/687a3c14-9765-45fd-a1fe-f7db3d56fee4.json +0 -1
  9. package/.yalc/@node-dlc/core/.nyc_output/processinfo/index.json +0 -1
  10. package/.yalc/@node-dlc/core/README.md +0 -11
  11. package/.yalc/@node-dlc/core/__tests__/core.spec.ts +0 -7
  12. package/.yalc/@node-dlc/core/__tests__/dlc/CETCalculator.spec.ts +0 -1029
  13. package/.yalc/@node-dlc/core/__tests__/dlc/CoinSelect.spec.ts +0 -179
  14. package/.yalc/@node-dlc/core/__tests__/dlc/PolynomialPayoutCurve.spec.ts +0 -345
  15. package/.yalc/@node-dlc/core/__tests__/dlc/TxBuilder.spec.ts +0 -424
  16. package/.yalc/@node-dlc/core/__tests__/dlc/finance/Builder.spec.ts +0 -492
  17. package/.yalc/@node-dlc/core/__tests__/dlc/finance/CoveredCall.spec.ts +0 -112
  18. package/.yalc/@node-dlc/core/__tests__/dlc/finance/CsoInfo.spec.ts +0 -1124
  19. package/.yalc/@node-dlc/core/__tests__/dlc/finance/LongCall.spec.ts +0 -55
  20. package/.yalc/@node-dlc/core/__tests__/dlc/finance/LongPut.spec.ts +0 -55
  21. package/.yalc/@node-dlc/core/__tests__/dlc/finance/OptionInfo.spec.ts +0 -226
  22. package/.yalc/@node-dlc/core/__tests__/dlc/finance/ShortPut.spec.ts +0 -62
  23. package/.yalc/@node-dlc/core/__tests__/tsconfig.json +0 -8
  24. package/.yalc/@node-dlc/core/__tests__/utils/precision.spec.ts +0 -40
  25. package/.yalc/@node-dlc/core/coverage/lcov-report/base.css +0 -224
  26. package/.yalc/@node-dlc/core/coverage/lcov-report/block-navigation.js +0 -79
  27. package/.yalc/@node-dlc/core/coverage/lcov-report/favicon.png +0 -0
  28. package/.yalc/@node-dlc/core/coverage/lcov-report/index.html +0 -171
  29. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/AsyncProcessingQueue.ts.html +0 -269
  30. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/Base32.ts.html +0 -86
  31. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/BigIntUtils.ts.html +0 -86
  32. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/BitField.ts.html +0 -86
  33. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/ChannelId.ts.html +0 -86
  34. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/LinkedList.ts.html +0 -413
  35. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/LinkedListNode.ts.html +0 -122
  36. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/Queue.ts.html +0 -188
  37. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/ShortChannelId.ts.html +0 -86
  38. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/ShortChannelIdUtils.ts.html +0 -107
  39. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/CETCalculator.ts.html +0 -1430
  40. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/CoinSelect.ts.html +0 -431
  41. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/HyperbolaPayoutCurve.ts.html +0 -644
  42. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/PolynomialPayoutCurve.ts.html +0 -878
  43. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/TxBuilder.ts.html +0 -1088
  44. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/TxFinalizer.ts.html +0 -731
  45. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/Builder.ts.html +0 -2270
  46. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/CoveredCall.ts.html +0 -410
  47. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/CsoInfo.ts.html +0 -1574
  48. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/LinearPayout.ts.html +0 -362
  49. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/LongCall.ts.html +0 -302
  50. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/LongPut.ts.html +0 -302
  51. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/OptionInfo.ts.html +0 -626
  52. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/ShortPut.ts.html +0 -305
  53. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/index.html +0 -216
  54. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/index.html +0 -186
  55. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/index.html +0 -261
  56. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/index.ts.html +0 -278
  57. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/ChannelId.ts.html +0 -242
  58. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/ChannelKeys.ts.html +0 -407
  59. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/CommitmentNumber.ts.html +0 -362
  60. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/CommitmentSecret.ts.html +0 -203
  61. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/CommitmentSecretStore.ts.html +0 -332
  62. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/Htlc.ts.html +0 -236
  63. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/HtlcDirection.ts.html +0 -131
  64. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/ScriptFactory.ts.html +0 -530
  65. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/TxFactory.ts.html +0 -1094
  66. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/index.html +0 -231
  67. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/utils/BigIntUtils.ts.html +0 -272
  68. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/utils/Precision.ts.html +0 -149
  69. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/utils/index.html +0 -126
  70. package/.yalc/@node-dlc/core/coverage/lcov-report/prettify.css +0 -1
  71. package/.yalc/@node-dlc/core/coverage/lcov-report/prettify.js +0 -2
  72. package/.yalc/@node-dlc/core/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  73. package/.yalc/@node-dlc/core/coverage/lcov-report/sorter.js +0 -170
  74. package/.yalc/@node-dlc/core/coverage/lcov.info +0 -2426
  75. package/.yalc/@node-dlc/core/dist/AsyncProcessingQueue.d.ts +0 -22
  76. package/.yalc/@node-dlc/core/dist/AsyncProcessingQueue.js +0 -55
  77. package/.yalc/@node-dlc/core/dist/AsyncProcessingQueue.js.map +0 -1
  78. package/.yalc/@node-dlc/core/dist/Base32.d.ts +0 -1
  79. package/.yalc/@node-dlc/core/dist/Base32.js +0 -7
  80. package/.yalc/@node-dlc/core/dist/Base32.js.map +0 -1
  81. package/.yalc/@node-dlc/core/dist/BigIntUtils.d.ts +0 -1
  82. package/.yalc/@node-dlc/core/dist/BigIntUtils.js +0 -8
  83. package/.yalc/@node-dlc/core/dist/BigIntUtils.js.map +0 -1
  84. package/.yalc/@node-dlc/core/dist/BitField.d.ts +0 -1
  85. package/.yalc/@node-dlc/core/dist/BitField.js +0 -7
  86. package/.yalc/@node-dlc/core/dist/BitField.js.map +0 -1
  87. package/.yalc/@node-dlc/core/dist/ChannelId.d.ts +0 -1
  88. package/.yalc/@node-dlc/core/dist/ChannelId.js +0 -7
  89. package/.yalc/@node-dlc/core/dist/ChannelId.js.map +0 -1
  90. package/.yalc/@node-dlc/core/dist/LinkedList.d.ts +0 -30
  91. package/.yalc/@node-dlc/core/dist/LinkedList.js +0 -104
  92. package/.yalc/@node-dlc/core/dist/LinkedList.js.map +0 -1
  93. package/.yalc/@node-dlc/core/dist/LinkedListNode.d.ts +0 -9
  94. package/.yalc/@node-dlc/core/dist/LinkedListNode.js +0 -15
  95. package/.yalc/@node-dlc/core/dist/LinkedListNode.js.map +0 -1
  96. package/.yalc/@node-dlc/core/dist/Queue.d.ts +0 -22
  97. package/.yalc/@node-dlc/core/dist/Queue.js +0 -38
  98. package/.yalc/@node-dlc/core/dist/Queue.js.map +0 -1
  99. package/.yalc/@node-dlc/core/dist/ShortChannelId.d.ts +0 -1
  100. package/.yalc/@node-dlc/core/dist/ShortChannelId.js +0 -7
  101. package/.yalc/@node-dlc/core/dist/ShortChannelId.js.map +0 -1
  102. package/.yalc/@node-dlc/core/dist/ShortChannelIdUtils.d.ts +0 -1
  103. package/.yalc/@node-dlc/core/dist/ShortChannelIdUtils.js +0 -12
  104. package/.yalc/@node-dlc/core/dist/ShortChannelIdUtils.js.map +0 -1
  105. package/.yalc/@node-dlc/core/dist/dlc/CETCalculator.d.ts +0 -50
  106. package/.yalc/@node-dlc/core/dist/dlc/CETCalculator.js +0 -332
  107. package/.yalc/@node-dlc/core/dist/dlc/CETCalculator.js.map +0 -1
  108. package/.yalc/@node-dlc/core/dist/dlc/CoinSelect.d.ts +0 -23
  109. package/.yalc/@node-dlc/core/dist/dlc/CoinSelect.js +0 -77
  110. package/.yalc/@node-dlc/core/dist/dlc/CoinSelect.js.map +0 -1
  111. package/.yalc/@node-dlc/core/dist/dlc/HyperbolaPayoutCurve.d.ts +0 -20
  112. package/.yalc/@node-dlc/core/dist/dlc/HyperbolaPayoutCurve.js +0 -117
  113. package/.yalc/@node-dlc/core/dist/dlc/HyperbolaPayoutCurve.js.map +0 -1
  114. package/.yalc/@node-dlc/core/dist/dlc/PayoutCurve.d.ts +0 -5
  115. package/.yalc/@node-dlc/core/dist/dlc/PayoutCurve.js +0 -3
  116. package/.yalc/@node-dlc/core/dist/dlc/PayoutCurve.js.map +0 -1
  117. package/.yalc/@node-dlc/core/dist/dlc/PolynomialPayoutCurve.d.ts +0 -52
  118. package/.yalc/@node-dlc/core/dist/dlc/PolynomialPayoutCurve.js +0 -173
  119. package/.yalc/@node-dlc/core/dist/dlc/PolynomialPayoutCurve.js.map +0 -1
  120. package/.yalc/@node-dlc/core/dist/dlc/TxBuilder.d.ts +0 -55
  121. package/.yalc/@node-dlc/core/dist/dlc/TxBuilder.js +0 -217
  122. package/.yalc/@node-dlc/core/dist/dlc/TxBuilder.js.map +0 -1
  123. package/.yalc/@node-dlc/core/dist/dlc/TxFinalizer.d.ts +0 -40
  124. package/.yalc/@node-dlc/core/dist/dlc/TxFinalizer.js +0 -146
  125. package/.yalc/@node-dlc/core/dist/dlc/TxFinalizer.js.map +0 -1
  126. package/.yalc/@node-dlc/core/dist/dlc/finance/Builder.d.ts +0 -193
  127. package/.yalc/@node-dlc/core/dist/dlc/finance/Builder.js +0 -422
  128. package/.yalc/@node-dlc/core/dist/dlc/finance/Builder.js.map +0 -1
  129. package/.yalc/@node-dlc/core/dist/dlc/finance/CoveredCall.d.ts +0 -13
  130. package/.yalc/@node-dlc/core/dist/dlc/finance/CoveredCall.js +0 -67
  131. package/.yalc/@node-dlc/core/dist/dlc/finance/CoveredCall.js.map +0 -1
  132. package/.yalc/@node-dlc/core/dist/dlc/finance/CsoInfo.d.ts +0 -114
  133. package/.yalc/@node-dlc/core/dist/dlc/finance/CsoInfo.js +0 -290
  134. package/.yalc/@node-dlc/core/dist/dlc/finance/CsoInfo.js.map +0 -1
  135. package/.yalc/@node-dlc/core/dist/dlc/finance/LinearPayout.d.ts +0 -6
  136. package/.yalc/@node-dlc/core/dist/dlc/finance/LinearPayout.js +0 -79
  137. package/.yalc/@node-dlc/core/dist/dlc/finance/LinearPayout.js.map +0 -1
  138. package/.yalc/@node-dlc/core/dist/dlc/finance/LongCall.d.ts +0 -13
  139. package/.yalc/@node-dlc/core/dist/dlc/finance/LongCall.js +0 -47
  140. package/.yalc/@node-dlc/core/dist/dlc/finance/LongCall.js.map +0 -1
  141. package/.yalc/@node-dlc/core/dist/dlc/finance/LongPut.d.ts +0 -13
  142. package/.yalc/@node-dlc/core/dist/dlc/finance/LongPut.js +0 -47
  143. package/.yalc/@node-dlc/core/dist/dlc/finance/LongPut.js.map +0 -1
  144. package/.yalc/@node-dlc/core/dist/dlc/finance/OptionInfo.d.ts +0 -20
  145. package/.yalc/@node-dlc/core/dist/dlc/finance/OptionInfo.js +0 -101
  146. package/.yalc/@node-dlc/core/dist/dlc/finance/OptionInfo.js.map +0 -1
  147. package/.yalc/@node-dlc/core/dist/dlc/finance/ShortPut.d.ts +0 -12
  148. package/.yalc/@node-dlc/core/dist/dlc/finance/ShortPut.js +0 -46
  149. package/.yalc/@node-dlc/core/dist/dlc/finance/ShortPut.js.map +0 -1
  150. package/.yalc/@node-dlc/core/dist/index.d.ts +0 -39
  151. package/.yalc/@node-dlc/core/dist/index.js +0 -78
  152. package/.yalc/@node-dlc/core/dist/index.js.map +0 -1
  153. package/.yalc/@node-dlc/core/dist/lightning/ChannelId.d.ts +0 -31
  154. package/.yalc/@node-dlc/core/dist/lightning/ChannelId.js +0 -52
  155. package/.yalc/@node-dlc/core/dist/lightning/ChannelId.js.map +0 -1
  156. package/.yalc/@node-dlc/core/dist/lightning/ChannelKeys.d.ts +0 -55
  157. package/.yalc/@node-dlc/core/dist/lightning/ChannelKeys.js +0 -105
  158. package/.yalc/@node-dlc/core/dist/lightning/ChannelKeys.js.map +0 -1
  159. package/.yalc/@node-dlc/core/dist/lightning/CommitmentNumber.d.ts +0 -55
  160. package/.yalc/@node-dlc/core/dist/lightning/CommitmentNumber.js +0 -76
  161. package/.yalc/@node-dlc/core/dist/lightning/CommitmentNumber.js.map +0 -1
  162. package/.yalc/@node-dlc/core/dist/lightning/CommitmentSecret.d.ts +0 -26
  163. package/.yalc/@node-dlc/core/dist/lightning/CommitmentSecret.js +0 -44
  164. package/.yalc/@node-dlc/core/dist/lightning/CommitmentSecret.js.map +0 -1
  165. package/.yalc/@node-dlc/core/dist/lightning/CommitmentSecretStore.d.ts +0 -41
  166. package/.yalc/@node-dlc/core/dist/lightning/CommitmentSecretStore.js +0 -79
  167. package/.yalc/@node-dlc/core/dist/lightning/CommitmentSecretStore.js.map +0 -1
  168. package/.yalc/@node-dlc/core/dist/lightning/Htlc.d.ts +0 -46
  169. package/.yalc/@node-dlc/core/dist/lightning/Htlc.js +0 -46
  170. package/.yalc/@node-dlc/core/dist/lightning/Htlc.js.map +0 -1
  171. package/.yalc/@node-dlc/core/dist/lightning/HtlcDirection.d.ts +0 -16
  172. package/.yalc/@node-dlc/core/dist/lightning/HtlcDirection.js +0 -21
  173. package/.yalc/@node-dlc/core/dist/lightning/HtlcDirection.js.map +0 -1
  174. package/.yalc/@node-dlc/core/dist/lightning/ScriptFactory.d.ts +0 -76
  175. package/.yalc/@node-dlc/core/dist/lightning/ScriptFactory.js +0 -102
  176. package/.yalc/@node-dlc/core/dist/lightning/ScriptFactory.js.map +0 -1
  177. package/.yalc/@node-dlc/core/dist/lightning/TxFactory.d.ts +0 -83
  178. package/.yalc/@node-dlc/core/dist/lightning/TxFactory.js +0 -222
  179. package/.yalc/@node-dlc/core/dist/lightning/TxFactory.js.map +0 -1
  180. package/.yalc/@node-dlc/core/dist/utils/BigIntUtils.d.ts +0 -9
  181. package/.yalc/@node-dlc/core/dist/utils/BigIntUtils.js +0 -59
  182. package/.yalc/@node-dlc/core/dist/utils/BigIntUtils.js.map +0 -1
  183. package/.yalc/@node-dlc/core/dist/utils/Precision.d.ts +0 -13
  184. package/.yalc/@node-dlc/core/dist/utils/Precision.js +0 -28
  185. package/.yalc/@node-dlc/core/dist/utils/Precision.js.map +0 -1
  186. package/.yalc/@node-dlc/core/lib/AsyncProcessingQueue.ts +0 -63
  187. package/.yalc/@node-dlc/core/lib/Base32.ts +0 -2
  188. package/.yalc/@node-dlc/core/lib/BigIntUtils.ts +0 -2
  189. package/.yalc/@node-dlc/core/lib/BitField.ts +0 -2
  190. package/.yalc/@node-dlc/core/lib/ChannelId.ts +0 -2
  191. package/.yalc/@node-dlc/core/lib/LinkedList.ts +0 -111
  192. package/.yalc/@node-dlc/core/lib/LinkedListNode.ts +0 -14
  193. package/.yalc/@node-dlc/core/lib/Queue.ts +0 -36
  194. package/.yalc/@node-dlc/core/lib/ShortChannelId.ts +0 -2
  195. package/.yalc/@node-dlc/core/lib/ShortChannelIdUtils.ts +0 -9
  196. package/.yalc/@node-dlc/core/lib/dlc/CETCalculator.ts +0 -450
  197. package/.yalc/@node-dlc/core/lib/dlc/CoinSelect.ts +0 -117
  198. package/.yalc/@node-dlc/core/lib/dlc/HyperbolaPayoutCurve.ts +0 -188
  199. package/.yalc/@node-dlc/core/lib/dlc/PayoutCurve.ts +0 -6
  200. package/.yalc/@node-dlc/core/lib/dlc/PolynomialPayoutCurve.ts +0 -266
  201. package/.yalc/@node-dlc/core/lib/dlc/TxBuilder.ts +0 -336
  202. package/.yalc/@node-dlc/core/lib/dlc/TxFinalizer.ts +0 -217
  203. package/.yalc/@node-dlc/core/lib/dlc/finance/Builder.ts +0 -730
  204. package/.yalc/@node-dlc/core/lib/dlc/finance/CoveredCall.ts +0 -110
  205. package/.yalc/@node-dlc/core/lib/dlc/finance/CsoInfo.ts +0 -498
  206. package/.yalc/@node-dlc/core/lib/dlc/finance/LinearPayout.ts +0 -94
  207. package/.yalc/@node-dlc/core/lib/dlc/finance/LongCall.ts +0 -74
  208. package/.yalc/@node-dlc/core/lib/dlc/finance/LongPut.ts +0 -74
  209. package/.yalc/@node-dlc/core/lib/dlc/finance/OptionInfo.ts +0 -182
  210. package/.yalc/@node-dlc/core/lib/dlc/finance/ShortPut.ts +0 -75
  211. package/.yalc/@node-dlc/core/lib/index.ts +0 -66
  212. package/.yalc/@node-dlc/core/lib/lightning/ChannelId.ts +0 -54
  213. package/.yalc/@node-dlc/core/lib/lightning/ChannelKeys.ts +0 -109
  214. package/.yalc/@node-dlc/core/lib/lightning/CommitmentNumber.ts +0 -94
  215. package/.yalc/@node-dlc/core/lib/lightning/CommitmentSecret.ts +0 -41
  216. package/.yalc/@node-dlc/core/lib/lightning/CommitmentSecretStore.ts +0 -84
  217. package/.yalc/@node-dlc/core/lib/lightning/Htlc.ts +0 -52
  218. package/.yalc/@node-dlc/core/lib/lightning/HtlcDirection.ts +0 -17
  219. package/.yalc/@node-dlc/core/lib/lightning/ScriptFactory.ts +0 -150
  220. package/.yalc/@node-dlc/core/lib/lightning/TxFactory.ts +0 -338
  221. package/.yalc/@node-dlc/core/lib/utils/BigIntUtils.ts +0 -64
  222. package/.yalc/@node-dlc/core/lib/utils/Precision.ts +0 -23
  223. package/.yalc/@node-dlc/core/package.json +0 -38
  224. package/.yalc/@node-dlc/core/tsconfig.json +0 -8
  225. package/.yalc/@node-dlc/core/yalc.sig +0 -1
  226. package/yalc.lock +0 -10
@@ -1,424 +0,0 @@
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
- });