@solidnative-dev/secure-storage 0.0.0-stage → 0.1.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +43 -2
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +67 -0
- package/dist/index.js.map +1 -0
- package/dist/keychain-10.d.ts +32 -0
- package/dist/keychain-10.d.ts.map +1 -0
- package/dist/keychain-10.js +118 -0
- package/dist/keychain-10.js.map +1 -0
- package/dist/react-native.d.ts +10 -0
- package/dist/react-native.d.ts.map +1 -0
- package/dist/react-native.js +20 -0
- package/dist/react-native.js.map +1 -0
- package/dist/solid.d.ts +8 -0
- package/dist/solid.d.ts.map +1 -0
- package/dist/solid.js +90 -0
- package/dist/solid.js.map +1 -0
- package/package.json +67 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Solid Native contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,44 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@solidnative-dev/secure-storage`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Bounded credential storage for Solid Native applications. The React Native
|
|
4
|
+
adapter targets the exact native ABI published by `react-native-keychain` 10
|
|
5
|
+
without evaluating its React-facing wrapper or runtime enums.
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { createReactNativeSecureStorage } from "@solidnative-dev/secure-storage/react-native";
|
|
9
|
+
import { createSecureStorageController } from "@solidnative-dev/secure-storage/solid";
|
|
10
|
+
|
|
11
|
+
const storage = createSecureStorageController(
|
|
12
|
+
createReactNativeSecureStorage({ servicePrefix: "com.example.session" }),
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
await storage.setItem("refresh-token", token);
|
|
16
|
+
const restored = await storage.getItem("refresh-token");
|
|
17
|
+
await storage.removeItem("refresh-token");
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Every key becomes a separate native generic-password service. Values are
|
|
21
|
+
limited to 65,536 UTF-16 code units and keys to 128. Empty values are encoded
|
|
22
|
+
so Android's non-empty credential ABI can represent them exactly. By default,
|
|
23
|
+
iOS values are available only while the device is unlocked and never migrate
|
|
24
|
+
to another device; Android requires at least software-backed Keystore storage.
|
|
25
|
+
Hardware-backed Android storage is an explicit opt-in because requiring it can
|
|
26
|
+
exclude otherwise supported devices. iCloud Keychain synchronization is always
|
|
27
|
+
disabled by this adapter.
|
|
28
|
+
|
|
29
|
+
The native dependency currently declares `RNKeychainSpec` but publishes no
|
|
30
|
+
discoverable `Native*` Codegen spec. Solid Native therefore labels this as an
|
|
31
|
+
explicit legacy-native seam. Before constructing `RCTHost`, the package-owned
|
|
32
|
+
Fabric Host enables React Native 0.87's bridgeless legacy-module interop, just
|
|
33
|
+
as that release's standard root factory does. The registry can then expose the
|
|
34
|
+
linked `RNKeychainManager`; this does not turn its empty Codegen declaration
|
|
35
|
+
into a generated TurboModule. All values crossing the fallback are validated
|
|
36
|
+
by the versioned `keychain-10` adapter. The adapter also supplies Keychain 10's
|
|
37
|
+
exact default authentication-prompt object because its iOS read implementation
|
|
38
|
+
cannot accept the missing value even for credentials without access control.
|
|
39
|
+
|
|
40
|
+
The Solid controller turns successful reads, writes, and removals into
|
|
41
|
+
default-priority causal platform events without recording keys or values.
|
|
42
|
+
Disposing its owner rejects unsettled application promises and prevents late
|
|
43
|
+
native results from re-entering retired Solid state. A native operation already
|
|
44
|
+
accepted by the platform cannot be canceled and may still complete.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare const SECURE_STORAGE_MAX_KEY_LENGTH = 128;
|
|
2
|
+
export declare const SECURE_STORAGE_MAX_VALUE_LENGTH = 65536;
|
|
3
|
+
export interface SecureStorage {
|
|
4
|
+
getItem(key: string): Promise<string | null>;
|
|
5
|
+
setItem(key: string, value: string): Promise<void>;
|
|
6
|
+
removeItem(key: string): Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
export interface SecureStorageAdapter {
|
|
9
|
+
getItem(key: string): Promise<unknown>;
|
|
10
|
+
setItem(key: string, value: string): Promise<unknown>;
|
|
11
|
+
removeItem(key: string): Promise<unknown>;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Narrows an untrusted secure native adapter to bounded string credentials.
|
|
15
|
+
* Operations are invoked in call order on each returned storage instance.
|
|
16
|
+
*/
|
|
17
|
+
export declare function createSecureStorage(adapter: SecureStorageAdapter): SecureStorage;
|
|
18
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,6BAA6B,MAAM,CAAC;AACjD,eAAO,MAAM,+BAA+B,QAAS,CAAC;AAEtD,MAAM,WAAW,aAAa;IAC5B,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAC7C,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACnD,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACxC;AAED,MAAM,WAAW,oBAAoB;IACnC,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACvC,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACtD,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAC3C;AAqCD;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,oBAAoB,GAC5B,aAAa,CA2Cf"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
export const SECURE_STORAGE_MAX_KEY_LENGTH = 128;
|
|
2
|
+
export const SECURE_STORAGE_MAX_VALUE_LENGTH = 65_536;
|
|
3
|
+
function secureKey(value) {
|
|
4
|
+
if (typeof value !== "string" ||
|
|
5
|
+
value.length === 0 ||
|
|
6
|
+
value.length > SECURE_STORAGE_MAX_KEY_LENGTH ||
|
|
7
|
+
value.includes("\0")) {
|
|
8
|
+
throw new TypeError(`Secure-storage keys must be 1-${SECURE_STORAGE_MAX_KEY_LENGTH} character strings without null bytes.`);
|
|
9
|
+
}
|
|
10
|
+
return value;
|
|
11
|
+
}
|
|
12
|
+
function secureValue(value, source) {
|
|
13
|
+
if (typeof value !== "string" ||
|
|
14
|
+
value.length > SECURE_STORAGE_MAX_VALUE_LENGTH) {
|
|
15
|
+
throw new TypeError(`${source === "application" ? "Secure-storage values" : "The native secure-storage value"} must be a string of at most ${SECURE_STORAGE_MAX_VALUE_LENGTH} characters.`);
|
|
16
|
+
}
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
function adapterMethod(adapter, name) {
|
|
20
|
+
if (typeof adapter[name] !== "function") {
|
|
21
|
+
throw new TypeError(`Secure-storage adapter ${name} must be a function.`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Narrows an untrusted secure native adapter to bounded string credentials.
|
|
26
|
+
* Operations are invoked in call order on each returned storage instance.
|
|
27
|
+
*/
|
|
28
|
+
export function createSecureStorage(adapter) {
|
|
29
|
+
if (typeof adapter !== "object" || adapter === null) {
|
|
30
|
+
throw new TypeError("Secure-storage adapter must be an object.");
|
|
31
|
+
}
|
|
32
|
+
adapterMethod(adapter, "getItem");
|
|
33
|
+
adapterMethod(adapter, "setItem");
|
|
34
|
+
adapterMethod(adapter, "removeItem");
|
|
35
|
+
const getItem = adapter.getItem.bind(adapter);
|
|
36
|
+
const setItem = adapter.setItem.bind(adapter);
|
|
37
|
+
const removeItem = adapter.removeItem.bind(adapter);
|
|
38
|
+
let operations = Promise.resolve();
|
|
39
|
+
const enqueue = (operation) => {
|
|
40
|
+
const result = operations.then(operation);
|
|
41
|
+
operations = result.then(() => undefined, () => undefined);
|
|
42
|
+
return result;
|
|
43
|
+
};
|
|
44
|
+
return Object.freeze({
|
|
45
|
+
async getItem(key) {
|
|
46
|
+
const selectedKey = secureKey(key);
|
|
47
|
+
return await enqueue(async () => {
|
|
48
|
+
const value = await getItem(selectedKey);
|
|
49
|
+
return value === null ? null : secureValue(value, "native");
|
|
50
|
+
});
|
|
51
|
+
},
|
|
52
|
+
async setItem(key, value) {
|
|
53
|
+
const selectedKey = secureKey(key);
|
|
54
|
+
const selectedValue = secureValue(value, "application");
|
|
55
|
+
await enqueue(async () => {
|
|
56
|
+
await setItem(selectedKey, selectedValue);
|
|
57
|
+
});
|
|
58
|
+
},
|
|
59
|
+
async removeItem(key) {
|
|
60
|
+
const selectedKey = secureKey(key);
|
|
61
|
+
await enqueue(async () => {
|
|
62
|
+
await removeItem(selectedKey);
|
|
63
|
+
});
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,6BAA6B,GAAG,GAAG,CAAC;AACjD,MAAM,CAAC,MAAM,+BAA+B,GAAG,MAAM,CAAC;AActD,SAAS,SAAS,CAAC,KAAc;IAC/B,IACE,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,CAAC,MAAM,KAAK,CAAC;QAClB,KAAK,CAAC,MAAM,GAAG,6BAA6B;QAC5C,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,EACpB,CAAC;QACD,MAAM,IAAI,SAAS,CACjB,iCAAiC,6BAA6B,wCAAwC,CACvG,CAAC;IACJ,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,WAAW,CAAC,KAAc,EAAE,MAAgC;IACnE,IACE,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,CAAC,MAAM,GAAG,+BAA+B,EAC9C,CAAC;QACD,MAAM,IAAI,SAAS,CACjB,GAAG,MAAM,KAAK,aAAa,CAAC,CAAC,CAAC,uBAAuB,CAAC,CAAC,CAAC,iCAAiC,gCAAgC,+BAA+B,cAAc,CACvK,CAAC;IACJ,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,aAAa,CACpB,OAA6B,EAC7B,IAAgC;IAEhC,IAAI,OAAO,OAAO,CAAC,IAAI,CAAC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AC,CAAC;gBACzC,OAAO,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,WAAW,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;YAC9D,CAAC,CAAC,CAAC;QACL,CAAC;QACD,KAAK,CAAC,OAAO,CAAC,GAAW,EAAE,KAAa;YACtC,MAAM,WAAW,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC;YACnC,MAAM,aAAa,GAAG,WAAW,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;YACxD,MAAM,OAAO,CAAC,KAAK,IAAI,EAAE;gBACvB,MAAM,OAAO,CAAC,WAAW,EAAE,aAAa,CAAC,CAAC;YAC5C,CAAC,CAAC,CAAC;QACL,CAAC;QACD,KAAK,CAAC,UAAU,CAAC,GAAW;YAC1B,MAAM,WAAW,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC;YACnC,MAAM,OAAO,CAAC,KAAK,IAAI,EAAE;gBACvB,MAAM,UAAU,CAAC,WAAW,CAAC,CAAC;YAChC,CAAC,CAAC,CAAC;QACL,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type SecureStorage } from "./index.js";
|
|
2
|
+
export declare const KEYCHAIN_10_MAX_SERVICE_PREFIX_LENGTH = 96;
|
|
3
|
+
interface KeychainOptions {
|
|
4
|
+
readonly accessible?: string;
|
|
5
|
+
readonly authenticationPrompt: Readonly<{
|
|
6
|
+
cancel: string;
|
|
7
|
+
title: string;
|
|
8
|
+
}>;
|
|
9
|
+
readonly cloudSync: false;
|
|
10
|
+
readonly securityLevel?: string;
|
|
11
|
+
readonly service: string;
|
|
12
|
+
}
|
|
13
|
+
export interface ReactNativeKeychain10Module {
|
|
14
|
+
setGenericPasswordForOptions(options: KeychainOptions, username: string, password: string): Promise<unknown>;
|
|
15
|
+
getGenericPasswordForOptions(options: KeychainOptions): Promise<unknown>;
|
|
16
|
+
resetGenericPasswordForOptions(options: KeychainOptions): Promise<unknown>;
|
|
17
|
+
}
|
|
18
|
+
export interface Keychain10SecureStorageOptions {
|
|
19
|
+
/** Stable application-owned prefix used to isolate every native service. */
|
|
20
|
+
readonly servicePrefix: string;
|
|
21
|
+
/** iOS availability policy. Defaults to device-only access while unlocked. */
|
|
22
|
+
readonly iosAccessibility?: "when-unlocked-device-only" | "after-first-unlock-device-only";
|
|
23
|
+
/** Android Keystore floor. Hardware-backed storage can exclude some devices. */
|
|
24
|
+
readonly androidSecurity?: "software" | "hardware";
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Adapts react-native-keychain 10's exact legacy native ABI without evaluating
|
|
28
|
+
* its React-facing JavaScript wrapper or runtime enums.
|
|
29
|
+
*/
|
|
30
|
+
export declare function createKeychain10SecureStorage(value: ReactNativeKeychain10Module, options: Keychain10SecureStorageOptions): SecureStorage;
|
|
31
|
+
export {};
|
|
32
|
+
//# sourceMappingURL=keychain-10.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keychain-10.d.ts","sourceRoot":"","sources":["../src/keychain-10.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,KAAK,aAAa,EAAE,MAAM,YAAY,CAAC;AAErE,eAAO,MAAM,qCAAqC,KAAK,CAAC;AASxD,UAAU,eAAe;IACvB,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,oBAAoB,EAAE,QAAQ,CAAC;QACtC,MAAM,EAAE,MAAM,CAAC;QACf,KAAK,EAAE,MAAM,CAAC;KACf,CAAC,CAAC;IACH,QAAQ,CAAC,SAAS,EAAE,KAAK,CAAC;IAC1B,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,2BAA2B;IAC1C,4BAA4B,CAC1B,OAAO,EAAE,eAAe,EACxB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,OAAO,CAAC,CAAC;IACpB,4BAA4B,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACzE,8BAA8B,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAC5E;AAED,MAAM,WAAW,8BAA8B;IAC7C,4EAA4E;IAC5E,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,8EAA8E;IAC9E,QAAQ,CAAC,gBAAgB,CAAC,EACxB,2BAA2B,GAAG,gCAAgC,CAAC;IACjE,gFAAgF;IAChF,QAAQ,CAAC,eAAe,CAAC,EAAE,UAAU,GAAG,UAAU,CAAC;CACpD;AA6FD;;;GAGG;AACH,wBAAgB,6BAA6B,CAC3C,KAAK,EAAE,2BAA2B,EAClC,OAAO,EAAE,8BAA8B,GACtC,aAAa,CAgEf"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { createSecureStorage } from "./index.js";
|
|
2
|
+
export const KEYCHAIN_10_MAX_SERVICE_PREFIX_LENGTH = 96;
|
|
3
|
+
const ACCOUNT = "solid-native.secure-storage/v1";
|
|
4
|
+
const ENCODED_VALUE_PREFIX = "solid-native:v1:";
|
|
5
|
+
const AUTHENTICATION_PROMPT = Object.freeze({
|
|
6
|
+
cancel: "Cancel",
|
|
7
|
+
title: "Authenticate to retrieve secret",
|
|
8
|
+
});
|
|
9
|
+
function record(value, path) {
|
|
10
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
11
|
+
throw new TypeError(`${path} must be an object.`);
|
|
12
|
+
}
|
|
13
|
+
return value;
|
|
14
|
+
}
|
|
15
|
+
function servicePrefix(value) {
|
|
16
|
+
if (typeof value !== "string" ||
|
|
17
|
+
value.length === 0 ||
|
|
18
|
+
value.length > KEYCHAIN_10_MAX_SERVICE_PREFIX_LENGTH ||
|
|
19
|
+
value.includes("\0") ||
|
|
20
|
+
value.endsWith(":")) {
|
|
21
|
+
throw new TypeError(`Keychain servicePrefix must be a 1-${KEYCHAIN_10_MAX_SERVICE_PREFIX_LENGTH} character string without null bytes or a trailing colon.`);
|
|
22
|
+
}
|
|
23
|
+
return value;
|
|
24
|
+
}
|
|
25
|
+
function selectedAccessibility(value) {
|
|
26
|
+
if (value === undefined || value === "when-unlocked-device-only") {
|
|
27
|
+
return "AccessibleWhenUnlockedThisDeviceOnly";
|
|
28
|
+
}
|
|
29
|
+
if (value === "after-first-unlock-device-only") {
|
|
30
|
+
return "AccessibleAfterFirstUnlockThisDeviceOnly";
|
|
31
|
+
}
|
|
32
|
+
throw new TypeError(`Unsupported iOS secure-storage accessibility ${String(value)}.`);
|
|
33
|
+
}
|
|
34
|
+
function selectedSecurity(value) {
|
|
35
|
+
if (value === undefined || value === "software")
|
|
36
|
+
return "SECURE_SOFTWARE";
|
|
37
|
+
if (value === "hardware")
|
|
38
|
+
return "SECURE_HARDWARE";
|
|
39
|
+
throw new TypeError(`Unsupported Android secure-storage security ${String(value)}.`);
|
|
40
|
+
}
|
|
41
|
+
function resultStorage(value, path) {
|
|
42
|
+
if (typeof value !== "string" ||
|
|
43
|
+
value.length === 0 ||
|
|
44
|
+
value.length > 128 ||
|
|
45
|
+
value.includes("\0")) {
|
|
46
|
+
throw new TypeError(`${path}.storage must be a bounded non-empty string.`);
|
|
47
|
+
}
|
|
48
|
+
return value;
|
|
49
|
+
}
|
|
50
|
+
function decodeMutationResult(value, expectedService) {
|
|
51
|
+
const result = record(value, "React Native Keychain 10 write result");
|
|
52
|
+
if (result.service !== expectedService) {
|
|
53
|
+
throw new TypeError("React Native Keychain 10 wrote outside the requested service.");
|
|
54
|
+
}
|
|
55
|
+
resultStorage(result.storage, "React Native Keychain 10 write result");
|
|
56
|
+
}
|
|
57
|
+
function decodeReadResult(value, expectedService) {
|
|
58
|
+
if (value === false)
|
|
59
|
+
return null;
|
|
60
|
+
const result = record(value, "React Native Keychain 10 read result");
|
|
61
|
+
if (result.service !== expectedService ||
|
|
62
|
+
result.username !== ACCOUNT ||
|
|
63
|
+
typeof result.password !== "string" ||
|
|
64
|
+
!result.password.startsWith(ENCODED_VALUE_PREFIX)) {
|
|
65
|
+
throw new TypeError("React Native Keychain 10 returned credentials outside the requested storage contract.");
|
|
66
|
+
}
|
|
67
|
+
resultStorage(result.storage, "React Native Keychain 10 read result");
|
|
68
|
+
return result.password.slice(ENCODED_VALUE_PREFIX.length);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Adapts react-native-keychain 10's exact legacy native ABI without evaluating
|
|
72
|
+
* its React-facing JavaScript wrapper or runtime enums.
|
|
73
|
+
*/
|
|
74
|
+
export function createKeychain10SecureStorage(value, options) {
|
|
75
|
+
const module = record(value, "React Native Keychain 10 module");
|
|
76
|
+
if (typeof module.setGenericPasswordForOptions !== "function" ||
|
|
77
|
+
typeof module.getGenericPasswordForOptions !== "function" ||
|
|
78
|
+
typeof module.resetGenericPasswordForOptions !== "function") {
|
|
79
|
+
throw new TypeError("React Native Keychain 10 module must provide the generic-password read, write, and reset methods.");
|
|
80
|
+
}
|
|
81
|
+
if (typeof options !== "object" || options === null) {
|
|
82
|
+
throw new TypeError("React Native Keychain 10 options must be an object.");
|
|
83
|
+
}
|
|
84
|
+
const prefix = servicePrefix(options.servicePrefix);
|
|
85
|
+
const accessible = selectedAccessibility(options.iosAccessibility);
|
|
86
|
+
const securityLevel = selectedSecurity(options.androidSecurity);
|
|
87
|
+
const setGenericPasswordForOptions = value.setGenericPasswordForOptions.bind(value);
|
|
88
|
+
const getGenericPasswordForOptions = value.getGenericPasswordForOptions.bind(value);
|
|
89
|
+
const resetGenericPasswordForOptions = value.resetGenericPasswordForOptions.bind(value);
|
|
90
|
+
// Keychain 10's React wrapper always supplies this prompt. Its iOS read ABI
|
|
91
|
+
// inserts the prompt into an NSDictionary without accepting nil, even when
|
|
92
|
+
// the credential has no access-control prompt. Reconstruct that required
|
|
93
|
+
// normalization here without evaluating the React-facing wrapper.
|
|
94
|
+
const nativeOptions = (key, mutation) => Object.freeze({
|
|
95
|
+
...(mutation ? { accessible, securityLevel } : {}),
|
|
96
|
+
authenticationPrompt: AUTHENTICATION_PROMPT,
|
|
97
|
+
cloudSync: false,
|
|
98
|
+
service: `${prefix}:${key}`,
|
|
99
|
+
});
|
|
100
|
+
return createSecureStorage({
|
|
101
|
+
async getItem(key) {
|
|
102
|
+
const selectedOptions = nativeOptions(key, false);
|
|
103
|
+
return decodeReadResult(await getGenericPasswordForOptions(selectedOptions), selectedOptions.service);
|
|
104
|
+
},
|
|
105
|
+
async setItem(key, secret) {
|
|
106
|
+
const selectedOptions = nativeOptions(key, true);
|
|
107
|
+
decodeMutationResult(await setGenericPasswordForOptions(selectedOptions, ACCOUNT, `${ENCODED_VALUE_PREFIX}${secret}`), selectedOptions.service);
|
|
108
|
+
},
|
|
109
|
+
async removeItem(key) {
|
|
110
|
+
const selectedOptions = nativeOptions(key, false);
|
|
111
|
+
const result = await resetGenericPasswordForOptions(selectedOptions);
|
|
112
|
+
if (result !== true) {
|
|
113
|
+
throw new TypeError("React Native Keychain 10 reset did not confirm credential removal.");
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=keychain-10.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keychain-10.js","sourceRoot":"","sources":["../src/keychain-10.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAsB,MAAM,YAAY,CAAC;AAErE,MAAM,CAAC,MAAM,qCAAqC,GAAG,EAAE,CAAC;AAExD,MAAM,OAAO,GAAG,gCAAgC,CAAC;AACjD,MAAM,oBAAoB,GAAG,kBAAkB,CAAC;AAChD,MAAM,qBAAqB,GAAG,MAAM,CAAC,MAAM,CAAC;IAC1C,MAAM,EAAE,QAAQ;IAChB,KAAK,EAAE,iCAAiC;CACzC,CAAC,CAAC;AAiCH,SAAS,MAAM,CACb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L,OAAO,mBAAmB,CAAC;QACzB,KAAK,CAAC,OAAO,CAAC,GAAG;YACf,MAAM,eAAe,GAAG,aAAa,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;YAClD,OAAO,gBAAgB,CACrB,MAAM,4BAA4B,CAAC,eAAe,CAAC,EACnD,eAAe,CAAC,OAAO,CACxB,CAAC;QACJ,CAAC;QACD,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM;YACvB,MAAM,eAAe,GAAG,aAAa,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;YACjD,oBAAoB,CAClB,MAAM,4BAA4B,CAChC,eAAe,EACf,OAAO,EACP,GAAG,oBAAoB,GAAG,MAAM,EAAE,CACnC,EACD,eAAe,CAAC,OAAO,CACxB,CAAC;QACJ,CAAC;QACD,KAAK,CAAC,UAAU,CAAC,GAAG;YAClB,MAAM,eAAe,GAAG,aAAa,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;YAClD,MAAM,MAAM,GAAG,MAAM,8BAA8B,CAAC,eAAe,CAAC,CAAC;YACrE,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;gBACpB,MAAM,IAAI,SAAS,CACjB,oEAAoE,CACrE,CAAC;YACJ,CAAC;QACH,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type Keychain10SecureStorageOptions } from "./keychain-10.js";
|
|
2
|
+
import type { SecureStorage } from "./index.js";
|
|
3
|
+
/**
|
|
4
|
+
* Resolves react-native-keychain 10 through React Native 0.87's native registry.
|
|
5
|
+
* The registry intentionally falls back to legacy bridge modules because the
|
|
6
|
+
* dependency publishes no discoverable TurboModule schema.
|
|
7
|
+
*/
|
|
8
|
+
export declare function createReactNativeSecureStorage(options: Keychain10SecureStorageOptions): SecureStorage;
|
|
9
|
+
export type { Keychain10SecureStorageOptions, SecureStorage };
|
|
10
|
+
//# sourceMappingURL=react-native.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react-native.d.ts","sourceRoot":"","sources":["../src/react-native.ts"],"names":[],"mappings":"AAMA,OAAO,EAEL,KAAK,8BAA8B,EAEpC,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAahD;;;;GAIG;AACH,wBAAgB,8BAA8B,CAC5C,OAAO,EAAE,8BAA8B,GACtC,aAAa,CASf;AAED,YAAY,EAAE,8BAA8B,EAAE,aAAa,EAAE,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { get, getEnforcing, } from "react-native/Libraries/TurboModule/TurboModuleRegistry";
|
|
2
|
+
import { assertVerifiedReactNativePlatform } from "@solidnative-dev/react-native-compat";
|
|
3
|
+
import { createKeychain10SecureStorage, } from "./keychain-10.js";
|
|
4
|
+
function assertPlatform() {
|
|
5
|
+
assertVerifiedReactNativePlatform(getEnforcing("PlatformConstants").getConstants(), "Secure storage");
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Resolves react-native-keychain 10 through React Native 0.87's native registry.
|
|
9
|
+
* The registry intentionally falls back to legacy bridge modules because the
|
|
10
|
+
* dependency publishes no discoverable TurboModule schema.
|
|
11
|
+
*/
|
|
12
|
+
export function createReactNativeSecureStorage(options) {
|
|
13
|
+
assertPlatform();
|
|
14
|
+
const module = get("RNKeychainManager");
|
|
15
|
+
if (module === null) {
|
|
16
|
+
throw new Error("The react-native-keychain 10 RNKeychainManager native module is unavailable.");
|
|
17
|
+
}
|
|
18
|
+
return createKeychain10SecureStorage(module, options);
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=react-native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react-native.js","sourceRoot":"","sources":["../src/react-native.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,GAAG,EACH,YAAY,GACb,MAAM,wDAAwD,CAAC;AAChE,OAAO,EAAE,iCAAiC,EAAE,MAAM,sCAAsC,CAAC;AAEzF,OAAO,EACL,6BAA6B,GAG9B,MAAM,kBAAkB,CAAC;AAO1B,SAAS,cAAc;IACrB,iCAAiC,CAC/B,YAAY,CAA0B,mBAAmB,CAAC,CAAC,YAAY,EAAE,EACzE,gBAAgB,CACjB,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,8BAA8B,CAC5C,OAAuC;IAEvC,cAAc,EAAE,CAAC;IACjB,MAAM,MAAM,GAAG,GAAG,CAA8B,mBAAmB,CAAC,CAAC;IACrE,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CACb,8EAA8E,CAC/E,CAAC;IACJ,CAAC;IACD,OAAO,6BAA6B,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AACxD,CAAC"}
|
package/dist/solid.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { SecureStorage } from "./index.js";
|
|
2
|
+
export declare class SecureStorageOwnerDisposedError extends Error {
|
|
3
|
+
constructor();
|
|
4
|
+
}
|
|
5
|
+
/** Owns private storage settlements and carries them into Solid causality. */
|
|
6
|
+
export declare function createSecureStorageController(storage: SecureStorage): SecureStorage;
|
|
7
|
+
export type { SecureStorage } from "./index.js";
|
|
8
|
+
//# sourceMappingURL=solid.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"solid.d.ts","sourceRoot":"","sources":["../src/solid.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD,qBAAa,+BAAgC,SAAQ,KAAK;;CAKzD;AAwBD,8EAA8E;AAC9E,wBAAgB,6BAA6B,CAC3C,OAAO,EAAE,aAAa,GACrB,aAAa,CAmFf;AAED,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/solid.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { createCausalPlatformEventHandler, retainCausalPlatformEvent, } from "@solidnative-dev/core";
|
|
2
|
+
import { getOwner, onCleanup } from "solid-js";
|
|
3
|
+
export class SecureStorageOwnerDisposedError extends Error {
|
|
4
|
+
constructor() {
|
|
5
|
+
super("The Solid owner was disposed before secure storage settled.");
|
|
6
|
+
this.name = "SecureStorageOwnerDisposedError";
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
function finishPromiseSettlement(event) {
|
|
10
|
+
if (event.state !== "active")
|
|
11
|
+
return;
|
|
12
|
+
try {
|
|
13
|
+
event.run(() => undefined);
|
|
14
|
+
event.finish();
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
event.fail(error);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function settleInsideEvent(settlement, value) {
|
|
21
|
+
return retainCausalPlatformEvent(undefined, (event) => {
|
|
22
|
+
settlement.resolve(value);
|
|
23
|
+
void Promise.resolve().then(() => finishPromiseSettlement(event));
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
/** Owns private storage settlements and carries them into Solid causality. */
|
|
27
|
+
export function createSecureStorageController(storage) {
|
|
28
|
+
if (typeof storage !== "object" ||
|
|
29
|
+
storage === null ||
|
|
30
|
+
typeof storage.getItem !== "function" ||
|
|
31
|
+
typeof storage.setItem !== "function" ||
|
|
32
|
+
typeof storage.removeItem !== "function") {
|
|
33
|
+
throw new TypeError("A Solid secure-storage controller requires a SecureStorage service.");
|
|
34
|
+
}
|
|
35
|
+
if (getOwner() === null) {
|
|
36
|
+
throw new Error("createSecureStorageController requires an active Solid owner.");
|
|
37
|
+
}
|
|
38
|
+
let active = true;
|
|
39
|
+
const pending = new Set();
|
|
40
|
+
const settleRead = createCausalPlatformEventHandler("platform.secure-storage.read", (settleInsideEvent), { priority: "default" });
|
|
41
|
+
const settleWrite = createCausalPlatformEventHandler("platform.secure-storage.write", (settleInsideEvent), { priority: "default" });
|
|
42
|
+
const settleRemove = createCausalPlatformEventHandler("platform.secure-storage.remove", (settleInsideEvent), { priority: "default" });
|
|
43
|
+
const invoke = (operation, settle) => {
|
|
44
|
+
if (!active)
|
|
45
|
+
return Promise.reject(new SecureStorageOwnerDisposedError());
|
|
46
|
+
return new Promise((resolve, reject) => {
|
|
47
|
+
const settlement = { reject, resolve };
|
|
48
|
+
pending.add(settlement);
|
|
49
|
+
let result;
|
|
50
|
+
try {
|
|
51
|
+
result = operation();
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
pending.delete(settlement);
|
|
55
|
+
reject(error);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
void Promise.resolve(result).then((value) => {
|
|
59
|
+
if (!pending.delete(settlement))
|
|
60
|
+
return;
|
|
61
|
+
settle(settlement, value);
|
|
62
|
+
}, (error) => {
|
|
63
|
+
if (!pending.delete(settlement))
|
|
64
|
+
return;
|
|
65
|
+
reject(error);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
onCleanup(() => {
|
|
70
|
+
if (!active)
|
|
71
|
+
return;
|
|
72
|
+
active = false;
|
|
73
|
+
const error = new SecureStorageOwnerDisposedError();
|
|
74
|
+
for (const settlement of pending)
|
|
75
|
+
settlement.reject(error);
|
|
76
|
+
pending.clear();
|
|
77
|
+
});
|
|
78
|
+
return Object.freeze({
|
|
79
|
+
getItem(key) {
|
|
80
|
+
return invoke(() => storage.getItem(key), settleRead);
|
|
81
|
+
},
|
|
82
|
+
setItem(key, value) {
|
|
83
|
+
return invoke(() => storage.setItem(key, value), settleWrite);
|
|
84
|
+
},
|
|
85
|
+
removeItem(key) {
|
|
86
|
+
return invoke(() => storage.removeItem(key), settleRemove);
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=solid.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"solid.js","sourceRoot":"","sources":["../src/solid.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gCAAgC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|
+
"version": "0.1.0-alpha.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Bounded device credential storage with Solid-owned asynchronous settlements.",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"homepage": "https://solidnative.dev",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/solid-native/solid-native.git",
|
|
11
|
+
"directory": "packages/secure-storage"
|
|
12
|
+
},
|
|
13
|
+
"publishConfig": {
|
|
14
|
+
"access": "public"
|
|
15
|
+
},
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": "^22.13.0 || ^24.3.0 || >=26.0.0"
|
|
18
|
+
},
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"default": "./dist/index.js"
|
|
23
|
+
},
|
|
24
|
+
"./keychain-10": {
|
|
25
|
+
"types": "./dist/keychain-10.d.ts",
|
|
26
|
+
"default": "./dist/keychain-10.js"
|
|
27
|
+
},
|
|
28
|
+
"./react-native": {
|
|
29
|
+
"types": "./dist/react-native.d.ts",
|
|
30
|
+
"default": "./dist/react-native.js"
|
|
31
|
+
},
|
|
32
|
+
"./solid": {
|
|
33
|
+
"types": "./dist/solid.d.ts",
|
|
34
|
+
"default": "./dist/solid.js"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"files": [
|
|
38
|
+
"dist/index.d.ts",
|
|
39
|
+
"dist/index.d.ts.map",
|
|
40
|
+
"dist/index.js",
|
|
41
|
+
"dist/index.js.map",
|
|
42
|
+
"dist/keychain-10.d.ts",
|
|
43
|
+
"dist/keychain-10.d.ts.map",
|
|
44
|
+
"dist/keychain-10.js",
|
|
45
|
+
"dist/keychain-10.js.map",
|
|
46
|
+
"dist/react-native.d.ts",
|
|
47
|
+
"dist/react-native.d.ts.map",
|
|
48
|
+
"dist/react-native.js",
|
|
49
|
+
"dist/react-native.js.map",
|
|
50
|
+
"dist/solid.d.ts",
|
|
51
|
+
"dist/solid.d.ts.map",
|
|
52
|
+
"dist/solid.js",
|
|
53
|
+
"dist/solid.js.map"
|
|
54
|
+
],
|
|
55
|
+
"dependencies": {
|
|
56
|
+
"@solidnative-dev/core": "0.1.0-alpha.0",
|
|
57
|
+
"@solidnative-dev/react-native-compat": "0.1.0-alpha.0"
|
|
58
|
+
},
|
|
59
|
+
"peerDependencies": {
|
|
60
|
+
"solid-js": "2.0.4"
|
|
61
|
+
},
|
|
62
|
+
"devDependencies": {
|
|
63
|
+
"solid-js": "2.0.4"
|
|
64
|
+
},
|
|
65
|
+
"scripts": {
|
|
66
|
+
"build": "tsc -p tsconfig.json",
|
|
67
|
+
"check": "tsc -p tsconfig.json --noEmit",
|
|
68
|
+
"test": "pnpm build && node --conditions=browser --test test/*.test.mjs"
|
|
69
|
+
}
|
|
6
70
|
}
|