astra-lightning 1.0.2 → 1.1.1
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/grpc/grpc_services.json +1 -1
- package/grpc/protos/invoices.proto +10 -4
- package/grpc/protos/lightning.proto +81 -6
- package/grpc/protos/rfqrpc/rfq.proto +107 -28
- package/grpc/protos/router.proto +91 -0
- package/grpc/protos/routerrpc/router.proto +56 -19
- package/grpc/protos/{taprootassetchannels.proto → tapchannelrpc.proto} +57 -0
- package/grpc/protos/taprootassets.proto +1438 -0
- package/index.js +2 -0
- package/lnd_methods/index.js +2 -0
- package/lnd_methods/invoices/create_invoice.js +0 -1
- package/lnd_methods/offchain/decode_asset_pay_req.d.ts +57 -0
- package/lnd_methods/offchain/decode_asset_pay_req.js +126 -0
- package/lnd_methods/offchain/index.d.ts +2 -0
- package/lnd_methods/offchain/index.js +2 -0
- package/lnd_responses/constants.json +1 -0
- package/lnd_responses/rpc_channel_as_channel.js +1 -0
- package/package.json +1 -1
- package/test.js +194 -0
package/index.js
CHANGED
|
@@ -16,6 +16,7 @@ const { createInvoice } = require('./lnd_methods');
|
|
|
16
16
|
const { createSeed } = require('./lnd_methods');
|
|
17
17
|
const { createWallet } = require('./lnd_methods');
|
|
18
18
|
const { decodePaymentRequest } = require('./lnd_methods');
|
|
19
|
+
const { decodeAssetPayReq } = require('./lnd_methods');
|
|
19
20
|
const { deleteChainTransaction } = require('./lnd_methods');
|
|
20
21
|
const { deleteFailedPayAttempts } = require('./lnd_methods');
|
|
21
22
|
const { deleteFailedPayments } = require('./lnd_methods');
|
|
@@ -178,6 +179,7 @@ module.exports = {
|
|
|
178
179
|
createSeed,
|
|
179
180
|
createWallet,
|
|
180
181
|
decodePaymentRequest,
|
|
182
|
+
decodeAssetPayReq,
|
|
181
183
|
deleteChainTransaction,
|
|
182
184
|
deleteFailedPayAttempts,
|
|
183
185
|
deleteFailedPayments,
|
package/lnd_methods/index.js
CHANGED
|
@@ -15,6 +15,7 @@ const { createInvoice } = require('./invoices');
|
|
|
15
15
|
const { createSeed } = require('./unauthenticated');
|
|
16
16
|
const { createWallet } = require('./unauthenticated');
|
|
17
17
|
const { decodePaymentRequest } = require('./offchain');
|
|
18
|
+
const { decodeAssetPayReq } = require('./offchain');
|
|
18
19
|
const { deleteChainTransaction } = require('./onchain');
|
|
19
20
|
const { deleteFailedPayAttempts } = require('./offchain');
|
|
20
21
|
const { deleteFailedPayments } = require('./offchain');
|
|
@@ -176,6 +177,7 @@ module.exports = {
|
|
|
176
177
|
createSeed,
|
|
177
178
|
createWallet,
|
|
178
179
|
decodePaymentRequest,
|
|
180
|
+
decodeAssetPayReq,
|
|
179
181
|
deleteChainTransaction,
|
|
180
182
|
deleteFailedPayAttempts,
|
|
181
183
|
deleteFailedPayments,
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AuthenticatedLndClient,
|
|
3
|
+
AuthenticatedTprClient,
|
|
4
|
+
DecimalDisplay,
|
|
5
|
+
PaymentRequestDetails,
|
|
6
|
+
} from '../../typescript';
|
|
7
|
+
|
|
8
|
+
export type DecodeAssetPayReqArgs = {
|
|
9
|
+
/** Asset ID Hex String */
|
|
10
|
+
asset_id: string;
|
|
11
|
+
/** Authenticated LND API Object */
|
|
12
|
+
lnd?: AuthenticatedLndClient;
|
|
13
|
+
/** BOLT 11 Payment Request String */
|
|
14
|
+
pay_req_string: string;
|
|
15
|
+
/** Authenticated TPR API Object */
|
|
16
|
+
tpr: AuthenticatedTprClient;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export type AssetGroup = {
|
|
20
|
+
/** Asset ID Hex Strings */
|
|
21
|
+
asset_ids: string[];
|
|
22
|
+
/** Tweaked Group Key String */
|
|
23
|
+
tweaked: string;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export type GenesisInfo = {
|
|
27
|
+
/** Asset ID Hex String */
|
|
28
|
+
asset_id: string;
|
|
29
|
+
/** Meta Hash Hex String */
|
|
30
|
+
meta_hash: string;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export type DecodeAssetPayReqResult = {
|
|
34
|
+
/** Invoice Amount in Asset Units Number */
|
|
35
|
+
asset_amount: number;
|
|
36
|
+
/** Asset Group Information */
|
|
37
|
+
asset_group?: AssetGroup;
|
|
38
|
+
/** Decimal Display Configuration */
|
|
39
|
+
decimal_display: DecimalDisplay;
|
|
40
|
+
/** Genesis Information */
|
|
41
|
+
genesis_info?: GenesisInfo;
|
|
42
|
+
/** Payment Request Details */
|
|
43
|
+
pay_req: PaymentRequestDetails;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Decode an asset payment request
|
|
48
|
+
*
|
|
49
|
+
* Requires `offchain:read` permission
|
|
50
|
+
*/
|
|
51
|
+
export declare const decodeAssetPayReq: (
|
|
52
|
+
args: DecodeAssetPayReqArgs,
|
|
53
|
+
cbk?: (
|
|
54
|
+
err: Error | null,
|
|
55
|
+
result: DecodeAssetPayReqResult,
|
|
56
|
+
) => void,
|
|
57
|
+
) => Promise<DecodeAssetPayReqResult>;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
const asyncAuto = require('async/auto');
|
|
2
|
+
const {returnResult} = require('asyncjs-util');
|
|
3
|
+
|
|
4
|
+
const hexAsBuffer = (hex) => (!!hex ? Buffer.from(hex, "hex") : undefined);
|
|
5
|
+
const bufferAsHex = (buffer) => (!!buffer ? buffer.toString("hex") : undefined);
|
|
6
|
+
|
|
7
|
+
/** Decode an asset payment request
|
|
8
|
+
|
|
9
|
+
Requires `offchain:read` permission
|
|
10
|
+
|
|
11
|
+
{
|
|
12
|
+
asset_id: <Asset ID Hex String>
|
|
13
|
+
lnd: <Authenticated LND API Object>
|
|
14
|
+
pay_req_string: <BOLT 11 Payment Request String>
|
|
15
|
+
tpr: <Authenticated TPR API Object>
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
@returns via cbk or Promise
|
|
19
|
+
{
|
|
20
|
+
asset_amount: <Invoice Amount in Asset Units Number>
|
|
21
|
+
asset_group: {
|
|
22
|
+
asset_ids: [<Asset Id Hex String>]
|
|
23
|
+
tweaked: <Tweaked Group Key String>
|
|
24
|
+
}
|
|
25
|
+
decimal_display: {
|
|
26
|
+
decimal_places: <Amount in Decimal Places for Asset String>
|
|
27
|
+
type: <Asset Type String>
|
|
28
|
+
units: <Asset Unit Label String>
|
|
29
|
+
}
|
|
30
|
+
genesis_info: {
|
|
31
|
+
asset_id: <Asset ID Hex String>
|
|
32
|
+
meta_hash: <Meta Hash Hex String>
|
|
33
|
+
}
|
|
34
|
+
pay_req: {
|
|
35
|
+
chain_address: <Fallback Chain Address String>
|
|
36
|
+
[cltv_delta]: <Final CLTV Delta Number>
|
|
37
|
+
created_at: <Payment Request Created At ISO 8601 Date String>
|
|
38
|
+
description: <Payment Description String>
|
|
39
|
+
description_hash: <Payment Longer Description Hash Hex String>
|
|
40
|
+
destination: <Public Key Hex String>
|
|
41
|
+
expires_at: <ISO 8601 Date String>
|
|
42
|
+
features: [{
|
|
43
|
+
bit: <BOLT 09 Feature Bit Number>
|
|
44
|
+
is_known: <Feature is Known Bool>
|
|
45
|
+
is_required: <Feature Support is Required To Pay Bool>
|
|
46
|
+
type: <Feature Type String>
|
|
47
|
+
}]
|
|
48
|
+
id: <Payment Hash Hex String>
|
|
49
|
+
is_expired: <Invoice is Expired Bool>
|
|
50
|
+
mtokens: <Requested Millitokens String>
|
|
51
|
+
[payment]: <Payment Identifier Hex Encoded String>
|
|
52
|
+
routes: [[{
|
|
53
|
+
[base_fee_mtokens]: <Base Routing Fee In Millitokens String>
|
|
54
|
+
[channel]: <Standard Format Channel Id String>
|
|
55
|
+
[cltv_delta]: <CLTV Blocks Delta Number>
|
|
56
|
+
[fee_rate]: <Fee Rate In Millitokens Per Million Number>
|
|
57
|
+
public_key: <Forward Edge Public Key Hex String>
|
|
58
|
+
}]]
|
|
59
|
+
safe_tokens: <Requested Tokens Rounded Up Number>
|
|
60
|
+
tokens: <Requested Tokens Rounded Down Number>
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
*/
|
|
64
|
+
module.exports = ({asset_id, pay_req_string, tpr}, cbk) => {
|
|
65
|
+
return new Promise((resolve, reject) => {
|
|
66
|
+
return asyncAuto({
|
|
67
|
+
// Check arguments
|
|
68
|
+
validate: cbk => {
|
|
69
|
+
if (!asset_id) {
|
|
70
|
+
return cbk([400, 'ExpectedAssetIdToDecodeAssetPayReq']);
|
|
71
|
+
}
|
|
72
|
+
if (!pay_req_string) {
|
|
73
|
+
return cbk([400, 'ExpectedPaymentRequestStringToDecodeAssetPayReq']);
|
|
74
|
+
}
|
|
75
|
+
if (!tpr) {
|
|
76
|
+
return cbk([400, 'ExpectedTprToDecodeAssetPayReq']);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return cbk();
|
|
80
|
+
},
|
|
81
|
+
|
|
82
|
+
// Decode asset payment request
|
|
83
|
+
decode: ['validate', ({}, cbk) => {
|
|
84
|
+
return tpr.taproot_asset_channels.decodeAssetPayReq({
|
|
85
|
+
asset_id: hexAsBuffer(asset_id),
|
|
86
|
+
pay_req_string: pay_req_string,
|
|
87
|
+
}, (err, res) => {
|
|
88
|
+
console.log("🚀 ~ decode ~ res:", res,err)
|
|
89
|
+
if (!!err) {
|
|
90
|
+
return cbk([503, 'UnexpectedDecodeAssetPayReqError', {err}]);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (!res) {
|
|
94
|
+
return cbk([503, 'ExpectedResponseFromDecodeAssetPayReq']);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Format the response
|
|
98
|
+
const response = {
|
|
99
|
+
asset_amount: res.asset_amount,
|
|
100
|
+
decimal_display: res.decimal_display,
|
|
101
|
+
pay_req: res.pay_req,
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
// Add asset group if exists
|
|
105
|
+
if (!!res.asset_group) {
|
|
106
|
+
response.asset_group = {
|
|
107
|
+
asset_ids: res.asset_group.asset_ids.map(id => bufferAsHex(id)),
|
|
108
|
+
tweaked: bufferAsHex(res.asset_group.tweaked),
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Add genesis info if exists
|
|
113
|
+
if (!!res.genesis_info) {
|
|
114
|
+
response.genesis_info = {
|
|
115
|
+
asset_id: bufferAsHex(res.genesis_info.asset_id),
|
|
116
|
+
meta_hash: bufferAsHex(res.genesis_info.meta_hash),
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return cbk(null, response);
|
|
121
|
+
});
|
|
122
|
+
}],
|
|
123
|
+
},
|
|
124
|
+
returnResult({reject, resolve, of: 'decode'}, cbk));
|
|
125
|
+
});
|
|
126
|
+
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export * from "./connect_watchtower";
|
|
2
|
+
export * from "./decode_asset_pay_req";
|
|
2
3
|
export * from "./decode_payment_request";
|
|
3
4
|
export * from "./delete_failed_pay_attempts";
|
|
4
5
|
export * from "./delete_failed_payments";
|
|
@@ -56,3 +57,4 @@ export * from "./update_pathfinding_settings";
|
|
|
56
57
|
export * from "./update_routing_fees";
|
|
57
58
|
export * from "./verify_backup";
|
|
58
59
|
export * from "./verify_backups";
|
|
60
|
+
export * from "./decode_asset_pay_req";
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const connectWatchtower = require('./connect_watchtower');
|
|
2
|
+
const decodeAssetPayReq = require('./decode_asset_pay_req');
|
|
2
3
|
const decodePaymentRequest = require('./decode_payment_request');
|
|
3
4
|
const deleteFailedPayAttempts = require('./delete_failed_pay_attempts');
|
|
4
5
|
const deleteFailedPayments = require('./delete_failed_payments');
|
|
@@ -59,6 +60,7 @@ const verifyBackups = require('./verify_backups');
|
|
|
59
60
|
|
|
60
61
|
module.exports = {
|
|
61
62
|
connectWatchtower,
|
|
63
|
+
decodeAssetPayReq,
|
|
62
64
|
decodePaymentRequest,
|
|
63
65
|
deleteFailedPayAttempts,
|
|
64
66
|
deleteFailedPayments,
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
"LEGACY": "original",
|
|
20
20
|
"SCRIPT_ENFORCED_LEASE": "anchor_with_lease_constraint",
|
|
21
21
|
"SIMPLE_TAPROOT": "simplified_taproot",
|
|
22
|
+
"SIMPLE_TAPROOT_OVERLAY": "simplified_taproot_overlay",
|
|
22
23
|
"STATIC_REMOTE_KEY": "original_with_static_to_remote"
|
|
23
24
|
},
|
|
24
25
|
"commitmentTypes": {
|
|
@@ -279,6 +279,7 @@ module.exports = args => {
|
|
|
279
279
|
transaction_id: transactionId,
|
|
280
280
|
transaction_vout: Number(vout),
|
|
281
281
|
type: channelTypes[args.commitment_type],
|
|
282
|
+
commitment_type: args.commitment_type,
|
|
282
283
|
unsettled_balance: Number(args.unsettled_balance),
|
|
283
284
|
custom_channel_data: customChannelData,
|
|
284
285
|
};
|
package/package.json
CHANGED
package/test.js
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
const {
|
|
2
|
+
authenticatedLndGrpc,
|
|
3
|
+
getChannels,
|
|
4
|
+
payTaprootInvoice,
|
|
5
|
+
decodePaymentRequest,
|
|
6
|
+
decodeAssetPayReq
|
|
7
|
+
} = require("./index.js");
|
|
8
|
+
const fs = require("fs");
|
|
9
|
+
// const dayjs = require("dayjs");
|
|
10
|
+
/* const LND_TLS_CERT =
|
|
11
|
+
"/Users/wjl/Documents/gamichi/2024/astra/volumes/server/tls.cert";
|
|
12
|
+
const base64Cert = fs.readFileSync(LND_TLS_CERT).toString("base64");
|
|
13
|
+
const LND_MACAROON =
|
|
14
|
+
"0201036c6e6402f801030a10860850e888c6982f5008d9802a2336d11201301a160a0761646472657373120472656164120577726974651a130a04696e666f120472656164120577726974651a170a08696e766f69636573120472656164120577726974651a210a086d616361726f6f6e120867656e6572617465120472656164120577726974651a160a076d657373616765120472656164120577726974651a170a086f6666636861696e120472656164120577726974651a160a076f6e636861696e120472656164120577726974651a140a057065657273120472656164120577726974651a180a067369676e6572120867656e657261746512047265616400000620ae6942110601d5fd7c8a95fda76195d72825a5fe3215a2e2bca8c520979540dd";
|
|
15
|
+
const LND_TPROOT_ASSET_MACAROON =
|
|
16
|
+
"0201047461706402ca01030a108d0850e888c6982f5008d9802a2336d11201301a180a09616464726573736573120472656164120577726974651a150a06617373657473120472656164120577726974651a110a086368616e6e656c73120577726974651a150a066461656d6f6e120472656164120577726974651a130a046d696e74120472656164120577726974651a150a0670726f6f6673120472656164120577726974651a120a03726671120472656164120577726974651a170a08756e69766572736512047265616412057772697465000006203f88b102cd1b94ea3c07fa15ef895d70cf7aa9c67eb50ced313eca9b86377f70";
|
|
17
|
+
const LND_SOCKET = "54.92.19.81:10109"; */
|
|
18
|
+
// const { ethers } = require("ethers");
|
|
19
|
+
// const assetId =
|
|
20
|
+
// "5bd129d549bd68cad64f2c2db141732a523e4546a49662c390e8c14294aa7e84"; //USDT
|
|
21
|
+
// const invoice =
|
|
22
|
+
// "lnbcrt10u1p5q3r0zpp50v0asn72aav354e27cals6l7j76sln0pzzvxktgur2wmlkf44mfqdy0f3hxv6fmv9ehxet5f9zr5dtzvscnywtyx56rjcnyxcuxxctyxc6xvvnrxfjxyvf5xymnxvnpx5erxef5x56rvcf58ymrvvnrxvunqefcvvcngv3ex3skzdm98q6rkctdda6kuap6xycrqwscqzzsxqrrssrzjqg3zz9zaagxqxan9fqzr6k7yvf900uf26m0z7c2g0rf55raupqclpakyc0a4gzq2v5qqqqlgqqqqqqgq2qsp58qmfwjwdrvr9dzjs2esms3cpvvgff3g4hsunszne3v7wszwcq62s9qxpqysgqscq2e3sqa0pfe5yzjdnp8q4temjazdw6y77c49tpvnhz0d4kjux92tw3gy9vvrh68qqef594frdp2uqhvwjy0sd7ezdcanvlln2rusgpg5w96t";
|
|
23
|
+
|
|
24
|
+
const LND_SOCKET = "127.0.0.1:8445"
|
|
25
|
+
const LND_MACAROON="0201036c6e6402f801030a10ce3f5e2dcbdd316f7d747797c37d2e6f1201301a160a0761646472657373120472656164120577726974651a130a04696e666f120472656164120577726974651a170a08696e766f69636573120472656164120577726974651a210a086d616361726f6f6e120867656e6572617465120472656164120577726974651a160a076d657373616765120472656164120577726974651a170a086f6666636861696e120472656164120577726974651a160a076f6e636861696e120472656164120577726974651a140a057065657273120472656164120577726974651a180a067369676e6572120867656e6572617465120472656164000006201405ad3da48e9500d8df7af8a0f69d788a1245796fd7fa5005205d81fbb1e0bf"
|
|
26
|
+
const LND_TPROOT_ASSET_MACAROON="0201047461706402d001030a10d63f5e2dcbdd316f7d747797c37d2e6f1201301a180a09616464726573736573120472656164120577726974651a150a06617373657473120472656164120577726974651a170a086368616e6e656c73120472656164120577726974651a150a066461656d6f6e120472656164120577726974651a130a046d696e74120472656164120577726974651a150a0670726f6f6673120472656164120577726974651a120a03726671120472656164120577726974651a170a08756e69766572736512047265616412057772697465000006206522977ce9ea4dcbd9bc740f98c7949b5c5305e7f0bf77cb1d138855a2ca1961"
|
|
27
|
+
const base64Cert="LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUNEVENDQWJLZ0F3SUJBZ0lSQU16eVFvTnVBZ01HdUFDTGxtNlNqVWt3Q2dZSUtvWkl6ajBFQXdJd01ERWcKTUI0R0ExVUVDaE1YYkdsMFpDQmhkWFJ2WjJWdVpYSmhkR1ZrSUdObGNuUXhEREFLQmdOVkJBTVRBMkp2WWpBZQpGdzB5TlRBeU1UWXdPVEU0TXpWYUZ3MHlOakEwTVRNd09URTRNelZhTURBeElEQWVCZ05WQkFvVEYyeHBkR1FnCllYVjBiMmRsYm1WeVlYUmxaQ0JqWlhKME1Rd3dDZ1lEVlFRREV3TmliMkl3V1RBVEJnY3Foa2pPUFFJQkJnZ3EKaGtqT1BRTUJCd05DQUFUR05qTGhicGY5eExQbGlqelZLM3BncU5POWZGMVpPaGtOanVrbTdTcVdJa0dNRmF5OAp4SERMaUhmQi85enAwZnJXQkdwc1VGazhVUW5HbzZXaFZIL3ZvNEdzTUlHcE1BNEdBMVVkRHdFQi93UUVBd0lDCnBEQVRCZ05WSFNVRUREQUtCZ2dyQmdFRkJRY0RBVEFQQmdOVkhSTUJBZjhFQlRBREFRSC9NQjBHQTFVZERnUVcKQkJUQ3lLdmc4Vk5sMlZOVFoybnpEbE9ydzZTQXdEQlNCZ05WSFJFRVN6QkpnZ05pYjJLQ0NXeHZZMkZzYUc5egpkSUlFZFc1cGVJSUtkVzVwZUhCaFkydGxkSUlIWW5WbVkyOXVib2NFZndBQUFZY1FBQUFBQUFBQUFBQUFBQUFBCkFBQUFBWWNFckJNQUJEQUtCZ2dxaGtqT1BRUURBZ05KQURCR0FpRUF1aWxIVGgydUVGYXA1MGpaMzJPMWtQWTcKd3R6Qkc1T3B4a1pBczBYZHVLTUNJUURaSWlPaXRnZGtEQlFVQ1NyV1JNNWlDRnNObnR4Y3JxQTV2VkVER0E4awpadz09Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K"
|
|
28
|
+
const assetId = "013eb3bad46547e67e78f67fa68349828303dda9689d4cebe6697756def223fb"
|
|
29
|
+
const invoice = "lnbcrt100u1p5q39x9pp5ujuvnrn342l798x6tpn6qahe8x798m7ewx97ymefshnstvwyatysdqqcqzzsxqrrssrzjq2t93du9nlmhyt3u0juc2a76tlcy602hzdcyay969dhcnlxxu6rutah4ntgudu02k5qqqqlgqqqqqqgq2qsp5mtqkapc04gksgmdjt42m4swkux48vjmqlu6jy6edz8fvec8kevrq9qxpqysgq02asgefvgvqq32x7qju4g6p66kdxgz0yxcxzedysmurfp62fvmkzv3tutd8lz354qy08h8k8aaqfp3khgq8vp5zpjn8z9uc69cvluhsqysdypv"
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
const { lnd } = authenticatedLndGrpc({
|
|
33
|
+
cert: base64Cert,
|
|
34
|
+
macaroon: LND_MACAROON,
|
|
35
|
+
socket: LND_SOCKET,
|
|
36
|
+
});
|
|
37
|
+
const { lnd: tpr } = authenticatedLndGrpc({
|
|
38
|
+
cert: base64Cert,
|
|
39
|
+
macaroon: LND_TPROOT_ASSET_MACAROON,
|
|
40
|
+
socket: LND_SOCKET,
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
const payWithTpr = async (invoice, assetId) => {
|
|
45
|
+
// const provider = new ethers.JsonRpcProvider('https://eth-sepolia.g.alchemy.com/v2/ClvXGqSMvZ6nEb_G5ekJGsZwNdsp72oz');
|
|
46
|
+
// const lspSigner = new ethers.Wallet('dd5862c69e641fb052092d34724ce62764186abf87474656f2b2149684dca754', provider);
|
|
47
|
+
// const signature = await lspSigner.signMessage('123');
|
|
48
|
+
// console.log("🚀 ~ signature:", signature)
|
|
49
|
+
// return;
|
|
50
|
+
|
|
51
|
+
// const decodedInvoice1 = await decodePaymentRequest({
|
|
52
|
+
// lnd: lnd,
|
|
53
|
+
// request: invoice
|
|
54
|
+
// })
|
|
55
|
+
|
|
56
|
+
const ret = await getChannels({ lnd }).catch((error) => console.log(error));
|
|
57
|
+
|
|
58
|
+
const filterChannels = ret.channels.filter(
|
|
59
|
+
(channel) =>
|
|
60
|
+
channel.commitment_type.includes("SIMPLE_TAPROOT") &&
|
|
61
|
+
channel.is_active === true &&
|
|
62
|
+
channel.custom_channel_data.includes(assetId)
|
|
63
|
+
);
|
|
64
|
+
if (filterChannels.length === 0) {
|
|
65
|
+
throw new Error("no available channel");
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const sortTprChannels = filterChannels.sort((a, b) => {
|
|
69
|
+
return a.local_balance - b.local_balance;
|
|
70
|
+
});
|
|
71
|
+
const maxLocalBalanceChannel = sortTprChannels[0];
|
|
72
|
+
console.log(
|
|
73
|
+
"🚀 ~ payWithTpr ~ maxLocalBalanceChannel:",
|
|
74
|
+
maxLocalBalanceChannel
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
const effectiveBalance =
|
|
78
|
+
maxLocalBalanceChannel.local_balance - maxLocalBalanceChannel.local_reserve;
|
|
79
|
+
const custom_channel_data = maxLocalBalanceChannel.custom_channel_data
|
|
80
|
+
? JSON.parse(maxLocalBalanceChannel.custom_channel_data)
|
|
81
|
+
: null;
|
|
82
|
+
const { capacity, local_balance, remote_balance } =
|
|
83
|
+
custom_channel_data.assets[0];
|
|
84
|
+
|
|
85
|
+
const decodedInvoice = await decodePaymentRequest({
|
|
86
|
+
lnd: lnd,
|
|
87
|
+
request: invoice,
|
|
88
|
+
});
|
|
89
|
+
const now = Math.floor(Date.now() / 1000);
|
|
90
|
+
const expires_at = dayjs(decodedInvoice.expires_at).unix();
|
|
91
|
+
|
|
92
|
+
if (now > expires_at) {
|
|
93
|
+
throw new Error("invoice is expired");
|
|
94
|
+
}
|
|
95
|
+
const invoiceAmount = decodedInvoice.tokens;
|
|
96
|
+
|
|
97
|
+
if (effectiveBalance < invoiceAmount) {
|
|
98
|
+
throw new Error(
|
|
99
|
+
`channelId: ${maxLocalBalanceChannel.channel_id} not enough balance`
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
const peerPubkey = maxLocalBalanceChannel.partner_public_key;
|
|
103
|
+
const retPay = await payTaprootInvoice({
|
|
104
|
+
lnd: lnd,
|
|
105
|
+
tpr: tpr,
|
|
106
|
+
asset_id: assetId,
|
|
107
|
+
asset_amount: 10,
|
|
108
|
+
peer_pubkey: peerPubkey,
|
|
109
|
+
payment_request: {
|
|
110
|
+
payment_request: invoice,
|
|
111
|
+
fee_limit_sat: 1000,
|
|
112
|
+
allow_self_payment: true,
|
|
113
|
+
timeout_seconds: 60 * 5,
|
|
114
|
+
outgoing_chan_id: maxLocalBalanceChannel.channel_id,
|
|
115
|
+
},
|
|
116
|
+
}).catch((e) => {
|
|
117
|
+
console.log("error", e.message);
|
|
118
|
+
});
|
|
119
|
+
console.log("ret", retPay);
|
|
120
|
+
|
|
121
|
+
/*
|
|
122
|
+
ret {
|
|
123
|
+
payment_result: {
|
|
124
|
+
htlcs: [ [Object] ],
|
|
125
|
+
payment_hash: 'b0924b224b51b7cd8065c1ef2f804d9ffc9adb6cd89d7ffa962b450cc77646de',
|
|
126
|
+
value: '24330',
|
|
127
|
+
creation_date: '1731480102',
|
|
128
|
+
fee: '0',
|
|
129
|
+
payment_preimage: '0fd2d89b423754456476ec6f58d63e104a5b61e2a3eb1223e855b3d7f6f62e24',
|
|
130
|
+
value_sat: '24330',
|
|
131
|
+
value_msat: '24330600',
|
|
132
|
+
payment_request: 'lnbcrt243306n1pnngjs6pp5kzfykgjt2xmumqr9c8hjlqzdnl7f4kmvmzwhl75k9dzse3mkgm0qdxvdec82c33wdmnq73s0qcxwurrxp4nquncxe4h56m9xu6xwetyd3mrq6ehdguxkd35wuurgarex4u8gefkdsekgdtnddehxurrxecxvhmwwp6kyvfexekhxwtv8paryvnpwsuhxdryvachwangw3kn2atddq6kzvrvwfcxzanewce8ja34d43k56rkweu8jdtcwv68zmrsvdescqzzsxqzfvrzjq2dw2l3yth0hy67kq6x5p8ght877y60ysypzxr98a66vr9c8u3hx7aqlt66fkl4dssqqqqlgqqqqqqgq2qsp54gsfgcdv5a804xr3wu9xr983re2u53rzaefxwsynf5aq5yx0mddq9qxpqysgqe3pnkercm3sskfchpmmfdgsyuaqd7k68r0yrgulygdw484w65trrqn82p6e9ce70c6fgr2pr3pqp88rmd3p6rk87d8rrxzhq2xw0haqp9c5eth',
|
|
133
|
+
status: 'SUCCEEDED',
|
|
134
|
+
fee_sat: '0',
|
|
135
|
+
fee_msat: '0',
|
|
136
|
+
creation_time_ns: '1731480102000736406',
|
|
137
|
+
payment_index: '3034',
|
|
138
|
+
failure_reason: 'FAILURE_REASON_NONE'
|
|
139
|
+
},
|
|
140
|
+
failure_reason: null,
|
|
141
|
+
assepted_sell_order: {
|
|
142
|
+
peer: '03aa8f3069b0116f8bf10ed6cb218657b92a972ee9b1ee41093cdacd6faed91735',
|
|
143
|
+
id: 'c4c2b055d8a76e03a6bd0893129b678c815f86f9241518a0175a270c6d5d58d9',
|
|
144
|
+
scid: '1682700345104226521',
|
|
145
|
+
asset_amount: '693032',
|
|
146
|
+
bid_price: '11586',
|
|
147
|
+
expiry: '1731480401970'
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
*/
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
//payWithTpr(invoice, assetId);
|
|
155
|
+
|
|
156
|
+
//const secret = crypto.randomBytes(32);
|
|
157
|
+
//const preimage = secret.toString("hex");
|
|
158
|
+
//console.log("🚀 ~ preimage:", preimage)
|
|
159
|
+
// const hash = sha256.hex(Buffer.from("9060effcf05155835f7baf0089a2fc086eb6d9f4dbb680c1744261b562a51519", "hex"));
|
|
160
|
+
// console.log("🚀 ~ hash:", hash)
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
//getPayemntById();
|
|
165
|
+
//getGasFee();
|
|
166
|
+
|
|
167
|
+
//9060effcf05155835f7baf0089a2fc086eb6d9f4dbb680c1744261b562a51519 b48a0bb1c075a0bf390ed156c6e7474fd1d0ceb203645b73db714145da4540cd
|
|
168
|
+
|
|
169
|
+
// const provider = new ethers.JsonRpcProvider('https://eth-sepolia.g.alchemy.com/v2/ClvXGqSMvZ6nEb_G5ekJGsZwNdsp72oz');
|
|
170
|
+
// const queryBalance = async () => {
|
|
171
|
+
// const ret = await provider.getBalance('0x978E3C654c78CD27A3a7aC2F9637f5086B7A3220')
|
|
172
|
+
// console.log("🚀 ~ queryBalance ~ ret:", ethers.formatEther(ret))
|
|
173
|
+
// }
|
|
174
|
+
// queryBalance();
|
|
175
|
+
|
|
176
|
+
const test = async () => {
|
|
177
|
+
/* const {methods} = await getMethods({ lnd }).catch((error) => console.log(error.message));
|
|
178
|
+
console.log("🚀 ~ test ~ methods:",methods, methods.find(item=>item.endpoint.includes('DecodeAssetPayReq'))); */
|
|
179
|
+
|
|
180
|
+
const ret = await decodeAssetPayReq({
|
|
181
|
+
asset_id: assetId,
|
|
182
|
+
pay_req_string: invoice,
|
|
183
|
+
tpr: tpr,
|
|
184
|
+
}).catch((error) => console.log(error.message));
|
|
185
|
+
console.log("🚀 ~ ret:", ret);
|
|
186
|
+
/* ret {
|
|
187
|
+
asset_amount: '100',
|
|
188
|
+
decimal_display: { decimal_display: 2 },
|
|
189
|
+
}
|
|
190
|
+
*/
|
|
191
|
+
/* const ret = await getChannels({ lnd }).catch((error) => console.log(error));
|
|
192
|
+
console.log("🚀 ~ test ~ ret:", ret); */
|
|
193
|
+
};
|
|
194
|
+
test();
|