Skip to content

Commit db20155

Browse files
committed
feat: eip681
1 parent 7459e5e commit db20155

File tree

7 files changed

+341
-0
lines changed

7 files changed

+341
-0
lines changed

backend-lib/Cargo.lock

Lines changed: 105 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend-lib/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ zcash_proofs = "0.26"
3232
zcash_protocol = "0.7"
3333
zcash_script = "0.4"
3434
zip32 = "0.2"
35+
eip681 = { git = "https://github.com/zcash/librustzcash.git", branch = "eip681-ffi-api" }
3536

3637
# Infrastructure
3738
prost = "0.14"
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package cash.z.ecc.android.sdk.internal
2+
3+
import cash.z.ecc.android.sdk.internal.model.JniEip681TransactionRequest
4+
5+
/**
6+
* Interface for EIP-681 transaction request parsing operations.
7+
*/
8+
interface Eip681 {
9+
/**
10+
* Parse an EIP-681 URI string into a [JniEip681TransactionRequest].
11+
*
12+
* @param uri a valid EIP-681 URI string (e.g. `"ethereum:0xAbC...?value=1e18"`).
13+
* @return a [JniEip681TransactionRequest] representing the parsed URI.
14+
* @throws RuntimeException if the input is not a valid EIP-681 URI.
15+
*/
16+
fun parseTransactionRequest(uri: String): JniEip681TransactionRequest
17+
18+
/**
19+
* Serialize an EIP-681 transaction request back to a normalized URI string.
20+
*
21+
* This parses the input URI and then serializes it back, which normalizes the URI format.
22+
*
23+
* @param uri a valid EIP-681 URI string.
24+
* @return the normalized URI string.
25+
* @throws RuntimeException if the input is not a valid EIP-681 URI.
26+
*/
27+
fun transactionRequestToUri(uri: String): String
28+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package cash.z.ecc.android.sdk.internal.jni
2+
3+
import cash.z.ecc.android.sdk.internal.Eip681
4+
import cash.z.ecc.android.sdk.internal.model.JniEip681TransactionRequest
5+
6+
class RustEip681Tool private constructor() : Eip681 {
7+
override fun parseTransactionRequest(uri: String): JniEip681TransactionRequest =
8+
parseEip681TransactionRequest(uri)
9+
10+
override fun transactionRequestToUri(uri: String): String =
11+
eip681TransactionRequestToUri(uri)
12+
13+
companion object {
14+
suspend fun new(): Eip681 {
15+
RustBackend.loadLibrary()
16+
17+
return RustEip681Tool()
18+
}
19+
20+
@JvmStatic
21+
private external fun parseEip681TransactionRequest(input: String): JniEip681TransactionRequest
22+
23+
@JvmStatic
24+
private external fun eip681TransactionRequestToUri(input: String): String
25+
}
26+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package cash.z.ecc.android.sdk.internal.model
2+
3+
import androidx.annotation.Keep
4+
5+
/**
6+
* Serves as cross layer (Kotlin, Rust) communication class for parsed EIP-681 transaction requests.
7+
*
8+
* EIP-681 defines a standard URI format for Ethereum transaction requests, commonly used in
9+
* QR codes and deep links. This sealed class represents the three recognized forms: native
10+
* ETH transfers, ERC-20 token transfers, and unrecognised (but syntactically valid) requests.
11+
*/
12+
@Keep
13+
sealed class JniEip681TransactionRequest {
14+
/**
15+
* A native ETH/chain token transfer (no function call).
16+
*
17+
* @param schemaPrefix the URI schema prefix (e.g. "ethereum").
18+
* @param chainId the chain ID, or -1L if not specified in the URI.
19+
* @param recipientAddress the recipient address (ERC-55 checksummed hex or ENS name).
20+
* @param valueHex the transfer value as a `0x`-prefixed hex string, or null if not specified.
21+
* @param gasLimitHex the gas limit as a `0x`-prefixed hex string, or null if not specified.
22+
* @param gasPriceHex the gas price as a `0x`-prefixed hex string, or null if not specified.
23+
*/
24+
@Keep
25+
class Native(
26+
val schemaPrefix: String,
27+
val chainId: Long,
28+
val recipientAddress: String,
29+
val valueHex: String?,
30+
val gasLimitHex: String?,
31+
val gasPriceHex: String?
32+
) : JniEip681TransactionRequest()
33+
34+
/**
35+
* An ERC-20 token transfer via `transfer(address,uint256)`.
36+
*
37+
* @param chainId the chain ID, or -1L if not specified in the URI.
38+
* @param tokenContractAddress the ERC-20 token contract address (ERC-55 checksummed hex or ENS name).
39+
* @param recipientAddress the transfer recipient address (ERC-55 checksummed hex or ENS name).
40+
* @param valueHex the transfer value in atomic units as a `0x`-prefixed hex string.
41+
*/
42+
@Keep
43+
class Erc20(
44+
val chainId: Long,
45+
val tokenContractAddress: String,
46+
val recipientAddress: String,
47+
val valueHex: String
48+
) : JniEip681TransactionRequest()
49+
50+
/**
51+
* A valid EIP-681 request that is not a recognized transfer pattern.
52+
*/
53+
@Keep
54+
class Unrecognised : JniEip681TransactionRequest()
55+
}

0 commit comments

Comments
 (0)