Skip to content

fix: compare auth response with trader instance address #5

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

Merged
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
12 changes: 6 additions & 6 deletions src/entities/cli-trader/base-trader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
} from 'viem';
import type { ERC20Contract } from '../contracts/erc20';
import type { SimulatedTxRequest } from '../../types';
import { handleGRPCRequest, authClient, createSIWEMessage } from '../../utils';
import { handleGRPCRequest, authClient, createSIWEMessage, fromH160ToAddress } from '../../utils';
import type { CLEAR_ADDRESS, SEAPORT_ADDRESS } from '../../constants';
import type { ClearinghouseContract } from '../contracts/clearinghouse';

Expand All @@ -31,12 +31,10 @@ export class Trader {
public chain: Chain;
public authenticated = false;
public publicClient: PublicClient<Transport, Chain>;
public walletClient: WalletClient; //<Transport, Chain, PrivateKeyAccount>;
public walletClient: WalletClient;

/** cached results */
// { [ERC20_ADDRESS]: BALANCE}
private erc20Balances = new Map<Address, bigint>();
// { [ERC20_ADDRESS]: { [CLEAR_ADDRESS]: APPROVED_AMOUNT, [SEAPORT_ADDRESS]: APPROVED_AMOUNT } }
private erc20Allowances = new Map<
Address,
{
Expand Down Expand Up @@ -96,7 +94,8 @@ export class Trader {
const res = await handleGRPCRequest(async () =>
authClient.authenticate({}),
);
this.authenticated = res !== null;
if (res) this.authenticated = fromH160ToAddress(res).toLowerCase() === this.account.address.toLowerCase()
return this.authenticated;
}

public async verifyWithSIWE(message: string, signature: `0x${string}`) {
Expand All @@ -108,7 +107,8 @@ export class Trader {
}),
}),
);
return { verified: res !== null };
if (res) return {verified: fromH160ToAddress(res).toLowerCase() === this.account.address.toLowerCase()}
return { verified: null };
}

public async createAndSignMessage(nonce: string) {
Expand Down