Skip to content

Commit

Permalink
Cosmetic changes and added changeset
Browse files Browse the repository at this point in the history
  • Loading branch information
aalaoui12 committed May 22, 2024
1 parent a010032 commit 544f572
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 55 deletions.
5 changes: 5 additions & 0 deletions .changeset/neat-ducks-own.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hyperlane-xyz/cli': minor
---

Add hyperlane validator address command to retrieve validator address from AWS
10 changes: 5 additions & 5 deletions typescript/cli/src/commands/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,33 +148,33 @@ export const addressCommandOption = (
});

/* Validator options */
export const awsAccessKeyOption: Options = {
export const awsAccessKeyCommandOption: Options = {
type: 'string',
description: 'AWS access key of IAM user associated with validator',
default: ENV.AWS_ACCESS_KEY_ID,
defaultDescription: 'process.env.AWS_ACCESS_KEY_ID',
};

export const awsSecretKeyOption: Options = {
export const awsSecretKeyCommandOption: Options = {
type: 'string',
description: 'AWS secret access key of IAM user associated with validator',
default: ENV.AWS_SECRET_ACCESS_KEY,
defaultDescription: 'process.env.AWS_SECRET_ACCESS_KEY',
};

export const awsRegionOption: Options = {
export const awsRegionCommandOption: Options = {
type: 'string',
describe: 'AWS region associated with validator',
default: ENV.AWS_REGION,
defaultDescription: 'process.env.AWS_REGION',
};

export const bucketCommandOption: Options = {
export const awsBucketCommandOption: Options = {
type: 'string',
describe: 'AWS S3 bucket containing validator signatures and announcement',
};

export const keyIdCommandOption: Options = {
export const awsKeyIdCommandOption: Options = {
type: 'string',
describe: 'Key ID from AWS KMS',
};
20 changes: 10 additions & 10 deletions typescript/cli/src/commands/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { log } from '../logger.js';
import { getValidatorAddress } from '../validator/address.js';

import {
awsAccessKeyOption,
awsRegionOption,
awsSecretKeyOption,
bucketCommandOption,
keyIdCommandOption,
awsAccessKeyCommandOption,
awsBucketCommandOption,
awsKeyIdCommandOption,
awsRegionCommandOption,
awsSecretKeyCommandOption,
} from './options.js';

// Parent command to help configure and set up Hyperlane validators
Expand All @@ -31,11 +31,11 @@ const addressCommand: CommandModuleWithContext<{
command: 'address',
describe: 'Get the validator address from S3 bucket or KMS key ID',
builder: {
'access-key': awsAccessKeyOption,
'secret-key': awsSecretKeyOption,
region: awsRegionOption,
bucket: bucketCommandOption,
'key-id': keyIdCommandOption,
'access-key': awsAccessKeyCommandOption,
'secret-key': awsSecretKeyCommandOption,
region: awsRegionCommandOption,
bucket: awsBucketCommandOption,
'key-id': awsKeyIdCommandOption,
},
handler: async ({ context, accessKey, secretKey, region, bucket, keyId }) => {
await getValidatorAddress({
Expand Down
28 changes: 0 additions & 28 deletions typescript/cli/src/utils/aws.ts

This file was deleted.

45 changes: 33 additions & 12 deletions typescript/cli/src/validator/address.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { GetPublicKeyCommand, KMSClient } from '@aws-sdk/client-kms';
import { GetObjectCommand, S3Client } from '@aws-sdk/client-s3';
import { input } from '@inquirer/prompts';
// @ts-ignore
import asn1 from 'asn1.js';
import { ethers } from 'ethers';

import { assert } from '@hyperlane-xyz/utils';

import { CommandContext } from '../context/types.js';
import { log, logBlue } from '../logger.js';
import { getAccessKeyId, getRegion, getSecretAccessKey } from '../utils/aws.js';

export async function getValidatorAddress({
context,
Expand All @@ -32,17 +34,9 @@ export async function getValidatorAddress({
secretKey ||= await getSecretAccessKey(context.skipConfirmation);
region ||= await getRegion(context.skipConfirmation);

if (!accessKey) {
throw new Error('No access key ID set.');
}

if (!secretKey) {
throw new Error('No secret access key set.');
}

if (!region) {
throw new Error('No AWS region set.');
}
assert(accessKey, 'No access key ID set.');
assert(secretKey, 'No secret access key set.');
assert(region, 'No AWS region set.');

let validatorAddress;
if (bucket) {
Expand Down Expand Up @@ -143,3 +137,30 @@ function getEthereumAddress(publicKey: Buffer): string {
const address = ethers.utils.keccak256(pubKeyBuffer); // keccak256 hash of publicKey
return `0x${address.slice(-40)}`; // take last 20 bytes as ethereum address
}

async function getAccessKeyId(skipConfirmation: boolean) {
if (skipConfirmation) throw new Error('No AWS access key ID set.');
else
return await input({
message:
'Please enter AWS access key ID or use the AWS_ACCESS_KEY_ID environment variable.',
});
}

async function getSecretAccessKey(skipConfirmation: boolean) {
if (skipConfirmation) throw new Error('No AWS secret access key set.');
else
return await input({
message:
'Please enter AWS secret access key or use the AWS_SECRET_ACCESS_KEY environment variable.',
});
}

async function getRegion(skipConfirmation: boolean) {
if (skipConfirmation) throw new Error('No AWS region set.');
else
return await input({
message:
'Please enter AWS region or use the AWS_REGION environment variable.',
});
}

0 comments on commit 544f572

Please sign in to comment.