Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
}
account = {
_isKeystoreAccount: true,
address: address,
privateKey: bytes_1.hexlify(privateKey)
};
// Version 0.1 x-ethers metadata must contain an encrypted mnemonic phrase
if (utils_1.searchPath(data, "x-ethers/version") === "0.1") {
mnemonicCiphertext = utils_1.looseArrayify(utils_1.searchPath(data, "x-ethers/mnemonicCiphertext"));
mnemonicIv = utils_1.looseArrayify(utils_1.searchPath(data, "x-ethers/mnemonicCounter"));
mnemonicCounter = new aes_js_1.default.Counter(mnemonicIv);
mnemonicAesCtr = new aes_js_1.default.ModeOfOperation.ctr(mnemonicKey, mnemonicCounter);
path = utils_1.searchPath(data, "x-ethers/path") || hdnode_1.defaultPath;
entropy = bytes_1.arrayify(mnemonicAesCtr.decrypt(mnemonicCiphertext));
mnemonic = hdnode_1.entropyToMnemonic(entropy);
node = hdnode_1.HDNode.fromMnemonic(mnemonic).derivePath(path);
if (node.privateKey != account.privateKey) {
throw new Error("mnemonic mismatch");
}
account.mnemonic = node.mnemonic;
account.path = node.path;
}
return [2 /*return*/, new KeystoreAccount(account)];
});
});
address: address,
privateKey: hexlify(privateKey)
};
// Version 0.1 x-ethers metadata must contain an encrypted mnemonic phrase
if (searchPath(data, "x-ethers/version") === "0.1") {
const mnemonicCiphertext = looseArrayify(searchPath(data, "x-ethers/mnemonicCiphertext"));
const mnemonicIv = looseArrayify(searchPath(data, "x-ethers/mnemonicCounter"));
const mnemonicCounter = new aes.Counter(mnemonicIv);
const mnemonicAesCtr = new aes.ModeOfOperation.ctr(mnemonicKey, mnemonicCounter);
const path = searchPath(data, "x-ethers/path") || defaultPath;
const entropy = arrayify(mnemonicAesCtr.decrypt(mnemonicCiphertext));
const mnemonic = entropyToMnemonic(entropy);
const node = HDNode.fromMnemonic(mnemonic).derivePath(path);
if (node.privateKey != account.privateKey) {
throw new Error("mnemonic mismatch");
}
account.mnemonic = node.mnemonic;
account.path = node.path;
}
return new KeystoreAccount(account);
}
}
}
const account = {
_isKeystoreAccount: true,
address: address,
privateKey: hexlify(privateKey)
};
// Version 0.1 x-ethers metadata must contain an encrypted mnemonic phrase
if (searchPath(data, "x-ethers/version") === "0.1") {
const mnemonicCiphertext = looseArrayify(searchPath(data, "x-ethers/mnemonicCiphertext"));
const mnemonicIv = looseArrayify(searchPath(data, "x-ethers/mnemonicCounter"));
const mnemonicCounter = new aes.Counter(mnemonicIv);
const mnemonicAesCtr = new aes.ModeOfOperation.ctr(mnemonicKey, mnemonicCounter);
const path = searchPath(data, "x-ethers/path") || defaultPath;
const entropy = arrayify(mnemonicAesCtr.decrypt(mnemonicCiphertext));
const mnemonic = entropyToMnemonic(entropy);
const node = HDNode.fromMnemonic(mnemonic).derivePath(path);
if (node.privateKey != account.privateKey) {
throw new Error("mnemonic mismatch");
}
account.mnemonic = node.mnemonic;
account.path = node.path;
}
return new KeystoreAccount(account);
});
};
return new ThreeId(provider, ipfs, opts)
} else {
const normalizedAddress = address.toLowerCase()
let serialized3id = localstorage.get(STORAGE_KEY + normalizedAddress)
if (serialized3id) {
if (opts.consentCallback) opts.consentCallback(false)
} else {
let sig
if (opts.contentSignature) {
sig = opts.contentSignature
} else {
sig = await utils.openBoxConsent(normalizedAddress, provider)
}
if (opts.consentCallback) opts.consentCallback(true)
const entropy = '0x' + utils.sha256(sig.slice(2))
const mnemonic = entropyToMnemonic(entropy)
const seed = mnemonicToSeed(mnemonic)
serialized3id = JSON.stringify({
managementAddress: normalizedAddress,
seed,
spaceSeeds: {}
})
}
const threeId = new ThreeId(provider, ipfs, opts)
threeId._initKeys(serialized3id)
await threeId._initDID()
return threeId
}
}
}
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) {
Wallet.createRandom = function (options) {
var entropy = random_1.randomBytes(16);
if (!options) {
options = {};
}
if (options.extraEntropy) {
entropy = bytes_1.arrayify(bytes_1.hexDataSlice(keccak256_1.keccak256(bytes_1.concat([entropy, options.extraEntropy])), 0, 16));
}
var mnemonic = hdnode_1.entropyToMnemonic(entropy, options.locale);
return Wallet.fromMnemonic(mnemonic, options.path, options.locale);
};
Wallet.fromEncryptedJson = function (json, password, progressCallback) {