Skip to content

Commit ee47933

Browse files
committed
chore: using viem address comparison
1 parent 8e19e55 commit ee47933

2 files changed

Lines changed: 20 additions & 6 deletions

File tree

packages/delegation-toolkit/src/actions/isValid7702Implementation.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { Client, Address, Hex } from 'viem';
2+
import { isAddressEqual } from 'viem';
23
import { getCode } from 'viem/actions';
34

45
import type { DeleGatorEnvironment } from '../types';
@@ -92,9 +93,7 @@ export async function isValid7702Implementation({
9293
return false;
9394
}
9495

95-
return (
96-
delegatedAddress.toLowerCase() === expectedImplementation.toLowerCase()
97-
);
96+
return isAddressEqual(delegatedAddress, expectedImplementation);
9897
} catch (error) {
9998
// If the call fails (e.g., no code at address, network error),
10099
// then it's not properly delegated to our implementation

packages/delegation-toolkit/test/actions/isValid7702Implementation.test.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ describe('isValid7702Implementation', () => {
6060

6161
it('should return true when delegation code uses different case but matches implementation', async () => {
6262
const testAddress = '0xabcdefabcdefabcdefabcdefabcdefabcdefabcd';
63-
const delegationCode = '0xef01004000000000000000000000000000000000000000';
63+
const delegationCode = '0xef0100abcdef1234567890abcdef1234567890abcdef00';
6464
mockGetCode.mockResolvedValue(delegationCode);
6565

66-
// Update environment with uppercase address
66+
// Update environment with uppercase address to test case insensitivity
6767
mockEnvironment.implementations.EIP7702StatelessDeleGatorImpl =
68-
'0x4000000000000000000000000000000000000000';
68+
'0xABCDEF1234567890ABCDEF1234567890ABCDEF00';
6969

7070
const result = await isValid7702Implementation({
7171
client: publicClient,
@@ -75,6 +75,21 @@ describe('isValid7702Implementation', () => {
7575

7676
expect(result).toBe(true);
7777
});
78+
79+
it('should return false when delegation prefix uses different case (case-sensitive prefix)', async () => {
80+
const testAddress = '0xdddddddddddddddddddddddddddddddddddddddd';
81+
// Use uppercase delegation prefix - this should fail because startsWith is case-sensitive
82+
const delegationCode = '0xEF01004000000000000000000000000000000000000000';
83+
mockGetCode.mockResolvedValue(delegationCode);
84+
85+
const result = await isValid7702Implementation({
86+
client: publicClient,
87+
accountAddress: testAddress,
88+
environment: mockEnvironment,
89+
});
90+
91+
expect(result).toBe(false);
92+
});
7893
});
7994

8095
describe('Failure Cases', () => {

0 commit comments

Comments
 (0)