How to use the tweetnacl/nacl.randomBytes function in tweetnacl

To help you get started, we’ve selected a few tweetnacl 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 chriscohoat / rai-wallet / src / Wallet.js View on Github external
secretKey: uint8_hex(key.priv),
        });
        break;
      default: throw "Unsupported key type"
      }
    }

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

    var context = blake.blake2bInit(32);
    blake.blake2bUpdate(context, pack);
    var 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]);

    // decrypt to check if wallet was corrupted during ecryption somehow
    if(api.decryptAndCheck(payload).toString('hex') === false)
      return api.pack(); // try again, shouldnt happen often
    return payload.toString('hex');
  }
github chriscohoat / rai-wallet / src / Wallet.js View on Github external
api.setLoginKey = function(lk = false)
	{
		if(loginKey === false)
		  if(lk)
			  loginKey = lk;
			else
			  loginKey = uint8_hex(nacl.randomBytes(32));
		// cannot be changed
	}
github vitorcremonez / nano-paper-wallet / src / helpers / RaiBlocksGenerator.js View on Github external
generateSeed(entropy = null) {
        return uint8_hex(nacl.randomBytes(32));
    }
github chriscohoat / rai-wallet / src / Wallet.js View on Github external
api.setRandomSeed = function (overwrite = false) {
    if (seed && !overwrite)
      throw "Seed already exists. To overwrite use setSeed or set overwrite to true";
    seed = nacl.randomBytes(32);
  }
github chriscohoat / rai-wallet / src / Wallet.js View on Github external
api.createWallet = function (setSeed = false) {
    if (!setSeed)
      seed = nacl.randomBytes(32);
    else
      api.setSeed(setSeed);
    api.newKeyFromSeed();
    api.useAccount(keys[0].account);
    loginKey = uint8_hex(nacl.randomBytes(32));
    return uint8_hex(seed);
  }