Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
this.ganacheProvider = new ethers.providers.Web3Provider(ganacheProvider);
this.ganacheWallet = new ethers.Wallet(secretKey, this.ganacheProvider);
}
// This will have to support provider.getSigner https://docs.ethers.io/ethers.js/html/api-providers.html#jsonrpcprovider
if (provider) {
this.realProvider = provider;
} else {
this.realProvider = new ethers.providers.JsonRpcProvider(`http://localhost:${realProviderPort}`);
}
if (minerAddress) {
this.minerAddress = minerAddress;
this.realWallet = this.realProvider.getSigner(minerAddress);
} else {
this.realWallet = new ethers.Wallet(privateKey, this.realProvider);
this.minerAddress = this.realWallet.address;
// TODO: Check that this wallet can stake?
this.minerAddress = this.realWallet.address;
console.log("Transactions will be signed from ", this.realWallet.address);
}
}
async function loadAccount(arg: string, plugin: Plugin, preventFile?: boolean): Promise {
// Secure entry; use prompt with mask
if (arg === "-") {
let content = await getPassword("Private Key / Mnemonic:");
return loadAccount(content, plugin, true);
}
// Raw private key
if (ethers.utils.isHexString(arg, 32)) {
let signer = new ethers.Wallet(arg, plugin.provider)
return Promise.resolve(new WrappedSigner(signer.getAddress(), () => Promise.resolve(signer), plugin));
}
// Mnemonic
if (ethers.utils.isValidMnemonic(arg)) {
let signerPromise: Promise = null;
if (plugin.mnemonicPassword) {
signerPromise = getPassword("Password (mnemonic): ").then((password) => {
let node = ethers.utils.HDNode.fromMnemonic(arg, password).derivePath(ethers.utils.defaultPath);
return new ethers.Wallet(node.privateKey, plugin.provider);
});
} else {
signerPromise = Promise.resolve(ethers.Wallet.fromMnemonic(arg).connect(plugin.provider));
}
return Promise.resolve(new WrappedSigner(
return __awaiter(this, void 0, void 0, function* () {
// Secure entry; use prompt with mask
if (arg === "-") {
let content = yield getPassword("Private Key / Mnemonic:");
return loadAccount(content, plugin, true);
}
// Raw private key
if (ethers.utils.isHexString(arg, 32)) {
let signer = new ethers.Wallet(arg, plugin.provider);
return Promise.resolve(new WrappedSigner(signer.getAddress(), () => Promise.resolve(signer), plugin));
}
// Mnemonic
if (ethers.utils.isValidMnemonic(arg)) {
const mnemonic = arg;
let signerPromise = null;
if (plugin.mnemonicPassword) {
signerPromise = getPassword("Password (mnemonic): ").then((password) => {
let node = ethers.utils.HDNode.fromMnemonic(mnemonic, password).derivePath(ethers.utils.defaultPath);
return new ethers.Wallet(node.privateKey, plugin.provider);
});
}
else if (plugin._xxxMnemonicPasswordHard) {
signerPromise = getPassword("Password (mnemonic; experimental - hard): ").then((password) => {
let passwordBytes = ethers.utils.toUtf8Bytes(password, ethers.utils.UnicodeNormalizationForm.NFKC);
let saltBytes = ethers.utils.arrayify(ethers.utils.HDNode.fromMnemonic(mnemonic).privateKey);
export async function fundAddress(to: string, ether = 1000) {
const gethMode = !!process.env.GETH_MODE || false
const provider = createProvider()
let signer: ethers.Signer
if (gethMode) {
signer = provider.getSigner(GETH_DEV_ADDRESS)
} else {
signer = new ethers.Wallet(DEVNET_PRIVATE_KEY).connect(provider)
}
const tx = await signer.sendTransaction({
to,
value: ethers.utils.parseEther(ether.toString()),
})
await tx.wait()
}
signerPromise = getPassword("Password (mnemonic): ").then((password) => {
let node = ethers.utils.HDNode.fromMnemonic(arg, password).derivePath(ethers.utils.defaultPath);
return new ethers.Wallet(node.privateKey, plugin.provider);
});
} else {
export const signTypedLocal = async ({ privateKey, authType, address, addrIdx, typedData, hash }) => {
const wallet = new ethers.Wallet(privateKey)
const hashBytes = ethers.utils.arrayify(hash)
const sig = await wallet.signMessage(hashBytes)
const signature = { sig: sig, hash, mode: SIGN_TYPES.EthPersonal.id }
return signature
}
static async createOfflineUserAsync(params: GatewayUserParams): Promise {
const provider = new ethers.providers.JsonRpcProvider(params.ethEndpoint)
const wallet = new ethers.Wallet(params.ethereumPrivateKey!, provider)
return DPOSUserV3.createUserAsync({
wallet,
...params
})
}
const createFromPrivateKey = privKey => {
try {
const wallet = new ethers.Wallet(privKey);
return wallet;
} catch (error) {
throw new Error(`Error creating wallet: ${error.message}`);
}
};