Skip to content

Commit

Permalink
🔄 synced file(s) with circlefin/modularwallets-ios-sdk-internal (#4)
Browse files Browse the repository at this point in the history
synced local file(s) with
[circlefin/modularwallets-ios-sdk-internal](https://github.com/circlefin/modularwallets-ios-sdk-internal).



<details>
<summary>Changed files</summary>
<ul>
<li>synced local directory <code>CircleModularWalletsCore/</code> with
remote directory <code>CircleModularWalletsCore/</code></li><li>synced
local <code>./SECURITY.md</code> with remote
<code>./SECURITY.md</code></li>
</ul>
</details>

---

This PR was created automatically by the
[repo-file-sync-action](https://github.com/BetaHuhn/repo-file-sync-action)
workflow run
[#12311614082](https://github.com/circlefin/modularwallets-ios-sdk-internal/actions/runs/12311614082)
  • Loading branch information
circle-github-action-bot authored Dec 13, 2024
1 parent 3339382 commit 0a0c88c
Show file tree
Hide file tree
Showing 13 changed files with 399 additions and 43 deletions.
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

0 comments on commit 0a0c88c

Please sign in to comment.