@atomicfinance/bitcoin-wallet-provider 4.0.3 → 4.1.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 (230) hide show
  1. package/.turbo/turbo-build.log +3 -0
  2. package/CHANGELOG.md +31 -0
  3. package/LICENSE +674 -0
  4. package/dist/BitcoinWalletProvider.d.ts +8 -11
  5. package/dist/BitcoinWalletProvider.js +18 -10
  6. package/dist/BitcoinWalletProvider.js.map +1 -1
  7. package/lib/BitcoinWalletProvider.ts +0 -2
  8. package/package.json +14 -13
  9. package/.turbo/turbo-lint.log +0 -1
  10. package/.turbo/turbo-test.log +0 -0
  11. package/.yalc/@node-dlc/core/.nyc_output/687a3c14-9765-45fd-a1fe-f7db3d56fee4.json +0 -1
  12. package/.yalc/@node-dlc/core/.nyc_output/processinfo/687a3c14-9765-45fd-a1fe-f7db3d56fee4.json +0 -1
  13. package/.yalc/@node-dlc/core/.nyc_output/processinfo/index.json +0 -1
  14. package/.yalc/@node-dlc/core/README.md +0 -11
  15. package/.yalc/@node-dlc/core/__tests__/core.spec.ts +0 -7
  16. package/.yalc/@node-dlc/core/__tests__/dlc/CETCalculator.spec.ts +0 -1029
  17. package/.yalc/@node-dlc/core/__tests__/dlc/CoinSelect.spec.ts +0 -179
  18. package/.yalc/@node-dlc/core/__tests__/dlc/PolynomialPayoutCurve.spec.ts +0 -345
  19. package/.yalc/@node-dlc/core/__tests__/dlc/TxBuilder.spec.ts +0 -424
  20. package/.yalc/@node-dlc/core/__tests__/dlc/finance/Builder.spec.ts +0 -492
  21. package/.yalc/@node-dlc/core/__tests__/dlc/finance/CoveredCall.spec.ts +0 -112
  22. package/.yalc/@node-dlc/core/__tests__/dlc/finance/CsoInfo.spec.ts +0 -1124
  23. package/.yalc/@node-dlc/core/__tests__/dlc/finance/LongCall.spec.ts +0 -55
  24. package/.yalc/@node-dlc/core/__tests__/dlc/finance/LongPut.spec.ts +0 -55
  25. package/.yalc/@node-dlc/core/__tests__/dlc/finance/OptionInfo.spec.ts +0 -226
  26. package/.yalc/@node-dlc/core/__tests__/dlc/finance/ShortPut.spec.ts +0 -62
  27. package/.yalc/@node-dlc/core/__tests__/tsconfig.json +0 -8
  28. package/.yalc/@node-dlc/core/__tests__/utils/precision.spec.ts +0 -40
  29. package/.yalc/@node-dlc/core/coverage/lcov-report/base.css +0 -224
  30. package/.yalc/@node-dlc/core/coverage/lcov-report/block-navigation.js +0 -79
  31. package/.yalc/@node-dlc/core/coverage/lcov-report/favicon.png +0 -0
  32. package/.yalc/@node-dlc/core/coverage/lcov-report/index.html +0 -171
  33. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/AsyncProcessingQueue.ts.html +0 -269
  34. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/Base32.ts.html +0 -86
  35. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/BigIntUtils.ts.html +0 -86
  36. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/BitField.ts.html +0 -86
  37. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/ChannelId.ts.html +0 -86
  38. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/LinkedList.ts.html +0 -413
  39. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/LinkedListNode.ts.html +0 -122
  40. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/Queue.ts.html +0 -188
  41. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/ShortChannelId.ts.html +0 -86
  42. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/ShortChannelIdUtils.ts.html +0 -107
  43. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/CETCalculator.ts.html +0 -1430
  44. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/CoinSelect.ts.html +0 -431
  45. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/HyperbolaPayoutCurve.ts.html +0 -644
  46. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/PolynomialPayoutCurve.ts.html +0 -878
  47. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/TxBuilder.ts.html +0 -1088
  48. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/TxFinalizer.ts.html +0 -731
  49. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/Builder.ts.html +0 -2270
  50. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/CoveredCall.ts.html +0 -410
  51. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/CsoInfo.ts.html +0 -1574
  52. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/LinearPayout.ts.html +0 -362
  53. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/LongCall.ts.html +0 -302
  54. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/LongPut.ts.html +0 -302
  55. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/OptionInfo.ts.html +0 -626
  56. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/ShortPut.ts.html +0 -305
  57. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/index.html +0 -216
  58. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/index.html +0 -186
  59. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/index.html +0 -261
  60. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/index.ts.html +0 -278
  61. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/ChannelId.ts.html +0 -242
  62. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/ChannelKeys.ts.html +0 -407
  63. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/CommitmentNumber.ts.html +0 -362
  64. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/CommitmentSecret.ts.html +0 -203
  65. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/CommitmentSecretStore.ts.html +0 -332
  66. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/Htlc.ts.html +0 -236
  67. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/HtlcDirection.ts.html +0 -131
  68. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/ScriptFactory.ts.html +0 -530
  69. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/TxFactory.ts.html +0 -1094
  70. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/index.html +0 -231
  71. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/utils/BigIntUtils.ts.html +0 -272
  72. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/utils/Precision.ts.html +0 -149
  73. package/.yalc/@node-dlc/core/coverage/lcov-report/lib/utils/index.html +0 -126
  74. package/.yalc/@node-dlc/core/coverage/lcov-report/prettify.css +0 -1
  75. package/.yalc/@node-dlc/core/coverage/lcov-report/prettify.js +0 -2
  76. package/.yalc/@node-dlc/core/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  77. package/.yalc/@node-dlc/core/coverage/lcov-report/sorter.js +0 -170
  78. package/.yalc/@node-dlc/core/coverage/lcov.info +0 -2426
  79. package/.yalc/@node-dlc/core/dist/AsyncProcessingQueue.d.ts +0 -22
  80. package/.yalc/@node-dlc/core/dist/AsyncProcessingQueue.js +0 -55
  81. package/.yalc/@node-dlc/core/dist/AsyncProcessingQueue.js.map +0 -1
  82. package/.yalc/@node-dlc/core/dist/Base32.d.ts +0 -1
  83. package/.yalc/@node-dlc/core/dist/Base32.js +0 -7
  84. package/.yalc/@node-dlc/core/dist/Base32.js.map +0 -1
  85. package/.yalc/@node-dlc/core/dist/BigIntUtils.d.ts +0 -1
  86. package/.yalc/@node-dlc/core/dist/BigIntUtils.js +0 -8
  87. package/.yalc/@node-dlc/core/dist/BigIntUtils.js.map +0 -1
  88. package/.yalc/@node-dlc/core/dist/BitField.d.ts +0 -1
  89. package/.yalc/@node-dlc/core/dist/BitField.js +0 -7
  90. package/.yalc/@node-dlc/core/dist/BitField.js.map +0 -1
  91. package/.yalc/@node-dlc/core/dist/ChannelId.d.ts +0 -1
  92. package/.yalc/@node-dlc/core/dist/ChannelId.js +0 -7
  93. package/.yalc/@node-dlc/core/dist/ChannelId.js.map +0 -1
  94. package/.yalc/@node-dlc/core/dist/LinkedList.d.ts +0 -30
  95. package/.yalc/@node-dlc/core/dist/LinkedList.js +0 -104
  96. package/.yalc/@node-dlc/core/dist/LinkedList.js.map +0 -1
  97. package/.yalc/@node-dlc/core/dist/LinkedListNode.d.ts +0 -9
  98. package/.yalc/@node-dlc/core/dist/LinkedListNode.js +0 -15
  99. package/.yalc/@node-dlc/core/dist/LinkedListNode.js.map +0 -1
  100. package/.yalc/@node-dlc/core/dist/Queue.d.ts +0 -22
  101. package/.yalc/@node-dlc/core/dist/Queue.js +0 -38
  102. package/.yalc/@node-dlc/core/dist/Queue.js.map +0 -1
  103. package/.yalc/@node-dlc/core/dist/ShortChannelId.d.ts +0 -1
  104. package/.yalc/@node-dlc/core/dist/ShortChannelId.js +0 -7
  105. package/.yalc/@node-dlc/core/dist/ShortChannelId.js.map +0 -1
  106. package/.yalc/@node-dlc/core/dist/ShortChannelIdUtils.d.ts +0 -1
  107. package/.yalc/@node-dlc/core/dist/ShortChannelIdUtils.js +0 -12
  108. package/.yalc/@node-dlc/core/dist/ShortChannelIdUtils.js.map +0 -1
  109. package/.yalc/@node-dlc/core/dist/dlc/CETCalculator.d.ts +0 -50
  110. package/.yalc/@node-dlc/core/dist/dlc/CETCalculator.js +0 -332
  111. package/.yalc/@node-dlc/core/dist/dlc/CETCalculator.js.map +0 -1
  112. package/.yalc/@node-dlc/core/dist/dlc/CoinSelect.d.ts +0 -23
  113. package/.yalc/@node-dlc/core/dist/dlc/CoinSelect.js +0 -77
  114. package/.yalc/@node-dlc/core/dist/dlc/CoinSelect.js.map +0 -1
  115. package/.yalc/@node-dlc/core/dist/dlc/HyperbolaPayoutCurve.d.ts +0 -20
  116. package/.yalc/@node-dlc/core/dist/dlc/HyperbolaPayoutCurve.js +0 -117
  117. package/.yalc/@node-dlc/core/dist/dlc/HyperbolaPayoutCurve.js.map +0 -1
  118. package/.yalc/@node-dlc/core/dist/dlc/PayoutCurve.d.ts +0 -5
  119. package/.yalc/@node-dlc/core/dist/dlc/PayoutCurve.js +0 -3
  120. package/.yalc/@node-dlc/core/dist/dlc/PayoutCurve.js.map +0 -1
  121. package/.yalc/@node-dlc/core/dist/dlc/PolynomialPayoutCurve.d.ts +0 -52
  122. package/.yalc/@node-dlc/core/dist/dlc/PolynomialPayoutCurve.js +0 -173
  123. package/.yalc/@node-dlc/core/dist/dlc/PolynomialPayoutCurve.js.map +0 -1
  124. package/.yalc/@node-dlc/core/dist/dlc/TxBuilder.d.ts +0 -55
  125. package/.yalc/@node-dlc/core/dist/dlc/TxBuilder.js +0 -217
  126. package/.yalc/@node-dlc/core/dist/dlc/TxBuilder.js.map +0 -1
  127. package/.yalc/@node-dlc/core/dist/dlc/TxFinalizer.d.ts +0 -40
  128. package/.yalc/@node-dlc/core/dist/dlc/TxFinalizer.js +0 -146
  129. package/.yalc/@node-dlc/core/dist/dlc/TxFinalizer.js.map +0 -1
  130. package/.yalc/@node-dlc/core/dist/dlc/finance/Builder.d.ts +0 -193
  131. package/.yalc/@node-dlc/core/dist/dlc/finance/Builder.js +0 -422
  132. package/.yalc/@node-dlc/core/dist/dlc/finance/Builder.js.map +0 -1
  133. package/.yalc/@node-dlc/core/dist/dlc/finance/CoveredCall.d.ts +0 -13
  134. package/.yalc/@node-dlc/core/dist/dlc/finance/CoveredCall.js +0 -67
  135. package/.yalc/@node-dlc/core/dist/dlc/finance/CoveredCall.js.map +0 -1
  136. package/.yalc/@node-dlc/core/dist/dlc/finance/CsoInfo.d.ts +0 -114
  137. package/.yalc/@node-dlc/core/dist/dlc/finance/CsoInfo.js +0 -290
  138. package/.yalc/@node-dlc/core/dist/dlc/finance/CsoInfo.js.map +0 -1
  139. package/.yalc/@node-dlc/core/dist/dlc/finance/LinearPayout.d.ts +0 -6
  140. package/.yalc/@node-dlc/core/dist/dlc/finance/LinearPayout.js +0 -79
  141. package/.yalc/@node-dlc/core/dist/dlc/finance/LinearPayout.js.map +0 -1
  142. package/.yalc/@node-dlc/core/dist/dlc/finance/LongCall.d.ts +0 -13
  143. package/.yalc/@node-dlc/core/dist/dlc/finance/LongCall.js +0 -47
  144. package/.yalc/@node-dlc/core/dist/dlc/finance/LongCall.js.map +0 -1
  145. package/.yalc/@node-dlc/core/dist/dlc/finance/LongPut.d.ts +0 -13
  146. package/.yalc/@node-dlc/core/dist/dlc/finance/LongPut.js +0 -47
  147. package/.yalc/@node-dlc/core/dist/dlc/finance/LongPut.js.map +0 -1
  148. package/.yalc/@node-dlc/core/dist/dlc/finance/OptionInfo.d.ts +0 -20
  149. package/.yalc/@node-dlc/core/dist/dlc/finance/OptionInfo.js +0 -101
  150. package/.yalc/@node-dlc/core/dist/dlc/finance/OptionInfo.js.map +0 -1
  151. package/.yalc/@node-dlc/core/dist/dlc/finance/ShortPut.d.ts +0 -12
  152. package/.yalc/@node-dlc/core/dist/dlc/finance/ShortPut.js +0 -46
  153. package/.yalc/@node-dlc/core/dist/dlc/finance/ShortPut.js.map +0 -1
  154. package/.yalc/@node-dlc/core/dist/index.d.ts +0 -39
  155. package/.yalc/@node-dlc/core/dist/index.js +0 -78
  156. package/.yalc/@node-dlc/core/dist/index.js.map +0 -1
  157. package/.yalc/@node-dlc/core/dist/lightning/ChannelId.d.ts +0 -31
  158. package/.yalc/@node-dlc/core/dist/lightning/ChannelId.js +0 -52
  159. package/.yalc/@node-dlc/core/dist/lightning/ChannelId.js.map +0 -1
  160. package/.yalc/@node-dlc/core/dist/lightning/ChannelKeys.d.ts +0 -55
  161. package/.yalc/@node-dlc/core/dist/lightning/ChannelKeys.js +0 -105
  162. package/.yalc/@node-dlc/core/dist/lightning/ChannelKeys.js.map +0 -1
  163. package/.yalc/@node-dlc/core/dist/lightning/CommitmentNumber.d.ts +0 -55
  164. package/.yalc/@node-dlc/core/dist/lightning/CommitmentNumber.js +0 -76
  165. package/.yalc/@node-dlc/core/dist/lightning/CommitmentNumber.js.map +0 -1
  166. package/.yalc/@node-dlc/core/dist/lightning/CommitmentSecret.d.ts +0 -26
  167. package/.yalc/@node-dlc/core/dist/lightning/CommitmentSecret.js +0 -44
  168. package/.yalc/@node-dlc/core/dist/lightning/CommitmentSecret.js.map +0 -1
  169. package/.yalc/@node-dlc/core/dist/lightning/CommitmentSecretStore.d.ts +0 -41
  170. package/.yalc/@node-dlc/core/dist/lightning/CommitmentSecretStore.js +0 -79
  171. package/.yalc/@node-dlc/core/dist/lightning/CommitmentSecretStore.js.map +0 -1
  172. package/.yalc/@node-dlc/core/dist/lightning/Htlc.d.ts +0 -46
  173. package/.yalc/@node-dlc/core/dist/lightning/Htlc.js +0 -46
  174. package/.yalc/@node-dlc/core/dist/lightning/Htlc.js.map +0 -1
  175. package/.yalc/@node-dlc/core/dist/lightning/HtlcDirection.d.ts +0 -16
  176. package/.yalc/@node-dlc/core/dist/lightning/HtlcDirection.js +0 -21
  177. package/.yalc/@node-dlc/core/dist/lightning/HtlcDirection.js.map +0 -1
  178. package/.yalc/@node-dlc/core/dist/lightning/ScriptFactory.d.ts +0 -76
  179. package/.yalc/@node-dlc/core/dist/lightning/ScriptFactory.js +0 -102
  180. package/.yalc/@node-dlc/core/dist/lightning/ScriptFactory.js.map +0 -1
  181. package/.yalc/@node-dlc/core/dist/lightning/TxFactory.d.ts +0 -83
  182. package/.yalc/@node-dlc/core/dist/lightning/TxFactory.js +0 -222
  183. package/.yalc/@node-dlc/core/dist/lightning/TxFactory.js.map +0 -1
  184. package/.yalc/@node-dlc/core/dist/utils/BigIntUtils.d.ts +0 -9
  185. package/.yalc/@node-dlc/core/dist/utils/BigIntUtils.js +0 -59
  186. package/.yalc/@node-dlc/core/dist/utils/BigIntUtils.js.map +0 -1
  187. package/.yalc/@node-dlc/core/dist/utils/Precision.d.ts +0 -13
  188. package/.yalc/@node-dlc/core/dist/utils/Precision.js +0 -28
  189. package/.yalc/@node-dlc/core/dist/utils/Precision.js.map +0 -1
  190. package/.yalc/@node-dlc/core/lib/AsyncProcessingQueue.ts +0 -63
  191. package/.yalc/@node-dlc/core/lib/Base32.ts +0 -2
  192. package/.yalc/@node-dlc/core/lib/BigIntUtils.ts +0 -2
  193. package/.yalc/@node-dlc/core/lib/BitField.ts +0 -2
  194. package/.yalc/@node-dlc/core/lib/ChannelId.ts +0 -2
  195. package/.yalc/@node-dlc/core/lib/LinkedList.ts +0 -111
  196. package/.yalc/@node-dlc/core/lib/LinkedListNode.ts +0 -14
  197. package/.yalc/@node-dlc/core/lib/Queue.ts +0 -36
  198. package/.yalc/@node-dlc/core/lib/ShortChannelId.ts +0 -2
  199. package/.yalc/@node-dlc/core/lib/ShortChannelIdUtils.ts +0 -9
  200. package/.yalc/@node-dlc/core/lib/dlc/CETCalculator.ts +0 -450
  201. package/.yalc/@node-dlc/core/lib/dlc/CoinSelect.ts +0 -117
  202. package/.yalc/@node-dlc/core/lib/dlc/HyperbolaPayoutCurve.ts +0 -188
  203. package/.yalc/@node-dlc/core/lib/dlc/PayoutCurve.ts +0 -6
  204. package/.yalc/@node-dlc/core/lib/dlc/PolynomialPayoutCurve.ts +0 -266
  205. package/.yalc/@node-dlc/core/lib/dlc/TxBuilder.ts +0 -336
  206. package/.yalc/@node-dlc/core/lib/dlc/TxFinalizer.ts +0 -217
  207. package/.yalc/@node-dlc/core/lib/dlc/finance/Builder.ts +0 -730
  208. package/.yalc/@node-dlc/core/lib/dlc/finance/CoveredCall.ts +0 -110
  209. package/.yalc/@node-dlc/core/lib/dlc/finance/CsoInfo.ts +0 -498
  210. package/.yalc/@node-dlc/core/lib/dlc/finance/LinearPayout.ts +0 -94
  211. package/.yalc/@node-dlc/core/lib/dlc/finance/LongCall.ts +0 -74
  212. package/.yalc/@node-dlc/core/lib/dlc/finance/LongPut.ts +0 -74
  213. package/.yalc/@node-dlc/core/lib/dlc/finance/OptionInfo.ts +0 -182
  214. package/.yalc/@node-dlc/core/lib/dlc/finance/ShortPut.ts +0 -75
  215. package/.yalc/@node-dlc/core/lib/index.ts +0 -66
  216. package/.yalc/@node-dlc/core/lib/lightning/ChannelId.ts +0 -54
  217. package/.yalc/@node-dlc/core/lib/lightning/ChannelKeys.ts +0 -109
  218. package/.yalc/@node-dlc/core/lib/lightning/CommitmentNumber.ts +0 -94
  219. package/.yalc/@node-dlc/core/lib/lightning/CommitmentSecret.ts +0 -41
  220. package/.yalc/@node-dlc/core/lib/lightning/CommitmentSecretStore.ts +0 -84
  221. package/.yalc/@node-dlc/core/lib/lightning/Htlc.ts +0 -52
  222. package/.yalc/@node-dlc/core/lib/lightning/HtlcDirection.ts +0 -17
  223. package/.yalc/@node-dlc/core/lib/lightning/ScriptFactory.ts +0 -150
  224. package/.yalc/@node-dlc/core/lib/lightning/TxFactory.ts +0 -338
  225. package/.yalc/@node-dlc/core/lib/utils/BigIntUtils.ts +0 -64
  226. package/.yalc/@node-dlc/core/lib/utils/Precision.ts +0 -23
  227. package/.yalc/@node-dlc/core/package.json +0 -38
  228. package/.yalc/@node-dlc/core/tsconfig.json +0 -8
  229. package/.yalc/@node-dlc/core/yalc.sig +0 -1
  230. package/yalc.lock +0 -10
