@qntx/wallet-native 0.13.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.
- package/README.md +184 -31
- package/WalletNative.podspec +11 -2
- package/android/CMakeLists.txt +7 -1
- package/android/build.gradle +4 -0
- package/android/src/main/AndroidManifest.xml +1 -2
- package/android/src/main/cpp/cpp-adapter.cpp +9 -0
- package/android/src/main/java/com/margelo/nitro/qntxwallet/CardReader.kt +316 -0
- package/android/src/main/java/com/margelo/nitro/qntxwallet/HybridGoogleDriveAuth.kt +142 -0
- package/android/src/main/java/com/margelo/nitro/qntxwallet/HybridSecureInputView.kt +25 -0
- package/android/src/main/java/com/margelo/nitro/qntxwallet/Keystore.kt +148 -9
- package/android/src/main/java/com/margelo/nitro/qntxwallet/SecureInputField.kt +422 -0
- package/android/src/main/java/com/margelo/nitro/qntxwallet/VaultAnchor.kt +90 -0
- package/android/src/main/java/com/margelo/nitro/qntxwallet/WalletNativePackage.java +10 -0
- package/cpp/host/CardReader.hpp +70 -0
- package/cpp/host/HybridKernelHost.cpp +90 -15
- package/cpp/host/HybridKernelHost.hpp +21 -5
- package/cpp/host/KernelFile.cpp +79 -15
- package/cpp/host/KernelFile.hpp +17 -6
- package/cpp/host/KernelSlot.hpp +103 -0
- package/cpp/host/Keystore.hpp +35 -11
- package/cpp/host/Lifecycle.cpp +11 -0
- package/cpp/host/Lifecycle.hpp +3 -0
- package/cpp/host/Passkey.hpp +8 -0
- package/cpp/host/SecureInput.cpp +233 -0
- package/cpp/host/SecureInput.hpp +103 -0
- package/cpp/host/VaultAnchor.cpp +39 -0
- package/cpp/host/VaultAnchor.hpp +28 -0
- package/cpp/host/VaultDirectory.hpp +1 -1
- package/cpp/platform/CardReaderAndroid.cpp +146 -0
- package/cpp/platform/CardReaderIos.mm +318 -0
- package/cpp/platform/KeystoreAndroid.cpp +48 -1
- package/cpp/platform/KeystoreIos.mm +109 -19
- package/cpp/platform/PasskeyAndroid.cpp +2 -0
- package/cpp/platform/PasskeyIos.mm +20 -18
- package/cpp/platform/QntxSecureInputField.h +24 -0
- package/cpp/platform/SecureInputAndroid.cpp +110 -0
- package/cpp/platform/SecureInputIos.mm +282 -0
- package/cpp/platform/VaultAnchorAndroid.cpp +76 -0
- package/cpp/platform/VaultAnchorIos.mm +76 -0
- package/cpp/runtime/KernelBackends.cpp +35 -28
- package/cpp/runtime/KernelBuffer.hpp +2 -5
- package/cpp/runtime/KernelCardReader.cpp +385 -0
- package/cpp/runtime/KernelCardReader.hpp +27 -0
- package/cpp/runtime/KernelGlobals.cpp +176 -63
- package/cpp/runtime/KernelGlobals.hpp +13 -7
- package/cpp/runtime/KernelJs.cpp +14 -0
- package/cpp/runtime/KernelJs.hpp +4 -0
- package/cpp/runtime/KernelKeystore.cpp +78 -2
- package/cpp/runtime/KernelKeystore.hpp +1 -0
- package/cpp/runtime/KernelPasskey.cpp +15 -12
- package/cpp/runtime/KernelRuntime.cpp +24 -7
- package/cpp/runtime/KernelRuntime.hpp +14 -6
- package/cpp/runtime/KernelSecureInput.cpp +154 -0
- package/cpp/runtime/KernelSecureInput.hpp +25 -0
- package/cpp/runtime/platform/KernelArgon2.cpp +34 -0
- package/cpp/runtime/platform/KernelArgon2.hpp +23 -0
- package/cpp/vendor/argon2/LICENSE +314 -0
- package/cpp/vendor/argon2/README.md +20 -0
- package/cpp/vendor/argon2/include/argon2.h +437 -0
- package/cpp/vendor/argon2/src/argon2.c +452 -0
- package/cpp/vendor/argon2/src/blake2/blake2-impl.h +156 -0
- package/cpp/vendor/argon2/src/blake2/blake2.h +89 -0
- package/cpp/vendor/argon2/src/blake2/blake2b.c +390 -0
- package/cpp/vendor/argon2/src/blake2/blamka-round-ref.h +56 -0
- package/cpp/vendor/argon2/src/core.c +648 -0
- package/cpp/vendor/argon2/src/core.h +228 -0
- package/cpp/vendor/argon2/src/encoding.c +463 -0
- package/cpp/vendor/argon2/src/encoding.h +57 -0
- package/cpp/vendor/argon2/src/ref.c +194 -0
- package/cpp/vendor/argon2/src/thread.c +57 -0
- package/cpp/vendor/argon2/src/thread.h +67 -0
- package/dist/cloud.d.mts +58 -0
- package/dist/cloud.mjs +114 -0
- package/dist/cloud.mjs.map +1 -0
- package/dist/index.d.mts +13 -4
- package/dist/index.mjs +89 -14
- package/dist/index.mjs.map +1 -1
- package/dist/secure-input.d.mts +24 -0
- package/dist/secure-input.mjs +25 -0
- package/dist/secure-input.mjs.map +1 -0
- package/ios/HybridCloudKitStore.swift +159 -0
- package/ios/HybridSecureInputView.swift +35 -0
- package/ios/cloud/CloudKitEnvelopeStore.swift +179 -0
- package/kernel/generated/kernel-entry.js +42170 -12741
- package/kernel/generated/kernel.manifest.json +17 -7
- package/nitrogen/generated/android/WalletNative+autolinking.cmake +7 -1
- package/nitrogen/generated/android/WalletNativeOnLoad.cpp +37 -2
- package/nitrogen/generated/android/c++/JFunc_void_SecureInputState.hpp +77 -0
- package/nitrogen/generated/android/c++/JHybridGoogleDriveAuthSpec.cpp +82 -0
- package/nitrogen/generated/android/c++/JHybridGoogleDriveAuthSpec.hpp +64 -0
- package/nitrogen/generated/android/c++/JHybridSecureInputViewSpec.cpp +70 -0
- package/nitrogen/generated/android/c++/JHybridSecureInputViewSpec.hpp +64 -0
- package/nitrogen/generated/android/c++/JSecureInputState.hpp +64 -0
- package/nitrogen/generated/android/c++/views/JHybridSecureInputViewStateUpdater.cpp +74 -0
- package/nitrogen/generated/android/c++/views/JHybridSecureInputViewStateUpdater.hpp +54 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/qntxwallet/Func_void_SecureInputState.kt +78 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/qntxwallet/HybridGoogleDriveAuthSpec.kt +61 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/qntxwallet/HybridSecureInputViewSpec.kt +67 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/qntxwallet/SecureInputState.kt +25 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/qntxwallet/views/HybridSecureInputViewManager.kt +96 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/qntxwallet/views/HybridSecureInputViewStateUpdater.kt +23 -0
- package/nitrogen/generated/ios/WalletNative-Swift-Cxx-Bridge.cpp +74 -1
- package/nitrogen/generated/ios/WalletNative-Swift-Cxx-Bridge.hpp +252 -3
- package/nitrogen/generated/ios/WalletNative-Swift-Cxx-Umbrella.hpp +21 -3
- package/nitrogen/generated/ios/WalletNativeAutolinking.mm +17 -1
- package/nitrogen/generated/ios/WalletNativeAutolinking.swift +22 -0
- package/nitrogen/generated/ios/c++/HybridCloudKitStoreSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridCloudKitStoreSpecSwift.hpp +116 -0
- package/nitrogen/generated/ios/c++/HybridSecureInputViewSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridSecureInputViewSpecSwift.hpp +83 -0
- package/nitrogen/generated/ios/c++/views/HybridSecureInputViewComponent.mm +144 -0
- package/nitrogen/generated/ios/swift/Func_void.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_SecureInputState.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_std__optional_std__string_.swift +53 -0
- package/nitrogen/generated/ios/swift/Func_void_std__vector_std__string_.swift +46 -0
- package/nitrogen/generated/ios/swift/HybridCloudKitStoreSpec.swift +59 -0
- package/nitrogen/generated/ios/swift/HybridCloudKitStoreSpec_cxx.swift +230 -0
- package/nitrogen/generated/ios/swift/HybridSecureInputViewSpec.swift +55 -0
- package/nitrogen/generated/ios/swift/HybridSecureInputViewSpec_cxx.swift +164 -0
- package/nitrogen/generated/ios/swift/SecureInputState.swift +48 -0
- package/nitrogen/generated/shared/c++/HybridCloudKitStoreSpec.cpp +25 -0
- package/nitrogen/generated/shared/c++/HybridCloudKitStoreSpec.hpp +70 -0
- package/nitrogen/generated/shared/c++/HybridGoogleDriveAuthSpec.cpp +22 -0
- package/nitrogen/generated/shared/c++/HybridGoogleDriveAuthSpec.hpp +64 -0
- package/nitrogen/generated/shared/c++/HybridKernelHostSpec.cpp +1 -0
- package/nitrogen/generated/shared/c++/HybridKernelHostSpec.hpp +1 -0
- package/nitrogen/generated/shared/c++/HybridSecureInputViewSpec.cpp +22 -0
- package/nitrogen/generated/shared/c++/HybridSecureInputViewSpec.hpp +65 -0
- package/nitrogen/generated/shared/c++/SecureInputState.hpp +84 -0
- package/nitrogen/generated/shared/c++/views/HybridSecureInputViewComponent.cpp +34 -0
- package/nitrogen/generated/shared/c++/views/HybridSecureInputViewComponent.hpp +85 -0
- package/nitrogen/generated/shared/json/SecureInputViewConfig.json +10 -0
- package/package.json +24 -6
- package/scripts/compile-kernel.mjs +7 -3
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { WalletError } from "@qntx/wallet";
|
|
2
2
|
import { connectKernel } from "@qntx/wallet/host";
|
|
3
|
-
import { decode,
|
|
3
|
+
import { decode, encodeInto } from "cborg";
|
|
4
|
+
import { encodedLength } from "cborg/length";
|
|
4
5
|
// src/cbor.ts
|
|
5
6
|
/**
|
|
6
7
|
* CBOR framing for the kernel channel. `ProtocolValue` travels main-side ↔ kernel-side as CBOR; the
|
|
@@ -27,9 +28,31 @@ const DECODE_OPTIONS = {
|
|
|
27
28
|
allowInfinity: false,
|
|
28
29
|
allowBigInt: false
|
|
29
30
|
};
|
|
30
|
-
/**
|
|
31
|
+
/**
|
|
32
|
+
* A string UTF-8 can carry unchanged: iterating by code point pairs every valid surrogate, so a
|
|
33
|
+
* surrogate code point on its own is a lone one.
|
|
34
|
+
*/
|
|
35
|
+
function wellFormed(text) {
|
|
36
|
+
for (const char of text) {
|
|
37
|
+
const point = char.codePointAt(0) ?? 0;
|
|
38
|
+
if (point >= 55296 && point <= 57343) return false;
|
|
39
|
+
}
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
function checkString(text) {
|
|
43
|
+
if (!wellFormed(text)) throw new CborError("lone-surrogate", "cbor frame: string with a lone UTF-16 surrogate");
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Reject non-safe-integer numbers, non-string map keys and strings UTF-8 cannot represent (a lone
|
|
47
|
+
* surrogate would be replaced with U+FFFD, silently changing the value); cborg flags cover the
|
|
48
|
+
* rest.
|
|
49
|
+
*/
|
|
31
50
|
function validate(value) {
|
|
32
|
-
if (value === null || typeof value === "boolean"
|
|
51
|
+
if (value === null || typeof value === "boolean") return;
|
|
52
|
+
if (typeof value === "string") {
|
|
53
|
+
checkString(value);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
33
56
|
if (typeof value === "number") {
|
|
34
57
|
if (!Number.isInteger(value)) throw new CborError("float", "cbor frame: non-integer number");
|
|
35
58
|
if (!Number.isSafeInteger(value)) throw new CborError("unsafe-int", "cbor frame: integer outside the safe range");
|
|
@@ -43,6 +66,7 @@ function validate(value) {
|
|
|
43
66
|
if (typeof value === "object") {
|
|
44
67
|
for (const [key, item] of Object.entries(value)) {
|
|
45
68
|
if (typeof key !== "string") throw new CborError("non-string-key", "cbor frame: non-string map key");
|
|
69
|
+
checkString(key);
|
|
46
70
|
validate(item);
|
|
47
71
|
}
|
|
48
72
|
return;
|
|
@@ -63,12 +87,30 @@ function classify(error) {
|
|
|
63
87
|
]) if (pattern.test(text)) return new CborError(code, `cbor frame: ${text}`);
|
|
64
88
|
return new CborError("malformed", `cbor frame: ${text}`);
|
|
65
89
|
}
|
|
66
|
-
/**
|
|
90
|
+
/**
|
|
91
|
+
* Encode a `ProtocolValue` to a CBOR frame, enforcing the 1 MiB cap. `encodeInto` writes straight
|
|
92
|
+
* into an exact-size buffer the caller owns: `encode` reuses a module-level writer whose first
|
|
93
|
+
* chunk survives across calls, which would keep the last frame's bytes resident in cborg state.
|
|
94
|
+
*/
|
|
67
95
|
function encodeFrame(value) {
|
|
68
96
|
validate(value);
|
|
69
|
-
const bytes =
|
|
70
|
-
|
|
71
|
-
|
|
97
|
+
const bytes = new Uint8Array(encodedLength(value));
|
|
98
|
+
let written;
|
|
99
|
+
try {
|
|
100
|
+
({written} = encodeInto(value, bytes));
|
|
101
|
+
} catch (error) {
|
|
102
|
+
bytes.fill(0);
|
|
103
|
+
throw error;
|
|
104
|
+
}
|
|
105
|
+
if (written > 1048576) {
|
|
106
|
+
bytes.fill(0);
|
|
107
|
+
throw new CborError("oversize", `cbor frame: ${written} bytes exceeds the 1 MiB cap`);
|
|
108
|
+
}
|
|
109
|
+
if (written !== bytes.byteLength) {
|
|
110
|
+
bytes.fill(0);
|
|
111
|
+
throw new CborError("malformed", "cbor frame: encoded length mismatch");
|
|
112
|
+
}
|
|
113
|
+
return bytes.buffer;
|
|
72
114
|
}
|
|
73
115
|
/** Decode a CBOR frame back to a `ProtocolValue`, enforcing the 1 MiB cap and strictness. */
|
|
74
116
|
function decodeFrame(frame) {
|
|
@@ -84,6 +126,11 @@ function decodeFrame(frame) {
|
|
|
84
126
|
}
|
|
85
127
|
}
|
|
86
128
|
// src/host.ts
|
|
129
|
+
/**
|
|
130
|
+
* `KernelHost` JS wrapper: CBOR frames over a Nitro-host-shaped channel. The host moves bytes only
|
|
131
|
+
* — encode/decode happens here and in the kernel entry — so a malformed inbound frame can never
|
|
132
|
+
* reach the message domain: the port exits `crashed` and the host runtime is destroyed.
|
|
133
|
+
*/
|
|
87
134
|
function spawnFromHost(host, backgroundLockSeconds) {
|
|
88
135
|
const exitHandlers = /* @__PURE__ */ new Set();
|
|
89
136
|
let exited = false;
|
|
@@ -100,6 +147,8 @@ function spawnFromHost(host, backgroundLockSeconds) {
|
|
|
100
147
|
} catch {
|
|
101
148
|
exit("crashed");
|
|
102
149
|
return;
|
|
150
|
+
} finally {
|
|
151
|
+
new Uint8Array(frame).fill(0);
|
|
103
152
|
}
|
|
104
153
|
dispatch(message);
|
|
105
154
|
});
|
|
@@ -113,9 +162,17 @@ function spawnFromHost(host, backgroundLockSeconds) {
|
|
|
113
162
|
host.start(backgroundLockSeconds);
|
|
114
163
|
return {
|
|
115
164
|
post: (message, transfer) => {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
165
|
+
let frame;
|
|
166
|
+
try {
|
|
167
|
+
frame = encodeFrame(message);
|
|
168
|
+
host.post(frame);
|
|
169
|
+
} catch (error) {
|
|
170
|
+
if (error instanceof CborError) throw new WalletError("invalid-input", `request cannot be encoded: ${error.message}`);
|
|
171
|
+
throw error;
|
|
172
|
+
} finally {
|
|
173
|
+
if (frame !== void 0) new Uint8Array(frame).fill(0);
|
|
174
|
+
for (const buffer of transfer) new Uint8Array(buffer).fill(0);
|
|
175
|
+
}
|
|
119
176
|
},
|
|
120
177
|
listen: (handler) => {
|
|
121
178
|
messageHandlers.add(handler);
|
|
@@ -137,8 +194,9 @@ function spawnFromHost(host, backgroundLockSeconds) {
|
|
|
137
194
|
// src/index.ts
|
|
138
195
|
/**
|
|
139
196
|
* `@qntx/wallet-native`: the RN host entry. `createNativeWallet` adapts a `KernelHost` (Nitro
|
|
140
|
-
* hybrid from W2b, or any object with the same shape) to the wallet `connectKernel` entry
|
|
141
|
-
*
|
|
197
|
+
* hybrid from W2b, or any object with the same shape) to the wallet `connectKernel` entry.
|
|
198
|
+
* `NativeWallet` adds `setAutoLock`: changing the background lock budget applies to the live kernel
|
|
199
|
+
* immediately and to every runtime spawned afterwards.
|
|
142
200
|
*/
|
|
143
201
|
const setTimer = (delayMs, fn) => {
|
|
144
202
|
const id = setTimeout(fn, delayMs);
|
|
@@ -150,18 +208,35 @@ async function defaultHostFactory() {
|
|
|
150
208
|
const { NitroModules } = await import("react-native-nitro-modules");
|
|
151
209
|
return () => NitroModules.createHybridObject("KernelHost");
|
|
152
210
|
}
|
|
211
|
+
const BACKGROUND_SECONDS = /* @__PURE__ */ new Set([
|
|
212
|
+
0,
|
|
213
|
+
60,
|
|
214
|
+
300,
|
|
215
|
+
900
|
|
216
|
+
]);
|
|
153
217
|
async function createNativeWallet(options) {
|
|
154
218
|
const { autoLock } = options;
|
|
155
219
|
if (autoLock.platform !== "native") throw new WalletError("invalid-input", "createNativeWallet accepts only the native autoLock policy");
|
|
156
220
|
const createHost = options.createHost ?? await defaultHostFactory();
|
|
157
|
-
|
|
158
|
-
|
|
221
|
+
let seconds = autoLock.backgroundSeconds;
|
|
222
|
+
let live;
|
|
223
|
+
const wallet = await connectKernel({
|
|
224
|
+
spawn: () => {
|
|
225
|
+
live = createHost();
|
|
226
|
+
return spawnFromHost(live, seconds);
|
|
227
|
+
},
|
|
159
228
|
factors: "hardware",
|
|
160
229
|
passkey: options.passkey,
|
|
161
230
|
verifyEvent: options.verifyEvent,
|
|
162
231
|
ceremony: void 0,
|
|
163
232
|
setTimer
|
|
164
233
|
});
|
|
234
|
+
const setAutoLock = (policy) => {
|
|
235
|
+
if (policy.platform !== "native" || !BACKGROUND_SECONDS.has(policy.backgroundSeconds)) throw new WalletError("invalid-input", "not a native auto-lock policy");
|
|
236
|
+
seconds = policy.backgroundSeconds;
|
|
237
|
+
live?.setBackgroundLock(policy.backgroundSeconds);
|
|
238
|
+
};
|
|
239
|
+
return Object.assign(wallet, { setAutoLock });
|
|
165
240
|
}
|
|
166
241
|
export { CborError, FRAME_MAX_BYTES, createNativeWallet, decodeFrame, encodeFrame, spawnFromHost };
|
|
167
242
|
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/cbor.ts","../src/host.ts","../src/index.ts"],"sourcesContent":["/**\n * CBOR framing for the kernel channel. `ProtocolValue` travels main-side ↔ kernel-side as CBOR; the\n * C++ layer moves bytes only. Decode is deliberately strict: floats, unsafe integers, undefined,\n * tags, non-string map keys, duplicate keys and indefinite-length items are all rejected — the wire\n * format carries exactly one value domain.\n */\nimport { decode, encode } from \"cborg\";\nimport type { DecodeOptions } from \"cborg\";\n\nimport type { ProtocolValue } from \"@qntx/wallet/protocol\";\n\nexport const FRAME_MAX_BYTES: number = 1024 * 1024;\n\nexport type CborErrorCode =\n | \"oversize\"\n | \"truncated\"\n | \"malformed\"\n | \"float\"\n | \"unsafe-int\"\n | \"bigint\"\n | \"undefined\"\n | \"tag\"\n | \"non-string-key\"\n | \"duplicate-key\"\n | \"indefinite\"\n | \"bad-type\";\n\nexport class CborError extends Error {\n readonly code: CborErrorCode;\n constructor(code: CborErrorCode, message: string) {\n super(message);\n this.name = \"CborError\";\n this.code = code;\n }\n}\n\nconst DECODE_OPTIONS: DecodeOptions = {\n strict: true,\n useMaps: false,\n rejectDuplicateMapKeys: true,\n allowUndefined: false,\n allowIndefinite: false,\n allowNaN: false,\n allowInfinity: false,\n allowBigInt: false,\n};\n\n/** Reject non-safe-integer numbers and non-string map keys; cborg flags cover the rest. */\nfunction validate(value: unknown): asserts value is ProtocolValue {\n if (value === null || typeof value === \"boolean\" || typeof value === \"string\") {\n return;\n }\n if (typeof value === \"number\") {\n if (!Number.isInteger(value)) {\n throw new CborError(\"float\", \"cbor frame: non-integer number\");\n }\n if (!Number.isSafeInteger(value)) {\n throw new CborError(\"unsafe-int\", \"cbor frame: integer outside the safe range\");\n }\n return;\n }\n if (value instanceof Uint8Array) {\n return;\n }\n if (Array.isArray(value)) {\n for (const item of value) {\n validate(item);\n }\n return;\n }\n if (typeof value === \"object\") {\n // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- the object came from a CBOR map\n for (const [key, item] of Object.entries(value as Record<string, unknown>)) {\n if (typeof key !== \"string\") {\n throw new CborError(\"non-string-key\", \"cbor frame: non-string map key\");\n }\n validate(item);\n }\n return;\n }\n throw new CborError(\"bad-type\", `cbor frame: unsupported value type ${typeof value}`);\n}\n\n/** Classify a cborg rejection into the frame error taxonomy. */\nfunction classify(error: unknown): CborError {\n if (error instanceof CborError) {\n return error;\n }\n const text = error instanceof Error ? error.message : String(error);\n const table: ReadonlyArray<[RegExp, CborErrorCode]> = [\n [/duplicate key|repeat map key/i, \"duplicate-key\"],\n [/indefinite/i, \"indefinite\"],\n [/undefined/i, \"undefined\"],\n [/bigint|safe integer range/i, \"unsafe-int\"],\n [/tag/i, \"tag\"],\n [/string/i, \"non-string-key\"],\n ];\n for (const [pattern, code] of table) {\n if (pattern.test(text)) {\n return new CborError(code, `cbor frame: ${text}`);\n }\n }\n return new CborError(\"malformed\", `cbor frame: ${text}`);\n}\n\n/** Encode a `ProtocolValue` to a CBOR frame, enforcing the 1 MiB cap. */\nexport function encodeFrame(value: ProtocolValue): ArrayBuffer {\n validate(value);\n const bytes = encode(value);\n if (bytes.byteLength > FRAME_MAX_BYTES) {\n throw new CborError(\"oversize\", `cbor frame: ${bytes.byteLength} bytes exceeds the 1 MiB cap`);\n }\n return bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength);\n}\n\n/** Decode a CBOR frame back to a `ProtocolValue`, enforcing the 1 MiB cap and strictness. */\nexport function decodeFrame(frame: ArrayBuffer | Uint8Array): ProtocolValue {\n const bytes = frame instanceof Uint8Array ? frame : new Uint8Array(frame);\n if (bytes.byteLength > FRAME_MAX_BYTES) {\n throw new CborError(\"oversize\", `cbor frame: ${bytes.byteLength} bytes exceeds the 1 MiB cap`);\n }\n if (bytes.byteLength === 0) {\n throw new CborError(\"truncated\", \"cbor frame: empty frame\");\n }\n try {\n const value: unknown = decode(bytes, DECODE_OPTIONS);\n validate(value);\n return value;\n } catch (error) {\n throw classify(error);\n }\n}\n","/**\n * `KernelHost` JS wrapper: CBOR frames over a Nitro-host-shaped channel. The host moves bytes only\n * — encode/decode happens here and in the kernel entry — so a malformed inbound frame can never\n * reach the message domain: the port exits `integrity` and the host runtime is destroyed.\n */\nimport type { MainPort, PortExit } from \"@qntx/wallet/host\";\nimport type { ProtocolValue } from \"@qntx/wallet/protocol\";\n\nimport { decodeFrame, encodeFrame } from \"./cbor.ts\";\n\nexport type KernelExitReason = \"locked\" | \"crashed\" | \"integrity\" | \"background\";\n\n/**\n * Structural mirror of the Nitro `KernelHost` spec (W2b registers the real hybrid object; tests\n * drive the same shape over an in-memory frame pipe).\n */\nexport type KernelHostLike = {\n readonly start: (backgroundLockSeconds: number) => void;\n readonly post: (frame: ArrayBuffer) => void;\n readonly onMessage: (cb: (frame: ArrayBuffer) => void) => void;\n readonly onExit: (cb: (reason: KernelExitReason) => void) => void;\n readonly lock: () => void;\n};\n\nexport function spawnFromHost(host: KernelHostLike, backgroundLockSeconds: number): MainPort {\n const exitHandlers = new Set<(reason: PortExit) => void>();\n let exited = false;\n\n const exit = (reason: PortExit): void => {\n if (exited) {\n return;\n }\n exited = true;\n for (const handler of exitHandlers) {\n handler(reason);\n }\n host.lock();\n };\n\n host.onMessage((frame) => {\n let message: ProtocolValue;\n try {\n message = decodeFrame(frame);\n } catch {\n exit(\"crashed\");\n return;\n }\n dispatch(message);\n });\n\n // The platform locked the enclave in the background — report it honestly so\n // the channel takes the lock path, not the crash path.\n host.onExit((reason) => {\n exit(reason === \"background\" ? \"background\" : \"crashed\");\n });\n\n const messageHandlers = new Set<(message: unknown) => void>();\n const dispatch = (message: unknown): void => {\n for (const handler of messageHandlers) {\n handler(message);\n }\n };\n\n host.start(backgroundLockSeconds);\n\n return {\n post: (message, transfer) => {\n const frame = encodeFrame(message);\n host.post(frame);\n // Structured clone would neuter transferred buffers on the web; the main↔kernel\n // contract is the same here — the caller's buffers hold secrets (passwords, PRF\n // output) and are zeroed once their bytes are inside the frame.\n for (const buffer of transfer) {\n new Uint8Array(buffer).fill(0);\n }\n },\n listen: (handler) => {\n messageHandlers.add(handler);\n return () => {\n messageHandlers.delete(handler);\n };\n },\n onExit: (handler) => {\n exitHandlers.add(handler);\n return () => {\n exitHandlers.delete(handler);\n };\n },\n terminate: () => {\n exit(\"crashed\");\n },\n };\n}\n","import { WalletError } from \"@qntx/wallet\";\nimport type { Wallet, WalletOptions } from \"@qntx/wallet\";\nimport type { SetTimer } from \"@qntx/wallet/host\";\n/**\n * `@qntx/wallet-native`: the RN host entry. `createNativeWallet` adapts a `KernelHost` (Nitro\n * hybrid from W2b, or any object with the same shape) to the wallet `connectKernel` entry — the\n * returned `Wallet` is the same type as the web/node host.\n */\nimport { connectKernel } from \"@qntx/wallet/host\";\n\nimport { spawnFromHost } from \"./host.ts\";\nimport type { KernelHostLike } from \"./host.ts\";\nimport type { KernelHost } from \"./specs/kernel-host.nitro.ts\";\n\nexport type NativeWalletOptions = WalletOptions & {\n /**\n * Creates one `KernelHost` per kernel runtime (a Nitro hybrid object, or a like-shaped fake for\n * tests). A host lives for a single runtime: after a lock or a crash it is spent, and the wallet\n * asks for a new one for the next unlock. Defaults to\n * `NitroModules.createHybridObject(\"KernelHost\")` — the only Nitro-registered object.\n */\n readonly createHost?: () => KernelHostLike;\n};\n\nconst setTimer: SetTimer = (delayMs, fn) => {\n const id = setTimeout(fn, delayMs);\n return () => {\n clearTimeout(id);\n };\n};\n\nasync function defaultHostFactory(): Promise<() => KernelHostLike> {\n const { NitroModules } = await import(\"react-native-nitro-modules\");\n return () => NitroModules.createHybridObject<KernelHost>(\"KernelHost\");\n}\n\nexport async function createNativeWallet(options: NativeWalletOptions): Promise<Wallet> {\n const { autoLock } = options;\n if (autoLock.platform !== \"native\") {\n throw new WalletError(\n \"invalid-input\",\n \"createNativeWallet accepts only the native autoLock policy\",\n );\n }\n const createHost = options.createHost ?? (await defaultHostFactory());\n // The native host owns the auto-lock signal: the platform layer calls host.lock() on\n // background expiry — the kernel never sees a presence source here.\n return connectKernel({\n spawn: () => spawnFromHost(createHost(), autoLock.backgroundSeconds),\n factors: \"hardware\",\n passkey: options.passkey,\n verifyEvent: options.verifyEvent,\n ceremony: undefined,\n setTimer,\n });\n}\n\nexport { spawnFromHost, type KernelHostLike, type KernelExitReason } from \"./host.ts\";\nexport {\n encodeFrame,\n decodeFrame,\n CborError,\n FRAME_MAX_BYTES,\n type CborErrorCode,\n} from \"./cbor.ts\";\n"],"mappings":";;;;;;;;;;AAWA,MAAa,kBAA0B;AAgBvC,IAAa,YAAb,cAA+B,MAAM;C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OAAO;EACL,OAAO,SAAS,aAAa;GAC3B,MAAM,QAAQ,YAAY,OAAO;GACjC,KAAK,KAAK,KAAK;GAIf,KAAK,MAAM,UAAU,UACnB,IAAI,WAAW,MAAM,CAAC,CAAC,KAAK,CAAC;EAEjC;EACA,SAAS,YAAY;GACnB,gBAAgB,IAAI,OAAO;GAC3B,aAAa;IACX,gBAAgB,OAAO,OAAO;GAChC;EACF;EACA,SAAS,YAAY;GACnB,aAAa,IAAI,OAAO;GACxB,aAAa;IACX,aAAa,OAAO,OAAO;GAC7B;EACF;EACA,iBAAiB;GACf,KAAK,SAAS;EAChB;CACF;AACF;;;;;;;ACpEA,MAAM,YAAsB,SAAS,OAAO;CAC1C,MAAM,KAAK,WAAW,IAAI,OAAO;CACjC,aAAa;EACX,aAAa,EAAE;CACjB;AACF;AAEA,eAAe,qBAAoD;CACjE,MAAM,EAAE,iBAAiB,MAAM,OAAO;CACtC,aAAa,aAAa,mBAA+B,YAAY;AACvE;AAEA,eAAsB,mBAAmB,SAA+C;CACtF,MAAM,EAAE,aAAa;CACrB,IAAI,SAAS,aAAa,UACxB,MAAM,IAAI,YACR,iBACA,4DACF;CAEF,MAAM,aAAa,QAAQ,cAAe,MAAM,mBAAmB;CAGnE,OAAO,cAAc;EACnB,aAAa,cAAc,WAAW,GAAG,SAAS,iBAAiB;EACnE,SAAS;EACT,SAAS,QAAQ;EACjB,aAAa,QAAQ;EACrB,UAAU,KAAA;EACV;CACF,CAAC;AACH"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/cbor.ts","../src/host.ts","../src/index.ts"],"sourcesContent":["/**\n * CBOR framing for the kernel channel. `ProtocolValue` travels main-side ↔ kernel-side as CBOR; the\n * C++ layer moves bytes only. Decode is deliberately strict: floats, unsafe integers, undefined,\n * tags, non-string map keys, duplicate keys and indefinite-length items are all rejected — the wire\n * format carries exactly one value domain.\n */\nimport { decode, encodeInto } from \"cborg\";\nimport type { DecodeOptions } from \"cborg\";\nimport { encodedLength } from \"cborg/length\";\n\nimport type { ProtocolValue } from \"@qntx/wallet/protocol\";\n\nexport const FRAME_MAX_BYTES: number = 1024 * 1024;\n\nexport type CborErrorCode =\n | \"oversize\"\n | \"truncated\"\n | \"malformed\"\n | \"float\"\n | \"unsafe-int\"\n | \"bigint\"\n | \"undefined\"\n | \"tag\"\n | \"non-string-key\"\n | \"duplicate-key\"\n | \"indefinite\"\n | \"lone-surrogate\"\n | \"bad-type\";\n\nexport class CborError extends Error {\n readonly code: CborErrorCode;\n constructor(code: CborErrorCode, message: string) {\n super(message);\n this.name = \"CborError\";\n this.code = code;\n }\n}\n\nconst DECODE_OPTIONS: DecodeOptions = {\n strict: true,\n useMaps: false,\n rejectDuplicateMapKeys: true,\n allowUndefined: false,\n allowIndefinite: false,\n allowNaN: false,\n allowInfinity: false,\n allowBigInt: false,\n};\n\n/**\n * A string UTF-8 can carry unchanged: iterating by code point pairs every valid surrogate, so a\n * surrogate code point on its own is a lone one.\n */\nfunction wellFormed(text: string): boolean {\n for (const char of text) {\n const point = char.codePointAt(0) ?? 0;\n if (point >= 0xd800 && point <= 0xdfff) {\n return false;\n }\n }\n return true;\n}\n\nfunction checkString(text: string): void {\n if (!wellFormed(text)) {\n throw new CborError(\"lone-surrogate\", \"cbor frame: string with a lone UTF-16 surrogate\");\n }\n}\n\n/**\n * Reject non-safe-integer numbers, non-string map keys and strings UTF-8 cannot represent (a lone\n * surrogate would be replaced with U+FFFD, silently changing the value); cborg flags cover the\n * rest.\n */\nfunction validate(value: unknown): asserts value is ProtocolValue {\n if (value === null || typeof value === \"boolean\") {\n return;\n }\n if (typeof value === \"string\") {\n checkString(value);\n return;\n }\n if (typeof value === \"number\") {\n if (!Number.isInteger(value)) {\n throw new CborError(\"float\", \"cbor frame: non-integer number\");\n }\n if (!Number.isSafeInteger(value)) {\n throw new CborError(\"unsafe-int\", \"cbor frame: integer outside the safe range\");\n }\n return;\n }\n if (value instanceof Uint8Array) {\n return;\n }\n if (Array.isArray(value)) {\n for (const item of value) {\n validate(item);\n }\n return;\n }\n if (typeof value === \"object\") {\n // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- the object came from a CBOR map\n for (const [key, item] of Object.entries(value as Record<string, unknown>)) {\n if (typeof key !== \"string\") {\n throw new CborError(\"non-string-key\", \"cbor frame: non-string map key\");\n }\n checkString(key);\n validate(item);\n }\n return;\n }\n throw new CborError(\"bad-type\", `cbor frame: unsupported value type ${typeof value}`);\n}\n\n/** Classify a cborg rejection into the frame error taxonomy. */\nfunction classify(error: unknown): CborError {\n if (error instanceof CborError) {\n return error;\n }\n const text = error instanceof Error ? error.message : String(error);\n const table: ReadonlyArray<[RegExp, CborErrorCode]> = [\n [/duplicate key|repeat map key/i, \"duplicate-key\"],\n [/indefinite/i, \"indefinite\"],\n [/undefined/i, \"undefined\"],\n [/bigint|safe integer range/i, \"unsafe-int\"],\n [/tag/i, \"tag\"],\n [/string/i, \"non-string-key\"],\n ];\n for (const [pattern, code] of table) {\n if (pattern.test(text)) {\n return new CborError(code, `cbor frame: ${text}`);\n }\n }\n return new CborError(\"malformed\", `cbor frame: ${text}`);\n}\n\n/**\n * Encode a `ProtocolValue` to a CBOR frame, enforcing the 1 MiB cap. `encodeInto` writes straight\n * into an exact-size buffer the caller owns: `encode` reuses a module-level writer whose first\n * chunk survives across calls, which would keep the last frame's bytes resident in cborg state.\n */\nexport function encodeFrame(value: ProtocolValue): ArrayBuffer {\n validate(value);\n const bytes = new Uint8Array(encodedLength(value));\n let written: number;\n try {\n ({ written } = encodeInto(value, bytes));\n } catch (error) {\n bytes.fill(0);\n throw error;\n }\n if (written > FRAME_MAX_BYTES) {\n bytes.fill(0);\n throw new CborError(\"oversize\", `cbor frame: ${written} bytes exceeds the 1 MiB cap`);\n }\n if (written !== bytes.byteLength) {\n bytes.fill(0);\n throw new CborError(\"malformed\", \"cbor frame: encoded length mismatch\");\n }\n return bytes.buffer;\n}\n\n/** Decode a CBOR frame back to a `ProtocolValue`, enforcing the 1 MiB cap and strictness. */\nexport function decodeFrame(frame: ArrayBuffer | Uint8Array): ProtocolValue {\n const bytes = frame instanceof Uint8Array ? frame : new Uint8Array(frame);\n if (bytes.byteLength > FRAME_MAX_BYTES) {\n throw new CborError(\"oversize\", `cbor frame: ${bytes.byteLength} bytes exceeds the 1 MiB cap`);\n }\n if (bytes.byteLength === 0) {\n throw new CborError(\"truncated\", \"cbor frame: empty frame\");\n }\n try {\n const value: unknown = decode(bytes, DECODE_OPTIONS);\n validate(value);\n return value;\n } catch (error) {\n throw classify(error);\n }\n}\n","/**\n * `KernelHost` JS wrapper: CBOR frames over a Nitro-host-shaped channel. The host moves bytes only\n * — encode/decode happens here and in the kernel entry — so a malformed inbound frame can never\n * reach the message domain: the port exits `crashed` and the host runtime is destroyed.\n */\nimport { WalletError } from \"@qntx/wallet\";\nimport type { MainPort, PortExit } from \"@qntx/wallet/host\";\nimport type { ProtocolValue } from \"@qntx/wallet/protocol\";\n\nimport { CborError, decodeFrame, encodeFrame } from \"./cbor.ts\";\n\nexport type KernelExitReason = \"locked\" | \"crashed\" | \"integrity\" | \"background\";\n\n/**\n * Structural mirror of the Nitro `KernelHost` spec (W2b registers the real hybrid object; tests\n * drive the same shape over an in-memory frame pipe).\n */\nexport type KernelHostLike = {\n readonly start: (backgroundLockSeconds: number) => void;\n readonly post: (frame: ArrayBuffer) => void;\n readonly onMessage: (cb: (frame: ArrayBuffer) => void) => void;\n readonly onExit: (cb: (reason: KernelExitReason) => void) => void;\n /** Changes the background lock budget of the live kernel — applied by `setAutoLock`. */\n readonly setBackgroundLock: (seconds: number) => void;\n readonly lock: () => void;\n};\n\nexport function spawnFromHost(host: KernelHostLike, backgroundLockSeconds: number): MainPort {\n const exitHandlers = new Set<(reason: PortExit) => void>();\n let exited = false;\n\n const exit = (reason: PortExit): void => {\n if (exited) {\n return;\n }\n exited = true;\n for (const handler of exitHandlers) {\n handler(reason);\n }\n host.lock();\n };\n\n host.onMessage((frame) => {\n let message: ProtocolValue;\n try {\n message = decodeFrame(frame);\n } catch {\n exit(\"crashed\");\n return;\n } finally {\n // The frame's bytes are decode-copied or dead either way — never leave the\n // encoded form resident past dispatch.\n new Uint8Array(frame).fill(0);\n }\n dispatch(message);\n });\n\n // The platform locked the enclave in the background — report it honestly so\n // the channel takes the lock path, not the crash path.\n host.onExit((reason) => {\n exit(reason === \"background\" ? \"background\" : \"crashed\");\n });\n\n const messageHandlers = new Set<(message: unknown) => void>();\n const dispatch = (message: unknown): void => {\n for (const handler of messageHandlers) {\n handler(message);\n }\n };\n\n host.start(backgroundLockSeconds);\n\n return {\n post: (message, transfer) => {\n // Structured clone would neuter transferred buffers on the web; the main↔kernel\n // contract is the same here — the caller's buffers hold secrets (passwords, PRF\n // output) and are zeroed once their bytes are inside the frame. The frame itself\n // is wiped on every path after the host took its copy — success or a throwing\n // host.post alike.\n let frame: ArrayBuffer | undefined;\n try {\n frame = encodeFrame(message);\n host.post(frame);\n } catch (error) {\n if (error instanceof CborError) {\n throw new WalletError(\"invalid-input\", `request cannot be encoded: ${error.message}`);\n }\n throw error;\n } finally {\n if (frame !== undefined) {\n new Uint8Array(frame).fill(0);\n }\n for (const buffer of transfer) {\n new Uint8Array(buffer).fill(0);\n }\n }\n },\n listen: (handler) => {\n messageHandlers.add(handler);\n return () => {\n messageHandlers.delete(handler);\n };\n },\n onExit: (handler) => {\n exitHandlers.add(handler);\n return () => {\n exitHandlers.delete(handler);\n };\n },\n terminate: () => {\n exit(\"crashed\");\n },\n };\n}\n","import { WalletError } from \"@qntx/wallet\";\nimport type { NativeAutoLockPolicy, Wallet, WalletOptions } from \"@qntx/wallet\";\nimport type { SetTimer } from \"@qntx/wallet/host\";\n/**\n * `@qntx/wallet-native`: the RN host entry. `createNativeWallet` adapts a `KernelHost` (Nitro\n * hybrid from W2b, or any object with the same shape) to the wallet `connectKernel` entry.\n * `NativeWallet` adds `setAutoLock`: changing the background lock budget applies to the live kernel\n * immediately and to every runtime spawned afterwards.\n */\nimport { connectKernel } from \"@qntx/wallet/host\";\n\nimport { spawnFromHost } from \"./host.ts\";\nimport type { KernelHostLike } from \"./host.ts\";\nimport type { KernelHost } from \"./specs/kernel-host.nitro.ts\";\n\nexport type NativeWallet = Wallet & {\n readonly setAutoLock: (policy: NativeAutoLockPolicy) => void;\n};\n\nexport type NativeWalletOptions = WalletOptions & {\n /**\n * Creates one `KernelHost` per kernel runtime (a Nitro hybrid object, or a like-shaped fake for\n * tests). A host lives for a single runtime: after a lock or a crash it is spent, and the wallet\n * asks for a new one for the next unlock. Defaults to\n * `NitroModules.createHybridObject(\"KernelHost\")` — the only Nitro-registered object.\n */\n readonly createHost?: () => KernelHostLike;\n};\n\nconst setTimer: SetTimer = (delayMs, fn) => {\n const id = setTimeout(fn, delayMs);\n return () => {\n clearTimeout(id);\n };\n};\n\nasync function defaultHostFactory(): Promise<() => KernelHostLike> {\n const { NitroModules } = await import(\"react-native-nitro-modules\");\n return () => NitroModules.createHybridObject<KernelHost>(\"KernelHost\");\n}\n\nconst BACKGROUND_SECONDS: ReadonlySet<number> = new Set([0, 60, 300, 900]);\n\nexport async function createNativeWallet(options: NativeWalletOptions): Promise<NativeWallet> {\n const { autoLock } = options;\n if (autoLock.platform !== \"native\") {\n throw new WalletError(\n \"invalid-input\",\n \"createNativeWallet accepts only the native autoLock policy\",\n );\n }\n const createHost = options.createHost ?? (await defaultHostFactory());\n let seconds: number = autoLock.backgroundSeconds;\n let live: KernelHostLike | undefined;\n // The native host owns the auto-lock signal: the platform layer calls host.lock() on\n // background expiry — the kernel never sees a presence source here.\n const wallet = await connectKernel({\n spawn: () => {\n live = createHost();\n return spawnFromHost(live, seconds);\n },\n factors: \"hardware\",\n passkey: options.passkey,\n verifyEvent: options.verifyEvent,\n ceremony: undefined,\n setTimer,\n });\n const setAutoLock = (policy: NativeAutoLockPolicy): void => {\n if (policy.platform !== \"native\" || !BACKGROUND_SECONDS.has(policy.backgroundSeconds)) {\n throw new WalletError(\"invalid-input\", \"not a native auto-lock policy\");\n }\n seconds = policy.backgroundSeconds;\n live?.setBackgroundLock(policy.backgroundSeconds);\n };\n // Object.assign keeps one identity: nostr(wallet) and friends key their internals on it.\n return Object.assign(wallet, { setAutoLock });\n}\n\nexport { spawnFromHost, type KernelHostLike, type KernelExitReason } from \"./host.ts\";\nexport {\n encodeFrame,\n decodeFrame,\n CborError,\n FRAME_MAX_BYTES,\n type CborErrorCode,\n} from \"./cbor.ts\";\n"],"mappings":";;;;;;;;;;;AAYA,MAAa,kBAA0B;AAiBvC,IAAa,YAAb,cAA+B,MAAM;CACnC;CACA,YAAY,MAAqB,SAAiB;EAChD,MAAM,OAAO;EACb,KAAK,OAAO;EACZ,KAAK,OAAO;CACd;AACF;AAEA,MAAM,iBAAgC;CACpC,QAAQ;CACR,SAAS;CACT,wBAAwB;CACxB,gBAAgB;CAChB,iBAAiB;CACjB,UAAU;CACV,eAAe;CACf,aAAa;AACf;;;;;AAMA,SAAS,WAAW,MAAuB;CACzC,KAAK,MAAM,QAAQ,MAAM;EACvB,MAAM,QAAQ,KAAK,YAAY,CAAC,KAAK;EACrC,IAAI,SAAS,SAAU,SAAS,OAC9B,OAAO;CAEX;CACA,OAAO;AACT;AAEA,SAAS,YAAY,MAAoB;CACvC,IAAI,CAAC,WAAW,IAAI,GAClB,MAAM,IAAI,UAAU,kBAAkB,iDAAiD;AAE3F;;;;;;AAOA,SAAS,SAAS,OAAgD;CAChE,IAAI,UAAU,QAAQ,OAAO,UAAU,WACrC;CAEF,IAAI,OAAO,UAAU,UAAU;EAC7B,YAAY,KAAK;EACjB;CACF;CACA,IAAI,OAAO,UAAU,UAAU;EAC7B,IAAI,CAAC,OAAO,UAAU,KAAK,GACzB,MAAM,IAAI,UAAU,SAAS,gCAAgC;EAE/D,IAAI,CAAC,OAAO,cAAc,KAAK,GAC7B,MAAM,IAAI,UAAU,cAAc,4CAA4C;EAEhF;CACF;CACA,IAAI,iBAAiB,YACnB;CAEF,IAAI,MAAM,QAAQ,KAAK,GAAG;EACxB,K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AAC9C"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { HybridViewMethods, HybridViewProps, ReactNativeView } from "react-native-nitro-modules";
|
|
2
|
+
/**
|
|
3
|
+
* The only thing the main runtime may observe of the trusted input: `idle` when no request is
|
|
4
|
+
* pending, `empty`/`filled` as the user types, and `submitted` after a confirmed entry. The main
|
|
5
|
+
* runtime can mount and size this view and receive these states — it can never read the text. What
|
|
6
|
+
* to collect (`access-code`, `short-id`, `backup-password` or `session-approval`) and the label the
|
|
7
|
+
* view shows come from the kernel's `secureInput.request`, not from props.
|
|
8
|
+
*/
|
|
9
|
+
type SecureInputState = "idle" | "empty" | "filled" | "submitted";
|
|
10
|
+
interface SecureInputProps extends HybridViewProps {
|
|
11
|
+
onStateChange: (state: SecureInputState) => void;
|
|
12
|
+
}
|
|
13
|
+
interface SecureInputMethods extends HybridViewMethods {}
|
|
14
|
+
/**
|
|
15
|
+
* The trusted secure-input surface. Mount it where the wallet collects a card access code, a short
|
|
16
|
+
* ID or the backup password: the kernel decides the kind and the label; the main runtime can only
|
|
17
|
+
* size the view and observe `onStateChange` — it never sees the characters. `onStateChange`, like
|
|
18
|
+
* every Nitro view callback, must be passed through `callback(...)`.
|
|
19
|
+
*
|
|
20
|
+
* @experimental
|
|
21
|
+
*/
|
|
22
|
+
export declare const SecureInput: ReactNativeView<SecureInputProps, SecureInputMethods>;
|
|
23
|
+
export type { SecureInputProps, SecureInputState };
|
|
24
|
+
//# sourceMappingURL=secure-input.d.mts.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { getHostComponent } from "react-native-nitro-modules";
|
|
2
|
+
// nitrogen/generated/shared/json/SecureInputViewConfig.json
|
|
3
|
+
var SecureInputViewConfig_default = {
|
|
4
|
+
uiViewClassName: "SecureInputView",
|
|
5
|
+
supportsRawText: false,
|
|
6
|
+
bubblingEventTypes: {},
|
|
7
|
+
directEventTypes: {},
|
|
8
|
+
validAttributes: {
|
|
9
|
+
"onStateChange": true,
|
|
10
|
+
"hybridRef": true
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
// src/secure-input.ts
|
|
14
|
+
/**
|
|
15
|
+
* The trusted secure-input surface. Mount it where the wallet collects a card access code, a short
|
|
16
|
+
* ID or the backup password: the kernel decides the kind and the label; the main runtime can only
|
|
17
|
+
* size the view and observe `onStateChange` — it never sees the characters. `onStateChange`, like
|
|
18
|
+
* every Nitro view callback, must be passed through `callback(...)`.
|
|
19
|
+
*
|
|
20
|
+
* @experimental
|
|
21
|
+
*/
|
|
22
|
+
const SecureInput = getHostComponent("SecureInputView", () => SecureInputViewConfig_default);
|
|
23
|
+
export { SecureInput };
|
|
24
|
+
|
|
25
|
+
//# sourceMappingURL=secure-input.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secure-input.mjs","names":["SecureInputViewConfig"],"sources":["../nitrogen/generated/shared/json/SecureInputViewConfig.json","../src/secure-input.ts"],"sourcesContent":["","import { getHostComponent } from \"react-native-nitro-modules\";\nimport type { ReactNativeView } from \"react-native-nitro-modules\";\n\nimport SecureInputViewConfig from \"../nitrogen/generated/shared/json/SecureInputViewConfig.json\" with { type: \"json\" };\nimport type { SecureInputMethods, SecureInputProps } from \"./specs/secure-input.nitro.ts\";\n\nexport type { SecureInputProps, SecureInputState } from \"./specs/secure-input.nitro.ts\";\n\n/**\n * The trusted secure-input surface. Mount it where the wallet collects a card access code, a short\n * ID or the backup password: the kernel decides the kind and the label; the main runtime can only\n * size the view and observe `onStateChange` — it never sees the characters. `onStateChange`, like\n * every Nitro view callback, must be passed through `callback(...)`.\n *\n * @experimental\n */\nexport const SecureInput: ReactNativeView<SecureInputProps, SecureInputMethods> = getHostComponent<\n SecureInputProps,\n SecureInputMethods\n>(\"SecureInputView\", () => SecureInputViewConfig);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;ACgBA,MAAa,cAAqE,iBAGhF,yBAAyBA,6BAAqB"}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import CloudKit
|
|
2
|
+
import Foundation
|
|
3
|
+
import NitroModules
|
|
4
|
+
|
|
5
|
+
/// The real `CloudKitDatabase`: forwards each call onto `CKDatabase` inside the custom
|
|
6
|
+
/// `QntxWalletBackup` zone and owns the `recordZoneChanges` paging (a `CKServerChangeToken`
|
|
7
|
+
/// cannot be faked, so paging lives here rather than in the pure core). All request-level
|
|
8
|
+
/// interpretation happens in `CloudKitEnvelopeStore`.
|
|
9
|
+
private final class PrivateCloudDatabase: CloudKitDatabase {
|
|
10
|
+
let database: CKDatabase
|
|
11
|
+
let zoneID: CKRecordZone.ID
|
|
12
|
+
|
|
13
|
+
init(container: String) {
|
|
14
|
+
database = CKContainer(identifier: container).privateCloudDatabase
|
|
15
|
+
zoneID = CKRecordZone.ID(
|
|
16
|
+
zoneName: CloudKitEnvelopeStore.zoneName,
|
|
17
|
+
ownerName: CKCurrentUserDefaultName
|
|
18
|
+
)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/// The async CKDatabase APIs run under this configuration; unlike the callback
|
|
22
|
+
/// operations they always resume the awaiting task, failure or not.
|
|
23
|
+
private func configured<R>(_ body: (CKDatabase) async throws -> R) async rethrows -> R {
|
|
24
|
+
let configuration = CKOperation.Configuration()
|
|
25
|
+
configuration.timeoutIntervalForRequest = 60
|
|
26
|
+
configuration.timeoutIntervalForResource = 120
|
|
27
|
+
configuration.qualityOfService = .userInitiated
|
|
28
|
+
return try await database.configuredWith(configuration: configuration, body: body)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
func recordNames() async throws -> [String] {
|
|
32
|
+
// desiredKeys [] fetches names only; the token pages until the zone is fully enumerated.
|
|
33
|
+
var names: [String] = []
|
|
34
|
+
var token: CKServerChangeToken? = nil
|
|
35
|
+
var moreComing = true
|
|
36
|
+
while moreComing {
|
|
37
|
+
let page = try await configured { database in
|
|
38
|
+
try await database.recordZoneChanges(
|
|
39
|
+
inZoneWith: zoneID, since: token, desiredKeys: [])
|
|
40
|
+
}
|
|
41
|
+
token = page.changeToken
|
|
42
|
+
moreComing = page.moreComing
|
|
43
|
+
for (id, result) in page.modificationResultsByID {
|
|
44
|
+
if case .success = result {
|
|
45
|
+
names.append(id.recordName)
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return names
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
func record(withID id: CKRecord.ID) async throws -> CKRecord {
|
|
53
|
+
let results = try await configured { database in
|
|
54
|
+
try await database.records(for: [id], desiredKeys: [CloudKitEnvelopeStore.field])
|
|
55
|
+
}
|
|
56
|
+
guard let result = results[id] else {
|
|
57
|
+
throw CKError(.unknownItem)
|
|
58
|
+
}
|
|
59
|
+
return try result.get()
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
func save(_ record: CKRecord) async throws -> CKRecord {
|
|
63
|
+
let outcome = try await configured { database in
|
|
64
|
+
try await database.modifyRecords(
|
|
65
|
+
saving: [record], deleting: [], savePolicy: .allKeys, atomically: true)
|
|
66
|
+
}
|
|
67
|
+
guard let result = outcome.saveResults[record.recordID] else {
|
|
68
|
+
throw CKError(.unknownItem)
|
|
69
|
+
}
|
|
70
|
+
_ = try result.get()
|
|
71
|
+
return record
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
func deleteRecord(withID id: CKRecord.ID) async throws {
|
|
75
|
+
let outcome = try await configured { database in
|
|
76
|
+
try await database.modifyRecords(
|
|
77
|
+
saving: [], deleting: [id], savePolicy: .allKeys, atomically: true)
|
|
78
|
+
}
|
|
79
|
+
guard let result = outcome.deleteResults[id] else {
|
|
80
|
+
throw CKError(.unknownItem)
|
|
81
|
+
}
|
|
82
|
+
try result.get()
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
func saveZone(_ zone: CKRecordZone) async throws {
|
|
86
|
+
let outcome = try await configured { database in
|
|
87
|
+
try await database.modifyRecordZones(saving: [zone], deleting: [])
|
|
88
|
+
}
|
|
89
|
+
guard let result = outcome.saveResults[zone.zoneID] else {
|
|
90
|
+
throw CKError(.unknownItem)
|
|
91
|
+
}
|
|
92
|
+
_ = try result.get()
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/// The CloudKitStore HybridObject: one private-database adapter per container plus a
|
|
97
|
+
/// `CKAccountChanged` observer that fans out to the registered JS listener. All payload
|
|
98
|
+
/// interpretation lives in `CloudKitEnvelopeStore` — this class only forwards.
|
|
99
|
+
class HybridCloudKitStore: HybridCloudKitStoreSpec {
|
|
100
|
+
private let databasesLock = NSLock()
|
|
101
|
+
private var databases: [String: PrivateCloudDatabase] = [:]
|
|
102
|
+
private var accountObserver: NSObjectProtocol?
|
|
103
|
+
private var accountListener: (() -> Void)?
|
|
104
|
+
|
|
105
|
+
private func database(for container: String) -> PrivateCloudDatabase {
|
|
106
|
+
databasesLock.lock()
|
|
107
|
+
defer { databasesLock.unlock() }
|
|
108
|
+
if let cached = databases[container] {
|
|
109
|
+
return cached
|
|
110
|
+
}
|
|
111
|
+
let created = PrivateCloudDatabase(container: container)
|
|
112
|
+
databases[container] = created
|
|
113
|
+
return created
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
func list(container: String) throws -> Promise<[String]> {
|
|
117
|
+
Promise.async {
|
|
118
|
+
try await CloudKitEnvelopeStore.list(database: self.database(for: container))
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
func read(container: String, name: String) throws -> Promise<String?> {
|
|
123
|
+
Promise.async {
|
|
124
|
+
let database = self.database(for: container)
|
|
125
|
+
return try await CloudKitEnvelopeStore.read(
|
|
126
|
+
database: database, name: name, zoneID: database.zoneID)
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
func write(container: String, name: String, text: String) throws -> Promise<Void> {
|
|
131
|
+
Promise.async {
|
|
132
|
+
let database = self.database(for: container)
|
|
133
|
+
try await CloudKitEnvelopeStore.write(
|
|
134
|
+
database: database, name: name, text: text, zoneID: database.zoneID)
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
func remove(container: String, name: String) throws -> Promise<Void> {
|
|
139
|
+
Promise.async {
|
|
140
|
+
let database = self.database(for: container)
|
|
141
|
+
try await CloudKitEnvelopeStore.remove(
|
|
142
|
+
database: database, name: name, zoneID: database.zoneID)
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
func setAccountListener(listener: @escaping () -> Void) throws {
|
|
147
|
+
accountListener = listener
|
|
148
|
+
guard accountObserver == nil else {
|
|
149
|
+
return
|
|
150
|
+
}
|
|
151
|
+
accountObserver = NotificationCenter.default.addObserver(
|
|
152
|
+
forName: NSNotification.Name.CKAccountChanged,
|
|
153
|
+
object: nil,
|
|
154
|
+
queue: nil
|
|
155
|
+
) { [weak self] _ in
|
|
156
|
+
self?.accountListener?()
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import UIKit
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The SecureInputView HybridObject. The rendered view is the ObjC
|
|
5
|
+
* `QntxSecureInputField` — the typed characters live in Objective-C++ and go
|
|
6
|
+
* to the kernel's SecureInputHub as bytes; this class only forwards the
|
|
7
|
+
* field's state transitions to the `onStateChange` prop.
|
|
8
|
+
*/
|
|
9
|
+
class HybridSecureInputView: HybridSecureInputViewSpec {
|
|
10
|
+
let view = QntxSecureInputField()
|
|
11
|
+
|
|
12
|
+
var onStateChange: (_ state: SecureInputState) -> Void = { _ in }
|
|
13
|
+
|
|
14
|
+
override init() {
|
|
15
|
+
super.init()
|
|
16
|
+
view.onStateChange = { [weak self] state in
|
|
17
|
+
self?.onStateChange(state.secureInputState)
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
private extension QntxSecureInputState {
|
|
23
|
+
var secureInputState: SecureInputState {
|
|
24
|
+
switch self {
|
|
25
|
+
case .empty:
|
|
26
|
+
return .empty
|
|
27
|
+
case .filled:
|
|
28
|
+
return .filled
|
|
29
|
+
case .submitted:
|
|
30
|
+
return .submitted
|
|
31
|
+
default:
|
|
32
|
+
return .idle
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|