Skip to content

Commit 76f0ad6

Browse files
🔄 synced local 'CircleModularWalletsCore/' with remote 'CircleModularWalletsCore/'
1 parent 8b6b81d commit 76f0ad6

File tree

7 files changed

+95
-47
lines changed

7 files changed

+95
-47
lines changed

‎CircleModularWalletsCore/Resources/Info.plist‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<plist version="1.0">
44
<dict>
55
<key>CFBundleShortVersionString</key>
6-
<string>1.1.0</string>
6+
<string>1.1.1</string>
77
<key>CFBundleIdentifier</key>
88
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
99
<key>CFBundleName</key>

‎CircleModularWalletsCore/Sources/Accounts/Account.swift‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,23 @@ public protocol Account {
2828
/// - Returns: The address of the account.
2929
func getAddress() -> String
3030

31-
/// Signs the given hex data.
31+
/// Signs a given hash.
3232
///
3333
/// - Parameters:
34-
/// - hex: The hex data to sign.
34+
/// - messageHash: The hash to sign.
3535
///
3636
/// - Returns: The signed data of type `T`.
37-
func sign(hex: String) async throws -> T
37+
func sign(messageHash: String) async throws -> T
3838

39-
/// Signs the given message.
39+
/// Signs a given message.
4040
///
4141
/// - Parameters:
4242
/// - message: The message to sign.
4343
///
4444
/// - Returns: The signed message of type `T`.
4545
func signMessage(message: String) async throws -> T
4646

47-
/// Signs the given typed data.
47+
/// Signs a given typed data.
4848
///
4949
/// - Parameters:
5050
/// - typedData: The typed data to sign.

‎CircleModularWalletsCore/Sources/Accounts/CircleSmartAccount.swift‎

Lines changed: 73 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,29 @@ public class CircleSmartAccount<A: Account>: SmartAccount, @unchecked Sendable w
105105
}
106106
}
107107

108+
/// Returns the address of the account.
109+
///
110+
/// - Returns: The address of the smart account.
108111
public func getAddress() -> String {
109112
return wallet.address ?? ""
110113
}
111114

115+
/// Encodes the given call data arguments.
116+
///
117+
/// - Parameters:
118+
/// - args: The call data arguments to encode.
119+
///
120+
/// - Returns: The encoded call data.
112121
public func encodeCalls(args: [EncodeCallDataArg]) -> String? {
113122
return Utils.encodeCallData(args: args)
114123
}
115124

