Skip to content
4 changes: 2 additions & 2 deletions packages/wallet/core/src/envelope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Address, Hex } from 'ox'

export type Envelope<T extends Payload.Payload> = {
readonly wallet: Address.Address
readonly chainId: bigint
readonly chainId: number
readonly configuration: Config.Config
readonly payload: T
}
Expand Down Expand Up @@ -67,7 +67,7 @@ export function encodeSignature(envelope: Signed<Payload.Payload>): Signature.Ra
(s) => signatureForLeaf(envelope, s)?.signature,
)
return {
noChainId: envelope.chainId === 0n,
noChainId: envelope.chainId === 0,
configuration: { ...envelope.configuration, topology },
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/wallet/core/src/preconditions/selectors.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Precondition, NativeBalancePrecondition, Erc20BalancePrecondition } from './types.js'
import { IntentPrecondition, decodePreconditions } from './codec.js'

export function extractChainID(precondition: IntentPrecondition): bigint | undefined {
export function extractChainID(precondition: IntentPrecondition): number | undefined {
if (!precondition) {
return undefined
}

try {
const data = JSON.parse(precondition.data)
return data.chainID ? BigInt(data.chainID) : undefined
return data.chainID ? Number(data.chainID) : undefined
} catch (e) {
return undefined
}
Expand Down
4 changes: 2 additions & 2 deletions packages/wallet/core/src/relayer/bundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ export interface Bundler {
payload: Payload.Calls4337_07,
): Promise<{ speed?: 'slow' | 'standard' | 'fast'; payload: Payload.Calls4337_07 }[]>
relay(entrypoint: Address.Address, userOperation: UserOperation.RpcV07): Promise<{ opHash: Hex.Hex }>
status(opHash: Hex.Hex, chainId: bigint): Promise<OperationStatus>
status(opHash: Hex.Hex, chainId: number): Promise<OperationStatus>

isAvailable(entrypoint: Address.Address, chainId: bigint): Promise<boolean>
isAvailable(entrypoint: Address.Address, chainId: number): Promise<boolean>
}

export function isBundler(relayer: any): relayer is Bundler {
Expand Down
6 changes: 3 additions & 3 deletions packages/wallet/core/src/relayer/bundlers/pimlico.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ export class PimlicoBundler implements Bundler {
this.bundlerRpcUrl = bundlerRpcUrl
}

async isAvailable(entrypoint: Address.Address, chainId: bigint): Promise<boolean> {
async isAvailable(entrypoint: Address.Address, chainId: number): Promise<boolean> {
const [bundlerChainId, supportedEntryPoints] = await Promise.all([
this.bundlerRpc<string>('eth_chainId', []),
this.bundlerRpc<Address.Address[]>('eth_supportedEntryPoints', []),
])

if (chainId !== BigInt(bundlerChainId)) {
if (chainId !== Number(bundlerChainId)) {
return false
}

Expand Down Expand Up @@ -103,7 +103,7 @@ export class PimlicoBundler implements Bundler {
}
}

async status(opHash: Hex.Hex, _chainId: bigint): Promise<OperationStatus> {
async status(opHash: Hex.Hex, _chainId: number): Promise<OperationStatus> {
try {
type PimlicoStatusResp = {
status: 'not_found' | 'not_submitted' | 'submitted' | 'rejected' | 'included' | 'failed' | 'reverted'
Expand Down
8 changes: 4 additions & 4 deletions packages/wallet/core/src/relayer/relayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,17 @@ export interface Relayer {
type: string
id: string

isAvailable(wallet: Address.Address, chainId: bigint): Promise<boolean>
isAvailable(wallet: Address.Address, chainId: number): Promise<boolean>

feeOptions(
wallet: Address.Address,
chainId: bigint,
chainId: number,
calls: Payload.Call[],
): Promise<{ options: FeeOption[]; quote?: FeeQuote }>

relay(to: Address.Address, data: Hex.Hex, chainId: bigint, quote?: FeeQuote): Promise<{ opHash: Hex.Hex }>
relay(to: Address.Address, data: Hex.Hex, chainId: number, quote?: FeeQuote): Promise<{ opHash: Hex.Hex }>

status(opHash: Hex.Hex, chainId: bigint): Promise<OperationStatus>
status(opHash: Hex.Hex, chainId: number): Promise<OperationStatus>

checkPrecondition(precondition: Precondition.Precondition): Promise<boolean>
}
Expand Down
8 changes: 4 additions & 4 deletions packages/wallet/core/src/relayer/standard/eip6963.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,23 @@ export class EIP6963Relayer implements Relayer {
this.relayer = new LocalRelayer(new EIP1193ProviderAdapter(detail.provider))
}

isAvailable(wallet: Address.Address, chainId: bigint): Promise<boolean> {
isAvailable(wallet: Address.Address, chainId: number): Promise<boolean> {
return this.relayer.isAvailable(wallet, chainId)
}

feeOptions(
wallet: Address.Address,
chainId: bigint,
chainId: number,
calls: Payload.Call[],
): Promise<{ options: FeeOption[]; quote?: FeeQuote }> {
return this.relayer.feeOptions(wallet, chainId, calls)
}

async relay(to: Address.Address, data: Hex.Hex, chainId: bigint, _?: FeeQuote): Promise<{ opHash: Hex.Hex }> {
async relay(to: Address.Address, data: Hex.Hex, chainId: number, _?: FeeQuote): Promise<{ opHash: Hex.Hex }> {
return this.relayer.relay(to, data, chainId)
}

status(opHash: Hex.Hex, chainId: bigint): Promise<OperationStatus> {
status(opHash: Hex.Hex, chainId: number): Promise<OperationStatus> {
return this.relayer.status(opHash, chainId)
}

Expand Down
18 changes: 9 additions & 9 deletions packages/wallet/core/src/relayer/standard/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import {
type GenericProviderTransactionReceipt = 'success' | 'failed' | 'unknown'

export interface GenericProvider {
sendTransaction(args: { to: Address.Address; data: Hex.Hex }, chainId: bigint): Promise<string | undefined>
sendTransaction(args: { to: Address.Address; data: Hex.Hex }, chainId: number): Promise<string | undefined>
getBalance(address: Address.Address): Promise<bigint>
call(args: { to: Address.Address; data: Hex.Hex }): Promise<string>
getTransactionReceipt(txHash: Hex.Hex, chainId: bigint): Promise<GenericProviderTransactionReceipt>
getTransactionReceipt(txHash: Hex.Hex, chainId: number): Promise<GenericProviderTransactionReceipt>
}

export class LocalRelayer implements Relayer {
Expand All @@ -29,7 +29,7 @@ export class LocalRelayer implements Relayer {

constructor(public readonly provider: GenericProvider) {}

isAvailable(_wallet: Address.Address, _chainId: bigint): Promise<boolean> {
isAvailable(_wallet: Address.Address, _chainId: number): Promise<boolean> {
return Promise.resolve(true)
}

Expand All @@ -49,7 +49,7 @@ export class LocalRelayer implements Relayer {

feeOptions(
wallet: Address.Address,
chainId: bigint,
chainId: number,
calls: Payload.Call[],
): Promise<{ options: FeeOption[]; quote?: FeeQuote }> {
return Promise.resolve({ options: [] })
Expand All @@ -72,7 +72,7 @@ export class LocalRelayer implements Relayer {
async relay(
to: Address.Address,
data: Hex.Hex,
chainId: bigint,
chainId: number,
quote?: FeeQuote,
preconditions?: IntentPrecondition[],
checkInterval: number = 5000,
Expand Down Expand Up @@ -151,7 +151,7 @@ export class LocalRelayer implements Relayer {
})
}

async status(opHash: Hex.Hex, chainId: bigint): Promise<OperationStatus> {
async status(opHash: Hex.Hex, chainId: number): Promise<OperationStatus> {
const receipt = await this.provider.getTransactionReceipt(opHash, chainId)
if (receipt === 'unknown') {
// Could be pending but we don't know
Expand Down Expand Up @@ -272,7 +272,7 @@ export class LocalRelayer implements Relayer {
export class EIP1193ProviderAdapter implements GenericProvider {
constructor(private readonly provider: EIP1193Provider) {}

private async trySwitchChain(chainId: bigint) {
private async trySwitchChain(chainId: number) {
try {
await this.provider.request({
method: 'wallet_switchEthereumChain',
Expand All @@ -288,7 +288,7 @@ export class EIP1193ProviderAdapter implements GenericProvider {
}
}

async sendTransaction(args: { to: Address.Address; data: Hex.Hex }, chainId: bigint) {
async sendTransaction(args: { to: Address.Address; data: Hex.Hex }, chainId: number) {
const accounts: Address.Address[] = await this.provider.request({ method: 'eth_requestAccounts' })
const from = accounts[0]

Expand Down Expand Up @@ -328,7 +328,7 @@ export class EIP1193ProviderAdapter implements GenericProvider {
})
}

async getTransactionReceipt(txHash: Hex.Hex, chainId: bigint) {
async getTransactionReceipt(txHash: Hex.Hex, chainId: number) {
await this.trySwitchChain(chainId)

const rpcReceipt = await this.provider.request({ method: 'eth_getTransactionReceipt', params: [txHash] })
Expand Down
18 changes: 9 additions & 9 deletions packages/wallet/core/src/relayer/standard/pk-relayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class PkRelayer implements Relayer {
const relayerAddress = Address.fromPublicKey(Secp256k1.getPublicKey({ privateKey }))
this.relayer = new LocalRelayer({
sendTransaction: async (args, chainId) => {
const providerChainId = BigInt(await this.provider.request({ method: 'eth_chainId' }))
const providerChainId = Number(await this.provider.request({ method: 'eth_chainId' }))
if (providerChainId !== chainId) {
throw new Error('Provider chain id does not match relayer chain id')
}
Expand Down Expand Up @@ -83,10 +83,10 @@ export class PkRelayer implements Relayer {
const callArgs = { to: args.to as `0x${string}`, data: args.data as `0x${string}` }
return await this.provider.request({ method: 'eth_call', params: [callArgs, 'latest'] })
},
getTransactionReceipt: async (txHash: string, chainId: bigint) => {
getTransactionReceipt: async (txHash: string, chainId: number) => {
Hex.assert(txHash)

const providerChainId = BigInt(await this.provider.request({ method: 'eth_chainId' }))
const providerChainId = Number(await this.provider.request({ method: 'eth_chainId' }))
if (providerChainId !== chainId) {
throw new Error('Provider chain id does not match relayer chain id')
}
Expand All @@ -101,28 +101,28 @@ export class PkRelayer implements Relayer {
})
}

async isAvailable(_wallet: Address.Address, chainId: bigint): Promise<boolean> {
const providerChainId = BigInt(await this.provider.request({ method: 'eth_chainId' }))
async isAvailable(_wallet: Address.Address, chainId: number): Promise<boolean> {
const providerChainId = Number(await this.provider.request({ method: 'eth_chainId' }))
return providerChainId === chainId
}

feeOptions(
wallet: Address.Address,
chainId: bigint,
chainId: number,
calls: Payload.Call[],
): Promise<{ options: FeeOption[]; quote?: FeeQuote }> {
return this.relayer.feeOptions(wallet, chainId, calls)
}

async relay(to: Address.Address, data: Hex.Hex, chainId: bigint, _?: FeeQuote): Promise<{ opHash: Hex.Hex }> {
const providerChainId = BigInt(await this.provider.request({ method: 'eth_chainId' }))
async relay(to: Address.Address, data: Hex.Hex, chainId: number, _?: FeeQuote): Promise<{ opHash: Hex.Hex }> {
const providerChainId = Number(await this.provider.request({ method: 'eth_chainId' }))
if (providerChainId !== chainId) {
throw new Error('Provider chain id does not match relayer chain id')
}
return this.relayer.relay(to, data, chainId)
}

status(opHash: Hex.Hex, chainId: bigint): Promise<OperationStatus> {
status(opHash: Hex.Hex, chainId: number): Promise<OperationStatus> {
return this.relayer.status(opHash, chainId)
}

Expand Down
12 changes: 6 additions & 6 deletions packages/wallet/core/src/relayer/standard/rpc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ export class RpcRelayer implements Relayer {
})
}

isAvailable(_wallet: Address.Address, chainId: bigint): Promise<boolean> {
return Promise.resolve(BigInt(this.chainId) === chainId)
isAvailable(_wallet: Address.Address, chainId: number): Promise<boolean> {
return Promise.resolve(this.chainId === chainId)
}

async feeOptions(
wallet: Address.Address,
chainId: bigint,
chainId: number,
calls: Payload.Call[],
): Promise<{ options: FeeOption[]; quote?: FeeQuote }> {
const callsStruct: Payload.Calls = { type: 'call', space: 0n, nonce: 0n, calls: calls }
Expand Down Expand Up @@ -103,7 +103,7 @@ export class RpcRelayer implements Relayer {
walletAddress: Address.Address,
to: Address.Address,
data: Hex.Hex,
chainId: bigint,
chainId: number,
quote?: FeeQuote,
preconditions?: IntentPrecondition[],
): Promise<{ opHash: Hex.Hex }> {
Expand Down Expand Up @@ -131,7 +131,7 @@ export class RpcRelayer implements Relayer {
async relay(
to: Address.Address,
data: Hex.Hex,
chainId: bigint,
chainId: number,
quote?: FeeQuote,
preconditions?: IntentPrecondition[],
): Promise<{ opHash: Hex.Hex }> {
Expand All @@ -156,7 +156,7 @@ export class RpcRelayer implements Relayer {
return { opHash: `0x${result.txnHash}` }
}

async status(opHash: Hex.Hex, chainId: bigint): Promise<OperationStatus> {
async status(opHash: Hex.Hex, chainId: number): Promise<OperationStatus> {
try {
const cleanedOpHash = opHash.startsWith('0x') ? opHash.substring(2) : opHash
const result = await this.client.getMetaTxnReceipt({ metaTxID: cleanedOpHash })
Expand Down
8 changes: 4 additions & 4 deletions packages/wallet/core/src/relayer/standard/sequence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ export class SequenceRelayer implements Relayer {
this.service = new Service(host, fetch)
}

async isAvailable(_wallet: Address.Address, _chainId: bigint): Promise<boolean> {
async isAvailable(_wallet: Address.Address, _chainId: number): Promise<boolean> {
return true
}

async feeOptions(
wallet: Address.Address,
_chainId: bigint,
_chainId: number,
calls: Payload.Call[],
): Promise<{ options: FeeOption[]; quote?: FeeQuote }> {
const to = wallet // TODO: this might be the guest module
Expand All @@ -42,7 +42,7 @@ export class SequenceRelayer implements Relayer {
return false
}

async relay(to: Address.Address, data: Hex.Hex, _chainId: bigint, quote?: FeeQuote): Promise<{ opHash: Hex.Hex }> {
async relay(to: Address.Address, data: Hex.Hex, _chainId: number, quote?: FeeQuote): Promise<{ opHash: Hex.Hex }> {
const walletAddress = to // TODO: pass wallet address or stop requiring it

const { txnHash } = await this.service.sendMetaTxn({
Expand All @@ -53,7 +53,7 @@ export class SequenceRelayer implements Relayer {
return { opHash: `0x${txnHash}` }
}

async status(opHash: Hex.Hex, _chainId: bigint): Promise<OperationStatus> {
async status(opHash: Hex.Hex, _chainId: number): Promise<OperationStatus> {
try {
const {
receipt: { status, revertReason, txnReceipt },
Expand Down
4 changes: 2 additions & 2 deletions packages/wallet/core/src/signers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface Signer {

sign: (
wallet: Address.Address,
chainId: bigint,
chainId: number,
payload: Payload.Parented,
) => Config.SignerSignature<Signature.SignatureOfSignerLeaf>
}
Expand All @@ -23,7 +23,7 @@ export interface SapientSigner {

signSapient: (
wallet: Address.Address,
chainId: bigint,
chainId: number,
payload: Payload.Parented,
imageHash: Hex.Hex,
) => Config.SignerSignature<Signature.SignatureOfSapientSignerLeaf>
Expand Down
6 changes: 3 additions & 3 deletions packages/wallet/core/src/signers/passkey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ export class Passkey implements SapientSigner, Witnessable {

async signSapient(
wallet: Address.Address,
chainId: bigint,
chainId: number,
payload: Payload.Parented,
imageHash: Hex.Hex,
): Promise<SignatureTypes.SignatureOfSapientSignerLeaf> {
Expand Down Expand Up @@ -274,8 +274,8 @@ export class Passkey implements SapientSigner, Witnessable {
),
)

const signature = await this.signSapient(wallet, 0n, payload, this.imageHash)
await stateWriter.saveWitnesses(wallet, 0n, payload, {
const signature = await this.signSapient(wallet, 0, payload, this.imageHash)
await stateWriter.saveWitnesses(wallet, 0, payload, {
type: 'unrecovered-signer',
weight: 1n,
signature,
Expand Down
6 changes: 3 additions & 3 deletions packages/wallet/core/src/signers/pk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class Pk implements SignerInterface, Witnessable {

async sign(
wallet: Address.Address,
chainId: bigint,
chainId: number,
payload: PayloadTypes.Parented,
): Promise<SignatureTypes.SignatureOfSignerLeaf> {
const hash = Payload.hash(wallet, chainId, payload)
Expand All @@ -65,8 +65,8 @@ export class Pk implements SignerInterface, Witnessable {
),
)

const signature = await this.sign(wallet, 0n, payload)
await stateWriter.saveWitnesses(wallet, 0n, payload, {
const signature = await this.sign(wallet, 0, payload)
await stateWriter.saveWitnesses(wallet, 0, payload, {
type: 'unrecovered-signer',
weight: 1n,
signature,
Expand Down
Loading