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

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 COPYRIGHT
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright 2024 Circle Internet Group, Inc. All rights reserved.
Copyright 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
Expand Up @@ -218,7 +218,7 @@ public class CircleSmartAccount<A: Account>: SmartAccount where A.T == SignResul

public func signUserOperation(chainId: Int, userOp: UserOperationV07) async throws -> String {
userOp.sender = getAddress()
let userOpHash = Utils.getUserOperationHash(
let userOpHash = try Utils.getUserOperationHash(
chainId: chainId,
entryPointAddress: EntryPoint.v07.address,
userOp: userOp
Expand Down
24 changes: 24 additions & 0 deletions CircleModularWalletsCore/Sources/Errors/EncodingError.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// Copyright (c) 2025, 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.
//

class IntegerOutOfRangeError: BaseError {
init(cause: BaseError? = nil) {
super.init(shortMessage: "The input value is out of range",
args: BaseErrorParameters(cause: cause, name: "IntegerOutOfRangeError"))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ extension KeyedEncodingContainer {

mutating func encodeBigInt(_ value: BigInt?, forKey key: KeyedEncodingContainer<K>.Key) throws {
if let value {
let hexString = HexUtils.bigIntToHex(value)
let hexString = try HexUtils.bigIntToHex(value)
try self.encodeIfPresent(hexString, forKey: key)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ struct HexUtils {
return BigInt(hex.noHexPrefix, radix: 16)
}

static func bigIntToHex(_ bigInt: BigInt, withPrefix: Bool = true) -> String {
static func bigIntToHex(_ bigInt: BigInt, withPrefix: Bool = true) throws -> String {
if bigInt.sign == .minus {
throw IntegerOutOfRangeError()
}
let hex = BigUInt(bigInt).hexString
return withPrefix ? hex : hex.noHexPrefix
}
Expand Down
14 changes: 7 additions & 7 deletions CircleModularWalletsCore/Sources/Helpers/Utils/Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,15 @@ public struct Utils {
chainId: Int,
entryPointAddress: String = ENTRYPOINT_V07_ADDRESS,
userOp: UserOperationV07
) -> String {
) throws -> String {

var accountGasLimits = [UInt8]()
if let verificationGasLimit = userOp.verificationGasLimit,
let callGasLimit = userOp.callGasLimit {

let verificationGasLimitHex = HexUtils.bigIntToHex(verificationGasLimit, withPrefix: false)
let verificationGasLimitHex = try HexUtils.bigIntToHex(verificationGasLimit, withPrefix: false)
let verificationGasLimitHexWithPadding = verificationGasLimitHex.leftPadding(toLength: 32, withPad: "0")
let callGasLimitHex = HexUtils.bigIntToHex(callGasLimit, withPrefix: false)
let callGasLimitHex = try HexUtils.bigIntToHex(callGasLimit, withPrefix: false)
let callGasLimitHexWithPadding = callGasLimitHex.leftPadding(toLength: 32, withPad: "0")
let finalHex = verificationGasLimitHexWithPadding + callGasLimitHexWithPadding

Expand All @@ -134,9 +134,9 @@ public struct Utils {
if let maxPriorityFeePerGas = userOp.maxPriorityFeePerGas,
let maxFeePerGas = userOp.maxFeePerGas {

let maxPriorityFeePerGasHex = HexUtils.bigIntToHex(maxPriorityFeePerGas, withPrefix: false)
let maxPriorityFeePerGasHex = try HexUtils.bigIntToHex(maxPriorityFeePerGas, withPrefix: false)
let maxPriorityFeePerGasHexWithPadding = maxPriorityFeePerGasHex.leftPadding(toLength: 32, withPad: "0")
let maxFeePerGasHex = HexUtils.bigIntToHex(maxFeePerGas, withPrefix: false)
let maxFeePerGasHex = try HexUtils.bigIntToHex(maxFeePerGas, withPrefix: false)
let maxFeePerGasHexWithPadding = maxFeePerGasHex.leftPadding(toLength: 32, withPad: "0")
let finalHex = maxPriorityFeePerGasHexWithPadding + maxFeePerGasHexWithPadding

Expand All @@ -161,11 +161,11 @@ public struct Utils {
if let paymaster = userOp.paymaster {

let paymasterVerificationGasLimit = userOp.paymasterVerificationGasLimit ?? BigInt.zero
let verificationGasLimitHex = HexUtils.bigIntToHex(paymasterVerificationGasLimit, withPrefix: false)
let verificationGasLimitHex = try HexUtils.bigIntToHex(paymasterVerificationGasLimit, withPrefix: false)
let verificationGasLimitHexWithPadding = verificationGasLimitHex.leftPadding(toLength: 32, withPad: "0")

let paymasterPostOpGasLimit = userOp.paymasterPostOpGasLimit ?? BigInt.zero
let postOpGasLimitHex = HexUtils.bigIntToHex(paymasterPostOpGasLimit, withPrefix: false)
let postOpGasLimitHex = try HexUtils.bigIntToHex(paymasterPostOpGasLimit, withPrefix: false)
let postOpGasLimitHexWithPadding = postOpGasLimitHex.leftPadding(toLength: 32, withPad: "0")

let paymasterData = userOp.paymasterData?.noHexPrefix ?? ""
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@

END OF TERMS AND CONDITIONS

© 2024, Circle Internet Financial, LTD. All rights reserved.
© 2025, Circle Internet Financial, LTD. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// swift-tools-version: 5.7
//
// Copyright (c) 2024, Circle Internet Financial, LTD. All rights reserved.
// Copyright (c) 2025, Circle Internet Financial, LTD. All rights reserved.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down
Loading