How to use the blakejs.blake2bInit function in blakejs

To help you get started, we’ve selected a few blakejs 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 vacuumlabs / adalite / utils.js View on Github external
exports.addressHash = function(input) {
  const serializedInput = cbor.encode(input)

  const firstHash = new Buffer(sha3256(serializedInput), 'hex')

  const context = blake2.blake2bInit(28) // blake2b-224
  blake2.blake2bUpdate(context, firstHash)

  return new Buffer(blake2.blake2bFinal(context)).toString('hex')
}
github vitorcremonez / nano-paper-wallet / src / helpers / RaiBlocksGenerator.js View on Github external
_generatePair(seed, accountIndex = 0) {
        if (!this._isValidSeed(seed)) {
            alert("This is not a valid SEED!");
            return null;
        }

        if(!this._isValidIndexAccount(accountIndex)) {
            alert("Invalid account index!");
            return null;
        }

        let index = hex_uint8(dec2hex(accountIndex, 4)); // 00000000 - FFFFFFFF
        let context = blake.blake2bInit(32);
        blake.blake2bUpdate(context, hex_uint8(seed));
        blake.blake2bUpdate(context, index);
        let key = blake.blake2bFinal(context);

        return {
            public_key: accountFromHexKey(uint8_hex(nacl.sign.keyPair.fromSecretKey(key).publicKey)),
            private_key: uint8_hex(key),
        }
    }
github NanoDevs / NanoLightWallet / src / js / rai-wallet / Wallet.js View on Github external
for (var _i7 in readyBlocks) {
      pack.readyBlocks.push(readyBlocks[_i7].getEntireJSON());
    }
    pack.keys = tempKeys;
    pack.seed = (0, _functions.uint8_hex)(seed);
    pack.last = lastKeyFromSeed;
    pack.recent = recentTxs;
    pack.remoteWork = remoteWork;
    pack.autoWork = autoWork;
    pack.minimumReceive = minimumReceive.toString();

    pack = JSON.stringify(pack);
    pack = (0, _functions.stringToHex)(pack);
    pack = new Buffer(pack, 'hex');

    var context = blake.blake2bInit(32);
    blake.blake2bUpdate(context, pack);
    checksum = blake.blake2bFinal(context);

    var salt = new Buffer(nacl.randomBytes(16));
    var key = pbkdf2.pbkdf2Sync(passPhrase, salt, iterations, 32, 'sha1');

    var options = { mode: AES.CBC, padding: Iso10126 };
    var encryptedBytes = AES.encrypt(pack, key, salt, options);

    var payload = Buffer.concat([new Buffer(checksum), salt, encryptedBytes]);
    return payload.toString('hex');
  };
github NanoDevs / NanoLightWallet / src / js / rai-wallet / Block.js View on Github external
api.checkWork = function (work) {
    var blockHash = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;

    if (blockHash === false) {
      blockHash = api.getPrevious();
    }

    var t = (0, _functions.hex_uint8)(MAIN_NET_WORK_THRESHOLD);
    var context = blake.blake2bInit(8, null);
    blake.blake2bUpdate(context, (0, _functions.hex_uint8)(work).reverse());
    blake.blake2bUpdate(context, (0, _functions.hex_uint8)(blockHash));
    var threshold = blake.blake2bFinal(context).reverse();

    if (threshold[0] == t[0]) if (threshold[1] == t[1]) if (threshold[2] == t[2]) if (threshold[3] >= t[3]) return true;
    return false;
  };
