@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.
Files changed (100) hide show
  1. package/dist/info/InfoHandler.js +3 -12
  2. package/dist/plugins/IPlugin.d.ts +34 -35
  3. package/dist/plugins/IPlugin.js +7 -8
  4. package/dist/plugins/PluginManager.d.ts +29 -30
  5. package/dist/plugins/PluginManager.js +160 -188
  6. package/dist/prices/BinanceSwapPrice.d.ts +1 -2
  7. package/dist/prices/BinanceSwapPrice.js +56 -70
  8. package/dist/prices/CoinGeckoSwapPrice.d.ts +2 -3
  9. package/dist/prices/CoinGeckoSwapPrice.js +30 -42
  10. package/dist/prices/OKXSwapPrice.d.ts +1 -2
  11. package/dist/prices/OKXSwapPrice.js +56 -70
  12. package/dist/storage/IIntermediaryStorage.d.ts +8 -5
  13. package/dist/storagemanager/IntermediaryStorageManager.d.ts +8 -5
  14. package/dist/storagemanager/IntermediaryStorageManager.js +52 -61
  15. package/dist/storagemanager/StorageManager.js +42 -59
  16. package/dist/swaps/FromBtcBaseSwap.d.ts +7 -8
  17. package/dist/swaps/FromBtcBaseSwap.js +2 -3
  18. package/dist/swaps/FromBtcBaseSwapHandler.d.ts +44 -31
  19. package/dist/swaps/FromBtcBaseSwapHandler.js +217 -196
  20. package/dist/swaps/FromBtcLnBaseSwapHandler.d.ts +1 -2
  21. package/dist/swaps/FromBtcLnBaseSwapHandler.js +13 -24
  22. package/dist/swaps/ISwapPrice.d.ts +4 -5
  23. package/dist/swaps/ISwapPrice.js +8 -30
  24. package/dist/swaps/SwapHandler.d.ts +26 -15
  25. package/dist/swaps/SwapHandler.js +107 -66
  26. package/dist/swaps/SwapHandlerSwap.d.ts +22 -11
  27. package/dist/swaps/SwapHandlerSwap.js +32 -8
  28. package/dist/swaps/ToBtcBaseSwap.d.ts +16 -17
  29. package/dist/swaps/ToBtcBaseSwap.js +4 -4
  30. package/dist/swaps/ToBtcBaseSwapHandler.d.ts +17 -17
  31. package/dist/swaps/ToBtcBaseSwapHandler.js +140 -155
  32. package/dist/swaps/frombtc_abstract/FromBtcAbs.d.ts +8 -15
  33. package/dist/swaps/frombtc_abstract/FromBtcAbs.js +131 -196
  34. package/dist/swaps/frombtc_abstract/FromBtcSwapAbs.d.ts +3 -5
  35. package/dist/swaps/frombtc_abstract/FromBtcSwapAbs.js +4 -4
  36. package/dist/swaps/frombtc_trusted/FromBtcTrusted.d.ts +10 -8
  37. package/dist/swaps/frombtc_trusted/FromBtcTrusted.js +330 -362
  38. package/dist/swaps/frombtc_trusted/FromBtcTrustedSwap.d.ts +10 -10
  39. package/dist/swaps/frombtc_trusted/FromBtcTrustedSwap.js +7 -4
  40. package/dist/swaps/frombtcln_abstract/FromBtcLnAbs.d.ts +8 -8
  41. package/dist/swaps/frombtcln_abstract/FromBtcLnAbs.js +330 -400
  42. package/dist/swaps/frombtcln_abstract/FromBtcLnSwapAbs.d.ts +10 -4
  43. package/dist/swaps/frombtcln_abstract/FromBtcLnSwapAbs.js +36 -6
  44. package/dist/swaps/frombtcln_trusted/FromBtcLnTrusted.d.ts +8 -7
  45. package/dist/swaps/frombtcln_trusted/FromBtcLnTrusted.js +251 -273
  46. package/dist/swaps/frombtcln_trusted/FromBtcLnTrustedSwap.d.ts +5 -5
  47. package/dist/swaps/frombtcln_trusted/FromBtcLnTrustedSwap.js +7 -5
  48. package/dist/swaps/tobtc_abstract/ToBtcAbs.d.ts +13 -12
  49. package/dist/swaps/tobtc_abstract/ToBtcAbs.js +261 -323
  50. package/dist/swaps/tobtc_abstract/ToBtcSwapAbs.d.ts +4 -4
  51. package/dist/swaps/tobtc_abstract/ToBtcSwapAbs.js +7 -6
  52. package/dist/swaps/tobtcln_abstract/ToBtcLnAbs.d.ts +22 -21
  53. package/dist/swaps/tobtcln_abstract/ToBtcLnAbs.js +398 -453
  54. package/dist/swaps/tobtcln_abstract/ToBtcLnSwapAbs.d.ts +3 -2
  55. package/dist/swaps/tobtcln_abstract/ToBtcLnSwapAbs.js +10 -6
  56. package/dist/utils/Utils.d.ts +2 -3
  57. package/dist/utils/Utils.js +4 -14
  58. package/dist/utils/paramcoders/LegacyParamEncoder.js +3 -14
  59. package/dist/utils/paramcoders/ParamDecoder.js +53 -65
  60. package/dist/utils/paramcoders/SchemaVerifier.d.ts +4 -5
  61. package/dist/utils/paramcoders/SchemaVerifier.js +8 -9
  62. package/dist/utils/paramcoders/server/ServerParamDecoder.js +1 -1
  63. package/dist/utils/paramcoders/server/ServerParamEncoder.js +3 -14
  64. package/dist/wallets/IBitcoinWallet.d.ts +4 -5
  65. package/dist/wallets/ILightningWallet.d.ts +20 -21
  66. package/dist/wallets/ILightningWallet.js +1 -1
  67. package/package.json +4 -6
  68. package/src/plugins/IPlugin.ts +28 -29
  69. package/src/plugins/PluginManager.ts +21 -22
  70. package/src/prices/BinanceSwapPrice.ts +3 -4
  71. package/src/prices/CoinGeckoSwapPrice.ts +4 -5
  72. package/src/prices/OKXSwapPrice.ts +3 -4
  73. package/src/storage/IIntermediaryStorage.ts +4 -5
  74. package/src/storagemanager/IntermediaryStorageManager.ts +17 -9
  75. package/src/swaps/FromBtcBaseSwap.ts +9 -10
  76. package/src/swaps/FromBtcBaseSwapHandler.ts +133 -91
  77. package/src/swaps/FromBtcLnBaseSwapHandler.ts +2 -3
  78. package/src/swaps/ISwapPrice.ts +10 -20
  79. package/src/swaps/SwapHandler.ts +101 -35
  80. package/src/swaps/SwapHandlerSwap.ts +42 -17
  81. package/src/swaps/ToBtcBaseSwap.ts +20 -18
  82. package/src/swaps/ToBtcBaseSwapHandler.ts +33 -33
  83. package/src/swaps/frombtc_abstract/FromBtcAbs.ts +64 -97
  84. package/src/swaps/frombtc_abstract/FromBtcSwapAbs.ts +7 -8
  85. package/src/swaps/frombtc_trusted/FromBtcTrusted.ts +56 -55
  86. package/src/swaps/frombtc_trusted/FromBtcTrustedSwap.ts +28 -21
  87. package/src/swaps/frombtcln_abstract/FromBtcLnAbs.ts +81 -116
  88. package/src/swaps/frombtcln_abstract/FromBtcLnSwapAbs.ts +73 -9
  89. package/src/swaps/frombtcln_trusted/FromBtcLnTrusted.ts +39 -36
  90. package/src/swaps/frombtcln_trusted/FromBtcLnTrustedSwap.ts +26 -12
  91. package/src/swaps/tobtc_abstract/ToBtcAbs.ts +82 -98
  92. package/src/swaps/tobtc_abstract/ToBtcSwapAbs.ts +25 -20
  93. package/src/swaps/tobtcln_abstract/ToBtcLnAbs.ts +106 -118
  94. package/src/swaps/tobtcln_abstract/ToBtcLnSwapAbs.ts +17 -9
  95. package/src/utils/Utils.ts +3 -4
  96. package/src/utils/paramcoders/ParamDecoder.ts +5 -5
  97. package/src/utils/paramcoders/SchemaVerifier.ts +10 -11
  98. package/src/utils/paramcoders/server/ServerParamDecoder.ts +1 -1
  99. package/src/wallets/IBitcoinWallet.ts +4 -5
  100. 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: BN, swapFee: BN, swapFeeInToken: BN, quotedNetworkFee: BN, quotedNetworkFeeInToken: BN);
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.add(new BN(999)).div(new BN(1000)), swapFee, swapFeeInToken, quotedNetworkFee, quotedNetworkFeeInToken);
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
- (_a = this.quotedNetworkFee) !== null && _a !== void 0 ? _a : (this.quotedNetworkFee = (0, Utils_1.deserializeBN)(chainIdOrObj.maxFee));
32
- (_b = this.realNetworkFee) !== null && _b !== void 0 ? _b : (this.realNetworkFee = (0, Utils_1.deserializeBN)(chainIdOrObj.realRoutingFee));
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
  }
