Skip to content

Commit 1be7cf2

Browse files
committed
dapp-client: do not require Checksummed
1 parent db3e254 commit 1be7cf2

File tree

4 files changed

+42
-42
lines changed

4 files changed

+42
-42
lines changed

packages/wallet/dapp-client/src/ChainSessionManager.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Envelope, Relayer, Signers, State, Wallet } from '@0xsequence/wallet-core'
22
import { Address, Attestation, Constants, Extensions, Payload, SessionConfig } from '@0xsequence/wallet-primitives'
3-
import { AbiFunction, Hex, Provider, RpcTransport, Secp256k1 } from 'ox'
3+
import { AbiFunction, Address as oxAddress, Hex, Provider, RpcTransport, Secp256k1 } from 'ox'
44

55
import { DappTransport } from './DappTransport.js'
66

@@ -185,10 +185,10 @@ export class ChainSessionManager {
185185
* This is used when a wallet address is known but the session manager for this chain hasn't been instantiated yet.
186186
* @param walletAddress The address of the wallet to initialize with.
187187
*/
188-
public initializeWithWallet(walletAddress: Address.Checksummed) {
188+
public initializeWithWallet(walletAddress: oxAddress.Address) {
189189
if (this.isInitialized) return
190190

191-
this.walletAddress = walletAddress
191+
this.walletAddress = Address.checksum(walletAddress)
192192
this.wallet = new Wallet(this.walletAddress, {
193193
stateProvider: this.stateProvider,
194194
})
@@ -221,7 +221,7 @@ export class ChainSessionManager {
221221

222222
const allExplicitSessions = await this.sequenceStorage.getExplicitSessions()
223223
const walletExplicitSessions = allExplicitSessions.filter(
224-
(s) => Address.isEqual(s.walletAddress, walletAddr) && s.chainId === this.chainId,
224+
(s) => oxAddress.isEqual(s.walletAddress, walletAddr) && s.chainId === this.chainId,
225225
)
226226

227227
for (const sessionData of walletExplicitSessions) {
@@ -278,7 +278,7 @@ export class ChainSessionManager {
278278
{ path: '/request/connect', redirectUrl: this.redirectUrl },
279279
)
280280

281-
const receivedAddress = connectResponse.walletAddress
281+
const receivedAddress = Address.checksum(connectResponse.walletAddress)
282282
const { attestation, signature, email, loginMethod } = connectResponse
283283
if (!attestation || !signature)
284284
throw new InitializationError('Attestation or signature missing for implicit session.')
@@ -357,7 +357,7 @@ export class ChainSessionManager {
357357
{ path: '/request/connect', redirectUrl: this.redirectUrl },
358358
)
359359

360-
if (!Address.isEqual(response.walletAddress, this.walletAddress)) {
360+
if (!oxAddress.isEqual(response.walletAddress, this.walletAddress)) {
361361
throw new AddExplicitSessionError('Wallet address mismatch.')
362362
}
363363

@@ -385,7 +385,7 @@ export class ChainSessionManager {
385385
* @throws {ModifyExplicitSessionError} If modifying the session fails.
386386
*/
387387
async modifyExplicitSession(
388-
sessionAddress: Address.Checksummed,
388+
sessionAddress: oxAddress.Address,
389389
newPermissions: Signers.Session.ExplicitParams,
390390
): Promise<void> {
391391
if (!this.walletAddress) {
@@ -419,8 +419,8 @@ export class ChainSessionManager {
419419
)
420420

421421
if (
422-
!Address.isEqual(response.walletAddress, this.walletAddress) &&
423-
!Address.isEqual(response.sessionAddress, sessionAddress)
422+
!oxAddress.isEqual(response.walletAddress, this.walletAddress) &&
423+
!oxAddress.isEqual(response.sessionAddress, sessionAddress)
424424
) {
425425
throw new ModifyExplicitSessionError('Wallet or session address mismatch.')
426426
}
@@ -450,7 +450,7 @@ export class ChainSessionManager {
450450

451451
try {
452452
const connectResponse = response.payload
453-
const receivedAddress = connectResponse.walletAddress
453+
const receivedAddress = Address.checksum(connectResponse.walletAddress)
454454
const { email, loginMethod } = connectResponse
455455

456456
if (response.action === RequestActionType.ADD_IMPLICIT_SESSION) {
@@ -758,7 +758,7 @@ export class ChainSessionManager {
758758
return true
759759
} else if (response.action === RequestActionType.MODIFY_EXPLICIT_SESSION) {
760760
const modifyResponse = response.payload as ModifySessionSuccessResponsePayload
761-
if (!Address.isEqual(modifyResponse.walletAddress, this.walletAddress!)) {
761+
if (!oxAddress.isEqual(modifyResponse.walletAddress, this.walletAddress!)) {
762762
throw new ModifyExplicitSessionError('Wallet address mismatch on redirect response.')
763763
}
764764

packages/wallet/dapp-client/src/DappClient.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { ChainId } from '@0xsequence/network'
33
import { Relayer, Signers } from '@0xsequence/wallet-core'
44
import { Address } from '@0xsequence/wallet-primitives'
5+
import { Address as oxAddress, TypedData } from 'ox'
56

67
import { ChainSessionManager } from './ChainSessionManager.js'
78
import { DappTransport } from './DappTransport.js'
@@ -11,13 +12,11 @@ import {
1112
DappClientExplicitSessionEventListener,
1213
DappClientSignatureEventListener,
1314
RandomPrivateKeyFn,
14-
RequestActionType,
1515
SequenceSessionStorage,
1616
Session,
1717
Transaction,
1818
TransportMode,
1919
} from './types/index.js'
20-
import { TypedData } from 'ox/TypedData'
2120

2221
export type DappClientEventListener = (data?: any) => void
2322

@@ -227,14 +226,14 @@ export class DappClient {
227226
return
228227
}
229228

230-
this.walletAddress = implicitSession.walletAddress
229+
this.walletAddress = Address.checksum(implicitSession.walletAddress)
231230
this.loginMethod = implicitSession.loginMethod ?? null
232231
this.userEmail = implicitSession.userEmail ?? null
233232

234233
const explicitSessions = await this.sequenceStorage.getExplicitSessions()
235234
const chainIdsToInitialize = new Set<ChainId>([
236235
implicitSession.chainId,
237-
...explicitSessions.filter((s) => Address.isEqual(s.walletAddress, this.walletAddress!)).map((s) => s.chainId),
236+
...explicitSessions.filter((s) => oxAddress.isEqual(s.walletAddress, this.walletAddress!)).map((s) => s.chainId),
238237
])
239238

240239
const initPromises = Array.from(chainIdsToInitialize).map((chainId) =>
@@ -425,7 +424,7 @@ export class DappClient {
425424
/**
426425
* Modifies the permissions of an existing explicit session for a given chain and session address.
427426
* @param chainId The chain ID on which the explicit session exists. {@link ChainId}
428-
* @param sessionAddress The address of the explicit session to modify. {@link Address.Checksummed}
427+
* @param sessionAddress The address of the explicit session to modify. {@link Address.Address}
429428
* @param permissions The new permissions to set for the session. {@link Signers.Session.ExplicitParams}
430429
*
431430
* @throws If the client or relevant chain is not initialized. {@link InitializationError}
@@ -454,7 +453,7 @@ export class DappClient {
454453
*/
455454
async modifyExplicitSession(
456455
chainId: ChainId,
457-
sessionAddress: Address.Checksummed,
456+
sessionAddress: oxAddress.Address,
458457
permissions: Signers.Session.ExplicitParams,
459458
): Promise<void> {
460459
if (!this.isInitialized || !this.walletAddress)
@@ -589,7 +588,7 @@ export class DappClient {
589588
* await dappClient.signTypedData(1, typedData);
590589
* }
591590
*/
592-
async signTypedData(chainId: ChainId, typedData: TypedData): Promise<void> {
591+
async signTypedData(chainId: ChainId, typedData: TypedData.TypedData): Promise<void> {
593592
if (!this.isInitialized) throw new InitializationError('Not initialized')
594593
const chainSessionManager = this.getChainSessionManager(chainId)
595594
if (!chainSessionManager.isInitialized)

packages/wallet/dapp-client/src/types/index.ts

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
2-
import { Address, Attestation, Payload } from '@0xsequence/wallet-primitives'
2+
import { Attestation, Payload } from '@0xsequence/wallet-primitives'
33
import { Signers } from '@0xsequence/wallet-core'
44
import { ChainId } from '@0xsequence/network'
5-
import { Hex } from 'ox'
5+
import type { Address } from 'ox/Address'
6+
import type { Hex } from 'ox/Hex'
67
import type { TypedData } from 'ox/TypedData'
78

89
// --- Public Interfaces and Constants ---
@@ -20,63 +21,63 @@ export type PreferredLoginMethod = 'google' | 'apple' | 'email' | 'passkey' | 'm
2021
// --- Payloads for Transport ---
2122

2223
export interface AddExplicitSessionPayload {
23-
sessionAddress: Address.Checksummed
24+
sessionAddress: Address
2425
permissions: Signers.Session.ExplicitParams
2526
preferredLoginMethod?: PreferredLoginMethod
2627
email?: string
2728
}
2829
export interface ModifySessionPayload {
29-
walletAddress: Address.Checksummed
30-
sessionAddress: Address.Checksummed
30+
walletAddress: Address
31+
sessionAddress: Address
3132
permissions: Signers.Session.ExplicitParams
3233
}
3334

3435
export interface AddImplicitSessionPayload {
35-
sessionAddress: Address.Checksummed
36+
sessionAddress: Address
3637
implicitSessionRedirectUrl?: string
3738
permissions?: Signers.Session.ExplicitParams
3839
preferredLoginMethod?: PreferredLoginMethod
3940
email?: string
4041
}
4142

4243
export interface SignMessagePayload {
43-
address: Address.Checksummed
44+
address: Address
4445
message: string
4546
chainId: ChainId
4647
}
4748

4849
export interface SignTypedDataPayload {
49-
address: Address.Checksummed
50+
address: Address
5051
typedData: TypedData
5152
chainId: ChainId
5253
}
5354

5455
export interface ConnectSuccessResponsePayload {
55-
walletAddress: Address.Checksummed
56+
walletAddress: Address
5657
attestation?: Attestation.Attestation
57-
signature?: Hex.Hex
58+
signature?: Hex
5859
email?: string
5960
loginMethod?: PreferredLoginMethod
6061
}
6162

6263
export interface ModifySessionSuccessResponsePayload {
63-
walletAddress: Address.Checksummed
64-
sessionAddress: Address.Checksummed
64+
walletAddress: Address
65+
sessionAddress: Address
6566
}
6667

6768
export interface SignatureResponse {
68-
signature: Hex.Hex
69-
walletAddress: Address.Checksummed
69+
signature: Hex
70+
walletAddress: Address
7071
}
7172

7273
export interface ExplicitSessionResponsePayload {
73-
walletAddress: Address.Checksummed
74-
sessionAddress: Address.Checksummed
74+
walletAddress: Address
75+
sessionAddress: Address
7576
}
7677

7778
// --- Dapp-facing Types ---
7879

79-
export type RandomPrivateKeyFn = () => Hex.Hex | Promise<Hex.Hex>
80+
export type RandomPrivateKeyFn = () => Hex | Promise<Hex>
8081

8182
type RequiredKeys = 'to' | 'data' | 'value'
8283

@@ -87,7 +88,7 @@ export type Transaction =
8788
Partial<Omit<Payload.Call, RequiredKeys>>
8889

8990
export type Session = {
90-
address: Address.Checksummed
91+
address: Address
9192
isImplicit: boolean
9293
}
9394

@@ -165,14 +166,14 @@ export interface BaseRequest {
165166
export interface MessageSignatureRequest extends BaseRequest {
166167
type: 'message_signature'
167168
message: string
168-
address: Address.Checksummed
169+
address: Address
169170
chainId: number
170171
}
171172

172173
export interface TypedDataSignatureRequest extends BaseRequest {
173174
type: 'typed_data_signature'
174175
typedData: unknown
175-
address: Address.Checksummed
176+
address: Address
176177
chainId: number
177178
}
178179

packages/wallet/dapp-client/src/utils/storage.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { Address, Attestation } from '@0xsequence/wallet-primitives'
2-
import { Hex } from 'ox'
1+
import { Attestation } from '@0xsequence/wallet-primitives'
2+
import { Address, Hex } from 'ox'
33
import { ChainId } from '@0xsequence/network'
44
import { jsonReplacers, jsonRevivers } from './index.js'
55
import {
@@ -13,15 +13,15 @@ import {
1313

1414
export interface ExplicitSessionData {
1515
pk: Hex.Hex
16-
walletAddress: Address.Checksummed
16+
walletAddress: Address.Address
1717
chainId: ChainId
1818
loginMethod?: PreferredLoginMethod
1919
userEmail?: string
2020
}
2121

2222
export interface ImplicitSessionData {
2323
pk: Hex.Hex
24-
walletAddress: Address.Checksummed
24+
walletAddress: Address.Address
2525
attestation: Attestation.Attestation
2626
identitySignature: Hex.Hex
2727
chainId: ChainId

0 commit comments

Comments
 (0)