@atomicfinance/bitcoin-dlc-provider 3.6.1 → 4.0.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.
- package/.nvmrc +1 -1
- package/.turbo/turbo-lint.log +1 -0
- package/.yalc/@node-dlc/bitcoin/.nyc_output/982e80bf-a70c-452f-b63d-d749ae385531.json +1 -0
- package/.yalc/@node-dlc/bitcoin/.nyc_output/processinfo/982e80bf-a70c-452f-b63d-d749ae385531.json +1 -0
- package/.yalc/@node-dlc/bitcoin/.nyc_output/processinfo/index.json +1 -0
- package/.yalc/@node-dlc/bitcoin/README.md +11 -0
- package/.yalc/@node-dlc/bitcoin/__tests__/bitcoin/amount.spec.ts +330 -0
- package/.yalc/@node-dlc/bitcoin/__tests__/bitcoin/value.spec.ts +320 -0
- package/.yalc/@node-dlc/bitcoin/__tests__/tsconfig.json +8 -0
- package/.yalc/@node-dlc/bitcoin/coverage/lcov-report/Amount.ts.html +290 -0
- package/.yalc/@node-dlc/bitcoin/coverage/lcov-report/Base58.ts.html +269 -0
- package/.yalc/@node-dlc/bitcoin/coverage/lcov-report/Base58Check.ts.html +182 -0
- package/.yalc/@node-dlc/bitcoin/coverage/lcov-report/BitcoinError.ts.html +173 -0
- package/.yalc/@node-dlc/bitcoin/coverage/lcov-report/BitcoinErrorCode.ts.html +110 -0
- package/.yalc/@node-dlc/bitcoin/coverage/lcov-report/HashByteOrder.ts.html +143 -0
- package/.yalc/@node-dlc/bitcoin/coverage/lcov-report/HashValue.ts.html +350 -0
- package/.yalc/@node-dlc/bitcoin/coverage/lcov-report/LexicographicalSorters.ts.html +191 -0
- package/.yalc/@node-dlc/bitcoin/coverage/lcov-report/LockTime.ts.html +386 -0
- package/.yalc/@node-dlc/bitcoin/coverage/lcov-report/OpCodes.ts.html +437 -0
- package/.yalc/@node-dlc/bitcoin/coverage/lcov-report/OutPoint.ts.html +383 -0
- package/.yalc/@node-dlc/bitcoin/coverage/lcov-report/Script.ts.html +1607 -0
- package/.yalc/@node-dlc/bitcoin/coverage/lcov-report/Sequence.ts.html +713 -0
- package/.yalc/@node-dlc/bitcoin/coverage/lcov-report/SigHashType.ts.html +137 -0
- package/.yalc/@node-dlc/bitcoin/coverage/lcov-report/Stack.ts.html +323 -0
- package/.yalc/@node-dlc/bitcoin/coverage/lcov-report/TimeLockMode.ts.html +128 -0
- package/.yalc/@node-dlc/bitcoin/coverage/lcov-report/Tx.ts.html +1520 -0
- package/.yalc/@node-dlc/bitcoin/coverage/lcov-report/TxBuilder.ts.html +971 -0
- package/.yalc/@node-dlc/bitcoin/coverage/lcov-report/TxIn.ts.html +425 -0
- package/.yalc/@node-dlc/bitcoin/coverage/lcov-report/TxOut.ts.html +341 -0
- package/.yalc/@node-dlc/bitcoin/coverage/lcov-report/Value.ts.html +683 -0
- package/.yalc/@node-dlc/bitcoin/coverage/lcov-report/Wif.ts.html +311 -0
- package/.yalc/@node-dlc/bitcoin/coverage/lcov-report/Witness.ts.html +275 -0
- package/.yalc/@node-dlc/bitcoin/coverage/lcov-report/base.css +224 -0
- package/.yalc/@node-dlc/bitcoin/coverage/lcov-report/block-navigation.js +79 -0
- package/.yalc/@node-dlc/bitcoin/coverage/lcov-report/favicon.png +0 -0
- package/.yalc/@node-dlc/bitcoin/coverage/lcov-report/index.html +126 -0
- package/.yalc/@node-dlc/bitcoin/coverage/lcov-report/index.ts.html +164 -0
- package/.yalc/@node-dlc/bitcoin/coverage/lcov-report/prettify.css +1 -0
- package/.yalc/@node-dlc/bitcoin/coverage/lcov-report/prettify.js +2 -0
- package/.yalc/@node-dlc/bitcoin/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/.yalc/@node-dlc/bitcoin/coverage/lcov-report/sorter.js +170 -0
- package/.yalc/@node-dlc/bitcoin/coverage/lcov.info +123 -0
- package/.yalc/@node-dlc/bitcoin/dist/Amount.d.ts +48 -0
- package/.yalc/@node-dlc/bitcoin/dist/Amount.js +68 -0
- package/.yalc/@node-dlc/bitcoin/dist/Amount.js.map +1 -0
- package/.yalc/@node-dlc/bitcoin/dist/Base58.d.ts +22 -0
- package/.yalc/@node-dlc/bitcoin/dist/Base58.js +62 -0
- package/.yalc/@node-dlc/bitcoin/dist/Base58.js.map +1 -0
- package/.yalc/@node-dlc/bitcoin/dist/Base58Check.d.ts +14 -0
- package/.yalc/@node-dlc/bitcoin/dist/Base58Check.js +36 -0
- package/.yalc/@node-dlc/bitcoin/dist/Base58Check.js.map +1 -0
- package/.yalc/@node-dlc/bitcoin/dist/BitcoinError.d.ts +6 -0
- package/.yalc/@node-dlc/bitcoin/dist/BitcoinError.js +36 -0
- package/.yalc/@node-dlc/bitcoin/dist/BitcoinError.js.map +1 -0
- package/.yalc/@node-dlc/bitcoin/dist/BitcoinErrorCode.d.ts +10 -0
- package/.yalc/@node-dlc/bitcoin/dist/BitcoinErrorCode.js +15 -0
- package/.yalc/@node-dlc/bitcoin/dist/BitcoinErrorCode.js.map +1 -0
- package/.yalc/@node-dlc/bitcoin/dist/Block.d.ts +19 -0
- package/.yalc/@node-dlc/bitcoin/dist/Block.js +3 -0
- package/.yalc/@node-dlc/bitcoin/dist/Block.js.map +1 -0
- package/.yalc/@node-dlc/bitcoin/dist/HashByteOrder.d.ts +20 -0
- package/.yalc/@node-dlc/bitcoin/dist/HashByteOrder.js +25 -0
- package/.yalc/@node-dlc/bitcoin/dist/HashByteOrder.js.map +1 -0
- package/.yalc/@node-dlc/bitcoin/dist/HashValue.d.ts +55 -0
- package/.yalc/@node-dlc/bitcoin/dist/HashValue.js +82 -0
- package/.yalc/@node-dlc/bitcoin/dist/HashValue.js.map +1 -0
- package/.yalc/@node-dlc/bitcoin/dist/ICloneable.d.ts +3 -0
- package/.yalc/@node-dlc/bitcoin/dist/ICloneable.js +3 -0
- package/.yalc/@node-dlc/bitcoin/dist/ICloneable.js.map +1 -0
- package/.yalc/@node-dlc/bitcoin/dist/LexicographicalSorters.d.ts +18 -0
- package/.yalc/@node-dlc/bitcoin/dist/LexicographicalSorters.js +41 -0
- package/.yalc/@node-dlc/bitcoin/dist/LexicographicalSorters.js.map +1 -0
- package/.yalc/@node-dlc/bitcoin/dist/LockTime.d.ts +61 -0
- package/.yalc/@node-dlc/bitcoin/dist/LockTime.js +94 -0
- package/.yalc/@node-dlc/bitcoin/dist/LockTime.js.map +1 -0
- package/.yalc/@node-dlc/bitcoin/dist/OpCodes.d.ts +102 -0
- package/.yalc/@node-dlc/bitcoin/dist/OpCodes.js +116 -0
- package/.yalc/@node-dlc/bitcoin/dist/OpCodes.js.map +1 -0
- package/.yalc/@node-dlc/bitcoin/dist/OutPoint.d.ts +57 -0
- package/.yalc/@node-dlc/bitcoin/dist/OutPoint.js +88 -0
- package/.yalc/@node-dlc/bitcoin/dist/OutPoint.js.map +1 -0
- package/.yalc/@node-dlc/bitcoin/dist/Script.d.ts +185 -0
- package/.yalc/@node-dlc/bitcoin/dist/Script.js +404 -0
- package/.yalc/@node-dlc/bitcoin/dist/Script.js.map +1 -0
- package/.yalc/@node-dlc/bitcoin/dist/ScriptCmd.d.ts +3 -0
- package/.yalc/@node-dlc/bitcoin/dist/ScriptCmd.js +3 -0
- package/.yalc/@node-dlc/bitcoin/dist/ScriptCmd.js.map +1 -0
- package/.yalc/@node-dlc/bitcoin/dist/Sequence.d.ts +116 -0
- package/.yalc/@node-dlc/bitcoin/dist/Sequence.js +187 -0
- package/.yalc/@node-dlc/bitcoin/dist/Sequence.js.map +1 -0
- package/.yalc/@node-dlc/bitcoin/dist/SigHashType.d.ts +7 -0
- package/.yalc/@node-dlc/bitcoin/dist/SigHashType.js +27 -0
- package/.yalc/@node-dlc/bitcoin/dist/SigHashType.js.map +1 -0
- package/.yalc/@node-dlc/bitcoin/dist/SizeResult.d.ts +5 -0
- package/.yalc/@node-dlc/bitcoin/dist/SizeResult.js +3 -0
- package/.yalc/@node-dlc/bitcoin/dist/SizeResult.js.map +1 -0
- package/.yalc/@node-dlc/bitcoin/dist/Sorter.d.ts +1 -0
- package/.yalc/@node-dlc/bitcoin/dist/Sorter.js +3 -0
- package/.yalc/@node-dlc/bitcoin/dist/Sorter.js.map +1 -0
- package/.yalc/@node-dlc/bitcoin/dist/Stack.d.ts +15 -0
- package/.yalc/@node-dlc/bitcoin/dist/Stack.js +77 -0
- package/.yalc/@node-dlc/bitcoin/dist/Stack.js.map +1 -0
- package/.yalc/@node-dlc/bitcoin/dist/TimeLockMode.d.ts +15 -0
- package/.yalc/@node-dlc/bitcoin/dist/TimeLockMode.js +20 -0
- package/.yalc/@node-dlc/bitcoin/dist/TimeLockMode.js.map +1 -0
- package/.yalc/@node-dlc/bitcoin/dist/Tx.d.ts +150 -0
- package/.yalc/@node-dlc/bitcoin/dist/Tx.js +408 -0
- package/.yalc/@node-dlc/bitcoin/dist/Tx.js.map +1 -0
- package/.yalc/@node-dlc/bitcoin/dist/TxBuilder.d.ts +110 -0
- package/.yalc/@node-dlc/bitcoin/dist/TxBuilder.js +238 -0
- package/.yalc/@node-dlc/bitcoin/dist/TxBuilder.js.map +1 -0
- package/.yalc/@node-dlc/bitcoin/dist/TxIn.d.ts +71 -0
- package/.yalc/@node-dlc/bitcoin/dist/TxIn.js +79 -0
- package/.yalc/@node-dlc/bitcoin/dist/TxIn.js.map +1 -0
- package/.yalc/@node-dlc/bitcoin/dist/TxOut.d.ts +57 -0
- package/.yalc/@node-dlc/bitcoin/dist/TxOut.js +68 -0
- package/.yalc/@node-dlc/bitcoin/dist/TxOut.js.map +1 -0
- package/.yalc/@node-dlc/bitcoin/dist/Value.d.ts +122 -0
- package/.yalc/@node-dlc/bitcoin/dist/Value.js +180 -0
- package/.yalc/@node-dlc/bitcoin/dist/Value.js.map +1 -0
- package/.yalc/@node-dlc/bitcoin/dist/Wif.d.ts +41 -0
- package/.yalc/@node-dlc/bitcoin/dist/Wif.js +62 -0
- package/.yalc/@node-dlc/bitcoin/dist/Wif.js.map +1 -0
- package/.yalc/@node-dlc/bitcoin/dist/Witness.d.ts +41 -0
- package/.yalc/@node-dlc/bitcoin/dist/Witness.js +63 -0
- package/.yalc/@node-dlc/bitcoin/dist/Witness.js.map +1 -0
- package/.yalc/@node-dlc/bitcoin/dist/index.d.ts +28 -0
- package/.yalc/@node-dlc/bitcoin/dist/index.js +45 -0
- package/.yalc/@node-dlc/bitcoin/dist/index.js.map +1 -0
- package/.yalc/@node-dlc/bitcoin/lib/Amount.ts +70 -0
- package/.yalc/@node-dlc/bitcoin/lib/Base58.ts +63 -0
- package/.yalc/@node-dlc/bitcoin/lib/Base58Check.ts +34 -0
- package/.yalc/@node-dlc/bitcoin/lib/BitcoinError.ts +31 -0
- package/.yalc/@node-dlc/bitcoin/lib/BitcoinErrorCode.ts +10 -0
- package/.yalc/@node-dlc/bitcoin/lib/Block.ts +20 -0
- package/.yalc/@node-dlc/bitcoin/lib/HashByteOrder.ts +21 -0
- package/.yalc/@node-dlc/bitcoin/lib/HashValue.ts +90 -0
- package/.yalc/@node-dlc/bitcoin/lib/ICloneable.ts +3 -0
- package/.yalc/@node-dlc/bitcoin/lib/LexicographicalSorters.ts +37 -0
- package/.yalc/@node-dlc/bitcoin/lib/LockTime.ts +102 -0
- package/.yalc/@node-dlc/bitcoin/lib/OpCodes.ts +119 -0
- package/.yalc/@node-dlc/bitcoin/lib/OutPoint.ts +101 -0
- package/.yalc/@node-dlc/bitcoin/lib/Script.ts +509 -0
- package/.yalc/@node-dlc/bitcoin/lib/ScriptCmd.ts +3 -0
- package/.yalc/@node-dlc/bitcoin/lib/Sequence.ts +211 -0
- package/.yalc/@node-dlc/bitcoin/lib/SigHashType.ts +19 -0
- package/.yalc/@node-dlc/bitcoin/lib/SizeResult.ts +5 -0
- package/.yalc/@node-dlc/bitcoin/lib/Sorter.ts +1 -0
- package/.yalc/@node-dlc/bitcoin/lib/Stack.ts +81 -0
- package/.yalc/@node-dlc/bitcoin/lib/TimeLockMode.ts +16 -0
- package/.yalc/@node-dlc/bitcoin/lib/Tx.ts +480 -0
- package/.yalc/@node-dlc/bitcoin/lib/TxBuilder.ts +297 -0
- package/.yalc/@node-dlc/bitcoin/lib/TxIn.ts +115 -0
- package/.yalc/@node-dlc/bitcoin/lib/TxOut.ts +87 -0
- package/.yalc/@node-dlc/bitcoin/lib/Value.ts +201 -0
- package/.yalc/@node-dlc/bitcoin/lib/Wif.ts +77 -0
- package/.yalc/@node-dlc/bitcoin/lib/Witness.ts +65 -0
- package/.yalc/@node-dlc/bitcoin/lib/index.ts +28 -0
- package/.yalc/@node-dlc/bitcoin/package.json +31 -0
- package/.yalc/@node-dlc/bitcoin/tsconfig.json +8 -0
- package/.yalc/@node-dlc/bitcoin/yalc.sig +1 -0
- package/.yalc/@node-dlc/bufio/.eslintrc +6 -0
- package/.yalc/@node-dlc/bufio/.nyc_output/3c26c5b3-2a5e-4a53-88d4-06f4a5c339f7.json +1 -0
- package/.yalc/@node-dlc/bufio/.nyc_output/processinfo/3c26c5b3-2a5e-4a53-88d4-06f4a5c339f7.json +1 -0
- package/.yalc/@node-dlc/bufio/.nyc_output/processinfo/index.json +1 -0
- package/.yalc/@node-dlc/bufio/README.md +68 -0
- package/.yalc/@node-dlc/bufio/__tests__/BufferReader.spec.ts +548 -0
- package/.yalc/@node-dlc/bufio/__tests__/BufferWriter.spec.ts +530 -0
- package/.yalc/@node-dlc/bufio/__tests__/Hex.spec.ts +51 -0
- package/.yalc/@node-dlc/bufio/__tests__/StreamReader.spec.ts +133 -0
- package/.yalc/@node-dlc/bufio/__tests__/bigFromBufBE.spec.ts +14 -0
- package/.yalc/@node-dlc/bufio/__tests__/bigFromBufLE.spec.ts +14 -0
- package/.yalc/@node-dlc/bufio/__tests__/bigToBufBE.spec.ts +15 -0
- package/.yalc/@node-dlc/bufio/__tests__/bigToBufLE.spec.ts +14 -0
- package/.yalc/@node-dlc/bufio/__tests__/encodeVarInt.spec.ts +25 -0
- package/.yalc/@node-dlc/bufio/__tests__/tsconfig.json +7 -0
- package/.yalc/@node-dlc/bufio/__tests__/varIntBytes.spec.ts +34 -0
- package/.yalc/@node-dlc/bufio/coverage/lcov-report/BufferReader.ts.html +1142 -0
- package/.yalc/@node-dlc/bufio/coverage/lcov-report/BufferWriter.ts.html +953 -0
- package/.yalc/@node-dlc/bufio/coverage/lcov-report/Hex.ts.html +323 -0
- package/.yalc/@node-dlc/bufio/coverage/lcov-report/StreamReader.ts.html +620 -0
- package/.yalc/@node-dlc/bufio/coverage/lcov-report/base.css +224 -0
- package/.yalc/@node-dlc/bufio/coverage/lcov-report/bigFromBufBE.ts.html +89 -0
- package/.yalc/@node-dlc/bufio/coverage/lcov-report/bigFromBufLE.ts.html +95 -0
- package/.yalc/@node-dlc/bufio/coverage/lcov-report/bigToBufBE.ts.html +98 -0
- package/.yalc/@node-dlc/bufio/coverage/lcov-report/bigToBufLE.ts.html +95 -0
- package/.yalc/@node-dlc/bufio/coverage/lcov-report/block-navigation.js +79 -0
- package/.yalc/@node-dlc/bufio/coverage/lcov-report/bufToStream.ts.html +113 -0
- package/.yalc/@node-dlc/bufio/coverage/lcov-report/encodeVarInt.ts.html +203 -0
- package/.yalc/@node-dlc/bufio/coverage/lcov-report/favicon.png +0 -0
- package/.yalc/@node-dlc/bufio/coverage/lcov-report/index.html +261 -0
- package/.yalc/@node-dlc/bufio/coverage/lcov-report/prettify.css +1 -0
- package/.yalc/@node-dlc/bufio/coverage/lcov-report/prettify.js +2 -0
- package/.yalc/@node-dlc/bufio/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/.yalc/@node-dlc/bufio/coverage/lcov-report/sorter.js +170 -0
- package/.yalc/@node-dlc/bufio/coverage/lcov-report/varIntBytes.ts.html +116 -0
- package/.yalc/@node-dlc/bufio/coverage/lcov.info +747 -0
- package/.yalc/@node-dlc/bufio/dist/BufferReader.d.ts +155 -0
- package/.yalc/@node-dlc/bufio/dist/BufferReader.js +346 -0
- package/.yalc/@node-dlc/bufio/dist/BufferReader.js.map +1 -0
- package/.yalc/@node-dlc/bufio/dist/BufferWriter.d.ts +143 -0
- package/.yalc/@node-dlc/bufio/dist/BufferWriter.js +279 -0
- package/.yalc/@node-dlc/bufio/dist/BufferWriter.js.map +1 -0
- package/.yalc/@node-dlc/bufio/dist/Hex.d.ts +13 -0
- package/.yalc/@node-dlc/bufio/dist/Hex.js +78 -0
- package/.yalc/@node-dlc/bufio/dist/Hex.js.map +1 -0
- package/.yalc/@node-dlc/bufio/dist/StreamReader.d.ts +111 -0
- package/.yalc/@node-dlc/bufio/dist/StreamReader.js +180 -0
- package/.yalc/@node-dlc/bufio/dist/StreamReader.js.map +1 -0
- package/.yalc/@node-dlc/bufio/dist/bigFromBufBE.d.ts +2 -0
- package/.yalc/@node-dlc/bufio/dist/bigFromBufBE.js +8 -0
- package/.yalc/@node-dlc/bufio/dist/bigFromBufBE.js.map +1 -0
- package/.yalc/@node-dlc/bufio/dist/bigFromBufLE.d.ts +2 -0
- package/.yalc/@node-dlc/bufio/dist/bigFromBufLE.js +9 -0
- package/.yalc/@node-dlc/bufio/dist/bigFromBufLE.js.map +1 -0
- package/.yalc/@node-dlc/bufio/dist/bigToBufBE.d.ts +2 -0
- package/.yalc/@node-dlc/bufio/dist/bigToBufBE.js +13 -0
- package/.yalc/@node-dlc/bufio/dist/bigToBufBE.js.map +1 -0
- package/.yalc/@node-dlc/bufio/dist/bigToBufLE.d.ts +2 -0
- package/.yalc/@node-dlc/bufio/dist/bigToBufLE.js +9 -0
- package/.yalc/@node-dlc/bufio/dist/bigToBufLE.js.map +1 -0
- package/.yalc/@node-dlc/bufio/dist/bufToStream.d.ts +7 -0
- package/.yalc/@node-dlc/bufio/dist/bufToStream.js +15 -0
- package/.yalc/@node-dlc/bufio/dist/bufToStream.js.map +1 -0
- package/.yalc/@node-dlc/bufio/dist/encodeVarInt.d.ts +12 -0
- package/.yalc/@node-dlc/bufio/dist/encodeVarInt.js +46 -0
- package/.yalc/@node-dlc/bufio/dist/encodeVarInt.js.map +1 -0
- package/.yalc/@node-dlc/bufio/dist/index.d.ts +11 -0
- package/.yalc/@node-dlc/bufio/dist/index.js +28 -0
- package/.yalc/@node-dlc/bufio/dist/index.js.map +1 -0
- package/.yalc/@node-dlc/bufio/dist/varIntBytes.d.ts +5 -0
- package/.yalc/@node-dlc/bufio/dist/varIntBytes.js +22 -0
- package/.yalc/@node-dlc/bufio/dist/varIntBytes.js.map +1 -0
- package/.yalc/@node-dlc/bufio/lib/BufferReader.ts +354 -0
- package/.yalc/@node-dlc/bufio/lib/BufferWriter.ts +291 -0
- package/.yalc/@node-dlc/bufio/lib/Hex.ts +81 -0
- package/.yalc/@node-dlc/bufio/lib/StreamReader.ts +180 -0
- package/.yalc/@node-dlc/bufio/lib/bigFromBufBE.ts +3 -0
- package/.yalc/@node-dlc/bufio/lib/bigFromBufLE.ts +5 -0
- package/.yalc/@node-dlc/bufio/lib/bigToBufBE.ts +6 -0
- package/.yalc/@node-dlc/bufio/lib/bigToBufLE.ts +5 -0
- package/.yalc/@node-dlc/bufio/lib/bufToStream.ts +11 -0
- package/.yalc/@node-dlc/bufio/lib/encodeVarInt.ts +41 -0
- package/.yalc/@node-dlc/bufio/lib/index.ts +11 -0
- package/.yalc/@node-dlc/bufio/lib/varIntBytes.ts +12 -0
- package/.yalc/@node-dlc/bufio/package.json +27 -0
- package/.yalc/@node-dlc/bufio/tsconfig-build.json +7 -0
- package/.yalc/@node-dlc/bufio/tsconfig.json +7 -0
- package/.yalc/@node-dlc/bufio/yalc.sig +1 -0
- package/.yalc/@node-dlc/core/.nyc_output/687a3c14-9765-45fd-a1fe-f7db3d56fee4.json +1 -0
- package/.yalc/@node-dlc/core/.nyc_output/processinfo/687a3c14-9765-45fd-a1fe-f7db3d56fee4.json +1 -0
- package/.yalc/@node-dlc/core/.nyc_output/processinfo/index.json +1 -0
- package/.yalc/@node-dlc/core/README.md +11 -0
- package/.yalc/@node-dlc/core/__tests__/core.spec.ts +7 -0
- package/.yalc/@node-dlc/core/__tests__/dlc/CETCalculator.spec.ts +1029 -0
- package/.yalc/@node-dlc/core/__tests__/dlc/CoinSelect.spec.ts +179 -0
- package/.yalc/@node-dlc/core/__tests__/dlc/PolynomialPayoutCurve.spec.ts +345 -0
- package/.yalc/@node-dlc/core/__tests__/dlc/TxBuilder.spec.ts +424 -0
- package/.yalc/@node-dlc/core/__tests__/dlc/finance/Builder.spec.ts +492 -0
- package/.yalc/@node-dlc/core/__tests__/dlc/finance/CoveredCall.spec.ts +112 -0
- package/.yalc/@node-dlc/core/__tests__/dlc/finance/CsoInfo.spec.ts +1124 -0
- package/.yalc/@node-dlc/core/__tests__/dlc/finance/LongCall.spec.ts +55 -0
- package/.yalc/@node-dlc/core/__tests__/dlc/finance/LongPut.spec.ts +55 -0
- package/.yalc/@node-dlc/core/__tests__/dlc/finance/OptionInfo.spec.ts +226 -0
- package/.yalc/@node-dlc/core/__tests__/dlc/finance/ShortPut.spec.ts +62 -0
- package/.yalc/@node-dlc/core/__tests__/tsconfig.json +8 -0
- package/.yalc/@node-dlc/core/__tests__/utils/precision.spec.ts +40 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/base.css +224 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/block-navigation.js +79 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/favicon.png +0 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/index.html +171 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/AsyncProcessingQueue.ts.html +269 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/Base32.ts.html +86 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/BigIntUtils.ts.html +86 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/BitField.ts.html +86 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/ChannelId.ts.html +86 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/LinkedList.ts.html +413 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/LinkedListNode.ts.html +122 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/Queue.ts.html +188 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/ShortChannelId.ts.html +86 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/ShortChannelIdUtils.ts.html +107 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/CETCalculator.ts.html +1430 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/CoinSelect.ts.html +431 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/HyperbolaPayoutCurve.ts.html +644 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/PolynomialPayoutCurve.ts.html +878 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/TxBuilder.ts.html +1088 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/TxFinalizer.ts.html +731 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/Builder.ts.html +2270 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/CoveredCall.ts.html +410 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/CsoInfo.ts.html +1574 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/LinearPayout.ts.html +362 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/LongCall.ts.html +302 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/LongPut.ts.html +302 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/OptionInfo.ts.html +626 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/ShortPut.ts.html +305 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/index.html +216 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/index.html +186 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/index.html +261 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/index.ts.html +278 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/ChannelId.ts.html +242 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/ChannelKeys.ts.html +407 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/CommitmentNumber.ts.html +362 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/CommitmentSecret.ts.html +203 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/CommitmentSecretStore.ts.html +332 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/Htlc.ts.html +236 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/HtlcDirection.ts.html +131 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/ScriptFactory.ts.html +530 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/TxFactory.ts.html +1094 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/index.html +231 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/utils/BigIntUtils.ts.html +272 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/utils/Precision.ts.html +149 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/utils/index.html +126 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/prettify.css +1 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/prettify.js +2 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/sorter.js +170 -0
- package/.yalc/@node-dlc/core/coverage/lcov.info +2426 -0
- package/.yalc/@node-dlc/core/dist/AsyncProcessingQueue.d.ts +22 -0
- package/.yalc/@node-dlc/core/dist/AsyncProcessingQueue.js +55 -0
- package/.yalc/@node-dlc/core/dist/AsyncProcessingQueue.js.map +1 -0
- package/.yalc/@node-dlc/core/dist/Base32.d.ts +1 -0
- package/.yalc/@node-dlc/core/dist/Base32.js +7 -0
- package/.yalc/@node-dlc/core/dist/Base32.js.map +1 -0
- package/.yalc/@node-dlc/core/dist/BigIntUtils.d.ts +1 -0
- package/.yalc/@node-dlc/core/dist/BigIntUtils.js +8 -0
- package/.yalc/@node-dlc/core/dist/BigIntUtils.js.map +1 -0
- package/.yalc/@node-dlc/core/dist/BitField.d.ts +1 -0
- package/.yalc/@node-dlc/core/dist/BitField.js +7 -0
- package/.yalc/@node-dlc/core/dist/BitField.js.map +1 -0
- package/.yalc/@node-dlc/core/dist/ChannelId.d.ts +1 -0
- package/.yalc/@node-dlc/core/dist/ChannelId.js +7 -0
- package/.yalc/@node-dlc/core/dist/ChannelId.js.map +1 -0
- package/.yalc/@node-dlc/core/dist/LinkedList.d.ts +30 -0
- package/.yalc/@node-dlc/core/dist/LinkedList.js +104 -0
- package/.yalc/@node-dlc/core/dist/LinkedList.js.map +1 -0
- package/.yalc/@node-dlc/core/dist/LinkedListNode.d.ts +9 -0
- package/.yalc/@node-dlc/core/dist/LinkedListNode.js +15 -0
- package/.yalc/@node-dlc/core/dist/LinkedListNode.js.map +1 -0
- package/.yalc/@node-dlc/core/dist/Queue.d.ts +22 -0
- package/.yalc/@node-dlc/core/dist/Queue.js +38 -0
- package/.yalc/@node-dlc/core/dist/Queue.js.map +1 -0
- package/.yalc/@node-dlc/core/dist/ShortChannelId.d.ts +1 -0
- package/.yalc/@node-dlc/core/dist/ShortChannelId.js +7 -0
- package/.yalc/@node-dlc/core/dist/ShortChannelId.js.map +1 -0
- package/.yalc/@node-dlc/core/dist/ShortChannelIdUtils.d.ts +1 -0
- package/.yalc/@node-dlc/core/dist/ShortChannelIdUtils.js +12 -0
- package/.yalc/@node-dlc/core/dist/ShortChannelIdUtils.js.map +1 -0
- package/.yalc/@node-dlc/core/dist/dlc/CETCalculator.d.ts +50 -0
- package/.yalc/@node-dlc/core/dist/dlc/CETCalculator.js +332 -0
- package/.yalc/@node-dlc/core/dist/dlc/CETCalculator.js.map +1 -0
- package/.yalc/@node-dlc/core/dist/dlc/CoinSelect.d.ts +23 -0
- package/.yalc/@node-dlc/core/dist/dlc/CoinSelect.js +77 -0
- package/.yalc/@node-dlc/core/dist/dlc/CoinSelect.js.map +1 -0
- package/.yalc/@node-dlc/core/dist/dlc/HyperbolaPayoutCurve.d.ts +20 -0
- package/.yalc/@node-dlc/core/dist/dlc/HyperbolaPayoutCurve.js +117 -0
- package/.yalc/@node-dlc/core/dist/dlc/HyperbolaPayoutCurve.js.map +1 -0
- package/.yalc/@node-dlc/core/dist/dlc/PayoutCurve.d.ts +5 -0
- package/.yalc/@node-dlc/core/dist/dlc/PayoutCurve.js +3 -0
- package/.yalc/@node-dlc/core/dist/dlc/PayoutCurve.js.map +1 -0
- package/.yalc/@node-dlc/core/dist/dlc/PolynomialPayoutCurve.d.ts +52 -0
- package/.yalc/@node-dlc/core/dist/dlc/PolynomialPayoutCurve.js +173 -0
- package/.yalc/@node-dlc/core/dist/dlc/PolynomialPayoutCurve.js.map +1 -0
- package/.yalc/@node-dlc/core/dist/dlc/TxBuilder.d.ts +55 -0
- package/.yalc/@node-dlc/core/dist/dlc/TxBuilder.js +217 -0
- package/.yalc/@node-dlc/core/dist/dlc/TxBuilder.js.map +1 -0
- package/.yalc/@node-dlc/core/dist/dlc/TxFinalizer.d.ts +40 -0
- package/.yalc/@node-dlc/core/dist/dlc/TxFinalizer.js +146 -0
- package/.yalc/@node-dlc/core/dist/dlc/TxFinalizer.js.map +1 -0
- package/.yalc/@node-dlc/core/dist/dlc/finance/Builder.d.ts +193 -0
- package/.yalc/@node-dlc/core/dist/dlc/finance/Builder.js +422 -0
- package/.yalc/@node-dlc/core/dist/dlc/finance/Builder.js.map +1 -0
- package/.yalc/@node-dlc/core/dist/dlc/finance/CoveredCall.d.ts +13 -0
- package/.yalc/@node-dlc/core/dist/dlc/finance/CoveredCall.js +67 -0
- package/.yalc/@node-dlc/core/dist/dlc/finance/CoveredCall.js.map +1 -0
- package/.yalc/@node-dlc/core/dist/dlc/finance/CsoInfo.d.ts +114 -0
- package/.yalc/@node-dlc/core/dist/dlc/finance/CsoInfo.js +290 -0
- package/.yalc/@node-dlc/core/dist/dlc/finance/CsoInfo.js.map +1 -0
- package/.yalc/@node-dlc/core/dist/dlc/finance/LinearPayout.d.ts +6 -0
- package/.yalc/@node-dlc/core/dist/dlc/finance/LinearPayout.js +79 -0
- package/.yalc/@node-dlc/core/dist/dlc/finance/LinearPayout.js.map +1 -0
- package/.yalc/@node-dlc/core/dist/dlc/finance/LongCall.d.ts +13 -0
- package/.yalc/@node-dlc/core/dist/dlc/finance/LongCall.js +47 -0
- package/.yalc/@node-dlc/core/dist/dlc/finance/LongCall.js.map +1 -0
- package/.yalc/@node-dlc/core/dist/dlc/finance/LongPut.d.ts +13 -0
- package/.yalc/@node-dlc/core/dist/dlc/finance/LongPut.js +47 -0
- package/.yalc/@node-dlc/core/dist/dlc/finance/LongPut.js.map +1 -0
- package/.yalc/@node-dlc/core/dist/dlc/finance/OptionInfo.d.ts +20 -0
- package/.yalc/@node-dlc/core/dist/dlc/finance/OptionInfo.js +101 -0
- package/.yalc/@node-dlc/core/dist/dlc/finance/OptionInfo.js.map +1 -0
- package/.yalc/@node-dlc/core/dist/dlc/finance/ShortPut.d.ts +12 -0
- package/.yalc/@node-dlc/core/dist/dlc/finance/ShortPut.js +46 -0
- package/.yalc/@node-dlc/core/dist/dlc/finance/ShortPut.js.map +1 -0
- package/.yalc/@node-dlc/core/dist/index.d.ts +39 -0
- package/.yalc/@node-dlc/core/dist/index.js +78 -0
- package/.yalc/@node-dlc/core/dist/index.js.map +1 -0
- package/.yalc/@node-dlc/core/dist/lightning/ChannelId.d.ts +31 -0
- package/.yalc/@node-dlc/core/dist/lightning/ChannelId.js +52 -0
- package/.yalc/@node-dlc/core/dist/lightning/ChannelId.js.map +1 -0
- package/.yalc/@node-dlc/core/dist/lightning/ChannelKeys.d.ts +55 -0
- package/.yalc/@node-dlc/core/dist/lightning/ChannelKeys.js +105 -0
- package/.yalc/@node-dlc/core/dist/lightning/ChannelKeys.js.map +1 -0
- package/.yalc/@node-dlc/core/dist/lightning/CommitmentNumber.d.ts +55 -0
- package/.yalc/@node-dlc/core/dist/lightning/CommitmentNumber.js +76 -0
- package/.yalc/@node-dlc/core/dist/lightning/CommitmentNumber.js.map +1 -0
- package/.yalc/@node-dlc/core/dist/lightning/CommitmentSecret.d.ts +26 -0
- package/.yalc/@node-dlc/core/dist/lightning/CommitmentSecret.js +44 -0
- package/.yalc/@node-dlc/core/dist/lightning/CommitmentSecret.js.map +1 -0
- package/.yalc/@node-dlc/core/dist/lightning/CommitmentSecretStore.d.ts +41 -0
- package/.yalc/@node-dlc/core/dist/lightning/CommitmentSecretStore.js +79 -0
- package/.yalc/@node-dlc/core/dist/lightning/CommitmentSecretStore.js.map +1 -0
- package/.yalc/@node-dlc/core/dist/lightning/Htlc.d.ts +46 -0
- package/.yalc/@node-dlc/core/dist/lightning/Htlc.js +46 -0
- package/.yalc/@node-dlc/core/dist/lightning/Htlc.js.map +1 -0
- package/.yalc/@node-dlc/core/dist/lightning/HtlcDirection.d.ts +16 -0
- package/.yalc/@node-dlc/core/dist/lightning/HtlcDirection.js +21 -0
- package/.yalc/@node-dlc/core/dist/lightning/HtlcDirection.js.map +1 -0
- package/.yalc/@node-dlc/core/dist/lightning/ScriptFactory.d.ts +76 -0
- package/.yalc/@node-dlc/core/dist/lightning/ScriptFactory.js +102 -0
- package/.yalc/@node-dlc/core/dist/lightning/ScriptFactory.js.map +1 -0
- package/.yalc/@node-dlc/core/dist/lightning/TxFactory.d.ts +83 -0
- package/.yalc/@node-dlc/core/dist/lightning/TxFactory.js +222 -0
- package/.yalc/@node-dlc/core/dist/lightning/TxFactory.js.map +1 -0
- package/.yalc/@node-dlc/core/dist/utils/BigIntUtils.d.ts +9 -0
- package/.yalc/@node-dlc/core/dist/utils/BigIntUtils.js +59 -0
- package/.yalc/@node-dlc/core/dist/utils/BigIntUtils.js.map +1 -0
- package/.yalc/@node-dlc/core/dist/utils/Precision.d.ts +13 -0
- package/.yalc/@node-dlc/core/dist/utils/Precision.js +28 -0
- package/.yalc/@node-dlc/core/dist/utils/Precision.js.map +1 -0
- package/.yalc/@node-dlc/core/lib/AsyncProcessingQueue.ts +63 -0
- package/.yalc/@node-dlc/core/lib/Base32.ts +2 -0
- package/.yalc/@node-dlc/core/lib/BigIntUtils.ts +2 -0
- package/.yalc/@node-dlc/core/lib/BitField.ts +2 -0
- package/.yalc/@node-dlc/core/lib/ChannelId.ts +2 -0
- package/.yalc/@node-dlc/core/lib/LinkedList.ts +111 -0
- package/.yalc/@node-dlc/core/lib/LinkedListNode.ts +14 -0
- package/.yalc/@node-dlc/core/lib/Queue.ts +36 -0
- package/.yalc/@node-dlc/core/lib/ShortChannelId.ts +2 -0
- package/.yalc/@node-dlc/core/lib/ShortChannelIdUtils.ts +9 -0
- package/.yalc/@node-dlc/core/lib/dlc/CETCalculator.ts +450 -0
- package/.yalc/@node-dlc/core/lib/dlc/CoinSelect.ts +117 -0
- package/.yalc/@node-dlc/core/lib/dlc/HyperbolaPayoutCurve.ts +188 -0
- package/.yalc/@node-dlc/core/lib/dlc/PayoutCurve.ts +6 -0
- package/.yalc/@node-dlc/core/lib/dlc/PolynomialPayoutCurve.ts +266 -0
- package/.yalc/@node-dlc/core/lib/dlc/TxBuilder.ts +336 -0
- package/.yalc/@node-dlc/core/lib/dlc/TxFinalizer.ts +217 -0
- package/.yalc/@node-dlc/core/lib/dlc/finance/Builder.ts +730 -0
- package/.yalc/@node-dlc/core/lib/dlc/finance/CoveredCall.ts +110 -0
- package/.yalc/@node-dlc/core/lib/dlc/finance/CsoInfo.ts +498 -0
- package/.yalc/@node-dlc/core/lib/dlc/finance/LinearPayout.ts +94 -0
- package/.yalc/@node-dlc/core/lib/dlc/finance/LongCall.ts +74 -0
- package/.yalc/@node-dlc/core/lib/dlc/finance/LongPut.ts +74 -0
- package/.yalc/@node-dlc/core/lib/dlc/finance/OptionInfo.ts +182 -0
- package/.yalc/@node-dlc/core/lib/dlc/finance/ShortPut.ts +75 -0
- package/.yalc/@node-dlc/core/lib/index.ts +66 -0
- package/.yalc/@node-dlc/core/lib/lightning/ChannelId.ts +54 -0
- package/.yalc/@node-dlc/core/lib/lightning/ChannelKeys.ts +109 -0
- package/.yalc/@node-dlc/core/lib/lightning/CommitmentNumber.ts +94 -0
- package/.yalc/@node-dlc/core/lib/lightning/CommitmentSecret.ts +41 -0
- package/.yalc/@node-dlc/core/lib/lightning/CommitmentSecretStore.ts +84 -0
- package/.yalc/@node-dlc/core/lib/lightning/Htlc.ts +52 -0
- package/.yalc/@node-dlc/core/lib/lightning/HtlcDirection.ts +17 -0
- package/.yalc/@node-dlc/core/lib/lightning/ScriptFactory.ts +150 -0
- package/.yalc/@node-dlc/core/lib/lightning/TxFactory.ts +338 -0
- package/.yalc/@node-dlc/core/lib/utils/BigIntUtils.ts +64 -0
- package/.yalc/@node-dlc/core/lib/utils/Precision.ts +23 -0
- package/.yalc/@node-dlc/core/package.json +38 -0
- package/.yalc/@node-dlc/core/tsconfig.json +8 -0
- package/.yalc/@node-dlc/core/yalc.sig +1 -0
- package/.yalc/@node-dlc/crypto/.eslintrc +6 -0
- package/.yalc/@node-dlc/crypto/.nyc_output/de03e0b4-d482-4f61-b680-59411360f56e.json +1 -0
- package/.yalc/@node-dlc/crypto/.nyc_output/processinfo/de03e0b4-d482-4f61-b680-59411360f56e.json +1 -0
- package/.yalc/@node-dlc/crypto/.nyc_output/processinfo/index.json +1 -0
- package/.yalc/@node-dlc/crypto/README.md +13 -0
- package/.yalc/@node-dlc/crypto/__tests__/chacha.spec.ts +29 -0
- package/.yalc/@node-dlc/crypto/__tests__/chachapoly.spec.ts +78 -0
- package/.yalc/@node-dlc/crypto/__tests__/hkdf.spec.ts +131 -0
- package/.yalc/@node-dlc/crypto/__tests__/key.spec.ts +125 -0
- package/.yalc/@node-dlc/crypto/__tests__/secp256k1.spec.ts +194 -0
- package/.yalc/@node-dlc/crypto/__tests__/xor.spec.ts +28 -0
- package/.yalc/@node-dlc/crypto/coverage/lcov-report/base.css +224 -0
- package/.yalc/@node-dlc/crypto/coverage/lcov-report/block-navigation.js +79 -0
- package/.yalc/@node-dlc/crypto/coverage/lcov-report/chacha.ts.html +119 -0
- package/.yalc/@node-dlc/crypto/coverage/lcov-report/chachapoly.ts.html +275 -0
- package/.yalc/@node-dlc/crypto/coverage/lcov-report/favicon.png +0 -0
- package/.yalc/@node-dlc/crypto/coverage/lcov-report/hkdf.ts.html +236 -0
- package/.yalc/@node-dlc/crypto/coverage/lcov-report/index.html +186 -0
- package/.yalc/@node-dlc/crypto/coverage/lcov-report/key.ts.html +272 -0
- package/.yalc/@node-dlc/crypto/coverage/lcov-report/prettify.css +1 -0
- package/.yalc/@node-dlc/crypto/coverage/lcov-report/prettify.js +2 -0
- package/.yalc/@node-dlc/crypto/coverage/lcov-report/secp256k1.ts.html +680 -0
- package/.yalc/@node-dlc/crypto/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/.yalc/@node-dlc/crypto/coverage/lcov-report/sorter.js +170 -0
- package/.yalc/@node-dlc/crypto/coverage/lcov-report/xor.ts.html +116 -0
- package/.yalc/@node-dlc/crypto/coverage/lcov.info +221 -0
- package/.yalc/@node-dlc/crypto/dist/aes-key.d.ts +6 -0
- package/.yalc/@node-dlc/crypto/dist/aes-key.js +3 -0
- package/.yalc/@node-dlc/crypto/dist/aes-key.js.map +1 -0
- package/.yalc/@node-dlc/crypto/dist/aes.d.ts +34 -0
- package/.yalc/@node-dlc/crypto/dist/aes.js +62 -0
- package/.yalc/@node-dlc/crypto/dist/aes.js.map +1 -0
- package/.yalc/@node-dlc/crypto/dist/chacha.d.ts +4 -0
- package/.yalc/@node-dlc/crypto/dist/chacha.js +40 -0
- package/.yalc/@node-dlc/crypto/dist/chacha.js.map +1 -0
- package/.yalc/@node-dlc/crypto/dist/chachapoly.d.ts +24 -0
- package/.yalc/@node-dlc/crypto/dist/chachapoly.js +61 -0
- package/.yalc/@node-dlc/crypto/dist/chachapoly.js.map +1 -0
- package/.yalc/@node-dlc/crypto/dist/hash.d.ts +29 -0
- package/.yalc/@node-dlc/crypto/dist/hash.js +51 -0
- package/.yalc/@node-dlc/crypto/dist/hash.js.map +1 -0
- package/.yalc/@node-dlc/crypto/dist/hkdf.d.ts +20 -0
- package/.yalc/@node-dlc/crypto/dist/hkdf.js +50 -0
- package/.yalc/@node-dlc/crypto/dist/hkdf.js.map +1 -0
- package/.yalc/@node-dlc/crypto/dist/hmac.d.ts +3 -0
- package/.yalc/@node-dlc/crypto/dist/hmac.js +14 -0
- package/.yalc/@node-dlc/crypto/dist/hmac.js.map +1 -0
- package/.yalc/@node-dlc/crypto/dist/index.d.ts +11 -0
- package/.yalc/@node-dlc/crypto/dist/index.js +30 -0
- package/.yalc/@node-dlc/crypto/dist/index.js.map +1 -0
- package/.yalc/@node-dlc/crypto/dist/key.d.ts +37 -0
- package/.yalc/@node-dlc/crypto/dist/key.js +72 -0
- package/.yalc/@node-dlc/crypto/dist/key.js.map +1 -0
- package/.yalc/@node-dlc/crypto/dist/secp256k1.d.ts +120 -0
- package/.yalc/@node-dlc/crypto/dist/secp256k1.js +184 -0
- package/.yalc/@node-dlc/crypto/dist/secp256k1.js.map +1 -0
- package/.yalc/@node-dlc/crypto/dist/xor.d.ts +8 -0
- package/.yalc/@node-dlc/crypto/dist/xor.js +17 -0
- package/.yalc/@node-dlc/crypto/dist/xor.js.map +1 -0
- package/.yalc/@node-dlc/crypto/lib/aes-key.ts +4 -0
- package/.yalc/@node-dlc/crypto/lib/aes.ts +81 -0
- package/.yalc/@node-dlc/crypto/lib/chacha.ts +13 -0
- package/.yalc/@node-dlc/crypto/lib/chachapoly.ts +65 -0
- package/.yalc/@node-dlc/crypto/lib/hash.ts +44 -0
- package/.yalc/@node-dlc/crypto/lib/hkdf.ts +52 -0
- package/.yalc/@node-dlc/crypto/lib/hmac.ts +7 -0
- package/.yalc/@node-dlc/crypto/lib/index.ts +11 -0
- package/.yalc/@node-dlc/crypto/lib/key.ts +64 -0
- package/.yalc/@node-dlc/crypto/lib/secp256k1.ts +200 -0
- package/.yalc/@node-dlc/crypto/lib/xor.ts +12 -0
- package/.yalc/@node-dlc/crypto/package.json +34 -0
- package/.yalc/@node-dlc/crypto/tsconfig-build.json +7 -0
- package/.yalc/@node-dlc/crypto/tsconfig.json +4 -0
- package/.yalc/@node-dlc/crypto/yalc.sig +1 -0
- package/.yalc/@node-dlc/messaging/.nyc_output/83d37f9d-cecf-4c52-a753-115ff80bbca0.json +1 -0
- package/.yalc/@node-dlc/messaging/.nyc_output/processinfo/83d37f9d-cecf-4c52-a753-115ff80bbca0.json +1 -0
- package/.yalc/@node-dlc/messaging/.nyc_output/processinfo/index.json +1 -0
- package/.yalc/@node-dlc/messaging/README.md +24 -0
- package/.yalc/@node-dlc/messaging/__tests__/_test-utils.ts +13 -0
- package/.yalc/@node-dlc/messaging/__tests__/chain/ChainManager.spec.ts +178 -0
- package/.yalc/@node-dlc/messaging/__tests__/compatibility/dlcspecs-compatibility.spec.ts +439 -0
- package/.yalc/@node-dlc/messaging/__tests__/compatibility/rust-dlc-cross-language.spec.ts +255 -0
- package/.yalc/@node-dlc/messaging/__tests__/compatibility/true-serialization-compatibility.spec.ts +342 -0
- package/.yalc/@node-dlc/messaging/__tests__/dlc_message_test.json +155 -0
- package/.yalc/@node-dlc/messaging/__tests__/irc/IrcMessage.spec.ts +94 -0
- package/.yalc/@node-dlc/messaging/__tests__/messages/AddressCache.spec.ts +79 -0
- package/.yalc/@node-dlc/messaging/__tests__/messages/BatchFundingGroup.spec.ts +72 -0
- package/.yalc/@node-dlc/messaging/__tests__/messages/CetAdaptorSignatures.spec.ts +57 -0
- package/.yalc/@node-dlc/messaging/__tests__/messages/ContractDescriptor.spec.ts +266 -0
- package/.yalc/@node-dlc/messaging/__tests__/messages/ContractInfo.spec.ts +419 -0
- package/.yalc/@node-dlc/messaging/__tests__/messages/DigitDecompositionEventDescriptor.spec.ts +59 -0
- package/.yalc/@node-dlc/messaging/__tests__/messages/DlcAccept.spec.ts +314 -0
- package/.yalc/@node-dlc/messaging/__tests__/messages/DlcCancel.spec.ts +42 -0
- package/.yalc/@node-dlc/messaging/__tests__/messages/DlcClose.spec.ts +315 -0
- package/.yalc/@node-dlc/messaging/__tests__/messages/DlcInput.spec.ts +111 -0
- package/.yalc/@node-dlc/messaging/__tests__/messages/DlcOffer.spec.ts +589 -0
- package/.yalc/@node-dlc/messaging/__tests__/messages/DlcSign.spec.ts +118 -0
- package/.yalc/@node-dlc/messaging/__tests__/messages/DlcTransactions.spec.ts +157 -0
- package/.yalc/@node-dlc/messaging/__tests__/messages/EnumEventDescriptor.spec.ts +50 -0
- package/.yalc/@node-dlc/messaging/__tests__/messages/EventDescriptor.spec.ts +93 -0
- package/.yalc/@node-dlc/messaging/__tests__/messages/FundingInput.spec.ts +169 -0
- package/.yalc/@node-dlc/messaging/__tests__/messages/FundingSignatures.spec.ts +83 -0
- package/.yalc/@node-dlc/messaging/__tests__/messages/NegotiationFields.spec.ts +328 -0
- package/.yalc/@node-dlc/messaging/__tests__/messages/NodeAnnouncementMessage.spec.ts +115 -0
- package/.yalc/@node-dlc/messaging/__tests__/messages/OracleAnnouncement.spec.ts +415 -0
- package/.yalc/@node-dlc/messaging/__tests__/messages/OracleAttestation.spec.ts +324 -0
- package/.yalc/@node-dlc/messaging/__tests__/messages/OracleEvent.spec.ts +143 -0
- package/.yalc/@node-dlc/messaging/__tests__/messages/OracleEventContainer.spec.ts +95 -0
- package/.yalc/@node-dlc/messaging/__tests__/messages/OracleIdentifier.spec.ts +48 -0
- package/.yalc/@node-dlc/messaging/__tests__/messages/OracleInfo.spec.ts +116 -0
- package/.yalc/@node-dlc/messaging/__tests__/messages/OrderAccept.spec.ts +75 -0
- package/.yalc/@node-dlc/messaging/__tests__/messages/OrderNegotiationFields.spec.ts +299 -0
- package/.yalc/@node-dlc/messaging/__tests__/messages/OrderOffer.spec.ts +121 -0
- package/.yalc/@node-dlc/messaging/__tests__/messages/OrderPositionInfo.spec.ts +75 -0
- package/.yalc/@node-dlc/messaging/__tests__/messages/PayoutCurvePiece.spec.ts +220 -0
- package/.yalc/@node-dlc/messaging/__tests__/messages/PayoutFunction.spec.ts +101 -0
- package/.yalc/@node-dlc/messaging/__tests__/messages/RoundingIntervals.spec.ts +75 -0
- package/.yalc/@node-dlc/messaging/__tests__/serialize/F64.spec.ts +261 -0
- package/.yalc/@node-dlc/messaging/__tests__/tsconfig.json +8 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/base.css +224 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/block-navigation.js +79 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/favicon.png +0 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/index.html +201 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/MessageType.ts.html +500 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/chain/ChainManager.ts.html +1061 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/chain/ChainMemoryStore.ts.html +182 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/chain/index.html +126 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/domain/Address.ts.html +272 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/domain/index.html +111 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/index.html +141 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/index.ts.html +215 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/irc/IrcMessage.ts.html +563 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/irc/index.html +111 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/messages/AddressCache.ts.html +302 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/messages/BatchFundingGroup.ts.html +503 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/messages/CetAdaptorSignatures.ts.html +347 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/messages/CetAdaptorSignaturesV0.ts.html +356 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/messages/CloseTLV.ts.html +344 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/messages/ContractDescriptor.ts.html +1031 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/messages/ContractInfo.ts.html +1397 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/messages/DlcAccept.ts.html +1997 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/messages/DlcCancel.ts.html +251 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/messages/DlcClose.ts.html +995 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/messages/DlcCloseMetadata.ts.html +434 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/messages/DlcIds.ts.html +281 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/messages/DlcInfo.ts.html +323 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/messages/DlcInput.ts.html +581 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/messages/DlcMessage.ts.html +341 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/messages/DlcOffer.ts.html +2075 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/messages/DlcSign.ts.html +1157 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/messages/DlcTransactions.ts.html +719 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/messages/EventDescriptor.ts.html +962 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/messages/FundingInput.ts.html +860 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/messages/FundingSignatures.ts.html +374 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/messages/FundingSignaturesV0.ts.html +344 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/messages/NegotiationFields.ts.html +848 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/messages/NodeAnnouncementMessage.ts.html +515 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/messages/OracleAnnouncement.ts.html +608 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/messages/OracleAnnouncementV0.ts.html +383 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/messages/OracleAttestation.ts.html +956 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/messages/OracleAttestationV0.ts.html +479 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/messages/OracleEvent.ts.html +830 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/messages/OracleEventContainer.ts.html +347 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/messages/OracleEventContainerV0.ts.html +347 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/messages/OracleEventV0.ts.html +503 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/messages/OracleIdentifier.ts.html +314 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/messages/OracleIdentifierV0.ts.html +314 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/messages/OracleInfo.ts.html +1658 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/messages/OracleInfoV0.ts.html +308 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/messages/OrderAccept.ts.html +602 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/messages/OrderIrcInfo.ts.html +380 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/messages/OrderMetadata.ts.html +437 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/messages/OrderNegotiationFields.ts.html +710 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/messages/OrderOffer.ts.html +1334 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/messages/OrderPositionInfo.ts.html +521 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/messages/PayoutCurvePiece.ts.html +1442 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/messages/PayoutFunction.ts.html +806 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/messages/RoundingIntervals.ts.html +464 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/messages/RoundingIntervalsV0.ts.html +428 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/messages/ScriptWitnessV0.ts.html +269 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/messages/index.html +651 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/serialize/F64.ts.html +1091 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/serialize/deserializeTlv.ts.html +125 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/serialize/getTlv.ts.html +143 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/serialize/index.html +141 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/util.ts.html +191 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/validation/index.html +111 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/validation/validate.ts.html +182 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/prettify.css +1 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/prettify.js +2 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/sorter.js +170 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov.info +5617 -0
- package/.yalc/@node-dlc/messaging/dist/MessageType.d.ts +101 -0
- package/.yalc/@node-dlc/messaging/dist/MessageType.js +118 -0
- package/.yalc/@node-dlc/messaging/dist/MessageType.js.map +1 -0
- package/.yalc/@node-dlc/messaging/dist/chain/ChainManager.d.ts +50 -0
- package/.yalc/@node-dlc/messaging/dist/chain/ChainManager.js +212 -0
- package/.yalc/@node-dlc/messaging/dist/chain/ChainManager.js.map +1 -0
- package/.yalc/@node-dlc/messaging/dist/chain/ChainMemoryStore.d.ts +14 -0
- package/.yalc/@node-dlc/messaging/dist/chain/ChainMemoryStore.js +28 -0
- package/.yalc/@node-dlc/messaging/dist/chain/ChainMemoryStore.js.map +1 -0
- package/.yalc/@node-dlc/messaging/dist/chain/DlcStore.d.ts +11 -0
- package/.yalc/@node-dlc/messaging/dist/chain/DlcStore.js +3 -0
- package/.yalc/@node-dlc/messaging/dist/chain/DlcStore.js.map +1 -0
- package/.yalc/@node-dlc/messaging/dist/chain/IChainFilterChainClient.d.ts +48 -0
- package/.yalc/@node-dlc/messaging/dist/chain/IChainFilterChainClient.js +3 -0
- package/.yalc/@node-dlc/messaging/dist/chain/IChainFilterChainClient.js.map +1 -0
- package/.yalc/@node-dlc/messaging/dist/domain/Address.d.ts +24 -0
- package/.yalc/@node-dlc/messaging/dist/domain/Address.js +46 -0
- package/.yalc/@node-dlc/messaging/dist/domain/Address.js.map +1 -0
- package/.yalc/@node-dlc/messaging/dist/index.d.ts +45 -0
- package/.yalc/@node-dlc/messaging/dist/index.js +64 -0
- package/.yalc/@node-dlc/messaging/dist/index.js.map +1 -0
- package/.yalc/@node-dlc/messaging/dist/irc/IrcMessage.d.ts +43 -0
- package/.yalc/@node-dlc/messaging/dist/irc/IrcMessage.js +116 -0
- package/.yalc/@node-dlc/messaging/dist/irc/IrcMessage.js.map +1 -0
- package/.yalc/@node-dlc/messaging/dist/messages/AddressCache.d.ts +15 -0
- package/.yalc/@node-dlc/messaging/dist/messages/AddressCache.js +51 -0
- package/.yalc/@node-dlc/messaging/dist/messages/AddressCache.js.map +1 -0
- package/.yalc/@node-dlc/messaging/dist/messages/BatchFundingGroup.d.ts +61 -0
- package/.yalc/@node-dlc/messaging/dist/messages/BatchFundingGroup.js +113 -0
- package/.yalc/@node-dlc/messaging/dist/messages/BatchFundingGroup.js.map +1 -0
- package/.yalc/@node-dlc/messaging/dist/messages/CetAdaptorSignatures.d.ts +40 -0
- package/.yalc/@node-dlc/messaging/dist/messages/CetAdaptorSignatures.js +67 -0
- package/.yalc/@node-dlc/messaging/dist/messages/CetAdaptorSignatures.js.map +1 -0
- package/.yalc/@node-dlc/messaging/dist/messages/CetAdaptorSignaturesV0.d.ts +42 -0
- package/.yalc/@node-dlc/messaging/dist/messages/CetAdaptorSignaturesV0.js +68 -0
- package/.yalc/@node-dlc/messaging/dist/messages/CetAdaptorSignaturesV0.js.map +1 -0
- package/.yalc/@node-dlc/messaging/dist/messages/CloseTLV.d.ts +38 -0
- package/.yalc/@node-dlc/messaging/dist/messages/CloseTLV.js +59 -0
- package/.yalc/@node-dlc/messaging/dist/messages/CloseTLV.js.map +1 -0
- package/.yalc/@node-dlc/messaging/dist/messages/ContractDescriptor.d.ts +121 -0
- package/.yalc/@node-dlc/messaging/dist/messages/ContractDescriptor.js +221 -0
- package/.yalc/@node-dlc/messaging/dist/messages/ContractDescriptor.js.map +1 -0
- package/.yalc/@node-dlc/messaging/dist/messages/ContractInfo.d.ts +135 -0
- package/.yalc/@node-dlc/messaging/dist/messages/ContractInfo.js +308 -0
- package/.yalc/@node-dlc/messaging/dist/messages/ContractInfo.js.map +1 -0
- package/.yalc/@node-dlc/messaging/dist/messages/DlcAccept.d.ts +160 -0
- package/.yalc/@node-dlc/messaging/dist/messages/DlcAccept.js +469 -0
- package/.yalc/@node-dlc/messaging/dist/messages/DlcAccept.js.map +1 -0
- package/.yalc/@node-dlc/messaging/dist/messages/DlcCancel.d.ts +31 -0
- package/.yalc/@node-dlc/messaging/dist/messages/DlcCancel.js +51 -0
- package/.yalc/@node-dlc/messaging/dist/messages/DlcCancel.js.map +1 -0
- package/.yalc/@node-dlc/messaging/dist/messages/DlcClose.d.ts +68 -0
- package/.yalc/@node-dlc/messaging/dist/messages/DlcClose.js +214 -0
- package/.yalc/@node-dlc/messaging/dist/messages/DlcClose.js.map +1 -0
- package/.yalc/@node-dlc/messaging/dist/messages/DlcCloseMetadata.d.ts +44 -0
- package/.yalc/@node-dlc/messaging/dist/messages/DlcCloseMetadata.js +74 -0
- package/.yalc/@node-dlc/messaging/dist/messages/DlcCloseMetadata.js.map +1 -0
- package/.yalc/@node-dlc/messaging/dist/messages/DlcIds.d.ts +26 -0
- package/.yalc/@node-dlc/messaging/dist/messages/DlcIds.js +58 -0
- package/.yalc/@node-dlc/messaging/dist/messages/DlcIds.js.map +1 -0
- package/.yalc/@node-dlc/messaging/dist/messages/DlcInfo.d.ts +31 -0
- package/.yalc/@node-dlc/messaging/dist/messages/DlcInfo.js +61 -0
- package/.yalc/@node-dlc/messaging/dist/messages/DlcInfo.js.map +1 -0
- package/.yalc/@node-dlc/messaging/dist/messages/DlcInput.d.ts +56 -0
- package/.yalc/@node-dlc/messaging/dist/messages/DlcInput.js +135 -0
- package/.yalc/@node-dlc/messaging/dist/messages/DlcInput.js.map +1 -0
- package/.yalc/@node-dlc/messaging/dist/messages/DlcMessage.d.ts +23 -0
- package/.yalc/@node-dlc/messaging/dist/messages/DlcMessage.js +54 -0
- package/.yalc/@node-dlc/messaging/dist/messages/DlcMessage.js.map +1 -0
- package/.yalc/@node-dlc/messaging/dist/messages/DlcOffer.d.ts +146 -0
- package/.yalc/@node-dlc/messaging/dist/messages/DlcOffer.js +463 -0
- package/.yalc/@node-dlc/messaging/dist/messages/DlcOffer.js.map +1 -0
- package/.yalc/@node-dlc/messaging/dist/messages/DlcSign.d.ts +96 -0
- package/.yalc/@node-dlc/messaging/dist/messages/DlcSign.js +275 -0
- package/.yalc/@node-dlc/messaging/dist/messages/DlcSign.js.map +1 -0
- package/.yalc/@node-dlc/messaging/dist/messages/DlcTransactions.d.ts +69 -0
- package/.yalc/@node-dlc/messaging/dist/messages/DlcTransactions.js +149 -0
- package/.yalc/@node-dlc/messaging/dist/messages/DlcTransactions.js.map +1 -0
- package/.yalc/@node-dlc/messaging/dist/messages/EventDescriptor.d.ts +107 -0
- package/.yalc/@node-dlc/messaging/dist/messages/EventDescriptor.js +212 -0
- package/.yalc/@node-dlc/messaging/dist/messages/EventDescriptor.js.map +1 -0
- package/.yalc/@node-dlc/messaging/dist/messages/FundingInput.d.ts +69 -0
- package/.yalc/@node-dlc/messaging/dist/messages/FundingInput.js +193 -0
- package/.yalc/@node-dlc/messaging/dist/messages/FundingInput.js.map +1 -0
- package/.yalc/@node-dlc/messaging/dist/messages/FundingSignatures.d.ts +36 -0
- package/.yalc/@node-dlc/messaging/dist/messages/FundingSignatures.js +78 -0
- package/.yalc/@node-dlc/messaging/dist/messages/FundingSignatures.js.map +1 -0
- package/.yalc/@node-dlc/messaging/dist/messages/FundingSignaturesV0.d.ts +34 -0
- package/.yalc/@node-dlc/messaging/dist/messages/FundingSignaturesV0.js +72 -0
- package/.yalc/@node-dlc/messaging/dist/messages/FundingSignaturesV0.js.map +1 -0
- package/.yalc/@node-dlc/messaging/dist/messages/IWireMessage.d.ts +6 -0
- package/.yalc/@node-dlc/messaging/dist/messages/IWireMessage.js +3 -0
- package/.yalc/@node-dlc/messaging/dist/messages/IWireMessage.js.map +1 -0
- package/.yalc/@node-dlc/messaging/dist/messages/NegotiationFields.d.ts +86 -0
- package/.yalc/@node-dlc/messaging/dist/messages/NegotiationFields.js +189 -0
- package/.yalc/@node-dlc/messaging/dist/messages/NegotiationFields.js.map +1 -0
- package/.yalc/@node-dlc/messaging/dist/messages/NodeAnnouncementMessage.d.ts +57 -0
- package/.yalc/@node-dlc/messaging/dist/messages/NodeAnnouncementMessage.js +127 -0
- package/.yalc/@node-dlc/messaging/dist/messages/NodeAnnouncementMessage.js.map +1 -0
- package/.yalc/@node-dlc/messaging/dist/messages/OracleAnnouncement.d.ts +76 -0
- package/.yalc/@node-dlc/messaging/dist/messages/OracleAnnouncement.js +131 -0
- package/.yalc/@node-dlc/messaging/dist/messages/OracleAnnouncement.js.map +1 -0
- package/.yalc/@node-dlc/messaging/dist/messages/OracleAnnouncementV0.d.ts +47 -0
- package/.yalc/@node-dlc/messaging/dist/messages/OracleAnnouncementV0.js +76 -0
- package/.yalc/@node-dlc/messaging/dist/messages/OracleAnnouncementV0.js.map +1 -0
- package/.yalc/@node-dlc/messaging/dist/messages/OracleAttestation.d.ts +68 -0
- package/.yalc/@node-dlc/messaging/dist/messages/OracleAttestation.js +239 -0
- package/.yalc/@node-dlc/messaging/dist/messages/OracleAttestation.js.map +1 -0
- package/.yalc/@node-dlc/messaging/dist/messages/OracleAttestationV0.d.ts +48 -0
- package/.yalc/@node-dlc/messaging/dist/messages/OracleAttestationV0.js +100 -0
- package/.yalc/@node-dlc/messaging/dist/messages/OracleAttestationV0.js.map +1 -0
- package/.yalc/@node-dlc/messaging/dist/messages/OracleEvent.d.ts +90 -0
- package/.yalc/@node-dlc/messaging/dist/messages/OracleEvent.js +189 -0
- package/.yalc/@node-dlc/messaging/dist/messages/OracleEvent.js.map +1 -0
- package/.yalc/@node-dlc/messaging/dist/messages/OracleEventContainer.d.ts +32 -0
- package/.yalc/@node-dlc/messaging/dist/messages/OracleEventContainer.js +67 -0
- package/.yalc/@node-dlc/messaging/dist/messages/OracleEventContainer.js.map +1 -0
- package/.yalc/@node-dlc/messaging/dist/messages/OracleEventContainerV0.d.ts +32 -0
- package/.yalc/@node-dlc/messaging/dist/messages/OracleEventContainerV0.js +67 -0
- package/.yalc/@node-dlc/messaging/dist/messages/OracleEventContainerV0.js.map +1 -0
- package/.yalc/@node-dlc/messaging/dist/messages/OracleEventV0.d.ts +54 -0
- package/.yalc/@node-dlc/messaging/dist/messages/OracleEventV0.js +100 -0
- package/.yalc/@node-dlc/messaging/dist/messages/OracleEventV0.js.map +1 -0
- package/.yalc/@node-dlc/messaging/dist/messages/OracleIdentifier.d.ts +32 -0
- package/.yalc/@node-dlc/messaging/dist/messages/OracleIdentifier.js +58 -0
- package/.yalc/@node-dlc/messaging/dist/messages/OracleIdentifier.js.map +1 -0
- package/.yalc/@node-dlc/messaging/dist/messages/OracleIdentifierV0.d.ts +32 -0
- package/.yalc/@node-dlc/messaging/dist/messages/OracleIdentifierV0.js +58 -0
- package/.yalc/@node-dlc/messaging/dist/messages/OracleIdentifierV0.js.map +1 -0
- package/.yalc/@node-dlc/messaging/dist/messages/OracleInfo.d.ts +163 -0
- package/.yalc/@node-dlc/messaging/dist/messages/OracleInfo.js +393 -0
- package/.yalc/@node-dlc/messaging/dist/messages/OracleInfo.js.map +1 -0
- package/.yalc/@node-dlc/messaging/dist/messages/OracleInfoV0.d.ts +35 -0
- package/.yalc/@node-dlc/messaging/dist/messages/OracleInfoV0.js +58 -0
- package/.yalc/@node-dlc/messaging/dist/messages/OracleInfoV0.js.map +1 -0
- package/.yalc/@node-dlc/messaging/dist/messages/OrderAccept.d.ts +66 -0
- package/.yalc/@node-dlc/messaging/dist/messages/OrderAccept.js +140 -0
- package/.yalc/@node-dlc/messaging/dist/messages/OrderAccept.js.map +1 -0
- package/.yalc/@node-dlc/messaging/dist/messages/OrderIrcInfo.d.ts +42 -0
- package/.yalc/@node-dlc/messaging/dist/messages/OrderIrcInfo.js +74 -0
- package/.yalc/@node-dlc/messaging/dist/messages/OrderIrcInfo.js.map +1 -0
- package/.yalc/@node-dlc/messaging/dist/messages/OrderMetadata.d.ts +56 -0
- package/.yalc/@node-dlc/messaging/dist/messages/OrderMetadata.js +87 -0
- package/.yalc/@node-dlc/messaging/dist/messages/OrderMetadata.js.map +1 -0
- package/.yalc/@node-dlc/messaging/dist/messages/OrderNegotiationFields.d.ts +81 -0
- package/.yalc/@node-dlc/messaging/dist/messages/OrderNegotiationFields.js +161 -0
- package/.yalc/@node-dlc/messaging/dist/messages/OrderNegotiationFields.js.map +1 -0
- package/.yalc/@node-dlc/messaging/dist/messages/OrderOffer.d.ts +97 -0
- package/.yalc/@node-dlc/messaging/dist/messages/OrderOffer.js +296 -0
- package/.yalc/@node-dlc/messaging/dist/messages/OrderOffer.js.map +1 -0
- package/.yalc/@node-dlc/messaging/dist/messages/OrderPositionInfo.d.ts +44 -0
- package/.yalc/@node-dlc/messaging/dist/messages/OrderPositionInfo.js +111 -0
- package/.yalc/@node-dlc/messaging/dist/messages/OrderPositionInfo.js.map +1 -0
- package/.yalc/@node-dlc/messaging/dist/messages/PayoutCurvePiece.d.ts +129 -0
- package/.yalc/@node-dlc/messaging/dist/messages/PayoutCurvePiece.js +332 -0
- package/.yalc/@node-dlc/messaging/dist/messages/PayoutCurvePiece.js.map +1 -0
- package/.yalc/@node-dlc/messaging/dist/messages/PayoutFunction.d.ts +66 -0
- package/.yalc/@node-dlc/messaging/dist/messages/PayoutFunction.js +173 -0
- package/.yalc/@node-dlc/messaging/dist/messages/PayoutFunction.js.map +1 -0
- package/.yalc/@node-dlc/messaging/dist/messages/RoundingIntervals.d.ts +52 -0
- package/.yalc/@node-dlc/messaging/dist/messages/RoundingIntervals.js +96 -0
- package/.yalc/@node-dlc/messaging/dist/messages/RoundingIntervals.js.map +1 -0
- package/.yalc/@node-dlc/messaging/dist/messages/RoundingIntervalsV0.d.ts +47 -0
- package/.yalc/@node-dlc/messaging/dist/messages/RoundingIntervalsV0.js +86 -0
- package/.yalc/@node-dlc/messaging/dist/messages/RoundingIntervalsV0.js.map +1 -0
- package/.yalc/@node-dlc/messaging/dist/messages/ScriptWitnessV0.d.ts +29 -0
- package/.yalc/@node-dlc/messaging/dist/messages/ScriptWitnessV0.js +50 -0
- package/.yalc/@node-dlc/messaging/dist/messages/ScriptWitnessV0.js.map +1 -0
- package/.yalc/@node-dlc/messaging/dist/messages/Tlv.d.ts +15 -0
- package/.yalc/@node-dlc/messaging/dist/messages/Tlv.js +32 -0
- package/.yalc/@node-dlc/messaging/dist/messages/Tlv.js.map +1 -0
- package/.yalc/@node-dlc/messaging/dist/serialize/F64.d.ts +146 -0
- package/.yalc/@node-dlc/messaging/dist/serialize/F64.js +294 -0
- package/.yalc/@node-dlc/messaging/dist/serialize/F64.js.map +1 -0
- package/.yalc/@node-dlc/messaging/dist/serialize/deserializeTlv.d.ts +9 -0
- package/.yalc/@node-dlc/messaging/dist/serialize/deserializeTlv.js +11 -0
- package/.yalc/@node-dlc/messaging/dist/serialize/deserializeTlv.js.map +1 -0
- package/.yalc/@node-dlc/messaging/dist/serialize/getTlv.d.ts +4 -0
- package/.yalc/@node-dlc/messaging/dist/serialize/getTlv.js +23 -0
- package/.yalc/@node-dlc/messaging/dist/serialize/getTlv.js.map +1 -0
- package/.yalc/@node-dlc/messaging/dist/serialize/readTlvs.d.ts +8 -0
- package/.yalc/@node-dlc/messaging/dist/serialize/readTlvs.js +33 -0
- package/.yalc/@node-dlc/messaging/dist/serialize/readTlvs.js.map +1 -0
- package/.yalc/@node-dlc/messaging/dist/util.d.ts +13 -0
- package/.yalc/@node-dlc/messaging/dist/util.js +42 -0
- package/.yalc/@node-dlc/messaging/dist/util.js.map +1 -0
- package/.yalc/@node-dlc/messaging/dist/validation/validate.d.ts +4 -0
- package/.yalc/@node-dlc/messaging/dist/validation/validate.js +31 -0
- package/.yalc/@node-dlc/messaging/dist/validation/validate.js.map +1 -0
- package/.yalc/@node-dlc/messaging/lib/MessageType.ts +140 -0
- package/.yalc/@node-dlc/messaging/lib/chain/ChainManager.ts +327 -0
- package/.yalc/@node-dlc/messaging/lib/chain/ChainMemoryStore.ts +34 -0
- package/.yalc/@node-dlc/messaging/lib/chain/DlcStore.ts +11 -0
- package/.yalc/@node-dlc/messaging/lib/chain/IChainFilterChainClient.ts +57 -0
- package/.yalc/@node-dlc/messaging/lib/domain/Address.ts +64 -0
- package/.yalc/@node-dlc/messaging/lib/index.ts +45 -0
- package/.yalc/@node-dlc/messaging/lib/irc/IrcMessage.ts +161 -0
- package/.yalc/@node-dlc/messaging/lib/messages/AddressCache.ts +74 -0
- package/.yalc/@node-dlc/messaging/lib/messages/BatchFundingGroup.ts +141 -0
- package/.yalc/@node-dlc/messaging/lib/messages/CetAdaptorSignatures.ts +89 -0
- package/.yalc/@node-dlc/messaging/lib/messages/ContractDescriptor.ts +317 -0
- package/.yalc/@node-dlc/messaging/lib/messages/ContractInfo.ts +439 -0
- package/.yalc/@node-dlc/messaging/lib/messages/DlcAccept.ts +639 -0
- package/.yalc/@node-dlc/messaging/lib/messages/DlcCancel.ts +57 -0
- package/.yalc/@node-dlc/messaging/lib/messages/DlcClose.ts +305 -0
- package/.yalc/@node-dlc/messaging/lib/messages/DlcCloseMetadata.ts +118 -0
- package/.yalc/@node-dlc/messaging/lib/messages/DlcIds.ts +67 -0
- package/.yalc/@node-dlc/messaging/lib/messages/DlcInfo.ts +81 -0
- package/.yalc/@node-dlc/messaging/lib/messages/DlcInput.ts +167 -0
- package/.yalc/@node-dlc/messaging/lib/messages/DlcMessage.ts +87 -0
- package/.yalc/@node-dlc/messaging/lib/messages/DlcOffer.ts +665 -0
- package/.yalc/@node-dlc/messaging/lib/messages/DlcSign.ts +359 -0
- package/.yalc/@node-dlc/messaging/lib/messages/DlcTransactions.ts +213 -0
- package/.yalc/@node-dlc/messaging/lib/messages/EventDescriptor.ts +294 -0
- package/.yalc/@node-dlc/messaging/lib/messages/FundingInput.ts +260 -0
- package/.yalc/@node-dlc/messaging/lib/messages/FundingSignatures.ts +98 -0
- package/.yalc/@node-dlc/messaging/lib/messages/IWireMessage.ts +6 -0
- package/.yalc/@node-dlc/messaging/lib/messages/NegotiationFields.ts +256 -0
- package/.yalc/@node-dlc/messaging/lib/messages/NodeAnnouncementMessage.ts +145 -0
- package/.yalc/@node-dlc/messaging/lib/messages/OracleAnnouncement.ts +176 -0
- package/.yalc/@node-dlc/messaging/lib/messages/OracleAttestation.ts +292 -0
- package/.yalc/@node-dlc/messaging/lib/messages/OracleEvent.ts +250 -0
- package/.yalc/@node-dlc/messaging/lib/messages/OracleEventContainer.ts +89 -0
- package/.yalc/@node-dlc/messaging/lib/messages/OracleIdentifier.ts +78 -0
- package/.yalc/@node-dlc/messaging/lib/messages/OracleInfo.ts +526 -0
- package/.yalc/@node-dlc/messaging/lib/messages/OrderAccept.ts +174 -0
- package/.yalc/@node-dlc/messaging/lib/messages/OrderIrcInfo.ts +100 -0
- package/.yalc/@node-dlc/messaging/lib/messages/OrderMetadata.ts +119 -0
- package/.yalc/@node-dlc/messaging/lib/messages/OrderNegotiationFields.ts +210 -0
- package/.yalc/@node-dlc/messaging/lib/messages/OrderOffer.ts +418 -0
- package/.yalc/@node-dlc/messaging/lib/messages/OrderPositionInfo.ts +147 -0
- package/.yalc/@node-dlc/messaging/lib/messages/PayoutCurvePiece.ts +454 -0
- package/.yalc/@node-dlc/messaging/lib/messages/PayoutFunction.ts +242 -0
- package/.yalc/@node-dlc/messaging/lib/messages/RoundingIntervals.ts +128 -0
- package/.yalc/@node-dlc/messaging/lib/messages/ScriptWitnessV0.ts +63 -0
- package/.yalc/@node-dlc/messaging/lib/messages/Tlv.ts +40 -0
- package/.yalc/@node-dlc/messaging/lib/serialize/F64.ts +337 -0
- package/.yalc/@node-dlc/messaging/lib/serialize/deserializeTlv.ts +15 -0
- package/.yalc/@node-dlc/messaging/lib/serialize/getTlv.ts +21 -0
- package/.yalc/@node-dlc/messaging/lib/serialize/readTlvs.ts +37 -0
- package/.yalc/@node-dlc/messaging/lib/util.ts +37 -0
- package/.yalc/@node-dlc/messaging/lib/validation/validate.ts +34 -0
- package/.yalc/@node-dlc/messaging/package.json +42 -0
- package/.yalc/@node-dlc/messaging/test_vectors/dlcspecs/enum_3_of_3_test.json +212 -0
- package/.yalc/@node-dlc/messaging/test_vectors/dlcspecs/enum_3_of_5_test.json +470 -0
- package/.yalc/@node-dlc/messaging/test_vectors/dlcspecs/enum_and_numerical_3_of_5_test.json +1519 -0
- package/.yalc/@node-dlc/messaging/test_vectors/dlcspecs/enum_and_numerical_5_of_5_test.json +547 -0
- package/.yalc/@node-dlc/messaging/test_vectors/dlcspecs/enum_and_numerical_with_diff_3_of_5_test.json +4763 -0
- package/.yalc/@node-dlc/messaging/test_vectors/dlcspecs/enum_and_numerical_with_diff_5_of_5_test.json +2171 -0
- package/.yalc/@node-dlc/messaging/test_vectors/dlcspecs/enum_single_oracle_test.json +166 -0
- package/.yalc/@node-dlc/messaging/test_vectors/dlcspecs/single_oracle_numerical_hyperbola_test.json +504 -0
- package/.yalc/@node-dlc/messaging/test_vectors/dlcspecs/single_oracle_numerical_test.json +264 -0
- package/.yalc/@node-dlc/messaging/test_vectors/dlcspecs/three_of_five_oracle_numerical_with_diff_test.json +4384 -0
- package/.yalc/@node-dlc/messaging/test_vectors/dlcspecs/three_of_three_oracle_numerical_test.json +326 -0
- package/.yalc/@node-dlc/messaging/test_vectors/dlcspecs/three_of_three_oracle_numerical_with_diff_test.json +654 -0
- package/.yalc/@node-dlc/messaging/test_vectors/dlcspecs/two_of_five_oracle_numerical_test.json +1140 -0
- package/.yalc/@node-dlc/messaging/test_vectors/dlcspecs/two_of_five_oracle_numerical_with_diff_test.json +2224 -0
- package/.yalc/@node-dlc/messaging/test_vectors/dlcspecs_backup_20250718_132453/enum_3_of_3_test.json +210 -0
- package/.yalc/@node-dlc/messaging/test_vectors/dlcspecs_backup_20250718_132453/enum_3_of_5_test.json +468 -0
- package/.yalc/@node-dlc/messaging/test_vectors/dlcspecs_backup_20250718_132453/enum_and_numerical_3_of_5_test.json +1517 -0
- package/.yalc/@node-dlc/messaging/test_vectors/dlcspecs_backup_20250718_132453/enum_and_numerical_5_of_5_test.json +545 -0
- package/.yalc/@node-dlc/messaging/test_vectors/dlcspecs_backup_20250718_132453/enum_and_numerical_with_diff_3_of_5_test.json +4761 -0
- package/.yalc/@node-dlc/messaging/test_vectors/dlcspecs_backup_20250718_132453/enum_and_numerical_with_diff_5_of_5_test.json +2169 -0
- package/.yalc/@node-dlc/messaging/test_vectors/dlcspecs_backup_20250718_132453/enum_single_oracle_test.json +164 -0
- package/.yalc/@node-dlc/messaging/test_vectors/dlcspecs_backup_20250718_132453/single_oracle_numerical_hyperbola_test.json +502 -0
- package/.yalc/@node-dlc/messaging/test_vectors/dlcspecs_backup_20250718_132453/single_oracle_numerical_test.json +262 -0
- package/.yalc/@node-dlc/messaging/test_vectors/dlcspecs_backup_20250718_132453/three_of_five_oracle_numerical_with_diff_test.json +4382 -0
- package/.yalc/@node-dlc/messaging/test_vectors/dlcspecs_backup_20250718_132453/three_of_three_oracle_numerical_test.json +324 -0
- package/.yalc/@node-dlc/messaging/test_vectors/dlcspecs_backup_20250718_132453/three_of_three_oracle_numerical_with_diff_test.json +652 -0
- package/.yalc/@node-dlc/messaging/test_vectors/dlcspecs_backup_20250718_132453/two_of_five_oracle_numerical_test.json +1138 -0
- package/.yalc/@node-dlc/messaging/test_vectors/dlcspecs_backup_20250718_132453/two_of_five_oracle_numerical_with_diff_test.json +2222 -0
- package/.yalc/@node-dlc/messaging/test_vectors/dlcspecs_backup_20250719_185952/enum_3_of_3_test.json +212 -0
- package/.yalc/@node-dlc/messaging/test_vectors/dlcspecs_backup_20250719_185952/enum_3_of_5_test.json +470 -0
- package/.yalc/@node-dlc/messaging/test_vectors/dlcspecs_backup_20250719_185952/enum_and_numerical_3_of_5_test.json +1519 -0
- package/.yalc/@node-dlc/messaging/test_vectors/dlcspecs_backup_20250719_185952/enum_and_numerical_5_of_5_test.json +547 -0
- package/.yalc/@node-dlc/messaging/test_vectors/dlcspecs_backup_20250719_185952/enum_and_numerical_with_diff_3_of_5_test.json +4763 -0
- package/.yalc/@node-dlc/messaging/test_vectors/dlcspecs_backup_20250719_185952/enum_and_numerical_with_diff_5_of_5_test.json +2171 -0
- package/.yalc/@node-dlc/messaging/test_vectors/dlcspecs_backup_20250719_185952/enum_single_oracle_test.json +166 -0
- package/.yalc/@node-dlc/messaging/test_vectors/dlcspecs_backup_20250719_185952/single_oracle_numerical_hyperbola_test.json +504 -0
- package/.yalc/@node-dlc/messaging/test_vectors/dlcspecs_backup_20250719_185952/single_oracle_numerical_test.json +264 -0
- package/.yalc/@node-dlc/messaging/test_vectors/dlcspecs_backup_20250719_185952/three_of_five_oracle_numerical_with_diff_test.json +4384 -0
- package/.yalc/@node-dlc/messaging/test_vectors/dlcspecs_backup_20250719_185952/three_of_three_oracle_numerical_test.json +326 -0
- package/.yalc/@node-dlc/messaging/test_vectors/dlcspecs_backup_20250719_185952/three_of_three_oracle_numerical_with_diff_test.json +654 -0
- package/.yalc/@node-dlc/messaging/test_vectors/dlcspecs_backup_20250719_185952/two_of_five_oracle_numerical_test.json +1140 -0
- package/.yalc/@node-dlc/messaging/test_vectors/dlcspecs_backup_20250719_185952/two_of_five_oracle_numerical_with_diff_test.json +2224 -0
- package/.yalc/@node-dlc/messaging/test_vectors/oracle/external_oracle_announcements.json +0 -0
- package/.yalc/@node-dlc/messaging/test_vectors/oracle/oracle_message_test_vectors.json +115 -0
- package/.yalc/@node-dlc/messaging/test_vectors/rust-dlc/accept_msg.json +1465 -0
- package/.yalc/@node-dlc/messaging/test_vectors/rust-dlc/dlc_fee_test.json +12362 -0
- package/.yalc/@node-dlc/messaging/test_vectors/rust-dlc/dlc_fee_test_scripts.json +57 -0
- package/.yalc/@node-dlc/messaging/test_vectors/rust-dlc/dlc_test.json +2766 -0
- package/.yalc/@node-dlc/messaging/test_vectors/rust-dlc/dlc_tx_test.json +2899 -0
- package/.yalc/@node-dlc/messaging/test_vectors/rust-dlc/offer_msg.json +163 -0
- package/.yalc/@node-dlc/messaging/test_vectors/rust-dlc/offer_msg_disjoint.json +352 -0
- package/.yalc/@node-dlc/messaging/test_vectors/rust-dlc/segment_chunk_msg.json +12635 -0
- package/.yalc/@node-dlc/messaging/test_vectors/rust-dlc/segment_start_msg.json +4022 -0
- package/.yalc/@node-dlc/messaging/test_vectors/rust-dlc/sign_msg.json +383 -0
- package/.yalc/@node-dlc/messaging/tsconfig.json +7 -0
- package/.yalc/@node-dlc/messaging/yalc.sig +1 -0
- package/CHANGELOG.md +114 -0
- package/README.md +48 -0
- package/dist/BitcoinDlcProvider.d.ts +51 -21
- package/dist/BitcoinDlcProvider.js +956 -459
- package/dist/BitcoinDlcProvider.js.map +1 -1
- package/dist/utils/Utils.d.ts +6 -6
- package/dist/utils/Utils.js +9 -5
- package/dist/utils/Utils.js.map +1 -1
- package/lib/BitcoinDlcProvider.ts +1525 -818
- package/lib/utils/Utils.ts +21 -24
- package/package.json +10 -10
- package/yalc.lock +30 -0
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
AddSignaturesToRefundTxResponse,
|
|
7
7
|
AddSignatureToFundTransactionRequest,
|
|
8
8
|
AddSignatureToFundTransactionResponse,
|
|
9
|
+
Amount,
|
|
9
10
|
CalculateEcSignatureRequest,
|
|
10
11
|
CreateBatchDlcTransactionsRequest,
|
|
11
12
|
CreateBatchDlcTransactionsResponse,
|
|
@@ -25,7 +26,12 @@ import {
|
|
|
25
26
|
CreateRefundTransactionRequest,
|
|
26
27
|
CreateRefundTransactionResponse,
|
|
27
28
|
CreateSignatureHashRequest,
|
|
29
|
+
CreateSplicedDlcTransactionsRequest,
|
|
30
|
+
CreateSplicedDlcTransactionsResponse,
|
|
31
|
+
DlcInputInfoRequest,
|
|
28
32
|
DlcProvider,
|
|
33
|
+
GetRawDlcFundingInputSignatureRequest,
|
|
34
|
+
GetRawDlcFundingInputSignatureResponse,
|
|
29
35
|
GetRawFundTxSignatureRequest,
|
|
30
36
|
GetRawFundTxSignatureResponse,
|
|
31
37
|
GetRawRefundTxSignatureRequest,
|
|
@@ -35,6 +41,8 @@ import {
|
|
|
35
41
|
PayoutRequest,
|
|
36
42
|
SignCetRequest,
|
|
37
43
|
SignCetResponse,
|
|
44
|
+
SignDlcFundingInputRequest,
|
|
45
|
+
SignDlcFundingInputResponse,
|
|
38
46
|
SignFundTransactionRequest,
|
|
39
47
|
SignFundTransactionResponse,
|
|
40
48
|
Utxo,
|
|
@@ -42,15 +50,22 @@ import {
|
|
|
42
50
|
VerifyCetAdaptorSignatureResponse,
|
|
43
51
|
VerifyCetAdaptorSignaturesRequest,
|
|
44
52
|
VerifyCetAdaptorSignaturesResponse,
|
|
53
|
+
VerifyDlcFundingInputSignatureRequest,
|
|
54
|
+
VerifyDlcFundingInputSignatureResponse,
|
|
45
55
|
VerifyFundTxSignatureRequest,
|
|
46
56
|
VerifyFundTxSignatureResponse,
|
|
47
57
|
VerifyRefundTxSignatureRequest,
|
|
48
58
|
VerifyRefundTxSignatureResponse,
|
|
49
59
|
VerifySignatureRequest,
|
|
50
60
|
} from '@atomicfinance/types';
|
|
61
|
+
import {
|
|
62
|
+
DlcInputInfo,
|
|
63
|
+
InputSupplementationMode,
|
|
64
|
+
} from '@atomicfinance/types/lib/models/Input';
|
|
51
65
|
import { sleep } from '@atomicfinance/utils';
|
|
52
66
|
import { Script, Sequence, Tx } from '@node-dlc/bitcoin';
|
|
53
67
|
import { StreamReader } from '@node-dlc/bufio';
|
|
68
|
+
import { BatchDlcTxBuilder } from '@node-dlc/core';
|
|
54
69
|
import {
|
|
55
70
|
DualClosingTxFinalizer,
|
|
56
71
|
DualFundingTxFinalizer,
|
|
@@ -61,42 +76,45 @@ import {
|
|
|
61
76
|
} from '@node-dlc/core';
|
|
62
77
|
import { hash160, sha256, xor } from '@node-dlc/crypto';
|
|
63
78
|
import {
|
|
64
|
-
|
|
79
|
+
CetAdaptorSignatures,
|
|
65
80
|
ContractDescriptor,
|
|
66
|
-
|
|
67
|
-
ContractDescriptorV1,
|
|
81
|
+
ContractDescriptorType,
|
|
68
82
|
ContractInfo,
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
83
|
+
ContractInfoType,
|
|
84
|
+
DigitDecompositionEventDescriptor,
|
|
85
|
+
DisjointContractInfo,
|
|
72
86
|
DlcAccept,
|
|
73
|
-
DlcAcceptV0,
|
|
74
87
|
DlcClose,
|
|
75
88
|
DlcCloseMetadata,
|
|
76
|
-
|
|
89
|
+
DlcInput,
|
|
77
90
|
DlcOffer,
|
|
78
|
-
DlcOfferV0,
|
|
79
91
|
DlcSign,
|
|
80
|
-
DlcSignV0,
|
|
81
92
|
DlcTransactions,
|
|
82
|
-
|
|
93
|
+
EnumeratedDescriptor,
|
|
94
|
+
EnumEventDescriptor,
|
|
95
|
+
F64,
|
|
83
96
|
FundingInput,
|
|
84
|
-
|
|
85
|
-
FundingSignaturesV0,
|
|
97
|
+
FundingSignatures,
|
|
86
98
|
HyperbolaPayoutCurvePiece,
|
|
87
99
|
MessageType,
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
100
|
+
MultiOracleInfo,
|
|
101
|
+
NumericalDescriptor,
|
|
102
|
+
OracleAttestation,
|
|
103
|
+
OracleEvent,
|
|
104
|
+
OracleInfo,
|
|
105
|
+
PayoutCurvePieceType,
|
|
106
|
+
PayoutFunction,
|
|
92
107
|
PayoutFunctionV0,
|
|
93
108
|
PolynomialPayoutCurvePiece,
|
|
94
109
|
ScriptWitnessV0,
|
|
110
|
+
SingleContractInfo,
|
|
111
|
+
SingleOracleInfo,
|
|
95
112
|
} from '@node-dlc/messaging';
|
|
96
113
|
import assert from 'assert';
|
|
97
114
|
import BigNumber from 'bignumber.js';
|
|
98
115
|
import { BitcoinNetwork, chainHashFromNetwork } from 'bitcoin-networks';
|
|
99
116
|
import { address, payments, Psbt, script } from 'bitcoinjs-lib';
|
|
117
|
+
import crypto from 'crypto';
|
|
100
118
|
import { ECPairInterface } from 'ecpair';
|
|
101
119
|
import * as ecc from 'tiny-secp256k1';
|
|
102
120
|
|
|
@@ -110,10 +128,13 @@ import {
|
|
|
110
128
|
|
|
111
129
|
export default class BitcoinDlcProvider
|
|
112
130
|
extends Provider
|
|
113
|
-
implements Partial<DlcProvider>
|
|
131
|
+
implements Partial<DlcProvider>
|
|
132
|
+
{
|
|
114
133
|
_network: BitcoinNetwork;
|
|
134
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
115
135
|
_cfdDlcJs: any;
|
|
116
136
|
|
|
137
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
117
138
|
constructor(network: BitcoinNetwork, cfdDlcJs?: any) {
|
|
118
139
|
super();
|
|
119
140
|
|
|
@@ -127,22 +148,110 @@ export default class BitcoinDlcProvider
|
|
|
127
148
|
}
|
|
128
149
|
}
|
|
129
150
|
|
|
151
|
+
/**
|
|
152
|
+
* Find private key for DLC funding pubkey by deriving wallet addresses
|
|
153
|
+
*/
|
|
154
|
+
private async findDlcFundingPrivateKey(
|
|
155
|
+
localFundPubkey: string,
|
|
156
|
+
remoteFundPubkey: string,
|
|
157
|
+
): Promise<string> {
|
|
158
|
+
const targetPubkeys = [localFundPubkey, remoteFundPubkey];
|
|
159
|
+
|
|
160
|
+
// First check existing wallet addresses
|
|
161
|
+
const addresses = await this.getMethod('getAddresses')();
|
|
162
|
+
|
|
163
|
+
for (const addressInfo of addresses) {
|
|
164
|
+
if (addressInfo.derivationPath) {
|
|
165
|
+
try {
|
|
166
|
+
const keyPair = await this.getMethod('keyPair')(
|
|
167
|
+
addressInfo.derivationPath,
|
|
168
|
+
);
|
|
169
|
+
const pubkey = Buffer.from(keyPair.publicKey);
|
|
170
|
+
const pubkeyHex = pubkey.toString('hex');
|
|
171
|
+
|
|
172
|
+
if (targetPubkeys.includes(pubkeyHex)) {
|
|
173
|
+
return Buffer.from(keyPair.privateKey).toString('hex');
|
|
174
|
+
}
|
|
175
|
+
} catch (error) {
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// If not found in existing addresses, do comprehensive search
|
|
182
|
+
// For DLC splicing, funding pubkeys can be at much higher derivation paths
|
|
183
|
+
console.log('Searching extensively for DLC funding private key...');
|
|
184
|
+
|
|
185
|
+
for (const isChange of [false, true]) {
|
|
186
|
+
for (let i = 0; i < 1000; i++) {
|
|
187
|
+
// Search up to 1000 addresses for DLC keys
|
|
188
|
+
try {
|
|
189
|
+
const address = await this.client.wallet.getAddresses(i, 1, isChange);
|
|
190
|
+
if (address && address.length > 0) {
|
|
191
|
+
const addressInfo = address[0];
|
|
192
|
+
|
|
193
|
+
if (addressInfo.derivationPath) {
|
|
194
|
+
const keyPair = await this.getMethod('keyPair')(
|
|
195
|
+
addressInfo.derivationPath,
|
|
196
|
+
);
|
|
197
|
+
const pubkey = Buffer.from(keyPair.publicKey);
|
|
198
|
+
const pubkeyHex = pubkey.toString('hex');
|
|
199
|
+
|
|
200
|
+
if (targetPubkeys.includes(pubkeyHex)) {
|
|
201
|
+
console.log(
|
|
202
|
+
`Found DLC funding key at derivation path: ${addressInfo.derivationPath}`,
|
|
203
|
+
);
|
|
204
|
+
return Buffer.from(keyPair.privateKey).toString('hex');
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
} catch (error) {
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
throw new Error(
|
|
215
|
+
`Could not find private key for DLC funding pubkeys: local=${localFundPubkey}, remote=${remoteFundPubkey}`,
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
|
|
130
219
|
private async GetPrivKeysForInputs(inputs: Input[]): Promise<string[]> {
|
|
131
220
|
const privKeys: string[] = [];
|
|
132
221
|
|
|
133
222
|
for (let i = 0; i < inputs.length; i++) {
|
|
134
223
|
const input = inputs[i];
|
|
135
|
-
let derivationPath = input.derivationPath;
|
|
136
224
|
|
|
137
|
-
if (
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
225
|
+
if (input.isDlcInput()) {
|
|
226
|
+
// Handle DLC input - use the dedicated method to find the funding private key
|
|
227
|
+
const dlcInput = input.dlcInput!;
|
|
228
|
+
const foundPrivKey = await this.findDlcFundingPrivateKey(
|
|
229
|
+
dlcInput.localFundPubkey,
|
|
230
|
+
dlcInput.remoteFundPubkey,
|
|
231
|
+
);
|
|
232
|
+
privKeys.push(foundPrivKey);
|
|
233
|
+
} else {
|
|
234
|
+
// Handle regular input
|
|
235
|
+
let derivationPath = input.derivationPath;
|
|
236
|
+
|
|
237
|
+
if (!derivationPath) {
|
|
238
|
+
try {
|
|
239
|
+
derivationPath = (
|
|
240
|
+
await this.getMethod('getWalletAddress')(input.address)
|
|
241
|
+
).derivationPath;
|
|
242
|
+
} catch (error) {
|
|
243
|
+
throw new Error(
|
|
244
|
+
`Unable to find address ${input.address} in wallet. ` +
|
|
245
|
+
`This may happen when using derivation paths outside the normal range. ` +
|
|
246
|
+
`Error: ${error.message}`,
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
142
250
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
251
|
+
const keyPair = await this.getMethod('keyPair')(derivationPath);
|
|
252
|
+
const privKey = Buffer.from(keyPair.__D).toString('hex');
|
|
253
|
+
privKeys.push(privKey);
|
|
254
|
+
}
|
|
146
255
|
}
|
|
147
256
|
|
|
148
257
|
return privKeys;
|
|
@@ -161,6 +270,46 @@ export default class BitcoinDlcProvider
|
|
|
161
270
|
}
|
|
162
271
|
}
|
|
163
272
|
|
|
273
|
+
/**
|
|
274
|
+
* Get inputs for amount with explicit supplementation control
|
|
275
|
+
*/
|
|
276
|
+
async GetInputsForAmountWithMode(
|
|
277
|
+
amounts: bigint[],
|
|
278
|
+
feeRatePerVb: bigint,
|
|
279
|
+
fixedInputs: Input[] = [],
|
|
280
|
+
supplementation: InputSupplementationMode = InputSupplementationMode.Required,
|
|
281
|
+
): Promise<Input[]> {
|
|
282
|
+
if (amounts.length === 0) return [];
|
|
283
|
+
|
|
284
|
+
// For "none" mode, use exactly the provided inputs
|
|
285
|
+
if (supplementation === InputSupplementationMode.None) {
|
|
286
|
+
return fixedInputs;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
// For "required" and "optional" modes, attempt supplementation
|
|
290
|
+
const fixedUtxos = fixedInputs.map((input) => input.toUtxo());
|
|
291
|
+
|
|
292
|
+
try {
|
|
293
|
+
const inputsForAmount: InputsForDualAmountResponse = await this.getMethod(
|
|
294
|
+
'getInputsForDualFunding',
|
|
295
|
+
)(amounts, feeRatePerVb, fixedUtxos);
|
|
296
|
+
|
|
297
|
+
// Convert UTXO objects to Input class instances
|
|
298
|
+
return inputsForAmount.inputs.map((utxo) => Input.fromUTXO(utxo));
|
|
299
|
+
} catch (e) {
|
|
300
|
+
const errorMessage = e instanceof Error ? e.message : 'Unknown error';
|
|
301
|
+
|
|
302
|
+
if (supplementation === InputSupplementationMode.Required) {
|
|
303
|
+
throw Error(
|
|
304
|
+
`Not enough balance GetInputsForAmountWithMode. Error: ${errorMessage}`,
|
|
305
|
+
);
|
|
306
|
+
} else {
|
|
307
|
+
// Optional mode: fallback to provided inputs
|
|
308
|
+
return fixedInputs;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
164
313
|
async GetInputsForAmount(
|
|
165
314
|
amounts: bigint[],
|
|
166
315
|
feeRatePerVb: bigint,
|
|
@@ -176,7 +325,8 @@ export default class BitcoinDlcProvider
|
|
|
176
325
|
'getInputsForDualFunding',
|
|
177
326
|
)(amounts, feeRatePerVb, fixedUtxos);
|
|
178
327
|
|
|
179
|
-
|
|
328
|
+
// Convert UTXO objects to Input class instances
|
|
329
|
+
inputs = inputsForAmount.inputs.map((utxo) => Input.fromUTXO(utxo));
|
|
180
330
|
} catch (e) {
|
|
181
331
|
const errorMessage = e instanceof Error ? e.message : 'Unknown error';
|
|
182
332
|
if (fixedInputs.length === 0) {
|
|
@@ -195,35 +345,34 @@ export default class BitcoinDlcProvider
|
|
|
195
345
|
collateral: bigint,
|
|
196
346
|
feeRatePerVb: bigint,
|
|
197
347
|
fixedInputs: Input[],
|
|
348
|
+
inputSupplementationMode: InputSupplementationMode = InputSupplementationMode.Required,
|
|
198
349
|
): Promise<InitializeResponse> {
|
|
199
350
|
const network = await this.getConnectedNetwork();
|
|
200
|
-
const payoutAddress: Address =
|
|
201
|
-
false
|
|
202
|
-
);
|
|
351
|
+
const payoutAddress: Address =
|
|
352
|
+
await this.client.wallet.getUnusedAddress(false);
|
|
203
353
|
const payoutSPK: Buffer = address.toOutputScript(
|
|
204
354
|
payoutAddress.address,
|
|
205
355
|
network,
|
|
206
356
|
);
|
|
207
|
-
const changeAddress: Address =
|
|
208
|
-
true
|
|
209
|
-
);
|
|
357
|
+
const changeAddress: Address =
|
|
358
|
+
await this.client.wallet.getUnusedAddress(true);
|
|
210
359
|
const changeSPK: Buffer = address.toOutputScript(
|
|
211
360
|
changeAddress.address,
|
|
212
361
|
network,
|
|
213
362
|
);
|
|
214
363
|
|
|
215
|
-
const fundingAddress: Address =
|
|
216
|
-
false
|
|
217
|
-
);
|
|
364
|
+
const fundingAddress: Address =
|
|
365
|
+
await this.client.wallet.getUnusedAddress(false);
|
|
218
366
|
const fundingPubKey: Buffer = Buffer.from(fundingAddress.publicKey, 'hex');
|
|
219
367
|
|
|
220
368
|
if (fundingAddress.address === payoutAddress.address)
|
|
221
369
|
throw Error('Address reuse');
|
|
222
370
|
|
|
223
|
-
const inputs: Input[] = await this.
|
|
371
|
+
const inputs: Input[] = await this.GetInputsForAmountWithMode(
|
|
224
372
|
[collateral],
|
|
225
373
|
feeRatePerVb,
|
|
226
374
|
fixedInputs,
|
|
375
|
+
inputSupplementationMode,
|
|
227
376
|
);
|
|
228
377
|
const fundingInputs: FundingInput[] = await Promise.all(
|
|
229
378
|
inputs.map(async (input) => {
|
|
@@ -251,10 +400,11 @@ export default class BitcoinDlcProvider
|
|
|
251
400
|
): Promise<BatchInitializeResponse> {
|
|
252
401
|
const network = await this.getConnectedNetwork();
|
|
253
402
|
|
|
254
|
-
const inputs: Input[] = await this.
|
|
403
|
+
const inputs: Input[] = await this.GetInputsForAmountWithMode(
|
|
255
404
|
collaterals,
|
|
256
405
|
feeRatePerVb,
|
|
257
406
|
fixedInputs,
|
|
407
|
+
InputSupplementationMode.Required,
|
|
258
408
|
);
|
|
259
409
|
|
|
260
410
|
const fundingInputs: FundingInput[] = await Promise.all(
|
|
@@ -267,26 +417,23 @@ export default class BitcoinDlcProvider
|
|
|
267
417
|
|
|
268
418
|
const changeSerialId: bigint = generateSerialId();
|
|
269
419
|
|
|
270
|
-
const changeAddress: Address =
|
|
271
|
-
true
|
|
272
|
-
);
|
|
420
|
+
const changeAddress: Address =
|
|
421
|
+
await this.client.wallet.getUnusedAddress(true);
|
|
273
422
|
const changeSPK: Buffer = address.toOutputScript(
|
|
274
423
|
changeAddress.address,
|
|
275
424
|
network,
|
|
276
425
|
);
|
|
277
426
|
|
|
278
427
|
for (let i = 0; i < collaterals.length; i++) {
|
|
279
|
-
const payoutAddress: Address =
|
|
280
|
-
false
|
|
281
|
-
);
|
|
428
|
+
const payoutAddress: Address =
|
|
429
|
+
await this.client.wallet.getUnusedAddress(false);
|
|
282
430
|
const payoutSPK: Buffer = address.toOutputScript(
|
|
283
431
|
payoutAddress.address,
|
|
284
432
|
network,
|
|
285
433
|
);
|
|
286
434
|
|
|
287
|
-
const fundingAddress: Address =
|
|
288
|
-
false
|
|
289
|
-
);
|
|
435
|
+
const fundingAddress: Address =
|
|
436
|
+
await this.client.wallet.getUnusedAddress(false);
|
|
290
437
|
const fundingPubKey: Buffer = Buffer.from(
|
|
291
438
|
fundingAddress.publicKey,
|
|
292
439
|
'hex',
|
|
@@ -317,35 +464,29 @@ export default class BitcoinDlcProvider
|
|
|
317
464
|
*/
|
|
318
465
|
|
|
319
466
|
private GetPayoutsFromPayoutFunction(
|
|
320
|
-
|
|
321
|
-
contractDescriptor:
|
|
322
|
-
oracleInfo:
|
|
467
|
+
dlcOffer: DlcOffer,
|
|
468
|
+
contractDescriptor: NumericalDescriptor,
|
|
469
|
+
oracleInfo: OracleInfo,
|
|
323
470
|
totalCollateral: bigint,
|
|
324
471
|
): GetPayoutsResponse {
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
const dlcOffer = _dlcOffer as DlcOfferV0;
|
|
328
|
-
if (contractDescriptor.payoutFunction.type !== MessageType.PayoutFunctionV0)
|
|
329
|
-
throw Error('PayoutFunction must be V0');
|
|
330
|
-
const payoutFunction = contractDescriptor.payoutFunction as PayoutFunctionV0;
|
|
331
|
-
if (payoutFunction.pieces.length === 0)
|
|
472
|
+
const payoutFunction = contractDescriptor.payoutFunction as PayoutFunction;
|
|
473
|
+
if (payoutFunction.payoutFunctionPieces.length === 0)
|
|
332
474
|
throw Error('PayoutFunction must have at least once PayoutCurvePiece');
|
|
333
|
-
if (payoutFunction.
|
|
475
|
+
if (payoutFunction.payoutFunctionPieces.length > 1)
|
|
334
476
|
throw Error('More than one PayoutCurvePiece not supported');
|
|
335
|
-
const payoutCurvePiece = payoutFunction.
|
|
477
|
+
const payoutCurvePiece = payoutFunction.payoutFunctionPieces[0]
|
|
336
478
|
.payoutCurvePiece as HyperbolaPayoutCurvePiece;
|
|
337
479
|
if (
|
|
338
|
-
payoutCurvePiece.
|
|
339
|
-
payoutCurvePiece.type !== MessageType.OldHyperbolaPayoutCurvePiece
|
|
480
|
+
payoutCurvePiece.payoutCurvePieceType !== PayoutCurvePieceType.Hyperbola
|
|
340
481
|
)
|
|
341
482
|
throw Error('Must be HyperbolaPayoutCurvePiece');
|
|
342
|
-
if (payoutCurvePiece.b
|
|
483
|
+
if (!payoutCurvePiece.b.eq(F64.ZERO) || !payoutCurvePiece.c.eq(F64.ZERO))
|
|
343
484
|
throw Error('b and c HyperbolaPayoutCurvePiece values must be 0');
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
eventDescriptor
|
|
348
|
-
)
|
|
485
|
+
// Cast to SingleOracleInfo to access announcement property
|
|
486
|
+
const singleOracleInfo = oracleInfo as SingleOracleInfo;
|
|
487
|
+
const eventDescriptor = singleOracleInfo.announcement.oracleEvent
|
|
488
|
+
.eventDescriptor as DigitDecompositionEventDescriptor;
|
|
489
|
+
if (eventDescriptor.type !== MessageType.DigitDecompositionEventDescriptor)
|
|
349
490
|
throw Error('Only DigitDecomposition Oracle Events supported');
|
|
350
491
|
|
|
351
492
|
const roundingIntervals = contractDescriptor.roundingIntervals;
|
|
@@ -368,13 +509,13 @@ export default class BitcoinDlcProvider
|
|
|
368
509
|
});
|
|
369
510
|
});
|
|
370
511
|
|
|
371
|
-
const rValuesMessagesList = this.GenerateMessages(
|
|
512
|
+
const rValuesMessagesList = this.GenerateMessages(singleOracleInfo);
|
|
372
513
|
|
|
373
514
|
const { payouts, messagesList } = outputsToPayouts(
|
|
374
515
|
payoutGroups,
|
|
375
516
|
rValuesMessagesList,
|
|
376
|
-
dlcOffer.
|
|
377
|
-
dlcOffer.contractInfo.totalCollateral - dlcOffer.
|
|
517
|
+
dlcOffer.offerCollateral,
|
|
518
|
+
dlcOffer.contractInfo.totalCollateral - dlcOffer.offerCollateral,
|
|
378
519
|
true,
|
|
379
520
|
);
|
|
380
521
|
|
|
@@ -382,30 +523,23 @@ export default class BitcoinDlcProvider
|
|
|
382
523
|
}
|
|
383
524
|
|
|
384
525
|
private GetPayoutsFromPolynomialPayoutFunction(
|
|
385
|
-
|
|
386
|
-
contractDescriptor:
|
|
387
|
-
oracleInfo:
|
|
526
|
+
dlcOffer: DlcOffer,
|
|
527
|
+
contractDescriptor: NumericalDescriptor,
|
|
528
|
+
oracleInfo: SingleOracleInfo,
|
|
388
529
|
totalCollateral: bigint,
|
|
389
530
|
): GetPayoutsResponse {
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
const dlcOffer = _dlcOffer as DlcOfferV0;
|
|
393
|
-
if (contractDescriptor.payoutFunction.type !== MessageType.PayoutFunctionV0)
|
|
394
|
-
throw Error('PayoutFunction must be V0');
|
|
395
|
-
const payoutFunction = contractDescriptor.payoutFunction as PayoutFunctionV0;
|
|
396
|
-
if (payoutFunction.pieces.length === 0)
|
|
531
|
+
const payoutFunction = contractDescriptor.payoutFunction as PayoutFunction;
|
|
532
|
+
if (payoutFunction.payoutFunctionPieces.length === 0)
|
|
397
533
|
throw Error('PayoutFunction must have at least once PayoutCurvePiece');
|
|
398
|
-
for (const piece of payoutFunction.
|
|
534
|
+
for (const piece of payoutFunction.payoutFunctionPieces) {
|
|
399
535
|
if (
|
|
400
536
|
piece.payoutCurvePiece.type !== MessageType.PolynomialPayoutCurvePiece
|
|
401
537
|
)
|
|
402
538
|
throw Error('Must be PolynomialPayoutCurvePiece');
|
|
403
539
|
}
|
|
404
540
|
const eventDescriptor = oracleInfo.announcement.oracleEvent
|
|
405
|
-
.eventDescriptor as
|
|
406
|
-
if (
|
|
407
|
-
eventDescriptor.type !== MessageType.DigitDecompositionEventDescriptorV0
|
|
408
|
-
)
|
|
541
|
+
.eventDescriptor as DigitDecompositionEventDescriptor;
|
|
542
|
+
if (eventDescriptor.type !== MessageType.DigitDecompositionEventDescriptor)
|
|
409
543
|
throw Error('Only DigitDecomposition Oracle Events supported');
|
|
410
544
|
|
|
411
545
|
const roundingIntervals = contractDescriptor.roundingIntervals;
|
|
@@ -433,17 +567,15 @@ export default class BitcoinDlcProvider
|
|
|
433
567
|
const { payouts, messagesList } = outputsToPayouts(
|
|
434
568
|
payoutGroups,
|
|
435
569
|
rValuesMessagesList,
|
|
436
|
-
dlcOffer.
|
|
437
|
-
dlcOffer.contractInfo.totalCollateral - dlcOffer.
|
|
570
|
+
dlcOffer.offerCollateral,
|
|
571
|
+
dlcOffer.contractInfo.totalCollateral - dlcOffer.offerCollateral,
|
|
438
572
|
true,
|
|
439
573
|
);
|
|
440
574
|
|
|
441
575
|
return { payouts, payoutGroups, messagesList };
|
|
442
576
|
}
|
|
443
577
|
|
|
444
|
-
private GetPayouts(
|
|
445
|
-
const { dlcOffer } = checkTypes({ _dlcOffer });
|
|
446
|
-
|
|
578
|
+
private GetPayouts(dlcOffer: DlcOffer): GetPayoutsResponse[] {
|
|
447
579
|
const contractInfo = dlcOffer.contractInfo;
|
|
448
580
|
const totalCollateral = contractInfo.totalCollateral;
|
|
449
581
|
const contractOraclePairs = this.GetContractOraclePairs(contractInfo);
|
|
@@ -489,78 +621,130 @@ export default class BitcoinDlcProvider
|
|
|
489
621
|
);
|
|
490
622
|
}
|
|
491
623
|
|
|
624
|
+
private GetPayoutsFromEnumeratedDescriptor(
|
|
625
|
+
dlcOffer: DlcOffer,
|
|
626
|
+
contractDescriptor: EnumeratedDescriptor,
|
|
627
|
+
oracleInfo: OracleInfo,
|
|
628
|
+
totalCollateral: bigint,
|
|
629
|
+
): GetPayoutsResponse {
|
|
630
|
+
const payoutGroups: PayoutGroup[] = [];
|
|
631
|
+
const rValuesMessagesList = this.GenerateMessages(
|
|
632
|
+
oracleInfo as SingleOracleInfo,
|
|
633
|
+
);
|
|
634
|
+
|
|
635
|
+
// For enumerated descriptors, each outcome creates one payout
|
|
636
|
+
// Each outcome maps to one index in the oracle's possible outcomes
|
|
637
|
+
contractDescriptor.outcomes.forEach((outcome, index) => {
|
|
638
|
+
payoutGroups.push({
|
|
639
|
+
payout: outcome.localPayout,
|
|
640
|
+
groups: [[index]], // Simple index-based grouping for enum outcomes
|
|
641
|
+
});
|
|
642
|
+
});
|
|
643
|
+
|
|
644
|
+
const { payouts, messagesList } = outputsToPayouts(
|
|
645
|
+
payoutGroups,
|
|
646
|
+
rValuesMessagesList,
|
|
647
|
+
dlcOffer.offerCollateral,
|
|
648
|
+
totalCollateral - dlcOffer.offerCollateral,
|
|
649
|
+
true,
|
|
650
|
+
);
|
|
651
|
+
|
|
652
|
+
return { payouts, payoutGroups, messagesList };
|
|
653
|
+
}
|
|
654
|
+
|
|
492
655
|
private GetPayoutsFromContractDescriptor(
|
|
493
|
-
dlcOffer:
|
|
656
|
+
dlcOffer: DlcOffer,
|
|
494
657
|
contractDescriptor: ContractDescriptor,
|
|
495
|
-
oracleInfo:
|
|
658
|
+
oracleInfo: OracleInfo,
|
|
496
659
|
totalCollateral: bigint,
|
|
497
660
|
) {
|
|
498
|
-
switch (contractDescriptor.
|
|
499
|
-
case
|
|
500
|
-
|
|
661
|
+
switch (contractDescriptor.contractDescriptorType) {
|
|
662
|
+
case ContractDescriptorType.Enumerated: {
|
|
663
|
+
return this.GetPayoutsFromEnumeratedDescriptor(
|
|
664
|
+
dlcOffer,
|
|
665
|
+
contractDescriptor as EnumeratedDescriptor,
|
|
666
|
+
oracleInfo,
|
|
667
|
+
totalCollateral,
|
|
668
|
+
);
|
|
501
669
|
}
|
|
502
|
-
case
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
case MessageType.PolynomialPayoutCurvePiece:
|
|
526
|
-
return this.GetPayoutsFromPolynomialPayoutFunction(
|
|
527
|
-
dlcOffer,
|
|
528
|
-
contractDescriptor as ContractDescriptorV1,
|
|
529
|
-
oracleInfo,
|
|
530
|
-
totalCollateral,
|
|
531
|
-
);
|
|
532
|
-
}
|
|
670
|
+
case ContractDescriptorType.NumericOutcome: {
|
|
671
|
+
const numericalDescriptor = contractDescriptor as NumericalDescriptor;
|
|
672
|
+
const payoutFunction = numericalDescriptor.payoutFunction;
|
|
673
|
+
|
|
674
|
+
// TODO: add a better check for this
|
|
675
|
+
const payoutCurvePiece =
|
|
676
|
+
payoutFunction.payoutFunctionPieces[0].payoutCurvePiece;
|
|
677
|
+
|
|
678
|
+
switch (payoutCurvePiece.payoutCurvePieceType) {
|
|
679
|
+
case PayoutCurvePieceType.Hyperbola:
|
|
680
|
+
return this.GetPayoutsFromPayoutFunction(
|
|
681
|
+
dlcOffer,
|
|
682
|
+
numericalDescriptor,
|
|
683
|
+
oracleInfo,
|
|
684
|
+
totalCollateral,
|
|
685
|
+
);
|
|
686
|
+
case PayoutCurvePieceType.Polynomial:
|
|
687
|
+
return this.GetPayoutsFromPolynomialPayoutFunction(
|
|
688
|
+
dlcOffer,
|
|
689
|
+
numericalDescriptor,
|
|
690
|
+
oracleInfo as SingleOracleInfo,
|
|
691
|
+
totalCollateral,
|
|
692
|
+
);
|
|
533
693
|
}
|
|
534
|
-
break;
|
|
535
|
-
default: {
|
|
536
|
-
throw Error('ContractDescriptor must be V0 or V1');
|
|
537
694
|
}
|
|
538
695
|
}
|
|
539
696
|
}
|
|
540
697
|
|
|
541
698
|
public async createDlcTxs(
|
|
542
|
-
|
|
543
|
-
|
|
699
|
+
dlcOffer: DlcOffer,
|
|
700
|
+
dlcAccept: DlcAccept,
|
|
544
701
|
): Promise<CreateDlcTxsResponse> {
|
|
545
|
-
const
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
const
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
const
|
|
554
|
-
const
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
702
|
+
const localFundPubkey = dlcOffer.fundingPubkey.toString('hex');
|
|
703
|
+
const remoteFundPubkey = dlcAccept.fundingPubkey.toString('hex');
|
|
704
|
+
const localFinalScriptPubkey = dlcOffer.payoutSpk.toString('hex');
|
|
705
|
+
const remoteFinalScriptPubkey = dlcAccept.payoutSpk.toString('hex');
|
|
706
|
+
const localChangeScriptPubkey = dlcOffer.changeSpk.toString('hex');
|
|
707
|
+
const remoteChangeScriptPubkey = dlcAccept.changeSpk.toString('hex');
|
|
708
|
+
|
|
709
|
+
// Separate regular inputs from DLC inputs (only from offeror side)
|
|
710
|
+
const localRegularInputs: Utxo[] = [];
|
|
711
|
+
const localDlcInputs: {
|
|
712
|
+
fundTxid: string;
|
|
713
|
+
fundVout: number;
|
|
714
|
+
fundAmount: number;
|
|
715
|
+
localFundPubkey: string;
|
|
716
|
+
remoteFundPubkey: string;
|
|
717
|
+
contractId: string;
|
|
718
|
+
maxWitnessLength: number;
|
|
719
|
+
inputSerialId?: bigint;
|
|
720
|
+
}[] = [];
|
|
721
|
+
|
|
722
|
+
for (const fundingInput of dlcOffer.fundingInputs) {
|
|
723
|
+
if (fundingInput.dlcInput) {
|
|
724
|
+
// This is a DLC input for splicing
|
|
725
|
+
// The pubkeys should be from the original DLC to correctly spend its funding output
|
|
726
|
+
localDlcInputs.push({
|
|
727
|
+
fundTxid: fundingInput.prevTx.txId.toString(),
|
|
728
|
+
fundVout: fundingInput.prevTxVout,
|
|
729
|
+
fundAmount: Number(
|
|
730
|
+
fundingInput.prevTx.outputs[fundingInput.prevTxVout].value.sats,
|
|
731
|
+
),
|
|
732
|
+
localFundPubkey:
|
|
733
|
+
fundingInput.dlcInput.localFundPubkey.toString('hex'),
|
|
734
|
+
remoteFundPubkey:
|
|
735
|
+
fundingInput.dlcInput.remoteFundPubkey.toString('hex'),
|
|
736
|
+
contractId: fundingInput.dlcInput.contractId.toString('hex'),
|
|
737
|
+
maxWitnessLength: fundingInput.maxWitnessLen,
|
|
738
|
+
inputSerialId: fundingInput.inputSerialId,
|
|
739
|
+
});
|
|
740
|
+
} else {
|
|
741
|
+
// Regular input
|
|
559
742
|
const input = await this.fundingInputToInput(fundingInput, false);
|
|
560
|
-
|
|
561
|
-
}
|
|
562
|
-
|
|
743
|
+
localRegularInputs.push(input.toUtxo());
|
|
744
|
+
}
|
|
745
|
+
}
|
|
563
746
|
|
|
747
|
+
// Process remote inputs (no DLC inputs from acceptor side)
|
|
564
748
|
const remoteInputs: Utxo[] = await Promise.all(
|
|
565
749
|
dlcAccept.fundingInputs.map(async (fundingInput) => {
|
|
566
750
|
const input = await this.fundingInputToInput(fundingInput, false);
|
|
@@ -568,7 +752,8 @@ export default class BitcoinDlcProvider
|
|
|
568
752
|
}),
|
|
569
753
|
);
|
|
570
754
|
|
|
571
|
-
|
|
755
|
+
// Calculate input amounts
|
|
756
|
+
const localInputAmount = localRegularInputs.reduce<number>(
|
|
572
757
|
(prev, cur) => prev + cur.amount.GetSatoshiAmount(),
|
|
573
758
|
0,
|
|
574
759
|
);
|
|
@@ -582,101 +767,164 @@ export default class BitcoinDlcProvider
|
|
|
582
767
|
let messagesList: Messages[] = [];
|
|
583
768
|
|
|
584
769
|
if (
|
|
585
|
-
dlcOffer.contractInfo.type === MessageType.
|
|
586
|
-
(dlcOffer.contractInfo as
|
|
587
|
-
|
|
770
|
+
dlcOffer.contractInfo.type === MessageType.SingleContractInfo &&
|
|
771
|
+
(dlcOffer.contractInfo as SingleContractInfo).contractDescriptor.type ===
|
|
772
|
+
ContractDescriptorType.Enumerated
|
|
588
773
|
) {
|
|
589
|
-
for (const outcome of (
|
|
590
|
-
.
|
|
774
|
+
for (const outcome of (
|
|
775
|
+
(dlcOffer.contractInfo as SingleContractInfo)
|
|
776
|
+
.contractDescriptor as EnumeratedDescriptor
|
|
777
|
+
).outcomes) {
|
|
591
778
|
payouts.push({
|
|
592
779
|
local: outcome.localPayout,
|
|
593
780
|
remote:
|
|
594
|
-
dlcOffer.
|
|
595
|
-
dlcAccept.
|
|
781
|
+
dlcOffer.offerCollateral +
|
|
782
|
+
dlcAccept.acceptCollateral -
|
|
596
783
|
outcome.localPayout,
|
|
597
784
|
});
|
|
598
|
-
messagesList.push({ messages: [outcome.outcome
|
|
785
|
+
messagesList.push({ messages: [outcome.outcome] });
|
|
599
786
|
}
|
|
600
787
|
} else {
|
|
601
788
|
const payoutResponses = this.GetPayouts(dlcOffer);
|
|
602
|
-
const {
|
|
603
|
-
|
|
604
|
-
messagesList: tempMessagesList,
|
|
605
|
-
} = this.FlattenPayouts(payoutResponses);
|
|
789
|
+
const { payouts: tempPayouts, messagesList: tempMessagesList } =
|
|
790
|
+
this.FlattenPayouts(payoutResponses);
|
|
606
791
|
payouts = tempPayouts;
|
|
607
792
|
messagesList = tempMessagesList;
|
|
608
793
|
}
|
|
609
794
|
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
795
|
+
// Determine whether to use regular or spliced DLC transactions
|
|
796
|
+
const hasDlcInputs = localDlcInputs.length > 0;
|
|
797
|
+
|
|
798
|
+
let dlcTxs:
|
|
799
|
+
| CreateDlcTransactionsResponse
|
|
800
|
+
| CreateSplicedDlcTransactionsResponse;
|
|
801
|
+
|
|
802
|
+
if (hasDlcInputs) {
|
|
803
|
+
// Use spliced DLC transactions when DLC inputs are present
|
|
804
|
+
const splicedDlcTxRequest: CreateSplicedDlcTransactionsRequest = {
|
|
805
|
+
payouts,
|
|
806
|
+
localFundPubkey,
|
|
807
|
+
localFinalScriptPubkey,
|
|
808
|
+
remoteFundPubkey,
|
|
809
|
+
remoteFinalScriptPubkey,
|
|
810
|
+
localInputAmount,
|
|
811
|
+
localCollateralAmount: dlcOffer.offerCollateral,
|
|
812
|
+
localPayoutSerialId: dlcOffer.payoutSerialId,
|
|
813
|
+
localChangeSerialId: dlcOffer.changeSerialId,
|
|
814
|
+
remoteInputAmount,
|
|
815
|
+
remoteCollateralAmount: dlcAccept.acceptCollateral,
|
|
816
|
+
remotePayoutSerialId: dlcAccept.payoutSerialId,
|
|
817
|
+
remoteChangeSerialId: dlcAccept.changeSerialId,
|
|
818
|
+
refundLocktime: dlcOffer.refundLocktime,
|
|
819
|
+
localInputs: localRegularInputs,
|
|
820
|
+
localDlcInputs: localDlcInputs,
|
|
821
|
+
remoteInputs,
|
|
822
|
+
localChangeScriptPubkey,
|
|
823
|
+
remoteChangeScriptPubkey,
|
|
824
|
+
feeRate: Number(dlcOffer.feeRatePerVb),
|
|
825
|
+
cetLockTime: dlcOffer.cetLocktime,
|
|
826
|
+
fundOutputSerialId: dlcOffer.fundOutputSerialId,
|
|
827
|
+
};
|
|
633
828
|
|
|
634
|
-
|
|
829
|
+
dlcTxs = await this.CreateSplicedDlcTransactions(splicedDlcTxRequest);
|
|
830
|
+
} else {
|
|
831
|
+
// Use regular DLC transactions when no DLC inputs
|
|
832
|
+
const dlcTxRequest: CreateDlcTransactionsRequest = {
|
|
833
|
+
payouts,
|
|
834
|
+
localFundPubkey,
|
|
835
|
+
localFinalScriptPubkey,
|
|
836
|
+
remoteFundPubkey,
|
|
837
|
+
remoteFinalScriptPubkey,
|
|
838
|
+
localInputAmount,
|
|
839
|
+
localCollateralAmount: dlcOffer.offerCollateral,
|
|
840
|
+
localPayoutSerialId: dlcOffer.payoutSerialId,
|
|
841
|
+
localChangeSerialId: dlcOffer.changeSerialId,
|
|
842
|
+
remoteInputAmount,
|
|
843
|
+
remoteCollateralAmount: dlcAccept.acceptCollateral,
|
|
844
|
+
remotePayoutSerialId: dlcAccept.payoutSerialId,
|
|
845
|
+
remoteChangeSerialId: dlcAccept.changeSerialId,
|
|
846
|
+
refundLocktime: dlcOffer.refundLocktime,
|
|
847
|
+
localInputs: localRegularInputs,
|
|
848
|
+
remoteInputs,
|
|
849
|
+
localChangeScriptPubkey,
|
|
850
|
+
remoteChangeScriptPubkey,
|
|
851
|
+
feeRate: Number(dlcOffer.feeRatePerVb),
|
|
852
|
+
cetLockTime: dlcOffer.cetLocktime,
|
|
853
|
+
fundOutputSerialId: dlcOffer.fundOutputSerialId,
|
|
854
|
+
};
|
|
855
|
+
|
|
856
|
+
dlcTxs = await this.CreateDlcTransactions(dlcTxRequest);
|
|
857
|
+
}
|
|
635
858
|
|
|
636
|
-
const dlcTransactions = new
|
|
859
|
+
const dlcTransactions = new DlcTransactions();
|
|
637
860
|
dlcTransactions.fundTx = Tx.decode(StreamReader.fromHex(dlcTxs.fundTxHex));
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
861
|
+
|
|
862
|
+
// Build serial IDs based on actual outputs in the transaction
|
|
863
|
+
const actualOutputs = dlcTransactions.fundTx.outputs;
|
|
864
|
+
const serialIds: bigint[] = [];
|
|
865
|
+
|
|
866
|
+
// Always include the funding output serial ID
|
|
867
|
+
serialIds.push(BigInt(dlcOffer.fundOutputSerialId));
|
|
868
|
+
|
|
869
|
+
// Only include change serial IDs if there are actually change outputs
|
|
870
|
+
// For exact amount DLCs with no change, there will be only 1 output (the funding output)
|
|
871
|
+
if (actualOutputs.length > 1) {
|
|
872
|
+
// Multiple outputs means there are change outputs
|
|
873
|
+
if (dlcOffer.offerCollateral > 0n) {
|
|
874
|
+
serialIds.push(BigInt(dlcOffer.changeSerialId));
|
|
875
|
+
}
|
|
876
|
+
if (dlcAccept.acceptCollateral > 0n) {
|
|
877
|
+
serialIds.push(BigInt(dlcAccept.changeSerialId));
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
dlcTransactions.fundTxVout = serialIds
|
|
643
882
|
.sort((a, b) => (a < b ? -1 : a > b ? 1 : 0))
|
|
644
|
-
.findIndex((i) => BigInt(i) === BigInt(
|
|
883
|
+
.findIndex((i) => BigInt(i) === BigInt(dlcOffer.fundOutputSerialId));
|
|
884
|
+
|
|
885
|
+
// Validate that the calculated fundTxVout is valid
|
|
886
|
+
if (
|
|
887
|
+
dlcTransactions.fundTxVout < 0 ||
|
|
888
|
+
dlcTransactions.fundTxVout >= dlcTransactions.fundTx.outputs.length
|
|
889
|
+
) {
|
|
890
|
+
throw new Error(
|
|
891
|
+
`Invalid fundTxVout calculation: calculated=${dlcTransactions.fundTxVout}, ` +
|
|
892
|
+
`fundTx.outputs.length=${dlcTransactions.fundTx.outputs.length}, ` +
|
|
893
|
+
`fundOutputSerialId=${dlcOffer.fundOutputSerialId}, ` +
|
|
894
|
+
`serialIds=[${serialIds.join(', ')}], ` +
|
|
895
|
+
`offerCollateral=${dlcOffer.offerCollateral}, ` +
|
|
896
|
+
`acceptCollateral=${dlcAccept.acceptCollateral}`,
|
|
897
|
+
);
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
dlcTransactions.cets = dlcTxs.cetsHex.map((cetHex) =>
|
|
901
|
+
Tx.decode(StreamReader.fromHex(cetHex)),
|
|
902
|
+
);
|
|
645
903
|
dlcTransactions.refundTx = Tx.decode(
|
|
646
904
|
StreamReader.fromHex(dlcTxs.refundTxHex),
|
|
647
905
|
);
|
|
648
|
-
dlcTransactions.cets = dlcTxs.cetsHex.map((cetHex) => {
|
|
649
|
-
return Tx.decode(StreamReader.fromHex(cetHex));
|
|
650
|
-
});
|
|
651
906
|
|
|
652
907
|
return { dlcTransactions, messagesList };
|
|
653
908
|
}
|
|
654
909
|
|
|
655
910
|
public async createBatchDlcTxs(
|
|
656
|
-
|
|
657
|
-
|
|
911
|
+
dlcOffers: DlcOffer[],
|
|
912
|
+
dlcAccepts: DlcAccept[],
|
|
658
913
|
): Promise<CreateBatchDlcTxsResponse> {
|
|
659
|
-
const dlcOffers = _dlcOffers.map((dlcOffer) => {
|
|
660
|
-
return checkTypes({ _dlcOffer: dlcOffer }).dlcOffer;
|
|
661
|
-
});
|
|
662
|
-
const dlcAccepts = _dlcAccepts.map((dlcAccept) => {
|
|
663
|
-
return checkTypes({ _dlcAccept: dlcAccept }).dlcAccept;
|
|
664
|
-
});
|
|
665
|
-
|
|
666
914
|
const localFundPubkeys = dlcOffers.map((dlcOffer) =>
|
|
667
|
-
dlcOffer.
|
|
915
|
+
dlcOffer.fundingPubkey.toString('hex'),
|
|
668
916
|
);
|
|
669
917
|
const remoteFundPubkeys = dlcAccepts.map((dlcAccept) =>
|
|
670
|
-
dlcAccept.
|
|
918
|
+
dlcAccept.fundingPubkey.toString('hex'),
|
|
671
919
|
);
|
|
672
920
|
const localFinalScriptPubkeys = dlcOffers.map((dlcOffer) =>
|
|
673
|
-
dlcOffer.
|
|
921
|
+
dlcOffer.payoutSpk.toString('hex'),
|
|
674
922
|
);
|
|
675
923
|
const remoteFinalScriptPubkeys = dlcAccepts.map((dlcAccept) =>
|
|
676
|
-
dlcAccept.
|
|
924
|
+
dlcAccept.payoutSpk.toString('hex'),
|
|
677
925
|
);
|
|
678
|
-
const localChangeScriptPubkey = dlcOffers[0].
|
|
679
|
-
const remoteChangeScriptPubkey = dlcAccepts[0].
|
|
926
|
+
const localChangeScriptPubkey = dlcOffers[0].changeSpk.toString('hex');
|
|
927
|
+
const remoteChangeScriptPubkey = dlcAccepts[0].changeSpk.toString('hex');
|
|
680
928
|
|
|
681
929
|
const localInputs: Utxo[] = await Promise.all(
|
|
682
930
|
dlcOffers[0].fundingInputs.map(async (fundingInput) => {
|
|
@@ -730,7 +978,7 @@ export default class BitcoinDlcProvider
|
|
|
730
978
|
remoteFinalScriptPubkeys,
|
|
731
979
|
localInputAmount,
|
|
732
980
|
localCollateralAmounts: dlcOffers.map(
|
|
733
|
-
(dlcOffer) => dlcOffer.
|
|
981
|
+
(dlcOffer) => dlcOffer.offerCollateral,
|
|
734
982
|
),
|
|
735
983
|
localPayoutSerialIds: dlcOffers.map(
|
|
736
984
|
(dlcOffer) => dlcOffer.payoutSerialId,
|
|
@@ -738,7 +986,7 @@ export default class BitcoinDlcProvider
|
|
|
738
986
|
localChangeSerialId: dlcOffers[0].changeSerialId,
|
|
739
987
|
remoteInputAmount,
|
|
740
988
|
remoteCollateralAmounts: dlcAccepts.map(
|
|
741
|
-
(dlcAccept) => dlcAccept.
|
|
989
|
+
(dlcAccept) => dlcAccept.acceptCollateral,
|
|
742
990
|
),
|
|
743
991
|
remotePayoutSerialIds: dlcAccepts.map(
|
|
744
992
|
(dlcAccept) => dlcAccept.payoutSerialId,
|
|
@@ -758,11 +1006,11 @@ export default class BitcoinDlcProvider
|
|
|
758
1006
|
|
|
759
1007
|
const dlcTxs = await this.CreateBatchDlcTransactions(batchDlcTxRequest);
|
|
760
1008
|
|
|
761
|
-
const dlcTransactionsList:
|
|
1009
|
+
const dlcTransactionsList: DlcTransactions[] = [];
|
|
762
1010
|
|
|
763
1011
|
let start = 0;
|
|
764
1012
|
for (let i = 0; i < dlcTxs.refundTxHexList.length; i++) {
|
|
765
|
-
const dlcTransactions = new
|
|
1013
|
+
const dlcTransactions = new DlcTransactions();
|
|
766
1014
|
|
|
767
1015
|
dlcTransactions.fundTx = Tx.decode(
|
|
768
1016
|
StreamReader.fromHex(dlcTxs.fundTxHex),
|
|
@@ -796,15 +1044,27 @@ export default class BitcoinDlcProvider
|
|
|
796
1044
|
return { dlcTransactionsList, nestedMessagesList };
|
|
797
1045
|
}
|
|
798
1046
|
|
|
799
|
-
private GenerateEnumMessages(oracleEvent:
|
|
800
|
-
|
|
1047
|
+
private GenerateEnumMessages(oracleEvent: OracleEvent): Messages[] {
|
|
1048
|
+
const eventDescriptor = oracleEvent.eventDescriptor as EnumEventDescriptor;
|
|
1049
|
+
|
|
1050
|
+
// For enum events, each oracle has one nonce and can attest to one of the possible outcomes
|
|
1051
|
+
const messagesList: Messages[] = [];
|
|
1052
|
+
|
|
1053
|
+
// For enum events, hash the outcomes to match the contract descriptor format
|
|
1054
|
+
const messages = eventDescriptor.outcomes.map((outcome) =>
|
|
1055
|
+
sha256(Buffer.from(outcome)).toString('hex'),
|
|
1056
|
+
);
|
|
1057
|
+
messagesList.push({ messages });
|
|
1058
|
+
|
|
1059
|
+
return messagesList;
|
|
801
1060
|
}
|
|
802
1061
|
|
|
803
1062
|
private GenerateDigitDecompositionMessages(
|
|
804
|
-
oracleEvent:
|
|
1063
|
+
oracleEvent: OracleEvent,
|
|
805
1064
|
): Messages[] {
|
|
806
1065
|
const oracleNonces = oracleEvent.oracleNonces;
|
|
807
|
-
const eventDescriptor =
|
|
1066
|
+
const eventDescriptor =
|
|
1067
|
+
oracleEvent.eventDescriptor as DigitDecompositionEventDescriptor;
|
|
808
1068
|
|
|
809
1069
|
const messagesList: Messages[] = [];
|
|
810
1070
|
oracleNonces.forEach(() => {
|
|
@@ -819,13 +1079,31 @@ export default class BitcoinDlcProvider
|
|
|
819
1079
|
return messagesList;
|
|
820
1080
|
}
|
|
821
1081
|
|
|
822
|
-
private GenerateMessages(oracleInfo:
|
|
823
|
-
|
|
1082
|
+
private GenerateMessages(oracleInfo: OracleInfo): Messages[] {
|
|
1083
|
+
// Handle both SingleOracleInfo and MultiOracleInfo using type property instead of instanceof
|
|
1084
|
+
let oracleEvent: OracleEvent;
|
|
1085
|
+
|
|
1086
|
+
if (oracleInfo.type === MessageType.SingleOracleInfo) {
|
|
1087
|
+
const singleOracleInfo = oracleInfo as SingleOracleInfo;
|
|
1088
|
+
oracleEvent = singleOracleInfo.announcement.oracleEvent;
|
|
1089
|
+
} else if (oracleInfo.type === MessageType.MultiOracleInfo) {
|
|
1090
|
+
const multiOracleInfo = oracleInfo as MultiOracleInfo;
|
|
1091
|
+
// For multi-oracle, use the first announcement for now
|
|
1092
|
+
// TODO: This might need more sophisticated handling for multi-oracle scenarios
|
|
1093
|
+
if (multiOracleInfo.announcements.length === 0) {
|
|
1094
|
+
throw Error('MultiOracleInfo must have at least one announcement');
|
|
1095
|
+
}
|
|
1096
|
+
oracleEvent = multiOracleInfo.announcements[0].oracleEvent;
|
|
1097
|
+
} else {
|
|
1098
|
+
throw Error(
|
|
1099
|
+
`OracleInfo must be SingleOracleInfo or MultiOracleInfo, got type: ${oracleInfo.type}`,
|
|
1100
|
+
);
|
|
1101
|
+
}
|
|
824
1102
|
|
|
825
1103
|
switch (oracleEvent.eventDescriptor.type) {
|
|
826
|
-
case MessageType.
|
|
1104
|
+
case MessageType.EnumEventDescriptor:
|
|
827
1105
|
return this.GenerateEnumMessages(oracleEvent);
|
|
828
|
-
case MessageType.
|
|
1106
|
+
case MessageType.DigitDecompositionEventDescriptor:
|
|
829
1107
|
return this.GenerateDigitDecompositionMessages(oracleEvent);
|
|
830
1108
|
default:
|
|
831
1109
|
throw Error('EventDescriptor must be Enum or DigitDecomposition');
|
|
@@ -834,23 +1112,35 @@ export default class BitcoinDlcProvider
|
|
|
834
1112
|
|
|
835
1113
|
private GetContractOraclePairs(
|
|
836
1114
|
_contractInfo: ContractInfo,
|
|
837
|
-
): { contractDescriptor: ContractDescriptor; oracleInfo:
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
1115
|
+
): { contractDescriptor: ContractDescriptor; oracleInfo: OracleInfo }[] {
|
|
1116
|
+
// Use contractInfoType property instead of instanceof for more reliable type checking
|
|
1117
|
+
if (_contractInfo.contractInfoType === ContractInfoType.Single) {
|
|
1118
|
+
const singleInfo = _contractInfo as SingleContractInfo;
|
|
1119
|
+
return [
|
|
1120
|
+
{
|
|
1121
|
+
contractDescriptor: singleInfo.contractDescriptor,
|
|
1122
|
+
oracleInfo: singleInfo.oracleInfo,
|
|
1123
|
+
},
|
|
1124
|
+
];
|
|
1125
|
+
} else if (_contractInfo.contractInfoType === ContractInfoType.Disjoint) {
|
|
1126
|
+
const disjointInfo = _contractInfo as DisjointContractInfo;
|
|
1127
|
+
return disjointInfo.contractOraclePairs;
|
|
1128
|
+
} else {
|
|
1129
|
+
throw Error('ContractInfo must be Single or Disjoint');
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
|
|
1133
|
+
private getFundOutputValueSats(dlcTxs: DlcTransactions): bigint {
|
|
1134
|
+
const fundOutput = dlcTxs.fundTx.outputs[dlcTxs.fundTxVout];
|
|
1135
|
+
if (!fundOutput || !fundOutput.value) {
|
|
1136
|
+
throw new Error(
|
|
1137
|
+
`Invalid fund output at vout ${dlcTxs.fundTxVout}: ` +
|
|
1138
|
+
`outputs.length=${dlcTxs.fundTx.outputs.length}, ` +
|
|
1139
|
+
`output exists=${!!fundOutput}, ` +
|
|
1140
|
+
`output.value exists=${!!(fundOutput && fundOutput.value)}`,
|
|
1141
|
+
);
|
|
853
1142
|
}
|
|
1143
|
+
return fundOutput.value.sats;
|
|
854
1144
|
}
|
|
855
1145
|
|
|
856
1146
|
private async CreateCetAdaptorAndRefundSigs(
|
|
@@ -870,7 +1160,7 @@ export default class BitcoinDlcProvider
|
|
|
870
1160
|
const cetsHex = dlcTxs.cets.map((cet) => cet.serialize().toString('hex'));
|
|
871
1161
|
|
|
872
1162
|
const fundingSPK = Script.p2wpkhLock(
|
|
873
|
-
hash160(isOfferer ? dlcOffer.
|
|
1163
|
+
hash160(isOfferer ? dlcOffer.fundingPubkey : dlcAccept.fundingPubkey),
|
|
874
1164
|
)
|
|
875
1165
|
.serialize()
|
|
876
1166
|
.slice(1);
|
|
@@ -894,12 +1184,16 @@ export default class BitcoinDlcProvider
|
|
|
894
1184
|
const sigs: ISig[][] = [];
|
|
895
1185
|
|
|
896
1186
|
if (
|
|
897
|
-
dlcOffer.contractInfo.
|
|
898
|
-
(dlcOffer.contractInfo as
|
|
1187
|
+
dlcOffer.contractInfo.contractInfoType === ContractInfoType.Single &&
|
|
1188
|
+
(dlcOffer.contractInfo as SingleContractInfo).contractDescriptor.type ===
|
|
899
1189
|
MessageType.ContractDescriptorV0
|
|
900
1190
|
) {
|
|
901
|
-
for (const
|
|
902
|
-
|
|
1191
|
+
for (const { oracleInfo } of contractOraclePairs) {
|
|
1192
|
+
if (oracleInfo.type !== MessageType.SingleOracleInfo) {
|
|
1193
|
+
throw new Error('Only SingleOracleInfo supported in this context');
|
|
1194
|
+
}
|
|
1195
|
+
const oracleAnnouncement = (oracleInfo as SingleOracleInfo)
|
|
1196
|
+
.announcement;
|
|
903
1197
|
|
|
904
1198
|
const adaptorSigRequestPromises: Promise<AdaptorPair[]>[] = [];
|
|
905
1199
|
|
|
@@ -912,9 +1206,9 @@ export default class BitcoinDlcProvider
|
|
|
912
1206
|
privkey: fundPrivateKey,
|
|
913
1207
|
fundTxId: dlcTxs.fundTx.txId.toString(),
|
|
914
1208
|
fundVout: dlcTxs.fundTxVout,
|
|
915
|
-
localFundPubkey: dlcOffer.
|
|
916
|
-
remoteFundPubkey: dlcAccept.
|
|
917
|
-
fundInputAmount:
|
|
1209
|
+
localFundPubkey: dlcOffer.fundingPubkey.toString('hex'),
|
|
1210
|
+
remoteFundPubkey: dlcAccept.fundingPubkey.toString('hex'),
|
|
1211
|
+
fundInputAmount: this.getFundOutputValueSats(dlcTxs),
|
|
918
1212
|
oraclePubkey: oracleAnnouncement.oraclePubkey.toString('hex'),
|
|
919
1213
|
oracleRValues: oracleAnnouncement.oracleEvent.oracleNonces.map(
|
|
920
1214
|
(nonce) => nonce.toString('hex'),
|
|
@@ -923,9 +1217,8 @@ export default class BitcoinDlcProvider
|
|
|
923
1217
|
|
|
924
1218
|
adaptorSigRequestPromises.push(
|
|
925
1219
|
(async () => {
|
|
926
|
-
const response =
|
|
927
|
-
cetSignRequest
|
|
928
|
-
);
|
|
1220
|
+
const response =
|
|
1221
|
+
await this.CreateCetAdaptorSignatures(cetSignRequest);
|
|
929
1222
|
return response.adaptorPairs;
|
|
930
1223
|
})(),
|
|
931
1224
|
);
|
|
@@ -947,7 +1240,11 @@ export default class BitcoinDlcProvider
|
|
|
947
1240
|
const indices = this.GetIndicesFromPayouts(this.GetPayouts(_dlcOffer));
|
|
948
1241
|
|
|
949
1242
|
for (const [index, { oracleInfo }] of contractOraclePairs.entries()) {
|
|
950
|
-
|
|
1243
|
+
if (oracleInfo.type !== MessageType.SingleOracleInfo) {
|
|
1244
|
+
throw new Error('Only SingleOracleInfo supported in this context');
|
|
1245
|
+
}
|
|
1246
|
+
const oracleAnnouncement = (oracleInfo as SingleOracleInfo)
|
|
1247
|
+
.announcement;
|
|
951
1248
|
|
|
952
1249
|
const startingIndex = indices[index].startingMessagesIndex,
|
|
953
1250
|
endingIndex = indices[index + 1].startingMessagesIndex;
|
|
@@ -971,10 +1268,9 @@ export default class BitcoinDlcProvider
|
|
|
971
1268
|
privkey: fundPrivateKey,
|
|
972
1269
|
fundTxId: dlcTxs.fundTx.txId.toString(),
|
|
973
1270
|
fundVout: dlcTxs.fundTxVout,
|
|
974
|
-
localFundPubkey: dlcOffer.
|
|
975
|
-
remoteFundPubkey: dlcAccept.
|
|
976
|
-
fundInputAmount:
|
|
977
|
-
dlcTxs.fundTx.outputs[dlcTxs.fundTxVout].value.sats,
|
|
1271
|
+
localFundPubkey: dlcOffer.fundingPubkey.toString('hex'),
|
|
1272
|
+
remoteFundPubkey: dlcAccept.fundingPubkey.toString('hex'),
|
|
1273
|
+
fundInputAmount: this.getFundOutputValueSats(dlcTxs),
|
|
978
1274
|
oraclePubkey: oracleAnnouncement.oraclePubkey.toString('hex'),
|
|
979
1275
|
oracleRValues: oracleAnnouncement.oracleEvent.oracleNonces.map(
|
|
980
1276
|
(nonce) => nonce.toString('hex'),
|
|
@@ -983,9 +1279,8 @@ export default class BitcoinDlcProvider
|
|
|
983
1279
|
|
|
984
1280
|
adaptorSigRequestPromises.push(
|
|
985
1281
|
(async () => {
|
|
986
|
-
const response =
|
|
987
|
-
cetSignRequest
|
|
988
|
-
);
|
|
1282
|
+
const response =
|
|
1283
|
+
await this.CreateCetAdaptorSignatures(cetSignRequest);
|
|
989
1284
|
return response.adaptorPairs;
|
|
990
1285
|
})(),
|
|
991
1286
|
);
|
|
@@ -1011,9 +1306,9 @@ export default class BitcoinDlcProvider
|
|
|
1011
1306
|
privkey: fundPrivateKey,
|
|
1012
1307
|
fundTxId: dlcTxs.fundTx.txId.toString(),
|
|
1013
1308
|
fundVout: dlcTxs.fundTxVout,
|
|
1014
|
-
localFundPubkey: dlcOffer.
|
|
1015
|
-
remoteFundPubkey: dlcAccept.
|
|
1016
|
-
fundInputAmount:
|
|
1309
|
+
localFundPubkey: dlcOffer.fundingPubkey.toString('hex'),
|
|
1310
|
+
remoteFundPubkey: dlcAccept.fundingPubkey.toString('hex'),
|
|
1311
|
+
fundInputAmount: this.getFundOutputValueSats(dlcTxs),
|
|
1017
1312
|
};
|
|
1018
1313
|
|
|
1019
1314
|
const refundSignature = Buffer.from(
|
|
@@ -1021,7 +1316,7 @@ export default class BitcoinDlcProvider
|
|
|
1021
1316
|
'hex',
|
|
1022
1317
|
);
|
|
1023
1318
|
|
|
1024
|
-
const cetSignatures = new
|
|
1319
|
+
const cetSignatures = new CetAdaptorSignatures();
|
|
1025
1320
|
cetSignatures.sigs = sigs.flat();
|
|
1026
1321
|
|
|
1027
1322
|
return { cetSignatures, refundSignature };
|
|
@@ -1049,17 +1344,21 @@ export default class BitcoinDlcProvider
|
|
|
1049
1344
|
);
|
|
1050
1345
|
|
|
1051
1346
|
if (
|
|
1052
|
-
dlcOffer.contractInfo.type === MessageType.
|
|
1053
|
-
(dlcOffer.contractInfo as
|
|
1347
|
+
dlcOffer.contractInfo.type === MessageType.SingleContractInfo &&
|
|
1348
|
+
(dlcOffer.contractInfo as SingleContractInfo).contractDescriptor.type ===
|
|
1054
1349
|
MessageType.ContractDescriptorV0
|
|
1055
1350
|
) {
|
|
1056
|
-
for (const
|
|
1057
|
-
|
|
1351
|
+
for (const { oracleInfo } of contractOraclePairs) {
|
|
1352
|
+
if (oracleInfo.type !== MessageType.SingleOracleInfo) {
|
|
1353
|
+
throw new Error('Only SingleOracleInfo supported in this context');
|
|
1354
|
+
}
|
|
1355
|
+
const oracleAnnouncement = (oracleInfo as SingleOracleInfo)
|
|
1356
|
+
.announcement;
|
|
1058
1357
|
|
|
1059
1358
|
const oracleEventCetsHex = cetsHex;
|
|
1060
1359
|
const oracleEventSigs = isOfferer
|
|
1061
|
-
? dlcAccept.
|
|
1062
|
-
: dlcSign.
|
|
1360
|
+
? dlcAccept.cetAdaptorSignatures.sigs
|
|
1361
|
+
: dlcSign.cetAdaptorSignatures.sigs;
|
|
1063
1362
|
|
|
1064
1363
|
const sigsValidity: Promise<boolean>[] = [];
|
|
1065
1364
|
|
|
@@ -1073,21 +1372,22 @@ export default class BitcoinDlcProvider
|
|
|
1073
1372
|
};
|
|
1074
1373
|
});
|
|
1075
1374
|
|
|
1076
|
-
const verifyCetAdaptorSignaturesRequest: VerifyCetAdaptorSignaturesRequest =
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1375
|
+
const verifyCetAdaptorSignaturesRequest: VerifyCetAdaptorSignaturesRequest =
|
|
1376
|
+
{
|
|
1377
|
+
cetsHex: tempCetsHex,
|
|
1378
|
+
messagesList: tempMessagesList,
|
|
1379
|
+
oraclePubkey: oracleAnnouncement.oraclePubkey.toString('hex'),
|
|
1380
|
+
oracleRValues: oracleAnnouncement.oracleEvent.oracleNonces.map(
|
|
1381
|
+
(nonce) => nonce.toString('hex'),
|
|
1382
|
+
),
|
|
1383
|
+
adaptorPairs: tempAdaptorPairs,
|
|
1384
|
+
localFundPubkey: dlcOffer.fundingPubkey.toString('hex'),
|
|
1385
|
+
remoteFundPubkey: dlcAccept.fundingPubkey.toString('hex'),
|
|
1386
|
+
fundTxId: dlcTxs.fundTx.txId.toString(),
|
|
1387
|
+
fundVout: dlcTxs.fundTxVout,
|
|
1388
|
+
fundInputAmount: this.getFundOutputValueSats(dlcTxs),
|
|
1389
|
+
verifyRemote: isOfferer,
|
|
1390
|
+
};
|
|
1091
1391
|
|
|
1092
1392
|
sigsValidity.push(
|
|
1093
1393
|
(async () => {
|
|
@@ -1105,11 +1405,11 @@ export default class BitcoinDlcProvider
|
|
|
1105
1405
|
signature: isOfferer
|
|
1106
1406
|
? dlcAccept.refundSignature.toString('hex')
|
|
1107
1407
|
: dlcSign.refundSignature.toString('hex'),
|
|
1108
|
-
localFundPubkey: dlcOffer.
|
|
1109
|
-
remoteFundPubkey: dlcAccept.
|
|
1408
|
+
localFundPubkey: dlcOffer.fundingPubkey.toString('hex'),
|
|
1409
|
+
remoteFundPubkey: dlcAccept.fundingPubkey.toString('hex'),
|
|
1110
1410
|
fundTxId: dlcTxs.fundTx.txId.toString(),
|
|
1111
1411
|
fundVout: dlcTxs.fundTxVout,
|
|
1112
|
-
fundInputAmount:
|
|
1412
|
+
fundInputAmount: this.getFundOutputValueSats(dlcTxs),
|
|
1113
1413
|
verifyRemote: isOfferer,
|
|
1114
1414
|
};
|
|
1115
1415
|
|
|
@@ -1127,7 +1427,11 @@ export default class BitcoinDlcProvider
|
|
|
1127
1427
|
const indices = this.GetIndicesFromPayouts(this.GetPayouts(_dlcOffer));
|
|
1128
1428
|
|
|
1129
1429
|
for (const [index, { oracleInfo }] of contractOraclePairs.entries()) {
|
|
1130
|
-
|
|
1430
|
+
if (oracleInfo.type !== MessageType.SingleOracleInfo) {
|
|
1431
|
+
throw new Error('Only SingleOracleInfo supported in this context');
|
|
1432
|
+
}
|
|
1433
|
+
const oracleAnnouncement = (oracleInfo as SingleOracleInfo)
|
|
1434
|
+
.announcement;
|
|
1131
1435
|
|
|
1132
1436
|
const startingIndex = indices[index].startingMessagesIndex,
|
|
1133
1437
|
endingIndex = indices[index + 1].startingMessagesIndex;
|
|
@@ -1137,9 +1441,10 @@ export default class BitcoinDlcProvider
|
|
|
1137
1441
|
endingIndex,
|
|
1138
1442
|
);
|
|
1139
1443
|
const oracleEventCetsHex = cetsHex.slice(startingIndex, endingIndex);
|
|
1140
|
-
const oracleEventSigs = (
|
|
1141
|
-
|
|
1142
|
-
|
|
1444
|
+
const oracleEventSigs = (
|
|
1445
|
+
isOfferer
|
|
1446
|
+
? dlcAccept.cetAdaptorSignatures.sigs
|
|
1447
|
+
: dlcSign.cetAdaptorSignatures.sigs
|
|
1143
1448
|
).slice(startingIndex, endingIndex);
|
|
1144
1449
|
|
|
1145
1450
|
const sigsValidity: Promise<boolean>[] = [];
|
|
@@ -1155,22 +1460,22 @@ export default class BitcoinDlcProvider
|
|
|
1155
1460
|
};
|
|
1156
1461
|
});
|
|
1157
1462
|
|
|
1158
|
-
const verifyCetAdaptorSignaturesRequest: VerifyCetAdaptorSignaturesRequest =
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1463
|
+
const verifyCetAdaptorSignaturesRequest: VerifyCetAdaptorSignaturesRequest =
|
|
1464
|
+
{
|
|
1465
|
+
cetsHex: tempCetsHex,
|
|
1466
|
+
messagesList: tempMessagesList,
|
|
1467
|
+
oraclePubkey: oracleAnnouncement.oraclePubkey.toString('hex'),
|
|
1468
|
+
oracleRValues: oracleAnnouncement.oracleEvent.oracleNonces.map(
|
|
1469
|
+
(nonce) => nonce.toString('hex'),
|
|
1470
|
+
),
|
|
1471
|
+
adaptorPairs: tempAdaptorPairs,
|
|
1472
|
+
localFundPubkey: dlcOffer.fundingPubkey.toString('hex'),
|
|
1473
|
+
remoteFundPubkey: dlcAccept.fundingPubkey.toString('hex'),
|
|
1474
|
+
fundTxId: dlcTxs.fundTx.txId.toString(),
|
|
1475
|
+
fundVout: dlcTxs.fundTxVout,
|
|
1476
|
+
fundInputAmount: this.getFundOutputValueSats(dlcTxs),
|
|
1477
|
+
verifyRemote: isOfferer,
|
|
1478
|
+
};
|
|
1174
1479
|
|
|
1175
1480
|
sigsValidity.push(
|
|
1176
1481
|
(async () => {
|
|
@@ -1189,11 +1494,11 @@ export default class BitcoinDlcProvider
|
|
|
1189
1494
|
signature: isOfferer
|
|
1190
1495
|
? dlcAccept.refundSignature.toString('hex')
|
|
1191
1496
|
: dlcSign.refundSignature.toString('hex'),
|
|
1192
|
-
localFundPubkey: dlcOffer.
|
|
1193
|
-
remoteFundPubkey: dlcAccept.
|
|
1497
|
+
localFundPubkey: dlcOffer.fundingPubkey.toString('hex'),
|
|
1498
|
+
remoteFundPubkey: dlcAccept.fundingPubkey.toString('hex'),
|
|
1194
1499
|
fundTxId: dlcTxs.fundTx.txId.toString(),
|
|
1195
1500
|
fundVout: dlcTxs.fundTxVout,
|
|
1196
|
-
fundInputAmount:
|
|
1501
|
+
fundInputAmount: this.getFundOutputValueSats(dlcTxs),
|
|
1197
1502
|
verifyRemote: isOfferer,
|
|
1198
1503
|
};
|
|
1199
1504
|
|
|
@@ -1213,7 +1518,7 @@ export default class BitcoinDlcProvider
|
|
|
1213
1518
|
_dlcAccept: DlcAccept,
|
|
1214
1519
|
_dlcTxs: DlcTransactions,
|
|
1215
1520
|
isOfferer: boolean,
|
|
1216
|
-
): Promise<
|
|
1521
|
+
): Promise<FundingSignatures> {
|
|
1217
1522
|
const { dlcOffer, dlcAccept, dlcTxs } = checkTypes({
|
|
1218
1523
|
_dlcOffer,
|
|
1219
1524
|
_dlcAccept,
|
|
@@ -1234,15 +1539,34 @@ export default class BitcoinDlcProvider
|
|
|
1234
1539
|
|
|
1235
1540
|
const fundTxSigs = await Promise.all(
|
|
1236
1541
|
inputs.map(async (input, index) => {
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1542
|
+
// Use DLC-specific signing for DLC inputs
|
|
1543
|
+
if (input.isDlcInput()) {
|
|
1544
|
+
const dlcInputInfo = input.dlcInput!;
|
|
1545
|
+
|
|
1546
|
+
const dlcSignRequest: GetRawDlcFundingInputSignatureRequest = {
|
|
1547
|
+
fundTxHex: dlcTxs.fundTx.serialize().toString('hex'),
|
|
1548
|
+
fundTxid: input.txid,
|
|
1549
|
+
fundVout: input.vout,
|
|
1550
|
+
fundAmount: input.value,
|
|
1551
|
+
localFundPubkey: dlcInputInfo.localFundPubkey,
|
|
1552
|
+
remoteFundPubkey: dlcInputInfo.remoteFundPubkey,
|
|
1553
|
+
privkey: inputPrivKeys[index],
|
|
1554
|
+
};
|
|
1555
|
+
|
|
1556
|
+
return (await this.GetRawDlcFundingInputSignature(dlcSignRequest))
|
|
1557
|
+
.hex;
|
|
1558
|
+
} else {
|
|
1559
|
+
// Use regular signing for non-DLC inputs
|
|
1560
|
+
const fundTxSignRequest: GetRawFundTxSignatureRequest = {
|
|
1561
|
+
fundTxHex: dlcTxs.fundTx.serialize().toString('hex'),
|
|
1562
|
+
privkey: inputPrivKeys[index],
|
|
1563
|
+
prevTxId: input.txid,
|
|
1564
|
+
prevVout: input.vout,
|
|
1565
|
+
amount: input.value,
|
|
1566
|
+
};
|
|
1244
1567
|
|
|
1245
|
-
|
|
1568
|
+
return (await this.GetRawFundTxSignature(fundTxSignRequest)).hex;
|
|
1569
|
+
}
|
|
1246
1570
|
}),
|
|
1247
1571
|
);
|
|
1248
1572
|
|
|
@@ -1267,26 +1591,19 @@ export default class BitcoinDlcProvider
|
|
|
1267
1591
|
witnessElements.push([sigWitness, pubKeyWitness]);
|
|
1268
1592
|
}
|
|
1269
1593
|
|
|
1270
|
-
const fundingSignatures = new
|
|
1594
|
+
const fundingSignatures = new FundingSignatures();
|
|
1271
1595
|
fundingSignatures.witnessElements = witnessElements;
|
|
1272
1596
|
|
|
1273
1597
|
return fundingSignatures;
|
|
1274
1598
|
}
|
|
1275
1599
|
|
|
1276
1600
|
private async VerifyFundingSigs(
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1601
|
+
dlcOffer: DlcOffer,
|
|
1602
|
+
dlcAccept: DlcAccept,
|
|
1603
|
+
dlcSign: DlcSign,
|
|
1604
|
+
dlcTxs: DlcTransactions,
|
|
1281
1605
|
isOfferer: boolean,
|
|
1282
1606
|
): Promise<void> {
|
|
1283
|
-
const { dlcOffer, dlcAccept, dlcSign, dlcTxs } = checkTypes({
|
|
1284
|
-
_dlcOffer,
|
|
1285
|
-
_dlcAccept,
|
|
1286
|
-
_dlcSign,
|
|
1287
|
-
_dlcTxs,
|
|
1288
|
-
});
|
|
1289
|
-
|
|
1290
1607
|
const sigsValidity: Promise<boolean>[] = [];
|
|
1291
1608
|
for (let i = 0; i < dlcSign.fundingSignatures.witnessElements.length; i++) {
|
|
1292
1609
|
const witnessElement = dlcSign.fundingSignatures.witnessElements[i];
|
|
@@ -1294,27 +1611,52 @@ export default class BitcoinDlcProvider
|
|
|
1294
1611
|
const pubkey = witnessElement[1].witness.toString('hex');
|
|
1295
1612
|
|
|
1296
1613
|
const fundingInput = isOfferer
|
|
1297
|
-
? (dlcAccept.fundingInputs[i] as
|
|
1298
|
-
: (dlcOffer.fundingInputs[i] as
|
|
1299
|
-
|
|
1300
|
-
const verifyFundSigRequest: VerifyFundTxSignatureRequest = {
|
|
1301
|
-
fundTxHex: dlcTxs.fundTx.serialize().toString('hex'),
|
|
1302
|
-
signature,
|
|
1303
|
-
pubkey,
|
|
1304
|
-
prevTxId: fundingInput.prevTx.txId.toString(),
|
|
1305
|
-
prevVout: fundingInput.prevTxVout,
|
|
1306
|
-
fundInputAmount:
|
|
1307
|
-
fundingInput.prevTx.outputs[fundingInput.prevTxVout].value.sats,
|
|
1308
|
-
};
|
|
1614
|
+
? (dlcAccept.fundingInputs[i] as FundingInput)
|
|
1615
|
+
: (dlcOffer.fundingInputs[i] as FundingInput);
|
|
1309
1616
|
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
)
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1617
|
+
// Check if this is a DLC input and use appropriate verification
|
|
1618
|
+
if (fundingInput.dlcInput) {
|
|
1619
|
+
const dlcInput = fundingInput.dlcInput;
|
|
1620
|
+
const verifyDlcSigRequest: VerifyDlcFundingInputSignatureRequest = {
|
|
1621
|
+
fundTxHex: dlcTxs.fundTx.serialize().toString('hex'),
|
|
1622
|
+
fundTxid: fundingInput.prevTx.txId.toString(),
|
|
1623
|
+
fundVout: fundingInput.prevTxVout,
|
|
1624
|
+
fundAmount: Number(
|
|
1625
|
+
fundingInput.prevTx.outputs[fundingInput.prevTxVout].value.sats,
|
|
1626
|
+
),
|
|
1627
|
+
localFundPubkey: dlcInput.localFundPubkey.toString('hex'),
|
|
1628
|
+
remoteFundPubkey: dlcInput.remoteFundPubkey.toString('hex'),
|
|
1629
|
+
signature,
|
|
1630
|
+
pubkey,
|
|
1631
|
+
};
|
|
1632
|
+
|
|
1633
|
+
sigsValidity.push(
|
|
1634
|
+
(async () => {
|
|
1635
|
+
const response =
|
|
1636
|
+
await this.VerifyDlcFundingInputSignature(verifyDlcSigRequest);
|
|
1637
|
+
return response.valid;
|
|
1638
|
+
})(),
|
|
1639
|
+
);
|
|
1640
|
+
} else {
|
|
1641
|
+
// Regular input verification
|
|
1642
|
+
const verifyFundSigRequest: VerifyFundTxSignatureRequest = {
|
|
1643
|
+
fundTxHex: dlcTxs.fundTx.serialize().toString('hex'),
|
|
1644
|
+
signature,
|
|
1645
|
+
pubkey,
|
|
1646
|
+
prevTxId: fundingInput.prevTx.txId.toString(),
|
|
1647
|
+
prevVout: fundingInput.prevTxVout,
|
|
1648
|
+
fundInputAmount:
|
|
1649
|
+
fundingInput.prevTx.outputs[fundingInput.prevTxVout].value.sats,
|
|
1650
|
+
};
|
|
1651
|
+
|
|
1652
|
+
sigsValidity.push(
|
|
1653
|
+
(async () => {
|
|
1654
|
+
const response =
|
|
1655
|
+
await this.VerifyFundTxSignature(verifyFundSigRequest);
|
|
1656
|
+
return response.valid;
|
|
1657
|
+
})(),
|
|
1658
|
+
);
|
|
1659
|
+
}
|
|
1318
1660
|
}
|
|
1319
1661
|
|
|
1320
1662
|
const areSigsValid = (await Promise.all(sigsValidity)).every((b) => b);
|
|
@@ -1325,19 +1667,12 @@ export default class BitcoinDlcProvider
|
|
|
1325
1667
|
}
|
|
1326
1668
|
|
|
1327
1669
|
private async CreateFundingTx(
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
fundingSignatures:
|
|
1670
|
+
dlcOffer: DlcOffer,
|
|
1671
|
+
dlcAccept: DlcAccept,
|
|
1672
|
+
dlcSign: DlcSign,
|
|
1673
|
+
dlcTxs: DlcTransactions,
|
|
1674
|
+
fundingSignatures: FundingSignatures,
|
|
1333
1675
|
): Promise<Tx> {
|
|
1334
|
-
const { dlcOffer, dlcAccept, dlcSign, dlcTxs } = checkTypes({
|
|
1335
|
-
_dlcOffer,
|
|
1336
|
-
_dlcAccept,
|
|
1337
|
-
_dlcSign,
|
|
1338
|
-
_dlcTxs,
|
|
1339
|
-
});
|
|
1340
|
-
|
|
1341
1676
|
const witnessElements = [
|
|
1342
1677
|
...dlcSign.fundingSignatures.witnessElements,
|
|
1343
1678
|
...fundingSignatures.witnessElements,
|
|
@@ -1349,23 +1684,59 @@ export default class BitcoinDlcProvider
|
|
|
1349
1684
|
|
|
1350
1685
|
let fundTxHex = dlcTxs.fundTx.serialize().toString('hex');
|
|
1351
1686
|
|
|
1687
|
+
// Track processed DLC inputs to avoid double processing
|
|
1688
|
+
const processedDlcInputs = new Set<string>();
|
|
1689
|
+
|
|
1352
1690
|
await asyncForEach(
|
|
1353
1691
|
witnessElements,
|
|
1354
1692
|
async (witnessElement: ScriptWitnessV0, i: number) => {
|
|
1355
1693
|
const signature = witnessElement[0].witness.toString('hex');
|
|
1356
1694
|
const pubkey = witnessElement[1].witness.toString('hex');
|
|
1357
1695
|
|
|
1358
|
-
const fundingInput = fundingInputs[i] as
|
|
1696
|
+
const fundingInput = fundingInputs[i] as FundingInput;
|
|
1697
|
+
const inputKey = `${fundingInput.prevTx.txId.toString()}:${fundingInput.prevTxVout}`;
|
|
1359
1698
|
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1699
|
+
// Check if this is a DLC input
|
|
1700
|
+
if (fundingInput.dlcInput && !processedDlcInputs.has(inputKey)) {
|
|
1701
|
+
// Mark as processed to avoid double processing
|
|
1702
|
+
processedDlcInputs.add(inputKey);
|
|
1703
|
+
|
|
1704
|
+
// For DLC inputs, use SignDlcFundingInput which properly combines signatures
|
|
1705
|
+
// This is the correct CFD method for DLC funding inputs
|
|
1706
|
+
const dlcInput = fundingInput.dlcInput;
|
|
1707
|
+
|
|
1708
|
+
// Find the private key for this DLC input
|
|
1709
|
+
const privateKey = await this.findDlcFundingPrivateKey(
|
|
1710
|
+
dlcInput.localFundPubkey.toString('hex'),
|
|
1711
|
+
dlcInput.remoteFundPubkey.toString('hex'),
|
|
1712
|
+
);
|
|
1713
|
+
|
|
1714
|
+
const signDlcRequest: SignDlcFundingInputRequest = {
|
|
1715
|
+
fundTxHex,
|
|
1716
|
+
fundTxid: fundingInput.prevTx.txId.toString(),
|
|
1717
|
+
fundVout: fundingInput.prevTxVout,
|
|
1718
|
+
fundAmount: Number(
|
|
1719
|
+
fundingInput.prevTx.outputs[fundingInput.prevTxVout].value.sats,
|
|
1720
|
+
),
|
|
1721
|
+
localFundPubkey: dlcInput.localFundPubkey.toString('hex'),
|
|
1722
|
+
remoteFundPubkey: dlcInput.remoteFundPubkey.toString('hex'),
|
|
1723
|
+
localPrivkey: privateKey,
|
|
1724
|
+
remoteSignature: signature,
|
|
1725
|
+
};
|
|
1726
|
+
fundTxHex = (await this.SignDlcFundingInput(signDlcRequest)).hex;
|
|
1727
|
+
} else if (!fundingInput.dlcInput) {
|
|
1728
|
+
// Regular input - use standard signing
|
|
1729
|
+
const addSignRequest: AddSignatureToFundTransactionRequest = {
|
|
1730
|
+
fundTxHex,
|
|
1731
|
+
signature,
|
|
1732
|
+
prevTxId: fundingInput.prevTx.txId.toString(),
|
|
1733
|
+
prevVout: fundingInput.prevTxVout,
|
|
1734
|
+
pubkey,
|
|
1735
|
+
};
|
|
1736
|
+
fundTxHex = (await this.AddSignatureToFundTransaction(addSignRequest))
|
|
1737
|
+
.hex;
|
|
1738
|
+
}
|
|
1739
|
+
// If it's a DLC input but already processed, skip it
|
|
1369
1740
|
},
|
|
1370
1741
|
);
|
|
1371
1742
|
|
|
@@ -1375,15 +1746,13 @@ export default class BitcoinDlcProvider
|
|
|
1375
1746
|
}
|
|
1376
1747
|
|
|
1377
1748
|
async FindOutcomeIndexFromPolynomialPayoutCurvePiece(
|
|
1378
|
-
|
|
1379
|
-
contractDescriptor:
|
|
1749
|
+
dlcOffer: DlcOffer,
|
|
1750
|
+
contractDescriptor: NumericalDescriptor,
|
|
1380
1751
|
contractOraclePairIndex: number,
|
|
1381
1752
|
polynomialPayoutCurvePiece: PolynomialPayoutCurvePiece,
|
|
1382
|
-
oracleAttestation:
|
|
1753
|
+
oracleAttestation: OracleAttestation,
|
|
1383
1754
|
outcome: bigint,
|
|
1384
1755
|
): Promise<FindOutcomeResponse> {
|
|
1385
|
-
const { dlcOffer } = checkTypes({ _dlcOffer });
|
|
1386
|
-
|
|
1387
1756
|
const polynomialCurve = PolynomialPayoutCurve.fromPayoutCurvePiece(
|
|
1388
1757
|
polynomialPayoutCurvePiece,
|
|
1389
1758
|
);
|
|
@@ -1400,9 +1769,9 @@ export default class BitcoinDlcProvider
|
|
|
1400
1769
|
const payout = clampBN(polynomialCurve.getPayout(outcome));
|
|
1401
1770
|
|
|
1402
1771
|
const payoutResponses = this.GetPayouts(dlcOffer);
|
|
1403
|
-
const payoutIndexOffset =
|
|
1404
|
-
contractOraclePairIndex
|
|
1405
|
-
|
|
1772
|
+
const payoutIndexOffset =
|
|
1773
|
+
this.GetIndicesFromPayouts(payoutResponses)[contractOraclePairIndex]
|
|
1774
|
+
.startingMessagesIndex;
|
|
1406
1775
|
|
|
1407
1776
|
const { payoutGroups } = payoutResponses[contractOraclePairIndex];
|
|
1408
1777
|
|
|
@@ -1457,10 +1826,10 @@ Payout Group not found',
|
|
|
1457
1826
|
|
|
1458
1827
|
async FindOutcomeIndexFromHyperbolaPayoutCurvePiece(
|
|
1459
1828
|
_dlcOffer: DlcOffer,
|
|
1460
|
-
contractDescriptor:
|
|
1829
|
+
contractDescriptor: NumericalDescriptor,
|
|
1461
1830
|
contractOraclePairIndex: number,
|
|
1462
1831
|
hyperbolaPayoutCurvePiece: HyperbolaPayoutCurvePiece,
|
|
1463
|
-
oracleAttestation:
|
|
1832
|
+
oracleAttestation: OracleAttestation,
|
|
1464
1833
|
outcome: bigint,
|
|
1465
1834
|
): Promise<FindOutcomeResponse> {
|
|
1466
1835
|
const { dlcOffer } = checkTypes({ _dlcOffer });
|
|
@@ -1478,9 +1847,9 @@ Payout Group not found',
|
|
|
1478
1847
|
const payout = clampBN(hyperbolaCurve.getPayout(outcome));
|
|
1479
1848
|
|
|
1480
1849
|
const payoutResponses = this.GetPayouts(dlcOffer);
|
|
1481
|
-
const payoutIndexOffset =
|
|
1482
|
-
contractOraclePairIndex
|
|
1483
|
-
|
|
1850
|
+
const payoutIndexOffset =
|
|
1851
|
+
this.GetIndicesFromPayouts(payoutResponses)[contractOraclePairIndex]
|
|
1852
|
+
.startingMessagesIndex;
|
|
1484
1853
|
|
|
1485
1854
|
const { payoutGroups } = payoutResponses[contractOraclePairIndex];
|
|
1486
1855
|
|
|
@@ -1541,31 +1910,52 @@ Payout Group not found',
|
|
|
1541
1910
|
}
|
|
1542
1911
|
|
|
1543
1912
|
if (groupIndex === -1) {
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1913
|
+
// Fallback to brute force search if payout-based search fails
|
|
1914
|
+
index = 0;
|
|
1915
|
+
groupLength = 0;
|
|
1916
|
+
|
|
1917
|
+
for (const [, payoutGroup] of payoutGroups.entries()) {
|
|
1918
|
+
groupIndex = payoutGroup.groups.findIndex((group) => {
|
|
1919
|
+
return group.every((msg, j) => msg === outcomesFormatted[j]);
|
|
1920
|
+
});
|
|
1921
|
+
|
|
1922
|
+
if (groupIndex !== -1) {
|
|
1923
|
+
index += groupIndex;
|
|
1924
|
+
groupLength = payoutGroup.groups[groupIndex].length;
|
|
1925
|
+
break;
|
|
1926
|
+
} else {
|
|
1927
|
+
index += payoutGroup.groups.length;
|
|
1928
|
+
}
|
|
1929
|
+
}
|
|
1930
|
+
|
|
1931
|
+
if (groupIndex === -1) {
|
|
1932
|
+
throw Error(
|
|
1933
|
+
'Failed to Find OutcomeIndex From HyperbolaPayoutCurvePiece. \
|
|
1934
|
+
Payout Group not found even with brute force search',
|
|
1935
|
+
);
|
|
1936
|
+
}
|
|
1548
1937
|
}
|
|
1549
1938
|
|
|
1550
1939
|
return { index: payoutIndexOffset + index, groupLength };
|
|
1551
1940
|
}
|
|
1552
1941
|
|
|
1553
1942
|
async FindOutcomeIndex(
|
|
1554
|
-
|
|
1555
|
-
oracleAttestation:
|
|
1943
|
+
dlcOffer: DlcOffer,
|
|
1944
|
+
oracleAttestation: OracleAttestation,
|
|
1556
1945
|
): Promise<FindOutcomeResponse> {
|
|
1557
|
-
const { dlcOffer } = checkTypes({ _dlcOffer });
|
|
1558
|
-
|
|
1559
1946
|
const contractOraclePairs = this.GetContractOraclePairs(
|
|
1560
1947
|
dlcOffer.contractInfo,
|
|
1561
1948
|
);
|
|
1562
|
-
|
|
1563
1949
|
const contractOraclePairIndex = contractOraclePairs.findIndex(
|
|
1564
|
-
({ oracleInfo }) =>
|
|
1565
|
-
oracleInfo.
|
|
1566
|
-
|
|
1950
|
+
({ oracleInfo }) => {
|
|
1951
|
+
if (oracleInfo.type !== MessageType.SingleOracleInfo) return false;
|
|
1952
|
+
const singleOracleInfo = oracleInfo as SingleOracleInfo;
|
|
1953
|
+
return (
|
|
1954
|
+
singleOracleInfo.announcement.oracleEvent.eventId ===
|
|
1955
|
+
oracleAttestation.eventId
|
|
1956
|
+
);
|
|
1957
|
+
},
|
|
1567
1958
|
);
|
|
1568
|
-
|
|
1569
1959
|
assert(
|
|
1570
1960
|
contractOraclePairIndex !== -1,
|
|
1571
1961
|
'OracleAttestation must be for an existing OracleEvent',
|
|
@@ -1573,39 +1963,42 @@ Payout Group not found',
|
|
|
1573
1963
|
|
|
1574
1964
|
const contractOraclePair = contractOraclePairs[contractOraclePairIndex];
|
|
1575
1965
|
|
|
1576
|
-
const {
|
|
1577
|
-
|
|
1578
|
-
oracleInfo,
|
|
1579
|
-
} = contractOraclePair;
|
|
1580
|
-
|
|
1966
|
+
const { contractDescriptor: _contractDescriptor, oracleInfo } =
|
|
1967
|
+
contractOraclePair;
|
|
1581
1968
|
assert(
|
|
1582
|
-
_contractDescriptor.
|
|
1583
|
-
|
|
1969
|
+
_contractDescriptor.contractDescriptorType ===
|
|
1970
|
+
ContractDescriptorType.NumericOutcome,
|
|
1971
|
+
'ContractDescriptor must be NumericOutcome',
|
|
1584
1972
|
);
|
|
1585
|
-
|
|
1586
|
-
const contractDescriptor = _contractDescriptor as ContractDescriptorV1;
|
|
1973
|
+
const contractDescriptor = _contractDescriptor as NumericalDescriptor;
|
|
1587
1974
|
const _payoutFunction = contractDescriptor.payoutFunction;
|
|
1588
|
-
|
|
1589
1975
|
assert(
|
|
1590
|
-
_payoutFunction.type === MessageType.
|
|
1976
|
+
_payoutFunction.type === MessageType.PayoutFunction,
|
|
1591
1977
|
'PayoutFunction must be V0',
|
|
1592
1978
|
);
|
|
1593
1979
|
|
|
1594
|
-
|
|
1595
|
-
|
|
1980
|
+
if (oracleInfo.type !== MessageType.SingleOracleInfo) {
|
|
1981
|
+
throw new Error('Only SingleOracleInfo supported in this context');
|
|
1982
|
+
}
|
|
1983
|
+
|
|
1984
|
+
const singleOracleInfo = oracleInfo as SingleOracleInfo;
|
|
1985
|
+
const eventDescriptor = singleOracleInfo.announcement.oracleEvent
|
|
1986
|
+
.eventDescriptor as DigitDecompositionEventDescriptor;
|
|
1596
1987
|
const payoutFunction = _payoutFunction as PayoutFunctionV0;
|
|
1597
1988
|
|
|
1598
1989
|
const base = eventDescriptor.base;
|
|
1599
|
-
|
|
1600
1990
|
const outcome: number = [...oracleAttestation.outcomes]
|
|
1601
1991
|
.reverse()
|
|
1602
1992
|
.reduce((acc, val, i) => acc + Number(val) * base ** i, 0);
|
|
1603
1993
|
|
|
1604
|
-
const piecesSorted = payoutFunction.
|
|
1605
|
-
(a, b) =>
|
|
1994
|
+
const piecesSorted = payoutFunction.payoutFunctionPieces.sort(
|
|
1995
|
+
(a, b) =>
|
|
1996
|
+
Number(a.endPoint.eventOutcome) - Number(b.endPoint.eventOutcome),
|
|
1606
1997
|
);
|
|
1607
1998
|
|
|
1608
|
-
const piece = piecesSorted.find(
|
|
1999
|
+
const piece = piecesSorted.find(
|
|
2000
|
+
(piece) => outcome < piece.endPoint.eventOutcome,
|
|
2001
|
+
);
|
|
1609
2002
|
|
|
1610
2003
|
switch (piece.payoutCurvePiece.type) {
|
|
1611
2004
|
case MessageType.PolynomialPayoutCurvePiece:
|
|
@@ -1641,30 +2034,34 @@ Payout Group not found',
|
|
|
1641
2034
|
}
|
|
1642
2035
|
|
|
1643
2036
|
ValidateEvent(
|
|
1644
|
-
|
|
1645
|
-
oracleAttestation:
|
|
2037
|
+
dlcOffer: DlcOffer,
|
|
2038
|
+
oracleAttestation: OracleAttestation,
|
|
1646
2039
|
): void {
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
case MessageType.ContractInfoV0: {
|
|
1653
|
-
const contractInfo = dlcOffer.contractInfo as ContractInfoV0;
|
|
1654
|
-
switch (contractInfo.contractDescriptor.type) {
|
|
1655
|
-
case MessageType.ContractDescriptorV0: {
|
|
2040
|
+
switch (dlcOffer.contractInfo.contractInfoType) {
|
|
2041
|
+
case ContractInfoType.Single: {
|
|
2042
|
+
const contractInfo = dlcOffer.contractInfo as SingleContractInfo;
|
|
2043
|
+
switch (contractInfo.contractDescriptor.contractDescriptorType) {
|
|
2044
|
+
case ContractDescriptorType.Enumerated: {
|
|
1656
2045
|
const oracleInfo = contractInfo.oracleInfo;
|
|
2046
|
+
if (oracleInfo.type !== MessageType.SingleOracleInfo) {
|
|
2047
|
+
throw Error('Only SingleOracleInfo supported in this context');
|
|
2048
|
+
}
|
|
2049
|
+
const singleOracleInfo = oracleInfo as SingleOracleInfo;
|
|
1657
2050
|
if (
|
|
1658
|
-
|
|
2051
|
+
singleOracleInfo.announcement.oracleEvent.eventId !==
|
|
1659
2052
|
oracleAttestation.eventId
|
|
1660
2053
|
)
|
|
1661
2054
|
throw Error('Incorrect Oracle Attestation. Event Id must match.');
|
|
1662
2055
|
break;
|
|
1663
2056
|
}
|
|
1664
|
-
case
|
|
2057
|
+
case ContractDescriptorType.NumericOutcome: {
|
|
1665
2058
|
const oracleInfo = contractInfo.oracleInfo;
|
|
2059
|
+
if (oracleInfo.type !== MessageType.SingleOracleInfo) {
|
|
2060
|
+
throw Error('Only SingleOracleInfo supported in this context');
|
|
2061
|
+
}
|
|
2062
|
+
const singleOracleInfo = oracleInfo as SingleOracleInfo;
|
|
1666
2063
|
if (
|
|
1667
|
-
|
|
2064
|
+
singleOracleInfo.announcement.oracleEvent.eventId !==
|
|
1668
2065
|
oracleAttestation.eventId
|
|
1669
2066
|
)
|
|
1670
2067
|
throw Error('Incorrect Oracle Attestation. Event Id must match.');
|
|
@@ -1675,12 +2072,17 @@ Payout Group not found',
|
|
|
1675
2072
|
}
|
|
1676
2073
|
break;
|
|
1677
2074
|
}
|
|
1678
|
-
case
|
|
1679
|
-
const contractInfo = dlcOffer.contractInfo as
|
|
2075
|
+
case ContractInfoType.Disjoint: {
|
|
2076
|
+
const contractInfo = dlcOffer.contractInfo as DisjointContractInfo;
|
|
1680
2077
|
const attestedOracleEvent = contractInfo.contractOraclePairs.find(
|
|
1681
|
-
({ oracleInfo }) =>
|
|
1682
|
-
oracleInfo.
|
|
1683
|
-
|
|
2078
|
+
({ oracleInfo }) => {
|
|
2079
|
+
if (oracleInfo.type !== MessageType.SingleOracleInfo) return false;
|
|
2080
|
+
const singleOracleInfo = oracleInfo as SingleOracleInfo;
|
|
2081
|
+
return (
|
|
2082
|
+
singleOracleInfo.announcement.oracleEvent.eventId ===
|
|
2083
|
+
oracleAttestation.eventId
|
|
2084
|
+
);
|
|
2085
|
+
},
|
|
1684
2086
|
);
|
|
1685
2087
|
|
|
1686
2088
|
if (!attestedOracleEvent)
|
|
@@ -1694,20 +2096,13 @@ Payout Group not found',
|
|
|
1694
2096
|
}
|
|
1695
2097
|
|
|
1696
2098
|
async FindAndSignCet(
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
oracleAttestation:
|
|
2099
|
+
dlcOffer: DlcOffer,
|
|
2100
|
+
dlcAccept: DlcAccept,
|
|
2101
|
+
dlcSign: DlcSign,
|
|
2102
|
+
dlcTxs: DlcTransactions,
|
|
2103
|
+
oracleAttestation: OracleAttestation,
|
|
1702
2104
|
isOfferer?: boolean,
|
|
1703
2105
|
): Promise<Tx> {
|
|
1704
|
-
const { dlcOffer, dlcAccept, dlcSign, dlcTxs } = checkTypes({
|
|
1705
|
-
_dlcOffer,
|
|
1706
|
-
_dlcAccept,
|
|
1707
|
-
_dlcSign,
|
|
1708
|
-
_dlcTxs,
|
|
1709
|
-
});
|
|
1710
|
-
|
|
1711
2106
|
if (isOfferer === undefined)
|
|
1712
2107
|
isOfferer = await this.isOfferer(dlcOffer, dlcAccept);
|
|
1713
2108
|
|
|
@@ -1720,14 +2115,16 @@ Payout Group not found',
|
|
|
1720
2115
|
let signCetRequest: SignCetRequest;
|
|
1721
2116
|
|
|
1722
2117
|
if (
|
|
1723
|
-
dlcOffer.contractInfo.
|
|
1724
|
-
(dlcOffer.contractInfo as
|
|
1725
|
-
|
|
2118
|
+
dlcOffer.contractInfo.contractInfoType === ContractInfoType.Single &&
|
|
2119
|
+
(dlcOffer.contractInfo as SingleContractInfo).contractDescriptor
|
|
2120
|
+
.contractDescriptorType === ContractDescriptorType.Enumerated
|
|
1726
2121
|
) {
|
|
1727
|
-
const outcomeIndex = (
|
|
1728
|
-
.
|
|
2122
|
+
const outcomeIndex = (
|
|
2123
|
+
(dlcOffer.contractInfo as SingleContractInfo)
|
|
2124
|
+
.contractDescriptor as EnumeratedDescriptor
|
|
2125
|
+
).outcomes.findIndex(
|
|
1729
2126
|
(outcome) =>
|
|
1730
|
-
outcome.outcome
|
|
2127
|
+
outcome.outcome ===
|
|
1731
2128
|
sha256(Buffer.from(oracleAttestation.outcomes[0])).toString('hex'),
|
|
1732
2129
|
);
|
|
1733
2130
|
|
|
@@ -1736,19 +2133,19 @@ Payout Group not found',
|
|
|
1736
2133
|
fundPrivkey: fundPrivateKey,
|
|
1737
2134
|
fundTxId: dlcTxs.fundTx.txId.toString(),
|
|
1738
2135
|
fundVout: dlcTxs.fundTxVout,
|
|
1739
|
-
localFundPubkey: dlcOffer.
|
|
1740
|
-
remoteFundPubkey: dlcAccept.
|
|
2136
|
+
localFundPubkey: dlcOffer.fundingPubkey.toString('hex'),
|
|
2137
|
+
remoteFundPubkey: dlcAccept.fundingPubkey.toString('hex'),
|
|
1741
2138
|
oracleSignatures: oracleAttestation.signatures.map((sig) =>
|
|
1742
2139
|
sig.toString('hex'),
|
|
1743
2140
|
),
|
|
1744
|
-
fundInputAmount:
|
|
2141
|
+
fundInputAmount: this.getFundOutputValueSats(dlcTxs),
|
|
1745
2142
|
adaptorSignature: isOfferer
|
|
1746
|
-
? dlcAccept.
|
|
1747
|
-
|
|
1748
|
-
)
|
|
1749
|
-
: dlcSign.
|
|
1750
|
-
|
|
1751
|
-
),
|
|
2143
|
+
? dlcAccept.cetAdaptorSignatures.sigs[
|
|
2144
|
+
outcomeIndex
|
|
2145
|
+
].encryptedSig.toString('hex')
|
|
2146
|
+
: dlcSign.cetAdaptorSignatures.sigs[
|
|
2147
|
+
outcomeIndex
|
|
2148
|
+
].encryptedSig.toString('hex'),
|
|
1752
2149
|
};
|
|
1753
2150
|
} else {
|
|
1754
2151
|
const { index: outcomeIndex, groupLength } = await this.FindOutcomeIndex(
|
|
@@ -1768,17 +2165,17 @@ Payout Group not found',
|
|
|
1768
2165
|
fundPrivkey: fundPrivateKey,
|
|
1769
2166
|
fundTxId: dlcTxs.fundTx.txId.toString(),
|
|
1770
2167
|
fundVout: dlcTxs.fundTxVout,
|
|
1771
|
-
localFundPubkey: dlcOffer.
|
|
1772
|
-
remoteFundPubkey: dlcAccept.
|
|
2168
|
+
localFundPubkey: dlcOffer.fundingPubkey.toString('hex'),
|
|
2169
|
+
remoteFundPubkey: dlcAccept.fundingPubkey.toString('hex'),
|
|
1773
2170
|
oracleSignatures: oracleSignatures.map((sig) => sig.toString('hex')),
|
|
1774
|
-
fundInputAmount:
|
|
2171
|
+
fundInputAmount: this.getFundOutputValueSats(dlcTxs),
|
|
1775
2172
|
adaptorSignature: isOfferer
|
|
1776
|
-
? dlcAccept.
|
|
1777
|
-
|
|
1778
|
-
)
|
|
1779
|
-
: dlcSign.
|
|
1780
|
-
|
|
1781
|
-
),
|
|
2173
|
+
? dlcAccept.cetAdaptorSignatures.sigs[
|
|
2174
|
+
outcomeIndex
|
|
2175
|
+
].encryptedSig.toString('hex')
|
|
2176
|
+
: dlcSign.cetAdaptorSignatures.sigs[
|
|
2177
|
+
outcomeIndex
|
|
2178
|
+
].encryptedSig.toString('hex'),
|
|
1782
2179
|
};
|
|
1783
2180
|
}
|
|
1784
2181
|
|
|
@@ -1788,14 +2185,14 @@ Payout Group not found',
|
|
|
1788
2185
|
}
|
|
1789
2186
|
|
|
1790
2187
|
private async GetFundAddress(
|
|
1791
|
-
dlcOffer:
|
|
1792
|
-
dlcAccept:
|
|
2188
|
+
dlcOffer: DlcOffer,
|
|
2189
|
+
dlcAccept: DlcAccept,
|
|
1793
2190
|
isOfferer: boolean,
|
|
1794
2191
|
): Promise<string> {
|
|
1795
2192
|
const network = await this.getConnectedNetwork();
|
|
1796
2193
|
|
|
1797
2194
|
const fundingSPK = Script.p2wpkhLock(
|
|
1798
|
-
hash160(isOfferer ? dlcOffer.
|
|
2195
|
+
hash160(isOfferer ? dlcOffer.fundingPubkey : dlcAccept.fundingPubkey),
|
|
1799
2196
|
)
|
|
1800
2197
|
.serialize()
|
|
1801
2198
|
.slice(1);
|
|
@@ -1809,8 +2206,8 @@ Payout Group not found',
|
|
|
1809
2206
|
}
|
|
1810
2207
|
|
|
1811
2208
|
private async GetFundKeyPair(
|
|
1812
|
-
dlcOffer:
|
|
1813
|
-
dlcAccept:
|
|
2209
|
+
dlcOffer: DlcOffer,
|
|
2210
|
+
dlcAccept: DlcAccept,
|
|
1814
2211
|
isOfferer: boolean,
|
|
1815
2212
|
): Promise<ECPairInterface> {
|
|
1816
2213
|
const fundingAddress = await this.GetFundAddress(
|
|
@@ -1819,19 +2216,17 @@ Payout Group not found',
|
|
|
1819
2216
|
isOfferer,
|
|
1820
2217
|
);
|
|
1821
2218
|
|
|
1822
|
-
const { derivationPath } =
|
|
1823
|
-
fundingAddress
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
derivationPath,
|
|
1827
|
-
);
|
|
2219
|
+
const { derivationPath } =
|
|
2220
|
+
await this.getMethod('getWalletAddress')(fundingAddress);
|
|
2221
|
+
const keyPair: ECPairInterface =
|
|
2222
|
+
await this.getMethod('keyPair')(derivationPath);
|
|
1828
2223
|
|
|
1829
2224
|
return keyPair;
|
|
1830
2225
|
}
|
|
1831
2226
|
|
|
1832
2227
|
private async GetFundPrivateKey(
|
|
1833
|
-
dlcOffer:
|
|
1834
|
-
dlcAccept:
|
|
2228
|
+
dlcOffer: DlcOffer,
|
|
2229
|
+
dlcAccept: DlcAccept,
|
|
1835
2230
|
isOfferer: boolean,
|
|
1836
2231
|
): Promise<string> {
|
|
1837
2232
|
const fundPrivateKeyPair: ECPairInterface = await this.GetFundKeyPair(
|
|
@@ -1844,28 +2239,23 @@ Payout Group not found',
|
|
|
1844
2239
|
}
|
|
1845
2240
|
|
|
1846
2241
|
async CreateCloseRawTxs(
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
2242
|
+
dlcOffer: DlcOffer,
|
|
2243
|
+
dlcAccept: DlcAccept,
|
|
2244
|
+
dlcTxs: DlcTransactions,
|
|
1850
2245
|
closeInputAmount: bigint,
|
|
1851
2246
|
isOfferer: boolean,
|
|
1852
2247
|
_dlcCloses: DlcClose[] = [],
|
|
1853
2248
|
fundingInputs?: FundingInput[],
|
|
1854
2249
|
initiatorPayouts?: bigint[],
|
|
1855
2250
|
): Promise<string[]> {
|
|
1856
|
-
const { dlcOffer, dlcAccept, dlcTxs } = checkTypes({
|
|
1857
|
-
_dlcOffer,
|
|
1858
|
-
_dlcAccept,
|
|
1859
|
-
_dlcTxs,
|
|
1860
|
-
});
|
|
1861
2251
|
const network = await this.getConnectedNetwork();
|
|
1862
2252
|
|
|
1863
2253
|
let finalizer: DualClosingTxFinalizer;
|
|
1864
2254
|
if (_dlcCloses.length === 0) {
|
|
1865
2255
|
finalizer = new DualClosingTxFinalizer(
|
|
1866
2256
|
fundingInputs,
|
|
1867
|
-
dlcOffer.
|
|
1868
|
-
dlcAccept.
|
|
2257
|
+
dlcOffer.payoutSpk,
|
|
2258
|
+
dlcAccept.payoutSpk,
|
|
1869
2259
|
dlcOffer.feeRatePerVb,
|
|
1870
2260
|
);
|
|
1871
2261
|
}
|
|
@@ -1909,14 +2299,14 @@ Payout Group not found',
|
|
|
1909
2299
|
|
|
1910
2300
|
if (Number(offerPayoutValue) > 0) {
|
|
1911
2301
|
txOuts.push({
|
|
1912
|
-
address: address.fromOutputScript(dlcOffer.
|
|
2302
|
+
address: address.fromOutputScript(dlcOffer.payoutSpk, network),
|
|
1913
2303
|
amount: Number(offerPayoutValue),
|
|
1914
2304
|
});
|
|
1915
2305
|
}
|
|
1916
2306
|
|
|
1917
2307
|
if (Number(acceptPayoutValue) > 0) {
|
|
1918
2308
|
txOuts.push({
|
|
1919
|
-
address: address.fromOutputScript(dlcAccept.
|
|
2309
|
+
address: address.fromOutputScript(dlcAccept.payoutSpk, network),
|
|
1920
2310
|
amount: Number(acceptPayoutValue),
|
|
1921
2311
|
});
|
|
1922
2312
|
}
|
|
@@ -1968,9 +2358,9 @@ Payout Group not found',
|
|
|
1968
2358
|
const network = await this.getConnectedNetwork();
|
|
1969
2359
|
|
|
1970
2360
|
const fundingPubKeys =
|
|
1971
|
-
Buffer.compare(dlcOffer.
|
|
1972
|
-
? [dlcOffer.
|
|
1973
|
-
: [dlcAccept.
|
|
2361
|
+
Buffer.compare(dlcOffer.fundingPubkey, dlcAccept.fundingPubkey) === -1
|
|
2362
|
+
? [dlcOffer.fundingPubkey, dlcAccept.fundingPubkey]
|
|
2363
|
+
: [dlcAccept.fundingPubkey, dlcOffer.fundingPubkey];
|
|
1974
2364
|
|
|
1975
2365
|
const p2ms = payments.p2ms({
|
|
1976
2366
|
m: 2,
|
|
@@ -1998,7 +2388,7 @@ Payout Group not found',
|
|
|
1998
2388
|
hex: paymentVariant.redeem.output.toString('hex'),
|
|
1999
2389
|
type: 'redeem_script',
|
|
2000
2390
|
},
|
|
2001
|
-
amount: Number(
|
|
2391
|
+
amount: Number(this.getFundOutputValueSats(dlcTxs)),
|
|
2002
2392
|
hashType: 'p2wsh',
|
|
2003
2393
|
sighashType: 'all',
|
|
2004
2394
|
sighashAnyoneCanPay: false,
|
|
@@ -2079,9 +2469,9 @@ Payout Group not found',
|
|
|
2079
2469
|
const network = await this.getConnectedNetwork();
|
|
2080
2470
|
|
|
2081
2471
|
const fundingPubKeys =
|
|
2082
|
-
Buffer.compare(dlcOffer.
|
|
2083
|
-
? [dlcOffer.
|
|
2084
|
-
: [dlcAccept.
|
|
2472
|
+
Buffer.compare(dlcOffer.fundingPubkey, dlcAccept.fundingPubkey) === -1
|
|
2473
|
+
? [dlcOffer.fundingPubkey, dlcAccept.fundingPubkey]
|
|
2474
|
+
: [dlcAccept.fundingPubkey, dlcOffer.fundingPubkey];
|
|
2085
2475
|
|
|
2086
2476
|
const p2ms = payments.p2ms({
|
|
2087
2477
|
m: 2,
|
|
@@ -2094,7 +2484,7 @@ Payout Group not found',
|
|
|
2094
2484
|
network,
|
|
2095
2485
|
});
|
|
2096
2486
|
|
|
2097
|
-
const pubkey = isOfferer ? dlcAccept.
|
|
2487
|
+
const pubkey = isOfferer ? dlcAccept.fundingPubkey : dlcOffer.fundingPubkey;
|
|
2098
2488
|
|
|
2099
2489
|
const sigsValidity: Promise<boolean>[] = [];
|
|
2100
2490
|
|
|
@@ -2113,7 +2503,7 @@ Payout Group not found',
|
|
|
2113
2503
|
hashType: 'p2wsh',
|
|
2114
2504
|
sighashType: 'all',
|
|
2115
2505
|
sighashAnyoneCanPay: false,
|
|
2116
|
-
amount: Number(
|
|
2506
|
+
amount: Number(this.getFundOutputValueSats(dlcTxs)),
|
|
2117
2507
|
},
|
|
2118
2508
|
};
|
|
2119
2509
|
|
|
@@ -2147,10 +2537,10 @@ Payout Group not found',
|
|
|
2147
2537
|
});
|
|
2148
2538
|
const network = await this.getConnectedNetwork();
|
|
2149
2539
|
|
|
2150
|
-
const offerFundingSPK = Script.p2wpkhLock(hash160(dlcOffer.
|
|
2540
|
+
const offerFundingSPK = Script.p2wpkhLock(hash160(dlcOffer.fundingPubkey))
|
|
2151
2541
|
.serialize()
|
|
2152
2542
|
.slice(1);
|
|
2153
|
-
const acceptFundingSPK = Script.p2wpkhLock(hash160(dlcAccept.
|
|
2543
|
+
const acceptFundingSPK = Script.p2wpkhLock(hash160(dlcAccept.fundingPubkey))
|
|
2154
2544
|
.serialize()
|
|
2155
2545
|
.slice(1);
|
|
2156
2546
|
|
|
@@ -2183,6 +2573,7 @@ Payout Group not found',
|
|
|
2183
2573
|
* @param feeRatePerVb Fee rate in satoshi per virtual byte that both sides use to compute fees in funding tx
|
|
2184
2574
|
* @param cetLocktime The nLockTime to be put on CETs
|
|
2185
2575
|
* @param refundLocktime The nLockTime to be put on the refund transaction
|
|
2576
|
+
* @param fixedInputs Optional fixed inputs - can be Input[] for regular inputs or FundingInput[] for DLC inputs
|
|
2186
2577
|
* @returns {Promise<DlcOffer>}
|
|
2187
2578
|
*/
|
|
2188
2579
|
async createDlcOffer(
|
|
@@ -2191,35 +2582,77 @@ Payout Group not found',
|
|
|
2191
2582
|
feeRatePerVb: bigint,
|
|
2192
2583
|
cetLocktime: number,
|
|
2193
2584
|
refundLocktime: number,
|
|
2194
|
-
fixedInputs?: Input[],
|
|
2585
|
+
fixedInputs?: Input[] | FundingInput[],
|
|
2586
|
+
inputSupplementationMode?: InputSupplementationMode,
|
|
2195
2587
|
): Promise<DlcOffer> {
|
|
2196
2588
|
contractInfo.validate();
|
|
2197
2589
|
const network = await this.getConnectedNetwork();
|
|
2198
2590
|
|
|
2199
|
-
const dlcOffer = new
|
|
2591
|
+
const dlcOffer = new DlcOffer();
|
|
2200
2592
|
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2593
|
+
// Generate a random 32-byte temporary contract ID
|
|
2594
|
+
dlcOffer.temporaryContractId = crypto.randomBytes(32);
|
|
2595
|
+
|
|
2596
|
+
// Check if we have FundingInput[] (DLC inputs) or Input[] (regular inputs)
|
|
2597
|
+
const hasFundingInputs =
|
|
2598
|
+
fixedInputs && fixedInputs.length > 0 && 'prevTx' in fixedInputs[0]; // FundingInput has prevTx, Input doesn't
|
|
2599
|
+
|
|
2600
|
+
let fundingPubKey: Buffer;
|
|
2601
|
+
let payoutSPK: Buffer;
|
|
2602
|
+
let payoutSerialId: bigint;
|
|
2603
|
+
let _fundingInputs: FundingInput[];
|
|
2604
|
+
let changeSPK: Buffer;
|
|
2605
|
+
let changeSerialId: bigint;
|
|
2606
|
+
|
|
2607
|
+
if (hasFundingInputs) {
|
|
2608
|
+
// Handle FundingInput[] directly (for DLC inputs)
|
|
2609
|
+
const fundingInputs = fixedInputs as FundingInput[];
|
|
2610
|
+
|
|
2611
|
+
// Generate addresses directly since we're bypassing Initialize()
|
|
2612
|
+
const payoutAddress: Address =
|
|
2613
|
+
await this.client.wallet.getUnusedAddress(false);
|
|
2614
|
+
payoutSPK = address.toOutputScript(payoutAddress.address, network);
|
|
2615
|
+
|
|
2616
|
+
const changeAddress: Address =
|
|
2617
|
+
await this.client.wallet.getUnusedAddress(true);
|
|
2618
|
+
changeSPK = address.toOutputScript(changeAddress.address, network);
|
|
2619
|
+
|
|
2620
|
+
const fundingAddress: Address =
|
|
2621
|
+
await this.client.wallet.getUnusedAddress(false);
|
|
2622
|
+
fundingPubKey = Buffer.from(fundingAddress.publicKey, 'hex');
|
|
2623
|
+
|
|
2624
|
+
if (fundingAddress.address === payoutAddress.address)
|
|
2625
|
+
throw Error('Address reuse');
|
|
2626
|
+
|
|
2627
|
+
payoutSerialId = generateSerialId();
|
|
2628
|
+
changeSerialId = generateSerialId();
|
|
2629
|
+
_fundingInputs = fundingInputs;
|
|
2630
|
+
} else {
|
|
2631
|
+
// Handle Input[] through existing Initialize() flow
|
|
2632
|
+
const initResult = await this.Initialize(
|
|
2633
|
+
offerCollateralSatoshis,
|
|
2634
|
+
feeRatePerVb,
|
|
2635
|
+
fixedInputs as Input[],
|
|
2636
|
+
inputSupplementationMode || InputSupplementationMode.Required,
|
|
2637
|
+
);
|
|
2638
|
+
|
|
2639
|
+
fundingPubKey = initResult.fundingPubKey;
|
|
2640
|
+
payoutSPK = initResult.payoutSPK;
|
|
2641
|
+
payoutSerialId = initResult.payoutSerialId;
|
|
2642
|
+
_fundingInputs = initResult.fundingInputs;
|
|
2643
|
+
changeSPK = initResult.changeSPK;
|
|
2644
|
+
changeSerialId = initResult.changeSerialId;
|
|
2645
|
+
}
|
|
2213
2646
|
|
|
2214
2647
|
_fundingInputs.forEach((input) =>
|
|
2215
2648
|
assert(
|
|
2216
|
-
input.type === MessageType.
|
|
2649
|
+
input.type === MessageType.FundingInput,
|
|
2217
2650
|
'FundingInput must be V0',
|
|
2218
2651
|
),
|
|
2219
2652
|
);
|
|
2220
2653
|
|
|
2221
|
-
const fundingInputs:
|
|
2222
|
-
(input) => input as
|
|
2654
|
+
const fundingInputs: FundingInput[] = _fundingInputs.map(
|
|
2655
|
+
(input) => input as FundingInput,
|
|
2223
2656
|
);
|
|
2224
2657
|
|
|
2225
2658
|
fundingInputs.sort(
|
|
@@ -2236,24 +2669,29 @@ Payout Group not found',
|
|
|
2236
2669
|
dlcOffer.contractFlags = Buffer.from('00', 'hex');
|
|
2237
2670
|
dlcOffer.chainHash = chainHashFromNetwork(network);
|
|
2238
2671
|
dlcOffer.contractInfo = contractInfo;
|
|
2239
|
-
dlcOffer.
|
|
2240
|
-
dlcOffer.
|
|
2672
|
+
dlcOffer.fundingPubkey = fundingPubKey;
|
|
2673
|
+
dlcOffer.payoutSpk = payoutSPK;
|
|
2241
2674
|
dlcOffer.payoutSerialId = payoutSerialId;
|
|
2242
|
-
dlcOffer.
|
|
2675
|
+
dlcOffer.offerCollateral = offerCollateralSatoshis;
|
|
2243
2676
|
dlcOffer.fundingInputs = fundingInputs;
|
|
2244
|
-
dlcOffer.
|
|
2677
|
+
dlcOffer.changeSpk = changeSPK;
|
|
2245
2678
|
dlcOffer.changeSerialId = changeSerialId;
|
|
2246
|
-
dlcOffer.fundOutputSerialId = dlcOffer.fundOutputSerialId =
|
|
2679
|
+
dlcOffer.fundOutputSerialId = dlcOffer.fundOutputSerialId =
|
|
2680
|
+
fundOutputSerialId;
|
|
2247
2681
|
dlcOffer.feeRatePerVb = feeRatePerVb;
|
|
2248
2682
|
dlcOffer.cetLocktime = cetLocktime;
|
|
2249
2683
|
dlcOffer.refundLocktime = refundLocktime;
|
|
2250
2684
|
|
|
2685
|
+
if (offerCollateralSatoshis === dlcOffer.contractInfo.totalCollateral) {
|
|
2686
|
+
dlcOffer.markAsSingleFunded();
|
|
2687
|
+
}
|
|
2688
|
+
|
|
2251
2689
|
assert(
|
|
2252
2690
|
(() => {
|
|
2253
2691
|
const finalizer = new DualFundingTxFinalizer(
|
|
2254
2692
|
dlcOffer.fundingInputs,
|
|
2255
|
-
dlcOffer.
|
|
2256
|
-
dlcOffer.
|
|
2693
|
+
dlcOffer.payoutSpk,
|
|
2694
|
+
dlcOffer.changeSpk,
|
|
2257
2695
|
null,
|
|
2258
2696
|
null,
|
|
2259
2697
|
null,
|
|
@@ -2290,7 +2728,7 @@ Payout Group not found',
|
|
|
2290
2728
|
);
|
|
2291
2729
|
}
|
|
2292
2730
|
|
|
2293
|
-
const dlcOffers:
|
|
2731
|
+
const dlcOffers: DlcOffer[] = [];
|
|
2294
2732
|
|
|
2295
2733
|
for (let i = 0; i < contractInfos.length; i++) {
|
|
2296
2734
|
contractInfos[i].validate();
|
|
@@ -2307,13 +2745,13 @@ Payout Group not found',
|
|
|
2307
2745
|
|
|
2308
2746
|
_fundingInputs.forEach((input) =>
|
|
2309
2747
|
assert(
|
|
2310
|
-
input.type === MessageType.
|
|
2748
|
+
input.type === MessageType.FundingInput,
|
|
2311
2749
|
'FundingInput must be V0',
|
|
2312
2750
|
),
|
|
2313
2751
|
);
|
|
2314
2752
|
|
|
2315
|
-
const fundingInputs:
|
|
2316
|
-
(input) => input as
|
|
2753
|
+
const fundingInputs: FundingInput[] = _fundingInputs.map(
|
|
2754
|
+
(input) => input as FundingInput,
|
|
2317
2755
|
);
|
|
2318
2756
|
|
|
2319
2757
|
fundingInputs.sort(
|
|
@@ -2326,34 +2764,40 @@ Payout Group not found',
|
|
|
2326
2764
|
const contractInfo = contractInfos[i];
|
|
2327
2765
|
const offerCollateralSatoshis = offerCollaterals[i];
|
|
2328
2766
|
const fundOutputSerialId = fundOutputsSerialIds[i];
|
|
2329
|
-
const { fundingPubKey, payoutSPK, payoutSerialId } =
|
|
2330
|
-
i
|
|
2331
|
-
];
|
|
2767
|
+
const { fundingPubKey, payoutSPK, payoutSerialId } =
|
|
2768
|
+
initializeResponses[i];
|
|
2332
2769
|
const refundLocktime = refundLocktimes[i];
|
|
2333
2770
|
|
|
2334
|
-
const dlcOffer = new
|
|
2771
|
+
const dlcOffer = new DlcOffer();
|
|
2772
|
+
|
|
2773
|
+
// Generate a random 32-byte temporary contract ID
|
|
2774
|
+
dlcOffer.temporaryContractId = crypto.randomBytes(32);
|
|
2335
2775
|
|
|
2336
2776
|
dlcOffer.contractFlags = Buffer.from('00', 'hex');
|
|
2337
2777
|
dlcOffer.chainHash = chainHashFromNetwork(network);
|
|
2338
2778
|
dlcOffer.contractInfo = contractInfo;
|
|
2339
|
-
dlcOffer.
|
|
2340
|
-
dlcOffer.
|
|
2779
|
+
dlcOffer.fundingPubkey = fundingPubKey;
|
|
2780
|
+
dlcOffer.payoutSpk = payoutSPK;
|
|
2341
2781
|
dlcOffer.payoutSerialId = payoutSerialId;
|
|
2342
|
-
dlcOffer.
|
|
2782
|
+
dlcOffer.offerCollateral = offerCollateralSatoshis;
|
|
2343
2783
|
dlcOffer.fundingInputs = fundingInputs;
|
|
2344
|
-
dlcOffer.
|
|
2784
|
+
dlcOffer.changeSpk = changeSPK;
|
|
2345
2785
|
dlcOffer.changeSerialId = changeSerialId;
|
|
2346
2786
|
dlcOffer.fundOutputSerialId = fundOutputSerialId;
|
|
2347
2787
|
dlcOffer.feeRatePerVb = feeRatePerVb;
|
|
2348
2788
|
dlcOffer.cetLocktime = cetLocktime;
|
|
2349
2789
|
dlcOffer.refundLocktime = refundLocktime;
|
|
2350
2790
|
|
|
2791
|
+
if (offerCollateralSatoshis === dlcOffer.contractInfo.totalCollateral) {
|
|
2792
|
+
dlcOffer.markAsSingleFunded();
|
|
2793
|
+
}
|
|
2794
|
+
|
|
2351
2795
|
assert(
|
|
2352
2796
|
(() => {
|
|
2353
2797
|
const finalizer = new DualFundingTxFinalizer(
|
|
2354
2798
|
dlcOffer.fundingInputs,
|
|
2355
|
-
dlcOffer.
|
|
2356
|
-
dlcOffer.
|
|
2799
|
+
dlcOffer.payoutSpk,
|
|
2800
|
+
dlcOffer.changeSpk,
|
|
2357
2801
|
null,
|
|
2358
2802
|
null,
|
|
2359
2803
|
null,
|
|
@@ -2373,74 +2817,166 @@ Payout Group not found',
|
|
|
2373
2817
|
dlcOffers.push(dlcOffer);
|
|
2374
2818
|
}
|
|
2375
2819
|
|
|
2376
|
-
return dlcOffers;
|
|
2377
|
-
}
|
|
2820
|
+
return dlcOffers;
|
|
2821
|
+
}
|
|
2822
|
+
|
|
2823
|
+
/**
|
|
2824
|
+
* Accept DLC Offer (supports single-funded DLCs when accept collateral is 0)
|
|
2825
|
+
* @param _dlcOffer Dlc Offer Message
|
|
2826
|
+
* @param fixedInputs Optional inputs to use for Funding Inputs
|
|
2827
|
+
* @returns {Promise<AcceptDlcOfferResponse}
|
|
2828
|
+
*/
|
|
2829
|
+
async acceptDlcOffer(
|
|
2830
|
+
_dlcOffer: DlcOffer,
|
|
2831
|
+
fixedInputs?: Input[] | FundingInput[],
|
|
2832
|
+
): Promise<AcceptDlcOfferResponse> {
|
|
2833
|
+
const { dlcOffer } = checkTypes({ _dlcOffer });
|
|
2834
|
+
dlcOffer.validate();
|
|
2835
|
+
|
|
2836
|
+
const acceptCollateralSatoshis =
|
|
2837
|
+
dlcOffer.contractInfo.totalCollateral - dlcOffer.offerCollateral;
|
|
2838
|
+
|
|
2839
|
+
assert(
|
|
2840
|
+
acceptCollateralSatoshis ===
|
|
2841
|
+
dlcOffer.contractInfo.totalCollateral - dlcOffer.offerCollateral,
|
|
2842
|
+
'acceptCollaterialSatoshis should equal totalCollateral - offerCollateralSatoshis',
|
|
2843
|
+
);
|
|
2844
|
+
|
|
2845
|
+
let fundingPubKey: Buffer;
|
|
2846
|
+
let payoutSPK: Buffer;
|
|
2847
|
+
let payoutSerialId: bigint;
|
|
2848
|
+
let fundingInputs: FundingInput[];
|
|
2849
|
+
let changeSPK: Buffer;
|
|
2850
|
+
let changeSerialId: bigint;
|
|
2851
|
+
|
|
2852
|
+
if (acceptCollateralSatoshis === BigInt(0)) {
|
|
2853
|
+
// Single-funded DLC: accept side provides no funding
|
|
2854
|
+
const network = await this.getConnectedNetwork();
|
|
2855
|
+
|
|
2856
|
+
// Still need payout address for receiving DLC outcomes
|
|
2857
|
+
const payoutAddress: Address =
|
|
2858
|
+
await this.client.wallet.getUnusedAddress(false);
|
|
2859
|
+
payoutSPK = address.toOutputScript(payoutAddress.address, network);
|
|
2860
|
+
|
|
2861
|
+
// Generate funding pubkey for DLC contract construction
|
|
2862
|
+
const fundingAddress: Address =
|
|
2863
|
+
await this.client.wallet.getUnusedAddress(false);
|
|
2864
|
+
fundingPubKey = Buffer.from(fundingAddress.publicKey, 'hex');
|
|
2865
|
+
|
|
2866
|
+
// Generate change address (even though not used)
|
|
2867
|
+
const changeAddress: Address =
|
|
2868
|
+
await this.client.wallet.getUnusedAddress(true);
|
|
2869
|
+
changeSPK = address.toOutputScript(changeAddress.address, network);
|
|
2870
|
+
|
|
2871
|
+
if (fundingAddress.address === payoutAddress.address)
|
|
2872
|
+
throw Error('Address reuse');
|
|
2873
|
+
|
|
2874
|
+
// Generate serial IDs
|
|
2875
|
+
payoutSerialId = generateSerialId();
|
|
2876
|
+
changeSerialId = generateSerialId();
|
|
2877
|
+
|
|
2878
|
+
// No funding inputs for single-funded DLC
|
|
2879
|
+
fundingInputs = [];
|
|
2880
|
+
} else {
|
|
2881
|
+
// Standard DLC: accept side provides funding
|
|
2882
|
+
|
|
2883
|
+
// Check if we have FundingInput[] (DLC inputs) or Input[] (regular inputs)
|
|
2884
|
+
const hasFundingInputs =
|
|
2885
|
+
fixedInputs && fixedInputs.length > 0 && 'prevTx' in fixedInputs[0]; // FundingInput has prevTx, Input doesn't
|
|
2886
|
+
|
|
2887
|
+
let initResult: InitializeResponse;
|
|
2888
|
+
|
|
2889
|
+
if (hasFundingInputs) {
|
|
2890
|
+
// Handle FundingInput[] directly (for DLC inputs)
|
|
2891
|
+
const fundingInputs = fixedInputs as FundingInput[];
|
|
2892
|
+
const network = await this.getConnectedNetwork();
|
|
2893
|
+
|
|
2894
|
+
// Generate addresses directly since we're bypassing Initialize()
|
|
2895
|
+
const payoutAddress: Address =
|
|
2896
|
+
await this.client.wallet.getUnusedAddress(false);
|
|
2897
|
+
const payoutSPK = address.toOutputScript(
|
|
2898
|
+
payoutAddress.address,
|
|
2899
|
+
network,
|
|
2900
|
+
);
|
|
2901
|
+
|
|
2902
|
+
const changeAddress: Address =
|
|
2903
|
+
await this.client.wallet.getUnusedAddress(true);
|
|
2904
|
+
const changeSPK = address.toOutputScript(
|
|
2905
|
+
changeAddress.address,
|
|
2906
|
+
network,
|
|
2907
|
+
);
|
|
2908
|
+
|
|
2909
|
+
const fundingAddress: Address =
|
|
2910
|
+
await this.client.wallet.getUnusedAddress(false);
|
|
2911
|
+
const fundingPubKey = Buffer.from(fundingAddress.publicKey, 'hex');
|
|
2378
2912
|
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
* @param _dlcOffer Dlc Offer Message
|
|
2382
|
-
* @param fixedInputs Optional inputs to use for Funding Inputs
|
|
2383
|
-
* @returns {Promise<AcceptDlcOfferResponse}
|
|
2384
|
-
*/
|
|
2385
|
-
async acceptDlcOffer(
|
|
2386
|
-
_dlcOffer: DlcOffer,
|
|
2387
|
-
fixedInputs?: Input[],
|
|
2388
|
-
): Promise<AcceptDlcOfferResponse> {
|
|
2389
|
-
const { dlcOffer } = checkTypes({ _dlcOffer });
|
|
2390
|
-
dlcOffer.validate();
|
|
2913
|
+
if (fundingAddress.address === payoutAddress.address)
|
|
2914
|
+
throw Error('Address reuse');
|
|
2391
2915
|
|
|
2392
|
-
|
|
2393
|
-
|
|
2916
|
+
const payoutSerialId = generateSerialId();
|
|
2917
|
+
const changeSerialId = generateSerialId();
|
|
2394
2918
|
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2919
|
+
initResult = {
|
|
2920
|
+
fundingPubKey,
|
|
2921
|
+
payoutSPK,
|
|
2922
|
+
payoutSerialId,
|
|
2923
|
+
fundingInputs,
|
|
2924
|
+
changeSPK,
|
|
2925
|
+
changeSerialId,
|
|
2926
|
+
};
|
|
2927
|
+
} else {
|
|
2928
|
+
// Handle Input[] through existing Initialize() flow
|
|
2929
|
+
// Use InputSupplementationMode.None when fixed inputs are provided
|
|
2930
|
+
// to avoid wallet lookup issues with unusual addresses
|
|
2931
|
+
const supplementationMode =
|
|
2932
|
+
fixedInputs && fixedInputs.length > 0
|
|
2933
|
+
? InputSupplementationMode.None
|
|
2934
|
+
: InputSupplementationMode.Required;
|
|
2935
|
+
|
|
2936
|
+
initResult = await this.Initialize(
|
|
2937
|
+
acceptCollateralSatoshis,
|
|
2938
|
+
dlcOffer.feeRatePerVb,
|
|
2939
|
+
fixedInputs as Input[],
|
|
2940
|
+
supplementationMode,
|
|
2941
|
+
);
|
|
2942
|
+
}
|
|
2401
2943
|
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
changeSPK,
|
|
2408
|
-
changeSerialId,
|
|
2409
|
-
} = await this.Initialize(
|
|
2410
|
-
acceptCollateralSatoshis,
|
|
2411
|
-
dlcOffer.feeRatePerVb,
|
|
2412
|
-
fixedInputs,
|
|
2413
|
-
);
|
|
2944
|
+
fundingPubKey = initResult.fundingPubKey;
|
|
2945
|
+
payoutSPK = initResult.payoutSPK;
|
|
2946
|
+
payoutSerialId = initResult.payoutSerialId;
|
|
2947
|
+
changeSPK = initResult.changeSPK;
|
|
2948
|
+
changeSerialId = initResult.changeSerialId;
|
|
2414
2949
|
|
|
2415
|
-
|
|
2416
|
-
Buffer.compare(dlcOffer.fundingPubKey, fundingPubKey) !== 0,
|
|
2417
|
-
'DlcOffer and DlcAccept FundingPubKey cannot be the same',
|
|
2418
|
-
);
|
|
2950
|
+
const _fundingInputs = initResult.fundingInputs;
|
|
2419
2951
|
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2952
|
+
_fundingInputs.forEach((input) =>
|
|
2953
|
+
assert(
|
|
2954
|
+
input.type === MessageType.FundingInput,
|
|
2955
|
+
'FundingInput must be V0',
|
|
2956
|
+
),
|
|
2957
|
+
);
|
|
2426
2958
|
|
|
2427
|
-
|
|
2428
|
-
(input) => input as FundingInputV0,
|
|
2429
|
-
);
|
|
2959
|
+
fundingInputs = _fundingInputs.map((input) => input as FundingInput);
|
|
2430
2960
|
|
|
2431
|
-
|
|
2432
|
-
|
|
2961
|
+
fundingInputs.sort(
|
|
2962
|
+
(a, b) => Number(a.inputSerialId) - Number(b.inputSerialId),
|
|
2963
|
+
);
|
|
2964
|
+
}
|
|
2965
|
+
|
|
2966
|
+
assert(
|
|
2967
|
+
Buffer.compare(dlcOffer.fundingPubkey, fundingPubKey) !== 0,
|
|
2968
|
+
'DlcOffer and DlcAccept FundingPubKey cannot be the same',
|
|
2433
2969
|
);
|
|
2434
2970
|
|
|
2435
|
-
const dlcAccept = new
|
|
2971
|
+
const dlcAccept = new DlcAccept();
|
|
2436
2972
|
|
|
2437
|
-
dlcAccept.
|
|
2438
|
-
dlcAccept.
|
|
2439
|
-
dlcAccept.
|
|
2440
|
-
dlcAccept.
|
|
2973
|
+
dlcAccept.temporaryContractId = sha256(dlcOffer.serialize());
|
|
2974
|
+
dlcAccept.acceptCollateral = acceptCollateralSatoshis;
|
|
2975
|
+
dlcAccept.fundingPubkey = fundingPubKey;
|
|
2976
|
+
dlcAccept.payoutSpk = payoutSPK;
|
|
2441
2977
|
dlcAccept.payoutSerialId = dlcAccept.payoutSerialId = payoutSerialId;
|
|
2442
2978
|
dlcAccept.fundingInputs = fundingInputs;
|
|
2443
|
-
dlcAccept.
|
|
2979
|
+
dlcAccept.changeSpk = changeSPK;
|
|
2444
2980
|
dlcAccept.changeSerialId = dlcAccept.changeSerialId = changeSerialId;
|
|
2445
2981
|
|
|
2446
2982
|
assert(
|
|
@@ -2465,59 +3001,57 @@ Payout Group not found',
|
|
|
2465
3001
|
'offer.changeSerialID, accept.changeSerialId and fundOutputSerialId must be unique',
|
|
2466
3002
|
);
|
|
2467
3003
|
|
|
3004
|
+
if (dlcOffer.singleFunded) dlcAccept.markAsSingleFunded();
|
|
3005
|
+
|
|
2468
3006
|
dlcAccept.validate();
|
|
2469
3007
|
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
3008
|
+
// Only validate funding requirements if accept side is providing collateral
|
|
3009
|
+
if (acceptCollateralSatoshis > BigInt(0)) {
|
|
3010
|
+
assert(
|
|
3011
|
+
(() => {
|
|
3012
|
+
const finalizer = new DualFundingTxFinalizer(
|
|
3013
|
+
dlcOffer.fundingInputs,
|
|
3014
|
+
dlcOffer.payoutSpk,
|
|
3015
|
+
dlcOffer.changeSpk,
|
|
3016
|
+
dlcAccept.fundingInputs,
|
|
3017
|
+
dlcAccept.payoutSpk,
|
|
3018
|
+
dlcAccept.changeSpk,
|
|
3019
|
+
dlcOffer.feeRatePerVb,
|
|
3020
|
+
);
|
|
3021
|
+
const funding = fundingInputs.reduce((total, input) => {
|
|
3022
|
+
return total + input.prevTx.outputs[input.prevTxVout].value.sats;
|
|
3023
|
+
}, BigInt(0));
|
|
2484
3024
|
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
3025
|
+
return funding >= acceptCollateralSatoshis + finalizer.acceptFees;
|
|
3026
|
+
})(),
|
|
3027
|
+
'fundingInputs for dlcAccept must be greater than acceptCollateralSatoshis plus acceptFees',
|
|
3028
|
+
);
|
|
3029
|
+
}
|
|
2489
3030
|
|
|
2490
3031
|
const { dlcTransactions, messagesList } = await this.createDlcTxs(
|
|
2491
3032
|
dlcOffer,
|
|
2492
3033
|
dlcAccept,
|
|
2493
3034
|
);
|
|
2494
3035
|
|
|
2495
|
-
const {
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
false,
|
|
2504
|
-
);
|
|
3036
|
+
const { cetSignatures, refundSignature } =
|
|
3037
|
+
await this.CreateCetAdaptorAndRefundSigs(
|
|
3038
|
+
dlcOffer,
|
|
3039
|
+
dlcAccept,
|
|
3040
|
+
dlcTransactions,
|
|
3041
|
+
messagesList,
|
|
3042
|
+
false,
|
|
3043
|
+
);
|
|
2505
3044
|
|
|
2506
|
-
|
|
2507
|
-
dlcTransactions.type === MessageType.DlcTransactionsV0,
|
|
2508
|
-
'DlcTransactions must be V0',
|
|
2509
|
-
);
|
|
2510
|
-
const _dlcTransactions = dlcTransactions as DlcTransactionsV0;
|
|
3045
|
+
const _dlcTransactions = dlcTransactions;
|
|
2511
3046
|
|
|
2512
3047
|
const contractId = xor(
|
|
2513
3048
|
_dlcTransactions.fundTx.txId.serialize(),
|
|
2514
|
-
dlcAccept.
|
|
3049
|
+
dlcAccept.temporaryContractId,
|
|
2515
3050
|
);
|
|
2516
3051
|
_dlcTransactions.contractId = contractId;
|
|
2517
3052
|
|
|
2518
|
-
dlcAccept.
|
|
3053
|
+
dlcAccept.cetAdaptorSignatures = cetSignatures;
|
|
2519
3054
|
dlcAccept.refundSignature = refundSignature;
|
|
2520
|
-
dlcAccept.negotiationFields = new NegotiationFieldsV0();
|
|
2521
3055
|
|
|
2522
3056
|
return { dlcAccept, dlcTransactions: _dlcTransactions };
|
|
2523
3057
|
}
|
|
@@ -2534,8 +3068,7 @@ Payout Group not found',
|
|
|
2534
3068
|
|
|
2535
3069
|
const acceptCollaterals = dlcOffers.map(
|
|
2536
3070
|
(dlcOffer) =>
|
|
2537
|
-
dlcOffer.contractInfo.totalCollateral -
|
|
2538
|
-
dlcOffer.offerCollateralSatoshis,
|
|
3071
|
+
dlcOffer.contractInfo.totalCollateral - dlcOffer.offerCollateral,
|
|
2539
3072
|
);
|
|
2540
3073
|
|
|
2541
3074
|
const {
|
|
@@ -2555,7 +3088,7 @@ Payout Group not found',
|
|
|
2555
3088
|
initializeResponses.forEach((initializeResponse) => {
|
|
2556
3089
|
assert(
|
|
2557
3090
|
Buffer.compare(
|
|
2558
|
-
dlcOffer.
|
|
3091
|
+
dlcOffer.fundingPubkey,
|
|
2559
3092
|
initializeResponse.fundingPubKey,
|
|
2560
3093
|
) !== 0,
|
|
2561
3094
|
'DlcOffer and DlcAccept FundingPubKey cannot be the same',
|
|
@@ -2565,34 +3098,34 @@ Payout Group not found',
|
|
|
2565
3098
|
|
|
2566
3099
|
_fundingInputs.forEach((input) =>
|
|
2567
3100
|
assert(
|
|
2568
|
-
input.type === MessageType.
|
|
3101
|
+
input.type === MessageType.FundingInput,
|
|
2569
3102
|
'FundingInput must be V0',
|
|
2570
3103
|
),
|
|
2571
3104
|
);
|
|
2572
3105
|
|
|
2573
|
-
const fundingInputs:
|
|
2574
|
-
(input) => input as
|
|
3106
|
+
const fundingInputs: FundingInput[] = _fundingInputs.map(
|
|
3107
|
+
(input) => input as FundingInput,
|
|
2575
3108
|
);
|
|
2576
3109
|
|
|
2577
3110
|
fundingInputs.sort(
|
|
2578
3111
|
(a, b) => Number(a.inputSerialId) - Number(b.inputSerialId),
|
|
2579
3112
|
);
|
|
2580
3113
|
|
|
2581
|
-
const dlcAccepts:
|
|
3114
|
+
const dlcAccepts: DlcAccept[] = [];
|
|
2582
3115
|
|
|
2583
3116
|
initializeResponses.forEach((initializeResponse, i) => {
|
|
2584
3117
|
const dlcOffer = dlcOffers[i];
|
|
2585
|
-
const dlcAccept = new
|
|
3118
|
+
const dlcAccept = new DlcAccept();
|
|
2586
3119
|
|
|
2587
3120
|
const { fundingPubKey, payoutSPK, payoutSerialId } = initializeResponse;
|
|
2588
3121
|
|
|
2589
|
-
dlcAccept.
|
|
2590
|
-
dlcAccept.
|
|
2591
|
-
dlcAccept.
|
|
2592
|
-
dlcAccept.
|
|
3122
|
+
dlcAccept.temporaryContractId = sha256(dlcOffers[i].serialize());
|
|
3123
|
+
dlcAccept.acceptCollateral = acceptCollaterals[i];
|
|
3124
|
+
dlcAccept.fundingPubkey = fundingPubKey;
|
|
3125
|
+
dlcAccept.payoutSpk = payoutSPK;
|
|
2593
3126
|
dlcAccept.payoutSerialId = payoutSerialId;
|
|
2594
3127
|
dlcAccept.fundingInputs = fundingInputs;
|
|
2595
|
-
dlcAccept.
|
|
3128
|
+
dlcAccept.changeSpk = changeSPK;
|
|
2596
3129
|
dlcAccept.changeSerialId = changeSerialId;
|
|
2597
3130
|
|
|
2598
3131
|
assert(
|
|
@@ -2623,11 +3156,11 @@ Payout Group not found',
|
|
|
2623
3156
|
(() => {
|
|
2624
3157
|
const finalizer = new DualFundingTxFinalizer(
|
|
2625
3158
|
dlcOffer.fundingInputs,
|
|
2626
|
-
dlcOffer.
|
|
2627
|
-
dlcOffer.
|
|
3159
|
+
dlcOffer.payoutSpk,
|
|
3160
|
+
dlcOffer.changeSpk,
|
|
2628
3161
|
dlcAccept.fundingInputs,
|
|
2629
|
-
dlcAccept.
|
|
2630
|
-
dlcAccept.
|
|
3162
|
+
dlcAccept.payoutSpk,
|
|
3163
|
+
dlcAccept.changeSpk,
|
|
2631
3164
|
dlcOffer.feeRatePerVb,
|
|
2632
3165
|
);
|
|
2633
3166
|
const funding = fundingInputs.reduce((total, input) => {
|
|
@@ -2642,10 +3175,8 @@ Payout Group not found',
|
|
|
2642
3175
|
dlcAccepts.push(dlcAccept);
|
|
2643
3176
|
});
|
|
2644
3177
|
|
|
2645
|
-
const {
|
|
2646
|
-
|
|
2647
|
-
nestedMessagesList,
|
|
2648
|
-
} = await this.createBatchDlcTxs(dlcOffers, dlcAccepts);
|
|
3178
|
+
const { dlcTransactionsList, nestedMessagesList } =
|
|
3179
|
+
await this.createBatchDlcTxs(dlcOffers, dlcAccepts);
|
|
2649
3180
|
|
|
2650
3181
|
for (let i = 0; i < dlcAccepts.length; i++) {
|
|
2651
3182
|
const dlcOffer = dlcOffers[i];
|
|
@@ -2653,32 +3184,25 @@ Payout Group not found',
|
|
|
2653
3184
|
const dlcTransactions = dlcTransactionsList[i];
|
|
2654
3185
|
const messagesList = nestedMessagesList[i];
|
|
2655
3186
|
|
|
2656
|
-
const {
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
false,
|
|
2665
|
-
);
|
|
3187
|
+
const { cetSignatures, refundSignature } =
|
|
3188
|
+
await this.CreateCetAdaptorAndRefundSigs(
|
|
3189
|
+
dlcOffer,
|
|
3190
|
+
dlcAccept,
|
|
3191
|
+
dlcTransactions,
|
|
3192
|
+
messagesList,
|
|
3193
|
+
false,
|
|
3194
|
+
);
|
|
2666
3195
|
|
|
2667
|
-
|
|
2668
|
-
dlcTransactions.type === MessageType.DlcTransactionsV0,
|
|
2669
|
-
'DlcTransactions must be V0',
|
|
2670
|
-
);
|
|
2671
|
-
const _dlcTransactions = dlcTransactions as DlcTransactionsV0;
|
|
3196
|
+
const _dlcTransactions = dlcTransactions;
|
|
2672
3197
|
|
|
2673
3198
|
const contractId = xor(
|
|
2674
3199
|
_dlcTransactions.fundTx.txId.serialize(),
|
|
2675
|
-
dlcAccept.
|
|
3200
|
+
dlcAccept.temporaryContractId,
|
|
2676
3201
|
);
|
|
2677
3202
|
_dlcTransactions.contractId = contractId;
|
|
2678
3203
|
|
|
2679
|
-
dlcAccepts[i].
|
|
3204
|
+
dlcAccepts[i].cetAdaptorSignatures = cetSignatures;
|
|
2680
3205
|
dlcAccepts[i].refundSignature = refundSignature;
|
|
2681
|
-
dlcAccepts[i].negotiationFields = new NegotiationFieldsV0();
|
|
2682
3206
|
}
|
|
2683
3207
|
|
|
2684
3208
|
return { dlcAccepts, dlcTransactionsList };
|
|
@@ -2691,22 +3215,18 @@ Payout Group not found',
|
|
|
2691
3215
|
* @returns {Promise<SignDlcAcceptResponse}
|
|
2692
3216
|
*/
|
|
2693
3217
|
async signDlcAccept(
|
|
2694
|
-
|
|
2695
|
-
|
|
3218
|
+
dlcOffer: DlcOffer,
|
|
3219
|
+
dlcAccept: DlcAccept,
|
|
2696
3220
|
): Promise<SignDlcAcceptResponse> {
|
|
2697
|
-
const { dlcOffer, dlcAccept } = checkTypes({
|
|
2698
|
-
_dlcOffer,
|
|
2699
|
-
_dlcAccept,
|
|
2700
|
-
});
|
|
2701
3221
|
dlcOffer.validate();
|
|
2702
3222
|
dlcAccept.validate();
|
|
2703
3223
|
|
|
2704
3224
|
assert(
|
|
2705
|
-
Buffer.compare(dlcOffer.
|
|
3225
|
+
Buffer.compare(dlcOffer.fundingPubkey, dlcAccept.fundingPubkey) !== 0,
|
|
2706
3226
|
'DlcOffer and DlcAccept FundingPubKey cannot be the same',
|
|
2707
3227
|
);
|
|
2708
3228
|
|
|
2709
|
-
const dlcSign = new
|
|
3229
|
+
const dlcSign = new DlcSign();
|
|
2710
3230
|
|
|
2711
3231
|
const { dlcTransactions, messagesList } = await this.createDlcTxs(
|
|
2712
3232
|
dlcOffer,
|
|
@@ -2722,16 +3242,14 @@ Payout Group not found',
|
|
|
2722
3242
|
true,
|
|
2723
3243
|
);
|
|
2724
3244
|
|
|
2725
|
-
const {
|
|
2726
|
-
|
|
2727
|
-
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
true,
|
|
2734
|
-
);
|
|
3245
|
+
const { cetSignatures, refundSignature } =
|
|
3246
|
+
await this.CreateCetAdaptorAndRefundSigs(
|
|
3247
|
+
dlcOffer,
|
|
3248
|
+
dlcAccept,
|
|
3249
|
+
dlcTransactions,
|
|
3250
|
+
messagesList,
|
|
3251
|
+
true,
|
|
3252
|
+
);
|
|
2735
3253
|
|
|
2736
3254
|
const fundingSignatures = await this.CreateFundingSigs(
|
|
2737
3255
|
dlcOffer,
|
|
@@ -2740,17 +3258,17 @@ Payout Group not found',
|
|
|
2740
3258
|
true,
|
|
2741
3259
|
);
|
|
2742
3260
|
|
|
2743
|
-
const dlcTxs = dlcTransactions
|
|
3261
|
+
const dlcTxs = dlcTransactions;
|
|
2744
3262
|
|
|
2745
3263
|
const contractId = xor(
|
|
2746
3264
|
dlcTxs.fundTx.txId.serialize(),
|
|
2747
|
-
dlcAccept.
|
|
3265
|
+
dlcAccept.temporaryContractId,
|
|
2748
3266
|
);
|
|
2749
3267
|
|
|
2750
3268
|
assert(
|
|
2751
3269
|
Buffer.compare(
|
|
2752
3270
|
contractId,
|
|
2753
|
-
xor(dlcTxs.fundTx.txId.serialize(), dlcAccept.
|
|
3271
|
+
xor(dlcTxs.fundTx.txId.serialize(), dlcAccept.temporaryContractId),
|
|
2754
3272
|
) === 0,
|
|
2755
3273
|
'contractId must be the xor of funding txid, fundingOutputIndex and the tempContractId',
|
|
2756
3274
|
);
|
|
@@ -2758,7 +3276,7 @@ Payout Group not found',
|
|
|
2758
3276
|
dlcTxs.contractId = contractId;
|
|
2759
3277
|
|
|
2760
3278
|
dlcSign.contractId = contractId;
|
|
2761
|
-
dlcSign.
|
|
3279
|
+
dlcSign.cetAdaptorSignatures = cetSignatures;
|
|
2762
3280
|
dlcSign.refundSignature = refundSignature;
|
|
2763
3281
|
dlcSign.fundingSignatures = fundingSignatures;
|
|
2764
3282
|
|
|
@@ -2781,12 +3299,10 @@ Payout Group not found',
|
|
|
2781
3299
|
return dlcAccept;
|
|
2782
3300
|
});
|
|
2783
3301
|
|
|
2784
|
-
const {
|
|
2785
|
-
|
|
2786
|
-
nestedMessagesList,
|
|
2787
|
-
} = await this.createBatchDlcTxs(dlcOffers, dlcAccepts);
|
|
3302
|
+
const { dlcTransactionsList, nestedMessagesList } =
|
|
3303
|
+
await this.createBatchDlcTxs(dlcOffers, dlcAccepts);
|
|
2788
3304
|
|
|
2789
|
-
const dlcSigns:
|
|
3305
|
+
const dlcSigns: DlcSign[] = [];
|
|
2790
3306
|
|
|
2791
3307
|
const fundingSignatures = await this.CreateFundingSigs(
|
|
2792
3308
|
dlcOffers[0],
|
|
@@ -2801,7 +3317,7 @@ Payout Group not found',
|
|
|
2801
3317
|
const dlcTransactions = dlcTransactionsList[i];
|
|
2802
3318
|
const messagesList = nestedMessagesList[i];
|
|
2803
3319
|
|
|
2804
|
-
const dlcSign = new
|
|
3320
|
+
const dlcSign = new DlcSign();
|
|
2805
3321
|
|
|
2806
3322
|
await this.VerifyCetAdaptorAndRefundSigs(
|
|
2807
3323
|
dlcOffer,
|
|
@@ -2812,28 +3328,26 @@ Payout Group not found',
|
|
|
2812
3328
|
true,
|
|
2813
3329
|
);
|
|
2814
3330
|
|
|
2815
|
-
const {
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
true,
|
|
2824
|
-
);
|
|
3331
|
+
const { cetSignatures, refundSignature } =
|
|
3332
|
+
await this.CreateCetAdaptorAndRefundSigs(
|
|
3333
|
+
dlcOffer,
|
|
3334
|
+
dlcAccept,
|
|
3335
|
+
dlcTransactions,
|
|
3336
|
+
messagesList,
|
|
3337
|
+
true,
|
|
3338
|
+
);
|
|
2825
3339
|
|
|
2826
|
-
const dlcTxs = dlcTransactions
|
|
3340
|
+
const dlcTxs = dlcTransactions;
|
|
2827
3341
|
|
|
2828
3342
|
const contractId = xor(
|
|
2829
3343
|
dlcTxs.fundTx.txId.serialize(),
|
|
2830
|
-
dlcAccept.
|
|
3344
|
+
dlcAccept.temporaryContractId,
|
|
2831
3345
|
);
|
|
2832
3346
|
|
|
2833
3347
|
dlcTxs.contractId = contractId;
|
|
2834
3348
|
|
|
2835
3349
|
dlcSign.contractId = contractId;
|
|
2836
|
-
dlcSign.
|
|
3350
|
+
dlcSign.cetAdaptorSignatures = cetSignatures;
|
|
2837
3351
|
dlcSign.refundSignature = refundSignature;
|
|
2838
3352
|
dlcSign.fundingSignatures = fundingSignatures;
|
|
2839
3353
|
|
|
@@ -2845,41 +3359,35 @@ Payout Group not found',
|
|
|
2845
3359
|
|
|
2846
3360
|
/**
|
|
2847
3361
|
* Finalize Dlc Sign
|
|
2848
|
-
* @param
|
|
2849
|
-
* @param
|
|
2850
|
-
* @param
|
|
2851
|
-
* @param
|
|
3362
|
+
* @param dlcOffer Dlc Offer Message
|
|
3363
|
+
* @param dlcAccept Dlc Accept Message
|
|
3364
|
+
* @param dlcSign Dlc Sign Message
|
|
3365
|
+
* @param dlcTxs Dlc Transactions Message
|
|
2852
3366
|
* @returns {Promise<Tx>}
|
|
2853
3367
|
*/
|
|
2854
3368
|
async finalizeDlcSign(
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
3369
|
+
dlcOffer: DlcOffer,
|
|
3370
|
+
dlcAccept: DlcAccept,
|
|
3371
|
+
dlcSign: DlcSign,
|
|
3372
|
+
dlcTxs: DlcTransactions,
|
|
2859
3373
|
): Promise<Tx> {
|
|
2860
|
-
const { dlcOffer, dlcAccept, dlcSign, dlcTxs } = checkTypes({
|
|
2861
|
-
_dlcOffer,
|
|
2862
|
-
_dlcAccept,
|
|
2863
|
-
_dlcSign,
|
|
2864
|
-
_dlcTxs,
|
|
2865
|
-
});
|
|
2866
|
-
|
|
2867
3374
|
let messagesList: Messages[] = [];
|
|
2868
3375
|
|
|
2869
3376
|
if (
|
|
2870
|
-
dlcOffer.contractInfo.type === MessageType.
|
|
2871
|
-
(dlcOffer.contractInfo as
|
|
2872
|
-
MessageType.
|
|
3377
|
+
dlcOffer.contractInfo.type === MessageType.SingleContractInfo &&
|
|
3378
|
+
(dlcOffer.contractInfo as SingleContractInfo).contractDescriptor.type ===
|
|
3379
|
+
MessageType.SingleContractInfo
|
|
2873
3380
|
) {
|
|
2874
|
-
for (const outcome of (
|
|
2875
|
-
.
|
|
2876
|
-
|
|
3381
|
+
for (const outcome of (
|
|
3382
|
+
(dlcOffer.contractInfo as SingleContractInfo)
|
|
3383
|
+
.contractDescriptor as EnumeratedDescriptor
|
|
3384
|
+
).outcomes) {
|
|
3385
|
+
messagesList.push({ messages: [outcome.outcome] });
|
|
2877
3386
|
}
|
|
2878
3387
|
} else {
|
|
2879
3388
|
const payoutResponses = this.GetPayouts(dlcOffer);
|
|
2880
|
-
const { messagesList: oracleEventMessagesList } =
|
|
2881
|
-
payoutResponses
|
|
2882
|
-
);
|
|
3389
|
+
const { messagesList: oracleEventMessagesList } =
|
|
3390
|
+
this.FlattenPayouts(payoutResponses);
|
|
2883
3391
|
messagesList = oracleEventMessagesList;
|
|
2884
3392
|
}
|
|
2885
3393
|
|
|
@@ -2996,20 +3504,13 @@ Payout Group not found',
|
|
|
2996
3504
|
* @returns {Promise<Tx>}
|
|
2997
3505
|
*/
|
|
2998
3506
|
async execute(
|
|
2999
|
-
|
|
3000
|
-
|
|
3001
|
-
|
|
3002
|
-
|
|
3003
|
-
oracleAttestation:
|
|
3507
|
+
dlcOffer: DlcOffer,
|
|
3508
|
+
dlcAccept: DlcAccept,
|
|
3509
|
+
dlcSign: DlcSign,
|
|
3510
|
+
dlcTxs: DlcTransactions,
|
|
3511
|
+
oracleAttestation: OracleAttestation,
|
|
3004
3512
|
isOfferer?: boolean,
|
|
3005
3513
|
): Promise<Tx> {
|
|
3006
|
-
const { dlcOffer, dlcAccept, dlcSign, dlcTxs } = checkTypes({
|
|
3007
|
-
_dlcOffer,
|
|
3008
|
-
_dlcAccept,
|
|
3009
|
-
_dlcSign,
|
|
3010
|
-
_dlcTxs,
|
|
3011
|
-
});
|
|
3012
|
-
|
|
3013
3514
|
if (isOfferer === undefined)
|
|
3014
3515
|
isOfferer = await this.isOfferer(dlcOffer, dlcAccept);
|
|
3015
3516
|
|
|
@@ -3047,7 +3548,7 @@ Payout Group not found',
|
|
|
3047
3548
|
});
|
|
3048
3549
|
|
|
3049
3550
|
const signatures =
|
|
3050
|
-
Buffer.compare(dlcOffer.
|
|
3551
|
+
Buffer.compare(dlcOffer.fundingPubkey, dlcAccept.fundingPubkey) === -1
|
|
3051
3552
|
? [
|
|
3052
3553
|
dlcSign.refundSignature.toString('hex'),
|
|
3053
3554
|
dlcAccept.refundSignature.toString('hex'),
|
|
@@ -3062,8 +3563,8 @@ Payout Group not found',
|
|
|
3062
3563
|
signatures,
|
|
3063
3564
|
fundTxId: dlcTxs.fundTx.txId.toString(),
|
|
3064
3565
|
fundVout: dlcTxs.fundTxVout,
|
|
3065
|
-
localFundPubkey: dlcOffer.
|
|
3066
|
-
remoteFundPubkey: dlcAccept.
|
|
3566
|
+
localFundPubkey: dlcOffer.fundingPubkey.toString('hex'),
|
|
3567
|
+
remoteFundPubkey: dlcAccept.fundingPubkey.toString('hex'),
|
|
3067
3568
|
};
|
|
3068
3569
|
|
|
3069
3570
|
const refundHex = (
|
|
@@ -3111,9 +3612,9 @@ Payout Group not found',
|
|
|
3111
3612
|
const psbt = new Psbt({ network });
|
|
3112
3613
|
|
|
3113
3614
|
const fundingPubKeys =
|
|
3114
|
-
Buffer.compare(dlcOffer.
|
|
3115
|
-
? [dlcOffer.
|
|
3116
|
-
: [dlcAccept.
|
|
3615
|
+
Buffer.compare(dlcOffer.fundingPubkey, dlcAccept.fundingPubkey) === -1
|
|
3616
|
+
? [dlcOffer.fundingPubkey, dlcAccept.fundingPubkey]
|
|
3617
|
+
: [dlcAccept.fundingPubkey, dlcOffer.fundingPubkey];
|
|
3117
3618
|
|
|
3118
3619
|
const p2ms = payments.p2ms({
|
|
3119
3620
|
m: 2,
|
|
@@ -3129,28 +3630,46 @@ Payout Group not found',
|
|
|
3129
3630
|
// Initiate and build PSBT
|
|
3130
3631
|
let inputs: Input[] = _inputs;
|
|
3131
3632
|
if (!_inputs) {
|
|
3132
|
-
const tempInputs = await this.
|
|
3633
|
+
const tempInputs = await this.GetInputsForAmountWithMode(
|
|
3133
3634
|
[BigInt(20000)],
|
|
3134
3635
|
dlcOffer.feeRatePerVb,
|
|
3135
|
-
_inputs,
|
|
3636
|
+
_inputs || [],
|
|
3637
|
+
InputSupplementationMode.Required,
|
|
3136
3638
|
);
|
|
3137
3639
|
_inputs = tempInputs;
|
|
3138
3640
|
}
|
|
3139
|
-
inputs
|
|
3140
|
-
|
|
3141
|
-
|
|
3142
|
-
|
|
3143
|
-
|
|
3144
|
-
|
|
3145
|
-
|
|
3641
|
+
// Ensure all inputs have derivation paths by fetching from wallet
|
|
3642
|
+
const inputsWithPaths: { input: Input; address: Address }[] =
|
|
3643
|
+
await Promise.all(
|
|
3644
|
+
_inputs.map(async (input) => {
|
|
3645
|
+
const address: Address = await this.getMethod('getWalletAddress')(
|
|
3646
|
+
input.address,
|
|
3647
|
+
);
|
|
3648
|
+
const inputWithPath = new Input(
|
|
3649
|
+
input.txid,
|
|
3650
|
+
input.vout,
|
|
3651
|
+
input.address,
|
|
3652
|
+
input.amount,
|
|
3653
|
+
input.value,
|
|
3654
|
+
input.derivationPath || address.derivationPath, // Use derivationPath from wallet if not set
|
|
3655
|
+
input.maxWitnessLength,
|
|
3656
|
+
input.redeemScript,
|
|
3657
|
+
input.inputSerialId || generateSerialId(),
|
|
3658
|
+
input.scriptPubKey,
|
|
3659
|
+
input.label,
|
|
3660
|
+
input.confirmations,
|
|
3661
|
+
input.spendable,
|
|
3662
|
+
input.solvable,
|
|
3663
|
+
input.safe,
|
|
3664
|
+
input.dlcInput,
|
|
3665
|
+
);
|
|
3666
|
+
return { input: inputWithPath, address };
|
|
3667
|
+
}),
|
|
3668
|
+
);
|
|
3146
3669
|
|
|
3147
|
-
|
|
3148
|
-
|
|
3149
|
-
|
|
3150
|
-
input.address,
|
|
3151
|
-
);
|
|
3152
|
-
return Buffer.from(address.publicKey, 'hex');
|
|
3153
|
-
}),
|
|
3670
|
+
inputs = inputsWithPaths.map((item) => item.input);
|
|
3671
|
+
const pubkeys: Buffer[] = inputsWithPaths.map((item) =>
|
|
3672
|
+
Buffer.from(item.address.publicKey, 'hex'),
|
|
3154
3673
|
);
|
|
3155
3674
|
|
|
3156
3675
|
const fundingInputSerialId = generateSerialId();
|
|
@@ -3164,7 +3683,7 @@ Payout Group not found',
|
|
|
3164
3683
|
sequence: 0,
|
|
3165
3684
|
witnessUtxo: {
|
|
3166
3685
|
script: paymentVariant.output,
|
|
3167
|
-
value: Number(
|
|
3686
|
+
value: Number(this.getFundOutputValueSats(dlcTxs)),
|
|
3168
3687
|
},
|
|
3169
3688
|
witnessScript: paymentVariant.redeem.output,
|
|
3170
3689
|
inputSerialId: fundingInputSerialId,
|
|
@@ -3202,7 +3721,7 @@ Payout Group not found',
|
|
|
3202
3721
|
);
|
|
3203
3722
|
|
|
3204
3723
|
// add to psbt
|
|
3205
|
-
sortedPsbtInputs.forEach((input
|
|
3724
|
+
sortedPsbtInputs.forEach((input) => psbt.addInput(input));
|
|
3206
3725
|
|
|
3207
3726
|
const fundingInputs: FundingInput[] = await Promise.all(
|
|
3208
3727
|
inputs.map(async (input) => {
|
|
@@ -3212,8 +3731,8 @@ Payout Group not found',
|
|
|
3212
3731
|
|
|
3213
3732
|
const finalizer = new DualClosingTxFinalizer(
|
|
3214
3733
|
fundingInputs,
|
|
3215
|
-
dlcOffer.
|
|
3216
|
-
dlcAccept.
|
|
3734
|
+
dlcOffer.payoutSpk,
|
|
3735
|
+
dlcAccept.payoutSpk,
|
|
3217
3736
|
dlcOffer.feeRatePerVb,
|
|
3218
3737
|
);
|
|
3219
3738
|
|
|
@@ -3238,7 +3757,7 @@ Payout Group not found',
|
|
|
3238
3757
|
psbt.addOutput({
|
|
3239
3758
|
value: Number(offerFirst ? offerPayoutValue : acceptPayoutValue),
|
|
3240
3759
|
address: address.fromOutputScript(
|
|
3241
|
-
offerFirst ? dlcOffer.
|
|
3760
|
+
offerFirst ? dlcOffer.payoutSpk : dlcAccept.payoutSpk,
|
|
3242
3761
|
network,
|
|
3243
3762
|
),
|
|
3244
3763
|
});
|
|
@@ -3246,7 +3765,7 @@ Payout Group not found',
|
|
|
3246
3765
|
psbt.addOutput({
|
|
3247
3766
|
value: Number(offerFirst ? acceptPayoutValue : offerPayoutValue),
|
|
3248
3767
|
address: address.fromOutputScript(
|
|
3249
|
-
offerFirst ? dlcAccept.
|
|
3768
|
+
offerFirst ? dlcAccept.payoutSpk : dlcOffer.payoutSpk,
|
|
3250
3769
|
network,
|
|
3251
3770
|
),
|
|
3252
3771
|
});
|
|
@@ -3267,6 +3786,9 @@ Payout Group not found',
|
|
|
3267
3786
|
if (i === fundingInputIndex) return;
|
|
3268
3787
|
|
|
3269
3788
|
// derive keypair
|
|
3789
|
+
if (!input.derivationPath) {
|
|
3790
|
+
throw new Error(`Missing derivation path for input ${i}`);
|
|
3791
|
+
}
|
|
3270
3792
|
const keyPair = await this.getMethod('keyPair')(input.derivationPath);
|
|
3271
3793
|
psbt.signInput(i, keyPair);
|
|
3272
3794
|
}),
|
|
@@ -3298,11 +3820,11 @@ Payout Group not found',
|
|
|
3298
3820
|
pubKeyWitness.witness = inputSigs[i].pubkey;
|
|
3299
3821
|
witnessElements.push([sigWitness, pubKeyWitness]);
|
|
3300
3822
|
}
|
|
3301
|
-
const fundingSignatures = new
|
|
3823
|
+
const fundingSignatures = new FundingSignatures();
|
|
3302
3824
|
fundingSignatures.witnessElements = witnessElements;
|
|
3303
3825
|
|
|
3304
3826
|
// Create DlcClose
|
|
3305
|
-
const dlcClose = new
|
|
3827
|
+
const dlcClose = new DlcClose();
|
|
3306
3828
|
dlcClose.contractId = dlcTxs.contractId;
|
|
3307
3829
|
dlcClose.offerPayoutSatoshis = BigInt(
|
|
3308
3830
|
psbt.txOutputs[offerFirst ? 0 : 1].value,
|
|
@@ -3313,7 +3835,7 @@ Payout Group not found',
|
|
|
3313
3835
|
dlcClose.fundInputSerialId = fundingInputSerialId; // randomly generated serial id
|
|
3314
3836
|
dlcClose.closeSignature = closeSignature;
|
|
3315
3837
|
dlcClose.fundingSignatures = fundingSignatures;
|
|
3316
|
-
dlcClose.fundingInputs = fundingInputs as
|
|
3838
|
+
dlcClose.fundingInputs = fundingInputs as FundingInput[];
|
|
3317
3839
|
dlcClose.validate();
|
|
3318
3840
|
|
|
3319
3841
|
return dlcClose;
|
|
@@ -3355,8 +3877,8 @@ Payout Group not found',
|
|
|
3355
3877
|
|
|
3356
3878
|
const finalizer = new DualClosingTxFinalizer(
|
|
3357
3879
|
fundingInputs,
|
|
3358
|
-
dlcOffer.
|
|
3359
|
-
dlcAccept.
|
|
3880
|
+
dlcOffer.payoutSpk,
|
|
3881
|
+
dlcAccept.payoutSpk,
|
|
3360
3882
|
dlcOffer.feeRatePerVb,
|
|
3361
3883
|
);
|
|
3362
3884
|
|
|
@@ -3415,9 +3937,9 @@ Payout Group not found',
|
|
|
3415
3937
|
? collateralMinusPayout
|
|
3416
3938
|
: closeInputAmount + payoutMinusOfferFees;
|
|
3417
3939
|
|
|
3418
|
-
const fundingSignatures = new
|
|
3940
|
+
const fundingSignatures = new FundingSignatures();
|
|
3419
3941
|
|
|
3420
|
-
const dlcClose = new
|
|
3942
|
+
const dlcClose = new DlcClose();
|
|
3421
3943
|
dlcClose.contractId = dlcTxs.contractId;
|
|
3422
3944
|
dlcClose.offerPayoutSatoshis = offerPayoutValue;
|
|
3423
3945
|
dlcClose.acceptPayoutSatoshis = acceptPayoutValue;
|
|
@@ -3542,9 +4064,9 @@ Payout Group not found',
|
|
|
3542
4064
|
const psbt = new Psbt({ network });
|
|
3543
4065
|
|
|
3544
4066
|
const fundingPubKeys =
|
|
3545
|
-
Buffer.compare(dlcOffer.
|
|
3546
|
-
? [dlcOffer.
|
|
3547
|
-
: [dlcAccept.
|
|
4067
|
+
Buffer.compare(dlcOffer.fundingPubkey, dlcAccept.fundingPubkey) === -1
|
|
4068
|
+
? [dlcOffer.fundingPubkey, dlcAccept.fundingPubkey]
|
|
4069
|
+
: [dlcAccept.fundingPubkey, dlcOffer.fundingPubkey];
|
|
3548
4070
|
|
|
3549
4071
|
const p2ms = payments.p2ms({
|
|
3550
4072
|
m: 2,
|
|
@@ -3566,14 +4088,14 @@ Payout Group not found',
|
|
|
3566
4088
|
sequence: 0,
|
|
3567
4089
|
witnessUtxo: {
|
|
3568
4090
|
script: paymentVariant.output,
|
|
3569
|
-
value: Number(
|
|
4091
|
+
value: Number(this.getFundOutputValueSats(dlcTxs)),
|
|
3570
4092
|
},
|
|
3571
4093
|
witnessScript: paymentVariant.redeem.output,
|
|
3572
4094
|
inputSerialId: dlcClose.fundInputSerialId,
|
|
3573
4095
|
});
|
|
3574
4096
|
|
|
3575
4097
|
// add all dlc close inputs
|
|
3576
|
-
dlcClose.fundingInputs.forEach((input
|
|
4098
|
+
dlcClose.fundingInputs.forEach((input) => {
|
|
3577
4099
|
psbtInputs.push({
|
|
3578
4100
|
hash: input.prevTx.txId.serialize(),
|
|
3579
4101
|
index: input.prevTxVout,
|
|
@@ -3610,7 +4132,7 @@ Payout Group not found',
|
|
|
3610
4132
|
: dlcClose.acceptPayoutSatoshis,
|
|
3611
4133
|
),
|
|
3612
4134
|
address: address.fromOutputScript(
|
|
3613
|
-
offerFirst ? dlcOffer.
|
|
4135
|
+
offerFirst ? dlcOffer.payoutSpk : dlcAccept.payoutSpk,
|
|
3614
4136
|
network,
|
|
3615
4137
|
),
|
|
3616
4138
|
});
|
|
@@ -3622,13 +4144,13 @@ Payout Group not found',
|
|
|
3622
4144
|
: dlcClose.offerPayoutSatoshis,
|
|
3623
4145
|
),
|
|
3624
4146
|
address: address.fromOutputScript(
|
|
3625
|
-
offerFirst ? dlcAccept.
|
|
4147
|
+
offerFirst ? dlcAccept.payoutSpk : dlcOffer.payoutSpk,
|
|
3626
4148
|
network,
|
|
3627
4149
|
),
|
|
3628
4150
|
});
|
|
3629
4151
|
|
|
3630
4152
|
// add to psbt
|
|
3631
|
-
sortedPsbtInputs.forEach((input
|
|
4153
|
+
sortedPsbtInputs.forEach((input) => psbt.addInput(input));
|
|
3632
4154
|
|
|
3633
4155
|
const offerer = await this.isOfferer(dlcOffer, dlcAccept);
|
|
3634
4156
|
|
|
@@ -3644,7 +4166,7 @@ Payout Group not found',
|
|
|
3644
4166
|
|
|
3645
4167
|
const partialSig = [
|
|
3646
4168
|
{
|
|
3647
|
-
pubkey: offerer ? dlcAccept.
|
|
4169
|
+
pubkey: offerer ? dlcAccept.fundingPubkey : dlcOffer.fundingPubkey,
|
|
3648
4170
|
signature: await script.signature.encode(dlcClose.closeSignature, 1), // encode using SIGHASH_ALL
|
|
3649
4171
|
},
|
|
3650
4172
|
];
|
|
@@ -3824,16 +4346,45 @@ Payout Group not found',
|
|
|
3824
4346
|
return this._cfdDlcJs.VerifyRefundTxSignature(jsonObject);
|
|
3825
4347
|
}
|
|
3826
4348
|
|
|
4349
|
+
async CreateSplicedDlcTransactions(
|
|
4350
|
+
jsonObject: CreateSplicedDlcTransactionsRequest,
|
|
4351
|
+
): Promise<CreateSplicedDlcTransactionsResponse> {
|
|
4352
|
+
await this.CfdLoaded();
|
|
4353
|
+
|
|
4354
|
+
return this._cfdDlcJs.CreateSplicedDlcTransactions(jsonObject);
|
|
4355
|
+
}
|
|
4356
|
+
|
|
4357
|
+
async GetRawDlcFundingInputSignature(
|
|
4358
|
+
jsonObject: GetRawDlcFundingInputSignatureRequest,
|
|
4359
|
+
): Promise<GetRawDlcFundingInputSignatureResponse> {
|
|
4360
|
+
await this.CfdLoaded();
|
|
4361
|
+
|
|
4362
|
+
return this._cfdDlcJs.GetRawDlcFundingInputSignature(jsonObject);
|
|
4363
|
+
}
|
|
4364
|
+
|
|
4365
|
+
async SignDlcFundingInput(
|
|
4366
|
+
jsonObject: SignDlcFundingInputRequest,
|
|
4367
|
+
): Promise<SignDlcFundingInputResponse> {
|
|
4368
|
+
await this.CfdLoaded();
|
|
4369
|
+
|
|
4370
|
+
return this._cfdDlcJs.SignDlcFundingInput(jsonObject);
|
|
4371
|
+
}
|
|
4372
|
+
|
|
4373
|
+
async VerifyDlcFundingInputSignature(
|
|
4374
|
+
jsonObject: VerifyDlcFundingInputSignatureRequest,
|
|
4375
|
+
): Promise<VerifyDlcFundingInputSignatureResponse> {
|
|
4376
|
+
await this.CfdLoaded();
|
|
4377
|
+
|
|
4378
|
+
return this._cfdDlcJs.VerifyDlcFundingInputSignature(jsonObject);
|
|
4379
|
+
}
|
|
4380
|
+
|
|
3827
4381
|
async fundingInputToInput(
|
|
3828
4382
|
_input: FundingInput,
|
|
3829
4383
|
findDerivationPath = true,
|
|
3830
4384
|
): Promise<Input> {
|
|
3831
|
-
assert(
|
|
3832
|
-
_input.type === MessageType.FundingInputV0,
|
|
3833
|
-
'FundingInput must be V0',
|
|
3834
|
-
);
|
|
4385
|
+
assert(_input.type === MessageType.FundingInput, 'FundingInput must be V0');
|
|
3835
4386
|
const network = await this.getConnectedNetwork();
|
|
3836
|
-
const input = _input as
|
|
4387
|
+
const input = _input as FundingInput;
|
|
3837
4388
|
const prevTx = input.prevTx;
|
|
3838
4389
|
const prevTxOut = prevTx.outputs[input.prevTxVout];
|
|
3839
4390
|
const scriptPubKey = prevTxOut.scriptPubKey.serialize().slice(1);
|
|
@@ -3849,25 +4400,40 @@ Payout Group not found',
|
|
|
3849
4400
|
}
|
|
3850
4401
|
}
|
|
3851
4402
|
|
|
3852
|
-
|
|
3853
|
-
|
|
3854
|
-
|
|
3855
|
-
|
|
3856
|
-
|
|
3857
|
-
|
|
4403
|
+
// Check if this FundingInput has DLC input information to preserve
|
|
4404
|
+
const dlcInputMessage = input.dlcInput;
|
|
4405
|
+
|
|
4406
|
+
let dlcInputInfo: DlcInputInfo | undefined;
|
|
4407
|
+
if (dlcInputMessage) {
|
|
4408
|
+
dlcInputInfo = {
|
|
4409
|
+
localFundPubkey: dlcInputMessage.localFundPubkey.toString('hex'),
|
|
4410
|
+
remoteFundPubkey: dlcInputMessage.remoteFundPubkey.toString('hex'),
|
|
4411
|
+
contractId: dlcInputMessage.contractId.toString('hex'),
|
|
4412
|
+
};
|
|
4413
|
+
}
|
|
4414
|
+
|
|
4415
|
+
return new Input(
|
|
4416
|
+
prevTx.txId.toString(),
|
|
4417
|
+
input.prevTxVout,
|
|
4418
|
+
_address,
|
|
4419
|
+
prevTxOut.value.bitcoin,
|
|
4420
|
+
Number(prevTxOut.value.sats),
|
|
3858
4421
|
derivationPath,
|
|
3859
|
-
|
|
3860
|
-
redeemScript
|
|
3861
|
-
|
|
3862
|
-
|
|
3863
|
-
|
|
3864
|
-
|
|
3865
|
-
|
|
3866
|
-
|
|
4422
|
+
input.maxWitnessLen,
|
|
4423
|
+
input.redeemScript ? input.redeemScript.toString('hex') : '',
|
|
4424
|
+
input.inputSerialId,
|
|
4425
|
+
scriptPubKey.toString('hex'),
|
|
4426
|
+
undefined, // label
|
|
4427
|
+
undefined, // confirmations
|
|
4428
|
+
undefined, // spendable
|
|
4429
|
+
undefined, // solvable
|
|
4430
|
+
undefined, // safe
|
|
4431
|
+
dlcInputInfo, // Preserve DLC input information if present
|
|
4432
|
+
);
|
|
3867
4433
|
}
|
|
3868
4434
|
|
|
3869
4435
|
async inputToFundingInput(input: Input): Promise<FundingInput> {
|
|
3870
|
-
const fundingInput = new
|
|
4436
|
+
const fundingInput = new FundingInput();
|
|
3871
4437
|
fundingInput.prevTxVout = input.vout;
|
|
3872
4438
|
|
|
3873
4439
|
let txRaw = '';
|
|
@@ -3898,12 +4464,155 @@ Payout Group not found',
|
|
|
3898
4464
|
? input.inputSerialId
|
|
3899
4465
|
: generateSerialId();
|
|
3900
4466
|
|
|
4467
|
+
// Preserve DLC input information if present
|
|
4468
|
+
if (input.isDlcInput()) {
|
|
4469
|
+
const dlcInputInfo = input.dlcInput!;
|
|
4470
|
+
const dlcInput = new DlcInput();
|
|
4471
|
+
dlcInput.localFundPubkey = Buffer.from(
|
|
4472
|
+
dlcInputInfo.localFundPubkey,
|
|
4473
|
+
'hex',
|
|
4474
|
+
);
|
|
4475
|
+
dlcInput.remoteFundPubkey = Buffer.from(
|
|
4476
|
+
dlcInputInfo.remoteFundPubkey,
|
|
4477
|
+
'hex',
|
|
4478
|
+
);
|
|
4479
|
+
dlcInput.contractId = Buffer.alloc(32); // Placeholder contract ID
|
|
4480
|
+
|
|
4481
|
+
fundingInput.dlcInput = dlcInput;
|
|
4482
|
+
}
|
|
4483
|
+
|
|
3901
4484
|
return fundingInput;
|
|
3902
4485
|
}
|
|
3903
4486
|
|
|
3904
4487
|
async getConnectedNetwork(): Promise<BitcoinNetwork> {
|
|
3905
4488
|
return this._network;
|
|
3906
4489
|
}
|
|
4490
|
+
|
|
4491
|
+
/**
|
|
4492
|
+
* Calculate the maximum collateral possible with given inputs
|
|
4493
|
+
* @param inputs Array of Input objects to use for funding
|
|
4494
|
+
* @param feeRatePerVb Fee rate in satoshis per virtual byte
|
|
4495
|
+
* @param contractCount Number of DLC contracts (default: 1)
|
|
4496
|
+
* @returns Maximum collateral amount in satoshis
|
|
4497
|
+
*/
|
|
4498
|
+
async calculateMaxCollateral(
|
|
4499
|
+
inputs: Input[],
|
|
4500
|
+
feeRatePerVb: bigint,
|
|
4501
|
+
contractCount: number = 1,
|
|
4502
|
+
): Promise<bigint> {
|
|
4503
|
+
if (inputs.length === 0) {
|
|
4504
|
+
return BigInt(0);
|
|
4505
|
+
}
|
|
4506
|
+
|
|
4507
|
+
try {
|
|
4508
|
+
// Convert Input[] to FundingInput[]
|
|
4509
|
+
const fundingInputs = await Promise.all(
|
|
4510
|
+
inputs.map((input) => this.inputToFundingInput(input)),
|
|
4511
|
+
);
|
|
4512
|
+
|
|
4513
|
+
// Use node-dlc's calculateMaxCollateral function
|
|
4514
|
+
// For single-funded DLC, pass only offerer inputs and fee rate
|
|
4515
|
+
return BatchDlcTxBuilder.calculateMaxCollateral(
|
|
4516
|
+
fundingInputs,
|
|
4517
|
+
feeRatePerVb,
|
|
4518
|
+
contractCount,
|
|
4519
|
+
);
|
|
4520
|
+
} catch (error) {
|
|
4521
|
+
// If calculation fails, return 0 to indicate insufficient funds
|
|
4522
|
+
console.warn('calculateMaxCollateral failed:', error);
|
|
4523
|
+
return BigInt(0);
|
|
4524
|
+
}
|
|
4525
|
+
}
|
|
4526
|
+
|
|
4527
|
+
/**
|
|
4528
|
+
* Create a funding input with DLC input information for splicing
|
|
4529
|
+
* @param dlcInputInfo DLC input information
|
|
4530
|
+
* @param fundingTxHex Raw transaction hex of the funding transaction
|
|
4531
|
+
*/
|
|
4532
|
+
async createDlcFundingInput(
|
|
4533
|
+
dlcInputInfo: DlcInputInfoRequest,
|
|
4534
|
+
fundingTxHex: string,
|
|
4535
|
+
): Promise<FundingInput> {
|
|
4536
|
+
const fundingInput = new FundingInput();
|
|
4537
|
+
const tx = Tx.decode(StreamReader.fromHex(fundingTxHex));
|
|
4538
|
+
|
|
4539
|
+
fundingInput.prevTx = tx;
|
|
4540
|
+
fundingInput.prevTxVout = dlcInputInfo.fundVout;
|
|
4541
|
+
fundingInput.sequence = Sequence.default();
|
|
4542
|
+
fundingInput.maxWitnessLen = dlcInputInfo.maxWitnessLength || 220;
|
|
4543
|
+
fundingInput.redeemScript = Buffer.from('', 'hex'); // Empty for P2WSH
|
|
4544
|
+
fundingInput.inputSerialId = BigInt(
|
|
4545
|
+
dlcInputInfo.inputSerialId || generateSerialId(),
|
|
4546
|
+
);
|
|
4547
|
+
|
|
4548
|
+
// Create the DLC multisig script for address generation
|
|
4549
|
+
const localPubkey = Buffer.from(dlcInputInfo.localFundPubkey, 'hex');
|
|
4550
|
+
const remotePubkey = Buffer.from(dlcInputInfo.remoteFundPubkey, 'hex');
|
|
4551
|
+
|
|
4552
|
+
// Use the same deterministic ordering as cfd-dlc-js: lexicographic by hex
|
|
4553
|
+
// This matches GetOrderedPubkeys() in cfddlc_transactions.cpp
|
|
4554
|
+
const orderedPubkeys =
|
|
4555
|
+
dlcInputInfo.localFundPubkey < dlcInputInfo.remoteFundPubkey
|
|
4556
|
+
? [localPubkey, remotePubkey]
|
|
4557
|
+
: [remotePubkey, localPubkey];
|
|
4558
|
+
|
|
4559
|
+
const network = await this.getConnectedNetwork();
|
|
4560
|
+
|
|
4561
|
+
// Create 2-of-2 multisig payment using deterministic ordering
|
|
4562
|
+
const p2ms = payments.p2ms({
|
|
4563
|
+
m: 2,
|
|
4564
|
+
pubkeys: orderedPubkeys,
|
|
4565
|
+
network,
|
|
4566
|
+
});
|
|
4567
|
+
|
|
4568
|
+
const paymentVariant = payments.p2wsh({
|
|
4569
|
+
redeem: p2ms,
|
|
4570
|
+
network,
|
|
4571
|
+
});
|
|
4572
|
+
|
|
4573
|
+
const multisigAddress = paymentVariant.address!;
|
|
4574
|
+
|
|
4575
|
+
// Verify this matches the actual funding output address
|
|
4576
|
+
const actualFundingOutput = tx.outputs[dlcInputInfo.fundVout];
|
|
4577
|
+
const actualFundingAddress = address.fromOutputScript(
|
|
4578
|
+
actualFundingOutput.scriptPubKey.serialize().slice(1),
|
|
4579
|
+
network,
|
|
4580
|
+
);
|
|
4581
|
+
|
|
4582
|
+
if (actualFundingAddress !== multisigAddress) {
|
|
4583
|
+
throw new Error(
|
|
4584
|
+
`DLC funding address mismatch. ` +
|
|
4585
|
+
`Expected: ${actualFundingAddress}, ` +
|
|
4586
|
+
`Constructed: ${multisigAddress}`,
|
|
4587
|
+
);
|
|
4588
|
+
}
|
|
4589
|
+
|
|
4590
|
+
// Add toUtxo method that's expected by GetInputsForAmount
|
|
4591
|
+
(fundingInput as FundingInput & { toUtxo: () => Utxo }).toUtxo = () => {
|
|
4592
|
+
return new Utxo(
|
|
4593
|
+
dlcInputInfo.fundTxid,
|
|
4594
|
+
dlcInputInfo.fundVout,
|
|
4595
|
+
Amount.FromSatoshis(Number(dlcInputInfo.fundAmount)),
|
|
4596
|
+
multisigAddress,
|
|
4597
|
+
'', // DLC inputs don't have derivation paths
|
|
4598
|
+
dlcInputInfo.maxWitnessLength || 220,
|
|
4599
|
+
fundingInput.inputSerialId,
|
|
4600
|
+
);
|
|
4601
|
+
};
|
|
4602
|
+
|
|
4603
|
+
// Create proper DlcInput object for splicing detection and signing
|
|
4604
|
+
const dlcInput = new DlcInput();
|
|
4605
|
+
dlcInput.localFundPubkey = Buffer.from(dlcInputInfo.localFundPubkey, 'hex');
|
|
4606
|
+
dlcInput.remoteFundPubkey = Buffer.from(
|
|
4607
|
+
dlcInputInfo.remoteFundPubkey,
|
|
4608
|
+
'hex',
|
|
4609
|
+
);
|
|
4610
|
+
dlcInput.contractId = Buffer.from(dlcInputInfo.contractId, 'hex');
|
|
4611
|
+
|
|
4612
|
+
fundingInput.dlcInput = dlcInput;
|
|
4613
|
+
|
|
4614
|
+
return fundingInput;
|
|
4615
|
+
}
|
|
3907
4616
|
}
|
|
3908
4617
|
|
|
3909
4618
|
export interface BasicInitializeResponse {
|
|
@@ -3973,7 +4682,7 @@ interface ISig {
|
|
|
3973
4682
|
}
|
|
3974
4683
|
|
|
3975
4684
|
export interface CreateCetAdaptorAndRefundSigsResponse {
|
|
3976
|
-
cetSignatures:
|
|
4685
|
+
cetSignatures: CetAdaptorSignatures;
|
|
3977
4686
|
refundSignature: Buffer;
|
|
3978
4687
|
}
|
|
3979
4688
|
|
|
@@ -4007,5 +4716,3 @@ export interface InputsForDualAmountResponse {
|
|
|
4007
4716
|
inputs: Input[];
|
|
4008
4717
|
fee: number;
|
|
4009
4718
|
}
|
|
4010
|
-
|
|
4011
|
-
const BurnAddress = 'bcrt1qxcjufgh2jarkp2qkx68azh08w9v5gah8u6es8s';
|