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

49 lines
1.2 KiB
JavaScript
Raw Permalink Normal View History

2019-05-14 18:48:48 -04:00
"use strict";
import { getAddress } from "@ethersproject/address";
export function isCrowdsaleWallet(json) {
let data = null;
2019-05-14 18:48:48 -04:00
try {
data = JSON.parse(json);
}
catch (error) {
return false;
}
return (data.encseed && data.ethaddr);
}
export function isKeystoreWallet(json) {
let data = null;
2019-05-14 18:48:48 -04:00
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;
}
//export function isJsonWallet(json: string): boolean {
// return (isSecretStorageWallet(json) || isCrowdsaleWallet(json));
//}
export function getJsonWalletAddress(json) {
2019-05-14 18:48:48 -04:00
if (isCrowdsaleWallet(json)) {
try {
return getAddress(JSON.parse(json).ethaddr);
2019-05-14 18:48:48 -04:00
}
catch (error) {
return null;
}
}
if (isKeystoreWallet(json)) {
try {
return getAddress(JSON.parse(json).address);
2019-05-14 18:48:48 -04:00
}
catch (error) {
return null;
}
}
return null;
}
2020-07-13 08:03:56 -04:00
//# sourceMappingURL=inspect.js.map