@hyperlane-xyz/cli
Version:
A command-line utility for common Hyperlane operations
47 lines • 1.94 kB
JavaScript
import { password } from '@inquirer/prompts';
import { Wallet } from 'ethers';
import { Wallet as ZKSyncWallet } from 'zksync-ethers';
import { ChainTechnicalStack, } from '@hyperlane-xyz/sdk';
import { ProtocolType } from '@hyperlane-xyz/utils';
import { BaseMultiProtocolSigner, } from './BaseMultiProtocolSigner.js';
export class MultiProtocolSignerFactory {
static getSignerStrategy(chain, strategyConfig, multiProvider) {
const { protocol, technicalStack } = multiProvider.getChainMetadata(chain);
switch (protocol) {
case ProtocolType.Ethereum:
if (technicalStack === ChainTechnicalStack.ZkSync)
return new ZKSyncSignerStrategy(strategyConfig);
return new EthereumSignerStrategy(strategyConfig);
default:
throw new Error(`Unsupported protocol: ${protocol}`);
}
}
}
class EthereumSignerStrategy extends BaseMultiProtocolSigner {
async getSignerConfig(chain) {
const submitter = this.config[chain]?.submitter;
const privateKey = submitter?.privateKey ??
(await password({
message: `Please enter the private key for chain ${chain}`,
}));
return { privateKey };
}
getSigner(config) {
return new Wallet(config.privateKey);
}
}
// 99% overlap with EthereumSignerStrategy for the sake of keeping MultiProtocolSignerFactory clean
class ZKSyncSignerStrategy extends BaseMultiProtocolSigner {
async getSignerConfig(chain) {
const submitter = this.config[chain]?.submitter;
const privateKey = submitter?.privateKey ??
(await password({
message: `Please enter the private key for chain ${chain}`,
}));
return { privateKey };
}
getSigner(config) {
return new ZKSyncWallet(config.privateKey);
}
}
//# sourceMappingURL=MultiProtocolSignerFactory.js.map