@baerae/zkap-zkp-react-native 0.1.1 → 0.1.3
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.
- package/android/build.gradle +2 -0
- package/android/libs/arm64-v8a/libzkap_uniffi_bindings.so +0 -0
- package/android/libs/armeabi-v7a/libzkap_uniffi_bindings.so +0 -0
- package/android/libs/x86_64/libzkap_uniffi_bindings.so +0 -0
- package/android/src/main/java/expo/modules/zkap/ZkapSdkModule.kt +127 -38
- package/android/src/main/java/uniffi/zkap_uniffi_bindings/zkap_uniffi_bindings.kt +1566 -0
- package/ios/ZkapSdkModule.podspec +7 -6
- package/ios/ZkapSdkModule.swift +104 -62
- package/ios/ZkapZkp.xcframework/Info.plist +9 -9
- package/ios/ZkapZkp.xcframework/ios-arm64/Headers/zkap_uniffi_bindingsFFI.h +567 -0
- package/ios/ZkapZkp.xcframework/ios-arm64/{libzkap_zkp_rn.a → libzkap_uniffi_bindings.a} +0 -0
- package/ios/ZkapZkp.xcframework/ios-arm64_x86_64-simulator/Headers/zkap_uniffi_bindingsFFI.h +567 -0
- package/ios/ZkapZkp.xcframework/ios-arm64_x86_64-simulator/{libzkap_zkp_rn_sim.a → libzkap_uniffi_bindings.a} +0 -0
- package/ios/uniffi/zkap_uniffi_bindings.swift +1174 -0
- package/ios/uniffi/zkap_uniffi_bindingsFFI.h +567 -0
- package/ios/uniffi/zkap_uniffi_bindingsFFI.modulemap +7 -0
- package/package.json +3 -2
- package/src/index.ts +10 -8
- package/android/libs/arm64-v8a/libzkap_zkp_rn.so +0 -0
- package/android/libs/armeabi-v7a/libzkap_zkp_rn.so +0 -0
- package/android/libs/x86_64/libzkap_zkp_rn.so +0 -0
- package/ios/ZkapZkp.xcframework/ios-arm64/Headers/zkap_zkp_rn.h +0 -15
- package/ios/ZkapZkp.xcframework/ios-arm64_x86_64-simulator/Headers/zkap_zkp_rn.h +0 -15
- package/ios/include/zkap_zkp_rn.h +0 -15
|
@@ -13,15 +13,14 @@ Pod::Spec.new do |s|
|
|
|
13
13
|
s.swift_version = '5.9'
|
|
14
14
|
s.source = { git: package['repository']['url'] }
|
|
15
15
|
|
|
16
|
-
s.source_files = '
|
|
16
|
+
s.source_files = ['ZkapSdkModule.swift', 'uniffi/**/*.{swift,h,m}']
|
|
17
17
|
|
|
18
18
|
# Pre-built Rust static libraries (generated by CI build-react-native.yml)
|
|
19
|
-
s.vendored_frameworks = '
|
|
19
|
+
s.vendored_frameworks = 'ZkapZkp.xcframework'
|
|
20
20
|
|
|
21
|
-
# Expose C headers for the Rust FFI symbols
|
|
22
|
-
s.preserve_paths = '
|
|
21
|
+
# Expose C headers for the Rust FFI symbols (UniFFI-generated module)
|
|
22
|
+
s.preserve_paths = 'uniffi/*.h'
|
|
23
23
|
s.xcconfig = {
|
|
24
|
-
'HEADER_SEARCH_PATHS' => '$(PODS_TARGET_SRCROOT)/ios/include',
|
|
25
24
|
'OTHER_LDFLAGS' => '-lc++'
|
|
26
25
|
}
|
|
27
26
|
|
|
@@ -29,6 +28,8 @@ Pod::Spec.new do |s|
|
|
|
29
28
|
|
|
30
29
|
s.pod_target_xcconfig = {
|
|
31
30
|
'DEFINES_MODULE' => 'YES',
|
|
32
|
-
'SWIFT_COMPILATION_MODE' => 'wholemodule'
|
|
31
|
+
'SWIFT_COMPILATION_MODE' => 'wholemodule',
|
|
32
|
+
'HEADER_SEARCH_PATHS' => '$(PODS_TARGET_SRCROOT)/uniffi',
|
|
33
|
+
'OTHER_CFLAGS' => '-fmodule-map-file=$(PODS_TARGET_SRCROOT)/uniffi/zkap_uniffi_bindingsFFI.modulemap'
|
|
33
34
|
}
|
|
34
35
|
end
|
package/ios/ZkapSdkModule.swift
CHANGED
|
@@ -8,98 +8,140 @@ public class ZkapSdkModule: Module {
|
|
|
8
8
|
// generateHash
|
|
9
9
|
// ──────────────────────────────────────────
|
|
10
10
|
AsyncFunction("generateHash") { (inputJson: String) -> String in
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
let result = zkap_generate_hash(cInput)
|
|
15
|
-
defer { zkap_free_string(result) }
|
|
16
|
-
return try ZkapSdkModule.unwrapResult(result)
|
|
17
|
-
}
|
|
11
|
+
let data = inputJson.data(using: .utf8)!
|
|
12
|
+
let obj = try JSONSerialization.jsonObject(with: data) as! [String: Any]
|
|
13
|
+
let messages = obj["messages"] as! [String]
|
|
18
14
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
throw ZkapError.invalidInput("Failed to encode inputJson as UTF-8")
|
|
25
|
-
}
|
|
26
|
-
let result = zkap_generate_anchor(cInput)
|
|
27
|
-
defer { zkap_free_string(result) }
|
|
28
|
-
return try ZkapSdkModule.unwrapResult(result)
|
|
15
|
+
let result = try generateHash(messages: messages)
|
|
16
|
+
|
|
17
|
+
let output: [String: Any] = ["result": result]
|
|
18
|
+
let outData = try JSONSerialization.data(withJSONObject: output)
|
|
19
|
+
return String(data: outData, encoding: .utf8)!
|
|
29
20
|
}
|
|
30
21
|
|
|
31
22
|
// ──────────────────────────────────────────
|
|
32
23
|
// generateAudHash
|
|
33
24
|
// ──────────────────────────────────────────
|
|
34
25
|
AsyncFunction("generateAudHash") { (inputJson: String) -> String in
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
let
|
|
39
|
-
|
|
40
|
-
|
|
26
|
+
let data = inputJson.data(using: .utf8)!
|
|
27
|
+
let obj = try JSONSerialization.jsonObject(with: data) as! [String: Any]
|
|
28
|
+
let config = parseConfig(obj["config"] as! [String: Any])
|
|
29
|
+
let audList = obj["aud_list"] as! [String]
|
|
30
|
+
|
|
31
|
+
let result = try generateAudHash(config: config, audList: audList)
|
|
32
|
+
|
|
33
|
+
let output: [String: Any] = [
|
|
34
|
+
"aud_hashes": result.audHashes,
|
|
35
|
+
"h_aud_list": result.hAudList
|
|
36
|
+
]
|
|
37
|
+
let outData = try JSONSerialization.data(withJSONObject: output)
|
|
38
|
+
return String(data: outData, encoding: .utf8)!
|
|
41
39
|
}
|
|
42
40
|
|
|
43
41
|
// ──────────────────────────────────────────
|
|
44
42
|
// generateLeafHash
|
|
45
43
|
// ──────────────────────────────────────────
|
|
46
44
|
AsyncFunction("generateLeafHash") { (inputJson: String) -> String in
|
|
47
|
-
|
|
48
|
-
|
|
45
|
+
let data = inputJson.data(using: .utf8)!
|
|
46
|
+
let obj = try JSONSerialization.jsonObject(with: data) as! [String: Any]
|
|
47
|
+
let config = parseConfig(obj["config"] as! [String: Any])
|
|
48
|
+
let iss = obj["iss"] as! String
|
|
49
|
+
let pkB64 = obj["pk_b64"] as! String
|
|
50
|
+
|
|
51
|
+
let result = try generateLeafHash(config: config, iss: iss, pkB64: pkB64)
|
|
52
|
+
|
|
53
|
+
let output: [String: Any] = ["result": result]
|
|
54
|
+
let outData = try JSONSerialization.data(withJSONObject: output)
|
|
55
|
+
return String(data: outData, encoding: .utf8)!
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// ──────────────────────────────────────────
|
|
59
|
+
// generateAnchor
|
|
60
|
+
// ──────────────────────────────────────────
|
|
61
|
+
AsyncFunction("generateAnchor") { (inputJson: String) -> String in
|
|
62
|
+
let data = inputJson.data(using: .utf8)!
|
|
63
|
+
let obj = try JSONSerialization.jsonObject(with: data) as! [String: Any]
|
|
64
|
+
let config = parseConfig(obj["config"] as! [String: Any])
|
|
65
|
+
let rawSecrets = obj["secrets"] as! [[String: Any]]
|
|
66
|
+
let secrets = rawSecrets.map { s in
|
|
67
|
+
ZkapSecret(
|
|
68
|
+
sub: s["sub"] as! String,
|
|
69
|
+
iss: s["iss"] as! String,
|
|
70
|
+
aud: s["aud"] as! String
|
|
71
|
+
)
|
|
49
72
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
73
|
+
|
|
74
|
+
let result = try generateAnchor(config: config, secrets: secrets)
|
|
75
|
+
|
|
76
|
+
let output: [String: Any] = ["evaluations": result.evaluations]
|
|
77
|
+
let outData = try JSONSerialization.data(withJSONObject: output)
|
|
78
|
+
return String(data: outData, encoding: .utf8)!
|
|
53
79
|
}
|
|
54
80
|
|
|
55
81
|
// ──────────────────────────────────────────
|
|
56
82
|
// prove
|
|
57
83
|
// ──────────────────────────────────────────
|
|
58
84
|
AsyncFunction("prove") { (inputJson: String) -> String in
|
|
59
|
-
|
|
60
|
-
|
|
85
|
+
let data = inputJson.data(using: .utf8)!
|
|
86
|
+
let obj = try JSONSerialization.jsonObject(with: data) as! [String: Any]
|
|
87
|
+
let config = parseConfig(obj["config"] as! [String: Any])
|
|
88
|
+
let req = obj["request"] as! [String: Any]
|
|
89
|
+
|
|
90
|
+
let rawLeafIndices = req["leaf_indices"] as! [Any]
|
|
91
|
+
let leafIndices: [UInt64] = rawLeafIndices.map { v in
|
|
92
|
+
if let n = v as? Int { return UInt64(n) }
|
|
93
|
+
if let n = v as? UInt64 { return n }
|
|
94
|
+
return UInt64(v as! NSNumber)
|
|
61
95
|
}
|
|
62
|
-
let result = zkap_prove(cInput)
|
|
63
|
-
defer { zkap_free_string(result) }
|
|
64
|
-
return try ZkapSdkModule.unwrapResult(result)
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
96
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
97
|
+
let request = ZkapProofRequest(
|
|
98
|
+
pkPath: req["pk_path"] as! String,
|
|
99
|
+
jwts: req["jwts"] as! [String],
|
|
100
|
+
pkOps: req["pk_ops"] as! [String],
|
|
101
|
+
merklePaths: req["merkle_paths"] as! [[String]],
|
|
102
|
+
leafIndices: leafIndices,
|
|
103
|
+
root: req["root"] as! String,
|
|
104
|
+
anchorEvals: req["anchor_evals"] as! [String],
|
|
105
|
+
hanchor: req["hanchor"] as! String,
|
|
106
|
+
hSignUserOp: req["h_sign_user_op"] as! String,
|
|
107
|
+
random: req["random"] as! String,
|
|
108
|
+
audHashList: req["aud_hash_list"] as! [String]
|
|
109
|
+
)
|
|
71
110
|
|
|
72
|
-
|
|
73
|
-
/// Throws ZkapError.rustError if the JSON contains an "error" field.
|
|
74
|
-
private static func unwrapResult(_ ptr: UnsafeMutablePointer<CChar>?) throws -> String {
|
|
75
|
-
guard let ptr = ptr else {
|
|
76
|
-
throw ZkapError.rustError("Rust FFI returned null pointer")
|
|
77
|
-
}
|
|
78
|
-
let json = String(cString: ptr)
|
|
111
|
+
let result = try prove(config: config, request: request)
|
|
79
112
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
113
|
+
let output: [String: Any] = [
|
|
114
|
+
"proofs": result.proofs,
|
|
115
|
+
"shared_inputs": result.sharedInputs,
|
|
116
|
+
"partial_rhs_list": result.partialRhsList,
|
|
117
|
+
"jwt_exp_list": result.jwtExpList
|
|
118
|
+
]
|
|
119
|
+
let outData = try JSONSerialization.data(withJSONObject: output)
|
|
120
|
+
return String(data: outData, encoding: .utf8)!
|
|
85
121
|
}
|
|
86
122
|
|
|
87
|
-
return json
|
|
88
123
|
}
|
|
89
124
|
}
|
|
90
125
|
|
|
91
126
|
// ──────────────────────────────────────────────────────────────────
|
|
92
|
-
//
|
|
127
|
+
// Helpers
|
|
93
128
|
// ──────────────────────────────────────────────────────────────────
|
|
94
129
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
130
|
+
private func parseConfig(_ d: [String: Any]) -> ZkapCircuitConfig {
|
|
131
|
+
ZkapCircuitConfig(
|
|
132
|
+
maxJwtB64Len: UInt64(d["max_jwt_b64_len"] as! Int),
|
|
133
|
+
maxPayloadB64Len: UInt64(d["max_payload_b64_len"] as! Int),
|
|
134
|
+
maxAudLen: UInt64(d["max_aud_len"] as! Int),
|
|
135
|
+
maxExpLen: UInt64(d["max_exp_len"] as! Int),
|
|
136
|
+
maxIssLen: UInt64(d["max_iss_len"] as! Int),
|
|
137
|
+
maxNonceLen: UInt64(d["max_nonce_len"] as! Int),
|
|
138
|
+
maxSubLen: UInt64(d["max_sub_len"] as! Int),
|
|
139
|
+
n: UInt64(d["n"] as! Int),
|
|
140
|
+
k: UInt64(d["k"] as! Int),
|
|
141
|
+
treeHeight: UInt64(d["tree_height"] as! Int),
|
|
142
|
+
numAudienceLimit: UInt64(d["num_audience_limit"] as! Int),
|
|
143
|
+
claims: d["claims"] as! [String],
|
|
144
|
+
forbiddenString: d["forbidden_string"] as! String
|
|
145
|
+
)
|
|
105
146
|
}
|
|
147
|
+
|
|
@@ -6,38 +6,38 @@
|
|
|
6
6
|
<array>
|
|
7
7
|
<dict>
|
|
8
8
|
<key>BinaryPath</key>
|
|
9
|
-
<string>
|
|
9
|
+
<string>libzkap_uniffi_bindings.a</string>
|
|
10
10
|
<key>HeadersPath</key>
|
|
11
11
|
<string>Headers</string>
|
|
12
12
|
<key>LibraryIdentifier</key>
|
|
13
|
-
<string>ios-
|
|
13
|
+
<string>ios-arm64</string>
|
|
14
14
|
<key>LibraryPath</key>
|
|
15
|
-
<string>
|
|
15
|
+
<string>libzkap_uniffi_bindings.a</string>
|
|
16
16
|
<key>SupportedArchitectures</key>
|
|
17
17
|
<array>
|
|
18
18
|
<string>arm64</string>
|
|
19
|
-
<string>x86_64</string>
|
|
20
19
|
</array>
|
|
21
20
|
<key>SupportedPlatform</key>
|
|
22
21
|
<string>ios</string>
|
|
23
|
-
<key>SupportedPlatformVariant</key>
|
|
24
|
-
<string>simulator</string>
|
|
25
22
|
</dict>
|
|
26
23
|
<dict>
|
|
27
24
|
<key>BinaryPath</key>
|
|
28
|
-
<string>
|
|
25
|
+
<string>libzkap_uniffi_bindings.a</string>
|
|
29
26
|
<key>HeadersPath</key>
|
|
30
27
|
<string>Headers</string>
|
|
31
28
|
<key>LibraryIdentifier</key>
|
|
32
|
-
<string>ios-
|
|
29
|
+
<string>ios-arm64_x86_64-simulator</string>
|
|
33
30
|
<key>LibraryPath</key>
|
|
34
|
-
<string>
|
|
31
|
+
<string>libzkap_uniffi_bindings.a</string>
|
|
35
32
|
<key>SupportedArchitectures</key>
|
|
36
33
|
<array>
|
|
37
34
|
<string>arm64</string>
|
|
35
|
+
<string>x86_64</string>
|
|
38
36
|
</array>
|
|
39
37
|
<key>SupportedPlatform</key>
|
|
40
38
|
<string>ios</string>
|
|
39
|
+
<key>SupportedPlatformVariant</key>
|
|
40
|
+
<string>simulator</string>
|
|
41
41
|
</dict>
|
|
42
42
|
</array>
|
|
43
43
|
<key>CFBundlePackageType</key>
|