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 CircleModularWalletsCore/Resources/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<plist version="1.0">
<dict>
<key>CFBundleShortVersionString</key>
<string>1.0.7</string>
<string>1.0.8</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleName</key>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ import BigInt

/// Result for ``BundlerClient/estimateUserOperationGas(userOp:entryPoint:)``
public struct EstimateUserOperationGasResult: Codable {
let preVerificationGas: BigInt?
let verificationGasLimit: BigInt?
let callGasLimit: BigInt?
let paymasterVerificationGasLimit: BigInt?
let paymasterPostOpGasLimit: BigInt?
public let preVerificationGas: BigInt?
public let verificationGasLimit: BigInt?
public let callGasLimit: BigInt?
public let paymasterVerificationGasLimit: BigInt?
public let paymasterPostOpGasLimit: BigInt?

init(preVerificationGas: BigInt?, verificationGasLimit: BigInt?, callGasLimit: BigInt?, paymasterVerificationGasLimit: BigInt?, paymasterPostOpGasLimit: BigInt?) {
self.preVerificationGas = preVerificationGas
Expand Down Expand Up @@ -64,11 +64,11 @@ public struct EstimateUserOperationGasResult: Codable {

/// Result for ``BundlerClient/getUserOperation(userOpHash:)``
public struct GetUserOperationResult: Codable {
let blockHash: String?
let blockNumber: BigInt?
let transactionHash: String?
let entryPoint: String?
let userOperation: UserOperationType?
public let blockHash: String?
public let blockNumber: BigInt?
public let transactionHash: String?
public let entryPoint: String?
public let userOperation: UserOperationType?

enum CodingKeys: String, CodingKey {
case userOperation
Expand Down Expand Up @@ -157,30 +157,30 @@ public struct GetUserOperationReceiptResult: Codable {

// https://github.com/wevm/viem/blob/e7431e88b0e8b83719c91f5a6a57da1a10076a1c/src/account-abstraction/types/userOperation.ts#L167
public struct UserOperationReceipt: Codable {
let transactionHash: String?
let transactionIndex: String?
let blockHash: String?
let blockNumber: String?
let from: String?
let to: String?
let cumulativeGasUsed: String?
let gasUsed: String?
let logs: [Log]?
let logsBloom: String?
let status: String?
let effectiveGasPrice: String?
public let transactionHash: String?
public let transactionIndex: String?
public let blockHash: String?
public let blockNumber: String?
public let from: String?
public let to: String?
public let cumulativeGasUsed: String?
public let gasUsed: String?
public let logs: [Log]?
public let logsBloom: String?
public let status: String?
public let effectiveGasPrice: String?
}

// https://github.com/wevm/viem/blob/e7431e88b0e8b83719c91f5a6a57da1a10076a1c/src/types/log.ts#L15
public struct Log: Codable {
let removed: Bool?
let logIndex: String?
let transactionIndex: String?
let transactionHash: String?
let blockHash: String?
let blockNumber: String?
let address: String?
let data: String?
let topics: [String]?
public let removed: Bool?
public let logIndex: String?
public let transactionIndex: String?
public let transactionHash: String?
public let blockHash: String?
public let blockNumber: String?
public let address: String?
public let data: String?
public let topics: [String]?
}
}
14 changes: 4 additions & 10 deletions CircleModularWalletsCore/Sources/APIs/Modular/ModularRpcApi.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,15 @@
import Foundation

protocol ModularRpcApi {

func circleGetAddress(
transport: Transport,
req: CreateWalletRequest
) async throws -> Wallet

func getAddress(transport: Transport, req: GetAddressReq) async throws -> ModularWallet
}

extension ModularRpcApi {

func circleGetAddress(
transport: Transport,
req: CreateWalletRequest
) async throws -> Wallet {
func getAddress(transport: Transport, req: GetAddressReq) async throws -> ModularWallet {
let req = RpcRequest(method: "circle_getAddress", params: [req])
let response = try await transport.request(req) as RpcResponse<Wallet>
let response = try await transport.request(req) as RpcResponse<ModularWallet>
return response.result
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,12 @@

import Foundation

public struct CreateWalletRequest: Encodable {
struct GetAddressReq: Encodable {
let scaConfiguration: ScaConfiguration
let metadata: Metadata
}

public struct CreateWalletResponse: Decodable {
var data: Data

struct Data: Codable {
var wallets: [Wallet]
}
}

public struct Wallet: Codable {
struct ModularWallet: Codable, Sendable {
var id: String?
var address: String?
var blockchain: String?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,9 @@ struct EthCallParams: Encodable {

/// Result for ``PublicRpcApi/estimateFeesPerGas(transport:feeValuesType:)``
public struct EstimateFeesPerGasResult: Encodable {

let maxFeePerGas: BigInt? // eip1559
let maxPriorityFeePerGas: BigInt? // eip1559
let gasPrice: BigInt? // legacy
public let maxFeePerGas: BigInt? // eip1559
public let maxPriorityFeePerGas: BigInt? // eip1559
public let gasPrice: BigInt? // legacy

init(maxFeePerGas: BigInt?, maxPriorityFeePerGas: BigInt?, gasPrice: BigInt? = nil) {
self.maxFeePerGas = maxFeePerGas
Expand Down
32 changes: 14 additions & 18 deletions CircleModularWalletsCore/Sources/Accounts/CircleSmartAccount.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ public func toCircleSmartAccount<A: Account>(
return try await .init(client: client, owner: owner, version: version, name: name)
}

public class CircleSmartAccount<A: Account>: SmartAccount where A.T == SignResult {
public class CircleSmartAccount<A: Account>: SmartAccount, @unchecked Sendable where A.T == SignResult {
public let client: Client
public let entryPoint: EntryPoint
let owner: A
let wallet: Wallet
let wallet: ModularWallet
private var deployed: Bool = false
private let nonceManager = NonceManager(source: NonceManagerSourceImpl())

init(client: Client, owner: A, wallet: Wallet, entryPoint: EntryPoint = .v07) {
init(client: Client, owner: A, wallet: ModularWallet, entryPoint: EntryPoint = .v07) {
self.client = client
self.owner = owner
self.wallet = wallet
Expand Down Expand Up @@ -98,11 +98,6 @@ public class CircleSmartAccount<A: Account>: SmartAccount where A.T == SignResul
}
}

// static func create(url: String, apiKey: String, client: Client, owner: A) -> CircleSmartAccount {
// let account = CircleSmartAccount(client: client, owner: owner, wallet: Wallet())
// return account
// }

public func getAddress() -> String {
return wallet.address ?? ""
}
Expand Down Expand Up @@ -270,9 +265,9 @@ extension CircleSmartAccount: PublicRpcApi {
hexPublicKey: String,
version: String,
name: String? = nil
) async throws -> Wallet {
) async throws -> ModularWallet {
let (publicKeyX, publicKeyY) = Self.extractXYFromCOSE(hexPublicKey)
let request = CreateWalletRequest(
let request = GetAddressReq(
scaConfiguration: ScaConfiguration(
initialOwnershipConfiguration: .init(
ownershipContractAddress: nil,
Expand All @@ -288,7 +283,7 @@ extension CircleSmartAccount: PublicRpcApi {
metadata: .init(name: name)
)

let wallet = try await transport.circleGetAddress(transport: transport, req: request)
let wallet = try await transport.getAddress(transport: transport, req: request)

return wallet
}
Expand Down Expand Up @@ -530,13 +525,14 @@ extension CircleSmartAccount: PublicRpcApi {
}

let slicedValue = "0x" + cleanValue[startIndex..<endIndex]

if strict {
guard slicedValue.range(of: "^0x[0-9a-fA-F]*$", options: .regularExpression) != nil else {
logger.passkeyAccount.notice("Invalid hexadecimal string")
return "0x"
}
}

// This block is never executed because the `strict` parameter is always set to its default value (`false`).
// if strict {
// guard slicedValue.range(of: "^0x[0-9a-fA-F]*$", options: .regularExpression) != nil else {
// logger.passkeyAccount.notice("Invalid hexadecimal string")
// return "0x"
// }
// }

return slicedValue
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public func toWebAuthnCredential(
}
}

public struct WebAuthnCredential: RpRpcApi {
public struct WebAuthnCredential: RpRpcApi, Sendable {

/// Credential ID property
public let id: String
Expand Down
8 changes: 4 additions & 4 deletions CircleModularWalletsCore/Sources/Chains/Arbitrum.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@

import Foundation

let Arbitrum = _Arbitrum()
public let Arbitrum = _Arbitrum()

struct _Arbitrum: Chain {
public struct _Arbitrum: Chain {

let chainId: Int = 42161
public let chainId: Int = 42161

let blockchain: String = "ARB"
public let blockchain: String = "ARB"

}
8 changes: 4 additions & 4 deletions CircleModularWalletsCore/Sources/Chains/ArbitrumSepolia.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@

import Foundation

let ArbitrumSepolia = _ArbitrumSepolia()
public let ArbitrumSepolia = _ArbitrumSepolia()

struct _ArbitrumSepolia: Chain {
public struct _ArbitrumSepolia: Chain {

let chainId: Int = 421614
public let chainId: Int = 421614

let blockchain: String = "ARB-SEPOLIA"
public let blockchain: String = "ARB-SEPOLIA"

}
4 changes: 3 additions & 1 deletion CircleModularWalletsCore/Sources/Chains/Chain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@

import Foundation

public protocol Chain {
public protocol Chain: Sendable {

var chainId: Int { get }

var blockchain: String { get }

}
8 changes: 4 additions & 4 deletions CircleModularWalletsCore/Sources/Chains/Mainnet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@

import Foundation

let Mainnet = _Mainnet()
public let Mainnet = _Mainnet()

struct _Mainnet: Chain {
public struct _Mainnet: Chain {

let chainId: Int = 1
public let chainId: Int = 1

let blockchain: String = "ETH"
public let blockchain: String = "ETH"

}
8 changes: 4 additions & 4 deletions CircleModularWalletsCore/Sources/Chains/Polygon.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@

import Foundation

let Polygon = _Polygon()
public let Polygon = _Polygon()

struct _Polygon: Chain {
public struct _Polygon: Chain {

let chainId: Int = 137
public let chainId: Int = 137

let blockchain: String = "MATIC"
public let blockchain: String = "MATIC"

}
8 changes: 4 additions & 4 deletions CircleModularWalletsCore/Sources/Chains/PolygonAmoy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@

import Foundation

let PolygonAmoy = _PolygonAmoy()
public let PolygonAmoy = _PolygonAmoy()

struct _PolygonAmoy: Chain {
public struct _PolygonAmoy: Chain {

let chainId: Int = 80_002
public let chainId: Int = 80_002

let blockchain: String = "MATIC-AMOY"
public let blockchain: String = "MATIC-AMOY"

}
8 changes: 4 additions & 4 deletions CircleModularWalletsCore/Sources/Chains/Sepolia.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@

import Foundation

let Sepolia = _Sepolia()
public let Sepolia = _Sepolia()

struct _Sepolia: Chain {
public struct _Sepolia: Chain {

let chainId: Int = 11155111
public let chainId: Int = 11155111

let blockchain: String = "ETH-SEPOLIA"
public let blockchain: String = "ETH-SEPOLIA"

}
2 changes: 1 addition & 1 deletion CircleModularWalletsCore/Sources/Clients/Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import Foundation

public class Client {
public class Client: @unchecked Sendable {

public let chain: Chain
public let transport: Transport
Expand Down
Loading
Loading