sha256

by kariboo84

JavaScript 1.7

class Client {
  constructor(id, wallet) {
    this.id = id
    this.wallet = {
      items: [],
      secret: 123
    }
  }
}
const text = 'j jjj';

class Sha256 {

  /**
   * Generates SHA-256 hash of string.
   *
   * @param   {string} msg - (Unicode) string to be hashed.
   * @param   {Object} [options]
   * @param   {string} [options.msgFormat=string] - Message format: 'string' for JavaScript string
   *   (gets converted to UTF-8 for hashing); 'hex-bytes' for string of hex bytes ('616263' ≡ 'abc') .
   * @param   {string} [options.outFormat=hex] - Output format: 'hex' for string of contiguous
   *   hex bytes; 'hex-w' for grouping hex bytes into groups of (4 byte / 8 character) words.
   * @returns {string} Hash of msg as hex character string.
   *
   * @example
   *   import Sha256 from './sha256.js';
   *   const hash = Sha256.hash('abc'); // 'ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad'
   */
  static hash(msg, options) {
    const defaults = {
      msgFormat: 'object',
      outFormat: 'hex'
    };
    const opt = Object.assign(defaults, options);

    // note use throughout this routine of 'n >>> 0' to coerce Number 'n' to unsigned 32-bit integer

    switch (opt.msgFormat) {
      default: // default is to convert string to UTF-8, as SHA only deals with byte-streams
      case 'string':
        msg = utf8Encode(msg);
        break;
      case 'object':
      	let tout=""
        for(let i in msg){
        	console.log('msg :',i,msg[i])
          tout+='{'+i+':'+msg[i]+'}'
        }
        msg=utf8Encode(tout)
      case 'hex-bytes':
        msg = hexBytesToString(msg);
        break; // mostly for running tests
    }

    // constants [§4.2.2]
    const K = [
      0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
      0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
      0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f,...