@octane-xplat/biometrics 0.17.0 → 0.18.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 +11 -9
- package/package.json +3 -2
- package/src/biometrics.macos.ts +32 -20
- package/src/biometrics.ts +25 -18
- package/src/biometrics.web.ts +14 -6
- package/src/types.ts +8 -8
- package/types/generated/biometrics.d.ts +2 -2
- package/types/generated/biometrics.macos.d.ts +3 -2
- package/types/generated/biometrics.web.d.ts +3 -2
- package/types/generated/types.d.ts +2 -7
package/README.md
CHANGED
|
@@ -13,30 +13,32 @@ a registered credential and an authentication ceremony.
|
|
|
13
13
|
```ts
|
|
14
14
|
import { biometrics } from '@octane-xplat/biometrics'
|
|
15
15
|
|
|
16
|
-
if ((await biometrics.
|
|
17
|
-
const ok = await biometrics.
|
|
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
|
|
21
|
+
The shared service contract: `supported` reports whether an
|
|
22
22
|
implementation exists on this target — branch on it rather than catching —
|
|
23
|
-
`
|
|
24
|
-
|
|
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 `
|
|
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.
|
|
38
|
-
if (availability
|
|
39
|
-
const verified = await biometrics.
|
|
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
|
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@octane-xplat/biometrics",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.0",
|
|
4
4
|
"description": "Biometric verification (FaceID/TouchID/fingerprint) for Octane xplat — matching web + NativeScript implementations",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"android",
|
|
@@ -51,7 +51,8 @@
|
|
|
51
51
|
"access": "public"
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@nativescript/biometrics": "1.3.1"
|
|
54
|
+
"@nativescript/biometrics": "1.3.1",
|
|
55
|
+
"@octane-xplat/lib": "0.18.0"
|
|
55
56
|
},
|
|
56
57
|
"devDependencies": {
|
|
57
58
|
"@nativescript-community/octane": "0.2.5",
|
package/src/biometrics.macos.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
// LocalAuthentication through the AppKit host's existing Objective-C bridge.
|
|
2
|
-
import
|
|
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
|
-
|
|
119
|
-
|
|
120
|
-
return
|
|
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
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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
|
-
|
|
138
|
-
|
|
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 {
|
|
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,23 +12,31 @@ const bio = new BiometricAuth()
|
|
|
12
12
|
// keychain entry on iOS.
|
|
13
13
|
let verifying = false
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
// enrollment, or a secure lockscreen — absence, not an error.
|
|
26
|
-
return 'unsupported'
|
|
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,
|
|
27
25
|
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
+
export const biometrics: Permissioned<BiometricsImpl> = {
|
|
34
|
+
supported: true,
|
|
35
|
+
isAvailable: async () => (await available()).granted,
|
|
36
|
+
getPermissions: available,
|
|
37
|
+
requestPermissions: available,
|
|
38
|
+
async verify(reason) {
|
|
39
|
+
if (verifying) {
|
|
32
40
|
return false
|
|
33
41
|
}
|
|
34
42
|
|
|
@@ -49,6 +57,5 @@ export const biometrics: Capability<BiometricsImpl> = {
|
|
|
49
57
|
} finally {
|
|
50
58
|
verifying = false
|
|
51
59
|
}
|
|
52
|
-
},
|
|
53
60
|
},
|
|
54
61
|
}
|
package/src/biometrics.web.ts
CHANGED
|
@@ -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
|
|
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
|
-
|
|
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
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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,11 @@
|
|
|
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
|
-
|
|
9
1
|
export interface BiometricsImpl {
|
|
10
2
|
verify(reason: string): Promise<boolean>
|
|
11
3
|
}
|
|
4
|
+
|
|
5
|
+
export { UnavailabilityError } from '@octane-xplat/lib/capability'
|
|
6
|
+
export type {
|
|
7
|
+
Permissioned,
|
|
8
|
+
PermissionResponse,
|
|
9
|
+
PermissionStatus,
|
|
10
|
+
Service,
|
|
11
|
+
} from '@octane-xplat/lib/capability'
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Permissioned } from '@octane-xplat/lib/capability';
|
|
2
2
|
import type { BiometricsImpl } from './types.js';
|
|
3
|
-
export declare const biometrics:
|
|
3
|
+
export declare const biometrics: Permissioned<BiometricsImpl>;
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
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 {
|
|
2
|
-
|
|
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,5 @@
|
|
|
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
|
export interface BiometricsImpl {
|
|
9
2
|
verify(reason: string): Promise<boolean>;
|
|
10
3
|
}
|
|
4
|
+
export { UnavailabilityError } from '@octane-xplat/lib/capability';
|
|
5
|
+
export type { Permissioned, PermissionResponse, PermissionStatus, Service, } from '@octane-xplat/lib/capability';
|