@atomiqlabs/sdk 8.8.3 → 8.9.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 (130) hide show
  1. package/api/index.d.ts +1 -0
  2. package/api/index.js +3 -0
  3. package/dist/ApiList.d.ts +37 -0
  4. package/dist/ApiList.js +30 -0
  5. package/dist/api/ApiEndpoints.d.ts +393 -0
  6. package/dist/api/ApiEndpoints.js +2 -0
  7. package/dist/api/ApiParser.d.ts +10 -0
  8. package/dist/api/ApiParser.js +134 -0
  9. package/dist/api/ApiTypes.d.ts +157 -0
  10. package/dist/api/ApiTypes.js +75 -0
  11. package/dist/api/SerializedAction.d.ts +40 -0
  12. package/dist/api/SerializedAction.js +59 -0
  13. package/dist/api/SwapperApi.d.ts +50 -0
  14. package/dist/api/SwapperApi.js +431 -0
  15. package/dist/api/index.d.ts +5 -0
  16. package/dist/api/index.js +24 -0
  17. package/dist/events/UnifiedSwapEventListener.d.ts +4 -3
  18. package/dist/events/UnifiedSwapEventListener.js +8 -2
  19. package/dist/http/HttpUtils.d.ts +4 -2
  20. package/dist/http/HttpUtils.js +10 -4
  21. package/dist/http/paramcoders/client/StreamingFetchPromise.d.ts +2 -1
  22. package/dist/http/paramcoders/client/StreamingFetchPromise.js +3 -2
  23. package/dist/index.d.ts +1 -0
  24. package/dist/index.js +1 -0
  25. package/dist/intermediaries/IntermediaryDiscovery.d.ts +7 -2
  26. package/dist/intermediaries/IntermediaryDiscovery.js +4 -4
  27. package/dist/intermediaries/apis/IntermediaryAPI.d.ts +171 -14
  28. package/dist/intermediaries/apis/IntermediaryAPI.js +174 -28
  29. package/dist/intermediaries/auth/SignedKeyBasedAuth.d.ts +14 -0
  30. package/dist/intermediaries/auth/SignedKeyBasedAuth.js +68 -0
  31. package/dist/storage/IUnifiedStorage.d.ts +45 -3
  32. package/dist/storage/UnifiedSwapStorage.d.ts +8 -2
  33. package/dist/storage/UnifiedSwapStorage.js +46 -8
  34. package/dist/swapper/Swapper.d.ts +36 -3
  35. package/dist/swapper/Swapper.js +54 -18
  36. package/dist/swapper/SwapperUtils.d.ts +18 -2
  37. package/dist/swapper/SwapperUtils.js +39 -1
  38. package/dist/swaps/ISwap.d.ts +70 -9
  39. package/dist/swaps/ISwap.js +28 -6
  40. package/dist/swaps/ISwapWrapper.d.ts +11 -1
  41. package/dist/swaps/ISwapWrapper.js +23 -3
  42. package/dist/swaps/escrow_swaps/IEscrowSwap.d.ts +1 -1
  43. package/dist/swaps/escrow_swaps/IEscrowSwap.js +4 -2
  44. package/dist/swaps/escrow_swaps/IEscrowSwapWrapper.d.ts +2 -1
  45. package/dist/swaps/escrow_swaps/IEscrowSwapWrapper.js +2 -2
  46. package/dist/swaps/escrow_swaps/frombtc/IFromBTCLNWrapper.d.ts +3 -1
  47. package/dist/swaps/escrow_swaps/frombtc/IFromBTCLNWrapper.js +3 -2
  48. package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.d.ts +47 -31
  49. package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.js +201 -67
  50. package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.d.ts +3 -1
  51. package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.js +6 -6
  52. package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.d.ts +82 -15
  53. package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.js +304 -98
  54. package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.d.ts +3 -1
  55. package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.js +6 -6
  56. package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.d.ts +75 -42
  57. package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.js +424 -87
  58. package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.d.ts +3 -1
  59. package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.js +7 -7
  60. package/dist/swaps/escrow_swaps/tobtc/IToBTCSwap.d.ts +54 -11
  61. package/dist/swaps/escrow_swaps/tobtc/IToBTCSwap.js +214 -41
  62. package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.d.ts +2 -1
  63. package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.js +7 -8
  64. package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper.d.ts +3 -1
  65. package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper.js +5 -5
  66. package/dist/swaps/spv_swaps/SpvFromBTCSwap.d.ts +76 -19
  67. package/dist/swaps/spv_swaps/SpvFromBTCSwap.js +290 -51
  68. package/dist/swaps/spv_swaps/SpvFromBTCWrapper.d.ts +3 -1
  69. package/dist/swaps/spv_swaps/SpvFromBTCWrapper.js +5 -5
  70. package/dist/swaps/trusted/ln/LnForGasSwap.d.ts +53 -12
  71. package/dist/swaps/trusted/ln/LnForGasSwap.js +163 -49
  72. package/dist/swaps/trusted/ln/LnForGasWrapper.js +1 -2
  73. package/dist/swaps/trusted/onchain/OnchainForGasSwap.d.ts +14 -13
  74. package/dist/swaps/trusted/onchain/OnchainForGasSwap.js +30 -47
  75. package/dist/swaps/trusted/onchain/OnchainForGasWrapper.d.ts +3 -1
  76. package/dist/swaps/trusted/onchain/OnchainForGasWrapper.js +4 -4
  77. package/dist/types/SwapExecutionAction.d.ts +141 -34
  78. package/dist/types/SwapExecutionAction.js +104 -0
  79. package/dist/types/SwapExecutionStep.d.ts +144 -0
  80. package/dist/types/SwapExecutionStep.js +87 -0
  81. package/dist/types/TokenAmount.d.ts +6 -0
  82. package/dist/types/TokenAmount.js +26 -1
  83. package/dist/utils/BitcoinUtils.d.ts +2 -0
  84. package/dist/utils/BitcoinUtils.js +34 -1
  85. package/dist/utils/Utils.d.ts +3 -1
  86. package/dist/utils/Utils.js +7 -1
  87. package/package.json +7 -4
  88. package/src/api/ApiEndpoints.ts +427 -0
  89. package/src/api/ApiParser.ts +138 -0
  90. package/src/api/ApiTypes.ts +229 -0
  91. package/src/api/SerializedAction.ts +97 -0
  92. package/src/api/SwapperApi.ts +545 -0
  93. package/src/api/index.ts +5 -0
  94. package/src/events/UnifiedSwapEventListener.ts +11 -3
  95. package/src/http/HttpUtils.ts +10 -4
  96. package/src/http/paramcoders/client/StreamingFetchPromise.ts +4 -2
  97. package/src/index.ts +1 -0
  98. package/src/intermediaries/IntermediaryDiscovery.ts +9 -2
  99. package/src/intermediaries/apis/IntermediaryAPI.ts +314 -30
  100. package/src/intermediaries/auth/SignedKeyBasedAuth.ts +69 -0
  101. package/src/storage/IUnifiedStorage.ts +45 -4
  102. package/src/storage/UnifiedSwapStorage.ts +42 -8
  103. package/src/swapper/Swapper.ts +87 -18
  104. package/src/swapper/SwapperUtils.ts +42 -2
  105. package/src/swaps/ISwap.ts +88 -16
  106. package/src/swaps/ISwapWrapper.ts +28 -3
  107. package/src/swaps/escrow_swaps/IEscrowSwap.ts +5 -3
  108. package/src/swaps/escrow_swaps/IEscrowSwapWrapper.ts +3 -1
  109. package/src/swaps/escrow_swaps/frombtc/IFromBTCLNWrapper.ts +4 -1
  110. package/src/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.ts +264 -67
  111. package/src/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.ts +6 -4
  112. package/src/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.ts +390 -89
  113. package/src/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.ts +6 -4
  114. package/src/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.ts +548 -94
  115. package/src/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.ts +7 -5
  116. package/src/swaps/escrow_swaps/tobtc/IToBTCSwap.ts +276 -45
  117. package/src/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.ts +7 -6
  118. package/src/swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper.ts +5 -3
  119. package/src/swaps/spv_swaps/SpvFromBTCSwap.ts +393 -57
  120. package/src/swaps/spv_swaps/SpvFromBTCWrapper.ts +5 -3
  121. package/src/swaps/trusted/ln/LnForGasSwap.ts +211 -47
  122. package/src/swaps/trusted/ln/LnForGasWrapper.ts +1 -2
  123. package/src/swaps/trusted/onchain/OnchainForGasSwap.ts +32 -51
  124. package/src/swaps/trusted/onchain/OnchainForGasWrapper.ts +5 -3
  125. package/src/types/SwapExecutionAction.ts +266 -43
  126. package/src/types/SwapExecutionStep.ts +224 -0
  127. package/src/types/TokenAmount.ts +36 -2
  128. package/src/utils/BitcoinUtils.ts +32 -0
  129. package/src/utils/Utils.ts +10 -1
  130. package/src/intermediaries/apis/TrustedIntermediaryAPI.ts +0 -258
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.IntermediaryAPI = exports.InvoiceStatusResponseCodes = exports.PaymentAuthorizationResponseCodes = exports.RefundAuthorizationResponseCodes = void 0;
3
+ exports.IntermediaryAPI = exports.TrustedAddressStatusResponseCodes = exports.TrustedInvoiceStatusResponseCodes = exports.InvoiceStatusResponseCodes = exports.PaymentAuthorizationResponseCodes = exports.RefundAuthorizationResponseCodes = void 0;
4
4
  const RequestError_1 = require("../../errors/RequestError");
