import { hmac , randomBytes } from './util/crypto-node' ; export { decrypt , decryptConnectionAddressToken , encrypt , encryptConnectionAddressToken , generateSharedSecretFromToken , generateReceiptHMAC , hash , hmac , randomBytes } from './util/crypto-node' ; export const TOKEN_NONCE_LENGTH = 18 ; const ENCRYPTION_KEY_STRING = Buffer . from ( 'ilp_stream_encryption' , 'utf8' ) ; const FULFILLMENT_GENERATION_STRING = Buffer . from ( 'ilp_stream_fulfillment' , 'utf8' ) ; const PACKET_ID_STRING = Buffer . from ( 'ilp_stream_packet_id' , 'utf8' ) ; export const ENCRYPTION_OVERHEAD = 28 ; export function generateTokenNonce ( ) { return randomBytes ( TOKEN_NONCE_LENGTH ) ; } export function generateRandomCondition ( ) { return randomBytes ( 32 ) ; } export function generatePskEncryptionKey ( sharedSecret ) { return hmac ( sharedSecret , ENCRYPTION_KEY_STRING ) ; } export function generateFulfillmentKey ( sharedSecret ) { return hmac ( sharedSecret , FULFILLMENT_GENERATION_STRING ) ; } export function generateFulfillment ( fulfillmentKey , data ) { return hmac ( fulfillmentKey , data ) ; } export function generateIncomingPacketId ( sharedSecret , sequence ) { return hmac ( sharedSecret , Buffer . concat ( [ PACKET_ID_STRING , Buffer . from ( sequence . toBytes ( ) ) ] ) ) ; }