@atomicfinance/bitcoin-dlc-provider 3.6.1 → 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/.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 +72 -0
- package/dist/BitcoinDlcProvider.d.ts +17 -16
- package/dist/BitcoinDlcProvider.js +345 -315
- 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 +624 -612
- package/lib/utils/Utils.ts +19 -24
- package/package.json +10 -10
- package/yalc.lock +10 -0
|
@@ -38,6 +38,7 @@ const assert_1 = __importDefault(require("assert"));
|
|
|
38
38
|
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
39
39
|
const bitcoin_networks_1 = require("bitcoin-networks");
|
|
40
40
|
const bitcoinjs_lib_1 = require("bitcoinjs-lib");
|
|
41
|
+
const crypto_2 = __importDefault(require("crypto"));
|
|
41
42
|
const ecc = __importStar(require("tiny-secp256k1"));
|
|
42
43
|
const Utils_1 = require("./utils/Utils");
|
|
43
44
|
class BitcoinDlcProvider extends provider_1.default {
|
|
@@ -155,27 +156,23 @@ class BitcoinDlcProvider extends provider_1.default {
|
|
|
155
156
|
* totalCollateral: bigint,
|
|
156
157
|
* ): PayoutRequest[] {}
|
|
157
158
|
*/
|
|
158
|
-
GetPayoutsFromPayoutFunction(
|
|
159
|
-
if (_dlcOffer.type !== messaging_1.MessageType.DlcOfferV0)
|
|
160
|
-
throw Error('DlcOffer must be V0');
|
|
161
|
-
const dlcOffer = _dlcOffer;
|
|
162
|
-
if (contractDescriptor.payoutFunction.type !== messaging_1.MessageType.PayoutFunctionV0)
|
|
163
|
-
throw Error('PayoutFunction must be V0');
|
|
159
|
+
GetPayoutsFromPayoutFunction(dlcOffer, contractDescriptor, oracleInfo, totalCollateral) {
|
|
164
160
|
const payoutFunction = contractDescriptor.payoutFunction;
|
|
165
|
-
if (payoutFunction.
|
|
161
|
+
if (payoutFunction.payoutFunctionPieces.length === 0)
|
|
166
162
|
throw Error('PayoutFunction must have at least once PayoutCurvePiece');
|
|
167
|
-
if (payoutFunction.
|
|
163
|
+
if (payoutFunction.payoutFunctionPieces.length > 1)
|
|
168
164
|
throw Error('More than one PayoutCurvePiece not supported');
|
|
169
|
-
const payoutCurvePiece = payoutFunction.
|
|
165
|
+
const payoutCurvePiece = payoutFunction.payoutFunctionPieces[0]
|
|
170
166
|
.payoutCurvePiece;
|
|
171
|
-
if (payoutCurvePiece.
|
|
172
|
-
payoutCurvePiece.type !== messaging_1.MessageType.OldHyperbolaPayoutCurvePiece)
|
|
167
|
+
if (payoutCurvePiece.payoutCurvePieceType !== messaging_1.PayoutCurvePieceType.Hyperbola)
|
|
173
168
|
throw Error('Must be HyperbolaPayoutCurvePiece');
|
|
174
|
-
if (payoutCurvePiece.b
|
|
169
|
+
if (!payoutCurvePiece.b.eq(messaging_1.F64.ZERO) || !payoutCurvePiece.c.eq(messaging_1.F64.ZERO))
|
|
175
170
|
throw Error('b and c HyperbolaPayoutCurvePiece values must be 0');
|
|
176
|
-
|
|
171
|
+
// Cast to SingleOracleInfo to access announcement property
|
|
172
|
+
const singleOracleInfo = oracleInfo;
|
|
173
|
+
const eventDescriptor = singleOracleInfo.announcement.oracleEvent
|
|
177
174
|
.eventDescriptor;
|
|
178
|
-
if (eventDescriptor.type !== messaging_1.MessageType.
|
|
175
|
+
if (eventDescriptor.type !== messaging_1.MessageType.DigitDecompositionEventDescriptor)
|
|
179
176
|
throw Error('Only DigitDecomposition Oracle Events supported');
|
|
180
177
|
const roundingIntervals = contractDescriptor.roundingIntervals;
|
|
181
178
|
const cetPayouts = core_1.HyperbolaPayoutCurve.computePayouts(payoutFunction, totalCollateral, roundingIntervals);
|
|
@@ -186,26 +183,21 @@ class BitcoinDlcProvider extends provider_1.default {
|
|
|
186
183
|
groups: (0, core_1.groupByIgnoringDigits)(p.indexFrom, p.indexTo, eventDescriptor.base, contractDescriptor.numDigits),
|
|
187
184
|
});
|
|
188
185
|
});
|
|
189
|
-
const rValuesMessagesList = this.GenerateMessages(
|
|
190
|
-
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);
|
|
191
188
|
return { payouts, payoutGroups, messagesList };
|
|
192
189
|
}
|
|
193
|
-
GetPayoutsFromPolynomialPayoutFunction(
|
|
194
|
-
if (_dlcOffer.type !== messaging_1.MessageType.DlcOfferV0)
|
|
195
|
-
throw Error('DlcOffer must be V0');
|
|
196
|
-
const dlcOffer = _dlcOffer;
|
|
197
|
-
if (contractDescriptor.payoutFunction.type !== messaging_1.MessageType.PayoutFunctionV0)
|
|
198
|
-
throw Error('PayoutFunction must be V0');
|
|
190
|
+
GetPayoutsFromPolynomialPayoutFunction(dlcOffer, contractDescriptor, oracleInfo, totalCollateral) {
|
|
199
191
|
const payoutFunction = contractDescriptor.payoutFunction;
|
|
200
|
-
if (payoutFunction.
|
|
192
|
+
if (payoutFunction.payoutFunctionPieces.length === 0)
|
|
201
193
|
throw Error('PayoutFunction must have at least once PayoutCurvePiece');
|
|
202
|
-
for (const piece of payoutFunction.
|
|
194
|
+
for (const piece of payoutFunction.payoutFunctionPieces) {
|
|
203
195
|
if (piece.payoutCurvePiece.type !== messaging_1.MessageType.PolynomialPayoutCurvePiece)
|
|
204
196
|
throw Error('Must be PolynomialPayoutCurvePiece');
|
|
205
197
|
}
|
|
206
198
|
const eventDescriptor = oracleInfo.announcement.oracleEvent
|
|
207
199
|
.eventDescriptor;
|
|
208
|
-
if (eventDescriptor.type !== messaging_1.MessageType.
|
|
200
|
+
if (eventDescriptor.type !== messaging_1.MessageType.DigitDecompositionEventDescriptor)
|
|
209
201
|
throw Error('Only DigitDecomposition Oracle Events supported');
|
|
210
202
|
const roundingIntervals = contractDescriptor.roundingIntervals;
|
|
211
203
|
const cetPayouts = core_1.PolynomialPayoutCurve.computePayouts(payoutFunction, totalCollateral, roundingIntervals);
|
|
@@ -217,11 +209,10 @@ class BitcoinDlcProvider extends provider_1.default {
|
|
|
217
209
|
});
|
|
218
210
|
});
|
|
219
211
|
const rValuesMessagesList = this.GenerateMessages(oracleInfo);
|
|
220
|
-
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);
|
|
221
213
|
return { payouts, payoutGroups, messagesList };
|
|
222
214
|
}
|
|
223
|
-
GetPayouts(
|
|
224
|
-
const { dlcOffer } = (0, Utils_1.checkTypes)({ _dlcOffer });
|
|
215
|
+
GetPayouts(dlcOffer) {
|
|
225
216
|
const contractInfo = dlcOffer.contractInfo;
|
|
226
217
|
const totalCollateral = contractInfo.totalCollateral;
|
|
227
218
|
const contractOraclePairs = this.GetContractOraclePairs(contractInfo);
|
|
@@ -247,43 +238,46 @@ class BitcoinDlcProvider extends provider_1.default {
|
|
|
247
238
|
});
|
|
248
239
|
}, [{ startingMessagesIndex: 0, startingPayoutGroupsIndex: 0 }]);
|
|
249
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
|
+
}
|
|
250
255
|
GetPayoutsFromContractDescriptor(dlcOffer, contractDescriptor, oracleInfo, totalCollateral) {
|
|
251
|
-
switch (contractDescriptor.
|
|
252
|
-
case messaging_1.
|
|
253
|
-
|
|
256
|
+
switch (contractDescriptor.contractDescriptorType) {
|
|
257
|
+
case messaging_1.ContractDescriptorType.Enumerated: {
|
|
258
|
+
return this.GetPayoutsFromEnumeratedDescriptor(dlcOffer, contractDescriptor, oracleInfo, totalCollateral);
|
|
254
259
|
}
|
|
255
|
-
case messaging_1.
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
return this.GetPayoutsFromPayoutFunction(dlcOffer, contractDescriptor, oracleInfo, totalCollateral);
|
|
266
|
-
case messaging_1.MessageType.PolynomialPayoutCurvePiece:
|
|
267
|
-
return this.GetPayoutsFromPolynomialPayoutFunction(dlcOffer, contractDescriptor, oracleInfo, totalCollateral);
|
|
268
|
-
}
|
|
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);
|
|
269
270
|
}
|
|
270
|
-
break;
|
|
271
|
-
default: {
|
|
272
|
-
throw Error('ContractDescriptor must be V0 or V1');
|
|
273
271
|
}
|
|
274
272
|
}
|
|
275
273
|
}
|
|
276
|
-
async createDlcTxs(
|
|
277
|
-
const
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
const
|
|
282
|
-
const
|
|
283
|
-
const localFinalScriptPubkey = dlcOffer.payoutSPK.toString('hex');
|
|
284
|
-
const remoteFinalScriptPubkey = dlcAccept.payoutSPK.toString('hex');
|
|
285
|
-
const localChangeScriptPubkey = dlcOffer.changeSPK.toString('hex');
|
|
286
|
-
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');
|
|
287
281
|
const localInputs = await Promise.all(dlcOffer.fundingInputs.map(async (fundingInput) => {
|
|
288
282
|
const input = await this.fundingInputToInput(fundingInput, false);
|
|
289
283
|
return input.toUtxo();
|
|
@@ -296,23 +290,23 @@ class BitcoinDlcProvider extends provider_1.default {
|
|
|
296
290
|
const remoteInputAmount = remoteInputs.reduce((prev, cur) => prev + cur.amount.GetSatoshiAmount(), 0);
|
|
297
291
|
let payouts = [];
|
|
298
292
|
let messagesList = [];
|
|
299
|
-
if (dlcOffer.contractInfo.type === messaging_1.MessageType.
|
|
293
|
+
if (dlcOffer.contractInfo.type === messaging_1.MessageType.SingleContractInfo &&
|
|
300
294
|
dlcOffer.contractInfo.contractDescriptor.type ===
|
|
301
|
-
messaging_1.
|
|
295
|
+
messaging_1.ContractDescriptorType.Enumerated) {
|
|
302
296
|
for (const outcome of dlcOffer.contractInfo
|
|
303
297
|
.contractDescriptor.outcomes) {
|
|
304
298
|
payouts.push({
|
|
305
299
|
local: outcome.localPayout,
|
|
306
|
-
remote: dlcOffer.
|
|
307
|
-
dlcAccept.
|
|
300
|
+
remote: dlcOffer.offerCollateral +
|
|
301
|
+
dlcAccept.acceptCollateral -
|
|
308
302
|
outcome.localPayout,
|
|
309
303
|
});
|
|
310
|
-
messagesList.push({ messages: [outcome.outcome
|
|
304
|
+
messagesList.push({ messages: [outcome.outcome] });
|
|
311
305
|
}
|
|
312
306
|
}
|
|
313
307
|
else {
|
|
314
308
|
const payoutResponses = this.GetPayouts(dlcOffer);
|
|
315
|
-
const { payouts: tempPayouts, messagesList: tempMessagesList
|
|
309
|
+
const { payouts: tempPayouts, messagesList: tempMessagesList } = this.FlattenPayouts(payoutResponses);
|
|
316
310
|
payouts = tempPayouts;
|
|
317
311
|
messagesList = tempMessagesList;
|
|
318
312
|
}
|
|
@@ -323,11 +317,11 @@ class BitcoinDlcProvider extends provider_1.default {
|
|
|
323
317
|
remoteFundPubkey,
|
|
324
318
|
remoteFinalScriptPubkey,
|
|
325
319
|
localInputAmount,
|
|
326
|
-
localCollateralAmount: dlcOffer.
|
|
320
|
+
localCollateralAmount: dlcOffer.offerCollateral,
|
|
327
321
|
localPayoutSerialId: dlcOffer.payoutSerialId,
|
|
328
322
|
localChangeSerialId: dlcOffer.changeSerialId,
|
|
329
323
|
remoteInputAmount,
|
|
330
|
-
remoteCollateralAmount: dlcAccept.
|
|
324
|
+
remoteCollateralAmount: dlcAccept.acceptCollateral,
|
|
331
325
|
remotePayoutSerialId: dlcAccept.payoutSerialId,
|
|
332
326
|
remoteChangeSerialId: dlcAccept.changeSerialId,
|
|
333
327
|
refundLocktime: dlcOffer.refundLocktime,
|
|
@@ -340,7 +334,7 @@ class BitcoinDlcProvider extends provider_1.default {
|
|
|
340
334
|
fundOutputSerialId: dlcOffer.fundOutputSerialId,
|
|
341
335
|
};
|
|
342
336
|
const dlcTxs = await this.CreateDlcTransactions(dlcTxRequest);
|
|
343
|
-
const dlcTransactions = new messaging_1.
|
|
337
|
+
const dlcTransactions = new messaging_1.DlcTransactions();
|
|
344
338
|
dlcTransactions.fundTx = bitcoin_1.Tx.decode(bufio_1.StreamReader.fromHex(dlcTxs.fundTxHex));
|
|
345
339
|
dlcTransactions.fundTxVout = [
|
|
346
340
|
BigInt(dlcOffer.changeSerialId),
|
|
@@ -355,19 +349,13 @@ class BitcoinDlcProvider extends provider_1.default {
|
|
|
355
349
|
});
|
|
356
350
|
return { dlcTransactions, messagesList };
|
|
357
351
|
}
|
|
358
|
-
async createBatchDlcTxs(
|
|
359
|
-
const
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
const
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
const localFundPubkeys = dlcOffers.map((dlcOffer) => dlcOffer.fundingPubKey.toString('hex'));
|
|
366
|
-
const remoteFundPubkeys = dlcAccepts.map((dlcAccept) => dlcAccept.fundingPubKey.toString('hex'));
|
|
367
|
-
const localFinalScriptPubkeys = dlcOffers.map((dlcOffer) => dlcOffer.payoutSPK.toString('hex'));
|
|
368
|
-
const remoteFinalScriptPubkeys = dlcAccepts.map((dlcAccept) => dlcAccept.payoutSPK.toString('hex'));
|
|
369
|
-
const localChangeScriptPubkey = dlcOffers[0].changeSPK.toString('hex');
|
|
370
|
-
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');
|
|
371
359
|
const localInputs = await Promise.all(dlcOffers[0].fundingInputs.map(async (fundingInput) => {
|
|
372
360
|
const input = await this.fundingInputToInput(fundingInput, false);
|
|
373
361
|
return input.toUtxo();
|
|
@@ -402,11 +390,11 @@ class BitcoinDlcProvider extends provider_1.default {
|
|
|
402
390
|
remoteFundPubkeys,
|
|
403
391
|
remoteFinalScriptPubkeys,
|
|
404
392
|
localInputAmount,
|
|
405
|
-
localCollateralAmounts: dlcOffers.map((dlcOffer) => dlcOffer.
|
|
393
|
+
localCollateralAmounts: dlcOffers.map((dlcOffer) => dlcOffer.offerCollateral),
|
|
406
394
|
localPayoutSerialIds: dlcOffers.map((dlcOffer) => dlcOffer.payoutSerialId),
|
|
407
395
|
localChangeSerialId: dlcOffers[0].changeSerialId,
|
|
408
396
|
remoteInputAmount,
|
|
409
|
-
remoteCollateralAmounts: dlcAccepts.map((dlcAccept) => dlcAccept.
|
|
397
|
+
remoteCollateralAmounts: dlcAccepts.map((dlcAccept) => dlcAccept.acceptCollateral),
|
|
410
398
|
remotePayoutSerialIds: dlcAccepts.map((dlcAccept) => dlcAccept.payoutSerialId),
|
|
411
399
|
remoteChangeSerialId: dlcAccepts[0].changeSerialId,
|
|
412
400
|
refundLocktimes: dlcOffers.map((dlcOffer) => dlcOffer.refundLocktime),
|
|
@@ -422,7 +410,7 @@ class BitcoinDlcProvider extends provider_1.default {
|
|
|
422
410
|
const dlcTransactionsList = [];
|
|
423
411
|
let start = 0;
|
|
424
412
|
for (let i = 0; i < dlcTxs.refundTxHexList.length; i++) {
|
|
425
|
-
const dlcTransactions = new messaging_1.
|
|
413
|
+
const dlcTransactions = new messaging_1.DlcTransactions();
|
|
426
414
|
dlcTransactions.fundTx = bitcoin_1.Tx.decode(bufio_1.StreamReader.fromHex(dlcTxs.fundTxHex));
|
|
427
415
|
dlcTransactions.fundTxVout = [
|
|
428
416
|
BigInt(dlcOffers[i].changeSerialId),
|
|
@@ -444,7 +432,13 @@ class BitcoinDlcProvider extends provider_1.default {
|
|
|
444
432
|
return { dlcTransactionsList, nestedMessagesList };
|
|
445
433
|
}
|
|
446
434
|
GenerateEnumMessages(oracleEvent) {
|
|
447
|
-
|
|
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;
|
|
448
442
|
}
|
|
449
443
|
GenerateDigitDecompositionMessages(oracleEvent) {
|
|
450
444
|
const oracleNonces = oracleEvent.oracleNonces;
|
|
@@ -461,32 +455,50 @@ class BitcoinDlcProvider extends provider_1.default {
|
|
|
461
455
|
return messagesList;
|
|
462
456
|
}
|
|
463
457
|
GenerateMessages(oracleInfo) {
|
|
464
|
-
|
|
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
|
+
}
|
|
465
476
|
switch (oracleEvent.eventDescriptor.type) {
|
|
466
|
-
case messaging_1.MessageType.
|
|
477
|
+
case messaging_1.MessageType.EnumEventDescriptor:
|
|
467
478
|
return this.GenerateEnumMessages(oracleEvent);
|
|
468
|
-
case messaging_1.MessageType.
|
|
479
|
+
case messaging_1.MessageType.DigitDecompositionEventDescriptor:
|
|
469
480
|
return this.GenerateDigitDecompositionMessages(oracleEvent);
|
|
470
481
|
default:
|
|
471
482
|
throw Error('EventDescriptor must be Enum or DigitDecomposition');
|
|
472
483
|
}
|
|
473
484
|
}
|
|
474
485
|
GetContractOraclePairs(_contractInfo) {
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
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');
|
|
490
502
|
}
|
|
491
503
|
}
|
|
492
504
|
async CreateCetAdaptorAndRefundSigs(_dlcOffer, _dlcAccept, _dlcTxs, messagesList, isOfferer) {
|
|
@@ -497,7 +509,7 @@ class BitcoinDlcProvider extends provider_1.default {
|
|
|
497
509
|
});
|
|
498
510
|
const network = await this.getConnectedNetwork();
|
|
499
511
|
const cetsHex = dlcTxs.cets.map((cet) => cet.serialize().toString('hex'));
|
|
500
|
-
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))
|
|
501
513
|
.serialize()
|
|
502
514
|
.slice(1);
|
|
503
515
|
const fundingAddress = bitcoinjs_lib_1.address.fromOutputScript(fundingSPK, network);
|
|
@@ -508,11 +520,15 @@ class BitcoinDlcProvider extends provider_1.default {
|
|
|
508
520
|
const fundPrivateKey = Buffer.from(fundPrivateKeyPair.__D).toString('hex');
|
|
509
521
|
const contractOraclePairs = this.GetContractOraclePairs(dlcOffer.contractInfo);
|
|
510
522
|
const sigs = [];
|
|
511
|
-
if (dlcOffer.contractInfo.
|
|
523
|
+
if (dlcOffer.contractInfo.contractInfoType === messaging_1.ContractInfoType.Single &&
|
|
512
524
|
dlcOffer.contractInfo.contractDescriptor.type ===
|
|
513
525
|
messaging_1.MessageType.ContractDescriptorV0) {
|
|
514
526
|
for (const [_, { oracleInfo }] of contractOraclePairs.entries()) {
|
|
515
|
-
|
|
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;
|
|
516
532
|
const adaptorSigRequestPromises = [];
|
|
517
533
|
const tempMessagesList = messagesList;
|
|
518
534
|
const tempCetsHex = cetsHex;
|
|
@@ -522,8 +538,8 @@ class BitcoinDlcProvider extends provider_1.default {
|
|
|
522
538
|
privkey: fundPrivateKey,
|
|
523
539
|
fundTxId: dlcTxs.fundTx.txId.toString(),
|
|
524
540
|
fundVout: dlcTxs.fundTxVout,
|
|
525
|
-
localFundPubkey: dlcOffer.
|
|
526
|
-
remoteFundPubkey: dlcAccept.
|
|
541
|
+
localFundPubkey: dlcOffer.fundingPubkey.toString('hex'),
|
|
542
|
+
remoteFundPubkey: dlcAccept.fundingPubkey.toString('hex'),
|
|
527
543
|
fundInputAmount: dlcTxs.fundTx.outputs[dlcTxs.fundTxVout].value.sats,
|
|
528
544
|
oraclePubkey: oracleAnnouncement.oraclePubkey.toString('hex'),
|
|
529
545
|
oracleRValues: oracleAnnouncement.oracleEvent.oracleNonces.map((nonce) => nonce.toString('hex')),
|
|
@@ -544,7 +560,11 @@ class BitcoinDlcProvider extends provider_1.default {
|
|
|
544
560
|
else {
|
|
545
561
|
const indices = this.GetIndicesFromPayouts(this.GetPayouts(_dlcOffer));
|
|
546
562
|
for (const [index, { oracleInfo }] of contractOraclePairs.entries()) {
|
|
547
|
-
|
|
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;
|
|
548
568
|
const startingIndex = indices[index].startingMessagesIndex, endingIndex = indices[index + 1].startingMessagesIndex;
|
|
549
569
|
const oracleEventMessagesList = messagesList.slice(startingIndex, endingIndex);
|
|
550
570
|
const oracleEventCetsHex = cetsHex.slice(startingIndex, endingIndex);
|
|
@@ -559,8 +579,8 @@ class BitcoinDlcProvider extends provider_1.default {
|
|
|
559
579
|
privkey: fundPrivateKey,
|
|
560
580
|
fundTxId: dlcTxs.fundTx.txId.toString(),
|
|
561
581
|
fundVout: dlcTxs.fundTxVout,
|
|
562
|
-
localFundPubkey: dlcOffer.
|
|
563
|
-
remoteFundPubkey: dlcAccept.
|
|
582
|
+
localFundPubkey: dlcOffer.fundingPubkey.toString('hex'),
|
|
583
|
+
remoteFundPubkey: dlcAccept.fundingPubkey.toString('hex'),
|
|
564
584
|
fundInputAmount: dlcTxs.fundTx.outputs[dlcTxs.fundTxVout].value.sats,
|
|
565
585
|
oraclePubkey: oracleAnnouncement.oraclePubkey.toString('hex'),
|
|
566
586
|
oracleRValues: oracleAnnouncement.oracleEvent.oracleNonces.map((nonce) => nonce.toString('hex')),
|
|
@@ -584,12 +604,12 @@ class BitcoinDlcProvider extends provider_1.default {
|
|
|
584
604
|
privkey: fundPrivateKey,
|
|
585
605
|
fundTxId: dlcTxs.fundTx.txId.toString(),
|
|
586
606
|
fundVout: dlcTxs.fundTxVout,
|
|
587
|
-
localFundPubkey: dlcOffer.
|
|
588
|
-
remoteFundPubkey: dlcAccept.
|
|
607
|
+
localFundPubkey: dlcOffer.fundingPubkey.toString('hex'),
|
|
608
|
+
remoteFundPubkey: dlcAccept.fundingPubkey.toString('hex'),
|
|
589
609
|
fundInputAmount: dlcTxs.fundTx.outputs[dlcTxs.fundTxVout].value.sats,
|
|
590
610
|
};
|
|
591
611
|
const refundSignature = Buffer.from((await this.GetRawRefundTxSignature(refundSignRequest)).hex, 'hex');
|
|
592
|
-
const cetSignatures = new messaging_1.
|
|
612
|
+
const cetSignatures = new messaging_1.CetAdaptorSignatures();
|
|
593
613
|
cetSignatures.sigs = sigs.flat();
|
|
594
614
|
return { cetSignatures, refundSignature };
|
|
595
615
|
}
|
|
@@ -602,15 +622,19 @@ class BitcoinDlcProvider extends provider_1.default {
|
|
|
602
622
|
});
|
|
603
623
|
const cetsHex = dlcTxs.cets.map((cet) => cet.serialize().toString('hex'));
|
|
604
624
|
const contractOraclePairs = this.GetContractOraclePairs(dlcOffer.contractInfo);
|
|
605
|
-
if (dlcOffer.contractInfo.type === messaging_1.MessageType.
|
|
625
|
+
if (dlcOffer.contractInfo.type === messaging_1.MessageType.SingleContractInfo &&
|
|
606
626
|
dlcOffer.contractInfo.contractDescriptor.type ===
|
|
607
627
|
messaging_1.MessageType.ContractDescriptorV0) {
|
|
608
628
|
for (const [_, { oracleInfo }] of contractOraclePairs.entries()) {
|
|
609
|
-
|
|
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;
|
|
610
634
|
const oracleEventCetsHex = cetsHex;
|
|
611
635
|
const oracleEventSigs = isOfferer
|
|
612
|
-
? dlcAccept.
|
|
613
|
-
: dlcSign.
|
|
636
|
+
? dlcAccept.cetAdaptorSignatures.sigs
|
|
637
|
+
: dlcSign.cetAdaptorSignatures.sigs;
|
|
614
638
|
const sigsValidity = [];
|
|
615
639
|
const tempMessagesList = messagesList;
|
|
616
640
|
const tempCetsHex = oracleEventCetsHex;
|
|
@@ -627,8 +651,8 @@ class BitcoinDlcProvider extends provider_1.default {
|
|
|
627
651
|
oraclePubkey: oracleAnnouncement.oraclePubkey.toString('hex'),
|
|
628
652
|
oracleRValues: oracleAnnouncement.oracleEvent.oracleNonces.map((nonce) => nonce.toString('hex')),
|
|
629
653
|
adaptorPairs: tempAdaptorPairs,
|
|
630
|
-
localFundPubkey: dlcOffer.
|
|
631
|
-
remoteFundPubkey: dlcAccept.
|
|
654
|
+
localFundPubkey: dlcOffer.fundingPubkey.toString('hex'),
|
|
655
|
+
remoteFundPubkey: dlcAccept.fundingPubkey.toString('hex'),
|
|
632
656
|
fundTxId: dlcTxs.fundTx.txId.toString(),
|
|
633
657
|
fundVout: dlcTxs.fundTxVout,
|
|
634
658
|
fundInputAmount: dlcTxs.fundTx.outputs[dlcTxs.fundTxVout].value.sats,
|
|
@@ -644,8 +668,8 @@ class BitcoinDlcProvider extends provider_1.default {
|
|
|
644
668
|
signature: isOfferer
|
|
645
669
|
? dlcAccept.refundSignature.toString('hex')
|
|
646
670
|
: dlcSign.refundSignature.toString('hex'),
|
|
647
|
-
localFundPubkey: dlcOffer.
|
|
648
|
-
remoteFundPubkey: dlcAccept.
|
|
671
|
+
localFundPubkey: dlcOffer.fundingPubkey.toString('hex'),
|
|
672
|
+
remoteFundPubkey: dlcAccept.fundingPubkey.toString('hex'),
|
|
649
673
|
fundTxId: dlcTxs.fundTx.txId.toString(),
|
|
650
674
|
fundVout: dlcTxs.fundTxVout,
|
|
651
675
|
fundInputAmount: dlcTxs.fundTx.outputs[dlcTxs.fundTxVout].value.sats,
|
|
@@ -663,13 +687,17 @@ class BitcoinDlcProvider extends provider_1.default {
|
|
|
663
687
|
const chunk = 100;
|
|
664
688
|
const indices = this.GetIndicesFromPayouts(this.GetPayouts(_dlcOffer));
|
|
665
689
|
for (const [index, { oracleInfo }] of contractOraclePairs.entries()) {
|
|
666
|
-
|
|
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;
|
|
667
695
|
const startingIndex = indices[index].startingMessagesIndex, endingIndex = indices[index + 1].startingMessagesIndex;
|
|
668
696
|
const oracleEventMessagesList = messagesList.slice(startingIndex, endingIndex);
|
|
669
697
|
const oracleEventCetsHex = cetsHex.slice(startingIndex, endingIndex);
|
|
670
698
|
const oracleEventSigs = (isOfferer
|
|
671
|
-
? dlcAccept.
|
|
672
|
-
: dlcSign.
|
|
699
|
+
? dlcAccept.cetAdaptorSignatures.sigs
|
|
700
|
+
: dlcSign.cetAdaptorSignatures.sigs).slice(startingIndex, endingIndex);
|
|
673
701
|
const sigsValidity = [];
|
|
674
702
|
for (let i = 0, j = oracleEventMessagesList.length; i < j; i += chunk) {
|
|
675
703
|
const tempMessagesList = oracleEventMessagesList.slice(i, i + chunk);
|
|
@@ -687,8 +715,8 @@ class BitcoinDlcProvider extends provider_1.default {
|
|
|
687
715
|
oraclePubkey: oracleAnnouncement.oraclePubkey.toString('hex'),
|
|
688
716
|
oracleRValues: oracleAnnouncement.oracleEvent.oracleNonces.map((nonce) => nonce.toString('hex')),
|
|
689
717
|
adaptorPairs: tempAdaptorPairs,
|
|
690
|
-
localFundPubkey: dlcOffer.
|
|
691
|
-
remoteFundPubkey: dlcAccept.
|
|
718
|
+
localFundPubkey: dlcOffer.fundingPubkey.toString('hex'),
|
|
719
|
+
remoteFundPubkey: dlcAccept.fundingPubkey.toString('hex'),
|
|
692
720
|
fundTxId: dlcTxs.fundTx.txId.toString(),
|
|
693
721
|
fundVout: dlcTxs.fundTxVout,
|
|
694
722
|
fundInputAmount: dlcTxs.fundTx.outputs[dlcTxs.fundTxVout].value.sats,
|
|
@@ -705,8 +733,8 @@ class BitcoinDlcProvider extends provider_1.default {
|
|
|
705
733
|
signature: isOfferer
|
|
706
734
|
? dlcAccept.refundSignature.toString('hex')
|
|
707
735
|
: dlcSign.refundSignature.toString('hex'),
|
|
708
|
-
localFundPubkey: dlcOffer.
|
|
709
|
-
remoteFundPubkey: dlcAccept.
|
|
736
|
+
localFundPubkey: dlcOffer.fundingPubkey.toString('hex'),
|
|
737
|
+
remoteFundPubkey: dlcAccept.fundingPubkey.toString('hex'),
|
|
710
738
|
fundTxId: dlcTxs.fundTx.txId.toString(),
|
|
711
739
|
fundVout: dlcTxs.fundTxVout,
|
|
712
740
|
fundInputAmount: dlcTxs.fundTx.outputs[dlcTxs.fundTxVout].value.sats,
|
|
@@ -760,17 +788,11 @@ class BitcoinDlcProvider extends provider_1.default {
|
|
|
760
788
|
pubKeyWitness.witness = Buffer.from(inputPubKeys[i], 'hex');
|
|
761
789
|
witnessElements.push([sigWitness, pubKeyWitness]);
|
|
762
790
|
}
|
|
763
|
-
const fundingSignatures = new messaging_1.
|
|
791
|
+
const fundingSignatures = new messaging_1.FundingSignatures();
|
|
764
792
|
fundingSignatures.witnessElements = witnessElements;
|
|
765
793
|
return fundingSignatures;
|
|
766
794
|
}
|
|
767
|
-
async VerifyFundingSigs(
|
|
768
|
-
const { dlcOffer, dlcAccept, dlcSign, dlcTxs } = (0, Utils_1.checkTypes)({
|
|
769
|
-
_dlcOffer,
|
|
770
|
-
_dlcAccept,
|
|
771
|
-
_dlcSign,
|
|
772
|
-
_dlcTxs,
|
|
773
|
-
});
|
|
795
|
+
async VerifyFundingSigs(dlcOffer, dlcAccept, dlcSign, dlcTxs, isOfferer) {
|
|
774
796
|
const sigsValidity = [];
|
|
775
797
|
for (let i = 0; i < dlcSign.fundingSignatures.witnessElements.length; i++) {
|
|
776
798
|
const witnessElement = dlcSign.fundingSignatures.witnessElements[i];
|
|
@@ -797,13 +819,7 @@ class BitcoinDlcProvider extends provider_1.default {
|
|
|
797
819
|
throw new Error('Invalid signatures received');
|
|
798
820
|
}
|
|
799
821
|
}
|
|
800
|
-
async CreateFundingTx(
|
|
801
|
-
const { dlcOffer, dlcAccept, dlcSign, dlcTxs } = (0, Utils_1.checkTypes)({
|
|
802
|
-
_dlcOffer,
|
|
803
|
-
_dlcAccept,
|
|
804
|
-
_dlcSign,
|
|
805
|
-
_dlcTxs,
|
|
806
|
-
});
|
|
822
|
+
async CreateFundingTx(dlcOffer, dlcAccept, dlcSign, dlcTxs, fundingSignatures) {
|
|
807
823
|
const witnessElements = [
|
|
808
824
|
...dlcSign.fundingSignatures.witnessElements,
|
|
809
825
|
...fundingSignatures.witnessElements,
|
|
@@ -830,8 +846,7 @@ class BitcoinDlcProvider extends provider_1.default {
|
|
|
830
846
|
const fundTx = bitcoin_1.Tx.decode(bufio_1.StreamReader.fromHex(fundTxHex));
|
|
831
847
|
return fundTx;
|
|
832
848
|
}
|
|
833
|
-
async FindOutcomeIndexFromPolynomialPayoutCurvePiece(
|
|
834
|
-
const { dlcOffer } = (0, Utils_1.checkTypes)({ _dlcOffer });
|
|
849
|
+
async FindOutcomeIndexFromPolynomialPayoutCurvePiece(dlcOffer, contractDescriptor, contractOraclePairIndex, polynomialPayoutCurvePiece, oracleAttestation, outcome) {
|
|
835
850
|
const polynomialCurve = core_1.PolynomialPayoutCurve.fromPayoutCurvePiece(polynomialPayoutCurvePiece);
|
|
836
851
|
const payouts = polynomialPayoutCurvePiece.points.map((point) => Number(point.outcomePayout));
|
|
837
852
|
const minPayout = Math.min(...payouts);
|
|
@@ -839,7 +854,8 @@ class BitcoinDlcProvider extends provider_1.default {
|
|
|
839
854
|
const clampBN = (val) => bignumber_js_1.default.max(minPayout, bignumber_js_1.default.min(val, maxPayout));
|
|
840
855
|
const payout = clampBN(polynomialCurve.getPayout(outcome));
|
|
841
856
|
const payoutResponses = this.GetPayouts(dlcOffer);
|
|
842
|
-
const payoutIndexOffset = this.GetIndicesFromPayouts(payoutResponses)[contractOraclePairIndex]
|
|
857
|
+
const payoutIndexOffset = this.GetIndicesFromPayouts(payoutResponses)[contractOraclePairIndex]
|
|
858
|
+
.startingMessagesIndex;
|
|
843
859
|
const { payoutGroups } = payoutResponses[contractOraclePairIndex];
|
|
844
860
|
const intervalsSorted = [
|
|
845
861
|
...contractDescriptor.roundingIntervals.intervals,
|
|
@@ -877,7 +893,8 @@ Payout Group not found');
|
|
|
877
893
|
const clampBN = (val) => bignumber_js_1.default.max(0, bignumber_js_1.default.min(val, dlcOffer.contractInfo.totalCollateral.toString()));
|
|
878
894
|
const payout = clampBN(hyperbolaCurve.getPayout(outcome));
|
|
879
895
|
const payoutResponses = this.GetPayouts(dlcOffer);
|
|
880
|
-
const payoutIndexOffset = this.GetIndicesFromPayouts(payoutResponses)[contractOraclePairIndex]
|
|
896
|
+
const payoutIndexOffset = this.GetIndicesFromPayouts(payoutResponses)[contractOraclePairIndex]
|
|
897
|
+
.startingMessagesIndex;
|
|
881
898
|
const { payoutGroups } = payoutResponses[contractOraclePairIndex];
|
|
882
899
|
const intervalsSorted = [
|
|
883
900
|
...contractDescriptor.roundingIntervals.intervals,
|
|
@@ -921,32 +938,59 @@ Payout Group not found');
|
|
|
921
938
|
}
|
|
922
939
|
}
|
|
923
940
|
if (groupIndex === -1) {
|
|
924
|
-
|
|
925
|
-
|
|
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
|
+
}
|
|
926
961
|
}
|
|
927
962
|
return { index: payoutIndexOffset + index, groupLength };
|
|
928
963
|
}
|
|
929
|
-
async FindOutcomeIndex(
|
|
930
|
-
const { dlcOffer } = (0, Utils_1.checkTypes)({ _dlcOffer });
|
|
964
|
+
async FindOutcomeIndex(dlcOffer, oracleAttestation) {
|
|
931
965
|
const contractOraclePairs = this.GetContractOraclePairs(dlcOffer.contractInfo);
|
|
932
|
-
const contractOraclePairIndex = contractOraclePairs.findIndex(({ oracleInfo }) =>
|
|
933
|
-
|
|
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
|
+
});
|
|
934
973
|
(0, assert_1.default)(contractOraclePairIndex !== -1, 'OracleAttestation must be for an existing OracleEvent');
|
|
935
974
|
const contractOraclePair = contractOraclePairs[contractOraclePairIndex];
|
|
936
|
-
const { contractDescriptor: _contractDescriptor, oracleInfo
|
|
937
|
-
(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');
|
|
938
978
|
const contractDescriptor = _contractDescriptor;
|
|
939
979
|
const _payoutFunction = contractDescriptor.payoutFunction;
|
|
940
|
-
(0, assert_1.default)(_payoutFunction.type === messaging_1.MessageType.
|
|
941
|
-
|
|
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
|
|
942
986
|
.eventDescriptor;
|
|
943
987
|
const payoutFunction = _payoutFunction;
|
|
944
988
|
const base = eventDescriptor.base;
|
|
945
989
|
const outcome = [...oracleAttestation.outcomes]
|
|
946
990
|
.reverse()
|
|
947
991
|
.reduce((acc, val, i) => acc + Number(val) * base ** i, 0);
|
|
948
|
-
const piecesSorted = payoutFunction.
|
|
949
|
-
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);
|
|
950
994
|
switch (piece.payoutCurvePiece.type) {
|
|
951
995
|
case messaging_1.MessageType.PolynomialPayoutCurvePiece:
|
|
952
996
|
return this.FindOutcomeIndexFromPolynomialPayoutCurvePiece(dlcOffer, contractDescriptor, contractOraclePairIndex, piece.payoutCurvePiece, oracleAttestation, BigInt(outcome));
|
|
@@ -958,24 +1002,29 @@ Payout Group not found');
|
|
|
958
1002
|
throw Error('Must be Hyperbola or Polynomial curve piece');
|
|
959
1003
|
}
|
|
960
1004
|
}
|
|
961
|
-
ValidateEvent(
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
});
|
|
965
|
-
switch (dlcOffer.contractInfo.type) {
|
|
966
|
-
case messaging_1.MessageType.ContractInfoV0: {
|
|
1005
|
+
ValidateEvent(dlcOffer, oracleAttestation) {
|
|
1006
|
+
switch (dlcOffer.contractInfo.contractInfoType) {
|
|
1007
|
+
case messaging_1.ContractInfoType.Single: {
|
|
967
1008
|
const contractInfo = dlcOffer.contractInfo;
|
|
968
|
-
switch (contractInfo.contractDescriptor.
|
|
969
|
-
case messaging_1.
|
|
1009
|
+
switch (contractInfo.contractDescriptor.contractDescriptorType) {
|
|
1010
|
+
case messaging_1.ContractDescriptorType.Enumerated: {
|
|
970
1011
|
const oracleInfo = contractInfo.oracleInfo;
|
|
971
|
-
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 !==
|
|
972
1017
|
oracleAttestation.eventId)
|
|
973
1018
|
throw Error('Incorrect Oracle Attestation. Event Id must match.');
|
|
974
1019
|
break;
|
|
975
1020
|
}
|
|
976
|
-
case messaging_1.
|
|
1021
|
+
case messaging_1.ContractDescriptorType.NumericOutcome: {
|
|
977
1022
|
const oracleInfo = contractInfo.oracleInfo;
|
|
978
|
-
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 !==
|
|
979
1028
|
oracleAttestation.eventId)
|
|
980
1029
|
throw Error('Incorrect Oracle Attestation. Event Id must match.');
|
|
981
1030
|
break;
|
|
@@ -985,10 +1034,15 @@ Payout Group not found');
|
|
|
985
1034
|
}
|
|
986
1035
|
break;
|
|
987
1036
|
}
|
|
988
|
-
case messaging_1.
|
|
1037
|
+
case messaging_1.ContractInfoType.Disjoint: {
|
|
989
1038
|
const contractInfo = dlcOffer.contractInfo;
|
|
990
|
-
const attestedOracleEvent = contractInfo.contractOraclePairs.find(({ oracleInfo }) =>
|
|
991
|
-
|
|
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
|
+
});
|
|
992
1046
|
if (!attestedOracleEvent)
|
|
993
1047
|
throw Error('Oracle event of attestation not found.');
|
|
994
1048
|
break;
|
|
@@ -997,35 +1051,29 @@ Payout Group not found');
|
|
|
997
1051
|
throw Error('ContractInfo must be V0 or V1');
|
|
998
1052
|
}
|
|
999
1053
|
}
|
|
1000
|
-
async FindAndSignCet(
|
|
1001
|
-
const { dlcOffer, dlcAccept, dlcSign, dlcTxs } = (0, Utils_1.checkTypes)({
|
|
1002
|
-
_dlcOffer,
|
|
1003
|
-
_dlcAccept,
|
|
1004
|
-
_dlcSign,
|
|
1005
|
-
_dlcTxs,
|
|
1006
|
-
});
|
|
1054
|
+
async FindAndSignCet(dlcOffer, dlcAccept, dlcSign, dlcTxs, oracleAttestation, isOfferer) {
|
|
1007
1055
|
if (isOfferer === undefined)
|
|
1008
1056
|
isOfferer = await this.isOfferer(dlcOffer, dlcAccept);
|
|
1009
1057
|
const fundPrivateKey = await this.GetFundPrivateKey(dlcOffer, dlcAccept, isOfferer);
|
|
1010
1058
|
let signCetRequest;
|
|
1011
|
-
if (dlcOffer.contractInfo.
|
|
1012
|
-
dlcOffer.contractInfo.contractDescriptor
|
|
1013
|
-
messaging_1.
|
|
1059
|
+
if (dlcOffer.contractInfo.contractInfoType === messaging_1.ContractInfoType.Single &&
|
|
1060
|
+
dlcOffer.contractInfo.contractDescriptor
|
|
1061
|
+
.contractDescriptorType === messaging_1.ContractDescriptorType.Enumerated) {
|
|
1014
1062
|
const outcomeIndex = dlcOffer.contractInfo
|
|
1015
|
-
.contractDescriptor.outcomes.findIndex((outcome) => outcome.outcome
|
|
1063
|
+
.contractDescriptor.outcomes.findIndex((outcome) => outcome.outcome ===
|
|
1016
1064
|
(0, crypto_1.sha256)(Buffer.from(oracleAttestation.outcomes[0])).toString('hex'));
|
|
1017
1065
|
signCetRequest = {
|
|
1018
1066
|
cetHex: dlcTxs.cets[outcomeIndex].serialize().toString('hex'),
|
|
1019
1067
|
fundPrivkey: fundPrivateKey,
|
|
1020
1068
|
fundTxId: dlcTxs.fundTx.txId.toString(),
|
|
1021
1069
|
fundVout: dlcTxs.fundTxVout,
|
|
1022
|
-
localFundPubkey: dlcOffer.
|
|
1023
|
-
remoteFundPubkey: dlcAccept.
|
|
1070
|
+
localFundPubkey: dlcOffer.fundingPubkey.toString('hex'),
|
|
1071
|
+
remoteFundPubkey: dlcAccept.fundingPubkey.toString('hex'),
|
|
1024
1072
|
oracleSignatures: oracleAttestation.signatures.map((sig) => sig.toString('hex')),
|
|
1025
1073
|
fundInputAmount: dlcTxs.fundTx.outputs[dlcTxs.fundTxVout].value.sats,
|
|
1026
1074
|
adaptorSignature: isOfferer
|
|
1027
|
-
? dlcAccept.
|
|
1028
|
-
: dlcSign.
|
|
1075
|
+
? dlcAccept.cetAdaptorSignatures.sigs[outcomeIndex].encryptedSig.toString('hex')
|
|
1076
|
+
: dlcSign.cetAdaptorSignatures.sigs[outcomeIndex].encryptedSig.toString('hex'),
|
|
1029
1077
|
};
|
|
1030
1078
|
}
|
|
1031
1079
|
else {
|
|
@@ -1039,13 +1087,13 @@ Payout Group not found');
|
|
|
1039
1087
|
fundPrivkey: fundPrivateKey,
|
|
1040
1088
|
fundTxId: dlcTxs.fundTx.txId.toString(),
|
|
1041
1089
|
fundVout: dlcTxs.fundTxVout,
|
|
1042
|
-
localFundPubkey: dlcOffer.
|
|
1043
|
-
remoteFundPubkey: dlcAccept.
|
|
1090
|
+
localFundPubkey: dlcOffer.fundingPubkey.toString('hex'),
|
|
1091
|
+
remoteFundPubkey: dlcAccept.fundingPubkey.toString('hex'),
|
|
1044
1092
|
oracleSignatures: oracleSignatures.map((sig) => sig.toString('hex')),
|
|
1045
1093
|
fundInputAmount: dlcTxs.fundTx.outputs[dlcTxs.fundTxVout].value.sats,
|
|
1046
1094
|
adaptorSignature: isOfferer
|
|
1047
|
-
? dlcAccept.
|
|
1048
|
-
: dlcSign.
|
|
1095
|
+
? dlcAccept.cetAdaptorSignatures.sigs[outcomeIndex].encryptedSig.toString('hex')
|
|
1096
|
+
: dlcSign.cetAdaptorSignatures.sigs[outcomeIndex].encryptedSig.toString('hex'),
|
|
1049
1097
|
};
|
|
1050
1098
|
}
|
|
1051
1099
|
const finalCet = (await this.SignCet(signCetRequest)).hex;
|
|
@@ -1053,7 +1101,7 @@ Payout Group not found');
|
|
|
1053
1101
|
}
|
|
1054
1102
|
async GetFundAddress(dlcOffer, dlcAccept, isOfferer) {
|
|
1055
1103
|
const network = await this.getConnectedNetwork();
|
|
1056
|
-
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))
|
|
1057
1105
|
.serialize()
|
|
1058
1106
|
.slice(1);
|
|
1059
1107
|
const fundingAddress = bitcoinjs_lib_1.address.fromOutputScript(fundingSPK, network);
|
|
@@ -1069,16 +1117,11 @@ Payout Group not found');
|
|
|
1069
1117
|
const fundPrivateKeyPair = await this.GetFundKeyPair(dlcOffer, dlcAccept, isOfferer);
|
|
1070
1118
|
return Buffer.from(fundPrivateKeyPair.privateKey).toString('hex');
|
|
1071
1119
|
}
|
|
1072
|
-
async CreateCloseRawTxs(
|
|
1073
|
-
const { dlcOffer, dlcAccept, dlcTxs } = (0, Utils_1.checkTypes)({
|
|
1074
|
-
_dlcOffer,
|
|
1075
|
-
_dlcAccept,
|
|
1076
|
-
_dlcTxs,
|
|
1077
|
-
});
|
|
1120
|
+
async CreateCloseRawTxs(dlcOffer, dlcAccept, dlcTxs, closeInputAmount, isOfferer, _dlcCloses = [], fundingInputs, initiatorPayouts) {
|
|
1078
1121
|
const network = await this.getConnectedNetwork();
|
|
1079
1122
|
let finalizer;
|
|
1080
1123
|
if (_dlcCloses.length === 0) {
|
|
1081
|
-
finalizer = new core_1.DualClosingTxFinalizer(fundingInputs, dlcOffer.
|
|
1124
|
+
finalizer = new core_1.DualClosingTxFinalizer(fundingInputs, dlcOffer.payoutSpk, dlcAccept.payoutSpk, dlcOffer.feeRatePerVb);
|
|
1082
1125
|
}
|
|
1083
1126
|
const rawTransactionRequestPromises = [];
|
|
1084
1127
|
const rawCloseTxs = [];
|
|
@@ -1109,13 +1152,13 @@ Payout Group not found');
|
|
|
1109
1152
|
const txOuts = [];
|
|
1110
1153
|
if (Number(offerPayoutValue) > 0) {
|
|
1111
1154
|
txOuts.push({
|
|
1112
|
-
address: bitcoinjs_lib_1.address.fromOutputScript(dlcOffer.
|
|
1155
|
+
address: bitcoinjs_lib_1.address.fromOutputScript(dlcOffer.payoutSpk, network),
|
|
1113
1156
|
amount: Number(offerPayoutValue),
|
|
1114
1157
|
});
|
|
1115
1158
|
}
|
|
1116
1159
|
if (Number(acceptPayoutValue) > 0) {
|
|
1117
1160
|
txOuts.push({
|
|
1118
|
-
address: bitcoinjs_lib_1.address.fromOutputScript(dlcAccept.
|
|
1161
|
+
address: bitcoinjs_lib_1.address.fromOutputScript(dlcAccept.payoutSpk, network),
|
|
1119
1162
|
amount: Number(acceptPayoutValue),
|
|
1120
1163
|
});
|
|
1121
1164
|
}
|
|
@@ -1149,9 +1192,9 @@ Payout Group not found');
|
|
|
1149
1192
|
_dlcTxs,
|
|
1150
1193
|
});
|
|
1151
1194
|
const network = await this.getConnectedNetwork();
|
|
1152
|
-
const fundingPubKeys = Buffer.compare(dlcOffer.
|
|
1153
|
-
? [dlcOffer.
|
|
1154
|
-
: [dlcAccept.
|
|
1195
|
+
const fundingPubKeys = Buffer.compare(dlcOffer.fundingPubkey, dlcAccept.fundingPubkey) === -1
|
|
1196
|
+
? [dlcOffer.fundingPubkey, dlcAccept.fundingPubkey]
|
|
1197
|
+
: [dlcAccept.fundingPubkey, dlcOffer.fundingPubkey];
|
|
1155
1198
|
const p2ms = bitcoinjs_lib_1.payments.p2ms({
|
|
1156
1199
|
m: 2,
|
|
1157
1200
|
pubkeys: fundingPubKeys,
|
|
@@ -1219,9 +1262,9 @@ Payout Group not found');
|
|
|
1219
1262
|
});
|
|
1220
1263
|
const dlcCloses = _dlcCloses.map((_dlcClose) => (0, Utils_1.checkTypes)({ _dlcClose }).dlcClose);
|
|
1221
1264
|
const network = await this.getConnectedNetwork();
|
|
1222
|
-
const fundingPubKeys = Buffer.compare(dlcOffer.
|
|
1223
|
-
? [dlcOffer.
|
|
1224
|
-
: [dlcAccept.
|
|
1265
|
+
const fundingPubKeys = Buffer.compare(dlcOffer.fundingPubkey, dlcAccept.fundingPubkey) === -1
|
|
1266
|
+
? [dlcOffer.fundingPubkey, dlcAccept.fundingPubkey]
|
|
1267
|
+
: [dlcAccept.fundingPubkey, dlcOffer.fundingPubkey];
|
|
1225
1268
|
const p2ms = bitcoinjs_lib_1.payments.p2ms({
|
|
1226
1269
|
m: 2,
|
|
1227
1270
|
pubkeys: fundingPubKeys,
|
|
@@ -1231,7 +1274,7 @@ Payout Group not found');
|
|
|
1231
1274
|
redeem: p2ms,
|
|
1232
1275
|
network,
|
|
1233
1276
|
});
|
|
1234
|
-
const pubkey = isOfferer ? dlcAccept.
|
|
1277
|
+
const pubkey = isOfferer ? dlcAccept.fundingPubkey : dlcOffer.fundingPubkey;
|
|
1235
1278
|
const sigsValidity = [];
|
|
1236
1279
|
for (let i = 0; i < rawCloseTxs.length; i++) {
|
|
1237
1280
|
const rawTx = rawCloseTxs[i];
|
|
@@ -1270,10 +1313,10 @@ Payout Group not found');
|
|
|
1270
1313
|
_dlcAccept,
|
|
1271
1314
|
});
|
|
1272
1315
|
const network = await this.getConnectedNetwork();
|
|
1273
|
-
const offerFundingSPK = bitcoin_1.Script.p2wpkhLock((0, crypto_1.hash160)(dlcOffer.
|
|
1316
|
+
const offerFundingSPK = bitcoin_1.Script.p2wpkhLock((0, crypto_1.hash160)(dlcOffer.fundingPubkey))
|
|
1274
1317
|
.serialize()
|
|
1275
1318
|
.slice(1);
|
|
1276
|
-
const acceptFundingSPK = bitcoin_1.Script.p2wpkhLock((0, crypto_1.hash160)(dlcAccept.
|
|
1319
|
+
const acceptFundingSPK = bitcoin_1.Script.p2wpkhLock((0, crypto_1.hash160)(dlcAccept.fundingPubkey))
|
|
1277
1320
|
.serialize()
|
|
1278
1321
|
.slice(1);
|
|
1279
1322
|
const offerFundingAddress = bitcoinjs_lib_1.address.fromOutputScript(offerFundingSPK, network);
|
|
@@ -1302,9 +1345,11 @@ Payout Group not found');
|
|
|
1302
1345
|
async createDlcOffer(contractInfo, offerCollateralSatoshis, feeRatePerVb, cetLocktime, refundLocktime, fixedInputs) {
|
|
1303
1346
|
contractInfo.validate();
|
|
1304
1347
|
const network = await this.getConnectedNetwork();
|
|
1305
|
-
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);
|
|
1306
1351
|
const { fundingPubKey, payoutSPK, payoutSerialId, fundingInputs: _fundingInputs, changeSPK, changeSerialId, } = await this.Initialize(offerCollateralSatoshis, feeRatePerVb, fixedInputs);
|
|
1307
|
-
_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'));
|
|
1308
1353
|
const fundingInputs = _fundingInputs.map((input) => input);
|
|
1309
1354
|
fundingInputs.sort((a, b) => Number(a.inputSerialId) - Number(b.inputSerialId));
|
|
1310
1355
|
const fundOutputSerialId = (0, Utils_1.generateSerialId)();
|
|
@@ -1312,19 +1357,20 @@ Payout Group not found');
|
|
|
1312
1357
|
dlcOffer.contractFlags = Buffer.from('00', 'hex');
|
|
1313
1358
|
dlcOffer.chainHash = (0, bitcoin_networks_1.chainHashFromNetwork)(network);
|
|
1314
1359
|
dlcOffer.contractInfo = contractInfo;
|
|
1315
|
-
dlcOffer.
|
|
1316
|
-
dlcOffer.
|
|
1360
|
+
dlcOffer.fundingPubkey = fundingPubKey;
|
|
1361
|
+
dlcOffer.payoutSpk = payoutSPK;
|
|
1317
1362
|
dlcOffer.payoutSerialId = payoutSerialId;
|
|
1318
|
-
dlcOffer.
|
|
1363
|
+
dlcOffer.offerCollateral = offerCollateralSatoshis;
|
|
1319
1364
|
dlcOffer.fundingInputs = fundingInputs;
|
|
1320
|
-
dlcOffer.
|
|
1365
|
+
dlcOffer.changeSpk = changeSPK;
|
|
1321
1366
|
dlcOffer.changeSerialId = changeSerialId;
|
|
1322
|
-
dlcOffer.fundOutputSerialId = dlcOffer.fundOutputSerialId =
|
|
1367
|
+
dlcOffer.fundOutputSerialId = dlcOffer.fundOutputSerialId =
|
|
1368
|
+
fundOutputSerialId;
|
|
1323
1369
|
dlcOffer.feeRatePerVb = feeRatePerVb;
|
|
1324
1370
|
dlcOffer.cetLocktime = cetLocktime;
|
|
1325
1371
|
dlcOffer.refundLocktime = refundLocktime;
|
|
1326
1372
|
(0, assert_1.default)((() => {
|
|
1327
|
-
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);
|
|
1328
1374
|
const funding = fundingInputs.reduce((total, input) => {
|
|
1329
1375
|
return total + input.prevTx.outputs[input.prevTxVout].value.sats;
|
|
1330
1376
|
}, BigInt(0));
|
|
@@ -1344,7 +1390,7 @@ Payout Group not found');
|
|
|
1344
1390
|
}
|
|
1345
1391
|
const network = await this.getConnectedNetwork();
|
|
1346
1392
|
const { fundingInputs: _fundingInputs, changeSPK, changeSerialId, initializeResponses, } = await this.BatchInitialize(offerCollaterals, feeRatePerVb, fixedInputs);
|
|
1347
|
-
_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'));
|
|
1348
1394
|
const fundingInputs = _fundingInputs.map((input) => input);
|
|
1349
1395
|
fundingInputs.sort((a, b) => Number(a.inputSerialId) - Number(b.inputSerialId));
|
|
1350
1396
|
const fundOutputsSerialIds = (0, Utils_1.generateSerialIds)(contractInfos.length);
|
|
@@ -1354,23 +1400,25 @@ Payout Group not found');
|
|
|
1354
1400
|
const fundOutputSerialId = fundOutputsSerialIds[i];
|
|
1355
1401
|
const { fundingPubKey, payoutSPK, payoutSerialId } = initializeResponses[i];
|
|
1356
1402
|
const refundLocktime = refundLocktimes[i];
|
|
1357
|
-
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);
|
|
1358
1406
|
dlcOffer.contractFlags = Buffer.from('00', 'hex');
|
|
1359
1407
|
dlcOffer.chainHash = (0, bitcoin_networks_1.chainHashFromNetwork)(network);
|
|
1360
1408
|
dlcOffer.contractInfo = contractInfo;
|
|
1361
|
-
dlcOffer.
|
|
1362
|
-
dlcOffer.
|
|
1409
|
+
dlcOffer.fundingPubkey = fundingPubKey;
|
|
1410
|
+
dlcOffer.payoutSpk = payoutSPK;
|
|
1363
1411
|
dlcOffer.payoutSerialId = payoutSerialId;
|
|
1364
|
-
dlcOffer.
|
|
1412
|
+
dlcOffer.offerCollateral = offerCollateralSatoshis;
|
|
1365
1413
|
dlcOffer.fundingInputs = fundingInputs;
|
|
1366
|
-
dlcOffer.
|
|
1414
|
+
dlcOffer.changeSpk = changeSPK;
|
|
1367
1415
|
dlcOffer.changeSerialId = changeSerialId;
|
|
1368
1416
|
dlcOffer.fundOutputSerialId = fundOutputSerialId;
|
|
1369
1417
|
dlcOffer.feeRatePerVb = feeRatePerVb;
|
|
1370
1418
|
dlcOffer.cetLocktime = cetLocktime;
|
|
1371
1419
|
dlcOffer.refundLocktime = refundLocktime;
|
|
1372
1420
|
(0, assert_1.default)((() => {
|
|
1373
|
-
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);
|
|
1374
1422
|
const funding = fundingInputs.reduce((total, input) => {
|
|
1375
1423
|
return total + input.prevTx.outputs[input.prevTxVout].value.sats;
|
|
1376
1424
|
}, BigInt(0));
|
|
@@ -1390,23 +1438,22 @@ Payout Group not found');
|
|
|
1390
1438
|
async acceptDlcOffer(_dlcOffer, fixedInputs) {
|
|
1391
1439
|
const { dlcOffer } = (0, Utils_1.checkTypes)({ _dlcOffer });
|
|
1392
1440
|
dlcOffer.validate();
|
|
1393
|
-
const acceptCollateralSatoshis = dlcOffer.contractInfo.totalCollateral - dlcOffer.
|
|
1441
|
+
const acceptCollateralSatoshis = dlcOffer.contractInfo.totalCollateral - dlcOffer.offerCollateral;
|
|
1394
1442
|
(0, assert_1.default)(acceptCollateralSatoshis ===
|
|
1395
|
-
dlcOffer.contractInfo.totalCollateral -
|
|
1396
|
-
dlcOffer.offerCollateralSatoshis, 'acceptCollaterialSatoshis should equal totalCollateral - offerCollateralSatoshis');
|
|
1443
|
+
dlcOffer.contractInfo.totalCollateral - dlcOffer.offerCollateral, 'acceptCollaterialSatoshis should equal totalCollateral - offerCollateralSatoshis');
|
|
1397
1444
|
const { fundingPubKey, payoutSPK, payoutSerialId, fundingInputs: _fundingInputs, changeSPK, changeSerialId, } = await this.Initialize(acceptCollateralSatoshis, dlcOffer.feeRatePerVb, fixedInputs);
|
|
1398
|
-
(0, assert_1.default)(Buffer.compare(dlcOffer.
|
|
1399
|
-
_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'));
|
|
1400
1447
|
const fundingInputs = _fundingInputs.map((input) => input);
|
|
1401
1448
|
fundingInputs.sort((a, b) => Number(a.inputSerialId) - Number(b.inputSerialId));
|
|
1402
|
-
const dlcAccept = new messaging_1.
|
|
1403
|
-
dlcAccept.
|
|
1404
|
-
dlcAccept.
|
|
1405
|
-
dlcAccept.
|
|
1406
|
-
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;
|
|
1407
1454
|
dlcAccept.payoutSerialId = dlcAccept.payoutSerialId = payoutSerialId;
|
|
1408
1455
|
dlcAccept.fundingInputs = fundingInputs;
|
|
1409
|
-
dlcAccept.
|
|
1456
|
+
dlcAccept.changeSpk = changeSPK;
|
|
1410
1457
|
dlcAccept.changeSerialId = dlcAccept.changeSerialId = changeSerialId;
|
|
1411
1458
|
(0, assert_1.default)(dlcAccept.changeSerialId !== dlcOffer.fundOutputSerialId, 'changeSerialId cannot equal the fundOutputSerialId');
|
|
1412
1459
|
(0, assert_1.default)(dlcOffer.payoutSerialId !== dlcAccept.payoutSerialId, 'offer.payoutSerialId cannot equal accept.payoutSerialId');
|
|
@@ -1420,21 +1467,19 @@ Payout Group not found');
|
|
|
1420
1467
|
})(), 'offer.changeSerialID, accept.changeSerialId and fundOutputSerialId must be unique');
|
|
1421
1468
|
dlcAccept.validate();
|
|
1422
1469
|
(0, assert_1.default)((() => {
|
|
1423
|
-
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);
|
|
1424
1471
|
const funding = fundingInputs.reduce((total, input) => {
|
|
1425
1472
|
return total + input.prevTx.outputs[input.prevTxVout].value.sats;
|
|
1426
1473
|
}, BigInt(0));
|
|
1427
1474
|
return funding >= acceptCollateralSatoshis + finalizer.acceptFees;
|
|
1428
1475
|
})(), 'fundingInputs for dlcAccept must be greater than acceptCollateralSatoshis plus acceptFees');
|
|
1429
1476
|
const { dlcTransactions, messagesList } = await this.createDlcTxs(dlcOffer, dlcAccept);
|
|
1430
|
-
const { cetSignatures, refundSignature
|
|
1431
|
-
(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);
|
|
1432
1478
|
const _dlcTransactions = dlcTransactions;
|
|
1433
|
-
const contractId = (0, crypto_1.xor)(_dlcTransactions.fundTx.txId.serialize(), dlcAccept.
|
|
1479
|
+
const contractId = (0, crypto_1.xor)(_dlcTransactions.fundTx.txId.serialize(), dlcAccept.temporaryContractId);
|
|
1434
1480
|
_dlcTransactions.contractId = contractId;
|
|
1435
|
-
dlcAccept.
|
|
1481
|
+
dlcAccept.cetAdaptorSignatures = cetSignatures;
|
|
1436
1482
|
dlcAccept.refundSignature = refundSignature;
|
|
1437
|
-
dlcAccept.negotiationFields = new messaging_1.NegotiationFieldsV0();
|
|
1438
1483
|
return { dlcAccept, dlcTransactions: _dlcTransactions };
|
|
1439
1484
|
}
|
|
1440
1485
|
async batchAcceptDlcOffer(_dlcOffers, fixedInputs) {
|
|
@@ -1443,31 +1488,30 @@ Payout Group not found');
|
|
|
1443
1488
|
dlcOffer.validate();
|
|
1444
1489
|
return dlcOffer;
|
|
1445
1490
|
});
|
|
1446
|
-
const acceptCollaterals = dlcOffers.map((dlcOffer) => dlcOffer.contractInfo.totalCollateral -
|
|
1447
|
-
dlcOffer.offerCollateralSatoshis);
|
|
1491
|
+
const acceptCollaterals = dlcOffers.map((dlcOffer) => dlcOffer.contractInfo.totalCollateral - dlcOffer.offerCollateral);
|
|
1448
1492
|
const { fundingInputs: _fundingInputs, changeSPK, changeSerialId, initializeResponses, } = await this.BatchInitialize(acceptCollaterals, dlcOffers[0].feeRatePerVb, fixedInputs);
|
|
1449
1493
|
// Check that none of the funding pubkeys are the same between the
|
|
1450
1494
|
// dlcOffers and the dlcAccepts (from initializeResponses)
|
|
1451
1495
|
dlcOffers.forEach((dlcOffer) => {
|
|
1452
1496
|
initializeResponses.forEach((initializeResponse) => {
|
|
1453
|
-
(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');
|
|
1454
1498
|
});
|
|
1455
1499
|
});
|
|
1456
|
-
_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'));
|
|
1457
1501
|
const fundingInputs = _fundingInputs.map((input) => input);
|
|
1458
1502
|
fundingInputs.sort((a, b) => Number(a.inputSerialId) - Number(b.inputSerialId));
|
|
1459
1503
|
const dlcAccepts = [];
|
|
1460
1504
|
initializeResponses.forEach((initializeResponse, i) => {
|
|
1461
1505
|
const dlcOffer = dlcOffers[i];
|
|
1462
|
-
const dlcAccept = new messaging_1.
|
|
1506
|
+
const dlcAccept = new messaging_1.DlcAccept();
|
|
1463
1507
|
const { fundingPubKey, payoutSPK, payoutSerialId } = initializeResponse;
|
|
1464
|
-
dlcAccept.
|
|
1465
|
-
dlcAccept.
|
|
1466
|
-
dlcAccept.
|
|
1467
|
-
dlcAccept.
|
|
1508
|
+
dlcAccept.temporaryContractId = (0, crypto_1.sha256)(dlcOffers[i].serialize());
|
|
1509
|
+
dlcAccept.acceptCollateral = acceptCollaterals[i];
|
|
1510
|
+
dlcAccept.fundingPubkey = fundingPubKey;
|
|
1511
|
+
dlcAccept.payoutSpk = payoutSPK;
|
|
1468
1512
|
dlcAccept.payoutSerialId = payoutSerialId;
|
|
1469
1513
|
dlcAccept.fundingInputs = fundingInputs;
|
|
1470
|
-
dlcAccept.
|
|
1514
|
+
dlcAccept.changeSpk = changeSPK;
|
|
1471
1515
|
dlcAccept.changeSerialId = changeSerialId;
|
|
1472
1516
|
(0, assert_1.default)(dlcAccept.changeSerialId !== dlcOffer.fundOutputSerialId, 'changeSerialId cannot equal the fundOutputSerialId');
|
|
1473
1517
|
(0, assert_1.default)(dlcOffer.payoutSerialId !== dlcAccept.payoutSerialId, 'offer.payoutSerialId cannot equal accept.payoutSerialId');
|
|
@@ -1481,7 +1525,7 @@ Payout Group not found');
|
|
|
1481
1525
|
})(), 'offer.changeSerialID, accept.changeSerialId and fundOutputSerialId must be unique');
|
|
1482
1526
|
dlcAccept.validate();
|
|
1483
1527
|
(0, assert_1.default)((() => {
|
|
1484
|
-
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);
|
|
1485
1529
|
const funding = fundingInputs.reduce((total, input) => {
|
|
1486
1530
|
return total + input.prevTx.outputs[input.prevTxVout].value.sats;
|
|
1487
1531
|
}, BigInt(0));
|
|
@@ -1489,20 +1533,18 @@ Payout Group not found');
|
|
|
1489
1533
|
})(), 'fundingInputs for dlcAccept must be greater than acceptCollateralSatoshis plus acceptFees');
|
|
1490
1534
|
dlcAccepts.push(dlcAccept);
|
|
1491
1535
|
});
|
|
1492
|
-
const { dlcTransactionsList, nestedMessagesList
|
|
1536
|
+
const { dlcTransactionsList, nestedMessagesList } = await this.createBatchDlcTxs(dlcOffers, dlcAccepts);
|
|
1493
1537
|
for (let i = 0; i < dlcAccepts.length; i++) {
|
|
1494
1538
|
const dlcOffer = dlcOffers[i];
|
|
1495
1539
|
const dlcAccept = dlcAccepts[i];
|
|
1496
1540
|
const dlcTransactions = dlcTransactionsList[i];
|
|
1497
1541
|
const messagesList = nestedMessagesList[i];
|
|
1498
|
-
const { cetSignatures, refundSignature
|
|
1499
|
-
(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);
|
|
1500
1543
|
const _dlcTransactions = dlcTransactions;
|
|
1501
|
-
const contractId = (0, crypto_1.xor)(_dlcTransactions.fundTx.txId.serialize(), dlcAccept.
|
|
1544
|
+
const contractId = (0, crypto_1.xor)(_dlcTransactions.fundTx.txId.serialize(), dlcAccept.temporaryContractId);
|
|
1502
1545
|
_dlcTransactions.contractId = contractId;
|
|
1503
|
-
dlcAccepts[i].
|
|
1546
|
+
dlcAccepts[i].cetAdaptorSignatures = cetSignatures;
|
|
1504
1547
|
dlcAccepts[i].refundSignature = refundSignature;
|
|
1505
|
-
dlcAccepts[i].negotiationFields = new messaging_1.NegotiationFieldsV0();
|
|
1506
1548
|
}
|
|
1507
1549
|
return { dlcAccepts, dlcTransactionsList };
|
|
1508
1550
|
}
|
|
@@ -1519,18 +1561,18 @@ Payout Group not found');
|
|
|
1519
1561
|
});
|
|
1520
1562
|
dlcOffer.validate();
|
|
1521
1563
|
dlcAccept.validate();
|
|
1522
|
-
(0, assert_1.default)(Buffer.compare(dlcOffer.
|
|
1523
|
-
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();
|
|
1524
1566
|
const { dlcTransactions, messagesList } = await this.createDlcTxs(dlcOffer, dlcAccept);
|
|
1525
1567
|
await this.VerifyCetAdaptorAndRefundSigs(dlcOffer, dlcAccept, dlcSign, dlcTransactions, messagesList, true);
|
|
1526
|
-
const { cetSignatures, refundSignature
|
|
1568
|
+
const { cetSignatures, refundSignature } = await this.CreateCetAdaptorAndRefundSigs(dlcOffer, dlcAccept, dlcTransactions, messagesList, true);
|
|
1527
1569
|
const fundingSignatures = await this.CreateFundingSigs(dlcOffer, dlcAccept, dlcTransactions, true);
|
|
1528
1570
|
const dlcTxs = dlcTransactions;
|
|
1529
|
-
const contractId = (0, crypto_1.xor)(dlcTxs.fundTx.txId.serialize(), dlcAccept.
|
|
1530
|
-
(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');
|
|
1531
1573
|
dlcTxs.contractId = contractId;
|
|
1532
1574
|
dlcSign.contractId = contractId;
|
|
1533
|
-
dlcSign.
|
|
1575
|
+
dlcSign.cetAdaptorSignatures = cetSignatures;
|
|
1534
1576
|
dlcSign.refundSignature = refundSignature;
|
|
1535
1577
|
dlcSign.fundingSignatures = fundingSignatures;
|
|
1536
1578
|
return { dlcSign, dlcTransactions: dlcTxs };
|
|
@@ -1546,7 +1588,7 @@ Payout Group not found');
|
|
|
1546
1588
|
dlcAccept.validate();
|
|
1547
1589
|
return dlcAccept;
|
|
1548
1590
|
});
|
|
1549
|
-
const { dlcTransactionsList, nestedMessagesList
|
|
1591
|
+
const { dlcTransactionsList, nestedMessagesList } = await this.createBatchDlcTxs(dlcOffers, dlcAccepts);
|
|
1550
1592
|
const dlcSigns = [];
|
|
1551
1593
|
const fundingSignatures = await this.CreateFundingSigs(dlcOffers[0], dlcAccepts[0], dlcTransactionsList[0], true);
|
|
1552
1594
|
for (let i = 0; i < dlcAccepts.length; i++) {
|
|
@@ -1554,14 +1596,14 @@ Payout Group not found');
|
|
|
1554
1596
|
const dlcAccept = dlcAccepts[i];
|
|
1555
1597
|
const dlcTransactions = dlcTransactionsList[i];
|
|
1556
1598
|
const messagesList = nestedMessagesList[i];
|
|
1557
|
-
const dlcSign = new messaging_1.
|
|
1599
|
+
const dlcSign = new messaging_1.DlcSign();
|
|
1558
1600
|
await this.VerifyCetAdaptorAndRefundSigs(dlcOffer, dlcAccept, dlcSign, dlcTransactions, messagesList, true);
|
|
1559
|
-
const { cetSignatures, refundSignature
|
|
1601
|
+
const { cetSignatures, refundSignature } = await this.CreateCetAdaptorAndRefundSigs(dlcOffer, dlcAccept, dlcTransactions, messagesList, true);
|
|
1560
1602
|
const dlcTxs = dlcTransactions;
|
|
1561
|
-
const contractId = (0, crypto_1.xor)(dlcTxs.fundTx.txId.serialize(), dlcAccept.
|
|
1603
|
+
const contractId = (0, crypto_1.xor)(dlcTxs.fundTx.txId.serialize(), dlcAccept.temporaryContractId);
|
|
1562
1604
|
dlcTxs.contractId = contractId;
|
|
1563
1605
|
dlcSign.contractId = contractId;
|
|
1564
|
-
dlcSign.
|
|
1606
|
+
dlcSign.cetAdaptorSignatures = cetSignatures;
|
|
1565
1607
|
dlcSign.refundSignature = refundSignature;
|
|
1566
1608
|
dlcSign.fundingSignatures = fundingSignatures;
|
|
1567
1609
|
dlcSigns.push(dlcSign);
|
|
@@ -1570,26 +1612,20 @@ Payout Group not found');
|
|
|
1570
1612
|
}
|
|
1571
1613
|
/**
|
|
1572
1614
|
* Finalize Dlc Sign
|
|
1573
|
-
* @param
|
|
1574
|
-
* @param
|
|
1575
|
-
* @param
|
|
1576
|
-
* @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
|
|
1577
1619
|
* @returns {Promise<Tx>}
|
|
1578
1620
|
*/
|
|
1579
|
-
async finalizeDlcSign(
|
|
1580
|
-
const { dlcOffer, dlcAccept, dlcSign, dlcTxs } = (0, Utils_1.checkTypes)({
|
|
1581
|
-
_dlcOffer,
|
|
1582
|
-
_dlcAccept,
|
|
1583
|
-
_dlcSign,
|
|
1584
|
-
_dlcTxs,
|
|
1585
|
-
});
|
|
1621
|
+
async finalizeDlcSign(dlcOffer, dlcAccept, dlcSign, dlcTxs) {
|
|
1586
1622
|
let messagesList = [];
|
|
1587
|
-
if (dlcOffer.contractInfo.type === messaging_1.MessageType.
|
|
1623
|
+
if (dlcOffer.contractInfo.type === messaging_1.MessageType.SingleContractInfo &&
|
|
1588
1624
|
dlcOffer.contractInfo.contractDescriptor.type ===
|
|
1589
|
-
messaging_1.MessageType.
|
|
1625
|
+
messaging_1.MessageType.SingleContractInfo) {
|
|
1590
1626
|
for (const outcome of dlcOffer.contractInfo
|
|
1591
1627
|
.contractDescriptor.outcomes) {
|
|
1592
|
-
messagesList.push({ messages: [outcome.outcome
|
|
1628
|
+
messagesList.push({ messages: [outcome.outcome] });
|
|
1593
1629
|
}
|
|
1594
1630
|
}
|
|
1595
1631
|
else {
|
|
@@ -1646,13 +1682,7 @@ Payout Group not found');
|
|
|
1646
1682
|
* @param isOfferer Whether party is Dlc Offerer
|
|
1647
1683
|
* @returns {Promise<Tx>}
|
|
1648
1684
|
*/
|
|
1649
|
-
async execute(
|
|
1650
|
-
const { dlcOffer, dlcAccept, dlcSign, dlcTxs } = (0, Utils_1.checkTypes)({
|
|
1651
|
-
_dlcOffer,
|
|
1652
|
-
_dlcAccept,
|
|
1653
|
-
_dlcSign,
|
|
1654
|
-
_dlcTxs,
|
|
1655
|
-
});
|
|
1685
|
+
async execute(dlcOffer, dlcAccept, dlcSign, dlcTxs, oracleAttestation, isOfferer) {
|
|
1656
1686
|
if (isOfferer === undefined)
|
|
1657
1687
|
isOfferer = await this.isOfferer(dlcOffer, dlcAccept);
|
|
1658
1688
|
this.ValidateEvent(dlcOffer, oracleAttestation);
|
|
@@ -1673,7 +1703,7 @@ Payout Group not found');
|
|
|
1673
1703
|
_dlcSign,
|
|
1674
1704
|
_dlcTxs,
|
|
1675
1705
|
});
|
|
1676
|
-
const signatures = Buffer.compare(dlcOffer.
|
|
1706
|
+
const signatures = Buffer.compare(dlcOffer.fundingPubkey, dlcAccept.fundingPubkey) === -1
|
|
1677
1707
|
? [
|
|
1678
1708
|
dlcSign.refundSignature.toString('hex'),
|
|
1679
1709
|
dlcAccept.refundSignature.toString('hex'),
|
|
@@ -1687,8 +1717,8 @@ Payout Group not found');
|
|
|
1687
1717
|
signatures,
|
|
1688
1718
|
fundTxId: dlcTxs.fundTx.txId.toString(),
|
|
1689
1719
|
fundVout: dlcTxs.fundTxVout,
|
|
1690
|
-
localFundPubkey: dlcOffer.
|
|
1691
|
-
remoteFundPubkey: dlcAccept.
|
|
1720
|
+
localFundPubkey: dlcOffer.fundingPubkey.toString('hex'),
|
|
1721
|
+
remoteFundPubkey: dlcAccept.fundingPubkey.toString('hex'),
|
|
1692
1722
|
};
|
|
1693
1723
|
const refundHex = (await this.AddSignaturesToRefundTx(addSigsToRefundTxRequest)).hex;
|
|
1694
1724
|
return bitcoin_1.Tx.decode(bufio_1.StreamReader.fromHex(refundHex));
|
|
@@ -1719,9 +1749,9 @@ Payout Group not found');
|
|
|
1719
1749
|
isOfferer = await this.isOfferer(dlcOffer, dlcAccept);
|
|
1720
1750
|
const network = await this.getConnectedNetwork();
|
|
1721
1751
|
const psbt = new bitcoinjs_lib_1.Psbt({ network });
|
|
1722
|
-
const fundingPubKeys = Buffer.compare(dlcOffer.
|
|
1723
|
-
? [dlcOffer.
|
|
1724
|
-
: [dlcAccept.
|
|
1752
|
+
const fundingPubKeys = Buffer.compare(dlcOffer.fundingPubkey, dlcAccept.fundingPubkey) === -1
|
|
1753
|
+
? [dlcOffer.fundingPubkey, dlcAccept.fundingPubkey]
|
|
1754
|
+
: [dlcAccept.fundingPubkey, dlcOffer.fundingPubkey];
|
|
1725
1755
|
const p2ms = bitcoinjs_lib_1.payments.p2ms({
|
|
1726
1756
|
m: 2,
|
|
1727
1757
|
pubkeys: fundingPubKeys,
|
|
@@ -1791,7 +1821,7 @@ Payout Group not found');
|
|
|
1791
1821
|
const fundingInputs = await Promise.all(inputs.map(async (input) => {
|
|
1792
1822
|
return this.inputToFundingInput(input);
|
|
1793
1823
|
}));
|
|
1794
|
-
const finalizer = new core_1.DualClosingTxFinalizer(fundingInputs, dlcOffer.
|
|
1824
|
+
const finalizer = new core_1.DualClosingTxFinalizer(fundingInputs, dlcOffer.payoutSpk, dlcAccept.payoutSpk, dlcOffer.feeRatePerVb);
|
|
1795
1825
|
const closeInputAmount = BigInt(inputs.reduce((acc, val) => acc + val.value, 0));
|
|
1796
1826
|
const offerPayoutValue = isOfferer
|
|
1797
1827
|
? closeInputAmount +
|
|
@@ -1806,11 +1836,11 @@ Payout Group not found');
|
|
|
1806
1836
|
const offerFirst = dlcOffer.payoutSerialId < dlcAccept.payoutSerialId;
|
|
1807
1837
|
psbt.addOutput({
|
|
1808
1838
|
value: Number(offerFirst ? offerPayoutValue : acceptPayoutValue),
|
|
1809
|
-
address: bitcoinjs_lib_1.address.fromOutputScript(offerFirst ? dlcOffer.
|
|
1839
|
+
address: bitcoinjs_lib_1.address.fromOutputScript(offerFirst ? dlcOffer.payoutSpk : dlcAccept.payoutSpk, network),
|
|
1810
1840
|
});
|
|
1811
1841
|
psbt.addOutput({
|
|
1812
1842
|
value: Number(offerFirst ? acceptPayoutValue : offerPayoutValue),
|
|
1813
|
-
address: bitcoinjs_lib_1.address.fromOutputScript(offerFirst ? dlcAccept.
|
|
1843
|
+
address: bitcoinjs_lib_1.address.fromOutputScript(offerFirst ? dlcAccept.payoutSpk : dlcOffer.payoutSpk, network),
|
|
1814
1844
|
});
|
|
1815
1845
|
// Generate keypair to sign inputs
|
|
1816
1846
|
const fundPrivateKeyPair = await this.GetFundKeyPair(dlcOffer, dlcAccept, isOfferer);
|
|
@@ -1843,10 +1873,10 @@ Payout Group not found');
|
|
|
1843
1873
|
pubKeyWitness.witness = inputSigs[i].pubkey;
|
|
1844
1874
|
witnessElements.push([sigWitness, pubKeyWitness]);
|
|
1845
1875
|
}
|
|
1846
|
-
const fundingSignatures = new messaging_1.
|
|
1876
|
+
const fundingSignatures = new messaging_1.FundingSignatures();
|
|
1847
1877
|
fundingSignatures.witnessElements = witnessElements;
|
|
1848
1878
|
// Create DlcClose
|
|
1849
|
-
const dlcClose = new messaging_1.
|
|
1879
|
+
const dlcClose = new messaging_1.DlcClose();
|
|
1850
1880
|
dlcClose.contractId = dlcTxs.contractId;
|
|
1851
1881
|
dlcClose.offerPayoutSatoshis = BigInt(psbt.txOutputs[offerFirst ? 0 : 1].value); // You give collateral back to users
|
|
1852
1882
|
dlcClose.acceptPayoutSatoshis = BigInt(psbt.txOutputs[offerFirst ? 1 : 0].value); // give collateral back to users
|
|
@@ -1879,7 +1909,7 @@ Payout Group not found');
|
|
|
1879
1909
|
throw Error('funding inputs not supported on BatchDlcClose'); // TODO support multiple funding inputs
|
|
1880
1910
|
const fundingInputSerialId = (0, Utils_1.generateSerialId)();
|
|
1881
1911
|
const fundingInputs = []; // TODO: support multiple funding inputs
|
|
1882
|
-
const finalizer = new core_1.DualClosingTxFinalizer(fundingInputs, dlcOffer.
|
|
1912
|
+
const finalizer = new core_1.DualClosingTxFinalizer(fundingInputs, dlcOffer.payoutSpk, dlcAccept.payoutSpk, dlcOffer.feeRatePerVb);
|
|
1883
1913
|
// Generate keypair to sign inputs
|
|
1884
1914
|
const fundPrivateKeyPair = await this.GetFundKeyPair(dlcOffer, dlcAccept, isOfferer);
|
|
1885
1915
|
const closeInputAmount = BigInt(0); // TODO support multiple funding inputs
|
|
@@ -1902,8 +1932,8 @@ Payout Group not found');
|
|
|
1902
1932
|
const acceptPayoutValue = isOfferer
|
|
1903
1933
|
? collateralMinusPayout
|
|
1904
1934
|
: closeInputAmount + payoutMinusOfferFees;
|
|
1905
|
-
const fundingSignatures = new messaging_1.
|
|
1906
|
-
const dlcClose = new messaging_1.
|
|
1935
|
+
const fundingSignatures = new messaging_1.FundingSignatures();
|
|
1936
|
+
const dlcClose = new messaging_1.DlcClose();
|
|
1907
1937
|
dlcClose.contractId = dlcTxs.contractId;
|
|
1908
1938
|
dlcClose.offerPayoutSatoshis = offerPayoutValue;
|
|
1909
1939
|
dlcClose.acceptPayoutSatoshis = acceptPayoutValue;
|
|
@@ -1970,9 +2000,9 @@ Payout Group not found');
|
|
|
1970
2000
|
dlcClose.validate();
|
|
1971
2001
|
const network = await this.getConnectedNetwork();
|
|
1972
2002
|
const psbt = new bitcoinjs_lib_1.Psbt({ network });
|
|
1973
|
-
const fundingPubKeys = Buffer.compare(dlcOffer.
|
|
1974
|
-
? [dlcOffer.
|
|
1975
|
-
: [dlcAccept.
|
|
2003
|
+
const fundingPubKeys = Buffer.compare(dlcOffer.fundingPubkey, dlcAccept.fundingPubkey) === -1
|
|
2004
|
+
? [dlcOffer.fundingPubkey, dlcAccept.fundingPubkey]
|
|
2005
|
+
: [dlcAccept.fundingPubkey, dlcOffer.fundingPubkey];
|
|
1976
2006
|
const p2ms = bitcoinjs_lib_1.payments.p2ms({
|
|
1977
2007
|
m: 2,
|
|
1978
2008
|
pubkeys: fundingPubKeys,
|
|
@@ -2023,13 +2053,13 @@ Payout Group not found');
|
|
|
2023
2053
|
value: Number(offerFirst
|
|
2024
2054
|
? dlcClose.offerPayoutSatoshis
|
|
2025
2055
|
: dlcClose.acceptPayoutSatoshis),
|
|
2026
|
-
address: bitcoinjs_lib_1.address.fromOutputScript(offerFirst ? dlcOffer.
|
|
2056
|
+
address: bitcoinjs_lib_1.address.fromOutputScript(offerFirst ? dlcOffer.payoutSpk : dlcAccept.payoutSpk, network),
|
|
2027
2057
|
});
|
|
2028
2058
|
psbt.addOutput({
|
|
2029
2059
|
value: Number(offerFirst
|
|
2030
2060
|
? dlcClose.acceptPayoutSatoshis
|
|
2031
2061
|
: dlcClose.offerPayoutSatoshis),
|
|
2032
|
-
address: bitcoinjs_lib_1.address.fromOutputScript(offerFirst ? dlcAccept.
|
|
2062
|
+
address: bitcoinjs_lib_1.address.fromOutputScript(offerFirst ? dlcAccept.payoutSpk : dlcOffer.payoutSpk, network),
|
|
2033
2063
|
});
|
|
2034
2064
|
// add to psbt
|
|
2035
2065
|
sortedPsbtInputs.forEach((input, i) => psbt.addInput(input));
|
|
@@ -2040,7 +2070,7 @@ Payout Group not found');
|
|
|
2040
2070
|
psbt.signInput(fundingInputIndex, fundPrivateKeyPair);
|
|
2041
2071
|
const partialSig = [
|
|
2042
2072
|
{
|
|
2043
|
-
pubkey: offerer ? dlcAccept.
|
|
2073
|
+
pubkey: offerer ? dlcAccept.fundingPubkey : dlcOffer.fundingPubkey,
|
|
2044
2074
|
signature: await bitcoinjs_lib_1.script.signature.encode(dlcClose.closeSignature, 1), // encode using SIGHASH_ALL
|
|
2045
2075
|
},
|
|
2046
2076
|
];
|
|
@@ -2138,7 +2168,7 @@ Payout Group not found');
|
|
|
2138
2168
|
return this._cfdDlcJs.VerifyRefundTxSignature(jsonObject);
|
|
2139
2169
|
}
|
|
2140
2170
|
async fundingInputToInput(_input, findDerivationPath = true) {
|
|
2141
|
-
(0, assert_1.default)(_input.type === messaging_1.MessageType.
|
|
2171
|
+
(0, assert_1.default)(_input.type === messaging_1.MessageType.FundingInput, 'FundingInput must be V0');
|
|
2142
2172
|
const network = await this.getConnectedNetwork();
|
|
2143
2173
|
const input = _input;
|
|
2144
2174
|
const prevTx = input.prevTx;
|
|
@@ -2171,7 +2201,7 @@ Payout Group not found');
|
|
|
2171
2201
|
};
|
|
2172
2202
|
}
|
|
2173
2203
|
async inputToFundingInput(input) {
|
|
2174
|
-
const fundingInput = new messaging_1.
|
|
2204
|
+
const fundingInput = new messaging_1.FundingInput();
|
|
2175
2205
|
fundingInput.prevTxVout = input.vout;
|
|
2176
2206
|
let txRaw = '';
|
|
2177
2207
|
try {
|