How to use js-sha256 - 10 common examples

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 RocketChat / Rocket.Chat.ReactNative / app / views / ProfileView / index.js View on Github external
params.username = username;
		}

		// Email
		if (user.emails && user.emails[0].address !== email) {
			params.email = email;
		}

		// newPassword
		if (newPassword) {
			params.newPassword = newPassword;
		}

		// currentPassword
		if (currentPassword) {
			params.currentPassword = SHA256(currentPassword);
		}

		const requirePassword = !!params.email || newPassword;
		if (requirePassword && !params.currentPassword) {
			return this.setState({ showPasswordAlert: true, saving: false });
		}

		try {
			if (avatar.url) {
				try {
					await RocketChat.setAvatarFromService(avatar);
				} catch (e) {
					this.setState({ saving: false, currentPassword: null });
					return this.handleError(e, 'setAvatarFromService', 'changing_avatar');
				}
			}
github dogethereum / dogethereum-contracts / test / utils.js View on Github external
function calcBlockSha256Hash(blockHeader) {
  const headerBin = module.exports.fromHex(blockHeader).slice(0, 80);
  return `0x${Buffer.from(sha256.array(sha256.arrayBuffer(headerBin))).reverse().toString('hex')}`;
}
github apollographql / apollo-server / packages / apollo-server-integration-testsuite / src / index.ts View on Github external
describe('Persisted Queries', () => {
      const query = '{testString}';
      const query2 = '{ testString }';

      const hash = sha256
        .create()
        .update(query)
        .hex();
      const extensions = {
        persistedQuery: {
          version: VERSION,
          sha256Hash: hash,
        },
      };

      const extensions2 = {
        persistedQuery: {
          version: VERSION,
          sha256Hash: sha256
            .create()
            .update(query2)
github apollographql / apollo-server / packages / apollo-server-integration-testsuite / src / index.ts View on Github external
const hash = sha256
        .create()
        .update(query)
        .hex();
      const extensions = {
        persistedQuery: {
          version: VERSION,
          sha256Hash: hash,
        },
      };

      const extensions2 = {
        persistedQuery: {
          version: VERSION,
          sha256Hash: sha256
            .create()
            .update(query2)
            .hex(),
        },
      };

      beforeEach(async () => {
        const map = new Map();
        const cache = {
          set: async (key, val) => {
            await map.set(key, val);
          },
          get: async key => map.get(key),
        };
        app = await createApp({
          graphqlOptions: {
github apollographql / apollo-server / packages / apollo-server-integration-testsuite / src / ApolloServer.ts View on Github external
describe('Persisted Queries', () => {
      let uri: string;
      const query = gql`
        ${TEST_STRING_QUERY}
      `;
      const hash = sha256
        .create()
        .update(TEST_STRING_QUERY)
        .hex();
      const extensions = {
        persistedQuery: {
          version: VERSION,
          sha256Hash: hash,
        },
      };

      beforeEach(async () => {
        const serverInfo = await createApolloServer({
          schema,
          introspection: false,
          persistedQueries: {
            cache: new Map() as any,
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 FourDizzle / js-gpu-bitcoin-miner / client / src / cpu-miner.worker.js View on Github external
function mine() {
  let duration = 0
  let startTime = (new Date()).getTime()
  let batchDiff = 0
  let finished = false
  let hash
  for (let i = 0; i < batchSize; i++) {
    let block = headerIntArr.concat(nonceToByteArray(nonce))
    hash = sha256.update(block)
    hash = sha256.update(hash.digest())

    if (isHashLessThanTarget(hash.hex())) {
      console.log('submit hash:', hash.hex())
      console.log('target:', target.toString(16))
      submitWork(work, nonce)
    }

    if (nonce >= 0xFFFFFFFF) {
      batchDiff = batchSize - i + 1
      finished = true
      break;
    } else {
      nonce++
    }
  }
  duration = (new Date()).getTime() - startTime
github FourDizzle / js-gpu-bitcoin-miner / client / src / cpu-miner.worker.js View on Github external
function mine() {
  let duration = 0
  let startTime = (new Date()).getTime()
  let batchDiff = 0
  let finished = false
  let hash
  for (let i = 0; i < batchSize; i++) {
    let block = headerIntArr.concat(nonceToByteArray(nonce))
    hash = sha256.update(block)
    hash = sha256.update(hash.digest())

    if (isHashLessThanTarget(hash.hex())) {
      console.log('submit hash:', hash.hex())
      console.log('target:', target.toString(16))
      submitWork(work, nonce)
    }

    if (nonce >= 0xFFFFFFFF) {
      batchDiff = batchSize - i + 1
      finished = true
      break;
    } else {
      nonce++
    }
  }