@qntx/wallet-native 0.12.0 → 0.14.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.
Files changed (135) hide show
  1. package/README.md +184 -31
  2. package/WalletNative.podspec +11 -2
  3. package/android/CMakeLists.txt +7 -1
  4. package/android/build.gradle +4 -0
  5. package/android/src/main/AndroidManifest.xml +1 -2
  6. package/android/src/main/cpp/cpp-adapter.cpp +9 -0
  7. package/android/src/main/java/com/margelo/nitro/qntxwallet/CardReader.kt +316 -0
  8. package/android/src/main/java/com/margelo/nitro/qntxwallet/HybridGoogleDriveAuth.kt +142 -0
  9. package/android/src/main/java/com/margelo/nitro/qntxwallet/HybridSecureInputView.kt +25 -0
  10. package/android/src/main/java/com/margelo/nitro/qntxwallet/Keystore.kt +148 -9
  11. package/android/src/main/java/com/margelo/nitro/qntxwallet/SecureInputField.kt +422 -0
  12. package/android/src/main/java/com/margelo/nitro/qntxwallet/VaultAnchor.kt +90 -0
  13. package/android/src/main/java/com/margelo/nitro/qntxwallet/WalletNativePackage.java +10 -0
  14. package/cpp/host/CardReader.hpp +70 -0
  15. package/cpp/host/HybridKernelHost.cpp +90 -15
  16. package/cpp/host/HybridKernelHost.hpp +21 -5
  17. package/cpp/host/KernelFile.cpp +79 -15
  18. package/cpp/host/KernelFile.hpp +17 -6
  19. package/cpp/host/KernelSlot.hpp +103 -0
  20. package/cpp/host/Keystore.hpp +35 -11
  21. package/cpp/host/Lifecycle.cpp +11 -0
  22. package/cpp/host/Lifecycle.hpp +3 -0
  23. package/cpp/host/Passkey.hpp +8 -0
  24. package/cpp/host/SecureInput.cpp +233 -0
  25. package/cpp/host/SecureInput.hpp +103 -0
  26. package/cpp/host/VaultAnchor.cpp +39 -0
  27. package/cpp/host/VaultAnchor.hpp +28 -0
  28. package/cpp/host/VaultDirectory.hpp +1 -1
  29. package/cpp/platform/CardReaderAndroid.cpp +146 -0
  30. package/cpp/platform/CardReaderIos.mm +318 -0
  31. package/cpp/platform/KeystoreAndroid.cpp +48 -1
  32. package/cpp/platform/KeystoreIos.mm +109 -19
  33. package/cpp/platform/PasskeyAndroid.cpp +2 -0
  34. package/cpp/platform/PasskeyIos.mm +20 -18
  35. package/cpp/platform/QntxSecureInputField.h +24 -0
  36. package/cpp/platform/SecureInputAndroid.cpp +110 -0
  37. package/cpp/platform/SecureInputIos.mm +282 -0
  38. package/cpp/platform/VaultAnchorAndroid.cpp +76 -0
  39. package/cpp/platform/VaultAnchorIos.mm +76 -0
  40. package/cpp/runtime/KernelBackends.cpp +35 -28
  41. package/cpp/runtime/KernelBuffer.hpp +2 -5
  42. package/cpp/runtime/KernelCardReader.cpp +385 -0
  43. package/cpp/runtime/KernelCardReader.hpp +27 -0
  44. package/cpp/runtime/KernelGlobals.cpp +176 -63
  45. package/cpp/runtime/KernelGlobals.hpp +13 -7
  46. package/cpp/runtime/KernelJs.cpp +14 -0
  47. package/cpp/runtime/KernelJs.hpp +4 -0
  48. package/cpp/runtime/KernelKeystore.cpp +78 -2
  49. package/cpp/runtime/KernelKeystore.hpp +1 -0
  50. package/cpp/runtime/KernelPasskey.cpp +15 -12
  51. package/cpp/runtime/KernelRuntime.cpp +24 -7
  52. package/cpp/runtime/KernelRuntime.hpp +14 -6
  53. package/cpp/runtime/KernelSecureInput.cpp +154 -0
  54. package/cpp/runtime/KernelSecureInput.hpp +25 -0
  55. package/cpp/runtime/platform/KernelArgon2.cpp +34 -0
  56. package/cpp/runtime/platform/KernelArgon2.hpp +23 -0
  57. package/cpp/vendor/argon2/LICENSE +314 -0
  58. package/cpp/vendor/argon2/README.md +20 -0
  59. package/cpp/vendor/argon2/include/argon2.h +437 -0
  60. package/cpp/vendor/argon2/src/argon2.c +452 -0
  61. package/cpp/vendor/argon2/src/blake2/blake2-impl.h +156 -0
  62. package/cpp/vendor/argon2/src/blake2/blake2.h +89 -0
  63. package/cpp/vendor/argon2/src/blake2/blake2b.c +390 -0
  64. package/cpp/vendor/argon2/src/blake2/blamka-round-ref.h +56 -0
  65. package/cpp/vendor/argon2/src/core.c +648 -0
  66. package/cpp/vendor/argon2/src/core.h +228 -0
  67. package/cpp/vendor/argon2/src/encoding.c +463 -0
  68. package/cpp/vendor/argon2/src/encoding.h +57 -0
  69. package/cpp/vendor/argon2/src/ref.c +194 -0
  70. package/cpp/vendor/argon2/src/thread.c +57 -0
  71. package/cpp/vendor/argon2/src/thread.h +67 -0
  72. package/dist/cloud.d.mts +58 -0
  73. package/dist/cloud.mjs +114 -0
  74. package/dist/cloud.mjs.map +1 -0
  75. package/dist/index.d.mts +13 -4
  76. package/dist/index.mjs +89 -14
  77. package/dist/index.mjs.map +1 -1
  78. package/dist/secure-input.d.mts +24 -0
  79. package/dist/secure-input.mjs +25 -0
  80. package/dist/secure-input.mjs.map +1 -0
  81. package/ios/HybridCloudKitStore.swift +159 -0
  82. package/ios/HybridSecureInputView.swift +35 -0
  83. package/ios/cloud/CloudKitEnvelopeStore.swift +179 -0
  84. package/kernel/generated/kernel-entry.js +51913 -20526
  85. package/kernel/generated/kernel.manifest.json +17 -7
  86. package/nitrogen/generated/android/WalletNative+autolinking.cmake +7 -1
  87. package/nitrogen/generated/android/WalletNativeOnLoad.cpp +37 -2
  88. package/nitrogen/generated/android/c++/JFunc_void_SecureInputState.hpp +77 -0
  89. package/nitrogen/generated/android/c++/JHybridGoogleDriveAuthSpec.cpp +82 -0
  90. package/nitrogen/generated/android/c++/JHybridGoogleDriveAuthSpec.hpp +64 -0
  91. package/nitrogen/generated/android/c++/JHybridSecureInputViewSpec.cpp +70 -0
  92. package/nitrogen/generated/android/c++/JHybridSecureInputViewSpec.hpp +64 -0
  93. package/nitrogen/generated/android/c++/JSecureInputState.hpp +64 -0
  94. package/nitrogen/generated/android/c++/views/JHybridSecureInputViewStateUpdater.cpp +74 -0
  95. package/nitrogen/generated/android/c++/views/JHybridSecureInputViewStateUpdater.hpp +54 -0
  96. package/nitrogen/generated/android/kotlin/com/margelo/nitro/qntxwallet/Func_void_SecureInputState.kt +78 -0
  97. package/nitrogen/generated/android/kotlin/com/margelo/nitro/qntxwallet/HybridGoogleDriveAuthSpec.kt +61 -0
  98. package/nitrogen/generated/android/kotlin/com/margelo/nitro/qntxwallet/HybridSecureInputViewSpec.kt +67 -0
  99. package/nitrogen/generated/android/kotlin/com/margelo/nitro/qntxwallet/SecureInputState.kt +25 -0
  100. package/nitrogen/generated/android/kotlin/com/margelo/nitro/qntxwallet/views/HybridSecureInputViewManager.kt +96 -0
  101. package/nitrogen/generated/android/kotlin/com/margelo/nitro/qntxwallet/views/HybridSecureInputViewStateUpdater.kt +23 -0
  102. package/nitrogen/generated/ios/WalletNative-Swift-Cxx-Bridge.cpp +74 -1
  103. package/nitrogen/generated/ios/WalletNative-Swift-Cxx-Bridge.hpp +252 -3
  104. package/nitrogen/generated/ios/WalletNative-Swift-Cxx-Umbrella.hpp +21 -3
  105. package/nitrogen/generated/ios/WalletNativeAutolinking.mm +17 -1
  106. package/nitrogen/generated/ios/WalletNativeAutolinking.swift +22 -0
  107. package/nitrogen/generated/ios/c++/HybridCloudKitStoreSpecSwift.cpp +11 -0
  108. package/nitrogen/generated/ios/c++/HybridCloudKitStoreSpecSwift.hpp +116 -0
  109. package/nitrogen/generated/ios/c++/HybridSecureInputViewSpecSwift.cpp +11 -0
  110. package/nitrogen/generated/ios/c++/HybridSecureInputViewSpecSwift.hpp +83 -0
  111. package/nitrogen/generated/ios/c++/views/HybridSecureInputViewComponent.mm +144 -0
  112. package/nitrogen/generated/ios/swift/Func_void.swift +46 -0
  113. package/nitrogen/generated/ios/swift/Func_void_SecureInputState.swift +46 -0
  114. package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +46 -0
  115. package/nitrogen/generated/ios/swift/Func_void_std__optional_std__string_.swift +53 -0
  116. package/nitrogen/generated/ios/swift/Func_void_std__vector_std__string_.swift +46 -0
  117. package/nitrogen/generated/ios/swift/HybridCloudKitStoreSpec.swift +59 -0
  118. package/nitrogen/generated/ios/swift/HybridCloudKitStoreSpec_cxx.swift +230 -0
  119. package/nitrogen/generated/ios/swift/HybridSecureInputViewSpec.swift +55 -0
  120. package/nitrogen/generated/ios/swift/HybridSecureInputViewSpec_cxx.swift +164 -0
  121. package/nitrogen/generated/ios/swift/SecureInputState.swift +48 -0
  122. package/nitrogen/generated/shared/c++/HybridCloudKitStoreSpec.cpp +25 -0
  123. package/nitrogen/generated/shared/c++/HybridCloudKitStoreSpec.hpp +70 -0
  124. package/nitrogen/generated/shared/c++/HybridGoogleDriveAuthSpec.cpp +22 -0
  125. package/nitrogen/generated/shared/c++/HybridGoogleDriveAuthSpec.hpp +64 -0
  126. package/nitrogen/generated/shared/c++/HybridKernelHostSpec.cpp +1 -0
  127. package/nitrogen/generated/shared/c++/HybridKernelHostSpec.hpp +1 -0
  128. package/nitrogen/generated/shared/c++/HybridSecureInputViewSpec.cpp +22 -0
  129. package/nitrogen/generated/shared/c++/HybridSecureInputViewSpec.hpp +65 -0
  130. package/nitrogen/generated/shared/c++/SecureInputState.hpp +84 -0
  131. package/nitrogen/generated/shared/c++/views/HybridSecureInputViewComponent.cpp +34 -0
  132. package/nitrogen/generated/shared/c++/views/HybridSecureInputViewComponent.hpp +85 -0
  133. package/nitrogen/generated/shared/json/SecureInputViewConfig.json +10 -0
  134. package/package.json +24 -6
  135. package/scripts/compile-kernel.mjs +7 -3
