lib/browser-adapters.js
function hashsum(hash, str) {
        // you have to convert from string to array buffer
      var ab
        // you have to represent the algorithm as an object 
        , algo = { name: algos[hash] }
        ;

      if ('string' === typeof str) {
        ab = str2ab(str);
      } else {
        ab = str;
      }

      // All crypto digest methods return a promise
      return crypto.subtle.digest(algo, ab).then(function (digest) {
        // you have to convert the ArrayBuffer to a DataView and then to a hex String
        return ab2hex(digest);
      }).catch(function (e) {
        // if you specify an unsupported digest algorithm or non-ArrayBuffer, you'll get an error
        console.error('sha1sum ERROR');
        console.error(e);
        throw e;
      });
    }
function hashsum(hash, str) {
        // you have to convert from string to array buffer
      var ab
        // you have to represent the algorithm as an object 
        , algo = { name: algos[hash] }
        ;

      if ('string' === typeof str) {
        ab = str2ab(str);
      } else {
        ab = str;
      }

      // All crypto digest methods return a promise
      return crypto.subtle.digest(algo, ab).then(function (digest) {
        // you have to convert the ArrayBuffer to a DataView and then to a hex String
        return ab2hex(digest);
      }).catch(function (e) {
        // if you specify an unsupported digest algorithm or non-ArrayBuffer, you'll get an error
        console.error('sha1sum ERROR');
        console.error(e);
        throw e;
      });
    }
function hashsum ( hash , str ) { // you have to convert from string to array buffer var ab // you have to represent the algorithm as an object  , algo = { name : algos [ hash ] } ; if ( 'string' === typeof str ) { ab = str2ab ( str ) ; } else { ab = str ; } // All crypto digest methods return a promise return crypto . subtle . digest ( algo , ab ) . then ( function ( digest ) { // you have to convert the ArrayBuffer to a DataView and then to a hex String return ab2hex ( digest ) ; } ) . catch ( function ( e ) { // if you specify an unsupported digest algorithm or non-ArrayBuffer, you'll get an error console . error ( 'sha1sum ERROR' ) ; console . error ( e ) ; throw e ; } ) ; }
a more general convenience function
a more general convenience function