lightning 5.5.0 → 5.6.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 CHANGED
@@ -1,5 +1,9 @@
1
1
  # Versions
2
2
 
3
+ ## 5.6.0
4
+
5
+ - `payViaRoutes`, `subscribeToPayViaRoutes`: Add support for relay messages
6
+
3
7
  ## 5.5.0
4
8
 
5
9
  - `partiallySignPsbt`: Add method to partially sign a PSBT
@@ -27,6 +27,12 @@ export type PayViaRoutesArgs = AuthenticatedLightningArgs<{
27
27
  forward: number;
28
28
  /** Forward Millitokens */
29
29
  forward_mtokens: string;
30
+ messages?: {
31
+ /** Message Type number */
32
+ type: string;
33
+ /** Message Raw Value Hex Encoded */
34
+ value: string;
35
+ }[];
30
36
  /** Public Key Hex */
31
37
  public_key?: string;
32
38
  /** Timeout Block Height */
@@ -29,6 +29,10 @@ const notFound = -1;
29
29
  fee_mtokens: <Fee Millitokens String>
30
30
  forward: <Forward Tokens Number>
31
31
  forward_mtokens: <Forward Millitokens String>
32
+ [messages]: [{
33
+ type: <Message Type Number String>
34
+ value: <Message Raw Value Hex Encoded String>
35
+ }]
32
36
  [public_key]: <Public Key Hex String>
33
37
  timeout: <Timeout Block Height Number>
34
38
  }]
@@ -43,6 +43,10 @@ const unknownWireError = 'unknown wire error';
43
43
  fee_mtokens: <Fee Millitokens String>
44
44
  forward: <Forward Tokens Number>
45
45
  forward_mtokens: <Forward Millitokens String>
46
+ [messages]: [{
47
+ type: <Message Type Number String>
48
+ value: <Message Raw Value Hex Encoded String>
49
+ }]
46
50
  public_key: <Public Key Hex String>
47
51
  timeout: <Timeout Block Height Number>
48
52
  }]
@@ -1,5 +1,6 @@
1
1
  const {chanNumber} = require('bolt07');
2
2
 
3
+ const hexAsBuffer = hex => Buffer.from(hex, 'hex');
3
4
  const isNumber = n => !isNaN(n);
4
5
  const millitokensAsTokens = n => Number(BigInt(n) / BigInt(1e3));
5
6
 
@@ -12,6 +13,10 @@ const millitokensAsTokens = n => Number(BigInt(n) / BigInt(1e3));
12
13
  fee_mtokens: <Fee Millitokens String>
13
14
  forward: <Forward Tokens Number>
14
15
  forward_mtokens: <Forward Millitokens String>
16
+ [messages]: [{
17
+ type: <Message Type Number String>
18
+ value: <Message Raw Value Hex Encoded String>
19
+ }]
15
20
  [public_key]: <Forward Edge Public Key Hex String>
16
21
  timeout: <Timeout Block Height Number>
17
22
  }
@@ -25,10 +30,12 @@ const millitokensAsTokens = n => Number(BigInt(n) / BigInt(1e3));
25
30
  amt_to_forward_msat: <Millitokens to Forward String>
26
31
  chan_id: <Numeric Format Channel Id String>
27
32
  chan_capacity: <Channel Capacity Number>
33
+ [custom_records]: {<TLV Type Number String>: <TLV Value Buffer Object>}
28
34
  expiry: <Timeout Chain Height Number>
29
35
  fee: <Fee in Tokens Number>
30
36
  fee_msat: <Fee in Millitokens String>
31
37
  [pub_key]: <Next Hop Public Key Hex String>
38
+ [tlv_payload]: <Has Extra TLV Data Bool>
32
39
  }
33
40
  */
