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

fix: use correct urls for networks #6

Merged
merged 2 commits into from
Nov 6, 2024
Merged
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
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.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
54 changes: 34 additions & 20 deletions src/verify.ts
Original file line number Diff line number Diff line change
@@ -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<any> {
try {
Expand All @@ -40,7 +38,17 @@ async function fetchData(url: string, hash: string): Promise<any> {
}
}

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.`);
Expand All @@ -52,16 +60,22 @@ export async function verify(expectedHash: string, url: 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
Loading