chaingate
Version:
A complete TypeScript library for connecting to and making transactions on different blockchains
43 lines • 1.52 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Web3Keystore = void 0;
const ethers_1 = require("ethers");
const errors_1 = require("./errors");
const Utils_1 = require("../../../InternalUtils/Utils");
const Keystore_1 = require("./Keystore");
class Web3Keystore extends Keystore_1.Keystore {
keystoreData;
constructor(keystoreData) {
super();
this.keystoreData = keystoreData;
}
async checkPassword(password) {
try {
await ethers_1.ethers.Wallet.fromEncryptedJson(JSON.stringify(this.keystoreData), password);
return true;
}
catch (ex) {
if (ex instanceof TypeError && 'argument' in ex && ex.argument === 'password') {
return false;
}
throw new Error('Invalid keystore');
}
}
async decrypt(password) {
try {
const ethersWallet = await ethers_1.ethers.Wallet.fromEncryptedJson(JSON.stringify(this.keystoreData), password);
return (0, Utils_1.hexToBytes)(ethersWallet.privateKey);
}
catch (ex) {
if (ex instanceof TypeError && 'argument' in ex && ex.argument === 'password') {
throw new errors_1.IncorrectPassword();
}
throw new Error('Invalid keystore');
}
}
static isKeystore(obj) {
return 'version' in obj && obj.version == 3;
}
}
exports.Web3Keystore = Web3Keystore;
//# sourceMappingURL=Web3Keystore.js.map