@atomicfinance/bitcoin-wallet-provider 4.2.8 → 4.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +1 -1
- package/.turbo/turbo-lint$colon$fix.log +4 -0
- package/.turbo/turbo-lint.log +5 -0
- package/.turbo/turbo-test.log +0 -0
- package/.yalc/@node-dlc/core/.nyc_output/687a3c14-9765-45fd-a1fe-f7db3d56fee4.json +1 -0
- package/.yalc/@node-dlc/core/.nyc_output/processinfo/687a3c14-9765-45fd-a1fe-f7db3d56fee4.json +1 -0
- package/.yalc/@node-dlc/core/.nyc_output/processinfo/index.json +1 -0
- package/.yalc/@node-dlc/core/README.md +11 -0
- package/.yalc/@node-dlc/core/__tests__/core.spec.ts +7 -0
- package/.yalc/@node-dlc/core/__tests__/dlc/CETCalculator.spec.ts +1029 -0
- package/.yalc/@node-dlc/core/__tests__/dlc/CoinSelect.spec.ts +179 -0
- package/.yalc/@node-dlc/core/__tests__/dlc/PolynomialPayoutCurve.spec.ts +345 -0
- package/.yalc/@node-dlc/core/__tests__/dlc/TxBuilder.spec.ts +424 -0
- package/.yalc/@node-dlc/core/__tests__/dlc/finance/Builder.spec.ts +492 -0
- package/.yalc/@node-dlc/core/__tests__/dlc/finance/CoveredCall.spec.ts +112 -0
- package/.yalc/@node-dlc/core/__tests__/dlc/finance/CsoInfo.spec.ts +1124 -0
- package/.yalc/@node-dlc/core/__tests__/dlc/finance/LongCall.spec.ts +55 -0
- package/.yalc/@node-dlc/core/__tests__/dlc/finance/LongPut.spec.ts +55 -0
- package/.yalc/@node-dlc/core/__tests__/dlc/finance/OptionInfo.spec.ts +226 -0
- package/.yalc/@node-dlc/core/__tests__/dlc/finance/ShortPut.spec.ts +62 -0
- package/.yalc/@node-dlc/core/__tests__/tsconfig.json +8 -0
- package/.yalc/@node-dlc/core/__tests__/utils/precision.spec.ts +40 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/base.css +224 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/block-navigation.js +79 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/favicon.png +0 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/index.html +171 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/AsyncProcessingQueue.ts.html +269 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/Base32.ts.html +86 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/BigIntUtils.ts.html +86 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/BitField.ts.html +86 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/ChannelId.ts.html +86 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/LinkedList.ts.html +413 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/LinkedListNode.ts.html +122 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/Queue.ts.html +188 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/ShortChannelId.ts.html +86 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/ShortChannelIdUtils.ts.html +107 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/CETCalculator.ts.html +1430 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/CoinSelect.ts.html +431 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/HyperbolaPayoutCurve.ts.html +644 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/PolynomialPayoutCurve.ts.html +878 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/TxBuilder.ts.html +1088 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/TxFinalizer.ts.html +731 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/Builder.ts.html +2270 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/CoveredCall.ts.html +410 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/CsoInfo.ts.html +1574 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/LinearPayout.ts.html +362 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/LongCall.ts.html +302 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/LongPut.ts.html +302 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/OptionInfo.ts.html +626 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/ShortPut.ts.html +305 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/finance/index.html +216 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/dlc/index.html +186 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/index.html +261 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/index.ts.html +278 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/ChannelId.ts.html +242 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/ChannelKeys.ts.html +407 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/CommitmentNumber.ts.html +362 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/CommitmentSecret.ts.html +203 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/CommitmentSecretStore.ts.html +332 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/Htlc.ts.html +236 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/HtlcDirection.ts.html +131 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/ScriptFactory.ts.html +530 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/TxFactory.ts.html +1094 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/lightning/index.html +231 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/utils/BigIntUtils.ts.html +272 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/utils/Precision.ts.html +149 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/lib/utils/index.html +126 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/prettify.css +1 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/prettify.js +2 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/.yalc/@node-dlc/core/coverage/lcov-report/sorter.js +170 -0
- package/.yalc/@node-dlc/core/coverage/lcov.info +2426 -0
- package/.yalc/@node-dlc/core/dist/AsyncProcessingQueue.d.ts +22 -0
- package/.yalc/@node-dlc/core/dist/AsyncProcessingQueue.js +55 -0
- package/.yalc/@node-dlc/core/dist/AsyncProcessingQueue.js.map +1 -0
- package/.yalc/@node-dlc/core/dist/Base32.d.ts +1 -0
- package/.yalc/@node-dlc/core/dist/Base32.js +7 -0
- package/.yalc/@node-dlc/core/dist/Base32.js.map +1 -0
- package/.yalc/@node-dlc/core/dist/BigIntUtils.d.ts +1 -0
- package/.yalc/@node-dlc/core/dist/BigIntUtils.js +8 -0
- package/.yalc/@node-dlc/core/dist/BigIntUtils.js.map +1 -0
- package/.yalc/@node-dlc/core/dist/BitField.d.ts +1 -0
- package/.yalc/@node-dlc/core/dist/BitField.js +7 -0
- package/.yalc/@node-dlc/core/dist/BitField.js.map +1 -0
- package/.yalc/@node-dlc/core/dist/ChannelId.d.ts +1 -0
- package/.yalc/@node-dlc/core/dist/ChannelId.js +7 -0
- package/.yalc/@node-dlc/core/dist/ChannelId.js.map +1 -0
- package/.yalc/@node-dlc/core/dist/LinkedList.d.ts +30 -0
- package/.yalc/@node-dlc/core/dist/LinkedList.js +104 -0
- package/.yalc/@node-dlc/core/dist/LinkedList.js.map +1 -0
- package/.yalc/@node-dlc/core/dist/LinkedListNode.d.ts +9 -0
- package/.yalc/@node-dlc/core/dist/LinkedListNode.js +15 -0
- package/.yalc/@node-dlc/core/dist/LinkedListNode.js.map +1 -0
- package/.yalc/@node-dlc/core/dist/Queue.d.ts +22 -0
- package/.yalc/@node-dlc/core/dist/Queue.js +38 -0
- package/.yalc/@node-dlc/core/dist/Queue.js.map +1 -0
- package/.yalc/@node-dlc/core/dist/ShortChannelId.d.ts +1 -0
- package/.yalc/@node-dlc/core/dist/ShortChannelId.js +7 -0
- package/.yalc/@node-dlc/core/dist/ShortChannelId.js.map +1 -0
- package/.yalc/@node-dlc/core/dist/ShortChannelIdUtils.d.ts +1 -0
- package/.yalc/@node-dlc/core/dist/ShortChannelIdUtils.js +12 -0
- package/.yalc/@node-dlc/core/dist/ShortChannelIdUtils.js.map +1 -0
- package/.yalc/@node-dlc/core/dist/dlc/CETCalculator.d.ts +50 -0
- package/.yalc/@node-dlc/core/dist/dlc/CETCalculator.js +332 -0
- package/.yalc/@node-dlc/core/dist/dlc/CETCalculator.js.map +1 -0
- package/.yalc/@node-dlc/core/dist/dlc/CoinSelect.d.ts +23 -0
- package/.yalc/@node-dlc/core/dist/dlc/CoinSelect.js +77 -0
- package/.yalc/@node-dlc/core/dist/dlc/CoinSelect.js.map +1 -0
- package/.yalc/@node-dlc/core/dist/dlc/HyperbolaPayoutCurve.d.ts +20 -0
- package/.yalc/@node-dlc/core/dist/dlc/HyperbolaPayoutCurve.js +117 -0
- package/.yalc/@node-dlc/core/dist/dlc/HyperbolaPayoutCurve.js.map +1 -0
- package/.yalc/@node-dlc/core/dist/dlc/PayoutCurve.d.ts +5 -0
- package/.yalc/@node-dlc/core/dist/dlc/PayoutCurve.js +3 -0
- package/.yalc/@node-dlc/core/dist/dlc/PayoutCurve.js.map +1 -0
- package/.yalc/@node-dlc/core/dist/dlc/PolynomialPayoutCurve.d.ts +52 -0
- package/.yalc/@node-dlc/core/dist/dlc/PolynomialPayoutCurve.js +173 -0
- package/.yalc/@node-dlc/core/dist/dlc/PolynomialPayoutCurve.js.map +1 -0
- package/.yalc/@node-dlc/core/dist/dlc/TxBuilder.d.ts +55 -0
- package/.yalc/@node-dlc/core/dist/dlc/TxBuilder.js +217 -0
- package/.yalc/@node-dlc/core/dist/dlc/TxBuilder.js.map +1 -0
- package/.yalc/@node-dlc/core/dist/dlc/TxFinalizer.d.ts +40 -0
- package/.yalc/@node-dlc/core/dist/dlc/TxFinalizer.js +146 -0
- package/.yalc/@node-dlc/core/dist/dlc/TxFinalizer.js.map +1 -0
- package/.yalc/@node-dlc/core/dist/dlc/finance/Builder.d.ts +193 -0
- package/.yalc/@node-dlc/core/dist/dlc/finance/Builder.js +422 -0
- package/.yalc/@node-dlc/core/dist/dlc/finance/Builder.js.map +1 -0
- package/.yalc/@node-dlc/core/dist/dlc/finance/CoveredCall.d.ts +13 -0
- package/.yalc/@node-dlc/core/dist/dlc/finance/CoveredCall.js +67 -0
- package/.yalc/@node-dlc/core/dist/dlc/finance/CoveredCall.js.map +1 -0
- package/.yalc/@node-dlc/core/dist/dlc/finance/CsoInfo.d.ts +114 -0
- package/.yalc/@node-dlc/core/dist/dlc/finance/CsoInfo.js +290 -0
- package/.yalc/@node-dlc/core/dist/dlc/finance/CsoInfo.js.map +1 -0
- package/.yalc/@node-dlc/core/dist/dlc/finance/LinearPayout.d.ts +6 -0
- package/.yalc/@node-dlc/core/dist/dlc/finance/LinearPayout.js +79 -0
- package/.yalc/@node-dlc/core/dist/dlc/finance/LinearPayout.js.map +1 -0
- package/.yalc/@node-dlc/core/dist/dlc/finance/LongCall.d.ts +13 -0
- package/.yalc/@node-dlc/core/dist/dlc/finance/LongCall.js +47 -0
- package/.yalc/@node-dlc/core/dist/dlc/finance/LongCall.js.map +1 -0
- package/.yalc/@node-dlc/core/dist/dlc/finance/LongPut.d.ts +13 -0
- package/.yalc/@node-dlc/core/dist/dlc/finance/LongPut.js +47 -0
- package/.yalc/@node-dlc/core/dist/dlc/finance/LongPut.js.map +1 -0
- package/.yalc/@node-dlc/core/dist/dlc/finance/OptionInfo.d.ts +20 -0
- package/.yalc/@node-dlc/core/dist/dlc/finance/OptionInfo.js +101 -0
- package/.yalc/@node-dlc/core/dist/dlc/finance/OptionInfo.js.map +1 -0
- package/.yalc/@node-dlc/core/dist/dlc/finance/ShortPut.d.ts +12 -0
- package/.yalc/@node-dlc/core/dist/dlc/finance/ShortPut.js +46 -0
- package/.yalc/@node-dlc/core/dist/dlc/finance/ShortPut.js.map +1 -0
- package/.yalc/@node-dlc/core/dist/index.d.ts +39 -0
- package/.yalc/@node-dlc/core/dist/index.js +78 -0
- package/.yalc/@node-dlc/core/dist/index.js.map +1 -0
- package/.yalc/@node-dlc/core/dist/lightning/ChannelId.d.ts +31 -0
- package/.yalc/@node-dlc/core/dist/lightning/ChannelId.js +52 -0
- package/.yalc/@node-dlc/core/dist/lightning/ChannelId.js.map +1 -0
- package/.yalc/@node-dlc/core/dist/lightning/ChannelKeys.d.ts +55 -0
- package/.yalc/@node-dlc/core/dist/lightning/ChannelKeys.js +105 -0
- package/.yalc/@node-dlc/core/dist/lightning/ChannelKeys.js.map +1 -0
- package/.yalc/@node-dlc/core/dist/lightning/CommitmentNumber.d.ts +55 -0
- package/.yalc/@node-dlc/core/dist/lightning/CommitmentNumber.js +76 -0
- package/.yalc/@node-dlc/core/dist/lightning/CommitmentNumber.js.map +1 -0
- package/.yalc/@node-dlc/core/dist/lightning/CommitmentSecret.d.ts +26 -0
- package/.yalc/@node-dlc/core/dist/lightning/CommitmentSecret.js +44 -0
- package/.yalc/@node-dlc/core/dist/lightning/CommitmentSecret.js.map +1 -0
- package/.yalc/@node-dlc/core/dist/lightning/CommitmentSecretStore.d.ts +41 -0
- package/.yalc/@node-dlc/core/dist/lightning/CommitmentSecretStore.js +79 -0
- package/.yalc/@node-dlc/core/dist/lightning/CommitmentSecretStore.js.map +1 -0
- package/.yalc/@node-dlc/core/dist/lightning/Htlc.d.ts +46 -0
- package/.yalc/@node-dlc/core/dist/lightning/Htlc.js +46 -0
- package/.yalc/@node-dlc/core/dist/lightning/Htlc.js.map +1 -0
- package/.yalc/@node-dlc/core/dist/lightning/HtlcDirection.d.ts +16 -0
- package/.yalc/@node-dlc/core/dist/lightning/HtlcDirection.js +21 -0
- package/.yalc/@node-dlc/core/dist/lightning/HtlcDirection.js.map +1 -0
- package/.yalc/@node-dlc/core/dist/lightning/ScriptFactory.d.ts +76 -0
- package/.yalc/@node-dlc/core/dist/lightning/ScriptFactory.js +102 -0
- package/.yalc/@node-dlc/core/dist/lightning/ScriptFactory.js.map +1 -0
- package/.yalc/@node-dlc/core/dist/lightning/TxFactory.d.ts +83 -0
- package/.yalc/@node-dlc/core/dist/lightning/TxFactory.js +222 -0
- package/.yalc/@node-dlc/core/dist/lightning/TxFactory.js.map +1 -0
- package/.yalc/@node-dlc/core/dist/utils/BigIntUtils.d.ts +9 -0
- package/.yalc/@node-dlc/core/dist/utils/BigIntUtils.js +59 -0
- package/.yalc/@node-dlc/core/dist/utils/BigIntUtils.js.map +1 -0
- package/.yalc/@node-dlc/core/dist/utils/Precision.d.ts +13 -0
- package/.yalc/@node-dlc/core/dist/utils/Precision.js +28 -0
- package/.yalc/@node-dlc/core/dist/utils/Precision.js.map +1 -0
- package/.yalc/@node-dlc/core/lib/AsyncProcessingQueue.ts +63 -0
- package/.yalc/@node-dlc/core/lib/Base32.ts +2 -0
- package/.yalc/@node-dlc/core/lib/BigIntUtils.ts +2 -0
- package/.yalc/@node-dlc/core/lib/BitField.ts +2 -0
- package/.yalc/@node-dlc/core/lib/ChannelId.ts +2 -0
- package/.yalc/@node-dlc/core/lib/LinkedList.ts +111 -0
- package/.yalc/@node-dlc/core/lib/LinkedListNode.ts +14 -0
- package/.yalc/@node-dlc/core/lib/Queue.ts +36 -0
- package/.yalc/@node-dlc/core/lib/ShortChannelId.ts +2 -0
- package/.yalc/@node-dlc/core/lib/ShortChannelIdUtils.ts +9 -0
- package/.yalc/@node-dlc/core/lib/dlc/CETCalculator.ts +450 -0
- package/.yalc/@node-dlc/core/lib/dlc/CoinSelect.ts +117 -0
- package/.yalc/@node-dlc/core/lib/dlc/HyperbolaPayoutCurve.ts +188 -0
- package/.yalc/@node-dlc/core/lib/dlc/PayoutCurve.ts +6 -0
- package/.yalc/@node-dlc/core/lib/dlc/PolynomialPayoutCurve.ts +266 -0
- package/.yalc/@node-dlc/core/lib/dlc/TxBuilder.ts +336 -0
- package/.yalc/@node-dlc/core/lib/dlc/TxFinalizer.ts +217 -0
- package/.yalc/@node-dlc/core/lib/dlc/finance/Builder.ts +730 -0
- package/.yalc/@node-dlc/core/lib/dlc/finance/CoveredCall.ts +110 -0
- package/.yalc/@node-dlc/core/lib/dlc/finance/CsoInfo.ts +498 -0
- package/.yalc/@node-dlc/core/lib/dlc/finance/LinearPayout.ts +94 -0
- package/.yalc/@node-dlc/core/lib/dlc/finance/LongCall.ts +74 -0
- package/.yalc/@node-dlc/core/lib/dlc/finance/LongPut.ts +74 -0
- package/.yalc/@node-dlc/core/lib/dlc/finance/OptionInfo.ts +182 -0
- package/.yalc/@node-dlc/core/lib/dlc/finance/ShortPut.ts +75 -0
- package/.yalc/@node-dlc/core/lib/index.ts +66 -0
- package/.yalc/@node-dlc/core/lib/lightning/ChannelId.ts +54 -0
- package/.yalc/@node-dlc/core/lib/lightning/ChannelKeys.ts +109 -0
- package/.yalc/@node-dlc/core/lib/lightning/CommitmentNumber.ts +94 -0
- package/.yalc/@node-dlc/core/lib/lightning/CommitmentSecret.ts +41 -0
- package/.yalc/@node-dlc/core/lib/lightning/CommitmentSecretStore.ts +84 -0
- package/.yalc/@node-dlc/core/lib/lightning/Htlc.ts +52 -0
- package/.yalc/@node-dlc/core/lib/lightning/HtlcDirection.ts +17 -0
- package/.yalc/@node-dlc/core/lib/lightning/ScriptFactory.ts +150 -0
- package/.yalc/@node-dlc/core/lib/lightning/TxFactory.ts +338 -0
- package/.yalc/@node-dlc/core/lib/utils/BigIntUtils.ts +64 -0
- package/.yalc/@node-dlc/core/lib/utils/Precision.ts +23 -0
- package/.yalc/@node-dlc/core/package.json +38 -0
- package/.yalc/@node-dlc/core/tsconfig.json +8 -0
- package/.yalc/@node-dlc/core/yalc.sig +1 -0
- package/CHANGELOG.md +23 -0
- package/package.json +7 -7
- package/yalc.lock +10 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getOptionInfoFromOffer = exports.getOptionInfoFromContractInfo = void 0;
|
|
7
|
+
const messaging_1 = require("@node-dlc/messaging");
|
|
8
|
+
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
9
|
+
const HyperbolaPayoutCurve_1 = require("../HyperbolaPayoutCurve");
|
|
10
|
+
const CoveredCall_1 = require("./CoveredCall");
|
|
11
|
+
const ShortPut_1 = require("./ShortPut");
|
|
12
|
+
function getOptionInfoFromContractInfo(_contractInfo) {
|
|
13
|
+
if (_contractInfo.type !== messaging_1.MessageType.SingleContractInfo)
|
|
14
|
+
throw Error('Only SingleContractInfo currently supported');
|
|
15
|
+
const contractInfo = _contractInfo;
|
|
16
|
+
if (contractInfo.contractDescriptor.contractDescriptorType !==
|
|
17
|
+
messaging_1.ContractDescriptorType.NumericOutcome)
|
|
18
|
+
throw Error('Numeric Descriptor currently supported');
|
|
19
|
+
const oracleInfo = contractInfo.oracleInfo;
|
|
20
|
+
// Handle both SingleOracleInfo and MultiOracleInfo using proper type discrimination
|
|
21
|
+
let eventMaturityEpoch;
|
|
22
|
+
let eventDescriptor;
|
|
23
|
+
switch (oracleInfo.type) {
|
|
24
|
+
case messaging_1.MessageType.SingleOracleInfo: {
|
|
25
|
+
const singleOracleInfo = oracleInfo;
|
|
26
|
+
eventMaturityEpoch =
|
|
27
|
+
singleOracleInfo.announcement.oracleEvent.eventMaturityEpoch;
|
|
28
|
+
eventDescriptor = singleOracleInfo.announcement.oracleEvent
|
|
29
|
+
.eventDescriptor;
|
|
30
|
+
if (singleOracleInfo.announcement.oracleEvent.eventDescriptor.type !==
|
|
31
|
+
messaging_1.MessageType.DigitDecompositionEventDescriptorV0) {
|
|
32
|
+
throw Error('Only DigitDecompositionEventDescriptorV0 currently supported');
|
|
33
|
+
}
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
case messaging_1.MessageType.MultiOracleInfo: {
|
|
37
|
+
const multiOracleInfo = oracleInfo;
|
|
38
|
+
eventMaturityEpoch =
|
|
39
|
+
multiOracleInfo.announcements[0].oracleEvent.eventMaturityEpoch;
|
|
40
|
+
eventDescriptor = multiOracleInfo.announcements[0].oracleEvent
|
|
41
|
+
.eventDescriptor;
|
|
42
|
+
if (multiOracleInfo.announcements[0].oracleEvent.eventDescriptor.type !==
|
|
43
|
+
messaging_1.MessageType.DigitDecompositionEventDescriptorV0) {
|
|
44
|
+
throw Error('Only DigitDecompositionEventDescriptorV0 currently supported');
|
|
45
|
+
}
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
default:
|
|
49
|
+
throw Error(`Unknown oracle info type: ${oracleInfo.type}`);
|
|
50
|
+
}
|
|
51
|
+
const { base: oracleBase, nbDigits: oracleDigits } = eventDescriptor;
|
|
52
|
+
const contractDescriptor = contractInfo.contractDescriptor;
|
|
53
|
+
if (contractDescriptor.payoutFunction.type !== messaging_1.MessageType.PayoutFunction)
|
|
54
|
+
throw Error('Only PayoutFunction currently supported');
|
|
55
|
+
const payoutFunction = contractDescriptor.payoutFunction;
|
|
56
|
+
if (payoutFunction.payoutFunctionPieces.length === 0)
|
|
57
|
+
throw Error('PayoutFunction must have at least once PayoutFunctionPiece');
|
|
58
|
+
if (payoutFunction.payoutFunctionPieces.length > 1)
|
|
59
|
+
throw Error('More than one PayoutFunctionPiece not supported');
|
|
60
|
+
const payoutCurvePiece = payoutFunction.payoutFunctionPieces[0]
|
|
61
|
+
.payoutCurvePiece;
|
|
62
|
+
if (payoutCurvePiece.payoutCurvePieceType !== messaging_1.PayoutCurvePieceType.Hyperbola)
|
|
63
|
+
throw Error('Must be HyperbolaPayoutCurvePiece');
|
|
64
|
+
if (!payoutCurvePiece.b.isZero() || !payoutCurvePiece.c.isZero())
|
|
65
|
+
throw Error('b and c HyperbolaPayoutCurvePiece values must be 0');
|
|
66
|
+
const curve = HyperbolaPayoutCurve_1.HyperbolaPayoutCurve.fromPayoutCurvePiece(payoutCurvePiece);
|
|
67
|
+
const maxOutcome = BigInt(new bignumber_js_1.default(oracleBase).pow(oracleDigits).minus(1).toString(10));
|
|
68
|
+
// For the new PayoutFunction structure, we need to get the initial payout from the first piece
|
|
69
|
+
const initialPayout = payoutFunction.payoutFunctionPieces[0].endPoint.outcomePayout;
|
|
70
|
+
const isAscending = curve.getPayout(maxOutcome).gt(Number(initialPayout));
|
|
71
|
+
const expiry = new Date(eventMaturityEpoch * 1000);
|
|
72
|
+
const totalCollateral = contractInfo.totalCollateral;
|
|
73
|
+
// if curve is ascending, assume it is a put.
|
|
74
|
+
const contractSize = isAscending
|
|
75
|
+
? BigInt(payoutCurvePiece.translatePayout.toDecimal().toString()) -
|
|
76
|
+
totalCollateral
|
|
77
|
+
: totalCollateral -
|
|
78
|
+
BigInt(payoutCurvePiece.translatePayout.toDecimal().toString());
|
|
79
|
+
const strikePrice = BigInt(payoutCurvePiece.d.toDecimal().toString()) / contractSize;
|
|
80
|
+
// rebuild payout curve from option info and perform a sanity check
|
|
81
|
+
const { payoutCurve: sanityCurve } = isAscending
|
|
82
|
+
? ShortPut_1.ShortPut.buildCurve(strikePrice, contractSize, totalCollateral, oracleBase, oracleDigits)
|
|
83
|
+
: CoveredCall_1.CoveredCall.buildCurve(strikePrice, contractSize, oracleBase, oracleDigits);
|
|
84
|
+
const type = isAscending ? 'put' : 'call';
|
|
85
|
+
if (!curve.equals(sanityCurve))
|
|
86
|
+
throw new Error('Payout curve built from extracted OptionInfo does not match original payout curve');
|
|
87
|
+
return { contractSize, strikePrice, expiry, type };
|
|
88
|
+
}
|
|
89
|
+
exports.getOptionInfoFromContractInfo = getOptionInfoFromContractInfo;
|
|
90
|
+
function getOptionInfoFromOffer(offer) {
|
|
91
|
+
if (offer.type !== messaging_1.MessageType.DlcOffer &&
|
|
92
|
+
offer.type !== messaging_1.MessageType.OrderOffer)
|
|
93
|
+
throw Error('Only DlcOffer and OrderOffer currently supported');
|
|
94
|
+
const premium = offer.contractInfo.totalCollateral - offer.offerCollateral;
|
|
95
|
+
return {
|
|
96
|
+
...getOptionInfoFromContractInfo(offer.contractInfo),
|
|
97
|
+
premium,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
exports.getOptionInfoFromOffer = getOptionInfoFromOffer;
|
|
101
|
+
//# sourceMappingURL=OptionInfo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OptionInfo.js","sourceRoot":"","sources":["../../../lib/dlc/finance/OptionInfo.ts"],"names":[],"mappings":";;;;;;AAAA,mDAY6B;AAC7B,gEAA8B;AAE9B,kEAA+D;AAC/D,+CAA4C;AAC5C,yCAAsC;AAwBtC,SAAgB,6BAA6B,CAC3C,aAA2B;IAE3B,IAAI,aAAa,CAAC,IAAI,KAAK,uBAAW,CAAC,kBAAkB;QACvD,MAAM,KAAK,CAAC,6CAA6C,CAAC,CAAC;IAE7D,MAAM,YAAY,GAAG,aAAmC,CAAC;IACzD,IACE,YAAY,CAAC,kBAAkB,CAAC,sBAAsB;QACtD,kCAAsB,CAAC,cAAc;QAErC,MAAM,KAAK,CAAC,wCAAwC,CAAC,CAAC;IAExD,MAAM,UAAU,GAAG,YAAY,CAAC,UAAU,CAAC;IAE3C,oFAAoF;IACpF,IAAI,kBAA0B,CAAC;IAC/B,IAAI,eAAkD,CAAC;IAEvD,QAAQ,UAAU,CAAC,IAAI,EAAE;QACvB,KAAK,uBAAW,CAAC,gBAAgB,CAAC,CAAC;YACjC,MAAM,gBAAgB,GAAG,UAA8B,CAAC;YACxD,kBAAkB;gBAChB,gBAAgB,CAAC,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
|
3
|
+
export declare const ShortPut: {
|
|
4
|
+
buildCurve: (strikePrice: bigint, contractSize: bigint, totalCollateral: bigint, oracleBase: number, oracleDigits: number) => {
|
|
5
|
+
maxOutcome: bigint;
|
|
6
|
+
totalCollateral: bigint;
|
|
7
|
+
payoutCurve: HyperbolaPayoutCurve;
|
|
8
|
+
};
|
|
9
|
+
buildPayoutFunction: (strikePrice: bigint, contractSize: bigint, totalCollateral: bigint, oracleBase: number, oracleDigits: number) => {
|
|
10
|
+
payoutFunction: PayoutFunctionV0;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ShortPut = void 0;
|
|
7
|
+
const messaging_1 = require("@node-dlc/messaging");
|
|
8
|
+
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
9
|
+
const HyperbolaPayoutCurve_1 = require("../HyperbolaPayoutCurve");
|
|
10
|
+
const buildCurve = (strikePrice, contractSize, totalCollateral, oracleBase, oracleDigits) => {
|
|
11
|
+
const a = new bignumber_js_1.default(-1);
|
|
12
|
+
const b = new bignumber_js_1.default(0);
|
|
13
|
+
const c = new bignumber_js_1.default(0);
|
|
14
|
+
const d = new bignumber_js_1.default((strikePrice * contractSize).toString());
|
|
15
|
+
const f_1 = new bignumber_js_1.default(0);
|
|
16
|
+
const f_2 = new bignumber_js_1.default(Number(contractSize)).plus(Number(totalCollateral));
|
|
17
|
+
const payoutCurve = new HyperbolaPayoutCurve_1.HyperbolaPayoutCurve(a, b, c, d, f_1, f_2);
|
|
18
|
+
const maxOutcome = BigInt(new bignumber_js_1.default(oracleBase).pow(oracleDigits).minus(1).toString(10));
|
|
19
|
+
return {
|
|
20
|
+
maxOutcome,
|
|
21
|
+
totalCollateral,
|
|
22
|
+
payoutCurve,
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
const buildPayoutFunction = (strikePrice, contractSize, totalCollateral, oracleBase, oracleDigits) => {
|
|
26
|
+
const { maxOutcome, payoutCurve } = buildCurve(strikePrice, contractSize, totalCollateral, oracleBase, oracleDigits);
|
|
27
|
+
const payoutFunction = new messaging_1.PayoutFunctionV0();
|
|
28
|
+
payoutFunction.payoutFunctionPieces.push({
|
|
29
|
+
endPoint: {
|
|
30
|
+
eventOutcome: maxOutcome,
|
|
31
|
+
outcomePayout: totalCollateral,
|
|
32
|
+
extraPrecision: 0,
|
|
33
|
+
},
|
|
34
|
+
payoutCurvePiece: payoutCurve.toPayoutCurvePiece(),
|
|
35
|
+
});
|
|
36
|
+
payoutFunction.lastEndpoint = {
|
|
37
|
+
eventOutcome: maxOutcome,
|
|
38
|
+
outcomePayout: totalCollateral,
|
|
39
|
+
extraPrecision: 0,
|
|
40
|
+
};
|
|
41
|
+
return {
|
|
42
|
+
payoutFunction,
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
exports.ShortPut = { buildCurve, buildPayoutFunction };
|
|
46
|
+
//# sourceMappingURL=ShortPut.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ShortPut.js","sourceRoot":"","sources":["../../../lib/dlc/finance/ShortPut.ts"],"names":[],"mappings":";;;;;;AAAA,mDAAuD;AACvD,gEAA8B;AAE9B,kEAA+D;AAE/D,MAAM,UAAU,GAAG,CACjB,WAAmB,EACnB,YAAoB,EACpB,eAAuB,EACvB,UAAkB,EAClB,YAAoB,EAKpB,EAAE;IACF,MAAM,CAAC,GAAG,IAAI,sBAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IACrB,MAAM,CAAC,GAAG,IAAI,sBAAE,CAAC,CAAC,CAAC,CAAC;IACpB,MAAM,CAAC,GAAG,IAAI,sBAAE,CAAC,CAAC,CAAC,CAAC;IACpB,MAAM,CAAC,GAA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AC;KAClB,CAAC;IAEF,OAAO;QACL,cAAc;KACf,CAAC;AACJ,CAAC,CAAC;AAEW,QAAA,QAAQ,GAAG,EAAE,UAAU,EAAE,mBAAmB,EAAE,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export * from '@node-dlc/bitcoin';
|
|
2
|
+
export * from './AsyncProcessingQueue';
|
|
3
|
+
export * from './Base32';
|
|
4
|
+
export * from './BigIntUtils';
|
|
5
|
+
export * from './BitField';
|
|
6
|
+
export * from './ChannelId';
|
|
7
|
+
export * from './LinkedList';
|
|
8
|
+
export * from './LinkedListNode';
|
|
9
|
+
export * from './Queue';
|
|
10
|
+
export * from './ShortChannelId';
|
|
11
|
+
export * from './ShortChannelIdUtils';
|
|
12
|
+
export { HashByteOrder, HashValue, OutPoint, Script, Tx, TxBuilder, TxIn, TxOut, Value, } from '@node-dlc/bitcoin';
|
|
13
|
+
export { shortChannelIdFromBuffer, shortChannelIdFromNumber, shortChannelIdFromString, shortChannelIdToBuffer, shortChannelIdToNumber, shortChannelIdToString, } from './ShortChannelIdUtils';
|
|
14
|
+
export { ChannelId as LightningChannelId } from './lightning/ChannelId';
|
|
15
|
+
export * from './lightning/ChannelKeys';
|
|
16
|
+
export * from './lightning/CommitmentNumber';
|
|
17
|
+
export * from './lightning/CommitmentSecret';
|
|
18
|
+
export * from './lightning/CommitmentSecretStore';
|
|
19
|
+
export * from './lightning/Htlc';
|
|
20
|
+
export * from './lightning/HtlcDirection';
|
|
21
|
+
export * from './lightning/ScriptFactory';
|
|
22
|
+
export * from './lightning/TxFactory';
|
|
23
|
+
export * from './dlc/CETCalculator';
|
|
24
|
+
export * from './dlc/CoinSelect';
|
|
25
|
+
export * from './dlc/HyperbolaPayoutCurve';
|
|
26
|
+
export * from './dlc/PayoutCurve';
|
|
27
|
+
export * from './dlc/PolynomialPayoutCurve';
|
|
28
|
+
export * from './dlc/TxBuilder';
|
|
29
|
+
export * from './dlc/TxFinalizer';
|
|
30
|
+
export * from './dlc/finance/Builder';
|
|
31
|
+
export * from './dlc/finance/CoveredCall';
|
|
32
|
+
export * from './dlc/finance/CsoInfo';
|
|
33
|
+
export * from './dlc/finance/LinearPayout';
|
|
34
|
+
export * from './dlc/finance/LongCall';
|
|
35
|
+
export * from './dlc/finance/LongPut';
|
|
36
|
+
export * from './dlc/finance/OptionInfo';
|
|
37
|
+
export * from './dlc/finance/ShortPut';
|
|
38
|
+
export * from './utils/BigIntUtils';
|
|
39
|
+
export * from './utils/Precision';
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.LightningChannelId = exports.shortChannelIdToString = exports.shortChannelIdToNumber = exports.shortChannelIdToBuffer = exports.shortChannelIdFromString = exports.shortChannelIdFromNumber = exports.shortChannelIdFromBuffer = exports.Value = exports.TxOut = exports.TxIn = exports.TxBuilder = exports.Tx = exports.Script = exports.OutPoint = exports.HashValue = exports.HashByteOrder = void 0;
|
|
18
|
+
__exportStar(require("@node-dlc/bitcoin"), exports);
|
|
19
|
+
// Explicitly re-export commonly used types from bitcoin for better TypeScript support
|
|
20
|
+
__exportStar(require("./AsyncProcessingQueue"), exports);
|
|
21
|
+
__exportStar(require("./Base32"), exports);
|
|
22
|
+
__exportStar(require("./BigIntUtils"), exports);
|
|
23
|
+
__exportStar(require("./BitField"), exports);
|
|
24
|
+
__exportStar(require("./ChannelId"), exports);
|
|
25
|
+
__exportStar(require("./LinkedList"), exports);
|
|
26
|
+
__exportStar(require("./LinkedListNode"), exports);
|
|
27
|
+
__exportStar(require("./Queue"), exports);
|
|
28
|
+
__exportStar(require("./ShortChannelId"), exports);
|
|
29
|
+
__exportStar(require("./ShortChannelIdUtils"), exports);
|
|
30
|
+
var bitcoin_1 = require("@node-dlc/bitcoin");
|
|
31
|
+
Object.defineProperty(exports, "HashByteOrder", { enumerable: true, get: function () { return bitcoin_1.HashByteOrder; } });
|
|
32
|
+
Object.defineProperty(exports, "HashValue", { enumerable: true, get: function () { return bitcoin_1.HashValue; } });
|
|
33
|
+
Object.defineProperty(exports, "OutPoint", { enumerable: true, get: function () { return bitcoin_1.OutPoint; } });
|
|
34
|
+
Object.defineProperty(exports, "Script", { enumerable: true, get: function () { return bitcoin_1.Script; } });
|
|
35
|
+
Object.defineProperty(exports, "Tx", { enumerable: true, get: function () { return bitcoin_1.Tx; } });
|
|
36
|
+
Object.defineProperty(exports, "TxBuilder", { enumerable: true, get: function () { return bitcoin_1.TxBuilder; } });
|
|
37
|
+
Object.defineProperty(exports, "TxIn", { enumerable: true, get: function () { return bitcoin_1.TxIn; } });
|
|
38
|
+
Object.defineProperty(exports, "TxOut", { enumerable: true, get: function () { return bitcoin_1.TxOut; } });
|
|
39
|
+
Object.defineProperty(exports, "Value", { enumerable: true, get: function () { return bitcoin_1.Value; } });
|
|
40
|
+
// Explicitly export the utility functions that wire needs
|
|
41
|
+
var ShortChannelIdUtils_1 = require("./ShortChannelIdUtils");
|
|
42
|
+
Object.defineProperty(exports, "shortChannelIdFromBuffer", { enumerable: true, get: function () { return ShortChannelIdUtils_1.shortChannelIdFromBuffer; } });
|
|
43
|
+
Object.defineProperty(exports, "shortChannelIdFromNumber", { enumerable: true, get: function () { return ShortChannelIdUtils_1.shortChannelIdFromNumber; } });
|
|
44
|
+
Object.defineProperty(exports, "shortChannelIdFromString", { enumerable: true, get: function () { return ShortChannelIdUtils_1.shortChannelIdFromString; } });
|
|
45
|
+
Object.defineProperty(exports, "shortChannelIdToBuffer", { enumerable: true, get: function () { return ShortChannelIdUtils_1.shortChannelIdToBuffer; } });
|
|
46
|
+
Object.defineProperty(exports, "shortChannelIdToNumber", { enumerable: true, get: function () { return ShortChannelIdUtils_1.shortChannelIdToNumber; } });
|
|
47
|
+
Object.defineProperty(exports, "shortChannelIdToString", { enumerable: true, get: function () { return ShortChannelIdUtils_1.shortChannelIdToString; } });
|
|
48
|
+
// Lightning subdirectory exports (excluding ChannelId to avoid conflict)
|
|
49
|
+
var ChannelId_1 = require("./lightning/ChannelId");
|
|
50
|
+
Object.defineProperty(exports, "LightningChannelId", { enumerable: true, get: function () { return ChannelId_1.ChannelId; } });
|
|
51
|
+
__exportStar(require("./lightning/ChannelKeys"), exports);
|
|
52
|
+
__exportStar(require("./lightning/CommitmentNumber"), exports);
|
|
53
|
+
__exportStar(require("./lightning/CommitmentSecret"), exports);
|
|
54
|
+
__exportStar(require("./lightning/CommitmentSecretStore"), exports);
|
|
55
|
+
__exportStar(require("./lightning/Htlc"), exports);
|
|
56
|
+
__exportStar(require("./lightning/HtlcDirection"), exports);
|
|
57
|
+
__exportStar(require("./lightning/ScriptFactory"), exports);
|
|
58
|
+
__exportStar(require("./lightning/TxFactory"), exports);
|
|
59
|
+
// Original node-dlc core exports
|
|
60
|
+
__exportStar(require("./dlc/CETCalculator"), exports);
|
|
61
|
+
__exportStar(require("./dlc/CoinSelect"), exports);
|
|
62
|
+
__exportStar(require("./dlc/HyperbolaPayoutCurve"), exports);
|
|
63
|
+
__exportStar(require("./dlc/PayoutCurve"), exports);
|
|
64
|
+
__exportStar(require("./dlc/PolynomialPayoutCurve"), exports);
|
|
65
|
+
__exportStar(require("./dlc/TxBuilder"), exports);
|
|
66
|
+
__exportStar(require("./dlc/TxFinalizer"), exports);
|
|
67
|
+
// Finance subdirectory exports
|
|
68
|
+
__exportStar(require("./dlc/finance/Builder"), exports);
|
|
69
|
+
__exportStar(require("./dlc/finance/CoveredCall"), exports);
|
|
70
|
+
__exportStar(require("./dlc/finance/CsoInfo"), exports);
|
|
71
|
+
__exportStar(require("./dlc/finance/LinearPayout"), exports);
|
|
72
|
+
__exportStar(require("./dlc/finance/LongCall"), exports);
|
|
73
|
+
__exportStar(require("./dlc/finance/LongPut"), exports);
|
|
74
|
+
__exportStar(require("./dlc/finance/OptionInfo"), exports);
|
|
75
|
+
__exportStar(require("./dlc/finance/ShortPut"), exports);
|
|
76
|
+
__exportStar(require("./utils/BigIntUtils"), exports);
|
|
77
|
+
__exportStar(require("./utils/Precision"), exports);
|
|
78
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,oDAAkC;AAElC,sFAAsF;AACtF,yDAAuC;AACvC,2CAAyB;AACzB,gDAA8B;AAC9B,6CAA2B;AAC3B,8CAA4B;AAC5B,+CAA6B;AAC7B,mDAAiC;AACjC,0CAAwB;AACxB,mDAAiC;AACjC,wDAAsC;AACtC,6CAU2B;AATzB,wGAAA,aAAa,OAAA;AACb,oGAAA,SAAS,OAAA;AACT,mGAAA,QAAQ,OAAA;AACR,iGAAA,MAAM,OAAA;AACN,6FAAA,EAAE,OAAA;AACF,oGAAA,SAAS,OAAA;AACT,+FAAA,IAAI,OAAA;AACJ,gGAAA,KAAK,OAAA;AACL,gGAAA,KAAK,OAAA;AAGP,0DAA0D;AAC1D,6DAO+B;AAN7B,+HAAA,wBAAwB,OAAA;AACxB,+HAAA,wBAAwB,OAAA;AACxB,+HAAA,wBAAwB,OAAA;AACxB,6HAAA,sBAAsB,OAAA;AACtB,6HAAA,sBAAsB,OAAA;AACtB,6HAAA,sBAAsB,OAAA;AAGxB,yEAAyE;AACzE,mDAAwE;AAA/D,+GAAA,SAAS,OAAsB;AACxC,0DAAwC;AACxC,+DAA6C;AAC7C,+DAA6C;AAC7C,oEAAkD;AAClD,mDAAiC;AACjC,4DAA0C;AAC1C,4DAA0C;AAC1C,wDAAsC;AAEtC,iCAAiC;AACjC,sDAAoC;AACpC,mDAAiC;AACjC,6DAA2C;AAC3C,oDAAkC;AAClC,8DAA4C;AAC5C,kDAAgC;AAChC,oDAAkC;AAElC,+BAA+B;AAC/B,wDAAsC;AACtC,4DAA0C;AAC1C,wDAAsC;AACtC,6DAA2C;AAC3C,yDAAuC;AACvC,wDAAsC;AACtC,2DAAyC;AACzC,yDAAuC;AACvC,sDAAoC;AACpC,oDAAkC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { OutPoint } from '@node-dlc/bitcoin';
|
|
3
|
+
/**
|
|
4
|
+
* ChannelId type that that encapsulates an outpoint as a 32-byte value
|
|
5
|
+
* and is used to identify a channel. This type is defined in BOLT 2
|
|
6
|
+
* under the peer protocol. It is defined as combinging the funding_txid
|
|
7
|
+
* and the funding_output_index, using big-endian XOR (meaning the
|
|
8
|
+
* output_index modifies the last two bytes).
|
|
9
|
+
*/
|
|
10
|
+
export declare class ChannelId {
|
|
11
|
+
readonly value: Buffer;
|
|
12
|
+
static fromOutPoint(outpoint: OutPoint): ChannelId;
|
|
13
|
+
constructor(value: Buffer);
|
|
14
|
+
/**
|
|
15
|
+
* Converts the ChannelId into a buffer
|
|
16
|
+
*/
|
|
17
|
+
toBuffer(): Buffer;
|
|
18
|
+
/**
|
|
19
|
+
* Converts the ChannelId into a hex-encoded string
|
|
20
|
+
*/
|
|
21
|
+
toString(): string;
|
|
22
|
+
/**
|
|
23
|
+
* Converts the ChannelId to a hex-encoded string
|
|
24
|
+
*/
|
|
25
|
+
toHex(): string;
|
|
26
|
+
/**
|
|
27
|
+
* Returns true if the ChannelIds are byte-wise equal
|
|
28
|
+
* @param other
|
|
29
|
+
*/
|
|
30
|
+
equals(other: ChannelId): boolean;
|
|
31
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ChannelId = void 0;
|
|
4
|
+
const bitcoin_1 = require("@node-dlc/bitcoin");
|
|
5
|
+
/**
|
|
6
|
+
* ChannelId type that that encapsulates an outpoint as a 32-byte value
|
|
7
|
+
* and is used to identify a channel. This type is defined in BOLT 2
|
|
8
|
+
* under the peer protocol. It is defined as combinging the funding_txid
|
|
9
|
+
* and the funding_output_index, using big-endian XOR (meaning the
|
|
10
|
+
* output_index modifies the last two bytes).
|
|
11
|
+
*/
|
|
12
|
+
class ChannelId {
|
|
13
|
+
static fromOutPoint(outpoint) {
|
|
14
|
+
const txid = outpoint.txid.serialize(bitcoin_1.HashByteOrder.RPC);
|
|
15
|
+
if (outpoint.outputIndex > 0xffff) {
|
|
16
|
+
throw new Error('Invalid output index length');
|
|
17
|
+
}
|
|
18
|
+
txid[30] ^= outpoint.outputIndex >> 8;
|
|
19
|
+
txid[31] ^= outpoint.outputIndex & 0xff;
|
|
20
|
+
return new ChannelId(txid);
|
|
21
|
+
}
|
|
22
|
+
constructor(value) {
|
|
23
|
+
this.value = value;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Converts the ChannelId into a buffer
|
|
27
|
+
*/
|
|
28
|
+
toBuffer() {
|
|
29
|
+
return Buffer.from(this.value);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Converts the ChannelId into a hex-encoded string
|
|
33
|
+
*/
|
|
34
|
+
toString() {
|
|
35
|
+
return this.toHex();
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Converts the ChannelId to a hex-encoded string
|
|
39
|
+
*/
|
|
40
|
+
toHex() {
|
|
41
|
+
return this.value.toString('hex');
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Returns true if the ChannelIds are byte-wise equal
|
|
45
|
+
* @param other
|
|
46
|
+
*/
|
|
47
|
+
equals(other) {
|
|
48
|
+
return this.value.equals(other.value);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.ChannelId = ChannelId;
|
|
52
|
+
//# sourceMappingURL=ChannelId.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChannelId.js","sourceRoot":"","sources":["../../lib/lightning/ChannelId.ts"],"names":[],"mappings":";;;AAAA,+CAA4D;AAE5D;;;;;;GAMG;AACH,MAAa,SAAS;IACb,MAAM,CAAC,YAAY,CAAC,QAAkB;QAC3C,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,uBAAa,CAAC,GAAG,CAAC,CAAC;QAExD,IAAI,QAAQ,CAAC,WAAW,GAAG,MAAM,EAAE;YACjC,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;SAChD;QAED,IAAI,CAAC,EAAE,CAAC,IAAI,QAAQ,CAAC,WAAW,IAAI,CAAC,CAAC;QACtC,IAAI,CAAC,EAAE,CAAC,IAAI,QAAQ,CAAC,WAAW,GAAG,IAAI,CAAC;QAExC,OAAO,IAAI,SAAS,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC;IAED,YAAqB,KAAa;QAAb,UAAK,GAAL,KAAK,CAAQ;IAAG,CAAC;IAEtC;;OAEG;IACI,QAAQ;QACb,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACjC,CAAC;IAED;;OAEG;IACI,QAAQ;QACb,OAAO,IAAI,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC;IAED;;OAEG;IACI,KAAK;QACV,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;IAED;;;OAGG;IACI,MAAM,CAAC,KAAgB;QAC5B,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACxC,CAAC;CACF;AA5CD,8BA4CC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
export declare class ChannelKeys {
|
|
3
|
+
/**
|
|
4
|
+
* Derives a public key that can be used for local or remote
|
|
5
|
+
* pubkey, htlc_pubkey, or delayed_pubkey
|
|
6
|
+
*
|
|
7
|
+
* Derived via:
|
|
8
|
+
* pubkey = basepoint + SHA256(per_commitment_point || basepoint) * G
|
|
9
|
+
*
|
|
10
|
+
* @param perCommitmentPoint 33-byte buffer
|
|
11
|
+
* @param basePoint 33-byte base point
|
|
12
|
+
* @returns 33-byte buffer
|
|
13
|
+
*/
|
|
14
|
+
static derivePubKey(perCommitmentPoint: Buffer, basePoint: Buffer): Buffer;
|
|
15
|
+
/**
|
|
16
|
+
* Derives the private keys based on local basepoint secrets and can
|
|
17
|
+
* be used to derive per-commitment
|
|
18
|
+
* - payment_scret
|
|
19
|
+
* - delayedpayment_secret
|
|
20
|
+
* - htlc_secret
|
|
21
|
+
*
|
|
22
|
+
* Derived via:
|
|
23
|
+
* privkey = basepoint_secret + SHA256(per_commitment_point || basepoint)
|
|
24
|
+
*
|
|
25
|
+
* @param perCommitmentPoint 32-byte buffer
|
|
26
|
+
* @param basePointSecret 32-byte buffer
|
|
27
|
+
* @return 32-byte buffer
|
|
28
|
+
*/
|
|
29
|
+
static derivePrivKey(perCommitmentPoint: Buffer, basePointSecret: Buffer): Buffer;
|
|
30
|
+
/**
|
|
31
|
+
* Derives the revocationpubkey blinded key for either local or
|
|
32
|
+
* remote revocation pubkey generation.
|
|
33
|
+
*
|
|
34
|
+
* Derived via:
|
|
35
|
+
* revocationpubkey = revocation_basepoint * SHA256(revocation_basepoint || per_commitment_point) +
|
|
36
|
+
* per_commitment_point * SHA256(per_commitment_point || revocation_basepoint)
|
|
37
|
+
*
|
|
38
|
+
* @param perCommitmentPoint 33-byte buffer
|
|
39
|
+
* @param basePoint 33-byte buffer
|
|
40
|
+
* @returns 33-byte buffer
|
|
41
|
+
*/
|
|
42
|
+
static deriveRevocationPubKey(perCommitmentPoint: Buffer, basePoint: Buffer): Buffer;
|
|
43
|
+
/**
|
|
44
|
+
* Derives the revocationprivkey which is used by the local node
|
|
45
|
+
* and with a per_commitment_secret that was revealed by the
|
|
46
|
+
* counterparty.
|
|
47
|
+
*
|
|
48
|
+
* Derived via:
|
|
49
|
+
* revocationprivkey = revocation_basepoint_secret * SHA256(revocation_basepoint || per_commitment_point) +
|
|
50
|
+
* per_commitment_secret * SHA256(per_commitment_point || revocation_basepoint)
|
|
51
|
+
* @param perCommitmentPointSecret 32-byte buffer
|
|
52
|
+
* @param basePointSecret 32-byte buffer
|
|
53
|
+
*/
|
|
54
|
+
static deriveRevocationPrivKey(perCommitmentPointSecret: Buffer, basePointSecret: Buffer): Buffer;
|
|
55
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.ChannelKeys = void 0;
|
|
27
|
+
const crypto = __importStar(require("@node-dlc/crypto"));
|
|
28
|
+
class ChannelKeys {
|
|
29
|
+
/**
|
|
30
|
+
* Derives a public key that can be used for local or remote
|
|
31
|
+
* pubkey, htlc_pubkey, or delayed_pubkey
|
|
32
|
+
*
|
|
33
|
+
* Derived via:
|
|
34
|
+
* pubkey = basepoint + SHA256(per_commitment_point || basepoint) * G
|
|
35
|
+
*
|
|
36
|
+
* @param perCommitmentPoint 33-byte buffer
|
|
37
|
+
* @param basePoint 33-byte base point
|
|
38
|
+
* @returns 33-byte buffer
|
|
39
|
+
*/
|
|
40
|
+
static derivePubKey(perCommitmentPoint, basePoint) {
|
|
41
|
+
const tweak = crypto.sha256(Buffer.concat([perCommitmentPoint, basePoint]));
|
|
42
|
+
return crypto.publicKeyTweakAdd(basePoint, tweak, true);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Derives the private keys based on local basepoint secrets and can
|
|
46
|
+
* be used to derive per-commitment
|
|
47
|
+
* - payment_scret
|
|
48
|
+
* - delayedpayment_secret
|
|
49
|
+
* - htlc_secret
|
|
50
|
+
*
|
|
51
|
+
* Derived via:
|
|
52
|
+
* privkey = basepoint_secret + SHA256(per_commitment_point || basepoint)
|
|
53
|
+
*
|
|
54
|
+
* @param perCommitmentPoint 32-byte buffer
|
|
55
|
+
* @param basePointSecret 32-byte buffer
|
|
56
|
+
* @return 32-byte buffer
|
|
57
|
+
*/
|
|
58
|
+
static derivePrivKey(perCommitmentPoint, basePointSecret) {
|
|
59
|
+
const basePoint = crypto.getPublicKey(basePointSecret, true);
|
|
60
|
+
const tweak = crypto.sha256(Buffer.concat([perCommitmentPoint, basePoint]));
|
|
61
|
+
return crypto.privateKeyTweakAdd(basePointSecret, tweak);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Derives the revocationpubkey blinded key for either local or
|
|
65
|
+
* remote revocation pubkey generation.
|
|
66
|
+
*
|
|
67
|
+
* Derived via:
|
|
68
|
+
* revocationpubkey = revocation_basepoint * SHA256(revocation_basepoint || per_commitment_point) +
|
|
69
|
+
* per_commitment_point * SHA256(per_commitment_point || revocation_basepoint)
|
|
70
|
+
*
|
|
71
|
+
* @param perCommitmentPoint 33-byte buffer
|
|
72
|
+
* @param basePoint 33-byte buffer
|
|
73
|
+
* @returns 33-byte buffer
|
|
74
|
+
*/
|
|
75
|
+
static deriveRevocationPubKey(perCommitmentPoint, basePoint) {
|
|
76
|
+
const tweakA = crypto.sha256(Buffer.concat([basePoint, perCommitmentPoint]));
|
|
77
|
+
const a = crypto.publicKeyTweakMul(basePoint, tweakA, true);
|
|
78
|
+
const tweakB = crypto.sha256(Buffer.concat([perCommitmentPoint, basePoint]));
|
|
79
|
+
const b = crypto.publicKeyTweakMul(perCommitmentPoint, tweakB, true);
|
|
80
|
+
return crypto.publicKeyCombine([a, b], true);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Derives the revocationprivkey which is used by the local node
|
|
84
|
+
* and with a per_commitment_secret that was revealed by the
|
|
85
|
+
* counterparty.
|
|
86
|
+
*
|
|
87
|
+
* Derived via:
|
|
88
|
+
* revocationprivkey = revocation_basepoint_secret * SHA256(revocation_basepoint || per_commitment_point) +
|
|
89
|
+
* per_commitment_secret * SHA256(per_commitment_point || revocation_basepoint)
|
|
90
|
+
* @param perCommitmentPointSecret 32-byte buffer
|
|
91
|
+
* @param basePointSecret 32-byte buffer
|
|
92
|
+
*/
|
|
93
|
+
static deriveRevocationPrivKey(perCommitmentPointSecret, basePointSecret) {
|
|
94
|
+
const basePoint = crypto.getPublicKey(basePointSecret, true);
|
|
95
|
+
const perCommitmentPoint = crypto.getPublicKey(perCommitmentPointSecret, true);
|
|
96
|
+
const tweakA = crypto.sha256(Buffer.concat([basePoint, perCommitmentPoint]));
|
|
97
|
+
const a = crypto.privateKeyTweakMul(basePointSecret, tweakA);
|
|
98
|
+
const tweakB = crypto.sha256(Buffer.concat([perCommitmentPoint, basePoint]));
|
|
99
|
+
const b = crypto.privateKeyTweakMul(perCommitmentPointSecret, tweakB);
|
|
100
|
+
const result = crypto.privateKeyTweakAdd(a, b);
|
|
101
|
+
return result;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
exports.ChannelKeys = ChannelKeys;
|
|
105
|
+
//# sourceMappingURL=ChannelKeys.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChannelKeys.js","sourceRoot":"","sources":["../../lib/lightning/ChannelKeys.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yDAA2C;AAE3C,MAAa,WAAW;IACtB;;;;;;;;;;OAUG;IACI,MAAM,CAAC,YAAY,CACxB,kBAA0B,EAC1B,SAAiB;QAEjB,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,kBAAkB,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;QAC5E,OAAO,MAAM,CAAC,iBAAiB,CAAC,SAAS,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;IAC1D,CAAC;IAED;;;;;;;;;;;;;OAaG;IACI,MAAM,CAAC,aAAa,CACzB,kBAA0B,EAC1B,eAAuB;QAEvB,MAAM,SAAS,GAAG,MAAM,CAAC,YAAY,CAAC,eAAe,EAAE,IAAI,CAAC,CAAC;QAC7D,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CA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GAAG,MAAM,CAAC,MAAM,CAC1B,MAAM,CAAC,MAAM,CAAC,CAAC,kBAAkB,EAAE,SAAS,CAAC,CAAC,CAC/C,CAAC;QACF,MAAM,CAAC,GAAG,MAAM,CAAC,kBAAkB,CAAC,wBAAwB,EAAE,MAAM,CAAC,CAAC;QAEtE,MAAM,MAAM,GAAG,MAAM,CAAC,kBAAkB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAC/C,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AA1GD,kCA0GC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { LockTime, Sequence } from '@node-dlc/bitcoin';
|
|
3
|
+
export declare class CommitmentNumber {
|
|
4
|
+
/**
|
|
5
|
+
* Using the obscured commitment number, creates a Sequence with
|
|
6
|
+
* the upper byte set to 0x80 and the lower three bytes set to the
|
|
7
|
+
* upper 3 bytes of the 48-bit commitment number.
|
|
8
|
+
*
|
|
9
|
+
* The upper most byte is set to 0x80 so that the relative lock time
|
|
10
|
+
* is disabled.
|
|
11
|
+
*
|
|
12
|
+
* @param commitment commitment number to obscure
|
|
13
|
+
*/
|
|
14
|
+
static getSequence(obscurred: bigint): Sequence;
|
|
15
|
+
/**
|
|
16
|
+
* Using the obscured commitment number, creates a LockTime with
|
|
17
|
+
* the upper byte set to 0x20 and the lower three bytes set to the
|
|
18
|
+
* lower 3 bytes of the 48-bit commitment number.
|
|
19
|
+
*
|
|
20
|
+
* The uppermost byte is set to 0x20 so the LockTime uses a time
|
|
21
|
+
* based absolute locktime that has already expired.
|
|
22
|
+
*
|
|
23
|
+
* @param obscurred obscurred commitment number
|
|
24
|
+
*/
|
|
25
|
+
static getLockTime(obscurred: bigint): LockTime;
|
|
26
|
+
/**
|
|
27
|
+
* Reveals the commitment number provided by the nSequence and
|
|
28
|
+
* nLockTime values. This function reverses the obscurring using the
|
|
29
|
+
* known payment base points.
|
|
30
|
+
*
|
|
31
|
+
* @param locktime
|
|
32
|
+
* @param sequence
|
|
33
|
+
*/
|
|
34
|
+
static reveal(locktime: LockTime, sequence: Sequence, openBasePoint: Buffer, acceptBasePoint: Buffer): number;
|
|
35
|
+
/**
|
|
36
|
+
* Defined in BOLT3, the obscurred commitment number is attached to the
|
|
37
|
+
* commitment transaction. The 48-bit commitment number is broken into
|
|
38
|
+
* two pieces, the lower 3-bytes are obscured in nLocketime and the
|
|
39
|
+
* upper 3-bytes are obscured in the funding input's nSequence.
|
|
40
|
+
*
|
|
41
|
+
* The obscurred commitment number is calculated as the:
|
|
42
|
+
* sha256(open_channel payment_basepoint || accept_channel payment_basepoint) ^ commitment_number
|
|
43
|
+
* @param commitment
|
|
44
|
+
* @param openBasePoint
|
|
45
|
+
* @param acceptBasePoint
|
|
46
|
+
*/
|
|
47
|
+
static obscure(commitment: number, openBasePoint: Buffer, acceptBasePoint: Buffer): bigint;
|
|
48
|
+
/**
|
|
49
|
+
* Obtains the lower 6-bytes from the sha256 of the open_channel
|
|
50
|
+
* basepoint and the accept_channel basepoint.
|
|
51
|
+
* @param openBasePoint
|
|
52
|
+
* @param acceptBasePoint
|
|
53
|
+
*/
|
|
54
|
+
private static getHash;
|
|
55
|
+
}
|