@atomiqlabs/lp-lib 16.0.8 → 16.0.10
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 +11 -9
- package/dist/swaps/escrow/tobtcln_abstract/ToBtcLnAbs.d.ts +2 -3
- package/dist/swaps/escrow/tobtcln_abstract/ToBtcLnAbs.js +24 -19
- package/package.json +1 -1
- package/src/info/InfoHandler.ts +13 -10
- package/src/swaps/escrow/tobtcln_abstract/ToBtcLnAbs.ts +26 -23
package/dist/info/InfoHandler.js
CHANGED
|
@@ -18,20 +18,19 @@ class InfoHandler {
|
|
|
18
18
|
* @param restServer
|
|
19
19
|
*/
|
|
20
20
|
startRestServer(restServer) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
if (
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
!HEX_REGEX.test(req.body.nonce)) {
|
|
21
|
+
const infoHandler = async (req, res) => {
|
|
22
|
+
const reqParams = { ...req.body, ...req.query };
|
|
23
|
+
if (reqParams.nonce == null ||
|
|
24
|
+
typeof (reqParams.nonce) !== "string" ||
|
|
25
|
+
reqParams.nonce.length > 64 ||
|
|
26
|
+
!HEX_REGEX.test(reqParams.nonce)) {
|
|
28
27
|
res.status(400).json({
|
|
29
28
|
msg: "Invalid request body (nonce)"
|
|
30
29
|
});
|
|
31
30
|
return;
|
|
32
31
|
}
|
|
33
32
|
const env = {
|
|
34
|
-
nonce:
|
|
33
|
+
nonce: reqParams.nonce,
|
|
35
34
|
services: {}
|
|
36
35
|
};
|
|
37
36
|
for (let swapHandler of this.swapHandlers) {
|
|
@@ -52,7 +51,10 @@ class InfoHandler {
|
|
|
52
51
|
chains
|
|
53
52
|
};
|
|
54
53
|
res.status(200).json(response);
|
|
55
|
-
}
|
|
54
|
+
};
|
|
55
|
+
restServer.use(this.path + "/info", express.json());
|
|
56
|
+
restServer.post(this.path + "/info", infoHandler);
|
|
57
|
+
restServer.get(this.path + "/info", infoHandler);
|
|
56
58
|
}
|
|
57
59
|
}
|
|
58
60
|
exports.InfoHandler = InfoHandler;
|
|
@@ -167,11 +167,10 @@ export declare class ToBtcLnAbs extends ToBtcBaseSwapHandler<ToBtcLnSwapAbs, ToB
|
|
|
167
167
|
* Checks if the newly submitted PR has the same parameters (destination, cltv_delta, routes) as the initial dummy
|
|
168
168
|
* invoice sent for exactIn swap quote
|
|
169
169
|
*
|
|
170
|
-
* @param
|
|
170
|
+
* @param parsedRequest
|
|
171
171
|
* @param parsedAuth
|
|
172
|
-
* @throws {DefinedRuntimeError} will throw an error if the details don't match
|
|
173
172
|
*/
|
|
174
|
-
private
|
|
173
|
+
private isPaymentRequestMatchingInitial;
|
|
175
174
|
startRestServer(restServer: Express): void;
|
|
176
175
|
init(): Promise<void>;
|
|
177
176
|
getInfoData(): any;
|
|
@@ -537,26 +537,13 @@ class ToBtcLnAbs extends ToBtcBaseSwapHandler_1.ToBtcBaseSwapHandler {
|
|
|
537
537
|
* Checks if the newly submitted PR has the same parameters (destination, cltv_delta, routes) as the initial dummy
|
|
538
538
|
* invoice sent for exactIn swap quote
|
|
539
539
|
*
|
|
540
|
-
* @param
|
|
540
|
+
* @param parsedRequest
|
|
541
541
|
* @param parsedAuth
|
|
542
|
-
* @throws {DefinedRuntimeError} will throw an error if the details don't match
|
|
543
542
|
*/
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
parsedRequest.
|
|
548
|
-
parsedRequest.mtokens !== parsedAuth.amount * 1000n) {
|
|
549
|
-
throw {
|
|
550
|
-
code: 20102,
|
|
551
|
-
msg: "Provided PR doesn't match initial!"
|
|
552
|
-
};
|
|
553
|
-
}
|
|
554
|
-
if (!(0, ILightningWallet_1.routesMatch)(parsedRequest.routes, parsedAuth.initialInvoice.routes)) {
|
|
555
|
-
throw {
|
|
556
|
-
code: 20102,
|
|
557
|
-
msg: "Provided PR doesn't match initial (routes)!"
|
|
558
|
-
};
|
|
559
|
-
}
|
|
543
|
+
isPaymentRequestMatchingInitial(parsedRequest, parsedAuth) {
|
|
544
|
+
return parsedRequest.destination === parsedAuth.initialInvoice.destination &&
|
|
545
|
+
parsedRequest.cltvDelta === parsedAuth.initialInvoice.cltvDelta &&
|
|
546
|
+
(0, ILightningWallet_1.routesMatch)(parsedRequest.routes, parsedAuth.initialInvoice.routes);
|
|
560
547
|
}
|
|
561
548
|
startRestServer(restServer) {
|
|
562
549
|
restServer.use(this.path + "/payInvoiceExactIn", (0, ServerParamDecoder_1.serverParamDecoder)(10 * 1000));
|
|
@@ -583,7 +570,25 @@ class ToBtcLnAbs extends ToBtcBaseSwapHandler_1.ToBtcBaseSwapHandler {
|
|
|
583
570
|
const abortSignal = responseStream.getAbortSignal();
|
|
584
571
|
//Check request params
|
|
585
572
|
const { parsedPR, halfConfidence } = await this.checkPaymentRequest(parsedAuth.chainIdentifier, parsedBody.pr);
|
|
586
|
-
|
|
573
|
+
if (parsedPR.mtokens !== parsedAuth.amount * 1000n)
|
|
574
|
+
throw {
|
|
575
|
+
code: 20102,
|
|
576
|
+
msg: "Provided PR doesn't match requested (amount)!"
|
|
577
|
+
};
|
|
578
|
+
if (!this.isPaymentRequestMatchingInitial(parsedPR, parsedAuth)) {
|
|
579
|
+
//The provided payment request doesn't match the parameters from the initial one, try to probe/route again
|
|
580
|
+
// with the same max fee parameters
|
|
581
|
+
const currentTimestamp = BigInt(Math.floor(Date.now() / 1000));
|
|
582
|
+
const { networkFee, confidence } = await this.checkAndGetNetworkFee(parsedAuth.amount, parsedAuth.quotedNetworkFee, parsedAuth.swapExpiry, currentTimestamp, parsedBody.pr, parsedAuth.metadata, abortSignal);
|
|
583
|
+
this.logger.info("REST: /payInvoiceExactIn: re-checked network fee for exact-in swap," +
|
|
584
|
+
" reqId: " + parsedBody.reqId +
|
|
585
|
+
" initialNetworkFee: " + parsedAuth.quotedNetworkFee.toString(10) +
|
|
586
|
+
" newNetworkFee: " + networkFee.toString(10) +
|
|
587
|
+
" oldConfidence: " + parsedAuth.confidence.toString(10) +
|
|
588
|
+
" newConfidence: " + confidence.toString(10) +
|
|
589
|
+
" invoice: " + parsedBody.pr);
|
|
590
|
+
parsedAuth.confidence = confidence;
|
|
591
|
+
}
|
|
587
592
|
const metadata = parsedAuth.metadata;
|
|
588
593
|
const sequence = base_1.BigIntBufferUtils.fromBuffer((0, crypto_1.randomBytes)(8));
|
|
589
594
|
const { swapContract, signer } = this.getChain(parsedAuth.chainIdentifier);
|
package/package.json
CHANGED
package/src/info/InfoHandler.ts
CHANGED
|
@@ -44,15 +44,14 @@ export class InfoHandler {
|
|
|
44
44
|
*/
|
|
45
45
|
startRestServer(restServer: Express) {
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
if (
|
|
50
|
-
req.body == null ||
|
|
47
|
+
const infoHandler = async (req, res) => {
|
|
48
|
+
const reqParams = {...req.body, ...req.query};
|
|
51
49
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
50
|
+
if (
|
|
51
|
+
reqParams.nonce == null ||
|
|
52
|
+
typeof(reqParams.nonce) !== "string" ||
|
|
53
|
+
reqParams.nonce.length>64 ||
|
|
54
|
+
!HEX_REGEX.test(reqParams.nonce)
|
|
56
55
|
) {
|
|
57
56
|
res.status(400).json({
|
|
58
57
|
msg: "Invalid request body (nonce)"
|
|
@@ -61,7 +60,7 @@ export class InfoHandler {
|
|
|
61
60
|
}
|
|
62
61
|
|
|
63
62
|
const env: InfoHandlerResponseEnvelope = {
|
|
64
|
-
nonce:
|
|
63
|
+
nonce: reqParams.nonce,
|
|
65
64
|
services: {}
|
|
66
65
|
};
|
|
67
66
|
|
|
@@ -92,7 +91,11 @@ export class InfoHandler {
|
|
|
92
91
|
};
|
|
93
92
|
|
|
94
93
|
res.status(200).json(response);
|
|
95
|
-
}
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
restServer.use(this.path+"/info", express.json());
|
|
97
|
+
restServer.post(this.path+"/info", infoHandler);
|
|
98
|
+
restServer.get(this.path+"/info", infoHandler);
|
|
96
99
|
|
|
97
100
|
}
|
|
98
101
|
|
|
@@ -666,30 +666,13 @@ export class ToBtcLnAbs extends ToBtcBaseSwapHandler<ToBtcLnSwapAbs, ToBtcLnSwap
|
|
|
666
666
|
* Checks if the newly submitted PR has the same parameters (destination, cltv_delta, routes) as the initial dummy
|
|
667
667
|
* invoice sent for exactIn swap quote
|
|
668
668
|
*
|
|
669
|
-
* @param
|
|
669
|
+
* @param parsedRequest
|
|
670
670
|
* @param parsedAuth
|
|
671
|
-
* @throws {DefinedRuntimeError} will throw an error if the details don't match
|
|
672
671
|
*/
|
|
673
|
-
private
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
parsedRequest.destination!==parsedAuth.initialInvoice.destination ||
|
|
678
|
-
parsedRequest.cltvDelta!==parsedAuth.initialInvoice.cltvDelta ||
|
|
679
|
-
parsedRequest.mtokens!==parsedAuth.amount * 1000n
|
|
680
|
-
) {
|
|
681
|
-
throw {
|
|
682
|
-
code: 20102,
|
|
683
|
-
msg: "Provided PR doesn't match initial!"
|
|
684
|
-
};
|
|
685
|
-
}
|
|
686
|
-
|
|
687
|
-
if(!routesMatch(parsedRequest.routes, parsedAuth.initialInvoice.routes)) {
|
|
688
|
-
throw {
|
|
689
|
-
code: 20102,
|
|
690
|
-
msg: "Provided PR doesn't match initial (routes)!"
|
|
691
|
-
};
|
|
692
|
-
}
|
|
672
|
+
private isPaymentRequestMatchingInitial(parsedRequest: ParsedPaymentRequest, parsedAuth: ExactInAuthorization): boolean {
|
|
673
|
+
return parsedRequest.destination===parsedAuth.initialInvoice.destination &&
|
|
674
|
+
parsedRequest.cltvDelta===parsedAuth.initialInvoice.cltvDelta &&
|
|
675
|
+
routesMatch(parsedRequest.routes, parsedAuth.initialInvoice.routes);
|
|
693
676
|
}
|
|
694
677
|
|
|
695
678
|
startRestServer(restServer: Express) {
|
|
@@ -721,7 +704,27 @@ export class ToBtcLnAbs extends ToBtcBaseSwapHandler<ToBtcLnSwapAbs, ToBtcLnSwap
|
|
|
721
704
|
|
|
722
705
|
//Check request params
|
|
723
706
|
const {parsedPR, halfConfidence} = await this.checkPaymentRequest(parsedAuth.chainIdentifier, parsedBody.pr);
|
|
724
|
-
|
|
707
|
+
if(parsedPR.mtokens!==parsedAuth.amount*1000n) throw {
|
|
708
|
+
code: 20102,
|
|
709
|
+
msg: "Provided PR doesn't match requested (amount)!"
|
|
710
|
+
};
|
|
711
|
+
if(!this.isPaymentRequestMatchingInitial(parsedPR, parsedAuth)) {
|
|
712
|
+
//The provided payment request doesn't match the parameters from the initial one, try to probe/route again
|
|
713
|
+
// with the same max fee parameters
|
|
714
|
+
const currentTimestamp: bigint = BigInt(Math.floor(Date.now()/1000));
|
|
715
|
+
const {networkFee, confidence} = await this.checkAndGetNetworkFee(
|
|
716
|
+
parsedAuth.amount, parsedAuth.quotedNetworkFee, parsedAuth.swapExpiry,
|
|
717
|
+
currentTimestamp, parsedBody.pr, parsedAuth.metadata, abortSignal
|
|
718
|
+
);
|
|
719
|
+
this.logger.info("REST: /payInvoiceExactIn: re-checked network fee for exact-in swap,"+
|
|
720
|
+
" reqId: "+parsedBody.reqId+
|
|
721
|
+
" initialNetworkFee: "+parsedAuth.quotedNetworkFee.toString(10)+
|
|
722
|
+
" newNetworkFee: "+networkFee.toString(10)+
|
|
723
|
+
" oldConfidence: "+parsedAuth.confidence.toString(10)+
|
|
724
|
+
" newConfidence: "+confidence.toString(10)+
|
|
725
|
+
" invoice: "+parsedBody.pr);
|
|
726
|
+
parsedAuth.confidence = confidence;
|
|
727
|
+
}
|
|
725
728
|
|
|
726
729
|
const metadata = parsedAuth.metadata;
|
|
727
730
|
|