cosmic-interchain-cli
Version:
A command-line utility for Cosmic Wire's interchain messaging protocol
78 lines • 3.17 kB
JavaScript
import { ProtocolType, isValidAddressEvm, normalizeAddressEvm, } from '@hyperlane-xyz/utils';
import { errorRed, log } from '../logger.js';
import { getValidatorAddress } from '../validator/address.js';
import { checkValidatorSetup } from '../validator/preFlightCheck.js';
import { awsAccessKeyCommandOption, awsBucketCommandOption, awsKeyIdCommandOption, awsRegionCommandOption, awsSecretKeyCommandOption, chainCommandOption, demandOption, validatorCommandOption, } from './options.js';
// Parent command to help configure and set up Hyperlane validators
export const validatorCommand = {
command: 'validator',
describe: 'Configure and manage interchain operators',
builder: (yargs) => yargs
.command(addressCommand)
.command(preFlightCheckCommand)
.demandCommand(),
handler: () => log('Command required'),
};
// If AWS access key needed for future validator commands, move to context
const addressCommand = {
command: 'address',
describe: 'Get the operator address from S3 bucket or KMS key ID',
builder: {
'access-key': awsAccessKeyCommandOption,
'secret-key': awsSecretKeyCommandOption,
region: awsRegionCommandOption,
bucket: awsBucketCommandOption,
'key-id': awsKeyIdCommandOption,
},
handler: async ({ context, accessKey, secretKey, region, bucket, keyId }) => {
await getValidatorAddress({
context,
accessKey,
secretKey,
region,
bucket,
keyId,
});
process.exit(0);
},
};
const preFlightCheckCommand = {
command: 'check',
describe: 'Check the operator has announced correctly for a given chain',
builder: {
chain: demandOption(chainCommandOption),
validators: validatorCommandOption,
},
handler: async ({ context, chain, validators }) => {
const { multiProvider } = context;
// validate chain
if (!multiProvider.hasChain(chain)) {
errorRed(`❌ No metadata found for ${chain}. Ensure it is included in your configured registry.`);
process.exit(1);
}
const chainMetadata = multiProvider.getChainMetadata(chain);
if (chainMetadata.protocol !== ProtocolType.Ethereum) {
errorRed(`\n❌ Operator pre flight check only supports EVM chains. Exiting.`);
process.exit(1);
}
// validate validators addresses
const validatorList = validators.split(',');
const invalidAddresses = new Set();
const validAddresses = new Set();
for (const address of validatorList) {
if (isValidAddressEvm(address)) {
validAddresses.add(normalizeAddressEvm(address));
}
else {
invalidAddresses.add(address);
}
}
if (invalidAddresses.size > 0) {
errorRed(`❌ Invalid addresses: ${Array.from(invalidAddresses).join(', ')}`);
process.exit(1);
}
await checkValidatorSetup(context, chain, validAddresses);
process.exit(0);
},
};
//# sourceMappingURL=validator.js.map