Skip to content

Commit 86fe835

Browse files
Merge pull request #840 from 0xsequence/networks
Networks update
2 parents 8ce43e8 + ba3c106 commit 86fe835

24 files changed

+1080
-831
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"turbo": "^2.5.4",
2626
"typescript": "5.8.3"
2727
},
28-
"packageManager": "pnpm@10.11.0",
28+
"packageManager": "pnpm@10.14.0",
2929
"engines": {
3030
"node": ">=18"
3131
}

packages/wallet/core/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"dev": "tsc --watch",
1313
"test": "vitest run",
1414
"test:coverage": "vitest run --coverage",
15+
"typecheck": "tsc --noEmit",
1516
"clean": "rimraf dist"
1617
},
1718
"exports": {

packages/wallet/dapp-client/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"scripts": {
1111
"build": "tsc",
1212
"dev": "tsc --watch",
13+
"typecheck": "tsc --noEmit",
1314
"clean": "rimraf dist"
1415
},
1516
"exports": {
@@ -29,7 +30,6 @@
2930
"vitest": "^3.2.1"
3031
},
3132
"dependencies": {
32-
"@0xsequence/network": "^2.3.23",
3333
"@0xsequence/wallet-core": "workspace:^",
3434
"@0xsequence/wallet-primitives": "workspace:^",
3535
"ox": "^0.7.2"

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

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

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

7-
import { ChainId } from '@0xsequence/network'
87
import {
98
AddExplicitSessionError,
109
FeeOptionError,
@@ -67,7 +66,7 @@ export class ChainSessionManager {
6766
private wallet: Wallet | null = null
6867
private provider: Provider.Provider | null = null
6968
private relayer: Relayer.Standard.Rpc.RpcRelayer
70-
private readonly chainId: ChainId
69+
private readonly chainId: bigint
7170
public transport: DappTransport | null = null
7271
private sequenceStorage: SequenceStorage
7372
public isInitialized: boolean = false
@@ -85,7 +84,7 @@ export class ChainSessionManager {
8584
* @param canUseIndexedDb (Optional) A flag to enable or disable IndexedDB for caching.
8685
*/
8786
constructor(
88-
chainId: ChainId,
87+
chainId: bigint,
8988
keyMachineUrl: string,
9089
transport: DappTransport,
9190
sequenceStorage: SequenceStorage,

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

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
2-
import { ChainId } from '@0xsequence/network'
32
import { Relayer, Signers } from '@0xsequence/wallet-core'
43
import { Address, Hex } from 'ox'
54

@@ -57,7 +56,7 @@ export class DappClient {
5756

5857
public readonly origin: string
5958

60-
private chainSessionManagers: Map<ChainId, ChainSessionManager> = new Map()
59+
private chainSessionManagers: Map<bigint, ChainSessionManager> = new Map()
6160
private transport: DappTransport
6261
private keymachineUrl: string
6362
private walletUrl: string
@@ -235,7 +234,7 @@ export class DappClient {
235234
this.userEmail = implicitSession.userEmail ?? null
236235

237236
const explicitSessions = await this.sequenceStorage.getExplicitSessions()
238-
const chainIdsToInitialize = new Set<ChainId>([
237+
const chainIdsToInitialize = new Set<bigint>([
239238
implicitSession.chainId,
240239
...explicitSessions.filter((s) => Address.isEqual(s.walletAddress, this.walletAddress!)).map((s) => s.chainId),
241240
])
@@ -328,7 +327,7 @@ export class DappClient {
328327

329328
/**
330329
* Initiates a connection with the wallet and creates a new session.
331-
* @param chainId The primary chain ID for the new session. {@link ChainId}
330+
* @param chainId The primary chain ID for the new session.
332331
* @param permissions (Optional) Permissions to request for an initial explicit session. {@link Signers.Session.ExplicitParams}
333332
* @param options (Optional) Connection options, such as a preferred login method or email for social or email logins.
334333
* @throws If the connection process fails. {@link ConnectionError}
@@ -345,7 +344,7 @@ export class DappClient {
345344
* });
346345
*/
347346
async connect(
348-
chainId: ChainId,
347+
chainId: bigint,
349348
permissions?: Signers.Session.ExplicitParams,
350349
options: {
351350
preferredLoginMethod?: 'google' | 'apple' | 'email' | 'passkey' | 'mnemonic'
@@ -375,7 +374,7 @@ export class DappClient {
375374
* Adds a new explicit session for a given chain to an existing wallet.
376375
* @remarks
377376
* An `explicit session` is a session that can interact with any contract, subject to user-approved permissions.
378-
* @param chainId The chain ID on which to add the explicit session. {@link ChainId}
377+
* @param chainId The chain ID on which to add the explicit session.
379378
* @param permissions The permissions to request for the new session. {@link Signers.Session.ExplicitParams}
380379
*
381380
* @throws If the session cannot be added. {@link AddExplicitSessionError}
@@ -408,7 +407,7 @@ export class DappClient {
408407
* await dappClient.addExplicitSession(1, permissions);
409408
* }
410409
*/
411-
async addExplicitSession(chainId: ChainId, permissions: Signers.Session.ExplicitParams): Promise<void> {
410+
async addExplicitSession(chainId: bigint, permissions: Signers.Session.ExplicitParams): Promise<void> {
412411
if (!this.isInitialized || !this.walletAddress)
413412
throw new InitializationError('Cannot add an explicit session without an existing wallet.')
414413

@@ -425,7 +424,7 @@ export class DappClient {
425424

426425
/**
427426
* Modifies the permissions of an existing explicit session for a given chain and session address.
428-
* @param chainId The chain ID on which the explicit session exists. {@link ChainId}
427+
* @param chainId The chain ID on which the explicit session exists.
429428
* @param sessionAddress The address of the explicit session to modify. {@link Address.Address}
430429
* @param permissions The new permissions to set for the session. {@link Signers.Session.ExplicitParams}
431430
*
@@ -454,7 +453,7 @@ export class DappClient {
454453
* }
455454
*/
456455
async modifyExplicitSession(
457-
chainId: ChainId,
456+
chainId: bigint,
458457
sessionAddress: Address.Address,
459458
permissions: Signers.Session.ExplicitParams,
460459
): Promise<void> {
@@ -474,7 +473,7 @@ export class DappClient {
474473

475474
/**
476475
* Gets the gas fee options for an array of transactions.
477-
* @param chainId The chain ID on which to get the fee options. {@link ChainId}
476+
* @param chainId The chain ID on which to get the fee options.
478477
* @param transactions An array of transactions to get fee options for. These transactions will not be sent.
479478
* @throws If the fee options cannot be fetched. {@link FeeOptionError}
480479
* @throws If the client or relevant chain is not initialized. {@link InitializationError}
@@ -501,7 +500,7 @@ export class DappClient {
501500
* const txHash = await dappClient.sendTransaction(1, transactions, feeOption);
502501
* }
503502
*/
504-
async getFeeOptions(chainId: ChainId, transactions: Transaction[]): Promise<Relayer.FeeOption[]> {
503+
async getFeeOptions(chainId: bigint, transactions: Transaction[]): Promise<Relayer.FeeOption[]> {
505504
if (!this.isInitialized) throw new InitializationError('Not initialized')
506505
const chainSessionManager = this.getChainSessionManager(chainId)
507506
if (!chainSessionManager.isInitialized)
@@ -511,7 +510,7 @@ export class DappClient {
511510

512511
/**
513512
* Signs and sends a transaction using an available session signer.
514-
* @param chainId The chain ID on which to send the transaction. {@link ChainId}
513+
* @param chainId The chain ID on which to send the transaction.
515514
* @param transactions An array of transactions to be executed atomically in a single batch. {@link Transaction}
516515
* @param feeOption (Optional) The selected fee option to sponsor the transaction. {@link Relayer.FeeOption}
517516
* @throws {TransactionError} If the transaction fails to send or confirm.
@@ -534,11 +533,7 @@ export class DappClient {
534533
*
535534
* const txHash = await dappClient.sendTransaction(1, [transaction]);
536535
*/
537-
async sendTransaction(
538-
chainId: ChainId,
539-
transactions: Transaction[],
540-
feeOption?: Relayer.FeeOption,
541-
): Promise<Hex.Hex> {
536+
async sendTransaction(chainId: bigint, transactions: Transaction[], feeOption?: Relayer.FeeOption): Promise<Hex.Hex> {
542537
if (!this.isInitialized) throw new InitializationError('Not initialized')
543538
const chainSessionManager = this.getChainSessionManager(chainId)
544539
if (!chainSessionManager.isInitialized)
@@ -548,7 +543,7 @@ export class DappClient {
548543

549544
/**
550545
* Signs a standard message (EIP-191) using an available session signer.
551-
* @param chainId The chain ID on which to sign the message. {@link ChainId}
546+
* @param chainId The chain ID on which to sign the message.
552547
* @param message The message to sign.
553548
* @throws If the message cannot be signed. {@link SigningError}
554549
* @throws If the client or relevant chain is not initialized. {@link InitializationError}
@@ -566,7 +561,7 @@ export class DappClient {
566561
* await dappClient.signMessage(1, message);
567562
* }
568563
*/
569-
async signMessage(chainId: ChainId, message: string): Promise<void> {
564+
async signMessage(chainId: bigint, message: string): Promise<void> {
570565
if (!this.isInitialized) throw new InitializationError('Not initialized')
571566
const chainSessionManager = this.getChainSessionManager(chainId)
572567
if (!chainSessionManager.isInitialized)
@@ -576,7 +571,7 @@ export class DappClient {
576571

577572
/**
578573
* Signs a typed data object (EIP-712) using an available session signer.
579-
* @param chainId The chain ID on which to sign the typed data. {@link ChainId}
574+
* @param chainId The chain ID on which to sign the typed data.
580575
* @param typedData The typed data object to sign.
581576
* @throws If the typed data cannot be signed. {@link SigningError}
582577
* @throws If the client or relevant chain is not initialized. {@link InitializationError}
@@ -594,7 +589,7 @@ export class DappClient {
594589
* await dappClient.signTypedData(1, typedData);
595590
* }
596591
*/
597-
async signTypedData(chainId: ChainId, typedData: TypedData): Promise<void> {
592+
async signTypedData(chainId: bigint, typedData: TypedData): Promise<void> {
598593
if (!this.isInitialized) throw new InitializationError('Not initialized')
599594
const chainSessionManager = this.getChainSessionManager(chainId)
600595
if (!chainSessionManager.isInitialized)
@@ -652,10 +647,10 @@ export class DappClient {
652647

653648
/**
654649
* @private Retrieves or creates a ChainSessionManager for a given chain ID.
655-
* @param chainId The chain ID to get the ChainSessionManager for. {@link ChainId}
650+
* @param chainId The chain ID to get the ChainSessionManager for.
656651
* @returns The ChainSessionManager for the given chain ID. {@link ChainSessionManager}
657652
*/
658-
private getChainSessionManager(chainId: ChainId): ChainSessionManager {
653+
private getChainSessionManager(chainId: bigint): ChainSessionManager {
659654
let chainSessionManager = this.chainSessionManagers.get(chainId)
660655
if (!chainSessionManager) {
661656
chainSessionManager = new ChainSessionManager(

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
22
import { Attestation, Payload } from '@0xsequence/wallet-primitives'
33
import { Signers } from '@0xsequence/wallet-core'
4-
import { ChainId } from '@0xsequence/network'
54
import { Address, Hex } from 'ox'
65
import type { TypedData } from 'ox/TypedData'
76

@@ -43,13 +42,13 @@ export interface AddImplicitSessionPayload {
4342
export interface SignMessagePayload {
4443
address: Address.Address
4544
message: string
46-
chainId: ChainId
45+
chainId: bigint
4746
}
4847

4948
export interface SignTypedDataPayload {
5049
address: Address.Address
5150
typedData: TypedData
52-
chainId: ChainId
51+
chainId: bigint
5352
}
5453

5554
export interface ConnectSuccessResponsePayload {
@@ -91,7 +90,7 @@ export type Session = {
9190
address: Address.Address
9291
isImplicit: boolean
9392
permissions?: Signers.Session.ExplicitParams
94-
chainId?: ChainId
93+
chainId?: bigint
9594
}
9695

9796
// --- Event Types ---
@@ -117,14 +116,14 @@ export type DappClientSignatureEventListener = (data: {
117116
action: (typeof RequestActionType)['SIGN_MESSAGE' | 'SIGN_TYPED_DATA']
118117
response?: SignatureResponse
119118
error?: any
120-
chainId: number
119+
chainId: bigint
121120
}) => void
122121

123122
export type DappClientExplicitSessionEventListener = (data: {
124123
action: (typeof RequestActionType)['ADD_EXPLICIT_SESSION' | 'MODIFY_EXPLICIT_SESSION']
125124
response?: ExplicitSessionResponsePayload
126125
error?: any
127-
chainId: number
126+
chainId: bigint
128127
}) => void
129128

130129
// --- DappTransport Types ---
@@ -169,14 +168,14 @@ export interface MessageSignatureRequest extends BaseRequest {
169168
type: 'message_signature'
170169
message: string
171170
address: Address.Address
172-
chainId: number
171+
chainId: bigint
173172
}
174173

175174
export interface TypedDataSignatureRequest extends BaseRequest {
176175
type: 'typed_data_signature'
177176
typedData: unknown
178177
address: Address.Address
179-
chainId: number
178+
chainId: bigint
180179
}
181180

182181
export const WalletSize = {

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
2-
import { allNetworks } from '@0xsequence/network'
2+
import { Network } from '@0xsequence/wallet-primitives'
33
import { Bytes, Hex } from 'ox'
44
import { NODES_URL, RELAYER_URL } from './constants.js'
55

@@ -117,8 +117,8 @@ function applyTemplate(template: string, values: Record<string, string>) {
117117
})
118118
}
119119

120-
export const getNetwork = (chainId: number) => {
121-
const network = allNetworks.find((network) => network.chainId === chainId)
120+
export const getNetwork = (chainId: Network.ChainId | bigint | number) => {
121+
const network = Network.getNetworkFromChainId(chainId)
122122

123123
if (!network) {
124124
throw new Error(`Network with chainId ${chainId} not found`)
@@ -127,25 +127,25 @@ export const getNetwork = (chainId: number) => {
127127
return network
128128
}
129129

130-
export const getRpcUrl = (chainId: number) => {
130+
export const getRpcUrl = (chainId: Network.ChainId | bigint | number) => {
131131
const network = getNetwork(chainId)
132132

133133
const url = applyTemplate(NODES_URL, { network: network.name })
134134

135135
return url
136136
}
137137

138-
export const getRelayerUrl = (chainId: number) => {
138+
export const getRelayerUrl = (chainId: Network.ChainId | bigint | number) => {
139139
const network = getNetwork(chainId)
140140

141141
const url = applyTemplate(RELAYER_URL, { network: network.name })
142142

143143
return url
144144
}
145145

146-
export const getExplorerUrl = (chainId: number, txHash: string) => {
146+
export const getExplorerUrl = (chainId: Network.ChainId | bigint | number, txHash: string) => {
147147
const network = getNetwork(chainId)
148-
const explorerUrl = network.blockExplorer?.rootUrl
148+
const explorerUrl = network.blockExplorer?.url
149149
if (!explorerUrl) {
150150
throw new Error(`Explorer URL not found for chainId ${chainId}`)
151151
}

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Attestation } from '@0xsequence/wallet-primitives'
22
import { Address, Hex } from 'ox'
3-
import { ChainId } from '@0xsequence/network'
43
import { jsonReplacers, jsonRevivers } from './index.js'
54
import {
65
AddExplicitSessionPayload,
@@ -14,7 +13,7 @@ import {
1413
export interface ExplicitSessionData {
1514
pk: Hex.Hex
1615
walletAddress: Address.Address
17-
chainId: ChainId
16+
chainId: bigint
1817
loginMethod?: PreferredLoginMethod
1918
userEmail?: string
2019
}
@@ -24,7 +23,7 @@ export interface ImplicitSessionData {
2423
walletAddress: Address.Address
2524
attestation: Attestation.Attestation
2625
identitySignature: Hex.Hex
27-
chainId: ChainId
26+
chainId: bigint
2827
loginMethod?: PreferredLoginMethod
2928
userEmail?: string
3029
}
@@ -37,7 +36,7 @@ export type PendingPayload =
3736
| SignTypedDataPayload
3837

3938
export interface PendingRequestContext {
40-
chainId: ChainId
39+
chainId: bigint
4140
action: string
4241
payload: PendingPayload
4342
}

packages/wallet/primitives-cli/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"dev:esbuild": "esbuild src/index.ts --bundle --platform=node --target=node16 --outfile=dist/index.js --watch --sourcemap",
99
"start": "tsc && node dist/index.js",
1010
"lint": "eslint . --max-warnings 0",
11+
"typecheck": "tsc --noEmit",
1112
"clean": "rimraf dist"
1213
},
1314
"exports": {

packages/wallet/primitives/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"dev": "tsc --watch",
1313
"test": "vitest run",
1414
"test:coverage": "vitest run --coverage",
15+
"typecheck": "tsc --noEmit",
1516
"clean": "rimraf dist"
1617
},
1718
"exports": {

0 commit comments

Comments
 (0)