How to use the tweetnacl.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 crossbario / autobahn-js / packages / autobahn / lib / auth / cryptosign.js View on Github external
function delete_private_key (name) {
    // FIXME: poor man's secure erase
    for (var i = 0; i < 5; ++i) {
        seed = nacl.randomBytes(nacl.sign.seedLength);
        localStorage.setItem(name, util.btoa(seed));
        localStorage.setItem(name, '');
        localStorage.setItem(name, null);
    }
}
github wallix / datapeps-sdk-js / test / integration / resource / delete.ts View on Github external
describe("resource.delete", () => {
  let seed = Math.floor(Math.random() * 99999);

  let ctx: Context.aliceBobWithDeviceAndGroupCtx;

  let aliceChildSecret = nacl.randomBytes(128);
  let aliceChild: Context.userAndSessionCtx;

  let resourceA: Utils.Resource, resourceB: Utils.Resource;
  let resourceC: Utils.Resource, resourceD: Utils.Resource;

  let randomResourceId: number;
  let randomResourceIdLong: Long;

  before(async () => {
    let init = await Context.init();
    ctx = await Context.aliceBobWithDeviceAndGroup(init);
    aliceChild = await Context.userAndSession(init, "aliceChild");

    let resourceADataPeps = await new ResourceAPI(aliceChild.session).create(
      "test kind",
      { text: "payload A" },
github wallix / datapeps-sdk-js / test / Context.js View on Github external
return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    identities = [];
                    promises = [];
                    options = options ? options : {};
                    name = options.name == null ? "id" : options.name;
                    for (i = 0; i < n; i++) {
                        secret = nacl.randomBytes(128);
                        identity_1 = generateIdentityFields(init, __assign({}, options, { name: "" + name + i }));
                        promises.push(create(identity_1, secret));
                        identities.push(__assign({}, identity_1, { created: new Date(), admin: false, active: true }));
                    }
                    return [4 /*yield*/, Promise.all(promises)];
                case 1:
                    _a.sent();
                    return [2 /*return*/, { identities: identities }];
            }
        });
    });
github wallix / datapeps-sdk-js / src / CryptoFuncs.ts View on Github external
private generateMasterSalt() {
    if (this.masterSalt == null || this.masterSalt.length == 0) {
      this.masterSalt = nacl.randomBytes(16);
    }
  }
github WorldBrain / Memex / src / sync / background / secrets.ts View on Github external
async generateSyncEncryptionKey(): Promise {
        this.key = ab2str(nacl.randomBytes(nacl.secretbox.keyLength))
        await this._storeKey()
    }
github irisnet / irisnet-crypto / keys / crypto / holder.js View on Github external
Create = function (bk, algo, language) {
    let secret = Nacl.randomBytes(16);
    let keyPair;
    switch (bk) {
        case "iris":
            keyPair = IrisnetKeyPair.Create(secret, algo);
    }
    if (keyPair) {
        let seed = Wordcodec.BytesToWords(keyPair.secret, language);
        let phrase = seed.toString().replace(/,/g, " ");
        return {
            "address": keyPair.address,
            "phrase": phrase,
            "privateKey": keyPair.privateKey,
            "publicKey": keyPair.publicKey
        };
    }
};
github royale-proxy / node-cr-proxy / lib / nonce.js View on Github external
constructor(arg) {
        if (!arg.clientKey) {
            if (arg.nonce) {
                this.buffer = arg.nonce;
            } else {
                this.buffer = new Buffer(nacl.randomBytes(nacl.box.nonceLength));
            }
        } else {
            var b2 = blake2.createHash('blake2b', { digestLength: 24 });
            if (arg.nonce) {
                b2.update(arg.nonce.getBuffer());
            }

            b2.update(arg.clientKey);
            b2.update(arg.serverKey);

            this.buffer = b2.digest();
        }
    }
github jeffallen6767 / chain / src / utils.js View on Github external
createRandomBytes = function(num) {
      return nacl.randomBytes(num);
    },
    getPrivateSeedBuffer = function(obj) {
github stellar / js-stellar-wallets / src / helpers / ScryptEncryption.ts View on Github external
function generateSalt(): string {
  return naclutil.encodeBase64(nacl.randomBytes(SALT_BYTES));
}