@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
|
@@ -1,4 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
27
|
};
|
|
@@ -15,6 +38,8 @@ const assert_1 = __importDefault(require("assert"));
|
|
|
15
38
|
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
16
39
|
const bitcoin_networks_1 = require("bitcoin-networks");
|
|
17
40
|
const bitcoinjs_lib_1 = require("bitcoinjs-lib");
|
|
41
|
+
const crypto_2 = __importDefault(require("crypto"));
|
|
42
|
+
const ecc = __importStar(require("tiny-secp256k1"));
|
|
18
43
|
const Utils_1 = require("./utils/Utils");
|
|
19
44
|
class BitcoinDlcProvider extends provider_1.default {
|
|
20
45
|
constructor(network, cfdDlcJs) {
|
|
@@ -131,27 +156,23 @@ class BitcoinDlcProvider extends provider_1.default {
|
|
|
131
156
|
* totalCollateral: bigint,
|
|
132
157
|
* ): PayoutRequest[] {}
|
|
133
158
|
*/
|
|
134
|
-
GetPayoutsFromPayoutFunction(
|
|
135
|
-
if (_dlcOffer.type !== messaging_1.MessageType.DlcOfferV0)
|
|
136
|
-
throw Error('DlcOffer must be V0');
|
|
137
|
-
const dlcOffer = _dlcOffer;
|
|
138
|
-
if (contractDescriptor.payoutFunction.type !== messaging_1.MessageType.PayoutFunctionV0)
|
|
139
|
-
throw Error('PayoutFunction must be V0');
|
|
159
|
+
GetPayoutsFromPayoutFunction(dlcOffer, contractDescriptor, oracleInfo, totalCollateral) {
|
|
140
160
|
const payoutFunction = contractDescriptor.payoutFunction;
|
|
141
|
-
if (payoutFunction.
|
|
161
|
+
if (payoutFunction.payoutFunctionPieces.length === 0)
|
|
142
162
|
throw Error('PayoutFunction must have at least once PayoutCurvePiece');
|
|
143
|
-
if (payoutFunction.
|
|
163
|
+
if (payoutFunction.payoutFunctionPieces.length > 1)
|
|
144
164
|
throw Error('More than one PayoutCurvePiece not supported');
|
|
145
|
-
const payoutCurvePiece = payoutFunction.
|
|
165
|
+
const payoutCurvePiece = payoutFunction.payoutFunctionPieces[0]
|
|
146
166
|
.payoutCurvePiece;
|
|
147
|
-
if (payoutCurvePiece.
|
|
148
|
-
payoutCurvePiece.type !== messaging_1.MessageType.OldHyperbolaPayoutCurvePiece)
|
|
167
|
+
if (payoutCurvePiece.payoutCurvePieceType !== messaging_1.PayoutCurvePieceType.Hyperbola)
|
|
149
168
|
throw Error('Must be HyperbolaPayoutCurvePiece');
|
|
150
|
-
if (payoutCurvePiece.b
|
|
169
|
+
if (!payoutCurvePiece.b.eq(messaging_1.F64.ZERO) || !payoutCurvePiece.c.eq(messaging_1.F64.ZERO))
|
|
151
170
|
throw Error('b and c HyperbolaPayoutCurvePiece values must be 0');
|
|
152
|
-
|
|
171
|
+
// Cast to SingleOracleInfo to access announcement property
|
|
172
|
+
const singleOracleInfo = oracleInfo;
|
|
173
|
+
const eventDescriptor = singleOracleInfo.announcement.oracleEvent
|
|
153
174
|
.eventDescriptor;
|
|
154
|
-
if (eventDescriptor.type !== messaging_1.MessageType.
|
|
175
|
+
if (eventDescriptor.type !== messaging_1.MessageType.DigitDecompositionEventDescriptor)
|
|
155
176
|
throw Error('Only DigitDecomposition Oracle Events supported');
|
|
156
177
|
const roundingIntervals = contractDescriptor.roundingIntervals;
|
|
157
178
|
const cetPayouts = core_1.HyperbolaPayoutCurve.computePayouts(payoutFunction, totalCollateral, roundingIntervals);
|
|
@@ -162,26 +183,21 @@ class BitcoinDlcProvider extends provider_1.default {
|
|
|
162
183
|
groups: (0, core_1.groupByIgnoringDigits)(p.indexFrom, p.indexTo, eventDescriptor.base, contractDescriptor.numDigits),
|
|
163
184
|
});
|
|
164
185
|
});
|
|
165
|
-
const rValuesMessagesList = this.GenerateMessages(
|
|
166
|
-
const { payouts, messagesList } = (0, Utils_1.outputsToPayouts)(payoutGroups, rValuesMessagesList, dlcOffer.
|
|
186
|
+
const rValuesMessagesList = this.GenerateMessages(singleOracleInfo);
|
|
187
|
+
const { payouts, messagesList } = (0, Utils_1.outputsToPayouts)(payoutGroups, rValuesMessagesList, dlcOffer.offerCollateral, dlcOffer.contractInfo.totalCollateral - dlcOffer.offerCollateral, true);
|
|
167
188
|
return { payouts, payoutGroups, messagesList };
|
|
168
189
|
}
|
|
169
|
-
GetPayoutsFromPolynomialPayoutFunction(
|
|
170
|
-
if (_dlcOffer.type !== messaging_1.MessageType.DlcOfferV0)
|
|
171
|
-
throw Error('DlcOffer must be V0');
|
|
172
|
-
const dlcOffer = _dlcOffer;
|
|
173
|
-
if (contractDescriptor.payoutFunction.type !== messaging_1.MessageType.PayoutFunctionV0)
|
|
174
|
-
throw Error('PayoutFunction must be V0');
|
|
190
|
+
GetPayoutsFromPolynomialPayoutFunction(dlcOffer, contractDescriptor, oracleInfo, totalCollateral) {
|
|
175
191
|
const payoutFunction = contractDescriptor.payoutFunction;
|
|
176
|
-
if (payoutFunction.
|
|
192
|
+
if (payoutFunction.payoutFunctionPieces.length === 0)
|
|
177
193
|
throw Error('PayoutFunction must have at least once PayoutCurvePiece');
|
|
178
|
-
for (const piece of payoutFunction.
|
|
194
|
+
for (const piece of payoutFunction.payoutFunctionPieces) {
|
|
179
195
|
if (piece.payoutCurvePiece.type !== messaging_1.MessageType.PolynomialPayoutCurvePiece)
|
|
180
196
|
throw Error('Must be PolynomialPayoutCurvePiece');
|
|
181
197
|
}
|
|
182
198
|
const eventDescriptor = oracleInfo.announcement.oracleEvent
|
|
183
199
|
.eventDescriptor;
|
|
184
|
-
if (eventDescriptor.type !== messaging_1.MessageType.
|
|
200
|
+
if (eventDescriptor.type !== messaging_1.MessageType.DigitDecompositionEventDescriptor)
|
|
185
201
|
throw Error('Only DigitDecomposition Oracle Events supported');
|
|
186
202
|
const roundingIntervals = contractDescriptor.roundingIntervals;
|
|
187
203
|
const cetPayouts = core_1.PolynomialPayoutCurve.computePayouts(payoutFunction, totalCollateral, roundingIntervals);
|
|
@@ -193,11 +209,10 @@ class BitcoinDlcProvider extends provider_1.default {
|
|
|
193
209
|
});
|
|
194
210
|
});
|
|
195
211
|
const rValuesMessagesList = this.GenerateMessages(oracleInfo);
|
|
196
|
-
const { payouts, messagesList } = (0, Utils_1.outputsToPayouts)(payoutGroups, rValuesMessagesList, dlcOffer.
|
|
212
|
+
const { payouts, messagesList } = (0, Utils_1.outputsToPayouts)(payoutGroups, rValuesMessagesList, dlcOffer.offerCollateral, dlcOffer.contractInfo.totalCollateral - dlcOffer.offerCollateral, true);
|
|
197
213
|
return { payouts, payoutGroups, messagesList };
|
|
198
214
|
}
|
|
199
|
-
GetPayouts(
|
|
200
|
-
const { dlcOffer } = (0, Utils_1.checkTypes)({ _dlcOffer });
|
|
215
|
+
GetPayouts(dlcOffer) {
|
|
201
216
|
const contractInfo = dlcOffer.contractInfo;
|
|
202
217
|
const totalCollateral = contractInfo.totalCollateral;
|
|
203
218
|
const contractOraclePairs = this.GetContractOraclePairs(contractInfo);
|
|
@@ -223,43 +238,46 @@ class BitcoinDlcProvider extends provider_1.default {
|
|
|
223
238
|
});
|
|
224
239
|
}, [{ startingMessagesIndex: 0, startingPayoutGroupsIndex: 0 }]);
|
|
225
240
|
}
|
|
241
|
+
GetPayoutsFromEnumeratedDescriptor(dlcOffer, contractDescriptor, oracleInfo, totalCollateral) {
|
|
242
|
+
const payoutGroups = [];
|
|
243
|
+
const rValuesMessagesList = this.GenerateMessages(oracleInfo);
|
|
244
|
+
// For enumerated descriptors, each outcome creates one payout
|
|
245
|
+
// Each outcome maps to one index in the oracle's possible outcomes
|
|
246
|
+
contractDescriptor.outcomes.forEach((outcome, index) => {
|
|
247
|
+
payoutGroups.push({
|
|
248
|
+
payout: outcome.localPayout,
|
|
249
|
+
groups: [[index]], // Simple index-based grouping for enum outcomes
|
|
250
|
+
});
|
|
251
|
+
});
|
|
252
|
+
const { payouts, messagesList } = (0, Utils_1.outputsToPayouts)(payoutGroups, rValuesMessagesList, dlcOffer.offerCollateral, totalCollateral - dlcOffer.offerCollateral, true);
|
|
253
|
+
return { payouts, payoutGroups, messagesList };
|
|
254
|
+
}
|
|
226
255
|
GetPayoutsFromContractDescriptor(dlcOffer, contractDescriptor, oracleInfo, totalCollateral) {
|
|
227
|
-
switch (contractDescriptor.
|
|
228
|
-
case messaging_1.
|
|
229
|
-
|
|
256
|
+
switch (contractDescriptor.contractDescriptorType) {
|
|
257
|
+
case messaging_1.ContractDescriptorType.Enumerated: {
|
|
258
|
+
return this.GetPayoutsFromEnumeratedDescriptor(dlcOffer, contractDescriptor, oracleInfo, totalCollateral);
|
|
230
259
|
}
|
|
231
|
-
case messaging_1.
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
return this.GetPayoutsFromPayoutFunction(dlcOffer, contractDescriptor, oracleInfo, totalCollateral);
|
|
242
|
-
case messaging_1.MessageType.PolynomialPayoutCurvePiece:
|
|
243
|
-
return this.GetPayoutsFromPolynomialPayoutFunction(dlcOffer, contractDescriptor, oracleInfo, totalCollateral);
|
|
244
|
-
}
|
|
260
|
+
case messaging_1.ContractDescriptorType.NumericOutcome: {
|
|
261
|
+
const numericalDescriptor = contractDescriptor;
|
|
262
|
+
const payoutFunction = numericalDescriptor.payoutFunction;
|
|
263
|
+
// TODO: add a better check for this
|
|
264
|
+
const payoutCurvePiece = payoutFunction.payoutFunctionPieces[0].payoutCurvePiece;
|
|
265
|
+
switch (payoutCurvePiece.payoutCurvePieceType) {
|
|
266
|
+
case messaging_1.PayoutCurvePieceType.Hyperbola:
|
|
267
|
+
return this.GetPayoutsFromPayoutFunction(dlcOffer, numericalDescriptor, oracleInfo, totalCollateral);
|
|
268
|
+
case messaging_1.PayoutCurvePieceType.Polynomial:
|
|
269
|
+
return this.GetPayoutsFromPolynomialPayoutFunction(dlcOffer, numericalDescriptor, oracleInfo, totalCollateral);
|
|
245
270
|
}
|
|
246
|
-
break;
|
|
247
|
-
default: {
|
|
248
|
-
throw Error('ContractDescriptor must be V0 or V1');
|
|
249
271
|
}
|
|
250
272
|
}
|
|
251
273
|
}
|
|
252
|
-
async createDlcTxs(
|
|
253
|
-
const
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
const
|
|
258
|
-
const
|
|
259
|
-
const localFinalScriptPubkey = dlcOffer.payoutSPK.toString('hex');
|
|
260
|
-
const remoteFinalScriptPubkey = dlcAccept.payoutSPK.toString('hex');
|
|
261
|
-
const localChangeScriptPubkey = dlcOffer.changeSPK.toString('hex');
|
|
262
|
-
const remoteChangeScriptPubkey = dlcAccept.changeSPK.toString('hex');
|
|
274
|
+
async createDlcTxs(dlcOffer, dlcAccept) {
|
|
275
|
+
const localFundPubkey = dlcOffer.fundingPubkey.toString('hex');
|
|
276
|
+
const remoteFundPubkey = dlcAccept.fundingPubkey.toString('hex');
|
|
277
|
+
const localFinalScriptPubkey = dlcOffer.payoutSpk.toString('hex');
|
|
278
|
+
const remoteFinalScriptPubkey = dlcAccept.payoutSpk.toString('hex');
|
|
279
|
+
const localChangeScriptPubkey = dlcOffer.changeSpk.toString('hex');
|
|
280
|
+
const remoteChangeScriptPubkey = dlcAccept.changeSpk.toString('hex');
|
|
263
281
|
const localInputs = await Promise.all(dlcOffer.fundingInputs.map(async (fundingInput) => {
|
|
264
282
|
const input = await this.fundingInputToInput(fundingInput, false);
|
|
265
283
|
return input.toUtxo();
|
|
@@ -272,23 +290,23 @@ class BitcoinDlcProvider extends provider_1.default {
|
|
|
272
290
|
const remoteInputAmount = remoteInputs.reduce((prev, cur) => prev + cur.amount.GetSatoshiAmount(), 0);
|
|
273
291
|
let payouts = [];
|
|
274
292
|
let messagesList = [];
|
|
275
|
-
if (dlcOffer.contractInfo.type === messaging_1.MessageType.
|
|
293
|
+
if (dlcOffer.contractInfo.type === messaging_1.MessageType.SingleContractInfo &&
|
|
276
294
|
dlcOffer.contractInfo.contractDescriptor.type ===
|
|
277
|
-
messaging_1.
|
|
295
|
+
messaging_1.ContractDescriptorType.Enumerated) {
|
|
278
296
|
for (const outcome of dlcOffer.contractInfo
|
|
279
297
|
.contractDescriptor.outcomes) {
|
|
280
298
|
payouts.push({
|
|
281
299
|
local: outcome.localPayout,
|
|
282
|
-
remote: dlcOffer.
|
|
283
|
-
dlcAccept.
|
|
300
|
+
remote: dlcOffer.offerCollateral +
|
|
301
|
+
dlcAccept.acceptCollateral -
|
|
284
302
|
outcome.localPayout,
|
|
285
303
|
});
|
|
286
|
-
messagesList.push({ messages: [outcome.outcome
|
|
304
|
+
messagesList.push({ messages: [outcome.outcome] });
|
|
287
305
|
}
|
|
288
306
|
}
|
|
289
307
|
else {
|
|
290
308
|
const payoutResponses = this.GetPayouts(dlcOffer);
|
|
291
|
-
const { payouts: tempPayouts, messagesList: tempMessagesList
|
|
309
|
+
const { payouts: tempPayouts, messagesList: tempMessagesList } = this.FlattenPayouts(payoutResponses);
|
|
292
310
|
payouts = tempPayouts;
|
|
293
311
|
messagesList = tempMessagesList;
|
|
294
312
|
}
|
|
@@ -299,11 +317,11 @@ class BitcoinDlcProvider extends provider_1.default {
|
|
|
299
317
|
remoteFundPubkey,
|
|
300
318
|
remoteFinalScriptPubkey,
|
|
301
319
|
localInputAmount,
|
|
302
|
-
localCollateralAmount: dlcOffer.
|
|
320
|
+
localCollateralAmount: dlcOffer.offerCollateral,
|
|
303
321
|
localPayoutSerialId: dlcOffer.payoutSerialId,
|
|
304
322
|
localChangeSerialId: dlcOffer.changeSerialId,
|
|
305
323
|
remoteInputAmount,
|
|
306
|
-
remoteCollateralAmount: dlcAccept.
|
|
324
|
+
remoteCollateralAmount: dlcAccept.acceptCollateral,
|
|
307
325
|
remotePayoutSerialId: dlcAccept.payoutSerialId,
|
|
308
326
|
remoteChangeSerialId: dlcAccept.changeSerialId,
|
|
309
327
|
refundLocktime: dlcOffer.refundLocktime,
|
|
@@ -316,7 +334,7 @@ class BitcoinDlcProvider extends provider_1.default {
|
|
|
316
334
|
fundOutputSerialId: dlcOffer.fundOutputSerialId,
|
|
317
335
|
};
|
|
318
336
|
const dlcTxs = await this.CreateDlcTransactions(dlcTxRequest);
|
|
319
|
-
const dlcTransactions = new messaging_1.
|
|
337
|
+
const dlcTransactions = new messaging_1.DlcTransactions();
|
|
320
338
|
dlcTransactions.fundTx = bitcoin_1.Tx.decode(bufio_1.StreamReader.fromHex(dlcTxs.fundTxHex));
|
|
321
339
|
dlcTransactions.fundTxVout = [
|
|
322
340
|
BigInt(dlcOffer.changeSerialId),
|
|
@@ -331,19 +349,13 @@ class BitcoinDlcProvider extends provider_1.default {
|
|
|
331
349
|
});
|
|
332
350
|
return { dlcTransactions, messagesList };
|
|
333
351
|
}
|
|
334
|
-
async createBatchDlcTxs(
|
|
335
|
-
const
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
const
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
const localFundPubkeys = dlcOffers.map((dlcOffer) => dlcOffer.fundingPubKey.toString('hex'));
|
|
342
|
-
const remoteFundPubkeys = dlcAccepts.map((dlcAccept) => dlcAccept.fundingPubKey.toString('hex'));
|
|
343
|
-
const localFinalScriptPubkeys = dlcOffers.map((dlcOffer) => dlcOffer.payoutSPK.toString('hex'));
|
|
344
|
-
const remoteFinalScriptPubkeys = dlcAccepts.map((dlcAccept) => dlcAccept.payoutSPK.toString('hex'));
|
|
345
|
-
const localChangeScriptPubkey = dlcOffers[0].changeSPK.toString('hex');
|
|
346
|
-
const remoteChangeScriptPubkey = dlcAccepts[0].changeSPK.toString('hex');
|
|
352
|
+
async createBatchDlcTxs(dlcOffers, dlcAccepts) {
|
|
353
|
+
const localFundPubkeys = dlcOffers.map((dlcOffer) => dlcOffer.fundingPubkey.toString('hex'));
|
|
354
|
+
const remoteFundPubkeys = dlcAccepts.map((dlcAccept) => dlcAccept.fundingPubkey.toString('hex'));
|
|
355
|
+
const localFinalScriptPubkeys = dlcOffers.map((dlcOffer) => dlcOffer.payoutSpk.toString('hex'));
|
|
356
|
+
const remoteFinalScriptPubkeys = dlcAccepts.map((dlcAccept) => dlcAccept.payoutSpk.toString('hex'));
|
|
357
|
+
const localChangeScriptPubkey = dlcOffers[0].changeSpk.toString('hex');
|
|
358
|
+
const remoteChangeScriptPubkey = dlcAccepts[0].changeSpk.toString('hex');
|
|
347
359
|
const localInputs = await Promise.all(dlcOffers[0].fundingInputs.map(async (fundingInput) => {
|
|
348
360
|
const input = await this.fundingInputToInput(fundingInput, false);
|
|
349
361
|
return input.toUtxo();
|
|
@@ -378,11 +390,11 @@ class BitcoinDlcProvider extends provider_1.default {
|
|
|
378
390
|
remoteFundPubkeys,
|
|
379
391
|
remoteFinalScriptPubkeys,
|
|
380
392
|
localInputAmount,
|
|
381
|
-
localCollateralAmounts: dlcOffers.map((dlcOffer) => dlcOffer.
|
|
393
|
+
localCollateralAmounts: dlcOffers.map((dlcOffer) => dlcOffer.offerCollateral),
|
|
382
394
|
localPayoutSerialIds: dlcOffers.map((dlcOffer) => dlcOffer.payoutSerialId),
|
|
383
395
|
localChangeSerialId: dlcOffers[0].changeSerialId,
|
|
384
396
|
remoteInputAmount,
|
|
385
|
-
remoteCollateralAmounts: dlcAccepts.map((dlcAccept) => dlcAccept.
|
|
397
|
+
remoteCollateralAmounts: dlcAccepts.map((dlcAccept) => dlcAccept.acceptCollateral),
|
|
386
398
|
remotePayoutSerialIds: dlcAccepts.map((dlcAccept) => dlcAccept.payoutSerialId),
|
|
387
399
|
remoteChangeSerialId: dlcAccepts[0].changeSerialId,
|
|
388
400
|
refundLocktimes: dlcOffers.map((dlcOffer) => dlcOffer.refundLocktime),
|
|
@@ -398,7 +410,7 @@ class BitcoinDlcProvider extends provider_1.default {
|
|
|
398
410
|
const dlcTransactionsList = [];
|
|
399
411
|
let start = 0;
|
|
400
412
|
for (let i = 0; i < dlcTxs.refundTxHexList.length; i++) {
|
|
401
|
-
const dlcTransactions = new messaging_1.
|
|
413
|
+
const dlcTransactions = new messaging_1.DlcTransactions();
|
|
402
414
|
dlcTransactions.fundTx = bitcoin_1.Tx.decode(bufio_1.StreamReader.fromHex(dlcTxs.fundTxHex));
|
|
403
415
|
dlcTransactions.fundTxVout = [
|
|
404
416
|
BigInt(dlcOffers[i].changeSerialId),
|
|
@@ -420,7 +432,13 @@ class BitcoinDlcProvider extends provider_1.default {
|
|
|
420
432
|
return { dlcTransactionsList, nestedMessagesList };
|
|
421
433
|
}
|
|
422
434
|
GenerateEnumMessages(oracleEvent) {
|
|
423
|
-
|
|
435
|
+
const eventDescriptor = oracleEvent.eventDescriptor;
|
|
436
|
+
// For enum events, each oracle has one nonce and can attest to one of the possible outcomes
|
|
437
|
+
const messagesList = [];
|
|
438
|
+
// For enum events, hash the outcomes to match the contract descriptor format
|
|
439
|
+
const messages = eventDescriptor.outcomes.map((outcome) => (0, crypto_1.sha256)(Buffer.from(outcome)).toString('hex'));
|
|
440
|
+
messagesList.push({ messages });
|
|
441
|
+
return messagesList;
|
|
424
442
|
}
|
|
425
443
|
GenerateDigitDecompositionMessages(oracleEvent) {
|
|
426
444
|
const oracleNonces = oracleEvent.oracleNonces;
|
|
@@ -437,32 +455,50 @@ class BitcoinDlcProvider extends provider_1.default {
|
|
|
437
455
|
return messagesList;
|
|
438
456
|
}
|
|
439
457
|
GenerateMessages(oracleInfo) {
|
|
440
|
-
|
|
458
|
+
// Handle both SingleOracleInfo and MultiOracleInfo using type property instead of instanceof
|
|
459
|
+
let oracleEvent;
|
|
460
|
+
if (oracleInfo.type === messaging_1.MessageType.SingleOracleInfo) {
|
|
461
|
+
const singleOracleInfo = oracleInfo;
|
|
462
|
+
oracleEvent = singleOracleInfo.announcement.oracleEvent;
|
|
463
|
+
}
|
|
464
|
+
else if (oracleInfo.type === messaging_1.MessageType.MultiOracleInfo) {
|
|
465
|
+
const multiOracleInfo = oracleInfo;
|
|
466
|
+
// For multi-oracle, use the first announcement for now
|
|
467
|
+
// TODO: This might need more sophisticated handling for multi-oracle scenarios
|
|
468
|
+
if (multiOracleInfo.announcements.length === 0) {
|
|
469
|
+
throw Error('MultiOracleInfo must have at least one announcement');
|
|
470
|
+
}
|
|
471
|
+
oracleEvent = multiOracleInfo.announcements[0].oracleEvent;
|
|
472
|
+
}
|
|
473
|
+
else {
|
|
474
|
+
throw Error(`OracleInfo must be SingleOracleInfo or MultiOracleInfo, got type: ${oracleInfo.type}`);
|
|
475
|
+
}
|
|
441
476
|
switch (oracleEvent.eventDescriptor.type) {
|
|
442
|
-
case messaging_1.MessageType.
|
|
477
|
+
case messaging_1.MessageType.EnumEventDescriptor:
|
|
443
478
|
return this.GenerateEnumMessages(oracleEvent);
|
|
444
|
-
case messaging_1.MessageType.
|
|
479
|
+
case messaging_1.MessageType.DigitDecompositionEventDescriptor:
|
|
445
480
|
return this.GenerateDigitDecompositionMessages(oracleEvent);
|
|
446
481
|
default:
|
|
447
482
|
throw Error('EventDescriptor must be Enum or DigitDecomposition');
|
|
448
483
|
}
|
|
449
484
|
}
|
|
450
485
|
GetContractOraclePairs(_contractInfo) {
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
486
|
+
// Use contractInfoType property instead of instanceof for more reliable type checking
|
|
487
|
+
if (_contractInfo.contractInfoType === messaging_1.ContractInfoType.Single) {
|
|
488
|
+
const singleInfo = _contractInfo;
|
|
489
|
+
return [
|
|
490
|
+
{
|
|
491
|
+
contractDescriptor: singleInfo.contractDescriptor,
|
|
492
|
+
oracleInfo: singleInfo.oracleInfo,
|
|
493
|
+
},
|
|
494
|
+
];
|
|
495
|
+
}
|
|
496
|
+
else if (_contractInfo.contractInfoType === messaging_1.ContractInfoType.Disjoint) {
|
|
497
|
+
const disjointInfo = _contractInfo;
|
|
498
|
+
return disjointInfo.contractOraclePairs;
|
|
499
|
+
}
|
|
500
|
+
else {
|
|
501
|
+
throw Error('ContractInfo must be Single or Disjoint');
|
|
466
502
|
}
|
|
467
503
|
}
|
|
468
504
|
async CreateCetAdaptorAndRefundSigs(_dlcOffer, _dlcAccept, _dlcTxs, messagesList, isOfferer) {
|
|
@@ -473,7 +509,7 @@ class BitcoinDlcProvider extends provider_1.default {
|
|
|
473
509
|
});
|
|
474
510
|
const network = await this.getConnectedNetwork();
|
|
475
511
|
const cetsHex = dlcTxs.cets.map((cet) => cet.serialize().toString('hex'));
|
|
476
|
-
const fundingSPK = bitcoin_1.Script.p2wpkhLock((0, crypto_1.hash160)(isOfferer ? dlcOffer.
|
|
512
|
+
const fundingSPK = bitcoin_1.Script.p2wpkhLock((0, crypto_1.hash160)(isOfferer ? dlcOffer.fundingPubkey : dlcAccept.fundingPubkey))
|
|
477
513
|
.serialize()
|
|
478
514
|
.slice(1);
|
|
479
515
|
const fundingAddress = bitcoinjs_lib_1.address.fromOutputScript(fundingSPK, network);
|
|
@@ -484,11 +520,15 @@ class BitcoinDlcProvider extends provider_1.default {
|
|
|
484
520
|
const fundPrivateKey = Buffer.from(fundPrivateKeyPair.__D).toString('hex');
|
|
485
521
|
const contractOraclePairs = this.GetContractOraclePairs(dlcOffer.contractInfo);
|
|
486
522
|
const sigs = [];
|
|
487
|
-
if (dlcOffer.contractInfo.
|
|
523
|
+
if (dlcOffer.contractInfo.contractInfoType === messaging_1.ContractInfoType.Single &&
|
|
488
524
|
dlcOffer.contractInfo.contractDescriptor.type ===
|
|
489
525
|
messaging_1.MessageType.ContractDescriptorV0) {
|
|
490
526
|
for (const [_, { oracleInfo }] of contractOraclePairs.entries()) {
|
|
491
|
-
|
|
527
|
+
if (oracleInfo.type !== messaging_1.MessageType.SingleOracleInfo) {
|
|
528
|
+
throw new Error('Only SingleOracleInfo supported in this context');
|
|
529
|
+
}
|
|
530
|
+
const oracleAnnouncement = oracleInfo
|
|
531
|
+
.announcement;
|
|
492
532
|
const adaptorSigRequestPromises = [];
|
|
493
533
|
const tempMessagesList = messagesList;
|
|
494
534
|
const tempCetsHex = cetsHex;
|
|
@@ -498,8 +538,8 @@ class BitcoinDlcProvider extends provider_1.default {
|
|
|
498
538
|
privkey: fundPrivateKey,
|
|
499
539
|
fundTxId: dlcTxs.fundTx.txId.toString(),
|
|
500
540
|
fundVout: dlcTxs.fundTxVout,
|
|
501
|
-
localFundPubkey: dlcOffer.
|
|
502
|
-
remoteFundPubkey: dlcAccept.
|
|
541
|
+
localFundPubkey: dlcOffer.fundingPubkey.toString('hex'),
|
|
542
|
+
remoteFundPubkey: dlcAccept.fundingPubkey.toString('hex'),
|
|
503
543
|
fundInputAmount: dlcTxs.fundTx.outputs[dlcTxs.fundTxVout].value.sats,
|
|
504
544
|
oraclePubkey: oracleAnnouncement.oraclePubkey.toString('hex'),
|
|
505
545
|
oracleRValues: oracleAnnouncement.oracleEvent.oracleNonces.map((nonce) => nonce.toString('hex')),
|
|
@@ -520,7 +560,11 @@ class BitcoinDlcProvider extends provider_1.default {
|
|
|
520
560
|
else {
|
|
521
561
|
const indices = this.GetIndicesFromPayouts(this.GetPayouts(_dlcOffer));
|
|
522
562
|
for (const [index, { oracleInfo }] of contractOraclePairs.entries()) {
|
|
523
|
-
|
|
563
|
+
if (oracleInfo.type !== messaging_1.MessageType.SingleOracleInfo) {
|
|
564
|
+
throw new Error('Only SingleOracleInfo supported in this context');
|
|
565
|
+
}
|
|
566
|
+
const oracleAnnouncement = oracleInfo
|
|
567
|
+
.announcement;
|
|
524
568
|
const startingIndex = indices[index].startingMessagesIndex, endingIndex = indices[index + 1].startingMessagesIndex;
|
|
525
569
|
const oracleEventMessagesList = messagesList.slice(startingIndex, endingIndex);
|
|
526
570
|
const oracleEventCetsHex = cetsHex.slice(startingIndex, endingIndex);
|
|
@@ -535,8 +579,8 @@ class BitcoinDlcProvider extends provider_1.default {
|
|
|
535
579
|
privkey: fundPrivateKey,
|
|
536
580
|
fundTxId: dlcTxs.fundTx.txId.toString(),
|
|
537
581
|
fundVout: dlcTxs.fundTxVout,
|
|
538
|
-
localFundPubkey: dlcOffer.
|
|
539
|
-
remoteFundPubkey: dlcAccept.
|
|
582
|
+
localFundPubkey: dlcOffer.fundingPubkey.toString('hex'),
|
|
583
|
+
remoteFundPubkey: dlcAccept.fundingPubkey.toString('hex'),
|
|
540
584
|
fundInputAmount: dlcTxs.fundTx.outputs[dlcTxs.fundTxVout].value.sats,
|
|
541
585
|
oraclePubkey: oracleAnnouncement.oraclePubkey.toString('hex'),
|
|
542
586
|
oracleRValues: oracleAnnouncement.oracleEvent.oracleNonces.map((nonce) => nonce.toString('hex')),
|
|
@@ -560,12 +604,12 @@ class BitcoinDlcProvider extends provider_1.default {
|
|
|
560
604
|
privkey: fundPrivateKey,
|
|
561
605
|
fundTxId: dlcTxs.fundTx.txId.toString(),
|
|
562
606
|
fundVout: dlcTxs.fundTxVout,
|
|
563
|
-
localFundPubkey: dlcOffer.
|
|
564
|
-
remoteFundPubkey: dlcAccept.
|
|
607
|
+
localFundPubkey: dlcOffer.fundingPubkey.toString('hex'),
|
|
608
|
+
remoteFundPubkey: dlcAccept.fundingPubkey.toString('hex'),
|
|
565
609
|
fundInputAmount: dlcTxs.fundTx.outputs[dlcTxs.fundTxVout].value.sats,
|
|
566
610
|
};
|
|
567
611
|
const refundSignature = Buffer.from((await this.GetRawRefundTxSignature(refundSignRequest)).hex, 'hex');
|
|
568
|
-
const cetSignatures = new messaging_1.
|
|
612
|
+
const cetSignatures = new messaging_1.CetAdaptorSignatures();
|
|
569
613
|
cetSignatures.sigs = sigs.flat();
|
|
570
614
|
return { cetSignatures, refundSignature };
|
|
571
615
|
}
|
|
@@ -578,15 +622,19 @@ class BitcoinDlcProvider extends provider_1.default {
|
|
|
578
622
|
});
|
|
579
623
|
const cetsHex = dlcTxs.cets.map((cet) => cet.serialize().toString('hex'));
|
|
580
624
|
const contractOraclePairs = this.GetContractOraclePairs(dlcOffer.contractInfo);
|
|
581
|
-
if (dlcOffer.contractInfo.type === messaging_1.MessageType.
|
|
625
|
+
if (dlcOffer.contractInfo.type === messaging_1.MessageType.SingleContractInfo &&
|
|
582
626
|
dlcOffer.contractInfo.contractDescriptor.type ===
|
|
583
627
|
messaging_1.MessageType.ContractDescriptorV0) {
|
|
584
628
|
for (const [_, { oracleInfo }] of contractOraclePairs.entries()) {
|
|
585
|
-
|
|
629
|
+
if (oracleInfo.type !== messaging_1.MessageType.SingleOracleInfo) {
|
|
630
|
+
throw new Error('Only SingleOracleInfo supported in this context');
|
|
631
|
+
}
|
|
632
|
+
const oracleAnnouncement = oracleInfo
|
|
633
|
+
.announcement;
|
|
586
634
|
const oracleEventCetsHex = cetsHex;
|
|
587
635
|
const oracleEventSigs = isOfferer
|
|
588
|
-
? dlcAccept.
|
|
589
|
-
: dlcSign.
|
|
636
|
+
? dlcAccept.cetAdaptorSignatures.sigs
|
|
637
|
+
: dlcSign.cetAdaptorSignatures.sigs;
|
|
590
638
|
const sigsValidity = [];
|
|
591
639
|
const tempMessagesList = messagesList;
|
|
592
640
|
const tempCetsHex = oracleEventCetsHex;
|
|
@@ -603,8 +651,8 @@ class BitcoinDlcProvider extends provider_1.default {
|
|
|
603
651
|
oraclePubkey: oracleAnnouncement.oraclePubkey.toString('hex'),
|
|
604
652
|
oracleRValues: oracleAnnouncement.oracleEvent.oracleNonces.map((nonce) => nonce.toString('hex')),
|
|
605
653
|
adaptorPairs: tempAdaptorPairs,
|
|
606
|
-
localFundPubkey: dlcOffer.
|
|
607
|
-
remoteFundPubkey: dlcAccept.
|
|
654
|
+
localFundPubkey: dlcOffer.fundingPubkey.toString('hex'),
|
|
655
|
+
remoteFundPubkey: dlcAccept.fundingPubkey.toString('hex'),
|
|
608
656
|
fundTxId: dlcTxs.fundTx.txId.toString(),
|
|
609
657
|
fundVout: dlcTxs.fundTxVout,
|
|
610
658
|
fundInputAmount: dlcTxs.fundTx.outputs[dlcTxs.fundTxVout].value.sats,
|
|
@@ -620,8 +668,8 @@ class BitcoinDlcProvider extends provider_1.default {
|
|
|
620
668
|
signature: isOfferer
|
|
621
669
|
? dlcAccept.refundSignature.toString('hex')
|
|
622
670
|
: dlcSign.refundSignature.toString('hex'),
|
|
623
|
-
localFundPubkey: dlcOffer.
|
|
624
|
-
remoteFundPubkey: dlcAccept.
|
|
671
|
+
localFundPubkey: dlcOffer.fundingPubkey.toString('hex'),
|
|
672
|
+
remoteFundPubkey: dlcAccept.fundingPubkey.toString('hex'),
|
|
625
673
|
fundTxId: dlcTxs.fundTx.txId.toString(),
|
|
626
674
|
fundVout: dlcTxs.fundTxVout,
|
|
627
675
|
fundInputAmount: dlcTxs.fundTx.outputs[dlcTxs.fundTxVout].value.sats,
|
|
@@ -639,13 +687,17 @@ class BitcoinDlcProvider extends provider_1.default {
|
|
|
639
687
|
const chunk = 100;
|
|
640
688
|
const indices = this.GetIndicesFromPayouts(this.GetPayouts(_dlcOffer));
|
|
641
689
|
for (const [index, { oracleInfo }] of contractOraclePairs.entries()) {
|
|
642
|
-
|
|
690
|
+
if (oracleInfo.type !== messaging_1.MessageType.SingleOracleInfo) {
|
|
691
|
+
throw new Error('Only SingleOracleInfo supported in this context');
|
|
692
|
+
}
|
|
693
|
+
const oracleAnnouncement = oracleInfo
|
|
694
|
+
.announcement;
|
|
643
695
|
const startingIndex = indices[index].startingMessagesIndex, endingIndex = indices[index + 1].startingMessagesIndex;
|
|
644
696
|
const oracleEventMessagesList = messagesList.slice(startingIndex, endingIndex);
|
|
645
697
|
const oracleEventCetsHex = cetsHex.slice(startingIndex, endingIndex);
|
|
646
698
|
const oracleEventSigs = (isOfferer
|
|
647
|
-
? dlcAccept.
|
|
648
|
-
: dlcSign.
|
|
699
|
+
? dlcAccept.cetAdaptorSignatures.sigs
|
|
700
|
+
: dlcSign.cetAdaptorSignatures.sigs).slice(startingIndex, endingIndex);
|
|
649
701
|
const sigsValidity = [];
|
|
650
702
|
for (let i = 0, j = oracleEventMessagesList.length; i < j; i += chunk) {
|
|
651
703
|
const tempMessagesList = oracleEventMessagesList.slice(i, i + chunk);
|
|
@@ -663,8 +715,8 @@ class BitcoinDlcProvider extends provider_1.default {
|
|
|
663
715
|
oraclePubkey: oracleAnnouncement.oraclePubkey.toString('hex'),
|
|
664
716
|
oracleRValues: oracleAnnouncement.oracleEvent.oracleNonces.map((nonce) => nonce.toString('hex')),
|
|
665
717
|
adaptorPairs: tempAdaptorPairs,
|
|
666
|
-
localFundPubkey: dlcOffer.
|
|
667
|
-
remoteFundPubkey: dlcAccept.
|
|
718
|
+
localFundPubkey: dlcOffer.fundingPubkey.toString('hex'),
|
|
719
|
+
remoteFundPubkey: dlcAccept.fundingPubkey.toString('hex'),
|
|
668
720
|
fundTxId: dlcTxs.fundTx.txId.toString(),
|
|
669
721
|
fundVout: dlcTxs.fundTxVout,
|
|
670
722
|
fundInputAmount: dlcTxs.fundTx.outputs[dlcTxs.fundTxVout].value.sats,
|
|
@@ -681,8 +733,8 @@ class BitcoinDlcProvider extends provider_1.default {
|
|
|
681
733
|
signature: isOfferer
|
|
682
734
|
? dlcAccept.refundSignature.toString('hex')
|
|
683
735
|
: dlcSign.refundSignature.toString('hex'),
|
|
684
|
-
localFundPubkey: dlcOffer.
|
|
685
|
-
remoteFundPubkey: dlcAccept.
|
|
736
|
+
localFundPubkey: dlcOffer.fundingPubkey.toString('hex'),
|
|
737
|
+
remoteFundPubkey: dlcAccept.fundingPubkey.toString('hex'),
|
|
686
738
|
fundTxId: dlcTxs.fundTx.txId.toString(),
|
|
687
739
|
fundVout: dlcTxs.fundTxVout,
|
|
688
740
|
fundInputAmount: dlcTxs.fundTx.outputs[dlcTxs.fundTxVout].value.sats,
|
|
@@ -736,17 +788,11 @@ class BitcoinDlcProvider extends provider_1.default {
|
|
|
736
788
|
pubKeyWitness.witness = Buffer.from(inputPubKeys[i], 'hex');
|
|
737
789
|
witnessElements.push([sigWitness, pubKeyWitness]);
|
|
738
790
|
}
|
|
739
|
-
const fundingSignatures = new messaging_1.
|
|
791
|
+
const fundingSignatures = new messaging_1.FundingSignatures();
|
|
740
792
|
fundingSignatures.witnessElements = witnessElements;
|
|
741
793
|
return fundingSignatures;
|
|
742
794
|
}
|
|
743
|
-
async VerifyFundingSigs(
|
|
744
|
-
const { dlcOffer, dlcAccept, dlcSign, dlcTxs } = (0, Utils_1.checkTypes)({
|
|
745
|
-
_dlcOffer,
|
|
746
|
-
_dlcAccept,
|
|
747
|
-
_dlcSign,
|
|
748
|
-
_dlcTxs,
|
|
749
|
-
});
|
|
795
|
+
async VerifyFundingSigs(dlcOffer, dlcAccept, dlcSign, dlcTxs, isOfferer) {
|
|
750
796
|
const sigsValidity = [];
|
|
751
797
|
for (let i = 0; i < dlcSign.fundingSignatures.witnessElements.length; i++) {
|
|
752
798
|
const witnessElement = dlcSign.fundingSignatures.witnessElements[i];
|
|
@@ -773,13 +819,7 @@ class BitcoinDlcProvider extends provider_1.default {
|
|
|
773
819
|
throw new Error('Invalid signatures received');
|
|
774
820
|
}
|
|
775
821
|
}
|
|
776
|
-
async CreateFundingTx(
|
|
777
|
-
const { dlcOffer, dlcAccept, dlcSign, dlcTxs } = (0, Utils_1.checkTypes)({
|
|
778
|
-
_dlcOffer,
|
|
779
|
-
_dlcAccept,
|
|
780
|
-
_dlcSign,
|
|
781
|
-
_dlcTxs,
|
|
782
|
-
});
|
|
822
|
+
async CreateFundingTx(dlcOffer, dlcAccept, dlcSign, dlcTxs, fundingSignatures) {
|
|
783
823
|
const witnessElements = [
|
|
784
824
|
...dlcSign.fundingSignatures.witnessElements,
|
|
785
825
|
...fundingSignatures.witnessElements,
|
|
@@ -806,8 +846,7 @@ class BitcoinDlcProvider extends provider_1.default {
|
|
|
806
846
|
const fundTx = bitcoin_1.Tx.decode(bufio_1.StreamReader.fromHex(fundTxHex));
|
|
807
847
|
return fundTx;
|
|
808
848
|
}
|
|
809
|
-
async FindOutcomeIndexFromPolynomialPayoutCurvePiece(
|
|
810
|
-
const { dlcOffer } = (0, Utils_1.checkTypes)({ _dlcOffer });
|
|
849
|
+
async FindOutcomeIndexFromPolynomialPayoutCurvePiece(dlcOffer, contractDescriptor, contractOraclePairIndex, polynomialPayoutCurvePiece, oracleAttestation, outcome) {
|
|
811
850
|
const polynomialCurve = core_1.PolynomialPayoutCurve.fromPayoutCurvePiece(polynomialPayoutCurvePiece);
|
|
812
851
|
const payouts = polynomialPayoutCurvePiece.points.map((point) => Number(point.outcomePayout));
|
|
813
852
|
const minPayout = Math.min(...payouts);
|
|
@@ -815,7 +854,8 @@ class BitcoinDlcProvider extends provider_1.default {
|
|
|
815
854
|
const clampBN = (val) => bignumber_js_1.default.max(minPayout, bignumber_js_1.default.min(val, maxPayout));
|
|
816
855
|
const payout = clampBN(polynomialCurve.getPayout(outcome));
|
|
817
856
|
const payoutResponses = this.GetPayouts(dlcOffer);
|
|
818
|
-
const payoutIndexOffset = this.GetIndicesFromPayouts(payoutResponses)[contractOraclePairIndex]
|
|
857
|
+
const payoutIndexOffset = this.GetIndicesFromPayouts(payoutResponses)[contractOraclePairIndex]
|
|
858
|
+
.startingMessagesIndex;
|
|
819
859
|
const { payoutGroups } = payoutResponses[contractOraclePairIndex];
|
|
820
860
|
const intervalsSorted = [
|
|
821
861
|
...contractDescriptor.roundingIntervals.intervals,
|
|
@@ -853,7 +893,8 @@ Payout Group not found');
|
|
|
853
893
|
const clampBN = (val) => bignumber_js_1.default.max(0, bignumber_js_1.default.min(val, dlcOffer.contractInfo.totalCollateral.toString()));
|
|
854
894
|
const payout = clampBN(hyperbolaCurve.getPayout(outcome));
|
|
855
895
|
const payoutResponses = this.GetPayouts(dlcOffer);
|
|
856
|
-
const payoutIndexOffset = this.GetIndicesFromPayouts(payoutResponses)[contractOraclePairIndex]
|
|
896
|
+
const payoutIndexOffset = this.GetIndicesFromPayouts(payoutResponses)[contractOraclePairIndex]
|
|
897
|
+
.startingMessagesIndex;
|
|
857
898
|
const { payoutGroups } = payoutResponses[contractOraclePairIndex];
|
|
858
899
|
const intervalsSorted = [
|
|
859
900
|
...contractDescriptor.roundingIntervals.intervals,
|
|
@@ -897,32 +938,59 @@ Payout Group not found');
|
|
|
897
938
|
}
|
|
898
939
|
}
|
|
899
940
|
if (groupIndex === -1) {
|
|
900
|
-
|
|
901
|
-
|
|
941
|
+
// Fallback to brute force search if payout-based search fails
|
|
942
|
+
index = 0;
|
|
943
|
+
groupLength = 0;
|
|
944
|
+
for (const [i, payoutGroup] of payoutGroups.entries()) {
|
|
945
|
+
groupIndex = payoutGroup.groups.findIndex((group) => {
|
|
946
|
+
return group.every((msg, j) => msg === outcomesFormatted[j]);
|
|
947
|
+
});
|
|
948
|
+
if (groupIndex !== -1) {
|
|
949
|
+
index += groupIndex;
|
|
950
|
+
groupLength = payoutGroup.groups[groupIndex].length;
|
|
951
|
+
break;
|
|
952
|
+
}
|
|
953
|
+
else {
|
|
954
|
+
index += payoutGroup.groups.length;
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
if (groupIndex === -1) {
|
|
958
|
+
throw Error('Failed to Find OutcomeIndex From HyperbolaPayoutCurvePiece. \
|
|
959
|
+
Payout Group not found even with brute force search');
|
|
960
|
+
}
|
|
902
961
|
}
|
|
903
962
|
return { index: payoutIndexOffset + index, groupLength };
|
|
904
963
|
}
|
|
905
|
-
async FindOutcomeIndex(
|
|
906
|
-
const { dlcOffer } = (0, Utils_1.checkTypes)({ _dlcOffer });
|
|
964
|
+
async FindOutcomeIndex(dlcOffer, oracleAttestation) {
|
|
907
965
|
const contractOraclePairs = this.GetContractOraclePairs(dlcOffer.contractInfo);
|
|
908
|
-
const contractOraclePairIndex = contractOraclePairs.findIndex(({ oracleInfo }) =>
|
|
909
|
-
|
|
966
|
+
const contractOraclePairIndex = contractOraclePairs.findIndex(({ oracleInfo }) => {
|
|
967
|
+
if (oracleInfo.type !== messaging_1.MessageType.SingleOracleInfo)
|
|
968
|
+
return false;
|
|
969
|
+
const singleOracleInfo = oracleInfo;
|
|
970
|
+
return (singleOracleInfo.announcement.oracleEvent.eventId ===
|
|
971
|
+
oracleAttestation.eventId);
|
|
972
|
+
});
|
|
910
973
|
(0, assert_1.default)(contractOraclePairIndex !== -1, 'OracleAttestation must be for an existing OracleEvent');
|
|
911
974
|
const contractOraclePair = contractOraclePairs[contractOraclePairIndex];
|
|
912
|
-
const { contractDescriptor: _contractDescriptor, oracleInfo
|
|
913
|
-
(0, assert_1.default)(_contractDescriptor.
|
|
975
|
+
const { contractDescriptor: _contractDescriptor, oracleInfo } = contractOraclePair;
|
|
976
|
+
(0, assert_1.default)(_contractDescriptor.contractDescriptorType ===
|
|
977
|
+
messaging_1.ContractDescriptorType.NumericOutcome, 'ContractDescriptor must be NumericOutcome');
|
|
914
978
|
const contractDescriptor = _contractDescriptor;
|
|
915
979
|
const _payoutFunction = contractDescriptor.payoutFunction;
|
|
916
|
-
(0, assert_1.default)(_payoutFunction.type === messaging_1.MessageType.
|
|
917
|
-
|
|
980
|
+
(0, assert_1.default)(_payoutFunction.type === messaging_1.MessageType.PayoutFunction, 'PayoutFunction must be V0');
|
|
981
|
+
if (oracleInfo.type !== messaging_1.MessageType.SingleOracleInfo) {
|
|
982
|
+
throw new Error('Only SingleOracleInfo supported in this context');
|
|
983
|
+
}
|
|
984
|
+
const singleOracleInfo = oracleInfo;
|
|
985
|
+
const eventDescriptor = singleOracleInfo.announcement.oracleEvent
|
|
918
986
|
.eventDescriptor;
|
|
919
987
|
const payoutFunction = _payoutFunction;
|
|
920
988
|
const base = eventDescriptor.base;
|
|
921
989
|
const outcome = [...oracleAttestation.outcomes]
|
|
922
990
|
.reverse()
|
|
923
991
|
.reduce((acc, val, i) => acc + Number(val) * base ** i, 0);
|
|
924
|
-
const piecesSorted = payoutFunction.
|
|
925
|
-
const piece = piecesSorted.find((piece) => outcome < piece.
|
|
992
|
+
const piecesSorted = payoutFunction.payoutFunctionPieces.sort((a, b) => Number(a.endPoint.eventOutcome) - Number(b.endPoint.eventOutcome));
|
|
993
|
+
const piece = piecesSorted.find((piece) => outcome < piece.endPoint.eventOutcome);
|
|
926
994
|
switch (piece.payoutCurvePiece.type) {
|
|
927
995
|
case messaging_1.MessageType.PolynomialPayoutCurvePiece:
|
|
928
996
|
return this.FindOutcomeIndexFromPolynomialPayoutCurvePiece(dlcOffer, contractDescriptor, contractOraclePairIndex, piece.payoutCurvePiece, oracleAttestation, BigInt(outcome));
|
|
@@ -934,24 +1002,29 @@ Payout Group not found');
|
|
|
934
1002
|
throw Error('Must be Hyperbola or Polynomial curve piece');
|
|
935
1003
|
}
|
|
936
1004
|
}
|
|
937
|
-
ValidateEvent(
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
});
|
|
941
|
-
switch (dlcOffer.contractInfo.type) {
|
|
942
|
-
case messaging_1.MessageType.ContractInfoV0: {
|
|
1005
|
+
ValidateEvent(dlcOffer, oracleAttestation) {
|
|
1006
|
+
switch (dlcOffer.contractInfo.contractInfoType) {
|
|
1007
|
+
case messaging_1.ContractInfoType.Single: {
|
|
943
1008
|
const contractInfo = dlcOffer.contractInfo;
|
|
944
|
-
switch (contractInfo.contractDescriptor.
|
|
945
|
-
case messaging_1.
|
|
1009
|
+
switch (contractInfo.contractDescriptor.contractDescriptorType) {
|
|
1010
|
+
case messaging_1.ContractDescriptorType.Enumerated: {
|
|
946
1011
|
const oracleInfo = contractInfo.oracleInfo;
|
|
947
|
-
if (oracleInfo.
|
|
1012
|
+
if (oracleInfo.type !== messaging_1.MessageType.SingleOracleInfo) {
|
|
1013
|
+
throw Error('Only SingleOracleInfo supported in this context');
|
|
1014
|
+
}
|
|
1015
|
+
const singleOracleInfo = oracleInfo;
|
|
1016
|
+
if (singleOracleInfo.announcement.oracleEvent.eventId !==
|
|
948
1017
|
oracleAttestation.eventId)
|
|
949
1018
|
throw Error('Incorrect Oracle Attestation. Event Id must match.');
|
|
950
1019
|
break;
|
|
951
1020
|
}
|
|
952
|
-
case messaging_1.
|
|
1021
|
+
case messaging_1.ContractDescriptorType.NumericOutcome: {
|
|
953
1022
|
const oracleInfo = contractInfo.oracleInfo;
|
|
954
|
-
if (oracleInfo.
|
|
1023
|
+
if (oracleInfo.type !== messaging_1.MessageType.SingleOracleInfo) {
|
|
1024
|
+
throw Error('Only SingleOracleInfo supported in this context');
|
|
1025
|
+
}
|
|
1026
|
+
const singleOracleInfo = oracleInfo;
|
|
1027
|
+
if (singleOracleInfo.announcement.oracleEvent.eventId !==
|
|
955
1028
|
oracleAttestation.eventId)
|
|
956
1029
|
throw Error('Incorrect Oracle Attestation. Event Id must match.');
|
|
957
1030
|
break;
|
|
@@ -961,10 +1034,15 @@ Payout Group not found');
|
|
|
961
1034
|
}
|
|
962
1035
|
break;
|
|
963
1036
|
}
|
|
964
|
-
case messaging_1.
|
|
1037
|
+
case messaging_1.ContractInfoType.Disjoint: {
|
|
965
1038
|
const contractInfo = dlcOffer.contractInfo;
|
|
966
|
-
const attestedOracleEvent = contractInfo.contractOraclePairs.find(({ oracleInfo }) =>
|
|
967
|
-
|
|
1039
|
+
const attestedOracleEvent = contractInfo.contractOraclePairs.find(({ oracleInfo }) => {
|
|
1040
|
+
if (oracleInfo.type !== messaging_1.MessageType.SingleOracleInfo)
|
|
1041
|
+
return false;
|
|
1042
|
+
const singleOracleInfo = oracleInfo;
|
|
1043
|
+
return (singleOracleInfo.announcement.oracleEvent.eventId ===
|
|
1044
|
+
oracleAttestation.eventId);
|
|
1045
|
+
});
|
|
968
1046
|
if (!attestedOracleEvent)
|
|
969
1047
|
throw Error('Oracle event of attestation not found.');
|
|
970
1048
|
break;
|
|
@@ -973,35 +1051,29 @@ Payout Group not found');
|
|
|
973
1051
|
throw Error('ContractInfo must be V0 or V1');
|
|
974
1052
|
}
|
|
975
1053
|
}
|
|
976
|
-
async FindAndSignCet(
|
|
977
|
-
const { dlcOffer, dlcAccept, dlcSign, dlcTxs } = (0, Utils_1.checkTypes)({
|
|
978
|
-
_dlcOffer,
|
|
979
|
-
_dlcAccept,
|
|
980
|
-
_dlcSign,
|
|
981
|
-
_dlcTxs,
|
|
982
|
-
});
|
|
1054
|
+
async FindAndSignCet(dlcOffer, dlcAccept, dlcSign, dlcTxs, oracleAttestation, isOfferer) {
|
|
983
1055
|
if (isOfferer === undefined)
|
|
984
1056
|
isOfferer = await this.isOfferer(dlcOffer, dlcAccept);
|
|
985
1057
|
const fundPrivateKey = await this.GetFundPrivateKey(dlcOffer, dlcAccept, isOfferer);
|
|
986
1058
|
let signCetRequest;
|
|
987
|
-
if (dlcOffer.contractInfo.
|
|
988
|
-
dlcOffer.contractInfo.contractDescriptor
|
|
989
|
-
messaging_1.
|
|
1059
|
+
if (dlcOffer.contractInfo.contractInfoType === messaging_1.ContractInfoType.Single &&
|
|
1060
|
+
dlcOffer.contractInfo.contractDescriptor
|
|
1061
|
+
.contractDescriptorType === messaging_1.ContractDescriptorType.Enumerated) {
|
|
990
1062
|
const outcomeIndex = dlcOffer.contractInfo
|
|
991
|
-
.contractDescriptor.outcomes.findIndex((outcome) => outcome.outcome
|
|
1063
|
+
.contractDescriptor.outcomes.findIndex((outcome) => outcome.outcome ===
|
|
992
1064
|
(0, crypto_1.sha256)(Buffer.from(oracleAttestation.outcomes[0])).toString('hex'));
|
|
993
1065
|
signCetRequest = {
|
|
994
1066
|
cetHex: dlcTxs.cets[outcomeIndex].serialize().toString('hex'),
|
|
995
1067
|
fundPrivkey: fundPrivateKey,
|
|
996
1068
|
fundTxId: dlcTxs.fundTx.txId.toString(),
|
|
997
1069
|
fundVout: dlcTxs.fundTxVout,
|
|
998
|
-
localFundPubkey: dlcOffer.
|
|
999
|
-
remoteFundPubkey: dlcAccept.
|
|
1070
|
+
localFundPubkey: dlcOffer.fundingPubkey.toString('hex'),
|
|
1071
|
+
remoteFundPubkey: dlcAccept.fundingPubkey.toString('hex'),
|
|
1000
1072
|
oracleSignatures: oracleAttestation.signatures.map((sig) => sig.toString('hex')),
|
|
1001
1073
|
fundInputAmount: dlcTxs.fundTx.outputs[dlcTxs.fundTxVout].value.sats,
|
|
1002
1074
|
adaptorSignature: isOfferer
|
|
1003
|
-
? dlcAccept.
|
|
1004
|
-
: dlcSign.
|
|
1075
|
+
? dlcAccept.cetAdaptorSignatures.sigs[outcomeIndex].encryptedSig.toString('hex')
|
|
1076
|
+
: dlcSign.cetAdaptorSignatures.sigs[outcomeIndex].encryptedSig.toString('hex'),
|
|
1005
1077
|
};
|
|
1006
1078
|
}
|
|
1007
1079
|
else {
|
|
@@ -1015,13 +1087,13 @@ Payout Group not found');
|
|
|
1015
1087
|
fundPrivkey: fundPrivateKey,
|
|
1016
1088
|
fundTxId: dlcTxs.fundTx.txId.toString(),
|
|
1017
1089
|
fundVout: dlcTxs.fundTxVout,
|
|
1018
|
-
localFundPubkey: dlcOffer.
|
|
1019
|
-
remoteFundPubkey: dlcAccept.
|
|
1090
|
+
localFundPubkey: dlcOffer.fundingPubkey.toString('hex'),
|
|
1091
|
+
remoteFundPubkey: dlcAccept.fundingPubkey.toString('hex'),
|
|
1020
1092
|
oracleSignatures: oracleSignatures.map((sig) => sig.toString('hex')),
|
|
1021
1093
|
fundInputAmount: dlcTxs.fundTx.outputs[dlcTxs.fundTxVout].value.sats,
|
|
1022
1094
|
adaptorSignature: isOfferer
|
|
1023
|
-
? dlcAccept.
|
|
1024
|
-
: dlcSign.
|
|
1095
|
+
? dlcAccept.cetAdaptorSignatures.sigs[outcomeIndex].encryptedSig.toString('hex')
|
|
1096
|
+
: dlcSign.cetAdaptorSignatures.sigs[outcomeIndex].encryptedSig.toString('hex'),
|
|
1025
1097
|
};
|
|
1026
1098
|
}
|
|
1027
1099
|
const finalCet = (await this.SignCet(signCetRequest)).hex;
|
|
@@ -1029,7 +1101,7 @@ Payout Group not found');
|
|
|
1029
1101
|
}
|
|
1030
1102
|
async GetFundAddress(dlcOffer, dlcAccept, isOfferer) {
|
|
1031
1103
|
const network = await this.getConnectedNetwork();
|
|
1032
|
-
const fundingSPK = bitcoin_1.Script.p2wpkhLock((0, crypto_1.hash160)(isOfferer ? dlcOffer.
|
|
1104
|
+
const fundingSPK = bitcoin_1.Script.p2wpkhLock((0, crypto_1.hash160)(isOfferer ? dlcOffer.fundingPubkey : dlcAccept.fundingPubkey))
|
|
1033
1105
|
.serialize()
|
|
1034
1106
|
.slice(1);
|
|
1035
1107
|
const fundingAddress = bitcoinjs_lib_1.address.fromOutputScript(fundingSPK, network);
|
|
@@ -1045,16 +1117,11 @@ Payout Group not found');
|
|
|
1045
1117
|
const fundPrivateKeyPair = await this.GetFundKeyPair(dlcOffer, dlcAccept, isOfferer);
|
|
1046
1118
|
return Buffer.from(fundPrivateKeyPair.privateKey).toString('hex');
|
|
1047
1119
|
}
|
|
1048
|
-
async CreateCloseRawTxs(
|
|
1049
|
-
const { dlcOffer, dlcAccept, dlcTxs } = (0, Utils_1.checkTypes)({
|
|
1050
|
-
_dlcOffer,
|
|
1051
|
-
_dlcAccept,
|
|
1052
|
-
_dlcTxs,
|
|
1053
|
-
});
|
|
1120
|
+
async CreateCloseRawTxs(dlcOffer, dlcAccept, dlcTxs, closeInputAmount, isOfferer, _dlcCloses = [], fundingInputs, initiatorPayouts) {
|
|
1054
1121
|
const network = await this.getConnectedNetwork();
|
|
1055
1122
|
let finalizer;
|
|
1056
1123
|
if (_dlcCloses.length === 0) {
|
|
1057
|
-
finalizer = new core_1.DualClosingTxFinalizer(fundingInputs, dlcOffer.
|
|
1124
|
+
finalizer = new core_1.DualClosingTxFinalizer(fundingInputs, dlcOffer.payoutSpk, dlcAccept.payoutSpk, dlcOffer.feeRatePerVb);
|
|
1058
1125
|
}
|
|
1059
1126
|
const rawTransactionRequestPromises = [];
|
|
1060
1127
|
const rawCloseTxs = [];
|
|
@@ -1085,13 +1152,13 @@ Payout Group not found');
|
|
|
1085
1152
|
const txOuts = [];
|
|
1086
1153
|
if (Number(offerPayoutValue) > 0) {
|
|
1087
1154
|
txOuts.push({
|
|
1088
|
-
address: bitcoinjs_lib_1.address.fromOutputScript(dlcOffer.
|
|
1155
|
+
address: bitcoinjs_lib_1.address.fromOutputScript(dlcOffer.payoutSpk, network),
|
|
1089
1156
|
amount: Number(offerPayoutValue),
|
|
1090
1157
|
});
|
|
1091
1158
|
}
|
|
1092
1159
|
if (Number(acceptPayoutValue) > 0) {
|
|
1093
1160
|
txOuts.push({
|
|
1094
|
-
address: bitcoinjs_lib_1.address.fromOutputScript(dlcAccept.
|
|
1161
|
+
address: bitcoinjs_lib_1.address.fromOutputScript(dlcAccept.payoutSpk, network),
|
|
1095
1162
|
amount: Number(acceptPayoutValue),
|
|
1096
1163
|
});
|
|
1097
1164
|
}
|
|
@@ -1125,9 +1192,9 @@ Payout Group not found');
|
|
|
1125
1192
|
_dlcTxs,
|
|
1126
1193
|
});
|
|
1127
1194
|
const network = await this.getConnectedNetwork();
|
|
1128
|
-
const fundingPubKeys = Buffer.compare(dlcOffer.
|
|
1129
|
-
? [dlcOffer.
|
|
1130
|
-
: [dlcAccept.
|
|
1195
|
+
const fundingPubKeys = Buffer.compare(dlcOffer.fundingPubkey, dlcAccept.fundingPubkey) === -1
|
|
1196
|
+
? [dlcOffer.fundingPubkey, dlcAccept.fundingPubkey]
|
|
1197
|
+
: [dlcAccept.fundingPubkey, dlcOffer.fundingPubkey];
|
|
1131
1198
|
const p2ms = bitcoinjs_lib_1.payments.p2ms({
|
|
1132
1199
|
m: 2,
|
|
1133
1200
|
pubkeys: fundingPubKeys,
|
|
@@ -1195,9 +1262,9 @@ Payout Group not found');
|
|
|
1195
1262
|
});
|
|
1196
1263
|
const dlcCloses = _dlcCloses.map((_dlcClose) => (0, Utils_1.checkTypes)({ _dlcClose }).dlcClose);
|
|
1197
1264
|
const network = await this.getConnectedNetwork();
|
|
1198
|
-
const fundingPubKeys = Buffer.compare(dlcOffer.
|
|
1199
|
-
? [dlcOffer.
|
|
1200
|
-
: [dlcAccept.
|
|
1265
|
+
const fundingPubKeys = Buffer.compare(dlcOffer.fundingPubkey, dlcAccept.fundingPubkey) === -1
|
|
1266
|
+
? [dlcOffer.fundingPubkey, dlcAccept.fundingPubkey]
|
|
1267
|
+
: [dlcAccept.fundingPubkey, dlcOffer.fundingPubkey];
|
|
1201
1268
|
const p2ms = bitcoinjs_lib_1.payments.p2ms({
|
|
1202
1269
|
m: 2,
|
|
1203
1270
|
pubkeys: fundingPubKeys,
|
|
@@ -1207,7 +1274,7 @@ Payout Group not found');
|
|
|
1207
1274
|
redeem: p2ms,
|
|
1208
1275
|
network,
|
|
1209
1276
|
});
|
|
1210
|
-
const pubkey = isOfferer ? dlcAccept.
|
|
1277
|
+
const pubkey = isOfferer ? dlcAccept.fundingPubkey : dlcOffer.fundingPubkey;
|
|
1211
1278
|
const sigsValidity = [];
|
|
1212
1279
|
for (let i = 0; i < rawCloseTxs.length; i++) {
|
|
1213
1280
|
const rawTx = rawCloseTxs[i];
|
|
@@ -1246,10 +1313,10 @@ Payout Group not found');
|
|
|
1246
1313
|
_dlcAccept,
|
|
1247
1314
|
});
|
|
1248
1315
|
const network = await this.getConnectedNetwork();
|
|
1249
|
-
const offerFundingSPK = bitcoin_1.Script.p2wpkhLock((0, crypto_1.hash160)(dlcOffer.
|
|
1316
|
+
const offerFundingSPK = bitcoin_1.Script.p2wpkhLock((0, crypto_1.hash160)(dlcOffer.fundingPubkey))
|
|
1250
1317
|
.serialize()
|
|
1251
1318
|
.slice(1);
|
|
1252
|
-
const acceptFundingSPK = bitcoin_1.Script.p2wpkhLock((0, crypto_1.hash160)(dlcAccept.
|
|
1319
|
+
const acceptFundingSPK = bitcoin_1.Script.p2wpkhLock((0, crypto_1.hash160)(dlcAccept.fundingPubkey))
|
|
1253
1320
|
.serialize()
|
|
1254
1321
|
.slice(1);
|
|
1255
1322
|
const offerFundingAddress = bitcoinjs_lib_1.address.fromOutputScript(offerFundingSPK, network);
|
|
@@ -1278,9 +1345,11 @@ Payout Group not found');
|
|
|
1278
1345
|
async createDlcOffer(contractInfo, offerCollateralSatoshis, feeRatePerVb, cetLocktime, refundLocktime, fixedInputs) {
|
|
1279
1346
|
contractInfo.validate();
|
|
1280
1347
|
const network = await this.getConnectedNetwork();
|
|
1281
|
-
const dlcOffer = new messaging_1.
|
|
1348
|
+
const dlcOffer = new messaging_1.DlcOffer();
|
|
1349
|
+
// Generate a random 32-byte temporary contract ID
|
|
1350
|
+
dlcOffer.temporaryContractId = crypto_2.default.randomBytes(32);
|
|
1282
1351
|
const { fundingPubKey, payoutSPK, payoutSerialId, fundingInputs: _fundingInputs, changeSPK, changeSerialId, } = await this.Initialize(offerCollateralSatoshis, feeRatePerVb, fixedInputs);
|
|
1283
|
-
_fundingInputs.forEach((input) => (0, assert_1.default)(input.type === messaging_1.MessageType.
|
|
1352
|
+
_fundingInputs.forEach((input) => (0, assert_1.default)(input.type === messaging_1.MessageType.FundingInput, 'FundingInput must be V0'));
|
|
1284
1353
|
const fundingInputs = _fundingInputs.map((input) => input);
|
|
1285
1354
|
fundingInputs.sort((a, b) => Number(a.inputSerialId) - Number(b.inputSerialId));
|
|
1286
1355
|
const fundOutputSerialId = (0, Utils_1.generateSerialId)();
|
|
@@ -1288,19 +1357,20 @@ Payout Group not found');
|
|
|
1288
1357
|
dlcOffer.contractFlags = Buffer.from('00', 'hex');
|
|
1289
1358
|
dlcOffer.chainHash = (0, bitcoin_networks_1.chainHashFromNetwork)(network);
|
|
1290
1359
|
dlcOffer.contractInfo = contractInfo;
|
|
1291
|
-
dlcOffer.
|
|
1292
|
-
dlcOffer.
|
|
1360
|
+
dlcOffer.fundingPubkey = fundingPubKey;
|
|
1361
|
+
dlcOffer.payoutSpk = payoutSPK;
|
|
1293
1362
|
dlcOffer.payoutSerialId = payoutSerialId;
|
|
1294
|
-
dlcOffer.
|
|
1363
|
+
dlcOffer.offerCollateral = offerCollateralSatoshis;
|
|
1295
1364
|
dlcOffer.fundingInputs = fundingInputs;
|
|
1296
|
-
dlcOffer.
|
|
1365
|
+
dlcOffer.changeSpk = changeSPK;
|
|
1297
1366
|
dlcOffer.changeSerialId = changeSerialId;
|
|
1298
|
-
dlcOffer.fundOutputSerialId = dlcOffer.fundOutputSerialId =
|
|
1367
|
+
dlcOffer.fundOutputSerialId = dlcOffer.fundOutputSerialId =
|
|
1368
|
+
fundOutputSerialId;
|
|
1299
1369
|
dlcOffer.feeRatePerVb = feeRatePerVb;
|
|
1300
1370
|
dlcOffer.cetLocktime = cetLocktime;
|
|
1301
1371
|
dlcOffer.refundLocktime = refundLocktime;
|
|
1302
1372
|
(0, assert_1.default)((() => {
|
|
1303
|
-
const finalizer = new core_1.DualFundingTxFinalizer(dlcOffer.fundingInputs, dlcOffer.
|
|
1373
|
+
const finalizer = new core_1.DualFundingTxFinalizer(dlcOffer.fundingInputs, dlcOffer.payoutSpk, dlcOffer.changeSpk, null, null, null, dlcOffer.feeRatePerVb);
|
|
1304
1374
|
const funding = fundingInputs.reduce((total, input) => {
|
|
1305
1375
|
return total + input.prevTx.outputs[input.prevTxVout].value.sats;
|
|
1306
1376
|
}, BigInt(0));
|
|
@@ -1320,7 +1390,7 @@ Payout Group not found');
|
|
|
1320
1390
|
}
|
|
1321
1391
|
const network = await this.getConnectedNetwork();
|
|
1322
1392
|
const { fundingInputs: _fundingInputs, changeSPK, changeSerialId, initializeResponses, } = await this.BatchInitialize(offerCollaterals, feeRatePerVb, fixedInputs);
|
|
1323
|
-
_fundingInputs.forEach((input) => (0, assert_1.default)(input.type === messaging_1.MessageType.
|
|
1393
|
+
_fundingInputs.forEach((input) => (0, assert_1.default)(input.type === messaging_1.MessageType.FundingInput, 'FundingInput must be V0'));
|
|
1324
1394
|
const fundingInputs = _fundingInputs.map((input) => input);
|
|
1325
1395
|
fundingInputs.sort((a, b) => Number(a.inputSerialId) - Number(b.inputSerialId));
|
|
1326
1396
|
const fundOutputsSerialIds = (0, Utils_1.generateSerialIds)(contractInfos.length);
|
|
@@ -1330,23 +1400,25 @@ Payout Group not found');
|
|
|
1330
1400
|
const fundOutputSerialId = fundOutputsSerialIds[i];
|
|
1331
1401
|
const { fundingPubKey, payoutSPK, payoutSerialId } = initializeResponses[i];
|
|
1332
1402
|
const refundLocktime = refundLocktimes[i];
|
|
1333
|
-
const dlcOffer = new messaging_1.
|
|
1403
|
+
const dlcOffer = new messaging_1.DlcOffer();
|
|
1404
|
+
// Generate a random 32-byte temporary contract ID
|
|
1405
|
+
dlcOffer.temporaryContractId = crypto_2.default.randomBytes(32);
|
|
1334
1406
|
dlcOffer.contractFlags = Buffer.from('00', 'hex');
|
|
1335
1407
|
dlcOffer.chainHash = (0, bitcoin_networks_1.chainHashFromNetwork)(network);
|
|
1336
1408
|
dlcOffer.contractInfo = contractInfo;
|
|
1337
|
-
dlcOffer.
|
|
1338
|
-
dlcOffer.
|
|
1409
|
+
dlcOffer.fundingPubkey = fundingPubKey;
|
|
1410
|
+
dlcOffer.payoutSpk = payoutSPK;
|
|
1339
1411
|
dlcOffer.payoutSerialId = payoutSerialId;
|
|
1340
|
-
dlcOffer.
|
|
1412
|
+
dlcOffer.offerCollateral = offerCollateralSatoshis;
|
|
1341
1413
|
dlcOffer.fundingInputs = fundingInputs;
|
|
1342
|
-
dlcOffer.
|
|
1414
|
+
dlcOffer.changeSpk = changeSPK;
|
|
1343
1415
|
dlcOffer.changeSerialId = changeSerialId;
|
|
1344
1416
|
dlcOffer.fundOutputSerialId = fundOutputSerialId;
|
|
1345
1417
|
dlcOffer.feeRatePerVb = feeRatePerVb;
|
|
1346
1418
|
dlcOffer.cetLocktime = cetLocktime;
|
|
1347
1419
|
dlcOffer.refundLocktime = refundLocktime;
|
|
1348
1420
|
(0, assert_1.default)((() => {
|
|
1349
|
-
const finalizer = new core_1.DualFundingTxFinalizer(dlcOffer.fundingInputs, dlcOffer.
|
|
1421
|
+
const finalizer = new core_1.DualFundingTxFinalizer(dlcOffer.fundingInputs, dlcOffer.payoutSpk, dlcOffer.changeSpk, null, null, null, dlcOffer.feeRatePerVb);
|
|
1350
1422
|
const funding = fundingInputs.reduce((total, input) => {
|
|
1351
1423
|
return total + input.prevTx.outputs[input.prevTxVout].value.sats;
|
|
1352
1424
|
}, BigInt(0));
|
|
@@ -1366,23 +1438,22 @@ Payout Group not found');
|
|
|
1366
1438
|
async acceptDlcOffer(_dlcOffer, fixedInputs) {
|
|
1367
1439
|
const { dlcOffer } = (0, Utils_1.checkTypes)({ _dlcOffer });
|
|
1368
1440
|
dlcOffer.validate();
|
|
1369
|
-
const acceptCollateralSatoshis = dlcOffer.contractInfo.totalCollateral - dlcOffer.
|
|
1441
|
+
const acceptCollateralSatoshis = dlcOffer.contractInfo.totalCollateral - dlcOffer.offerCollateral;
|
|
1370
1442
|
(0, assert_1.default)(acceptCollateralSatoshis ===
|
|
1371
|
-
dlcOffer.contractInfo.totalCollateral -
|
|
1372
|
-
dlcOffer.offerCollateralSatoshis, 'acceptCollaterialSatoshis should equal totalCollateral - offerCollateralSatoshis');
|
|
1443
|
+
dlcOffer.contractInfo.totalCollateral - dlcOffer.offerCollateral, 'acceptCollaterialSatoshis should equal totalCollateral - offerCollateralSatoshis');
|
|
1373
1444
|
const { fundingPubKey, payoutSPK, payoutSerialId, fundingInputs: _fundingInputs, changeSPK, changeSerialId, } = await this.Initialize(acceptCollateralSatoshis, dlcOffer.feeRatePerVb, fixedInputs);
|
|
1374
|
-
(0, assert_1.default)(Buffer.compare(dlcOffer.
|
|
1375
|
-
_fundingInputs.forEach((input) => (0, assert_1.default)(input.type === messaging_1.MessageType.
|
|
1445
|
+
(0, assert_1.default)(Buffer.compare(dlcOffer.fundingPubkey, fundingPubKey) !== 0, 'DlcOffer and DlcAccept FundingPubKey cannot be the same');
|
|
1446
|
+
_fundingInputs.forEach((input) => (0, assert_1.default)(input.type === messaging_1.MessageType.FundingInput, 'FundingInput must be V0'));
|
|
1376
1447
|
const fundingInputs = _fundingInputs.map((input) => input);
|
|
1377
1448
|
fundingInputs.sort((a, b) => Number(a.inputSerialId) - Number(b.inputSerialId));
|
|
1378
|
-
const dlcAccept = new messaging_1.
|
|
1379
|
-
dlcAccept.
|
|
1380
|
-
dlcAccept.
|
|
1381
|
-
dlcAccept.
|
|
1382
|
-
dlcAccept.
|
|
1449
|
+
const dlcAccept = new messaging_1.DlcAccept();
|
|
1450
|
+
dlcAccept.temporaryContractId = (0, crypto_1.sha256)(dlcOffer.serialize());
|
|
1451
|
+
dlcAccept.acceptCollateral = acceptCollateralSatoshis;
|
|
1452
|
+
dlcAccept.fundingPubkey = fundingPubKey;
|
|
1453
|
+
dlcAccept.payoutSpk = payoutSPK;
|
|
1383
1454
|
dlcAccept.payoutSerialId = dlcAccept.payoutSerialId = payoutSerialId;
|
|
1384
1455
|
dlcAccept.fundingInputs = fundingInputs;
|
|
1385
|
-
dlcAccept.
|
|
1456
|
+
dlcAccept.changeSpk = changeSPK;
|
|
1386
1457
|
dlcAccept.changeSerialId = dlcAccept.changeSerialId = changeSerialId;
|
|
1387
1458
|
(0, assert_1.default)(dlcAccept.changeSerialId !== dlcOffer.fundOutputSerialId, 'changeSerialId cannot equal the fundOutputSerialId');
|
|
1388
1459
|
(0, assert_1.default)(dlcOffer.payoutSerialId !== dlcAccept.payoutSerialId, 'offer.payoutSerialId cannot equal accept.payoutSerialId');
|
|
@@ -1396,21 +1467,19 @@ Payout Group not found');
|
|
|
1396
1467
|
})(), 'offer.changeSerialID, accept.changeSerialId and fundOutputSerialId must be unique');
|
|
1397
1468
|
dlcAccept.validate();
|
|
1398
1469
|
(0, assert_1.default)((() => {
|
|
1399
|
-
const finalizer = new core_1.DualFundingTxFinalizer(dlcOffer.fundingInputs, dlcOffer.
|
|
1470
|
+
const finalizer = new core_1.DualFundingTxFinalizer(dlcOffer.fundingInputs, dlcOffer.payoutSpk, dlcOffer.changeSpk, dlcAccept.fundingInputs, dlcAccept.payoutSpk, dlcAccept.changeSpk, dlcOffer.feeRatePerVb);
|
|
1400
1471
|
const funding = fundingInputs.reduce((total, input) => {
|
|
1401
1472
|
return total + input.prevTx.outputs[input.prevTxVout].value.sats;
|
|
1402
1473
|
}, BigInt(0));
|
|
1403
1474
|
return funding >= acceptCollateralSatoshis + finalizer.acceptFees;
|
|
1404
1475
|
})(), 'fundingInputs for dlcAccept must be greater than acceptCollateralSatoshis plus acceptFees');
|
|
1405
1476
|
const { dlcTransactions, messagesList } = await this.createDlcTxs(dlcOffer, dlcAccept);
|
|
1406
|
-
const { cetSignatures, refundSignature
|
|
1407
|
-
(0, assert_1.default)(dlcTransactions.type === messaging_1.MessageType.DlcTransactionsV0, 'DlcTransactions must be V0');
|
|
1477
|
+
const { cetSignatures, refundSignature } = await this.CreateCetAdaptorAndRefundSigs(dlcOffer, dlcAccept, dlcTransactions, messagesList, false);
|
|
1408
1478
|
const _dlcTransactions = dlcTransactions;
|
|
1409
|
-
const contractId = (0, crypto_1.xor)(_dlcTransactions.fundTx.txId.serialize(), dlcAccept.
|
|
1479
|
+
const contractId = (0, crypto_1.xor)(_dlcTransactions.fundTx.txId.serialize(), dlcAccept.temporaryContractId);
|
|
1410
1480
|
_dlcTransactions.contractId = contractId;
|
|
1411
|
-
dlcAccept.
|
|
1481
|
+
dlcAccept.cetAdaptorSignatures = cetSignatures;
|
|
1412
1482
|
dlcAccept.refundSignature = refundSignature;
|
|
1413
|
-
dlcAccept.negotiationFields = new messaging_1.NegotiationFieldsV0();
|
|
1414
1483
|
return { dlcAccept, dlcTransactions: _dlcTransactions };
|
|
1415
1484
|
}
|
|
1416
1485
|
async batchAcceptDlcOffer(_dlcOffers, fixedInputs) {
|
|
@@ -1419,31 +1488,30 @@ Payout Group not found');
|
|
|
1419
1488
|
dlcOffer.validate();
|
|
1420
1489
|
return dlcOffer;
|
|
1421
1490
|
});
|
|
1422
|
-
const acceptCollaterals = dlcOffers.map((dlcOffer) => dlcOffer.contractInfo.totalCollateral -
|
|
1423
|
-
dlcOffer.offerCollateralSatoshis);
|
|
1491
|
+
const acceptCollaterals = dlcOffers.map((dlcOffer) => dlcOffer.contractInfo.totalCollateral - dlcOffer.offerCollateral);
|
|
1424
1492
|
const { fundingInputs: _fundingInputs, changeSPK, changeSerialId, initializeResponses, } = await this.BatchInitialize(acceptCollaterals, dlcOffers[0].feeRatePerVb, fixedInputs);
|
|
1425
1493
|
// Check that none of the funding pubkeys are the same between the
|
|
1426
1494
|
// dlcOffers and the dlcAccepts (from initializeResponses)
|
|
1427
1495
|
dlcOffers.forEach((dlcOffer) => {
|
|
1428
1496
|
initializeResponses.forEach((initializeResponse) => {
|
|
1429
|
-
(0, assert_1.default)(Buffer.compare(dlcOffer.
|
|
1497
|
+
(0, assert_1.default)(Buffer.compare(dlcOffer.fundingPubkey, initializeResponse.fundingPubKey) !== 0, 'DlcOffer and DlcAccept FundingPubKey cannot be the same');
|
|
1430
1498
|
});
|
|
1431
1499
|
});
|
|
1432
|
-
_fundingInputs.forEach((input) => (0, assert_1.default)(input.type === messaging_1.MessageType.
|
|
1500
|
+
_fundingInputs.forEach((input) => (0, assert_1.default)(input.type === messaging_1.MessageType.FundingInput, 'FundingInput must be V0'));
|
|
1433
1501
|
const fundingInputs = _fundingInputs.map((input) => input);
|
|
1434
1502
|
fundingInputs.sort((a, b) => Number(a.inputSerialId) - Number(b.inputSerialId));
|
|
1435
1503
|
const dlcAccepts = [];
|
|
1436
1504
|
initializeResponses.forEach((initializeResponse, i) => {
|
|
1437
1505
|
const dlcOffer = dlcOffers[i];
|
|
1438
|
-
const dlcAccept = new messaging_1.
|
|
1506
|
+
const dlcAccept = new messaging_1.DlcAccept();
|
|
1439
1507
|
const { fundingPubKey, payoutSPK, payoutSerialId } = initializeResponse;
|
|
1440
|
-
dlcAccept.
|
|
1441
|
-
dlcAccept.
|
|
1442
|
-
dlcAccept.
|
|
1443
|
-
dlcAccept.
|
|
1508
|
+
dlcAccept.temporaryContractId = (0, crypto_1.sha256)(dlcOffers[i].serialize());
|
|
1509
|
+
dlcAccept.acceptCollateral = acceptCollaterals[i];
|
|
1510
|
+
dlcAccept.fundingPubkey = fundingPubKey;
|
|
1511
|
+
dlcAccept.payoutSpk = payoutSPK;
|
|
1444
1512
|
dlcAccept.payoutSerialId = payoutSerialId;
|
|
1445
1513
|
dlcAccept.fundingInputs = fundingInputs;
|
|
1446
|
-
dlcAccept.
|
|
1514
|
+
dlcAccept.changeSpk = changeSPK;
|
|
1447
1515
|
dlcAccept.changeSerialId = changeSerialId;
|
|
1448
1516
|
(0, assert_1.default)(dlcAccept.changeSerialId !== dlcOffer.fundOutputSerialId, 'changeSerialId cannot equal the fundOutputSerialId');
|
|
1449
1517
|
(0, assert_1.default)(dlcOffer.payoutSerialId !== dlcAccept.payoutSerialId, 'offer.payoutSerialId cannot equal accept.payoutSerialId');
|
|
@@ -1457,7 +1525,7 @@ Payout Group not found');
|
|
|
1457
1525
|
})(), 'offer.changeSerialID, accept.changeSerialId and fundOutputSerialId must be unique');
|
|
1458
1526
|
dlcAccept.validate();
|
|
1459
1527
|
(0, assert_1.default)((() => {
|
|
1460
|
-
const finalizer = new core_1.DualFundingTxFinalizer(dlcOffer.fundingInputs, dlcOffer.
|
|
1528
|
+
const finalizer = new core_1.DualFundingTxFinalizer(dlcOffer.fundingInputs, dlcOffer.payoutSpk, dlcOffer.changeSpk, dlcAccept.fundingInputs, dlcAccept.payoutSpk, dlcAccept.changeSpk, dlcOffer.feeRatePerVb);
|
|
1461
1529
|
const funding = fundingInputs.reduce((total, input) => {
|
|
1462
1530
|
return total + input.prevTx.outputs[input.prevTxVout].value.sats;
|
|
1463
1531
|
}, BigInt(0));
|
|
@@ -1465,20 +1533,18 @@ Payout Group not found');
|
|
|
1465
1533
|
})(), 'fundingInputs for dlcAccept must be greater than acceptCollateralSatoshis plus acceptFees');
|
|
1466
1534
|
dlcAccepts.push(dlcAccept);
|
|
1467
1535
|
});
|
|
1468
|
-
const { dlcTransactionsList, nestedMessagesList
|
|
1536
|
+
const { dlcTransactionsList, nestedMessagesList } = await this.createBatchDlcTxs(dlcOffers, dlcAccepts);
|
|
1469
1537
|
for (let i = 0; i < dlcAccepts.length; i++) {
|
|
1470
1538
|
const dlcOffer = dlcOffers[i];
|
|
1471
1539
|
const dlcAccept = dlcAccepts[i];
|
|
1472
1540
|
const dlcTransactions = dlcTransactionsList[i];
|
|
1473
1541
|
const messagesList = nestedMessagesList[i];
|
|
1474
|
-
const { cetSignatures, refundSignature
|
|
1475
|
-
(0, assert_1.default)(dlcTransactions.type === messaging_1.MessageType.DlcTransactionsV0, 'DlcTransactions must be V0');
|
|
1542
|
+
const { cetSignatures, refundSignature } = await this.CreateCetAdaptorAndRefundSigs(dlcOffer, dlcAccept, dlcTransactions, messagesList, false);
|
|
1476
1543
|
const _dlcTransactions = dlcTransactions;
|
|
1477
|
-
const contractId = (0, crypto_1.xor)(_dlcTransactions.fundTx.txId.serialize(), dlcAccept.
|
|
1544
|
+
const contractId = (0, crypto_1.xor)(_dlcTransactions.fundTx.txId.serialize(), dlcAccept.temporaryContractId);
|
|
1478
1545
|
_dlcTransactions.contractId = contractId;
|
|
1479
|
-
dlcAccepts[i].
|
|
1546
|
+
dlcAccepts[i].cetAdaptorSignatures = cetSignatures;
|
|
1480
1547
|
dlcAccepts[i].refundSignature = refundSignature;
|
|
1481
|
-
dlcAccepts[i].negotiationFields = new messaging_1.NegotiationFieldsV0();
|
|
1482
1548
|
}
|
|
1483
1549
|
return { dlcAccepts, dlcTransactionsList };
|
|
1484
1550
|
}
|
|
@@ -1495,18 +1561,18 @@ Payout Group not found');
|
|
|
1495
1561
|
});
|
|
1496
1562
|
dlcOffer.validate();
|
|
1497
1563
|
dlcAccept.validate();
|
|
1498
|
-
(0, assert_1.default)(Buffer.compare(dlcOffer.
|
|
1499
|
-
const dlcSign = new messaging_1.
|
|
1564
|
+
(0, assert_1.default)(Buffer.compare(dlcOffer.fundingPubkey, dlcAccept.fundingPubkey) !== 0, 'DlcOffer and DlcAccept FundingPubKey cannot be the same');
|
|
1565
|
+
const dlcSign = new messaging_1.DlcSign();
|
|
1500
1566
|
const { dlcTransactions, messagesList } = await this.createDlcTxs(dlcOffer, dlcAccept);
|
|
1501
1567
|
await this.VerifyCetAdaptorAndRefundSigs(dlcOffer, dlcAccept, dlcSign, dlcTransactions, messagesList, true);
|
|
1502
|
-
const { cetSignatures, refundSignature
|
|
1568
|
+
const { cetSignatures, refundSignature } = await this.CreateCetAdaptorAndRefundSigs(dlcOffer, dlcAccept, dlcTransactions, messagesList, true);
|
|
1503
1569
|
const fundingSignatures = await this.CreateFundingSigs(dlcOffer, dlcAccept, dlcTransactions, true);
|
|
1504
1570
|
const dlcTxs = dlcTransactions;
|
|
1505
|
-
const contractId = (0, crypto_1.xor)(dlcTxs.fundTx.txId.serialize(), dlcAccept.
|
|
1506
|
-
(0, assert_1.default)(Buffer.compare(contractId, (0, crypto_1.xor)(dlcTxs.fundTx.txId.serialize(), dlcAccept.
|
|
1571
|
+
const contractId = (0, crypto_1.xor)(dlcTxs.fundTx.txId.serialize(), dlcAccept.temporaryContractId);
|
|
1572
|
+
(0, assert_1.default)(Buffer.compare(contractId, (0, crypto_1.xor)(dlcTxs.fundTx.txId.serialize(), dlcAccept.temporaryContractId)) === 0, 'contractId must be the xor of funding txid, fundingOutputIndex and the tempContractId');
|
|
1507
1573
|
dlcTxs.contractId = contractId;
|
|
1508
1574
|
dlcSign.contractId = contractId;
|
|
1509
|
-
dlcSign.
|
|
1575
|
+
dlcSign.cetAdaptorSignatures = cetSignatures;
|
|
1510
1576
|
dlcSign.refundSignature = refundSignature;
|
|
1511
1577
|
dlcSign.fundingSignatures = fundingSignatures;
|
|
1512
1578
|
return { dlcSign, dlcTransactions: dlcTxs };
|
|
@@ -1522,7 +1588,7 @@ Payout Group not found');
|
|
|
1522
1588
|
dlcAccept.validate();
|
|
1523
1589
|
return dlcAccept;
|
|
1524
1590
|
});
|
|
1525
|
-
const { dlcTransactionsList, nestedMessagesList
|
|
1591
|
+
const { dlcTransactionsList, nestedMessagesList } = await this.createBatchDlcTxs(dlcOffers, dlcAccepts);
|
|
1526
1592
|
const dlcSigns = [];
|
|
1527
1593
|
const fundingSignatures = await this.CreateFundingSigs(dlcOffers[0], dlcAccepts[0], dlcTransactionsList[0], true);
|
|
1528
1594
|
for (let i = 0; i < dlcAccepts.length; i++) {
|
|
@@ -1530,14 +1596,14 @@ Payout Group not found');
|
|
|
1530
1596
|
const dlcAccept = dlcAccepts[i];
|
|
1531
1597
|
const dlcTransactions = dlcTransactionsList[i];
|
|
1532
1598
|
const messagesList = nestedMessagesList[i];
|
|
1533
|
-
const dlcSign = new messaging_1.
|
|
1599
|
+
const dlcSign = new messaging_1.DlcSign();
|
|
1534
1600
|
await this.VerifyCetAdaptorAndRefundSigs(dlcOffer, dlcAccept, dlcSign, dlcTransactions, messagesList, true);
|
|
1535
|
-
const { cetSignatures, refundSignature
|
|
1601
|
+
const { cetSignatures, refundSignature } = await this.CreateCetAdaptorAndRefundSigs(dlcOffer, dlcAccept, dlcTransactions, messagesList, true);
|
|
1536
1602
|
const dlcTxs = dlcTransactions;
|
|
1537
|
-
const contractId = (0, crypto_1.xor)(dlcTxs.fundTx.txId.serialize(), dlcAccept.
|
|
1603
|
+
const contractId = (0, crypto_1.xor)(dlcTxs.fundTx.txId.serialize(), dlcAccept.temporaryContractId);
|
|
1538
1604
|
dlcTxs.contractId = contractId;
|
|
1539
1605
|
dlcSign.contractId = contractId;
|
|
1540
|
-
dlcSign.
|
|
1606
|
+
dlcSign.cetAdaptorSignatures = cetSignatures;
|
|
1541
1607
|
dlcSign.refundSignature = refundSignature;
|
|
1542
1608
|
dlcSign.fundingSignatures = fundingSignatures;
|
|
1543
1609
|
dlcSigns.push(dlcSign);
|
|
@@ -1546,26 +1612,20 @@ Payout Group not found');
|
|
|
1546
1612
|
}
|
|
1547
1613
|
/**
|
|
1548
1614
|
* Finalize Dlc Sign
|
|
1549
|
-
* @param
|
|
1550
|
-
* @param
|
|
1551
|
-
* @param
|
|
1552
|
-
* @param
|
|
1615
|
+
* @param dlcOffer Dlc Offer Message
|
|
1616
|
+
* @param dlcAccept Dlc Accept Message
|
|
1617
|
+
* @param dlcSign Dlc Sign Message
|
|
1618
|
+
* @param dlcTxs Dlc Transactions Message
|
|
1553
1619
|
* @returns {Promise<Tx>}
|
|
1554
1620
|
*/
|
|
1555
|
-
async finalizeDlcSign(
|
|
1556
|
-
const { dlcOffer, dlcAccept, dlcSign, dlcTxs } = (0, Utils_1.checkTypes)({
|
|
1557
|
-
_dlcOffer,
|
|
1558
|
-
_dlcAccept,
|
|
1559
|
-
_dlcSign,
|
|
1560
|
-
_dlcTxs,
|
|
1561
|
-
});
|
|
1621
|
+
async finalizeDlcSign(dlcOffer, dlcAccept, dlcSign, dlcTxs) {
|
|
1562
1622
|
let messagesList = [];
|
|
1563
|
-
if (dlcOffer.contractInfo.type === messaging_1.MessageType.
|
|
1623
|
+
if (dlcOffer.contractInfo.type === messaging_1.MessageType.SingleContractInfo &&
|
|
1564
1624
|
dlcOffer.contractInfo.contractDescriptor.type ===
|
|
1565
|
-
messaging_1.MessageType.
|
|
1625
|
+
messaging_1.MessageType.SingleContractInfo) {
|
|
1566
1626
|
for (const outcome of dlcOffer.contractInfo
|
|
1567
1627
|
.contractDescriptor.outcomes) {
|
|
1568
|
-
messagesList.push({ messages: [outcome.outcome
|
|
1628
|
+
messagesList.push({ messages: [outcome.outcome] });
|
|
1569
1629
|
}
|
|
1570
1630
|
}
|
|
1571
1631
|
else {
|
|
@@ -1622,13 +1682,7 @@ Payout Group not found');
|
|
|
1622
1682
|
* @param isOfferer Whether party is Dlc Offerer
|
|
1623
1683
|
* @returns {Promise<Tx>}
|
|
1624
1684
|
*/
|
|
1625
|
-
async execute(
|
|
1626
|
-
const { dlcOffer, dlcAccept, dlcSign, dlcTxs } = (0, Utils_1.checkTypes)({
|
|
1627
|
-
_dlcOffer,
|
|
1628
|
-
_dlcAccept,
|
|
1629
|
-
_dlcSign,
|
|
1630
|
-
_dlcTxs,
|
|
1631
|
-
});
|
|
1685
|
+
async execute(dlcOffer, dlcAccept, dlcSign, dlcTxs, oracleAttestation, isOfferer) {
|
|
1632
1686
|
if (isOfferer === undefined)
|
|
1633
1687
|
isOfferer = await this.isOfferer(dlcOffer, dlcAccept);
|
|
1634
1688
|
this.ValidateEvent(dlcOffer, oracleAttestation);
|
|
@@ -1649,7 +1703,7 @@ Payout Group not found');
|
|
|
1649
1703
|
_dlcSign,
|
|
1650
1704
|
_dlcTxs,
|
|
1651
1705
|
});
|
|
1652
|
-
const signatures = Buffer.compare(dlcOffer.
|
|
1706
|
+
const signatures = Buffer.compare(dlcOffer.fundingPubkey, dlcAccept.fundingPubkey) === -1
|
|
1653
1707
|
? [
|
|
1654
1708
|
dlcSign.refundSignature.toString('hex'),
|
|
1655
1709
|
dlcAccept.refundSignature.toString('hex'),
|
|
@@ -1663,8 +1717,8 @@ Payout Group not found');
|
|
|
1663
1717
|
signatures,
|
|
1664
1718
|
fundTxId: dlcTxs.fundTx.txId.toString(),
|
|
1665
1719
|
fundVout: dlcTxs.fundTxVout,
|
|
1666
|
-
localFundPubkey: dlcOffer.
|
|
1667
|
-
remoteFundPubkey: dlcAccept.
|
|
1720
|
+
localFundPubkey: dlcOffer.fundingPubkey.toString('hex'),
|
|
1721
|
+
remoteFundPubkey: dlcAccept.fundingPubkey.toString('hex'),
|
|
1668
1722
|
};
|
|
1669
1723
|
const refundHex = (await this.AddSignaturesToRefundTx(addSigsToRefundTxRequest)).hex;
|
|
1670
1724
|
return bitcoin_1.Tx.decode(bufio_1.StreamReader.fromHex(refundHex));
|
|
@@ -1695,9 +1749,9 @@ Payout Group not found');
|
|
|
1695
1749
|
isOfferer = await this.isOfferer(dlcOffer, dlcAccept);
|
|
1696
1750
|
const network = await this.getConnectedNetwork();
|
|
1697
1751
|
const psbt = new bitcoinjs_lib_1.Psbt({ network });
|
|
1698
|
-
const fundingPubKeys = Buffer.compare(dlcOffer.
|
|
1699
|
-
? [dlcOffer.
|
|
1700
|
-
: [dlcAccept.
|
|
1752
|
+
const fundingPubKeys = Buffer.compare(dlcOffer.fundingPubkey, dlcAccept.fundingPubkey) === -1
|
|
1753
|
+
? [dlcOffer.fundingPubkey, dlcAccept.fundingPubkey]
|
|
1754
|
+
: [dlcAccept.fundingPubkey, dlcOffer.fundingPubkey];
|
|
1701
1755
|
const p2ms = bitcoinjs_lib_1.payments.p2ms({
|
|
1702
1756
|
m: 2,
|
|
1703
1757
|
pubkeys: fundingPubKeys,
|
|
@@ -1767,7 +1821,7 @@ Payout Group not found');
|
|
|
1767
1821
|
const fundingInputs = await Promise.all(inputs.map(async (input) => {
|
|
1768
1822
|
return this.inputToFundingInput(input);
|
|
1769
1823
|
}));
|
|
1770
|
-
const finalizer = new core_1.DualClosingTxFinalizer(fundingInputs, dlcOffer.
|
|
1824
|
+
const finalizer = new core_1.DualClosingTxFinalizer(fundingInputs, dlcOffer.payoutSpk, dlcAccept.payoutSpk, dlcOffer.feeRatePerVb);
|
|
1771
1825
|
const closeInputAmount = BigInt(inputs.reduce((acc, val) => acc + val.value, 0));
|
|
1772
1826
|
const offerPayoutValue = isOfferer
|
|
1773
1827
|
? closeInputAmount +
|
|
@@ -1782,11 +1836,11 @@ Payout Group not found');
|
|
|
1782
1836
|
const offerFirst = dlcOffer.payoutSerialId < dlcAccept.payoutSerialId;
|
|
1783
1837
|
psbt.addOutput({
|
|
1784
1838
|
value: Number(offerFirst ? offerPayoutValue : acceptPayoutValue),
|
|
1785
|
-
address: bitcoinjs_lib_1.address.fromOutputScript(offerFirst ? dlcOffer.
|
|
1839
|
+
address: bitcoinjs_lib_1.address.fromOutputScript(offerFirst ? dlcOffer.payoutSpk : dlcAccept.payoutSpk, network),
|
|
1786
1840
|
});
|
|
1787
1841
|
psbt.addOutput({
|
|
1788
1842
|
value: Number(offerFirst ? acceptPayoutValue : offerPayoutValue),
|
|
1789
|
-
address: bitcoinjs_lib_1.address.fromOutputScript(offerFirst ? dlcAccept.
|
|
1843
|
+
address: bitcoinjs_lib_1.address.fromOutputScript(offerFirst ? dlcAccept.payoutSpk : dlcOffer.payoutSpk, network),
|
|
1790
1844
|
});
|
|
1791
1845
|
// Generate keypair to sign inputs
|
|
1792
1846
|
const fundPrivateKeyPair = await this.GetFundKeyPair(dlcOffer, dlcAccept, isOfferer);
|
|
@@ -1801,7 +1855,9 @@ Payout Group not found');
|
|
|
1801
1855
|
psbt.signInput(i, keyPair);
|
|
1802
1856
|
}));
|
|
1803
1857
|
// Validate signatures
|
|
1804
|
-
psbt.validateSignaturesOfAllInputs()
|
|
1858
|
+
psbt.validateSignaturesOfAllInputs((pubkey, msghash, signature) => {
|
|
1859
|
+
return ecc.verify(msghash, pubkey, signature);
|
|
1860
|
+
});
|
|
1805
1861
|
// Extract close signature from psbt and decode it to only extract r and s values
|
|
1806
1862
|
const closeSignature = await bitcoinjs_lib_1.script.signature.decode(psbt.data.inputs[fundingInputIndex].partialSig[0].signature).signature;
|
|
1807
1863
|
// Extract funding signatures from psbt
|
|
@@ -1817,10 +1873,10 @@ Payout Group not found');
|
|
|
1817
1873
|
pubKeyWitness.witness = inputSigs[i].pubkey;
|
|
1818
1874
|
witnessElements.push([sigWitness, pubKeyWitness]);
|
|
1819
1875
|
}
|
|
1820
|
-
const fundingSignatures = new messaging_1.
|
|
1876
|
+
const fundingSignatures = new messaging_1.FundingSignatures();
|
|
1821
1877
|
fundingSignatures.witnessElements = witnessElements;
|
|
1822
1878
|
// Create DlcClose
|
|
1823
|
-
const dlcClose = new messaging_1.
|
|
1879
|
+
const dlcClose = new messaging_1.DlcClose();
|
|
1824
1880
|
dlcClose.contractId = dlcTxs.contractId;
|
|
1825
1881
|
dlcClose.offerPayoutSatoshis = BigInt(psbt.txOutputs[offerFirst ? 0 : 1].value); // You give collateral back to users
|
|
1826
1882
|
dlcClose.acceptPayoutSatoshis = BigInt(psbt.txOutputs[offerFirst ? 1 : 0].value); // give collateral back to users
|
|
@@ -1853,7 +1909,7 @@ Payout Group not found');
|
|
|
1853
1909
|
throw Error('funding inputs not supported on BatchDlcClose'); // TODO support multiple funding inputs
|
|
1854
1910
|
const fundingInputSerialId = (0, Utils_1.generateSerialId)();
|
|
1855
1911
|
const fundingInputs = []; // TODO: support multiple funding inputs
|
|
1856
|
-
const finalizer = new core_1.DualClosingTxFinalizer(fundingInputs, dlcOffer.
|
|
1912
|
+
const finalizer = new core_1.DualClosingTxFinalizer(fundingInputs, dlcOffer.payoutSpk, dlcAccept.payoutSpk, dlcOffer.feeRatePerVb);
|
|
1857
1913
|
// Generate keypair to sign inputs
|
|
1858
1914
|
const fundPrivateKeyPair = await this.GetFundKeyPair(dlcOffer, dlcAccept, isOfferer);
|
|
1859
1915
|
const closeInputAmount = BigInt(0); // TODO support multiple funding inputs
|
|
@@ -1876,8 +1932,8 @@ Payout Group not found');
|
|
|
1876
1932
|
const acceptPayoutValue = isOfferer
|
|
1877
1933
|
? collateralMinusPayout
|
|
1878
1934
|
: closeInputAmount + payoutMinusOfferFees;
|
|
1879
|
-
const fundingSignatures = new messaging_1.
|
|
1880
|
-
const dlcClose = new messaging_1.
|
|
1935
|
+
const fundingSignatures = new messaging_1.FundingSignatures();
|
|
1936
|
+
const dlcClose = new messaging_1.DlcClose();
|
|
1881
1937
|
dlcClose.contractId = dlcTxs.contractId;
|
|
1882
1938
|
dlcClose.offerPayoutSatoshis = offerPayoutValue;
|
|
1883
1939
|
dlcClose.acceptPayoutSatoshis = acceptPayoutValue;
|
|
@@ -1944,9 +2000,9 @@ Payout Group not found');
|
|
|
1944
2000
|
dlcClose.validate();
|
|
1945
2001
|
const network = await this.getConnectedNetwork();
|
|
1946
2002
|
const psbt = new bitcoinjs_lib_1.Psbt({ network });
|
|
1947
|
-
const fundingPubKeys = Buffer.compare(dlcOffer.
|
|
1948
|
-
? [dlcOffer.
|
|
1949
|
-
: [dlcAccept.
|
|
2003
|
+
const fundingPubKeys = Buffer.compare(dlcOffer.fundingPubkey, dlcAccept.fundingPubkey) === -1
|
|
2004
|
+
? [dlcOffer.fundingPubkey, dlcAccept.fundingPubkey]
|
|
2005
|
+
: [dlcAccept.fundingPubkey, dlcOffer.fundingPubkey];
|
|
1950
2006
|
const p2ms = bitcoinjs_lib_1.payments.p2ms({
|
|
1951
2007
|
m: 2,
|
|
1952
2008
|
pubkeys: fundingPubKeys,
|
|
@@ -1997,13 +2053,13 @@ Payout Group not found');
|
|
|
1997
2053
|
value: Number(offerFirst
|
|
1998
2054
|
? dlcClose.offerPayoutSatoshis
|
|
1999
2055
|
: dlcClose.acceptPayoutSatoshis),
|
|
2000
|
-
address: bitcoinjs_lib_1.address.fromOutputScript(offerFirst ? dlcOffer.
|
|
2056
|
+
address: bitcoinjs_lib_1.address.fromOutputScript(offerFirst ? dlcOffer.payoutSpk : dlcAccept.payoutSpk, network),
|
|
2001
2057
|
});
|
|
2002
2058
|
psbt.addOutput({
|
|
2003
2059
|
value: Number(offerFirst
|
|
2004
2060
|
? dlcClose.acceptPayoutSatoshis
|
|
2005
2061
|
: dlcClose.offerPayoutSatoshis),
|
|
2006
|
-
address: bitcoinjs_lib_1.address.fromOutputScript(offerFirst ? dlcAccept.
|
|
2062
|
+
address: bitcoinjs_lib_1.address.fromOutputScript(offerFirst ? dlcAccept.payoutSpk : dlcOffer.payoutSpk, network),
|
|
2007
2063
|
});
|
|
2008
2064
|
// add to psbt
|
|
2009
2065
|
sortedPsbtInputs.forEach((input, i) => psbt.addInput(input));
|
|
@@ -2014,7 +2070,7 @@ Payout Group not found');
|
|
|
2014
2070
|
psbt.signInput(fundingInputIndex, fundPrivateKeyPair);
|
|
2015
2071
|
const partialSig = [
|
|
2016
2072
|
{
|
|
2017
|
-
pubkey: offerer ? dlcAccept.
|
|
2073
|
+
pubkey: offerer ? dlcAccept.fundingPubkey : dlcOffer.fundingPubkey,
|
|
2018
2074
|
signature: await bitcoinjs_lib_1.script.signature.encode(dlcClose.closeSignature, 1), // encode using SIGHASH_ALL
|
|
2019
2075
|
},
|
|
2020
2076
|
];
|
|
@@ -2033,7 +2089,9 @@ Payout Group not found');
|
|
|
2033
2089
|
];
|
|
2034
2090
|
psbt.updateInput(i, { partialSig });
|
|
2035
2091
|
}
|
|
2036
|
-
psbt.validateSignaturesOfAllInputs()
|
|
2092
|
+
psbt.validateSignaturesOfAllInputs((pubkey, msghash, signature) => {
|
|
2093
|
+
return ecc.verify(msghash, pubkey, signature);
|
|
2094
|
+
});
|
|
2037
2095
|
psbt.finalizeAllInputs();
|
|
2038
2096
|
return psbt.extractTransaction().toHex();
|
|
2039
2097
|
}
|
|
@@ -2110,7 +2168,7 @@ Payout Group not found');
|
|
|
2110
2168
|
return this._cfdDlcJs.VerifyRefundTxSignature(jsonObject);
|
|
2111
2169
|
}
|
|
2112
2170
|
async fundingInputToInput(_input, findDerivationPath = true) {
|
|
2113
|
-
(0, assert_1.default)(_input.type === messaging_1.MessageType.
|
|
2171
|
+
(0, assert_1.default)(_input.type === messaging_1.MessageType.FundingInput, 'FundingInput must be V0');
|
|
2114
2172
|
const network = await this.getConnectedNetwork();
|
|
2115
2173
|
const input = _input;
|
|
2116
2174
|
const prevTx = input.prevTx;
|
|
@@ -2143,7 +2201,7 @@ Payout Group not found');
|
|
|
2143
2201
|
};
|
|
2144
2202
|
}
|
|
2145
2203
|
async inputToFundingInput(input) {
|
|
2146
|
-
const fundingInput = new messaging_1.
|
|
2204
|
+
const fundingInput = new messaging_1.FundingInput();
|
|
2147
2205
|
fundingInput.prevTxVout = input.vout;
|
|
2148
2206
|
let txRaw = '';
|
|
2149
2207
|
try {
|