Skip to content

Commit ed9edb4

Browse files
authored
Normalize addresses with checksum, remove toLowerCase (0xsequence#105)
1 parent cefd9c8 commit ed9edb4

File tree

19 files changed

+111
-112
lines changed

19 files changed

+111
-112
lines changed

Diff for: packages/0xsequence/tests/browser/mock-wallet/mock-wallet.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ const main = async () => {
2727

2828
// assert testWalletContext value is correct
2929
if (
30-
deployedWalletContext.factory.toLowerCase() !== testWalletContext.factory.toLowerCase() ||
31-
deployedWalletContext.guestModule.toLowerCase() !== testWalletContext.guestModule.toLowerCase()
30+
deployedWalletContext.factory !== testWalletContext.factory ||
31+
deployedWalletContext.guestModule !== testWalletContext.guestModule
3232
) {
3333
throw new Error('deployedWalletContext and testWalletContext do not match. check or regen.')
3434
}

Diff for: packages/0xsequence/tests/browser/proxy-transport/channel.test.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,14 @@ export const tests = async () => {
6464
const address = await signer.getAddress()
6565

6666
await test('verifying getAddress result', async () => {
67-
assert.equal(address.toLowerCase(), '0xfbbabe29b5ec5fcd0beead9fa1c7f367bb985e9d'.toLowerCase(), 'wallet address')
67+
assert.equal(address, ethers.utils.getAddress('0xfbbabe29b5ec5fcd0beead9fa1c7f367bb985e9d'), 'wallet address')
6868
})
6969

7070
await test('sending a json-rpc request', async () => {
7171
await walletProvider.sendAsync({ jsonrpc: '2.0', id: 88, method: 'eth_accounts', params: [] }, (err, resp) => {
7272
assert.true(!err, 'error is empty')
7373
assert.true(!!resp, 'response successful')
74-
assert.true(resp.result == address.toLowerCase(), 'response address check')
74+
assert.true(resp.result == address, 'response address check')
7575
})
7676
})
7777

@@ -120,10 +120,10 @@ export const tests = async () => {
120120
const walletConfig = await recoverConfig(subDigest, sig)
121121

122122
const recoveredWalletAddress = addressOf(walletConfig, sequenceContext)
123-
assert.true(recoveredWalletAddress.toLowerCase() === address.toLowerCase(), 'recover address')
123+
assert.true(recoveredWalletAddress === address, 'recover address')
124124

125-
const singleSignerAddress = '0x4e37E14f5d5AAC4DF1151C6E8DF78B7541680853' // expected from mock-wallet owner
126-
assert.true(singleSignerAddress.toLowerCase() === walletConfig.signers[0].address.toLowerCase(), 'owner address check')
125+
const singleSignerAddress = ethers.utils.getAddress('0x4e37E14f5d5AAC4DF1151C6E8DF78B7541680853') // expected from mock-wallet owner
126+
assert.true(singleSignerAddress === walletConfig.signers[0].address, 'owner address check')
127127
})
128128

129129
walletProvider.closeWallet()

Diff for: packages/0xsequence/tests/browser/wallet-provider/dapp.test.ts

+16-16
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export const tests = async () => {
8787

8888
await test('getAccounts', async () => {
8989
const address = await wallet.getAddress()
90-
assert.equal(address.toLowerCase(), '0x1abe642a25d9f3a725f07c622abd4356646c1820'.toLowerCase(), 'wallet address is correct')
90+
assert.equal(address, ethers.utils.getAddress('0x1abe642a25d9f3a725f07c622abd4356646c1820'), 'wallet address is correct')
9191
})
9292

9393
await test('getWalletConfig', async () => {
@@ -98,14 +98,14 @@ export const tests = async () => {
9898
assert.true(config1.chainId !== undefined, 'config1, chainId is set')
9999
assert.true(config1.threshold === 1, 'config1, 1 threshold')
100100
assert.true(config1.signers.length === 1, 'config1, 1 signer')
101-
assert.true(config1.signers[0].address === '0x4e37e14f5d5aac4df1151c6e8df78b7541680853', 'config1, signer address')
101+
assert.true(config1.signers[0].address === '0x4e37E14f5d5AAC4DF1151C6E8DF78B7541680853', 'config1, signer address')
102102
assert.true(config1.signers[0].weight === 1, 'config1, signer weight')
103103

104104
const config2 = allWalletConfigs[0]
105105
assert.true(config2.chainId !== undefined, 'config2, chainId is set')
106106
assert.true(config2.threshold === 1, 'config2, 1 threshold')
107107
assert.true(config2.signers.length === 1, 'config2, 1 signer')
108-
assert.true(config2.signers[0].address === '0x4e37e14f5d5aac4df1151c6e8df78b7541680853', 'config2, signer address')
108+
assert.true(config2.signers[0].address === '0x4e37E14f5d5AAC4DF1151C6E8DF78B7541680853', 'config2, signer address')
109109
assert.true(config2.signers[0].weight === 1, 'config2, signer weight')
110110
})
111111

@@ -118,7 +118,7 @@ export const tests = async () => {
118118
assert.true(state1.chainId === 31337, 'state1, chainId is 31337')
119119
assert.true(state1.config.threshold === 1, 'state1, threshold')
120120
assert.true(state1.config.signers.length === 1, 'state1, 1 signer')
121-
assert.true(state1.address.toLowerCase() === (await wallet.getAddress()).toLowerCase(), 'state1, address')
121+
assert.true(state1.address === await wallet.getAddress(), 'state1, address')
122122
// assert.true(state1.deployed, 'state1, deployed')
123123
// assert.true(state1.publishedLatest, 'state1, publishedLatest')
124124
})
@@ -163,7 +163,7 @@ export const tests = async () => {
163163
await test('getSigners', async () => {
164164
const signers = await signer.getSigners()
165165
assert.true(signers.length === 1, 'signers, single owner')
166-
assert.true(signers[0] === '0x4e37e14f5d5aac4df1151c6e8df78b7541680853', 'signers, check address')
166+
assert.true(signers[0] === '0x4e37E14f5d5AAC4DF1151C6E8DF78B7541680853', 'signers, check address')
167167
})
168168

169169
await test('signMessage on defaultChain', async () => {
@@ -193,10 +193,10 @@ export const tests = async () => {
193193

194194
// Recover the address / config from the signature
195195
const walletConfig = await wallet.commands.recoverWalletConfigFromMessage(address, message, sig, chainId)
196-
assert.true(walletConfig.address.toLowerCase() === address.toLowerCase(), 'recover address')
196+
assert.true(walletConfig.address === address, 'recover address')
197197

198198
const singleSignerAddress = '0x4e37E14f5d5AAC4DF1151C6E8DF78B7541680853' // expected from mock-wallet owner
199-
assert.true(singleSignerAddress.toLowerCase() === walletConfig.signers[0].address.toLowerCase(), 'owner address check')
199+
assert.true(singleSignerAddress === walletConfig.signers[0].address, 'owner address check')
200200
})
201201

202202
await test('signTypedData on defaultChain', async () => {
@@ -235,10 +235,10 @@ export const tests = async () => {
235235

236236
// Recover config / address
237237
const walletConfig = await wallet.commands.recoverWalletConfigFromTypedData(address, { domain, types, message }, sig, chainId)
238-
assert.true(walletConfig.address.toLowerCase() === address.toLowerCase(), 'recover address')
238+
assert.true(walletConfig.address === address, 'recover address')
239239

240240
const singleSignerAddress = '0x4e37E14f5d5AAC4DF1151C6E8DF78B7541680853' // expected from mock-wallet owner
241-
assert.true(singleSignerAddress.toLowerCase() === walletConfig.signers[0].address.toLowerCase(), 'owner address check')
241+
assert.true(singleSignerAddress === walletConfig.signers[0].address, 'owner address check')
242242
})
243243

244244
await test('signAuthMessage', async () => {
@@ -276,10 +276,10 @@ export const tests = async () => {
276276

277277
// Recover the address / config from the signature
278278
const walletConfig = await wallet.commands.recoverWalletConfigFromMessage(address, message, sig, chainId)
279-
assert.true(walletConfig.address.toLowerCase() === address.toLowerCase(), 'recover address')
279+
assert.true(walletConfig.address === address, 'recover address')
280280

281281
const singleSignerAddress = '0x4e37E14f5d5AAC4DF1151C6E8DF78B7541680853' // expected from mock-wallet owner
282-
assert.true(singleSignerAddress.toLowerCase() === walletConfig.signers[0].address.toLowerCase(), 'owner address check')
282+
assert.true(singleSignerAddress === walletConfig.signers[0].address, 'owner address check')
283283
})
284284

285285
await test('getBalance', async () => {
@@ -355,9 +355,9 @@ export const tests = async () => {
355355

356356
// transaction is sent to the deployed wallet, if the wallet is deployed.. otherwise its sent to guestModule
357357
if (beforeWalletDeployed) {
358-
assert.equal(txReceipt.to.toLowerCase(), (await wallet.getAddress()).toLowerCase(), 'recipient is correct')
358+
assert.equal(txReceipt.to, await wallet.getAddress(), 'recipient is correct')
359359
} else {
360-
assert.equal(txReceipt.to.toLowerCase(), walletContext.guestModule.toLowerCase(), 'recipient is correct')
360+
assert.equal(txReceipt.to, walletContext.guestModule, 'recipient is correct')
361361
}
362362

363363
// Ensure fromAddress sent their eth
@@ -491,9 +491,9 @@ export const tests = async () => {
491491

492492
// confirm all account addresses are the same and correct
493493
{
494-
assert.equal((await wallet.getAddress()).toLowerCase(), await signer.getAddress(), 'wallet and signer address match')
495-
assert.equal((await wallet.getAddress()).toLowerCase(), await signer2.getAddress(), 'wallet and signer2 address match')
496-
assert.true((await wallet.getAddress()).toLowerCase() !== testAccounts[0].address.toLowerCase(), 'wallet is not subkey address')
494+
assert.equal(await wallet.getAddress(), await signer.getAddress(), 'wallet and signer address match')
495+
assert.equal(await wallet.getAddress(), await signer2.getAddress(), 'wallet and signer2 address match')
496+
assert.true(await wallet.getAddress() !== testAccounts[0].address, 'wallet is not subkey address')
497497
}
498498

499499
// initial balances

Diff for: packages/0xsequence/tests/browser/wallet-provider/dapp2.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export const tests = async () => {
9494
sig,
9595
await signer.getChainId()
9696
)
97-
assert.equal(walletConfig.address.toLowerCase(), (await wallet.getAddress()).toLowerCase(), 'signMessage, recovered address ok')
97+
assert.equal(walletConfig.address, await wallet.getAddress(), 'signMessage, recovered address ok')
9898
})
9999

100100
await test('signTypedData on defaultChain (in this case, hardhat2)', async () => {
@@ -133,9 +133,9 @@ export const tests = async () => {
133133

134134
// Recover config / address
135135
const walletConfig = await wallet.commands.recoverWalletConfigFromTypedData(address, { domain, types, message }, sig, chainId)
136-
assert.true(walletConfig.address.toLowerCase() === address.toLowerCase(), 'recover address')
136+
assert.true(walletConfig.address === address, 'recover address')
137137

138138
const singleSignerAddress = '0x4e37E14f5d5AAC4DF1151C6E8DF78B7541680853' // expected from mock-wallet owner
139-
assert.true(singleSignerAddress.toLowerCase() === walletConfig.signers[0].address.toLowerCase(), 'owner address check')
139+
assert.true(singleSignerAddress === walletConfig.signers[0].address, 'owner address check')
140140
})
141141
}

Diff for: packages/0xsequence/tests/browser/window-transport/dapp.test.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,19 @@ export const tests = async () => {
2929
const chainId = await signer.getChainId()
3030

3131
await test('getAddress', async () => {
32-
assert.equal(address.toLowerCase(), '0x1abe642a25d9f3a725f07c622abd4356646c1820', 'wallet address')
32+
assert.equal(address, ethers.utils.getAddress('0x1abe642a25d9f3a725f07c622abd4356646c1820'), 'wallet address')
3333
})
3434

3535
await test('sending a json-rpc request', async () => {
3636
await walletProvider.sendAsync({ jsonrpc: '2.0', id: 88, method: 'eth_accounts', params: [] }, (err, resp) => {
3737
assert.true(!err, 'error is empty')
3838
assert.true(!!resp, 'response successful')
39-
assert.true(resp.result[0] === address.toLowerCase(), 'response address check')
39+
assert.true(resp.result[0] === address, 'response address check')
4040
})
4141

4242
const resp = await provider.send('eth_accounts', [])
4343
assert.true(!!resp, 'response successful')
44-
assert.true(resp[0] === address.toLowerCase(), 'response address check')
44+
assert.true(resp[0] === address, 'response address check')
4545
})
4646

4747
await test('get chain id', async () => {
@@ -93,10 +93,10 @@ export const tests = async () => {
9393
const walletConfig = await recoverConfig(subDigest, sig)
9494

9595
const recoveredWalletAddress = addressOf(walletConfig, testWalletContext)
96-
assert.true(recoveredWalletAddress.toLowerCase() === address.toLowerCase(), 'recover address')
96+
assert.true(recoveredWalletAddress === address, 'recover address')
9797

9898
const singleSignerAddress = '0x4e37E14f5d5AAC4DF1151C6E8DF78B7541680853' // expected from mock-wallet owner
99-
assert.true(singleSignerAddress.toLowerCase() === walletConfig.signers[0].address.toLowerCase(), 'owner address check')
99+
assert.true(singleSignerAddress === walletConfig.signers[0].address, 'owner address check')
100100

101101

102102
// NOTE: below is to verify and recover signature of an EOA account
@@ -172,9 +172,9 @@ export const tests = async () => {
172172
const walletConfig = await recoverConfig(subDigest, sig)
173173

174174
const recoveredWalletAddress = addressOf(walletConfig, testWalletContext)
175-
assert.true(recoveredWalletAddress.toLowerCase() === address.toLowerCase(), 'recover address')
175+
assert.true(recoveredWalletAddress === address, 'recover address')
176176

177177
const singleSignerAddress = '0x4e37E14f5d5AAC4DF1151C6E8DF78B7541680853' // expected from mock-wallet owner
178-
assert.true(singleSignerAddress.toLowerCase() === walletConfig.signers[0].address.toLowerCase(), 'owner address check')
178+
assert.true(singleSignerAddress === walletConfig.signers[0].address, 'owner address check')
179179
})
180180
}

Diff for: packages/auth/tests/session.spec.ts

+15-15
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ describe('Wallet integration', function () {
113113
expect(session.config.address).to.be.undefined
114114
expect(session.config.threshold).to.equal(1)
115115
expect(session.config.signers.length).to.equal(1)
116-
expect(session.config.signers[0].address).to.equal(referenceSigner.address.toLowerCase())
116+
expect(session.config.signers[0].address).to.equal(referenceSigner.address)
117117
expect(session.config.signers[0].weight).to.equal(1)
118118

119119
await session.account.sendTransaction({ to: referenceSigner.address })
@@ -171,12 +171,12 @@ describe('Wallet integration', function () {
171171

172172
const [ogSignerId, signerId] = compareAddr(referenceSigner.address, newSigner.address) === 1 ? [1, 0] : [0, 1]
173173

174-
expect(session.account.address.toLowerCase()).to.equal(ogSession.account.address.toLowerCase())
174+
expect(session.account.address).to.equal(ogSession.account.address)
175175
expect(session.config.threshold).to.equal(2)
176176
expect(session.config.signers.length).to.equal(2)
177-
expect(session.config.signers[ogSignerId].address.toLowerCase()).to.equal(referenceSigner.address.toLowerCase())
177+
expect(session.config.signers[ogSignerId].address).to.equal(referenceSigner.address)
178178
expect(session.config.signers[ogSignerId].weight).to.equal(1)
179-
expect(session.config.signers[signerId].address.toLowerCase()).to.equal(newSigner.address.toLowerCase())
179+
expect(session.config.signers[signerId].address).to.equal(newSigner.address)
180180
expect(session.config.signers[signerId].weight).to.equal(1)
181181
})
182182

@@ -210,7 +210,7 @@ describe('Wallet integration', function () {
210210
deepSearch: true
211211
})
212212

213-
expect(ogSession.account.address.toLowerCase()).to.equal(session.account.address.toLowerCase())
213+
expect(ogSession.account.address).to.equal(session.account.address)
214214
})
215215

216216
it("Should fail to open session without authChain", async () => {
@@ -260,7 +260,7 @@ describe('Wallet integration', function () {
260260
deepSearch: false
261261
})
262262

263-
expect(ogSession.account.address.toLowerCase()).to.not.equal(session.account.address.toLowerCase())
263+
expect(ogSession.account.address).to.not.equal(session.account.address)
264264
})
265265

266266
describe('JWT Auth', () => {
@@ -306,7 +306,7 @@ describe('Wallet integration', function () {
306306

307307
try {
308308
const proof = await ethauth.decodeProof(request.body.json['ewtString'])
309-
proofAddress = proof.address.toLowerCase()
309+
proofAddress = ethers.utils.getAddress(proof.address)
310310

311311
if (recoverCount[proofAddress]) {
312312
recoverCount[proofAddress]++
@@ -360,7 +360,7 @@ describe('Wallet integration', function () {
360360
await session.auth(networksWithApi[0])
361361
expect(totalCount).to.equal(1)
362362
expect(session.jwts[sequenceApiUrl].token).to.equal(fakeJwt)
363-
expect(proofAddress.toLowerCase()).to.equal(session.account.address.toLowerCase())
363+
expect(proofAddress).to.equal(session.account.address)
364364
})
365365

366366
it("Should get JWT token (using network number)", async () => {
@@ -380,7 +380,7 @@ describe('Wallet integration', function () {
380380
await session.auth(ethnode.chainId)
381381
expect(totalCount).to.equal(1)
382382
expect(session.jwts[sequenceApiUrl].token).to.equal(fakeJwt)
383-
expect(proofAddress.toLowerCase()).to.equal(session.account.address.toLowerCase())
383+
expect(proofAddress).to.equal(session.account.address)
384384
})
385385

386386
it("Should fail to get JWT token (using non-existing network)", async () => {
@@ -456,7 +456,7 @@ describe('Wallet integration', function () {
456456

457457
expect(totalCount).to.equal(1)
458458
expect(session.jwts[sequenceApiUrl].token).to.equal(fakeJwt)
459-
expect(proofAddress.toLowerCase()).to.equal(session.account.address.toLowerCase())
459+
expect(proofAddress).to.equal(session.account.address)
460460
})
461461

462462
it("Should get JWT during first session creation", async () => {
@@ -477,7 +477,7 @@ describe('Wallet integration', function () {
477477
await Promise.all(session.authPromises.map((p) => p.promise))
478478

479479
expect(totalCount).to.equal(1)
480-
expect(recoverCount[session.account.address.toLowerCase()]).to.equal(1)
480+
expect(recoverCount[session.account.address]).to.equal(1)
481481

482482
expect(session.jwts[sequenceApiUrl].token).to.equal(fakeJwt)
483483
})
@@ -516,7 +516,7 @@ describe('Wallet integration', function () {
516516

517517
expect(totalCount).to.equal(2)
518518
expect(recoverCount["error"]).to.equal(1)
519-
expect(recoverCount[session.account.address.toLowerCase()]).to.equal(1)
519+
expect(recoverCount[session.account.address]).to.equal(1)
520520

521521
expect(session.jwts[sequenceApiUrl].token).to.equal(fakeJwt)
522522
})
@@ -538,7 +538,7 @@ describe('Wallet integration', function () {
538538
const api = await session.getAPI(networksWithApi[0])
539539

540540
expect(totalCount).to.equal(1)
541-
expect(recoverCount[session.account.address.toLowerCase()]).to.equal(1)
541+
expect(recoverCount[session.account.address]).to.equal(1)
542542

543543
expect(session.jwts[sequenceApiUrl].token).to.equal(fakeJwt)
544544

@@ -581,7 +581,7 @@ describe('Wallet integration', function () {
581581
const api = await session.getAPI(networksWithApi[0])
582582

583583
expect(totalCount).to.equal(1)
584-
expect(recoverCount[session.account.address.toLowerCase()]).to.equal(1)
584+
expect(recoverCount[session.account.address]).to.equal(1)
585585

586586
expect(session.jwts[sequenceApiUrl].token).to.equal(fakeJwt)
587587

@@ -708,7 +708,7 @@ describe('Wallet integration', function () {
708708

709709
expect(totalCount).to.equal(2)
710710
expect(recoverCount["error"]).to.equal(1)
711-
expect(recoverCount[session.account.address.toLowerCase()]).to.equal(1)
711+
expect(recoverCount[session.account.address]).to.equal(1)
712712

713713
expect(session.jwts[sequenceApiUrl].token).to.equal(fakeJwt)
714714

Diff for: packages/bridge/src/bridges/matic-bridge.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export class MaticPosBridge implements BridgeNative, BridgeERC20, BridgeERC1155,
7777
}
7878

7979
isMaticToken(token: string): boolean {
80-
return token.toLowerCase() === this.conf.maticToken
80+
return ethers.utils.getAddress(token) === ethers.utils.getAddress(this.conf.maticToken)
8181
}
8282

8383
get posClient() {

Diff for: packages/config/src/config.ts

+5-7
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ export const isUsableConfig = (config: WalletConfig): boolean => {
6767

6868
export const isValidConfigSigners = (config: WalletConfig, signers: string[]): boolean => {
6969
if (signers.length === 0) return true
70-
const a = config.signers.map(s => s.address.toLowerCase())
71-
const b = signers.map(s => s.toLowerCase())
70+
const a = config.signers.map(s => ethers.utils.getAddress(s.address))
71+
const b = signers.map(s => ethers.utils.getAddress(s))
7272
let valid = true
7373
b.forEach(s => {
7474
if (!a.includes(s)) valid = false
@@ -104,14 +104,12 @@ export const imageHash = (config: WalletConfig): string => {
104104
}
105105

106106
// sortConfig normalizes the list of signer addreses in a WalletConfig
107-
export const sortConfig = (config: WalletConfig, downcase: boolean = true): WalletConfig => {
107+
export const sortConfig = (config: WalletConfig): WalletConfig => {
108108
config.signers.sort((a, b) => compareAddr(a.address, b.address))
109109

110110
// normalize
111-
if (downcase) {
112-
config.signers.forEach(s => s.address = s.address.toLowerCase())
113-
if (config.address) config.address = config.address.toLowerCase()
114-
}
111+
config.signers.forEach(s => s.address = ethers.utils.getAddress(s.address))
112+
if (config.address) config.address = ethers.utils.getAddress(config.address)
115113

116114
// ensure no duplicate signers in the config
117115
const signers = config.signers.map(s => s.address)

0 commit comments

Comments
 (0)