import crypto from "crypto" ; remarks param ikm param len param salt param info param hash returns export function hkdf ( ikm , len , salt = Buffer . alloc ( 0 ) , info = Buffer . alloc ( 0 ) , hash = "sha256" ) { const prk = hmacHash ( salt , ikm , hash ) ; const n = Math . ceil ( len / prk . byteLength ) ; if ( n > 255 ) throw new Error ( "Output length exceeds maximum" ) ; const t = [ Buffer . alloc ( 0 ) ] ; for ( let i = 1 ; i <= n ; i ++ ) { const tp = t [ t . length - 1 ] ; const bi = Buffer . from ( [ i ] ) ; t . push ( hmacHash ( prk , Buffer . concat ( [ tp , info , bi ] ) , hash ) ) ; } return Buffer . concat ( t . slice ( 1 ) ) . slice ( 0 , len ) ; } function hmacHash ( key , input , hash ) { const hmac = crypto . createHmac ( hash , key ) ; hmac . update ( input ) ; return hmac . digest ( ) ; }