@onekeyfe/react-native-keychain-module 6.7.0-alpha.475 → 6.8.0-11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +101 -31
  2. package/package.json +2 -1
package/README.md CHANGED
@@ -1,9 +1,35 @@
1
+ <div align="center">
2
+
1
3
  # @onekeyfe/react-native-keychain-module
2
4
 
3
- An iOS Keychain interface for storing and retrieving string values in OneKey
4
- React Native applications. The native implementation uses the application's
5
- bundle identifier as its service and supports optional iCloud synchronization.
6
- The application owns key naming, data serialization and removal policy.
5
+ **iOS Keychain string storage for OneKey, device-local or iCloud-synchronized.**
6
+
7
+ [![npm](https://img.shields.io/npm/v/%40onekeyfe%2Freact-native-keychain-module?label=npm&color=4D6BFE)](https://www.npmjs.com/package/@onekeyfe/react-native-keychain-module)
8
+ [![license](https://img.shields.io/npm/l/%40onekeyfe%2Freact-native-keychain-module?label=license&color=4D6BFE)](LICENSE)
9
+ ![iOS](https://img.shields.io/badge/iOS-000000?logo=apple&logoColor=white)
10
+ ![Nitro Modules](https://img.shields.io/badge/Nitro_Modules-4D6BFE)
11
+
12
+ </div>
13
+
14
+ Stores, reads, checks and removes string values in the iOS Keychain through a
15
+ small Nitro HybridObject. Items are generic passwords in the application's
16
+ bundle-identifier service, stored with `kSecAttrAccessibleWhenUnlocked`, and can
17
+ be made synchronizable across the user's devices. This is an iOS package: the
18
+ Android binding in the package is a stub that persists nothing. Key naming,
19
+ value serialization and removal policy belong to the application.
20
+
21
+ ## Features
22
+
23
+ - **Upsert semantics** — `setItem` adds a new item or updates the existing one
24
+ in place, with no delete-then-add race window.
25
+ - **Per-item sync choice** — `enableSync` selects iCloud-synchronizable storage;
26
+ pass `false` to keep a value on this device only.
27
+ - **Local and synced lookups** — `getItem`, `hasItem` and `removeItem` match
28
+ synchronizable and non-synchronizable items alike.
29
+ - **Availability probe** — `isICloudSyncEnabled()` reports whether the app can
30
+ actually write a synchronizable item right now.
31
+ - **Typed parameters** — exported `SetItemParams`, `GetItemParams` and result
32
+ types keep consumer adapters type-safe.
7
33
 
8
34
  ## Installation
9
35
 
@@ -11,9 +37,18 @@ The application owns key naming, data serialization and removal policy.
11
37
  yarn add @onekeyfe/react-native-keychain-module react-native-nitro-modules
12
38
  ```
13
39
 
14
- Install the application's iOS pods and rebuild the native application. iCloud
15
- Keychain availability depends on the device account and application entitlement
16
- configuration; this package does not configure either of those.
40
+ Install the native peer packages this package links as well:
41
+
42
+ ```sh
43
+ yarn add @onekeyfe/react-native-native-logger
44
+ ```
45
+
46
+ This is an iOS-native package. Install the application's iOS pods and rebuild
47
+ the native binary; a JavaScript-only update does not register the module.
48
+
49
+ iCloud Keychain synchronization needs the app's iCloud Keychain entitlement and
50
+ a signed-in iCloud account. This package configures neither; when either is
51
+ missing, synchronizable writes fail and `isICloudSyncEnabled()` returns `false`.
17
52
 
18
53
  ## Usage
19
54
 
@@ -23,41 +58,76 @@ import { KeychainModule } from '@onekeyfe/react-native-keychain-module';
23
58
  await KeychainModule.setItem({
24
59
  key: 'example.preference',
25
60
  value: 'enabled',
26
- enableSync: false,
61
+ enableSync: true,
62
+ label: 'Example preference',
27
63
  });
64
+
28
65
  const item = await KeychainModule.getItem({ key: 'example.preference' });
66
+ if (item) {
67
+ // item.value is the stored string.
68
+ }
69
+
29
70
  await KeychainModule.removeItem({ key: 'example.preference' });
30
71
  ```
31
72
 
32
- ## API and platform behavior
73
+ `enableSync` defaults to `true` on iOS, so omit it only when the value may leave
74
+ the device. Serialize structured values yourself and handle parse failures above
75
+ this storage boundary.
76
+
77
+ ## API
78
+
79
+ | Method | Result | Platforms | Description |
80
+ | --- | --- | :-: | --- |
81
+ | `setItem(params)` | `Promise<void>` | iOS | Stores or updates a string; `enableSync` defaults to `true`, `label`/`description` are optional. |
82
+ | `getItem({ key })` | `Promise<{ key, value } \| null>` | iOS | Returns the item, or `null` when absent. |
83
+ | `hasItem({ key })` | `Promise<boolean>` | iOS | Whether an item exists. |
84
+ | `removeItem({ key })` | `Promise<void>` | iOS | Removes the item; a missing item is not an error. |
85
+ | `isICloudSyncEnabled()` | `Promise<boolean>` | iOS | Probes whether synchronizable Keychain storage is available. |
86
+ | `SetItemParams`, `GetItemParams`, `RemoveItemParams`, `HasItemParams`, `GetItemResult` | types | iOS | Parameter and result types for consumer adapters. |
87
+
88
+ Failures reject as promises. Native failures carry the `OSStatus` code in the
89
+ `NSOSStatusErrorDomain`; encoding and wrapper failures use the
90
+ `keychain_*_error` domains. See
91
+ [`src/KeychainModule.nitro.ts`](src/KeychainModule.nitro.ts) for the complete
92
+ interface.
93
+
94
+ ## Platform support
95
+
96
+ | Capability | iOS | Android | Web |
97
+ | --- | :-: | :-: | :-: |
98
+ | Persist a string in the Keychain | ✅ | — | — |
99
+ | Read, check and remove items | ✅ | — | — |
100
+ | iCloud-synchronizable items | ✅ with entitlement | — | — |
101
+ | `isICloudSyncEnabled()` probe | ✅ | — | — |
102
+
103
+ On Android the module compiles as a stub: writes and removals resolve without
104
+ persisting, reads return `null`, and existence/sync checks return `false`. Do not
105
+ use it as Android secure storage.
33
106
 
34
- | Method | Result |
35
- | --- | --- |
36
- | `setItem(params)` | Store a string; accepts optional sync, label and description. |
37
- | `getItem({ key })` | Return `{ key, value }` or `null` when absent. |
38
- | `hasItem({ key })` | Return whether an item exists. |
39
- | `removeItem({ key })` | Remove the item. |
40
- | `isICloudSyncEnabled()` | Probe whether synchronizable Keychain storage is available. |
107
+ ## Caveats
41
108
 
42
- On iOS, omitted `enableSync` defaults to `true`; pass it explicitly when storage
43
- must remain local. Handle Keychain errors as promise rejections.
44
- Android is a stub: writes/removals resolve without persistence, reads return
45
- `null`, and existence/sync checks return `false`. Do not use this package as
46
- Android secure storage or infer a successful backup from a resolved stub call.
109
+ > [!IMPORTANT]
110
+ > `enableSync` defaults to `true`. Omit it and an item is eligible to sync to the
111
+ > user's other devices through iCloud Keychain. Pass `enableSync: false`
112
+ > explicitly for device-local secrets.
47
113
 
48
- The complete types are in [src/KeychainModule.nitro.ts](src/KeychainModule.nitro.ts).
114
+ > [!WARNING]
115
+ > The Android binding is a stub with no persistence: a resolved `setItem` or
116
+ > `removeItem` proves nothing. Keep Android secure-storage code out of this
117
+ > package, and never infer a successful backup from a stub call.
49
118
 
50
- ## Handling absent values
119
+ > [!NOTE]
120
+ > `getItem` returns an object, not the string, and an empty-string value is a
121
+ > present value. `hasItem` is a separate promise and cannot make a later read
122
+ > atomic.
51
123
 
52
- `getItem({ key })` returns an object, not the stored string directly. Check for
53
- `null` before reading `item.value`; an empty stored string remains a present
54
- value. `hasItem` is a separate promise and cannot make a later read atomic.
124
+ ## References
55
125
 
56
- `SetItemParams` contains `key`, `value` and optional `enableSync`, `label` and
57
- `description`. The package exports these parameter/result types for consumer
58
- adapters. Serialize structured application values explicitly and handle parse
59
- failures outside the native storage boundary.
126
+ - [Native interface](src/KeychainModule.nitro.ts)
127
+ - [Example page](../../example/react-native/pages/KeychainTestPage.tsx)
128
+ - [npm package](https://www.npmjs.com/package/@onekeyfe/react-native-keychain-module)
129
+ - [Changelog](../../CHANGELOG.md)
60
130
 
61
131
  ## License
62
132
 
63
- MIT.
133
+ MIT. See [LICENSE](LICENSE).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/react-native-keychain-module",
3
- "version": "6.7.0-alpha.475",
3
+ "version": "6.8.0-11",
4
4
  "description": "iOS Keychain string storage with optional iCloud synchronization for OneKey",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",
@@ -90,6 +90,7 @@
90
90
  "typescript": "^5.9.2"
91
91
  },
92
92
  "peerDependencies": {
93
+ "@onekeyfe/react-native-native-logger": "*",
93
94
  "react": "*",
94
95
  "react-native": "*",
95
96
  "react-native-nitro-modules": "0.37.0"