lifecycleScope.launch {
val types = mapOf(
"EIP712Domain" to listOf(
ScanEip712TypeProperty("name", "string"),
ScanEip712TypeProperty("version", "string"),
ScanEip712TypeProperty("chainId", "uint256"),
ScanEip712TypeProperty("verifyingContract", "address")
),
"Permit" to listOf(
ScanEip712TypeProperty("owner", "address"),
ScanEip712TypeProperty("spender", "address"),
ScanEip712TypeProperty("value", "uint256"),
ScanEip712TypeProperty("nonce", "uint256"),
ScanEip712TypeProperty("deadline", "uint256")
)
)
val domain = ScanEip712Domain(
name = "MyToken",
version = "1",
chainId = "eip155:1",
verifyingContract = "0xa0b86991c6218b36c1d19d4a2e9Eb0cE3606eB48"
)
val message = mapOf<String, Any>(
"owner" to "0x7b1363f33b86d16ef7c8d03d11f4394a37d95c36",
"spender" to "0x67beb4dd770a9c2cbc7133ba428b9eecdcf09186",
"value" to 3000,
"nonce" to 0,
"deadline" to 50000000000L
)
val typedData = ScanEip712TypedData(
primaryType = "Permit",
types = types,
domain = domain,
message = message
)
val request = ScanEip712Request(
walletAddress = "0x7b1363f33b86d16ef7c8d03d11f4394a37d95c36",
chainId = "eip155:1",
eip712Message = typedData
)
val result = portal.security.hypernative.scanEip712Tx(request)
result.onSuccess { response ->
val rawResponse = response.data?.rawResponse
println("Success: ${rawResponse?.success}")
rawResponse?.data?.let { data ->
println("Recommendation: ${data.recommendation}")
println("Assessment ID: ${data.assessmentId}")
}
}.onFailure { error ->
println("Error scanning EIP-712 transaction: ${error.message}")
}
}