@@ -1,338 +0,0 @@
1
- import {
2
- HashValue,
3
- LockTime,
4
- OutPoint,
5
- Script,
6
- Sequence,
7
- TxBuilder,
8
- TxOut,
9
- Value,
10
- } from '@node-dlc/bitcoin';
11
-
12
- import { CommitmentNumber } from './CommitmentNumber';
13
- import { Htlc } from './Htlc';
14
- import { HtlcDirection } from './HtlcDirection';
15
- import { ScriptFactory } from './ScriptFactory';
16
-
17
- export class TxFactory {
18
- /**
19
- * Creates a TxOut to attach to a funding transaction. This includes
20
- * the P2WSH-P2MS script that uses 2-2MS. The open and accept funding
21
- * pubkeys are sorted lexicographcially to create the script.
22
- * @param builder
23
- */
24
- public static createFundingOutput(
25
- value: Value,
26
- openPubKey: Buffer,
27
- acceptPubKey: Buffer,
28
- ): TxOut {
29
- const script = Script.p2wshLock(
30
- ScriptFactory.fundingScript(openPubKey, acceptPubKey),
31
- );
32
- return new TxOut(value, script);
33
- }
34
-
35
- /**
36
- * Constructs an unsigned commitment transaction according to BOLT3.
37
- * This method is a low level commitment transaction builder, meaning
38
- * it accepts primatives and constructs a commitment transaction
39
- * accordingly. The proper inputs are determiend
40
- *
41
- * @param isFunderLocal True when the funding node is local. This
42
- * is used to determine which output pays fees (to_local/to_remote).
43
- * @param commitmentNumber The commitment number of the transaction
44
- * which is used to generate the obscurred commitment number.
45
- * @param openPaymentBasePoint The basepoint sent in open_channel
46
- * which is used to generate the obscurred commitment number.
47
- * @param acceptPaymentBasePoint The basepoitn sent in accept_channel
48
- * which is used to generate the obscurred commitment number.
49
- * @param fundingOutPoint The outpoint of the funding transaction
50
- * which was established in funding_created.
51
- * @param dustLimitSatoshi The dust limit in sats after which outputs
52
- * will be prune
53
- * @param feePerKw The fee rate per kiloweight which will be deducted
54
- * from the funding node's output
55
- * @param localDelay The delay applied to the to_local output
56
- * @param localValue Value paid to the to_local RSMC output
57
- * @param remoteValue Value paid to the to_emote P2WPKH output
58
- * @param revocationPubKey The revocation public key used to in the
59
- * to_local and HTLC outputs
60
- * @param delayedPubKey The delayed public key used to spend the
61
- * to_local output
62
- * @param remotePubKey The public key used to spend the to_remote
63
- * output
64
- * @param reverseHtlcs True when the HTLC direction needs to be
65
- * inverted because the holder of this commitment transaction is
66
- * our counterparty.
67
- * @param localHtlcPubKey The public key used to spend HTLC outputs
68
- * by the commitment holder.
69
- * @param remoteHtlcPubKey The public key used to spend HTLC outputs
70
- * by the commitment counterparty.
71
- * @param htlcs A full list of HTLCs that will be selectively
72
- * included in the commitment transaction based on the feePerKw.
73
- */
74
- public static createCommitment(
75
- isFunderLocal: boolean,
76
- commitmentNumber: number,
77
- openPaymentBasePoint: Buffer,
78
- acceptPaymentBasePoint: Buffer,
79
- fundingOutPoint: OutPoint,
80
- dustLimitSatoshi: Value,
81
- feePerKw: bigint,
82
- localDelay: number,
83
- localValue: Value,
84
- remoteValue: Value,
85
- revocationPubKey: Buffer,
86
- delayedPubKey: Buffer,
87
- remotePubKey: Buffer,
88
- reverseHtlcs: boolean,
89
- localHtlcPubKey?: Buffer,
90
- remoteHtlcPubKey?: Buffer,
91
- htlcs: Htlc[] = [],
92
- ): [TxBuilder, Htlc[]] {
93
- const obscuredCommitmentNumber = CommitmentNumber.obscure(
94
- commitmentNumber,
95
- openPaymentBasePoint,
96
- acceptPaymentBasePoint,
97
- );
98
-
99
- // 1. add the input as the funding outpoint and set the nSequence
100
- const tx = new TxBuilder();
101
- tx.version = 2;
102
- tx.addInput(
103
- fundingOutPoint,
104
- CommitmentNumber.getSequence(obscuredCommitmentNumber),
105
- );
106
-
107
- // 2. set the locktime to the obscurred commitment number
108
- tx.locktime = CommitmentNumber.getLockTime(obscuredCommitmentNumber);
109
-
110
- // 3. find unpruned outputs
111
- const unprunedHtlcs: Htlc[] = [];
112
- for (const htlc of htlcs) {
113
- const valueInSats = htlc.value.sats;
114
- let feeWeight: bigint;
115
-
116
- // HtlcDirection refers to the local nodes perception of the HTLC.
117
- // When isLocal, offered uses the HTLC-Timeout weight of 663. When
118
- // remote, the commitment is for the remote counterparty and an
119
- // offered HTLC is received and will be spent by the remote
120
- // counterparty using the HTLC-Success transaction with a weight of 703
121
- if (reverseHtlcs) {
122
- feeWeight =
123
- htlc.direction === HtlcDirection.Offered ? BigInt(703) : BigInt(663);
124
- } else {
125
- feeWeight =
126
- htlc.direction === HtlcDirection.Offered ? BigInt(663) : BigInt(703);
127
- }
128
-
129
- // Calculate the HTLC less fees
130
- const feeInSats = (feeWeight * feePerKw) / BigInt(1000);
131
- const satsLessFee = valueInSats - feeInSats;
132
-
133
- // Only keep HTLCs greater than the dustLimitSatoshi for the tx
134
- if (satsLessFee >= dustLimitSatoshi.sats) {
135
- unprunedHtlcs.push(htlc);
136
- }
137
- }
138
-
139
- // 4. calculate base fee
140
- const weight = 724 + unprunedHtlcs.length * 172;
141
- const baseFee = (BigInt(weight) * feePerKw) / BigInt(1000);
142
-
143
- // 5. substract base fee from funding node
144
- if (isFunderLocal) {
145
- const newValue = localValue.sats - baseFee;
146
- if (newValue > BigInt(0)) {
147
- localValue = Value.fromSats(newValue);
148
- } else {
149
- localValue = Value.zero();
150
- }
151
- } else {
152
- const newValue = remoteValue.sats - baseFee;
153
- if (newValue > BigInt(0)) {
154
- remoteValue = Value.fromSats(newValue);
155
- } else {
156
- remoteValue = Value.zero();
157
- }
158
- }
159
-
160
- // 6/7. add unpruned offered/received HTLCs
161
- const txouts: Array<[TxOut, Htlc?]> = [];
162
- for (const htlc of unprunedHtlcs) {
163
- const witnessScript: Script =
164
- (!reverseHtlcs && htlc.direction === HtlcDirection.Offered) ||
165
- (reverseHtlcs && htlc.direction === HtlcDirection.Accepted)
166
- ? ScriptFactory.offeredHtlcScript(
167
- htlc.paymentHash,
168
- revocationPubKey,
169
- localHtlcPubKey,
170
- remoteHtlcPubKey,
171
- )
172
- : ScriptFactory.receivedHtlcScript(
173
- htlc.paymentHash,
174
- htlc.cltvExpiry,
175
- revocationPubKey,
176
- localHtlcPubKey,
177
- remoteHtlcPubKey,
178
- );
179
- const txout = new TxOut(htlc.value, Script.p2wshLock(witnessScript));
180
- txouts.push([txout, htlc]);
181
- }
182
-
183
- // 8. add local if unpruned
184
- if (localValue.sats >= dustLimitSatoshi.sats) {
185
- txouts.push([
186
- new TxOut(
187
- localValue,
188
- Script.p2wshLock(
189
- ScriptFactory.toLocalScript(
190
- revocationPubKey,
191
- delayedPubKey,
192
- localDelay,
193
- ),
194
- ),
195
- ),
196
- ]);
197
- }
198
-
199
- // 9. add remote if unpruned
200
- if (remoteValue.sats >= dustLimitSatoshi.sats) {
201
- txouts.push([new TxOut(remoteValue, Script.p2wpkhLock(remotePubKey))]);
202
- }
203
-
204
- // 10. sort outputs using bip69 and using cltv for htlc tiebreaks
205
- txouts.sort((a, b) => {
206
- // compare on value
207
- const value = Number(a[0].value.sats - b[0].value.sats);
208
- if (value !== 0) return value;
209
-
210
- // compare on script
211
- const scriptCompare = a[0].scriptPubKey
212
- .serializeCmds()
213
- .compare(b[0].scriptPubKey.serializeCmds());
214
- if (scriptCompare !== 0) return scriptCompare;
215
-
216
- // tie-break on htlcs
217
- return b[1].cltvExpiry - a[1].cltvExpiry;
218
- });
219
-
220
- // add hte outputs in sorted order
221
- const sortedHtlcs: Htlc[] = [];
222
- for (const [txout, htlc] of txouts) {
223
- tx.addOutput(txout);
224
- sortedHtlcs.push(htlc);
225
- }
226
-
227
- // return the tuple with the sorted htlcs
228
- return [tx, sortedHtlcs];
229
- }
230
-
231
- /**
232
- * Constructs an HTLC-Timeout transaction as defined in BOLT3. This
233
- * transaction spends an offered HTLC from the commitment transaction
234
- * and outputs the HTLC value less the fee. The output is spendable
235
- * via an RSMC that is sequence locked for the received by the
236
- * transaction owner. Finally this transaction has an absolute
237
- * locktime of the HTLC's cltv expiry.
238
- * @param commitmentTx
239
- * @param outputIndex
240
- * @param localDelay
241
- * @param revocationPubKey
242
- * @param delayedPubKey
243
- * @param feePerKw
244
- * @param htlc
245
- */
246
- public static createHtlcTimeout(
247
- commitmentTx: HashValue,
248
- outputIndex: number,
249
- localDelay: number,
250
- revocationPubKey: Buffer,
251
- delayedPubKey: Buffer,
252
- feePerKw: bigint,
253
- htlc: Htlc,
254
- ): TxBuilder {
255
- const tx = new TxBuilder();
256
-
257
- // Input points to the commmitment transaction and the BIP69
258
- // sorted index of the HTLC. nSequence is set to zero.
259
- tx.addInput(new OutPoint(commitmentTx, outputIndex), Sequence.zero());
260
-
261
- // calc value less fees for this transaction
262
- const weight = BigInt(663);
263
- const fees = (weight * feePerKw) / BigInt(1000);
264
- const sats = fees > htlc.value.sats ? 0 : htlc.value.sats - fees;
265
-
266
- // Spends a P2WSH RSMC
267
- tx.addOutput(
268
- Value.fromSats(sats),
269
- Script.p2wshLock(
270
- ScriptFactory.toLocalScript(
271
- revocationPubKey,
272
- delayedPubKey,
273
- localDelay,
274
- ),
275
- ),
276
- );
277
-
278
- // nLocktime is set to the cltvExpiry of the HTLC. This prevents
279
- // the HTLC-Timeout from being broadcast until after the expiry
280
- // has been reached.
281
- tx.locktime = new LockTime(htlc.cltvExpiry);
282
-
283
- return tx;
284
- }
285
-
286
- /**
287
- * Constructs an HTLC-Success transaction as defined in BOLT3. This
288
- * transaction spends a received HTLC form the commitment transaction
289
- * and outputs the HTLC value less the fee. The output is spendable
290
- * via an RSMC that is sequence locked for the received by the
291
- * transaction owner.
292
- * @param commitmentTx
293
- * @param outputIndex
294
- * @param localDelay
295
- * @param revocationPubKey
296
- * @param delayedPubKey
297
- * @param feePerKw
298
- * @param htlc
299
- */
300
- public static createHtlcSuccess(
301
- commitmentTx: HashValue,
302
- outputIndex: number,
303
- localDelay: number,
304
- revocationPubKey: Buffer,
305
- delayedPubKey: Buffer,
306
- feePerKw: bigint,
307
- htlc: Htlc,
308
- ): TxBuilder {
309
- const tx = new TxBuilder();
310
-
311
- // Input points to the commmitment transaction and the BIP69
312
- // sorted index of the HTLC. nSequence is set to zero.
313
- tx.addInput(new OutPoint(commitmentTx, outputIndex), Sequence.zero());
314
-
315
- // calc value less fees for this transaction
316
- const weight = BigInt(703);
317
- const fees = (weight * feePerKw) / BigInt(1000);
318
- const sats = fees > htlc.value.sats ? 0 : htlc.value.sats - fees;
319
-
320
- // Spends a P2WSH RSMC
321
- tx.addOutput(
322
- Value.fromSats(sats),
323
- Script.p2wshLock(
324
- ScriptFactory.toLocalScript(
325
- revocationPubKey,
326
- delayedPubKey,
327
- localDelay,
328
- ),
329
- ),
330
- );
331
-
332
- // nLockTime is zero since the tx owner can immediately spend
333
- // this transaction if they have the preimage
334
- tx.locktime = LockTime.zero();
335
-
336
- return tx;
337
- }
338
- }
@@ -1,64 +0,0 @@
1
- import BigNumber from 'bignumber.js';
2
-
3
- export class BigIntMath {
4
- static max(...values: bigint[]): bigint {
5
- if (values.length === 0) {
6
- return null;
7
- }
8
-
9
- if (values.length === 1) {
10
- return values[0];
11
- }
12
-
13
- let max = values[0];
14
- for (let i = 1; i < values.length; i++) {
15
- if (values[i] > max) {
16
- max = values[i];
17
- }
18
- }
19
- return max;
20
- }
21
-
22
- static min(...values: bigint[]): bigint {
23
- if (values.length === 0) {
24
- return null;
25
- }
26
-
27
- if (values.length === 1) {
28
- return values[0];
29
- }
30
-
31
- let min = values[0];
32
- for (let i = 1; i < values.length; i++) {
33
- if (values[i] < min) {
34
- min = values[i];
35
- }
36
- }
37
- return min;
38
- }
39
-
40
- static sign(value: bigint): bigint {
41
- if (value > BigInt(0)) {
42
- return BigInt(1);
43
- }
44
- if (value < BigInt(0)) {
45
- return BigInt(-1);
46
- }
47
- return BigInt(0);
48
- }
49
-
50
- static abs(value: bigint): bigint {
51
- if (this.sign(value) === BigInt(-1)) {
52
- return -value;
53
- }
54
- return value;
55
- }
56
-
57
- static clamp(min: bigint, val: bigint, max: bigint): bigint {
58
- return this.max(min, this.min(val, max));
59
- }
60
- }
61
-
62
- export function toBigInt(num: BigNumber): bigint {
63
- return BigInt(num.integerValue().toString());
64
- }
@@ -1,23 +0,0 @@
1
- import BigNumber from 'bignumber.js';
2
-
3
- // Precision refers to the number of digits after the decimal point.
4
- // Refer to https://github.com/discreetlogcontracts/dlcspecs/blob/master/PayoutCurve.md#version-0-payout_function
5
-
6
- /**
7
- * Extract the precision of a number
8
- * @param num
9
- * @returns The precision of the number
10
- */
11
- export const getPrecision = (num: BigNumber): number =>
12
- num.decimalPlaces(16).abs().modulo(1).shiftedBy(16).toNumber();
13
-
14
- /**
15
- * Creates a precise number from a precision
16
- * @param precision
17
- * @returns The number with the given precision
18
- */
19
- export const fromPrecision = (precision: number): BigNumber => {
20
- if (precision.toString().length > 16)
21
- throw new Error('Precision is too large');
22
- return new BigNumber(precision).shiftedBy(-16);
23
- };
@@ -1,38 +0,0 @@
1
- {
2
- "name": "@node-dlc/core",
3
- "version": "1.0.1",
4
- "description": "DLC Core",
5
- "scripts": {
6
- "start": "npm run build && node dist/index.js",
7
- "test": "../../node_modules/.bin/nyc --reporter=lcov --reporter=text --extension=.ts ../../node_modules/.bin/mocha --require ts-node/register --recursive \"__tests__/**/*.spec.*\"",
8
- "lint": "../../node_modules/.bin/eslint --ignore-path ../../.eslintignore -c ../../.eslintrc.js .",
9
- "lint:fix": "../../node_modules/.bin/eslint --fix --ignore-path ../../.eslintignore -c ../../.eslintrc.js .",
10
- "build": "../../node_modules/.bin/tsc --project tsconfig.json"
11
- },
12
- "keywords": [
13
- "dlc",
14
- "core"
15
- ],
16
- "author": "Atomic Finance <info@atomic.finance>",
17
- "homepage": "https://github.com/atomicfinance/node-dlc/tree/master/packages/daemon",
18
- "license": "MIT",
19
- "main": "dist/index.js",
20
- "repository": {
21
- "type": "git",
22
- "url": "git+https://github.com/atomicfinance/node-dlc.git"
23
- },
24
- "dependencies": {
25
- "@node-dlc/bitcoin": "^1.0.1",
26
- "@node-dlc/bufio": "^1.0.1",
27
- "@node-dlc/common": "^1.0.1",
28
- "@node-dlc/crypto": "^1.0.1",
29
- "@node-dlc/messaging": "^1.0.1",
30
- "bignumber.js": "^9.0.1",
31
- "bitcoin-networks": "^1.0.0",
32
- "decimal.js": "10.4.3"
33
- },
34
- "publishConfig": {
35
- "access": "public"
36
- },
37
- "yalcSig": "d6b67fd54b29f78ffbe9737666f9467e"
38
- }
@@ -1,8 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "./dist"
5
- },
6
- "include": ["./lib"],
7
- "exclude": ["./dist", "node_modules"]
8
- }
@@ -1 +0,0 @@
1
- d6b67fd54b29f78ffbe9737666f9467e
package/yalc.lock DELETED
@@ -1,10 +0,0 @@
1
- {
2
- "version": "v1",
3
- "packages": {
4
- "@node-dlc/core": {
5
- "signature": "d6b67fd54b29f78ffbe9737666f9467e",
6
- "file": true,
7
- "replaced": "1.0.1"
8
- }
9
- }
10
- }