import * as crypto from "@node-lightning/crypto" ; import { generateCipherStream } from "./generateCipherStream" ; import { generateKey } from "./generateKey" ; import { KeyType } from "./KeyType" ; export function generateFiller ( key , numHops , hopSize , sharedSecrets ) { const maxNumHops = 20 ; const fillerSize = ( maxNumHops + 1 ) * hopSize ; let filler = Buffer . alloc ( fillerSize ) ; for ( let i = 0 ; i < numHops - 1 ; i ++ ) { const slice = filler . slice ( hopSize ) ; filler = Buffer . alloc ( fillerSize ) ; slice . copy ( filler ) ; const streamKey = generateKey ( key , sharedSecrets [ i ] ) ; const streamBytes = generateCipherStream ( streamKey , fillerSize ) ; filler = crypto . xor ( filler , streamBytes ) ; } return filler . slice ( ( maxNumHops - numHops + 2 ) * hopSize ) ; }