@octane-xplat/biometrics 0.17.1 → 0.19.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 CHANGED
@@ -1,47 +1,49 @@
1
1
  # `@octane-xplat/biometrics`
2
2
 
3
- ```sh
4
- pnpm add @octane-xplat/biometrics
5
- ```
6
-
7
3
  Local biometric verification — Face ID / Touch ID / fingerprint or device
8
4
  credential — behind one capability object. iOS and Android run
9
5
  `@nativescript/biometrics`; macOS AppKit uses Apple LocalAuthentication
10
6
  for Touch ID. Web reports `supported: false` because WebAuthn requires
11
7
  a registered credential and an authentication ceremony.
12
8
 
9
+ ```sh
10
+ bun add @octane-xplat/biometrics
11
+ ```
12
+
13
13
  ```ts
14
14
  import { biometrics } from '@octane-xplat/biometrics'
15
15
 
16
- if ((await biometrics.ensure()) === 'granted') {
17
- const ok = await biometrics.impl!.verify('Unlock your saved trips')
16
+ if ((await biometrics.requestPermissions()).granted) {
17
+ const ok = await biometrics.verify('Unlock your saved trips')
18
18
  }
19
19
  ```
20
20
 
21
- The shared capability contract: `supported` reports whether an
21
+ The shared service contract: `supported` reports whether an
22
22
  implementation exists on this target — branch on it rather than catching —
23
- `ensure()` resolves `'granted' | 'denied' | 'unsupported'`, and `impl` is
24
- the service once usable. `verify(reason)` resolves `false` for a declined
23
+ `getPermissions()`/`requestPermissions()` resolve
24
+ `{status: 'granted' | 'denied' | 'unsupported', granted, canAskAgain}`.
25
+ `verify(reason)` resolves `false` for a declined
25
26
  or failed prompt rather than throwing.
26
27
 
27
28
  On macOS, availability checks do not open a prompt. Missing hardware,
28
29
  enrollment, pairing, or a connected sensor returns `unsupported`; lockout
29
30
  or an interaction restriction returns `denied`. A host without the Objective-C
30
- LocalAuthentication bridge reports `supported: false` and `impl: null`.
31
+ LocalAuthentication bridge reports `supported: false` and `verify()` rejects
32
+ `UnavailabilityError`.
31
33
  Verification uses biometrics only, hides password fallback, and returns
32
34
  `false` on cancellation, failure, or an overlapping prompt.
33
35
 
34
36
  ```ts
35
37
  import { biometrics } from '@octane-xplat/biometrics'
36
38
 
37
- const availability = await biometrics.ensure()
38
- if (availability === 'granted') {
39
- const verified = await biometrics.impl!.verify('Unlock your saved trips')
39
+ const availability = await biometrics.requestPermissions()
40
+ if (availability.granted) {
41
+ const verified = await biometrics.verify('Unlock your saved trips')
40
42
  console.log(verified ? 'Unlocked' : 'Still locked')
41
43
  }
42
44
  ```
43
45
 
