2019-05-15 01:48:48 +03:00
|
|
|
"use strict";
|
2019-08-25 09:39:20 +03:00
|
|
|
import { getAddress } from "@ethersproject/address";
|
|
|
|
export function isCrowdsaleWallet(json) {
|
|
|
|
let data = null;
|
2019-05-15 01:48:48 +03:00
|
|
|
try {
|
|
|
|
data = JSON.parse(json);
|
|
|
|
}
|
|
|
|
catch (error) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return (data.encseed && data.ethaddr);
|
|
|
|
}
|
2019-08-25 09:39:20 +03:00
|
|
|
export function isKeystoreWallet(json) {
|
|
|
|
let data = null;
|
2019-05-15 01:48:48 +03: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 09:39:20 +03:00
|
|
|
export function getJsonWalletAddress(json) {
|
2019-05-15 01:48:48 +03:00
|
|
|
if (isCrowdsaleWallet(json)) {
|
|
|
|
try {
|
2019-08-25 09:39:20 +03:00
|
|
|
return getAddress(JSON.parse(json).ethaddr);
|
2019-05-15 01:48:48 +03:00
|
|
|
}
|
|
|
|
catch (error) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (isKeystoreWallet(json)) {
|
|
|
|
try {
|
2019-08-25 09:39:20 +03:00
|
|
|
return getAddress(JSON.parse(json).address);
|
2019-05-15 01:48:48 +03:00
|
|
|
}
|
|
|
|
catch (error) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|