5
5
  const SchemaVerifier_1 = require("../../http/paramcoders/SchemaVerifier");
6
6
  const StreamingFetchPromise_1 = require("../../http/paramcoders/client/StreamingFetchPromise");
@@ -129,7 +129,64 @@ const SpvFromBTCPrepareResponseSchema = {
129
129
  const SpvFromBTCInitResponseSchema = {
130
130
  txId: SchemaVerifier_1.FieldTypeEnum.String
131
131
  };
132
+ /////////////////////////
133
+ ///// Trusted from BTCLN
134
+ var TrustedInvoiceStatusResponseCodes;
135
+ (function (TrustedInvoiceStatusResponseCodes) {
136
+ TrustedInvoiceStatusResponseCodes[TrustedInvoiceStatusResponseCodes["EXPIRED"] = 10001] = "EXPIRED";
137
+ TrustedInvoiceStatusResponseCodes[TrustedInvoiceStatusResponseCodes["PAID"] = 10000] = "PAID";
138
+ TrustedInvoiceStatusResponseCodes[TrustedInvoiceStatusResponseCodes["AWAIT_PAYMENT"] = 10010] = "AWAIT_PAYMENT";
139
+ TrustedInvoiceStatusResponseCodes[TrustedInvoiceStatusResponseCodes["PENDING"] = 10011] = "PENDING";
140
+ TrustedInvoiceStatusResponseCodes[TrustedInvoiceStatusResponseCodes["TX_SENT"] = 10012] = "TX_SENT";
141
+ })(TrustedInvoiceStatusResponseCodes = exports.TrustedInvoiceStatusResponseCodes || (exports.TrustedInvoiceStatusResponseCodes = {}));
142
+ const TrustedFromBTCLNResponseSchema = {
143
+ pr: SchemaVerifier_1.FieldTypeEnum.String,
144
+ swapFee: SchemaVerifier_1.FieldTypeEnum.BigInt,
145
+ swapFeeSats: SchemaVerifier_1.FieldTypeEnum.BigInt,
146
+ total: SchemaVerifier_1.FieldTypeEnum.BigInt
147
+ };
148
+ /////////////////////////
149
+ ///// Trusted from BTC
150
+ var TrustedAddressStatusResponseCodes;
151
+ (function (TrustedAddressStatusResponseCodes) {
152
+ TrustedAddressStatusResponseCodes[TrustedAddressStatusResponseCodes["EXPIRED"] = 10001] = "EXPIRED";
153
+ TrustedAddressStatusResponseCodes[TrustedAddressStatusResponseCodes["PAID"] = 10000] = "PAID";
154
+ TrustedAddressStatusResponseCodes[TrustedAddressStatusResponseCodes["AWAIT_PAYMENT"] = 10010] = "AWAIT_PAYMENT";
155
+ TrustedAddressStatusResponseCodes[TrustedAddressStatusResponseCodes["AWAIT_CONFIRMATION"] = 10011] = "AWAIT_CONFIRMATION";
156
+ TrustedAddressStatusResponseCodes[TrustedAddressStatusResponseCodes["PENDING"] = 10013] = "PENDING";
157
+ TrustedAddressStatusResponseCodes[TrustedAddressStatusResponseCodes["TX_SENT"] = 10012] = "TX_SENT";
158
+ TrustedAddressStatusResponseCodes[TrustedAddressStatusResponseCodes["REFUNDED"] = 10014] = "REFUNDED";
159
+ TrustedAddressStatusResponseCodes[TrustedAddressStatusResponseCodes["DOUBLE_SPENT"] = 10015] = "DOUBLE_SPENT";
160
+ TrustedAddressStatusResponseCodes[TrustedAddressStatusResponseCodes["REFUNDABLE"] = 10016] = "REFUNDABLE";
161
+ })(TrustedAddressStatusResponseCodes = exports.TrustedAddressStatusResponseCodes || (exports.TrustedAddressStatusResponseCodes = {}));
162
+ const TrustedFromBTCResponseSchema = {
163
+ paymentHash: SchemaVerifier_1.FieldTypeEnum.String,
164
+ sequence: SchemaVerifier_1.FieldTypeEnum.BigInt,
165
+ btcAddress: SchemaVerifier_1.FieldTypeEnum.String,
166
+ amountSats: SchemaVerifier_1.FieldTypeEnum.BigInt,
167
+ swapFeeSats: SchemaVerifier_1.FieldTypeEnum.BigInt,
168
+ swapFee: SchemaVerifier_1.FieldTypeEnum.BigInt,
169
+ total: SchemaVerifier_1.FieldTypeEnum.BigInt,
170
+ intermediaryKey: SchemaVerifier_1.FieldTypeEnum.String,
171
+ recommendedFee: SchemaVerifier_1.FieldTypeEnum.Number,
172
+ expiresAt: SchemaVerifier_1.FieldTypeEnum.Number
173
+ };
132
174
  class IntermediaryAPI {
175
+ constructor(requestHeaders) {
176
+ this.requestHeaders = requestHeaders;
177
+ }
178
+ httpGet(url, timeout, abortSignal, allowNon200 = false) {
179
+ const headers = this.requestHeaders == null ? {} : this.requestHeaders("GET", url);
180
+ return (0, HttpUtils_1.httpGet)(url, timeout, abortSignal, allowNon200, headers);
181
+ }
182
+ httpPost(url, body, timeout, abortSignal) {
183
+ const headers = this.requestHeaders == null ? {} : this.requestHeaders("POST", url, body);
184
+ return (0, HttpUtils_1.httpPost)(url, body, timeout, abortSignal, headers);
185
+ }
186
+ streamingFetchPromise(url, body, schema, timeout, signal, streamRequest) {
187
+ const headers = this.requestHeaders == null ? {} : this.requestHeaders("POST", url);
188
+ return (0, StreamingFetchPromise_1.streamingFetchPromise)(url, body, schema, timeout, signal, streamRequest, headers);
189
+ }
133
190
  /**
134
191
  * Returns the information about a specific intermediary
135
192
  *
@@ -140,14 +197,14 @@ class IntermediaryAPI {
140
197
  * @throws {RequestError} If non-200 http response code is returned
141
198
  * @throws {Error} If the supplied nonce doesn't match the response
142
199
  */
143
- static async getIntermediaryInfo(baseUrl, timeout, abortSignal) {
200
+ async getIntermediaryInfo(baseUrl, timeout, abortSignal) {
144
201
  const nonce = (0, Utils_1.randomBytes)(32).toString("hex");
145
202
  const abortController = (0, Utils_1.extendAbortController)(abortSignal);
146
203
  //We don't know whether the node supports only POST or also has GET info support enabled
147
204
  // here we try both, and abort when the first one returns (which should be GET)
148
205
  const response = await Promise.any([
149
- (0, HttpUtils_1.httpGet)(baseUrl + "/info?nonce=" + nonce, timeout, abortController.signal),
150
- (0, HttpUtils_1.httpPost)(baseUrl + "/info", {
206
+ this.httpGet(baseUrl + "/info?nonce=" + nonce, timeout, abortController.signal),
207
+ this.httpPost(baseUrl + "/info", {
151
208
  nonce,
152
209
  }, timeout, abortController.signal)
153
210
  ]);
@@ -168,8 +225,8 @@ class IntermediaryAPI {
168
225
  *
169
226
  * @throws {RequestError} If non-200 http response code is returned
170
227
  */
171
- static async getRefundAuthorization(url, paymentHash, sequence, timeout, abortSignal) {
172
- return (0, RetryUtils_1.tryWithRetries)(() => (0, HttpUtils_1.httpGet)(url + "/getRefundAuthorization" +
228
+ async getRefundAuthorization(url, paymentHash, sequence, timeout, abortSignal) {
229
+ return (0, RetryUtils_1.tryWithRetries)(() => this.httpGet(url + "/getRefundAuthorization" +
173
230
  "?paymentHash=" + encodeURIComponent(paymentHash) +
174
231
  "&sequence=" + encodeURIComponent(sequence.toString(10)), timeout, abortSignal), undefined, RequestError_1.RequestError, abortSignal);
175
232
  }
@@ -183,8 +240,8 @@ class IntermediaryAPI {
183
240
  *
184
241
  * @throws {RequestError} If non-200 http response code is returned
185
242
  */
186
- static async getPaymentAuthorization(url, paymentHash, timeout, abortSignal) {
187
- return (0, RetryUtils_1.tryWithRetries)(() => (0, HttpUtils_1.httpGet)(url + "/getInvoicePaymentAuth" +
243
+ async getPaymentAuthorization(url, paymentHash, timeout, abortSignal) {
244
+ return (0, RetryUtils_1.tryWithRetries)(() => this.httpGet(url + "/getInvoicePaymentAuth" +
188
245
  "?paymentHash=" + encodeURIComponent(paymentHash), timeout, abortSignal), undefined, RequestError_1.RequestError, abortSignal);
189
246
  }
190
247
  /**
@@ -197,8 +254,8 @@ class IntermediaryAPI {
197
254
  *
198
255
  * @throws {RequestError} If non-200 http response code is returned
199
256
  */
200
- static async getInvoiceStatus(url, paymentHash, timeout, abortSignal) {
201
- return (0, RetryUtils_1.tryWithRetries)(() => (0, HttpUtils_1.httpGet)(url + "/getInvoiceStatus" +
257
+ async getInvoiceStatus(url, paymentHash, timeout, abortSignal) {
258
+ return (0, RetryUtils_1.tryWithRetries)(() => this.httpGet(url + "/getInvoiceStatus" +
202
259
  "?paymentHash=" + encodeURIComponent(paymentHash), timeout, abortSignal), undefined, RequestError_1.RequestError, abortSignal);
203
260
  }
204
261
  /**
@@ -213,8 +270,8 @@ class IntermediaryAPI {
213
270
  *
214
271
  * @throws {RequestError} If non-200 http response code is returned
215
272
  */
216
- static initToBTC(chainIdentifier, baseUrl, init, timeout, abortSignal, streamRequest) {
217
- const responseBodyPromise = (0, StreamingFetchPromise_1.streamingFetchPromise)(baseUrl + "/tobtc/payInvoice?chain=" + encodeURIComponent(chainIdentifier), {
273
+ initToBTC(chainIdentifier, baseUrl, init, timeout, abortSignal, streamRequest) {
274
+ const responseBodyPromise = this.streamingFetchPromise(baseUrl + "/tobtc/payInvoice?chain=" + encodeURIComponent(chainIdentifier), {
218
275
  ...init.additionalParams,
219
276
  address: init.btcAddress,
220
277
  amount: init.amount.toString(10),
@@ -261,8 +318,8 @@ class IntermediaryAPI {
261
318
  *
262
319
  * @throws {RequestError} If non-200 http response code is returned
263
320
  */
264
- static initFromBTC(chainIdentifier, baseUrl, depositToken, init, timeout, abortSignal, streamRequest) {
265
- const responseBodyPromise = (0, StreamingFetchPromise_1.streamingFetchPromise)(baseUrl + "/frombtc/getAddress?chain=" + encodeURIComponent(chainIdentifier) + "&depositToken=" + encodeURIComponent(depositToken), {
321
+ initFromBTC(chainIdentifier, baseUrl, depositToken, init, timeout, abortSignal, streamRequest) {
322
+ const responseBodyPromise = this.streamingFetchPromise(baseUrl + "/frombtc/getAddress?chain=" + encodeURIComponent(chainIdentifier) + "&depositToken=" + encodeURIComponent(depositToken), {
266
323
  ...init.additionalParams,
267
324
  address: init.claimer,
268
325
  amount: init.amount.toString(10),
@@ -315,8 +372,8 @@ class IntermediaryAPI {
315
372
  *
316
373
  * @throws {RequestError} If non-200 http response code is returned
317
374
  */
318
- static initFromBTCLN(chainIdentifier, baseUrl, depositToken, init, timeout, abortSignal, streamRequest) {
319
- const responseBodyPromise = (0, StreamingFetchPromise_1.streamingFetchPromise)(baseUrl + "/frombtcln/createInvoice?chain=" + encodeURIComponent(chainIdentifier) + "&depositToken=" + encodeURIComponent(depositToken), {
375
+ initFromBTCLN(chainIdentifier, baseUrl, depositToken, init, timeout, abortSignal, streamRequest) {
376
+ const responseBodyPromise = this.streamingFetchPromise(baseUrl + "/frombtcln/createInvoice?chain=" + encodeURIComponent(chainIdentifier) + "&depositToken=" + encodeURIComponent(depositToken), {
320
377
  ...init.additionalParams,
321
378
  paymentHash: init.paymentHash.toString("hex"),
322
379
  amount: init.amount.toString(),
@@ -361,8 +418,8 @@ class IntermediaryAPI {
361
418
  *
362
419
  * @throws {RequestError} If non-200 http response code is returned
363
420
  */
364
- static initFromBTCLNAuto(chainIdentifier, baseUrl, init, timeout, abortSignal, streamRequest) {
365
- const responseBodyPromise = (0, StreamingFetchPromise_1.streamingFetchPromise)(baseUrl + "/frombtcln_auto/createInvoice?chain=" + encodeURIComponent(chainIdentifier), {
421
+ initFromBTCLNAuto(chainIdentifier, baseUrl, init, timeout, abortSignal, streamRequest) {
422
+ const responseBodyPromise = this.streamingFetchPromise(baseUrl + "/frombtcln_auto/createInvoice?chain=" + encodeURIComponent(chainIdentifier), {
366
423
  ...init.additionalParams,
367
424
  paymentHash: init.paymentHash.toString("hex"),
368
425
  amount: init.amount.toString(),
@@ -409,8 +466,8 @@ class IntermediaryAPI {
409
466
  *
410
467
  * @throws {RequestError} If non-200 http response code is returned
411
468
  */
412
- static initToBTCLN(chainIdentifier, baseUrl, init, timeout, abortSignal, streamRequest) {
413
- const responseBodyPromise = (0, StreamingFetchPromise_1.streamingFetchPromise)(baseUrl + "/tobtcln/payInvoice?chain=" + encodeURIComponent(chainIdentifier), {
469
+ initToBTCLN(chainIdentifier, baseUrl, init, timeout, abortSignal, streamRequest) {
470
+ const responseBodyPromise = this.streamingFetchPromise(baseUrl + "/tobtcln/payInvoice?chain=" + encodeURIComponent(chainIdentifier), {
414
471
  exactIn: false,
415
472
  ...init.additionalParams,
416
473
  pr: init.pr,
@@ -454,8 +511,8 @@ class IntermediaryAPI {
454
511
  *
455
512
  * @throws {RequestError} If non-200 http response code is returned
456
513
  */
457
- static async initToBTCLNExactIn(baseUrl, init, timeout, abortSignal, streamRequest) {
458
- const responseBody = await (0, StreamingFetchPromise_1.streamingFetchPromise)(baseUrl + "/tobtcln/payInvoiceExactIn", {
514
+ async initToBTCLNExactIn(baseUrl, init, timeout, abortSignal, streamRequest) {
515
+ const responseBody = await this.streamingFetchPromise(baseUrl + "/tobtcln/payInvoiceExactIn", {
459
516
  ...init.additionalParams,
460
517
  pr: init.pr,
461
518
  reqId: init.reqId,
@@ -489,8 +546,8 @@ class IntermediaryAPI {
489
546
  *
490
547
  * @throws {RequestError} If non-200 http response code is returned
491
548
  */
492
- static prepareToBTCLNExactIn(chainIdentifier, baseUrl, init, timeout, abortSignal, streamRequest) {
493
- const responseBodyPromise = (0, StreamingFetchPromise_1.streamingFetchPromise)(baseUrl + "/tobtcln/payInvoice?chain=" + encodeURIComponent(chainIdentifier), {
549
+ prepareToBTCLNExactIn(chainIdentifier, baseUrl, init, timeout, abortSignal, streamRequest) {
550
+ const responseBodyPromise = this.streamingFetchPromise(baseUrl + "/tobtcln/payInvoice?chain=" + encodeURIComponent(chainIdentifier), {
494
551
  exactIn: true,
495
552
  ...init.additionalParams,
496
553
  pr: init.pr,
@@ -534,7 +591,7 @@ class IntermediaryAPI {
534
591
  *
535
592
  * @throws {RequestError} If non-200 http response code is returned
536
593
  */
537
- static prepareSpvFromBTC(chainIdentifier, baseUrl, init, timeout, abortSignal, streamRequest) {
594
+ prepareSpvFromBTC(chainIdentifier, baseUrl, init, timeout, abortSignal, streamRequest) {
538
595
  //We need to make sure we only send the amount parameter after the amountUtxos and amountFeeRate resolve
539
596
  // this is needed, because in the LP code to maintain backwards compatibility the amountUtxos and amountFeeRate
540
597
  // params are checked immediately after the amount param (and other params) are received, if amount were sent
@@ -547,7 +604,7 @@ class IntermediaryAPI {
547
604
  const amount = await init.amount;
548
605
  return amount.toString(10);
549
606
  })();
550
- const responseBodyPromise = (0, StreamingFetchPromise_1.streamingFetchPromise)(baseUrl + "/frombtc_spv/getQuote?chain=" + encodeURIComponent(chainIdentifier), {
607
+ const responseBodyPromise = this.streamingFetchPromise(baseUrl + "/frombtc_spv/getQuote?chain=" + encodeURIComponent(chainIdentifier), {
551
608
  exactOut: init.exactOut,
552
609
  ...init.additionalParams,
553
610
  address: init.address,
@@ -591,8 +648,8 @@ class IntermediaryAPI {
591
648
  *
592
649
  * @throws {RequestError} If non-200 http response code is returned
593
650
  */
594
- static initSpvFromBTC(chainIdentifier, url, init, timeout, abortSignal, streamRequest) {
595
- const responseBodyPromise = (0, StreamingFetchPromise_1.streamingFetchPromise)(url + "/postQuote?chain=" + encodeURIComponent(chainIdentifier), {
651
+ initSpvFromBTC(chainIdentifier, url, init, timeout, abortSignal, streamRequest) {
652
+ const responseBodyPromise = this.streamingFetchPromise(url + "/postQuote?chain=" + encodeURIComponent(chainIdentifier), {
596
653
  quoteId: init.quoteId,
597
654
  psbtHex: init.psbtHex
598
655
  }, {
@@ -614,5 +671,94 @@ class IntermediaryAPI {
614
671
  return result;
615
672
  });
616
673
  }
674
+ /**
675
+ * Fetches the invoice status from the intermediary node
676
+ *
677
+ * @param url Url of the trusted intermediary
678
+ * @param paymentHash Payment hash of the lightning invoice
679
+ * @param timeout Timeout in milliseconds
680
+ * @param abortSignal
681
+ * @throws {RequestError} if non-200 http response is returned
682
+ */
683
+ async getTrustedInvoiceStatus(url, paymentHash, timeout, abortSignal) {
684
+ return (0, RetryUtils_1.tryWithRetries)(() => this.httpGet(url + "/getInvoiceStatus?paymentHash=" + encodeURIComponent(paymentHash), timeout, abortSignal), undefined, RequestError_1.RequestError, abortSignal);
685
+ }
686
+ /**
687
+ * Initiate a trusted swap from BTCLN to SC native currency, retries!
688
+ *
689
+ * @param chainIdentifier
690
+ * @param baseUrl Base url of the trusted swap intermediary
691
+ * @param init Initialization parameters
692
+ * @param timeout Timeout in milliseconds for the request
693
+ * @param abortSignal
694
+ * @throws {RequestError} If the response is non-200
695
+ */
696
+ async initTrustedFromBTCLN(chainIdentifier, baseUrl, init, timeout, abortSignal) {
697
+ const resp = await (0, RetryUtils_1.tryWithRetries)(() => this.httpGet(baseUrl + "/lnforgas/createInvoice" +
698
+ "?address=" + encodeURIComponent(init.address) +
699
+ "&amount=" + encodeURIComponent(init.amount.toString(10)) +
700
+ "&chain=" + encodeURIComponent(chainIdentifier) +
701
+ "&token=" + encodeURIComponent(init.token), timeout, abortSignal), undefined, RequestError_1.RequestError, abortSignal);
702
+ if (resp.code !== 10000)
703
+ throw RequestError_1.RequestError.parse(JSON.stringify(resp), 400);
704
+ const res = (0, SchemaVerifier_1.verifySchema)(resp.data, TrustedFromBTCLNResponseSchema);
705
+ if (res == null)
706
+ throw new Error("Invalid response returned from LP");
707
+ return res;
708
+ }
709
+ /**
710
+ * Fetches the address status from the intermediary node
711
+ *
712
+ * @param url Url of the trusted intermediary
713
+ * @param paymentHash Payment hash of the swap
714
+ * @param sequence Sequence number of the swap
715
+ * @param timeout Timeout in milliseconds
716
+ * @param abortSignal
717
+ * @throws {RequestError} if non-200 http response is returned
718
+ */
719
+ async getTrustedAddressStatus(url, paymentHash, sequence, timeout, abortSignal) {
720
+ return (0, RetryUtils_1.tryWithRetries)(() => this.httpGet(url + "/getAddressStatus?paymentHash=" + encodeURIComponent(paymentHash) + "&sequence=" + encodeURIComponent(sequence.toString(10)), timeout, abortSignal), undefined, RequestError_1.RequestError, abortSignal);
721
+ }
722
+ /**
723
+ * Sets the refund address for an on-chain gas swap
724
+ *
725
+ * @param url Url of the trusted intermediary
726
+ * @param paymentHash Payment hash of the swap
727
+ * @param sequence Sequence number of the swap
728
+ * @param refundAddress Refund address to set for the swap
729
+ * @param timeout Timeout in milliseconds
730
+ * @param abortSignal
731
+ * @throws {RequestError} if non-200 http response is returned
732
+ */
733
+ async setTrustedRefundAddress(url, paymentHash, sequence, refundAddress, timeout, abortSignal) {
734
+ return (0, RetryUtils_1.tryWithRetries)(() => this.httpGet(url + "/setRefundAddress" +
735
+ "?paymentHash=" + encodeURIComponent(paymentHash) +
736
+ "&sequence=" + encodeURIComponent(sequence.toString(10)) +
737
+ "&refundAddress=" + encodeURIComponent(refundAddress), timeout, abortSignal), undefined, RequestError_1.RequestError, abortSignal);
738
+ }
739
+ /**
740
+ * Initiate a trusted swap from BTC to SC native currency, retries!
741
+ *
742
+ * @param chainIdentifier
743
+ * @param baseUrl Base url of the trusted swap intermediary
744
+ * @param init Initialization parameters
745
+ * @param timeout Timeout in milliseconds for the request
746
+ * @param abortSignal
747
+ * @throws {RequestError} If the response is non-200
748
+ */
749
+ async initTrustedFromBTC(chainIdentifier, baseUrl, init, timeout, abortSignal) {
750
+ const resp = await (0, RetryUtils_1.tryWithRetries)(() => this.httpGet(baseUrl + "/frombtc_trusted/getAddress?chain=" + encodeURIComponent(chainIdentifier) +
751
+ "&address=" + encodeURIComponent(init.address) +
752
+ "&amount=" + encodeURIComponent(init.amount.toString(10)) +
753
+ (init.refundAddress == null ? "" : "&refundAddress=" + encodeURIComponent(init.refundAddress)) +
754
+ "&exactIn=true" +
755
+ "&token=" + encodeURIComponent(init.token), timeout, abortSignal), undefined, RequestError_1.RequestError, abortSignal);
756
+ if (resp.code !== 10000)
757
+ throw RequestError_1.RequestError.parse(JSON.stringify(resp), 400);
758
+ const res = (0, SchemaVerifier_1.verifySchema)(resp.data, TrustedFromBTCResponseSchema);
759
+ if (res == null)
760
+ throw new Error("Invalid response returned from LP");
761
+ return res;
762
+ }
617
763
  }
618
764
  exports.IntermediaryAPI = IntermediaryAPI;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Adds a `x-atomiq-auth` header with the following binary format, that is hex-encoded:
3
+ * - 4 bytes - timestamp (timestamp when the request was sent)
4
+ * - 32 bytes - random bytes (entropy, to be signed)
5
+ *
6
+ * - 32 bytes - key of the signing authority
7
+ * - 64 bytes - schnorr signature signing the request signing key by the signing authority
8
+ *
9
+ * - 32 bytes - request signing key (signed by the signing authority)
10
+ * - 64 bytes - schnorr signature of the timestamp and random bytes
11
+ *
12
+ * Uses secp256k1 curve and schnorr signatures
13
+ */
14
+ export declare function getSignedKeyBasedAuthHandler(certificate: string, privateKey: string): (type: "GET" | "POST", url: string, body?: any) => Record<string, string>;
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getSignedKeyBasedAuthHandler = void 0;
4
+ const secp256k1_1 = require("@noble/curves/secp256k1");
5
+ const Utils_1 = require("../../utils/Utils");
6
+ function parsePrivateKey(value, name) {
7
+ if (!/^[0-9a-fA-F]{64}$/.test(value))
8
+ throw new Error(`${name} must be a 32-byte hex private key`);
9
+ const bytes = Buffer.from(value, "hex");
10
+ if (!secp256k1_1.secp256k1.utils.isValidPrivateKey(bytes))
11
+ throw new Error(`${name} is not a valid secp256k1 private key`);
12
+ return bytes;
13
+ }
14
+ function parsePublicKey(value, name) {
15
+ if (!/^[0-9a-fA-F]{64}$/.test(value))
16
+ throw new Error(`${name} must be an X-only 32-byte hex public key`);
17
+ if (!secp256k1_1.secp256k1.utils.isValidPublicKey(Buffer.from("02" + value, "hex"), true))
18
+ throw new Error(`${name} is not a valid X-only 32-byte secp256k1 public key`);
19
+ return Buffer.from(value, "hex");
20
+ }
21
+ function parseSignature(value, name) {
22
+ if (!/^[0-9a-fA-F]{128}$/.test(value))
23
+ throw new Error(`${name} must be a valid 64-byte hex schnorr signature`);
24
+ return Buffer.from(value, "hex");
25
+ }
26
+ const CERTIFICATE_LENGTH = 64 + 128 + 64;
27
+ /**
28
+ * Adds a `x-atomiq-auth` header with the following binary format, that is hex-encoded:
29
+ * - 4 bytes - timestamp (timestamp when the request was sent)
30
+ * - 32 bytes - random bytes (entropy, to be signed)
31
+ *
32
+ * - 32 bytes - key of the signing authority
33
+ * - 64 bytes - schnorr signature signing the request signing key by the signing authority
34
+ *
35
+ * - 32 bytes - request signing key (signed by the signing authority)
36
+ * - 64 bytes - schnorr signature of the timestamp and random bytes
37
+ *
38
+ * Uses secp256k1 curve and schnorr signatures
39
+ */
40
+ function getSignedKeyBasedAuthHandler(certificate, privateKey) {
41
+ const _privateKey = parsePrivateKey(privateKey, "Private key");
42
+ if (certificate.length !== CERTIFICATE_LENGTH)
43
+ throw new Error(`Certificate has invalid length, expected ${CERTIFICATE_LENGTH}!`);
44
+ const authorityPublicKey = parsePublicKey(certificate.substring(0, 64), "Certificate: Authority Public key");
45
+ const authoritySignature = parseSignature(certificate.substring(64, 64 + 128), "Certificate: Authority Signature");
46
+ const signingPublicKey = parsePublicKey(certificate.substring(64 + 128), "Certificate: Signing Public key");
47
+ if (!secp256k1_1.schnorr.verify(authoritySignature, signingPublicKey, authorityPublicKey))
48
+ throw new Error("Invalid certificate, authority signature is not valid!");
49
+ if (!signingPublicKey.equals(secp256k1_1.schnorr.getPublicKey(privateKey)))
50
+ throw new Error("Passed private key doesn't match the certificate!");
51
+ const _certificate = Buffer.from(certificate, "hex");
52
+ return () => {
53
+ const timestamp = Math.floor(Date.now() / 1000);
54
+ const timestampBuffer = Buffer.alloc(4);
55
+ timestampBuffer.writeUInt32BE(timestamp);
56
+ const requestUid = (0, Utils_1.randomBytes)(32);
57
+ const toSign = Buffer.concat([timestampBuffer, requestUid]);
58
+ const signature = secp256k1_1.schnorr.sign(toSign, _privateKey);
59
+ return {
60
+ "x-atomiq-auth": Buffer.concat([
61
+ toSign,
62
+ _certificate,
63
+ signature
64
+ ]).toString("hex")
65
+ };
66
+ };
67
+ }
68
+ exports.getSignedKeyBasedAuthHandler = getSignedKeyBasedAuthHandler;
@@ -14,12 +14,14 @@ export type QueryParams = {
14
14
  value: any | any[];
15
15
  };
16
16
  /**
17
- * Base type for stored objects, every storage object MUST have an `id` field
17
+ * Base type for stored objects, every storage object MUST have an `id` field. The object might also specify a `_meta`
18
+ * field which gets carried to the delete/save operations (and can be used to implement optimistic concurrency)
18
19
  *
19
20
  * @category Storage
20
21
  */
21
22
  export type UnifiedStoredObject = {
22
23
  id: string;
24
+ _meta?: any;
23
25
  } & any;
24
26
  /**
25
27
  * Defines simple indexes (for queries that use a single key)
@@ -59,27 +61,67 @@ export interface IUnifiedStorage<I extends UnifiedStorageIndexes, C extends Unif
59
61
  * - [[condition1, condition2]] - returns all rows where condition1 AND condition2 is met
60
62
  * - [[condition1], [condition2]] - returns all rows where condition1 OR condition2 is met
61
63
  * - [[condition1, condition2], [condition3]] - returns all rows where (condition1 AND condition2) OR condition3 is met
64
+ *
65
+ * You can also add an optional `_meta` field in the returned unified storage object which gets attached to that
66
+ * returned object and will be present for subsequent saves and removal of this object, if you specify the `_meta`
67
+ * field here, you need to explicitly handle it in the all the saving and remove functions and not simply serialize
68
+ * it into the storage
69
+ *
62
70
  * @param params
63
71
  */
64
72
  query(params: Array<Array<QueryParams>>): Promise<Array<UnifiedStoredObject>>;
65
73
  /**
66
74
  * Saves an object to storage, updating indexes as needed
75
+ *
76
+ * If the object contains a `_meta` field, this will be also present in the to-be-saved value, to mutate the `_meta`
77
+ * field of the object that is saved, you can mutate the `_meta` field directly on the passed value, which then
78
+ * gets reflected automatically in the existing object. The mutated `_meta` field is copied even if the function
79
+ * throws, hence the implementations must be careful with setting the `_meta` field on the still in-flight requests
80
+ * that might fail.
81
+ *
67
82
  * @param value Object to save (must have an id property)
68
83
  */
69
84
  save(value: UnifiedStoredObject): Promise<void>;
70
85
  /**
71
86
  * Saves multiple objects to storage in a batch operation
87
+ *
88
+ * If the objects contain a `_meta` field, this will be also present in the to-be-saved values, to mutate the `_meta`
89
+ * field of the objects that are saved, you can mutate the `_meta` field directly on the passed values, which then
90
+ * gets reflected automatically in the existing objects. The mutated `_meta` field is copied even if the function
91
+ * throws, hence the implementations must be careful with setting the `_meta` field on the still in-flight requests
92
+ * that might fail.
93
+ *
72
94
  * @param value Array of objects to save
95
+ * @param lenient In lenient mode the persistency layer doesn't throw on individual swap failures due to
96
+ * optimistic concurrency, or other (implementation specific), this flag is to be used when the saving of the swap
97
+ * isn't mission-critical for executing next steps (e.g. in tick or sync loops)
73
98
  */
74
- saveAll(value: UnifiedStoredObject[]): Promise<void>;
99
+ saveAll(value: UnifiedStoredObject[], lenient?: boolean): Promise<void>;
75
100
  /**
76
101
  * Removes an object from storage
102
+ *
103
+ * If the object contains a `_meta` field, this will be also present in the to-be-removed value, to mutate the `_meta`
104
+ * field of the object that is saved, you can mutate the `_meta` field directly on the passed value, which then
105
+ * gets reflected automatically in the existing object. The mutated `_meta` field is copied even if the function
106
+ * throws, hence the implementations must be careful with setting the `_meta` field on the still in-flight requests
107
+ * that might fail.
108
+ *
77
109
  * @param value Object to remove (must have an id property)
78
110
  */
79
111
  remove(value: UnifiedStoredObject): Promise<void>;
80
112
  /**
81
113
  * Removes multiple objects from storage in a batch operation
114
+ *
115
+ * If the objects contain a `_meta` field, this will be also present in the to-be-removed values, to mutate the `_meta`
116
+ * field of the objects that are saved, you can mutate the `_meta` field directly on the passed values, which then
117
+ * gets reflected automatically in the existing objects. The mutated `_meta` field is copied even if the function
118
+ * throws, hence the implementations must be careful with setting the `_meta` field on the still in-flight requests
119
+ * that might fail.
120
+ *
82
121
  * @param value Array of objects to remove
122
+ * @param lenient In lenient mode the persistency layer doesn't throw on individual swap failures due to
123
+ * optimistic concurrency, or other (implementation specific), this flag is to be used when the saving of the swap
124
+ * isn't mission-critical for executing next steps (e.g. in tick or sync loops)
83
125
  */
84
- removeAll(value: UnifiedStoredObject[]): Promise<void>;
126
+ removeAll(value: UnifiedStoredObject[], lenient?: boolean): Promise<void>;
85
127
  }
@@ -98,8 +98,11 @@ export declare class UnifiedSwapStorage<T extends ChainType> {
98
98
  /**
99
99
  * Saves multiple swaps to storage in a batch operation
100
100
  * @param values Array of swaps to save
101
+ * @param lenient In lenient mode the underlying persistent layer doesn't throw on individual swap failures due to
102
+ * optimistic concurrency, or other (implementation specific), this flag is to be used when the saving of the swap
103
+ * isn't mission-critical for executing next steps (e.g. in tick or sync loops)
101
104
  */
102
- saveAll<S extends ISwap<T>>(values: S[]): Promise<void>;
105
+ saveAll<S extends ISwap<T>>(values: S[], lenient?: boolean): Promise<void>;
103
106
  /**
104
107
  * Removes a swap from storage
105
108
  * @param value Swap to remove
@@ -108,7 +111,10 @@ export declare class UnifiedSwapStorage<T extends ChainType> {
108
111
  /**
109
112
  * Removes multiple swaps from storage in a batch operation
110
113
  * @param values Array of swaps to remove
114
+ * @param lenient In lenient mode the underlying persistent layer doesn't throw on individual swap failures due to
115
+ * optimistic concurrency, or other (implementation specific), this flag is to be used when the saving of the swap
116
+ * isn't mission-critical for executing next steps (e.g. in tick or sync loops)
111
117
  */
112
- removeAll<S extends ISwap<T>>(values: S[]): Promise<void>;
118
+ removeAll<S extends ISwap<T>>(values: S[], lenient?: boolean): Promise<void>;
113
119
  }
114
120
  export {};
@@ -79,18 +79,37 @@ class UnifiedSwapStorage {
79
79
  async save(value) {
80
80
  if (!this.noWeakRefMap)
81
81
  this.weakRefCache.set(value.getId(), new WeakRef(value));
82
- await this.storage.save(value.serialize());
82
+ const serialized = value.serialize();
83
+ try {
84
+ await this.storage.save(serialized);
85
+ }
86
+ finally {
87
+ value._meta = serialized._meta;
88
+ }
83
89
  value._persisted = true;
84
90
  }
85
91
  /**
86
92
  * Saves multiple swaps to storage in a batch operation
87
93
  * @param values Array of swaps to save
94
+ * @param lenient In lenient mode the underlying persistent layer doesn't throw on individual swap failures due to
95
+ * optimistic concurrency, or other (implementation specific), this flag is to be used when the saving of the swap
96
+ * isn't mission-critical for executing next steps (e.g. in tick or sync loops)
88
97
  */
89
- async saveAll(values) {
98
+ async saveAll(values, lenient) {
90
99
  if (!this.noWeakRefMap)
91
100
  values.forEach(value => this.weakRefCache.set(value.getId(), new WeakRef(value)));
92
- await this.storage.saveAll(values.map(obj => obj.serialize()));
93
- values.forEach(value => value._persisted = true);
101
+ const serialized = values.map(obj => obj.serialize());
102
+ try {
103
+ await this.storage.saveAll(serialized, lenient);
104
+ }
105
+ finally {
106
+ values.forEach((value, index) => {
107
+ value._meta = serialized[index]._meta;
108
+ });
109
+ }
110
+ values.forEach((value) => {
111
+ value._persisted = true;
112
+ });
94
113
  }
95
114
  /**
96
115
  * Removes a swap from storage
@@ -99,18 +118,37 @@ class UnifiedSwapStorage {
99
118
  async remove(value) {
100
119
  if (!this.noWeakRefMap)
101
120
  this.weakRefCache.delete(value.getId());
102
- await this.storage.remove(value.serialize());
121
+ const serialized = value.serialize();
122
+ try {
123
+ await this.storage.remove(serialized);
124
+ }
125
+ finally {
126
+ value._meta = serialized._meta;
127
+ }
103
128
  value._persisted = false;
104
129
  }
105
130
  /**
106
131
  * Removes multiple swaps from storage in a batch operation
107
132
  * @param values Array of swaps to remove
133
+ * @param lenient In lenient mode the underlying persistent layer doesn't throw on individual swap failures due to
134
+ * optimistic concurrency, or other (implementation specific), this flag is to be used when the saving of the swap
135
+ * isn't mission-critical for executing next steps (e.g. in tick or sync loops)
108
136
  */
109
- async removeAll(values) {
137
+ async removeAll(values, lenient) {
110
138
  if (!this.noWeakRefMap)
111
139
  values.forEach(value => this.weakRefCache.delete(value.getId()));
112
- await this.storage.removeAll(values.map(obj => obj.serialize()));
113
- values.forEach(value => value._persisted = false);
140
+ const serialized = values.map(obj => obj.serialize());
141
+ try {
142
+ await this.storage.removeAll(serialized, lenient);
143
+ }
144
+ finally {
145
+ values.forEach((value, index) => {
146
+ value._meta = serialized[index]._meta;
147
+ });
148
+ }
149
+ values.forEach((value) => {
150
+ value._persisted = false;
151
+ });
114
152
  }
115
153
  }
116
154
  exports.UnifiedSwapStorage = UnifiedSwapStorage;