verify_ecdsa_message.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import * as anchor from "@coral-xyz/anchor";
  2. import { Program } from "@coral-xyz/anchor";
  3. import { PythLazerSolanaContract } from "../target/types/pyth_lazer_solana_contract";
  4. import * as pythLazerSolanaContractIdl from "../target/idl/pyth_lazer_solana_contract.json";
  5. import yargs from "yargs/yargs";
  6. import { readFileSync } from "fs";
  7. import NodeWallet from "@coral-xyz/anchor/dist/cjs/nodewallet";
  8. async function main() {
  9. let argv = await yargs(process.argv.slice(2))
  10. .options({
  11. url: { type: "string", demandOption: true },
  12. "keypair-path": { type: "string", demandOption: true },
  13. message: { type: "string", demandOption: true },
  14. })
  15. .parse();
  16. const keypair = anchor.web3.Keypair.fromSecretKey(
  17. new Uint8Array(JSON.parse(readFileSync(argv.keypairPath, "ascii"))),
  18. );
  19. const wallet = new NodeWallet(keypair);
  20. const connection = new anchor.web3.Connection(argv.url, {
  21. commitment: "confirmed",
  22. });
  23. const provider = new anchor.AnchorProvider(connection, wallet);
  24. const program: Program<PythLazerSolanaContract> = new Program(
  25. pythLazerSolanaContractIdl as PythLazerSolanaContract,
  26. provider,
  27. );
  28. await program.methods
  29. .verifyEcdsaMessage(Buffer.from(argv.message, "hex"))
  30. .accounts({
  31. payer: wallet.publicKey,
  32. })
  33. .rpc();
  34. console.log("message is valid");
  35. }
  36. main();