@octane-xplat/biometrics 0.0.0-nightly.g2e22171
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 +47 -0
- package/package.json +91 -0
- package/src/biometrics.macos.ts +140 -0
- package/src/biometrics.ts +54 -0
- package/src/biometrics.web.ts +13 -0
- package/src/index.macos.ts +2 -0
- package/src/index.ts +2 -0
- package/src/types.ts +11 -0
- package/types/generated/.tsrx-typegen-manifest.json +11 -0
- package/types/generated/biometrics.d.ts +3 -0
- package/types/generated/biometrics.macos.d.ts +2 -0
- package/types/generated/biometrics.web.d.ts +2 -0
- package/types/generated/index.d.ts +2 -0
- package/types/generated/index.macos.d.ts +2 -0
- package/types/generated/types.d.ts +10 -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
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# `@octane-xplat/biometrics`
|
|
2
|
+
|
|
3
|
+
```sh
|
|
4
|
+
pnpm add @octane-xplat/biometrics
|
|
5
|
+
```
|
|
6
|
+
|
|
7
|
+
Local biometric verification — Face ID / Touch ID / fingerprint or device
|
|
8
|
+
credential — behind one capability object. iOS and Android run
|
|
9
|
+
`@nativescript/biometrics`; macOS AppKit uses Apple LocalAuthentication
|
|
10
|
+
for Touch ID. Web reports `supported: false` because WebAuthn requires
|
|
11
|
+
a registered credential and an authentication ceremony.
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { biometrics } from '@octane-xplat/biometrics'
|
|
15
|
+
|
|
16
|
+
if ((await biometrics.ensure()) === 'granted') {
|
|
17
|
+
const ok = await biometrics.impl!.verify('Unlock your saved trips')
|
|
18
|
+
}
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
The shared capability contract: `supported` reports whether an
|
|
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
|
|
25
|
+
or failed prompt rather than throwing.
|
|
26
|
+
|
|
27
|
+
On macOS, availability checks do not open a prompt. Missing hardware,
|
|
28
|
+
enrollment, pairing, or a connected sensor returns `unsupported`; lockout
|
|
29
|
+
or an interaction restriction returns `denied`. A host without the Objective-C
|
|
30
|
+
LocalAuthentication bridge reports `supported: false` and `impl: null`.
|
|
31
|
+
Verification uses biometrics only, hides password fallback, and returns
|
|
32
|
+
`false` on cancellation, failure, or an overlapping prompt.
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
import { biometrics } from '@octane-xplat/biometrics'
|
|
36
|
+
|
|
37
|
+
const availability = await biometrics.ensure()
|
|
38
|
+
if (availability === 'granted') {
|
|
39
|
+
const verified = await biometrics.impl!.verify('Unlock your saved trips')
|
|
40
|
+
console.log(verified ? 'Unlocked' : 'Still locked')
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Guide: [Using device features](../../docs/platform/platform-services.md);
|
|
45
|
+
per-target availability: [platform notes](../../.agents/docs/notes/platform-notes.md).
|
|
46
|
+
Exercised by the harness `Services` screen
|
|
47
|
+
([`packages/app/src/Services.tsrx`](../app/src/Services.tsrx)).
|
package/package.json
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@octane-xplat/biometrics",
|
|
3
|
+
"version": "0.0.0-nightly.g2e22171",
|
|
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.11.0",
|
|
62
|
+
"tsrx-typegen": "0.3.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
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
// LocalAuthentication through the AppKit host's existing Objective-C bridge.
|
|
2
|
+
import type { BiometricsImpl, Capability } from './types'
|
|
3
|
+
|
|
4
|
+
declare const objc: { import(name: string): void }
|
|
5
|
+
declare const interop: { Reference: new () => { value?: { domain: string; code: number } } }
|
|
6
|
+
declare const LAContext: { new: () => AuthenticationContext }
|
|
7
|
+
|
|
8
|
+
interface AuthenticationContext {
|
|
9
|
+
localizedFallbackTitle: string
|
|
10
|
+
canEvaluatePolicyError(policy: number, error: InstanceType<typeof interop.Reference>): boolean
|
|
11
|
+
evaluatePolicyLocalizedReasonReply(
|
|
12
|
+
policy: number,
|
|
13
|
+
reason: string,
|
|
14
|
+
reply: (success: boolean, error: unknown) => void,
|
|
15
|
+
): void
|
|
16
|
+
invalidate(): void
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// LAPolicyDeviceOwnerAuthenticationWithBiometrics: do not silently substitute
|
|
20
|
+
// password/Apple Watch authentication on a machine without biometric hardware.
|
|
21
|
+
const biometricPolicy = 1
|
|
22
|
+
|
|
23
|
+
function frameworkAvailable(): boolean {
|
|
24
|
+
try {
|
|
25
|
+
objc.import('LocalAuthentication')
|
|
26
|
+
} catch {
|
|
27
|
+
// Some hosts have already bound the symbols; others cannot provide them.
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return (
|
|
31
|
+
typeof LAContext !== 'undefined' &&
|
|
32
|
+
typeof interop !== 'undefined' &&
|
|
33
|
+
typeof interop.Reference !== 'undefined'
|
|
34
|
+
)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function availability(context: AuthenticationContext): 'granted' | 'denied' | 'unsupported' {
|
|
38
|
+
const error = new interop.Reference()
|
|
39
|
+
if (context.canEvaluatePolicyError(biometricPolicy, error)) {
|
|
40
|
+
return 'granted'
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Missing hardware (-6), enrollment (-7), pairing (-12) or a connected
|
|
44
|
+
// sensor (-13) is absence, not a permission denial.
|
|
45
|
+
// Lockout (-8), interaction restrictions and other failures remain denied.
|
|
46
|
+
return error.value?.domain === 'com.apple.LocalAuthentication' &&
|
|
47
|
+
[-6, -7, -12, -13].includes(Number(error.value.code))
|
|
48
|
+
? 'unsupported'
|
|
49
|
+
: 'denied'
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function invalidate(context: AuthenticationContext | null): void {
|
|
53
|
+
try {
|
|
54
|
+
context?.invalidate()
|
|
55
|
+
} catch {
|
|
56
|
+
// Cleanup must not turn a failed authentication into a rejected promise.
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Root both the context and callback until completion; native callbacks may
|
|
61
|
+
// outlive the JS call. Refuse concurrent prompts rather than canceling one.
|
|
62
|
+
let active: {
|
|
63
|
+
context: AuthenticationContext | null
|
|
64
|
+
reply: ((success: boolean, error: unknown) => void) | null
|
|
65
|
+
} | null = null
|
|
66
|
+
|
|
67
|
+
const implementation: BiometricsImpl = {
|
|
68
|
+
verify(reason) {
|
|
69
|
+
if (active || !frameworkAvailable() || typeof reason !== 'string' || !reason.trim()) {
|
|
70
|
+
return Promise.resolve(false)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const operation = {
|
|
74
|
+
context: null as AuthenticationContext | null,
|
|
75
|
+
reply: null as ((success: boolean, error: unknown) => void) | null,
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
active = operation
|
|
79
|
+
return new Promise<boolean>((resolve) => {
|
|
80
|
+
let settled = false
|
|
81
|
+
const finish = (success: boolean) => {
|
|
82
|
+
if (settled) {
|
|
83
|
+
return
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
settled = true
|
|
87
|
+
if (active === operation) {
|
|
88
|
+
active = null
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
invalidate(operation.context)
|
|
92
|
+
operation.context = null
|
|
93
|
+
operation.reply = null
|
|
94
|
+
resolve(success)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
try {
|
|
98
|
+
operation.context = LAContext.new()
|
|
99
|
+
if (availability(operation.context) !== 'granted') {
|
|
100
|
+
finish(false)
|
|
101
|
+
return
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
operation.context.localizedFallbackTitle = ''
|
|
105
|
+
operation.reply = (success, error) => finish(Boolean(success) && !error)
|
|
106
|
+
operation.context.evaluatePolicyLocalizedReasonReply(
|
|
107
|
+
biometricPolicy,
|
|
108
|
+
reason,
|
|
109
|
+
operation.reply,
|
|
110
|
+
)
|
|
111
|
+
} catch {
|
|
112
|
+
finish(false)
|
|
113
|
+
}
|
|
114
|
+
})
|
|
115
|
+
},
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export const biometrics: Capability<BiometricsImpl> = {
|
|
119
|
+
get supported() {
|
|
120
|
+
return frameworkAvailable()
|
|
121
|
+
},
|
|
122
|
+
async ensure() {
|
|
123
|
+
if (!frameworkAvailable()) {
|
|
124
|
+
return 'unsupported'
|
|
125
|
+
}
|
|
126
|
+
|
|
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)
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
get impl() {
|
|
138
|
+
return frameworkAvailable() ? implementation : null
|
|
139
|
+
},
|
|
140
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// Biometrics — FaceID/TouchID/fingerprint via @nativescript/biometrics.
|
|
2
|
+
import { BiometricAuth } from '@nativescript/biometrics'
|
|
3
|
+
import type { VerifyBiometricOptions } from '@nativescript/biometrics'
|
|
4
|
+
import { isIOS } from '@nativescript/core'
|
|
5
|
+
import type { Capability } from './types'
|
|
6
|
+
import type { BiometricsImpl } from './types'
|
|
7
|
+
|
|
8
|
+
const bio = new BiometricAuth()
|
|
9
|
+
|
|
10
|
+
// One prompt at a time — matching the macOS leaf, an overlapping call
|
|
11
|
+
// resolves false rather than stacking prompts or racing the shared
|
|
12
|
+
// keychain entry on iOS.
|
|
13
|
+
let verifying = false
|
|
14
|
+
|
|
15
|
+
export const biometrics: Capability<BiometricsImpl> = {
|
|
16
|
+
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'
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
impl: {
|
|
30
|
+
async verify(reason) {
|
|
31
|
+
if (verifying) {
|
|
32
|
+
return false
|
|
33
|
+
}
|
|
34
|
+
|
|
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
|
+
|
|
45
|
+
const r = await bio.verifyBiometric(options)
|
|
46
|
+
return r.code === 0
|
|
47
|
+
} catch {
|
|
48
|
+
return false
|
|
49
|
+
} finally {
|
|
50
|
+
verifying = false
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Biometrics — web leaf. WebAuthn is an authentication ceremony, not a
|
|
2
|
+
// standalone local-presence API: it requires an RP challenge and a registered
|
|
3
|
+
// credential, and may require a user gesture. Do not claim it implements the
|
|
4
|
+
// native verify(reason) contract by creating an ephemeral passkey.
|
|
5
|
+
import type { BiometricsImpl, Capability } from './types'
|
|
6
|
+
|
|
7
|
+
export const biometrics: Capability<BiometricsImpl> = {
|
|
8
|
+
supported: false,
|
|
9
|
+
async ensure() {
|
|
10
|
+
return 'unsupported'
|
|
11
|
+
},
|
|
12
|
+
impl: null,
|
|
13
|
+
}
|
package/src/index.ts
ADDED
package/src/types.ts
ADDED
|
@@ -0,0 +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
|
+
export interface BiometricsImpl {
|
|
10
|
+
verify(reason: string): Promise<boolean>
|
|
11
|
+
}
|
|
@@ -0,0 +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
|
+
}
|
|
8
|
+
export interface BiometricsImpl {
|
|
9
|
+
verify(reason: string): Promise<boolean>;
|
|
10
|
+
}
|