How to use the js-sha256.digest 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 FactomProject / factom-harmony-connect-js-sdk / lib / utils / keyCommon.js View on Github external
static validateCheckSum({ signerKey = '' } = {}) {
    if (!signerKey) {
      return false;
    }

    const signerKeyBytes = base58.decode(signerKey);
    if (signerKeyBytes.length !== 41) {
      return false;
    }

    const prefixBytes = signerKeyBytes.slice(0, 5);
    const keyBytes = signerKeyBytes.slice(5, 37);
    const checkSum = signerKeyBytes.slice(37, 41);

    const tmp = sha256.digest((sha256.digest([...prefixBytes, ...keyBytes])));
    const tmpCheckSum = tmp.slice(0, 4);

    if (Buffer.compare(Buffer.from(checkSum), Buffer.from(tmpCheckSum)) !== 0) {
      return false;
    }

    return true;
  }
github FactomProject / factom-harmony-connect-js-sdk / lib / utils / keyCommon.js View on Github external
static createKeyPair() {
    const privateKeyBytes = secureRandom.randomUint8Array(32);
    let tmp;
    let checkSum;

    tmp = sha256.digest((sha256.digest([...privatePrefixBytes, ...privateKeyBytes])));
    checkSum = tmp.slice(0, 4);
    const privateKey = base58.encode([...privatePrefixBytes, ...privateKeyBytes, ...checkSum]);
    const publicKeyBytes = ec.keyFromSecret(privateKeyBytes).getPublic();
    tmp = sha256.digest((sha256.digest([...publicPrefixBytes, ...publicKeyBytes])));
    checkSum = tmp.slice(0, 4);
    const publicKey = base58.encode([...publicPrefixBytes, ...publicKeyBytes, ...checkSum]);
    return {
      privateKey: privateKey,
      publicKey: publicKey,
    };
  }