How to use the js-sha256.sha256 function in js-sha256

To help you get started, we’ve selected a few js-sha256 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github shd101wyy / ribbit / frontend / lib / ribbit.ts View on Github external
public formatTag(tag: string): string {
    // check if this is user address
    if (this.web3.utils.isAddress(tag)) {
      return tag.toLowerCase().replace(/^0x/, "0x000000000000000000000000"); // to make it 32bytes.
    }

    // check if this is transaction hash
    if (tag.startsWith("0x") && tag.length === 66) {
      return tag.toLowerCase();
    }

    tag = chineseConv.sify(tag); // convert to simplified Chinese.
    return "0x" + sha256(tag.toLowerCase().replace(IgnoredCharacters, ""));

    /*
    const compressedTag = compressString(tag.toLowerCase().replace(/\s/g, ""));
    let hexString = hexEncode(compressedTag);
    if (hexString.length >= 64) {
      // greate than bytes32
      return "";
    } else {
      while (hexString.length !== 64) {
        // to make it 32bytes.
        hexString += "0";
      }
      return "0x" + hexString;
    }
    */
  }
github jaedb / Iris / src / js / services / spotify / middleware.js View on Github external
results: helpers.arrayOf('uri', action.data.playlists.items),
          more: action.data.playlists.next,
        });
        break;


      case 'SPOTIFY_ME_LOADED':
        var me = { ...helpers.formatUser(action.me) };

        // We are Anonymous currently so use 'me' name as my Pusher username
        if (store.getState().pusher.username == 'Anonymous') {
          store.dispatch(pusherActions.setUsername(me.name));
        }

        if (store.getState().ui.allow_reporting) {
	                const hashed_username = sha256(me.id);
	                ReactGA.set({ userId: hashed_username });
	                ReactGA.event({ category: 'Spotify', action: 'Authorization verified', label: hashed_username });
	            }

        store.dispatch(coreActions.userLoaded(me));
        action.me = me;
        next(action);
        break;

        // This action is irrelevant to us, pass it on to the next middleware
      default:
        return next(action);
    }
  };
}());
github swarmcity / SCLabs-gasstation-service / utility.js View on Github external
utility.signgastankparameters = function(tokenaddress, gastankaddress, gastankclient, take, give, valid_until, random, privatekey) {
    if (privatekey.substring(0, 2) === '0x') privatekey = privatekey.substring(2, privatekey.length);
    const condensed = utility.pack(
      [
        tokenaddress,
        gastankaddress,
        gastankclient,
        take,
        give,
        valid_until,
        random,
      ], [160, 160, 160, 256, 256, 256, 256]);
    const hash = sha256(new Buffer(condensed, 'hex'));
    console.log('tokenaddress', tokenaddress);
    console.log('gastankaddress', gastankaddress);
    console.log('gastankclient', gastankclient);
    console.log('take', take);
    console.log('give', give);
    console.log('valid_until', valid_until);
    console.log('random', random);
    console.log('my hash=', hash);
    const sig = ethUtil.ecsign(
      new Buffer(hash, 'hex'),
      new Buffer(privatekey, 'hex'));
    const r = `0x${sig.r.toString('hex')}`;
    const s = `0x${sig.s.toString('hex')}`;
    const v = sig.v;
    const result = {
      r,
github jaedb / Iris / src / js / services / snapcast / middleware.js View on Github external
'Snapcast websocket error',
              e,
              e.type,
            ));
          }
        };

        socket.onmessage = (message) => {
          var message = JSON.parse(message.data);
          handleMessage(socket, store, message);
        };
        break;

      case 'SNAPCAST_CONNECTED':
        if (store.getState().ui.allow_reporting) {
          const hashed_hostname = sha256(window.location.hostname);
          ReactGA.event({ category: 'Snapcast', action: 'Connected', label: hashed_hostname });
        }
        store.dispatch(uiActions.createNotification({ content: 'Snapcast connected' }));
        store.dispatch(snapcastActions.getServer());
        next(action);
        break;

      case 'SNAPCAST_DISCONNECT':
        if (socket != null) socket.close();
        socket = null;
        break;

      case 'SNAPCAST_DISCONNECTED':
        if (store.getState().snapcast.enabled) {
          store.dispatch(uiActions.createNotification({ type: 'bad', content: 'Snapcast disconnected' }));
        }
