import * as crypto from "@node-lightning/crypto" ; /**
 * Generates blinded shared secret between each hop in an onion packet.
 */ export class SharedSecretGenerator { public readonly sessionPubKey : Buffer ; public readonly sharedSecrets : Buffer [ ] ; param sessionKey param hops constructor ( readonly sessionKey , ... hops ) { this . sessionPubKey = crypto . getPublicKey ( sessionKey , true ) ; this . sharedSecrets = [ ] ; let ephemeralKey = sessionKey ; for ( let i = 0 ; i < hops . length ; i ++ ) { const hop = hops [ i ] ; const ss = crypto . ecdh ( hop , ephemeralKey ) ; this . sharedSecrets . push ( ss ) ; const ephemeralPubKey = crypto . getPublicKey ( ephemeralKey , true ) ; const blindingFactor = crypto . sha256 ( Buffer . concat ( [ ephemeralPubKey , ss ] ) ) ; ephemeralKey = crypto . privateKeyMul ( ephemeralKey , blindingFactor ) ; } } }