Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔄 synced file(s) with circlefin/modularwallets-ios-sdk-internal #4

Merged
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.2</string>
<string>1.0.3</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleName</key>
Expand Down
2 changes: 1 addition & 1 deletion CircleModularWalletsCore/Sources/Accounts/Account.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ public protocol Account {
func getAddress() -> String
func sign(hex: String) async throws -> T
func signMessage(message: String) async throws -> T
func signTypedData(jsonData: String) async throws -> T
func signTypedData(typedData: String) async throws -> T
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class CircleSmartAccount<A: Account>: SmartAccount where A.T == SignResul
public let entryPoint: EntryPoint
let owner: A
let wallet: Wallet
var deployed: Bool = false

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

public var userOperation: UserOperationConfiguration? {
get async {
let minimumVerificationGasLimit = await self.isDeployed() ?
MINIMUM_VERIFICATION_GAS_LIMIT : MINIMUM_UNDEPLOY_VERIFICATION_GAS_LIMIT

let minimumVerificationGasLimit = SmartAccountUtils.getMinimumVerificationGasLimit(
deployed: await self.isDeployed(),
chainId: client.chain.chainId
)

let config = UserOperationConfiguration { userOperation in
let verificationGasLimit = BigInt(minimumVerificationGasLimit)
let maxGasLimit = max(verificationGasLimit, userOperation.verificationGasLimit ?? BigInt(0))
Expand Down Expand Up @@ -181,7 +184,7 @@ public class CircleSmartAccount<A: Account>: SmartAccount where A.T == SignResul
public func signTypedData(typedData: String) async throws -> String {
guard let typedData = try? EIP712Parser.parse(typedData),
let typedDataHash = try? typedData.signHash() else {
logger.passkeyAccount.error("jsonData signHash failure")
logger.passkeyAccount.error("typedData signHash failure")
throw BaseError(shortMessage: "Failed to hash TypedData: \"\(typedData)\"")
}

Expand Down Expand Up @@ -246,11 +249,13 @@ extension CircleSmartAccount: PublicRpcApi {
// MARK: Internal Usage

private func isDeployed() async -> Bool {
if deployed { return true }
do {
let byteCode = try await getCode(transport: client.transport,
address: getAddress())
let isEmpty = try HexUtils.hexToBytes(hex: byteCode).isEmpty
return !isEmpty
deployed = !isEmpty
return deployed
} catch {
return false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ public struct WebAuthnAccount: Account {
return try await sign(hex: hex)
}

public func signTypedData(jsonData: String) async throws -> SignResult {
guard let typedData = try? EIP712Parser.parse(jsonData),
let hash = try? typedData.signHash() else {
throw BaseError(shortMessage: "Failed to hash TypedData: \"\(jsonData)\"")
public func signTypedData(typedData: String) async throws -> SignResult {
guard let typedDataObj = try? EIP712Parser.parse(typedData),
let hash = try? typedDataObj.signHash() else {
throw BaseError(shortMessage: "Failed to hash TypedData: \"\(typedData)\"")
}

let hex = HexUtils.dataToHex(hash)
Expand Down
29 changes: 29 additions & 0 deletions CircleModularWalletsCore/Sources/Chains/Mainnet.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// Copyright (c) 2024, Circle Internet Group, Inc. All rights reserved.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import Foundation

let Mainnet = _Mainnet()

struct _Mainnet: Chain {

let chainId: Int = 1

let blockchain: String = "ETH"

}
29 changes: 29 additions & 0 deletions CircleModularWalletsCore/Sources/Chains/Sepolia.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// Copyright (c) 2024, Circle Internet Group, Inc. All rights reserved.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import Foundation

let Sepolia = _Sepolia()

struct _Sepolia: Chain {

let chainId: Int = 11155111

let blockchain: String = "ETH-SEPOLIA"

}
8 changes: 8 additions & 0 deletions CircleModularWalletsCore/Sources/Clients/BundlerClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ public class BundlerClient: Client, BundlerRpcApi, PublicRpcApi {
paymaster: Paymaster? = nil,
estimateFeesPerGas: ((SmartAccount, BundlerClient, UserOperationV07) async -> EstimateFeesPerGasResult)? = nil
) async throws -> String? {
if !(partialUserOp.signature?.isEmpty ?? true) {
return try await self.sendUserOperation(
transport: transport,
partialUserOp: partialUserOp,
entryPointAddress: account.entryPoint.address
)
}

let userOp = try await self.prepareUserOperation(
transport: transport,
account: account,
Expand Down
Loading
Loading