lightning 5.16.0 → 5.16.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/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Versions
2
2
 
3
- ## 5.16.0
3
+ ## 5.16.1
4
4
 
5
5
  - `signTransaction`: Add `root_hash` to support Taproot signatures with scripts
6
6
 
@@ -6,7 +6,11 @@ const {isLnd} = require('./../../lnd_requests');
6
6
 
7
7
  const connectFailMessage = '14 UNAVAILABLE: Connect Failed';
8
8
  const defaultAddressFormat = 'p2wpkh';
9
+ const {isArray} = Array;
10
+ const isNeedingDerivationsCheck = format => format === 'p2tr';
11
+ const isTrSupported = n => !!n.find(n => n.address_type === 'TAPROOT_PUBKEY');
9
12
  const method = 'newAddress';
13
+ const notSupported = /unknown.*walletrpc.WalletKit/;
10
14
  const type = 'default';
11
15
 
12
16
  /** Create a new receive address.
@@ -42,6 +46,38 @@ module.exports = (args, cbk) => {
42
46
  return cbk();
43
47
  },
44
48
 
49
+ // Get account derivations to confirm P2TR support
50
+ checkFormat: ['validate', ({}, cbk) => {
51
+ // Exit early when there is no need to check the derivations
52
+ if (!isNeedingDerivationsCheck(args.format)) {
53
+ return cbk();
54
+ }
55
+
56
+ return args.lnd.wallet.listAccounts({}, (err, res) => {
57
+ if (!!err && notSupported.test(err.details)) {
58
+ return cbk([501, 'CreationOfTaprootAddressesUnsupported']);
59
+ }
60
+
61
+ if (!!err) {
62
+ return cbk([503, 'UnexpectedErrorCheckingTaprootSupport', {err}]);
63
+ }
64
+
65
+ if (!res) {
66
+ return cbk([503, 'ExpectedResultForDerivationPathsRequest']);
67
+ }
68
+
69
+ if (!isArray(res.accounts)) {
70
+ return cbk([503, 'ExpectedAccountsInDerivationPathsResult']);
71
+ }
72
+
73
+ if (!isTrSupported(res.accounts)) {
74
+ return cbk([501, 'ExpectedTaprootSupportingLndToCreateAddress']);
75
+ }
76
+
77
+ return cbk();
78
+ });
79
+ }],
80
+
45
81
  // Type
46
82
  type: ['validate', ({}, cbk) => {
47
83
  const format = args.format || defaultAddressFormat;
@@ -54,7 +90,7 @@ module.exports = (args, cbk) => {
54
90
  }],
55
91
 
56
92
  // Get the address
57
- createAddress: ['type', ({type}, cbk) => {
93
+ createAddress: ['checkFormat', 'type', ({type}, cbk) => {
58
94
  return args.lnd.default.newAddress({type}, (err, res) => {
59
95
  if (!!err && err.message === connectFailMessage) {
60
96
  return cbk([503, 'FailedToConnectToDaemonToCreateChainAddress']);
@@ -34,6 +34,7 @@
34
34
  "type": "tower_client"
35
35
  },
36
36
  "createChainAddress": {
37
+ "depends_on": ["getMasterPublicKeys"],
37
38
  "method": "NewAddress",
38
39
  "type": "default"
39
40
  },
@@ -13,12 +13,14 @@ export type SignTransactionArgs = AuthenticatedLightningArgs<{
13
13
  output_script: string;
14
14
  /** Output Tokens */
15
15
  output_tokens: number;
16
+ /** Taproot Root Hash Hex String */
17
+ root_hash?: string;
16
18
  /** Sighash Type */
17
19
  sighash: number;
18
20
  /** Input Index To Sign */
19
21
  vin: number;
20
22
  /** Witness Script Hex String */
21
- witness_script: string;
23
+ witness_script?: string;
22
24
  }[];
