Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
checkForKeys() {
if (!Settings.getValue('dht25519pub')) {
const keypair = ed.createKeyPair(ed.createSeed());
Settings.setValue('dht25519pub', keypair.publicKey.toString('hex'));
Settings.setValue('dht25519priv', keypair.secretKey.toString('hex'));
Settings.save();
this.keypair = keypair;
return;
}
this.keypair = {
publicKey: Buffer.from(Settings.getValue('dht25519pub'), 'hex'),
secretKey: Buffer.from(Settings.getValue('dht25519priv'), 'hex'),
};
}
async function ensureKey(req, res, next) {
let gci = req.params.gci || parseGCIFromHeaders(req.headers)
let userId = req.cookies.userId
let index = [userId, gci].join(':')
let seed
try {
seed = Buffer.from(await keyStore.get(index), 'base64')
} catch (e) {
seed = ed.createSeed()
await keyStore.put(index, seed.toString('base64'))
}
req.keypair = ed.createKeyPair(seed)
next()
}
export function createKeyPair (): IKeyPair {
const seed = supercop.createSeed();
const keys = supercop.createKeyPair(seed);
return {
publicKey: keys.publicKey.toString("base64"),
privateKey: keys.secretKey.toString("base64")
};
}
constructor (keyPair?: IWallet) {
const seed = supercop.createSeed();
const keys = keyPair || supercop.createKeyPair(seed);
this.publicKey = keys.publicKey;
this.privateKey = (keyPair) ? keyPair.privateKey : keys.secretKey;
}