diff --git a/COPYRIGHT b/COPYRIGHT index d2a44e1..0f376a7 100644 --- a/COPYRIGHT +++ b/COPYRIGHT @@ -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 diff --git a/CircleModularWalletsCore/Sources/Accounts/CircleSmartAccount.swift b/CircleModularWalletsCore/Sources/Accounts/CircleSmartAccount.swift index 61acdce..2a029c1 100644 --- a/CircleModularWalletsCore/Sources/Accounts/CircleSmartAccount.swift +++ b/CircleModularWalletsCore/Sources/Accounts/CircleSmartAccount.swift @@ -218,7 +218,7 @@ public class CircleSmartAccount: 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 diff --git a/CircleModularWalletsCore/Sources/Errors/EncodingError.swift b/CircleModularWalletsCore/Sources/Errors/EncodingError.swift new file mode 100644 index 0000000..16a55cf --- /dev/null +++ b/CircleModularWalletsCore/Sources/Errors/EncodingError.swift @@ -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")) + } +} diff --git a/CircleModularWalletsCore/Sources/Helpers/Extensions/KeyedEncodingContainer+Extension.swift b/CircleModularWalletsCore/Sources/Helpers/Extensions/KeyedEncodingContainer+Extension.swift index b864beb..c256cdb 100644 --- a/CircleModularWalletsCore/Sources/Helpers/Extensions/KeyedEncodingContainer+Extension.swift +++ b/CircleModularWalletsCore/Sources/Helpers/Extensions/KeyedEncodingContainer+Extension.swift @@ -23,7 +23,7 @@ extension KeyedEncodingContainer { mutating func encodeBigInt(_ value: BigInt?, forKey key: KeyedEncodingContainer.Key) throws { if let value { - let hexString = HexUtils.bigIntToHex(value) + let hexString = try HexUtils.bigIntToHex(value) try self.encodeIfPresent(hexString, forKey: key) } } diff --git a/CircleModularWalletsCore/Sources/Helpers/Utils/HexUtils.swift b/CircleModularWalletsCore/Sources/Helpers/Utils/HexUtils.swift index 14c5ecd..e01c068 100644 --- a/CircleModularWalletsCore/Sources/Helpers/Utils/HexUtils.swift +++ b/CircleModularWalletsCore/Sources/Helpers/Utils/HexUtils.swift @@ -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 } diff --git a/CircleModularWalletsCore/Sources/Helpers/Utils/Utils.swift b/CircleModularWalletsCore/Sources/Helpers/Utils/Utils.swift index 3334ee0..ab0493c 100644 --- a/CircleModularWalletsCore/Sources/Helpers/Utils/Utils.swift +++ b/CircleModularWalletsCore/Sources/Helpers/Utils/Utils.swift @@ -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 @@ -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 @@ -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 ?? "" diff --git a/LICENSE b/LICENSE index 085faa7..82bc20b 100644 --- a/LICENSE +++ b/LICENSE @@ -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. diff --git a/Package.swift b/Package.swift index 1ea7a66..b2ef996 100644 --- a/Package.swift +++ b/Package.swift @@ -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 //