github smartcontractkit / chainlink / explorer / src / entity / ChainlinkNode.ts View on Github external
export function hashCredentials(
  accessKey: string,
  secret: string,
  salt: string,
): string {
  return sha256(`v0-${accessKey}-${secret}-${salt}`)
}
github NantesJS / nantesjs-website / src / pages / profil.js View on Github external
<button>Retour</button>
              
              <div>
                <img alt="Fusee" src="{Fusee}">
                <button>Voir mes badges</button>
              </div>
              <div>
                <img alt="Smiley" src="{Smiley}">
                <button>Mon profil public</button>
              </div>
            
          
        
        :
        <div>
          {result === sha256(test) ?
            
            :
            
            }
        </div>
      }
    
  )
}
github chainify / nolik / web / store / Cdms.js View on Github external
type: 'to',
            signature: signBytes(keys, bytes),
          })),
        ),
      from: {
        senderPublicKey: keys.publicKey,
      },
    };
    data.push(cdm);

    for (let i = 0; i &lt; threads.current.cdms.length; i += 1) {
      const fwdCdm = threads.current.cdms[i];
      const fwdBytes = Uint8Array.from(
        sha256(
          `${fwdCdm.rawSubject ? sha256(fwdCdm.rawSubject) : ''}${
            fwdCdm.rawMessage ? sha256(fwdCdm.rawMessage) : ''
          }`,
        ),
      );

      const fwd = {
        subject: fwdCdm.subject,
        message: fwdCdm.message,
        rawSubject: fwdCdm.id === initCdm.id ? fwdInitRawSubject : null,
        rawMessage: fwdCdm.id === initCdm.id ? fwdInitRawMessage : null,
        regarding: {
          reSubjectHash:
            fwdCdm.id === initCdm.id ? null : sha256(fwdInitRawSubject),
          reMessageHash:
            fwdCdm.id === initCdm.id ? null : sha256(fwdInitRawMessage),
        },
        forwarded: {
github chainify / nolik / web / store / Crypto.js View on Github external
decrypThread(item) {
    const { heartbeat } = this.stores;
    const cdms = [];
    const { onliners } = heartbeat;
    const thisItem = item;

    for (let i = 0; i &lt; item.cdms.length; i += 1) {
      const cdm = this.decryptCdm(item.cdms[i]);
      cdms.push(cdm);
    }

    for (let i = 0; i &lt; cdms[0].sharedWith.length; i += 1) {
      const member = cdms[0].sharedWith[i];
      if (onliners.indexOf(member) &lt; 0) {
        onliners.push(sha256(member));
      }
    }

    thisItem.members = cdms[0].sharedWith;
    thisItem.cdms = cdms.reverse();
    heartbeat.onliners = onliners;
    return thisItem;
  }
}
github onejgordon / flow-dashboard / src / js / components / common / BrowserEncryptionWidget.js View on Github external
verify() {
    let {form} = this.state
    if (form.password.length > 0) {
      let key = sha256(form.password)
      let sha = sha256(key)
      api.post("/api/user/encryption/validate_password", {encr_pw_sha: sha}, (res) => {
        this.setState({form_showing: false, form: {password: ''}}, () => {
          UserActions.storeVerifiedEncryptionKey(key)
        })
      }, (res) => {
        this.clear()
      })
    }
  }
github chainify / nolik / web / store / Crypto.js View on Github external
}
        if (fwdMessageHash) {
          msg += `\r\n${fwdMessageHash}`;
        }
        msg += `\r\n`;
      }
      if (data.from &amp;&amp; senderPublicKey &amp;&amp; data.recipients[i].signature) {
        msg += `\r\n`;
        msg += `\r\n`;
        if (senderPublicKey) {
          const cipherText = this.clientCipherText(
            keyPair(CLIENT_SEED).publicKey,
            senderPublicKey,
          );
          msg += `\r\n${cipherText}`;
          msg += `\r\n${sha256(senderPublicKey)}`;
        }
        if (data.recipients[i].signature) {
          msg += `\r\n${data.recipients[i].signature}`;
        }
        msg += `\r\n`;
        msg += `\r\n`;
      }
      msg += '\r\n';
    }
    return msg;
  }