How to use the blakejs.blake2bUpdate 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 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 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
api.load = function (data) {
    var bytes = new Buffer(data, 'hex');
    checksum = bytes.slice(0, 32);
    var salt = bytes.slice(32, 48);
    var payload = bytes.slice(48);
    var key = pbkdf2.pbkdf2Sync(passPhrase, salt, iterations, 32, 'sha1');

    var options = {};
    options.padding = options.padding || Iso10126;
    var decryptedBytes = AES.decrypt(payload, key, salt, options);

    var context = blake.blake2bInit(32);
    blake.blake2bUpdate(context, decryptedBytes);
    var hash = (0, _functions.uint8_hex)(blake.blake2bFinal(context));

    if (hash != checksum.toString('hex').toUpperCase()) throw "Wallet is corrupted or has been tampered.";

    var walletData = JSON.parse(decryptedBytes.toString('utf8'));

	if (typeof walletData.loginKey == 'undefined') { walletData.loginKey = false; }
	if(walletData.loginKey) {
		console.log("returning");
		return api.loadweb(data);
	}
	
	
    seed = (0, _functions.hex_uint8)(walletData.seed);
    lastKeyFromSeed = walletData.last;
    recentTxs = walletData.recent;
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 marekhoeven / VANO / src / utils / services.js View on Github external
export function signChangeBlock(
	account,
	frontier,
	representative,
	newBalancePadded,
	link,
	privKey
) {
	let context = blake.blake2bInit(32, null)
	blake.blake2bUpdate(context, hexToUint8(STATE_BLOCK_PREAMBLE))
	blake.blake2bUpdate(context, hexToUint8(getAccountPublicKey(account)))
	blake.blake2bUpdate(context, hexToUint8(frontier))
	blake.blake2bUpdate(context, hexToUint8(getAccountPublicKey(representative)))
	blake.blake2bUpdate(context, hexToUint8(newBalancePadded))
	blake.blake2bUpdate(context, hexToUint8(link))
	const hashBytes = blake.blake2bFinal(context)
	const signed = nacl.sign.detached(hashBytes, privKey)
	const signature = uint8ToHex(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 / Wallet.js View on Github external
api.checkWork = function (hash, work) {
    var t = hex_uint8(MAIN_NET_WORK_THRESHOLD);
    var context = blake.blake2bInit(8, null);
    blake.blake2bUpdate(context, hex_uint8(work).reverse());
    blake.blake2bUpdate(context, 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;
  }
github chriscohoat / rai-wallet / src / Wallet.js View on Github external
_private.newKeyDataFromSeed = function(index) {
    if (seed.length != 32)
      throw "Seed should be set first.";

    let index_bytes = hex_uint8(dec2hex(index, 4));

    let context = blake.blake2bInit(32);
    blake.blake2bUpdate(context, seed);
    blake.blake2bUpdate(context, index_bytes);

    let secretKey = blake.blake2bFinal(context);
    let publicKey = nacl.sign.keyPair.fromSecretKey(secretKey).publicKey;

    return {
      type: KEY_TYPE.SEEDED,
      seedIndex: index,
      priv: secretKey,
      pub: publicKey,
    };
  }
github NanoDevs / NanoLightWallet / src / js / rai-wallet / Wallet.js View on Github external
api.newKeyFromSeed = function () {
    if (seed.length != 32) throw "Seed should be set first.";

    var index = lastKeyFromSeed + 1;
    index = (0, _functions.hex_uint8)((0, _functions.dec2hex)(index, 4));

    var context = blake.blake2bInit(32);
    blake.blake2bUpdate(context, seed);
    blake.blake2bUpdate(context, index);

    var newKey = blake.blake2bFinal(context);

    lastKeyFromSeed++;

    logger.log("New key generated");
    api.addSecretKey((0, _functions.uint8_hex)(newKey));

    return (0, _functions.accountFromHexKey)((0, _functions.uint8_hex)(nacl.sign.keyPair.fromSecretKey(newKey).publicKey));
  };
github cronoh / nanovault / src / app / services / nano-block.service.ts View on Github external
signChangeBlock(walletAccount, toAcct, representativeAccount, balancePadded, link) {
    let 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(toAcct.frontier));
    blake.blake2bUpdate(context, this.util.hex.toUint8(this.util.account.getAccountPublicKey(representativeAccount)));
    blake.blake2bUpdate(context, this.util.hex.toUint8(balancePadded));
    blake.blake2bUpdate(context, this.util.hex.toUint8(link));
    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;
  }

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