ethers.js/packages/json-wallets/lib/inspect.js

54 lines
1.5 KiB
JavaScript
Raw Permalink Normal View History

2019-05-14 18:48:48 -04:00
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
2021-03-07 18:24:04 -05:00
exports.getJsonWalletAddress = exports.isKeystoreWallet = exports.isCrowdsaleWallet = void 0;
2019-05-14 18:48:48 -04:00
var address_1 = require("@ethersproject/address");
function isCrowdsaleWallet(json) {
var data = null;
try {
data = JSON.parse(json);
}
catch (error) {
return false;
}
return (data.encseed && data.ethaddr);
}
exports.isCrowdsaleWallet = isCrowdsaleWallet;
function isKeystoreWallet(json) {
var data = null;
try {
data = JSON.parse(json);
}
catch (error) {
return false;
}
if (!data.version || parseInt(data.version) !== data.version || parseInt(data.version) !== 3) {
return false;
}
// @TODO: Put more checks to make sure it has kdf, iv and all that good stuff
return true;
}
exports.isKeystoreWallet = isKeystoreWallet;
//export function isJsonWallet(json: string): boolean {
// return (isSecretStorageWallet(json) || isCrowdsaleWallet(json));
//}
function getJsonWalletAddress(json) {
if (isCrowdsaleWallet(json)) {
try {
2021-10-16 02:29:27 -04:00
return (0, address_1.getAddress)(JSON.parse(json).ethaddr);
2019-05-14 18:48:48 -04:00
}
catch (error) {
return null;
}
}
if (isKeystoreWallet(json)) {
try {
2021-10-16 02:29:27 -04:00
return (0, address_1.getAddress)(JSON.parse(json).address);
2019-05-14 18:48:48 -04:00
}
catch (error) {
return null;
}
}
return null;
}
exports.getJsonWalletAddress = getJsonWalletAddress;
2020-07-13 08:03:56 -04:00
//# sourceMappingURL=inspect.js.map