Skip to content

Commit

Permalink
add more context on error; update readme and fix CI
Browse files Browse the repository at this point in the history
  • Loading branch information
pscott committed Nov 6, 2024
1 parent db20b7d commit 09cae94
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ jobs:
cache: "yarn"
- run: yarn --frozen-lockfile
- run: yarn lint
- run: yarn verify 0x62abf12fcadc73d129acf8f762a806654936daca722c2ec546dcdcb2ec9c91b
- run: yarn verify 0x62abf12fcadc73d129acf8f762a806654936daca722c2ec546dcdcb2ec9c91b -n sepolia
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ yarn

<img width="654" alt="Screenshot 2024-11-05 at 14 38 22" src="https://github.com/user-attachments/assets/c867fd97-65ba-4ec5-a07a-cc61aaed5b73">


5. Verify it

```sh
Expand All @@ -40,19 +39,19 @@ yarn verify <hash>

<img width="1217" alt="Screenshot 2024-11-05 at 14 40 30" src="https://github.com/user-attachments/assets/32abc44e-c51f-443e-9e55-e7606f605099">


## 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.
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.
26 changes: 16 additions & 10 deletions src/verify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 09cae94

Please sign in to comment.