@tamga-network/zk 0.0.0-stage → 0.2.0
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/LICENSE +190 -0
- package/README.md +70 -2
- package/android/build.gradle +20 -0
- package/android/src/main/java/network/tamga/zk/TamgaZkModule.kt +41 -0
- package/android/src/main/jniLibs/arm64-v8a/libtamga_zk_prover.so +0 -0
- package/android/src/main/jniLibs/armeabi-v7a/libtamga_zk_prover.so +0 -0
- package/android/src/main/jniLibs/x86_64/libtamga_zk_prover.so +0 -0
- package/expo-module.config.json +15 -0
- package/lib/circuits.d.ts +10 -0
- package/lib/circuits.d.ts.map +1 -0
- package/lib/circuits.js +31 -0
- package/lib/circuits.js.map +1 -0
- package/lib/index.d.ts +18 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +16 -0
- package/lib/index.js.map +1 -0
- package/lib/native-checksums.json +8 -0
- package/lib/node.d.ts +17 -0
- package/lib/node.d.ts.map +1 -0
- package/lib/node.js +97 -0
- package/lib/node.js.map +1 -0
- package/lib/present.d.ts +32 -0
- package/lib/present.d.ts.map +1 -0
- package/lib/present.js +94 -0
- package/lib/present.js.map +1 -0
- package/lib/react-native.d.ts +10 -0
- package/lib/react-native.d.ts.map +1 -0
- package/lib/react-native.js +40 -0
- package/lib/react-native.js.map +1 -0
- package/lib/request.d.ts +29 -0
- package/lib/request.d.ts.map +1 -0
- package/lib/request.js +34 -0
- package/lib/request.js.map +1 -0
- package/lib/sources.d.ts +30 -0
- package/lib/sources.d.ts.map +1 -0
- package/lib/sources.js +70 -0
- package/lib/sources.js.map +1 -0
- package/lib/types.d.ts +54 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js +9 -0
- package/lib/types.js.map +1 -0
- package/package.json +54 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
Copyright 2026 Tamga Network
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
+
See the License for the specific language governing permissions and
|
|
190
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,71 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @tamga-network/zk
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Wallet-side zero-knowledge proofs for ISO mdoc credentials on Tamga Network ([ADR-0032](https://docs.tamga.network/adr/0032-zk-mdoc-presentation),
|
|
4
|
+
Longfellow ZK — the system the EU age-verification profile uses). The wallet proves a statement about a credential it holds — "in
|
|
5
|
+
this credential, `age_over_18` is `true`" — without showing the credential, the issuer's signature or any other element. The
|
|
6
|
+
issuer's credential is not changed (ZK1). Verification is `@tamga-network/verifier/zk`.
|
|
7
|
+
|
|
8
|
+
Any wallet on the network can use this package.
|
|
9
|
+
|
|
10
|
+
## Entry points
|
|
11
|
+
|
|
12
|
+
| Import | Runs on | What |
|
|
13
|
+
|---|---|---|
|
|
14
|
+
| `@tamga-network/zk` | everywhere (pure TS, React Native safe) | DCQL `mso_mdoc_zk` query → claims, circuit selection and check against the trust list (ZK2), ZK DeviceResponse (TS13 `ZkDocument`) |
|
|
15
|
+
| `@tamga-network/zk/react-native` | iOS, Android (Expo module `TamgaZk`) | on-device prover: Rust → static library (iOS) / `.so` (Android) |
|
|
16
|
+
| `@tamga-network/zk/node` | desktop, CI | prover as a child process (`tamga-zk-prove`): tests, conformance runs, development |
|
|
17
|
+
|
|
18
|
+
When no prover is available (Expo Go, unsupported phone, module missing) `available()` returns `false` and the wallet presents the
|
|
19
|
+
usual way (ZK5).
|
|
20
|
+
|
|
21
|
+
## Flow
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import { presentZk, zkQueryFromDcql, firstCircuitSource } from "@tamga-network/zk";
|
|
25
|
+
import { nativeProver } from "@tamga-network/zk/react-native";
|
|
26
|
+
|
|
27
|
+
const query = zkQueryFromDcql(dcqlCredentialQuery); // format "mso_mdoc_zk"
|
|
28
|
+
const response = await presentZk({
|
|
29
|
+
prover: nativeProver,
|
|
30
|
+
circuits: firstCircuitSource(bundledCircuits /* , httpCircuitSource(<circuit host>) */),
|
|
31
|
+
trustedCircuits: lotl.zk_circuits,
|
|
32
|
+
query,
|
|
33
|
+
deviceResponse, // the wallet's usual device-signed DeviceResponse for this session (never sent)
|
|
34
|
+
transcript, // OpenID4VP / DC API SessionTranscript
|
|
35
|
+
issuerX5chain, // issuer leaf (+ chain), DER
|
|
36
|
+
issuerKey, // issuer P-256 key, uncompressed point
|
|
37
|
+
});
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Circuit files (~300 KB, no personal data) are checked against the SHA-256 in the signed trust list before use, so their source
|
|
41
|
+
does not change trust: bundle them with the app, or fetch them with `httpCircuitSource` once a circuit host is published.
|
|
42
|
+
|
|
43
|
+
The device signature is made the usual way (hardware key, phone lock — WL11); the prover only takes the signed response as input.
|
|
44
|
+
Nothing leaves the device except the proof.
|
|
45
|
+
|
|
46
|
+
## Building the native parts
|
|
47
|
+
|
|
48
|
+
| Target | Command | Needs |
|
|
49
|
+
|---|---|---|
|
|
50
|
+
| Desktop prover (`bin/`) | `npm run zk:build -w @tamga-network/zk` | Rust (`rust/rust-toolchain.toml`); on Windows the patched upstream clone from `tools/zk-circuit` |
|
|
51
|
+
| Android (`android/src/main/jniLibs/`) | `npm run zk:android -w @tamga-network/zk` | Android NDK, `cargo-ndk` |
|
|
52
|
+
| iOS (`ios/TamgaZkProver.xcframework`) | `npm run zk:ios -w @tamga-network/zk` | macOS, Xcode |
|
|
53
|
+
|
|
54
|
+
Build outputs are not committed; the published package includes them. Packing (`scripts/pack-packages.mjs`) fails if any of the
|
|
55
|
+
three Android libraries is missing, and writes their SHA-256 checksums to `lib/native-checksums.json`.
|
|
56
|
+
|
|
57
|
+
**iOS (for now):** the iOS library needs macOS to build and has not been built yet. Until `ios/TamgaZkProver.xcframework` exists,
|
|
58
|
+
the module is Android-only: `expo-module.config.json` lists only `"android"` and the published package does not contain `ios/`, so
|
|
59
|
+
iOS apps build normally and `available()` returns `false` there (usual presentation, ZK5). Once the xcframework is built, packing
|
|
60
|
+
adds `ios/` and the `"apple"` platform automatically. The Rust core (`rust/`) uses the same pinned upstream commit
|
|
61
|
+
as the verifier (`packages/verifier/zk`).
|
|
62
|
+
|
|
63
|
+
## Status
|
|
64
|
+
|
|
65
|
+
Published on npm as the `0.2.0` test release; the stable `1.0.0` comes when everything is ready. In test releases the API
|
|
66
|
+
may change. Every release is built from this repository by GitHub Actions and carries npm provenance (verifiable link to
|
|
67
|
+
the source commit).
|
|
68
|
+
|
|
69
|
+
## License
|
|
70
|
+
|
|
71
|
+
Apache-2.0
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// @tamga-network/zk — Expo modülü (Android). Rust kütüphanesi `src/main/jniLibs/<abi>/libtamga_zk_prover.so` olarak gelir
|
|
2
|
+
// (packages/zk/scripts/build-android.mjs; depoya girmez, paket yayınında dahil edilir).
|
|
3
|
+
plugins {
|
|
4
|
+
id 'com.android.library'
|
|
5
|
+
id 'expo-module-gradle-plugin'
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
group = 'network.tamga'
|
|
9
|
+
version = '1.0.0'
|
|
10
|
+
|
|
11
|
+
android {
|
|
12
|
+
namespace "network.tamga.zk"
|
|
13
|
+
defaultConfig {
|
|
14
|
+
versionCode 1
|
|
15
|
+
versionName '1.0.0'
|
|
16
|
+
ndk {
|
|
17
|
+
abiFilters 'arm64-v8a', 'armeabi-v7a', 'x86_64'
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// @tamga-network/zk — Android yerel ispatçı (ADR-0032 Aşama 2). Rust `tamga_zk_prover` kütüphanesi (`scripts/build-android.mjs`,
|
|
2
|
+
// cargo-ndk → jniLibs/<abi>/libtamga_zk_prover.so) JNI ile çağrılır. Girdi tamponu biçimi packages/zk/rust/src/lib.rs.
|
|
3
|
+
// İspat cihazda üretilir; girdiler (belge, cihaz imzası) ağa ya da diske yazılmaz, günlüklenmez. Kütüphane yoksa (ABI desteklenmiyor,
|
|
4
|
+
// derlemeye girmemiş) isSupported() false döner ve cüzdan olağan sunuma döner (ZK5).
|
|
5
|
+
package network.tamga.zk
|
|
6
|
+
|
|
7
|
+
import expo.modules.kotlin.exception.CodedException
|
|
8
|
+
import expo.modules.kotlin.modules.Module
|
|
9
|
+
import expo.modules.kotlin.modules.ModuleDefinition
|
|
10
|
+
|
|
11
|
+
internal object ZkNative {
|
|
12
|
+
val loaded: Boolean = try {
|
|
13
|
+
System.loadLibrary("tamga_zk_prover")
|
|
14
|
+
true
|
|
15
|
+
} catch (_: Throwable) {
|
|
16
|
+
false
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
@JvmStatic external fun circuitVersion(): Int
|
|
20
|
+
|
|
21
|
+
/** Başarıda ispat baytları; hatada `null` — hata kodu/ayrıntısı Kotlin'e geçmez (kişi verisi içerebilir; rust/src/lib.rs). */
|
|
22
|
+
@JvmStatic external fun prove(input: ByteArray): ByteArray?
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
internal class ProveFailedException : CodedException("ERR_ZK_PROVE_FAILED", "TamgaZk: the proof could not be created", null)
|
|
26
|
+
|
|
27
|
+
class TamgaZkModule : Module() {
|
|
28
|
+
override fun definition() = ModuleDefinition {
|
|
29
|
+
Name("TamgaZk")
|
|
30
|
+
|
|
31
|
+
Function("isSupported") { ZkNative.loaded }
|
|
32
|
+
|
|
33
|
+
Function("circuitVersion") { if (ZkNative.loaded) ZkNative.circuitVersion() else 0 }
|
|
34
|
+
|
|
35
|
+
// Ağır iş (~0,5–3 sn): Expo AsyncFunction arka plan iş parçacığında çalışır, arayüzü kilitlemez.
|
|
36
|
+
AsyncFunction("prove") { input: ByteArray ->
|
|
37
|
+
if (!ZkNative.loaded) throw ProveFailedException()
|
|
38
|
+
ZkNative.prove(input) ?: throw ProveFailedException()
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type ZkCircuitEntry, type ZkCircuitSource } from "./types.js";
|
|
2
|
+
export declare const ZK_SYSTEM = "longfellow-libzk-v1";
|
|
3
|
+
/**
|
|
4
|
+
* `attributes` öğeli istek için kullanılacak devre: etkin, sistem Longfellow, sürümü ispatçınınkiyle aynı, öğe sayısı eşleşen.
|
|
5
|
+
* Birden çok uygun devre varsa listedeki ilki (yayıncı sırası). Yoksa `no_circuit`.
|
|
6
|
+
*/
|
|
7
|
+
export declare function selectCircuit(list: readonly ZkCircuitEntry[] | undefined, attributes: number, version: number): ZkCircuitEntry;
|
|
8
|
+
/** Devre baytlarını kaynaktan alır ve listedeki SHA-256 ile karşılaştırır (eşleşmezse kullanılmaz). */
|
|
9
|
+
export declare function loadCircuit(source: ZkCircuitSource, entry: ZkCircuitEntry): Promise<Uint8Array>;
|
|
10
|
+
//# sourceMappingURL=circuits.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"circuits.d.ts","sourceRoot":"","sources":["../src/circuits.ts"],"names":[],"mappings":"AAMA,OAAO,EAAW,KAAK,cAAc,EAAE,KAAK,eAAe,EAAE,MAAM,YAAY,CAAC;AAEhF,eAAO,MAAM,SAAS,wBAAwB,CAAC;AAE/C;;;GAGG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,SAAS,cAAc,EAAE,GAAG,SAAS,EAC3C,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,MAAM,GACd,cAAc,CAUhB;AAED,uGAAuG;AACvG,wBAAsB,WAAW,CAAC,MAAM,EAAE,eAAe,EAAE,KAAK,EAAE,cAAc,GAAG,OAAO,CAAC,UAAU,CAAC,CAMrG"}
|
package/lib/circuits.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Devre seçimi ve denetimi (ZK2: yalnız güven listesinde yayınlanan ve özetiyle sabitlenen devre kullanılır). Cüzdan ve doğrulayıcı
|
|
3
|
+
* aynı listeye bakar; ispatçı listede olmayan devreyle ispat üretmez.
|
|
4
|
+
*/
|
|
5
|
+
import { sha256 } from "@noble/hashes/sha2.js";
|
|
6
|
+
import { bytesToHex } from "@noble/hashes/utils.js";
|
|
7
|
+
import { ZkError } from "./types.js";
|
|
8
|
+
export const ZK_SYSTEM = "longfellow-libzk-v1";
|
|
9
|
+
/**
|
|
10
|
+
* `attributes` öğeli istek için kullanılacak devre: etkin, sistem Longfellow, sürümü ispatçınınkiyle aynı, öğe sayısı eşleşen.
|
|
11
|
+
* Birden çok uygun devre varsa listedeki ilki (yayıncı sırası). Yoksa `no_circuit`.
|
|
12
|
+
*/
|
|
13
|
+
export function selectCircuit(list, attributes, version) {
|
|
14
|
+
const c = (list ?? []).find((x) => x.status.toUpperCase() === "ACTIVE" &&
|
|
15
|
+
x.system === ZK_SYSTEM &&
|
|
16
|
+
x.version === version &&
|
|
17
|
+
x.attributes === attributes);
|
|
18
|
+
if (!c)
|
|
19
|
+
throw new ZkError("no_circuit", `no active circuit for ${attributes} attribute(s), version ${version}`);
|
|
20
|
+
return c;
|
|
21
|
+
}
|
|
22
|
+
/** Devre baytlarını kaynaktan alır ve listedeki SHA-256 ile karşılaştırır (eşleşmezse kullanılmaz). */
|
|
23
|
+
export async function loadCircuit(source, entry) {
|
|
24
|
+
const bytes = await source.get(entry.circuit_id);
|
|
25
|
+
if (!bytes)
|
|
26
|
+
throw new ZkError("no_circuit", `circuit ${entry.circuit_id} is not available on this device`);
|
|
27
|
+
if (bytesToHex(sha256(bytes)) !== entry.sha256)
|
|
28
|
+
throw new ZkError("circuit_mismatch", "circuit does not match the trust list");
|
|
29
|
+
return bytes;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=circuits.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"circuits.js","sourceRoot":"","sources":["../src/circuits.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,OAAO,EAA6C,MAAM,YAAY,CAAC;AAEhF,MAAM,CAAC,MAAM,SAAS,GAAG,qBAAqB,CAAC;AAE/C;;;GAGG;AACH,MAAM,UAAU,aAAa,CAC3B,IAA2C,EAC3C,UAAkB,EAClB,OAAe;IAEf,MAAM,CAAC,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,IAAI,CACzB,CAAC,CAAC,EAAE,EAAE,CACJ,CAAC,CAAC,MAAM,CAAC,WAAW,EAAE,KAAK,QAAQ;QACnC,CAAC,CAAC,MAAM,KAAK,SAAS;QACtB,CAAC,CAAC,OAAO,KAAK,OAAO;QACrB,CAAC,CAAC,UAAU,KAAK,UAAU,CAC9B,CAAC;IACF,IAAI,CAAC,CAAC;QAAE,MAAM,IAAI,OAAO,CAAC,YAAY,EAAE,yBAAyB,UAAU,0BAA0B,OAAO,EAAE,CAAC,CAAC;IAChH,OAAO,CAAC,CAAC;AACX,CAAC;AAED,uGAAuG;AACvG,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,MAAuB,EAAE,KAAqB;IAC9E,MAAM,KAAK,GAAG,MAAM,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IACjD,IAAI,CAAC,KAAK;QAAE,MAAM,IAAI,OAAO,CAAC,YAAY,EAAE,WAAW,KAAK,CAAC,UAAU,kCAAkC,CAAC,CAAC;IAC3G,IAAI,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,KAAK,CAAC,MAAM;QAC5C,MAAM,IAAI,OAAO,CAAC,kBAAkB,EAAE,uCAAuC,CAAC,CAAC;IACjF,OAAO,KAAK,CAAC;AACf,CAAC"}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @tamga-network/zk — cüzdan tarafında sıfır bilgi ispatı (ADR-0032 Aşama 2, Longfellow ZK). Kurumun imzaladığı mdoc belgesi
|
|
3
|
+
* hakkında "şu öğe şu değerdedir" ispatını üretir (ilk kullanım: 18 yaş üstü); belge, kurum imzası ve diğer öğeler gösterilmez.
|
|
4
|
+
*
|
|
5
|
+
* - Çekirdek (bu giriş): saf TS, React Native uyumlu — DCQL'den istek, devre seçimi ve denetimi, ZK DeviceResponse.
|
|
6
|
+
* - `@tamga-network/zk/react-native`: telefonda yerel ispatçı (Expo modülü; Rust → iOS/Android).
|
|
7
|
+
* - `@tamga-network/zk/node`: masaüstü ispatçı (alt süreç) — test, uyum denemesi, geliştirme.
|
|
8
|
+
*
|
|
9
|
+
* Ağdaki her cüzdan kullanabilir; doğrulama tarafı `@tamga-network/verifier/zk`.
|
|
10
|
+
*/
|
|
11
|
+
export * from "./types.js";
|
|
12
|
+
export { ZK_FORMAT, isZkQuery, zkQueryFromDcql } from "./request.js";
|
|
13
|
+
export type { DcqlCredentialQuery, ZkQuery } from "./request.js";
|
|
14
|
+
export { ZK_SYSTEM, selectCircuit, loadCircuit } from "./circuits.js";
|
|
15
|
+
export { presentZk, encodeProveBuffer } from "./present.js";
|
|
16
|
+
export type { ZkPresentArgs } from "./present.js";
|
|
17
|
+
export { memoryCircuitSource, httpCircuitSource, firstCircuitSource, unavailableProver } from "./sources.js";
|
|
18
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACrE,YAAY,EAAE,mBAAmB,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACtE,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAC5D,YAAY,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC"}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @tamga-network/zk — cüzdan tarafında sıfır bilgi ispatı (ADR-0032 Aşama 2, Longfellow ZK). Kurumun imzaladığı mdoc belgesi
|
|
3
|
+
* hakkında "şu öğe şu değerdedir" ispatını üretir (ilk kullanım: 18 yaş üstü); belge, kurum imzası ve diğer öğeler gösterilmez.
|
|
4
|
+
*
|
|
5
|
+
* - Çekirdek (bu giriş): saf TS, React Native uyumlu — DCQL'den istek, devre seçimi ve denetimi, ZK DeviceResponse.
|
|
6
|
+
* - `@tamga-network/zk/react-native`: telefonda yerel ispatçı (Expo modülü; Rust → iOS/Android).
|
|
7
|
+
* - `@tamga-network/zk/node`: masaüstü ispatçı (alt süreç) — test, uyum denemesi, geliştirme.
|
|
8
|
+
*
|
|
9
|
+
* Ağdaki her cüzdan kullanabilir; doğrulama tarafı `@tamga-network/verifier/zk`.
|
|
10
|
+
*/
|
|
11
|
+
export * from "./types.js";
|
|
12
|
+
export { ZK_FORMAT, isZkQuery, zkQueryFromDcql } from "./request.js";
|
|
13
|
+
export { ZK_SYSTEM, selectCircuit, loadCircuit } from "./circuits.js";
|
|
14
|
+
export { presentZk, encodeProveBuffer } from "./present.js";
|
|
15
|
+
export { memoryCircuitSource, httpCircuitSource, firstCircuitSource, unavailableProver } from "./sources.js";
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAErE,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACtE,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAE5D,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
{
|
|
2
|
+
"note": "SHA-256 of the packed native prover libraries (ADR-0032)",
|
|
3
|
+
"files": {
|
|
4
|
+
"android/src/main/jniLibs/arm64-v8a/libtamga_zk_prover.so": "fe9e421a4ea70cc61f02ea5b714917648d82812ce151c02335bad1ef01dfaac2",
|
|
5
|
+
"android/src/main/jniLibs/armeabi-v7a/libtamga_zk_prover.so": "ea55f289a6ef49ad21a2ef21fbc75c0d5efbcd6911af1d31d351bc1b6be7485e",
|
|
6
|
+
"android/src/main/jniLibs/x86_64/libtamga_zk_prover.so": "7aba0a6566339d68f1243d9e0dd5bf9f8404838e50e5de142606ad4ec8f3b49e"
|
|
7
|
+
}
|
|
8
|
+
}
|
package/lib/node.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type ZkCircuitSource, type ZkProveArgs, type ZkProver } from "./types.js";
|
|
2
|
+
export declare class NodeProcessProver implements ZkProver {
|
|
3
|
+
private readonly bin;
|
|
4
|
+
private readonly timeoutMs;
|
|
5
|
+
readonly name = "node-process";
|
|
6
|
+
private version?;
|
|
7
|
+
constructor(bin: string, timeoutMs?: number);
|
|
8
|
+
available(): Promise<boolean>;
|
|
9
|
+
circuitVersion(): Promise<number>;
|
|
10
|
+
prove(args: ZkProveArgs): Promise<Uint8Array>;
|
|
11
|
+
private run;
|
|
12
|
+
}
|
|
13
|
+
/** Varsayılan ikili yolu: `TAMGA_ZK_PROVE_BIN` ya da derleme betiğinin çıktısı (`packages/zk/bin/`). */
|
|
14
|
+
export declare function defaultProverBin(): string;
|
|
15
|
+
/** Klasördeki devre dosyaları (`<circuit_id>.zst`). */
|
|
16
|
+
export declare function fileCircuitSource(dir: string): ZkCircuitSource;
|
|
17
|
+
//# sourceMappingURL=node.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AAUA,OAAO,EAAW,KAAK,eAAe,EAAE,KAAK,WAAW,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,CAAC;AAI5F,qBAAa,iBAAkB,YAAW,QAAQ;IAI9C,OAAO,CAAC,QAAQ,CAAC,GAAG;IACpB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAJ5B,QAAQ,CAAC,IAAI,kBAAkB;IAC/B,OAAO,CAAC,OAAO,CAAC,CAAS;gBAEN,GAAG,EAAE,MAAM,EACX,SAAS,SAAS;IAG/B,SAAS;IAUT,cAAc;IAOd,KAAK,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC;IAanD,OAAO,CAAC,GAAG;CAoBZ;AAED,wGAAwG;AACxG,wBAAgB,gBAAgB,IAAI,MAAM,CAIzC;AAED,uDAAuD;AACvD,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,eAAe,CAQ9D"}
|
package/lib/node.js
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @tamga-network/zk/node — masaüstü ispatçısı: Rust `tamga-zk-prove` ikilisini alt süreç olarak çalıştırır (stdin/stdout, ağ yok,
|
|
3
|
+
* dosya yok). Test, uyum denemesi ve geliştirme içindir; telefonda aynı Rust kodu yerel kütüphane olarak çalışır
|
|
4
|
+
* (`@tamga-network/zk/react-native`). İkili: `npm run zk:build -w @tamga-network/zk` (packages/zk/scripts/build-cli.mjs).
|
|
5
|
+
*/
|
|
6
|
+
import { spawn } from "node:child_process";
|
|
7
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
8
|
+
import { join } from "node:path";
|
|
9
|
+
import { fileURLToPath } from "node:url";
|
|
10
|
+
import { encodeProveBuffer } from "./present.js";
|
|
11
|
+
import { ZkError } from "./types.js";
|
|
12
|
+
const MAX_OUTPUT = 4 * 1024 * 1024;
|
|
13
|
+
export class NodeProcessProver {
|
|
14
|
+
bin;
|
|
15
|
+
timeoutMs;
|
|
16
|
+
name = "node-process";
|
|
17
|
+
version;
|
|
18
|
+
constructor(bin, timeoutMs = 60_000) {
|
|
19
|
+
this.bin = bin;
|
|
20
|
+
this.timeoutMs = timeoutMs;
|
|
21
|
+
}
|
|
22
|
+
async available() {
|
|
23
|
+
if (!existsSync(this.bin))
|
|
24
|
+
return false;
|
|
25
|
+
try {
|
|
26
|
+
await this.circuitVersion();
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
async circuitVersion() {
|
|
34
|
+
if (this.version !== undefined)
|
|
35
|
+
return this.version;
|
|
36
|
+
const out = await this.run(["--info"]);
|
|
37
|
+
this.version = JSON.parse(new TextDecoder().decode(out)).circuit_version;
|
|
38
|
+
return this.version;
|
|
39
|
+
}
|
|
40
|
+
async prove(args) {
|
|
41
|
+
const req = encodeProveBuffer(args);
|
|
42
|
+
const frame = new Uint8Array(4 + req.length);
|
|
43
|
+
new DataView(frame.buffer).setUint32(0, req.length, true);
|
|
44
|
+
frame.set(req, 4);
|
|
45
|
+
const out = await this.run([], frame);
|
|
46
|
+
if (out.length < 4)
|
|
47
|
+
throw new ZkError("prove_failed", "prover returned no result");
|
|
48
|
+
const dv = new DataView(out.buffer, out.byteOffset, out.byteLength);
|
|
49
|
+
if (dv.getInt32(0, true) !== 0)
|
|
50
|
+
throw new ZkError("prove_failed", "the proof could not be created");
|
|
51
|
+
const n = dv.getUint32(4, true);
|
|
52
|
+
return out.slice(8, 8 + n);
|
|
53
|
+
}
|
|
54
|
+
run(argv, input) {
|
|
55
|
+
return new Promise((resolve, reject) => {
|
|
56
|
+
const p = spawn(this.bin, argv, { stdio: ["pipe", "pipe", "ignore"], windowsHide: true });
|
|
57
|
+
const chunks = [];
|
|
58
|
+
let size = 0;
|
|
59
|
+
const timer = setTimeout(() => p.kill(), this.timeoutMs);
|
|
60
|
+
p.stdout.on("data", (c) => {
|
|
61
|
+
size += c.length;
|
|
62
|
+
if (size > MAX_OUTPUT)
|
|
63
|
+
p.kill();
|
|
64
|
+
else
|
|
65
|
+
chunks.push(c);
|
|
66
|
+
});
|
|
67
|
+
p.on("error", (e) => (clearTimeout(timer), reject(e)));
|
|
68
|
+
p.on("close", () => {
|
|
69
|
+
clearTimeout(timer);
|
|
70
|
+
resolve(new Uint8Array(Buffer.concat(chunks)));
|
|
71
|
+
});
|
|
72
|
+
if (input)
|
|
73
|
+
p.stdin.end(Buffer.from(input));
|
|
74
|
+
else
|
|
75
|
+
p.stdin.end();
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/** Varsayılan ikili yolu: `TAMGA_ZK_PROVE_BIN` ya da derleme betiğinin çıktısı (`packages/zk/bin/`). */
|
|
80
|
+
export function defaultProverBin() {
|
|
81
|
+
if (process.env.TAMGA_ZK_PROVE_BIN)
|
|
82
|
+
return process.env.TAMGA_ZK_PROVE_BIN;
|
|
83
|
+
const exe = process.platform === "win32" ? "tamga-zk-prove.exe" : "tamga-zk-prove";
|
|
84
|
+
return join(fileURLToPath(new URL("../bin/", import.meta.url)), exe);
|
|
85
|
+
}
|
|
86
|
+
/** Klasördeki devre dosyaları (`<circuit_id>.zst`). */
|
|
87
|
+
export function fileCircuitSource(dir) {
|
|
88
|
+
return {
|
|
89
|
+
get: async (id) => {
|
|
90
|
+
if (!/^[0-9a-f]{64}$/.test(id))
|
|
91
|
+
return undefined;
|
|
92
|
+
const p = join(dir, `${id}.zst`);
|
|
93
|
+
return existsSync(p) ? new Uint8Array(readFileSync(p)) : undefined;
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=node.js.map
|
package/lib/node.js.map
ADDED
|
@@ -0,0 +1 @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GAAG,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,gBAAgB,CAAC;IACnF,OAAO,IAAI,CAAC,aAAa,CAAC,IAAI,GAAG,CAAC,SAAS,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;AACvE,CAAC;AAED,uDAAuD;AACvD,MAAM,UAAU,iBAAiB,CAAC,GAAW;IAC3C,OAAO;QACL,GAAG,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE;YAChB,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,EAAE,CAAC;gBAAE,OAAO,SAAS,CAAC;YACjD,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;YACjC,OAAO,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,UAAU,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QACrE,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/lib/present.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ZkQuery } from "./request.js";
|
|
2
|
+
import { type ZkCircuitEntry, type ZkCircuitSource, type ZkProveArgs, type ZkProver } from "./types.js";
|
|
3
|
+
export interface ZkPresentArgs {
|
|
4
|
+
prover: ZkProver;
|
|
5
|
+
circuits: ZkCircuitSource;
|
|
6
|
+
/** Güven listesindeki devreler (`lotl.zk_circuits`). */
|
|
7
|
+
trustedCircuits: readonly ZkCircuitEntry[] | undefined;
|
|
8
|
+
/**
|
|
9
|
+
* Doğrulayıcının kabul ettiği devre kimlikleri (DCQL `meta.zk_system_type[].params.circuit_hash`). Verilirse yalnız hem güven
|
|
10
|
+
* listesinde hem bu listede olan devre kullanılır — doğrulayıcının kabul etmeyeceği ispat üretilmez.
|
|
11
|
+
*/
|
|
12
|
+
acceptedCircuits?: readonly string[];
|
|
13
|
+
query: ZkQuery;
|
|
14
|
+
/** Bu oturumun cihaz imzalı DeviceResponse'u (cüzdanın olağan mdoc sunumu; doğrulayıcıya gönderilmez). */
|
|
15
|
+
deviceResponse: Uint8Array;
|
|
16
|
+
transcript: Uint8Array;
|
|
17
|
+
/** Kurum yaprak sertifikası (+ zincir), DER; ZkDocument'e `msoX5chain` olarak girer. */
|
|
18
|
+
issuerX5chain: Uint8Array[];
|
|
19
|
+
/** Kurum anahtarı, P-256 sıkıştırılmamış nokta (65 bayt). */
|
|
20
|
+
issuerKey: Uint8Array;
|
|
21
|
+
/** Varsayılan: şimdi. */
|
|
22
|
+
now?: Date;
|
|
23
|
+
}
|
|
24
|
+
/** İspatı üretir ve doğrulayıcıya gidecek ZK DeviceResponse'u döndürür. Yapılamıyorsa `ZkError` (cüzdan olağan yola döner — ZK5). */
|
|
25
|
+
export declare function presentZk(a: ZkPresentArgs): Promise<Uint8Array>;
|
|
26
|
+
/**
|
|
27
|
+
* Arka uçların ortak girdi tamponu (Rust `prove_buffer`, packages/zk/rust/src/lib.rs): art arda `u32 LE uzunluk + bayt`.
|
|
28
|
+
* combined_hash(32) · circuit · device_response · transcript · pkx("0x…") · pky · now · doc_type · öğe sayısı (u32 LE)
|
|
29
|
+
* · her öğe için namespace · id · değerin CBOR'u
|
|
30
|
+
*/
|
|
31
|
+
export declare function encodeProveBuffer(a: ZkProveArgs): Uint8Array;
|
|
32
|
+
//# sourceMappingURL=present.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"present.d.ts","sourceRoot":"","sources":["../src/present.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAW,KAAK,cAAc,EAAE,KAAK,eAAe,EAAE,KAAK,WAAW,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEjH,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,QAAQ,CAAC;IACjB,QAAQ,EAAE,eAAe,CAAC;IAC1B,wDAAwD;IACxD,eAAe,EAAE,SAAS,cAAc,EAAE,GAAG,SAAS,CAAC;IACvD;;;OAGG;IACH,gBAAgB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACrC,KAAK,EAAE,OAAO,CAAC;IACf,0GAA0G;IAC1G,cAAc,EAAE,UAAU,CAAC;IAC3B,UAAU,EAAE,UAAU,CAAC;IACvB,wFAAwF;IACxF,aAAa,EAAE,UAAU,EAAE,CAAC;IAC5B,6DAA6D;IAC7D,SAAS,EAAE,UAAU,CAAC;IACtB,yBAAyB;IACzB,GAAG,CAAC,EAAE,IAAI,CAAC;CACZ;AAID,qIAAqI;AACrI,wBAAsB,SAAS,CAAC,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,UAAU,CAAC,CAoCrE;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,WAAW,GAAG,UAAU,CAyB5D"}
|
package/lib/present.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ZK sunumu (ADR-0032; AB TS13 §5): cüzdan önce bu oturum için olağan, cihaz imzalı DeviceResponse'u üretir (donanım anahtarı,
|
|
3
|
+
* telefon kilidi onayı — WL11 aynen), sonra ispatçı bu yanıttan "belgede şu öğeler şu değerdedir" ispatını üretir. Doğrulayıcıya
|
|
4
|
+
* yalnız ZkDocument gider: belge, MSO, cihaz anahtarı ve iptal listesi indeksi GİTMEZ (ZK3, ZK4).
|
|
5
|
+
*/
|
|
6
|
+
import { buildZkDeviceResponse, encode } from "@tamga-network/mdoc";
|
|
7
|
+
import { loadCircuit, selectCircuit } from "./circuits.js";
|
|
8
|
+
import { ZkError } from "./types.js";
|
|
9
|
+
const isoSeconds = (d) => d.toISOString().replace(/\.\d{3}Z$/, "Z");
|
|
10
|
+
/** İspatı üretir ve doğrulayıcıya gidecek ZK DeviceResponse'u döndürür. Yapılamıyorsa `ZkError` (cüzdan olağan yola döner — ZK5). */
|
|
11
|
+
export async function presentZk(a) {
|
|
12
|
+
if (!(await a.prover.available()))
|
|
13
|
+
throw new ZkError("unavailable", "zero-knowledge proofs are not available on this device");
|
|
14
|
+
const version = await a.prover.circuitVersion();
|
|
15
|
+
const trusted = a.acceptedCircuits
|
|
16
|
+
? (a.trustedCircuits ?? []).filter((c) => a.acceptedCircuits.includes(c.circuit_id))
|
|
17
|
+
: a.trustedCircuits;
|
|
18
|
+
const entry = selectCircuit(trusted, a.query.claims.length, version);
|
|
19
|
+
const circuit = await loadCircuit(a.circuits, entry);
|
|
20
|
+
const timestamp = isoSeconds(a.now ?? new Date());
|
|
21
|
+
let proof;
|
|
22
|
+
try {
|
|
23
|
+
proof = await a.prover.prove({
|
|
24
|
+
circuitId: entry.circuit_id,
|
|
25
|
+
circuit,
|
|
26
|
+
deviceResponse: a.deviceResponse,
|
|
27
|
+
transcript: a.transcript,
|
|
28
|
+
docType: a.query.docType,
|
|
29
|
+
claims: a.query.claims,
|
|
30
|
+
now: timestamp,
|
|
31
|
+
issuerKey: a.issuerKey,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
catch (e) {
|
|
35
|
+
if (e instanceof ZkError)
|
|
36
|
+
throw e;
|
|
37
|
+
throw new ZkError("prove_failed", "the proof could not be created");
|
|
38
|
+
}
|
|
39
|
+
const elements = {};
|
|
40
|
+
for (const c of a.query.claims)
|
|
41
|
+
elements[c.element] = c.value;
|
|
42
|
+
return buildZkDeviceResponse({
|
|
43
|
+
docType: a.query.docType,
|
|
44
|
+
zkSystemId: entry.circuit_id,
|
|
45
|
+
timestamp,
|
|
46
|
+
disclosed: { namespace: a.query.claims[0].namespace, elements },
|
|
47
|
+
msoX5chain: a.issuerX5chain,
|
|
48
|
+
proof,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Arka uçların ortak girdi tamponu (Rust `prove_buffer`, packages/zk/rust/src/lib.rs): art arda `u32 LE uzunluk + bayt`.
|
|
53
|
+
* combined_hash(32) · circuit · device_response · transcript · pkx("0x…") · pky · now · doc_type · öğe sayısı (u32 LE)
|
|
54
|
+
* · her öğe için namespace · id · değerin CBOR'u
|
|
55
|
+
*/
|
|
56
|
+
export function encodeProveBuffer(a) {
|
|
57
|
+
if (a.issuerKey.length !== 65 || a.issuerKey[0] !== 0x04)
|
|
58
|
+
throw new ZkError("unsupported_request", "issuer key must be an uncompressed P-256 point");
|
|
59
|
+
const te = new TextEncoder();
|
|
60
|
+
const fields = [
|
|
61
|
+
hexToBytes(a.circuitId),
|
|
62
|
+
a.circuit,
|
|
63
|
+
a.deviceResponse,
|
|
64
|
+
a.transcript,
|
|
65
|
+
te.encode("0x" + toHex(a.issuerKey.subarray(1, 33))),
|
|
66
|
+
te.encode("0x" + toHex(a.issuerKey.subarray(33, 65))),
|
|
67
|
+
te.encode(a.now),
|
|
68
|
+
te.encode(a.docType),
|
|
69
|
+
u32(a.claims.length),
|
|
70
|
+
];
|
|
71
|
+
for (const c of a.claims)
|
|
72
|
+
fields.push(te.encode(c.namespace), te.encode(c.element), encode(c.value));
|
|
73
|
+
const out = new Uint8Array(fields.reduce((n, f) => n + 4 + f.length, 0));
|
|
74
|
+
const dv = new DataView(out.buffer);
|
|
75
|
+
let at = 0;
|
|
76
|
+
for (const f of fields) {
|
|
77
|
+
dv.setUint32(at, f.length, true);
|
|
78
|
+
out.set(f, at + 4);
|
|
79
|
+
at += 4 + f.length;
|
|
80
|
+
}
|
|
81
|
+
return out;
|
|
82
|
+
}
|
|
83
|
+
const toHex = (b) => Array.from(b, (x) => x.toString(16).padStart(2, "0")).join("");
|
|
84
|
+
function u32(n) {
|
|
85
|
+
const b = new Uint8Array(4);
|
|
86
|
+
new DataView(b.buffer).setUint32(0, n, true);
|
|
87
|
+
return b;
|
|
88
|
+
}
|
|
89
|
+
function hexToBytes(h) {
|
|
90
|
+
if (!/^[0-9a-f]{64}$/.test(h))
|
|
91
|
+
throw new ZkError("unsupported_request", "circuit id must be 64 lowercase hex characters");
|
|
92
|
+
return Uint8Array.from(h.match(/../g), (x) => parseInt(x, 16));
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=present.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"present.js","sourceRoot":"","sources":["../src/present.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,qBAAqB,EAAE,MAAM,EAAkB,MAAM,qBAAqB,CAAC;AACpF,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAE3D,OAAO,EAAE,OAAO,EAA8E,MAAM,YAAY,CAAC;AAwBjH,MAAM,UAAU,GAAG,CAAC,CAAO,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC;AAE1E,qIAAqI;AACrI,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,CAAgB;IAC9C,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC;QAC/B,MAAM,IAAI,OAAO,CAAC,aAAa,EAAE,wDAAwD,CAAC,CAAC;IAC7F,MAAM,OAAO,GAAG,MAAM,CAAC,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC;IAChD,MAAM,OAAO,GAAG,CAAC,CAAC,gBAAgB;QAChC,CAAC,CAAC,CAAC,CAAC,CAAC,eAAe,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,gBAAiB,CAAC,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC;QACrF,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC;IACtB,MAAM,KAAK,GAAG,aAAa,CAAC,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrE,MAAM,OAAO,GAAG,MAAM,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,10 @@
|
|
|
1
|
+
import { type ZkProveArgs, type ZkProver } from "./types.js";
|
|
2
|
+
export declare class NativeModuleProver implements ZkProver {
|
|
3
|
+
readonly name = "native-module";
|
|
4
|
+
available(): Promise<boolean>;
|
|
5
|
+
circuitVersion(): Promise<number>;
|
|
6
|
+
prove(args: ZkProveArgs): Promise<Uint8Array>;
|
|
7
|
+
}
|
|
8
|
+
/** Uygulamanın tek ispatçısı. */
|
|
9
|
+
export declare const nativeProver: NativeModuleProver;
|
|
10
|
+
//# sourceMappingURL=react-native.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react-native.d.ts","sourceRoot":"","sources":["../src/react-native.ts"],"names":[],"mappings":"AAOA,OAAO,EAAW,KAAK,WAAW,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,CAAC;AAUtE,qBAAa,kBAAmB,YAAW,QAAQ;IACjD,QAAQ,CAAC,IAAI,mBAAmB;IAE1B,SAAS;IAQT,cAAc;IAKd,KAAK,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC;CASpD;AAED,iCAAiC;AACjC,eAAO,MAAM,YAAY,oBAA2B,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @tamga-network/zk/react-native — telefonda yerel ispatçı (Expo modülü `TamgaZk`; Rust → Android .so / iOS xcframework).
|
|
3
|
+
* Modül yalnız geliştirme ve mağaza derlemesinde vardır; Expo Go'da ya da desteklenmeyen telefonda `available()` false döner ve
|
|
4
|
+
* cüzdan olağan sunuma döner (ZK5). İspat telefonda üretilir; belge ve cihaz imzası telefondan çıkmaz.
|
|
5
|
+
*/
|
|
6
|
+
import { requireOptionalNativeModule } from "expo-modules-core";
|
|
7
|
+
import { encodeProveBuffer } from "./present.js";
|
|
8
|
+
import { ZkError } from "./types.js";
|
|
9
|
+
const native = requireOptionalNativeModule("TamgaZk");
|
|
10
|
+
export class NativeModuleProver {
|
|
11
|
+
name = "native-module";
|
|
12
|
+
async available() {
|
|
13
|
+
try {
|
|
14
|
+
return !!native && native.isSupported();
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
async circuitVersion() {
|
|
21
|
+
if (!native)
|
|
22
|
+
throw new ZkError("unavailable", "zero-knowledge prover is not available");
|
|
23
|
+
return native.circuitVersion();
|
|
24
|
+
}
|
|
25
|
+
async prove(args) {
|
|
26
|
+
if (!native)
|
|
27
|
+
throw new ZkError("unavailable", "zero-knowledge prover is not available");
|
|
28
|
+
try {
|
|
29
|
+
return await native.prove(encodeProveBuffer(args));
|
|
30
|
+
}
|
|
31
|
+
catch (e) {
|
|
32
|
+
if (e instanceof ZkError)
|
|
33
|
+
throw e;
|
|
34
|
+
throw new ZkError("prove_failed", "the proof could not be created");
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/** Uygulamanın tek ispatçısı. */
|
|
39
|
+
export const nativeProver = new NativeModuleProver();
|
|
40
|
+
//# sourceMappingURL=react-native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react-native.js","sourceRoot":"","sources":["../src/react-native.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,2BAA2B,EAAE,MAAM,mBAAmB,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,OAAO,EAAmC,MAAM,YAAY,CAAC;AAQtE,MAAM,MAAM,GAAG,2BAA2B,CAAgB,SAAS,CAAC,CAAC;AAErE,MAAM,OAAO,kBAAkB;IACpB,IAAI,GAAG,eAAe,CAAC;IAEhC,KAAK,CAAC,SAAS;QACb,IAAI,CAAC;YACH,OAAO,CAAC,CAAC,MAAM,IAAI,MAAM,CAAC,WAAW,EAAE,CAAC;QAC1C,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IAED,KAAK,CAAC,cAAc;QAClB,IAAI,CAAC,MAAM;YAAE,MAAM,IAAI,OAAO,CAAC,aAAa,EAAE,wCAAwC,CAAC,CAAC;QACxF,OAAO,MAAM,CAAC,cAAc,EAAE,CAAC;IACjC,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,IAAiB;QAC3B,IAAI,CAAC,MAAM;YAAE,MAAM,IAAI,OAAO,CAAC,aAAa,EAAE,wCAAwC,CAAC,CAAC;QACxF,IAAI,CAAC;YACH,OAAO,MAAM,MAAM,CAAC,KAAK,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC,CAAC;QACrD,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,IAAI,CAAC,YAAY,OAAO;gBAAE,MAAM,CAAC,CAAC;YAClC,MAAM,IAAI,OAAO,CAAC,cAAc,EAAE,gCAAgC,CAAC,CAAC;QACtE,CAAC;IACH,CAAC;CACF;AAED,iCAAiC;AACjC,MAAM,CAAC,MAAM,YAAY,GAAG,IAAI,kBAAkB,EAAE,CAAC"}
|
package/lib/request.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DCQL isteğinden ZK ile ispatlanacak öğeleri çıkarır (ADR-0032; AB TS13 `format: "mso_mdoc_zk"`). ZK ispatı yalnız sabit değerli
|
|
3
|
+
* öğeleri kanıtlar ("age_over_18 = true"): tek bir beklenen değeri olmayan öğe ZK ile istenemez (ZK açıklama değil, ispattır).
|
|
4
|
+
* Bir sorgu tek belge türü ve tek ad alanı içerir (ZK6: bir belge türünde bir öğe adı yalnız bir ad alanında bulunur).
|
|
5
|
+
*/
|
|
6
|
+
import { type ZkClaim } from "./types.js";
|
|
7
|
+
export declare const ZK_FORMAT = "mso_mdoc_zk";
|
|
8
|
+
/** DCQL `credentials[]` öğesinin bu paketi ilgilendiren kısmı. */
|
|
9
|
+
export interface DcqlCredentialQuery {
|
|
10
|
+
id: string;
|
|
11
|
+
format: string;
|
|
12
|
+
meta?: {
|
|
13
|
+
doctype_value?: string;
|
|
14
|
+
};
|
|
15
|
+
claims?: {
|
|
16
|
+
path: (string | number)[];
|
|
17
|
+
values?: unknown[];
|
|
18
|
+
}[];
|
|
19
|
+
}
|
|
20
|
+
export interface ZkQuery {
|
|
21
|
+
queryId: string;
|
|
22
|
+
docType: string;
|
|
23
|
+
claims: ZkClaim[];
|
|
24
|
+
}
|
|
25
|
+
/** Sorgu ZK sorgusu mu? */
|
|
26
|
+
export declare const isZkQuery: (q: DcqlCredentialQuery) => boolean;
|
|
27
|
+
/** ZK sorgusunu ispatlanacak öğelere çevirir; ispatlanamayan biçimdeyse `unsupported_request`. */
|
|
28
|
+
export declare function zkQueryFromDcql(q: DcqlCredentialQuery): ZkQuery;
|
|
29
|
+
//# sourceMappingURL=request.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../src/request.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAW,KAAK,OAAO,EAAE,MAAM,YAAY,CAAC;AAEnD,eAAO,MAAM,SAAS,gBAAgB,CAAC;AAEvC,kEAAkE;AAClE,MAAM,WAAW,mBAAmB;IAClC,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE;QAAE,aAAa,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAClC,MAAM,CAAC,EAAE;QAAE,IAAI,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;QAAC,MAAM,CAAC,EAAE,OAAO,EAAE,CAAA;KAAE,EAAE,CAAC;CAC9D;AAED,MAAM,WAAW,OAAO;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,OAAO,EAAE,CAAC;CACnB;AAED,2BAA2B;AAC3B,eAAO,MAAM,SAAS,GAAI,GAAG,mBAAmB,YAA2B,CAAC;AAE5E,kGAAkG;AAClG,wBAAgB,eAAe,CAAC,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAmB/D"}
|
package/lib/request.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DCQL isteğinden ZK ile ispatlanacak öğeleri çıkarır (ADR-0032; AB TS13 `format: "mso_mdoc_zk"`). ZK ispatı yalnız sabit değerli
|
|
3
|
+
* öğeleri kanıtlar ("age_over_18 = true"): tek bir beklenen değeri olmayan öğe ZK ile istenemez (ZK açıklama değil, ispattır).
|
|
4
|
+
* Bir sorgu tek belge türü ve tek ad alanı içerir (ZK6: bir belge türünde bir öğe adı yalnız bir ad alanında bulunur).
|
|
5
|
+
*/
|
|
6
|
+
import { ZkError } from "./types.js";
|
|
7
|
+
export const ZK_FORMAT = "mso_mdoc_zk";
|
|
8
|
+
/** Sorgu ZK sorgusu mu? */
|
|
9
|
+
export const isZkQuery = (q) => q.format === ZK_FORMAT;
|
|
10
|
+
/** ZK sorgusunu ispatlanacak öğelere çevirir; ispatlanamayan biçimdeyse `unsupported_request`. */
|
|
11
|
+
export function zkQueryFromDcql(q) {
|
|
12
|
+
if (!isZkQuery(q))
|
|
13
|
+
throw new ZkError("unsupported_request", `not a ${ZK_FORMAT} query`);
|
|
14
|
+
const docType = q.meta?.doctype_value;
|
|
15
|
+
if (!docType)
|
|
16
|
+
throw new ZkError("unsupported_request", "doctype_value missing");
|
|
17
|
+
const claims = (q.claims ?? []).map((c) => {
|
|
18
|
+
const [namespace, element] = c.path;
|
|
19
|
+
if (c.path.length !== 2 || typeof namespace !== "string" || typeof element !== "string")
|
|
20
|
+
throw new ZkError("unsupported_request", "claim path must be [namespace, element]");
|
|
21
|
+
if (!c.values || c.values.length !== 1)
|
|
22
|
+
throw new ZkError("unsupported_request", `claim ${element}: exactly one expected value is required`);
|
|
23
|
+
const v = c.values[0];
|
|
24
|
+
if (typeof v !== "boolean" && typeof v !== "string" && typeof v !== "number")
|
|
25
|
+
throw new ZkError("unsupported_request", `claim ${element}: value type not supported`);
|
|
26
|
+
return { namespace, element, value: v };
|
|
27
|
+
});
|
|
28
|
+
if (claims.length === 0)
|
|
29
|
+
throw new ZkError("unsupported_request", "no claims");
|
|
30
|
+
if (new Set(claims.map((c) => c.namespace)).size > 1)
|
|
31
|
+
throw new ZkError("unsupported_request", "claims must share one namespace");
|
|
32
|
+
return { queryId: q.id, docType, claims };
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=request.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request.js","sourceRoot":"","sources":["../src/request.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,OAAO,EAAgB,MAAM,YAAY,CAAC;AAEnD,MAAM,CAAC,MAAM,SAAS,GAAG,aAAa,CAAC;AAgBvC,2BAA2B;AAC3B,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAAsB,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,SAAS,CAAC;AAE5E,kGAAkG;AAClG,MAAM,UAAU,eAAe,CAAC,CAAsB;IACpD,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;QAAE,MAAM,IAAI,OAAO,CAAC,qBAAqB,EAAE,SAAS,SAAS,QAAQ,CAAC,CAAC;IACxF,MAAM,OAAO,GAAG,CAAC,CAAC,IAAI,EAAE,aAAa,CAAC;IACtC,IAAI,CAAC,OAAO;QAAE,MAAM,IAAI,OAAO,CAAC,qBAAqB,EAAE,uBAAuB,CAAC,CAAC;IAChF,MAAM,MAAM,GAAc,CAAC,CAAC,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;QACnD,MAAM,CAAC,SAAS,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;QACpC,IAAI,CAAC,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,IAAI,OAAO,SAAS,KAAK,QAAQ,IAAI,OAAO,OAAO,KAAK,QAAQ;YACrF,MAAM,IAAI,OAAO,CAAC,qBAAqB,EAAE,yCAAyC,CAAC,CAAC;QACtF,IAAI,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC;YACpC,MAAM,IAAI,OAAO,CAAC,qBAAqB,EAAE,SAAS,OAAO,0CAA0C,CAAC,CAAC;QACvG,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QACtB,IAAI,OAAO,CAAC,KAAK,SAAS,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,OAAO,CAAC,KAAK,QAAQ;YAC1E,MAAM,IAAI,OAAO,CAAC,qBAAqB,EAAE,SAAS,OAAO,4BAA4B,CAAC,CAAC;QACzF,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;IAC1C,CAAC,CAAC,CAAC;IACH,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;QAAE,MAAM,IAAI,OAAO,CAAC,qBAAqB,EAAE,WAAW,CAAC,CAAC;IAC/E,IAAI,IAAI,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC;QAClD,MAAM,IAAI,OAAO,CAAC,qBAAqB,EAAE,iCAAiC,CAAC,CAAC;IAC9E,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;AAC5C,CAAC"}
|
package/lib/sources.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { ZkCircuitEntry, ZkCircuitSource } from "./types.js";
|
|
2
|
+
/** Bellekteki devreler (uygulamayla gelen varlıklar ya da testler). */
|
|
3
|
+
export declare function memoryCircuitSource(circuits: Record<string, Uint8Array>): ZkCircuitSource;
|
|
4
|
+
/**
|
|
5
|
+
* Ağdan indirilen devreler: `${baseUrl}/${circuit_id}.zst` (ör. güven listesi sitesi). İsteğe bağlı önbellek telefonda tutar;
|
|
6
|
+
* indirme yalnız devre içindir (kişi verisi, belge ya da oturum bilgisi gönderilmez). Boyut üst sınırlı (`maxBytes`). Önbelleğe
|
|
7
|
+
* yalnız güven listesindeki özetle (`trustedCircuits`) eşleşen dosya yazılır — bozuk/sahte dosya önbelleği kalıcı zehirlemez;
|
|
8
|
+
* liste verilmezse indirilen dosya önbelleğe yazılmaz (kullanımda `loadCircuit` yine denetler).
|
|
9
|
+
*/
|
|
10
|
+
export declare function httpCircuitSource(baseUrl: string, opts?: {
|
|
11
|
+
fetch?: typeof fetch;
|
|
12
|
+
cache?: {
|
|
13
|
+
get(id: string): Promise<Uint8Array | undefined>;
|
|
14
|
+
set(id: string, bytes: Uint8Array): Promise<void>;
|
|
15
|
+
};
|
|
16
|
+
/** Güven listesindeki devreler (`lotl.zk_circuits`): önbelleğe yazmadan önce özet denetimi için. */
|
|
17
|
+
trustedCircuits?: readonly ZkCircuitEntry[];
|
|
18
|
+
/** Dosya üst sınırı (bayt; varsayılan 8 MiB). */
|
|
19
|
+
maxBytes?: number;
|
|
20
|
+
}): ZkCircuitSource;
|
|
21
|
+
/** Birden çok kaynağı sırayla dener (ör. önce uygulamayla gelen, yoksa ağ). */
|
|
22
|
+
export declare function firstCircuitSource(...sources: ZkCircuitSource[]): ZkCircuitSource;
|
|
23
|
+
/** Bu cihazda ispatçı yokken kullanılan arka uç: her zaman `available() === false` (cüzdan olağan yola döner — ZK5). */
|
|
24
|
+
export declare const unavailableProver: {
|
|
25
|
+
readonly name: "unavailable";
|
|
26
|
+
readonly available: () => Promise<boolean>;
|
|
27
|
+
readonly circuitVersion: () => Promise<number>;
|
|
28
|
+
readonly prove: () => Promise<Uint8Array>;
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=sources.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sources.d.ts","sourceRoot":"","sources":["../src/sources.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAKlE,uEAAuE;AACvE,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,GAAG,eAAe,CAEzF;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,MAAM,EACf,IAAI,GAAE;IACJ,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;IACrB,KAAK,CAAC,EAAE;QAAE,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAAC;QAAC,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;KAAE,CAAC;IAChH,oGAAoG;IACpG,eAAe,CAAC,EAAE,SAAS,cAAc,EAAE,CAAC;IAC5C,iDAAiD;IACjD,QAAQ,CAAC,EAAE,MAAM,CAAC;CACd,GACL,eAAe,CAsBjB;AAED,+EAA+E;AAC/E,wBAAgB,kBAAkB,CAAC,GAAG,OAAO,EAAE,eAAe,EAAE,GAAG,eAAe,CAUjF;AAED,wHAAwH;AACxH,eAAO,MAAM,iBAAiB;;;;0BAIX,OAAO,CAAC,UAAU,CAAC;CAG5B,CAAC"}
|
package/lib/sources.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Devre kaynakları (React Native uyumlu). Devre dosyası (~300 KB, zstd) kişisel veri içermez; güven listesinde özetiyle yayınlanır
|
|
3
|
+
* ve her kullanımda o özetle denetlenir (`loadCircuit`), bu yüzden nereden geldiği güveni değiştirmez.
|
|
4
|
+
*/
|
|
5
|
+
import { sha256 } from "@noble/hashes/sha2.js";
|
|
6
|
+
import { bytesToHex } from "@noble/hashes/utils.js";
|
|
7
|
+
/** İndirilen devre dosyası üst sınırı (bugünkü devreler ~300 KB) — bellek tüketme saldırısı. */
|
|
8
|
+
const MAX_CIRCUIT_BYTES = 8 * 1024 * 1024;
|
|
9
|
+
/** Bellekteki devreler (uygulamayla gelen varlıklar ya da testler). */
|
|
10
|
+
export function memoryCircuitSource(circuits) {
|
|
11
|
+
return { get: async (id) => circuits[id] };
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Ağdan indirilen devreler: `${baseUrl}/${circuit_id}.zst` (ör. güven listesi sitesi). İsteğe bağlı önbellek telefonda tutar;
|
|
15
|
+
* indirme yalnız devre içindir (kişi verisi, belge ya da oturum bilgisi gönderilmez). Boyut üst sınırlı (`maxBytes`). Önbelleğe
|
|
16
|
+
* yalnız güven listesindeki özetle (`trustedCircuits`) eşleşen dosya yazılır — bozuk/sahte dosya önbelleği kalıcı zehirlemez;
|
|
17
|
+
* liste verilmezse indirilen dosya önbelleğe yazılmaz (kullanımda `loadCircuit` yine denetler).
|
|
18
|
+
*/
|
|
19
|
+
export function httpCircuitSource(baseUrl, opts = {}) {
|
|
20
|
+
const f = opts.fetch ?? fetch;
|
|
21
|
+
const base = baseUrl.replace(/\/$/, "");
|
|
22
|
+
return {
|
|
23
|
+
async get(id) {
|
|
24
|
+
if (!/^[0-9a-f]{64}$/.test(id))
|
|
25
|
+
return undefined;
|
|
26
|
+
const hit = await opts.cache?.get(id);
|
|
27
|
+
if (hit)
|
|
28
|
+
return hit;
|
|
29
|
+
const r = await f(`${base}/${id}.zst`);
|
|
30
|
+
if (!r.ok)
|
|
31
|
+
return undefined;
|
|
32
|
+
const max = opts.maxBytes ?? MAX_CIRCUIT_BYTES;
|
|
33
|
+
if (Number(r.headers?.get?.("content-length") ?? 0) > max)
|
|
34
|
+
return undefined;
|
|
35
|
+
const bytes = new Uint8Array(await r.arrayBuffer());
|
|
36
|
+
if (bytes.length > max)
|
|
37
|
+
return undefined;
|
|
38
|
+
const want = opts.trustedCircuits?.find((c) => c.circuit_id === id)?.sha256;
|
|
39
|
+
if (opts.cache && want) {
|
|
40
|
+
if (bytesToHex(sha256(bytes)) !== want)
|
|
41
|
+
return undefined; // ZK2: listedeki özetle tutmayan dosya kullanılmaz
|
|
42
|
+
await opts.cache.set(id, bytes);
|
|
43
|
+
}
|
|
44
|
+
return bytes;
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/** Birden çok kaynağı sırayla dener (ör. önce uygulamayla gelen, yoksa ağ). */
|
|
49
|
+
export function firstCircuitSource(...sources) {
|
|
50
|
+
return {
|
|
51
|
+
async get(id) {
|
|
52
|
+
for (const s of sources) {
|
|
53
|
+
const b = await s.get(id);
|
|
54
|
+
if (b)
|
|
55
|
+
return b;
|
|
56
|
+
}
|
|
57
|
+
return undefined;
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/** Bu cihazda ispatçı yokken kullanılan arka uç: her zaman `available() === false` (cüzdan olağan yola döner — ZK5). */
|
|
62
|
+
export const unavailableProver = {
|
|
63
|
+
name: "unavailable",
|
|
64
|
+
available: async () => false,
|
|
65
|
+
circuitVersion: async () => 0,
|
|
66
|
+
prove: async () => {
|
|
67
|
+
throw new Error("zero-knowledge prover is not available");
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
//# sourceMappingURL=sources.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sources.js","sourceRoot":"","sources":["../src/sources.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAGpD,gGAAgG;AAChG,MAAM,iBAAiB,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;AAE1C,uEAAuE;AACvE,MAAM,UAAU,mBAAmB,CAAC,QAAoC;IACtE,OAAO,EAAE,GAAG,EAAE,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I,IAAI,EAAE,CAAC;gBACvB,IAAI,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,IAAI;oBAAE,OAAO,SAAS,CAAC,CAAC,mDAAmD;gBAC7G,MAAM,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;YAClC,CAAC;YACD,OAAO,KAAK,CAAC;QACf,CAAC;KACF,CAAC;AACJ,CAAC;AAED,+EAA+E;AAC/E,MAAM,UAAU,kBAAkB,CAAC,GAAG,OAA0B;IAC9D,OAAO;QACL,KAAK,CAAC,GAAG,CAAC,EAAE;YACV,KAAK,MAAM,CAAC,IAAI,OAAO,EAAE,CAAC;gBACxB,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;gBAC1B,IAAI,CAAC;oBAAE,OAAO,CAAC,CAAC;YAClB,CAAC;YACD,OAAO,SAAS,CAAC;QACnB,CAAC;KACF,CAAC;AACJ,CAAC;AAED,wHAAwH;AACxH,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,IAAI,EAAE,aAAa;IACnB,SAAS,EAAE,KAAK,IAAI,EAAE,CAAC,KAAK;IAC5B,cAAc,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC;IAC7B,KAAK,EAAE,KAAK,IAAyB,EAAE;QACrC,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;IAC5D,CAAC;CACO,CAAC"}
|
package/lib/types.d.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @tamga-network/zk türleri (ADR-0032 Aşama 2). Paket cüzdan tarafındadır: ispatı ÜRETİR. Doğrulama `@tamga-network/verifier/zk`.
|
|
3
|
+
* İlke (ZK1): kurum belgesi değişmez; ispat cüzdanın sakladığı belgeden ve o oturumun olağan cihaz imzasından üretilir.
|
|
4
|
+
*/
|
|
5
|
+
import type { CborValue } from "@tamga-network/mdoc";
|
|
6
|
+
/** İspatlanacak tek öğe: "bu ad alanında bu öğe şu değerdir" (ör. tamga.id.1 / age_over_18 = true). */
|
|
7
|
+
export interface ZkClaim {
|
|
8
|
+
namespace: string;
|
|
9
|
+
element: string;
|
|
10
|
+
value: CborValue;
|
|
11
|
+
}
|
|
12
|
+
/** Güven listesindeki kabul edilen devre (`lotl.zk_circuits[]`, SPEC-TRUST-0001). Yapısal tür: trust paketine bağımlılık yok. */
|
|
13
|
+
export interface ZkCircuitEntry {
|
|
14
|
+
circuit_id: string;
|
|
15
|
+
system: string;
|
|
16
|
+
version: number;
|
|
17
|
+
attributes: number;
|
|
18
|
+
sha256: string;
|
|
19
|
+
status: string;
|
|
20
|
+
}
|
|
21
|
+
/** Arka uca giden ham istek. Bütün baytlar cihazda kalır; arka uç ağa çıkmaz, dosyaya yazmaz, loglamaz. */
|
|
22
|
+
export interface ZkProveArgs {
|
|
23
|
+
/** Devre kimliği (`circuit_id`, onaltılık 64) ve özeti denetlenmiş devre baytları (zstd). */
|
|
24
|
+
circuitId: string;
|
|
25
|
+
circuit: Uint8Array;
|
|
26
|
+
/** Bu oturum için cüzdanın olağan yolla ürettiği, cihaz imzalı DeviceResponse (CBOR). Doğrulayıcıya GİTMEZ. */
|
|
27
|
+
deviceResponse: Uint8Array;
|
|
28
|
+
/** OpenID4VP / DC API SessionTranscript (CBOR). */
|
|
29
|
+
transcript: Uint8Array;
|
|
30
|
+
docType: string;
|
|
31
|
+
claims: ZkClaim[];
|
|
32
|
+
/** İspatın "şimdi"si: ISO 8601, saniye, `Z`. */
|
|
33
|
+
now: string;
|
|
34
|
+
/** Belgeyi imzalayan kurum anahtarı (P-256, sıkıştırılmamış nokta 65 bayt: 04 || X || Y). */
|
|
35
|
+
issuerKey: Uint8Array;
|
|
36
|
+
}
|
|
37
|
+
/** İspat üreticisi. Telefonda yerel modül, masaüstünde alt süreç; yoksa `available() === false` ve cüzdan olağan yola döner (ZK5). */
|
|
38
|
+
export interface ZkProver {
|
|
39
|
+
readonly name: string;
|
|
40
|
+
available(): Promise<boolean>;
|
|
41
|
+
/** Longfellow devre sürümü (güven listesindeki devreyle eşleşmeli). */
|
|
42
|
+
circuitVersion(): Promise<number>;
|
|
43
|
+
prove(args: ZkProveArgs): Promise<Uint8Array>;
|
|
44
|
+
}
|
|
45
|
+
/** Devre baytlarını sağlayan kaynak (paketle gelen devreler, uygulama varlıkları ya da önbellek). */
|
|
46
|
+
export interface ZkCircuitSource {
|
|
47
|
+
get(circuitId: string): Promise<Uint8Array | undefined>;
|
|
48
|
+
}
|
|
49
|
+
export type ZkErrorCode = "unavailable" | "no_circuit" | "circuit_mismatch" | "unsupported_request" | "prove_failed";
|
|
50
|
+
export declare class ZkError extends Error {
|
|
51
|
+
readonly code: ZkErrorCode;
|
|
52
|
+
constructor(code: ZkErrorCode, message: string);
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAErD,uGAAuG;AACvG,MAAM,WAAW,OAAO;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,SAAS,CAAC;CAClB;AAED,iIAAiI;AACjI,MAAM,WAAW,cAAc;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,2GAA2G;AAC3G,MAAM,WAAW,WAAW;IAC1B,6FAA6F;IAC7F,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,UAAU,CAAC;IACpB,+GAA+G;IAC/G,cAAc,EAAE,UAAU,CAAC;IAC3B,mDAAmD;IACnD,UAAU,EAAE,UAAU,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,OAAO,EAAE,CAAC;IAClB,gDAAgD;IAChD,GAAG,EAAE,MAAM,CAAC;IACZ,6FAA6F;IAC7F,SAAS,EAAE,UAAU,CAAC;CACvB;AAED,sIAAsI;AACtI,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,SAAS,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IAC9B,uEAAuE;IACvE,cAAc,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAClC,KAAK,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;CAC/C;AAED,qGAAqG;AACrG,MAAM,WAAW,eAAe;IAC9B,GAAG,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAAC;CACzD;AAED,MAAM,MAAM,WAAW,GACnB,aAAa,GACb,YAAY,GACZ,kBAAkB,GAClB,qBAAqB,GACrB,cAAc,CAAC;AAEnB,qBAAa,OAAQ,SAAQ,KAAK;IAE9B,QAAQ,CAAC,IAAI,EAAE,WAAW;gBAAjB,IAAI,EAAE,WAAW,EAC1B,OAAO,EAAE,MAAM;CAKlB"}
|
package/lib/types.js
ADDED
package/lib/types.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AA6DA,MAAM,OAAO,OAAQ,SAAQ,KAAK;IAErB;IADX,YACW,IAAiB,EAC1B,OAAe;QAEf,KAAK,CAAC,OAAO,CAAC,CAAC;QAHN,SAAI,GAAJ,IAAI,CAAa;QAI1B,IAAI,CAAC,IAAI,GAAG,SAAS,CAAC;IACxB,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,56 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamga-network/zk",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Cüzdan tarafında sıfır bilgi ispatı (ADR-0032, Longfellow ZK): ISO mdoc belgesi hakkında \"şu öğe şu değerdedir\" ispatını cihazda üretir (ilk kullanım: 18 yaş üstü). Çekirdek saf TS (React Native uyumlu); /react-native yerel ispatçı (Expo modülü, Rust), /node masaüstü ispatçı. Doğrulama: @tamga-network/verifier/zk.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./lib/index.js",
|
|
8
|
+
"types": "./lib/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./lib/index.d.ts",
|
|
12
|
+
"default": "./lib/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./node": {
|
|
15
|
+
"types": "./lib/node.d.ts",
|
|
16
|
+
"default": "./lib/node.js"
|
|
17
|
+
},
|
|
18
|
+
"./react-native": {
|
|
19
|
+
"types": "./lib/react-native.d.ts",
|
|
20
|
+
"default": "./lib/react-native.js"
|
|
21
|
+
},
|
|
22
|
+
"./package.json": "./package.json"
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"lib",
|
|
26
|
+
"README.md",
|
|
27
|
+
"LICENSE",
|
|
28
|
+
"android",
|
|
29
|
+
"expo-module.config.json"
|
|
30
|
+
],
|
|
31
|
+
"sideEffects": false,
|
|
32
|
+
"engines": {
|
|
33
|
+
"node": ">=22"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@noble/hashes": "^2.0.0",
|
|
37
|
+
"@tamga-network/mdoc": "^0.2.0"
|
|
38
|
+
},
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"expo-modules-core": "*"
|
|
41
|
+
},
|
|
42
|
+
"peerDependenciesMeta": {
|
|
43
|
+
"expo-modules-core": {
|
|
44
|
+
"optional": true
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
"repository": {
|
|
48
|
+
"type": "git",
|
|
49
|
+
"url": "https://github.com/tamga-network/tamga-network.git",
|
|
50
|
+
"directory": "packages/zk"
|
|
51
|
+
},
|
|
52
|
+
"homepage": "https://docs.tamga.network",
|
|
53
|
+
"publishConfig": {
|
|
54
|
+
"access": "public"
|
|
55
|
+
}
|
|
56
|
+
}
|