github cronoh / nanovault / src / app / services / nano-block.service.ts View on Github external
signOpenBlock(walletAccount, previousBlock, sourceBlock, newBalancePadded, representative) {
    const context = blake.blake2bInit(32, null);
    blake.blake2bUpdate(context, this.util.hex.toUint8(STATE_BLOCK_PREAMBLE));
    blake.blake2bUpdate(context, this.util.hex.toUint8(this.util.account.getAccountPublicKey(walletAccount.id)));
    blake.blake2bUpdate(context, this.util.hex.toUint8(previousBlock));
    blake.blake2bUpdate(context, this.util.hex.toUint8(this.util.account.getAccountPublicKey(representative)));
    blake.blake2bUpdate(context, this.util.hex.toUint8(newBalancePadded));
    blake.blake2bUpdate(context, this.util.hex.toUint8(sourceBlock));
    const hashBytes = blake.blake2bFinal(context);

    const privKey = walletAccount.keyPair.secretKey;
    const signed = nacl.sign.detached(hashBytes, privKey);
    const signature = this.util.hex.fromUint8(signed);

    return signature;
  }
github cronoh / nanovault / src / app / services / util.service.ts View on Github external
function generateAccountSecretKeyBytes(seedBytes, accountIndex) {
  const accountBytes = hexToUint8(decToHex(accountIndex, 4));
  const context = blake.blake2bInit(32);
  blake.blake2bUpdate(context, seedBytes);
  blake.blake2bUpdate(context, accountBytes);
  const newKey = blake.blake2bFinal(context);

  return newKey;
}
github chriscohoat / rai-wallet / src / Block.js View on Github external
api.build = function () {

    switch (type) {
      case 'send':
        data = "";
        data += MAGIC_NUMBER + VERSION_MAX + VERSION_USING + VERSION_MIN + uint8_hex(blockID[type]) + EXTENSIONS;
        data += previous;
        data += destination
        data += balance;

        var context = blake.blake2bInit(32, null);
        blake.blake2bUpdate(context, hex_uint8(previous));
        blake.blake2bUpdate(context, hex_uint8(destination));
        blake.blake2bUpdate(context, hex_uint8(balance));
        hash = uint8_hex(blake.blake2bFinal(context));
        break;

      case 'receive':
        data = "";
        data += MAGIC_NUMBER + VERSION_MAX + VERSION_USING + VERSION_MIN + uint8_hex(blockID[type]) + EXTENSIONS;
        data += previous;
        data += source;

        var context = blake.blake2bInit(32, null);
        blake.blake2bUpdate(context, hex_uint8(previous));
        blake.blake2bUpdate(context, hex_uint8(source));
        hash = uint8_hex(blake.blake2bFinal(context));
github marekhoeven / VANO / src / utils / services.js View on Github external
export function signOpenBlock(
	account,
	previousBlock,
	sourceBlock,
	newBalancePadded,
	representative,
	privKey
) {
	const context = blake.blake2bInit(32, null)
	blake.blake2bUpdate(context, hexToUint8(STATE_BLOCK_PREAMBLE))
	blake.blake2bUpdate(context, hexToUint8(getAccountPublicKey(account)))
	blake.blake2bUpdate(context, hexToUint8(previousBlock))
	blake.blake2bUpdate(context, hexToUint8(getAccountPublicKey(representative)))
	blake.blake2bUpdate(context, hexToUint8(newBalancePadded))
	blake.blake2bUpdate(context, hexToUint8(sourceBlock))
	const hashBytes = blake.blake2bFinal(context)
	const signed = nacl.sign.detached(hashBytes, privKey)
	const signature = uint8ToHex(signed)

	return signature
}
github NanoDevs / NanoLightWallet / src / js / rai-wallet / Wallet.js View on Github external
api.checkWork = function (hash, work) {
    var t = (0, _functions.hex_uint8)(MAIN_NET_WORK_THRESHOLD);
    var context = blake.blake2bInit(8, null);
    blake.blake2bUpdate(context, (0, _functions.hex_uint8)(work).reverse());
    blake.blake2bUpdate(context, (0, _functions.hex_uint8)(hash));
    var threshold = blake.blake2bFinal(context).reverse();

    if (threshold[0] == t[0]) if (threshold[1] == t[1]) if (threshold[2] == t[2]) if (threshold[3] >= t[3]) return true;
    return false;
  };

blakejs

Pure Javascript implementation of the BLAKE2b and BLAKE2s hash functions

MIT
Latest version published 3 years ago

Package Health Score

65 / 100
Full package analysis