@qntx/wallet-native 0.10.0 → 0.11.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/README.md +6 -5
- package/android/src/main/java/com/margelo/nitro/qntxwallet/Keystore.kt +42 -27
- package/android/src/main/java/com/margelo/nitro/qntxwallet/Passkey.kt +26 -11
- package/cpp/host/Keystore.hpp +13 -3
- package/cpp/host/Passkey.hpp +13 -3
- package/cpp/platform/KeystoreAndroid.cpp +10 -2
- package/cpp/platform/KeystoreIos.mm +55 -11
- package/cpp/platform/PasskeyAndroid.cpp +10 -1
- package/cpp/platform/PasskeyIos.mm +26 -6
- package/cpp/runtime/KernelKeystore.cpp +25 -6
- package/cpp/runtime/KernelPasskey.cpp +24 -3
- package/kernel/generated/kernel-entry.js +57 -40
- package/kernel/generated/kernel.manifest.json +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -87,9 +87,8 @@ const wallet = await createNativeWallet({
|
|
|
87
87
|
Passkey wallets need the platform's domain association:
|
|
88
88
|
|
|
89
89
|
- **iOS** — `webcredentials:<rpId>` associated domain (requires a paid developer account; free
|
|
90
|
-
signing cannot hold the entitlement).
|
|
91
|
-
|
|
92
|
-
offered on iOS; ship mnemonic restore.
|
|
90
|
+
signing cannot hold the entitlement). Without the entitlement the ceremony returns
|
|
91
|
+
`passkey-not-configured`, and below iOS 18 it returns `unsupported`.
|
|
93
92
|
- **Android** — Credential Manager resolves the RP against
|
|
94
93
|
`https://<rpId>/.well-known/assetlinks.json` with
|
|
95
94
|
`delegate_permission/common.get_login_creds` naming the app's package and SHA-256 signing
|
|
@@ -111,8 +110,10 @@ Passkey wallets need the platform's domain association:
|
|
|
111
110
|
`spark.approve` request open a platform authentication ceremony with kernel-owned prompt text
|
|
112
111
|
(Simplified Chinese under a `zh*` locale, English otherwise).
|
|
113
112
|
- `vault.reset` authenticates the device owner first, then erases the vault and all hardware
|
|
114
|
-
keys. Devices without a lock screen return `
|
|
115
|
-
user to set one up.
|
|
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
|
|
115
|
+
(`"<domain>:<code>"`, e.g. `"LAErrorDomain:-5"` or
|
|
116
|
+
`"android:KeyPermanentlyInvalidatedException"`) when the native layer can produce one.
|
|
116
117
|
- `chain.sign` prompts _before_ any secret derivation: the kernel normalizes and decodes the
|
|
117
118
|
intent, shows the prompt, and only then touches key material.
|
|
118
119
|
- The kernel serializes ceremonies — two concurrent signing requests cannot race two system
|
|
@@ -51,6 +51,7 @@ object Keystore {
|
|
|
51
51
|
private const val INVALIDATED = 2
|
|
52
52
|
private const val UNAVAILABLE = 3
|
|
53
53
|
private const val FAILED = 4
|
|
54
|
+
private const val NO_DEVICE_CREDENTIAL = 5
|
|
54
55
|
|
|
55
56
|
@Volatile private var current: BiometricPrompt? = null
|
|
56
57
|
|
|
@@ -60,9 +61,13 @@ object Keystore {
|
|
|
60
61
|
@JvmStatic
|
|
61
62
|
fun seal(token: Long, id: String, secret: ByteArray, title: String, description: String) {
|
|
62
63
|
val activity = foregroundActivity()
|
|
63
|
-
if (activity == null
|
|
64
|
+
if (activity == null) {
|
|
64
65
|
secret.fill(0)
|
|
65
|
-
return nativeComplete(token, UNAVAILABLE, null)
|
|
66
|
+
return nativeComplete(token, UNAVAILABLE, null, "android:no-activity")
|
|
67
|
+
}
|
|
68
|
+
if (!deviceSecure(activity)) {
|
|
69
|
+
secret.fill(0)
|
|
70
|
+
return nativeComplete(token, NO_DEVICE_CREDENTIAL, null, null)
|
|
66
71
|
}
|
|
67
72
|
val alias = PREFIX + id
|
|
68
73
|
val cipher = try {
|
|
@@ -70,20 +75,20 @@ object Keystore {
|
|
|
70
75
|
Cipher.getInstance(TRANSFORMATION).apply { init(Cipher.ENCRYPT_MODE, generate(alias, activity)) }
|
|
71
76
|
} catch (e: Exception) {
|
|
72
77
|
secret.fill(0)
|
|
73
|
-
return nativeComplete(token, UNAVAILABLE, null)
|
|
78
|
+
return nativeComplete(token, UNAVAILABLE, null, detailOf(e))
|
|
74
79
|
}
|
|
75
|
-
prompt(activity, title, description, BiometricPrompt.CryptoObject(cipher)) { status, crypto ->
|
|
80
|
+
prompt(activity, title, description, BiometricPrompt.CryptoObject(cipher)) { status, detail, crypto ->
|
|
76
81
|
try {
|
|
77
82
|
val authenticated = crypto?.cipher
|
|
78
83
|
if (status != OK || authenticated == null) {
|
|
79
84
|
keyStore().deleteEntry(alias)
|
|
80
|
-
nativeComplete(token, if (status == OK) FAILED else status, null)
|
|
85
|
+
nativeComplete(token, if (status == OK) FAILED else status, null, detail)
|
|
81
86
|
} else {
|
|
82
|
-
nativeComplete(token, OK, authenticated.iv + authenticated.doFinal(secret))
|
|
87
|
+
nativeComplete(token, OK, authenticated.iv + authenticated.doFinal(secret), null)
|
|
83
88
|
}
|
|
84
89
|
} catch (e: Exception) {
|
|
85
90
|
keyStore().deleteEntry(alias)
|
|
86
|
-
nativeComplete(token, FAILED, null)
|
|
91
|
+
nativeComplete(token, FAILED, null, detailOf(e))
|
|
87
92
|
} finally {
|
|
88
93
|
secret.fill(0)
|
|
89
94
|
}
|
|
@@ -92,39 +97,40 @@ object Keystore {
|
|
|
92
97
|
|
|
93
98
|
@JvmStatic
|
|
94
99
|
fun open(token: Long, id: String, sealed: ByteArray, title: String, description: String) {
|
|
95
|
-
val activity = foregroundActivity()
|
|
100
|
+
val activity = foregroundActivity()
|
|
101
|
+
?: return nativeComplete(token, UNAVAILABLE, null, "android:no-activity")
|
|
96
102
|
if (sealed.size <= IV_BYTES + TAG_BITS / 8) {
|
|
97
|
-
return nativeComplete(token, FAILED, null)
|
|
103
|
+
return nativeComplete(token, FAILED, null, null)
|
|
98
104
|
}
|
|
99
105
|
val alias = PREFIX + id
|
|
100
106
|
val key = try {
|
|
101
107
|
keyStore().getKey(alias, null) as? SecretKey
|
|
102
108
|
} catch (e: UnrecoverableKeyException) {
|
|
103
109
|
null
|
|
104
|
-
} ?: return nativeComplete(token, INVALIDATED, null)
|
|
110
|
+
} ?: return nativeComplete(token, INVALIDATED, null, null)
|
|
105
111
|
val cipher = try {
|
|
106
112
|
Cipher.getInstance(TRANSFORMATION).apply {
|
|
107
113
|
init(Cipher.DECRYPT_MODE, key, GCMParameterSpec(TAG_BITS, sealed, 0, IV_BYTES))
|
|
108
114
|
}
|
|
109
115
|
} catch (e: KeyPermanentlyInvalidatedException) {
|
|
110
116
|
keyStore().deleteEntry(alias)
|
|
111
|
-
return nativeComplete(token, INVALIDATED, null)
|
|
117
|
+
return nativeComplete(token, INVALIDATED, null, detailOf(e))
|
|
112
118
|
} catch (e: Exception) {
|
|
113
|
-
return nativeComplete(token, FAILED, null)
|
|
119
|
+
return nativeComplete(token, FAILED, null, detailOf(e))
|
|
114
120
|
}
|
|
115
|
-
prompt(activity, title, description, BiometricPrompt.CryptoObject(cipher)) { status, crypto ->
|
|
121
|
+
prompt(activity, title, description, BiometricPrompt.CryptoObject(cipher)) { status, detail, crypto ->
|
|
116
122
|
val authenticated = crypto?.cipher
|
|
117
123
|
if (status != OK || authenticated == null) {
|
|
118
|
-
nativeComplete(token, if (status == OK) FAILED else status, null)
|
|
124
|
+
nativeComplete(token, if (status == OK) FAILED else status, null, detail)
|
|
119
125
|
return@prompt
|
|
120
126
|
}
|
|
121
127
|
val plain = try {
|
|
122
128
|
authenticated.doFinal(sealed, IV_BYTES, sealed.size - IV_BYTES)
|
|
123
129
|
} catch (e: Exception) {
|
|
124
|
-
return@prompt nativeComplete(token, FAILED, null)
|
|
130
|
+
return@prompt nativeComplete(token, FAILED, null, detailOf(e))
|
|
125
131
|
}
|
|
126
132
|
try {
|
|
127
|
-
nativeComplete(token, OK, plain)
|
|
133
|
+
nativeComplete(token, OK, plain, null)
|
|
128
134
|
} finally {
|
|
129
135
|
plain.fill(0)
|
|
130
136
|
}
|
|
@@ -134,10 +140,15 @@ object Keystore {
|
|
|
134
140
|
@JvmStatic
|
|
135
141
|
fun authenticate(token: Long, title: String, description: String) {
|
|
136
142
|
val activity = foregroundActivity()
|
|
137
|
-
if (activity == null
|
|
138
|
-
return nativeComplete(token, UNAVAILABLE, null)
|
|
143
|
+
if (activity == null) {
|
|
144
|
+
return nativeComplete(token, UNAVAILABLE, null, "android:no-activity")
|
|
145
|
+
}
|
|
146
|
+
if (!deviceSecure(activity)) {
|
|
147
|
+
return nativeComplete(token, NO_DEVICE_CREDENTIAL, null, null)
|
|
148
|
+
}
|
|
149
|
+
prompt(activity, title, description, null) { status, detail, _ ->
|
|
150
|
+
nativeComplete(token, status, null, detail)
|
|
139
151
|
}
|
|
140
|
-
prompt(activity, title, description, null) { status, _ -> nativeComplete(token, status, null) }
|
|
141
152
|
}
|
|
142
153
|
|
|
143
154
|
@JvmStatic
|
|
@@ -149,7 +160,7 @@ object Keystore {
|
|
|
149
160
|
} catch (e: Exception) {
|
|
150
161
|
FAILED
|
|
151
162
|
}
|
|
152
|
-
nativeComplete(token, status, null)
|
|
163
|
+
nativeComplete(token, status, null, null)
|
|
153
164
|
}
|
|
154
165
|
|
|
155
166
|
@JvmStatic
|
|
@@ -203,7 +214,7 @@ object Keystore {
|
|
|
203
214
|
title: String,
|
|
204
215
|
description: String,
|
|
205
216
|
crypto: BiometricPrompt.CryptoObject?,
|
|
206
|
-
done: (Int, BiometricPrompt.CryptoObject?) -> Unit,
|
|
217
|
+
done: (Int, String?, BiometricPrompt.CryptoObject?) -> Unit,
|
|
207
218
|
) {
|
|
208
219
|
val executor = ContextCompat.getMainExecutor(activity)
|
|
209
220
|
executor.execute { whenResumed(activity) { show(activity, executor, title, description, crypto, done) } }
|
|
@@ -232,7 +243,7 @@ object Keystore {
|
|
|
232
243
|
title: String,
|
|
233
244
|
description: String,
|
|
234
245
|
crypto: BiometricPrompt.CryptoObject?,
|
|
235
|
-
done: (Int, BiometricPrompt.CryptoObject?) -> Unit,
|
|
246
|
+
done: (Int, String?, BiometricPrompt.CryptoObject?) -> Unit,
|
|
236
247
|
) {
|
|
237
248
|
val info = BiometricPrompt.PromptInfo.Builder()
|
|
238
249
|
.setTitle(title)
|
|
@@ -245,12 +256,13 @@ object Keystore {
|
|
|
245
256
|
object : BiometricPrompt.AuthenticationCallback() {
|
|
246
257
|
override fun onAuthenticationSucceeded(result: BiometricPrompt.AuthenticationResult) {
|
|
247
258
|
current = null
|
|
248
|
-
done(OK, result.cryptoObject)
|
|
259
|
+
done(OK, null, result.cryptoObject)
|
|
249
260
|
}
|
|
250
261
|
|
|
251
262
|
override fun onAuthenticationError(errorCode: Int, errString: CharSequence) {
|
|
252
263
|
current = null
|
|
253
|
-
|
|
264
|
+
// The numeric code only — errString is localized free text.
|
|
265
|
+
done(statusOf(errorCode), "android:BiometricPrompt:$errorCode", null)
|
|
254
266
|
}
|
|
255
267
|
},
|
|
256
268
|
)
|
|
@@ -259,7 +271,7 @@ object Keystore {
|
|
|
259
271
|
if (crypto == null) biometricPrompt.authenticate(info) else biometricPrompt.authenticate(info, crypto)
|
|
260
272
|
} catch (e: Exception) {
|
|
261
273
|
current = null
|
|
262
|
-
done(FAILED, null)
|
|
274
|
+
done(FAILED, detailOf(e), null)
|
|
263
275
|
}
|
|
264
276
|
}
|
|
265
277
|
|
|
@@ -268,13 +280,16 @@ object Keystore {
|
|
|
268
280
|
BiometricPrompt.ERROR_NEGATIVE_BUTTON,
|
|
269
281
|
BiometricPrompt.ERROR_CANCELED,
|
|
270
282
|
BiometricPrompt.ERROR_TIMEOUT -> CANCELLED
|
|
271
|
-
BiometricPrompt.ERROR_NO_DEVICE_CREDENTIAL
|
|
283
|
+
BiometricPrompt.ERROR_NO_DEVICE_CREDENTIAL -> NO_DEVICE_CREDENTIAL
|
|
272
284
|
BiometricPrompt.ERROR_HW_UNAVAILABLE,
|
|
273
285
|
BiometricPrompt.ERROR_HW_NOT_PRESENT,
|
|
274
286
|
BiometricPrompt.ERROR_NO_BIOMETRICS -> UNAVAILABLE
|
|
275
287
|
else -> FAILED
|
|
276
288
|
}
|
|
277
289
|
|
|
290
|
+
// The exception's simple class name only — the message can name the account.
|
|
291
|
+
private fun detailOf(e: Exception): String = "android:" + e.javaClass.simpleName
|
|
292
|
+
|
|
278
293
|
@JvmStatic
|
|
279
|
-
private external fun nativeComplete(token: Long, status: Int, bytes: ByteArray?)
|
|
294
|
+
private external fun nativeComplete(token: Long, status: Int, bytes: ByteArray?, detail: String?)
|
|
280
295
|
}
|
|
@@ -44,6 +44,8 @@ object Passkey {
|
|
|
44
44
|
private const val CANCELLED = 1
|
|
45
45
|
private const val UNAVAILABLE = 3
|
|
46
46
|
private const val FAILED = 4
|
|
47
|
+
private const val NOT_CONFIGURED = 5
|
|
48
|
+
private const val UNSUPPORTED = 6
|
|
47
49
|
// The exception type only — never the message, which can name the account.
|
|
48
50
|
private const val TAG = "QntxPasskey"
|
|
49
51
|
|
|
@@ -51,7 +53,8 @@ object Passkey {
|
|
|
51
53
|
|
|
52
54
|
@JvmStatic
|
|
53
55
|
fun create(token: Long, requestJson: String) {
|
|
54
|
-
val activity = foregroundActivity()
|
|
56
|
+
val activity = foregroundActivity()
|
|
57
|
+
?: return nativeComplete(token, UNAVAILABLE, null, "android:no-activity")
|
|
55
58
|
val cancel = CancellationSignal().also { signal = it }
|
|
56
59
|
CredentialManager.create(activity).createCredentialAsync(
|
|
57
60
|
activity,
|
|
@@ -66,13 +69,14 @@ object Passkey {
|
|
|
66
69
|
token,
|
|
67
70
|
if (response == null) FAILED else OK,
|
|
68
71
|
response?.registrationResponseJson,
|
|
72
|
+
null,
|
|
69
73
|
)
|
|
70
74
|
}
|
|
71
75
|
|
|
72
76
|
override fun onError(e: CreateCredentialException) {
|
|
73
77
|
signal = null
|
|
74
78
|
Log.w(TAG, "create failed: ${e.type}")
|
|
75
|
-
nativeComplete(token, statusOf(e), null)
|
|
79
|
+
nativeComplete(token, statusOf(e), null, detailOf(e))
|
|
76
80
|
}
|
|
77
81
|
},
|
|
78
82
|
)
|
|
@@ -80,7 +84,8 @@ object Passkey {
|
|
|
80
84
|
|
|
81
85
|
@JvmStatic
|
|
82
86
|
fun get(token: Long, requestJson: String) {
|
|
83
|
-
val activity = foregroundActivity()
|
|
87
|
+
val activity = foregroundActivity()
|
|
88
|
+
?: return nativeComplete(token, UNAVAILABLE, null, "android:no-activity")
|
|
84
89
|
val cancel = CancellationSignal().also { signal = it }
|
|
85
90
|
CredentialManager.create(activity).getCredentialAsync(
|
|
86
91
|
activity,
|
|
@@ -95,13 +100,14 @@ object Passkey {
|
|
|
95
100
|
token,
|
|
96
101
|
if (credential == null) FAILED else OK,
|
|
97
102
|
credential?.authenticationResponseJson,
|
|
103
|
+
null,
|
|
98
104
|
)
|
|
99
105
|
}
|
|
100
106
|
|
|
101
107
|
override fun onError(e: GetCredentialException) {
|
|
102
108
|
signal = null
|
|
103
109
|
Log.w(TAG, "get failed: ${e.type}")
|
|
104
|
-
nativeComplete(token, statusOf(e), null)
|
|
110
|
+
nativeComplete(token, statusOf(e), null, detailOf(e))
|
|
105
111
|
}
|
|
106
112
|
},
|
|
107
113
|
)
|
|
@@ -121,27 +127,36 @@ object Passkey {
|
|
|
121
127
|
private fun statusOf(e: CreateCredentialException): Int = when (e) {
|
|
122
128
|
is CreateCredentialCancellationException -> CANCELLED
|
|
123
129
|
is CreateCredentialNoCreateOptionException,
|
|
124
|
-
is CreateCredentialProviderConfigurationException
|
|
125
|
-
is CreateCredentialUnsupportedException ->
|
|
130
|
+
is CreateCredentialProviderConfigurationException -> NOT_CONFIGURED
|
|
131
|
+
is CreateCredentialUnsupportedException -> UNSUPPORTED
|
|
126
132
|
is CreatePublicKeyCredentialDomException -> domStatus(e.type)
|
|
127
133
|
else -> FAILED
|
|
128
134
|
}
|
|
129
135
|
|
|
130
136
|
private fun statusOf(e: GetCredentialException): Int = when (e) {
|
|
131
137
|
is GetCredentialCancellationException -> CANCELLED
|
|
132
|
-
is
|
|
133
|
-
is
|
|
134
|
-
is
|
|
138
|
+
is GetCredentialProviderConfigurationException -> NOT_CONFIGURED
|
|
139
|
+
is GetCredentialUnsupportedException -> UNSUPPORTED
|
|
140
|
+
is NoCredentialException -> UNAVAILABLE
|
|
135
141
|
is GetPublicKeyCredentialDomException -> domStatus(e.type)
|
|
136
142
|
else -> FAILED
|
|
137
143
|
}
|
|
138
144
|
|
|
139
145
|
private fun domStatus(type: String): Int = when {
|
|
140
146
|
type.endsWith("NotAllowedError") -> CANCELLED
|
|
141
|
-
type.endsWith("
|
|
147
|
+
type.endsWith("NotSupportedError") -> UNSUPPORTED
|
|
148
|
+
type.endsWith("SecurityError") -> UNAVAILABLE
|
|
142
149
|
else -> FAILED
|
|
143
150
|
}
|
|
144
151
|
|
|
152
|
+
// The exception's simple class name only — the message can name the account.
|
|
153
|
+
private fun detailOf(e: Exception): String = "android:" + e.javaClass.simpleName
|
|
154
|
+
|
|
145
155
|
@JvmStatic
|
|
146
|
-
private external fun nativeComplete(
|
|
156
|
+
private external fun nativeComplete(
|
|
157
|
+
token: Long,
|
|
158
|
+
status: Int,
|
|
159
|
+
responseJson: String?,
|
|
160
|
+
detail: String?,
|
|
161
|
+
)
|
|
147
162
|
}
|
package/cpp/host/Keystore.hpp
CHANGED
|
@@ -22,14 +22,24 @@ struct KeystorePrompt {
|
|
|
22
22
|
|
|
23
23
|
// How a keystore call ended. The binding maps each status to the kernel's
|
|
24
24
|
// error code: cancelled → "cancelled", invalidated → "factor-invalidated",
|
|
25
|
-
// unavailable → "
|
|
26
|
-
//
|
|
27
|
-
|
|
25
|
+
// unavailable → "unavailable", failed → "unavailable",
|
|
26
|
+
// noDeviceCredential → "no-device-credential". The values are part of the
|
|
27
|
+
// Android JNI contract (Keystore.kt).
|
|
28
|
+
enum class KeystoreStatus {
|
|
29
|
+
ok = 0,
|
|
30
|
+
cancelled = 1,
|
|
31
|
+
invalidated = 2,
|
|
32
|
+
unavailable = 3,
|
|
33
|
+
failed = 4,
|
|
34
|
+
noDeviceCredential = 5,
|
|
35
|
+
};
|
|
28
36
|
|
|
29
37
|
struct KeystoreResult {
|
|
30
38
|
KeystoreStatus status = KeystoreStatus::failed;
|
|
31
39
|
// seal: the platform ciphertext; open: the KEK; empty otherwise.
|
|
32
40
|
SecretBytes bytes;
|
|
41
|
+
// A "<domain>:<code>" diagnostic (e.g. "LAErrorDomain:-5"), empty when none.
|
|
42
|
+
std::string detail;
|
|
33
43
|
};
|
|
34
44
|
|
|
35
45
|
// Completion callbacks run exactly once, on any thread.
|
package/cpp/host/Passkey.hpp
CHANGED
|
@@ -14,14 +14,24 @@ namespace qntx {
|
|
|
14
14
|
// PasskeyIos.mm); host tests link a fake.
|
|
15
15
|
|
|
16
16
|
// The binding maps each status to the kernel's error code: cancelled →
|
|
17
|
-
// "cancelled", unavailable → "
|
|
18
|
-
//
|
|
19
|
-
|
|
17
|
+
// "cancelled", unavailable → "unavailable", failed → "unavailable",
|
|
18
|
+
// notConfigured → "passkey-not-configured", unsupported → "unsupported". The
|
|
19
|
+
// values are part of the Android JNI contract (Passkey.kt).
|
|
20
|
+
enum class PasskeyStatus {
|
|
21
|
+
ok = 0,
|
|
22
|
+
cancelled = 1,
|
|
23
|
+
unavailable = 3,
|
|
24
|
+
failed = 4,
|
|
25
|
+
notConfigured = 5,
|
|
26
|
+
unsupported = 6,
|
|
27
|
+
};
|
|
20
28
|
|
|
21
29
|
struct PasskeyResult {
|
|
22
30
|
PasskeyStatus status = PasskeyStatus::failed;
|
|
23
31
|
// The WebAuthn registration or authentication response JSON on success.
|
|
24
32
|
std::string responseJson;
|
|
33
|
+
// A "<domain>:<code>" diagnostic (e.g. "ASAuthorizationErrorDomain:1004").
|
|
34
|
+
std::string detail;
|
|
25
35
|
};
|
|
26
36
|
|
|
27
37
|
// Completion callbacks run exactly once, on any thread.
|
|
@@ -153,14 +153,15 @@ std::string keystoreLocale() {
|
|
|
153
153
|
// is copied into wiping storage; Kotlin wipes its own copy afterwards.
|
|
154
154
|
extern "C" JNIEXPORT void JNICALL
|
|
155
155
|
Java_com_margelo_nitro_qntxwallet_Keystore_nativeComplete(
|
|
156
|
-
JNIEnv* env, jclass, jlong token, jint status, jbyteArray bytes) {
|
|
156
|
+
JNIEnv* env, jclass, jlong token, jint status, jbyteArray bytes, jstring detail) {
|
|
157
157
|
auto done = qntx::take(static_cast<int64_t>(token));
|
|
158
158
|
if (!done) {
|
|
159
159
|
return;
|
|
160
160
|
}
|
|
161
161
|
qntx::KeystoreResult result;
|
|
162
162
|
result.status = static_cast<qntx::KeystoreStatus>(status);
|
|
163
|
-
if (status < 0 ||
|
|
163
|
+
if (status < 0 ||
|
|
164
|
+
status > static_cast<jint>(qntx::KeystoreStatus::noDeviceCredential)) {
|
|
164
165
|
result.status = qntx::KeystoreStatus::failed;
|
|
165
166
|
}
|
|
166
167
|
if (bytes != nullptr && result.status == qntx::KeystoreStatus::ok) {
|
|
@@ -169,6 +170,13 @@ Java_com_margelo_nitro_qntxwallet_Keystore_nativeComplete(
|
|
|
169
170
|
env->GetByteArrayRegion(bytes, 0, size, reinterpret_cast<jbyte*>(copy.data()));
|
|
170
171
|
result.bytes = std::move(copy);
|
|
171
172
|
}
|
|
173
|
+
if (detail != nullptr) {
|
|
174
|
+
const char* utf = env->GetStringUTFChars(detail, nullptr);
|
|
175
|
+
if (utf != nullptr) {
|
|
176
|
+
result.detail = utf;
|
|
177
|
+
env->ReleaseStringUTFChars(detail, utf);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
172
180
|
done(std::move(result));
|
|
173
181
|
}
|
|
174
182
|
|
|
@@ -16,6 +16,8 @@
|
|
|
16
16
|
#include <cstring>
|
|
17
17
|
#include <memory>
|
|
18
18
|
#include <mutex>
|
|
19
|
+
#include <optional>
|
|
20
|
+
#include <string>
|
|
19
21
|
#include <utility>
|
|
20
22
|
|
|
21
23
|
namespace qntx {
|
|
@@ -60,7 +62,7 @@ KeystoreStatus statusOf(NSError* error) {
|
|
|
60
62
|
case LAErrorUserFallback:
|
|
61
63
|
return KeystoreStatus::cancelled;
|
|
62
64
|
case LAErrorPasscodeNotSet:
|
|
63
|
-
return KeystoreStatus::
|
|
65
|
+
return KeystoreStatus::noDeviceCredential;
|
|
64
66
|
default:
|
|
65
67
|
return KeystoreStatus::failed;
|
|
66
68
|
}
|
|
@@ -82,6 +84,39 @@ KeystoreStatus statusOf(CFErrorRef error) {
|
|
|
82
84
|
return statusOf((__bridge NSError*)error);
|
|
83
85
|
}
|
|
84
86
|
|
|
87
|
+
// The "<domain>:<code>" diagnostic — never userInfo or localizedDescription,
|
|
88
|
+
// which can name the account.
|
|
89
|
+
std::string detailOf(NSError* error) {
|
|
90
|
+
if (error == nil) {
|
|
91
|
+
return {};
|
|
92
|
+
}
|
|
93
|
+
char buffer[96];
|
|
94
|
+
std::snprintf(
|
|
95
|
+
buffer,
|
|
96
|
+
sizeof(buffer),
|
|
97
|
+
"%s:%ld",
|
|
98
|
+
error.domain.UTF8String,
|
|
99
|
+
static_cast<long>(error.code));
|
|
100
|
+
return buffer;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
std::string detailOf(CFErrorRef error) {
|
|
104
|
+
return detailOf((__bridge NSError*)error);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// A failed canEvaluatePolicy: LAErrorPasscodeNotSet is the one failure a user
|
|
108
|
+
// can act on (no device passcode → no hardware factor can exist), so it gets
|
|
109
|
+
// its own status; every other LAError is a plain platform failure.
|
|
110
|
+
KeystoreResult credentialProbeFailure(NSError* error) {
|
|
111
|
+
return {
|
|
112
|
+
error != nil && [error.domain isEqualToString:LAErrorDomain] &&
|
|
113
|
+
error.code == LAErrorPasscodeNotSet
|
|
114
|
+
? KeystoreStatus::noDeviceCredential
|
|
115
|
+
: KeystoreStatus::unavailable,
|
|
116
|
+
{},
|
|
117
|
+
detailOf(error)};
|
|
118
|
+
}
|
|
119
|
+
|
|
85
120
|
void deleteKey(NSData* tag) {
|
|
86
121
|
SecItemDelete((__bridge CFDictionaryRef) @{
|
|
87
122
|
(id)kSecClass : (id)kSecClassKey,
|
|
@@ -89,14 +124,20 @@ void deleteKey(NSData* tag) {
|
|
|
89
124
|
});
|
|
90
125
|
}
|
|
91
126
|
|
|
92
|
-
|
|
127
|
+
// The device-credential gate: seal cannot create a hardware key while the
|
|
128
|
+
// policy cannot be evaluated at all.
|
|
129
|
+
std::optional<KeystoreResult> deviceCredentialMissing() {
|
|
93
130
|
LAContext* probe = [LAContext new];
|
|
94
|
-
|
|
131
|
+
NSError* error = nil;
|
|
132
|
+
if ([probe canEvaluatePolicy:LAPolicyDeviceOwnerAuthentication error:&error]) {
|
|
133
|
+
return std::nullopt;
|
|
134
|
+
}
|
|
135
|
+
return credentialProbeFailure(error);
|
|
95
136
|
}
|
|
96
137
|
|
|
97
138
|
KeystoreResult sealNow(const std::string& factorId, const SecretBytes& secret) {
|
|
98
|
-
if (
|
|
99
|
-
return
|
|
139
|
+
if (auto missing = deviceCredentialMissing()) {
|
|
140
|
+
return std::move(*missing);
|
|
100
141
|
}
|
|
101
142
|
NSData* tag = tagFor(factorId);
|
|
102
143
|
deleteKey(tag);
|
|
@@ -108,10 +149,11 @@ KeystoreResult sealNow(const std::string& factorId, const SecretBytes& secret) {
|
|
|
108
149
|
SecAccessControlRef access = SecAccessControlCreateWithFlags(
|
|
109
150
|
kCFAllocatorDefault, kSecAttrAccessibleWhenPasscodeSetThisDeviceOnly, flags, &error);
|
|
110
151
|
if (access == nullptr) {
|
|
152
|
+
KeystoreResult out{KeystoreStatus::unavailable, {}, detailOf(error)};
|
|
111
153
|
if (error != nullptr) {
|
|
112
154
|
CFRelease(error);
|
|
113
155
|
}
|
|
114
|
-
return
|
|
156
|
+
return out;
|
|
115
157
|
}
|
|
116
158
|
NSMutableDictionary* attributes = [@{
|
|
117
159
|
(id)kSecAttrKeyType : (id)kSecAttrKeyTypeECSECPrimeRandom,
|
|
@@ -128,10 +170,11 @@ KeystoreResult sealNow(const std::string& factorId, const SecretBytes& secret) {
|
|
|
128
170
|
SecKeyRef privateKey = SecKeyCreateRandomKey((__bridge CFDictionaryRef)attributes, &error);
|
|
129
171
|
CFRelease(access);
|
|
130
172
|
if (privateKey == nullptr) {
|
|
173
|
+
KeystoreResult out{KeystoreStatus::unavailable, {}, detailOf(error)};
|
|
131
174
|
if (error != nullptr) {
|
|
132
175
|
CFRelease(error);
|
|
133
176
|
}
|
|
134
|
-
return
|
|
177
|
+
return out;
|
|
135
178
|
}
|
|
136
179
|
SecKeyRef publicKey = SecKeyCopyPublicKey(privateKey);
|
|
137
180
|
CFRelease(privateKey);
|
|
@@ -145,11 +188,12 @@ KeystoreResult sealNow(const std::string& factorId, const SecretBytes& secret) {
|
|
|
145
188
|
CFRelease(plain);
|
|
146
189
|
CFRelease(publicKey);
|
|
147
190
|
if (sealed == nullptr) {
|
|
191
|
+
KeystoreResult out{KeystoreStatus::unavailable, {}, detailOf(error)};
|
|
148
192
|
if (error != nullptr) {
|
|
149
193
|
CFRelease(error);
|
|
150
194
|
}
|
|
151
195
|
deleteKey(tag);
|
|
152
|
-
return
|
|
196
|
+
return out;
|
|
153
197
|
}
|
|
154
198
|
SecretBytes out(CFDataGetBytePtr(sealed), static_cast<size_t>(CFDataGetLength(sealed)));
|
|
155
199
|
CFRelease(sealed);
|
|
@@ -239,9 +283,9 @@ void keystoreAuthenticate(KeystorePrompt prompt, KeystoreDone done) {
|
|
|
239
283
|
dispatch_async(keystoreQueue(), ^{
|
|
240
284
|
LAContext* context = [LAContext new];
|
|
241
285
|
context.touchIDAuthenticationAllowableReuseDuration = 0;
|
|
242
|
-
NSError*
|
|
243
|
-
if (![context canEvaluatePolicy:LAPolicyDeviceOwnerAuthentication error:&
|
|
244
|
-
(*finish)(
|
|
286
|
+
NSError* error = nil;
|
|
287
|
+
if (![context canEvaluatePolicy:LAPolicyDeviceOwnerAuthentication error:&error]) {
|
|
288
|
+
(*finish)(credentialProbeFailure(error));
|
|
245
289
|
return;
|
|
246
290
|
}
|
|
247
291
|
setCurrentContext(context);
|
|
@@ -90,7 +90,7 @@ void passkeyCancel() {
|
|
|
90
90
|
|
|
91
91
|
extern "C" JNIEXPORT void JNICALL
|
|
92
92
|
Java_com_margelo_nitro_qntxwallet_Passkey_nativeComplete(
|
|
93
|
-
JNIEnv* env, jclass, jlong token, jint status, jstring responseJson) {
|
|
93
|
+
JNIEnv* env, jclass, jlong token, jint status, jstring responseJson, jstring detail) {
|
|
94
94
|
auto done = qntx::take(static_cast<int64_t>(token));
|
|
95
95
|
if (!done) {
|
|
96
96
|
return;
|
|
@@ -100,6 +100,8 @@ Java_com_margelo_nitro_qntxwallet_Passkey_nativeComplete(
|
|
|
100
100
|
case static_cast<jint>(qntx::PasskeyStatus::ok):
|
|
101
101
|
case static_cast<jint>(qntx::PasskeyStatus::cancelled):
|
|
102
102
|
case static_cast<jint>(qntx::PasskeyStatus::unavailable):
|
|
103
|
+
case static_cast<jint>(qntx::PasskeyStatus::notConfigured):
|
|
104
|
+
case static_cast<jint>(qntx::PasskeyStatus::unsupported):
|
|
103
105
|
result.status = static_cast<qntx::PasskeyStatus>(status);
|
|
104
106
|
break;
|
|
105
107
|
default:
|
|
@@ -112,6 +114,13 @@ Java_com_margelo_nitro_qntxwallet_Passkey_nativeComplete(
|
|
|
112
114
|
env->ReleaseStringUTFChars(responseJson, utf);
|
|
113
115
|
}
|
|
114
116
|
}
|
|
117
|
+
if (detail != nullptr) {
|
|
118
|
+
const char* utf = env->GetStringUTFChars(detail, nullptr);
|
|
119
|
+
if (utf != nullptr) {
|
|
120
|
+
result.detail = utf;
|
|
121
|
+
env->ReleaseStringUTFChars(detail, utf);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
115
124
|
done(std::move(result));
|
|
116
125
|
}
|
|
117
126
|
|
|
@@ -145,6 +145,22 @@ std::string jsonString(NSDictionary<NSString*, id>* json) {
|
|
|
145
145
|
return std::string(static_cast<const char*>(data.bytes), data.length);
|
|
146
146
|
}
|
|
147
147
|
|
|
148
|
+
// The "<domain>:<code>" diagnostic — never userInfo or localizedDescription,
|
|
149
|
+
// which can name the account.
|
|
150
|
+
std::string detailOf(NSError* error) {
|
|
151
|
+
if (error == nil) {
|
|
152
|
+
return {};
|
|
153
|
+
}
|
|
154
|
+
char buffer[96];
|
|
155
|
+
std::snprintf(
|
|
156
|
+
buffer,
|
|
157
|
+
sizeof(buffer),
|
|
158
|
+
"%s:%ld",
|
|
159
|
+
error.domain.UTF8String,
|
|
160
|
+
static_cast<long>(error.code));
|
|
161
|
+
return buffer;
|
|
162
|
+
}
|
|
163
|
+
|
|
148
164
|
} // namespace
|
|
149
165
|
|
|
150
166
|
API_AVAILABLE(ios(18.0))
|
|
@@ -197,7 +213,8 @@ API_AVAILABLE(ios(18.0))
|
|
|
197
213
|
}];
|
|
198
214
|
return;
|
|
199
215
|
}
|
|
200
|
-
[self finish:qntx::PasskeyResult{
|
|
216
|
+
[self finish:qntx::PasskeyResult{
|
|
217
|
+
qntx::PasskeyStatus::unavailable, {}, "ios:no-key-window"}];
|
|
201
218
|
}
|
|
202
219
|
|
|
203
220
|
- (void)sceneActivated {
|
|
@@ -205,7 +222,8 @@ API_AVAILABLE(ios(18.0))
|
|
|
205
222
|
_observer = nil;
|
|
206
223
|
ASPresentationAnchor anchor = activeKeyWindow();
|
|
207
224
|
if (anchor == nil) {
|
|
208
|
-
[self finish:qntx::PasskeyResult{
|
|
225
|
+
[self finish:qntx::PasskeyResult{
|
|
226
|
+
qntx::PasskeyStatus::unavailable, {}, "ios:no-key-window"}];
|
|
209
227
|
return;
|
|
210
228
|
}
|
|
211
229
|
[self performWithAnchor:anchor];
|
|
@@ -329,6 +347,8 @@ API_AVAILABLE(ios(18.0))
|
|
|
329
347
|
status = qntx::PasskeyStatus::cancelled;
|
|
330
348
|
break;
|
|
331
349
|
case ASAuthorizationErrorNotHandled:
|
|
350
|
+
status = qntx::PasskeyStatus::notConfigured;
|
|
351
|
+
break;
|
|
332
352
|
case ASAuthorizationErrorFailed:
|
|
333
353
|
case ASAuthorizationErrorNotInteractive:
|
|
334
354
|
status = qntx::PasskeyStatus::unavailable;
|
|
@@ -336,7 +356,7 @@ API_AVAILABLE(ios(18.0))
|
|
|
336
356
|
default:
|
|
337
357
|
// 1010 = ASAuthorizationErrorDeviceNotConfiguredForPasskeyCreation,
|
|
338
358
|
// compared raw so the iOS 19 symbol needs no availability guard.
|
|
339
|
-
status = error.code == 1010 ? qntx::PasskeyStatus::
|
|
359
|
+
status = error.code == 1010 ? qntx::PasskeyStatus::notConfigured
|
|
340
360
|
: qntx::PasskeyStatus::failed;
|
|
341
361
|
}
|
|
342
362
|
}
|
|
@@ -346,7 +366,7 @@ API_AVAILABLE(ios(18.0))
|
|
|
346
366
|
"passkey ceremony failed: %{public}@/%ld",
|
|
347
367
|
error.domain,
|
|
348
368
|
static_cast<long>(error.code));
|
|
349
|
-
[self finish:qntx::PasskeyResult{status, {}}];
|
|
369
|
+
[self finish:qntx::PasskeyResult{status, {}, detailOf(error)}];
|
|
350
370
|
}
|
|
351
371
|
|
|
352
372
|
@end
|
|
@@ -452,7 +472,7 @@ void passkeyCreate(std::string requestJson, PasskeyDone done) {
|
|
|
452
472
|
if (@available(iOS 18.0, *)) {
|
|
453
473
|
run(registrationRequest(jsonOf(*json)), std::move(*finish));
|
|
454
474
|
} else {
|
|
455
|
-
(*finish)(PasskeyResult{PasskeyStatus::
|
|
475
|
+
(*finish)(PasskeyResult{PasskeyStatus::unsupported, {}, "ios:passkeys-unavailable"});
|
|
456
476
|
}
|
|
457
477
|
});
|
|
458
478
|
}
|
|
@@ -464,7 +484,7 @@ void passkeyGet(std::string requestJson, PasskeyDone done) {
|
|
|
464
484
|
if (@available(iOS 18.0, *)) {
|
|
465
485
|
run(assertionRequest(jsonOf(*json)), std::move(*finish));
|
|
466
486
|
} else {
|
|
467
|
-
(*finish)(PasskeyResult{PasskeyStatus::
|
|
487
|
+
(*finish)(PasskeyResult{PasskeyStatus::unsupported, {}, "ios:passkeys-unavailable"});
|
|
468
488
|
}
|
|
469
489
|
});
|
|
470
490
|
}
|
|
@@ -71,15 +71,32 @@ const char* errorCode(KeystoreStatus status) {
|
|
|
71
71
|
return "cancelled";
|
|
72
72
|
case KeystoreStatus::invalidated:
|
|
73
73
|
return "factor-invalidated";
|
|
74
|
-
case KeystoreStatus::
|
|
75
|
-
return "
|
|
74
|
+
case KeystoreStatus::noDeviceCredential:
|
|
75
|
+
return "no-device-credential";
|
|
76
76
|
case KeystoreStatus::ok:
|
|
77
|
+
case KeystoreStatus::unavailable:
|
|
77
78
|
case KeystoreStatus::failed:
|
|
78
79
|
break;
|
|
79
80
|
}
|
|
80
81
|
return "unavailable";
|
|
81
82
|
}
|
|
82
83
|
|
|
84
|
+
// A detail is a "<domain>:<code>" diagnostic the JS side validates again;
|
|
85
|
+
// pass it through only while it stays a short token string.
|
|
86
|
+
jsi::Value detailValue(jsi::Runtime& rt, const std::string& detail) {
|
|
87
|
+
if (detail.empty() || detail.size() > 80) {
|
|
88
|
+
return jsi::Value::undefined();
|
|
89
|
+
}
|
|
90
|
+
for (const char c : detail) {
|
|
91
|
+
const bool ok = (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') ||
|
|
92
|
+
(c >= '0' && c <= '9') || c == '_' || c == '.' || c == ':' || c == '-';
|
|
93
|
+
if (!ok) {
|
|
94
|
+
return jsi::Value::undefined();
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return jsi::Value(rt, jsi::String::createFromAscii(rt, detail));
|
|
98
|
+
}
|
|
99
|
+
|
|
83
100
|
// Shared by every keystore call of one runtime: the number of platform calls
|
|
84
101
|
// whose completion has not yet returned (kernel thread only).
|
|
85
102
|
struct KeystoreCalls {
|
|
@@ -118,23 +135,25 @@ KeystoreDone park(
|
|
|
118
135
|
done->call(
|
|
119
136
|
rt,
|
|
120
137
|
jsi::Value::undefined(),
|
|
121
|
-
jsi::Value(rt, jsi::String::createFromAscii(rt, errorCode(shared->status)))
|
|
138
|
+
jsi::Value(rt, jsi::String::createFromAscii(rt, errorCode(shared->status))),
|
|
139
|
+
detailValue(rt, shared->detail));
|
|
122
140
|
return;
|
|
123
141
|
}
|
|
124
142
|
if (!withBytes) {
|
|
125
|
-
done->call(rt, jsi::Value::undefined(), jsi::Value::undefined());
|
|
143
|
+
done->call(rt, jsi::Value::undefined(), jsi::Value::undefined(), jsi::Value::undefined());
|
|
126
144
|
return;
|
|
127
145
|
}
|
|
128
146
|
if (shared->bytes.size() == 0) {
|
|
129
147
|
done->call(
|
|
130
148
|
rt,
|
|
131
149
|
jsi::Value::undefined(),
|
|
132
|
-
jsi::Value(rt, jsi::String::createFromAscii(rt, errorCode(KeystoreStatus::failed)))
|
|
150
|
+
jsi::Value(rt, jsi::String::createFromAscii(rt, errorCode(KeystoreStatus::failed))),
|
|
151
|
+
jsi::Value::undefined());
|
|
133
152
|
return;
|
|
134
153
|
}
|
|
135
154
|
auto buffer = arrayBufferFromBytes(rt, shared->bytes.data(), shared->bytes.size());
|
|
136
155
|
auto array = makeUint8Array(rt, *state->intrinsics, std::move(buffer));
|
|
137
|
-
done->call(rt, jsi::Value(std::move(array)), jsi::Value::undefined());
|
|
156
|
+
done->call(rt, jsi::Value(std::move(array)), jsi::Value::undefined(), jsi::Value::undefined());
|
|
138
157
|
});
|
|
139
158
|
};
|
|
140
159
|
}
|
|
@@ -19,15 +19,34 @@ const char* errorCode(PasskeyStatus status) {
|
|
|
19
19
|
switch (status) {
|
|
20
20
|
case PasskeyStatus::cancelled:
|
|
21
21
|
return "cancelled";
|
|
22
|
-
case PasskeyStatus::
|
|
23
|
-
return "
|
|
22
|
+
case PasskeyStatus::notConfigured:
|
|
23
|
+
return "passkey-not-configured";
|
|
24
|
+
case PasskeyStatus::unsupported:
|
|
25
|
+
return "unsupported";
|
|
24
26
|
case PasskeyStatus::ok:
|
|
27
|
+
case PasskeyStatus::unavailable:
|
|
25
28
|
case PasskeyStatus::failed:
|
|
26
29
|
break;
|
|
27
30
|
}
|
|
28
31
|
return "unavailable";
|
|
29
32
|
}
|
|
30
33
|
|
|
34
|
+
// A detail is a "<domain>:<code>" diagnostic the JS side validates again;
|
|
35
|
+
// pass it through only while it stays a short token string.
|
|
36
|
+
jsi::Value detailValue(jsi::Runtime& rt, const std::string& detail) {
|
|
37
|
+
if (detail.empty() || detail.size() > 80) {
|
|
38
|
+
return jsi::Value::undefined();
|
|
39
|
+
}
|
|
40
|
+
for (const char c : detail) {
|
|
41
|
+
const bool ok = (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') ||
|
|
42
|
+
(c >= '0' && c <= '9') || c == '_' || c == '.' || c == ':' || c == '-';
|
|
43
|
+
if (!ok) {
|
|
44
|
+
return jsi::Value::undefined();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return jsi::Value(rt, jsi::String::createFromAscii(rt, detail));
|
|
48
|
+
}
|
|
49
|
+
|
|
31
50
|
struct PasskeyCalls {
|
|
32
51
|
int inFlight = 0; // kernel thread only
|
|
33
52
|
};
|
|
@@ -74,12 +93,14 @@ PasskeyDone park(
|
|
|
74
93
|
done->call(
|
|
75
94
|
rt,
|
|
76
95
|
jsi::Value::undefined(),
|
|
77
|
-
jsi::Value(rt, jsi::String::createFromAscii(rt, errorCode(status)))
|
|
96
|
+
jsi::Value(rt, jsi::String::createFromAscii(rt, errorCode(status))),
|
|
97
|
+
detailValue(rt, shared->detail));
|
|
78
98
|
return;
|
|
79
99
|
}
|
|
80
100
|
done->call(
|
|
81
101
|
rt,
|
|
82
102
|
jsi::Value(rt, jsi::String::createFromUtf8(rt, shared->responseJson)),
|
|
103
|
+
jsi::Value::undefined(),
|
|
83
104
|
jsi::Value::undefined());
|
|
84
105
|
});
|
|
85
106
|
};
|
|
@@ -497,7 +497,7 @@
|
|
|
497
497
|
var init_defineProperty = __esmMin((() => {
|
|
498
498
|
init_toPropertyKey();
|
|
499
499
|
}));
|
|
500
|
-
// packages/wallet/dist/core-
|
|
500
|
+
// packages/wallet/dist/core-DDfzuSIa.mjs
|
|
501
501
|
init_defineProperty();
|
|
502
502
|
/**
|
|
503
503
|
* Strict validator combinators for the secret-area protocol. Both sides share them: the kernel
|
|
@@ -716,7 +716,7 @@
|
|
|
716
716
|
});
|
|
717
717
|
/** A BIP-39 passphrase on the wire: raw UTF-8 bytes, never empty (the host omits "none"). */
|
|
718
718
|
var passphraseBytes = bytes(1, 1024);
|
|
719
|
-
var walletErrorCode = union(literal("locked"), literal("cancelled"), literal("factor-
|
|
719
|
+
var walletErrorCode = union(literal("locked"), literal("cancelled"), literal("factor-invalidated"), literal("no-device-credential"), literal("passkey-not-configured"), literal("passkey-prf-unsupported"), literal("wrong-password"), literal("wrong-passkey"), literal("rate-limited"), literal("invalid-input"), literal("not-found"), literal("already-exists"), literal("conflict"), literal("unsupported"), literal("unavailable"), literal("integrity"), literal("approval-required"), literal("crashed"));
|
|
720
720
|
var createdResult = obj({
|
|
721
721
|
wallet: walletInfo$1,
|
|
722
722
|
session: sessionId
|
|
@@ -901,7 +901,7 @@
|
|
|
901
901
|
var init_objectSpread2 = __esmMin((() => {
|
|
902
902
|
init_defineProperty();
|
|
903
903
|
}));
|
|
904
|
-
// packages/wallet/dist/protocol-
|
|
904
|
+
// packages/wallet/dist/protocol-DqBfdhN5.mjs
|
|
905
905
|
init_objectSpread2();
|
|
906
906
|
/**
|
|
907
907
|
* Backup-envelope wire validators (design/backup.mdx): the strict structural shape the kernel and
|
|
@@ -1661,7 +1661,8 @@
|
|
|
1661
1661
|
var lockReason = union(literal("cold-start"), literal("user"), literal("idle"), literal("background"), literal("expired"), literal("crashed"), literal("invalidated"));
|
|
1662
1662
|
obj({
|
|
1663
1663
|
code: walletErrorCode,
|
|
1664
|
-
retryAt: opt(safeTime)
|
|
1664
|
+
retryAt: opt(safeTime),
|
|
1665
|
+
detail: opt(str(80, /^[A-Za-z0-9_.:-]+$/))
|
|
1665
1666
|
});
|
|
1666
1667
|
obj({
|
|
1667
1668
|
v: literal(2),
|
|
@@ -3615,7 +3616,7 @@
|
|
|
3615
3616
|
* input or secret contents.
|
|
3616
3617
|
*/
|
|
3617
3618
|
var KernelError = class extends Error {
|
|
3618
|
-
constructor(code, message, retryAt, corrupted = false) {
|
|
3619
|
+
constructor(code, message, retryAt, corrupted = false, detail) {
|
|
3619
3620
|
super(message);
|
|
3620
3621
|
_defineProperty(this, "code", void 0);
|
|
3621
3622
|
_defineProperty(this, "retryAt", void 0);
|
|
@@ -3628,17 +3629,24 @@
|
|
|
3628
3629
|
"corrupted",
|
|
3629
3630
|
void 0
|
|
3630
3631
|
);
|
|
3632
|
+
_defineProperty(
|
|
3633
|
+
this,
|
|
3634
|
+
/** Platform diagnostic `"<domain>:<code>"` a backend reported; forwarded to the host verbatim. */
|
|
3635
|
+
"detail",
|
|
3636
|
+
void 0
|
|
3637
|
+
);
|
|
3631
3638
|
this.name = "KernelError";
|
|
3632
3639
|
this.code = code;
|
|
3633
3640
|
this.retryAt = retryAt;
|
|
3634
3641
|
this.corrupted = corrupted;
|
|
3642
|
+
this.detail = detail;
|
|
3635
3643
|
}
|
|
3636
3644
|
};
|
|
3637
3645
|
// packages/wallet-kernel/src/platform.ts
|
|
3638
3646
|
init_objectSpread2();
|
|
3639
|
-
/** The platform authenticator, or `
|
|
3647
|
+
/** The platform authenticator, or `unsupported` where the host runs ceremonies. */
|
|
3640
3648
|
function requirePasskey(platform) {
|
|
3641
|
-
if (platform.passkey === void 0) throw new KernelError("
|
|
3649
|
+
if (platform.passkey === void 0) throw new KernelError("unsupported", "this platform runs passkey ceremonies in the host");
|
|
3642
3650
|
return platform.passkey;
|
|
3643
3651
|
}
|
|
3644
3652
|
/**
|
|
@@ -3683,11 +3691,11 @@
|
|
|
3683
3691
|
* factors are exempt.
|
|
3684
3692
|
*/
|
|
3685
3693
|
function assertFactorKindAvailable(platform, kind) {
|
|
3686
|
-
if (platform.keystore !== void 0 !== (kind === "hardware")) throw new KernelError("
|
|
3694
|
+
if (platform.keystore !== void 0 !== (kind === "hardware")) throw new KernelError("unsupported", "this factor kind is not available here");
|
|
3687
3695
|
}
|
|
3688
|
-
/** The platform keystore, or `
|
|
3696
|
+
/** The platform keystore, or `unsupported` on hosts without secure hardware. */
|
|
3689
3697
|
function requireKeystore(platform) {
|
|
3690
|
-
if (platform.keystore === void 0) throw new KernelError("
|
|
3698
|
+
if (platform.keystore === void 0) throw new KernelError("unsupported", "this platform has no hardware keystore");
|
|
3691
3699
|
return platform.keystore;
|
|
3692
3700
|
}
|
|
3693
3701
|
// packages/wallet-kernel/src/prompts.ts
|
|
@@ -7969,7 +7977,7 @@
|
|
|
7969
7977
|
let dek;
|
|
7970
7978
|
if (factor.kind === "hardware") {
|
|
7971
7979
|
const stored = image.factors.find((f) => f.kind === "hardware");
|
|
7972
|
-
if (stored === void 0) throw new KernelError("
|
|
7980
|
+
if (stored === void 0) throw new KernelError("not-found", "no hardware factor exists");
|
|
7973
7981
|
const kek = await kekFor(platform, factor, stored, corePromptFor(platform.keystore, "unlock"));
|
|
7974
7982
|
try {
|
|
7975
7983
|
dek = unwrapDek(kek, stored);
|
|
@@ -8031,9 +8039,9 @@
|
|
|
8031
8039
|
* compare. A public-key miss — `wrong-password`/`wrong-passkey` — tries the next candidate; every
|
|
8032
8040
|
* other failure (including corruption-marked integrity) propagates immediately. When no candidate
|
|
8033
8041
|
* matched, the miss is reported by factor kind: `wrong-password` (or `invalid-input` when no
|
|
8034
|
-
* password factor exists), `wrong-passkey`, or for hardware `
|
|
8035
|
-
*
|
|
8036
|
-
*
|
|
8042
|
+
* password factor exists), `wrong-passkey`, or for hardware `not-found` (no hardware factor) /
|
|
8043
|
+
* `integrity` (the keystore opened a KEK for another DEK). `prompt` renders the system verification
|
|
8044
|
+
* text and runs only for hardware. The verify path never touches the rate limiter.
|
|
8037
8045
|
*/
|
|
8038
8046
|
async function verifyFactor(platform, image, factor, dek, prompt) {
|
|
8039
8047
|
assertFactorKindAvailable(platform, factor.kind);
|
|
@@ -8057,7 +8065,7 @@
|
|
|
8057
8065
|
}
|
|
8058
8066
|
}
|
|
8059
8067
|
if (factor.kind === "password") throw new KernelError(candidates.length > 0 ? "wrong-password" : "invalid-input", "password did not verify");
|
|
8060
|
-
if (factor.kind === "hardware") throw candidates.length > 0 ? new KernelError("integrity", "hardware factor does not open this vault", void 0, true) : new KernelError("
|
|
8068
|
+
if (factor.kind === "hardware") throw candidates.length > 0 ? new KernelError("integrity", "hardware factor does not open this vault", void 0, true) : new KernelError("not-found", "no hardware factor exists");
|
|
8061
8069
|
throw new KernelError("wrong-passkey", "passkey did not verify");
|
|
8062
8070
|
}
|
|
8063
8071
|
/**
|
|
@@ -12903,15 +12911,15 @@ zoo`.split("\n"));
|
|
|
12903
12911
|
var PURPOSE_WALLET = 1;
|
|
12904
12912
|
/**
|
|
12905
12913
|
* One platform ceremony's wallet PRF: the result must be user-verified and carry a 32-byte `first`
|
|
12906
|
-
* output; anything else is an authenticator without usable PRF support (`
|
|
12907
|
-
* unused `second` output is wiped.
|
|
12914
|
+
* output; anything else is an authenticator without usable PRF support (`passkey-prf-unsupported`).
|
|
12915
|
+
* The unused `second` output is wiped.
|
|
12908
12916
|
*/
|
|
12909
12917
|
function walletPrfOf(result) {
|
|
12910
12918
|
var _result$first;
|
|
12911
12919
|
if (result.second !== void 0) wipe(result.second);
|
|
12912
12920
|
if (!result.userVerified || ((_result$first = result.first) === null || _result$first === void 0 ? void 0 : _result$first.length) !== 32) {
|
|
12913
12921
|
if (result.first !== void 0) wipe(result.first);
|
|
12914
|
-
throw new KernelError("
|
|
12922
|
+
throw new KernelError("passkey-prf-unsupported", "the passkey returned no verified PRF output");
|
|
12915
12923
|
}
|
|
12916
12924
|
return {
|
|
12917
12925
|
prfWallet: result.first,
|
|
@@ -12958,10 +12966,10 @@ zoo`.split("\n"));
|
|
|
12958
12966
|
/**
|
|
12959
12967
|
* Creates or restores a passkey wallet. The ceremony runs where the platform puts it: in the kernel
|
|
12960
12968
|
* when a platform authenticator exists, in the host (evidence on the wire) otherwise — the other
|
|
12961
|
-
* shape is `
|
|
12969
|
+
* shape is `unsupported`.
|
|
12962
12970
|
*/
|
|
12963
12971
|
async function createWithPasskey(ctx, params, requestSession) {
|
|
12964
|
-
if (ctx.platform.passkey !== void 0 !== (params.ceremony === "kernel")) throw new KernelError("
|
|
12972
|
+
if (ctx.platform.passkey !== void 0 !== (params.ceremony === "kernel")) throw new KernelError("unsupported", "this platform runs passkey ceremonies elsewhere");
|
|
12965
12973
|
const gated = gate(ctx, params.factor, requestSession);
|
|
12966
12974
|
let prf;
|
|
12967
12975
|
try {
|
|
@@ -13127,7 +13135,7 @@ zoo`.split("\n"));
|
|
|
13127
13135
|
var PURPOSE_PROTECTION = 2;
|
|
13128
13136
|
/**
|
|
13129
13137
|
* The backup PRF from one platform ceremony: user-verified with a 32-byte `first` output, else
|
|
13130
|
-
* `
|
|
13138
|
+
* `passkey-prf-unsupported`. The unused `second` output is wiped.
|
|
13131
13139
|
*/
|
|
13132
13140
|
function backupMaterialOf(result) {
|
|
13133
13141
|
var _result$second, _result$first;
|
|
@@ -13135,7 +13143,7 @@ zoo`.split("\n"));
|
|
|
13135
13143
|
if (!result.userVerified || ((_result$first = result.first) === null || _result$first === void 0 ? void 0 : _result$first.length) !== 32) {
|
|
13136
13144
|
var _result$first2;
|
|
13137
13145
|
(_result$first2 = result.first) === null || _result$first2 === void 0 || _result$first2.fill(0);
|
|
13138
|
-
throw new KernelError("
|
|
13146
|
+
throw new KernelError("passkey-prf-unsupported", "the passkey returned no verified PRF output");
|
|
13139
13147
|
}
|
|
13140
13148
|
return {
|
|
13141
13149
|
kind: "passkey",
|
|
@@ -13151,7 +13159,7 @@ zoo`.split("\n"));
|
|
|
13151
13159
|
*/
|
|
13152
13160
|
async function backupMaterial(ctx, factor, allowCredentials) {
|
|
13153
13161
|
if (factor.kind === "password") return factor;
|
|
13154
|
-
if (ctx.platform.passkey !== void 0 !== (factor.ceremony === "kernel")) throw new KernelError("
|
|
13162
|
+
if (ctx.platform.passkey !== void 0 !== (factor.ceremony === "kernel")) throw new KernelError("unsupported", "this platform runs passkey ceremonies elsewhere");
|
|
13155
13163
|
if (factor.ceremony === "host") return factor;
|
|
13156
13164
|
const passkey = requirePasskey(ctx.platform);
|
|
13157
13165
|
const salts = { first: utf8ToBytes$1(factor.backupSalt) };
|
|
@@ -41309,10 +41317,7 @@ zoo`.split("\n"));
|
|
|
41309
41317
|
integrityFailure = true;
|
|
41310
41318
|
setHealth("corrupted");
|
|
41311
41319
|
}
|
|
41312
|
-
const err = error instanceof KernelError ? error.retryAt === void 0 ? {
|
|
41313
|
-
code: error.code,
|
|
41314
|
-
retryAt: error.retryAt
|
|
41315
|
-
} : { code: "integrity" };
|
|
41320
|
+
const err = error instanceof KernelError ? _objectSpread2(_objectSpread2({ code: error.code }, error.retryAt === void 0 ? {} : { retryAt: error.retryAt }), error.detail === void 0 ? {} : { detail: error.detail }) : { code: "integrity" };
|
|
41316
41321
|
return {
|
|
41317
41322
|
v: 2,
|
|
41318
41323
|
id,
|
|
@@ -41338,21 +41343,32 @@ zoo`.split("\n"));
|
|
|
41338
41343
|
});
|
|
41339
41344
|
enqueue(reloadAndPost);
|
|
41340
41345
|
}
|
|
41346
|
+
// packages/wallet-native/kernel/detail.ts
|
|
41347
|
+
/**
|
|
41348
|
+
* A `"<domain>:<code>"` diagnostic a platform reports alongside a failure code (e.g.
|
|
41349
|
+
* `"LAErrorDomain:-5"`, `"android:KeyPermanentlyInvalidatedException"`): kept only when it is a
|
|
41350
|
+
* short token string — anything else (oversize, free text) is dropped at this producer boundary,
|
|
41351
|
+
* never rejected. Never carries userInfo, localized text or input.
|
|
41352
|
+
*/
|
|
41353
|
+
function detailOf(detail) {
|
|
41354
|
+
return detail !== void 0 && detail.length <= 80 && /^[A-Za-z0-9_.:-]+$/.test(detail) ? detail : void 0;
|
|
41355
|
+
}
|
|
41341
41356
|
// packages/wallet-native/kernel/keystore.ts
|
|
41342
41357
|
/**
|
|
41343
41358
|
* Binds the native `__qntx.keystore` object to the kernel's `Keystore` contract. The C++ side
|
|
41344
|
-
* completes each call with `(bytes, code)`; a failure code is already the kernel error code
|
|
41345
|
-
* (`cancelled`, `factor-invalidated`, `
|
|
41359
|
+
* completes each call with `(bytes, code, detail)`; a failure code is already the kernel error code
|
|
41360
|
+
* (`cancelled`, `factor-invalidated`, `no-device-credential`, `unavailable`) and becomes a
|
|
41346
41361
|
* `KernelError` so the vault reports it verbatim instead of as an integrity failure.
|
|
41347
41362
|
*/
|
|
41348
|
-
function failure$1(code) {
|
|
41349
|
-
|
|
41363
|
+
function failure$1(code, detail) {
|
|
41364
|
+
const diagnostic = detailOf(detail);
|
|
41365
|
+
return code === "cancelled" || code === "factor-invalidated" || code === "no-device-credential" || code === "unavailable" ? new KernelError(code, "the platform keystore did not complete", void 0, false, diagnostic) : new KernelError("unavailable", "the platform keystore reported no outcome", void 0, false, diagnostic);
|
|
41350
41366
|
}
|
|
41351
41367
|
async function bytesOf$1(start) {
|
|
41352
41368
|
return new Promise((resolve, reject) => {
|
|
41353
|
-
start((result, code) => {
|
|
41369
|
+
start((result, code, detail) => {
|
|
41354
41370
|
if (result === void 0) {
|
|
41355
|
-
reject(failure$1(code));
|
|
41371
|
+
reject(failure$1(code, detail));
|
|
41356
41372
|
return;
|
|
41357
41373
|
}
|
|
41358
41374
|
resolve(result);
|
|
@@ -41361,9 +41377,9 @@ zoo`.split("\n"));
|
|
|
41361
41377
|
}
|
|
41362
41378
|
async function outcomeOf(start) {
|
|
41363
41379
|
return new Promise((resolve, reject) => {
|
|
41364
|
-
start((_result, code) => {
|
|
41380
|
+
start((_result, code, detail) => {
|
|
41365
41381
|
if (code !== void 0) {
|
|
41366
|
-
reject(failure$1(code));
|
|
41382
|
+
reject(failure$1(code, detail));
|
|
41367
41383
|
return;
|
|
41368
41384
|
}
|
|
41369
41385
|
resolve();
|
|
@@ -43756,8 +43772,9 @@ zoo`.split("\n"));
|
|
|
43756
43772
|
};
|
|
43757
43773
|
/** Whether bit `flag` (a power of two) is set in the authenticator-data flags byte. */
|
|
43758
43774
|
var hasFlag = (flags, flag) => Math.floor(flags / flag) % 2 === 1;
|
|
43759
|
-
function failure(code) {
|
|
43760
|
-
|
|
43775
|
+
function failure(code, detail) {
|
|
43776
|
+
const diagnostic = detailOf(detail);
|
|
43777
|
+
return code === "cancelled" || code === "passkey-not-configured" || code === "unsupported" || code === "unavailable" ? new KernelError(code, "the platform passkey ceremony did not complete", void 0, false, diagnostic) : new KernelError("unavailable", "the platform passkey ceremony reported no outcome", void 0, false, diagnostic);
|
|
43761
43778
|
}
|
|
43762
43779
|
var malformed = () => new KernelError("unavailable", "the platform returned a malformed passkey response");
|
|
43763
43780
|
var b64 = (bytes) => base64urlnopad.encode(bytes);
|
|
@@ -43829,7 +43846,7 @@ zoo`.split("\n"));
|
|
|
43829
43846
|
if (!assertion && enabled === false) {
|
|
43830
43847
|
first === null || first === void 0 || first.fill(0);
|
|
43831
43848
|
second === null || second === void 0 || second.fill(0);
|
|
43832
|
-
throw new KernelError("
|
|
43849
|
+
throw new KernelError("passkey-prf-unsupported", "the passkey does not support the PRF extension");
|
|
43833
43850
|
}
|
|
43834
43851
|
const rawAuthData = response["authenticatorData"];
|
|
43835
43852
|
let authData;
|
|
@@ -43862,9 +43879,9 @@ zoo`.split("\n"));
|
|
|
43862
43879
|
}
|
|
43863
43880
|
async function run(start, request, assertion) {
|
|
43864
43881
|
return parseResponse(await new Promise((resolve, reject) => {
|
|
43865
|
-
start(JSON.stringify(request), (responseJson, code) => {
|
|
43882
|
+
start(JSON.stringify(request), (responseJson, code, detail) => {
|
|
43866
43883
|
if (responseJson === void 0) {
|
|
43867
|
-
reject(failure(code));
|
|
43884
|
+
reject(failure(code, detail));
|
|
43868
43885
|
return;
|
|
43869
43886
|
}
|
|
43870
43887
|
resolve(responseJson);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qntx/wallet-native",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "Native kernel runtime host for the qntx wallet — CBOR transport, KernelHost adapter and createNativeWallet",
|
|
5
5
|
"license": "MIT OR Apache-2.0",
|
|
6
6
|
"author": "QuantX <x@qntx.org>",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"peerDependencies": {
|
|
62
62
|
"@qntx/nostr-native": "0.15.3",
|
|
63
63
|
"@qntx/spark-native": "0.5.2",
|
|
64
|
-
"@qntx/wallet": "0.
|
|
64
|
+
"@qntx/wallet": "0.11.0",
|
|
65
65
|
"react-native": "~0.88.0",
|
|
66
66
|
"react-native-nitro-modules": "~0.37.1"
|
|
67
67
|
}
|