Skip to content

Commit 41a55dc

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

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

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

Lines changed: 12 additions & 9 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,32 @@ 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+
* Derives the shared secret for the middleware using a private key and the middleware's public key.
212213
* This is used for secure communication between the middleware and the user.
213214
*/
214-
export function deriveMiddlewareSharedSecret(coinName: 'lnbtc' | 'tlnbtc', userXprv: string): Buffer {
215+
export function deriveMiddlewareSharedSecret(coinName: 'lnbtc' | 'tlnbtc', xprv: string): Buffer {
215216
const publicKey = Buffer.from(getStaticsLightningNetwork(coinName).middlewarePubKey, 'hex');
216-
const userAuthHdNode = utxolib.bip32.fromBase58(userXprv);
217+
const userAuthHdNode = utxolib.bip32.fromBase58(xprv);
217218
return sdkcore.getSharedSecret(userAuthHdNode, publicKey);
218219
}
219220

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

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

0 commit comments

Comments
 (0)