import native from './native' ; import { HashInput } from '../node/hash-fn' ; import { IBaseHashOptions , defaultHashLength } from '../base/hash-fn' ; hidden export const normalizeInput = ( input , encoding ? ) : Buffer => { if ( input instanceof Buffer ) { return input ; } if ( typeof input === 'string' ) { return Buffer . from ( input , encoding ) ; } return Buffer . from ( input as Uint8Array ) ; } ; /**
 * Returns a blake3 hash of the input, returning the binary hash data.
 */ export function hash ( input , { length = defaultHashLength } = { } ) { return native . hash ( normalizeInput ( input ) , length ) ; } /**
 * Given cryptographic key material  and a context string, services a subkey of
 * any length. See  https * for more information.
  export function deriveKey ( context , material , { length = defaultHashLength } = { } ) { const hasher = new native . Hasher ( undefined , context ) ; hasher . update ( normalizeInput ( material ) ) ; const result = Buffer . alloc ( length ) ; hasher . digest ( result ) ; return result ; } /**
 * The keyed hash function. See  https .
  export function keyedHash ( key , input , { length = defaultHashLength } = { } ) { const hasher = new native . Hasher ( key ) ; hasher . update ( normalizeInput ( input ) ) ; const result = Buffer . alloc ( length ) ; hasher . digest ( result ) ; return result ; }