Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export const getPublicKey: NaclInterface['getPublicKey'] = privateKey => {
const publicKeyBytes = Buffer.alloc(sodium.crypto_sign_PUBLICKEYBYTES);
const privateKeyBytes = Buffer.alloc(sodium.crypto_sign_SECRETKEYBYTES);
sodium.crypto_sign_seed_keypair(publicKeyBytes, privateKeyBytes, privateKey);
return publicKeyBytes;
};
public makeKeyPair(hash: Buffer): IKeyPair {
const keyPair: IKeyPair = {
publicKey: Buffer.alloc(sodium.crypto_sign_PUBLICKEYBYTES),
privateKey: Buffer.alloc(sodium.crypto_sign_SECRETKEYBYTES)
};
sodium.crypto_sign_seed_keypair(keyPair.publicKey, keyPair.privateKey, hash);
return keyPair;
}
public makeKeyPair(hash: Buffer): IKeypair {
const publicKey = Buffer.alloc(
sodium.crypto_sign_PUBLICKEYBYTES
) as Buffer & As<'publicKey'>;
const privateKey = Buffer.alloc(
sodium.crypto_sign_SECRETKEYBYTES
) as Buffer & As<'privateKey'>;
sodium.crypto_sign_seed_keypair(publicKey, privateKey, hash);
return { privateKey, publicKey };
}
crypto_sign_SEEDBYTES) ||
Buffer.allocUnsafe(crypto_sign_SEEDBYTES)
)
const key = (
ensureBufferWithSize(
utils.toBuffer(opts.key, 'hex'),
crypto_kdf_KEYBYTES) ||
secretKey.slice(0, crypto_kdf_KEYBYTES)
)
if (!opts.publicKey || !opts.secretKey) {
if (!opts.seed) {
crypto_generichash_batch(seed, [ secret ])
}
crypto_sign_seed_keypair(publicKey, secretKey, seed)
}
if (true === opts.keygen) {
return {
publicKey, secretKey, secret, key
}
}
opts.sign.publicKey = publicKey
opts.sign.secretKey = secretKey
opts.segment.key = key
if (null !== nonce) {
opts.segment.nonce = nonce
}
ed.makeKeypair = function(hash) {
const publicKey = Buffer.alloc(sodium.crypto_sign_PUBLICKEYBYTES);
const privateKey = Buffer.alloc(sodium.crypto_sign_SECRETKEYBYTES);
sodium.crypto_sign_seed_keypair(publicKey, privateKey, hash);
return {
publicKey,
privateKey,
};
};
export const getKeyPair: NaclInterface['getKeyPair'] = hashedSeed => {
const publicKeyBytes = Buffer.alloc(sodium.crypto_sign_PUBLICKEYBYTES);
const privateKeyBytes = Buffer.alloc(sodium.crypto_sign_SECRETKEYBYTES);
sodium.crypto_sign_seed_keypair(publicKeyBytes, privateKeyBytes, hashedSeed);
return {
publicKeyBytes,
privateKeyBytes,
};
};
exports.keyPair = function (seed) {
var publicKey = new Buffer(sodium.crypto_sign_PUBLICKEYBYTES)
var secretKey = new Buffer(sodium.crypto_sign_SECRETKEYBYTES)
if (seed) sodium.crypto_sign_seed_keypair(publicKey, secretKey, seed)
else sodium.crypto_sign_keypair(publicKey, secretKey)
return {
publicKey: publicKey,
secretKey: secretKey
}
}
assert(message.byteLength <= 1000)
var self = this
var rendevousPoint = Buffer.allocUnsafe(sodium.crypto_kx_SESSIONKEYBYTES)
sodium.crypto_kx_server_session_keys(
rendevousPoint,
null,
self.keypair.publicKey,
self.keypair.secretKey,
remoteKey
)
var discoveryPk = Buffer.alloc(sodium.crypto_sign_PUBLICKEYBYTES)
var discoverySk = sodium.sodium_malloc(sodium.crypto_sign_SECRETKEYBYTES)
sodium.crypto_sign_seed_keypair(discoveryPk, discoverySk, rendevousPoint)
self.dht.put({
v: message,
k: discoveryPk,
seq: 0,
sign: function (buf) {
var sig = Buffer.alloc(sodium.crypto_sign_BYTES)
sodium.crypto_sign_detached(sig, buf, discoverySk)
return sig
}
}, cb)
}
secretKey.writable(_secretKey => {
sodium.crypto_sign_seed_keypair(publicKey, _secretKey, _seed)
})
})