@novastera-oss/nitro-metamask 0.4.5 → 0.5.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,7 +11,7 @@ Pod::Spec.new do |s|
11
11
  s.authors = package["author"]
12
12
 
13
13
  s.platforms = { :ios => min_ios_version_supported, :visionos => 1.0 }
14
- s.source = { :git => "https://github.com/darksorrow/@novastera-oss/nitro-metamask.git", :tag => "#{s.version}" }
14
+ s.source = { :git => "https://github.com/novastera/nitro-metamask.git", :tag => "#{s.version}" }
15
15
 
16
16
  s.source_files = [
17
17
  # Implementation (Swift)
@@ -24,6 +24,9 @@ include_directories(
24
24
 
25
25
  find_library(LOG_LIB log)
26
26
 
27
+ # 16 KB max page size (complements ANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES in Gradle)
28
+ target_link_options(${PACKAGE_NAME} PRIVATE "-Wl,-z,max-page-size=16384")
29
+
27
30
  # Link all libraries together
28
31
  target_link_libraries(
29
32
  ${PACKAGE_NAME}
@@ -117,6 +117,7 @@ android {
117
117
 
118
118
  sourceSets {
119
119
  main {
120
+ jniLibs.srcDirs += ["${buildDir}/intermediates/rust-ecies-jni"]
120
121
  if (isNewArchitectureEnabled()) {
121
122
  java.srcDirs += [
122
123
  // React Codegen files
@@ -146,12 +147,15 @@ dependencies {
146
147
  // Required for Promise.async with coroutines in Nitro modules
147
148
  implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.10.2"
148
149
 
149
- // MetaMask Android SDK
150
- // See: https://github.com/MetaMask/metamask-android-sdk
151
- // Available on Maven Central: https://mvnrepository.com/artifact/io.metamask.androidsdk/metamask-android-sdk
152
- implementation "io.metamask.androidsdk:metamask-android-sdk:0.6.6"
150
+ // MetaMask Android SDK — exclude prebuilt io.metamask.ecies (4 KB ELF); we ship io.metamask.ecies.Ecies + libecies.so from rust/ecies-jni
151
+ // See: https://github.com/MetaMask/metamask-android-sdk/issues/157
152
+ implementation("io.metamask.androidsdk:metamask-android-sdk:0.6.6") {
153
+ exclude group: "io.metamask.ecies", module: "ecies"
154
+ }
153
155
  }
154
156
 
157
+ apply from: "./cargo-ecies.gradle"
158
+
155
159
  if (isNewArchitectureEnabled()) {
156
160
  react {
157
161
  jsRootDir = file("../src/")
@@ -0,0 +1,54 @@
1
+ def eciesRustDir = file("${projectDir}/../rust/ecies-jni")
2
+ def eciesCargoToml = file("${projectDir}/../rust/ecies-jni/Cargo.toml")
3
+ def eciesJniOut = file("${buildDir}/intermediates/rust-ecies-jni")
4
+
5
+ def reactNativeArchitectures() {
6
+ def value = rootProject.getProperties().get("reactNativeArchitectures")
7
+ return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
8
+ }
9
+
10
+ tasks.register("cargoNdkBuildEcies", Exec) {
11
+ group = "build"
12
+ description = "Build libecies.so via Rust (cargo-ndk), 16 KB max page size"
13
+ onlyIf {
14
+ eciesRustDir.isDirectory() && eciesCargoToml.isFile()
15
+ }
16
+ workingDir eciesRustDir
17
+ standardOutput System.out
18
+ errorOutput System.err
19
+ outputs.dir(eciesJniOut)
20
+ }
21
+
22
+ // Resolve NDK + ABIs at configuration time (afterEvaluate). Task actions must NOT touch
23
+ // Task.project — configuration cache forbids it (see Gradle 9 config cache requirements).
24
+ afterEvaluate {
25
+ def ndkProp = project.android.ndkDirectory
26
+ def ndkDir = (ndkProp instanceof File) ? ndkProp : ndkProp.get().asFile
27
+ def ndkPath = ndkDir.absolutePath
28
+ def ndkVer = project.android.ndkVersion
29
+ def abis = reactNativeArchitectures()
30
+ def outPath = eciesJniOut.absolutePath
31
+
32
+ tasks.named("cargoNdkBuildEcies", Exec).configure {
33
+ doFirst {
34
+ eciesJniOut.mkdirs()
35
+ if (!ndkDir.exists()) {
36
+ throw new GradleException("ANDROID NDK not found; ndkVersion is ${ndkVer}")
37
+ }
38
+ environment "ANDROID_NDK_HOME", ndkPath
39
+ environment "ANDROID_NDK_ROOT", ndkPath
40
+ environment "RUSTFLAGS", "-C link-arg=-Wl,-z,max-page-size=16384"
41
+ def args = ["cargo", "ndk"]
42
+ abis.each { abi ->
43
+ args.add("-t")
44
+ args.add(abi)
45
+ }
46
+ args.addAll(["-o", outPath, "build", "--release"])
47
+ commandLine args
48
+ }
49
+ }
50
+
51
+ tasks.matching { it.name.startsWith("preBuild") }.configureEach {
52
+ dependsOn("cargoNdkBuildEcies")
53
+ }
54
+ }
@@ -2,4 +2,4 @@ NitroMetamask_kotlinVersion=2.1.20
2
2
  NitroMetamask_minSdkVersion=23
3
3
  NitroMetamask_targetSdkVersion=35
4
4
  NitroMetamask_compileSdkVersion=34
5
- NitroMetamask_ndkVersion=27.1.12297006
5
+ NitroMetamask_ndkVersion=28.2.13676358
@@ -0,0 +1,44 @@
1
+ package io.metamask.ecies
2
+
3
+ import android.util.Log
4
+
5
+ /**
6
+ * ECIES helpers used by [io.metamask.androidsdk.Crypto].
7
+ * Source: MetaMask metamask-android-sdk `ecies` module (API-compatible).
8
+ * Native [libecies.so] is built from [rust/ecies-jni] (16 KB page–aligned) instead of Maven `io.metamask.ecies:ecies`.
9
+ */
10
+ public class Ecies {
11
+ companion object {
12
+ const val TAG = "ECIES"
13
+
14
+ init {
15
+ try {
16
+ System.loadLibrary("ecies")
17
+ Log.d(TAG, "Ecies loaded successfully!")
18
+ } catch (e: UnsatisfiedLinkError) {
19
+ Log.d(TAG, "Ecies could not be loaded: ${e.message}")
20
+ }
21
+ }
22
+
23
+ @JvmStatic external fun generateSecretKey(): String
24
+ @JvmStatic external fun derivePublicKeyFrom(secret: String): String
25
+ @JvmStatic external fun encryptMessage(public: String, message: String): String
26
+ @JvmStatic external fun decryptMessage(secret: String, message: String): String
27
+ }
28
+
29
+ public fun privateKey(): String {
30
+ return generateSecretKey()
31
+ }
32
+
33
+ public fun publicKeyFrom(secretKey: String): String {
34
+ return derivePublicKeyFrom(secretKey)
35
+ }
36
+
37
+ public fun encrypt(publicKey: String, message: String): String {
38
+ return encryptMessage(publicKey, message)
39
+ }
40
+
41
+ public fun decrypt(secretKey: String, message: String): String {
42
+ return decryptMessage(secretKey, message)
43
+ }
44
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@novastera-oss/nitro-metamask",
3
- "version": "0.4.5",
3
+ "version": "0.5.5",
4
4
  "description": "Native mobile MetaMask wallet integration for React Native. Part of Novastera CRM/ERP platform ecosystem. Provides secure authentication and message signing for Web3 mobile applications.",
5
5
  "main": "./lib/commonjs/index.js",
6
6
  "module": "./lib/module/index.js",
@@ -41,6 +41,7 @@
41
41
  "cpp",
42
42
  "nitro.json",
43
43
  "android/build.gradle",
44
+ "android/cargo-ecies.gradle",
44
45
  "android/fix-prefab.gradle",
45
46
  "android/gradle.properties",
46
47
  "android/CMakeLists.txt",
@@ -53,16 +54,24 @@
53
54
  "ios/**/*.swift",
54
55
  "app.plugin.js",
55
56
  "*.podspec",
56
- "README.md"
57
+ "README.md",
58
+ "rust/ecies-jni/Cargo.toml",
59
+ "rust/ecies-jni/src",
60
+ "rust/ecies-jni/Cargo.lock",
61
+ "scripts/verify-16k-page-alignment.sh",
62
+ "scripts/verify-16k-page-alignment.py"
57
63
  ],
58
64
  "workspaces": [
59
65
  "example"
60
66
  ],
61
- "repository": "https://github.com/darksorrow/@novastera-oss/nitro-metamask.git",
67
+ "repository": {
68
+ "type": "git",
69
+ "url": "https://github.com/novastera/nitro-metamask.git"
70
+ },
62
71
  "author": "DarkSorrow",
63
72
  "license": "MIT",
64
- "bugs": "https://github.com/darksorrow/@novastera-oss/nitro-metamask/issues",
65
- "homepage": "https://github.com/darksorrow/@novastera-oss/nitro-metamask#readme",
73
+ "bugs": "https://github.com/novastera/nitro-metamask/issues",
74
+ "homepage": "https://github.com/novastera/nitro-metamask#readme",
66
75
  "publishConfig": {
67
76
  "access": "public",
68
77
  "registry": "https://registry.npmjs.org/"
@@ -0,0 +1,782 @@
1
+ # This file is automatically @generated by Cargo.
2
+ # It is not intended for manual editing.
3
+ version = 4
4
+
5
+ [[package]]
6
+ name = "aead"
7
+ version = "0.5.2"
8
+ source = "registry+https://github.com/rust-lang/crates.io-index"
9
+ checksum = "d122413f284cf2d62fb1b7db97e02edb8cda96d769b16e443a4f6195e35662b0"
10
+ dependencies = [
11
+ "crypto-common",
12
+ "generic-array",
13
+ ]
14
+
15
+ [[package]]
16
+ name = "aes"
17
+ version = "0.8.4"
18
+ source = "registry+https://github.com/rust-lang/crates.io-index"
19
+ checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0"
20
+ dependencies = [
21
+ "cfg-if",
22
+ "cipher",
23
+ "cpufeatures",
24
+ ]
25
+
26
+ [[package]]
27
+ name = "aes-gcm"
28
+ version = "0.10.3"
29
+ source = "registry+https://github.com/rust-lang/crates.io-index"
30
+ checksum = "831010a0f742e1209b3bcea8fab6a8e149051ba6099432c8cb2cc117dec3ead1"
31
+ dependencies = [
32
+ "aead",
33
+ "aes",
34
+ "cipher",
35
+ "ctr",
36
+ "ghash",
37
+ "subtle",
38
+ ]
39
+
40
+ [[package]]
41
+ name = "arrayref"
42
+ version = "0.3.9"
43
+ source = "registry+https://github.com/rust-lang/crates.io-index"
44
+ checksum = "76a2e8124351fda1ef8aaaa3bbd7ebbcb486bbcd4225aca0aa0d84bb2db8fecb"
45
+
46
+ [[package]]
47
+ name = "autocfg"
48
+ version = "1.5.0"
49
+ source = "registry+https://github.com/rust-lang/crates.io-index"
50
+ checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8"
51
+
52
+ [[package]]
53
+ name = "base64"
54
+ version = "0.22.1"
55
+ source = "registry+https://github.com/rust-lang/crates.io-index"
56
+ checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"
57
+
58
+ [[package]]
59
+ name = "bitflags"
60
+ version = "2.11.1"
61
+ source = "registry+https://github.com/rust-lang/crates.io-index"
62
+ checksum = "c4512299f36f043ab09a583e57bceb5a5aab7a73db1805848e8fef3c9e8c78b3"
63
+
64
+ [[package]]
65
+ name = "block-buffer"
66
+ version = "0.10.4"
67
+ source = "registry+https://github.com/rust-lang/crates.io-index"
68
+ checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71"
69
+ dependencies = [
70
+ "generic-array",
71
+ ]
72
+
73
+ [[package]]
74
+ name = "bumpalo"
75
+ version = "3.20.2"
76
+ source = "registry+https://github.com/rust-lang/crates.io-index"
77
+ checksum = "5d20789868f4b01b2f2caec9f5c4e0213b41e3e5702a50157d699ae31ced2fcb"
78
+
79
+ [[package]]
80
+ name = "bytes"
81
+ version = "1.11.1"
82
+ source = "registry+https://github.com/rust-lang/crates.io-index"
83
+ checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33"
84
+
85
+ [[package]]
86
+ name = "cesu8"
87
+ version = "1.1.0"
88
+ source = "registry+https://github.com/rust-lang/crates.io-index"
89
+ checksum = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c"
90
+
91
+ [[package]]
92
+ name = "cfg-if"
93
+ version = "1.0.4"
94
+ source = "registry+https://github.com/rust-lang/crates.io-index"
95
+ checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
96
+
97
+ [[package]]
98
+ name = "cipher"
99
+ version = "0.4.4"
100
+ source = "registry+https://github.com/rust-lang/crates.io-index"
101
+ checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad"
102
+ dependencies = [
103
+ "crypto-common",
104
+ "inout",
105
+ ]
106
+
107
+ [[package]]
108
+ name = "combine"
109
+ version = "4.6.7"
110
+ source = "registry+https://github.com/rust-lang/crates.io-index"
111
+ checksum = "ba5a308b75df32fe02788e748662718f03fde005016435c444eea572398219fd"
112
+ dependencies = [
113
+ "bytes",
114
+ "memchr",
115
+ ]
116
+
117
+ [[package]]
118
+ name = "cpufeatures"
119
+ version = "0.2.17"
120
+ source = "registry+https://github.com/rust-lang/crates.io-index"
121
+ checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280"
122
+ dependencies = [
123
+ "libc",
124
+ ]
125
+
126
+ [[package]]
127
+ name = "critical-section"
128
+ version = "1.2.0"
129
+ source = "registry+https://github.com/rust-lang/crates.io-index"
130
+ checksum = "790eea4361631c5e7d22598ecd5723ff611904e3344ce8720784c93e3d83d40b"
131
+
132
+ [[package]]
133
+ name = "crunchy"
134
+ version = "0.2.4"
135
+ source = "registry+https://github.com/rust-lang/crates.io-index"
136
+ checksum = "460fbee9c2c2f33933d720630a6a0bac33ba7053db5344fac858d4b8952d77d5"
137
+
138
+ [[package]]
139
+ name = "crypto-common"
140
+ version = "0.1.7"
141
+ source = "registry+https://github.com/rust-lang/crates.io-index"
142
+ checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a"
143
+ dependencies = [
144
+ "generic-array",
145
+ "typenum",
146
+ ]
147
+
148
+ [[package]]
149
+ name = "ctr"
150
+ version = "0.9.2"
151
+ source = "registry+https://github.com/rust-lang/crates.io-index"
152
+ checksum = "0369ee1ad671834580515889b80f2ea915f23b8be8d0daa4bbaf2ac5c7590835"
153
+ dependencies = [
154
+ "cipher",
155
+ ]
156
+
157
+ [[package]]
158
+ name = "digest"
159
+ version = "0.9.0"
160
+ source = "registry+https://github.com/rust-lang/crates.io-index"
161
+ checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066"
162
+ dependencies = [
163
+ "generic-array",
164
+ ]
165
+
166
+ [[package]]
167
+ name = "digest"
168
+ version = "0.10.7"
169
+ source = "registry+https://github.com/rust-lang/crates.io-index"
170
+ checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
171
+ dependencies = [
172
+ "block-buffer",
173
+ "crypto-common",
174
+ "subtle",
175
+ ]
176
+
177
+ [[package]]
178
+ name = "ecies"
179
+ version = "0.2.10"
180
+ source = "registry+https://github.com/rust-lang/crates.io-index"
181
+ checksum = "0cd378cd438dcec2698ce6fd6cdbb323c671552d8be5af853690dc8320bc676d"
182
+ dependencies = [
183
+ "aes-gcm",
184
+ "getrandom",
185
+ "hkdf",
186
+ "libsecp256k1",
187
+ "lock_api",
188
+ "once_cell",
189
+ "parking_lot",
190
+ "rand_core",
191
+ "sha2",
192
+ "typenum",
193
+ "wasm-bindgen",
194
+ ]
195
+
196
+ [[package]]
197
+ name = "ecies-jni"
198
+ version = "0.1.0"
199
+ dependencies = [
200
+ "ecies",
201
+ "hex",
202
+ "jni",
203
+ ]
204
+
205
+ [[package]]
206
+ name = "generic-array"
207
+ version = "0.14.7"
208
+ source = "registry+https://github.com/rust-lang/crates.io-index"
209
+ checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a"
210
+ dependencies = [
211
+ "typenum",
212
+ "version_check",
213
+ ]
214
+
215
+ [[package]]
216
+ name = "getrandom"
217
+ version = "0.2.17"
218
+ source = "registry+https://github.com/rust-lang/crates.io-index"
219
+ checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0"
220
+ dependencies = [
221
+ "cfg-if",
222
+ "js-sys",
223
+ "libc",
224
+ "wasi",
225
+ "wasm-bindgen",
226
+ ]
227
+
228
+ [[package]]
229
+ name = "ghash"
230
+ version = "0.5.1"
231
+ source = "registry+https://github.com/rust-lang/crates.io-index"
232
+ checksum = "f0d8a4362ccb29cb0b265253fb0a2728f592895ee6854fd9bc13f2ffda266ff1"
233
+ dependencies = [
234
+ "opaque-debug",
235
+ "polyval",
236
+ ]
237
+
238
+ [[package]]
239
+ name = "hex"
240
+ version = "0.4.3"
241
+ source = "registry+https://github.com/rust-lang/crates.io-index"
242
+ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
243
+
244
+ [[package]]
245
+ name = "hkdf"
246
+ version = "0.12.4"
247
+ source = "registry+https://github.com/rust-lang/crates.io-index"
248
+ checksum = "7b5f8eb2ad728638ea2c7d47a21db23b7b58a72ed6a38256b8a1849f15fbbdf7"
249
+ dependencies = [
250
+ "hmac",
251
+ ]
252
+
253
+ [[package]]
254
+ name = "hmac"
255
+ version = "0.12.1"
256
+ source = "registry+https://github.com/rust-lang/crates.io-index"
257
+ checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e"
258
+ dependencies = [
259
+ "digest 0.10.7",
260
+ ]
261
+
262
+ [[package]]
263
+ name = "inout"
264
+ version = "0.1.4"
265
+ source = "registry+https://github.com/rust-lang/crates.io-index"
266
+ checksum = "879f10e63c20629ecabbb64a8010319738c66a5cd0c29b02d63d272b03751d01"
267
+ dependencies = [
268
+ "generic-array",
269
+ ]
270
+
271
+ [[package]]
272
+ name = "jni"
273
+ version = "0.21.1"
274
+ source = "registry+https://github.com/rust-lang/crates.io-index"
275
+ checksum = "1a87aa2bb7d2af34197c04845522473242e1aa17c12f4935d5856491a7fb8c97"
276
+ dependencies = [
277
+ "cesu8",
278
+ "cfg-if",
279
+ "combine",
280
+ "jni-sys 0.3.1",
281
+ "log",
282
+ "thiserror",
283
+ "walkdir",
284
+ "windows-sys 0.45.0",
285
+ ]
286
+
287
+ [[package]]
288
+ name = "jni-sys"
289
+ version = "0.3.1"
290
+ source = "registry+https://github.com/rust-lang/crates.io-index"
291
+ checksum = "41a652e1f9b6e0275df1f15b32661cf0d4b78d4d87ddec5e0c3c20f097433258"
292
+ dependencies = [
293
+ "jni-sys 0.4.1",
294
+ ]
295
+
296
+ [[package]]
297
+ name = "jni-sys"
298
+ version = "0.4.1"
299
+ source = "registry+https://github.com/rust-lang/crates.io-index"
300
+ checksum = "c6377a88cb3910bee9b0fa88d4f42e1d2da8e79915598f65fb0c7ee14c878af2"
301
+ dependencies = [
302
+ "jni-sys-macros",
303
+ ]
304
+
305
+ [[package]]
306
+ name = "jni-sys-macros"
307
+ version = "0.4.1"
308
+ source = "registry+https://github.com/rust-lang/crates.io-index"
309
+ checksum = "38c0b942f458fe50cdac086d2f946512305e5631e720728f2a61aabcd47a6264"
310
+ dependencies = [
311
+ "quote",
312
+ "syn",
313
+ ]
314
+
315
+ [[package]]
316
+ name = "js-sys"
317
+ version = "0.3.95"
318
+ source = "registry+https://github.com/rust-lang/crates.io-index"
319
+ checksum = "2964e92d1d9dc3364cae4d718d93f227e3abb088e747d92e0395bfdedf1c12ca"
320
+ dependencies = [
321
+ "once_cell",
322
+ "wasm-bindgen",
323
+ ]
324
+
325
+ [[package]]
326
+ name = "libc"
327
+ version = "0.2.185"
328
+ source = "registry+https://github.com/rust-lang/crates.io-index"
329
+ checksum = "52ff2c0fe9bc6cb6b14a0592c2ff4fa9ceb83eea9db979b0487cd054946a2b8f"
330
+
331
+ [[package]]
332
+ name = "libsecp256k1"
333
+ version = "0.7.2"
334
+ source = "registry+https://github.com/rust-lang/crates.io-index"
335
+ checksum = "e79019718125edc905a079a70cfa5f3820bc76139fc91d6f9abc27ea2a887139"
336
+ dependencies = [
337
+ "arrayref",
338
+ "base64",
339
+ "digest 0.9.0",
340
+ "libsecp256k1-core",
341
+ "libsecp256k1-gen-ecmult",
342
+ "libsecp256k1-gen-genmult",
343
+ "rand",
344
+ "serde",
345
+ ]
346
+
347
+ [[package]]
348
+ name = "libsecp256k1-core"
349
+ version = "0.3.0"
350
+ source = "registry+https://github.com/rust-lang/crates.io-index"
351
+ checksum = "5be9b9bb642d8522a44d533eab56c16c738301965504753b03ad1de3425d5451"
352
+ dependencies = [
353
+ "crunchy",
354
+ "digest 0.9.0",
355
+ "subtle",
356
+ ]
357
+
358
+ [[package]]
359
+ name = "libsecp256k1-gen-ecmult"
360
+ version = "0.3.0"
361
+ source = "registry+https://github.com/rust-lang/crates.io-index"
362
+ checksum = "3038c808c55c87e8a172643a7d87187fc6c4174468159cb3090659d55bcb4809"
363
+ dependencies = [
364
+ "libsecp256k1-core",
365
+ ]
366
+
367
+ [[package]]
368
+ name = "libsecp256k1-gen-genmult"
369
+ version = "0.3.0"
370
+ source = "registry+https://github.com/rust-lang/crates.io-index"
371
+ checksum = "3db8d6ba2cec9eacc40e6e8ccc98931840301f1006e95647ceb2dd5c3aa06f7c"
372
+ dependencies = [
373
+ "libsecp256k1-core",
374
+ ]
375
+
376
+ [[package]]
377
+ name = "lock_api"
378
+ version = "0.4.13"
379
+ source = "registry+https://github.com/rust-lang/crates.io-index"
380
+ checksum = "96936507f153605bddfcda068dd804796c84324ed2510809e5b2a624c81da765"
381
+ dependencies = [
382
+ "autocfg",
383
+ "scopeguard",
384
+ ]
385
+
386
+ [[package]]
387
+ name = "log"
388
+ version = "0.4.29"
389
+ source = "registry+https://github.com/rust-lang/crates.io-index"
390
+ checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897"
391
+
392
+ [[package]]
393
+ name = "memchr"
394
+ version = "2.8.0"
395
+ source = "registry+https://github.com/rust-lang/crates.io-index"
396
+ checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79"
397
+
398
+ [[package]]
399
+ name = "once_cell"
400
+ version = "1.21.4"
401
+ source = "registry+https://github.com/rust-lang/crates.io-index"
402
+ checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
403
+ dependencies = [
404
+ "critical-section",
405
+ "portable-atomic",
406
+ ]
407
+
408
+ [[package]]
409
+ name = "opaque-debug"
410
+ version = "0.3.1"
411
+ source = "registry+https://github.com/rust-lang/crates.io-index"
412
+ checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381"
413
+
414
+ [[package]]
415
+ name = "parking_lot"
416
+ version = "0.12.4"
417
+ source = "registry+https://github.com/rust-lang/crates.io-index"
418
+ checksum = "70d58bf43669b5795d1576d0641cfb6fbb2057bf629506267a92807158584a13"
419
+ dependencies = [
420
+ "lock_api",
421
+ "parking_lot_core",
422
+ ]
423
+
424
+ [[package]]
425
+ name = "parking_lot_core"
426
+ version = "0.9.12"
427
+ source = "registry+https://github.com/rust-lang/crates.io-index"
428
+ checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1"
429
+ dependencies = [
430
+ "cfg-if",
431
+ "libc",
432
+ "redox_syscall",
433
+ "smallvec",
434
+ "windows-link",
435
+ ]
436
+
437
+ [[package]]
438
+ name = "polyval"
439
+ version = "0.6.2"
440
+ source = "registry+https://github.com/rust-lang/crates.io-index"
441
+ checksum = "9d1fe60d06143b2430aa532c94cfe9e29783047f06c0d7fd359a9a51b729fa25"
442
+ dependencies = [
443
+ "cfg-if",
444
+ "cpufeatures",
445
+ "opaque-debug",
446
+ "universal-hash",
447
+ ]
448
+
449
+ [[package]]
450
+ name = "portable-atomic"
451
+ version = "1.13.1"
452
+ source = "registry+https://github.com/rust-lang/crates.io-index"
453
+ checksum = "c33a9471896f1c69cecef8d20cbe2f7accd12527ce60845ff44c153bb2a21b49"
454
+
455
+ [[package]]
456
+ name = "proc-macro2"
457
+ version = "1.0.106"
458
+ source = "registry+https://github.com/rust-lang/crates.io-index"
459
+ checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934"
460
+ dependencies = [
461
+ "unicode-ident",
462
+ ]
463
+
464
+ [[package]]
465
+ name = "quote"
466
+ version = "1.0.45"
467
+ source = "registry+https://github.com/rust-lang/crates.io-index"
468
+ checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924"
469
+ dependencies = [
470
+ "proc-macro2",
471
+ ]
472
+
473
+ [[package]]
474
+ name = "rand"
475
+ version = "0.8.6"
476
+ source = "registry+https://github.com/rust-lang/crates.io-index"
477
+ checksum = "5ca0ecfa931c29007047d1bc58e623ab12e5590e8c7cc53200d5202b69266d8a"
478
+ dependencies = [
479
+ "rand_core",
480
+ ]
481
+
482
+ [[package]]
483
+ name = "rand_core"
484
+ version = "0.6.4"
485
+ source = "registry+https://github.com/rust-lang/crates.io-index"
486
+ checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
487
+ dependencies = [
488
+ "getrandom",
489
+ ]
490
+
491
+ [[package]]
492
+ name = "redox_syscall"
493
+ version = "0.5.18"
494
+ source = "registry+https://github.com/rust-lang/crates.io-index"
495
+ checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d"
496
+ dependencies = [
497
+ "bitflags",
498
+ ]
499
+
500
+ [[package]]
501
+ name = "rustversion"
502
+ version = "1.0.22"
503
+ source = "registry+https://github.com/rust-lang/crates.io-index"
504
+ checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"
505
+
506
+ [[package]]
507
+ name = "same-file"
508
+ version = "1.0.6"
509
+ source = "registry+https://github.com/rust-lang/crates.io-index"
510
+ checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502"
511
+ dependencies = [
512
+ "winapi-util",
513
+ ]
514
+
515
+ [[package]]
516
+ name = "scopeguard"
517
+ version = "1.2.0"
518
+ source = "registry+https://github.com/rust-lang/crates.io-index"
519
+ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
520
+
521
+ [[package]]
522
+ name = "serde"
523
+ version = "1.0.228"
524
+ source = "registry+https://github.com/rust-lang/crates.io-index"
525
+ checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e"
526
+ dependencies = [
527
+ "serde_core",
528
+ "serde_derive",
529
+ ]
530
+
531
+ [[package]]
532
+ name = "serde_core"
533
+ version = "1.0.228"
534
+ source = "registry+https://github.com/rust-lang/crates.io-index"
535
+ checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad"
536
+ dependencies = [
537
+ "serde_derive",
538
+ ]
539
+
540
+ [[package]]
541
+ name = "serde_derive"
542
+ version = "1.0.228"
543
+ source = "registry+https://github.com/rust-lang/crates.io-index"
544
+ checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79"
545
+ dependencies = [
546
+ "proc-macro2",
547
+ "quote",
548
+ "syn",
549
+ ]
550
+
551
+ [[package]]
552
+ name = "sha2"
553
+ version = "0.10.9"
554
+ source = "registry+https://github.com/rust-lang/crates.io-index"
555
+ checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283"
556
+ dependencies = [
557
+ "cfg-if",
558
+ "cpufeatures",
559
+ "digest 0.10.7",
560
+ ]
561
+
562
+ [[package]]
563
+ name = "smallvec"
564
+ version = "1.15.1"
565
+ source = "registry+https://github.com/rust-lang/crates.io-index"
566
+ checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03"
567
+
568
+ [[package]]
569
+ name = "subtle"
570
+ version = "2.6.1"
571
+ source = "registry+https://github.com/rust-lang/crates.io-index"
572
+ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
573
+
574
+ [[package]]
575
+ name = "syn"
576
+ version = "2.0.117"
577
+ source = "registry+https://github.com/rust-lang/crates.io-index"
578
+ checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99"
579
+ dependencies = [
580
+ "proc-macro2",
581
+ "quote",
582
+ "unicode-ident",
583
+ ]
584
+
585
+ [[package]]
586
+ name = "thiserror"
587
+ version = "1.0.69"
588
+ source = "registry+https://github.com/rust-lang/crates.io-index"
589
+ checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52"
590
+ dependencies = [
591
+ "thiserror-impl",
592
+ ]
593
+
594
+ [[package]]
595
+ name = "thiserror-impl"
596
+ version = "1.0.69"
597
+ source = "registry+https://github.com/rust-lang/crates.io-index"
598
+ checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1"
599
+ dependencies = [
600
+ "proc-macro2",
601
+ "quote",
602
+ "syn",
603
+ ]
604
+
605
+ [[package]]
606
+ name = "typenum"
607
+ version = "1.19.0"
608
+ source = "registry+https://github.com/rust-lang/crates.io-index"
609
+ checksum = "562d481066bde0658276a35467c4af00bdc6ee726305698a55b86e61d7ad82bb"
610
+
611
+ [[package]]
612
+ name = "unicode-ident"
613
+ version = "1.0.24"
614
+ source = "registry+https://github.com/rust-lang/crates.io-index"
615
+ checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
616
+
617
+ [[package]]
618
+ name = "universal-hash"
619
+ version = "0.5.1"
620
+ source = "registry+https://github.com/rust-lang/crates.io-index"
621
+ checksum = "fc1de2c688dc15305988b563c3854064043356019f97a4b46276fe734c4f07ea"
622
+ dependencies = [
623
+ "crypto-common",
624
+ "subtle",
625
+ ]
626
+
627
+ [[package]]
628
+ name = "version_check"
629
+ version = "0.9.5"
630
+ source = "registry+https://github.com/rust-lang/crates.io-index"
631
+ checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
632
+
633
+ [[package]]
634
+ name = "walkdir"
635
+ version = "2.5.0"
636
+ source = "registry+https://github.com/rust-lang/crates.io-index"
637
+ checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b"
638
+ dependencies = [
639
+ "same-file",
640
+ "winapi-util",
641
+ ]
642
+
643
+ [[package]]
644
+ name = "wasi"
645
+ version = "0.11.1+wasi-snapshot-preview1"
646
+ source = "registry+https://github.com/rust-lang/crates.io-index"
647
+ checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b"
648
+
649
+ [[package]]
650
+ name = "wasm-bindgen"
651
+ version = "0.2.118"
652
+ source = "registry+https://github.com/rust-lang/crates.io-index"
653
+ checksum = "0bf938a0bacb0469e83c1e148908bd7d5a6010354cf4fb73279b7447422e3a89"
654
+ dependencies = [
655
+ "cfg-if",
656
+ "once_cell",
657
+ "rustversion",
658
+ "wasm-bindgen-macro",
659
+ "wasm-bindgen-shared",
660
+ ]
661
+
662
+ [[package]]
663
+ name = "wasm-bindgen-macro"
664
+ version = "0.2.118"
665
+ source = "registry+https://github.com/rust-lang/crates.io-index"
666
+ checksum = "eeff24f84126c0ec2db7a449f0c2ec963c6a49efe0698c4242929da037ca28ed"
667
+ dependencies = [
668
+ "quote",
669
+ "wasm-bindgen-macro-support",
670
+ ]
671
+
672
+ [[package]]
673
+ name = "wasm-bindgen-macro-support"
674
+ version = "0.2.118"
675
+ source = "registry+https://github.com/rust-lang/crates.io-index"
676
+ checksum = "9d08065faf983b2b80a79fd87d8254c409281cf7de75fc4b773019824196c904"
677
+ dependencies = [
678
+ "bumpalo",
679
+ "proc-macro2",
680
+ "quote",
681
+ "syn",
682
+ "wasm-bindgen-shared",
683
+ ]
684
+
685
+ [[package]]
686
+ name = "wasm-bindgen-shared"
687
+ version = "0.2.118"
688
+ source = "registry+https://github.com/rust-lang/crates.io-index"
689
+ checksum = "5fd04d9e306f1907bd13c6361b5c6bfc7b3b3c095ed3f8a9246390f8dbdee129"
690
+ dependencies = [
691
+ "unicode-ident",
692
+ ]
693
+
694
+ [[package]]
695
+ name = "winapi-util"
696
+ version = "0.1.11"
697
+ source = "registry+https://github.com/rust-lang/crates.io-index"
698
+ checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22"
699
+ dependencies = [
700
+ "windows-sys 0.61.2",
701
+ ]
702
+
703
+ [[package]]
704
+ name = "windows-link"
705
+ version = "0.2.1"
706
+ source = "registry+https://github.com/rust-lang/crates.io-index"
707
+ checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
708
+
709
+ [[package]]
710
+ name = "windows-sys"
711
+ version = "0.45.0"
712
+ source = "registry+https://github.com/rust-lang/crates.io-index"
713
+ checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0"
714
+ dependencies = [
715
+ "windows-targets",
716
+ ]
717
+
718
+ [[package]]
719
+ name = "windows-sys"
720
+ version = "0.61.2"
721
+ source = "registry+https://github.com/rust-lang/crates.io-index"
722
+ checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc"
723
+ dependencies = [
724
+ "windows-link",
725
+ ]
726
+
727
+ [[package]]
728
+ name = "windows-targets"
729
+ version = "0.42.2"
730
+ source = "registry+https://github.com/rust-lang/crates.io-index"
731
+ checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071"
732
+ dependencies = [
733
+ "windows_aarch64_gnullvm",
734
+ "windows_aarch64_msvc",
735
+ "windows_i686_gnu",
736
+ "windows_i686_msvc",
737
+ "windows_x86_64_gnu",
738
+ "windows_x86_64_gnullvm",
739
+ "windows_x86_64_msvc",
740
+ ]
741
+
742
+ [[package]]
743
+ name = "windows_aarch64_gnullvm"
744
+ version = "0.42.2"
745
+ source = "registry+https://github.com/rust-lang/crates.io-index"
746
+ checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8"
747
+
748
+ [[package]]
749
+ name = "windows_aarch64_msvc"
750
+ version = "0.42.2"
751
+ source = "registry+https://github.com/rust-lang/crates.io-index"
752
+ checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43"
753
+
754
+ [[package]]
755
+ name = "windows_i686_gnu"
756
+ version = "0.42.2"
757
+ source = "registry+https://github.com/rust-lang/crates.io-index"
758
+ checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f"
759
+
760
+ [[package]]
761
+ name = "windows_i686_msvc"
762
+ version = "0.42.2"
763
+ source = "registry+https://github.com/rust-lang/crates.io-index"
764
+ checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060"
765
+
766
+ [[package]]
767
+ name = "windows_x86_64_gnu"
768
+ version = "0.42.2"
769
+ source = "registry+https://github.com/rust-lang/crates.io-index"
770
+ checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36"
771
+
772
+ [[package]]
773
+ name = "windows_x86_64_gnullvm"
774
+ version = "0.42.2"
775
+ source = "registry+https://github.com/rust-lang/crates.io-index"
776
+ checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3"
777
+
778
+ [[package]]
779
+ name = "windows_x86_64_msvc"
780
+ version = "0.42.2"
781
+ source = "registry+https://github.com/rust-lang/crates.io-index"
782
+ checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0"
@@ -0,0 +1,16 @@
1
+ [package]
2
+ name = "ecies-jni"
3
+ version = "0.1.0"
4
+ edition = "2021"
5
+ publish = false
6
+
7
+ # Android loads libecies.so (cdylib file name = libecies.so)
8
+ [lib]
9
+ crate-type = ["cdylib"]
10
+ name = "ecies"
11
+
12
+ [dependencies]
13
+ jni = "0.21"
14
+ # Match ecies.org / MetaMask stack (secp256k1, AES-256-GCM); pure Rust AES for simpler Android linking
15
+ ecies = { version = "0.2.10", default-features = false, features = ["std", "aes-rust"] }
16
+ hex = "0.4"
@@ -0,0 +1,127 @@
1
+ //! JNI bridge for `io.metamask.ecies.Ecies` (MetaMask Android SDK).
2
+ //! Rebuilt with NDK r28+ / 16 KB page-size compatible linking (see Gradle + cargo-ndk).
3
+
4
+ use ecies::{decrypt, encrypt, utils::generate_keypair};
5
+ use jni::objects::JString;
6
+ use jni::sys::jstring;
7
+ use jni::JNIEnv;
8
+
9
+ fn empty_jstring(env: &mut JNIEnv) -> jstring {
10
+ env.new_string("")
11
+ .expect("empty jstring")
12
+ .into_raw()
13
+ }
14
+
15
+ fn jstring_to_string(env: &mut JNIEnv, j: JString) -> Result<String, jni::errors::Error> {
16
+ Ok(env.get_string(&j)?.into())
17
+ }
18
+
19
+ /// Kotlin: `Ecies.companion.generateSecretKey`
20
+ #[no_mangle]
21
+ pub extern "system" fn Java_io_metamask_ecies_Ecies_00024Companion_generateSecretKey(
22
+ mut env: JNIEnv,
23
+ _class: jni::objects::JClass,
24
+ ) -> jstring {
25
+ let (sk, _pk) = generate_keypair();
26
+ let hex = hex::encode(sk.serialize());
27
+ match env.new_string(hex) {
28
+ Ok(s) => s.into_raw(),
29
+ Err(_) => empty_jstring(&mut env),
30
+ }
31
+ }
32
+
33
+ /// Kotlin: `Ecies.companion.derivePublicKeyFrom`
34
+ #[no_mangle]
35
+ pub extern "system" fn Java_io_metamask_ecies_Ecies_00024Companion_derivePublicKeyFrom(
36
+ mut env: JNIEnv,
37
+ _class: jni::objects::JClass,
38
+ secret: JString,
39
+ ) -> jstring {
40
+ let secret_str = match jstring_to_string(&mut env, secret) {
41
+ Ok(s) => s,
42
+ Err(_) => return empty_jstring(&mut env),
43
+ };
44
+ let sk_bytes = match hex::decode(secret_str.trim()) {
45
+ Ok(b) => b,
46
+ Err(_) => return empty_jstring(&mut env),
47
+ };
48
+ let sk = match ecies::SecretKey::parse_slice(&sk_bytes) {
49
+ Ok(k) => k,
50
+ Err(_) => return empty_jstring(&mut env),
51
+ };
52
+ let pk = ecies::PublicKey::from_secret_key(&sk);
53
+ let hex = hex::encode(pk.serialize());
54
+ match env.new_string(hex) {
55
+ Ok(s) => s.into_raw(),
56
+ Err(_) => empty_jstring(&mut env),
57
+ }
58
+ }
59
+
60
+ /// Kotlin: `Ecies.companion.encryptMessage`
61
+ #[no_mangle]
62
+ pub extern "system" fn Java_io_metamask_ecies_Ecies_00024Companion_encryptMessage(
63
+ mut env: JNIEnv,
64
+ _class: jni::objects::JClass,
65
+ public: JString,
66
+ message: JString,
67
+ ) -> jstring {
68
+ let pub_hex = match jstring_to_string(&mut env, public) {
69
+ Ok(s) => s,
70
+ Err(_) => return empty_jstring(&mut env),
71
+ };
72
+ let msg_str = match jstring_to_string(&mut env, message) {
73
+ Ok(s) => s,
74
+ Err(_) => return empty_jstring(&mut env),
75
+ };
76
+ let pk_bytes = match hex::decode(pub_hex.trim()) {
77
+ Ok(b) => b,
78
+ Err(_) => return empty_jstring(&mut env),
79
+ };
80
+ let ct = match encrypt(&pk_bytes, msg_str.as_bytes()) {
81
+ Ok(c) => c,
82
+ Err(_) => return empty_jstring(&mut env),
83
+ };
84
+ let hex = hex::encode(ct);
85
+ match env.new_string(hex) {
86
+ Ok(s) => s.into_raw(),
87
+ Err(_) => empty_jstring(&mut env),
88
+ }
89
+ }
90
+
91
+ /// Kotlin: `Ecies.companion.decryptMessage`
92
+ #[no_mangle]
93
+ pub extern "system" fn Java_io_metamask_ecies_Ecies_00024Companion_decryptMessage(
94
+ mut env: JNIEnv,
95
+ _class: jni::objects::JClass,
96
+ secret: JString,
97
+ message: JString,
98
+ ) -> jstring {
99
+ let sec_hex = match jstring_to_string(&mut env, secret) {
100
+ Ok(s) => s,
101
+ Err(_) => return empty_jstring(&mut env),
102
+ };
103
+ let ct_hex = match jstring_to_string(&mut env, message) {
104
+ Ok(s) => s,
105
+ Err(_) => return empty_jstring(&mut env),
106
+ };
107
+ let sk_bytes = match hex::decode(sec_hex.trim()) {
108
+ Ok(b) => b,
109
+ Err(_) => return empty_jstring(&mut env),
110
+ };
111
+ let ct_bytes = match hex::decode(ct_hex.trim()) {
112
+ Ok(b) => b,
113
+ Err(_) => return empty_jstring(&mut env),
114
+ };
115
+ let plain = match decrypt(&sk_bytes, &ct_bytes) {
116
+ Ok(p) => p,
117
+ Err(_) => return empty_jstring(&mut env),
118
+ };
119
+ let text = match String::from_utf8(plain) {
120
+ Ok(t) => t,
121
+ Err(_) => return empty_jstring(&mut env),
122
+ };
123
+ match env.new_string(text) {
124
+ Ok(s) => s.into_raw(),
125
+ Err(_) => empty_jstring(&mut env),
126
+ }
127
+ }
@@ -0,0 +1,117 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ Verify 16 KB ELF program-header alignment for Google Play (PT_LOAD p_align).
4
+
5
+ Uses NDK llvm-readobj (reliable). readelf(1) column positions vary by version;
6
+ do not parse readelf -l by $NF.
7
+ """
8
+ from __future__ import annotations
9
+
10
+ import os
11
+ import re
12
+ import shutil
13
+ import subprocess
14
+ import sys
15
+
16
+ MIN_ALIGN = 16 * 1024
17
+
18
+
19
+ def find_llvm_readobj() -> str | None:
20
+ env = os.environ.get("ANDROID_NDK_HOME") or os.environ.get("ANDROID_NDK_ROOT")
21
+ if env:
22
+ prebuilt = os.path.join(env, "toolchains", "llvm", "prebuilt")
23
+ if os.path.isdir(prebuilt):
24
+ for host in (
25
+ "linux-x86_64",
26
+ "darwin-x86_64",
27
+ "darwin-arm64",
28
+ "windows-x86_64",
29
+ ):
30
+ cand = os.path.join(prebuilt, host, "bin", "llvm-readobj")
31
+ if os.path.isfile(cand):
32
+ return cand
33
+ sdk = os.environ.get("ANDROID_SDK_ROOT") or os.environ.get("ANDROID_HOME")
34
+ if sdk:
35
+ for ver in ("28.2.13676358",):
36
+ for host in ("linux-x86_64", "windows-x86_64", "darwin-x86_64"):
37
+ cand = os.path.join(
38
+ sdk, "ndk", ver, "toolchains", "llvm", "prebuilt", host, "bin", "llvm-readobj"
39
+ )
40
+ if os.path.isfile(cand):
41
+ return cand
42
+ return shutil.which("llvm-readobj")
43
+
44
+
45
+ def verify_so(llvm_readobj: str, path: str) -> bool:
46
+ try:
47
+ out = subprocess.check_output(
48
+ [llvm_readobj, "--program-headers", path],
49
+ text=True,
50
+ stderr=subprocess.DEVNULL,
51
+ )
52
+ except (subprocess.CalledProcessError, FileNotFoundError) as e:
53
+ print(f"ERROR: llvm-readobj failed for {path}: {e}", file=sys.stderr)
54
+ return False
55
+
56
+ saw_nonzero = False
57
+ # Each "ProgramHeader {" block: match PT_LOAD and its Alignment (not readelf columns).
58
+ for block in out.split("ProgramHeader {")[1:]:
59
+ if "Type: PT_LOAD" not in block:
60
+ continue
61
+ m = re.search(r"Alignment:\s*(\d+)", block)
62
+ if not m:
63
+ continue
64
+ a = int(m.group(1))
65
+ if a == 0:
66
+ # p_align 0 = default; other LOADs carry explicit alignment on 16K builds
67
+ continue
68
+ saw_nonzero = True
69
+ if a < MIN_ALIGN:
70
+ print(
71
+ f"FAIL {path}: PT_LOAD Alignment {a} < {MIN_ALIGN}",
72
+ file=sys.stderr,
73
+ )
74
+ return False
75
+
76
+ if not saw_nonzero:
77
+ print(
78
+ f"FAIL {path}: no PT_LOAD with non-zero Alignment (unexpected for .so)",
79
+ file=sys.stderr,
80
+ )
81
+ return False
82
+ return True
83
+
84
+
85
+ def main() -> int:
86
+ if len(sys.argv) < 2:
87
+ print("Usage: verify-16k-page-alignment.py <shared-object> [...]", file=sys.stderr)
88
+ return 2
89
+
90
+ lr = find_llvm_readobj()
91
+ if not lr:
92
+ print(
93
+ "ERROR: llvm-readobj not found. Set ANDROID_NDK_HOME or install Android NDK.",
94
+ file=sys.stderr,
95
+ )
96
+ return 2
97
+
98
+ ok = True
99
+ for path in sys.argv[1:]:
100
+ if not os.path.isfile(path):
101
+ print(f"ERROR: not a file: {path}", file=sys.stderr)
102
+ return 1
103
+ print(f"Checking: {path}")
104
+ if not verify_so(lr, path):
105
+ ok = False
106
+ else:
107
+ print(f" OK (llvm-readobj PT_LOAD Alignment >= {MIN_ALIGN} where specified)")
108
+
109
+ if not ok:
110
+ print("verify-16k-page-alignment: FAILED", file=sys.stderr)
111
+ return 1
112
+ print("verify-16k-page-alignment: all checks passed")
113
+ return 0
114
+
115
+
116
+ if __name__ == "__main__":
117
+ sys.exit(main())
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env bash
2
+ # Thin wrapper; real check is scripts/verify-16k-page-alignment.py (llvm-readobj).
3
+ set -euo pipefail
4
+ ROOT="$(cd "$(dirname "$0")/.." && pwd)"
5
+ exec python3 "$ROOT/scripts/verify-16k-page-alignment.py" "$@"