23
25
  spending?: {
24
26
  /** Non-Internal Spend Output Script Hex String */
@@ -21,6 +21,7 @@ const unimplementedError = '12 UNIMPLEMENTED: unknown service signrpc.Signer';
21
21
 
22
22
  Requires `signer:generate` permission
23
23
 
24
+ `root_hash` is not supported in LND 0.14.3 and below
24
25
  `spending` is not supported in LND 0.14.3 and below
25
26
 
26
27
  {
package/package.json CHANGED
@@ -10,13 +10,13 @@
10
10
  "@grpc/grpc-js": "1.6.7",
11
11
  "@grpc/proto-loader": "0.6.12",
12
12
  "@types/express": "4.17.13",
13
- "@types/node": "17.0.33",
13
+ "@types/node": "17.0.38",
14
14
  "@types/request": "2.48.8",
15
15
  "@types/ws": "8.5.3",
16
16
  "async": "3.2.3",
17
17
  "asyncjs-util": "1.2.9",
18
18
  "bitcoinjs-lib": "6.0.1",
19
- "bn.js": "5.2.0",
19
+ "bn.js": "5.2.1",
20
20
  "body-parser": "1.20.0",
21
21
  "bolt07": "1.8.1",
22
22
  "bolt09": "0.2.3",
@@ -24,17 +24,17 @@
24
24
  "ecpair": "2.0.1",
25
25
  "express": "4.18.1",
26
26
  "invoices": "2.0.6",
27
- "psbt": "2.0.1",
27
+ "psbt": "2.3.0",
28
28
  "tiny-secp256k1": "2.2.1",
29
- "type-fest": "2.12.2"
29
+ "type-fest": "2.13.0"
30
30
  },
31
31
  "description": "Lightning Network client library",
32
32
  "devDependencies": {
33
33
  "@alexbosworth/node-fetch": "2.6.2",
34
34
  "@alexbosworth/tap": "15.0.11",
35
35
  "tsd": "0.20.0",
36
- "typescript": "4.6.4",
37
- "ws": "8.6.0"
36
+ "typescript": "4.7.2",
37
+ "ws": "8.7.0"
38
38
  },
39
39
  "engines": {
40
40
  "node": ">=12.20"
@@ -59,5 +59,5 @@
59
59
  "directory": "test/typescript"
60
60
  },
61
61
  "types": "index.d.ts",
62
- "version": "5.16.0"
62
+ "version": "5.16.1"
63
63
  }
@@ -66,6 +66,93 @@ const tests = [
66
66
  description: 'An address is required',
67
67
  expected: {address: 'addr'},
68
68
  },
69
+ {
70
+ args: {
71
+ lnd: {default: {newAddress: ({}, cbk) => cbk(null, {address: 'addr'})}},
72
+ },
73
+ description: 'The default address is p2wpkh',
74
+ expected: {address: 'addr'},
75
+ },
76
+ {
77
+ args: {
78
+ format: 'p2tr',
79
+ lnd: {
80
+ default: {
81
+ newAddress: ({}, cbk) => cbk(null, {address: 'addr'}),
82
+ },
83
+ wallet: {
84
+ listAccounts: ({}, cbk) => cbk({
85
+ details: 'unknown.service.walletrpc.WalletKit',
86
+ }),
87
+ },
88
+ },
89
+ },
90
+ description: 'Taproot requires TR account',
91
+ error: [501, 'CreationOfTaprootAddressesUnsupported'],
92
+ },
93
+ {
94
+ args: {
95
+ format: 'p2tr',
96
+ lnd: {
97
+ default: {newAddress: ({}, cbk) => cbk(null, {address: 'addr'})},
98
+ wallet: {listAccounts: ({}, cbk) => cbk('err')},
99
+ },
100
+ },
101
+ description: 'Taproot check errors are passed back',
102
+ error: [503, 'UnexpectedErrorCheckingTaprootSupport'],
103
+ },
104
+ {
105
+ args: {
106
+ format: 'p2tr',
107
+ lnd: {
108
+ default: {newAddress: ({}, cbk) => cbk(null, {address: 'addr'})},
109
+ wallet: {listAccounts: ({}, cbk) => cbk()},
110
+ },
111
+ },
112
+ description: 'Taproot requires account result',
113
+ error: [503, 'ExpectedResultForDerivationPathsRequest'],
114
+ },
115
+ {
116
+ args: {
117
+ format: 'p2tr',
118
+ lnd: {
119
+ default: {newAddress: ({}, cbk) => cbk(null, {address: 'addr'})},
120
+ wallet: {listAccounts: ({}, cbk) => cbk(null, {})},
121
+ },
122
+ },
123
+ description: 'Taproot accounts are expected',
124
+ error: [503, 'ExpectedAccountsInDerivationPathsResult'],
125
+ },
126
+ {
127
+ args: {
128
+ format: 'p2tr',
129
+ lnd: {
130
+ default: {newAddress: ({}, cbk) => cbk(null, {address: 'addr'})},
131
+ wallet: {listAccounts: ({}, cbk) => cbk(null, {accounts: []})},
132
+ },
133
+ },
134
+ description: 'Taproot supporting account is expected',
135
+ error: [501, 'ExpectedTaprootSupportingLndToCreateAddress'],
136
+ },
137
+ {
138
+ args: {
139
+ format: 'p2tr',
140
+ lnd: {
141
+ default: {
142
+ newAddress: ({}, cbk) => cbk(null, {
143
+ address: 'taproot_address',
144
+ }),
145
+ },
146
+ wallet: {
147
+ listAccounts: ({}, cbk) => cbk(null, {
148
+ accounts: [{address_type: 'TAPROOT_PUBKEY'}],
149
+ }),
150
+ },
151
+ },
152
+ },
153
+ description: 'Taproot supporting account',
154
+ expected: {address: 'taproot_address'},
155
+ },
69
156
  {
70
157
  args: {
71
158
  format: 'p2wpkh',
@@ -11,7 +11,6 @@ const inputs = [
11
11
  output_tokens: 1,
12
12
  sighash: 1,
13
13
  vin: 0,
14
- witness_script: '00',
15
14
  },
16
15
  ];
17
16
  const spending = [