@atomicfinance/bitcoin-dlc-provider 3.6.0 → 4.0.0
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-build.log +1 -0
- package/.turbo/turbo-test.log +0 -0
- package/.yalc/@node-dlc/messaging/.nyc_output/2cf48009-1094-4275-bb91-c164c932feb6.json +1 -0
- package/.yalc/@node-dlc/messaging/.nyc_output/processinfo/2cf48009-1094-4275-bb91-c164c932feb6.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 +12 -0
- package/.yalc/@node-dlc/messaging/__tests__/chain/ChainManager.spec.ts +178 -0
- package/.yalc/@node-dlc/messaging/__tests__/compatibility/dlcspecs-compatibility.spec.ts +473 -0
- package/.yalc/@node-dlc/messaging/__tests__/compatibility/rust-dlc-cross-language.spec.ts +342 -0
- package/.yalc/@node-dlc/messaging/__tests__/compatibility/true-serialization-compatibility.spec.ts +611 -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 +264 -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 +242 -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/DlcOffer.spec.ts +527 -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 +84 -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 +326 -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 +77 -0
- package/.yalc/@node-dlc/messaging/__tests__/messages/OrderNegotiationFields.spec.ts +216 -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 +260 -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 +494 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/chain/ChainManager.ts.html +1058 -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 +212 -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 +347 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/messages/ContractDescriptor.ts.html +1040 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/messages/ContractInfo.ts.html +1382 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/messages/DlcAccept.ts.html +1865 -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 +986 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/messages/DlcCloseMetadata.ts.html +443 -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/DlcMessage.ts.html +341 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/messages/DlcOffer.ts.html +1895 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/messages/DlcSign.ts.html +1142 -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 +947 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/messages/FundingInput.ts.html +728 -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 +374 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/messages/NegotiationFields.ts.html +836 -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 +605 -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 +770 -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 +827 -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 +1637 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/messages/OracleInfoV0.ts.html +1631 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/messages/OrderAccept.ts.html +557 -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 +551 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/messages/OrderOffer.ts.html +1337 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/messages/OrderPositionInfo.ts.html +590 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/messages/PayoutCurvePiece.ts.html +1427 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/messages/PayoutFunction.ts.html +800 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/messages/RoundingIntervals.ts.html +461 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/messages/RoundingIntervalsV0.ts.html +482 -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 +636 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/serde/SerdeUtils.ts.html +1394 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/serde/index.html +111 -0
- package/.yalc/@node-dlc/messaging/coverage/lcov-report/lib/serialize/F64.ts.html +1136 -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 +179 -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 +5394 -0
- package/.yalc/@node-dlc/messaging/dist/MessageType.d.ts +100 -0
- package/.yalc/@node-dlc/messaging/dist/MessageType.js +117 -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 +211 -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 +44 -0
- package/.yalc/@node-dlc/messaging/dist/index.js +63 -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/ContractDescriptor.d.ts +122 -0
- package/.yalc/@node-dlc/messaging/dist/messages/ContractDescriptor.js +222 -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 +304 -0
- package/.yalc/@node-dlc/messaging/dist/messages/ContractInfo.js.map +1 -0
- package/.yalc/@node-dlc/messaging/dist/messages/DlcAccept.d.ts +145 -0
- package/.yalc/@node-dlc/messaging/dist/messages/DlcAccept.js +428 -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 +210 -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/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 +131 -0
- package/.yalc/@node-dlc/messaging/dist/messages/DlcOffer.js +418 -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 +267 -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 +106 -0
- package/.yalc/@node-dlc/messaging/dist/messages/EventDescriptor.js +209 -0
- package/.yalc/@node-dlc/messaging/dist/messages/EventDescriptor.js.map +1 -0
- package/.yalc/@node-dlc/messaging/dist/messages/FundingInput.d.ts +62 -0
- package/.yalc/@node-dlc/messaging/dist/messages/FundingInput.js +163 -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/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 +185 -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/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/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/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 +161 -0
- package/.yalc/@node-dlc/messaging/dist/messages/OracleInfo.js +390 -0
- package/.yalc/@node-dlc/messaging/dist/messages/OracleInfo.js.map +1 -0
- package/.yalc/@node-dlc/messaging/dist/messages/OracleInfoV0.d.ts +161 -0
- package/.yalc/@node-dlc/messaging/dist/messages/OracleInfoV0.js +387 -0
- package/.yalc/@node-dlc/messaging/dist/messages/OracleInfoV0.js.map +1 -0
- package/.yalc/@node-dlc/messaging/dist/messages/OrderAccept.d.ts +65 -0
- package/.yalc/@node-dlc/messaging/dist/messages/OrderAccept.js +125 -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 +69 -0
- package/.yalc/@node-dlc/messaging/dist/messages/OrderNegotiationFields.js +114 -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 +50 -0
- package/.yalc/@node-dlc/messaging/dist/messages/OrderPositionInfo.js +125 -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 +327 -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 +170 -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 +95 -0
- package/.yalc/@node-dlc/messaging/dist/messages/RoundingIntervals.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 +154 -0
- package/.yalc/@node-dlc/messaging/dist/serialize/F64.js +307 -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 +40 -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 +138 -0
- package/.yalc/@node-dlc/messaging/lib/chain/ChainManager.ts +326 -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 +44 -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 +318 -0
- package/.yalc/@node-dlc/messaging/lib/messages/ContractInfo.ts +434 -0
- package/.yalc/@node-dlc/messaging/lib/messages/DlcAccept.ts +595 -0
- package/.yalc/@node-dlc/messaging/lib/messages/DlcCancel.ts +57 -0
- package/.yalc/@node-dlc/messaging/lib/messages/DlcClose.ts +302 -0
- package/.yalc/@node-dlc/messaging/lib/messages/DlcCloseMetadata.ts +121 -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/DlcMessage.ts +87 -0
- package/.yalc/@node-dlc/messaging/lib/messages/DlcOffer.ts +605 -0
- package/.yalc/@node-dlc/messaging/lib/messages/DlcSign.ts +354 -0
- package/.yalc/@node-dlc/messaging/lib/messages/DlcTransactions.ts +213 -0
- package/.yalc/@node-dlc/messaging/lib/messages/EventDescriptor.ts +289 -0
- package/.yalc/@node-dlc/messaging/lib/messages/FundingInput.ts +216 -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 +252 -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 +519 -0
- package/.yalc/@node-dlc/messaging/lib/messages/OrderAccept.ts +159 -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 +157 -0
- package/.yalc/@node-dlc/messaging/lib/messages/OrderOffer.ts +419 -0
- package/.yalc/@node-dlc/messaging/lib/messages/OrderPositionInfo.ts +170 -0
- package/.yalc/@node-dlc/messaging/lib/messages/PayoutCurvePiece.ts +449 -0
- package/.yalc/@node-dlc/messaging/lib/messages/PayoutFunction.ts +240 -0
- package/.yalc/@node-dlc/messaging/lib/messages/RoundingIntervals.ts +127 -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 +352 -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 +33 -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 +210 -0
- package/.yalc/@node-dlc/messaging/test_vectors/dlcspecs/enum_3_of_5_test.json +468 -0
- package/.yalc/@node-dlc/messaging/test_vectors/dlcspecs/enum_and_numerical_3_of_5_test.json +1517 -0
- package/.yalc/@node-dlc/messaging/test_vectors/dlcspecs/enum_and_numerical_5_of_5_test.json +545 -0
- package/.yalc/@node-dlc/messaging/test_vectors/dlcspecs/enum_and_numerical_with_diff_3_of_5_test.json +4761 -0
- package/.yalc/@node-dlc/messaging/test_vectors/dlcspecs/enum_and_numerical_with_diff_5_of_5_test.json +2169 -0
- package/.yalc/@node-dlc/messaging/test_vectors/dlcspecs/enum_single_oracle_test.json +164 -0
- package/.yalc/@node-dlc/messaging/test_vectors/dlcspecs/single_oracle_numerical_hyperbola_test.json +502 -0
- package/.yalc/@node-dlc/messaging/test_vectors/dlcspecs/single_oracle_numerical_test.json +262 -0
- package/.yalc/@node-dlc/messaging/test_vectors/dlcspecs/three_of_five_oracle_numerical_with_diff_test.json +4382 -0
- package/.yalc/@node-dlc/messaging/test_vectors/dlcspecs/three_of_three_oracle_numerical_test.json +324 -0
- package/.yalc/@node-dlc/messaging/test_vectors/dlcspecs/three_of_three_oracle_numerical_with_diff_test.json +652 -0
- package/.yalc/@node-dlc/messaging/test_vectors/dlcspecs/two_of_five_oracle_numerical_test.json +1138 -0
- package/.yalc/@node-dlc/messaging/test_vectors/dlcspecs/two_of_five_oracle_numerical_with_diff_test.json +2222 -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 +83 -0
- package/dist/BitcoinDlcProvider.d.ts +17 -16
- package/dist/BitcoinDlcProvider.js +375 -317
- package/dist/BitcoinDlcProvider.js.map +1 -1
- package/dist/utils/Utils.d.ts +6 -6
- package/dist/utils/Utils.js +4 -4
- package/dist/utils/Utils.js.map +1 -1
- package/lib/BitcoinDlcProvider.ts +637 -621
- package/lib/utils/Utils.ts +19 -24
- package/package.json +13 -11
- package/yalc.lock +10 -0
|
@@ -61,48 +61,46 @@ import {
|
|
|
61
61
|
} from '@node-dlc/core';
|
|
62
62
|
import { hash160, sha256, xor } from '@node-dlc/crypto';
|
|
63
63
|
import {
|
|
64
|
-
|
|
64
|
+
CetAdaptorSignatures,
|
|
65
65
|
ContractDescriptor,
|
|
66
|
-
|
|
67
|
-
ContractDescriptorV1,
|
|
66
|
+
ContractDescriptorType,
|
|
68
67
|
ContractInfo,
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
68
|
+
ContractInfoType,
|
|
69
|
+
DigitDecompositionEventDescriptor,
|
|
70
|
+
DisjointContractInfo,
|
|
72
71
|
DlcAccept,
|
|
73
|
-
DlcAcceptV0,
|
|
74
72
|
DlcClose,
|
|
75
73
|
DlcCloseMetadata,
|
|
76
|
-
DlcCloseV0,
|
|
77
74
|
DlcOffer,
|
|
78
|
-
DlcOfferV0,
|
|
79
75
|
DlcSign,
|
|
80
|
-
DlcSignV0,
|
|
81
76
|
DlcTransactions,
|
|
82
|
-
|
|
77
|
+
EnumeratedDescriptor,
|
|
78
|
+
EnumEventDescriptor,
|
|
79
|
+
F64,
|
|
83
80
|
FundingInput,
|
|
84
|
-
|
|
85
|
-
FundingSignaturesV0,
|
|
81
|
+
FundingSignatures,
|
|
86
82
|
HyperbolaPayoutCurvePiece,
|
|
87
83
|
MessageType,
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
84
|
+
MultiOracleInfo,
|
|
85
|
+
NumericalDescriptor,
|
|
86
|
+
OracleAttestation,
|
|
87
|
+
OracleEvent,
|
|
88
|
+
OracleInfo,
|
|
89
|
+
PayoutCurvePieceType,
|
|
90
|
+
PayoutFunction,
|
|
92
91
|
PayoutFunctionV0,
|
|
93
92
|
PolynomialPayoutCurvePiece,
|
|
94
93
|
ScriptWitnessV0,
|
|
94
|
+
SingleContractInfo,
|
|
95
|
+
SingleOracleInfo,
|
|
95
96
|
} from '@node-dlc/messaging';
|
|
96
97
|
import assert from 'assert';
|
|
97
98
|
import BigNumber from 'bignumber.js';
|
|
98
99
|
import { BitcoinNetwork, chainHashFromNetwork } from 'bitcoin-networks';
|
|
99
|
-
import {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
Psbt,
|
|
104
|
-
script,
|
|
105
|
-
} from 'bitcoinjs-lib';
|
|
100
|
+
import { address, payments, Psbt, script } from 'bitcoinjs-lib';
|
|
101
|
+
import crypto from 'crypto';
|
|
102
|
+
import { ECPairInterface } from 'ecpair';
|
|
103
|
+
import * as ecc from 'tiny-secp256k1';
|
|
106
104
|
|
|
107
105
|
import {
|
|
108
106
|
asyncForEach,
|
|
@@ -114,7 +112,8 @@ import {
|
|
|
114
112
|
|
|
115
113
|
export default class BitcoinDlcProvider
|
|
116
114
|
extends Provider
|
|
117
|
-
implements Partial<DlcProvider>
|
|
115
|
+
implements Partial<DlcProvider>
|
|
116
|
+
{
|
|
118
117
|
_network: BitcoinNetwork;
|
|
119
118
|
_cfdDlcJs: any;
|
|
120
119
|
|
|
@@ -201,24 +200,21 @@ export default class BitcoinDlcProvider
|
|
|
201
200
|
fixedInputs: Input[],
|
|
202
201
|
): Promise<InitializeResponse> {
|
|
203
202
|
const network = await this.getConnectedNetwork();
|
|
204
|
-
const payoutAddress: Address =
|
|
205
|
-
false
|
|
206
|
-
);
|
|
203
|
+
const payoutAddress: Address =
|
|
204
|
+
await this.client.wallet.getUnusedAddress(false);
|
|
207
205
|
const payoutSPK: Buffer = address.toOutputScript(
|
|
208
206
|
payoutAddress.address,
|
|
209
207
|
network,
|
|
210
208
|
);
|
|
211
|
-
const changeAddress: Address =
|
|
212
|
-
true
|
|
213
|
-
);
|
|
209
|
+
const changeAddress: Address =
|
|
210
|
+
await this.client.wallet.getUnusedAddress(true);
|
|
214
211
|
const changeSPK: Buffer = address.toOutputScript(
|
|
215
212
|
changeAddress.address,
|
|
216
213
|
network,
|
|
217
214
|
);
|
|
218
215
|
|
|
219
|
-
const fundingAddress: Address =
|
|
220
|
-
false
|
|
221
|
-
);
|
|
216
|
+
const fundingAddress: Address =
|
|
217
|
+
await this.client.wallet.getUnusedAddress(false);
|
|
222
218
|
const fundingPubKey: Buffer = Buffer.from(fundingAddress.publicKey, 'hex');
|
|
223
219
|
|
|
224
220
|
if (fundingAddress.address === payoutAddress.address)
|
|
@@ -271,26 +267,23 @@ export default class BitcoinDlcProvider
|
|
|
271
267
|
|
|
272
268
|
const changeSerialId: bigint = generateSerialId();
|
|
273
269
|
|
|
274
|
-
const changeAddress: Address =
|
|
275
|
-
true
|
|
276
|
-
);
|
|
270
|
+
const changeAddress: Address =
|
|
271
|
+
await this.client.wallet.getUnusedAddress(true);
|
|
277
272
|
const changeSPK: Buffer = address.toOutputScript(
|
|
278
273
|
changeAddress.address,
|
|
279
274
|
network,
|
|
280
275
|
);
|
|
281
276
|
|
|
282
277
|
for (let i = 0; i < collaterals.length; i++) {
|
|
283
|
-
const payoutAddress: Address =
|
|
284
|
-
false
|
|
285
|
-
);
|
|
278
|
+
const payoutAddress: Address =
|
|
279
|
+
await this.client.wallet.getUnusedAddress(false);
|
|
286
280
|
const payoutSPK: Buffer = address.toOutputScript(
|
|
287
281
|
payoutAddress.address,
|
|
288
282
|
network,
|
|
289
283
|
);
|
|
290
284
|
|
|
291
|
-
const fundingAddress: Address =
|
|
292
|
-
false
|
|
293
|
-
);
|
|
285
|
+
const fundingAddress: Address =
|
|
286
|
+
await this.client.wallet.getUnusedAddress(false);
|
|
294
287
|
const fundingPubKey: Buffer = Buffer.from(
|
|
295
288
|
fundingAddress.publicKey,
|
|
296
289
|
'hex',
|
|
@@ -321,35 +314,29 @@ export default class BitcoinDlcProvider
|
|
|
321
314
|
*/
|
|
322
315
|
|
|
323
316
|
private GetPayoutsFromPayoutFunction(
|
|
324
|
-
|
|
325
|
-
contractDescriptor:
|
|
326
|
-
oracleInfo:
|
|
317
|
+
dlcOffer: DlcOffer,
|
|
318
|
+
contractDescriptor: NumericalDescriptor,
|
|
319
|
+
oracleInfo: OracleInfo,
|
|
327
320
|
totalCollateral: bigint,
|
|
328
321
|
): GetPayoutsResponse {
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
const dlcOffer = _dlcOffer as DlcOfferV0;
|
|
332
|
-
if (contractDescriptor.payoutFunction.type !== MessageType.PayoutFunctionV0)
|
|
333
|
-
throw Error('PayoutFunction must be V0');
|
|
334
|
-
const payoutFunction = contractDescriptor.payoutFunction as PayoutFunctionV0;
|
|
335
|
-
if (payoutFunction.pieces.length === 0)
|
|
322
|
+
const payoutFunction = contractDescriptor.payoutFunction as PayoutFunction;
|
|
323
|
+
if (payoutFunction.payoutFunctionPieces.length === 0)
|
|
336
324
|
throw Error('PayoutFunction must have at least once PayoutCurvePiece');
|
|
337
|
-
if (payoutFunction.
|
|
325
|
+
if (payoutFunction.payoutFunctionPieces.length > 1)
|
|
338
326
|
throw Error('More than one PayoutCurvePiece not supported');
|
|
339
|
-
const payoutCurvePiece = payoutFunction.
|
|
327
|
+
const payoutCurvePiece = payoutFunction.payoutFunctionPieces[0]
|
|
340
328
|
.payoutCurvePiece as HyperbolaPayoutCurvePiece;
|
|
341
329
|
if (
|
|
342
|
-
payoutCurvePiece.
|
|
343
|
-
payoutCurvePiece.type !== MessageType.OldHyperbolaPayoutCurvePiece
|
|
330
|
+
payoutCurvePiece.payoutCurvePieceType !== PayoutCurvePieceType.Hyperbola
|
|
344
331
|
)
|
|
345
332
|
throw Error('Must be HyperbolaPayoutCurvePiece');
|
|
346
|
-
if (payoutCurvePiece.b
|
|
333
|
+
if (!payoutCurvePiece.b.eq(F64.ZERO) || !payoutCurvePiece.c.eq(F64.ZERO))
|
|
347
334
|
throw Error('b and c HyperbolaPayoutCurvePiece values must be 0');
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
eventDescriptor
|
|
352
|
-
)
|
|
335
|
+
// Cast to SingleOracleInfo to access announcement property
|
|
336
|
+
const singleOracleInfo = oracleInfo as SingleOracleInfo;
|
|
337
|
+
const eventDescriptor = singleOracleInfo.announcement.oracleEvent
|
|
338
|
+
.eventDescriptor as DigitDecompositionEventDescriptor;
|
|
339
|
+
if (eventDescriptor.type !== MessageType.DigitDecompositionEventDescriptor)
|
|
353
340
|
throw Error('Only DigitDecomposition Oracle Events supported');
|
|
354
341
|
|
|
355
342
|
const roundingIntervals = contractDescriptor.roundingIntervals;
|
|
@@ -372,13 +359,13 @@ export default class BitcoinDlcProvider
|
|
|
372
359
|
});
|
|
373
360
|
});
|
|
374
361
|
|
|
375
|
-
const rValuesMessagesList = this.GenerateMessages(
|
|
362
|
+
const rValuesMessagesList = this.GenerateMessages(singleOracleInfo);
|
|
376
363
|
|
|
377
364
|
const { payouts, messagesList } = outputsToPayouts(
|
|
378
365
|
payoutGroups,
|
|
379
366
|
rValuesMessagesList,
|
|
380
|
-
dlcOffer.
|
|
381
|
-
dlcOffer.contractInfo.totalCollateral - dlcOffer.
|
|
367
|
+
dlcOffer.offerCollateral,
|
|
368
|
+
dlcOffer.contractInfo.totalCollateral - dlcOffer.offerCollateral,
|
|
382
369
|
true,
|
|
383
370
|
);
|
|
384
371
|
|
|
@@ -386,30 +373,23 @@ export default class BitcoinDlcProvider
|
|
|
386
373
|
}
|
|
387
374
|
|
|
388
375
|
private GetPayoutsFromPolynomialPayoutFunction(
|
|
389
|
-
|
|
390
|
-
contractDescriptor:
|
|
391
|
-
oracleInfo:
|
|
376
|
+
dlcOffer: DlcOffer,
|
|
377
|
+
contractDescriptor: NumericalDescriptor,
|
|
378
|
+
oracleInfo: SingleOracleInfo,
|
|
392
379
|
totalCollateral: bigint,
|
|
393
380
|
): GetPayoutsResponse {
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
const dlcOffer = _dlcOffer as DlcOfferV0;
|
|
397
|
-
if (contractDescriptor.payoutFunction.type !== MessageType.PayoutFunctionV0)
|
|
398
|
-
throw Error('PayoutFunction must be V0');
|
|
399
|
-
const payoutFunction = contractDescriptor.payoutFunction as PayoutFunctionV0;
|
|
400
|
-
if (payoutFunction.pieces.length === 0)
|
|
381
|
+
const payoutFunction = contractDescriptor.payoutFunction as PayoutFunction;
|
|
382
|
+
if (payoutFunction.payoutFunctionPieces.length === 0)
|
|
401
383
|
throw Error('PayoutFunction must have at least once PayoutCurvePiece');
|
|
402
|
-
for (const piece of payoutFunction.
|
|
384
|
+
for (const piece of payoutFunction.payoutFunctionPieces) {
|
|
403
385
|
if (
|
|
404
386
|
piece.payoutCurvePiece.type !== MessageType.PolynomialPayoutCurvePiece
|
|
405
387
|
)
|
|
406
388
|
throw Error('Must be PolynomialPayoutCurvePiece');
|
|
407
389
|
}
|
|
408
390
|
const eventDescriptor = oracleInfo.announcement.oracleEvent
|
|
409
|
-
.eventDescriptor as
|
|
410
|
-
if (
|
|
411
|
-
eventDescriptor.type !== MessageType.DigitDecompositionEventDescriptorV0
|
|
412
|
-
)
|
|
391
|
+
.eventDescriptor as DigitDecompositionEventDescriptor;
|
|
392
|
+
if (eventDescriptor.type !== MessageType.DigitDecompositionEventDescriptor)
|
|
413
393
|
throw Error('Only DigitDecomposition Oracle Events supported');
|
|
414
394
|
|
|
415
395
|
const roundingIntervals = contractDescriptor.roundingIntervals;
|
|
@@ -437,17 +417,15 @@ export default class BitcoinDlcProvider
|
|
|
437
417
|
const { payouts, messagesList } = outputsToPayouts(
|
|
438
418
|
payoutGroups,
|
|
439
419
|
rValuesMessagesList,
|
|
440
|
-
dlcOffer.
|
|
441
|
-
dlcOffer.contractInfo.totalCollateral - dlcOffer.
|
|
420
|
+
dlcOffer.offerCollateral,
|
|
421
|
+
dlcOffer.contractInfo.totalCollateral - dlcOffer.offerCollateral,
|
|
442
422
|
true,
|
|
443
423
|
);
|
|
444
424
|
|
|
445
425
|
return { payouts, payoutGroups, messagesList };
|
|
446
426
|
}
|
|
447
427
|
|
|
448
|
-
private GetPayouts(
|
|
449
|
-
const { dlcOffer } = checkTypes({ _dlcOffer });
|
|
450
|
-
|
|
428
|
+
private GetPayouts(dlcOffer: DlcOffer): GetPayoutsResponse[] {
|
|
451
429
|
const contractInfo = dlcOffer.contractInfo;
|
|
452
430
|
const totalCollateral = contractInfo.totalCollateral;
|
|
453
431
|
const contractOraclePairs = this.GetContractOraclePairs(contractInfo);
|
|
@@ -493,70 +471,90 @@ export default class BitcoinDlcProvider
|
|
|
493
471
|
);
|
|
494
472
|
}
|
|
495
473
|
|
|
474
|
+
private GetPayoutsFromEnumeratedDescriptor(
|
|
475
|
+
dlcOffer: DlcOffer,
|
|
476
|
+
contractDescriptor: EnumeratedDescriptor,
|
|
477
|
+
oracleInfo: OracleInfo,
|
|
478
|
+
totalCollateral: bigint,
|
|
479
|
+
): GetPayoutsResponse {
|
|
480
|
+
const payoutGroups: PayoutGroup[] = [];
|
|
481
|
+
const rValuesMessagesList = this.GenerateMessages(
|
|
482
|
+
oracleInfo as SingleOracleInfo,
|
|
483
|
+
);
|
|
484
|
+
|
|
485
|
+
// For enumerated descriptors, each outcome creates one payout
|
|
486
|
+
// Each outcome maps to one index in the oracle's possible outcomes
|
|
487
|
+
contractDescriptor.outcomes.forEach((outcome, index) => {
|
|
488
|
+
payoutGroups.push({
|
|
489
|
+
payout: outcome.localPayout,
|
|
490
|
+
groups: [[index]], // Simple index-based grouping for enum outcomes
|
|
491
|
+
});
|
|
492
|
+
});
|
|
493
|
+
|
|
494
|
+
const { payouts, messagesList } = outputsToPayouts(
|
|
495
|
+
payoutGroups,
|
|
496
|
+
rValuesMessagesList,
|
|
497
|
+
dlcOffer.offerCollateral,
|
|
498
|
+
totalCollateral - dlcOffer.offerCollateral,
|
|
499
|
+
true,
|
|
500
|
+
);
|
|
501
|
+
|
|
502
|
+
return { payouts, payoutGroups, messagesList };
|
|
503
|
+
}
|
|
504
|
+
|
|
496
505
|
private GetPayoutsFromContractDescriptor(
|
|
497
|
-
dlcOffer:
|
|
506
|
+
dlcOffer: DlcOffer,
|
|
498
507
|
contractDescriptor: ContractDescriptor,
|
|
499
|
-
oracleInfo:
|
|
508
|
+
oracleInfo: OracleInfo,
|
|
500
509
|
totalCollateral: bigint,
|
|
501
510
|
) {
|
|
502
|
-
switch (contractDescriptor.
|
|
503
|
-
case
|
|
504
|
-
|
|
511
|
+
switch (contractDescriptor.contractDescriptorType) {
|
|
512
|
+
case ContractDescriptorType.Enumerated: {
|
|
513
|
+
return this.GetPayoutsFromEnumeratedDescriptor(
|
|
514
|
+
dlcOffer,
|
|
515
|
+
contractDescriptor as EnumeratedDescriptor,
|
|
516
|
+
oracleInfo,
|
|
517
|
+
totalCollateral,
|
|
518
|
+
);
|
|
505
519
|
}
|
|
506
|
-
case
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
case MessageType.PolynomialPayoutCurvePiece:
|
|
530
|
-
return this.GetPayoutsFromPolynomialPayoutFunction(
|
|
531
|
-
dlcOffer,
|
|
532
|
-
contractDescriptor as ContractDescriptorV1,
|
|
533
|
-
oracleInfo,
|
|
534
|
-
totalCollateral,
|
|
535
|
-
);
|
|
536
|
-
}
|
|
520
|
+
case ContractDescriptorType.NumericOutcome: {
|
|
521
|
+
const numericalDescriptor = contractDescriptor as NumericalDescriptor;
|
|
522
|
+
const payoutFunction = numericalDescriptor.payoutFunction;
|
|
523
|
+
|
|
524
|
+
// TODO: add a better check for this
|
|
525
|
+
const payoutCurvePiece =
|
|
526
|
+
payoutFunction.payoutFunctionPieces[0].payoutCurvePiece;
|
|
527
|
+
|
|
528
|
+
switch (payoutCurvePiece.payoutCurvePieceType) {
|
|
529
|
+
case PayoutCurvePieceType.Hyperbola:
|
|
530
|
+
return this.GetPayoutsFromPayoutFunction(
|
|
531
|
+
dlcOffer,
|
|
532
|
+
numericalDescriptor,
|
|
533
|
+
oracleInfo,
|
|
534
|
+
totalCollateral,
|
|
535
|
+
);
|
|
536
|
+
case PayoutCurvePieceType.Polynomial:
|
|
537
|
+
return this.GetPayoutsFromPolynomialPayoutFunction(
|
|
538
|
+
dlcOffer,
|
|
539
|
+
numericalDescriptor,
|
|
540
|
+
oracleInfo as SingleOracleInfo,
|
|
541
|
+
totalCollateral,
|
|
542
|
+
);
|
|
537
543
|
}
|
|
538
|
-
break;
|
|
539
|
-
default: {
|
|
540
|
-
throw Error('ContractDescriptor must be V0 or V1');
|
|
541
544
|
}
|
|
542
545
|
}
|
|
543
546
|
}
|
|
544
547
|
|
|
545
548
|
public async createDlcTxs(
|
|
546
|
-
|
|
547
|
-
|
|
549
|
+
dlcOffer: DlcOffer,
|
|
550
|
+
dlcAccept: DlcAccept,
|
|
548
551
|
): Promise<CreateDlcTxsResponse> {
|
|
549
|
-
const
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
const
|
|
555
|
-
const remoteFundPubkey = dlcAccept.fundingPubKey.toString('hex');
|
|
556
|
-
const localFinalScriptPubkey = dlcOffer.payoutSPK.toString('hex');
|
|
557
|
-
const remoteFinalScriptPubkey = dlcAccept.payoutSPK.toString('hex');
|
|
558
|
-
const localChangeScriptPubkey = dlcOffer.changeSPK.toString('hex');
|
|
559
|
-
const remoteChangeScriptPubkey = dlcAccept.changeSPK.toString('hex');
|
|
552
|
+
const localFundPubkey = dlcOffer.fundingPubkey.toString('hex');
|
|
553
|
+
const remoteFundPubkey = dlcAccept.fundingPubkey.toString('hex');
|
|
554
|
+
const localFinalScriptPubkey = dlcOffer.payoutSpk.toString('hex');
|
|
555
|
+
const remoteFinalScriptPubkey = dlcAccept.payoutSpk.toString('hex');
|
|
556
|
+
const localChangeScriptPubkey = dlcOffer.changeSpk.toString('hex');
|
|
557
|
+
const remoteChangeScriptPubkey = dlcAccept.changeSpk.toString('hex');
|
|
560
558
|
|
|
561
559
|
const localInputs: Utxo[] = await Promise.all(
|
|
562
560
|
dlcOffer.fundingInputs.map(async (fundingInput) => {
|
|
@@ -586,27 +584,27 @@ export default class BitcoinDlcProvider
|
|
|
586
584
|
let messagesList: Messages[] = [];
|
|
587
585
|
|
|
588
586
|
if (
|
|
589
|
-
dlcOffer.contractInfo.type === MessageType.
|
|
590
|
-
(dlcOffer.contractInfo as
|
|
591
|
-
|
|
587
|
+
dlcOffer.contractInfo.type === MessageType.SingleContractInfo &&
|
|
588
|
+
(dlcOffer.contractInfo as SingleContractInfo).contractDescriptor.type ===
|
|
589
|
+
ContractDescriptorType.Enumerated
|
|
592
590
|
) {
|
|
593
|
-
for (const outcome of (
|
|
594
|
-
.
|
|
591
|
+
for (const outcome of (
|
|
592
|
+
(dlcOffer.contractInfo as SingleContractInfo)
|
|
593
|
+
.contractDescriptor as EnumeratedDescriptor
|
|
594
|
+
).outcomes) {
|
|
595
595
|
payouts.push({
|
|
596
596
|
local: outcome.localPayout,
|
|
597
597
|
remote:
|
|
598
|
-
dlcOffer.
|
|
599
|
-
dlcAccept.
|
|
598
|
+
dlcOffer.offerCollateral +
|
|
599
|
+
dlcAccept.acceptCollateral -
|
|
600
600
|
outcome.localPayout,
|
|
601
601
|
});
|
|
602
|
-
messagesList.push({ messages: [outcome.outcome
|
|
602
|
+
messagesList.push({ messages: [outcome.outcome] });
|
|
603
603
|
}
|
|
604
604
|
} else {
|
|
605
605
|
const payoutResponses = this.GetPayouts(dlcOffer);
|
|
606
|
-
const {
|
|
607
|
-
|
|
608
|
-
messagesList: tempMessagesList,
|
|
609
|
-
} = this.FlattenPayouts(payoutResponses);
|
|
606
|
+
const { payouts: tempPayouts, messagesList: tempMessagesList } =
|
|
607
|
+
this.FlattenPayouts(payoutResponses);
|
|
610
608
|
payouts = tempPayouts;
|
|
611
609
|
messagesList = tempMessagesList;
|
|
612
610
|
}
|
|
@@ -618,11 +616,11 @@ export default class BitcoinDlcProvider
|
|
|
618
616
|
remoteFundPubkey,
|
|
619
617
|
remoteFinalScriptPubkey,
|
|
620
618
|
localInputAmount,
|
|
621
|
-
localCollateralAmount: dlcOffer.
|
|
619
|
+
localCollateralAmount: dlcOffer.offerCollateral,
|
|
622
620
|
localPayoutSerialId: dlcOffer.payoutSerialId,
|
|
623
621
|
localChangeSerialId: dlcOffer.changeSerialId,
|
|
624
622
|
remoteInputAmount,
|
|
625
|
-
remoteCollateralAmount: dlcAccept.
|
|
623
|
+
remoteCollateralAmount: dlcAccept.acceptCollateral,
|
|
626
624
|
remotePayoutSerialId: dlcAccept.payoutSerialId,
|
|
627
625
|
remoteChangeSerialId: dlcAccept.changeSerialId,
|
|
628
626
|
refundLocktime: dlcOffer.refundLocktime,
|
|
@@ -637,7 +635,7 @@ export default class BitcoinDlcProvider
|
|
|
637
635
|
|
|
638
636
|
const dlcTxs = await this.CreateDlcTransactions(dlcTxRequest);
|
|
639
637
|
|
|
640
|
-
const dlcTransactions = new
|
|
638
|
+
const dlcTransactions = new DlcTransactions();
|
|
641
639
|
dlcTransactions.fundTx = Tx.decode(StreamReader.fromHex(dlcTxs.fundTxHex));
|
|
642
640
|
dlcTransactions.fundTxVout = [
|
|
643
641
|
BigInt(dlcOffer.changeSerialId),
|
|
@@ -657,30 +655,23 @@ export default class BitcoinDlcProvider
|
|
|
657
655
|
}
|
|
658
656
|
|
|
659
657
|
public async createBatchDlcTxs(
|
|
660
|
-
|
|
661
|
-
|
|
658
|
+
dlcOffers: DlcOffer[],
|
|
659
|
+
dlcAccepts: DlcAccept[],
|
|
662
660
|
): Promise<CreateBatchDlcTxsResponse> {
|
|
663
|
-
const dlcOffers = _dlcOffers.map((dlcOffer) => {
|
|
664
|
-
return checkTypes({ _dlcOffer: dlcOffer }).dlcOffer;
|
|
665
|
-
});
|
|
666
|
-
const dlcAccepts = _dlcAccepts.map((dlcAccept) => {
|
|
667
|
-
return checkTypes({ _dlcAccept: dlcAccept }).dlcAccept;
|
|
668
|
-
});
|
|
669
|
-
|
|
670
661
|
const localFundPubkeys = dlcOffers.map((dlcOffer) =>
|
|
671
|
-
dlcOffer.
|
|
662
|
+
dlcOffer.fundingPubkey.toString('hex'),
|
|
672
663
|
);
|
|
673
664
|
const remoteFundPubkeys = dlcAccepts.map((dlcAccept) =>
|
|
674
|
-
dlcAccept.
|
|
665
|
+
dlcAccept.fundingPubkey.toString('hex'),
|
|
675
666
|
);
|
|
676
667
|
const localFinalScriptPubkeys = dlcOffers.map((dlcOffer) =>
|
|
677
|
-
dlcOffer.
|
|
668
|
+
dlcOffer.payoutSpk.toString('hex'),
|
|
678
669
|
);
|
|
679
670
|
const remoteFinalScriptPubkeys = dlcAccepts.map((dlcAccept) =>
|
|
680
|
-
dlcAccept.
|
|
671
|
+
dlcAccept.payoutSpk.toString('hex'),
|
|
681
672
|
);
|
|
682
|
-
const localChangeScriptPubkey = dlcOffers[0].
|
|
683
|
-
const remoteChangeScriptPubkey = dlcAccepts[0].
|
|
673
|
+
const localChangeScriptPubkey = dlcOffers[0].changeSpk.toString('hex');
|
|
674
|
+
const remoteChangeScriptPubkey = dlcAccepts[0].changeSpk.toString('hex');
|
|
684
675
|
|
|
685
676
|
const localInputs: Utxo[] = await Promise.all(
|
|
686
677
|
dlcOffers[0].fundingInputs.map(async (fundingInput) => {
|
|
@@ -734,7 +725,7 @@ export default class BitcoinDlcProvider
|
|
|
734
725
|
remoteFinalScriptPubkeys,
|
|
735
726
|
localInputAmount,
|
|
736
727
|
localCollateralAmounts: dlcOffers.map(
|
|
737
|
-
(dlcOffer) => dlcOffer.
|
|
728
|
+
(dlcOffer) => dlcOffer.offerCollateral,
|
|
738
729
|
),
|
|
739
730
|
localPayoutSerialIds: dlcOffers.map(
|
|
740
731
|
(dlcOffer) => dlcOffer.payoutSerialId,
|
|
@@ -742,7 +733,7 @@ export default class BitcoinDlcProvider
|
|
|
742
733
|
localChangeSerialId: dlcOffers[0].changeSerialId,
|
|
743
734
|
remoteInputAmount,
|
|
744
735
|
remoteCollateralAmounts: dlcAccepts.map(
|
|
745
|
-
(dlcAccept) => dlcAccept.
|
|
736
|
+
(dlcAccept) => dlcAccept.acceptCollateral,
|
|
746
737
|
),
|
|
747
738
|
remotePayoutSerialIds: dlcAccepts.map(
|
|
748
739
|
(dlcAccept) => dlcAccept.payoutSerialId,
|
|
@@ -762,11 +753,11 @@ export default class BitcoinDlcProvider
|
|
|
762
753
|
|
|
763
754
|
const dlcTxs = await this.CreateBatchDlcTransactions(batchDlcTxRequest);
|
|
764
755
|
|
|
765
|
-
const dlcTransactionsList:
|
|
756
|
+
const dlcTransactionsList: DlcTransactions[] = [];
|
|
766
757
|
|
|
767
758
|
let start = 0;
|
|
768
759
|
for (let i = 0; i < dlcTxs.refundTxHexList.length; i++) {
|
|
769
|
-
const dlcTransactions = new
|
|
760
|
+
const dlcTransactions = new DlcTransactions();
|
|
770
761
|
|
|
771
762
|
dlcTransactions.fundTx = Tx.decode(
|
|
772
763
|
StreamReader.fromHex(dlcTxs.fundTxHex),
|
|
@@ -800,15 +791,27 @@ export default class BitcoinDlcProvider
|
|
|
800
791
|
return { dlcTransactionsList, nestedMessagesList };
|
|
801
792
|
}
|
|
802
793
|
|
|
803
|
-
private GenerateEnumMessages(oracleEvent:
|
|
804
|
-
|
|
794
|
+
private GenerateEnumMessages(oracleEvent: OracleEvent): Messages[] {
|
|
795
|
+
const eventDescriptor = oracleEvent.eventDescriptor as EnumEventDescriptor;
|
|
796
|
+
|
|
797
|
+
// For enum events, each oracle has one nonce and can attest to one of the possible outcomes
|
|
798
|
+
const messagesList: Messages[] = [];
|
|
799
|
+
|
|
800
|
+
// For enum events, hash the outcomes to match the contract descriptor format
|
|
801
|
+
const messages = eventDescriptor.outcomes.map((outcome) =>
|
|
802
|
+
sha256(Buffer.from(outcome)).toString('hex'),
|
|
803
|
+
);
|
|
804
|
+
messagesList.push({ messages });
|
|
805
|
+
|
|
806
|
+
return messagesList;
|
|
805
807
|
}
|
|
806
808
|
|
|
807
809
|
private GenerateDigitDecompositionMessages(
|
|
808
|
-
oracleEvent:
|
|
810
|
+
oracleEvent: OracleEvent,
|
|
809
811
|
): Messages[] {
|
|
810
812
|
const oracleNonces = oracleEvent.oracleNonces;
|
|
811
|
-
const eventDescriptor =
|
|
813
|
+
const eventDescriptor =
|
|
814
|
+
oracleEvent.eventDescriptor as DigitDecompositionEventDescriptor;
|
|
812
815
|
|
|
813
816
|
const messagesList: Messages[] = [];
|
|
814
817
|
oracleNonces.forEach(() => {
|
|
@@ -823,13 +826,31 @@ export default class BitcoinDlcProvider
|
|
|
823
826
|
return messagesList;
|
|
824
827
|
}
|
|
825
828
|
|
|
826
|
-
private GenerateMessages(oracleInfo:
|
|
827
|
-
|
|
829
|
+
private GenerateMessages(oracleInfo: OracleInfo): Messages[] {
|
|
830
|
+
// Handle both SingleOracleInfo and MultiOracleInfo using type property instead of instanceof
|
|
831
|
+
let oracleEvent: OracleEvent;
|
|
832
|
+
|
|
833
|
+
if (oracleInfo.type === MessageType.SingleOracleInfo) {
|
|
834
|
+
const singleOracleInfo = oracleInfo as SingleOracleInfo;
|
|
835
|
+
oracleEvent = singleOracleInfo.announcement.oracleEvent;
|
|
836
|
+
} else if (oracleInfo.type === MessageType.MultiOracleInfo) {
|
|
837
|
+
const multiOracleInfo = oracleInfo as MultiOracleInfo;
|
|
838
|
+
// For multi-oracle, use the first announcement for now
|
|
839
|
+
// TODO: This might need more sophisticated handling for multi-oracle scenarios
|
|
840
|
+
if (multiOracleInfo.announcements.length === 0) {
|
|
841
|
+
throw Error('MultiOracleInfo must have at least one announcement');
|
|
842
|
+
}
|
|
843
|
+
oracleEvent = multiOracleInfo.announcements[0].oracleEvent;
|
|
844
|
+
} else {
|
|
845
|
+
throw Error(
|
|
846
|
+
`OracleInfo must be SingleOracleInfo or MultiOracleInfo, got type: ${oracleInfo.type}`,
|
|
847
|
+
);
|
|
848
|
+
}
|
|
828
849
|
|
|
829
850
|
switch (oracleEvent.eventDescriptor.type) {
|
|
830
|
-
case MessageType.
|
|
851
|
+
case MessageType.EnumEventDescriptor:
|
|
831
852
|
return this.GenerateEnumMessages(oracleEvent);
|
|
832
|
-
case MessageType.
|
|
853
|
+
case MessageType.DigitDecompositionEventDescriptor:
|
|
833
854
|
return this.GenerateDigitDecompositionMessages(oracleEvent);
|
|
834
855
|
default:
|
|
835
856
|
throw Error('EventDescriptor must be Enum or DigitDecomposition');
|
|
@@ -838,22 +859,21 @@ export default class BitcoinDlcProvider
|
|
|
838
859
|
|
|
839
860
|
private GetContractOraclePairs(
|
|
840
861
|
_contractInfo: ContractInfo,
|
|
841
|
-
): { contractDescriptor: ContractDescriptor; oracleInfo:
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
throw Error('ContractInfo must be V0 or V1');
|
|
862
|
+
): { contractDescriptor: ContractDescriptor; oracleInfo: OracleInfo }[] {
|
|
863
|
+
// Use contractInfoType property instead of instanceof for more reliable type checking
|
|
864
|
+
if (_contractInfo.contractInfoType === ContractInfoType.Single) {
|
|
865
|
+
const singleInfo = _contractInfo as SingleContractInfo;
|
|
866
|
+
return [
|
|
867
|
+
{
|
|
868
|
+
contractDescriptor: singleInfo.contractDescriptor,
|
|
869
|
+
oracleInfo: singleInfo.oracleInfo,
|
|
870
|
+
},
|
|
871
|
+
];
|
|
872
|
+
} else if (_contractInfo.contractInfoType === ContractInfoType.Disjoint) {
|
|
873
|
+
const disjointInfo = _contractInfo as DisjointContractInfo;
|
|
874
|
+
return disjointInfo.contractOraclePairs;
|
|
875
|
+
} else {
|
|
876
|
+
throw Error('ContractInfo must be Single or Disjoint');
|
|
857
877
|
}
|
|
858
878
|
}
|
|
859
879
|
|
|
@@ -874,7 +894,7 @@ export default class BitcoinDlcProvider
|
|
|
874
894
|
const cetsHex = dlcTxs.cets.map((cet) => cet.serialize().toString('hex'));
|
|
875
895
|
|
|
876
896
|
const fundingSPK = Script.p2wpkhLock(
|
|
877
|
-
hash160(isOfferer ? dlcOffer.
|
|
897
|
+
hash160(isOfferer ? dlcOffer.fundingPubkey : dlcAccept.fundingPubkey),
|
|
878
898
|
)
|
|
879
899
|
.serialize()
|
|
880
900
|
.slice(1);
|
|
@@ -898,12 +918,16 @@ export default class BitcoinDlcProvider
|
|
|
898
918
|
const sigs: ISig[][] = [];
|
|
899
919
|
|
|
900
920
|
if (
|
|
901
|
-
dlcOffer.contractInfo.
|
|
902
|
-
(dlcOffer.contractInfo as
|
|
921
|
+
dlcOffer.contractInfo.contractInfoType === ContractInfoType.Single &&
|
|
922
|
+
(dlcOffer.contractInfo as SingleContractInfo).contractDescriptor.type ===
|
|
903
923
|
MessageType.ContractDescriptorV0
|
|
904
924
|
) {
|
|
905
925
|
for (const [_, { oracleInfo }] of contractOraclePairs.entries()) {
|
|
906
|
-
|
|
926
|
+
if (oracleInfo.type !== MessageType.SingleOracleInfo) {
|
|
927
|
+
throw new Error('Only SingleOracleInfo supported in this context');
|
|
928
|
+
}
|
|
929
|
+
const oracleAnnouncement = (oracleInfo as SingleOracleInfo)
|
|
930
|
+
.announcement;
|
|
907
931
|
|
|
908
932
|
const adaptorSigRequestPromises: Promise<AdaptorPair[]>[] = [];
|
|
909
933
|
|
|
@@ -916,8 +940,8 @@ export default class BitcoinDlcProvider
|
|
|
916
940
|
privkey: fundPrivateKey,
|
|
917
941
|
fundTxId: dlcTxs.fundTx.txId.toString(),
|
|
918
942
|
fundVout: dlcTxs.fundTxVout,
|
|
919
|
-
localFundPubkey: dlcOffer.
|
|
920
|
-
remoteFundPubkey: dlcAccept.
|
|
943
|
+
localFundPubkey: dlcOffer.fundingPubkey.toString('hex'),
|
|
944
|
+
remoteFundPubkey: dlcAccept.fundingPubkey.toString('hex'),
|
|
921
945
|
fundInputAmount: dlcTxs.fundTx.outputs[dlcTxs.fundTxVout].value.sats,
|
|
922
946
|
oraclePubkey: oracleAnnouncement.oraclePubkey.toString('hex'),
|
|
923
947
|
oracleRValues: oracleAnnouncement.oracleEvent.oracleNonces.map(
|
|
@@ -927,9 +951,8 @@ export default class BitcoinDlcProvider
|
|
|
927
951
|
|
|
928
952
|
adaptorSigRequestPromises.push(
|
|
929
953
|
(async () => {
|
|
930
|
-
const response =
|
|
931
|
-
cetSignRequest
|
|
932
|
-
);
|
|
954
|
+
const response =
|
|
955
|
+
await this.CreateCetAdaptorSignatures(cetSignRequest);
|
|
933
956
|
return response.adaptorPairs;
|
|
934
957
|
})(),
|
|
935
958
|
);
|
|
@@ -951,7 +974,11 @@ export default class BitcoinDlcProvider
|
|
|
951
974
|
const indices = this.GetIndicesFromPayouts(this.GetPayouts(_dlcOffer));
|
|
952
975
|
|
|
953
976
|
for (const [index, { oracleInfo }] of contractOraclePairs.entries()) {
|
|
954
|
-
|
|
977
|
+
if (oracleInfo.type !== MessageType.SingleOracleInfo) {
|
|
978
|
+
throw new Error('Only SingleOracleInfo supported in this context');
|
|
979
|
+
}
|
|
980
|
+
const oracleAnnouncement = (oracleInfo as SingleOracleInfo)
|
|
981
|
+
.announcement;
|
|
955
982
|
|
|
956
983
|
const startingIndex = indices[index].startingMessagesIndex,
|
|
957
984
|
endingIndex = indices[index + 1].startingMessagesIndex;
|
|
@@ -975,8 +1002,8 @@ export default class BitcoinDlcProvider
|
|
|
975
1002
|
privkey: fundPrivateKey,
|
|
976
1003
|
fundTxId: dlcTxs.fundTx.txId.toString(),
|
|
977
1004
|
fundVout: dlcTxs.fundTxVout,
|
|
978
|
-
localFundPubkey: dlcOffer.
|
|
979
|
-
remoteFundPubkey: dlcAccept.
|
|
1005
|
+
localFundPubkey: dlcOffer.fundingPubkey.toString('hex'),
|
|
1006
|
+
remoteFundPubkey: dlcAccept.fundingPubkey.toString('hex'),
|
|
980
1007
|
fundInputAmount:
|
|
981
1008
|
dlcTxs.fundTx.outputs[dlcTxs.fundTxVout].value.sats,
|
|
982
1009
|
oraclePubkey: oracleAnnouncement.oraclePubkey.toString('hex'),
|
|
@@ -987,9 +1014,8 @@ export default class BitcoinDlcProvider
|
|
|
987
1014
|
|
|
988
1015
|
adaptorSigRequestPromises.push(
|
|
989
1016
|
(async () => {
|
|
990
|
-
const response =
|
|
991
|
-
cetSignRequest
|
|
992
|
-
);
|
|
1017
|
+
const response =
|
|
1018
|
+
await this.CreateCetAdaptorSignatures(cetSignRequest);
|
|
993
1019
|
return response.adaptorPairs;
|
|
994
1020
|
})(),
|
|
995
1021
|
);
|
|
@@ -1015,8 +1041,8 @@ export default class BitcoinDlcProvider
|
|
|
1015
1041
|
privkey: fundPrivateKey,
|
|
1016
1042
|
fundTxId: dlcTxs.fundTx.txId.toString(),
|
|
1017
1043
|
fundVout: dlcTxs.fundTxVout,
|
|
1018
|
-
localFundPubkey: dlcOffer.
|
|
1019
|
-
remoteFundPubkey: dlcAccept.
|
|
1044
|
+
localFundPubkey: dlcOffer.fundingPubkey.toString('hex'),
|
|
1045
|
+
remoteFundPubkey: dlcAccept.fundingPubkey.toString('hex'),
|
|
1020
1046
|
fundInputAmount: dlcTxs.fundTx.outputs[dlcTxs.fundTxVout].value.sats,
|
|
1021
1047
|
};
|
|
1022
1048
|
|
|
@@ -1025,7 +1051,7 @@ export default class BitcoinDlcProvider
|
|
|
1025
1051
|
'hex',
|
|
1026
1052
|
);
|
|
1027
1053
|
|
|
1028
|
-
const cetSignatures = new
|
|
1054
|
+
const cetSignatures = new CetAdaptorSignatures();
|
|
1029
1055
|
cetSignatures.sigs = sigs.flat();
|
|
1030
1056
|
|
|
1031
1057
|
return { cetSignatures, refundSignature };
|
|
@@ -1053,17 +1079,21 @@ export default class BitcoinDlcProvider
|
|
|
1053
1079
|
);
|
|
1054
1080
|
|
|
1055
1081
|
if (
|
|
1056
|
-
dlcOffer.contractInfo.type === MessageType.
|
|
1057
|
-
(dlcOffer.contractInfo as
|
|
1082
|
+
dlcOffer.contractInfo.type === MessageType.SingleContractInfo &&
|
|
1083
|
+
(dlcOffer.contractInfo as SingleContractInfo).contractDescriptor.type ===
|
|
1058
1084
|
MessageType.ContractDescriptorV0
|
|
1059
1085
|
) {
|
|
1060
1086
|
for (const [_, { oracleInfo }] of contractOraclePairs.entries()) {
|
|
1061
|
-
|
|
1087
|
+
if (oracleInfo.type !== MessageType.SingleOracleInfo) {
|
|
1088
|
+
throw new Error('Only SingleOracleInfo supported in this context');
|
|
1089
|
+
}
|
|
1090
|
+
const oracleAnnouncement = (oracleInfo as SingleOracleInfo)
|
|
1091
|
+
.announcement;
|
|
1062
1092
|
|
|
1063
1093
|
const oracleEventCetsHex = cetsHex;
|
|
1064
1094
|
const oracleEventSigs = isOfferer
|
|
1065
|
-
? dlcAccept.
|
|
1066
|
-
: dlcSign.
|
|
1095
|
+
? dlcAccept.cetAdaptorSignatures.sigs
|
|
1096
|
+
: dlcSign.cetAdaptorSignatures.sigs;
|
|
1067
1097
|
|
|
1068
1098
|
const sigsValidity: Promise<boolean>[] = [];
|
|
1069
1099
|
|
|
@@ -1077,21 +1107,23 @@ export default class BitcoinDlcProvider
|
|
|
1077
1107
|
};
|
|
1078
1108
|
});
|
|
1079
1109
|
|
|
1080
|
-
const verifyCetAdaptorSignaturesRequest: VerifyCetAdaptorSignaturesRequest =
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1110
|
+
const verifyCetAdaptorSignaturesRequest: VerifyCetAdaptorSignaturesRequest =
|
|
1111
|
+
{
|
|
1112
|
+
cetsHex: tempCetsHex,
|
|
1113
|
+
messagesList: tempMessagesList,
|
|
1114
|
+
oraclePubkey: oracleAnnouncement.oraclePubkey.toString('hex'),
|
|
1115
|
+
oracleRValues: oracleAnnouncement.oracleEvent.oracleNonces.map(
|
|
1116
|
+
(nonce) => nonce.toString('hex'),
|
|
1117
|
+
),
|
|
1118
|
+
adaptorPairs: tempAdaptorPairs,
|
|
1119
|
+
localFundPubkey: dlcOffer.fundingPubkey.toString('hex'),
|
|
1120
|
+
remoteFundPubkey: dlcAccept.fundingPubkey.toString('hex'),
|
|
1121
|
+
fundTxId: dlcTxs.fundTx.txId.toString(),
|
|
1122
|
+
fundVout: dlcTxs.fundTxVout,
|
|
1123
|
+
fundInputAmount:
|
|
1124
|
+
dlcTxs.fundTx.outputs[dlcTxs.fundTxVout].value.sats,
|
|
1125
|
+
verifyRemote: isOfferer,
|
|
1126
|
+
};
|
|
1095
1127
|
|
|
1096
1128
|
sigsValidity.push(
|
|
1097
1129
|
(async () => {
|
|
@@ -1109,8 +1141,8 @@ export default class BitcoinDlcProvider
|
|
|
1109
1141
|
signature: isOfferer
|
|
1110
1142
|
? dlcAccept.refundSignature.toString('hex')
|
|
1111
1143
|
: dlcSign.refundSignature.toString('hex'),
|
|
1112
|
-
localFundPubkey: dlcOffer.
|
|
1113
|
-
remoteFundPubkey: dlcAccept.
|
|
1144
|
+
localFundPubkey: dlcOffer.fundingPubkey.toString('hex'),
|
|
1145
|
+
remoteFundPubkey: dlcAccept.fundingPubkey.toString('hex'),
|
|
1114
1146
|
fundTxId: dlcTxs.fundTx.txId.toString(),
|
|
1115
1147
|
fundVout: dlcTxs.fundTxVout,
|
|
1116
1148
|
fundInputAmount: dlcTxs.fundTx.outputs[dlcTxs.fundTxVout].value.sats,
|
|
@@ -1131,7 +1163,11 @@ export default class BitcoinDlcProvider
|
|
|
1131
1163
|
const indices = this.GetIndicesFromPayouts(this.GetPayouts(_dlcOffer));
|
|
1132
1164
|
|
|
1133
1165
|
for (const [index, { oracleInfo }] of contractOraclePairs.entries()) {
|
|
1134
|
-
|
|
1166
|
+
if (oracleInfo.type !== MessageType.SingleOracleInfo) {
|
|
1167
|
+
throw new Error('Only SingleOracleInfo supported in this context');
|
|
1168
|
+
}
|
|
1169
|
+
const oracleAnnouncement = (oracleInfo as SingleOracleInfo)
|
|
1170
|
+
.announcement;
|
|
1135
1171
|
|
|
1136
1172
|
const startingIndex = indices[index].startingMessagesIndex,
|
|
1137
1173
|
endingIndex = indices[index + 1].startingMessagesIndex;
|
|
@@ -1141,9 +1177,10 @@ export default class BitcoinDlcProvider
|
|
|
1141
1177
|
endingIndex,
|
|
1142
1178
|
);
|
|
1143
1179
|
const oracleEventCetsHex = cetsHex.slice(startingIndex, endingIndex);
|
|
1144
|
-
const oracleEventSigs = (
|
|
1145
|
-
|
|
1146
|
-
|
|
1180
|
+
const oracleEventSigs = (
|
|
1181
|
+
isOfferer
|
|
1182
|
+
? dlcAccept.cetAdaptorSignatures.sigs
|
|
1183
|
+
: dlcSign.cetAdaptorSignatures.sigs
|
|
1147
1184
|
).slice(startingIndex, endingIndex);
|
|
1148
1185
|
|
|
1149
1186
|
const sigsValidity: Promise<boolean>[] = [];
|
|
@@ -1159,22 +1196,23 @@ export default class BitcoinDlcProvider
|
|
|
1159
1196
|
};
|
|
1160
1197
|
});
|
|
1161
1198
|
|
|
1162
|
-
const verifyCetAdaptorSignaturesRequest: VerifyCetAdaptorSignaturesRequest =
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1199
|
+
const verifyCetAdaptorSignaturesRequest: VerifyCetAdaptorSignaturesRequest =
|
|
1200
|
+
{
|
|
1201
|
+
cetsHex: tempCetsHex,
|
|
1202
|
+
messagesList: tempMessagesList,
|
|
1203
|
+
oraclePubkey: oracleAnnouncement.oraclePubkey.toString('hex'),
|
|
1204
|
+
oracleRValues: oracleAnnouncement.oracleEvent.oracleNonces.map(
|
|
1205
|
+
(nonce) => nonce.toString('hex'),
|
|
1206
|
+
),
|
|
1207
|
+
adaptorPairs: tempAdaptorPairs,
|
|
1208
|
+
localFundPubkey: dlcOffer.fundingPubkey.toString('hex'),
|
|
1209
|
+
remoteFundPubkey: dlcAccept.fundingPubkey.toString('hex'),
|
|
1210
|
+
fundTxId: dlcTxs.fundTx.txId.toString(),
|
|
1211
|
+
fundVout: dlcTxs.fundTxVout,
|
|
1212
|
+
fundInputAmount:
|
|
1213
|
+
dlcTxs.fundTx.outputs[dlcTxs.fundTxVout].value.sats,
|
|
1214
|
+
verifyRemote: isOfferer,
|
|
1215
|
+
};
|
|
1178
1216
|
|
|
1179
1217
|
sigsValidity.push(
|
|
1180
1218
|
(async () => {
|
|
@@ -1193,8 +1231,8 @@ export default class BitcoinDlcProvider
|
|
|
1193
1231
|
signature: isOfferer
|
|
1194
1232
|
? dlcAccept.refundSignature.toString('hex')
|
|
1195
1233
|
: dlcSign.refundSignature.toString('hex'),
|
|
1196
|
-
localFundPubkey: dlcOffer.
|
|
1197
|
-
remoteFundPubkey: dlcAccept.
|
|
1234
|
+
localFundPubkey: dlcOffer.fundingPubkey.toString('hex'),
|
|
1235
|
+
remoteFundPubkey: dlcAccept.fundingPubkey.toString('hex'),
|
|
1198
1236
|
fundTxId: dlcTxs.fundTx.txId.toString(),
|
|
1199
1237
|
fundVout: dlcTxs.fundTxVout,
|
|
1200
1238
|
fundInputAmount: dlcTxs.fundTx.outputs[dlcTxs.fundTxVout].value.sats,
|
|
@@ -1217,7 +1255,7 @@ export default class BitcoinDlcProvider
|
|
|
1217
1255
|
_dlcAccept: DlcAccept,
|
|
1218
1256
|
_dlcTxs: DlcTransactions,
|
|
1219
1257
|
isOfferer: boolean,
|
|
1220
|
-
): Promise<
|
|
1258
|
+
): Promise<FundingSignatures> {
|
|
1221
1259
|
const { dlcOffer, dlcAccept, dlcTxs } = checkTypes({
|
|
1222
1260
|
_dlcOffer,
|
|
1223
1261
|
_dlcAccept,
|
|
@@ -1271,26 +1309,19 @@ export default class BitcoinDlcProvider
|
|
|
1271
1309
|
witnessElements.push([sigWitness, pubKeyWitness]);
|
|
1272
1310
|
}
|
|
1273
1311
|
|
|
1274
|
-
const fundingSignatures = new
|
|
1312
|
+
const fundingSignatures = new FundingSignatures();
|
|
1275
1313
|
fundingSignatures.witnessElements = witnessElements;
|
|
1276
1314
|
|
|
1277
1315
|
return fundingSignatures;
|
|
1278
1316
|
}
|
|
1279
1317
|
|
|
1280
1318
|
private async VerifyFundingSigs(
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1319
|
+
dlcOffer: DlcOffer,
|
|
1320
|
+
dlcAccept: DlcAccept,
|
|
1321
|
+
dlcSign: DlcSign,
|
|
1322
|
+
dlcTxs: DlcTransactions,
|
|
1285
1323
|
isOfferer: boolean,
|
|
1286
1324
|
): Promise<void> {
|
|
1287
|
-
const { dlcOffer, dlcAccept, dlcSign, dlcTxs } = checkTypes({
|
|
1288
|
-
_dlcOffer,
|
|
1289
|
-
_dlcAccept,
|
|
1290
|
-
_dlcSign,
|
|
1291
|
-
_dlcTxs,
|
|
1292
|
-
});
|
|
1293
|
-
|
|
1294
1325
|
const sigsValidity: Promise<boolean>[] = [];
|
|
1295
1326
|
for (let i = 0; i < dlcSign.fundingSignatures.witnessElements.length; i++) {
|
|
1296
1327
|
const witnessElement = dlcSign.fundingSignatures.witnessElements[i];
|
|
@@ -1298,8 +1329,8 @@ export default class BitcoinDlcProvider
|
|
|
1298
1329
|
const pubkey = witnessElement[1].witness.toString('hex');
|
|
1299
1330
|
|
|
1300
1331
|
const fundingInput = isOfferer
|
|
1301
|
-
? (dlcAccept.fundingInputs[i] as
|
|
1302
|
-
: (dlcOffer.fundingInputs[i] as
|
|
1332
|
+
? (dlcAccept.fundingInputs[i] as FundingInput)
|
|
1333
|
+
: (dlcOffer.fundingInputs[i] as FundingInput);
|
|
1303
1334
|
|
|
1304
1335
|
const verifyFundSigRequest: VerifyFundTxSignatureRequest = {
|
|
1305
1336
|
fundTxHex: dlcTxs.fundTx.serialize().toString('hex'),
|
|
@@ -1313,9 +1344,8 @@ export default class BitcoinDlcProvider
|
|
|
1313
1344
|
|
|
1314
1345
|
sigsValidity.push(
|
|
1315
1346
|
(async () => {
|
|
1316
|
-
const response =
|
|
1317
|
-
verifyFundSigRequest
|
|
1318
|
-
);
|
|
1347
|
+
const response =
|
|
1348
|
+
await this.VerifyFundTxSignature(verifyFundSigRequest);
|
|
1319
1349
|
return response.valid;
|
|
1320
1350
|
})(),
|
|
1321
1351
|
);
|
|
@@ -1329,19 +1359,12 @@ export default class BitcoinDlcProvider
|
|
|
1329
1359
|
}
|
|
1330
1360
|
|
|
1331
1361
|
private async CreateFundingTx(
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
fundingSignatures:
|
|
1362
|
+
dlcOffer: DlcOffer,
|
|
1363
|
+
dlcAccept: DlcAccept,
|
|
1364
|
+
dlcSign: DlcSign,
|
|
1365
|
+
dlcTxs: DlcTransactions,
|
|
1366
|
+
fundingSignatures: FundingSignatures,
|
|
1337
1367
|
): Promise<Tx> {
|
|
1338
|
-
const { dlcOffer, dlcAccept, dlcSign, dlcTxs } = checkTypes({
|
|
1339
|
-
_dlcOffer,
|
|
1340
|
-
_dlcAccept,
|
|
1341
|
-
_dlcSign,
|
|
1342
|
-
_dlcTxs,
|
|
1343
|
-
});
|
|
1344
|
-
|
|
1345
1368
|
const witnessElements = [
|
|
1346
1369
|
...dlcSign.fundingSignatures.witnessElements,
|
|
1347
1370
|
...fundingSignatures.witnessElements,
|
|
@@ -1359,7 +1382,7 @@ export default class BitcoinDlcProvider
|
|
|
1359
1382
|
const signature = witnessElement[0].witness.toString('hex');
|
|
1360
1383
|
const pubkey = witnessElement[1].witness.toString('hex');
|
|
1361
1384
|
|
|
1362
|
-
const fundingInput = fundingInputs[i] as
|
|
1385
|
+
const fundingInput = fundingInputs[i] as FundingInput;
|
|
1363
1386
|
|
|
1364
1387
|
const addSignRequest: AddSignatureToFundTransactionRequest = {
|
|
1365
1388
|
fundTxHex,
|
|
@@ -1379,15 +1402,13 @@ export default class BitcoinDlcProvider
|
|
|
1379
1402
|
}
|
|
1380
1403
|
|
|
1381
1404
|
async FindOutcomeIndexFromPolynomialPayoutCurvePiece(
|
|
1382
|
-
|
|
1383
|
-
contractDescriptor:
|
|
1405
|
+
dlcOffer: DlcOffer,
|
|
1406
|
+
contractDescriptor: NumericalDescriptor,
|
|
1384
1407
|
contractOraclePairIndex: number,
|
|
1385
1408
|
polynomialPayoutCurvePiece: PolynomialPayoutCurvePiece,
|
|
1386
|
-
oracleAttestation:
|
|
1409
|
+
oracleAttestation: OracleAttestation,
|
|
1387
1410
|
outcome: bigint,
|
|
1388
1411
|
): Promise<FindOutcomeResponse> {
|
|
1389
|
-
const { dlcOffer } = checkTypes({ _dlcOffer });
|
|
1390
|
-
|
|
1391
1412
|
const polynomialCurve = PolynomialPayoutCurve.fromPayoutCurvePiece(
|
|
1392
1413
|
polynomialPayoutCurvePiece,
|
|
1393
1414
|
);
|
|
@@ -1404,9 +1425,9 @@ export default class BitcoinDlcProvider
|
|
|
1404
1425
|
const payout = clampBN(polynomialCurve.getPayout(outcome));
|
|
1405
1426
|
|
|
1406
1427
|
const payoutResponses = this.GetPayouts(dlcOffer);
|
|
1407
|
-
const payoutIndexOffset =
|
|
1408
|
-
contractOraclePairIndex
|
|
1409
|
-
|
|
1428
|
+
const payoutIndexOffset =
|
|
1429
|
+
this.GetIndicesFromPayouts(payoutResponses)[contractOraclePairIndex]
|
|
1430
|
+
.startingMessagesIndex;
|
|
1410
1431
|
|
|
1411
1432
|
const { payoutGroups } = payoutResponses[contractOraclePairIndex];
|
|
1412
1433
|
|
|
@@ -1461,10 +1482,10 @@ Payout Group not found',
|
|
|
1461
1482
|
|
|
1462
1483
|
async FindOutcomeIndexFromHyperbolaPayoutCurvePiece(
|
|
1463
1484
|
_dlcOffer: DlcOffer,
|
|
1464
|
-
contractDescriptor:
|
|
1485
|
+
contractDescriptor: NumericalDescriptor,
|
|
1465
1486
|
contractOraclePairIndex: number,
|
|
1466
1487
|
hyperbolaPayoutCurvePiece: HyperbolaPayoutCurvePiece,
|
|
1467
|
-
oracleAttestation:
|
|
1488
|
+
oracleAttestation: OracleAttestation,
|
|
1468
1489
|
outcome: bigint,
|
|
1469
1490
|
): Promise<FindOutcomeResponse> {
|
|
1470
1491
|
const { dlcOffer } = checkTypes({ _dlcOffer });
|
|
@@ -1482,9 +1503,9 @@ Payout Group not found',
|
|
|
1482
1503
|
const payout = clampBN(hyperbolaCurve.getPayout(outcome));
|
|
1483
1504
|
|
|
1484
1505
|
const payoutResponses = this.GetPayouts(dlcOffer);
|
|
1485
|
-
const payoutIndexOffset =
|
|
1486
|
-
contractOraclePairIndex
|
|
1487
|
-
|
|
1506
|
+
const payoutIndexOffset =
|
|
1507
|
+
this.GetIndicesFromPayouts(payoutResponses)[contractOraclePairIndex]
|
|
1508
|
+
.startingMessagesIndex;
|
|
1488
1509
|
|
|
1489
1510
|
const { payoutGroups } = payoutResponses[contractOraclePairIndex];
|
|
1490
1511
|
|
|
@@ -1545,31 +1566,52 @@ Payout Group not found',
|
|
|
1545
1566
|
}
|
|
1546
1567
|
|
|
1547
1568
|
if (groupIndex === -1) {
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1569
|
+
// Fallback to brute force search if payout-based search fails
|
|
1570
|
+
index = 0;
|
|
1571
|
+
groupLength = 0;
|
|
1572
|
+
|
|
1573
|
+
for (const [i, payoutGroup] of payoutGroups.entries()) {
|
|
1574
|
+
groupIndex = payoutGroup.groups.findIndex((group) => {
|
|
1575
|
+
return group.every((msg, j) => msg === outcomesFormatted[j]);
|
|
1576
|
+
});
|
|
1577
|
+
|
|
1578
|
+
if (groupIndex !== -1) {
|
|
1579
|
+
index += groupIndex;
|
|
1580
|
+
groupLength = payoutGroup.groups[groupIndex].length;
|
|
1581
|
+
break;
|
|
1582
|
+
} else {
|
|
1583
|
+
index += payoutGroup.groups.length;
|
|
1584
|
+
}
|
|
1585
|
+
}
|
|
1586
|
+
|
|
1587
|
+
if (groupIndex === -1) {
|
|
1588
|
+
throw Error(
|
|
1589
|
+
'Failed to Find OutcomeIndex From HyperbolaPayoutCurvePiece. \
|
|
1590
|
+
Payout Group not found even with brute force search',
|
|
1591
|
+
);
|
|
1592
|
+
}
|
|
1552
1593
|
}
|
|
1553
1594
|
|
|
1554
1595
|
return { index: payoutIndexOffset + index, groupLength };
|
|
1555
1596
|
}
|
|
1556
1597
|
|
|
1557
1598
|
async FindOutcomeIndex(
|
|
1558
|
-
|
|
1559
|
-
oracleAttestation:
|
|
1599
|
+
dlcOffer: DlcOffer,
|
|
1600
|
+
oracleAttestation: OracleAttestation,
|
|
1560
1601
|
): Promise<FindOutcomeResponse> {
|
|
1561
|
-
const { dlcOffer } = checkTypes({ _dlcOffer });
|
|
1562
|
-
|
|
1563
1602
|
const contractOraclePairs = this.GetContractOraclePairs(
|
|
1564
1603
|
dlcOffer.contractInfo,
|
|
1565
1604
|
);
|
|
1566
|
-
|
|
1567
1605
|
const contractOraclePairIndex = contractOraclePairs.findIndex(
|
|
1568
|
-
({ oracleInfo }) =>
|
|
1569
|
-
oracleInfo.
|
|
1570
|
-
|
|
1606
|
+
({ oracleInfo }) => {
|
|
1607
|
+
if (oracleInfo.type !== MessageType.SingleOracleInfo) return false;
|
|
1608
|
+
const singleOracleInfo = oracleInfo as SingleOracleInfo;
|
|
1609
|
+
return (
|
|
1610
|
+
singleOracleInfo.announcement.oracleEvent.eventId ===
|
|
1611
|
+
oracleAttestation.eventId
|
|
1612
|
+
);
|
|
1613
|
+
},
|
|
1571
1614
|
);
|
|
1572
|
-
|
|
1573
1615
|
assert(
|
|
1574
1616
|
contractOraclePairIndex !== -1,
|
|
1575
1617
|
'OracleAttestation must be for an existing OracleEvent',
|
|
@@ -1577,39 +1619,42 @@ Payout Group not found',
|
|
|
1577
1619
|
|
|
1578
1620
|
const contractOraclePair = contractOraclePairs[contractOraclePairIndex];
|
|
1579
1621
|
|
|
1580
|
-
const {
|
|
1581
|
-
|
|
1582
|
-
oracleInfo,
|
|
1583
|
-
} = contractOraclePair;
|
|
1584
|
-
|
|
1622
|
+
const { contractDescriptor: _contractDescriptor, oracleInfo } =
|
|
1623
|
+
contractOraclePair;
|
|
1585
1624
|
assert(
|
|
1586
|
-
_contractDescriptor.
|
|
1587
|
-
|
|
1625
|
+
_contractDescriptor.contractDescriptorType ===
|
|
1626
|
+
ContractDescriptorType.NumericOutcome,
|
|
1627
|
+
'ContractDescriptor must be NumericOutcome',
|
|
1588
1628
|
);
|
|
1589
|
-
|
|
1590
|
-
const contractDescriptor = _contractDescriptor as ContractDescriptorV1;
|
|
1629
|
+
const contractDescriptor = _contractDescriptor as NumericalDescriptor;
|
|
1591
1630
|
const _payoutFunction = contractDescriptor.payoutFunction;
|
|
1592
|
-
|
|
1593
1631
|
assert(
|
|
1594
|
-
_payoutFunction.type === MessageType.
|
|
1632
|
+
_payoutFunction.type === MessageType.PayoutFunction,
|
|
1595
1633
|
'PayoutFunction must be V0',
|
|
1596
1634
|
);
|
|
1597
1635
|
|
|
1598
|
-
|
|
1599
|
-
|
|
1636
|
+
if (oracleInfo.type !== MessageType.SingleOracleInfo) {
|
|
1637
|
+
throw new Error('Only SingleOracleInfo supported in this context');
|
|
1638
|
+
}
|
|
1639
|
+
|
|
1640
|
+
const singleOracleInfo = oracleInfo as SingleOracleInfo;
|
|
1641
|
+
const eventDescriptor = singleOracleInfo.announcement.oracleEvent
|
|
1642
|
+
.eventDescriptor as DigitDecompositionEventDescriptor;
|
|
1600
1643
|
const payoutFunction = _payoutFunction as PayoutFunctionV0;
|
|
1601
1644
|
|
|
1602
1645
|
const base = eventDescriptor.base;
|
|
1603
|
-
|
|
1604
1646
|
const outcome: number = [...oracleAttestation.outcomes]
|
|
1605
1647
|
.reverse()
|
|
1606
1648
|
.reduce((acc, val, i) => acc + Number(val) * base ** i, 0);
|
|
1607
1649
|
|
|
1608
|
-
const piecesSorted = payoutFunction.
|
|
1609
|
-
(a, b) =>
|
|
1650
|
+
const piecesSorted = payoutFunction.payoutFunctionPieces.sort(
|
|
1651
|
+
(a, b) =>
|
|
1652
|
+
Number(a.endPoint.eventOutcome) - Number(b.endPoint.eventOutcome),
|
|
1610
1653
|
);
|
|
1611
1654
|
|
|
1612
|
-
const piece = piecesSorted.find(
|
|
1655
|
+
const piece = piecesSorted.find(
|
|
1656
|
+
(piece) => outcome < piece.endPoint.eventOutcome,
|
|
1657
|
+
);
|
|
1613
1658
|
|
|
1614
1659
|
switch (piece.payoutCurvePiece.type) {
|
|
1615
1660
|
case MessageType.PolynomialPayoutCurvePiece:
|
|
@@ -1645,30 +1690,34 @@ Payout Group not found',
|
|
|
1645
1690
|
}
|
|
1646
1691
|
|
|
1647
1692
|
ValidateEvent(
|
|
1648
|
-
|
|
1649
|
-
oracleAttestation:
|
|
1693
|
+
dlcOffer: DlcOffer,
|
|
1694
|
+
oracleAttestation: OracleAttestation,
|
|
1650
1695
|
): void {
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
case MessageType.ContractInfoV0: {
|
|
1657
|
-
const contractInfo = dlcOffer.contractInfo as ContractInfoV0;
|
|
1658
|
-
switch (contractInfo.contractDescriptor.type) {
|
|
1659
|
-
case MessageType.ContractDescriptorV0: {
|
|
1696
|
+
switch (dlcOffer.contractInfo.contractInfoType) {
|
|
1697
|
+
case ContractInfoType.Single: {
|
|
1698
|
+
const contractInfo = dlcOffer.contractInfo as SingleContractInfo;
|
|
1699
|
+
switch (contractInfo.contractDescriptor.contractDescriptorType) {
|
|
1700
|
+
case ContractDescriptorType.Enumerated: {
|
|
1660
1701
|
const oracleInfo = contractInfo.oracleInfo;
|
|
1702
|
+
if (oracleInfo.type !== MessageType.SingleOracleInfo) {
|
|
1703
|
+
throw Error('Only SingleOracleInfo supported in this context');
|
|
1704
|
+
}
|
|
1705
|
+
const singleOracleInfo = oracleInfo as SingleOracleInfo;
|
|
1661
1706
|
if (
|
|
1662
|
-
|
|
1707
|
+
singleOracleInfo.announcement.oracleEvent.eventId !==
|
|
1663
1708
|
oracleAttestation.eventId
|
|
1664
1709
|
)
|
|
1665
1710
|
throw Error('Incorrect Oracle Attestation. Event Id must match.');
|
|
1666
1711
|
break;
|
|
1667
1712
|
}
|
|
1668
|
-
case
|
|
1713
|
+
case ContractDescriptorType.NumericOutcome: {
|
|
1669
1714
|
const oracleInfo = contractInfo.oracleInfo;
|
|
1715
|
+
if (oracleInfo.type !== MessageType.SingleOracleInfo) {
|
|
1716
|
+
throw Error('Only SingleOracleInfo supported in this context');
|
|
1717
|
+
}
|
|
1718
|
+
const singleOracleInfo = oracleInfo as SingleOracleInfo;
|
|
1670
1719
|
if (
|
|
1671
|
-
|
|
1720
|
+
singleOracleInfo.announcement.oracleEvent.eventId !==
|
|
1672
1721
|
oracleAttestation.eventId
|
|
1673
1722
|
)
|
|
1674
1723
|
throw Error('Incorrect Oracle Attestation. Event Id must match.');
|
|
@@ -1679,12 +1728,17 @@ Payout Group not found',
|
|
|
1679
1728
|
}
|
|
1680
1729
|
break;
|
|
1681
1730
|
}
|
|
1682
|
-
case
|
|
1683
|
-
const contractInfo = dlcOffer.contractInfo as
|
|
1731
|
+
case ContractInfoType.Disjoint: {
|
|
1732
|
+
const contractInfo = dlcOffer.contractInfo as DisjointContractInfo;
|
|
1684
1733
|
const attestedOracleEvent = contractInfo.contractOraclePairs.find(
|
|
1685
|
-
({ oracleInfo }) =>
|
|
1686
|
-
oracleInfo.
|
|
1687
|
-
|
|
1734
|
+
({ oracleInfo }) => {
|
|
1735
|
+
if (oracleInfo.type !== MessageType.SingleOracleInfo) return false;
|
|
1736
|
+
const singleOracleInfo = oracleInfo as SingleOracleInfo;
|
|
1737
|
+
return (
|
|
1738
|
+
singleOracleInfo.announcement.oracleEvent.eventId ===
|
|
1739
|
+
oracleAttestation.eventId
|
|
1740
|
+
);
|
|
1741
|
+
},
|
|
1688
1742
|
);
|
|
1689
1743
|
|
|
1690
1744
|
if (!attestedOracleEvent)
|
|
@@ -1698,20 +1752,13 @@ Payout Group not found',
|
|
|
1698
1752
|
}
|
|
1699
1753
|
|
|
1700
1754
|
async FindAndSignCet(
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
oracleAttestation:
|
|
1755
|
+
dlcOffer: DlcOffer,
|
|
1756
|
+
dlcAccept: DlcAccept,
|
|
1757
|
+
dlcSign: DlcSign,
|
|
1758
|
+
dlcTxs: DlcTransactions,
|
|
1759
|
+
oracleAttestation: OracleAttestation,
|
|
1706
1760
|
isOfferer?: boolean,
|
|
1707
1761
|
): Promise<Tx> {
|
|
1708
|
-
const { dlcOffer, dlcAccept, dlcSign, dlcTxs } = checkTypes({
|
|
1709
|
-
_dlcOffer,
|
|
1710
|
-
_dlcAccept,
|
|
1711
|
-
_dlcSign,
|
|
1712
|
-
_dlcTxs,
|
|
1713
|
-
});
|
|
1714
|
-
|
|
1715
1762
|
if (isOfferer === undefined)
|
|
1716
1763
|
isOfferer = await this.isOfferer(dlcOffer, dlcAccept);
|
|
1717
1764
|
|
|
@@ -1724,14 +1771,16 @@ Payout Group not found',
|
|
|
1724
1771
|
let signCetRequest: SignCetRequest;
|
|
1725
1772
|
|
|
1726
1773
|
if (
|
|
1727
|
-
dlcOffer.contractInfo.
|
|
1728
|
-
(dlcOffer.contractInfo as
|
|
1729
|
-
|
|
1774
|
+
dlcOffer.contractInfo.contractInfoType === ContractInfoType.Single &&
|
|
1775
|
+
(dlcOffer.contractInfo as SingleContractInfo).contractDescriptor
|
|
1776
|
+
.contractDescriptorType === ContractDescriptorType.Enumerated
|
|
1730
1777
|
) {
|
|
1731
|
-
const outcomeIndex = (
|
|
1732
|
-
.
|
|
1778
|
+
const outcomeIndex = (
|
|
1779
|
+
(dlcOffer.contractInfo as SingleContractInfo)
|
|
1780
|
+
.contractDescriptor as EnumeratedDescriptor
|
|
1781
|
+
).outcomes.findIndex(
|
|
1733
1782
|
(outcome) =>
|
|
1734
|
-
outcome.outcome
|
|
1783
|
+
outcome.outcome ===
|
|
1735
1784
|
sha256(Buffer.from(oracleAttestation.outcomes[0])).toString('hex'),
|
|
1736
1785
|
);
|
|
1737
1786
|
|
|
@@ -1740,19 +1789,19 @@ Payout Group not found',
|
|
|
1740
1789
|
fundPrivkey: fundPrivateKey,
|
|
1741
1790
|
fundTxId: dlcTxs.fundTx.txId.toString(),
|
|
1742
1791
|
fundVout: dlcTxs.fundTxVout,
|
|
1743
|
-
localFundPubkey: dlcOffer.
|
|
1744
|
-
remoteFundPubkey: dlcAccept.
|
|
1792
|
+
localFundPubkey: dlcOffer.fundingPubkey.toString('hex'),
|
|
1793
|
+
remoteFundPubkey: dlcAccept.fundingPubkey.toString('hex'),
|
|
1745
1794
|
oracleSignatures: oracleAttestation.signatures.map((sig) =>
|
|
1746
1795
|
sig.toString('hex'),
|
|
1747
1796
|
),
|
|
1748
1797
|
fundInputAmount: dlcTxs.fundTx.outputs[dlcTxs.fundTxVout].value.sats,
|
|
1749
1798
|
adaptorSignature: isOfferer
|
|
1750
|
-
? dlcAccept.
|
|
1751
|
-
|
|
1752
|
-
)
|
|
1753
|
-
: dlcSign.
|
|
1754
|
-
|
|
1755
|
-
),
|
|
1799
|
+
? dlcAccept.cetAdaptorSignatures.sigs[
|
|
1800
|
+
outcomeIndex
|
|
1801
|
+
].encryptedSig.toString('hex')
|
|
1802
|
+
: dlcSign.cetAdaptorSignatures.sigs[
|
|
1803
|
+
outcomeIndex
|
|
1804
|
+
].encryptedSig.toString('hex'),
|
|
1756
1805
|
};
|
|
1757
1806
|
} else {
|
|
1758
1807
|
const { index: outcomeIndex, groupLength } = await this.FindOutcomeIndex(
|
|
@@ -1772,17 +1821,17 @@ Payout Group not found',
|
|
|
1772
1821
|
fundPrivkey: fundPrivateKey,
|
|
1773
1822
|
fundTxId: dlcTxs.fundTx.txId.toString(),
|
|
1774
1823
|
fundVout: dlcTxs.fundTxVout,
|
|
1775
|
-
localFundPubkey: dlcOffer.
|
|
1776
|
-
remoteFundPubkey: dlcAccept.
|
|
1824
|
+
localFundPubkey: dlcOffer.fundingPubkey.toString('hex'),
|
|
1825
|
+
remoteFundPubkey: dlcAccept.fundingPubkey.toString('hex'),
|
|
1777
1826
|
oracleSignatures: oracleSignatures.map((sig) => sig.toString('hex')),
|
|
1778
1827
|
fundInputAmount: dlcTxs.fundTx.outputs[dlcTxs.fundTxVout].value.sats,
|
|
1779
1828
|
adaptorSignature: isOfferer
|
|
1780
|
-
? dlcAccept.
|
|
1781
|
-
|
|
1782
|
-
)
|
|
1783
|
-
: dlcSign.
|
|
1784
|
-
|
|
1785
|
-
),
|
|
1829
|
+
? dlcAccept.cetAdaptorSignatures.sigs[
|
|
1830
|
+
outcomeIndex
|
|
1831
|
+
].encryptedSig.toString('hex')
|
|
1832
|
+
: dlcSign.cetAdaptorSignatures.sigs[
|
|
1833
|
+
outcomeIndex
|
|
1834
|
+
].encryptedSig.toString('hex'),
|
|
1786
1835
|
};
|
|
1787
1836
|
}
|
|
1788
1837
|
|
|
@@ -1792,14 +1841,14 @@ Payout Group not found',
|
|
|
1792
1841
|
}
|
|
1793
1842
|
|
|
1794
1843
|
private async GetFundAddress(
|
|
1795
|
-
dlcOffer:
|
|
1796
|
-
dlcAccept:
|
|
1844
|
+
dlcOffer: DlcOffer,
|
|
1845
|
+
dlcAccept: DlcAccept,
|
|
1797
1846
|
isOfferer: boolean,
|
|
1798
1847
|
): Promise<string> {
|
|
1799
1848
|
const network = await this.getConnectedNetwork();
|
|
1800
1849
|
|
|
1801
1850
|
const fundingSPK = Script.p2wpkhLock(
|
|
1802
|
-
hash160(isOfferer ? dlcOffer.
|
|
1851
|
+
hash160(isOfferer ? dlcOffer.fundingPubkey : dlcAccept.fundingPubkey),
|
|
1803
1852
|
)
|
|
1804
1853
|
.serialize()
|
|
1805
1854
|
.slice(1);
|
|
@@ -1813,8 +1862,8 @@ Payout Group not found',
|
|
|
1813
1862
|
}
|
|
1814
1863
|
|
|
1815
1864
|
private async GetFundKeyPair(
|
|
1816
|
-
dlcOffer:
|
|
1817
|
-
dlcAccept:
|
|
1865
|
+
dlcOffer: DlcOffer,
|
|
1866
|
+
dlcAccept: DlcAccept,
|
|
1818
1867
|
isOfferer: boolean,
|
|
1819
1868
|
): Promise<ECPairInterface> {
|
|
1820
1869
|
const fundingAddress = await this.GetFundAddress(
|
|
@@ -1823,19 +1872,17 @@ Payout Group not found',
|
|
|
1823
1872
|
isOfferer,
|
|
1824
1873
|
);
|
|
1825
1874
|
|
|
1826
|
-
const { derivationPath } =
|
|
1827
|
-
fundingAddress
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
derivationPath,
|
|
1831
|
-
);
|
|
1875
|
+
const { derivationPath } =
|
|
1876
|
+
await this.getMethod('getWalletAddress')(fundingAddress);
|
|
1877
|
+
const keyPair: ECPairInterface =
|
|
1878
|
+
await this.getMethod('keyPair')(derivationPath);
|
|
1832
1879
|
|
|
1833
1880
|
return keyPair;
|
|
1834
1881
|
}
|
|
1835
1882
|
|
|
1836
1883
|
private async GetFundPrivateKey(
|
|
1837
|
-
dlcOffer:
|
|
1838
|
-
dlcAccept:
|
|
1884
|
+
dlcOffer: DlcOffer,
|
|
1885
|
+
dlcAccept: DlcAccept,
|
|
1839
1886
|
isOfferer: boolean,
|
|
1840
1887
|
): Promise<string> {
|
|
1841
1888
|
const fundPrivateKeyPair: ECPairInterface = await this.GetFundKeyPair(
|
|
@@ -1848,28 +1895,23 @@ Payout Group not found',
|
|
|
1848
1895
|
}
|
|
1849
1896
|
|
|
1850
1897
|
async CreateCloseRawTxs(
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1898
|
+
dlcOffer: DlcOffer,
|
|
1899
|
+
dlcAccept: DlcAccept,
|
|
1900
|
+
dlcTxs: DlcTransactions,
|
|
1854
1901
|
closeInputAmount: bigint,
|
|
1855
1902
|
isOfferer: boolean,
|
|
1856
1903
|
_dlcCloses: DlcClose[] = [],
|
|
1857
1904
|
fundingInputs?: FundingInput[],
|
|
1858
1905
|
initiatorPayouts?: bigint[],
|
|
1859
1906
|
): Promise<string[]> {
|
|
1860
|
-
const { dlcOffer, dlcAccept, dlcTxs } = checkTypes({
|
|
1861
|
-
_dlcOffer,
|
|
1862
|
-
_dlcAccept,
|
|
1863
|
-
_dlcTxs,
|
|
1864
|
-
});
|
|
1865
1907
|
const network = await this.getConnectedNetwork();
|
|
1866
1908
|
|
|
1867
1909
|
let finalizer: DualClosingTxFinalizer;
|
|
1868
1910
|
if (_dlcCloses.length === 0) {
|
|
1869
1911
|
finalizer = new DualClosingTxFinalizer(
|
|
1870
1912
|
fundingInputs,
|
|
1871
|
-
dlcOffer.
|
|
1872
|
-
dlcAccept.
|
|
1913
|
+
dlcOffer.payoutSpk,
|
|
1914
|
+
dlcAccept.payoutSpk,
|
|
1873
1915
|
dlcOffer.feeRatePerVb,
|
|
1874
1916
|
);
|
|
1875
1917
|
}
|
|
@@ -1913,14 +1955,14 @@ Payout Group not found',
|
|
|
1913
1955
|
|
|
1914
1956
|
if (Number(offerPayoutValue) > 0) {
|
|
1915
1957
|
txOuts.push({
|
|
1916
|
-
address: address.fromOutputScript(dlcOffer.
|
|
1958
|
+
address: address.fromOutputScript(dlcOffer.payoutSpk, network),
|
|
1917
1959
|
amount: Number(offerPayoutValue),
|
|
1918
1960
|
});
|
|
1919
1961
|
}
|
|
1920
1962
|
|
|
1921
1963
|
if (Number(acceptPayoutValue) > 0) {
|
|
1922
1964
|
txOuts.push({
|
|
1923
|
-
address: address.fromOutputScript(dlcAccept.
|
|
1965
|
+
address: address.fromOutputScript(dlcAccept.payoutSpk, network),
|
|
1924
1966
|
amount: Number(acceptPayoutValue),
|
|
1925
1967
|
});
|
|
1926
1968
|
}
|
|
@@ -1972,9 +2014,9 @@ Payout Group not found',
|
|
|
1972
2014
|
const network = await this.getConnectedNetwork();
|
|
1973
2015
|
|
|
1974
2016
|
const fundingPubKeys =
|
|
1975
|
-
Buffer.compare(dlcOffer.
|
|
1976
|
-
? [dlcOffer.
|
|
1977
|
-
: [dlcAccept.
|
|
2017
|
+
Buffer.compare(dlcOffer.fundingPubkey, dlcAccept.fundingPubkey) === -1
|
|
2018
|
+
? [dlcOffer.fundingPubkey, dlcAccept.fundingPubkey]
|
|
2019
|
+
: [dlcAccept.fundingPubkey, dlcOffer.fundingPubkey];
|
|
1978
2020
|
|
|
1979
2021
|
const p2ms = payments.p2ms({
|
|
1980
2022
|
m: 2,
|
|
@@ -2083,9 +2125,9 @@ Payout Group not found',
|
|
|
2083
2125
|
const network = await this.getConnectedNetwork();
|
|
2084
2126
|
|
|
2085
2127
|
const fundingPubKeys =
|
|
2086
|
-
Buffer.compare(dlcOffer.
|
|
2087
|
-
? [dlcOffer.
|
|
2088
|
-
: [dlcAccept.
|
|
2128
|
+
Buffer.compare(dlcOffer.fundingPubkey, dlcAccept.fundingPubkey) === -1
|
|
2129
|
+
? [dlcOffer.fundingPubkey, dlcAccept.fundingPubkey]
|
|
2130
|
+
: [dlcAccept.fundingPubkey, dlcOffer.fundingPubkey];
|
|
2089
2131
|
|
|
2090
2132
|
const p2ms = payments.p2ms({
|
|
2091
2133
|
m: 2,
|
|
@@ -2098,7 +2140,7 @@ Payout Group not found',
|
|
|
2098
2140
|
network,
|
|
2099
2141
|
});
|
|
2100
2142
|
|
|
2101
|
-
const pubkey = isOfferer ? dlcAccept.
|
|
2143
|
+
const pubkey = isOfferer ? dlcAccept.fundingPubkey : dlcOffer.fundingPubkey;
|
|
2102
2144
|
|
|
2103
2145
|
const sigsValidity: Promise<boolean>[] = [];
|
|
2104
2146
|
|
|
@@ -2151,10 +2193,10 @@ Payout Group not found',
|
|
|
2151
2193
|
});
|
|
2152
2194
|
const network = await this.getConnectedNetwork();
|
|
2153
2195
|
|
|
2154
|
-
const offerFundingSPK = Script.p2wpkhLock(hash160(dlcOffer.
|
|
2196
|
+
const offerFundingSPK = Script.p2wpkhLock(hash160(dlcOffer.fundingPubkey))
|
|
2155
2197
|
.serialize()
|
|
2156
2198
|
.slice(1);
|
|
2157
|
-
const acceptFundingSPK = Script.p2wpkhLock(hash160(dlcAccept.
|
|
2199
|
+
const acceptFundingSPK = Script.p2wpkhLock(hash160(dlcAccept.fundingPubkey))
|
|
2158
2200
|
.serialize()
|
|
2159
2201
|
.slice(1);
|
|
2160
2202
|
|
|
@@ -2200,7 +2242,10 @@ Payout Group not found',
|
|
|
2200
2242
|
contractInfo.validate();
|
|
2201
2243
|
const network = await this.getConnectedNetwork();
|
|
2202
2244
|
|
|
2203
|
-
const dlcOffer = new
|
|
2245
|
+
const dlcOffer = new DlcOffer();
|
|
2246
|
+
|
|
2247
|
+
// Generate a random 32-byte temporary contract ID
|
|
2248
|
+
dlcOffer.temporaryContractId = crypto.randomBytes(32);
|
|
2204
2249
|
|
|
2205
2250
|
const {
|
|
2206
2251
|
fundingPubKey,
|
|
@@ -2217,13 +2262,13 @@ Payout Group not found',
|
|
|
2217
2262
|
|
|
2218
2263
|
_fundingInputs.forEach((input) =>
|
|
2219
2264
|
assert(
|
|
2220
|
-
input.type === MessageType.
|
|
2265
|
+
input.type === MessageType.FundingInput,
|
|
2221
2266
|
'FundingInput must be V0',
|
|
2222
2267
|
),
|
|
2223
2268
|
);
|
|
2224
2269
|
|
|
2225
|
-
const fundingInputs:
|
|
2226
|
-
(input) => input as
|
|
2270
|
+
const fundingInputs: FundingInput[] = _fundingInputs.map(
|
|
2271
|
+
(input) => input as FundingInput,
|
|
2227
2272
|
);
|
|
2228
2273
|
|
|
2229
2274
|
fundingInputs.sort(
|
|
@@ -2240,14 +2285,15 @@ Payout Group not found',
|
|
|
2240
2285
|
dlcOffer.contractFlags = Buffer.from('00', 'hex');
|
|
2241
2286
|
dlcOffer.chainHash = chainHashFromNetwork(network);
|
|
2242
2287
|
dlcOffer.contractInfo = contractInfo;
|
|
2243
|
-
dlcOffer.
|
|
2244
|
-
dlcOffer.
|
|
2288
|
+
dlcOffer.fundingPubkey = fundingPubKey;
|
|
2289
|
+
dlcOffer.payoutSpk = payoutSPK;
|
|
2245
2290
|
dlcOffer.payoutSerialId = payoutSerialId;
|
|
2246
|
-
dlcOffer.
|
|
2291
|
+
dlcOffer.offerCollateral = offerCollateralSatoshis;
|
|
2247
2292
|
dlcOffer.fundingInputs = fundingInputs;
|
|
2248
|
-
dlcOffer.
|
|
2293
|
+
dlcOffer.changeSpk = changeSPK;
|
|
2249
2294
|
dlcOffer.changeSerialId = changeSerialId;
|
|
2250
|
-
dlcOffer.fundOutputSerialId = dlcOffer.fundOutputSerialId =
|
|
2295
|
+
dlcOffer.fundOutputSerialId = dlcOffer.fundOutputSerialId =
|
|
2296
|
+
fundOutputSerialId;
|
|
2251
2297
|
dlcOffer.feeRatePerVb = feeRatePerVb;
|
|
2252
2298
|
dlcOffer.cetLocktime = cetLocktime;
|
|
2253
2299
|
dlcOffer.refundLocktime = refundLocktime;
|
|
@@ -2256,8 +2302,8 @@ Payout Group not found',
|
|
|
2256
2302
|
(() => {
|
|
2257
2303
|
const finalizer = new DualFundingTxFinalizer(
|
|
2258
2304
|
dlcOffer.fundingInputs,
|
|
2259
|
-
dlcOffer.
|
|
2260
|
-
dlcOffer.
|
|
2305
|
+
dlcOffer.payoutSpk,
|
|
2306
|
+
dlcOffer.changeSpk,
|
|
2261
2307
|
null,
|
|
2262
2308
|
null,
|
|
2263
2309
|
null,
|
|
@@ -2294,7 +2340,7 @@ Payout Group not found',
|
|
|
2294
2340
|
);
|
|
2295
2341
|
}
|
|
2296
2342
|
|
|
2297
|
-
const dlcOffers:
|
|
2343
|
+
const dlcOffers: DlcOffer[] = [];
|
|
2298
2344
|
|
|
2299
2345
|
for (let i = 0; i < contractInfos.length; i++) {
|
|
2300
2346
|
contractInfos[i].validate();
|
|
@@ -2311,13 +2357,13 @@ Payout Group not found',
|
|
|
2311
2357
|
|
|
2312
2358
|
_fundingInputs.forEach((input) =>
|
|
2313
2359
|
assert(
|
|
2314
|
-
input.type === MessageType.
|
|
2360
|
+
input.type === MessageType.FundingInput,
|
|
2315
2361
|
'FundingInput must be V0',
|
|
2316
2362
|
),
|
|
2317
2363
|
);
|
|
2318
2364
|
|
|
2319
|
-
const fundingInputs:
|
|
2320
|
-
(input) => input as
|
|
2365
|
+
const fundingInputs: FundingInput[] = _fundingInputs.map(
|
|
2366
|
+
(input) => input as FundingInput,
|
|
2321
2367
|
);
|
|
2322
2368
|
|
|
2323
2369
|
fundingInputs.sort(
|
|
@@ -2330,22 +2376,24 @@ Payout Group not found',
|
|
|
2330
2376
|
const contractInfo = contractInfos[i];
|
|
2331
2377
|
const offerCollateralSatoshis = offerCollaterals[i];
|
|
2332
2378
|
const fundOutputSerialId = fundOutputsSerialIds[i];
|
|
2333
|
-
const { fundingPubKey, payoutSPK, payoutSerialId } =
|
|
2334
|
-
i
|
|
2335
|
-
];
|
|
2379
|
+
const { fundingPubKey, payoutSPK, payoutSerialId } =
|
|
2380
|
+
initializeResponses[i];
|
|
2336
2381
|
const refundLocktime = refundLocktimes[i];
|
|
2337
2382
|
|
|
2338
|
-
const dlcOffer = new
|
|
2383
|
+
const dlcOffer = new DlcOffer();
|
|
2384
|
+
|
|
2385
|
+
// Generate a random 32-byte temporary contract ID
|
|
2386
|
+
dlcOffer.temporaryContractId = crypto.randomBytes(32);
|
|
2339
2387
|
|
|
2340
2388
|
dlcOffer.contractFlags = Buffer.from('00', 'hex');
|
|
2341
2389
|
dlcOffer.chainHash = chainHashFromNetwork(network);
|
|
2342
2390
|
dlcOffer.contractInfo = contractInfo;
|
|
2343
|
-
dlcOffer.
|
|
2344
|
-
dlcOffer.
|
|
2391
|
+
dlcOffer.fundingPubkey = fundingPubKey;
|
|
2392
|
+
dlcOffer.payoutSpk = payoutSPK;
|
|
2345
2393
|
dlcOffer.payoutSerialId = payoutSerialId;
|
|
2346
|
-
dlcOffer.
|
|
2394
|
+
dlcOffer.offerCollateral = offerCollateralSatoshis;
|
|
2347
2395
|
dlcOffer.fundingInputs = fundingInputs;
|
|
2348
|
-
dlcOffer.
|
|
2396
|
+
dlcOffer.changeSpk = changeSPK;
|
|
2349
2397
|
dlcOffer.changeSerialId = changeSerialId;
|
|
2350
2398
|
dlcOffer.fundOutputSerialId = fundOutputSerialId;
|
|
2351
2399
|
dlcOffer.feeRatePerVb = feeRatePerVb;
|
|
@@ -2356,8 +2404,8 @@ Payout Group not found',
|
|
|
2356
2404
|
(() => {
|
|
2357
2405
|
const finalizer = new DualFundingTxFinalizer(
|
|
2358
2406
|
dlcOffer.fundingInputs,
|
|
2359
|
-
dlcOffer.
|
|
2360
|
-
dlcOffer.
|
|
2407
|
+
dlcOffer.payoutSpk,
|
|
2408
|
+
dlcOffer.changeSpk,
|
|
2361
2409
|
null,
|
|
2362
2410
|
null,
|
|
2363
2411
|
null,
|
|
@@ -2394,12 +2442,11 @@ Payout Group not found',
|
|
|
2394
2442
|
dlcOffer.validate();
|
|
2395
2443
|
|
|
2396
2444
|
const acceptCollateralSatoshis =
|
|
2397
|
-
dlcOffer.contractInfo.totalCollateral - dlcOffer.
|
|
2445
|
+
dlcOffer.contractInfo.totalCollateral - dlcOffer.offerCollateral;
|
|
2398
2446
|
|
|
2399
2447
|
assert(
|
|
2400
2448
|
acceptCollateralSatoshis ===
|
|
2401
|
-
dlcOffer.contractInfo.totalCollateral -
|
|
2402
|
-
dlcOffer.offerCollateralSatoshis,
|
|
2449
|
+
dlcOffer.contractInfo.totalCollateral - dlcOffer.offerCollateral,
|
|
2403
2450
|
'acceptCollaterialSatoshis should equal totalCollateral - offerCollateralSatoshis',
|
|
2404
2451
|
);
|
|
2405
2452
|
|
|
@@ -2417,34 +2464,34 @@ Payout Group not found',
|
|
|
2417
2464
|
);
|
|
2418
2465
|
|
|
2419
2466
|
assert(
|
|
2420
|
-
Buffer.compare(dlcOffer.
|
|
2467
|
+
Buffer.compare(dlcOffer.fundingPubkey, fundingPubKey) !== 0,
|
|
2421
2468
|
'DlcOffer and DlcAccept FundingPubKey cannot be the same',
|
|
2422
2469
|
);
|
|
2423
2470
|
|
|
2424
2471
|
_fundingInputs.forEach((input) =>
|
|
2425
2472
|
assert(
|
|
2426
|
-
input.type === MessageType.
|
|
2473
|
+
input.type === MessageType.FundingInput,
|
|
2427
2474
|
'FundingInput must be V0',
|
|
2428
2475
|
),
|
|
2429
2476
|
);
|
|
2430
2477
|
|
|
2431
|
-
const fundingInputs:
|
|
2432
|
-
(input) => input as
|
|
2478
|
+
const fundingInputs: FundingInput[] = _fundingInputs.map(
|
|
2479
|
+
(input) => input as FundingInput,
|
|
2433
2480
|
);
|
|
2434
2481
|
|
|
2435
2482
|
fundingInputs.sort(
|
|
2436
2483
|
(a, b) => Number(a.inputSerialId) - Number(b.inputSerialId),
|
|
2437
2484
|
);
|
|
2438
2485
|
|
|
2439
|
-
const dlcAccept = new
|
|
2486
|
+
const dlcAccept = new DlcAccept();
|
|
2440
2487
|
|
|
2441
|
-
dlcAccept.
|
|
2442
|
-
dlcAccept.
|
|
2443
|
-
dlcAccept.
|
|
2444
|
-
dlcAccept.
|
|
2488
|
+
dlcAccept.temporaryContractId = sha256(dlcOffer.serialize());
|
|
2489
|
+
dlcAccept.acceptCollateral = acceptCollateralSatoshis;
|
|
2490
|
+
dlcAccept.fundingPubkey = fundingPubKey;
|
|
2491
|
+
dlcAccept.payoutSpk = payoutSPK;
|
|
2445
2492
|
dlcAccept.payoutSerialId = dlcAccept.payoutSerialId = payoutSerialId;
|
|
2446
2493
|
dlcAccept.fundingInputs = fundingInputs;
|
|
2447
|
-
dlcAccept.
|
|
2494
|
+
dlcAccept.changeSpk = changeSPK;
|
|
2448
2495
|
dlcAccept.changeSerialId = dlcAccept.changeSerialId = changeSerialId;
|
|
2449
2496
|
|
|
2450
2497
|
assert(
|
|
@@ -2475,11 +2522,11 @@ Payout Group not found',
|
|
|
2475
2522
|
(() => {
|
|
2476
2523
|
const finalizer = new DualFundingTxFinalizer(
|
|
2477
2524
|
dlcOffer.fundingInputs,
|
|
2478
|
-
dlcOffer.
|
|
2479
|
-
dlcOffer.
|
|
2525
|
+
dlcOffer.payoutSpk,
|
|
2526
|
+
dlcOffer.changeSpk,
|
|
2480
2527
|
dlcAccept.fundingInputs,
|
|
2481
|
-
dlcAccept.
|
|
2482
|
-
dlcAccept.
|
|
2528
|
+
dlcAccept.payoutSpk,
|
|
2529
|
+
dlcAccept.changeSpk,
|
|
2483
2530
|
dlcOffer.feeRatePerVb,
|
|
2484
2531
|
);
|
|
2485
2532
|
const funding = fundingInputs.reduce((total, input) => {
|
|
@@ -2496,32 +2543,25 @@ Payout Group not found',
|
|
|
2496
2543
|
dlcAccept,
|
|
2497
2544
|
);
|
|
2498
2545
|
|
|
2499
|
-
const {
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
false,
|
|
2508
|
-
);
|
|
2546
|
+
const { cetSignatures, refundSignature } =
|
|
2547
|
+
await this.CreateCetAdaptorAndRefundSigs(
|
|
2548
|
+
dlcOffer,
|
|
2549
|
+
dlcAccept,
|
|
2550
|
+
dlcTransactions,
|
|
2551
|
+
messagesList,
|
|
2552
|
+
false,
|
|
2553
|
+
);
|
|
2509
2554
|
|
|
2510
|
-
|
|
2511
|
-
dlcTransactions.type === MessageType.DlcTransactionsV0,
|
|
2512
|
-
'DlcTransactions must be V0',
|
|
2513
|
-
);
|
|
2514
|
-
const _dlcTransactions = dlcTransactions as DlcTransactionsV0;
|
|
2555
|
+
const _dlcTransactions = dlcTransactions;
|
|
2515
2556
|
|
|
2516
2557
|
const contractId = xor(
|
|
2517
2558
|
_dlcTransactions.fundTx.txId.serialize(),
|
|
2518
|
-
dlcAccept.
|
|
2559
|
+
dlcAccept.temporaryContractId,
|
|
2519
2560
|
);
|
|
2520
2561
|
_dlcTransactions.contractId = contractId;
|
|
2521
2562
|
|
|
2522
|
-
dlcAccept.
|
|
2563
|
+
dlcAccept.cetAdaptorSignatures = cetSignatures;
|
|
2523
2564
|
dlcAccept.refundSignature = refundSignature;
|
|
2524
|
-
dlcAccept.negotiationFields = new NegotiationFieldsV0();
|
|
2525
2565
|
|
|
2526
2566
|
return { dlcAccept, dlcTransactions: _dlcTransactions };
|
|
2527
2567
|
}
|
|
@@ -2538,8 +2578,7 @@ Payout Group not found',
|
|
|
2538
2578
|
|
|
2539
2579
|
const acceptCollaterals = dlcOffers.map(
|
|
2540
2580
|
(dlcOffer) =>
|
|
2541
|
-
dlcOffer.contractInfo.totalCollateral -
|
|
2542
|
-
dlcOffer.offerCollateralSatoshis,
|
|
2581
|
+
dlcOffer.contractInfo.totalCollateral - dlcOffer.offerCollateral,
|
|
2543
2582
|
);
|
|
2544
2583
|
|
|
2545
2584
|
const {
|
|
@@ -2559,7 +2598,7 @@ Payout Group not found',
|
|
|
2559
2598
|
initializeResponses.forEach((initializeResponse) => {
|
|
2560
2599
|
assert(
|
|
2561
2600
|
Buffer.compare(
|
|
2562
|
-
dlcOffer.
|
|
2601
|
+
dlcOffer.fundingPubkey,
|
|
2563
2602
|
initializeResponse.fundingPubKey,
|
|
2564
2603
|
) !== 0,
|
|
2565
2604
|
'DlcOffer and DlcAccept FundingPubKey cannot be the same',
|
|
@@ -2569,34 +2608,34 @@ Payout Group not found',
|
|
|
2569
2608
|
|
|
2570
2609
|
_fundingInputs.forEach((input) =>
|
|
2571
2610
|
assert(
|
|
2572
|
-
input.type === MessageType.
|
|
2611
|
+
input.type === MessageType.FundingInput,
|
|
2573
2612
|
'FundingInput must be V0',
|
|
2574
2613
|
),
|
|
2575
2614
|
);
|
|
2576
2615
|
|
|
2577
|
-
const fundingInputs:
|
|
2578
|
-
(input) => input as
|
|
2616
|
+
const fundingInputs: FundingInput[] = _fundingInputs.map(
|
|
2617
|
+
(input) => input as FundingInput,
|
|
2579
2618
|
);
|
|
2580
2619
|
|
|
2581
2620
|
fundingInputs.sort(
|
|
2582
2621
|
(a, b) => Number(a.inputSerialId) - Number(b.inputSerialId),
|
|
2583
2622
|
);
|
|
2584
2623
|
|
|
2585
|
-
const dlcAccepts:
|
|
2624
|
+
const dlcAccepts: DlcAccept[] = [];
|
|
2586
2625
|
|
|
2587
2626
|
initializeResponses.forEach((initializeResponse, i) => {
|
|
2588
2627
|
const dlcOffer = dlcOffers[i];
|
|
2589
|
-
const dlcAccept = new
|
|
2628
|
+
const dlcAccept = new DlcAccept();
|
|
2590
2629
|
|
|
2591
2630
|
const { fundingPubKey, payoutSPK, payoutSerialId } = initializeResponse;
|
|
2592
2631
|
|
|
2593
|
-
dlcAccept.
|
|
2594
|
-
dlcAccept.
|
|
2595
|
-
dlcAccept.
|
|
2596
|
-
dlcAccept.
|
|
2632
|
+
dlcAccept.temporaryContractId = sha256(dlcOffers[i].serialize());
|
|
2633
|
+
dlcAccept.acceptCollateral = acceptCollaterals[i];
|
|
2634
|
+
dlcAccept.fundingPubkey = fundingPubKey;
|
|
2635
|
+
dlcAccept.payoutSpk = payoutSPK;
|
|
2597
2636
|
dlcAccept.payoutSerialId = payoutSerialId;
|
|
2598
2637
|
dlcAccept.fundingInputs = fundingInputs;
|
|
2599
|
-
dlcAccept.
|
|
2638
|
+
dlcAccept.changeSpk = changeSPK;
|
|
2600
2639
|
dlcAccept.changeSerialId = changeSerialId;
|
|
2601
2640
|
|
|
2602
2641
|
assert(
|
|
@@ -2627,11 +2666,11 @@ Payout Group not found',
|
|
|
2627
2666
|
(() => {
|
|
2628
2667
|
const finalizer = new DualFundingTxFinalizer(
|
|
2629
2668
|
dlcOffer.fundingInputs,
|
|
2630
|
-
dlcOffer.
|
|
2631
|
-
dlcOffer.
|
|
2669
|
+
dlcOffer.payoutSpk,
|
|
2670
|
+
dlcOffer.changeSpk,
|
|
2632
2671
|
dlcAccept.fundingInputs,
|
|
2633
|
-
dlcAccept.
|
|
2634
|
-
dlcAccept.
|
|
2672
|
+
dlcAccept.payoutSpk,
|
|
2673
|
+
dlcAccept.changeSpk,
|
|
2635
2674
|
dlcOffer.feeRatePerVb,
|
|
2636
2675
|
);
|
|
2637
2676
|
const funding = fundingInputs.reduce((total, input) => {
|
|
@@ -2646,10 +2685,8 @@ Payout Group not found',
|
|
|
2646
2685
|
dlcAccepts.push(dlcAccept);
|
|
2647
2686
|
});
|
|
2648
2687
|
|
|
2649
|
-
const {
|
|
2650
|
-
|
|
2651
|
-
nestedMessagesList,
|
|
2652
|
-
} = await this.createBatchDlcTxs(dlcOffers, dlcAccepts);
|
|
2688
|
+
const { dlcTransactionsList, nestedMessagesList } =
|
|
2689
|
+
await this.createBatchDlcTxs(dlcOffers, dlcAccepts);
|
|
2653
2690
|
|
|
2654
2691
|
for (let i = 0; i < dlcAccepts.length; i++) {
|
|
2655
2692
|
const dlcOffer = dlcOffers[i];
|
|
@@ -2657,32 +2694,25 @@ Payout Group not found',
|
|
|
2657
2694
|
const dlcTransactions = dlcTransactionsList[i];
|
|
2658
2695
|
const messagesList = nestedMessagesList[i];
|
|
2659
2696
|
|
|
2660
|
-
const {
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
false,
|
|
2669
|
-
);
|
|
2697
|
+
const { cetSignatures, refundSignature } =
|
|
2698
|
+
await this.CreateCetAdaptorAndRefundSigs(
|
|
2699
|
+
dlcOffer,
|
|
2700
|
+
dlcAccept,
|
|
2701
|
+
dlcTransactions,
|
|
2702
|
+
messagesList,
|
|
2703
|
+
false,
|
|
2704
|
+
);
|
|
2670
2705
|
|
|
2671
|
-
|
|
2672
|
-
dlcTransactions.type === MessageType.DlcTransactionsV0,
|
|
2673
|
-
'DlcTransactions must be V0',
|
|
2674
|
-
);
|
|
2675
|
-
const _dlcTransactions = dlcTransactions as DlcTransactionsV0;
|
|
2706
|
+
const _dlcTransactions = dlcTransactions;
|
|
2676
2707
|
|
|
2677
2708
|
const contractId = xor(
|
|
2678
2709
|
_dlcTransactions.fundTx.txId.serialize(),
|
|
2679
|
-
dlcAccept.
|
|
2710
|
+
dlcAccept.temporaryContractId,
|
|
2680
2711
|
);
|
|
2681
2712
|
_dlcTransactions.contractId = contractId;
|
|
2682
2713
|
|
|
2683
|
-
dlcAccepts[i].
|
|
2714
|
+
dlcAccepts[i].cetAdaptorSignatures = cetSignatures;
|
|
2684
2715
|
dlcAccepts[i].refundSignature = refundSignature;
|
|
2685
|
-
dlcAccepts[i].negotiationFields = new NegotiationFieldsV0();
|
|
2686
2716
|
}
|
|
2687
2717
|
|
|
2688
2718
|
return { dlcAccepts, dlcTransactionsList };
|
|
@@ -2706,11 +2736,11 @@ Payout Group not found',
|
|
|
2706
2736
|
dlcAccept.validate();
|
|
2707
2737
|
|
|
2708
2738
|
assert(
|
|
2709
|
-
Buffer.compare(dlcOffer.
|
|
2739
|
+
Buffer.compare(dlcOffer.fundingPubkey, dlcAccept.fundingPubkey) !== 0,
|
|
2710
2740
|
'DlcOffer and DlcAccept FundingPubKey cannot be the same',
|
|
2711
2741
|
);
|
|
2712
2742
|
|
|
2713
|
-
const dlcSign = new
|
|
2743
|
+
const dlcSign = new DlcSign();
|
|
2714
2744
|
|
|
2715
2745
|
const { dlcTransactions, messagesList } = await this.createDlcTxs(
|
|
2716
2746
|
dlcOffer,
|
|
@@ -2726,16 +2756,14 @@ Payout Group not found',
|
|
|
2726
2756
|
true,
|
|
2727
2757
|
);
|
|
2728
2758
|
|
|
2729
|
-
const {
|
|
2730
|
-
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
|
|
2735
|
-
|
|
2736
|
-
|
|
2737
|
-
true,
|
|
2738
|
-
);
|
|
2759
|
+
const { cetSignatures, refundSignature } =
|
|
2760
|
+
await this.CreateCetAdaptorAndRefundSigs(
|
|
2761
|
+
dlcOffer,
|
|
2762
|
+
dlcAccept,
|
|
2763
|
+
dlcTransactions,
|
|
2764
|
+
messagesList,
|
|
2765
|
+
true,
|
|
2766
|
+
);
|
|
2739
2767
|
|
|
2740
2768
|
const fundingSignatures = await this.CreateFundingSigs(
|
|
2741
2769
|
dlcOffer,
|
|
@@ -2744,17 +2772,17 @@ Payout Group not found',
|
|
|
2744
2772
|
true,
|
|
2745
2773
|
);
|
|
2746
2774
|
|
|
2747
|
-
const dlcTxs = dlcTransactions
|
|
2775
|
+
const dlcTxs = dlcTransactions;
|
|
2748
2776
|
|
|
2749
2777
|
const contractId = xor(
|
|
2750
2778
|
dlcTxs.fundTx.txId.serialize(),
|
|
2751
|
-
dlcAccept.
|
|
2779
|
+
dlcAccept.temporaryContractId,
|
|
2752
2780
|
);
|
|
2753
2781
|
|
|
2754
2782
|
assert(
|
|
2755
2783
|
Buffer.compare(
|
|
2756
2784
|
contractId,
|
|
2757
|
-
xor(dlcTxs.fundTx.txId.serialize(), dlcAccept.
|
|
2785
|
+
xor(dlcTxs.fundTx.txId.serialize(), dlcAccept.temporaryContractId),
|
|
2758
2786
|
) === 0,
|
|
2759
2787
|
'contractId must be the xor of funding txid, fundingOutputIndex and the tempContractId',
|
|
2760
2788
|
);
|
|
@@ -2762,7 +2790,7 @@ Payout Group not found',
|
|
|
2762
2790
|
dlcTxs.contractId = contractId;
|
|
2763
2791
|
|
|
2764
2792
|
dlcSign.contractId = contractId;
|
|
2765
|
-
dlcSign.
|
|
2793
|
+
dlcSign.cetAdaptorSignatures = cetSignatures;
|
|
2766
2794
|
dlcSign.refundSignature = refundSignature;
|
|
2767
2795
|
dlcSign.fundingSignatures = fundingSignatures;
|
|
2768
2796
|
|
|
@@ -2785,12 +2813,10 @@ Payout Group not found',
|
|
|
2785
2813
|
return dlcAccept;
|
|
2786
2814
|
});
|
|
2787
2815
|
|
|
2788
|
-
const {
|
|
2789
|
-
|
|
2790
|
-
nestedMessagesList,
|
|
2791
|
-
} = await this.createBatchDlcTxs(dlcOffers, dlcAccepts);
|
|
2816
|
+
const { dlcTransactionsList, nestedMessagesList } =
|
|
2817
|
+
await this.createBatchDlcTxs(dlcOffers, dlcAccepts);
|
|
2792
2818
|
|
|
2793
|
-
const dlcSigns:
|
|
2819
|
+
const dlcSigns: DlcSign[] = [];
|
|
2794
2820
|
|
|
2795
2821
|
const fundingSignatures = await this.CreateFundingSigs(
|
|
2796
2822
|
dlcOffers[0],
|
|
@@ -2805,7 +2831,7 @@ Payout Group not found',
|
|
|
2805
2831
|
const dlcTransactions = dlcTransactionsList[i];
|
|
2806
2832
|
const messagesList = nestedMessagesList[i];
|
|
2807
2833
|
|
|
2808
|
-
const dlcSign = new
|
|
2834
|
+
const dlcSign = new DlcSign();
|
|
2809
2835
|
|
|
2810
2836
|
await this.VerifyCetAdaptorAndRefundSigs(
|
|
2811
2837
|
dlcOffer,
|
|
@@ -2816,28 +2842,26 @@ Payout Group not found',
|
|
|
2816
2842
|
true,
|
|
2817
2843
|
);
|
|
2818
2844
|
|
|
2819
|
-
const {
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
true,
|
|
2828
|
-
);
|
|
2845
|
+
const { cetSignatures, refundSignature } =
|
|
2846
|
+
await this.CreateCetAdaptorAndRefundSigs(
|
|
2847
|
+
dlcOffer,
|
|
2848
|
+
dlcAccept,
|
|
2849
|
+
dlcTransactions,
|
|
2850
|
+
messagesList,
|
|
2851
|
+
true,
|
|
2852
|
+
);
|
|
2829
2853
|
|
|
2830
|
-
const dlcTxs = dlcTransactions
|
|
2854
|
+
const dlcTxs = dlcTransactions;
|
|
2831
2855
|
|
|
2832
2856
|
const contractId = xor(
|
|
2833
2857
|
dlcTxs.fundTx.txId.serialize(),
|
|
2834
|
-
dlcAccept.
|
|
2858
|
+
dlcAccept.temporaryContractId,
|
|
2835
2859
|
);
|
|
2836
2860
|
|
|
2837
2861
|
dlcTxs.contractId = contractId;
|
|
2838
2862
|
|
|
2839
2863
|
dlcSign.contractId = contractId;
|
|
2840
|
-
dlcSign.
|
|
2864
|
+
dlcSign.cetAdaptorSignatures = cetSignatures;
|
|
2841
2865
|
dlcSign.refundSignature = refundSignature;
|
|
2842
2866
|
dlcSign.fundingSignatures = fundingSignatures;
|
|
2843
2867
|
|
|
@@ -2849,41 +2873,35 @@ Payout Group not found',
|
|
|
2849
2873
|
|
|
2850
2874
|
/**
|
|
2851
2875
|
* Finalize Dlc Sign
|
|
2852
|
-
* @param
|
|
2853
|
-
* @param
|
|
2854
|
-
* @param
|
|
2855
|
-
* @param
|
|
2876
|
+
* @param dlcOffer Dlc Offer Message
|
|
2877
|
+
* @param dlcAccept Dlc Accept Message
|
|
2878
|
+
* @param dlcSign Dlc Sign Message
|
|
2879
|
+
* @param dlcTxs Dlc Transactions Message
|
|
2856
2880
|
* @returns {Promise<Tx>}
|
|
2857
2881
|
*/
|
|
2858
2882
|
async finalizeDlcSign(
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
|
|
2883
|
+
dlcOffer: DlcOffer,
|
|
2884
|
+
dlcAccept: DlcAccept,
|
|
2885
|
+
dlcSign: DlcSign,
|
|
2886
|
+
dlcTxs: DlcTransactions,
|
|
2863
2887
|
): Promise<Tx> {
|
|
2864
|
-
const { dlcOffer, dlcAccept, dlcSign, dlcTxs } = checkTypes({
|
|
2865
|
-
_dlcOffer,
|
|
2866
|
-
_dlcAccept,
|
|
2867
|
-
_dlcSign,
|
|
2868
|
-
_dlcTxs,
|
|
2869
|
-
});
|
|
2870
|
-
|
|
2871
2888
|
let messagesList: Messages[] = [];
|
|
2872
2889
|
|
|
2873
2890
|
if (
|
|
2874
|
-
dlcOffer.contractInfo.type === MessageType.
|
|
2875
|
-
(dlcOffer.contractInfo as
|
|
2876
|
-
MessageType.
|
|
2891
|
+
dlcOffer.contractInfo.type === MessageType.SingleContractInfo &&
|
|
2892
|
+
(dlcOffer.contractInfo as SingleContractInfo).contractDescriptor.type ===
|
|
2893
|
+
MessageType.SingleContractInfo
|
|
2877
2894
|
) {
|
|
2878
|
-
for (const outcome of (
|
|
2879
|
-
.
|
|
2880
|
-
|
|
2895
|
+
for (const outcome of (
|
|
2896
|
+
(dlcOffer.contractInfo as SingleContractInfo)
|
|
2897
|
+
.contractDescriptor as EnumeratedDescriptor
|
|
2898
|
+
).outcomes) {
|
|
2899
|
+
messagesList.push({ messages: [outcome.outcome] });
|
|
2881
2900
|
}
|
|
2882
2901
|
} else {
|
|
2883
2902
|
const payoutResponses = this.GetPayouts(dlcOffer);
|
|
2884
|
-
const { messagesList: oracleEventMessagesList } =
|
|
2885
|
-
payoutResponses
|
|
2886
|
-
);
|
|
2903
|
+
const { messagesList: oracleEventMessagesList } =
|
|
2904
|
+
this.FlattenPayouts(payoutResponses);
|
|
2887
2905
|
messagesList = oracleEventMessagesList;
|
|
2888
2906
|
}
|
|
2889
2907
|
|
|
@@ -3000,20 +3018,13 @@ Payout Group not found',
|
|
|
3000
3018
|
* @returns {Promise<Tx>}
|
|
3001
3019
|
*/
|
|
3002
3020
|
async execute(
|
|
3003
|
-
|
|
3004
|
-
|
|
3005
|
-
|
|
3006
|
-
|
|
3007
|
-
oracleAttestation:
|
|
3021
|
+
dlcOffer: DlcOffer,
|
|
3022
|
+
dlcAccept: DlcAccept,
|
|
3023
|
+
dlcSign: DlcSign,
|
|
3024
|
+
dlcTxs: DlcTransactions,
|
|
3025
|
+
oracleAttestation: OracleAttestation,
|
|
3008
3026
|
isOfferer?: boolean,
|
|
3009
3027
|
): Promise<Tx> {
|
|
3010
|
-
const { dlcOffer, dlcAccept, dlcSign, dlcTxs } = checkTypes({
|
|
3011
|
-
_dlcOffer,
|
|
3012
|
-
_dlcAccept,
|
|
3013
|
-
_dlcSign,
|
|
3014
|
-
_dlcTxs,
|
|
3015
|
-
});
|
|
3016
|
-
|
|
3017
3028
|
if (isOfferer === undefined)
|
|
3018
3029
|
isOfferer = await this.isOfferer(dlcOffer, dlcAccept);
|
|
3019
3030
|
|
|
@@ -3051,7 +3062,7 @@ Payout Group not found',
|
|
|
3051
3062
|
});
|
|
3052
3063
|
|
|
3053
3064
|
const signatures =
|
|
3054
|
-
Buffer.compare(dlcOffer.
|
|
3065
|
+
Buffer.compare(dlcOffer.fundingPubkey, dlcAccept.fundingPubkey) === -1
|
|
3055
3066
|
? [
|
|
3056
3067
|
dlcSign.refundSignature.toString('hex'),
|
|
3057
3068
|
dlcAccept.refundSignature.toString('hex'),
|
|
@@ -3066,8 +3077,8 @@ Payout Group not found',
|
|
|
3066
3077
|
signatures,
|
|
3067
3078
|
fundTxId: dlcTxs.fundTx.txId.toString(),
|
|
3068
3079
|
fundVout: dlcTxs.fundTxVout,
|
|
3069
|
-
localFundPubkey: dlcOffer.
|
|
3070
|
-
remoteFundPubkey: dlcAccept.
|
|
3080
|
+
localFundPubkey: dlcOffer.fundingPubkey.toString('hex'),
|
|
3081
|
+
remoteFundPubkey: dlcAccept.fundingPubkey.toString('hex'),
|
|
3071
3082
|
};
|
|
3072
3083
|
|
|
3073
3084
|
const refundHex = (
|
|
@@ -3115,9 +3126,9 @@ Payout Group not found',
|
|
|
3115
3126
|
const psbt = new Psbt({ network });
|
|
3116
3127
|
|
|
3117
3128
|
const fundingPubKeys =
|
|
3118
|
-
Buffer.compare(dlcOffer.
|
|
3119
|
-
? [dlcOffer.
|
|
3120
|
-
: [dlcAccept.
|
|
3129
|
+
Buffer.compare(dlcOffer.fundingPubkey, dlcAccept.fundingPubkey) === -1
|
|
3130
|
+
? [dlcOffer.fundingPubkey, dlcAccept.fundingPubkey]
|
|
3131
|
+
: [dlcAccept.fundingPubkey, dlcOffer.fundingPubkey];
|
|
3121
3132
|
|
|
3122
3133
|
const p2ms = payments.p2ms({
|
|
3123
3134
|
m: 2,
|
|
@@ -3216,8 +3227,8 @@ Payout Group not found',
|
|
|
3216
3227
|
|
|
3217
3228
|
const finalizer = new DualClosingTxFinalizer(
|
|
3218
3229
|
fundingInputs,
|
|
3219
|
-
dlcOffer.
|
|
3220
|
-
dlcAccept.
|
|
3230
|
+
dlcOffer.payoutSpk,
|
|
3231
|
+
dlcAccept.payoutSpk,
|
|
3221
3232
|
dlcOffer.feeRatePerVb,
|
|
3222
3233
|
);
|
|
3223
3234
|
|
|
@@ -3242,7 +3253,7 @@ Payout Group not found',
|
|
|
3242
3253
|
psbt.addOutput({
|
|
3243
3254
|
value: Number(offerFirst ? offerPayoutValue : acceptPayoutValue),
|
|
3244
3255
|
address: address.fromOutputScript(
|
|
3245
|
-
offerFirst ? dlcOffer.
|
|
3256
|
+
offerFirst ? dlcOffer.payoutSpk : dlcAccept.payoutSpk,
|
|
3246
3257
|
network,
|
|
3247
3258
|
),
|
|
3248
3259
|
});
|
|
@@ -3250,7 +3261,7 @@ Payout Group not found',
|
|
|
3250
3261
|
psbt.addOutput({
|
|
3251
3262
|
value: Number(offerFirst ? acceptPayoutValue : offerPayoutValue),
|
|
3252
3263
|
address: address.fromOutputScript(
|
|
3253
|
-
offerFirst ? dlcAccept.
|
|
3264
|
+
offerFirst ? dlcAccept.payoutSpk : dlcOffer.payoutSpk,
|
|
3254
3265
|
network,
|
|
3255
3266
|
),
|
|
3256
3267
|
});
|
|
@@ -3277,7 +3288,11 @@ Payout Group not found',
|
|
|
3277
3288
|
);
|
|
3278
3289
|
|
|
3279
3290
|
// Validate signatures
|
|
3280
|
-
psbt.validateSignaturesOfAllInputs(
|
|
3291
|
+
psbt.validateSignaturesOfAllInputs(
|
|
3292
|
+
(pubkey: Buffer, msghash: Buffer, signature: Buffer) => {
|
|
3293
|
+
return ecc.verify(msghash, pubkey, signature);
|
|
3294
|
+
},
|
|
3295
|
+
);
|
|
3281
3296
|
|
|
3282
3297
|
// Extract close signature from psbt and decode it to only extract r and s values
|
|
3283
3298
|
const closeSignature = await script.signature.decode(
|
|
@@ -3298,11 +3313,11 @@ Payout Group not found',
|
|
|
3298
3313
|
pubKeyWitness.witness = inputSigs[i].pubkey;
|
|
3299
3314
|
witnessElements.push([sigWitness, pubKeyWitness]);
|
|
3300
3315
|
}
|
|
3301
|
-
const fundingSignatures = new
|
|
3316
|
+
const fundingSignatures = new FundingSignatures();
|
|
3302
3317
|
fundingSignatures.witnessElements = witnessElements;
|
|
3303
3318
|
|
|
3304
3319
|
// Create DlcClose
|
|
3305
|
-
const dlcClose = new
|
|
3320
|
+
const dlcClose = new DlcClose();
|
|
3306
3321
|
dlcClose.contractId = dlcTxs.contractId;
|
|
3307
3322
|
dlcClose.offerPayoutSatoshis = BigInt(
|
|
3308
3323
|
psbt.txOutputs[offerFirst ? 0 : 1].value,
|
|
@@ -3313,7 +3328,7 @@ Payout Group not found',
|
|
|
3313
3328
|
dlcClose.fundInputSerialId = fundingInputSerialId; // randomly generated serial id
|
|
3314
3329
|
dlcClose.closeSignature = closeSignature;
|
|
3315
3330
|
dlcClose.fundingSignatures = fundingSignatures;
|
|
3316
|
-
dlcClose.fundingInputs = fundingInputs as
|
|
3331
|
+
dlcClose.fundingInputs = fundingInputs as FundingInput[];
|
|
3317
3332
|
dlcClose.validate();
|
|
3318
3333
|
|
|
3319
3334
|
return dlcClose;
|
|
@@ -3355,8 +3370,8 @@ Payout Group not found',
|
|
|
3355
3370
|
|
|
3356
3371
|
const finalizer = new DualClosingTxFinalizer(
|
|
3357
3372
|
fundingInputs,
|
|
3358
|
-
dlcOffer.
|
|
3359
|
-
dlcAccept.
|
|
3373
|
+
dlcOffer.payoutSpk,
|
|
3374
|
+
dlcAccept.payoutSpk,
|
|
3360
3375
|
dlcOffer.feeRatePerVb,
|
|
3361
3376
|
);
|
|
3362
3377
|
|
|
@@ -3415,9 +3430,9 @@ Payout Group not found',
|
|
|
3415
3430
|
? collateralMinusPayout
|
|
3416
3431
|
: closeInputAmount + payoutMinusOfferFees;
|
|
3417
3432
|
|
|
3418
|
-
const fundingSignatures = new
|
|
3433
|
+
const fundingSignatures = new FundingSignatures();
|
|
3419
3434
|
|
|
3420
|
-
const dlcClose = new
|
|
3435
|
+
const dlcClose = new DlcClose();
|
|
3421
3436
|
dlcClose.contractId = dlcTxs.contractId;
|
|
3422
3437
|
dlcClose.offerPayoutSatoshis = offerPayoutValue;
|
|
3423
3438
|
dlcClose.acceptPayoutSatoshis = acceptPayoutValue;
|
|
@@ -3542,9 +3557,9 @@ Payout Group not found',
|
|
|
3542
3557
|
const psbt = new Psbt({ network });
|
|
3543
3558
|
|
|
3544
3559
|
const fundingPubKeys =
|
|
3545
|
-
Buffer.compare(dlcOffer.
|
|
3546
|
-
? [dlcOffer.
|
|
3547
|
-
: [dlcAccept.
|
|
3560
|
+
Buffer.compare(dlcOffer.fundingPubkey, dlcAccept.fundingPubkey) === -1
|
|
3561
|
+
? [dlcOffer.fundingPubkey, dlcAccept.fundingPubkey]
|
|
3562
|
+
: [dlcAccept.fundingPubkey, dlcOffer.fundingPubkey];
|
|
3548
3563
|
|
|
3549
3564
|
const p2ms = payments.p2ms({
|
|
3550
3565
|
m: 2,
|
|
@@ -3610,7 +3625,7 @@ Payout Group not found',
|
|
|
3610
3625
|
: dlcClose.acceptPayoutSatoshis,
|
|
3611
3626
|
),
|
|
3612
3627
|
address: address.fromOutputScript(
|
|
3613
|
-
offerFirst ? dlcOffer.
|
|
3628
|
+
offerFirst ? dlcOffer.payoutSpk : dlcAccept.payoutSpk,
|
|
3614
3629
|
network,
|
|
3615
3630
|
),
|
|
3616
3631
|
});
|
|
@@ -3622,7 +3637,7 @@ Payout Group not found',
|
|
|
3622
3637
|
: dlcClose.offerPayoutSatoshis,
|
|
3623
3638
|
),
|
|
3624
3639
|
address: address.fromOutputScript(
|
|
3625
|
-
offerFirst ? dlcAccept.
|
|
3640
|
+
offerFirst ? dlcAccept.payoutSpk : dlcOffer.payoutSpk,
|
|
3626
3641
|
network,
|
|
3627
3642
|
),
|
|
3628
3643
|
});
|
|
@@ -3644,7 +3659,7 @@ Payout Group not found',
|
|
|
3644
3659
|
|
|
3645
3660
|
const partialSig = [
|
|
3646
3661
|
{
|
|
3647
|
-
pubkey: offerer ? dlcAccept.
|
|
3662
|
+
pubkey: offerer ? dlcAccept.fundingPubkey : dlcOffer.fundingPubkey,
|
|
3648
3663
|
signature: await script.signature.encode(dlcClose.closeSignature, 1), // encode using SIGHASH_ALL
|
|
3649
3664
|
},
|
|
3650
3665
|
];
|
|
@@ -3674,7 +3689,11 @@ Payout Group not found',
|
|
|
3674
3689
|
psbt.updateInput(i, { partialSig });
|
|
3675
3690
|
}
|
|
3676
3691
|
|
|
3677
|
-
psbt.validateSignaturesOfAllInputs(
|
|
3692
|
+
psbt.validateSignaturesOfAllInputs(
|
|
3693
|
+
(pubkey: Buffer, msghash: Buffer, signature: Buffer) => {
|
|
3694
|
+
return ecc.verify(msghash, pubkey, signature);
|
|
3695
|
+
},
|
|
3696
|
+
);
|
|
3678
3697
|
psbt.finalizeAllInputs();
|
|
3679
3698
|
|
|
3680
3699
|
return psbt.extractTransaction().toHex();
|
|
@@ -3824,12 +3843,9 @@ Payout Group not found',
|
|
|
3824
3843
|
_input: FundingInput,
|
|
3825
3844
|
findDerivationPath = true,
|
|
3826
3845
|
): Promise<Input> {
|
|
3827
|
-
assert(
|
|
3828
|
-
_input.type === MessageType.FundingInputV0,
|
|
3829
|
-
'FundingInput must be V0',
|
|
3830
|
-
);
|
|
3846
|
+
assert(_input.type === MessageType.FundingInput, 'FundingInput must be V0');
|
|
3831
3847
|
const network = await this.getConnectedNetwork();
|
|
3832
|
-
const input = _input as
|
|
3848
|
+
const input = _input as FundingInput;
|
|
3833
3849
|
const prevTx = input.prevTx;
|
|
3834
3850
|
const prevTxOut = prevTx.outputs[input.prevTxVout];
|
|
3835
3851
|
const scriptPubKey = prevTxOut.scriptPubKey.serialize().slice(1);
|
|
@@ -3863,7 +3879,7 @@ Payout Group not found',
|
|
|
3863
3879
|
}
|
|
3864
3880
|
|
|
3865
3881
|
async inputToFundingInput(input: Input): Promise<FundingInput> {
|
|
3866
|
-
const fundingInput = new
|
|
3882
|
+
const fundingInput = new FundingInput();
|
|
3867
3883
|
fundingInput.prevTxVout = input.vout;
|
|
3868
3884
|
|
|
3869
3885
|
let txRaw = '';
|
|
@@ -3969,7 +3985,7 @@ interface ISig {
|
|
|
3969
3985
|
}
|
|
3970
3986
|
|
|
3971
3987
|
export interface CreateCetAdaptorAndRefundSigsResponse {
|
|
3972
|
-
cetSignatures:
|
|
3988
|
+
cetSignatures: CetAdaptorSignatures;
|
|
3973
3989
|
refundSignature: Buffer;
|
|
3974
3990
|
}
|
|
3975
3991
|
|