@@ -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 }
0 commit comments