diff --git a/clients/js/README.md b/clients/js/README.md index 35b414e8bb..9168863580 100644 --- a/clients/js/README.md +++ b/clients/js/README.md @@ -35,7 +35,7 @@ Commands: worm recover Recover an address from a signature worm submit Execute a VAA worm sui Sui utilities - worm verify-vaa Verifies a VAA by querying the core contract on Ethereum + worm verify-vaa Verifies a VAA by querying the core contract on the specified EVM chain Options: --help Show help [boolean] @@ -340,10 +340,23 @@ Options: ```sh Options: - --help Show help [boolean] - --version Show version number [boolean] - -v, --vaa vaa in hex format [string] [required] - -n, --network Network [required] [choices: "mainnet", "testnet", "devnet"] + --help Show help [boolean] + --version Show version number [boolean] + -v, --vaa vaa in hex format [string] [required] + -n, --network Network + [required] [choices: "mainnet", "testnet", "devnet"] + -c, --chain chain name + [required] [choices: "unset", "solana", "ethereum", "terra", "bsc", "polygon", + "avalanche", "oasis", "algorand", "aurora", "fantom", "karura", "acala", + "klaytn", "celo", "near", "moonbeam", "neon", "terra2", "injective", + "osmosis", "sui", "aptos", "arbitrum", "optimism", "gnosis", "pythnet", + "xpla", "btc", "base", "sei", "rootstock", "scroll", "mantle", "blast", + "xlayer", "linea", "berachain", "seievm", "wormchain", "cosmoshub", "evmos", + "kujira", "neutron", "celestia", "stargaze", "seda", "dymension", + "provenance", "sepolia", "arbitrum_sepolia", "base_sepolia", + "optimism_sepolia", "holesky", "polygon_sepolia"] + -a, --contract-address Contract to verify VAA on (override config) [string] + --rpc RPC endpoint [string] ``` diff --git a/clients/js/src/cmds/verifyVaa.ts b/clients/js/src/cmds/verifyVaa.ts index 07700a18e8..55acf0d92d 100644 --- a/clients/js/src/cmds/verifyVaa.ts +++ b/clients/js/src/cmds/verifyVaa.ts @@ -1,14 +1,21 @@ -// The verify-vaa command invokes the parseAndVerifyVM method on the core contract on Ethereum to verify the specified VAA. +// The verify-vaa command invokes the parseAndVerifyVM method on the core contract on the specified EVM chain to verify the specified VAA. import { Implementation__factory } from "@certusone/wormhole-sdk/lib/esm/ethers-contracts"; -import { CONTRACTS } from "@certusone/wormhole-sdk/lib/esm/utils/consts"; +import { + CONTRACTS, + CHAINS, + ChainName, + assertChain, + assertEVMChain, +} from "@certusone/wormhole-sdk/lib/esm/utils/consts"; import { ethers } from "ethers"; import yargs from "yargs"; import { NETWORKS, NETWORK_OPTIONS } from "../consts"; import { assertNetwork } from "../utils"; export const command = "verify-vaa"; -export const desc = "Verifies a VAA by querying the core contract on Ethereum"; +export const desc = + "Verifies a VAA by querying the core contract on the specified EVM chain"; export const builder = (y: typeof yargs) => y .option("vaa", { @@ -17,22 +24,42 @@ export const builder = (y: typeof yargs) => type: "string", demandOption: true, }) - .option("network", NETWORK_OPTIONS); + .option("network", NETWORK_OPTIONS) + .option("chain", { + alias: "c", + describe: "chain name", + choices: Object.keys(CHAINS) as ChainName[], + demandOption: true, + } as const) + .option("contract-address", { + alias: "a", + describe: "Contract to verify VAA on (override config)", + type: "string", + demandOption: false, + }) + .option("rpc", { + describe: "RPC endpoint", + type: "string", + demandOption: false, + }); export const handler = async ( argv: Awaited["argv"]> ) => { - const network = argv.network.toUpperCase(); + const chain = argv.chain; + assertChain(chain); + assertEVMChain(chain); + + const network = (argv.network ?? "mainnet").toUpperCase(); assertNetwork(network); - const buf = Buffer.from(String(argv.vaa), "hex"); - const contract_address = CONTRACTS[network].ethereum.core; + const rpc = argv.rpc ?? NETWORKS[network][chain].rpc; + const contract_address = + argv["contract-address"] ?? CONTRACTS[network][chain].core; if (!contract_address) { - throw Error(`Unknown core contract on ${network} for ethereum`); + throw Error(`Unknown core contract on ${network} for ${chain}`); } - - const provider = new ethers.providers.JsonRpcProvider( - NETWORKS[network].ethereum.rpc - ); + const buf = Buffer.from(String(argv.vaa), "hex"); + const provider = new ethers.providers.JsonRpcProvider(rpc); const contract = Implementation__factory.connect(contract_address, provider); const result = await contract.parseAndVerifyVM(buf); if (result[1]) {