balanceofsatoshis 22.1.5 → 22.1.7

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
- ## 22.1.5
3
+ ## 22.1.7
4
4
 
5
5
  - Add support for LND 0.21.1
6
6
 
package/lnurl/auth.js CHANGED
@@ -2,7 +2,6 @@ const asyncAuto = require('async/auto');
2
2
  const {bech32} = require('bech32');
3
3
  const {returnResult} = require('asyncjs-util');
4
4
  const {signMessage} = require('ln-service');
5
- const tinysecp = require('tiny-secp256k1');
6
5
 
7
6
  const signAuthChallenge = require('./sign_auth_challenge');
8
7
 
@@ -35,9 +34,6 @@ const wordsAsUtf8 = n => Buffer.from(bech32.fromWords(n)).toString('utf8');
35
34
  module.exports = (args, cbk) => {
36
35
  return new Promise((resolve, reject) => {
37
36
  return asyncAuto({
38
- // Import the ECPair library
39
- ecp: async () => (await import('ecpair')).ECPairFactory(tinysecp),
40
-
41
37
  // Check arguments
42
38
  validate: cbk => {
43
39
  if (!args.ask) {
@@ -112,18 +108,21 @@ module.exports = (args, cbk) => {
112
108
  }],
113
109
 
114
110
  // Derive keys and get signatures
115
- sign: ['ecp', 'parse', 'seed', ({ecp, parse, seed}, cbk) => {
116
- const sign = signAuthChallenge({
117
- ecp,
118
- hostname: parse.hostname,
119
- k1: parse.k1,
120
- seed: seed.signature,
121
- });
122
-
123
- return cbk(null, {
124
- public_key: sign.public_key,
125
- signature: sign.signature,
126
- });
111
+ sign: ['parse', 'seed', ({parse, seed}, cbk) => {
112
+ try {
113
+ const sign = signAuthChallenge({
114
+ hostname: parse.hostname,
115
+ k1: parse.k1,
116
+ seed: seed.signature,
117
+ });
118
+
119
+ return cbk(null, {
120
+ public_key: sign.public_key,
121
+ signature: sign.signature,
122
+ });
123
+ } catch (err) {
124
+ return cbk([500, 'UnexpectedErrorSigningAuthChallenge', {err}]);
125
+ }
127
126
  }],
128
127
 
129
128
  // Display confirmation dialog with domain name and action
@@ -1,46 +1,59 @@
1
1
  const {createHash} = require('crypto');
2
2
  const {createHmac} = require('crypto');
3
3
 
4
+ const tinysecp256k1 = require('tiny-secp256k1');
5
+
4
6
  const derEncodeSignature = require('./der_encode_signature');
5
7
 
6
- const asDer = n => (n[0]&128)?Buffer.concat([Buffer.alloc(1),n],1+n.length):n;
7
- const bufferAsHex = buffer => buffer.toString('hex');
8
- const {from} = Buffer;
8
+ const bufferAsHex = buffer => Buffer.from(buffer).toString('hex');
9
+ const derivePublicKey = key => tinysecp256k1.pointFromScalar(key, true);
9
10
  const hexAsBuffer = hex => Buffer.from(hex, 'hex');
10
11
  const hmacSha256 = (pk, url) => createHmac('sha256', pk).update(url).digest();
12
+ const {isPrivate} = tinysecp256k1;
11
13
  const sha256 = n => createHash('sha256').update(n).digest();
14
+ const {sign} = tinysecp256k1;
12
15
  const utf8AsBuffer = utf8 => Buffer.from(utf8, 'utf8');
13
16
 
14
17
  /** Sign an authentication challenge for LNURL Auth
15
18
 
16
19
  {
17
- ecp: <ECPair Object>
18
20
  hostname: <Domain for Authentication Challenge String>
19
21
  k1: <Challenge Nonce String>
20
22
  seed: <Seed Signature String>
21
23
  }
22
24
 
25
+ @throws
26
+ <Error>
27
+
23
28
  @returns
24
29
  {
25
30
  public_key: <Signing Identity Public Key Hex String>
26
31
  signature: <Signature For Authentication Challenge Hex String>
27
32
  }
28
33
  */
29
- module.exports = ({ecp, hostname, k1, seed}) => {
34
+ module.exports = ({hostname, k1, seed}) => {
30
35
  // LUD-13: LN wallet defines hashingKey as sha256(signature)
31
36
  const hashingKey = sha256(utf8AsBuffer(seed));
32
37
 
33
38
  // LUD-13: linkingPrivKey is defined as hmacSha256(hashingKey, domain)
34
39
  const linkingPrivKey = hmacSha256(hashingKey, utf8AsBuffer(hostname));
35
40
 
36
- // Instantiate the key pair from this derived private key
37
- const linkingKey = ecp.fromPrivateKey(linkingPrivKey);
41
+ // Validate the private key
42
+ if (!isPrivate(linkingPrivKey)) {
43
+ throw new Error('ExpectedValidLinkingPrivateKey');
44
+ }
45
+
46
+ const publicKey = derivePublicKey(linkingPrivKey);
47
+
48
+ if (!publicKey) {
49
+ throw new Error('ExpectedPublicKeyFromLinkingPrivateKey');
50
+ }
38
51
 
39
52
  // Using the host-specific linking key, sign the challenge k1 value
40
- const signature = bufferAsHex(from(linkingKey.sign(hexAsBuffer(k1))));
53
+ const signature = bufferAsHex(sign(hexAsBuffer(k1), linkingPrivKey));
41
54
 
42
55
  return {
43
- public_key: bufferAsHex(linkingKey.publicKey),
56
+ public_key: bufferAsHex(publicKey),
44
57
  signature: derEncodeSignature({signature}).encoded,
45
58
  };
46
59
  };
@@ -1,6 +1,7 @@
1
1
  const {randomBytes} = require('crypto');
2
2
 
3
3
  const asyncAuto = require('async/auto');
4
+ const asyncRetry = require('async/retry');
4
5
  const {createSignedRequest} = require('ln-service');
5
6
  const {createUnsignedRequest} = require('ln-service');
6
7
  const {decode} = require('bip66');
@@ -8,13 +9,15 @@ const {returnResult} = require('asyncjs-util');
8
9
  const {signBytes} = require('ln-service');
9
10
  const tinysecp256k1 = require('tiny-secp256k1');
10
11
 
11
- const bufferAsHex = buffer => buffer.toString('hex');
12
+ const bufferAsHex = buffer => Buffer.from(buffer).toString('hex');
12
13
  const {concat} = Buffer;
13
14
  const defaultBaseFee = '1000';
14
15
  const defaultCltvDelta = 144;
15
16
  const defaultFeeRate = '1';
17
+ const derivePublicKey = key => tinysecp256k1.pointFromScalar(key, true);
16
18
  const hexAsBuffer = hex => Buffer.from(hex, 'hex');
17
19
  const {isArray} = Array;
20
+ const {isPrivate} = tinysecp256k1;
18
21
  const keyFamilyIdentity = 6;
19
22
  const keyIndexIdentity = 0;
20
23
  const makePrivateKey = () => randomBytes(32);
@@ -103,20 +106,33 @@ module.exports = (args, cbk) => {
103
106
  return cbk();
104
107
  },
105
108
 
106
- // Create a key pair for a virtual channel invoice
107
- getKeyPair: ['validate', async ({}) => {
109
+ // Generate key pair
110
+ getKeyPair: ['validate', ({}, cbk) => {
108
111
  // Exit early when not using a virtual channel
109
112
  if (!args.is_virtual) {
110
- return;
113
+ return cbk();
111
114
  }
112
115
 
113
- const ecp = (await import('ecpair')).ECPairFactory(tinysecp256k1);
116
+ return asyncRetry({}, cbk => {
117
+ const privateKey = makePrivateKey();
114
118
 
115
- const key = ecp.fromPrivateKey(makePrivateKey());
119
+ // Very rarely random bytes are not a valid private key
120
+ if (!isPrivate(privateKey)) {
121
+ return cbk([503, 'ExpectedValidPrivateKeyFromRandomBytes']);
122
+ }
123
+
124
+ const publicKey = derivePublicKey(privateKey);
116
125
 
117
- const publicKey = unit8AsHex(key.publicKey);
126
+ if (!publicKey) {
127
+ return cbk([503, 'ExpectedDerivedPublicKeyFromPrivateKey']);
128
+ }
118
129
 
119
- return {private_key: key.privateKey, public_key: publicKey};
130
+ return cbk(null, {
131
+ private_key: privateKey,
132
+ public_key: bufferAsHex(publicKey),
133
+ });
134
+ },
135
+ cbk);
120
136
  }],
121
137
 
122
138
  // Assemble the hop hints from the chosen hint channels
package/package.json CHANGED
@@ -28,8 +28,7 @@
28
28
  "cbor": "10.0.12",
29
29
  "colorette": "2.0.20",
30
30
  "crypto-js": "4.2.0",
31
- "csv-parse": "6.2.1",
32
- "ecpair": "2.1.0",
31
+ "csv-parse": "7.0.1",
33
32
  "goldengate": "16.0.3",
34
33
  "grammy": "1.44.0",
35
34
  "hot-formula-parser": "4.0.0",
@@ -37,7 +36,7 @@
37
36
  "ini": "7.0.0",
38
37
  "inquirer": "14.0.2",
39
38
  "ln-accounting": "10.0.3",
40
- "ln-service": "59.1.2",
39
+ "ln-service": "59.2.0",
41
40
  "ln-sync": "8.0.3",
42
41
  "ln-telegram": "8.0.3",
43
42
  "minimist": "1.2.8",
@@ -81,5 +80,5 @@
81
80
  "postpublish": "docker buildx build --platform linux/amd64,linux/arm64 -t alexbosworth/balanceofsatoshis -t alexbosworth/balanceofsatoshis:$npm_package_version --push .",
82
81
  "test": "npx nyc@17.1.0 node --experimental-test-coverage --test test/arrays/*.js test/balances/*.js test/chain/*.js test/display/*.js test/encryption/*.js test/lnd/*.js test/network/*.js test/nodes/*.js test/peers/*.js test/responses/*.js test/routing/*.js test/services/*.js test/swaps/*.js test/tags/*.js test/telegram/*.js test/wallets/*.js"
83
82
  },
84
- "version": "22.1.5"
83
+ "version": "22.1.7"
85
84
  }
@@ -1,37 +1,25 @@
1
1
  const {equal} = require('node:assert').strict;
2
2
  const test = require('node:test');
3
3
 
4
- const {address} = require('bitcoinjs-lib');
5
4
  const {createChainAddress} = require('ln-service');
6
- const {crypto} = require('bitcoinjs-lib');
7
- const {networks} = require('bitcoinjs-lib');
8
- const {script} = require('bitcoinjs-lib');
9
5
  const {spawnLightningCluster} = require('ln-docker-daemons');
10
- const tinysecp = require('tiny-secp256k1');
11
6
 
12
7
  const {fundTransaction} = require('./../../chain');
13
8
 
14
- const {compile} = script;
15
9
  const count = 100;
16
- const {fromOutputScript} = address;
17
- const makeTaprootKey = (k, h) => tinysecp.xOnlyPointAddTweak(k, h).xOnlyPubkey;
18
- const OP_1 = 81;
19
- const shortKey = keyPair => keyPair.publicKey.slice(1, 33);
20
- const tapHash = k => crypto.taggedHash('TapTweak', k.publicKey.slice(1, 33));
21
10
  const tokens = 1e6;
22
11
 
23
12
  // Funding a transaction should result in a funded tx
24
13
  test(`Fund transaction`, async () => {
25
- const ecp = (await import('ecpair')).ECPairFactory(tinysecp);
26
14
  const {kill, nodes} = await spawnLightningCluster({});
27
15
 
28
16
  const [{generate, lnd}] = nodes;
29
17
 
30
- const {address} = await createChainAddress({lnd, format: 'p2tr'});
18
+ try {
19
+ const {address} = await createChainAddress({lnd, format: 'p2tr'});
31
20
 
32
- await generate({count});
21
+ await generate({count});
33
22
 
34
- try {
35
23
  await fundTransaction({
36
24
  lnd,
37
25
  addresses: [address],
@@ -44,7 +32,7 @@ test(`Fund transaction`, async () => {
44
32
  });
45
33
  } catch (err) {
46
34
  equal(err, null, 'Expected no error');
35
+ } finally {
36
+ await kill({});
47
37
  }
48
-
49
- await kill({});
50
38
  });
@@ -19,7 +19,7 @@ const report = [
19
19
  },
20
20
  {},
21
21
  {
22
- subtitle: '56 years ago',
22
+ subtitle: '57 years ago',
23
23
  title: 'Last Block:',
24
24
  },
25
25
  {