How to use the js-sha3.keccak256.create function in js-sha3

To help you get started, we’ve selected a few js-sha3 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 burtonator / polar-bookshelf / web / js / Hashcodes.ts View on Github external
public static async createFromStream(readableStream: NodeJS.ReadableStream): Promise {

        const hasher = keccak256.create();

        return new Promise((resolve, reject) => {

            readableStream.on('end', chunk => {
                resolve(base58check.encode(hasher.hex()));
            });

            readableStream.on('error', err => {
                reject(err);
            });

            // data resumes the paused stream so end/error have to be added
            // first.
            readableStream.on('data', chunk => {
                hasher.update(chunk);
            });
github nemtech / nem2-sdk-typescript-javascript / src / core / format / RawAddress.ts View on Github external
public static isValidAddress = (decoded: Uint8Array, networkType: NetworkType): boolean => {
        if (RawAddress.constants.sizes.addressDecoded !== decoded.length) {
            return false;
        }
        const signSchema = SHA3Hasher.resolveSignSchema(networkType);
        const hash = signSchema === SignSchema.SHA3 ? sha3_256.create() : keccak256.create();
        const checksumBegin = RawAddress.constants.sizes.addressDecoded - RawAddress.constants.sizes.checksum;
        hash.update(decoded.subarray(0, checksumBegin));
        const checksum = new Uint8Array(RawAddress.constants.sizes.checksum);
        RawArray.copy(checksum, RawArray.uint8View(hash.arrayBuffer()), RawAddress.constants.sizes.checksum);
        return RawArray.deepEqual(checksum, decoded.subarray(checksumBegin));
    }
}
github parity-js / shell / src / util / hashFetch / index.js View on Github external
return new Promise((resolve, reject) => {
    const hasher = keccak256.create();
    const fileReadStream = fs.createReadStream(path);

    fileReadStream.on('end', () => {
      const actualHash = hasher.hex();

      if (actualHash !== expectedHash) {
        reject(`Hashes don't match: expected ${expectedHash}, got ${actualHash}`);
      } else {
        resolve();
      }
    });

    fileReadStream.on('data', (chunk) => {
      hasher.update(chunk);
    });
  });
github burtonator / polar-bookshelf / web / js / Hashcodes.ts View on Github external
public static async createFromInputSource(inputSource: InputSource): Promise {

        const hasher = keccak256.create();

        return new Promise((resolve, reject) => {

            InputSources.open(inputSource, (data: InputData | undefined, err: Error | undefined) => {

                if (err) {
                    reject(err);
                }

                if (data) {
                    hasher.update(data);
                } else {
                    resolve(base58check.encode(hasher.hex()));
                }

            });