Skip to content

Commit e07d2ed

Browse files
🔄 synced file(s) with circlefin/modularwallets-android-sdk-internal (#7)
synced local file(s) with [circlefin/modularwallets-android-sdk-internal](https://github.com/circlefin/modularwallets-android-sdk-internal). <details> <summary>Changed files</summary> <ul> <li>synced local directory <code>./lib/</code> with remote directory <code>./lib/</code></li> </ul> </details> --- This PR was created automatically by the [repo-file-sync-action](https://github.com/BetaHuhn/repo-file-sync-action) workflow run [#14608415960](https://github.com/circlefin/modularwallets-android-sdk-internal/actions/runs/14608415960)
1 parent 987ec70 commit e07d2ed

File tree

6 files changed

+41
-46
lines changed

6 files changed

+41
-46
lines changed

‎lib/src/main/java/com/circle/modularwallets/core/accounts/Account.kt‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,16 @@ abstract class Account<T> {
3535
abstract fun getAddress(): String
3636

3737
/**
38-
* Signs the given hex data.
38+
* Signs a given hash
3939
*
4040
* @param context The context in which the signing operation is performed.
41-
* @param hex The hex data to sign.
41+
* @param messageHash The hash to sign.
4242
* @return The signed data of type T.
4343
*/
44-
abstract suspend fun sign(context: Context, hex: String): T
44+
abstract suspend fun sign(context: Context, messageHash: String): T
4545

4646
/**
47-
* Signs the given message.
47+
* Signs a given message.
4848
*
4949
* @param context The context in which the signing operation is performed.
5050
* @param message The message to sign.
@@ -53,7 +53,7 @@ abstract class Account<T> {
5353
abstract suspend fun signMessage(context: Context, message: String): T
5454

5555
/**
56-
* Signs the given typed data.
56+
* Signs a given typed data.
5757
*
5858
* @param context The context in which the signing operation is performed.
5959
* @param typedData The typed data to sign.

‎lib/src/main/java/com/circle/modularwallets/core/accounts/CircleSmartAccount.kt‎

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,8 @@ import com.circle.modularwallets.core.clients.Client
3232
import com.circle.modularwallets.core.constants.CIRCLE_SMART_ACCOUNT_VERSION
3333
import com.circle.modularwallets.core.constants.CIRCLE_SMART_ACCOUNT_VERSION_V1
3434
import com.circle.modularwallets.core.constants.CIRCLE_WEIGHTED_WEB_AUTHN_MULTISIG_PLUGIN
35-
import com.circle.modularwallets.core.constants.EIP712_PREFIX
3635
import com.circle.modularwallets.core.constants.FACTORY
3736
import com.circle.modularwallets.core.constants.PUBLIC_KEY_OWN_WEIGHT
38-
import com.circle.modularwallets.core.constants.REPLAY_SAFE_HASH_V1
3937
import com.circle.modularwallets.core.constants.SALT
4038
import com.circle.modularwallets.core.constants.STUB_SIGNATURE
4139
import com.circle.modularwallets.core.constants.THRESHOLD_WEIGHT
@@ -52,13 +50,9 @@ import com.circle.modularwallets.core.utils.NonceManagerSource
5250
import com.circle.modularwallets.core.utils.abi.encodeAbiParameters
5351
import com.circle.modularwallets.core.utils.abi.encodeCallData
5452
import com.circle.modularwallets.core.utils.abi.encodePacked
55-
import com.circle.modularwallets.core.utils.data.concat
5653
import com.circle.modularwallets.core.utils.data.pad
5754
import com.circle.modularwallets.core.utils.data.slice
58-
import com.circle.modularwallets.core.utils.encoding.bytesToHex
5955
import com.circle.modularwallets.core.utils.encoding.stringToHex
60-
import com.circle.modularwallets.core.utils.encoding.toBytes
61-
import com.circle.modularwallets.core.utils.encoding.toSha3Bytes
6256
import com.circle.modularwallets.core.utils.signature.hashMessage
6357
import com.circle.modularwallets.core.utils.signature.hashTypedData
6458
import com.circle.modularwallets.core.utils.signature.parseP256Signature
@@ -74,7 +68,6 @@ import org.web3j.abi.datatypes.DynamicBytes
7468
import org.web3j.abi.datatypes.DynamicStruct
7569
import org.web3j.abi.datatypes.StaticStruct
7670
import org.web3j.abi.datatypes.Type
77-
import org.web3j.abi.datatypes.Utf8String
7871
import org.web3j.abi.datatypes.generated.Bytes32
7972
import org.web3j.abi.datatypes.generated.Uint256
8073
import org.web3j.abi.datatypes.generated.Uint8
@@ -276,18 +269,17 @@ class CircleSmartAccount(
276269
}
277270

278271
/**
279-
* Signs the given hex data.
272+
* Signs a hash via the Smart Account's owner.
280273
*
281274
* @param context The context used to launch framework UI flows ; use an activity context to make sure the UI will be launched within the same task stack.
282-
* @param hex The hex data to sign.
275+
* @param messageHash The hash to sign.
283276
* @return The signed data.
284277
*/
285278
@ExcludeFromGeneratedCCReport
286279
@Throws(Exception::class)
287-
override suspend fun sign(context: Context, hex: String): String {
288-
val digest = toSha3Bytes(hex)
289-
val hash = UtilApiImpl.getReplaySafeMessageHash(client.transport, getAddress(), bytesToHex(digest))
290-
val signResult = owner.sign(context, hash)
280+
override suspend fun sign(context: Context, messageHash: String): String {
281+
val replaySafeMessageHash = UtilApiImpl.getReplaySafeMessageHash(client.transport, getAddress(), messageHash)
282+
val signResult = owner.sign(context, replaySafeMessageHash)
291283
val signature = encodePackedForSignature(
292284
signResult,
293285
owner.getAddress(),
@@ -297,7 +289,7 @@ class CircleSmartAccount(
297289
}
298290

299291
/**
300-
* Signs the given message.
292+
* Signs a [EIP-191 Personal Sign message](https://eips.ethereum.org/EIPS/eip-191).
301293
*
302294
* @param context The context used to launch framework UI flows ; use an activity context to make sure the UI will be launched within the same task stack.
303295
* @param message The message to sign.
@@ -306,9 +298,9 @@ class CircleSmartAccount(
306298
@ExcludeFromGeneratedCCReport
307299
@Throws(Exception::class)
308300
override suspend fun signMessage(context: Context, message: String): String {
309-
val digest = toSha3Bytes(hashMessage(message.toByteArray()))
310-
val hash = UtilApiImpl.getReplaySafeMessageHash(client.transport, getAddress(), bytesToHex(digest))
311-
val signResult = owner.sign(context, hash)
301+
val hashedMessage = hashMessage(message.toByteArray())
302+
val replaySafeMessageHash = UtilApiImpl.getReplaySafeMessageHash(client.transport, getAddress(), hashedMessage)
303+
val signResult = owner.sign(context, replaySafeMessageHash)
312304
val signature = encodePackedForSignature(
313305
signResult,
314306
owner.getAddress(),
@@ -327,9 +319,9 @@ class CircleSmartAccount(
327319
@ExcludeFromGeneratedCCReport
328320
@Throws(Exception::class)
329321
override suspend fun signTypedData(context: Context, typedData: String): String {
330-
val digest = toSha3Bytes(hashTypedData(typedData))
331-
val hash = UtilApiImpl.getReplaySafeMessageHash(client.transport, getAddress(), bytesToHex(digest))
332-
val signResult = owner.sign(context, hash)
322+
val hashedTypedData = hashTypedData(typedData)
323+
val replaySafeMessageHash = UtilApiImpl.getReplaySafeMessageHash(client.transport, getAddress(), hashedTypedData)
324+
val signResult = owner.sign(context, replaySafeMessageHash)
333325
val signature = encodePackedForSignature(
334326
signResult,
335327
owner.getAddress(),
@@ -339,7 +331,7 @@ class CircleSmartAccount(
339331
}
340332

341333
/**
342-
* Signs the given user operation.
334+
* Signs a given user operation.
343335
*
344336
* @param context The context used to launch framework UI flows ; use an activity context to make sure the UI will be launched within the same task stack.
345337
* @param chainId The chain ID for the user operation. Default is the chain ID of the client.

‎lib/src/main/java/com/circle/modularwallets/core/accounts/SmartAccount.kt‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,16 @@ abstract class SmartAccount(val client: Client, val entryPoint: EntryPoint) {
7979
abstract fun <T : UserOperation> getStubSignature(userOp: T): String
8080

8181
/**
82-
* Signs the given hex data.
82+
* Signs a hash via the Smart Account's owner.
8383
*
8484
* @param context The context in which the signing operation is performed.
85-
* @param hex The hex data to sign.
85+
* @param messageHash The hash to sign.
8686
* @return The signed data.
8787
*/
88-
abstract suspend fun sign(context: Context, hex: String): String
88+
abstract suspend fun sign(context: Context, messageHash: String): String
8989

9090
/**
91-
* Signs the given message.
91+
* Signs a given message.
9292
*
9393
* @param context The context in which the signing operation is performed.
9494
* @param message The message to sign.
@@ -97,7 +97,7 @@ abstract class SmartAccount(val client: Client, val entryPoint: EntryPoint) {
9797
abstract suspend fun signMessage(context: Context, message: String): String
9898

9999
/**
100-
* Signs the given typed data.
100+
* Signs a given typed data.
101101
*
102102
* @param context The context in which the signing operation is performed.
103103
* @param typedData The typed data to sign.
@@ -106,7 +106,7 @@ abstract class SmartAccount(val client: Client, val entryPoint: EntryPoint) {
106106
abstract suspend fun signTypedData(context: Context, typedData: String): String
107107

108108
/**
109-
* Signs the given user operation.
109+
* Signs a given user operation.
110110
*
111111
* @param context The context in which the signing operation is performed.
112112
* @param chainId The chain ID for the user operation. Default is the chain ID of the client.

‎lib/src/main/java/com/circle/modularwallets/core/accounts/WebAuthnAccount.kt‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,17 @@ open class WebAuthnAccount internal constructor(internal val credential: WebAuth
6060
}
6161

6262
/**
63-
* Signs the given hex data.
63+
* Signs a given hash
6464
*
6565
* @param context The context used to launch framework UI flows ; use an activity context to make sure the UI will be launched within the same task stack.
66-
* @param hex The hex data to sign.
66+
* @param messageHash The hash to sign.
6767
* @return The result of the signing operation.
6868
* @throws BaseError if the credential request fails.
6969
*/
7070
@ExcludeFromGeneratedCCReport
7171
@Throws(Exception::class)
72-
override suspend fun sign(context: Context, hex: String): SignResult {
73-
val optionsAndJson = getRequestOptions(credential.rpId, credential.id, hex)
72+
override suspend fun sign(context: Context, messageHash: String): SignResult {
73+
val optionsAndJson = getRequestOptions(credential.rpId, credential.id, messageHash)
7474
val authRespJson = getSavedCredentials(context, optionsAndJson.second)
7575
val authResp = fromJson(authRespJson, AuthenticationCredential::class.java)
7676
?: throw BaseError("credential request failed. Get null from json\n${authRespJson}")
@@ -85,7 +85,7 @@ open class WebAuthnAccount internal constructor(internal val credential: WebAuth
8585
}
8686

8787
/**
88-
* Signs the given message.
88+
* Signs a given message.
8989
*
9090
* @param context The context used to launch framework UI flows ; use an activity context to make sure the UI will be launched within the same task stack.
9191
* @param message The message to sign.
@@ -100,7 +100,7 @@ open class WebAuthnAccount internal constructor(internal val credential: WebAuth
100100
}
101101

102102
/**
103-
* Signs the given typed data.
103+
* Signs a given typed data.
104104
*
105105
* @param context The context used to launch framework UI flows ; use an activity context to make sure the UI will be launched within the same task stack.
106106
* @param typedData The typed data to sign.

‎lib/src/main/java/com/circle/modularwallets/core/apis/util/UtilApi.kt‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
package com.circle.modularwallets.core.apis.util
2020

21-
import com.circle.modularwallets.core.constants.CIRCLE_WEIGHTED_WEB_AUTHN_MULTISIG_PLUGIN
2221
import com.circle.modularwallets.core.transports.Transport
2322
import java.math.BigInteger
2423

@@ -52,7 +51,7 @@ internal interface UtilApi {
5251

5352
suspend fun isValidSignature(
5453
transport: Transport,
55-
message: String,
54+
digest: String,
5655
signature: String,
5756
from: String,
5857
to: String

‎lib/src/main/java/com/circle/modularwallets/core/apis/util/UtilApiImpl.kt‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import com.circle.modularwallets.core.transports.Transport
2727
import com.circle.modularwallets.core.utils.Logger
2828
import com.circle.modularwallets.core.utils.encoding.bytesToHex
2929
import com.circle.modularwallets.core.utils.encoding.hexToBigInteger
30-
import com.circle.modularwallets.core.utils.encoding.toSha3Bytes
3130
import com.circle.modularwallets.core.utils.rpc.performJsonRpcRequest
3231
import org.web3j.abi.FunctionEncoder
3332
import org.web3j.abi.FunctionReturnDecoder
@@ -117,31 +116,36 @@ internal object UtilApiImpl : UtilApi {
117116
@ExcludeFromGeneratedCCReport
118117
override suspend fun isValidSignature(
119118
transport: Transport,
120-
message: String,
119+
digest: String,
121120
signature: String,
122121
from: String,
123122
to: String
124123
): Boolean {
125-
val digest = toSha3Bytes(message)
126124
val function = Function(
127125
"isValidSignature",
128-
listOf<Type<*>>(Bytes32(digest), DynamicBytes(Numeric.hexStringToByteArray(signature))),
126+
listOf<Type<*>>(
127+
Bytes32(Numeric.hexStringToByteArray(digest)),
128+
DynamicBytes(Numeric.hexStringToByteArray(signature))
129+
),
129130
listOf<TypeReference<*>>(
130131
object : TypeReference<Bytes4>() {})
131132
)
132133
val data = FunctionEncoder.encode(function)
133134
Logger.d(
134135
msg = """
135136
isValidSignature > call
136-
Message: $message
137-
Digest: ${bytesToHex(digest)}
137+
Digest: $digest
138138
Signature: $signature
139139
From: $from
140140
To: $to
141141
""".trimIndent()
142142
)
143143
val resp = call(transport, from, to, data)
144144
val decoded = FunctionReturnDecoder.decode(resp, function.outputParameters)
145+
if (decoded.isEmpty()) {
146+
Logger.w(msg = "Empty response from isValidSignature call")
147+
return false
148+
}
145149
return EIP1271_VALID_SIGNATURE.contentEquals(decoded[0].value as ByteArray)
146150
}
147151

0 commit comments

Comments
 (0)