Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const encrypt = async (event) => {
try {
const { passphrase } = event.data;
const privateKey = schnorr.generatePrivateKey();
const keystoreJSON = await encryptPrivateKey('pbkdf2', privateKey, passphrase);
// @ts-ignore
self.postMessage({ keystoreJSON, privateKey });
} catch (error) {
console.log(error);
// @ts-ignore
self.postMessage({ keystoreJSON: undefined, privateKey: undefined });
}
};
async toFile(
passphrase: string,
kdf: 'pbkdf2' | 'scrypt' = 'scrypt',
): Promise {
if (!passphrase || !passphrase.length) {
throw new Error('Passphrase cannot have a length of 0');
}
const keystore = await zcrypto.encryptPrivateKey(
kdf,
this.privateKey,
passphrase,
);
return keystore;
}