Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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;
}