Skip to content

Commit 2adbb4e

Browse files
🔄 synced file(s) with circlefin/modularwallets-android-sdk-internal (#9)
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 [#15482647787](https://github.com/circlefin/modularwallets-android-sdk-internal/actions/runs/15482647787)
1 parent 9cf1807 commit 2adbb4e

File tree

13 files changed

+512
-42
lines changed

13 files changed

+512
-42
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ import com.circle.modularwallets.core.utils.NonceManagerSource
4444
import com.circle.modularwallets.core.utils.abi.encodeCallData
4545
import com.circle.modularwallets.core.utils.signature.hashMessage
4646
import com.circle.modularwallets.core.utils.signature.hashTypedData
47-
import com.circle.modularwallets.core.utils.smartAccount.getMinimumVerificationGasLimit
47+
import com.circle.modularwallets.core.utils.smartAccount.getDefaultVerificationGasLimit
4848
import com.circle.modularwallets.core.utils.userOperation.getUserOperationHash
4949
import com.circle.modularwallets.core.utils.userOperation.parseFactoryAddressAndData
5050
import org.web3j.utils.Numeric
@@ -167,8 +167,7 @@ class CircleSmartAccount(
167167
*/
168168
override var userOperation: UserOperationConfiguration? =
169169
UserOperationConfiguration { userOperation ->
170-
val minimumVerificationGasLimit =
171-
getMinimumVerificationGasLimit(isDeployed(), client.chain.chainId)
170+
val minimumVerificationGasLimit = getDefaultVerificationGasLimit(isDeployed(), client.transport)
172171
EstimateUserOperationGasResult(
173172
verificationGasLimit = minimumVerificationGasLimit
174173
.max(userOperation.verificationGasLimit ?: BigInteger.ZERO)

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ import com.circle.modularwallets.core.utils.webauthn.getSavedCredentials
4545
* Throws: BaseError if userName is null for WebAuthnMode.Register.
4646
*
4747
*/
48-
4948
@ExcludeFromGeneratedCCReport
5049
@Throws(Exception::class)
5150
@JvmOverloads

‎lib/src/main/java/com/circle/modularwallets/core/apis/modular/ModularApi.kt‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
package com.circle.modularwallets.core.apis.modular
2020

2121
import com.circle.modularwallets.core.models.AddressMappingOwner
22-
import com.circle.modularwallets.core.models.CreateAddressMappingResult
22+
import com.circle.modularwallets.core.models.AddressMappingResult
23+
import com.circle.modularwallets.core.models.GetUserOperationGasPriceResult
2324
import com.circle.modularwallets.core.transports.Transport
2425

2526
internal interface ModularApi {
@@ -28,6 +29,20 @@ internal interface ModularApi {
2829
transport: Transport,
2930
walletAddress: String,
3031
owners: Array<AddressMappingOwner>
31-
): Array<CreateAddressMappingResult>
32+
): Array<AddressMappingResult>
3233

34+
suspend fun getAddressMapping(
35+
transport: Transport,
36+
owner: AddressMappingOwner
37+
): Array<AddressMappingResult>
38+
39+
/**
40+
* Gets the gas price options for a user operation.
41+
*
42+
* @param transport The transport to use for the request.
43+
* @return The gas price options with low, medium, high tiers and optional verificationGasLimit.
44+
*/
45+
suspend fun getUserOperationGasPrice(
46+
transport: Transport
47+
): GetUserOperationGasPriceResult
3348
}

‎lib/src/main/java/com/circle/modularwallets/core/apis/modular/ModularApiImpl.kt‎

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ package com.circle.modularwallets.core.apis.modular
2020

2121
import com.circle.modularwallets.core.errors.BaseError
2222
import com.circle.modularwallets.core.models.AddressMappingOwner
23-
import com.circle.modularwallets.core.models.CreateAddressMappingResult
23+
import com.circle.modularwallets.core.models.AddressMappingResult
2424
import com.circle.modularwallets.core.models.EoaAddressMappingOwner
25+
import com.circle.modularwallets.core.models.GetUserOperationGasPriceResult
2526
import com.circle.modularwallets.core.models.WebAuthnAddressMappingOwner
2627
import com.circle.modularwallets.core.transports.RpcRequest
2728
import com.circle.modularwallets.core.transports.Transport
@@ -43,7 +44,7 @@ internal object ModularApiImpl : ModularApi {
4344
transport: Transport,
4445
walletAddress: String,
4546
owners: Array<AddressMappingOwner>
46-
): Array<CreateAddressMappingResult> {
47+
): Array<AddressMappingResult> {
4748
if (!isAddress(walletAddress)) {
4849
throw BaseError("walletAddress is invalid")
4950
}
@@ -75,10 +76,50 @@ internal object ModularApiImpl : ModularApi {
7576
listOf(CreateAddressMappingReq(walletAddress, owners))
7677
)
7778
val rawList = performJsonRpcRequest(transport, req) as ArrayList<*>
78-
val result: Array<CreateAddressMappingResult> = rawList.mapNotNull { item ->
79-
resultToTypeAndJson(item, CreateAddressMappingResult::class.java).first
80-
}.toTypedArray()
79+
val result: Array<AddressMappingResult> = processAddressMappingResponse(rawList)
8180
return result
8281
}
82+
83+
override suspend fun getAddressMapping(
84+
transport: Transport,
85+
owner: AddressMappingOwner
86+
): Array<AddressMappingResult> {
87+
val req = RpcRequest(
88+
"circle_getAddressMapping",
89+
listOf(GetAddressMappingReq(owner))
90+
)
91+
val rawList = performJsonRpcRequest(transport, req) as ArrayList<*>
92+
val result: Array<AddressMappingResult> = processAddressMappingResponse(rawList)
93+
return result
94+
}
95+
96+
private fun processAddressMappingResponse(rawList: ArrayList<*>):
97+
Array<AddressMappingResult> {
98+
return rawList.mapNotNull { item ->
99+
resultToTypeAndJson(item, AddressMappingResult::class.java).first
100+
}.toTypedArray()
101+
}
102+
/**
103+
* Gets the gas price options for a user operation.
104+
*
105+
* @param transport The transport to use for the request.
106+
* @return The gas price options with low, medium, high tiers and optional verificationGasLimit.
107+
*/
108+
override suspend fun getUserOperationGasPrice(
109+
transport: Transport,
110+
): GetUserOperationGasPriceResult {
111+
112+
val req = RpcRequest(
113+
"circle_getUserOperationGasPrice"
114+
)
115+
116+
val result = performJsonRpcRequest(
117+
transport,
118+
req,
119+
GetUserOperationGasPriceResult::class.java
120+
)
121+
122+
return result.first
123+
}
83124
}
84125

‎lib/src/main/java/com/circle/modularwallets/core/apis/modular/ModularReqResp.kt‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,8 @@ internal data class CreateAddressMappingReq(
148148
@Json(name = "walletAddress") val walletAddress: String,
149149
@Json(name = "owners") val owners: Array<AddressMappingOwner>,
150150
)
151+
152+
@JsonClass(generateAdapter = true)
153+
internal data class GetAddressMappingReq(
154+
@Json(name = "owner") val owner: AddressMappingOwner,
155+
)

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,11 @@ internal interface UtilApi {
6868
account: String,
6969
ownerToCheck: String,
7070
): Boolean
71+
72+
suspend fun isOwnerOf(
73+
transport: Transport,
74+
account: String,
75+
ownerXToCheck: String,
76+
ownerYToCheck: String,
77+
): Boolean
7178
}

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import org.web3j.abi.datatypes.Address
3636
import org.web3j.abi.datatypes.Bool
3737
import org.web3j.abi.datatypes.DynamicBytes
3838
import org.web3j.abi.datatypes.Function
39+
import org.web3j.abi.datatypes.StaticStruct
3940
import org.web3j.abi.datatypes.Type
4041
import org.web3j.abi.datatypes.generated.Bytes32
4142
import org.web3j.abi.datatypes.generated.Bytes4
@@ -187,6 +188,48 @@ internal object UtilApiImpl : UtilApi {
187188
}
188189
return decoded[0].value as Boolean
189190
}
191+
@ExcludeFromGeneratedCCReport
192+
override suspend fun isOwnerOf(
193+
transport: Transport,
194+
account: String,
195+
xOfOwnerToCheck: String,
196+
yOfOwnerToCheck: String,
197+
): Boolean {
198+
val publicKeys = StaticStruct(
199+
Uint256(BigInteger(xOfOwnerToCheck)),
200+
Uint256(BigInteger(yOfOwnerToCheck))
201+
)
202+
val function = Function(
203+
"isOwnerOf",
204+
listOf<Type<*>>(
205+
Address(account),
206+
publicKeys
207+
),
208+
listOf<TypeReference<*>>(
209+
object : TypeReference<Bool>() {})
210+
)
211+
val data = FunctionEncoder.encode(function)
212+
Logger.d(
213+
msg = """
214+
isOwnerOf > call
215+
Account: $account
216+
xOfOwnerToCheck: $xOfOwnerToCheck
217+
yOfOwnerToCheck: $yOfOwnerToCheck
218+
""".trimIndent()
219+
)
220+
val resp = call(
221+
transport,
222+
from = account,
223+
to = CIRCLE_WEIGHTED_WEB_AUTHN_MULTISIG_PLUGIN.address,
224+
data
225+
)
226+
val decoded = FunctionReturnDecoder.decode(resp, function.outputParameters)
227+
if (decoded.isEmpty()) {
228+
Logger.w(msg = "Empty response from isOwner call")
229+
return false
230+
}
231+
return decoded[0].value as Boolean
232+
}
190233

191234
override suspend fun getReplaySafeMessageHash(
192235
transport: Transport,

0 commit comments

Comments
 (0)