Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"turbo": "^2.5.4",
"typescript": "5.8.3"
},
"packageManager": "pnpm@10.11.0",
"packageManager": "pnpm@10.14.0",
"engines": {
"node": ">=18"
}
Expand Down
1 change: 1 addition & 0 deletions packages/wallet/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"dev": "tsc --watch",
"test": "vitest run",
"test:coverage": "vitest run --coverage",
"typecheck": "tsc --noEmit",
"clean": "rimraf dist"
},
"exports": {
Expand Down
2 changes: 1 addition & 1 deletion packages/wallet/dapp-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"scripts": {
"build": "tsc",
"dev": "tsc --watch",
"typecheck": "tsc --noEmit",
"clean": "rimraf dist"
},
"exports": {
Expand All @@ -29,7 +30,6 @@
"vitest": "^3.2.1"
},
"dependencies": {
"@0xsequence/network": "^2.3.23",
"@0xsequence/wallet-core": "workspace:^",
"@0xsequence/wallet-primitives": "workspace:^",
"ox": "^0.7.2"
Expand Down
7 changes: 3 additions & 4 deletions packages/wallet/dapp-client/src/ChainSessionManager.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { Envelope, Relayer, Signers, State, Wallet } from '@0xsequence/wallet-core'
import { Attestation, Constants, Extensions, Payload, SessionConfig } from '@0xsequence/wallet-primitives'
import { Attestation, Constants, Extensions, Network, Payload, SessionConfig } from '@0xsequence/wallet-primitives'
import { AbiFunction, Address, Hex, Provider, RpcTransport, Secp256k1 } from 'ox'

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

import { ChainId } from '@0xsequence/network'
import {
AddExplicitSessionError,
FeeOptionError,
Expand Down Expand Up @@ -67,7 +66,7 @@ export class ChainSessionManager {
private wallet: Wallet | null = null
private provider: Provider.Provider | null = null
private relayer: Relayer.Standard.Rpc.RpcRelayer
private readonly chainId: ChainId
private readonly chainId: bigint
public transport: DappTransport | null = null
private sequenceStorage: SequenceStorage
public isInitialized: boolean = false
Expand All @@ -85,7 +84,7 @@ export class ChainSessionManager {
* @param canUseIndexedDb (Optional) A flag to enable or disable IndexedDB for caching.
*/
constructor(
chainId: ChainId,
chainId: bigint,
keyMachineUrl: string,
transport: DappTransport,
sequenceStorage: SequenceStorage,
Expand Down
41 changes: 18 additions & 23 deletions packages/wallet/dapp-client/src/DappClient.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { ChainId } from '@0xsequence/network'
import { Relayer, Signers } from '@0xsequence/wallet-core'
import { Address, Hex } from 'ox'

Expand Down Expand Up @@ -57,7 +56,7 @@ export class DappClient {

public readonly origin: string

private chainSessionManagers: Map<ChainId, ChainSessionManager> = new Map()
private chainSessionManagers: Map<bigint, ChainSessionManager> = new Map()
private transport: DappTransport
private keymachineUrl: string
private walletUrl: string
Expand Down Expand Up @@ -235,7 +234,7 @@ export class DappClient {
this.userEmail = implicitSession.userEmail ?? null

const explicitSessions = await this.sequenceStorage.getExplicitSessions()
const chainIdsToInitialize = new Set<ChainId>([
const chainIdsToInitialize = new Set<bigint>([
implicitSession.chainId,
...explicitSessions.filter((s) => Address.isEqual(s.walletAddress, this.walletAddress!)).map((s) => s.chainId),
])
Expand Down Expand Up @@ -328,7 +327,7 @@ export class DappClient {

/**
* Initiates a connection with the wallet and creates a new session.
* @param chainId The primary chain ID for the new session. {@link ChainId}
* @param chainId The primary chain ID for the new session.
* @param permissions (Optional) Permissions to request for an initial explicit session. {@link Signers.Session.ExplicitParams}
* @param options (Optional) Connection options, such as a preferred login method or email for social or email logins.
* @throws If the connection process fails. {@link ConnectionError}
Expand All @@ -345,7 +344,7 @@ export class DappClient {
* });
*/
async connect(
chainId: ChainId,
chainId: bigint,
permissions?: Signers.Session.ExplicitParams,
options: {
preferredLoginMethod?: 'google' | 'apple' | 'email' | 'passkey' | 'mnemonic'
Expand Down Expand Up @@ -375,7 +374,7 @@ export class DappClient {
* Adds a new explicit session for a given chain to an existing wallet.
* @remarks
* An `explicit session` is a session that can interact with any contract, subject to user-approved permissions.
* @param chainId The chain ID on which to add the explicit session. {@link ChainId}
* @param chainId The chain ID on which to add the explicit session.
* @param permissions The permissions to request for the new session. {@link Signers.Session.ExplicitParams}
*
* @throws If the session cannot be added. {@link AddExplicitSessionError}
Expand Down Expand Up @@ -408,7 +407,7 @@ export class DappClient {
* await dappClient.addExplicitSession(1, permissions);
* }
*/
async addExplicitSession(chainId: ChainId, permissions: Signers.Session.ExplicitParams): Promise<void> {
async addExplicitSession(chainId: bigint, permissions: Signers.Session.ExplicitParams): Promise<void> {
if (!this.isInitialized || !this.walletAddress)
throw new InitializationError('Cannot add an explicit session without an existing wallet.')

Expand All @@ -425,7 +424,7 @@ export class DappClient {

/**
* Modifies the permissions of an existing explicit session for a given chain and session address.
* @param chainId The chain ID on which the explicit session exists. {@link ChainId}
* @param chainId The chain ID on which the explicit session exists.
* @param sessionAddress The address of the explicit session to modify. {@link Address.Address}
* @param permissions The new permissions to set for the session. {@link Signers.Session.ExplicitParams}
*
Expand Down Expand Up @@ -454,7 +453,7 @@ export class DappClient {
* }
*/
async modifyExplicitSession(
chainId: ChainId,
chainId: bigint,
sessionAddress: Address.Address,
permissions: Signers.Session.ExplicitParams,
): Promise<void> {
Expand All @@ -474,7 +473,7 @@ export class DappClient {

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

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

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

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

/**
* @private Retrieves or creates a ChainSessionManager for a given chain ID.
* @param chainId The chain ID to get the ChainSessionManager for. {@link ChainId}
* @param chainId The chain ID to get the ChainSessionManager for.
* @returns The ChainSessionManager for the given chain ID. {@link ChainSessionManager}
*/
private getChainSessionManager(chainId: ChainId): ChainSessionManager {
private getChainSessionManager(chainId: bigint): ChainSessionManager {
let chainSessionManager = this.chainSessionManagers.get(chainId)
if (!chainSessionManager) {
chainSessionManager = new ChainSessionManager(
Expand Down
15 changes: 7 additions & 8 deletions packages/wallet/dapp-client/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { Attestation, Payload } from '@0xsequence/wallet-primitives'
import { Signers } from '@0xsequence/wallet-core'
import { ChainId } from '@0xsequence/network'
import { Address, Hex } from 'ox'
import type { TypedData } from 'ox/TypedData'

Expand Down Expand Up @@ -43,13 +42,13 @@ export interface AddImplicitSessionPayload {
export interface SignMessagePayload {
address: Address.Address
message: string
chainId: ChainId
chainId: bigint
}

export interface SignTypedDataPayload {
address: Address.Address
typedData: TypedData
chainId: ChainId
chainId: bigint
}

export interface ConnectSuccessResponsePayload {
Expand Down Expand Up @@ -91,7 +90,7 @@ export type Session = {
address: Address.Address
isImplicit: boolean
permissions?: Signers.Session.ExplicitParams
chainId?: ChainId
chainId?: bigint
}

// --- Event Types ---
Expand All @@ -117,14 +116,14 @@ export type DappClientSignatureEventListener = (data: {
action: (typeof RequestActionType)['SIGN_MESSAGE' | 'SIGN_TYPED_DATA']
response?: SignatureResponse
error?: any
chainId: number
chainId: bigint
}) => void

export type DappClientExplicitSessionEventListener = (data: {
action: (typeof RequestActionType)['ADD_EXPLICIT_SESSION' | 'MODIFY_EXPLICIT_SESSION']
response?: ExplicitSessionResponsePayload
error?: any
chainId: number
chainId: bigint
}) => void

// --- DappTransport Types ---
Expand Down Expand Up @@ -169,14 +168,14 @@ export interface MessageSignatureRequest extends BaseRequest {
type: 'message_signature'
message: string
address: Address.Address
chainId: number
chainId: bigint
}

export interface TypedDataSignatureRequest extends BaseRequest {
type: 'typed_data_signature'
typedData: unknown
address: Address.Address
chainId: number
chainId: bigint
}

export const WalletSize = {
Expand Down
14 changes: 7 additions & 7 deletions packages/wallet/dapp-client/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { allNetworks } from '@0xsequence/network'
import { Network } from '@0xsequence/wallet-primitives'
import { Bytes, Hex } from 'ox'
import { NODES_URL, RELAYER_URL } from './constants.js'

Expand Down Expand Up @@ -117,8 +117,8 @@ function applyTemplate(template: string, values: Record<string, string>) {
})
}

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

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

export const getRpcUrl = (chainId: number) => {
export const getRpcUrl = (chainId: Network.ChainId | bigint | number) => {
const network = getNetwork(chainId)

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

return url
}

export const getRelayerUrl = (chainId: number) => {
export const getRelayerUrl = (chainId: Network.ChainId | bigint | number) => {
const network = getNetwork(chainId)

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

return url
}

export const getExplorerUrl = (chainId: number, txHash: string) => {
export const getExplorerUrl = (chainId: Network.ChainId | bigint | number, txHash: string) => {
const network = getNetwork(chainId)
const explorerUrl = network.blockExplorer?.rootUrl
const explorerUrl = network.blockExplorer?.url
if (!explorerUrl) {
throw new Error(`Explorer URL not found for chainId ${chainId}`)
}
Expand Down
7 changes: 3 additions & 4 deletions packages/wallet/dapp-client/src/utils/storage.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Attestation } from '@0xsequence/wallet-primitives'
import { Address, Hex } from 'ox'
import { ChainId } from '@0xsequence/network'
import { jsonReplacers, jsonRevivers } from './index.js'
import {
AddExplicitSessionPayload,
Expand All @@ -14,7 +13,7 @@ import {
export interface ExplicitSessionData {
pk: Hex.Hex
walletAddress: Address.Address
chainId: ChainId
chainId: bigint
loginMethod?: PreferredLoginMethod
userEmail?: string
}
Expand All @@ -24,7 +23,7 @@ export interface ImplicitSessionData {
walletAddress: Address.Address
attestation: Attestation.Attestation
identitySignature: Hex.Hex
chainId: ChainId
chainId: bigint
loginMethod?: PreferredLoginMethod
userEmail?: string
}
Expand All @@ -37,7 +36,7 @@ export type PendingPayload =
| SignTypedDataPayload

export interface PendingRequestContext {
chainId: ChainId
chainId: bigint
action: string
payload: PendingPayload
}
Expand Down
1 change: 1 addition & 0 deletions packages/wallet/primitives-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"dev:esbuild": "esbuild src/index.ts --bundle --platform=node --target=node16 --outfile=dist/index.js --watch --sourcemap",
"start": "tsc && node dist/index.js",
"lint": "eslint . --max-warnings 0",
"typecheck": "tsc --noEmit",
"clean": "rimraf dist"
},
"exports": {
Expand Down
1 change: 1 addition & 0 deletions packages/wallet/primitives/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"dev": "tsc --watch",
"test": "vitest run",
"test:coverage": "vitest run --coverage",
"typecheck": "tsc --noEmit",
"clean": "rimraf dist"
},
"exports": {
Expand Down
Loading