Skip to content

Commit

Permalink
🔄 synced file(s) with circlefin/modularwallets-ios-sdk-internal (#5)
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>
</ul>
</details>

---

This PR was created automatically by the
[repo-file-sync-action](https://github.com/BetaHuhn/repo-file-sync-action)
workflow run
[#12424259975](https://github.com/circlefin/modularwallets-ios-sdk-internal/actions/runs/12424259975)
  • Loading branch information
circle-github-action-bot authored Dec 20, 2024
1 parent 0a0c88c commit c1bd6f8
Show file tree
Hide file tree
Showing 76 changed files with 253 additions and 107 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2024, Circle Internet Group, Inc. All rights reserved.
// Copyright (c) 2025, Circle Internet Group, Inc. All rights reserved.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down
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.3</string>
<string>1.0.4</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleName</key>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2024, Circle Internet Group, Inc. All rights reserved.
// Copyright (c) 2025, Circle Internet Group, Inc. All rights reserved.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2024, Circle Internet Group, Inc. All rights reserved.
// Copyright (c) 2025, Circle Internet Group, Inc. All rights reserved.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2024, Circle Internet Group, Inc. All rights reserved.
// Copyright (c) 2025, Circle Internet Group, Inc. All rights reserved.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2024, Circle Internet Group, Inc. All rights reserved.
// Copyright (c) 2025, Circle Internet Group, Inc. All rights reserved.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand All @@ -20,6 +20,7 @@ import Foundation

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

public struct CreateWalletResponse: Decodable {
Expand Down Expand Up @@ -78,3 +79,7 @@ struct ScaConfiguration: Codable {
}
}
}

struct Metadata: Codable {
let name: String?
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2024, Circle Internet Group, Inc. All rights reserved.
// Copyright (c) 2025, Circle Internet Group, Inc. All rights reserved.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2024, Circle Internet Group, Inc. All rights reserved.
// Copyright (c) 2025, Circle Internet Group, Inc. All rights reserved.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2024, Circle Internet Group, Inc. All rights reserved.
// Copyright (c) 2025, Circle Internet Group, Inc. All rights reserved.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -57,7 +57,7 @@ protocol PublicRpcApi {
/// - Returns: EstimateFeesPerGasResult
func estimateFeesPerGas(transport: Transport, feeValuesType: FeeValuesType) async throws -> EstimateFeesPerGasResult

/** Returns the current price of gas (in wei) */
/// Returns the current price of gas (in wei)
func getGasPrice(transport: Transport) async throws -> BigInt
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2024, Circle Internet Group, Inc. All rights reserved.
// Copyright (c) 2025, Circle Internet Group, Inc. All rights reserved.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down
2 changes: 1 addition & 1 deletion CircleModularWalletsCore/Sources/APIs/Rp/RpRpcApi.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2024, Circle Internet Group, Inc. All rights reserved.
// Copyright (c) 2025, Circle Internet Group, Inc. All rights reserved.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2024, Circle Internet Group, Inc. All rights reserved.
// Copyright (c) 2025, Circle Internet Group, Inc. All rights reserved.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down
2 changes: 1 addition & 1 deletion CircleModularWalletsCore/Sources/Accounts/Account.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2024, Circle Internet Group, Inc. All rights reserved.
// Copyright (c) 2025, Circle Internet Group, Inc. All rights reserved.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2024, Circle Internet Group, Inc. All rights reserved.
// Copyright (c) 2025, Circle Internet Group, Inc. All rights reserved.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand All @@ -21,18 +21,21 @@ import BigInt
import Web3Core
import web3swift

public func toCircleSmartAccount<A: Account>(client: Client,
owner: A,
version: String = "") async throws -> CircleSmartAccount<A> where A.T == SignResult {
try await .init(client: client, owner: owner)
public func toCircleSmartAccount<A: Account>(
client: Client,
owner: A,
version: String = "circle_6900_v1"
) async throws -> CircleSmartAccount<A> where A.T == SignResult {
try await .init(client: client, owner: owner, version: version)
}

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

init(client: Client, owner: A, wallet: Wallet, entryPoint: EntryPoint = .v07) {
self.client = client
Expand All @@ -41,32 +44,21 @@ public class CircleSmartAccount<A: Account>: SmartAccount where A.T == SignResul
self.entryPoint = entryPoint
}

convenience init(client: Client, owner: A) async throws {
convenience init(client: Client, owner: A, version: String) async throws {
guard let buidlTransport = client.transport as? ModularTransport else {
throw BaseError(shortMessage: "The property client.transport is not the ModularTransport")
}
guard let webAuthnAccount = owner as? WebAuthnAccount else {
throw BaseError(shortMessage: "The property owner is not the WebAuthnAccount")
}

let (publicKeyX, publicKeyY) = Self.extractXYFromCOSE(webAuthnAccount.credential.publicKey)
let request = CreateWalletRequest(
scaConfiguration: ScaConfiguration(
initialOwnershipConfiguration: .init(
ownershipContractAddress: nil,
weightedMultiSig: .init(
owners: nil,
webauthnOwners: [.init(publicKeyX: publicKeyX.description,
publicKeyY: publicKeyY.description,
weight: PUBLIC_KEY_OWN_WEIGHT)],
thresholdWeight: THRESHOLD_WEIGHT)
),
scaCore: "circle_6900_v1",
initCode: nil)
let wallet = try await Self.createWallet(
transport: buidlTransport,
hexPublicKey: webAuthnAccount.credential.publicKey,
version: version,
name: webAuthnAccount.credential.userName
)

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

self.init(client: client, owner: owner, wallet: wallet)
}

Expand Down Expand Up @@ -118,9 +110,20 @@ public class CircleSmartAccount<A: Account>: SmartAccount where A.T == SignResul
}

public func getNonce(key: BigInt?) async throws -> BigInt {
return try await Utils.getNonce(transport: client.transport,
address: getAddress(),
entryPoint: entryPoint)
let _key = key ?? nonceManager.consume(
params: FunctionParameters(address: getAddress(),
chainId: client.chain.chainId)
)

guard _key >= BigInt(0) else {
throw BaseError(shortMessage: "Cannot convert negative BigInt(\(_key) to BigUInt")
}

let nonce = try await Utils.getNonce(transport: client.transport,
address: getAddress(),
entryPoint: entryPoint,
key: BigUInt(_key))
return nonce
}

public func getStubSignature<T: UserOperation>(userOp: T) -> String {
Expand Down Expand Up @@ -248,6 +251,34 @@ extension CircleSmartAccount: PublicRpcApi {

// MARK: Internal Usage

static func createWallet(
transport: ModularTransport,
hexPublicKey: String,
version: String,
name: String? = nil
) async throws -> Wallet {
let (publicKeyX, publicKeyY) = Self.extractXYFromCOSE(hexPublicKey)
let request = CreateWalletRequest(
scaConfiguration: ScaConfiguration(
initialOwnershipConfiguration: .init(
ownershipContractAddress: nil,
weightedMultiSig: .init(
owners: nil,
webauthnOwners: [.init(publicKeyX: publicKeyX.description,
publicKeyY: publicKeyY.description,
weight: PUBLIC_KEY_OWN_WEIGHT)],
thresholdWeight: THRESHOLD_WEIGHT)
),
scaCore: version,
initCode: nil),
metadata: .init(name: name)
)

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

return wallet
}

private func isDeployed() async -> Bool {
if deployed { return true }
do {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2024, Circle Internet Group, Inc. All rights reserved.
// Copyright (c) 2025, Circle Internet Group, Inc. All rights reserved.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2024, Circle Internet Group, Inc. All rights reserved.
// Copyright (c) 2025, Circle Internet Group, Inc. All rights reserved.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2024, Circle Internet Group, Inc. All rights reserved.
// Copyright (c) 2025, Circle Internet Group, Inc. All rights reserved.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -67,6 +67,9 @@ public struct WebAuthnCredential: RpRpcApi {
/// Relying party identifier
public let rpId: String

/// User name
public var userName: String? = nil

static func register(transport: Transport,
userName: String) async throws -> WebAuthnCredential {
do {
Expand Down Expand Up @@ -101,7 +104,8 @@ public struct WebAuthnCredential: RpRpcApi {
return WebAuthnCredential(id: credential.id,
publicKey: serializedPublicKey,
raw: credential,
rpId: option.relyingParty.id)
rpId: option.relyingParty.id,
userName: userName)
} catch let error as BaseError {
throw error
} catch {
Expand Down
2 changes: 1 addition & 1 deletion CircleModularWalletsCore/Sources/Chains/Chain.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2024, Circle Internet Group, Inc. All rights reserved.
// Copyright (c) 2025, Circle Internet Group, Inc. All rights reserved.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down
2 changes: 1 addition & 1 deletion CircleModularWalletsCore/Sources/Chains/Mainnet.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2024, Circle Internet Group, Inc. All rights reserved.
// Copyright (c) 2025, Circle Internet Group, Inc. All rights reserved.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down
2 changes: 1 addition & 1 deletion CircleModularWalletsCore/Sources/Chains/Sepolia.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2024, Circle Internet Group, Inc. All rights reserved.
// Copyright (c) 2025, Circle Internet Group, Inc. All rights reserved.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2024, Circle Internet Group, Inc. All rights reserved.
// Copyright (c) 2025, Circle Internet Group, Inc. All rights reserved.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down
2 changes: 1 addition & 1 deletion CircleModularWalletsCore/Sources/Clients/Client.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2024, Circle Internet Group, Inc. All rights reserved.
// Copyright (c) 2025, Circle Internet Group, Inc. All rights reserved.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2024, Circle Internet Group, Inc. All rights reserved.
// Copyright (c) 2025, Circle Internet Group, Inc. All rights reserved.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down
2 changes: 1 addition & 1 deletion CircleModularWalletsCore/Sources/Errors/BaseError.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2024, Circle Internet Group, Inc. All rights reserved.
// Copyright (c) 2025, Circle Internet Group, Inc. All rights reserved.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2024, Circle Internet Group, Inc. All rights reserved.
// Copyright (c) 2025, Circle Internet Group, Inc. All rights reserved.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2024, Circle Internet Group, Inc. All rights reserved.
// Copyright (c) 2025, Circle Internet Group, Inc. All rights reserved.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2024, Circle Internet Group, Inc. All rights reserved.
// Copyright (c) 2025, Circle Internet Group, Inc. All rights reserved.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2024, Circle Internet Group, Inc. All rights reserved.
// Copyright (c) 2025, Circle Internet Group, Inc. All rights reserved.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down
2 changes: 1 addition & 1 deletion CircleModularWalletsCore/Sources/Errors/RpcErrors.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2024, Circle Internet Group, Inc. All rights reserved.
// Copyright (c) 2025, Circle Internet Group, Inc. All rights reserved.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2024, Circle Internet Group, Inc. All rights reserved.
// Copyright (c) 2025, Circle Internet Group, Inc. All rights reserved.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2024, Circle Internet Group, Inc. All rights reserved.
// Copyright (c) 2025, Circle Internet Group, Inc. All rights reserved.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down
Loading

0 comments on commit c1bd6f8

Please sign in to comment.