From db20b7d80d5c2ae8080116bc32cdbcb8c89b5c7d Mon Sep 17 00:00:00 2001 From: Scott Piriou <30843220+pscott@users.noreply.github.com> Date: Wed, 6 Nov 2024 15:53:51 +0100 Subject: [PATCH 1/2] fix: use correct urls for networks --- src/index.ts | 2 +- src/verify.ts | 28 ++++++++++++++++++---------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/index.ts b/src/index.ts index cff6964..f41ae2e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -48,7 +48,7 @@ const commandHandler = (argv: Arguments) => { `Verifying hash: \`${hash}\` with network \`${argv.network}\` and mana URL \`${manaUrl}\`` ); - verify(hash as string, manaUrl); + verify(hash as string, manaUrl, argv.network as string); }; // Converts decimal representation to hex representation, if necessary diff --git a/src/verify.ts b/src/verify.ts index 91dac0d..b1139cb 100644 --- a/src/verify.ts +++ b/src/verify.ts @@ -1,19 +1,17 @@ -import { clients, starknetSepolia } from '@snapshot-labs/sx'; +import { clients, starknetMainnet, starknetSepolia } from '@snapshot-labs/sx'; import axios from 'axios'; import { RpcProvider } from 'starknet'; const { EthereumTx } = clients; -// These values doesn't matter for this script, but it's required to instantiate the EthereumTx client -const starkProvider = new RpcProvider({ - nodeUrl: 'http://127.0.0.1:5050/rpc' +const starkProviderMainnet = new RpcProvider({ + nodeUrl: 'https://starknet-mainnet.infura.io/v3/e881110087914af69a1ca2c49aa56d14' }); -const ethUrl = 'http://127.0.0.1:8545'; +const ethUrlMainnet = 'https://mainnet.infura.io/v3/e881110087914af69a1ca2c49aa56d14'; -const ethTxClient = new EthereumTx({ - starkProvider: starkProvider as any, - ethUrl, - networkConfig: starknetSepolia +const starknetProviderSepolia = new RpcProvider({ + nodeUrl: 'https://starknet-sepolia.infura.io/v3/e881110087914af69a1ca2c49aa56d14' }); +const ethUrlSepolia = 'https://sepolia.infura.io/v3/e881110087914af69a1ca2c49aa56d14'; async function fetchData(url: string, hash: string): Promise { try { @@ -40,7 +38,17 @@ async function fetchData(url: string, hash: string): Promise { } } -export async function verify(expectedHash: string, url: string) { +export async function verify(expectedHash: string, url: string, network: string) { + const networkConfig = network === 'mainnet' ? starknetMainnet : starknetSepolia; + const ethurl = network === 'mainnet' ? ethUrlMainnet : ethUrlSepolia; + const starkProvider = network === 'mainnet' ? starkProviderMainnet : starknetProviderSepolia; + + const ethTxClient = new EthereumTx({ + starkProvider: starkProvider, + ethUrl: ethurl, + networkConfig: networkConfig + }); + const json = await fetchData(url, expectedHash); if (json == null) { console.error(`\nNo data found for hash \`${expectedHash}\`\n.`); From 09cae94533b9797a72fd0e30140e98f3d8aa46c5 Mon Sep 17 00:00:00 2001 From: Scott Piriou <30843220+pscott@users.noreply.github.com> Date: Wed, 6 Nov 2024 15:57:52 +0100 Subject: [PATCH 2/2] add more context on error; update readme and fix CI --- .github/workflows/lint.yml | 2 +- README.md | 7 +++---- src/verify.ts | 26 ++++++++++++++++---------- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 49ff8fe..2c98c9d 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -15,4 +15,4 @@ jobs: cache: "yarn" - run: yarn --frozen-lockfile - run: yarn lint - - run: yarn verify 0x62abf12fcadc73d129acf8f762a806654936daca722c2ec546dcdcb2ec9c91b \ No newline at end of file + - run: yarn verify 0x62abf12fcadc73d129acf8f762a806654936daca722c2ec546dcdcb2ec9c91b -n sepolia \ No newline at end of file diff --git a/README.md b/README.md index ebaad6a..19cba3d 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,6 @@ yarn Screenshot 2024-11-05 at 14 38 22 - 5. Verify it ```sh @@ -40,19 +39,19 @@ yarn verify Screenshot 2024-11-05 at 14 40 30 - ## Example For testing purposes, we have a transaction that we have never broadcast, this way you can try it yourself. ```sh -yarn verify 0x62abf12fcadc73d129acf8f762a806654936daca722c2ec546dcdcb2ec9c91b +yarn verify 0x62abf12fcadc73d129acf8f762a806654936daca722c2ec546dcdcb2ec9c91b --network sepolia ``` ## What's going on under the hood? What this simple script does is fairly simple: + 1. First we use the code in `./src/index.ts` to parse the command and transform the hash to its hexadecimal format. 2. In `./src/verify.ts` we then query `https://mana.box` to get the information related to the hash that was given as input. 3. Next we display the information on your screen. -4. Finally, we hash all this information and checks that it corresponds to the hash given as input. If it does, we display a little check mark. \ No newline at end of file +4. Finally, we hash all this information and checks that it corresponds to the hash given as input. If it does, we display a little check mark. diff --git a/src/verify.ts b/src/verify.ts index b1139cb..15fe7d3 100644 --- a/src/verify.ts +++ b/src/verify.ts @@ -60,16 +60,22 @@ export async function verify(expectedHash: string, url: string, network: string) console.log(`Type: \`${json.type}\``); console.log(`Sender: \`${json.sender}\``); console.dir(json.data, { depth: null }); - if (type === 'vote') { - console.log('Authenticating vote...'); - console.log('Sender: ', json.sender); - computedHash = await ethTxClient.getVoteHash(json.sender, json.data); - } else if (type === 'propose') { - computedHash = await ethTxClient.getProposeHash(json.sender, json.data); - } else if (type === 'updateproposal') { - computedHash = await ethTxClient.getUpdateProposalHash(json.sender, json.data); - } else { - console.error('Invalid type specified. Use "vote", "proposal", or "updateProposal".'); + try { + if (type === 'vote') { + console.log('Authenticating vote...'); + console.log('Sender: ', json.sender); + computedHash = await ethTxClient.getVoteHash(json.sender, json.data); + } else if (type === 'propose') { + computedHash = await ethTxClient.getProposeHash(json.sender, json.data); + } else if (type === 'updateproposal') { + computedHash = await ethTxClient.getUpdateProposalHash(json.sender, json.data); + } else { + console.error('Invalid type specified. Use "vote", "proposal", or "updateProposal".'); + process.exit(1); + } + } catch (error) { + console.log(error); + console.error('\n❌ Error verifying hash. Are you sure you are using the correct network?\n'); process.exit(1); }