44
- Guide: [Using device features](../../docs/platform/platform-services.md);
45
- per-target availability: [platform notes](../../.agents/docs/notes/platform-notes.md).
46
+ Guide: [Using device features](https://octane-xplat.goddardai.org/platform-services);
47
+ per-target availability: [platform notes](https://github.com/octane-xplat/octane-xplat/blob/main/.agents/docs/notes/platform-notes.md).
46
48
  Exercised by the harness `Services` screen
47
- ([`packages/app/src/Services.tsrx`](../app/src/Services.tsrx)).
49
+ ([`packages/app/src/Services.tsrx`](https://github.com/octane-xplat/octane-xplat/blob/main/packages/app/src/Services.tsrx)).
package/package.json CHANGED
@@ -1,91 +1,90 @@
1
1
  {
2
- "name": "@octane-xplat/biometrics",
3
- "version": "0.17.1",
4
- "description": "Biometric verification (FaceID/TouchID/fingerprint) for Octane xplat — matching web + NativeScript implementations",
5
- "keywords": [
6
- "android",
7
- "biometrics",
8
- "cross-platform",
9
- "faceid",
10
- "fingerprint",
11
- "ios",
12
- "nativescript",
13
- "octane",
14
- "touchid",
15
- "web",
16
- "xplat"
17
- ],
18
- "homepage": "https://github.com/octane-xplat/octane-xplat/tree/main/packages/biometrics",
19
- "license": "MIT",
20
- "repository": {
21
- "type": "git",
22
- "url": "https://github.com/octane-xplat/octane-xplat",
23
- "directory": "packages/biometrics"
24
- },
25
- "files": [
26
- "src",
27
- "types",
28
- "!src/**/*.test.*",
29
- "!src/**/*.spec.*"
30
- ],
31
- "type": "module",
32
- "exports": {
33
- ".": {
34
- "macos": {
35
- "types": "./types/generated/index.macos.d.ts",
36
- "default": "./src/index.macos.ts"
37
- },
38
- "types": "./types/generated/index.d.ts",
39
- "default": "./src/index.ts"
40
- },
41
- "./*": {
42
- "types": "./types/generated/*.d.ts",
43
- "default": "./src/*"
44
- },
45
- "./*.ts": {
46
- "types": "./types/generated/*.d.ts",
47
- "default": "./src/*.ts"
48
- }
49
- },
50
- "publishConfig": {
51
- "access": "public"
52
- },
53
- "dependencies": {
54
- "@nativescript/biometrics": "1.3.1"
55
- },
56
- "devDependencies": {
57
- "@nativescript-community/octane": "0.2.5",
58
- "@nativescript/core": "9.1.3",
59
- "@nativescript/types": "9.1.4",
60
- "@tsrx/typescript-plugin": "0.4.11",
61
- "octane": "0.14.0",
62
- "tsrx-typegen": "0.4.0",
63
- "typescript": "5.9.3"
64
- },
65
- "peerDependencies": {
66
- "@nativescript-community/octane": ">=0.2.1 <1",
67
- "@nativescript/core": ">=9.1.0 <10",
68
- "octane": ">=0.6.3 <1"
69
- },
70
- "peerDependenciesMeta": {
71
- "@nativescript-community/octane": {
72
- "optional": true
73
- },
74
- "@nativescript/core": {
75
- "optional": true
76
- }
77
- },
78
- "nativescript": {
79
- "platforms": {
80
- "android": "9.1.0",
81
- "ios": "9.1.0"
82
- }
83
- },
84
- "scripts": {
85
- "test:packed": "node tests/packed-consumer.mjs",
86
- "test": "node --test tests/*.test.mjs",
87
- "test:macos-runtime": "node ../../apps/macos/test/verify-biometrics.mjs",
88
- "typegen": "tsrx-typegen --project tsconfig.types.json",
89
- "pack:check": "tsrx-typegen --pack-check"
90
- }
91
- }
2
+ "name": "@octane-xplat/biometrics",
3
+ "version": "0.19.0",
4
+ "description": "Biometric verification (FaceID/TouchID/fingerprint) for Octane xplat — matching web + NativeScript implementations",
5
+ "keywords": [
6
+ "android",
7
+ "biometrics",
8
+ "cross-platform",
9
+ "faceid",
10
+ "fingerprint",
11
+ "ios",
12
+ "nativescript",
13
+ "octane",
14
+ "touchid",
15
+ "web",
16
+ "xplat"
17
+ ],
18
+ "homepage": "https://github.com/octane-xplat/octane-xplat/tree/main/packages/biometrics",
19
+ "license": "MIT",
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "https://github.com/octane-xplat/octane-xplat",
23
+ "directory": "packages/biometrics"
24
+ },
25
+ "files": [
26
+ "src",
27
+ "types",
28
+ "!src/**/*.test.*",
29
+ "!src/**/*.spec.*"
30
+ ],
31
+ "type": "module",
32
+ "exports": {
33
+ ".": {
34
+ "types": "./types/generated/index.d.ts",
35
+ "macos": "./src/index.macos.ts",
36
+ "default": "./src/index.ts"
37
+ },
38
+ "./*": {
39
+ "types": "./types/generated/*.d.ts",
40
+ "default": "./src/*"
41
+ },
42
+ "./*.ts": {
43
+ "types": "./types/generated/*.d.ts",
44
+ "default": "./src/*.ts"
45
+ }
46
+ },
47
+ "publishConfig": {
48
+ "access": "public"
49
+ },
50
+ "scripts": {
51
+ "test:packed": "node tests/packed-consumer.mjs",
52
+ "test": "node --test tests/*.test.mjs",
53
+ "test:macos-runtime": "node ../../apps/macos/test/verify-biometrics.mjs",
54
+ "typegen": "tsrx-typegen --project tsconfig.types.json",
55
+ "prepack": "bun run typegen && tsrx-typegen --pack-check",
56
+ "pack:check": "tsrx-typegen --pack-check"
57
+ },
58
+ "dependencies": {
59
+ "@nativescript/biometrics": "1.3.1",
60
+ "@octane-xplat/lib": "0.19.0"
61
+ },
62
+ "devDependencies": {
63
+ "@nativescript-community/octane": "0.2.5",
64
+ "@nativescript/core": "9.1.3",
65
+ "@nativescript/types": "9.1.4",
66
+ "@tsrx/typescript-plugin": "0.4.11",
67
+ "octane": "0.16.3",
68
+ "tsrx-typegen": "0.5.0",
69
+ "typescript": "5.9.3"
70
+ },
71
+ "peerDependencies": {
72
+ "@nativescript-community/octane": ">=0.2.1 <1",
73
+ "@nativescript/core": ">=9.1.0 <10",
74
+ "octane": ">=0.6.3 <1"
75
+ },
76
+ "peerDependenciesMeta": {
77
+ "@nativescript-community/octane": {
78
+ "optional": true
79
+ },
80
+ "@nativescript/core": {
81
+ "optional": true
82
+ }
83
+ },
84
+ "nativescript": {
85
+ "platforms": {
86
+ "android": "9.1.0",
87
+ "ios": "9.1.0"
88
+ }
89
+ }
90
+ }
@@ -1,5 +1,7 @@
1
1
  // LocalAuthentication through the AppKit host's existing Objective-C bridge.
2
- import type { BiometricsImpl, Capability } from './types'
2
+ import { UnavailabilityError } from '@octane-xplat/lib/capability'
3
+ import type { Permissioned, PermissionResponse } from '@octane-xplat/lib/capability'
4
+ import type { BiometricsImpl } from './types'
3
5
 
4
6
  declare const objc: { import(name: string): void }
5
7
  declare const interop: { Reference: new () => { value?: { domain: string; code: number } } }
@@ -115,26 +117,36 @@ const implementation: BiometricsImpl = {
115
117
  },
116
118
  }
117
119
 
118
- export const biometrics: Capability<BiometricsImpl> = {
119
- get supported() {
120
- return frameworkAvailable()
121
- },
122
- async ensure() {
123
- if (!frameworkAvailable()) {
124
- return 'unsupported'
125
- }
120
+ const ensure = async (): Promise<PermissionResponse> => {
121
+ if (!frameworkAvailable()) {
122
+ return { status: 'unsupported', granted: false, canAskAgain: false }
123
+ }
126
124
 
127
- let context: AuthenticationContext | null = null
128
- try {
129
- context = LAContext.new()
130
- return availability(context)
131
- } catch {
132
- return 'denied'
133
- } finally {
134
- invalidate(context)
125
+ let context: AuthenticationContext | null = null
126
+ try {
127
+ context = LAContext.new()
128
+ const status = availability(context)
129
+ return {
130
+ status,
131
+ granted: status === 'granted',
132
+ canAskAgain: status === 'granted',
135
133
  }
134
+ } catch {
135
+ return { status: 'denied', granted: false, canAskAgain: false }
136
+ } finally {
137
+ invalidate(context)
138
+ }
139
+ }
140
+
141
+ export const biometrics: Permissioned<BiometricsImpl> = {
142
+ get supported() {
143
+ return frameworkAvailable()
136
144
  },
137
- get impl() {
138
- return frameworkAvailable() ? implementation : null
139
- },
145
+ isAvailable: async () => frameworkAvailable(),
146
+ getPermissions: ensure,
147
+ requestPermissions: ensure,
148
+ verify: (reason) =>
149
+ frameworkAvailable()
150
+ ? implementation.verify(reason)
151
+ : Promise.reject(new UnavailabilityError('biometrics')),
140
152
  }
package/src/biometrics.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  import { BiometricAuth } from '@nativescript/biometrics'
3
3
  import type { VerifyBiometricOptions } from '@nativescript/biometrics'
4
4
  import { isIOS } from '@nativescript/core'
5
- import type { Capability } from './types'
5
+ import type { Permissioned, PermissionResponse } from '@octane-xplat/lib/capability'
6
6
  import type { BiometricsImpl } from './types'
7
7
 
8
8
  const bio = new BiometricAuth()
@@ -12,43 +12,51 @@ const bio = new BiometricAuth()
12
12
  // keychain entry on iOS.
13
13
  let verifying = false
14
14
 
15
- export const biometrics: Capability<BiometricsImpl> = {
15
+ const available = async (): Promise<PermissionResponse> => {
16
+ try {
17
+ const r = await bio.available()
18
+ // Android reports `any` for a secure lockscreen without biometrics —
19
+ // verify() requires BIOMETRIC_STRONG, so that state is not usable.
20
+ const usable = !!(r.any && (isIOS || r.biometrics))
21
+ return {
22
+ status: usable ? 'granted' : 'unsupported',
23
+ granted: usable,
24
+ canAskAgain: usable,
25
+ }
26
+ } catch {
27
+ // Android rejects when the device lacks biometric hardware,
28
+ // enrollment, or a secure lockscreen — absence, not an error.
29
+ return { status: 'unsupported', granted: false, canAskAgain: false }
30
+ }
31
+ }
32
+
33
+ /** Biometrics service backed by @nativescript/biometrics. */
34
+ export const biometrics: Permissioned<BiometricsImpl> = {
16
35
  supported: true,
17
- async ensure() {
18
- try {
19
- const r = await bio.available()
20
- // Android reports `any` for a secure lockscreen without biometrics —
21
- // verify() requires BIOMETRIC_STRONG, so that state is not usable.
22
- return r.any && (isIOS || r.biometrics) ? 'granted' : 'unsupported'
23
- } catch {
24
- // Android rejects when the device lacks biometric hardware,
25
- // enrollment, or a secure lockscreen — absence, not an error.
26
- return 'unsupported'
36
+ isAvailable: async () => (await available()).granted,
37
+ getPermissions: available,
38
+ requestPermissions: available,
39
+ async verify(reason) {
40
+ if (verifying) {
41
+ return false
27
42
  }
28
- },
29
- impl: {
30
- async verify(reason) {
31
- if (verifying) {
32
- return false
33
- }
34
43
 
35
- verifying = true
36
- try {
37
- // iOS ignores `title` on its default keychain path — route
38
- // through LAContext (pinFallback selects that path; customFallback
39
- // keeps the biometrics-only policy) so `message` surfaces the
40
- // caller's reason, matching Android's dialog title.
41
- const options: VerifyBiometricOptions = isIOS
42
- ? { title: reason, message: reason, pinFallback: true, ios: { customFallback: true } }
43
- : { title: reason }
44
+ verifying = true
45
+ try {
46
+ // iOS ignores `title` on its default keychain path — route
47
+ // through LAContext (pinFallback selects that path; customFallback
48
+ // keeps the biometrics-only policy) so `message` surfaces the
49
+ // caller's reason, matching Android's dialog title.
50
+ const options: VerifyBiometricOptions = isIOS
51
+ ? { title: reason, message: reason, pinFallback: true, ios: { customFallback: true } }
52
+ : { title: reason }
44
53
 
45
- const r = await bio.verifyBiometric(options)
46
- return r.code === 0
47
- } catch {
48
- return false
49
- } finally {
50
- verifying = false
51
- }
52
- },
54
+ const r = await bio.verifyBiometric(options)
55
+ return r.code === 0
56
+ } catch {
57
+ return false
58
+ } finally {
59
+ verifying = false
60
+ }
53
61
  },
54
62
  }
@@ -2,12 +2,20 @@
2
2
  // standalone local-presence API: it requires an RP challenge and a registered
3
3
  // credential, and may require a user gesture. Do not claim it implements the
4
4
  // native verify(reason) contract by creating an ephemeral passkey.
5
- import type { BiometricsImpl, Capability } from './types'
5
+ import { UnavailabilityError } from '@octane-xplat/lib/capability'
6
+ import type { Permissioned, PermissionResponse } from '@octane-xplat/lib/capability'
7
+ import type { BiometricsImpl } from './types'
6
8
 
7
- export const biometrics: Capability<BiometricsImpl> = {
9
+ const UNSUPPORTED: PermissionResponse = {
10
+ status: 'unsupported',
11
+ granted: false,
12
+ canAskAgain: false,
13
+ }
14
+
15
+ export const biometrics: Permissioned<BiometricsImpl> = {
8
16
  supported: false,
9
- async ensure() {
10
- return 'unsupported'
11
- },
12
- impl: null,
17
+ isAvailable: async () => false,
18
+ getPermissions: async () => UNSUPPORTED,
19
+ requestPermissions: async () => UNSUPPORTED,
20
+ verify: () => Promise.reject(new UnavailabilityError('biometrics')),
13
21
  }
package/src/types.ts CHANGED
@@ -1,11 +1,16 @@
1
- /** Optional capability — never throws for absence (docs/platform/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
-
1
+ /** Biometric verification façade (Face ID / Touch ID / Android BIOMETRIC_STRONG). */
9
2
  export interface BiometricsImpl {
3
+ /** Prompt the user for biometric verification, showing `reason` as the
4
+ * dialog title/message. Resolves false on failure, cancel, or lockout —
5
+ * it does not reject. Only one prompt runs at a time; overlapping calls
6
+ * resolve false immediately rather than queuing. */
10
7
  verify(reason: string): Promise<boolean>
11
8
  }
9
+
10
+ export { UnavailabilityError } from '@octane-xplat/lib/capability'
11
+ export type {
12
+ Permissioned,
13
+ PermissionResponse,
14
+ PermissionStatus,
15
+ Service,
16
+ } from '@octane-xplat/lib/capability'
@@ -1,3 +1,4 @@
1
- import type { Capability } from './types.js';
1
+ import type { Permissioned } from '@octane-xplat/lib/capability';
2
2
  import type { BiometricsImpl } from './types.js';
3
- export declare const biometrics: Capability<BiometricsImpl>;
3
+ /** Biometrics service backed by @nativescript/biometrics. */
4
+ export declare const biometrics: Permissioned<BiometricsImpl>;
@@ -1,2 +1,3 @@
1
- import type { BiometricsImpl, Capability } from './types.js';
2
- export declare const biometrics: Capability<BiometricsImpl>;
1
+ import type { Permissioned } from '@octane-xplat/lib/capability';
2
+ import type { BiometricsImpl } from './types.js';
3
+ export declare const biometrics: Permissioned<BiometricsImpl>;
@@ -1,2 +1,3 @@
1
- import type { BiometricsImpl, Capability } from './types.js';
2
- export declare const biometrics: Capability<BiometricsImpl>;
1
+ import type { Permissioned } from '@octane-xplat/lib/capability';
2
+ import type { BiometricsImpl } from './types.js';
3
+ export declare const biometrics: Permissioned<BiometricsImpl>;
@@ -1,10 +1,10 @@
1
- /** Optional capability — never throws for absence (docs/platform/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
- }
1
+ /** Biometric verification façade (Face ID / Touch ID / Android BIOMETRIC_STRONG). */
8
2
  export interface BiometricsImpl {
3
+ /** Prompt the user for biometric verification, showing `reason` as the
4
+ * dialog title/message. Resolves false on failure, cancel, or lockout —
5
+ * it does not reject. Only one prompt runs at a time; overlapping calls
6
+ * resolve false immediately rather than queuing. */
9
7
  verify(reason: string): Promise<boolean>;
10
8
  }
9
+ export { UnavailabilityError } from '@octane-xplat/lib/capability';
10
+ export type { Permissioned, PermissionResponse, PermissionStatus, Service, } from '@octane-xplat/lib/capability';
package/LICENSE DELETED
@@ -1,21 +0,0 @@
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.