@octane-xplat/biometrics 0.19.0 → 0.20.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,49 +1,5 @@
1
1
  # `@octane-xplat/biometrics`
2
2
 
3
- Local biometric verification — Face ID / Touch ID / fingerprint or device
4
- credential — behind one capability object. iOS and Android run
5
- `@nativescript/biometrics`; macOS AppKit uses Apple LocalAuthentication
6
- for Touch ID. Web reports `supported: false` because WebAuthn requires
7
- a registered credential and an authentication ceremony.
3
+ [Documentation](https://octane-xplat.goddardai.org/package-biometrics).
8
4
 
9
- ```sh
10
- bun add @octane-xplat/biometrics
11
- ```
12
-
13
- ```ts
14
- import { biometrics } from '@octane-xplat/biometrics'
15
-
16
- if ((await biometrics.requestPermissions()).granted) {
17
- const ok = await biometrics.verify('Unlock your saved trips')
18
- }
19
- ```
20
-
21
- The shared service contract: `supported` reports whether an
22
- implementation exists on this target — branch on it rather than catching —
23
- `getPermissions()`/`requestPermissions()` resolve
24
- `{status: 'granted' | 'denied' | 'unsupported', granted, canAskAgain}`.
25
- `verify(reason)` resolves `false` for a declined
26
- or failed prompt rather than throwing.
27
-
28
- On macOS, availability checks do not open a prompt. Missing hardware,
29
- enrollment, pairing, or a connected sensor returns `unsupported`; lockout
30
- or an interaction restriction returns `denied`. A host without the Objective-C
31
- LocalAuthentication bridge reports `supported: false` and `verify()` rejects
32
- `UnavailabilityError`.
33
- Verification uses biometrics only, hides password fallback, and returns
34
- `false` on cancellation, failure, or an overlapping prompt.
35
-
36
- ```ts
37
- import { biometrics } from '@octane-xplat/biometrics'
38
-
39
- const availability = await biometrics.requestPermissions()
40
- if (availability.granted) {
41
- const verified = await biometrics.verify('Unlock your saved trips')
42
- console.log(verified ? 'Unlocked' : 'Still locked')
43
- }
44
- ```
45
-
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).
48
- Exercised by the harness `Services` screen
49
- ([`packages/app/src/Services.tsrx`](https://github.com/octane-xplat/octane-xplat/blob/main/packages/app/src/Services.tsrx)).
5
+ [API reference](https://octane-xplat.goddardai.org/api-biometrics).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@octane-xplat/biometrics",
3
- "version": "0.19.0",
3
+ "version": "0.20.0",
4
4
  "description": "Biometric verification (FaceID/TouchID/fingerprint) for Octane xplat — matching web + NativeScript implementations",
5
5
  "keywords": [
6
6
  "android",
@@ -57,16 +57,17 @@
57
57
  },
58
58
  "dependencies": {
59
59
  "@nativescript/biometrics": "1.3.1",
60
- "@octane-xplat/lib": "0.19.0"
60
+ "@octane-xplat/lib": "0.20.0"
61
61
  },
62
62
  "devDependencies": {
63
63
  "@nativescript-community/octane": "0.2.5",
64
64
  "@nativescript/core": "9.1.3",
65
65
  "@nativescript/types": "9.1.4",
66
- "@tsrx/typescript-plugin": "0.4.11",
67
66
  "octane": "0.16.3",
68
- "tsrx-typegen": "0.5.0",
69
- "typescript": "5.9.3"
67
+ "tsrx-typegen": "0.6.1",
68
+ "typescript": "7.1.0-beta",
69
+ "@tsrx/content-mapper": "0.1.2",
70
+ "typescript-classic": "npm:typescript@5.9.3"
70
71
  },
71
72
  "peerDependencies": {
72
73
  "@nativescript-community/octane": ">=0.2.1 <1",
@@ -8,14 +8,14 @@ declare const interop: { Reference: new () => { value?: { domain: string; code:
8
8
  declare const LAContext: { new: () => AuthenticationContext }
9
9
 
10
10
  interface AuthenticationContext {
11
- localizedFallbackTitle: string
12
- canEvaluatePolicyError(policy: number, error: InstanceType<typeof interop.Reference>): boolean
13
- evaluatePolicyLocalizedReasonReply(
14
- policy: number,
15
- reason: string,
16
- reply: (success: boolean, error: unknown) => void,
17
- ): void
18
- invalidate(): void
11
+ localizedFallbackTitle: string
12
+ canEvaluatePolicyError(policy: number, error: InstanceType<typeof interop.Reference>): boolean
13
+ evaluatePolicyLocalizedReasonReply(
14
+ policy: number,
15
+ reason: string,
16
+ reply: (success: boolean, error: unknown) => void,
17
+ ): void
18
+ invalidate(): void
19
19
  }
20
20
 
21
21
  // LAPolicyDeviceOwnerAuthenticationWithBiometrics: do not silently substitute
@@ -23,130 +23,134 @@ interface AuthenticationContext {
23
23
  const biometricPolicy = 1
24
24
 
25
25
  function frameworkAvailable(): boolean {
26
- try {
27
- objc.import('LocalAuthentication')
28
- } catch {
29
- // Some hosts have already bound the symbols; others cannot provide them.
30
- }
31
-
32
- return (
33
- typeof LAContext !== 'undefined' &&
34
- typeof interop !== 'undefined' &&
35
- typeof interop.Reference !== 'undefined'
36
- )
26
+ try {
27
+ objc.import('LocalAuthentication')
28
+ } catch {
29
+ // Some hosts have already bound the symbols; others cannot provide them.
30
+ }
31
+
32
+ return (
33
+ typeof LAContext !== 'undefined' &&
34
+ typeof interop !== 'undefined' &&
35
+ typeof interop.Reference !== 'undefined'
36
+ )
37
37
  }
38
38
 
39
39
  function availability(context: AuthenticationContext): 'granted' | 'denied' | 'unsupported' {
40
- const error = new interop.Reference()
41
- if (context.canEvaluatePolicyError(biometricPolicy, error)) {
42
- return 'granted'
43
- }
44
-
45
- // Missing hardware (-6), enrollment (-7), pairing (-12) or a connected
46
- // sensor (-13) is absence, not a permission denial.
47
- // Lockout (-8), interaction restrictions and other failures remain denied.
48
- return error.value?.domain === 'com.apple.LocalAuthentication' &&
49
- [-6, -7, -12, -13].includes(Number(error.value.code))
50
- ? 'unsupported'
51
- : 'denied'
40
+ const error = new interop.Reference()
41
+
42
+ if (context.canEvaluatePolicyError(biometricPolicy, error)) {
43
+ return 'granted'
44
+ }
45
+
46
+ // Missing hardware (-6), enrollment (-7), pairing (-12) or a connected
47
+ // sensor (-13) is absence, not a permission denial.
48
+ // Lockout (-8), interaction restrictions and other failures remain denied.
49
+ return error.value?.domain === 'com.apple.LocalAuthentication' &&
50
+ [-6, -7, -12, -13].includes(Number(error.value.code))
51
+ ? 'unsupported'
52
+ : 'denied'
52
53
  }
53
54
 
54
55
  function invalidate(context: AuthenticationContext | null): void {
55
- try {
56
- context?.invalidate()
57
- } catch {
58
- // Cleanup must not turn a failed authentication into a rejected promise.
59
- }
56
+ try {
57
+ context?.invalidate()
58
+ } catch {
59
+ // Cleanup must not turn a failed authentication into a rejected promise.
60
+ }
60
61
  }
61
62
 
62
63
  // Root both the context and callback until completion; native callbacks may
63
64
  // outlive the JS call. Refuse concurrent prompts rather than canceling one.
64
65
  let active: {
65
- context: AuthenticationContext | null
66
- reply: ((success: boolean, error: unknown) => void) | null
66
+ context: AuthenticationContext | null
67
+ reply: ((success: boolean, error: unknown) => void) | null
67
68
  } | null = null
68
69
 
69
70
  const implementation: BiometricsImpl = {
70
- verify(reason) {
71
- if (active || !frameworkAvailable() || typeof reason !== 'string' || !reason.trim()) {
72
- return Promise.resolve(false)
73
- }
74
-
75
- const operation = {
76
- context: null as AuthenticationContext | null,
77
- reply: null as ((success: boolean, error: unknown) => void) | null,
78
- }
79
-
80
- active = operation
81
- return new Promise<boolean>((resolve) => {
82
- let settled = false
83
- const finish = (success: boolean) => {
84
- if (settled) {
85
- return
86
- }
87
-
88
- settled = true
89
- if (active === operation) {
90
- active = null
91
- }
92
-
93
- invalidate(operation.context)
94
- operation.context = null
95
- operation.reply = null
96
- resolve(success)
97
- }
98
-
99
- try {
100
- operation.context = LAContext.new()
101
- if (availability(operation.context) !== 'granted') {
102
- finish(false)
103
- return
104
- }
105
-
106
- operation.context.localizedFallbackTitle = ''
107
- operation.reply = (success, error) => finish(Boolean(success) && !error)
108
- operation.context.evaluatePolicyLocalizedReasonReply(
109
- biometricPolicy,
110
- reason,
111
- operation.reply,
112
- )
113
- } catch {
114
- finish(false)
115
- }
116
- })
117
- },
71
+ verify(reason) {
72
+ if (active || !frameworkAvailable() || typeof reason !== 'string' || !reason.trim()) {
73
+ return Promise.resolve(false)
74
+ }
75
+
76
+ const operation = {
77
+ context: null as AuthenticationContext | null,
78
+ reply: null as ((success: boolean, error: unknown) => void) | null,
79
+ }
80
+
81
+ active = operation
82
+ return new Promise<boolean>((resolve) => {
83
+ let settled = false
84
+ const finish = (success: boolean) => {
85
+ if (settled) {
86
+ return
87
+ }
88
+
89
+ settled = true
90
+ if (active === operation) {
91
+ active = null
92
+ }
93
+
94
+ invalidate(operation.context)
95
+ operation.context = null
96
+ operation.reply = null
97
+ resolve(success)
98
+ }
99
+
100
+ try {
101
+ operation.context = LAContext.new()
102
+ if (availability(operation.context) !== 'granted') {
103
+ finish(false)
104
+ return
105
+ }
106
+
107
+ operation.context.localizedFallbackTitle = ''
108
+ operation.reply = (success, error) => finish(Boolean(success) && !error)
109
+ operation.context.evaluatePolicyLocalizedReasonReply(
110
+ biometricPolicy,
111
+ reason,
112
+ operation.reply,
113
+ )
114
+ } catch {
115
+ finish(false)
116
+ }
117
+ })
118
+ },
118
119
  }
119
120
 
120
121
  const ensure = async (): Promise<PermissionResponse> => {
121
- if (!frameworkAvailable()) {
122
- return { status: 'unsupported', granted: false, canAskAgain: false }
123
- }
124
-
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',
133
- }
134
- } catch {
135
- return { status: 'denied', granted: false, canAskAgain: false }
136
- } finally {
137
- invalidate(context)
138
- }
122
+ if (!frameworkAvailable()) {
123
+ return { status: 'unsupported', granted: false, canAskAgain: false }
124
+ }
125
+
126
+ let context: AuthenticationContext | null = null
127
+
128
+ try {
129
+ context = LAContext.new()
130
+
131
+ const status = availability(context)
132
+
133
+ return {
134
+ status,
135
+ granted: status === 'granted',
136
+ canAskAgain: status === 'granted',
137
+ }
138
+ } catch {
139
+ return { status: 'denied', granted: false, canAskAgain: false }
140
+ } finally {
141
+ invalidate(context)
142
+ }
139
143
  }
140
144
 
141
145
  export const biometrics: Permissioned<BiometricsImpl> = {
142
- get supported() {
143
- return frameworkAvailable()
144
- },
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')),
146
+ get supported() {
147
+ return frameworkAvailable()
148
+ },
149
+ isAvailable: async () => frameworkAvailable(),
150
+ getPermissions: ensure,
151
+ requestPermissions: ensure,
152
+ verify: (reason) =>
153
+ frameworkAvailable()
154
+ ? implementation.verify(reason)
155
+ : Promise.reject(new UnavailabilityError('biometrics')),
152
156
  }
package/src/biometrics.ts CHANGED
@@ -13,50 +13,52 @@ const bio = new BiometricAuth()
13
13
  let verifying = false
14
14
 
15
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
- }
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
+
22
+ return {
23
+ status: usable ? 'granted' : 'unsupported',
24
+ granted: usable,
25
+ canAskAgain: usable,
26
+ }
27
+ } catch {
28
+ // Android rejects when the device lacks biometric hardware,
29
+ // enrollment, or a secure lockscreen — absence, not an error.
30
+ return { status: 'unsupported', granted: false, canAskAgain: false }
31
+ }
31
32
  }
32
33
 
33
34
  /** Biometrics service backed by @nativescript/biometrics. */
34
35
  export const biometrics: Permissioned<BiometricsImpl> = {
35
- supported: true,
36
- isAvailable: async () => (await available()).granted,
37
- getPermissions: available,
38
- requestPermissions: available,
39
- async verify(reason) {
40
- if (verifying) {
41
- return false
42
- }
43
-
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 }
53
-
54
- const r = await bio.verifyBiometric(options)
55
- return r.code === 0
56
- } catch {
57
- return false
58
- } finally {
59
- verifying = false
60
- }
61
- },
36
+ supported: true,
37
+ isAvailable: async () => (await available()).granted,
38
+ getPermissions: available,
39
+ requestPermissions: available,
40
+ async verify(reason) {
41
+ if (verifying) {
42
+ return false
43
+ }
44
+
45
+ verifying = true
46
+ try {
47
+ // iOS ignores `title` on its default keychain path — route
48
+ // through LAContext (pinFallback selects that path; customFallback
49
+ // keeps the biometrics-only policy) so `message` surfaces the
50
+ // caller's reason, matching Android's dialog title.
51
+ const options: VerifyBiometricOptions = isIOS
52
+ ? { title: reason, message: reason, pinFallback: true, ios: { customFallback: true } }
53
+ : { title: reason }
54
+
55
+ const r = await bio.verifyBiometric(options)
56
+
57
+ return r.code === 0
58
+ } catch {
59
+ return false
60
+ } finally {
61
+ verifying = false
62
+ }
63
+ },
62
64
  }
@@ -7,15 +7,15 @@ import type { Permissioned, PermissionResponse } from '@octane-xplat/lib/capabil
7
7
  import type { BiometricsImpl } from './types'
8
8
 
9
9
  const UNSUPPORTED: PermissionResponse = {
10
- status: 'unsupported',
11
- granted: false,
12
- canAskAgain: false,
10
+ status: 'unsupported',
11
+ granted: false,
12
+ canAskAgain: false,
13
13
  }
14
14
 
15
15
  export const biometrics: Permissioned<BiometricsImpl> = {
16
- supported: false,
17
- isAvailable: async () => false,
18
- getPermissions: async () => UNSUPPORTED,
19
- requestPermissions: async () => UNSUPPORTED,
20
- verify: () => Promise.reject(new UnavailabilityError('biometrics')),
16
+ supported: false,
17
+ isAvailable: async () => false,
18
+ getPermissions: async () => UNSUPPORTED,
19
+ requestPermissions: async () => UNSUPPORTED,
20
+ verify: () => Promise.reject(new UnavailabilityError('biometrics')),
21
21
  }
package/src/types.ts CHANGED
@@ -1,16 +1,16 @@
1
1
  /** Biometric verification façade (Face ID / Touch ID / Android BIOMETRIC_STRONG). */
2
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. */
7
- verify(reason: string): Promise<boolean>
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. */
7
+ verify(reason: string): Promise<boolean>
8
8
  }
9
9
 
10
10
  export { UnavailabilityError } from '@octane-xplat/lib/capability'
11
11
  export type {
12
- Permissioned,
13
- PermissionResponse,
14
- PermissionStatus,
15
- Service,
12
+ Permissioned,
13
+ PermissionResponse,
14
+ PermissionStatus,
15
+ Service,
16
16
  } from '@octane-xplat/lib/capability'
@@ -2,10 +2,7 @@
2
2
  "version": 1,
3
3
  "files": [
4
4
  "biometrics.d.ts",
5
- "biometrics.macos.d.ts",
6
- "biometrics.web.d.ts",
7
5
  "index.d.ts",
8
- "index.macos.d.ts",
9
6
  "types.d.ts"
10
7
  ]
11
8
  }
@@ -1,3 +0,0 @@
1
- import type { Permissioned } from '@octane-xplat/lib/capability';
2
- import type { BiometricsImpl } from './types.js';
3
- export declare const biometrics: Permissioned<BiometricsImpl>;
@@ -1,3 +0,0 @@
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 +0,0 @@
1
- export * from './types.js';
2
- export { biometrics } from './biometrics.macos.js';