diff --git a/src/api.ts b/src/api.ts index fb11d2d9..71ca04bb 100644 --- a/src/api.ts +++ b/src/api.ts @@ -1332,7 +1332,6 @@ export default class API extends EventEmitter { delete zktx.signature const result = await verifyMessage ({ - provider: this.ETHERS_PROVIDERS[chainId] as ethers.providers.Provider, signer: zktx.user, typedData: { domain: networkProviderConfig.domain, @@ -1480,7 +1479,6 @@ export default class API extends EventEmitter { if (signerAddress !== userId) throw new Error('Unauthorized') } else { const res = await verifyMessage({ - provider: this.ETHERS_PROVIDERS[chainId] as ethers.providers.Provider, signer: userId as string, message: `cancelall2:${chainId}:${validUntil}`, signature @@ -1599,8 +1597,7 @@ export default class API extends EventEmitter { signerAddress = res.result.accountId.toString() if (signerAddress !== select.rows[0].userid) throw new Error('Unauthorized') } else { - const res = await verifyMessage({ - provider: this.ETHERS_PROVIDERS[chainId] as ethers.providers.Provider, + const res = await verifyMessage({verifyMessage signer: select.rows[0].userid as string, message: `cancelorder2:${chainId}:${orderId}`, signature diff --git a/src/cryptography.ts b/src/cryptography.ts index 50f03f52..367459f7 100644 --- a/src/cryptography.ts +++ b/src/cryptography.ts @@ -1,10 +1,8 @@ import { ethers } from 'ethers' import type { AnyObject } from './types' -import { redis, publisher } from './redisClient' +import { redis } from './redisClient' -const VALIDATOR_1271_ABI = [ - 'function isValidSignature(bytes32 hash, bytes signature) view returns (bytes4)' -] +const VALIDATOR_1271_ABI = ['function isValidSignature(bytes32 hash, bytes signature) view returns (bytes4)'] export function getEvmEIP712Types(chainId: number) { if ([42161, 421613].includes(chainId)) { @@ -46,6 +44,7 @@ function addrMatching(recoveredAddr: string, targetAddr: string) { return recoveredAddr.toLowerCase() === targetAddr.toLowerCase() } +/* // EIP 1271 check async function eip1271Check( provider: ethers.providers.Provider, @@ -70,16 +69,16 @@ async function eip1271Check( } return false } +*/ // you only need to pass one of: typedData or message export async function verifyMessage(param: { - provider: ethers.providers.Provider signer: string message?: string typedData?: AnyObject signature: string }): Promise { - const { message, typedData, provider, signer } = param + const { message, typedData, signer } = param const signature = modifyOldSignature(param.signature) let finalDigest: string @@ -108,9 +107,9 @@ export async function verifyMessage(param: { // 2nd try: Check registered vault address // Requires manual whitelist - const vaultSigner = await redis.get(`vaultsigner:${signer.toLowerCase()}`); + const vaultSigner = await redis.get(`vaultsigner:${signer.toLowerCase()}`) if (vaultSigner && addrMatching(recoveredAddress, vaultSigner)) return true - console.log(`Expected ${signer}, recovered ${recoveredAddress}`); + console.log(`Expected ${signer}, recovered ${recoveredAddress}`) return false }