Skip to content

Commit

Permalink
refactor: code improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
wa0x6e committed Jul 3, 2024
1 parent e5b8f2d commit 98a4cd8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
10 changes: 5 additions & 5 deletions src/verify/evm.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { verifyTypedData } from '@ethersproject/wallet';
import { arrayify } from '@ethersproject/bytes';
import { StaticJsonRpcProvider } from '@ethersproject/providers';
import { getHash, SignaturePayload } from '.';
import getProvider, { ProviderOptions } from '../utils/provider';
import { call } from '../utils';
import getProvider, { type ProviderOptions } from '../utils/provider';
import utils, { call } from '../utils';
import type { SignaturePayload } from '.';
import type { StaticJsonRpcProvider } from '@ethersproject/providers';

function isSameAddress(a: string, b: string) {
return a.toLowerCase() === b.toLowerCase();
Expand All @@ -24,7 +24,7 @@ export default async function verify(
} catch (e: any) {}

const provider = getProvider(network, options);
const hash = getHash(data);
const hash = utils.getHash(data);

if (await verifyDefault(address, sig, hash, provider)) return true;

Expand Down
15 changes: 9 additions & 6 deletions src/verify/starknet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ import abi from './starknet-account-abi.json';
import type { SignaturePayload } from '.';
import type { ProviderOptions } from '../utils/provider';

const DEFAULT_STARKNET_RPC = 'https://starknet-mainnet.public.blastapi.io';

function getProvider(options: ProviderOptions) {
return new RpcProvider({
nodeUrl: options?.broviderUrl ?? DEFAULT_STARKNET_RPC
});
}

export default async function verify(
address: string,
sig: string[],
Expand All @@ -11,12 +19,7 @@ export default async function verify(
): Promise<boolean> {
const { domain, types, primaryType, message } =
data as Required<SignaturePayload>;
const provider = new RpcProvider({
nodeUrl:
options?.broviderUrl ?? 'https://starknet-mainnet.public.blastapi.io'
});
const contractAccount = new Contract(abi, address, provider);

const contractAccount = new Contract(abi, address, getProvider(options));
const hash = typedData.getMessageHash(
{ types, primaryType, domain, message },
address
Expand Down

0 comments on commit 98a4cd8

Please sign in to comment.