125+
/// Encodes the given call data arguments.
126+
///
127+
/// - Parameters:
128+
/// - args: The call data arguments to encode.
129+
///
130+
/// - Returns: The encoded call data.
116131
public func getFactoryArgs() async throws -> (String, String)? {
117132
if await isDeployed() {
118133
return nil
@@ -125,6 +140,12 @@ public class CircleSmartAccount<A: Account>: SmartAccount, @unchecked Sendable w
125140
return Utils.parseFactoryAddressAndData(initCode: initCode)
126141
}
127142

143+
/// Returns the nonce for the Circle smart account.
144+
///
145+
/// - Parameters:
146+
/// - key: An optional key to retrieve the nonce for.
147+
///
148+
/// - Returns: The nonce of the Circle smart account.
128149
public func getNonce(key: BigInt?) async throws -> BigInt {
129150
let _key: BigInt
130151
if let key = key {
@@ -153,20 +174,31 @@ public class CircleSmartAccount<A: Account>: SmartAccount, @unchecked Sendable w
153174
return nonce
154175
}
155176

177+
/// Returns the stub signature for the given user operation.
178+
///
179+
/// - Parameters:
180+
/// - userOp: The user operation to retrieve the stub signature for. The type `T` must be a subclass of `UserOperation`.
181+
///
182+
/// - Returns: The stub signature.
156183
public func getStubSignature<T: UserOperation>(userOp: T) -> String {
157184
return STUB_SIGNATURE
158185
}
159186

160-
public func sign(hex: String) async throws -> String {
161-
let digest = Utils.toSha3Data(message: hex)
162-
let hash = try await Utils.getReplaySafeMessageHash(
187+
/// Signs a hash via the Smart Account's owner.
188+
///
189+
/// - Parameters:
190+
/// - messageHash: The hash to sign.
191+
///
192+
/// - Returns: The signed data.
193+
public func sign(messageHash: String) async throws -> String {
194+
let replaySafeMessageHash = try await Utils.getReplaySafeMessageHash(
163195
transport: client.transport,
164196
account: getAddress(),
165-
hash: HexUtils.dataToHex(digest)
197+
hash: messageHash
166198
)
167199

168200
do {
169-
let signResult = try await owner.sign(hex: hash)
201+
let signResult = try await owner.sign(messageHash: replaySafeMessageHash)
170202
let signature = encodePackedForSignature(
171203
signResult: signResult,
172204
publicKey: owner.getAddress(),
@@ -176,27 +208,31 @@ public class CircleSmartAccount<A: Account>: SmartAccount, @unchecked Sendable w
176208
} catch let error as BaseError {
177209
throw error
178210
} catch {
179-
throw BaseError(shortMessage: "CircleSmartAccount.owner.sign(hex: \"\(hash)\") failure",
211+
throw BaseError(shortMessage: "CircleSmartAccount.owner.sign(hash: \"\(replaySafeMessageHash)\") failure",
180212
args: .init(cause: error, name: String(describing: error)))
181213
}
182214
}
183215

216+
/// Signs a [EIP-191 Personal Sign message](https://eips.ethereum.org/EIPS/eip-191).
217+
///
218+
/// - Parameters:
219+
/// - message: The message to sign.
220+
///
221+
/// - Returns: The signed message.
184222
public func signMessage(message: String) async throws -> String {
185-
guard let messageHash = Utilities.hashPersonalMessage(Data(message.utf8)) else {
223+
guard let hashedMessageData = Utilities.hashPersonalMessage(Data(message.utf8)) else {
186224
throw BaseError(shortMessage: "Failed to hash message: \"\(message)\"")
187225
}
188226

189-
let messageHashHex = HexUtils.dataToHex(messageHash)
190-
191-
let digest = Utils.toSha3Data(message: messageHashHex)
192-
let hash = try await Utils.getReplaySafeMessageHash(
227+
let hashedMessage = HexUtils.dataToHex(hashedMessageData)
228+
let replaySafeMessageHash = try await Utils.getReplaySafeMessageHash(
193229
transport: client.transport,
194230
account: getAddress(),
195-
hash: HexUtils.dataToHex(digest)
231+
hash: hashedMessage
196232
)
197233

198234
do {
199-
let signResult = try await owner.sign(hex: hash)
235+
let signResult = try await owner.sign(messageHash: replaySafeMessageHash)
200236
let signature = encodePackedForSignature(
201237
signResult: signResult,
202238
publicKey: owner.getAddress(),
@@ -206,29 +242,33 @@ public class CircleSmartAccount<A: Account>: SmartAccount, @unchecked Sendable w
206242
} catch let error as BaseError {
207243
throw error
208244
} catch {
209-
throw BaseError(shortMessage: "CircleSmartAccount.owner.sign(hex: \"\(hash)\") failure",
245+
throw BaseError(shortMessage: "CircleSmartAccount.owner.sign(hash: \"\(replaySafeMessageHash)\") failure",
210246
args: .init(cause: error, name: String(describing: error)))
211247
}
212248
}
213249

250+
/// Signs a given typed data.
251+
///
252+
/// - Parameters:
253+
/// - typedData: The typed data to sign.
254+
///
255+
/// - Returns: The signed typed data.
214256
public func signTypedData(typedData: String) async throws -> String {
215257
guard let typedData = try? EIP712Parser.parse(typedData),
216-
let typedDataHash = try? typedData.signHash() else {
258+
let hashedTypedDataData = try? typedData.signHash() else {
217259
logger.passkeyAccount.error("typedData signHash failure")
218260
throw BaseError(shortMessage: "Failed to hash TypedData: \"\(typedData)\"")
219261
}
220262

221-
let typedDataHashHex = HexUtils.dataToHex(typedDataHash)
222-
223-
let digest = Utils.toSha3Data(message: typedDataHashHex)
224-
let hash = try await Utils.getReplaySafeMessageHash(
263+
let hashedTypedData = HexUtils.dataToHex(hashedTypedDataData)
264+
let replaySafeMessageHash = try await Utils.getReplaySafeMessageHash(
225265
transport: client.transport,
226266
account: getAddress(),
227-
hash: HexUtils.dataToHex(digest)
267+
hash: hashedTypedData
228268
)
229269

230270
do {
231-
let signResult = try await owner.sign(hex: hash)
271+
let signResult = try await owner.sign(messageHash: replaySafeMessageHash)
232272
let signature = encodePackedForSignature(
233273
signResult: signResult,
234274
publicKey: owner.getAddress(),
@@ -238,11 +278,18 @@ public class CircleSmartAccount<A: Account>: SmartAccount, @unchecked Sendable w
238278
} catch let error as BaseError {
239279
throw error
240280
} catch {
241-
throw BaseError(shortMessage: "CircleSmartAccount.owner.sign(hex: \"\(hash)\") failure",
281+
throw BaseError(shortMessage: "CircleSmartAccount.owner.sign(hash: \"\(replaySafeMessageHash)\") failure",
242282
args: .init(cause: error, name: String(describing: error)))
243283
}
244284
}
245285

286+
/// Signs a given user operation.
287+
///
288+
/// - Parameters:
289+
/// - chainId: The chain ID for the user operation. Default is the chain ID of the client.
290+
/// - userOp: The user operation to sign.
291+
///
292+
/// - Returns: The signed user operation.
246293
public func signUserOperation(chainId: Int, userOp: UserOperationV07) async throws -> String {
247294
userOp.sender = getAddress()
248295
let userOpHash = try Utils.getUserOperationHash(
@@ -254,7 +301,7 @@ public class CircleSmartAccount<A: Account>: SmartAccount, @unchecked Sendable w
254301
let hash = Utils.hashMessage(hex: userOpHash)
255302

256303
do {
257-
let signResult = try await owner.sign(hex: hash)
304+
let signResult = try await owner.sign(messageHash: hash)
258305
let signature = encodePackedForSignature(
259306
signResult: signResult,
260307
publicKey: owner.getAddress(),
@@ -269,6 +316,9 @@ public class CircleSmartAccount<A: Account>: SmartAccount, @unchecked Sendable w
269316
}
270317
}
271318

319+
/// Returns the initialization code for the Circle smart account.
320+
///
321+
/// - Returns: The initialization code.
272322
public func getInitCode() -> String? {
273323
return wallet.getInitCode()
274324
}

‎CircleModularWalletsCore/Sources/Accounts/SmartAccount.swift‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,31 +68,31 @@ public protocol SmartAccount {
6868
/// - Returns: The stub signature.
6969
func getStubSignature<T: UserOperation>(userOp: T) -> String
7070

71-
/// Signs the given hex data.
71+
/// Signs a hash via the Smart Account's owner.
7272
///
7373
/// - Parameters:
74-
/// - hex: The hex data to sign.
74+
/// - messageHash: The hash to sign.
7575
///
7676
/// - Returns: The signed data.
77-
func sign(hex: String) async throws -> String
77+
func sign(messageHash: String) async throws -> String
7878

79-
/// Signs the given message.
79+
/// Signs a [EIP-191 Personal Sign message](https://eips.ethereum.org/EIPS/eip-191).
8080
///
8181
/// - Parameters:
8282
/// - message: The message to sign.
8383
///
8484
/// - Returns: The signed message.
8585
func signMessage(message: String) async throws -> String
8686

87-
/// Signs the given typed data.
87+
/// Signs a given typed data.
8888
///
8989
/// - Parameters:
9090
/// - typedData: The typed data to sign.
9191
///
9292
/// - Returns: The signed typed data.
9393
func signTypedData(typedData: String) async throws -> String
9494

95-
/// Signs the given user operation.
95+
/// Signs a given user operation.
9696
///
9797
/// - Parameters:
9898
/// - chainId: The chain ID for the user operation. Default is the chain ID of the client.

‎CircleModularWalletsCore/Sources/Accounts/WebAuthnAccount.swift‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,20 @@ public struct WebAuthnAccount: Account {
4444
return credential.publicKey
4545
}
4646

47-
/// Signs the given hex data.
47+
/// Signs a given hash.
4848
///
4949
/// - Parameters:
50-
/// - hex: The hex data to sign.
50+
/// - messageHash: The hash to sign.
5151
///
5252
/// - Returns: The result of the signing operation.
5353
/// - Throws: A `BaseError` if the credential request fails.
54-
public func sign(hex: String) async throws -> SignResult {
54+
public func sign(messageHash: String) async throws -> SignResult {
5555
do {
5656
/// Step 1. Get RequestOptions
5757
let option = try WebAuthnUtils.getRequestOption(
5858
rpId: credential.rpId,
5959
allowCredentialId: credential.id,
60-
hex: hex)
60+
hex: messageHash)
6161

6262
/// Step 2. Get credential
6363
let credential = try await WebAuthnHandler.shared.signInWith(option: option)
@@ -95,7 +95,7 @@ public struct WebAuthnAccount: Account {
9595
}
9696
}
9797

98-
/// Signs the given message.
98+
/// Signs a given message.
9999
///
100100
/// - Parameters:
101101
/// - message: The message to sign.
@@ -108,10 +108,10 @@ public struct WebAuthnAccount: Account {
108108
}
109109

110110
let hex = HexUtils.dataToHex(hash)
111-
return try await sign(hex: hex)
111+
return try await sign(messageHash: hex)
112112
}
113113

114-
/// Signs the given typed data.
114+
/// Signs a given typed data.
115115
///
116116
/// - Parameters:
117117
/// - typedData: The typed data to sign.
@@ -125,7 +125,7 @@ public struct WebAuthnAccount: Account {
125125
}
126126

127127
let hex = HexUtils.dataToHex(hash)
128-
return try await sign(hex: hex)
128+
return try await sign(messageHash: hex)
129129
}
130130
}
131131

‎CircleModularWalletsCore/Sources/Helpers/Extensions/Bundle+Extension.swift‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import Foundation
2121
#if SWIFT_PACKAGE
2222
extension Bundle {
2323
public enum SDK {
24-
public static let version = "1.1.0"
24+
public static let version = "1.1.1"
2525
}
2626
}
2727
#else

‎CircleModularWalletsCore/Sources/Helpers/Utils/Utils.swift‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -815,12 +815,10 @@ extension Utils {
815815

816816
static func isValidSignature(
817817
transport: Transport,
818-
message: String,
818+
digest: String,
819819
signature: String,
820820
walletAddress: String
821821
) async -> Bool {
822-
let digest = toSha3Data(message: message)
823-
824822
let functionName = "isValidSignature"
825823
let input1 = InOut(name: "digest", type: .bytes(length: 32))
826824
let input2 = InOut(name: "signature", type: .dynamicBytes)

0 commit comments

Comments
 (0)