@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,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
 
5
4
  export type DefinedRuntimeError = {
6
5
  code: number;
@@ -68,10 +67,10 @@ export function getLogger(prefix: string) {
68
67
 
69
68
  export const HEX_REGEX = /[0-9a-fA-F]+/;
70
69
 
71
- export function serializeBN(bn: BN | null): string | null {
70
+ export function serializeBN(bn: bigint | null): string | null {
72
71
  return bn==null ? null : bn.toString(10);
73
72
  }
74
73
 
75
- export function deserializeBN(str: string | null): BN | null {
76
- return str==null ? null : new BN(str);
74
+ export function deserializeBN(str: string | null): bigint | null {
75
+ return str==null ? null : BigInt(str);
77
76
  }
@@ -1,4 +1,4 @@
1
- import {FieldTypeEnum, parseBN, RequestSchema, RequestSchemaResult, verifySchema} from "./SchemaVerifier";
1
+ import {FieldTypeEnum, parseBigInt, RequestSchema, RequestSchemaResult, verifySchema} from "./SchemaVerifier";
2
2
  import {IParamReader} from "./IParamReader";
3
3
 
4
4
 
@@ -155,8 +155,8 @@ export class ParamDecoder implements IParamReader {
155
155
  if(typeof(val)!=="number") return null;
156
156
  if(isNaN(val as number)) return null;
157
157
  resultSchema[fieldName] = val;
158
- } else if(type===FieldTypeEnum.BN || type===FieldTypeEnum.BNOptional) {
159
- const result = parseBN(val);
158
+ } else if(type===FieldTypeEnum.BigInt || type===FieldTypeEnum.BigIntOptional) {
159
+ const result = parseBigInt(val);
160
160
  if(result==null) return null;
161
161
  resultSchema[fieldName] = result;
162
162
  } else if(type===FieldTypeEnum.String || type===FieldTypeEnum.StringOptional) {
@@ -199,8 +199,8 @@ export class ParamDecoder implements IParamReader {
199
199
  if(typeof(val)!=="number") return null;
200
200
  if(isNaN(val as number)) return null;
201
201
  resultSchema[fieldName] = val;
202
- } else if(type===FieldTypeEnum.BN || type===FieldTypeEnum.BNOptional) {
203
- const result = parseBN(val);
202
+ } else if(type===FieldTypeEnum.BigInt || type===FieldTypeEnum.BigIntOptional) {
203
+ const result = parseBigInt(val);
204
204
  if(result==null) return null;
205
205
  resultSchema[fieldName] = result;
206
206
  } else if(type===FieldTypeEnum.String || type===FieldTypeEnum.StringOptional) {
@@ -1,10 +1,9 @@
1
- import * as BN from "bn.js";
2
1
 
3
- export function parseBN(str: string | number): BN | null {
2
+ export function parseBigInt(str: string | number): bigint | null {
4
3
  if(str==null) return null;
5
4
  if(typeof(str)!=="string" && typeof(str)!=="number") return null;
6
5
  try {
7
- return new BN(str);
6
+ return BigInt(str);
8
7
  } catch (e) {
9
8
  return null;
10
9
  }
@@ -14,32 +13,32 @@ export enum FieldTypeEnum {
14
13
  String=0,
15
14
  Boolean=1,
16
15
  Number=2,
17
- BN=3,
16
+ BigInt=3,
18
17
  Any=4,
19
18
 
20
19
  StringOptional=100,
21
20
  BooleanOptional=101,
22
21
  NumberOptional=102,
23
- BNOptional=103,
22
+ BigIntOptional=103,
24
23
  AnyOptional=104,
25
24
  }
26
25
 
27
- export type FieldType<T extends FieldTypeEnum | RequestSchema | ((val: any) => (string | boolean | number | BN | any))> =
26
+ export type FieldType<T extends FieldTypeEnum | RequestSchema | ((val: any) => (string | boolean | number | bigint | any))> =
28
27
  T extends FieldTypeEnum.String ? string :
29
28
  T extends FieldTypeEnum.Boolean ? boolean :
30
29
  T extends FieldTypeEnum.Number ? number :
31
- T extends FieldTypeEnum.BN ? BN :
30
+ T extends FieldTypeEnum.BigInt ? bigint :
32
31
  T extends FieldTypeEnum.Any ? any :
33
32
  T extends FieldTypeEnum.StringOptional ? string :
34
33
  T extends FieldTypeEnum.BooleanOptional ? boolean :
35
34
  T extends FieldTypeEnum.NumberOptional ? number :
36
- T extends FieldTypeEnum.BNOptional ? BN :
35
+ T extends FieldTypeEnum.BigIntOptional ? bigint :
37
36
  T extends FieldTypeEnum.AnyOptional ? any :
38
37
  T extends RequestSchema ? RequestSchemaResult<T> :
39
38
  T extends ((val: any) => string) ? string :
40
39
  T extends ((val: any) => boolean) ? boolean :
41
40
  T extends ((val: any) => number) ? number :
42
- T extends ((val: any) => BN) ? BN :
41
+ T extends ((val: any) => bigint) ? bigint :
43
42
  T extends ((val: any) => any) ? any :
44
43
  never;
45
44
 
@@ -79,8 +78,8 @@ export function verifySchema<T extends RequestSchema>(req: any, schema: T): Requ
79
78
  if(typeof(val)!=="number") return null;
80
79
  if(isNaN(val as number)) return null;
81
80
  resultSchema[fieldName] = val;
82
- } else if(type===FieldTypeEnum.BN || type===FieldTypeEnum.BNOptional) {
83
- const result = parseBN(val);
81
+ } else if(type===FieldTypeEnum.BigInt || type===FieldTypeEnum.BigIntOptional) {
82
+ const result = parseBigInt(val);
84
83
  if(result==null) return null;
85
84
  resultSchema[fieldName] = result;
86
85
  } else if(type===FieldTypeEnum.String || type===FieldTypeEnum.StringOptional) {
@@ -38,7 +38,7 @@ export const serverParamDecoder = (timeoutMillis: number) => (req: Request, res:
38
38
  });
39
39
  req.on("end", () => {
40
40
  try {
41
- const body = JSON.parse(Buffer.concat(dataBuffers).toString());
41
+ const body = dataBuffers.length===0 ? {} : JSON.parse(Buffer.concat(dataBuffers).toString());
42
42
  const paramReader: IParamReader = {
43
43
  getParams: <T extends RequestSchema>(schema: T) => {
44
44
  return Promise.resolve(verifySchema(body, schema));
@@ -1,7 +1,6 @@
1
- import BN from "bn.js";
2
- import {Psbt, Transaction} from "bitcoinjs-lib";
3
1
  import {BtcTx} from "@atomiqlabs/base";
4
2
  import {Command} from "@atomiqlabs/server-base";
3
+ import {Transaction} from "@scure/btc-signer";
5
4
 
6
5
  export type BitcoinUtxo = {
7
6
  address: string,
@@ -14,7 +13,7 @@ export type BitcoinUtxo = {
14
13
  };
15
14
 
16
15
  export type SignPsbtResponse = {
17
- psbt: Psbt,
16
+ psbt: Transaction,
18
17
  tx: Transaction,
19
18
  raw: string,
20
19
  txId: string,
@@ -53,9 +52,9 @@ export interface IBitcoinWallet {
53
52
  getWalletTransaction(txId: string): Promise<BtcTx | null>;
54
53
  subscribeToWalletTransactions(callback: (tx: BtcTx) => void, abortSignal?: AbortSignal): void;
55
54
 
56
- signPsbt(psbt: Psbt): Promise<SignPsbtResponse>;
55
+ signPsbt(psbt: Transaction): Promise<SignPsbtResponse>;
57
56
  sendRawTransaction(tx: string): Promise<void>;
58
- getSignedTransaction(destination: string, amount: number, feeRate?: number, nonce?: BN, maxAllowedFeeRate?: number): Promise<SignPsbtResponse>;
57
+ getSignedTransaction(destination: string, amount: number, feeRate?: number, nonce?: bigint, maxAllowedFeeRate?: number): Promise<SignPsbtResponse>;
59
58
  estimateFee(destination: string, amount: number, feeRate?: number, feeRateMultiplier?: number): Promise<{satsPerVbyte: number, networkFee: number}>;
60
59
  drainAll(destination: string | Buffer, inputs: Omit<BitcoinUtxo, "address">[], feeRate?: number): Promise<SignPsbtResponse>;
61
60
  burnAll(inputs: Omit<BitcoinUtxo, "address">[]): Promise<SignPsbtResponse>;
@@ -1,4 +1,3 @@
1
- import * as BN from "bn.js";
2
1
  import {Command} from "@atomiqlabs/server-base";
3
2
 
4
3
  export type IncomingLightningNetworkPayment = {
@@ -10,7 +9,7 @@ export type IncomingLightningNetworkPayment = {
10
9
 
11
10
  status: "held" | "canceled" | "confirmed"
12
11
 
13
- mtokens: BN
12
+ mtokens: bigint
14
13
  }
15
14
 
16
15
  export type LightningNetworkInvoice = {
@@ -19,7 +18,7 @@ export type LightningNetworkInvoice = {
19
18
  secret?: string,
20
19
 
21
20
  cltvDelta: number,
22
- mtokens: BN,
21
+ mtokens: bigint,
23
22
 
24
23
  createdAt: number,
25
24
  expiresAt: number,
@@ -36,25 +35,25 @@ export type OutgoingLightningNetworkPayment = {
36
35
  failedReason?: "insufficient_balance" | "invalid_payment" | "pathfinding_timeout" | "route_not_found",
37
36
  status: "confirmed" | "failed" | "pending",
38
37
  secret?: string,
39
- feeMtokens?: BN
38
+ feeMtokens?: bigint
40
39
  };
41
40
 
42
41
  export type LightningNetworkChannel = {
43
42
  id: string,
44
- capacity: BN,
43
+ capacity: bigint,
45
44
  isActive: boolean,
46
45
 
47
- localBalance: BN,
48
- localReserve: BN,
49
- remoteBalance: BN,
50
- remoteReserve: BN,
51
- unsettledBalance: BN,
46
+ localBalance: bigint,
47
+ localReserve: bigint,
48
+ remoteBalance: bigint,
49
+ remoteReserve: bigint,
50
+ unsettledBalance: bigint,
52
51
  transactionId: string,
53
52
  transactionVout: number
54
53
  };
55
54
 
56
55
  export type InvoiceInit = {
57
- mtokens: BN,
56
+ mtokens: bigint,
58
57
  descriptionHash?: string
59
58
  description?: string,
60
59
  cltvDelta?: number,
@@ -66,7 +65,7 @@ export type HodlInvoiceInit = {
66
65
  cltvDelta: number,
67
66
  expiresAt: number,
68
67
  id: string,
69
- mtokens: BN,
68
+ mtokens: bigint,
70
69
  descriptionHash?: string
71
70
  };
72
71
 
@@ -75,12 +74,12 @@ export type LNRoutes = {
75
74
  feeRate?: number,
76
75
  cltvDelta?: number,
77
76
  channel?: string,
78
- baseFeeMtokens?: BN
77
+ baseFeeMtokens?: bigint
79
78
  }[][];
80
79
 
81
80
  export type ParsedPaymentRequest = {
82
81
  id: string,
83
- mtokens: BN,
82
+ mtokens: bigint,
84
83
  expiryEpochMillis: number,
85
84
  destination: string,
86
85
  cltvDelta: number,
@@ -90,26 +89,26 @@ export type ParsedPaymentRequest = {
90
89
 
91
90
  export type LightningPaymentInit = {
92
91
  request: string,
93
- maxFeeMtokens?: BN,
92
+ maxFeeMtokens?: bigint,
94
93
  maxTimeoutHeight?: number
95
94
  };
96
95
 
97
96
  export type LightningBalanceResponse = {
98
- localBalance: BN,
99
- remoteBalance: BN,
100
- unsettledBalance: BN
97
+ localBalance: bigint,
98
+ remoteBalance: bigint,
99
+ unsettledBalance: bigint
101
100
  };
102
101
 
103
102
  export type ProbeAndRouteInit = {
104
103
  request: string,
105
- amountMtokens: BN,
106
- maxFeeMtokens: BN,
104
+ amountMtokens: bigint,
105
+ maxFeeMtokens: bigint,
107
106
  maxTimeoutHeight: number
108
107
  }
109
108
 
110
109
  export type ProbeAndRouteResponse = {
111
110
  confidence: number,
112
- feeMtokens: BN,
111
+ feeMtokens: bigint,
113
112
  destination: string,
114
113
  privateRoutes: LNRoutes
115
114
  }
@@ -133,7 +132,7 @@ export function routesMatch(routesA: LNRoutes, routesB: LNRoutes) {
133
132
  }
134
133
  if(
135
134
  routesA[i][e].publicKey!==routesB[i][e].publicKey ||
136
- !routesA[i][e].baseFeeMtokens.eq(routesB[i][e].baseFeeMtokens) ||
135
+ routesA[i][e].baseFeeMtokens!==routesB[i][e].baseFeeMtokens ||
137
136
  routesA[i][e].channel!==routesB[i][e].channel ||
138
137
  routesA[i][e].cltvDelta!==routesB[i][e].cltvDelta ||
139
138
  routesA[i][e].feeRate!==routesB[i][e].feeRate