@octane-xplat/secure-storage 0.0.0-stage → 0.9.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 +33 -2
- package/package.json +66 -3
- package/src/index.macos.ts +2 -0
- package/src/index.ts +2 -0
- package/src/secure-storage.linux.ts +2 -0
- package/src/secure-storage.macos.ts +9 -0
- package/src/secure-storage.ts +17 -0
- package/src/secure-storage.web.ts +23 -0
- package/src/types.ts +13 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Alec Larson
|
|
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
|
|
13
|
+
all 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
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,34 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@octane-xplat/secure-storage`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Keychain/Keystore-backed secret storage for Octane xplat apps. iOS writes
|
|
4
|
+
to the Keychain and Android to the Keystore via
|
|
5
|
+
`@nativescript/secure-storage`; Linux goes through the desktop host bridge
|
|
6
|
+
to the Secret Service API (`org.freedesktop.secrets`); web and the macOS
|
|
7
|
+
AppKit dev host report `supported: false` — IndexedDB and NSUserDefaults
|
|
8
|
+
are not a trust boundary, so the leaf refuses to pretend.
|
|
9
|
+
|
|
10
|
+
```sh
|
|
11
|
+
pnpm add @octane-xplat/secure-storage
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
import { secureStorage } from '@octane-xplat/secure-storage'
|
|
16
|
+
|
|
17
|
+
if (secureStorage.supported) {
|
|
18
|
+
const store = secureStorage.impl!
|
|
19
|
+
await store.set('session-token', token)
|
|
20
|
+
const token = await store.get('session-token')
|
|
21
|
+
await store.remove('session-token')
|
|
22
|
+
}
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
The shared capability contract: `supported` reports whether an
|
|
26
|
+
implementation exists on this target — branch on it rather than catching —
|
|
27
|
+
`ensure()` resolves the permission/availability state, and `impl` is an
|
|
28
|
+
async string key-value store (`get` / `set` / `remove`).
|
|
29
|
+
|
|
30
|
+
For non-secret preferences, use `storage` from
|
|
31
|
+
[`@octane-xplat/platform`](../platform/README.md) instead.
|
|
32
|
+
|
|
33
|
+
Guide: [Using device features](../../docs/platform-services.md);
|
|
34
|
+
per-target availability: [platform notes](../../docs/platform-notes.md).
|
package/package.json
CHANGED
|
@@ -1,6 +1,69 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@octane-xplat/secure-storage",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.9.0",
|
|
4
|
+
"description": "Keychain/Keystore-backed secure storage for Octane xplat — matching web + NativeScript implementations",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"android",
|
|
7
|
+
"cross-platform",
|
|
8
|
+
"ios",
|
|
9
|
+
"keychain",
|
|
10
|
+
"keystore",
|
|
11
|
+
"nativescript",
|
|
12
|
+
"octane",
|
|
13
|
+
"secure-storage",
|
|
14
|
+
"web",
|
|
15
|
+
"xplat"
|
|
16
|
+
],
|
|
17
|
+
"homepage": "https://github.com/octane-xplat/octane-xplat/tree/main/packages/secure-storage",
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "https://github.com/octane-xplat/octane-xplat",
|
|
22
|
+
"directory": "packages/secure-storage"
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"src"
|
|
26
|
+
],
|
|
27
|
+
"type": "module",
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"macos": "./src/index.macos.ts",
|
|
31
|
+
"default": "./src/index.ts"
|
|
32
|
+
},
|
|
33
|
+
"./*": "./src/*"
|
|
34
|
+
},
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@nativescript/secure-storage": "4.0.2",
|
|
40
|
+
"@octane-xplat/platform": "0.9.0"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@nativescript-community/octane": "0.2.4",
|
|
44
|
+
"@nativescript/core": "9.1.2",
|
|
45
|
+
"octane": "0.6.3"
|
|
46
|
+
},
|
|
47
|
+
"peerDependencies": {
|
|
48
|
+
"@nativescript-community/octane": ">=0.2.1 <1",
|
|
49
|
+
"@nativescript/core": ">=9.1.0 <10",
|
|
50
|
+
"octane": ">=0.6.3 <1"
|
|
51
|
+
},
|
|
52
|
+
"peerDependenciesMeta": {
|
|
53
|
+
"@nativescript-community/octane": {
|
|
54
|
+
"optional": true
|
|
55
|
+
},
|
|
56
|
+
"@nativescript/core": {
|
|
57
|
+
"optional": true
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
"nativescript": {
|
|
61
|
+
"platforms": {
|
|
62
|
+
"android": "9.1.0",
|
|
63
|
+
"ios": "9.1.0"
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
"scripts": {
|
|
67
|
+
"test:packed": "node tests/packed-consumer.mjs"
|
|
68
|
+
}
|
|
6
69
|
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Secure storage — AppKit host leaf. The dev host exposes NSUserDefaults,
|
|
2
|
+
// which is not a trust boundary, so the capability stays unsupported.
|
|
3
|
+
import type { Capability, SecureStore } from './types'
|
|
4
|
+
|
|
5
|
+
export const secureStorage: Capability<SecureStore> = {
|
|
6
|
+
supported: false,
|
|
7
|
+
ensure: async () => 'unsupported',
|
|
8
|
+
impl: null,
|
|
9
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Secure storage — Keychain (iOS) / Keystore (Android) via plugin.
|
|
2
|
+
import { SecureStorage } from '@nativescript/secure-storage'
|
|
3
|
+
import type { Capability } from './types'
|
|
4
|
+
import type { SecureStore } from './types'
|
|
5
|
+
|
|
6
|
+
const store = new SecureStorage()
|
|
7
|
+
|
|
8
|
+
export const secureStorage: Capability<SecureStore> = {
|
|
9
|
+
supported: true,
|
|
10
|
+
// No runtime permission needed — Keychain/Keystore is device-owned.
|
|
11
|
+
ensure: async () => 'granted',
|
|
12
|
+
impl: {
|
|
13
|
+
get: (key) => store.get({ key }).then((v) => v ?? null),
|
|
14
|
+
set: (key, value) => store.set({ key, value }),
|
|
15
|
+
remove: (key) => store.remove({ key }),
|
|
16
|
+
},
|
|
17
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Secure storage — plain web has no equivalent trust boundary. Desktop
|
|
2
|
+
// webview hosts can provide one through the typed host bridge.
|
|
3
|
+
import { desktopHost } from '@octane-xplat/platform/host/web'
|
|
4
|
+
import type { Capability, SecureStore } from './types'
|
|
5
|
+
|
|
6
|
+
const hostStore: SecureStore = {
|
|
7
|
+
get: (key) => desktopHost()?.secureStorage.get(key) ?? Promise.resolve(null),
|
|
8
|
+
set: (key, value) => desktopHost()?.secureStorage.set(key, value) ?? Promise.resolve(false),
|
|
9
|
+
remove: (key) => desktopHost()?.secureStorage.remove(key) ?? Promise.resolve(false),
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const secureStorage: Capability<SecureStore> = {
|
|
13
|
+
get supported() {
|
|
14
|
+
return desktopHost() !== null
|
|
15
|
+
},
|
|
16
|
+
async ensure() {
|
|
17
|
+
const host = desktopHost()
|
|
18
|
+
return host && (await host.supports('secureStorage', 'get')) ? 'granted' : 'unsupported'
|
|
19
|
+
},
|
|
20
|
+
get impl() {
|
|
21
|
+
return desktopHost() ? hostStore : null
|
|
22
|
+
},
|
|
23
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Optional capability — never throws for absence (docs/platform-services.md). */
|
|
2
|
+
export interface Capability<T> {
|
|
3
|
+
supported: boolean
|
|
4
|
+
ensure(): Promise<'granted' | 'denied' | 'unsupported'>
|
|
5
|
+
/** usable iff supported && ensured */
|
|
6
|
+
impl: T | null
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface SecureStore {
|
|
10
|
+
get(key: string): Promise<string | null>
|
|
11
|
+
set(key: string, value: string): Promise<boolean>
|
|
12
|
+
remove(key: string): Promise<boolean>
|
|
13
|
+
}
|