Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clients/js: add chain and rpc support for worm verify-vaa command #3951

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions clients/js/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Commands:
worm recover <digest> <signature> Recover an address from a signature
worm submit <vaa> 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]
Expand Down Expand Up @@ -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]
```
</details>

Expand Down
51 changes: 39 additions & 12 deletions clients/js/src/cmds/verifyVaa.ts
Original file line number Diff line number Diff line change
@@ -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", {
Expand All @@ -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<ReturnType<typeof builder>["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]) {
Expand Down
Loading