lightning 10.20.2 → 10.22.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,13 @@
1
1
  # Versions
2
2
 
3
+ ## 10.22.0
4
+
5
+ - `createFundedPsbt`: Add support for `change_format` for change address type
6
+
7
+ ## 10.21.0
8
+
9
+ - `fundPsbt`: Add support for `change_format` to specify change address type
10
+
3
11
  ## 10.20.2
4
12
 
5
13
  - `payViaPaymentRequest`, `subscribeToPayViaRequest`: Add `index` to response
package/bolt02/ids.json CHANGED
@@ -2,6 +2,7 @@
2
2
  "chains": {
3
3
  "bitcoinmainnet": "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f",
4
4
  "bitcoinregtest": "0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206",
5
+ "bitcoinsignet": "00000008819873e925422c1ff0f99f7cc9bbb232af63a077a480a3633bee1ef6",
5
6
  "bitcointestnet": "000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943",
6
7
  "litecoinmainnet": "12a765e31ffd4059bada1e25190f6e98c99d9714d334efa41a195a7e7e04bfe2",
7
8
  "litecoinregtest": "530827f38f93b43ed12af0b3ad25a288dc02ed74d6d7857862df51fc56c416f9",
@@ -5,12 +5,13 @@ const {returnResult} = require('asyncjs-util');
5
5
  const {isLnd} = require('./../../lnd_requests');
6
6
 
7
7
  const bufferAsHex = buffer => buffer.toString('hex');
8
- const defaultChangeType = 'CHANGE_ADDRESS_TYPE_P2TR';
8
+ const defaultChangeType = () => 'CHANGE_ADDRESS_TYPE_P2TR';
9
9
  const defaultConfirmationTarget = 6;
10
10
  const errorUnsupported = 'transaction template missing, need to specify either PSBT or raw TX template';
11
11
  const hexAsBuffer = hex => Buffer.from(hex, 'hex');
12
12
  const indexNotFound = -1;
13
13
  const {isBuffer} = Buffer;
14
+ const isKnownChangeFormat = format => !format || format === 'p2tr';
14
15
  const method = 'fundPsbt';
15
16
  const strategy = type => !type ? undefined : `STRATEGY_${type.toUpperCase()}`;
16
17
  const type = 'wallet';
@@ -22,6 +23,8 @@ const unconfirmedConfirmationsCount = 0;
22
23
 
23
24
  `utxo_selection` methods: 'largest', 'random'
24
25
 
26
+ `change_format` options: `p2tr` (only one change type is supported)
27
+
25
28
  Requires `onchain:write` permission
26
29
 
27
30
  Requires LND built with `walletrpc` tag
@@ -29,6 +32,7 @@ const unconfirmedConfirmationsCount = 0;
29
32
  This method is not supported on LND 0.17.5 or below
30
33
 
31
34
  {
35
+ [change_format]: <Change Address Address Format String>
32
36
  [fee_tokens_per_vbyte]: <Chain Fee Tokens Per Virtual Byte Number>
33
37
  [inputs]: [{
34
38
  [sequence]: <Sequence Number>
@@ -58,6 +62,10 @@ module.exports = (args, cbk) => {
58
62
  return asyncAuto({
59
63
  // Check arguments
60
64
  validate: cbk => {
65
+ if (!isKnownChangeFormat(args.change_format)) {
66
+ return cbk([400, 'ExpectedKnownChangeFormatToFundPsbt']);
67
+ }
68
+
61
69
  if (!isLnd({method, type, lnd: args.lnd})) {
62
70
  return cbk([400, 'ExpectedAuthenticatedLndToCreateFundedPsbt']);
63
71
  }
@@ -97,6 +105,7 @@ module.exports = (args, cbk) => {
97
105
  // Construct the PSBT that is needed for coin select type funding
98
106
  funding: ['validate', ({}, cbk) => {
99
107
  const {psbt} = createPsbt({
108
+ change_type: defaultChangeType(args.change_type),
100
109
  outputs: args.outputs || [],
101
110
  timelock: args.timelock,
102
111
  utxos: (args.inputs || []).map(input => ({
@@ -7,13 +7,14 @@ const {Transaction} = require('bitcoinjs-lib');
7
7
  const {isLnd} = require('./../../lnd_requests');
8
8
 
9
9
  const asOutpoint = n => `${n.transaction_id}:${n.transaction_vout}`;
10
- const defaultChangeType = 'CHANGE_ADDRESS_TYPE_P2TR';
10
+ const defaultChangeType = () => 'CHANGE_ADDRESS_TYPE_P2TR';
11
11
  const defaultConfirmationTarget = 6;
12
12
  const expirationAsDate = epoch => new Date(Number(epoch) * 1e3).toISOString();
13
13
  const {fromHex} = Transaction;
14
14
  const hexFromBuffer = buffer => buffer.toString('hex');
15
15
  const {isArray} = Array;
16
16
  const {isBuffer} = Buffer;
17
+ const isKnownChangeFormat = format => !format || format === 'p2tr';
17
18
  const method = 'fundPsbt';
18
19
  const notSupported = /unknown.*walletrpc.WalletKit/;
19
20
  const strategy = type => !type ? undefined : `STRATEGY_${type.toUpperCase()}`;
@@ -29,6 +30,8 @@ const txIdFromHash = hash => hash.reverse().toString('hex');
29
30
 
30
31
  `utxo_selection` methods: 'largest', 'random'
31
32
 
33
+ `change_format` options: `p2tr` (only one change type is supported)
34
+
32
35
  Requires `onchain:write` permission
33
36
 
34
37
  Requires LND built with `walletrpc` tag
@@ -40,6 +43,7 @@ const txIdFromHash = hash => hash.reverse().toString('hex');
40
43
  `utxo_selection` is not supported in LND 0.17.5 and below
41
44
 
42
45
  {
46
+ [change_format]: <Change Address Address Format String>
43
47
  [fee_tokens_per_vbyte]: <Chain Fee Tokens Per Virtual Byte Number>
44
48
  [inputs]: [{
45
49
  transaction_id: <Unspent Transaction Id Hex String>
@@ -80,6 +84,10 @@ module.exports = (args, cbk) => {
80
84
 
81
85
  // Check arguments
82
86
  validate: cbk => {
87
+ if (!isKnownChangeFormat(args.change_format)) {
88
+ return cbk([400, 'ExpectedKnownChangeFormatToFundPsbt']);
89
+ }
90
+
83
91
  if (!isLnd({method, type, lnd: args.lnd})) {
84
92
  return cbk([400, 'ExpectedAuthenticatedLndToFundPsbt']);
85
93
  }
@@ -163,7 +171,7 @@ module.exports = (args, cbk) => {
163
171
  // Fund the PSBT
164
172
  fund: ['fee', 'funding', 'minConfs', ({fee, funding, minConfs}, cbk) => {
165
173
  return args.lnd[type][method]({
166
- change_type: defaultChangeType,
174
+ change_type: defaultChangeType(args.change_type),
167
175
  coin_selection_strategy: strategy(args.utxo_selection),
168
176
  min_confs: minConfs !== undefined ? minConfs : undefined,
169
177
  psbt: !!args.psbt ? Buffer.from(args.psbt, 'hex') : undefined,
package/package.json CHANGED
@@ -7,9 +7,9 @@
7
7
  "url": "https://github.com/alexbosworth/lightning/issues"
8
8
  },
9
9
  "dependencies": {
10
- "@grpc/grpc-js": "1.11.2",
10
+ "@grpc/grpc-js": "1.12.0",
11
11
  "@grpc/proto-loader": "0.7.13",
12
- "@types/node": "22.5.4",
12
+ "@types/node": "22.7.5",
13
13
  "@types/request": "2.48.12",
14
14
  "@types/ws": "8.5.12",
15
15
  "async": "3.2.6",
@@ -27,7 +27,7 @@
27
27
  "description": "Lightning Network client library",
28
28
  "devDependencies": {
29
29
  "tsd": "0.31.2",
30
- "typescript": "5.6.2"
30
+ "typescript": "5.6.3"
31
31
  },
32
32
  "engines": {
33
33
  "node": ">=18"
@@ -53,5 +53,5 @@
53
53
  "directory": "test/typescript"
54
54
  },
55
55
  "types": "index.d.ts",
56
- "version": "10.20.2"
56
+ "version": "10.22.0"
57
57
  }
@@ -48,6 +48,11 @@ const makeExpected = overrides => {
48
48
  };
49
49
 
50
50
  const tests = [
51
+ {
52
+ args: makeArgs({change_format: 'change_format'}),
53
+ description: 'A valid change format is required',
54
+ error: [400, 'ExpectedKnownChangeFormatToFundPsbt'],
55
+ },
51
56
  {
52
57
  args: makeArgs({lnd: undefined}),
53
58
  description: 'An LND object is required',
@@ -74,6 +74,11 @@ const makeExpected = overrides => {
74
74
  };
75
75
 
76
76
  const tests = [
77
+ {
78
+ args: makeArgs({change_format: 'change_format'}),
79
+ description: 'A valid change format is required',
80
+ error: [400, 'ExpectedKnownChangeFormatToFundPsbt'],
81
+ },
77
82
  {
78
83
  args: makeArgs({lnd: undefined}),
79
84
  description: 'An LND object is required',