Skip to content

Commit 56c22ba

Browse files
authored
Merge pull request #5 from h0tw4t3r/fix/compare-traders-address-to-auth-response
fix: compare auth response with trader instance address
2 parents 3eda6c4 + 59b00f3 commit 56c22ba

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/entities/cli-trader/base-trader.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
} from 'viem';
1818
import type { ERC20Contract } from '../contracts/erc20';
1919
import type { SimulatedTxRequest } from '../../types';
20-
import { handleGRPCRequest, authClient, createSIWEMessage } from '../../utils';
20+
import { handleGRPCRequest, authClient, createSIWEMessage, fromH160ToAddress } from '../../utils';
2121
import type { CLEAR_ADDRESS, SEAPORT_ADDRESS } from '../../constants';
2222
import type { ClearinghouseContract } from '../contracts/clearinghouse';
2323

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

3636
/** cached results */
37-
// { [ERC20_ADDRESS]: BALANCE}
3837
private erc20Balances = new Map<Address, bigint>();
39-
// { [ERC20_ADDRESS]: { [CLEAR_ADDRESS]: APPROVED_AMOUNT, [SEAPORT_ADDRESS]: APPROVED_AMOUNT } }
4038
private erc20Allowances = new Map<
4139
Address,
4240
{
@@ -96,7 +94,8 @@ export class Trader {
9694
const res = await handleGRPCRequest(async () =>
9795
authClient.authenticate({}),
9896
);
99-
this.authenticated = res !== null;
97+
if (res) this.authenticated = fromH160ToAddress(res).toLowerCase() === this.account.address.toLowerCase()
98+
return this.authenticated;
10099
}
101100

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

114114
public async createAndSignMessage(nonce: string) {

0 commit comments

Comments
 (0)