34
41
  module.exports = args => {
@@ -44,7 +51,7 @@ module.exports = args => {
44
51
  throw new Error('ExpectedFeeMillitokensToMapRpcHopFromHop');
45
52
  }
46
53
 
47
- return {
54
+ const hop = {
48
55
  amt_to_forward: millitokensAsTokens(args.forward_mtokens).toString(),
49
56
  amt_to_forward_msat: args.forward_mtokens,
50
57
  chan_id: chanNumber({channel: args.channel}).number,
@@ -54,4 +61,21 @@ module.exports = args => {
54
61
  fee_msat: args.fee_mtokens,
55
62
  pub_key: args.public_key,
56
63
  };
64
+
65
+ // Exit early when there are no messages to encode in this hop
66
+ if (!args.messages || !args.messages.length) {
67
+ return hop;
68
+ }
69
+
70
+ // Set custom TLV payload records for this hop
71
+ hop.tlv_payload = true;
72
+
73
+ hop.custom_records = args.messages.reduce((tlv, n) => {
74
+ tlv[n.type] = hexAsBuffer(n.value);
75
+
76
+ return tlv;
77
+ },
78
+ {});
79
+
80
+ return hop;
57
81
  };
@@ -14,6 +14,10 @@ const isNumber = n => !isNaN(n);
14
14
  fee_mtokens: <Fee Millitokens String>
15
15
  forward: <Forward Tokens Number>
16
16
  forward_mtokens: <Forward Millitokens String>
17
+ [messages]: [{
18
+ type: <Message Type Number String>
19
+ value: <Message Raw Value Hex Encoded String>
20
+ }]
17
21
  [public_key]: <Forward Edge Public Key Hex String>
18
22
  timeout: <Timeout Block Height Number>
19
23
  }]
@@ -38,6 +42,7 @@ const isNumber = n => !isNaN(n);
38
42
  amt_to_forward_msat: <Millitokens to Forward String>
39
43
  chan_id: <Numeric Format Channel Id String>
40
44
  chan_capacity: <Channel Capacity Number>
45
+ [custom_records]: {<TLV Type Number String>: <TLV Value Buffer Object>}
41
46
  expiry: <Timeout Chain Height Number>
42
47
  fee: <Fee in Tokens Number>
43
48
  fee_msat: <Fee in Millitokens Number>
@@ -79,7 +84,7 @@ module.exports = args => {
79
84
  };
80
85
  }
81
86
 
82
- // Set custom TLV payload records
87
+ // Set custom TLV payload records on the final hop
83
88
  if (!!args.messages && !!args.messages.length) {
84
89
  hops[finalHopIndex].tlv_payload = true;
85
90
 
@@ -88,7 +93,7 @@ module.exports = args => {
88
93
 
89
94
  return tlv;
90
95
  },
91
- {});
96
+ hops[finalHopIndex].custom_records || {});
92
97
  }
93
98
 
94
99
  return {
package/package.json CHANGED
@@ -7,10 +7,10 @@
7
7
  "url": "https://github.com/alexbosworth/lightning/issues"
8
8
  },
9
9
  "dependencies": {
10
- "@grpc/grpc-js": "1.5.3",
10
+ "@grpc/grpc-js": "1.5.4",
11
11
  "@grpc/proto-loader": "0.6.9",
12
12
  "@types/express": "4.17.13",
13
- "@types/node": "17.0.13",
13
+ "@types/node": "17.0.14",
14
14
  "@types/request": "2.48.8",
15
15
  "@types/ws": "8.2.2",
16
16
  "async": "3.2.3",
@@ -24,7 +24,7 @@
24
24
  "express": "4.17.2",
25
25
  "invoices": "2.0.3",
26
26
  "psbt": "1.1.11",
27
- "type-fest": "2.11.0"
27
+ "type-fest": "2.11.1"
28
28
  },
29
29
  "description": "Lightning Network client library",
30
30
  "devDependencies": {
@@ -57,5 +57,5 @@
57
57
  "directory": "test/typescript"
58
58
  },
59
59
  "types": "index.d.ts",
60
- "version": "5.5.0"
60
+ "version": "5.6.0"
61
61
  }
@@ -41,6 +41,32 @@ const tests = [
41
41
  pub_key: 'public_key',
42
42
  },
43
43
  },
44
+ {
45
+ args: {
46
+ channel: '0x0x1',
47
+ channel_capacity: 1,
48
+ fee: 1,
49
+ fee_mtokens: '1000',
50
+ forward: '1',
51
+ forward_mtokens: '1000',
52
+ messages: [{type: '12', value: '34'}],
53
+ public_key: 'public_key',
54
+ timeout: 1,
55
+ },
56
+ description: 'Hop is mapped to RPC hop',
57
+ expected: {
58
+ amt_to_forward: '1',
59
+ amt_to_forward_msat: '1000',
60
+ chan_id: '1',
61
+ chan_capacity: '1',
62
+ custom_records: {'12': Buffer.from('34', 'hex')},
63
+ expiry: 1,
64
+ fee: '1',
65
+ fee_msat: '1000',
66
+ pub_key: 'public_key',
67
+ tlv_payload: true,
68
+ },
69
+ },
44
70
  ];
45
71
 
46
72
  tests.forEach(({args, description, error, expected}) => {