const ALGORITHM = 'SHA-256' ; export function hash ( source ) { const encoder = new TextEncoder ( ) ; const data = encoder . encode ( source ) ; return ( global . crypto as any ) . subtle . digest ( ALGORITHM , data ) . then ( ( digest ) => arrayBufferToHex ( digest ) ) ; } function arrayBufferToHex ( source ) { const bytes = new Uint8Array ( source ) ; return [ ... bytes ] . map ( b => b . toString ( 16 ) . padStart ( 2 , '0' ) ) . join ( '' ) ; }