package/README.md CHANGED
@@ -4,28 +4,28 @@ React Native host for [`@qntx/wallet`](https://www.npmjs.com/package/@qntx/walle
4
4
  wallet kernel on its own Hermes runtime on a separate thread (the Nitro `KernelHost` object
5
5
  shuttles CBOR messages to it across JSI), keeps the
6
6
  encrypted vault under the platform's never-backed-up directory, and makes the platform keystore
7
- (Secure Enclave on iOS, Android Keystore) the vault factor — every unlock and every signing
8
- request is gated by a system user-presence prompt rendered with kernel-owned text.
7
+ (Secure Enclave on iOS, Android Keystore) the vault factors: a silent `device` key opens the
8
+ vault for everyday use (Nostr signing, DMs, reading state, receiving), and every guarded
9
+ operation — exports, cloud-backup enable and disable, wallet and key deletion, app-lock changes, reset and
10
+ every outgoing payment — is gated by a fresh system user-presence prompt (`hardware` key) with
11
+ kernel-owned text.
9
12
 
10
13
  ```bash
11
14
  npm install @qntx/wallet-native @qntx/wallet @qntx/nostr-native @qntx/spark-native
12
15
  ```
13
16
 
14
- Peer dependencies (exact `@qntx/*` pins are required — the host/kernel protocol and the bundled
15
- kernel artifacts are built against those releases):
17
+ Peer dependencies: `@qntx/wallet`, `@qntx/nostr-native`, `@qntx/spark-native`, `react-native`
18
+ and `react-native-nitro-modules`; `@qntx/wallet-engine` is an optional peer needed only by the
19
+ `/cloud` subpath. The exact ranges are this package's `peerDependencies` — the `@qntx/*` pins
20
+ are exact because the host/kernel protocol and the bundled kernel artifacts are built against
21
+ those releases.
16
22
 
17
- | package | range |
18
- | ---------------------------- | ---------------- |
19
- | `@qntx/wallet` | `0.4.0` (exact) |
20
- | `@qntx/nostr-native` | `0.15.3` (exact) |
21
- | `@qntx/spark-native` | `0.5.2` (exact) |
22
- | `react-native` | `~0.88.0` |
23
- | `react-native-nitro-modules` | `~0.37.1` |
24
-
25
- The package registers one Nitro hybrid object, `KernelHost`. Everything else the kernel needs —
26
- keystore, passkey ceremonies, lifecycle, pbkdf2, the vault directory — is injected as JSI host
27
- objects inside the kernel runtime and is never registered with Nitro. **No Nitro patch or
28
- `nitro::install` call is needed in the consuming app.**
23
+ The package registers four Nitro hybrid objects: `KernelHost`, `SecureInputView` (the card's
24
+ secure-input surface), `CloudKitStore` on iOS and `GoogleDriveAuth` on Android (the cloud-backup
25
+ transports below). Everything else the kernel needs — keystore, passkey ceremonies, lifecycle,
26
+ pbkdf2, the vault directory — is injected as JSI host objects inside the kernel runtime and is
27
+ never registered with Nitro. **No Nitro patch or `nitro::install` call is needed in the
28
+ consuming app.**
29
29
 
30
30
  ## Expo configuration
31
31
 
@@ -49,21 +49,71 @@ export default {
49
49
  - `android.minSdkVersion: 30` — required: per-use Keystore keys that accept a biometric _or_ the
50
50
  device credential need API 30 (`setUserAuthenticationParameters` semantics).
51
51
 
52
+ ## Card wallets
53
+
54
+ Card wallets run end to end on React Native — the kernel drives the native NFC reader and
55
+ collects the access code through `SecureInput` — but **this release pins no production card
56
+ certificate anchor, so every card answers `card-not-genuine`** until a later release ships the
57
+ anchor. Keep card UI behind a flag until then.
58
+
59
+ The library's Android manifest declares nothing: a host that offers card wallets declares the NFC
60
+ and overlay entries itself — with Expo (`android.permissions` plus a `uses-feature` manifest mod)
61
+ or in `android/app/src/main/AndroidManifest.xml`:
62
+
63
+ ```xml
64
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
65
+ <uses-permission android:name="android.permission.NFC" />
66
+ <uses-permission android:name="android.permission.HIDE_OVERLAY_WINDOWS" />
67
+ <uses-feature android:name="android.hardware.nfc" android:required="false" />
68
+ </manifest>
69
+ ```
70
+
71
+ On iOS the host app also needs:
72
+
73
+ - The entitlement `com.apple.developer.nfc.readersession.formats` = `["TAG"]`.
74
+ - `ios.infoPlist.NFCReaderUsageDescription` — the purpose string shown under the NFC system
75
+ panel's prompt.
76
+ - `ios.infoPlist["com.apple.developer.nfc.readersession.iso7816.select-identifiers"]` =
77
+ `["F0716E74780101", "D2760000850101"]` — every AID a `SELECT` may name must be declared or
78
+ CoreNFC rejects it (the wallet applet and its NDEF applet, protocol §2).
79
+
80
+ For the secure-input field, render `SecureInput` from the `@qntx/wallet-native/secure-input`
81
+ subpath wherever the wallet asks for the card's access code or short ID:
82
+
83
+ ```jsx
84
+ import { callback } from "react-native-nitro-modules";
85
+
86
+ import { SecureInput } from "@qntx/wallet-native/secure-input";
87
+
88
+ <SecureInput onStateChange={callback((state) => setState(state))} />;
89
+ ```
90
+
91
+ Its `onStateChange` callback (and every Nitro view callback) must be wrapped with
92
+ `callback(...)`. The component takes no other props: the kernel decides the kind and the label;
93
+ the main runtime only observes `idle | empty | filled | submitted`. The component lives on a
94
+ subpath so importing the package root does not eagerly load the Nitro view machinery.
95
+
96
+ Card operations themselves run through `card(wallet)` from `@qntx/wallet/card`: the kernel opens
97
+ the NFC session, sets its text, exchanges the APDUs and closes it; the host never touches the
98
+ reader. `SecureInput` also collects the cloud-backup password and the iOS session-approval code
99
+ on React Native.
100
+
52
101
  ## Usage
53
102
 
54
103
  ```ts
104
+ import { verifyEvent } from "@qntx/nostr";
55
105
  import { createNativeWallet } from "@qntx/wallet-native";
56
106
 
57
107
  const wallet = await createNativeWallet({
58
108
  passkey: {
59
- rpId: "example.com",
109
+ rpId: "wallet.example.com",
60
110
  rpName: "Example",
61
111
  walletSalt: "example/wallet",
62
112
  vaultSalt: "example/vault",
63
113
  backupSalt: "example/backup",
64
114
  },
65
115
  autoLock: { platform: "native", backgroundSeconds: 60 },
66
- verifyEvent, // e.g. createEventVerifier(signing) from @qntx/nostr-native
116
+ verifyEvent, // e.g. createEventVerifier (@qntx/nostr/core) over signing from @qntx/nostr-native
67
117
  });
68
118
  ```
69
119
 
@@ -71,8 +121,12 @@ const wallet = await createNativeWallet({
71
121
  passkey). `rpId`, `walletSalt` and `vaultSalt` are permanent identifiers: changing them makes
72
122
  existing passkey factors and passkey-derived wallets unrecoverable. `backupSalt` is the PRF
73
123
  salt for the cloud-backup factor — a third, distinct permanent label.
74
- - `autoLock` — must be `{ platform: "native", backgroundSeconds }`. The native host owns the
75
- signal: it calls `host.lock()` when the app has spent `backgroundSeconds` in the background.
124
+ - `autoLock` — must be `{ platform: "native", backgroundSeconds }` (0, 60, 300 or 900). The
125
+ native host owns the signal: it calls `host.lock()` when the app has spent `backgroundSeconds`
126
+ in the background. `createNativeWallet` returns a `NativeWallet` whose
127
+ `setAutoLock({ platform: "native", backgroundSeconds })` changes the budget at runtime — it
128
+ applies to the live kernel immediately and to every runtime spawned later. The vault does not
129
+ store the value; persist it in the app and pass it to `createNativeWallet` on the next launch.
76
130
  - `createHost` — optional factory for the `KernelHost` (a like-shaped fake in tests). A host serves one
77
131
  kernel runtime: after a lock, a wallet deletion or a crash it is spent, and the wallet calls the
78
132
  factory again for the next unlock.
@@ -84,7 +138,10 @@ const wallet = await createNativeWallet({
84
138
 
85
139
  ## Passkey domains
86
140
 
87
- Passkey wallets need the platform's domain association:
141
+ Passkey wallets need the platform's domain association. That association is also the wallet's
142
+ trust boundary: every app and every web origin entitled to the `rpId` can evaluate the passkey's
143
+ PRF and derive a passkey wallet's seed. Use a domain that serves only the wallet, and list only
144
+ the wallet app in its association files.
88
145
 
89
146
  - **iOS** — `webcredentials:<rpId>` associated domain (requires a paid developer account; free
90
147
  signing cannot hold the entitlement). Without the entitlement the ceremony returns
@@ -94,30 +151,126 @@ Passkey wallets need the platform's domain association:
94
151
  `delegate_permission/common.get_login_creds` naming the app's package and SHA-256 signing
95
152
  certificate. Android passkeys are implemented via `androidx.credentials`.
96
153
 
154
+ ## Cloud backup transports
155
+
156
+ The `@qntx/wallet-native/cloud` subpath adapts the platform cloud to the engine's `CloudStore`
157
+ port. Both transports move **encrypted backup envelopes only** — every byte the kernel uploads
158
+ is ciphertext produced inside the enclave; the backup key never leaves it. `GoogleDriveAuth`
159
+ additionally returns a `drive.appdata` OAuth access token: that scope touches only the app's
160
+ own hidden Drive folder and cannot move wallet value, so neither hybrid is a secret-holding
161
+ capability and registering them with Nitro is allowed.
162
+
163
+ ```ts
164
+ import { createWalletEngine } from "@qntx/wallet-engine";
165
+ import type { EngineOptions } from "@qntx/wallet-engine";
166
+ import { createICloudStore, createGoogleDriveStore } from "@qntx/wallet-native/cloud";
167
+
168
+ // `Platform` from react-native; `engineOptions` are your usual EngineOptions minus `cloud`.
169
+ declare const Platform: { readonly OS: "ios" | "android" };
170
+ declare const engineOptions: Omit<EngineOptions, "cloud">;
171
+
172
+ const cloud =
173
+ Platform.OS === "ios"
174
+ ? createICloudStore({ container: "iCloud.org.qntx.wallet" })
175
+ : createGoogleDriveStore();
176
+
177
+ const engine = createWalletEngine({ ...engineOptions, cloud });
178
+ // iOS only: re-sync when the iCloud account changes under the app.
179
+ if ("onAccountChange" in cloud) {
180
+ cloud.onAccountChange(() => engine.backup.sync());
181
+ }
182
+ ```
183
+
184
+ - Both `createICloudStore` and `createGoogleDriveStore` lazily create their Nitro object on
185
+ first use; importing the subpath alone registers nothing.
186
+ - Failures reject with `CloudStoreError`; a `auth-required` on Android means call
187
+ `store.authorize()` from a user action to run the Google consent screen, then retry the
188
+ operation.
189
+ - **iOS** — the app needs the iCloud capability with CloudKit enabled and the container
190
+ identifier listed under `com.apple.developer.icloud-container-identifiers` (the harness sets
191
+ both from `EXPO_PUBLIC_ICLOUD_CONTAINER` at prebuild). The `QntxWalletBackup` record zone and
192
+ the `Backup` record type are created by the store; the zone's schema still needs deploying to
193
+ production in the CloudKit console — see the cloud-store owner-setup notes (§1). **A missing
194
+ iCloud entitlement crashes `CKContainer` at first use** — that is the platform surfacing a
195
+ configuration error, not a store fault.
196
+ - **Android** — silent token fetch works out of the box only once the project has an OAuth
197
+ client (Android type, matching package + signing SHA-1) in the Google Cloud project
198
+ (owner-setup §2). Without it `accessToken` reports `failed` (`not-configured`); before user
199
+ consent it reports `auth-required`.
200
+ - Requires `@qntx/wallet-engine` as an optional peer — only this subpath imports it, so apps
201
+ that do not ship cloud backup do not pull the engine in for it.
202
+
97
203
  ## Vault storage and backup
98
204
 
99
205
  - **iOS** — the vault image lives under `Application Support/qntx-wallet/`, created with
100
206
  `NSFileProtectionComplete` and `NSURLIsExcludedFromBackupKey`. Device-to-device migration and
101
- iCloud backups must not carry the vault: it is bound to this device's hardware factor, which
207
+ iCloud backups must not carry the vault: it is bound to this device's keystore factors, which
102
208
  cannot leave the Secure Enclave.
103
209
  - **Android** — the vault image lives under `noBackupFilesDir/qntx-wallet`, excluded from
104
210
  Auto Backup by construction.
105
211
 
106
212
  ## Security notes
107
213
 
108
- - The hardware vault factor is the only factor kind on this platform. Unlock, vault creation,
109
- mnemonic/key export, wallet deletion, cloud-backup enable, reset and every `chain.sign` /
110
- `spark.approve` request open a platform authentication ceremony with kernel-owned prompt text
111
- (Simplified Chinese under a `zh*` locale, English otherwise).
112
- - `vault.reset` authenticates the device owner first, then erases the vault and all hardware
113
- keys. Devices without a lock screen return `no-device-credential` — the host should send the
114
- user to set one up. A `WalletError.detail` string carries the platform diagnostic
214
+ - Two factor kinds, both device-bound and never backed up. `device` — iOS Secure Enclave P-256
215
+ (`kSecAttrAccessibleWhenUnlockedThisDeviceOnly`, `.privateKeyUsage`), Android Keystore
216
+ AES-256-GCM without user authentication (`setUnlockedDeviceRequired` from API 35; Android 12–14
217
+ delete or refuse such keys without a lock screen) — unlocks with no UI and can never verify.
218
+ `hardware` — the user-presence key — is the only verifying factor. The host never chooses
219
+ factors: creating a vault always creates `device`, plus `hardware` when the device has a lock
220
+ screen (Android prompts once for it).
221
+ - `vault.unlock()` with no argument uses `device` while `snapshot.appLock` is false and
222
+ `hardware` (one prompt) while it is true. After an auto-lock, one `vault.unlock()` call reopens
223
+ the vault silently.
224
+ - Every guarded call takes `verify: { kind: "hardware" }` and opens a platform authentication
225
+ ceremony with kernel-owned prompt text (Simplified Chinese under a `zh*` locale, English
226
+ otherwise). `{ kind: "device" }` is rejected (`invalid-input`) by the client, the wire validator
227
+ and the kernel. Without a `hardware` factor (no lock screen) guarded calls fail with
228
+ `verification-unavailable` and show nothing — `snapshot.verification` says so up front; send
229
+ the user to system settings, then call `vault.enrolVerification()`.
230
+ - A `chain.sign` prompt is rendered by the kernel from its own decode of the request: amounts,
231
+ recipients, approvals and the fee cap of a transaction; the text, sign-in fields or typed-data
232
+ domain of a message. Android's `BiometricPrompt` shows the title and description. iOS shows the
233
+ description on the Touch ID and device-passcode sheets only — **the Face ID sheet shows no
234
+ custom text**, so there the verification proves presence, not that the user read the content.
235
+ - Blind signing is off on a new vault. A request is blind only when the chain decoder marks it
236
+ so (raw bytes, typed data too large or misformed to show, an unrecognised token function,
237
+ calldata to the signing account's own code, a Safe delegatecall or unbounded refund) and fails
238
+ with `blind-signing-disabled` and no prompt until
239
+ `vault.setBlindSigning(true, { kind: "hardware" })`; described requests the wallet cannot fully
240
+ verify sign without the setting. This is the one kernel-side control that also holds on a
241
+ Face ID device.
242
+ - App lock is optional and off by default: `vault.setAppLock(true, { kind: "hardware" })` removes
243
+ the `device` factor and rotates the DEK, so every unlock prompts again; `false` restores it.
244
+ With app lock off, removing the lock screen keeps the vault usable (the dead `hardware` factor
245
+ is dropped and `verification` becomes `unavailable`); with app lock on it makes the vault
246
+ unrecoverable on this device, as before.
247
+ - The trade-off of app lock off, stated plainly: whoever holds the unlocked phone, and a
248
+ compromised main runtime, can act socially as the user (sign, decrypt DMs) without a prompt,
249
+ but cannot pay, export, back up, delete, change the app lock or reset. Code running inside the
250
+ app process on a jailbroken/rooted device can open the `device` key and therefore the whole
251
+ vault without any user action; app lock on restores the previous guarantee. On Android 11–14
252
+ the `device` key stays usable while the device is locked, so do not reopen the vault from
253
+ lock-screen background work.
254
+ - This build reads and writes vault format 5 only. A vault written by an older format reports
255
+ `vault: "unsupported"` and every command fails with `unsupported` — the data is left
256
+ untouched and `vault.reset` is the recovery path.
257
+ - `vault.addFactor` / `vault.removeFactor` are `unsupported` here, and so is the `factor`
258
+ option on create, import and restore — the host picks the vault's factors itself.
259
+ - `vault.reset` authenticates the device owner first, then erases the vault and all keystore
260
+ keys. Devices without a lock screen return `verification-unavailable`. A `WalletError.detail`
261
+ string carries the platform diagnostic
115
262
  (`"<domain>:<code>"`, e.g. `"LAErrorDomain:-5"` or
116
263
  `"android:KeyPermanentlyInvalidatedException"`) when the native layer can produce one.
117
- - `chain.sign` prompts _before_ any secret derivation: the kernel normalizes and decodes the
118
- intent, shows the prompt, and only then touches key material.
264
+ - `chain.sign` makes two passes over the signing secret: it derives the key material once to
265
+ normalize and decode the request and build the prompt, wipes it before the (possibly long)
266
+ system verification, re-checks the session, and only then derives it again and signs.
119
267
  - The kernel serializes ceremonies — two concurrent signing requests cannot race two system
120
268
  prompts.
269
+ - One kernel runtime runs per process: `createNativeWallet` throws while a previous wallet is
270
+ still live — `wallet.destroy()` it first.
271
+ - The package provides no secure view: screens that show a mnemonic or exported private key are
272
+ the host's to protect. On Android set `FLAG_SECURE` on the window; on iOS cover the screen with
273
+ a privacy overlay when the app resigns active — the app-switcher snapshot is written to disk.
121
274
  - `kernel/generated/kernel.manifest.json` inside the package records the kernel bundle's
122
275
  SHA-256 and every pinned protocol dependency; `scripts/compile-kernel.mjs` verifies it when
123
276
  the host is natively built and fails the build on a mismatch. At kernel start the host
@@ -19,8 +19,12 @@ Pod::Spec.new do |s|
19
19
  "cpp/runtime/**/*.{h,hpp,c,cpp,mm}",
20
20
  "cpp/host/**/*.{h,hpp,c,cpp,mm}",
21
21
  "cpp/platform/**/*.{h,hpp,c,cpp,mm}",
22
+ "ios/**/*.swift",
23
+ # The Argon2 reference implementation (cpp/vendor/argon2/README.md).
24
+ "cpp/vendor/argon2/**/*.{h,c}",
22
25
  ]
23
- s.public_header_files = "cpp/**/*.hpp"
26
+ s.private_header_files = "cpp/vendor/**/*.h"
27
+ s.public_header_files = ["cpp/**/*.hpp", "cpp/platform/QntxSecureInputField.h"]
24
28
  s.header_mappings_dir = "cpp"
25
29
 
26
30
  s.pod_target_xcconfig = {
@@ -28,6 +32,8 @@ Pod::Spec.new do |s|
28
32
  "CLANG_CXX_LANGUAGE_STANDARD" => "c++20",
29
33
  "HEADER_SEARCH_PATHS" => [
30
34
  '"$(PODS_TARGET_SRCROOT)/cpp"',
35
+ '"$(PODS_TARGET_SRCROOT)/cpp/vendor/argon2/include"',
36
+ '"$(PODS_TARGET_SRCROOT)/cpp/vendor/argon2/src"',
31
37
  '"$(PODS_ROOT)/hermes-engine/destroot/include"',
32
38
  '"$(PODS_ROOT)/Headers/Public/SparkNative"',
33
39
  '"$(DERIVED_FILE_DIR)/qntx-kernel"',
@@ -59,7 +65,10 @@ Pod::Spec.new do |s|
59
65
 
60
66
  # The kernel's backends.spark binds the qs_* C ABI; the prebuilt
61
67
  # QntxSpark.xcframework ships inside the SparkNative pod.
62
- s.frameworks = "LocalAuthentication", "Security", "AuthenticationServices", "UIKit"
68
+ s.frameworks = "LocalAuthentication", "Security", "AuthenticationServices", "UIKit", "CloudKit"
69
+ # CoreNFC is absent on the simulator and pre-NFC devices; weak-linking keeps
70
+ # those builds loading — `readingAvailable` reports no hardware instead.
71
+ s.weak_frameworks = "CoreNFC"
63
72
 
64
73
  s.dependency 'NostrNative'
65
74
  s.dependency 'SparkNative'
@@ -1,4 +1,4 @@
1
- project(WalletNative)
1
+ project(WalletNative C CXX)
2
2
  cmake_minimum_required(VERSION 3.16)
3
3
 
4
4
  set(PACKAGE_NAME WalletNative)
@@ -10,6 +10,8 @@ file(GLOB_RECURSE runtime_files CONFIGURE_DEPENDS
10
10
  "${CMAKE_CURRENT_SOURCE_DIR}/../cpp/host/*.cpp"
11
11
  "${CMAKE_CURRENT_SOURCE_DIR}/../cpp/platform/*.cpp"
12
12
  "${CMAKE_CURRENT_SOURCE_DIR}/src/main/cpp/*.cpp"
13
+ # The Argon2 reference implementation (cpp/vendor/argon2/README.md).
14
+ "${CMAKE_CURRENT_SOURCE_DIR}/../cpp/vendor/argon2/src/*.c"
13
15
  )
14
16
 
15
17
  add_library(${PACKAGE_NAME} SHARED ${runtime_files})
@@ -19,6 +21,10 @@ target_include_directories(${PACKAGE_NAME} PUBLIC
19
21
  "${CMAKE_CURRENT_SOURCE_DIR}/../cpp/platform"
20
22
  "${CMAKE_CURRENT_BINARY_DIR}/qntx-kernel"
21
23
  )
24
+ target_include_directories(${PACKAGE_NAME} PRIVATE
25
+ "${CMAKE_CURRENT_SOURCE_DIR}/../cpp/vendor/argon2/include"
26
+ "${CMAKE_CURRENT_SOURCE_DIR}/../cpp/vendor/argon2/src"
27
+ )
22
28
 
23
29
  # Compile the shipped kernel bundle to bytecode with the app's own hermesc —
24
30
  # Hermes only loads its own bytecode version, so precompiled hbc cannot ship.
@@ -148,6 +148,10 @@ dependencies {
148
148
  // backs Google Password Manager.
149
149
  implementation "androidx.credentials:credentials:1.6.0"
150
150
  implementation "androidx.credentials:credentials-play-services-auth:1.6.0"
151
+
152
+ // Google Identity authorization for drive.appdata tokens — the Google Drive
153
+ // cloud backup transport needs silent + interactive OAuth on Android.
154
+ implementation "com.google.android.gms:play-services-auth:22.0.0"
151
155
  }
152
156
 
153
157
  repositories {
@@ -1,2 +1 @@
1
- <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
- </manifest>
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android" />
@@ -6,21 +6,30 @@
6
6
 
7
7
  namespace qntx {
8
8
  void kernelVaultDirectoryInit(facebook::jni::alias_ref<jclass> clazz);
9
+ void kernelAnchorInit(facebook::jni::alias_ref<jclass> clazz);
9
10
  void kernelLifecycleInit(facebook::jni::alias_ref<jclass> clazz);
10
11
  void kernelKeystoreInit(facebook::jni::alias_ref<jclass> clazz);
11
12
  void kernelPasskeyInit(facebook::jni::alias_ref<jclass> clazz);
13
+ void kernelCardReaderInit(facebook::jni::alias_ref<jclass> clazz);
14
+ void kernelSecureInputInit(facebook::jni::alias_ref<jclass> clazz);
12
15
  }
13
16
 
14
17
  JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void*) {
15
18
  return facebook::jni::initialize(vm, []() {
16
19
  qntx::kernelVaultDirectoryInit(
17
20
  facebook::jni::findClassLocal("com/margelo/nitro/qntxwallet/VaultDirectory"));
21
+ qntx::kernelAnchorInit(
22
+ facebook::jni::findClassLocal("com/margelo/nitro/qntxwallet/VaultAnchor"));
18
23
  qntx::kernelLifecycleInit(
19
24
  facebook::jni::findClassLocal("com/margelo/nitro/qntxwallet/AppLifecycle"));
20
25
  qntx::kernelKeystoreInit(
21
26
  facebook::jni::findClassLocal("com/margelo/nitro/qntxwallet/Keystore"));
22
27
  qntx::kernelPasskeyInit(
23
28
  facebook::jni::findClassLocal("com/margelo/nitro/qntxwallet/Passkey"));
29
+ qntx::kernelCardReaderInit(
30
+ facebook::jni::findClassLocal("com/margelo/nitro/qntxwallet/CardReader"));
31
+ qntx::kernelSecureInputInit(
32
+ facebook::jni::findClassLocal("com/margelo/nitro/qntxwallet/SecureInputField"));
24
33
  margelo::nitro::qntxwallet::registerAllNatives();
25
34
  qntx::kernelPbkdf2OnLoad(
26
35
  facebook::jni::Environment::current(),