lightning 9.13.4 → 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.
Files changed (45) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/grpc/protos/lightning.proto +5 -0
  3. package/index.d.ts +0 -1
  4. package/index.js +0 -6
  5. package/lnd_methods/info/constants.json +1 -0
  6. package/lnd_methods/onchain/open_channel.d.ts +2 -0
  7. package/lnd_methods/onchain/open_channel.js +5 -0
  8. package/package.json +6 -12
  9. package/test/lnd_methods/onchain/test_open_channel.js +1 -0
  10. package/lnd_gateway/bearer_token.js +0 -30
  11. package/lnd_gateway/decode_cbor_body.js +0 -30
  12. package/lnd_gateway/emit_event.js +0 -18
  13. package/lnd_gateway/emit_grpc_events.d.ts +0 -17
  14. package/lnd_gateway/emit_grpc_events.js +0 -50
  15. package/lnd_gateway/encode_response.js +0 -42
  16. package/lnd_gateway/execute_request.js +0 -74
  17. package/lnd_gateway/gateway_request.js +0 -143
  18. package/lnd_gateway/gateway_subscribe.js +0 -53
  19. package/lnd_gateway/grpc_response.js +0 -42
  20. package/lnd_gateway/grpc_router.d.ts +0 -13
  21. package/lnd_gateway/grpc_router.js +0 -45
  22. package/lnd_gateway/handle_errors.js +0 -37
  23. package/lnd_gateway/index.d.ts +0 -3
  24. package/lnd_gateway/index.js +0 -5
  25. package/lnd_gateway/lnd_gateway.d.ts +0 -37
  26. package/lnd_gateway/lnd_gateway.js +0 -118
  27. package/lnd_gateway/return_response.js +0 -38
  28. package/lnd_gateway/subscribe_to_response.js +0 -40
  29. package/lnd_gateway/ws_url.js +0 -34
  30. package/test/lnd_gateway/test_bearer_token.js +0 -31
  31. package/test/lnd_gateway/test_decode_cbor_body.js +0 -37
  32. package/test/lnd_gateway/test_emit_event.js +0 -51
  33. package/test/lnd_gateway/test_emit_grpc_events.js +0 -31
  34. package/test/lnd_gateway/test_encode_response.js +0 -37
  35. package/test/lnd_gateway/test_gateway_request.js +0 -139
  36. package/test/lnd_gateway/test_gateway_subscribe.js +0 -97
  37. package/test/lnd_gateway/test_grpc_response.js +0 -29
  38. package/test/lnd_gateway/test_grpc_router.js +0 -20
  39. package/test/lnd_gateway/test_handle_errors.js +0 -48
  40. package/test/lnd_gateway/test_lnd_gateway.js +0 -67
  41. package/test/lnd_gateway/test_return_response.js +0 -51
  42. package/test/lnd_gateway/test_ws_url.js +0 -32
  43. package/test/typescript/emit_grpc_events.test-d.ts +0 -12
  44. package/test/typescript/grpc_router.test-d.ts +0 -8
  45. package/test/typescript/lnd_gateway.test-d.ts +0 -36
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
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
+
12
+ ## 9.14.0
13
+
14
+ - `openChannel`: Add `is_allowing_minimal_reserve` to allow no reserve on peer
15
+
3
16
  ## 9.13.4
4
17
 
5
18
  - `openChannels`: Add `is_simplified_taproot` to make a simplified taproot chan
@@ -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
@@ -1,4 +1,3 @@
1
- export * from './lnd_gateway';
2
1
  export * from './lnd_grpc';
3
2
  export * from './lnd_methods';
4
3
  export * from './typescript';
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",
@@ -24,6 +24,8 @@ export type ChannelOpenOptions = {
24
24
  /** Tokens to Gift To Partner */
25
25
  give_tokens?: number;
26
26
  inputs?: ChannelOpenOptionsInput[]
27
+ /** Allow Peer to Have Minimal Reserve Bool */
28
+ is_allowing_minimal_reserve?: boolean;
27
29
  /** Use Maximal Chain Funds For Local Funding Bool */
28
30
  is_max_funding?: boolean;
29
31
  /** Channel is Private */
@@ -11,6 +11,7 @@ const errMemoLength = /^provided memo \(.*\) is of length \d*, exceeds (\d*)$/;
11
11
  const {isArray} = Array;
12
12
  const minChannelTokens = 20000;
13
13
  const method = 'openChannel';
14
+ const reserve = isDust => isDust ? 354 : undefined;
14
15
  const simplifiedTaprootChannelType = 'SIMPLE_TAPROOT';
15
16
  const type = 'default';
16
17
 
@@ -28,6 +29,8 @@ const type = 'default';
28
29
  `--protocol.option-scid-alias` and `--protocol.zero-conf` set on both sides
29
30
  as well as a channel open request listener to accept the trusted funding.
30
31
 
32
+ `is_allowing_minimal_reserve` is not supported on LND 0.15.0 and below
33
+
31
34
  `base_fee_mtokens` is not supported on LND 0.15.5 and below
32
35
  `fee_rate` is not supported on LND 0.15.5 and below
33
36
 
@@ -51,6 +54,7 @@ const type = 'default';
51
54
  transaction_id: <Fund With Unspent Transaction Id Hex String>
52
55
  transaction_vout: <Fund With Unspent Transaction Output Index Number>
53
56
  }]
57
+ [is_allowing_minimal_reserve]: <Allow Peer to Have Minimal Reserve Bool>
54
58
  [is_max_funding]: <Use Maximal Chain Funds For Local Funding Bool>
55
59
  [is_private]: <Channel is Private Bool> // Defaults to false
56
60
  [is_simplified_taproot]: <Channel is Simplified Taproot Type Bool>
@@ -157,6 +161,7 @@ module.exports = (args, cbk) => {
157
161
  node_pubkey: Buffer.from(args.partner_public_key, 'hex'),
158
162
  outpoints: outpoints || undefined,
159
163
  private: !!args.is_private,
164
+ remote_chan_reserve_sat: reserve(!!args.is_allowing_minimal_reserve),
160
165
  remote_csv_delay: args.partner_csv_delay || undefined,
161
166
  spend_unconfirmed: !minConfs,
162
167
  use_base_fee: args.base_fee_mtokens !== undefined,
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.4",
10
+ "@grpc/grpc-js": "1.9.5",
11
11
  "@grpc/proto-loader": "0.7.10",
12
- "@types/express": "4.17.18",
13
- "@types/node": "20.7.0",
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.2"
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": ">=16"
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": "9.13.4"
56
+ "version": "10.0.0"
63
57
  }
@@ -76,6 +76,7 @@ const makeArgs = overrides => {
76
76
  lnd: makeLnd({}),
77
77
  give_tokens: 1,
78
78
  local_tokens: 1e6,
79
+ is_allowing_minimal_reserve: true,
79
80
  partner_public_key: Buffer.alloc(33).toString('hex'),
80
81
  };
81
82
 
@@ -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
- };