From 539609b6b237b753e614fd517667e00dc15e6aab Mon Sep 17 00:00:00 2001 From: Ryan Hamphrey Date: Fri, 24 May 2024 10:23:41 +0000 Subject: [PATCH 1/4] clients/js: chain, rpc, contract-address added to verify-vaa command --- clients/js/src/cmds/verifyVaa.ts | 48 ++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 12 deletions(-) diff --git a/clients/js/src/cmds/verifyVaa.ts b/clients/js/src/cmds/verifyVaa.ts index 07700a18e8..ed86a29e7a 100644 --- a/clients/js/src/cmds/verifyVaa.ts +++ b/clients/js/src/cmds/verifyVaa.ts @@ -1,14 +1,19 @@ -// 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, + 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 +22,41 @@ 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]) { From 3cc9accd9354d1c02ba6f3262d1f194bf781a10a Mon Sep 17 00:00:00 2001 From: Ryan Hamphrey Date: Fri, 24 May 2024 10:24:57 +0000 Subject: [PATCH 2/4] clients/js: updated README.md --- clients/js/README.md | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/clients/js/README.md b/clients/js/README.md index 35b414e8bb..78783666a5 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,22 @@ 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", "kla + ytn", "celo", "near", "moonbeam", "neon", "terra2", "injective", "osmosis", "s + ui", "aptos", "arbitrum", "optimism", "gnosis", "pythnet", "xpla", "btc", "bas + e", "sei", "rootstock", "scroll", "mantle", "blast", "xlayer", "linea", "berac + hain", "seievm", "wormchain", "cosmoshub", "evmos", "kujira", "neutron", "cele + stia", "stargaze", "seda", "dymension", "provenance", "sepolia", "arbitrum_sep + olia", "base_sepolia", "optimism_sepolia", "holesky", "polygon_sepolia"] + -a, --contract-address Contract to verify VAA on (override config) [string] + --rpc RPC endpoint [string] ``` From e28c8782321428fb65aad5f9518f6a7d7190bb81 Mon Sep 17 00:00:00 2001 From: Ryan Hamphrey Date: Thu, 6 Jun 2024 11:54:37 +0000 Subject: [PATCH 3/4] fixed verifyVaa --- clients/js/src/cmds/verifyVaa.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/clients/js/src/cmds/verifyVaa.ts b/clients/js/src/cmds/verifyVaa.ts index ed86a29e7a..55acf0d92d 100644 --- a/clients/js/src/cmds/verifyVaa.ts +++ b/clients/js/src/cmds/verifyVaa.ts @@ -1,11 +1,12 @@ // 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 { +import { CONTRACTS, CHAINS, + ChainName, assertChain, - assertEVMChain + assertEVMChain, } from "@certusone/wormhole-sdk/lib/esm/utils/consts"; import { ethers } from "ethers"; import yargs from "yargs"; @@ -13,7 +14,8 @@ 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 the specified EVM chain"; +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", { @@ -39,7 +41,7 @@ export const builder = (y: typeof yargs) => describe: "RPC endpoint", type: "string", demandOption: false, - }) + }); export const handler = async ( argv: Awaited["argv"]> ) => { @@ -51,7 +53,8 @@ export const handler = async ( assertNetwork(network); const rpc = argv.rpc ?? NETWORKS[network][chain].rpc; - const contract_address = argv["contract-address"] ?? CONTRACTS[network][chain].core; + const contract_address = + argv["contract-address"] ?? CONTRACTS[network][chain].core; if (!contract_address) { throw Error(`Unknown core contract on ${network} for ${chain}`); } From d3ccf4260ed534fe276ce19d2883fae43b8bc6b5 Mon Sep 17 00:00:00 2001 From: Ryan Hamphrey Date: Thu, 6 Jun 2024 11:55:38 +0000 Subject: [PATCH 4/4] fixed README.md --- clients/js/README.md | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/clients/js/README.md b/clients/js/README.md index 78783666a5..9168863580 100644 --- a/clients/js/README.md +++ b/clients/js/README.md @@ -347,13 +347,14 @@ Options: [required] [choices: "mainnet", "testnet", "devnet"] -c, --chain chain name [required] [choices: "unset", "solana", "ethereum", "terra", "bsc", "polygon", - "avalanche", "oasis", "algorand", "aurora", "fantom", "karura", "acala", "kla - ytn", "celo", "near", "moonbeam", "neon", "terra2", "injective", "osmosis", "s - ui", "aptos", "arbitrum", "optimism", "gnosis", "pythnet", "xpla", "btc", "bas - e", "sei", "rootstock", "scroll", "mantle", "blast", "xlayer", "linea", "berac - hain", "seievm", "wormchain", "cosmoshub", "evmos", "kujira", "neutron", "cele - stia", "stargaze", "seda", "dymension", "provenance", "sepolia", "arbitrum_sep - olia", "base_sepolia", "optimism_sepolia", "holesky", "polygon_sepolia"] + "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] ```