@atomicfinance/bitcoin-wallet-provider 4.1.3 → 4.1.5

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 +5 -4
  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 +24 -0
  225. package/package.json +6 -6
  226. package/yalc.lock +10 -0
@@ -0,0 +1,338 @@
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
+ }
@@ -0,0 +1,64 @@
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
+ }
@@ -0,0 +1,23 @@
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
+ };
@@ -0,0 +1,38 @@
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 .",
9
+ "lint:fix": "../../node_modules/.bin/eslint --fix .",
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
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "./dist"
5
+ },
6
+ "include": ["./lib"],
7
+ "exclude": ["./dist", "node_modules"]
8
+ }
@@ -0,0 +1 @@
1
+ d6b67fd54b29f78ffbe9737666f9467e
package/CHANGELOG.md CHANGED
@@ -1,5 +1,29 @@
1
1
  # @atomicfinance/bitcoin-wallet-provider
2
2
 
3
+ ## 4.1.5
4
+
5
+ ### Patch Changes
6
+
7
+ - f1806a6: Implement rust-dlc/ddk compatible Contract ID computation
8
+ - Updated dependencies [f1806a6]
9
+ - @atomicfinance/bitcoin-utils@4.1.5
10
+ - @atomicfinance/errors@4.1.5
11
+ - @atomicfinance/provider@4.1.5
12
+ - @atomicfinance/types@4.1.5
13
+ - @atomicfinance/utils@4.1.5
14
+
15
+ ## 4.1.4
16
+
17
+ ### Patch Changes
18
+
19
+ - 77dd82f: Ensure compact signatures for refund signatures in BitcoinDdkProvider
20
+ - Updated dependencies [77dd82f]
21
+ - @atomicfinance/bitcoin-utils@4.1.4
22
+ - @atomicfinance/errors@4.1.4
23
+ - @atomicfinance/provider@4.1.4
24
+ - @atomicfinance/types@4.1.4
25
+ - @atomicfinance/utils@4.1.4
26
+
3
27
  ## 4.1.3
4
28
 
5
29
  ### Patch Changes
package/package.json CHANGED
@@ -1,18 +1,18 @@
1
1
  {
2
2
  "name": "@atomicfinance/bitcoin-wallet-provider",
3
3
  "umdName": "BitcoinWalletProvider",
4
- "version": "4.1.3",
4
+ "version": "4.1.5",
5
5
  "description": "Bitcoin Abstraction Layer Wallet Provider",
6
6
  "author": "Atomic Finance <info@atomic.finance>",
7
7
  "homepage": "",
8
8
  "license": "ISC",
9
9
  "main": "dist/index.js",
10
10
  "dependencies": {
11
- "@atomicfinance/bitcoin-utils": "^4.1.3",
12
- "@atomicfinance/errors": "^4.1.3",
13
- "@atomicfinance/provider": "^4.1.3",
14
- "@atomicfinance/types": "^4.1.3",
15
- "@atomicfinance/utils": "^4.1.3",
11
+ "@atomicfinance/bitcoin-utils": "^4.1.5",
12
+ "@atomicfinance/errors": "^4.1.5",
13
+ "@atomicfinance/provider": "^4.1.5",
14
+ "@atomicfinance/types": "^4.1.5",
15
+ "@atomicfinance/utils": "^4.1.5",
16
16
  "@node-dlc/core": "1.1.0",
17
17
  "bip32": "^2.0.6",
18
18
  "bitcoin-networks": "^1.0.0",
package/yalc.lock ADDED
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": "v1",
3
+ "packages": {
4
+ "@node-dlc/core": {
5
+ "signature": "d6b67fd54b29f78ffbe9737666f9467e",
6
+ "file": true,
7
+ "replaced": "1.0.1"
8
+ }
9
+ }
10
+ }