@@ -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: BN | null): string | null;
22
- export declare function deserializeBN(str: string | null): BN | null;
20
+ export declare function serializeBN(bn: bigint | null): string | null;
21
+ export declare function deserializeBN(str: string | null): bigint | null;
@@ -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
- (() => __awaiter(this, void 0, void 0, function* () {
17
+ (async () => {
28
18
  try {
29
- yield func(req, res);
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 : new BN(str);
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
- return __awaiter(this, void 0, void 0, function* () {
28
- yield this.writeFN(Buffer.from(JSON.stringify(this.obj)));
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
- return __awaiter(this, void 0, void 0, function* () {
128
- const resultSchema = {};
129
- for (let fieldName in schema) {
130
- const val = yield this.getParam(fieldName);
131
- const type = schema[fieldName];
132
- if (typeof (type) === "function") {
133
- const result = type(val);
134
- if (result == null)
135
- return null;
136
- resultSchema[fieldName] = result;
137
- continue;
138
- }
139
- if (val == null && type >= 100) {
140
- resultSchema[fieldName] = null;
141
- continue;
142
- }
143
- if (type === SchemaVerifier_1.FieldTypeEnum.Any || type === SchemaVerifier_1.FieldTypeEnum.AnyOptional) {
144
- resultSchema[fieldName] = val;
145
- }
146
- else if (type === SchemaVerifier_1.FieldTypeEnum.Boolean || type === SchemaVerifier_1.FieldTypeEnum.BooleanOptional) {
147
- if (typeof (val) !== "boolean")
148
- return null;
149
- resultSchema[fieldName] = val;
150
- }
151
- else if (type === SchemaVerifier_1.FieldTypeEnum.Number || type === SchemaVerifier_1.FieldTypeEnum.NumberOptional) {
152
- if (typeof (val) !== "number")
153
- return null;
154
- if (isNaN(val))
155
- return null;
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
- return resultSchema;
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 = (_a = this.params[fieldName]) === null || _a === void 0 ? void 0 : _a.value;
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.BN || type === SchemaVerifier_1.FieldTypeEnum.BNOptional) {
213
- const result = (0, SchemaVerifier_1.parseBN)(val);
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
- import * as BN from "bn.js";
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
- BN = 3,
6
+ BigInt = 3,
8
7
  Any = 4,
9
8
  StringOptional = 100,
10
9
  BooleanOptional = 101,
11
10
  NumberOptional = 102,
12
- BNOptional = 103,
11
+ BigIntOptional = 103,
13
12
  AnyOptional = 104
14
13
  }
15
- export type FieldType<T extends FieldTypeEnum | RequestSchema | ((val: any) => (string | boolean | number | BN | any))> = T extends FieldTypeEnum.String ? string : T extends FieldTypeEnum.Boolean ? boolean : T extends FieldTypeEnum.Number ? number : T extends FieldTypeEnum.BN ? BN : T extends FieldTypeEnum.Any ? any : T extends FieldTypeEnum.StringOptional ? string : T extends FieldTypeEnum.BooleanOptional ? boolean : T extends FieldTypeEnum.NumberOptional ? number : T extends FieldTypeEnum.BNOptional ? BN : 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) => BN) ? BN : T extends ((val: any) => any) ? any : never;
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.parseBN = void 0;
4
- const BN = require("bn.js");
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 new BN(str);
10
+ return BigInt(str);
12
11
  }
13
12
  catch (e) {
14
13
  return null;
15
14
  }
16
15
  }
17
- exports.parseBN = parseBN;
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["BN"] = 3] = "BN";
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["BNOptional"] = 103] = "BNOptional";
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.BN || type === FieldTypeEnum.BNOptional) {
65
- const result = parseBN(val);
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
- return __awaiter(this, void 0, void 0, function* () {
68
- yield this.writeParams(params);
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: 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: Psbt): Promise<SignPsbtResponse>;
50
+ signPsbt(psbt: Transaction): Promise<SignPsbtResponse>;
52
51
  sendRawTransaction(tx: string): Promise<void>;
53
- getSignedTransaction(destination: string, amount: number, feeRate?: number, nonce?: BN, maxAllowedFeeRate?: number): Promise<SignPsbtResponse>;
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: BN;
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: BN;
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?: BN;
27
+ feeMtokens?: bigint;
29
28
  };
30
29
  export type LightningNetworkChannel = {
31
30
  id: string;
32
- capacity: BN;
31
+ capacity: bigint;
33
32
  isActive: boolean;
34
- localBalance: BN;
35
- localReserve: BN;
36
- remoteBalance: BN;
37
- remoteReserve: BN;
38
- unsettledBalance: BN;
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: BN;
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: BN;
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?: BN;
61
+ baseFeeMtokens?: bigint;
63
62
  }[][];
64
63
  export type ParsedPaymentRequest = {
65
64
  id: string;
66
- mtokens: BN;
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?: BN;
74
+ maxFeeMtokens?: bigint;
76
75
  maxTimeoutHeight?: number;
77
76
  };
78
77
  export type LightningBalanceResponse = {
79
- localBalance: BN;
80
- remoteBalance: BN;
81
- unsettledBalance: BN;
78
+ localBalance: bigint;
79
+ remoteBalance: bigint;
80
+ unsettledBalance: bigint;
82
81
  };
83
82
  export type ProbeAndRouteInit = {
84
83
  request: string;
85
- amountMtokens: BN;
86
- maxFeeMtokens: BN;
84
+ amountMtokens: bigint;
85
+ maxFeeMtokens: bigint;
87
86
  maxTimeoutHeight: number;
88
87
  };
89
88
  export type ProbeAndRouteResponse = {
90
89
  confidence: number;
91
- feeMtokens: BN;
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
- !routesA[i][e].baseFeeMtokens.eq(routesB[i][e].baseFeeMtokens) ||
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": "11.0.5",
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": "7.2.2",
26
- "@atomiqlabs/server-base": "1.0.5",
27
- "bitcoinjs-lib": "6.1.5",
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"