@atomiqlabs/lp-lib 11.0.5 → 12.0.0-beta.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/dist/info/InfoHandler.js +3 -12
- package/dist/plugins/IPlugin.d.ts +34 -35
- package/dist/plugins/IPlugin.js +7 -8
- package/dist/plugins/PluginManager.d.ts +29 -30
- package/dist/plugins/PluginManager.js +160 -188
- package/dist/prices/BinanceSwapPrice.d.ts +1 -2
- package/dist/prices/BinanceSwapPrice.js +56 -70
- package/dist/prices/CoinGeckoSwapPrice.d.ts +2 -3
- package/dist/prices/CoinGeckoSwapPrice.js +30 -42
- package/dist/prices/OKXSwapPrice.d.ts +1 -2
- package/dist/prices/OKXSwapPrice.js +56 -70
- package/dist/storage/IIntermediaryStorage.d.ts +8 -5
- package/dist/storagemanager/IntermediaryStorageManager.d.ts +8 -5
- package/dist/storagemanager/IntermediaryStorageManager.js +52 -61
- package/dist/storagemanager/StorageManager.js +42 -59
- package/dist/swaps/FromBtcBaseSwap.d.ts +7 -8
- package/dist/swaps/FromBtcBaseSwap.js +2 -3
- package/dist/swaps/FromBtcBaseSwapHandler.d.ts +44 -31
- package/dist/swaps/FromBtcBaseSwapHandler.js +217 -196
- package/dist/swaps/FromBtcLnBaseSwapHandler.d.ts +1 -2
- package/dist/swaps/FromBtcLnBaseSwapHandler.js +13 -24
- package/dist/swaps/ISwapPrice.d.ts +4 -5
- package/dist/swaps/ISwapPrice.js +8 -30
- package/dist/swaps/SwapHandler.d.ts +26 -15
- package/dist/swaps/SwapHandler.js +107 -66
- package/dist/swaps/SwapHandlerSwap.d.ts +22 -11
- package/dist/swaps/SwapHandlerSwap.js +32 -8
- package/dist/swaps/ToBtcBaseSwap.d.ts +16 -17
- package/dist/swaps/ToBtcBaseSwap.js +4 -4
- package/dist/swaps/ToBtcBaseSwapHandler.d.ts +17 -17
- package/dist/swaps/ToBtcBaseSwapHandler.js +140 -155
- package/dist/swaps/frombtc_abstract/FromBtcAbs.d.ts +8 -15
- package/dist/swaps/frombtc_abstract/FromBtcAbs.js +131 -196
- package/dist/swaps/frombtc_abstract/FromBtcSwapAbs.d.ts +3 -5
- package/dist/swaps/frombtc_abstract/FromBtcSwapAbs.js +4 -4
- package/dist/swaps/frombtc_trusted/FromBtcTrusted.d.ts +10 -8
- package/dist/swaps/frombtc_trusted/FromBtcTrusted.js +330 -362
- package/dist/swaps/frombtc_trusted/FromBtcTrustedSwap.d.ts +10 -10
- package/dist/swaps/frombtc_trusted/FromBtcTrustedSwap.js +7 -4
- package/dist/swaps/frombtcln_abstract/FromBtcLnAbs.d.ts +8 -8
- package/dist/swaps/frombtcln_abstract/FromBtcLnAbs.js +330 -400
- package/dist/swaps/frombtcln_abstract/FromBtcLnSwapAbs.d.ts +10 -4
- package/dist/swaps/frombtcln_abstract/FromBtcLnSwapAbs.js +36 -6
- package/dist/swaps/frombtcln_trusted/FromBtcLnTrusted.d.ts +8 -7
- package/dist/swaps/frombtcln_trusted/FromBtcLnTrusted.js +251 -273
- package/dist/swaps/frombtcln_trusted/FromBtcLnTrustedSwap.d.ts +5 -5
- package/dist/swaps/frombtcln_trusted/FromBtcLnTrustedSwap.js +7 -5
- package/dist/swaps/tobtc_abstract/ToBtcAbs.d.ts +13 -12
- package/dist/swaps/tobtc_abstract/ToBtcAbs.js +261 -323
- package/dist/swaps/tobtc_abstract/ToBtcSwapAbs.d.ts +4 -4
- package/dist/swaps/tobtc_abstract/ToBtcSwapAbs.js +7 -6
- package/dist/swaps/tobtcln_abstract/ToBtcLnAbs.d.ts +22 -21
- package/dist/swaps/tobtcln_abstract/ToBtcLnAbs.js +398 -453
- package/dist/swaps/tobtcln_abstract/ToBtcLnSwapAbs.d.ts +3 -2
- package/dist/swaps/tobtcln_abstract/ToBtcLnSwapAbs.js +10 -6
- package/dist/utils/Utils.d.ts +2 -3
- package/dist/utils/Utils.js +4 -14
- package/dist/utils/paramcoders/LegacyParamEncoder.js +3 -14
- package/dist/utils/paramcoders/ParamDecoder.js +53 -65
- package/dist/utils/paramcoders/SchemaVerifier.d.ts +4 -5
- package/dist/utils/paramcoders/SchemaVerifier.js +8 -9
- package/dist/utils/paramcoders/server/ServerParamDecoder.js +1 -1
- package/dist/utils/paramcoders/server/ServerParamEncoder.js +3 -14
- package/dist/wallets/IBitcoinWallet.d.ts +4 -5
- package/dist/wallets/ILightningWallet.d.ts +20 -21
- package/dist/wallets/ILightningWallet.js +1 -1
- package/package.json +4 -6
- package/src/plugins/IPlugin.ts +28 -29
- package/src/plugins/PluginManager.ts +21 -22
- package/src/prices/BinanceSwapPrice.ts +3 -4
- package/src/prices/CoinGeckoSwapPrice.ts +4 -5
- package/src/prices/OKXSwapPrice.ts +3 -4
- package/src/storage/IIntermediaryStorage.ts +4 -5
- package/src/storagemanager/IntermediaryStorageManager.ts +17 -9
- package/src/swaps/FromBtcBaseSwap.ts +9 -10
- package/src/swaps/FromBtcBaseSwapHandler.ts +133 -91
- package/src/swaps/FromBtcLnBaseSwapHandler.ts +2 -3
- package/src/swaps/ISwapPrice.ts +10 -20
- package/src/swaps/SwapHandler.ts +101 -35
- package/src/swaps/SwapHandlerSwap.ts +42 -17
- package/src/swaps/ToBtcBaseSwap.ts +20 -18
- package/src/swaps/ToBtcBaseSwapHandler.ts +33 -33
- package/src/swaps/frombtc_abstract/FromBtcAbs.ts +64 -97
- package/src/swaps/frombtc_abstract/FromBtcSwapAbs.ts +7 -8
- package/src/swaps/frombtc_trusted/FromBtcTrusted.ts +56 -55
- package/src/swaps/frombtc_trusted/FromBtcTrustedSwap.ts +28 -21
- package/src/swaps/frombtcln_abstract/FromBtcLnAbs.ts +81 -116
- package/src/swaps/frombtcln_abstract/FromBtcLnSwapAbs.ts +73 -9
- package/src/swaps/frombtcln_trusted/FromBtcLnTrusted.ts +39 -36
- package/src/swaps/frombtcln_trusted/FromBtcLnTrustedSwap.ts +26 -12
- package/src/swaps/tobtc_abstract/ToBtcAbs.ts +82 -98
- package/src/swaps/tobtc_abstract/ToBtcSwapAbs.ts +25 -20
- package/src/swaps/tobtcln_abstract/ToBtcLnAbs.ts +106 -118
- package/src/swaps/tobtcln_abstract/ToBtcLnSwapAbs.ts +17 -9
- package/src/utils/Utils.ts +3 -4
- package/src/utils/paramcoders/ParamDecoder.ts +5 -5
- package/src/utils/paramcoders/SchemaVerifier.ts +10 -11
- package/src/utils/paramcoders/server/ServerParamDecoder.ts +1 -1
- package/src/wallets/IBitcoinWallet.ts +4 -5
- package/src/wallets/ILightningWallet.ts +21 -22
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as BN from "bn.js";
|
|
2
1
|
import { SwapData } from "@atomiqlabs/base";
|
|
3
2
|
import { ToBtcBaseSwap } from "../ToBtcBaseSwap";
|
|
4
3
|
export declare enum ToBtcLnSwapState {
|
|
@@ -11,10 +10,12 @@ export declare enum ToBtcLnSwapState {
|
|
|
11
10
|
CLAIMED = 3
|
|
12
11
|
}
|
|
13
12
|
export declare class ToBtcLnSwapAbs<T extends SwapData = SwapData> extends ToBtcBaseSwap<T, ToBtcLnSwapState> {
|
|
13
|
+
lnPaymentHash: string;
|
|
14
14
|
readonly pr: string;
|
|
15
15
|
secret: string;
|
|
16
|
-
constructor(chainIdentifier: string, pr: string, amountMtokens:
|
|
16
|
+
constructor(chainIdentifier: string, lnPaymentHash: string, pr: string, amountMtokens: bigint, swapFee: bigint, swapFeeInToken: bigint, quotedNetworkFee: bigint, quotedNetworkFeeInToken: bigint);
|
|
17
17
|
constructor(obj: any);
|
|
18
|
+
getIdentifierHash(): string;
|
|
18
19
|
serialize(): any;
|
|
19
20
|
isInitiated(): boolean;
|
|
20
21
|
isFailed(): boolean;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ToBtcLnSwapAbs = exports.ToBtcLnSwapState = void 0;
|
|
4
|
-
const BN = require("bn.js");
|
|
5
4
|
const __1 = require("../..");
|
|
6
5
|
const Utils_1 = require("../../utils/Utils");
|
|
7
6
|
const ToBtcBaseSwap_1 = require("../ToBtcBaseSwap");
|
|
@@ -16,26 +15,31 @@ var ToBtcLnSwapState;
|
|
|
16
15
|
ToBtcLnSwapState[ToBtcLnSwapState["CLAIMED"] = 3] = "CLAIMED";
|
|
17
16
|
})(ToBtcLnSwapState = exports.ToBtcLnSwapState || (exports.ToBtcLnSwapState = {}));
|
|
18
17
|
class ToBtcLnSwapAbs extends ToBtcBaseSwap_1.ToBtcBaseSwap {
|
|
19
|
-
constructor(chainIdOrObj, pr, amount, swapFee, swapFeeInToken, quotedNetworkFee, quotedNetworkFeeInToken) {
|
|
20
|
-
var _a, _b;
|
|
18
|
+
constructor(chainIdOrObj, lnPaymentHash, pr, amount, swapFee, swapFeeInToken, quotedNetworkFee, quotedNetworkFeeInToken) {
|
|
21
19
|
if (typeof (chainIdOrObj) === "string") {
|
|
22
|
-
super(chainIdOrObj, amount
|
|
20
|
+
super(chainIdOrObj, (amount + 999n) / 1000n, swapFee, swapFeeInToken, quotedNetworkFee, quotedNetworkFeeInToken);
|
|
23
21
|
this.state = ToBtcLnSwapState.SAVED;
|
|
22
|
+
this.lnPaymentHash = lnPaymentHash;
|
|
24
23
|
this.pr = pr;
|
|
25
24
|
}
|
|
26
25
|
else {
|
|
27
26
|
super(chainIdOrObj);
|
|
28
27
|
this.pr = chainIdOrObj.pr;
|
|
29
28
|
this.secret = chainIdOrObj.secret;
|
|
29
|
+
this.lnPaymentHash = chainIdOrObj.lnPaymentHash;
|
|
30
30
|
//Compatibility with older versions
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
this.quotedNetworkFee ?? (this.quotedNetworkFee = (0, Utils_1.deserializeBN)(chainIdOrObj.maxFee));
|
|
32
|
+
this.realNetworkFee ?? (this.realNetworkFee = (0, Utils_1.deserializeBN)(chainIdOrObj.realRoutingFee));
|
|
33
33
|
}
|
|
34
34
|
this.type = __1.SwapHandlerType.TO_BTCLN;
|
|
35
35
|
}
|
|
36
|
+
getIdentifierHash() {
|
|
37
|
+
return this.lnPaymentHash;
|
|
38
|
+
}
|
|
36
39
|
serialize() {
|
|
37
40
|
const partialSerialized = super.serialize();
|
|
38
41
|
partialSerialized.pr = this.pr;
|
|
42
|
+
partialSerialized.lnPaymentHash = this.lnPaymentHash;
|
|
39
43
|
partialSerialized.secret = this.secret;
|
|
40
44
|
return partialSerialized;
|
|
41
45
|
}
|
package/dist/utils/Utils.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Request, Response } from "express";
|
|
2
2
|
import { ServerParamEncoder } from "./paramcoders/server/ServerParamEncoder";
|
|
3
|
-
import * as BN from "bn.js";
|
|
4
3
|
export type DefinedRuntimeError = {
|
|
5
4
|
code: number;
|
|
6
5
|
msg?: string;
|
|
@@ -18,5 +17,5 @@ export declare function getLogger(prefix: string): {
|
|
|
18
17
|
error: (msg: any, ...args: any[]) => void;
|
|
19
18
|
};
|
|
20
19
|
export declare const HEX_REGEX: RegExp;
|
|
21
|
-
export declare function serializeBN(bn:
|
|
22
|
-
export declare function deserializeBN(str: string | null):
|
|
20
|
+
export declare function serializeBN(bn: bigint | null): string | null;
|
|
21
|
+
export declare function deserializeBN(str: string | null): bigint | null;
|
package/dist/utils/Utils.js
CHANGED
|
@@ -1,16 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.deserializeBN = exports.serializeBN = exports.HEX_REGEX = exports.getLogger = exports.expressHandlerWrapper = exports.isDefinedRuntimeError = void 0;
|
|
13
|
-
const BN = require("bn.js");
|
|
14
4
|
function isDefinedRuntimeError(obj) {
|
|
15
5
|
if (obj.code != null && typeof (obj.code) === "number") {
|
|
16
6
|
if (obj.msg != null && typeof (obj.msg) !== "string")
|
|
@@ -24,9 +14,9 @@ function isDefinedRuntimeError(obj) {
|
|
|
24
14
|
exports.isDefinedRuntimeError = isDefinedRuntimeError;
|
|
25
15
|
function expressHandlerWrapper(func) {
|
|
26
16
|
return (req, res) => {
|
|
27
|
-
(() =>
|
|
17
|
+
(async () => {
|
|
28
18
|
try {
|
|
29
|
-
|
|
19
|
+
await func(req, res);
|
|
30
20
|
}
|
|
31
21
|
catch (e) {
|
|
32
22
|
console.error(e);
|
|
@@ -52,7 +42,7 @@ function expressHandlerWrapper(func) {
|
|
|
52
42
|
res.status(statusCode).json(obj);
|
|
53
43
|
}
|
|
54
44
|
}
|
|
55
|
-
})
|
|
45
|
+
})();
|
|
56
46
|
};
|
|
57
47
|
}
|
|
58
48
|
exports.expressHandlerWrapper = expressHandlerWrapper;
|
|
@@ -71,6 +61,6 @@ function serializeBN(bn) {
|
|
|
71
61
|
}
|
|
72
62
|
exports.serializeBN = serializeBN;
|
|
73
63
|
function deserializeBN(str) {
|
|
74
|
-
return str == null ? null :
|
|
64
|
+
return str == null ? null : BigInt(str);
|
|
75
65
|
}
|
|
76
66
|
exports.deserializeBN = deserializeBN;
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.LegacyParamEncoder = void 0;
|
|
13
4
|
class LegacyParamEncoder {
|
|
@@ -23,11 +14,9 @@ class LegacyParamEncoder {
|
|
|
23
14
|
}
|
|
24
15
|
return Promise.resolve();
|
|
25
16
|
}
|
|
26
|
-
end() {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
yield this.endFN();
|
|
30
|
-
});
|
|
17
|
+
async end() {
|
|
18
|
+
await this.writeFN(Buffer.from(JSON.stringify(this.obj)));
|
|
19
|
+
await this.endFN();
|
|
31
20
|
}
|
|
32
21
|
}
|
|
33
22
|
exports.LegacyParamEncoder = LegacyParamEncoder;
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.ParamDecoder = void 0;
|
|
13
4
|
const SchemaVerifier_1 = require("./SchemaVerifier");
|
|
@@ -123,65 +114,62 @@ class ParamDecoder {
|
|
|
123
114
|
}
|
|
124
115
|
return this.params[key].promise;
|
|
125
116
|
}
|
|
126
|
-
getParams(schema) {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
resultSchema[fieldName] = val;
|
|
157
|
-
}
|
|
158
|
-
else if (type === SchemaVerifier_1.FieldTypeEnum.BN || type === SchemaVerifier_1.FieldTypeEnum.BNOptional) {
|
|
159
|
-
const result = (0, SchemaVerifier_1.parseBN)(val);
|
|
160
|
-
if (result == null)
|
|
161
|
-
return null;
|
|
162
|
-
resultSchema[fieldName] = result;
|
|
163
|
-
}
|
|
164
|
-
else if (type === SchemaVerifier_1.FieldTypeEnum.String || type === SchemaVerifier_1.FieldTypeEnum.StringOptional) {
|
|
165
|
-
if (typeof (val) !== "string")
|
|
166
|
-
return null;
|
|
167
|
-
resultSchema[fieldName] = val;
|
|
168
|
-
}
|
|
169
|
-
else {
|
|
170
|
-
//Probably another request schema
|
|
171
|
-
const result = (0, SchemaVerifier_1.verifySchema)(val, type);
|
|
172
|
-
if (result == null)
|
|
173
|
-
return null;
|
|
174
|
-
resultSchema[fieldName] = result;
|
|
175
|
-
}
|
|
117
|
+
async getParams(schema) {
|
|
118
|
+
const resultSchema = {};
|
|
119
|
+
for (let fieldName in schema) {
|
|
120
|
+
const val = await this.getParam(fieldName);
|
|
121
|
+
const type = schema[fieldName];
|
|
122
|
+
if (typeof (type) === "function") {
|
|
123
|
+
const result = type(val);
|
|
124
|
+
if (result == null)
|
|
125
|
+
return null;
|
|
126
|
+
resultSchema[fieldName] = result;
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
if (val == null && type >= 100) {
|
|
130
|
+
resultSchema[fieldName] = null;
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
if (type === SchemaVerifier_1.FieldTypeEnum.Any || type === SchemaVerifier_1.FieldTypeEnum.AnyOptional) {
|
|
134
|
+
resultSchema[fieldName] = val;
|
|
135
|
+
}
|
|
136
|
+
else if (type === SchemaVerifier_1.FieldTypeEnum.Boolean || type === SchemaVerifier_1.FieldTypeEnum.BooleanOptional) {
|
|
137
|
+
if (typeof (val) !== "boolean")
|
|
138
|
+
return null;
|
|
139
|
+
resultSchema[fieldName] = val;
|
|
140
|
+
}
|
|
141
|
+
else if (type === SchemaVerifier_1.FieldTypeEnum.Number || type === SchemaVerifier_1.FieldTypeEnum.NumberOptional) {
|
|
142
|
+
if (typeof (val) !== "number")
|
|
143
|
+
return null;
|
|
144
|
+
if (isNaN(val))
|
|
145
|
+
return null;
|
|
146
|
+
resultSchema[fieldName] = val;
|
|
176
147
|
}
|
|
177
|
-
|
|
178
|
-
|
|
148
|
+
else if (type === SchemaVerifier_1.FieldTypeEnum.BigInt || type === SchemaVerifier_1.FieldTypeEnum.BigIntOptional) {
|
|
149
|
+
const result = (0, SchemaVerifier_1.parseBigInt)(val);
|
|
150
|
+
if (result == null)
|
|
151
|
+
return null;
|
|
152
|
+
resultSchema[fieldName] = result;
|
|
153
|
+
}
|
|
154
|
+
else if (type === SchemaVerifier_1.FieldTypeEnum.String || type === SchemaVerifier_1.FieldTypeEnum.StringOptional) {
|
|
155
|
+
if (typeof (val) !== "string")
|
|
156
|
+
return null;
|
|
157
|
+
resultSchema[fieldName] = val;
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
//Probably another request schema
|
|
161
|
+
const result = (0, SchemaVerifier_1.verifySchema)(val, type);
|
|
162
|
+
if (result == null)
|
|
163
|
+
return null;
|
|
164
|
+
resultSchema[fieldName] = result;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return resultSchema;
|
|
179
168
|
}
|
|
180
169
|
getExistingParamsOrNull(schema) {
|
|
181
|
-
var _a;
|
|
182
170
|
const resultSchema = {};
|
|
183
171
|
for (let fieldName in schema) {
|
|
184
|
-
const val =
|
|
172
|
+
const val = this.params[fieldName]?.value;
|
|
185
173
|
if (val == null) {
|
|
186
174
|
resultSchema[fieldName] = null;
|
|
187
175
|
continue;
|
|
@@ -209,8 +197,8 @@ class ParamDecoder {
|
|
|
209
197
|
return null;
|
|
210
198
|
resultSchema[fieldName] = val;
|
|
211
199
|
}
|
|
212
|
-
else if (type === SchemaVerifier_1.FieldTypeEnum.
|
|
213
|
-
const result = (0, SchemaVerifier_1.
|
|
200
|
+
else if (type === SchemaVerifier_1.FieldTypeEnum.BigInt || type === SchemaVerifier_1.FieldTypeEnum.BigIntOptional) {
|
|
201
|
+
const result = (0, SchemaVerifier_1.parseBigInt)(val);
|
|
214
202
|
if (result == null)
|
|
215
203
|
return null;
|
|
216
204
|
resultSchema[fieldName] = result;
|
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
export declare function parseBN(str: string | number): BN | null;
|
|
1
|
+
export declare function parseBigInt(str: string | number): bigint | null;
|
|
3
2
|
export declare enum FieldTypeEnum {
|
|
4
3
|
String = 0,
|
|
5
4
|
Boolean = 1,
|
|
6
5
|
Number = 2,
|
|
7
|
-
|
|
6
|
+
BigInt = 3,
|
|
8
7
|
Any = 4,
|
|
9
8
|
StringOptional = 100,
|
|
10
9
|
BooleanOptional = 101,
|
|
11
10
|
NumberOptional = 102,
|
|
12
|
-
|
|
11
|
+
BigIntOptional = 103,
|
|
13
12
|
AnyOptional = 104
|
|
14
13
|
}
|
|
15
|
-
export type FieldType<T extends FieldTypeEnum | RequestSchema | ((val: any) => (string | boolean | number |
|
|
14
|
+
export type FieldType<T extends FieldTypeEnum | RequestSchema | ((val: any) => (string | boolean | number | bigint | any))> = T extends FieldTypeEnum.String ? string : T extends FieldTypeEnum.Boolean ? boolean : T extends FieldTypeEnum.Number ? number : T extends FieldTypeEnum.BigInt ? bigint : T extends FieldTypeEnum.Any ? any : T extends FieldTypeEnum.StringOptional ? string : T extends FieldTypeEnum.BooleanOptional ? boolean : T extends FieldTypeEnum.NumberOptional ? number : T extends FieldTypeEnum.BigIntOptional ? bigint : T extends FieldTypeEnum.AnyOptional ? any : T extends RequestSchema ? RequestSchemaResult<T> : T extends ((val: any) => string) ? string : T extends ((val: any) => boolean) ? boolean : T extends ((val: any) => number) ? number : T extends ((val: any) => bigint) ? bigint : T extends ((val: any) => any) ? any : never;
|
|
16
15
|
export type RequestSchemaResult<T extends RequestSchema> = {
|
|
17
16
|
[key in keyof T]: FieldType<T[key]>;
|
|
18
17
|
};
|
|
@@ -1,31 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.verifySchema = exports.FieldTypeEnum = exports.
|
|
4
|
-
|
|
5
|
-
function parseBN(str) {
|
|
3
|
+
exports.verifySchema = exports.FieldTypeEnum = exports.parseBigInt = void 0;
|
|
4
|
+
function parseBigInt(str) {
|
|
6
5
|
if (str == null)
|
|
7
6
|
return null;
|
|
8
7
|
if (typeof (str) !== "string" && typeof (str) !== "number")
|
|
9
8
|
return null;
|
|
10
9
|
try {
|
|
11
|
-
return
|
|
10
|
+
return BigInt(str);
|
|
12
11
|
}
|
|
13
12
|
catch (e) {
|
|
14
13
|
return null;
|
|
15
14
|
}
|
|
16
15
|
}
|
|
17
|
-
exports.
|
|
16
|
+
exports.parseBigInt = parseBigInt;
|
|
18
17
|
var FieldTypeEnum;
|
|
19
18
|
(function (FieldTypeEnum) {
|
|
20
19
|
FieldTypeEnum[FieldTypeEnum["String"] = 0] = "String";
|
|
21
20
|
FieldTypeEnum[FieldTypeEnum["Boolean"] = 1] = "Boolean";
|
|
22
21
|
FieldTypeEnum[FieldTypeEnum["Number"] = 2] = "Number";
|
|
23
|
-
FieldTypeEnum[FieldTypeEnum["
|
|
22
|
+
FieldTypeEnum[FieldTypeEnum["BigInt"] = 3] = "BigInt";
|
|
24
23
|
FieldTypeEnum[FieldTypeEnum["Any"] = 4] = "Any";
|
|
25
24
|
FieldTypeEnum[FieldTypeEnum["StringOptional"] = 100] = "StringOptional";
|
|
26
25
|
FieldTypeEnum[FieldTypeEnum["BooleanOptional"] = 101] = "BooleanOptional";
|
|
27
26
|
FieldTypeEnum[FieldTypeEnum["NumberOptional"] = 102] = "NumberOptional";
|
|
28
|
-
FieldTypeEnum[FieldTypeEnum["
|
|
27
|
+
FieldTypeEnum[FieldTypeEnum["BigIntOptional"] = 103] = "BigIntOptional";
|
|
29
28
|
FieldTypeEnum[FieldTypeEnum["AnyOptional"] = 104] = "AnyOptional";
|
|
30
29
|
})(FieldTypeEnum = exports.FieldTypeEnum || (exports.FieldTypeEnum = {}));
|
|
31
30
|
function verifySchema(req, schema) {
|
|
@@ -61,8 +60,8 @@ function verifySchema(req, schema) {
|
|
|
61
60
|
return null;
|
|
62
61
|
resultSchema[fieldName] = val;
|
|
63
62
|
}
|
|
64
|
-
else if (type === FieldTypeEnum.
|
|
65
|
-
const result =
|
|
63
|
+
else if (type === FieldTypeEnum.BigInt || type === FieldTypeEnum.BigIntOptional) {
|
|
64
|
+
const result = parseBigInt(val);
|
|
66
65
|
if (result == null)
|
|
67
66
|
return null;
|
|
68
67
|
resultSchema[fieldName] = result;
|
|
@@ -30,7 +30,7 @@ const serverParamDecoder = (timeoutMillis) => (req, res, next) => {
|
|
|
30
30
|
});
|
|
31
31
|
req.on("end", () => {
|
|
32
32
|
try {
|
|
33
|
-
const body = JSON.parse(Buffer.concat(dataBuffers).toString());
|
|
33
|
+
const body = dataBuffers.length === 0 ? {} : JSON.parse(Buffer.concat(dataBuffers).toString());
|
|
34
34
|
const paramReader = {
|
|
35
35
|
getParams: (schema) => {
|
|
36
36
|
return Promise.resolve((0, SchemaVerifier_1.verifySchema)(body, schema));
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.ServerParamEncoder = void 0;
|
|
13
4
|
const ParamEncoder_1 = require("../ParamEncoder");
|
|
@@ -63,11 +54,9 @@ class ServerParamEncoder {
|
|
|
63
54
|
end() {
|
|
64
55
|
return this.paramWriter.end();
|
|
65
56
|
}
|
|
66
|
-
writeParamsAndEnd(params) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
yield this.end();
|
|
70
|
-
});
|
|
57
|
+
async writeParamsAndEnd(params) {
|
|
58
|
+
await this.writeParams(params);
|
|
59
|
+
await this.end();
|
|
71
60
|
}
|
|
72
61
|
getAbortSignal() {
|
|
73
62
|
return this.controller.signal;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import BN from "bn.js";
|
|
3
|
-
import { Psbt, Transaction } from "bitcoinjs-lib";
|
|
4
2
|
import { BtcTx } from "@atomiqlabs/base";
|
|
5
3
|
import { Command } from "@atomiqlabs/server-base";
|
|
4
|
+
import { Transaction } from "@scure/btc-signer";
|
|
6
5
|
export type BitcoinUtxo = {
|
|
7
6
|
address: string;
|
|
8
7
|
type: "p2wpkh" | "p2sh-p2wpkh" | "p2tr";
|
|
@@ -13,7 +12,7 @@ export type BitcoinUtxo = {
|
|
|
13
12
|
vout: number;
|
|
14
13
|
};
|
|
15
14
|
export type SignPsbtResponse = {
|
|
16
|
-
psbt:
|
|
15
|
+
psbt: Transaction;
|
|
17
16
|
tx: Transaction;
|
|
18
17
|
raw: string;
|
|
19
18
|
txId: string;
|
|
@@ -48,9 +47,9 @@ export interface IBitcoinWallet {
|
|
|
48
47
|
getWalletTransactions(startHeight?: number): Promise<BtcTx[]>;
|
|
49
48
|
getWalletTransaction(txId: string): Promise<BtcTx | null>;
|
|
50
49
|
subscribeToWalletTransactions(callback: (tx: BtcTx) => void, abortSignal?: AbortSignal): void;
|
|
51
|
-
signPsbt(psbt:
|
|
50
|
+
signPsbt(psbt: Transaction): Promise<SignPsbtResponse>;
|
|
52
51
|
sendRawTransaction(tx: string): Promise<void>;
|
|
53
|
-
getSignedTransaction(destination: string, amount: number, feeRate?: number, nonce?:
|
|
52
|
+
getSignedTransaction(destination: string, amount: number, feeRate?: number, nonce?: bigint, maxAllowedFeeRate?: number): Promise<SignPsbtResponse>;
|
|
54
53
|
estimateFee(destination: string, amount: number, feeRate?: number, feeRateMultiplier?: number): Promise<{
|
|
55
54
|
satsPerVbyte: number;
|
|
56
55
|
networkFee: number;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as BN from "bn.js";
|
|
2
1
|
import { Command } from "@atomiqlabs/server-base";
|
|
3
2
|
export type IncomingLightningNetworkPayment = {
|
|
4
3
|
createdAt: number;
|
|
@@ -6,14 +5,14 @@ export type IncomingLightningNetworkPayment = {
|
|
|
6
5
|
createdHeight: number;
|
|
7
6
|
timeout: number;
|
|
8
7
|
status: "held" | "canceled" | "confirmed";
|
|
9
|
-
mtokens:
|
|
8
|
+
mtokens: bigint;
|
|
10
9
|
};
|
|
11
10
|
export type LightningNetworkInvoice = {
|
|
12
11
|
id: string;
|
|
13
12
|
request: string;
|
|
14
13
|
secret?: string;
|
|
15
14
|
cltvDelta: number;
|
|
16
|
-
mtokens:
|
|
15
|
+
mtokens: bigint;
|
|
17
16
|
createdAt: number;
|
|
18
17
|
expiresAt: number;
|
|
19
18
|
description: string;
|
|
@@ -25,22 +24,22 @@ export type OutgoingLightningNetworkPayment = {
|
|
|
25
24
|
failedReason?: "insufficient_balance" | "invalid_payment" | "pathfinding_timeout" | "route_not_found";
|
|
26
25
|
status: "confirmed" | "failed" | "pending";
|
|
27
26
|
secret?: string;
|
|
28
|
-
feeMtokens?:
|
|
27
|
+
feeMtokens?: bigint;
|
|
29
28
|
};
|
|
30
29
|
export type LightningNetworkChannel = {
|
|
31
30
|
id: string;
|
|
32
|
-
capacity:
|
|
31
|
+
capacity: bigint;
|
|
33
32
|
isActive: boolean;
|
|
34
|
-
localBalance:
|
|
35
|
-
localReserve:
|
|
36
|
-
remoteBalance:
|
|
37
|
-
remoteReserve:
|
|
38
|
-
unsettledBalance:
|
|
33
|
+
localBalance: bigint;
|
|
34
|
+
localReserve: bigint;
|
|
35
|
+
remoteBalance: bigint;
|
|
36
|
+
remoteReserve: bigint;
|
|
37
|
+
unsettledBalance: bigint;
|
|
39
38
|
transactionId: string;
|
|
40
39
|
transactionVout: number;
|
|
41
40
|
};
|
|
42
41
|
export type InvoiceInit = {
|
|
43
|
-
mtokens:
|
|
42
|
+
mtokens: bigint;
|
|
44
43
|
descriptionHash?: string;
|
|
45
44
|
description?: string;
|
|
46
45
|
cltvDelta?: number;
|
|
@@ -51,7 +50,7 @@ export type HodlInvoiceInit = {
|
|
|
51
50
|
cltvDelta: number;
|
|
52
51
|
expiresAt: number;
|
|
53
52
|
id: string;
|
|
54
|
-
mtokens:
|
|
53
|
+
mtokens: bigint;
|
|
55
54
|
descriptionHash?: string;
|
|
56
55
|
};
|
|
57
56
|
export type LNRoutes = {
|
|
@@ -59,11 +58,11 @@ export type LNRoutes = {
|
|
|
59
58
|
feeRate?: number;
|
|
60
59
|
cltvDelta?: number;
|
|
61
60
|
channel?: string;
|
|
62
|
-
baseFeeMtokens?:
|
|
61
|
+
baseFeeMtokens?: bigint;
|
|
63
62
|
}[][];
|
|
64
63
|
export type ParsedPaymentRequest = {
|
|
65
64
|
id: string;
|
|
66
|
-
mtokens:
|
|
65
|
+
mtokens: bigint;
|
|
67
66
|
expiryEpochMillis: number;
|
|
68
67
|
destination: string;
|
|
69
68
|
cltvDelta: number;
|
|
@@ -72,23 +71,23 @@ export type ParsedPaymentRequest = {
|
|
|
72
71
|
};
|
|
73
72
|
export type LightningPaymentInit = {
|
|
74
73
|
request: string;
|
|
75
|
-
maxFeeMtokens?:
|
|
74
|
+
maxFeeMtokens?: bigint;
|
|
76
75
|
maxTimeoutHeight?: number;
|
|
77
76
|
};
|
|
78
77
|
export type LightningBalanceResponse = {
|
|
79
|
-
localBalance:
|
|
80
|
-
remoteBalance:
|
|
81
|
-
unsettledBalance:
|
|
78
|
+
localBalance: bigint;
|
|
79
|
+
remoteBalance: bigint;
|
|
80
|
+
unsettledBalance: bigint;
|
|
82
81
|
};
|
|
83
82
|
export type ProbeAndRouteInit = {
|
|
84
83
|
request: string;
|
|
85
|
-
amountMtokens:
|
|
86
|
-
maxFeeMtokens:
|
|
84
|
+
amountMtokens: bigint;
|
|
85
|
+
maxFeeMtokens: bigint;
|
|
87
86
|
maxTimeoutHeight: number;
|
|
88
87
|
};
|
|
89
88
|
export type ProbeAndRouteResponse = {
|
|
90
89
|
confidence: number;
|
|
91
|
-
feeMtokens:
|
|
90
|
+
feeMtokens: bigint;
|
|
92
91
|
destination: string;
|
|
93
92
|
privateRoutes: LNRoutes;
|
|
94
93
|
};
|
|
@@ -24,7 +24,7 @@ function routesMatch(routesA, routesB) {
|
|
|
24
24
|
return false;
|
|
25
25
|
}
|
|
26
26
|
if (routesA[i][e].publicKey !== routesB[i][e].publicKey ||
|
|
27
|
-
|
|
27
|
+
routesA[i][e].baseFeeMtokens !== routesB[i][e].baseFeeMtokens ||
|
|
28
28
|
routesA[i][e].channel !== routesB[i][e].channel ||
|
|
29
29
|
routesA[i][e].cltvDelta !== routesB[i][e].cltvDelta ||
|
|
30
30
|
routesA[i][e].feeRate !== routesB[i][e].feeRate) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atomiqlabs/lp-lib",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "12.0.0-beta.0",
|
|
4
4
|
"description": "Main functionality implementation for atomiq LP node",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types:": "./dist/index.d.ts",
|
|
@@ -22,15 +22,13 @@
|
|
|
22
22
|
"author": "adambor",
|
|
23
23
|
"license": "ISC",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@atomiqlabs/base": "
|
|
26
|
-
"@atomiqlabs/server-base": "
|
|
27
|
-
"
|
|
28
|
-
"bn.js": "5.2.1",
|
|
25
|
+
"@atomiqlabs/base": "8.0.0-beta.0",
|
|
26
|
+
"@atomiqlabs/server-base": "2.0.0",
|
|
27
|
+
"@scure/btc-signer": "1.6.0",
|
|
29
28
|
"express": "4.21.1",
|
|
30
29
|
"promise-queue-ts": "0.0.1"
|
|
31
30
|
},
|
|
32
31
|
"devDependencies": {
|
|
33
|
-
"@types/bn.js": "5.1.5",
|
|
34
32
|
"@types/express": "4.17.21",
|
|
35
33
|
"@types/node": "18.15.11",
|
|
36
34
|
"typescript": "4.9.5"
|