Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
entropy = bytes_1.arrayify(hdnode_1.mnemonicToEntropy(account.mnemonic));
if (!path) {
path = hdnode_1.defaultPath;
}
}
var client = options.client;
if (!client) {
client = "ethers.js";
}
// Check/generate the salt
var salt = null;
if (options.salt) {
salt = bytes_1.arrayify(options.salt);
}
else {
salt = random_1.randomBytes(32);
;
}
// Override initialization vector
var iv = null;
if (options.iv) {
iv = bytes_1.arrayify(options.iv);
if (iv.length !== 16) {
throw new Error("invalid iv");
}
}
else {
iv = random_1.randomBytes(16);
}
// Override the uuid
var uuidRandom = null;
if (options.uuid) {
salt = bytes_1.arrayify(options.salt);
}
else {
salt = random_1.randomBytes(32);
;
}
// Override initialization vector
var iv = null;
if (options.iv) {
iv = bytes_1.arrayify(options.iv);
if (iv.length !== 16) {
throw new Error("invalid iv");
}
}
else {
iv = random_1.randomBytes(16);
}
// Override the uuid
var uuidRandom = null;
if (options.uuid) {
uuidRandom = bytes_1.arrayify(options.uuid);
if (uuidRandom.length !== 16) {
throw new Error("invalid uuid");
}
}
else {
uuidRandom = random_1.randomBytes(16);
}
// Override the scrypt password-based key derivation function parameters
var N = (1 << 17), r = 8, p = 1;
if (options.scrypt) {
if (options.scrypt.N) {
throw new Error("invalid iv");
}
}
else {
iv = randomBytes(16);
}
// Override the uuid
let uuidRandom = null;
if (options.uuid) {
uuidRandom = arrayify(options.uuid);
if (uuidRandom.length !== 16) {
throw new Error("invalid uuid");
}
}
else {
uuidRandom = randomBytes(16);
}
// Override the scrypt password-based key derivation function parameters
let N = (1 << 17), r = 8, p = 1;
if (options.scrypt) {
if (options.scrypt.N) {
N = options.scrypt.N;
}
if (options.scrypt.r) {
r = options.scrypt.r;
}
if (options.scrypt.p) {
p = options.scrypt.p;
}
}
// We take 64 bytes:
// - 32 bytes As normal for the Web3 secret storage (derivedKey, macPrefix)
entropy = arrayify(mnemonicToEntropy(account.mnemonic));
if (!path) {
path = defaultPath;
}
}
let client = options.client;
if (!client) {
client = "ethers.js";
}
// Check/generate the salt
let salt = null;
if (options.salt) {
salt = arrayify(options.salt);
}
else {
salt = randomBytes(32);
;
}
// Override initialization vector
let iv = null;
if (options.iv) {
iv = arrayify(options.iv);
if (iv.length !== 16) {
throw new Error("invalid iv");
}
}
else {
iv = randomBytes(16);
}
// Override the uuid
let uuidRandom = null;
if (options.uuid) {
},
ciphertext: hexlify(ciphertext).substring(2),
kdf: "scrypt",
kdfparams: {
salt: hexlify(salt).substring(2),
n: N,
dklen: 32,
p: p,
r: r
},
mac: mac.substring(2)
}
};
// If we have a mnemonic, encrypt it into the JSON wallet
if (entropy) {
const mnemonicIv = randomBytes(16);
const mnemonicCounter = new aes.Counter(mnemonicIv);
const mnemonicAesCtr = new aes.ModeOfOperation.ctr(mnemonicKey, mnemonicCounter);
const mnemonicCiphertext = arrayify(mnemonicAesCtr.encrypt(entropy));
const now = new Date();
const timestamp = (now.getUTCFullYear() + "-" +
zpad(now.getUTCMonth() + 1, 2) + "-" +
zpad(now.getUTCDate(), 2) + "T" +
zpad(now.getUTCHours(), 2) + "-" +
zpad(now.getUTCMinutes(), 2) + "-" +
zpad(now.getUTCSeconds(), 2) + ".0Z");
data["x-ethers"] = {
client: client,
gethFilename: ("UTC--" + timestamp + "--" + data.address),
mnemonicCounter: hexlify(mnemonicIv).substring(2),
mnemonicCiphertext: hexlify(mnemonicCiphertext).substring(2),
path: path,
let entropy: Uint8Array = null
let path: string = account.path;
if (account.mnemonic) {
entropy = arrayify(mnemonicToEntropy(account.mnemonic));
if (!path) { path = defaultPath; }
}
let client = options.client;
if (!client) { client = "ethers.js"; }
// Check/generate the salt
let salt: Uint8Array = null;
if (options.salt) {
salt = arrayify(options.salt);
} else {
salt = randomBytes(32);;
}
// Override initialization vector
let iv: Uint8Array = null;
if (options.iv) {
iv = arrayify(options.iv);
if (iv.length !== 16) { throw new Error("invalid iv"); }
} else {
iv = randomBytes(16);
}
// Override the uuid
let uuidRandom: Uint8Array = null;
if (options.uuid) {
uuidRandom = arrayify(options.uuid);
if (uuidRandom.length !== 16) { throw new Error("invalid uuid"); }
salt = arrayify(options.salt);
}
else {
salt = randomBytes(32);
;
}
// Override initialization vector
let iv = null;
if (options.iv) {
iv = arrayify(options.iv);
if (iv.length !== 16) {
throw new Error("invalid iv");
}
}
else {
iv = randomBytes(16);
}
// Override the uuid
let uuidRandom = null;
if (options.uuid) {
uuidRandom = arrayify(options.uuid);
if (uuidRandom.length !== 16) {
throw new Error("invalid uuid");
}
}
else {
uuidRandom = randomBytes(16);
}
// Override the scrypt password-based key derivation function parameters
let N = (1 << 17), r = 8, p = 1;
if (options.scrypt) {
if (options.scrypt.N) {
// Override initialization vector
let iv: Uint8Array = null;
if (options.iv) {
iv = arrayify(options.iv);
if (iv.length !== 16) { throw new Error("invalid iv"); }
} else {
iv = randomBytes(16);
}
// Override the uuid
let uuidRandom: Uint8Array = null;
if (options.uuid) {
uuidRandom = arrayify(options.uuid);
if (uuidRandom.length !== 16) { throw new Error("invalid uuid"); }
} else {
uuidRandom = randomBytes(16);
}
// Override the scrypt password-based key derivation function parameters
let N = (1 << 17), r = 8, p = 1;
if (options.scrypt) {
if (options.scrypt.N) { N = options.scrypt.N; }
if (options.scrypt.r) { r = options.scrypt.r; }
if (options.scrypt.p) { p = options.scrypt.p; }
}
// We take 64 bytes:
// - 32 bytes As normal for the Web3 secret storage (derivedKey, macPrefix)
// - 32 bytes AES key to encrypt mnemonic with (required here to be Ethers Wallet)
return scrypt.scrypt(passwordBytes, salt, N, r, p, 64, progressCallback).then((key) => {
key = arrayify(key);
static createRandom(options?: any): Wallet {
let entropy: Uint8Array = randomBytes(16);
if (!options) { options = { }; }
if (options.extraEntropy) {
entropy = arrayify(hexDataSlice(keccak256(concat([ entropy, options.extraEntropy ])), 0, 16));
}
const mnemonic = entropyToMnemonic(entropy, options.locale);
return Wallet.fromMnemonic(mnemonic, options.path, options.locale);
}
static createRandom(options) {
let entropy = randomBytes(16);
if (!options) {
options = {};
}
if (options.extraEntropy) {
entropy = arrayify(hexDataSlice(keccak256(concat([entropy, options.extraEntropy])), 0, 16));
}
const mnemonic = entropyToMnemonic(entropy, options.locale);
return Wallet.fromMnemonic(mnemonic, options.path, options.locale);
}
static fromEncryptedJson(json, password, progressCallback) {