2019-05-15 01:25:46 +03:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
import { Bytes } from "@ethersproject/bytes";
|
|
|
|
import { ExternallyOwnedAccount } from "@ethersproject/abstract-signer";
|
|
|
|
|
|
|
|
import { decrypt as decryptCrowdsale } from "./crowdsale";
|
|
|
|
import { getJsonWalletAddress, isCrowdsaleWallet, isKeystoreWallet } from "./inspect";
|
2020-02-27 21:42:59 +03:00
|
|
|
import { decrypt as decryptKeystore, decryptSync as decryptKeystoreSync, encrypt as encryptKeystore, EncryptOptions, ProgressCallback } from "./keystore";
|
2019-05-15 01:25:46 +03:00
|
|
|
|
|
|
|
function decryptJsonWallet(json: string, password: Bytes | string, progressCallback?: ProgressCallback): Promise<ExternallyOwnedAccount> {
|
|
|
|
if (isCrowdsaleWallet(json)) {
|
|
|
|
if (progressCallback) { progressCallback(0); }
|
2019-11-01 17:33:51 +03:00
|
|
|
const account = decryptCrowdsale(json, password)
|
2019-05-15 01:25:46 +03:00
|
|
|
if (progressCallback) { progressCallback(1); }
|
|
|
|
return Promise.resolve(account);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isKeystoreWallet(json)) {
|
|
|
|
return decryptKeystore(json, password, progressCallback);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Promise.reject(new Error("invalid JSON wallet"));
|
|
|
|
}
|
|
|
|
|
2020-02-27 21:42:59 +03:00
|
|
|
function decryptJsonWalletSync(json: string, password: Bytes | string): ExternallyOwnedAccount {
|
|
|
|
if (isCrowdsaleWallet(json)) {
|
|
|
|
return decryptCrowdsale(json, password)
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isKeystoreWallet(json)) {
|
|
|
|
return decryptKeystoreSync(json, password);
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new Error("invalid JSON wallet");
|
|
|
|
}
|
|
|
|
|
2019-05-15 01:25:46 +03:00
|
|
|
export {
|
|
|
|
decryptCrowdsale,
|
|
|
|
|
|
|
|
decryptKeystore,
|
2020-02-27 21:42:59 +03:00
|
|
|
decryptKeystoreSync,
|
2019-05-15 01:25:46 +03:00
|
|
|
encryptKeystore,
|
|
|
|
|
|
|
|
isCrowdsaleWallet,
|
|
|
|
isKeystoreWallet,
|
|
|
|
getJsonWalletAddress,
|
|
|
|
|
|
|
|
decryptJsonWallet,
|
2020-02-27 21:42:59 +03:00
|
|
|
decryptJsonWalletSync,
|
2019-05-15 01:25:46 +03:00
|
|
|
|
|
|
|
ProgressCallback,
|
|
|
|
EncryptOptions,
|
|
|
|
};
|