lightning 9.14.0 → 10.0.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.
- package/CHANGELOG.md +9 -0
- package/grpc/protos/lightning.proto +5 -0
- package/index.d.ts +0 -1
- package/index.js +0 -6
- package/lnd_methods/info/constants.json +1 -0
- package/package.json +6 -12
- package/lnd_gateway/bearer_token.js +0 -30
- package/lnd_gateway/decode_cbor_body.js +0 -30
- package/lnd_gateway/emit_event.js +0 -18
- package/lnd_gateway/emit_grpc_events.d.ts +0 -17
- package/lnd_gateway/emit_grpc_events.js +0 -50
- package/lnd_gateway/encode_response.js +0 -42
- package/lnd_gateway/execute_request.js +0 -74
- package/lnd_gateway/gateway_request.js +0 -143
- package/lnd_gateway/gateway_subscribe.js +0 -53
- package/lnd_gateway/grpc_response.js +0 -42
- package/lnd_gateway/grpc_router.d.ts +0 -13
- package/lnd_gateway/grpc_router.js +0 -45
- package/lnd_gateway/handle_errors.js +0 -37
- package/lnd_gateway/index.d.ts +0 -3
- package/lnd_gateway/index.js +0 -5
- package/lnd_gateway/lnd_gateway.d.ts +0 -37
- package/lnd_gateway/lnd_gateway.js +0 -118
- package/lnd_gateway/return_response.js +0 -38
- package/lnd_gateway/subscribe_to_response.js +0 -40
- package/lnd_gateway/ws_url.js +0 -34
- package/test/lnd_gateway/test_bearer_token.js +0 -31
- package/test/lnd_gateway/test_decode_cbor_body.js +0 -37
- package/test/lnd_gateway/test_emit_event.js +0 -51
- package/test/lnd_gateway/test_emit_grpc_events.js +0 -31
- package/test/lnd_gateway/test_encode_response.js +0 -37
- package/test/lnd_gateway/test_gateway_request.js +0 -139
- package/test/lnd_gateway/test_gateway_subscribe.js +0 -97
- package/test/lnd_gateway/test_grpc_response.js +0 -29
- package/test/lnd_gateway/test_grpc_router.js +0 -20
- package/test/lnd_gateway/test_handle_errors.js +0 -48
- package/test/lnd_gateway/test_lnd_gateway.js +0 -67
- package/test/lnd_gateway/test_return_response.js +0 -51
- package/test/lnd_gateway/test_ws_url.js +0 -32
- package/test/typescript/emit_grpc_events.test-d.ts +0 -12
- package/test/typescript/grpc_router.test-d.ts +0 -8
- package/test/typescript/lnd_gateway.test-d.ts +0 -36
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# Versions
|
|
2
2
|
|
|
3
|
+
## 10.0.0
|
|
4
|
+
|
|
5
|
+
- Add support for LND 0.17.0-beta
|
|
6
|
+
|
|
7
|
+
### Breaking Changes
|
|
8
|
+
|
|
9
|
+
- End support for node.js 16, require 18 or higher
|
|
10
|
+
- `emitGrpcEvents`, `grpcRouter`, `lndGateway`: Remove gRPC gateway methods
|
|
11
|
+
|
|
3
12
|
## 9.14.0
|
|
4
13
|
|
|
5
14
|
- `openChannel`: Add `is_allowing_minimal_reserve` to allow no reserve on peer
|
|
@@ -2453,6 +2453,11 @@ message ChanPointShim {
|
|
|
2453
2453
|
the value is less than 500,000, or as an absolute height otherwise.
|
|
2454
2454
|
*/
|
|
2455
2455
|
uint32 thaw_height = 6;
|
|
2456
|
+
|
|
2457
|
+
/*
|
|
2458
|
+
Indicates that the funding output is using a MuSig2 multi-sig output.
|
|
2459
|
+
*/
|
|
2460
|
+
bool musig2 = 7;
|
|
2456
2461
|
}
|
|
2457
2462
|
|
|
2458
2463
|
message PsbtShim {
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -23,7 +23,6 @@ const {deletePendingChannel} = require('./lnd_methods');
|
|
|
23
23
|
const {diffieHellmanComputeSecret} = require('./lnd_methods');
|
|
24
24
|
const {disableChannel} = require('./lnd_methods');
|
|
25
25
|
const {disconnectWatchtower} = require('./lnd_methods');
|
|
26
|
-
const {emitGrpcEvents} = require('./lnd_gateway');
|
|
27
26
|
const {enableChannel} = require('./lnd_methods');
|
|
28
27
|
const {endGroupSigningSession} = require('./lnd_methods');
|
|
29
28
|
const {fundPendingChannels} = require('./lnd_methods');
|
|
@@ -79,9 +78,7 @@ const {getWalletInfo} = require('./lnd_methods');
|
|
|
79
78
|
const {getWalletStatus} = require('./lnd_methods');
|
|
80
79
|
const {getWalletVersion} = require('./lnd_methods');
|
|
81
80
|
const {grantAccess} = require('./lnd_methods');
|
|
82
|
-
const {grpcRouter} = require('./lnd_gateway');
|
|
83
81
|
const {isDestinationPayable} = require('./lnd_methods');
|
|
84
|
-
const {lndGateway} = require('./lnd_gateway');
|
|
85
82
|
const {lockUtxo} = require('./lnd_methods');
|
|
86
83
|
const {openChannel} = require('./lnd_methods');
|
|
87
84
|
const {openChannels} = require('./lnd_methods');
|
|
@@ -179,7 +176,6 @@ module.exports = {
|
|
|
179
176
|
enableChannel,
|
|
180
177
|
endGroupSigningSession,
|
|
181
178
|
diffieHellmanComputeSecret,
|
|
182
|
-
emitGrpcEvents,
|
|
183
179
|
fundPendingChannels,
|
|
184
180
|
fundPsbt,
|
|
185
181
|
getAccessIds,
|
|
@@ -233,9 +229,7 @@ module.exports = {
|
|
|
233
229
|
getWalletStatus,
|
|
234
230
|
getWalletVersion,
|
|
235
231
|
grantAccess,
|
|
236
|
-
grpcRouter,
|
|
237
232
|
isDestinationPayable,
|
|
238
|
-
lndGateway,
|
|
239
233
|
lockUtxo,
|
|
240
234
|
openChannel,
|
|
241
235
|
openChannels,
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
"15c1eb13972f86a7c1e8cb084aa6d52700d685ff": "0.14.5-beta",
|
|
23
23
|
"1a3194d302f33bb52823297d9d7f75cd37516053": "0.10.0-beta",
|
|
24
24
|
"1e511be523eb8e97c4e2d9c89a7a263963a3929f": "0.14.2-beta",
|
|
25
|
+
"2fb150c8fe827df9df0520ef9916b3afb7b03a8d": "0.17.0-beta",
|
|
25
26
|
"3ae46d81f4a2edad06ef778b2940d9b06386d93b": "0.11.0-beta",
|
|
26
27
|
"47483f1c66ae6fbb2e03ff29f9bc9b80c611c027": "0.16.3-beta",
|
|
27
28
|
"4f567577db9d85b6f392f960b3aabddcad3cd02c": "0.13.3-beta",
|
package/package.json
CHANGED
|
@@ -7,36 +7,30 @@
|
|
|
7
7
|
"url": "https://github.com/alexbosworth/lightning/issues"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@grpc/grpc-js": "1.9.
|
|
10
|
+
"@grpc/grpc-js": "1.9.5",
|
|
11
11
|
"@grpc/proto-loader": "0.7.10",
|
|
12
|
-
"@types/
|
|
13
|
-
"@types/node": "20.7.1",
|
|
12
|
+
"@types/node": "20.8.2",
|
|
14
13
|
"@types/request": "2.48.9",
|
|
15
14
|
"@types/ws": "8.5.6",
|
|
16
15
|
"async": "3.2.4",
|
|
17
16
|
"asyncjs-util": "1.2.12",
|
|
18
17
|
"bitcoinjs-lib": "6.1.5",
|
|
19
18
|
"bn.js": "5.2.1",
|
|
20
|
-
"body-parser": "1.20.2",
|
|
21
19
|
"bolt07": "1.8.4",
|
|
22
20
|
"bolt09": "1.0.0",
|
|
23
|
-
"cbor": "9.0.1",
|
|
24
21
|
"ecpair": "2.1.0",
|
|
25
|
-
"express": "4.18.2",
|
|
26
22
|
"invoices": "3.0.0",
|
|
27
23
|
"psbt": "3.0.0",
|
|
28
24
|
"tiny-secp256k1": "2.2.3",
|
|
29
|
-
"type-fest": "4.3.
|
|
25
|
+
"type-fest": "4.3.3"
|
|
30
26
|
},
|
|
31
27
|
"description": "Lightning Network client library",
|
|
32
28
|
"devDependencies": {
|
|
33
|
-
"@alexbosworth/node-fetch": "2.6.2",
|
|
34
29
|
"tsd": "0.29.0",
|
|
35
|
-
"typescript": "5.2.2"
|
|
36
|
-
"ws": "8.14.2"
|
|
30
|
+
"typescript": "5.2.2"
|
|
37
31
|
},
|
|
38
32
|
"engines": {
|
|
39
|
-
"node": ">=
|
|
33
|
+
"node": ">=18"
|
|
40
34
|
},
|
|
41
35
|
"keywords": [
|
|
42
36
|
"grpc",
|
|
@@ -59,5 +53,5 @@
|
|
|
59
53
|
"directory": "test/typescript"
|
|
60
54
|
},
|
|
61
55
|
"types": "index.d.ts",
|
|
62
|
-
"version": "
|
|
56
|
+
"version": "10.0.0"
|
|
63
57
|
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
const authHeaderName = 'authorization';
|
|
2
|
-
const bearerTokenRegex = /Bearer\s(\S+)/;
|
|
3
|
-
|
|
4
|
-
/** Parse out bearer token
|
|
5
|
-
|
|
6
|
-
{}
|
|
7
|
-
|
|
8
|
-
@returns
|
|
9
|
-
{
|
|
10
|
-
middleware: <Parse Bearer Token Express Middleware Function>
|
|
11
|
-
}
|
|
12
|
-
*/
|
|
13
|
-
module.exports = ({}) => {
|
|
14
|
-
const middleware = (req, res, next) => {
|
|
15
|
-
const authHeaderValue = req.get(authHeaderName);
|
|
16
|
-
|
|
17
|
-
// Exit early when there is no bearer token
|
|
18
|
-
if (!authHeaderValue) {
|
|
19
|
-
return next();
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const [, bearer] = authHeaderValue.match(bearerTokenRegex);
|
|
23
|
-
|
|
24
|
-
res.locals.auth = {bearer};
|
|
25
|
-
|
|
26
|
-
return next();
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
return {middleware};
|
|
30
|
-
};
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
const {decodeFirst} = require('cbor');
|
|
2
|
-
|
|
3
|
-
const badArgumentsCode = 400;
|
|
4
|
-
|
|
5
|
-
/** Create express middleware to decode a CBOR body
|
|
6
|
-
|
|
7
|
-
{}
|
|
8
|
-
|
|
9
|
-
@returns
|
|
10
|
-
{
|
|
11
|
-
middleware: <Middleware Function>
|
|
12
|
-
}
|
|
13
|
-
*/
|
|
14
|
-
module.exports = ({}) => {
|
|
15
|
-
const middleware = (req, res, next) => {
|
|
16
|
-
decodeFirst(req.body, (err, decoded) => {
|
|
17
|
-
if (!!err) {
|
|
18
|
-
return next([badArgumentsCode, 'ExpectedCborRequestArgs']);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
req.body = decoded;
|
|
22
|
-
|
|
23
|
-
return next();
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
return;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
return {middleware};
|
|
30
|
-
};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
const {decodeFirst} = require('cbor');
|
|
2
|
-
|
|
3
|
-
/** Emit an proxy response
|
|
4
|
-
|
|
5
|
-
{
|
|
6
|
-
emitter: <Emit Response EventEmitter Object>
|
|
7
|
-
message: <CBOR Encoded gRPC Event and Data Message>
|
|
8
|
-
}
|
|
9
|
-
*/
|
|
10
|
-
module.exports = ({emitter, message}) => {
|
|
11
|
-
return decodeFirst(message, (err, decoded) => {
|
|
12
|
-
if (!!err) {
|
|
13
|
-
return emitter.emit('error', new Error('FailedToDecodeGatewayResponse'));
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
return emitter.emit(decoded.event, decoded.data);
|
|
17
|
-
});
|
|
18
|
-
};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export type GrpcConnection = {
|
|
2
|
-
/** Base64 or Hex Serialized LND TLS Cert String */
|
|
3
|
-
cert?: string;
|
|
4
|
-
/** Host:Port Network Address String */
|
|
5
|
-
socket?: string;
|
|
6
|
-
ws: {
|
|
7
|
-
/** Add Event Listener Function */
|
|
8
|
-
on: (event: string, listener: (...args: any[]) => void) => void;
|
|
9
|
-
/** Send Data Function */
|
|
10
|
-
send: (message: any) => void;
|
|
11
|
-
};
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Emit events from a gRPC call
|
|
16
|
-
*/
|
|
17
|
-
export function emitGrpcEvents(connection: GrpcConnection): void;
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
const {decodeFirst} = require('cbor');
|
|
2
|
-
|
|
3
|
-
const {authenticatedLndGrpc} = require('./../lnd_grpc');
|
|
4
|
-
const encodeResponse = require('./encode_response');
|
|
5
|
-
const subscribeToResponse = require('./subscribe_to_response');
|
|
6
|
-
|
|
7
|
-
const encodeType = 'blob';
|
|
8
|
-
const invalidMessageErr = 'ExpectedValidCborWsMessage';
|
|
9
|
-
|
|
10
|
-
/** Emit events from a gRPC call
|
|
11
|
-
|
|
12
|
-
{
|
|
13
|
-
[cert]: <Base64 or Hex Serialized LND TLS Cert String>
|
|
14
|
-
[socket]: <Host:Port Network Address String>
|
|
15
|
-
ws: {
|
|
16
|
-
on: <Add Event Listener Function>
|
|
17
|
-
send: <Send Data Function>
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
*/
|
|
21
|
-
module.exports = ({cert, socket, ws}) => {
|
|
22
|
-
let cancel = () => {};
|
|
23
|
-
|
|
24
|
-
ws.binaryType = encodeType;
|
|
25
|
-
|
|
26
|
-
ws.on('close', () => cancel());
|
|
27
|
-
|
|
28
|
-
ws.on('message', message => {
|
|
29
|
-
return decodeFirst(message, async (err, decoded) => {
|
|
30
|
-
if (!!err) {
|
|
31
|
-
const {response} = await encodeResponse({
|
|
32
|
-
data: {details: invalidMessageErr},
|
|
33
|
-
event: 'error',
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
return ws.send(response);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const {macaroon, method, params, server} = decoded;
|
|
40
|
-
|
|
41
|
-
const {lnd} = authenticatedLndGrpc({cert, macaroon, socket});
|
|
42
|
-
|
|
43
|
-
const sub = subscribeToResponse({lnd, method, params, server, ws});
|
|
44
|
-
|
|
45
|
-
cancel = sub.cancel;
|
|
46
|
-
|
|
47
|
-
return;
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
};
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
const asyncAuto = require('async/auto');
|
|
2
|
-
const {encodeAsync} = require('cbor');
|
|
3
|
-
const {returnResult} = require('asyncjs-util');
|
|
4
|
-
|
|
5
|
-
/** Encode a CBOR response
|
|
6
|
-
|
|
7
|
-
{
|
|
8
|
-
data: <Data Object>
|
|
9
|
-
event: <Event String>
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
@returns via cbk or Promise
|
|
13
|
-
{
|
|
14
|
-
response: <Response Buffer>
|
|
15
|
-
}
|
|
16
|
-
*/
|
|
17
|
-
module.exports = ({data, event}, cbk) => {
|
|
18
|
-
return new Promise((resolve, reject) => {
|
|
19
|
-
return asyncAuto({
|
|
20
|
-
// Check arguments
|
|
21
|
-
validate: cbk => {
|
|
22
|
-
if (!data) {
|
|
23
|
-
return cbk([400, 'ExpectedDataToEncodeResponse']);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if (!event) {
|
|
27
|
-
return cbk([400, 'ExpectedEventToEncodeResponse']);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return cbk();
|
|
31
|
-
},
|
|
32
|
-
|
|
33
|
-
// Encode the response to CBOR
|
|
34
|
-
encode: ['validate', ({}, cbk) => {
|
|
35
|
-
(async () => {
|
|
36
|
-
return cbk(null, {response: await encodeAsync({data, event})});
|
|
37
|
-
})();
|
|
38
|
-
}],
|
|
39
|
-
},
|
|
40
|
-
returnResult({reject, resolve, of: 'encode'}, cbk));
|
|
41
|
-
});
|
|
42
|
-
};
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
const asyncAuto = require('async/auto');
|
|
2
|
-
const {returnResult} = require('asyncjs-util');
|
|
3
|
-
|
|
4
|
-
/** Execute an LND request and get the CBOR encoded result
|
|
5
|
-
|
|
6
|
-
{
|
|
7
|
-
lnd: <gRPC LND Object>
|
|
8
|
-
method: <Method Name String>
|
|
9
|
-
params: <gRPC API Arguments Object>
|
|
10
|
-
service: <Service Name String>
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
@returns via cbk or Promise
|
|
14
|
-
{
|
|
15
|
-
[err]: {
|
|
16
|
-
details: <Error Details String>
|
|
17
|
-
message: <Error Message String>
|
|
18
|
-
}
|
|
19
|
-
[res]: <Response Object>
|
|
20
|
-
}
|
|
21
|
-
*/
|
|
22
|
-
module.exports = ({lnd, method, params, service}, cbk) => {
|
|
23
|
-
return new Promise((resolve, reject) => {
|
|
24
|
-
return asyncAuto({
|
|
25
|
-
// Check arguments
|
|
26
|
-
validate: cbk => {
|
|
27
|
-
if (!lnd) {
|
|
28
|
-
return cbk([400, 'ExpectedLndToExecuteGatewayRequest']);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (!method) {
|
|
32
|
-
return cbk([400, 'ExpectedMethodToExecuteGatewayRequest']);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (!params) {
|
|
36
|
-
return cbk([400, 'ExpectedArgumentsToExecuteGatewayRequest']);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if (!service) {
|
|
40
|
-
return cbk([400, 'ExpectedServiceToExecuteGatewayRequest']);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return cbk();
|
|
44
|
-
},
|
|
45
|
-
|
|
46
|
-
// Execute request
|
|
47
|
-
execute: ['validate', ({}, cbk) => {
|
|
48
|
-
try {
|
|
49
|
-
return lnd[service][method](params, (err, res) => {
|
|
50
|
-
if (!!err) {
|
|
51
|
-
return cbk(null, {err});
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return cbk(null, {res});
|
|
55
|
-
});
|
|
56
|
-
} catch (err) {
|
|
57
|
-
return cbk(null, {err});
|
|
58
|
-
}
|
|
59
|
-
}],
|
|
60
|
-
|
|
61
|
-
// Result of execution
|
|
62
|
-
result: ['execute', ({execute}, cbk) => {
|
|
63
|
-
if (!!execute.err) {
|
|
64
|
-
return cbk(null, {
|
|
65
|
-
err: {details: execute.err.details, message: execute.err.details},
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return cbk(null, {res: execute.res});
|
|
70
|
-
}],
|
|
71
|
-
},
|
|
72
|
-
returnResult({reject, resolve, of: 'result'}, cbk));
|
|
73
|
-
});
|
|
74
|
-
};
|
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
const asyncAuto = require('async/auto');
|
|
2
|
-
const {decodeFirst} = require('cbor');
|
|
3
|
-
const {encodeAsync} = require('cbor');
|
|
4
|
-
const {returnResult} = require('asyncjs-util');
|
|
5
|
-
|
|
6
|
-
const cborContentType = 'application/cbor';
|
|
7
|
-
const defaultRequestTimeoutMs = 1000 * 25;
|
|
8
|
-
const errKey = 'err';
|
|
9
|
-
const gatewayGrpcMethod = 'POST';
|
|
10
|
-
const {keys} = Object;
|
|
11
|
-
const okStatusCode = 200;
|
|
12
|
-
const pathSeparator = '/';
|
|
13
|
-
const resKey = 'res';
|
|
14
|
-
const timeoutCode = 'ETIMEDOUT';
|
|
15
|
-
|
|
16
|
-
/** Make a request to the gateway
|
|
17
|
-
|
|
18
|
-
{
|
|
19
|
-
[bearer]: <Bearer Authentication Token String>
|
|
20
|
-
call: {
|
|
21
|
-
method: <Call Method String>
|
|
22
|
-
params: <Call Arguments Object>
|
|
23
|
-
server: <Call Server String>
|
|
24
|
-
}
|
|
25
|
-
request: <Request Function>
|
|
26
|
-
url: <LND Gateway URL String>
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
@returns via cbk or Promise
|
|
30
|
-
<gRPC Result Object>
|
|
31
|
-
*/
|
|
32
|
-
module.exports = ({bearer, call, request, url}, cbk) => {
|
|
33
|
-
return new Promise((resolve, reject) => {
|
|
34
|
-
return asyncAuto({
|
|
35
|
-
// Check arguments
|
|
36
|
-
validate: cbk => {
|
|
37
|
-
if (!call) {
|
|
38
|
-
return cbk([400, 'ExpectedCallToMakeGatewayRequest']);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if (!call.params) {
|
|
42
|
-
return cbk([400, 'ExpectedCallArgumentsToMakeGatewayRequest']);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if (!call.method) {
|
|
46
|
-
return cbk([400, 'ExpectedCallMethodToMakeGatewayRequest']);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (!call.server) {
|
|
50
|
-
return cbk([400, 'ExpectedCallServerToMakeGatewayRequest']);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (!request) {
|
|
54
|
-
return cbk([400, 'ExpectedRequestFunctionToMakeGatewayRequest']);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if (!url) {
|
|
58
|
-
return cbk([400, 'ExpectedUrlToMakeGatewayRequest']);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return cbk();
|
|
62
|
-
},
|
|
63
|
-
|
|
64
|
-
// Request body CBOR encoded
|
|
65
|
-
encoded: ['validate', ({}, cbk) => {
|
|
66
|
-
return (async () => {
|
|
67
|
-
let encoded;
|
|
68
|
-
|
|
69
|
-
try { encoded = await encodeAsync(call.params); } catch (err) {}
|
|
70
|
-
|
|
71
|
-
if (!encoded) {
|
|
72
|
-
return cbk([400, 'FailedToEncodeCborForGatewayRequest']);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return cbk(null, encoded);
|
|
76
|
-
})();
|
|
77
|
-
}],
|
|
78
|
-
|
|
79
|
-
// Make request
|
|
80
|
-
makeRequest: ['encoded', ({encoded}, cbk) => {
|
|
81
|
-
return request({
|
|
82
|
-
auth: {bearer},
|
|
83
|
-
body: encoded,
|
|
84
|
-
encoding: null,
|
|
85
|
-
forever: true,
|
|
86
|
-
headers: {'content-type': cborContentType},
|
|
87
|
-
method: gatewayGrpcMethod,
|
|
88
|
-
timeout: defaultRequestTimeoutMs,
|
|
89
|
-
uri: [url, call.server, call.method].join(pathSeparator),
|
|
90
|
-
},
|
|
91
|
-
(err, response, encoded) => {
|
|
92
|
-
if (!!err && err.code === timeoutCode && !!err.connect) {
|
|
93
|
-
return cbk([503, 'FailedToConnectToLndGatewayServer']);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
if (!!err && err.code === timeoutCode) {
|
|
97
|
-
return cbk([503, 'LndGatewayServerFailedToRespondBeforeTimeout']);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (!!err) {
|
|
101
|
-
return cbk([503, 'UnexpectedErrorFromLndGatewayServer', {err}]);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
if (!response) {
|
|
105
|
-
return cbk([503, 'UnexpectedEmptyResponseFromLndGatewayServer']);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
const {statusCode} = response;
|
|
109
|
-
|
|
110
|
-
if (statusCode !== okStatusCode) {
|
|
111
|
-
return cbk([503, 'UnexpectedGatewayStatus', {code: statusCode}]);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
if (!Buffer.isBuffer(encoded)) {
|
|
115
|
-
return cbk([503, 'UnexpectedNontBufferResponseFromLndGateway']);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
return cbk(null, encoded);
|
|
119
|
-
});
|
|
120
|
-
}],
|
|
121
|
-
|
|
122
|
-
// Decode result
|
|
123
|
-
decodeResult: ['makeRequest', ({makeRequest}, cbk) => {
|
|
124
|
-
return decodeFirst(makeRequest, (err, decoded) => {
|
|
125
|
-
if (!!err) {
|
|
126
|
-
return cbk([503, 'UnexpectedErrDecodingGatewayResponse']);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
if (!keys(decoded).find(n => n === errKey)) {
|
|
130
|
-
return cbk([503, 'ExpectedErrorAttributeInGatewayResponse']);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
if (!keys(decoded).find(n => n === resKey)) {
|
|
134
|
-
return cbk([503, 'ExpectedResponseAttributeInGatewayResponse']);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
return cbk(decoded.err, decoded.res);
|
|
138
|
-
});
|
|
139
|
-
}],
|
|
140
|
-
},
|
|
141
|
-
returnResult({reject, resolve, of: 'decodeResult'}, cbk));
|
|
142
|
-
});
|
|
143
|
-
};
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
const EventEmitter = require('events');
|
|
2
|
-
|
|
3
|
-
const {encodeAsync} = require('cbor');
|
|
4
|
-
|
|
5
|
-
const emitEvent = require('./emit_event');
|
|
6
|
-
const wsUrl = require('./ws_url');
|
|
7
|
-
|
|
8
|
-
/** Subscribe to a gateway stream response
|
|
9
|
-
|
|
10
|
-
{
|
|
11
|
-
bearer: <Bearer Authentication Token String>
|
|
12
|
-
call: {
|
|
13
|
-
method: <Call Method String>
|
|
14
|
-
params: <Call Arguments Object>
|
|
15
|
-
server: <Call Server String>
|
|
16
|
-
}
|
|
17
|
-
websocket: <WebSocket Constructor Function>
|
|
18
|
-
url: <LND Gateway URL String>
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
@throws
|
|
22
|
-
<Error>
|
|
23
|
-
|
|
24
|
-
@returns
|
|
25
|
-
{
|
|
26
|
-
cancel: <Terminate Subscription Function>
|
|
27
|
-
on: <Event Listener Function>
|
|
28
|
-
}
|
|
29
|
-
*/
|
|
30
|
-
module.exports = ({bearer, call, websocket, url}) => {
|
|
31
|
-
const emitter = new EventEmitter();
|
|
32
|
-
|
|
33
|
-
const ws = new websocket(wsUrl({url}).url);
|
|
34
|
-
|
|
35
|
-
ws.on('close', () => {});
|
|
36
|
-
ws.on('error', err => emitter.emit('error', err));
|
|
37
|
-
ws.on('message', message => emitEvent({emitter, message}))
|
|
38
|
-
|
|
39
|
-
ws.on('open', async () => {
|
|
40
|
-
const bytes = await encodeAsync({
|
|
41
|
-
macaroon: bearer,
|
|
42
|
-
method: call.method,
|
|
43
|
-
params: call.params,
|
|
44
|
-
server: call.server,
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
return ws.send(new Uint8Array(bytes));
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
emitter.cancel = () => ws.close();
|
|
51
|
-
|
|
52
|
-
return emitter;
|
|
53
|
-
};
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
const {authenticatedLndGrpc} = require('./../lnd_grpc');
|
|
2
|
-
const executeRequest = require('./execute_request');
|
|
3
|
-
const returnResponse = require('./return_response');
|
|
4
|
-
const {unauthenticatedLndGrpc} = require('./../lnd_grpc');
|
|
5
|
-
|
|
6
|
-
const defaultSocket = '127.0.0.1:10009';
|
|
7
|
-
|
|
8
|
-
/** Send response to call from gRPC
|
|
9
|
-
|
|
10
|
-
{
|
|
11
|
-
credentials: {
|
|
12
|
-
[cert]: <Base64 or Hex Serialized LND TLS Cert String>
|
|
13
|
-
[socket]: <Host:Port Network Address String>
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
@returns
|
|
18
|
-
{
|
|
19
|
-
middleware: <Middleware Function>
|
|
20
|
-
}
|
|
21
|
-
*/
|
|
22
|
-
module.exports = ({credentials}) => {
|
|
23
|
-
const middleware = ({body, params}, res) => {
|
|
24
|
-
const {cert} = credentials;
|
|
25
|
-
const macaroon = !!res.locals.auth ? res.locals.auth.bearer : undefined;
|
|
26
|
-
const socket = credentials.socket || defaultSocket;
|
|
27
|
-
|
|
28
|
-
const makeLnd = !!macaroon ? authenticatedLndGrpc: unauthenticatedLndGrpc;
|
|
29
|
-
|
|
30
|
-
const {lnd} = makeLnd({cert, macaroon, socket});
|
|
31
|
-
|
|
32
|
-
return executeRequest({
|
|
33
|
-
lnd,
|
|
34
|
-
method: params.method,
|
|
35
|
-
params: body,
|
|
36
|
-
service: params.service,
|
|
37
|
-
},
|
|
38
|
-
returnResponse({res}).responder);
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
return {middleware};
|
|
42
|
-
};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import {Router} from 'express';
|
|
2
|
-
|
|
3
|
-
export type Credentials = {
|
|
4
|
-
/** Base64 or Hex Serialized LND TLS Cert String */
|
|
5
|
-
cert?: string;
|
|
6
|
-
/** Host:Port Network Address String */
|
|
7
|
-
socket?: string;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Get a gRPC gateway router
|
|
12
|
-
*/
|
|
13
|
-
export function grpcRouter(credentials: Credentials): Router;
|