Skip to content

Commit b151135

Browse files
chore(abstract-lightning): apply comments
BTC-2202 TICKET: BTC-2202
1 parent 0e70c6a commit b151135

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

modules/abstract-lightning/src/lightning/lightningUtils.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as statics from '@bitgo/statics';
22
import * as utxolib from '@bitgo/utxo-lib';
3+
import { randomBytes } from 'crypto';
34
import { importMacaroon, bytesToBase64 } from 'macaroon';
45
import * as bs58check from 'bs58check';
56
import * as sdkcore from '@bitgo/sdk-core';
@@ -208,30 +209,30 @@ export function deriveLightningServiceSharedSecret(coinName: 'lnbtc' | 'tlnbtc',
208209
}
209210

210211
/**
211-
* Derives the shared secret for the middleware using the user's auth extended private key and the middleware's public key.
212-
* This is used for secure communication between the middleware and the user.
212+
* Derives the shared secret for the middleware using a private key and the middleware's public key.
213213
*/
214-
export function deriveMiddlewareSharedSecret(coinName: 'lnbtc' | 'tlnbtc', userXprv: string): Buffer {
214+
export function deriveMiddlewareSharedSecret(coinName: 'lnbtc' | 'tlnbtc', xprv: string): Buffer {
215215
const publicKey = Buffer.from(getStaticsLightningNetwork(coinName).middlewarePubKey, 'hex');
216-
const userAuthHdNode = utxolib.bip32.fromBase58(userXprv);
216+
const userAuthHdNode = utxolib.bip32.fromBase58(xprv);
217217
return sdkcore.getSharedSecret(userAuthHdNode, publicKey);
218218
}
219219

220220
/**
221-
* Derives the shared secret for TAT service using the user's private key and the TAT public key.
222-
* This is used for secure communication with the TAT service and the user.
221+
* Derives the shared secret for TAT service using ta private key and the TAT public key.
223222
*/
224-
export function deriveTatSharedSecret(coinName: 'lnbtc' | 'tlnbtc', userXprv: string): Buffer {
223+
export function deriveTatSharedSecret(coinName: 'lnbtc' | 'tlnbtc', xprv: string): Buffer {
225224
const publicKey = Buffer.from(getStaticsLightningNetwork(coinName).tatPubKey, 'hex');
226-
const userAuthHdNode = utxolib.bip32.fromBase58(userXprv);
225+
const userAuthHdNode = utxolib.bip32.fromBase58(xprv);
227226
return sdkcore.getSharedSecret(userAuthHdNode, publicKey);
228227
}
229228

230229
/**
231230
* Given a seed, compute a BIP32 derivation index.
232231
* 0 <= index < 4294967295 (largest 4 byte number)
233-
* @param seed
232+
* @param seed (optional) If nothing provided, we will generate one randomly
234233
*/
235-
export function computeBip32DerivationIndexFromSeed(seed: string): number {
236-
return Buffer.from(utxolib.crypto.sha256(Buffer.from(seed, 'utf8'))).readUint32BE(0);
234+
export function computeBip32DerivationIndexFromSeed(seed?: string): number {
235+
return Buffer.from(utxolib.crypto.sha256(Buffer.from(seed ?? randomBytes(32).toString('hex'), 'utf8'))).readUint32BE(
236+
0
237+
);
237238
}

0 commit comments

Comments
 (0)