2019-05-14 18:48:48 -04:00
|
|
|
"use strict";
|
2019-08-25 02:39:20 -04:00
|
|
|
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);
|
|
|
|
}
|
2019-08-25 02:39:20 -04:00
|
|
|
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));
|
|
|
|
//}
|
2019-08-25 02:39:20 -04:00
|
|
|
export function getJsonWalletAddress(json) {
|
2019-05-14 18:48:48 -04:00
|
|
|
if (isCrowdsaleWallet(json)) {
|
|
|
|
try {
|
2019-08-25 02:39:20 -04:00
|
|
|
return getAddress(JSON.parse(json).ethaddr);
|
2019-05-14 18:48:48 -04:00
|
|
|
}
|
|
|
|
catch (error) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (isKeystoreWallet(json)) {
|
|
|
|
try {
|
2019-08-25 02:39:20 -04:00
|
|
|
return getAddress(JSON.parse(json).address);
|
2019-05-14 18:48:48 -04:00
|
|
|
}
|
|
|
|
catch (error) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|