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 #5

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
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
Loading