Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
exports.scalarMultiplicationKeyPair = function (secretKey) {
if (!secretKey) secretKey = Buffer(tweetnacl.randomBytes(tweetnacl.lowlevel.crypto_scalarmult_SCALARBYTES))
return {
secretKey: secretKey,
publicKey: Buffer(tweetnacl.scalarMult.base(secretKey))
}
}
exports.keyPair = function (seed) {
var publicKey = Buffer(tweetnacl.lowlevel.crypto_sign_PUBLICKEYBYTES)
var secretKey = Buffer(tweetnacl.lowlevel.crypto_sign_SECRETKEYBYTES)
if (seed) {
if (seed.length !== tweetnacl.lowlevel.crypto_sign_SEEDBYTES) {
throw new Error('Seed must be ' + tweetnacl.lowlevel.crypto_sign_SEEDBYTES + ' bytes long')
}
secretKey.fill(seed, 0, seed.length)
tweetnacl.lowlevel.crypto_sign_keypair(publicKey, secretKey, true)
} else {
tweetnacl.lowlevel.crypto_sign_keypair(publicKey, secretKey)
}
return {publicKey: publicKey, secretKey: secretKey}
}
exports.key = function () {
return Buffer(tweetnacl.randomBytes(tweetnacl.lowlevel.crypto_secretbox_KEYBYTES))
}
exports.keyPair = function (seed) {
var publicKey = Buffer(tweetnacl.lowlevel.crypto_sign_PUBLICKEYBYTES)
var secretKey = Buffer(tweetnacl.lowlevel.crypto_sign_SECRETKEYBYTES)
if (seed) {
if (seed.length !== tweetnacl.lowlevel.crypto_sign_SEEDBYTES) {
throw new Error('Seed must be ' + tweetnacl.lowlevel.crypto_sign_SEEDBYTES + ' bytes long')
}
secretKey.fill(seed, 0, seed.length)
tweetnacl.lowlevel.crypto_sign_keypair(publicKey, secretKey, true)
} else {
tweetnacl.lowlevel.crypto_sign_keypair(publicKey, secretKey)
}
return {publicKey: publicKey, secretKey: secretKey}
}
'use strict';
var crypto_hash_sha512 = require('tweetnacl').lowlevel.crypto_hash;
/*
* This file is a 1:1 port from the OpenBSD blowfish.c and bcrypt_pbkdf.c. As a
* result, it retains the original copyright and license. The two files are
* under slightly different (but compatible) licenses, and are here combined in
* one file.
*
* Credit for the actual porting work goes to:
* Devi Mandiri
*/
/*
* The Blowfish portions are under the following license:
*
* Blowfish block cipher for OpenBSD
* Copyright 1997 Niels Provos
exports.nonce = function () {
return Buffer(tweetnacl.randomBytes(tweetnacl.lowlevel.crypto_box_NONCEBYTES))
}