@korajs/auth 0.3.3 → 0.5.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 +81 -28
- package/dist/{chunk-FSU4SK32.js → chunk-IO2MCCG2.js} +35 -40
- package/dist/chunk-IO2MCCG2.js.map +1 -0
- package/dist/{chunk-HOZXDR6Y.js → chunk-L7GXPS74.js} +3 -9
- package/dist/chunk-L7GXPS74.js.map +1 -0
- package/dist/index.cjs +978 -606
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +77 -118
- package/dist/index.d.ts +77 -118
- package/dist/index.js +686 -313
- package/dist/index.js.map +1 -1
- package/dist/org-client-q2u55qod.d.cts +665 -0
- package/dist/org-client-q2u55qod.d.ts +665 -0
- package/dist/{password-hash-HDH6VQCQ.js → password-hash-QRBG6BNJ.js} +2 -2
- package/dist/react.cjs +79 -0
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +17 -1
- package/dist/react.d.ts +17 -1
- package/dist/react.js +79 -0
- package/dist/react.js.map +1 -1
- package/dist/server.cjs +2524 -1672
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts +415 -224
- package/dist/server.d.ts +415 -224
- package/dist/server.js +2325 -1484
- package/dist/server.js.map +1 -1
- package/package.json +5 -5
- package/dist/chunk-FSU4SK32.js.map +0 -1
- package/dist/chunk-HOZXDR6Y.js.map +0 -1
- package/dist/org-client-BVTLKcIk.d.cts +0 -355
- package/dist/org-client-BVTLKcIk.d.ts +0 -355
- /package/dist/{password-hash-HDH6VQCQ.js.map → password-hash-QRBG6BNJ.js.map} +0 -0
package/dist/index.d.cts
CHANGED
|
@@ -1,148 +1,107 @@
|
|
|
1
|
-
|
|
1
|
+
import { A as AuthClientConfig, a as AuthTokenStorage, b as AuthKeyValueStorage, c as AuthDeviceIdentityProvider, D as DeviceKeyStore, d as AuthClient, e as AuthState } from './org-client-q2u55qod.cjs';
|
|
2
|
+
export { f as AuthDeviceIdentity, g as AuthDeviceIdentityError, h as AuthError, i as AuthTokenStorageOptions, j as AuthUser, C as ClientInvitation, k as ClientMembership, l as ClientOrganization, m as DeviceKeyStoreError, I as InMemoryDeviceKeyStore, n as IndexedDBDeviceKeyStore, L as LinkedOAuthAccount, O as OAuthAuthorizationOptions, o as OAuthAuthorizationResult, p as OAuthCallbackParams, q as OrgClient, r as OrgClientConfig, s as OrgClientError, P as PersistentDeviceIdentityOptions, t as createAuthTokenStorage, u as createDeviceKeyStore, v as createMemoryAuthTokenStorage, w as createPersistentDeviceIdentity, x as createWebStorageAuthTokenStorage } from './org-client-q2u55qod.cjs';
|
|
3
|
+
import { SchemaDefinition, ScopeMap, KoraError } from '@korajs/core';
|
|
2
4
|
import { A as AuthTokens } from './operation-encryptor-DRmKNWpF.cjs';
|
|
3
5
|
export { a as AuthConfig, b as AuthEvent, c as AuthEventType, d as AuthStatus, C as CryptoUnavailableError, D as DeviceIdentityError, O as OperationEncryptionError, e as OperationEncryptor, f as OperationEncryptorConfig, T as TokenPayload, g as TokenType, h as computePublicKeyThumbprint, i as exportPublicKeyJwk, j as fromBase64Url, k as generateDeviceKeyPair, l as isEncryptedField, s as signChallenge, t as toBase64Url, v as verifyChallenge } from './operation-encryptor-DRmKNWpF.cjs';
|
|
4
|
-
import { KoraError } from '@korajs/core';
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
* Thrown when a device key store operation fails.
|
|
8
|
-
* Provides context about the operation and the underlying cause.
|
|
9
|
-
*/
|
|
10
|
-
declare class DeviceKeyStoreError extends KoraError {
|
|
11
|
-
constructor(message: string, context?: Record<string, unknown>);
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Persistent storage interface for ECDSA P-256 device key pairs.
|
|
15
|
-
*
|
|
16
|
-
* Device key pairs are used for proof-of-possession authentication:
|
|
17
|
-
* the private key never leaves the device, and the public key is
|
|
18
|
-
* registered with the server. This store persists key pairs across
|
|
19
|
-
* page reloads and app restarts.
|
|
20
|
-
*
|
|
21
|
-
* In the browser, CryptoKey objects are structured-cloneable, so they
|
|
22
|
-
* can be stored directly in IndexedDB without serialization. In Node.js
|
|
23
|
-
* or test environments, an in-memory implementation is used instead.
|
|
24
|
-
*/
|
|
25
|
-
interface DeviceKeyStore {
|
|
7
|
+
interface CreateKoraAuthOptions extends Omit<AuthClientConfig, 'storage' | 'deviceIdentity'> {
|
|
26
8
|
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* Overwrites any previously stored key pair for the same device ID.
|
|
30
|
-
*
|
|
31
|
-
* @param deviceId - The unique device identifier (typically a UUID v7)
|
|
32
|
-
* @param keyPair - The ECDSA P-256 CryptoKeyPair to store
|
|
33
|
-
* @throws {DeviceKeyStoreError} If the storage operation fails
|
|
9
|
+
* Complete token storage adapter. Use this for fully custom runtimes.
|
|
10
|
+
* If omitted, `credentialStore` is adapted automatically.
|
|
34
11
|
*/
|
|
35
|
-
|
|
12
|
+
storage?: AuthTokenStorage;
|
|
36
13
|
/**
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* @param deviceId - The unique device identifier
|
|
40
|
-
* @returns The stored CryptoKeyPair, or null if no key pair exists for the device
|
|
41
|
-
* @throws {DeviceKeyStoreError} If the storage operation fails
|
|
14
|
+
* Runtime credential store used for tokens and stable device ID.
|
|
15
|
+
* Examples: Tauri secure storage, Expo SecureStore, iOS Keychain, Android Keystore.
|
|
42
16
|
*/
|
|
43
|
-
|
|
17
|
+
credentialStore?: AuthKeyValueStorage;
|
|
44
18
|
/**
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
* No-op if no key pair exists for the device ID.
|
|
48
|
-
*
|
|
49
|
-
* @param deviceId - The unique device identifier
|
|
50
|
-
* @throws {DeviceKeyStoreError} If the storage operation fails
|
|
19
|
+
* Explicit device identity provider. Set to `false` to disable automatic
|
|
20
|
+
* device binding during sign-up/sign-in.
|
|
51
21
|
*/
|
|
52
|
-
|
|
22
|
+
deviceIdentity?: AuthDeviceIdentityProvider | false;
|
|
53
23
|
/**
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
* @param deviceId - The unique device identifier
|
|
57
|
-
* @returns True if a key pair is stored for the device, false otherwise
|
|
58
|
-
* @throws {DeviceKeyStoreError} If the storage operation fails
|
|
24
|
+
* Device key store for runtimes without IndexedDB, such as React Native.
|
|
59
25
|
*/
|
|
60
|
-
|
|
26
|
+
deviceKeyStore?: DeviceKeyStore;
|
|
61
27
|
}
|
|
62
28
|
/**
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
* CryptoKey objects are structured-cloneable, so they can be stored
|
|
66
|
-
* directly in IndexedDB without needing to export/import them as JWK.
|
|
67
|
-
* This preserves the non-extractable flag on private keys, ensuring
|
|
68
|
-
* they cannot be read even from storage.
|
|
69
|
-
*
|
|
70
|
-
* The database uses a single object store (`keypairs`) with the device ID
|
|
71
|
-
* as the key and the full CryptoKeyPair as the value.
|
|
29
|
+
* Create a production-shaped Kora auth client with minimal setup.
|
|
72
30
|
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
*
|
|
31
|
+
* Defaults:
|
|
32
|
+
* - browser/Tauri WebView: localStorage for tokens, IndexedDB for device keys
|
|
33
|
+
* - desktop/mobile: pass `credentialStore` and optionally `deviceKeyStore`
|
|
34
|
+
* - automatic device identity is enabled when a persistent device ID store exists
|
|
35
|
+
*/
|
|
36
|
+
declare function createKoraAuth(options: CreateKoraAuthOptions): AuthClient;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Minimal auth client surface required for sync integration.
|
|
40
|
+
* Matches {@link AuthClient} without importing implementation details.
|
|
41
|
+
*/
|
|
42
|
+
interface AuthSyncClient {
|
|
43
|
+
getAccessToken(): Promise<string | null>;
|
|
44
|
+
onAuthChange?(callback: (state: AuthState) => void): () => void;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Sync binding returned by {@link createKoraAuthSync}.
|
|
48
|
+
* Passed to `createApp({ sync: { authClient } })` in korajs.
|
|
82
49
|
*/
|
|
83
|
-
|
|
84
|
-
|
|
50
|
+
interface KoraAuthSyncBinding {
|
|
51
|
+
/** Returns the access token for sync handshake (empty string when signed out). */
|
|
52
|
+
auth: () => Promise<{
|
|
53
|
+
token: string;
|
|
54
|
+
}>;
|
|
55
|
+
/** Builds a scope map from the current token and schema. */
|
|
56
|
+
resolveScopeMap?: () => Promise<ScopeMap | undefined>;
|
|
85
57
|
/**
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
* The database connection is lazily initialized on first use and
|
|
89
|
-
* reused for subsequent operations. If the database does not exist,
|
|
90
|
-
* it is created with the `keypairs` object store.
|
|
58
|
+
* Returns the device-bound sync node id from the token `dev` claim.
|
|
59
|
+
* Separate from the user id (`sub`).
|
|
91
60
|
*/
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
|
|
95
|
-
/** @inheritdoc */
|
|
96
|
-
loadKeyPair(deviceId: string): Promise<CryptoKeyPair | null>;
|
|
97
|
-
/** @inheritdoc */
|
|
98
|
-
deleteKeyPair(deviceId: string): Promise<void>;
|
|
99
|
-
/** @inheritdoc */
|
|
100
|
-
hasKeyPair(deviceId: string): Promise<boolean>;
|
|
61
|
+
resolveNodeId?: () => Promise<string | undefined>;
|
|
62
|
+
/** Notifies when auth state changes so sync can refresh scope or reconnect. */
|
|
63
|
+
subscribe?: (listener: () => void) => () => void;
|
|
101
64
|
}
|
|
102
65
|
/**
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
* Key pairs are stored in a plain Map and do not survive process restarts.
|
|
106
|
-
* This is suitable for server-side rendering, Node.js scripts, and unit tests
|
|
107
|
-
* where IndexedDB is not available.
|
|
108
|
-
*
|
|
109
|
-
* @example
|
|
110
|
-
* ```typescript
|
|
111
|
-
* const store = new InMemoryDeviceKeyStore()
|
|
112
|
-
* const keyPair = await generateDeviceKeyPair()
|
|
113
|
-
* await store.saveKeyPair('device-123', keyPair)
|
|
114
|
-
*
|
|
115
|
-
* const loaded = await store.loadKeyPair('device-123')
|
|
116
|
-
* ```
|
|
66
|
+
* Configuration for {@link createKoraAuthSync}.
|
|
117
67
|
*/
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
|
|
68
|
+
interface CreateKoraAuthSyncOptions {
|
|
69
|
+
/** Kora auth client from `createKoraAuth()`. */
|
|
70
|
+
authClient: AuthSyncClient;
|
|
71
|
+
/**
|
|
72
|
+
* Application schema. When provided, scope maps are built automatically
|
|
73
|
+
* from JWT claims and schema scope declarations.
|
|
74
|
+
*/
|
|
75
|
+
schema?: SchemaDefinition;
|
|
76
|
+
/**
|
|
77
|
+
* Custom claim → flat scope value mapping.
|
|
78
|
+
* Defaults to {@link extractScopeValuesFromClaims}.
|
|
79
|
+
*/
|
|
80
|
+
scopeFromClaims?: (claims: Record<string, unknown>) => Record<string, unknown>;
|
|
128
81
|
}
|
|
129
82
|
/**
|
|
130
|
-
* Creates a
|
|
131
|
-
*
|
|
132
|
-
* In browsers where IndexedDB is available, returns an {@link IndexedDBDeviceKeyStore}
|
|
133
|
-
* that persists CryptoKeyPair objects as structured clones. In Node.js, SSR,
|
|
134
|
-
* or environments without IndexedDB, returns an {@link InMemoryDeviceKeyStore}.
|
|
83
|
+
* Creates a sync auth binding for `createApp({ sync: { authClient: binding } })`.
|
|
135
84
|
*
|
|
136
|
-
*
|
|
85
|
+
* Wires token refresh, automatic scope maps from JWT claims, and device-bound
|
|
86
|
+
* sync node ids (`dev` claim) separate from the user id (`sub`).
|
|
137
87
|
*
|
|
138
88
|
* @example
|
|
139
89
|
* ```typescript
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
90
|
+
* import { createKoraAuth, createKoraAuthSync } from '@korajs/auth'
|
|
91
|
+
* import { createApp } from 'korajs'
|
|
92
|
+
*
|
|
93
|
+
* const authClient = createKoraAuth({ serverUrl: 'https://api.example.com' })
|
|
94
|
+
*
|
|
95
|
+
* const app = createApp({
|
|
96
|
+
* schema,
|
|
97
|
+
* sync: {
|
|
98
|
+
* url: 'wss://api.example.com/kora-sync',
|
|
99
|
+
* authClient: createKoraAuthSync({ authClient, schema }),
|
|
100
|
+
* },
|
|
101
|
+
* })
|
|
143
102
|
* ```
|
|
144
103
|
*/
|
|
145
|
-
declare function
|
|
104
|
+
declare function createKoraAuthSync(options: CreateKoraAuthSyncOptions): KoraAuthSyncBinding;
|
|
146
105
|
|
|
147
106
|
/**
|
|
148
107
|
* Client-side token storage for Kora auth tokens.
|
|
@@ -780,4 +739,4 @@ declare class AutoLockManager {
|
|
|
780
739
|
private _clearTimer;
|
|
781
740
|
}
|
|
782
741
|
|
|
783
|
-
export { AuthTokens, type AutoLockConfig, AutoLockManager, type
|
|
742
|
+
export { AuthClient, AuthClientConfig, AuthDeviceIdentityProvider, AuthKeyValueStorage, AuthState, type AuthSyncClient, AuthTokenStorage, AuthTokens, type AutoLockConfig, AutoLockManager, type CreateKoraAuthOptions, type CreateKoraAuthSyncOptions, DeviceKeyStore, EncryptedTokenStore, type EncryptedTokenStoreConfig, EncryptedTokenStoreError, EncryptionError, KeyDerivationError, type KoraAuthSyncBinding, type PasskeyAuthenticationResponse, PasskeyError, type PasskeyRegistrationResponse, PasskeyUnsupportedError, TokenStore, authenticateWithPasskey, createKoraAuth, createKoraAuthSync, createPasskeyCredential, decryptData, deriveEncryptionKey, encryptData, exportKey, generateEncryptionKey, generateSalt, importKey, isPasskeySupported, isPlatformAuthenticatorAvailable };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,148 +1,107 @@
|
|
|
1
|
-
|
|
1
|
+
import { A as AuthClientConfig, a as AuthTokenStorage, b as AuthKeyValueStorage, c as AuthDeviceIdentityProvider, D as DeviceKeyStore, d as AuthClient, e as AuthState } from './org-client-q2u55qod.js';
|
|
2
|
+
export { f as AuthDeviceIdentity, g as AuthDeviceIdentityError, h as AuthError, i as AuthTokenStorageOptions, j as AuthUser, C as ClientInvitation, k as ClientMembership, l as ClientOrganization, m as DeviceKeyStoreError, I as InMemoryDeviceKeyStore, n as IndexedDBDeviceKeyStore, L as LinkedOAuthAccount, O as OAuthAuthorizationOptions, o as OAuthAuthorizationResult, p as OAuthCallbackParams, q as OrgClient, r as OrgClientConfig, s as OrgClientError, P as PersistentDeviceIdentityOptions, t as createAuthTokenStorage, u as createDeviceKeyStore, v as createMemoryAuthTokenStorage, w as createPersistentDeviceIdentity, x as createWebStorageAuthTokenStorage } from './org-client-q2u55qod.js';
|
|
3
|
+
import { SchemaDefinition, ScopeMap, KoraError } from '@korajs/core';
|
|
2
4
|
import { A as AuthTokens } from './operation-encryptor-DRmKNWpF.js';
|
|
3
5
|
export { a as AuthConfig, b as AuthEvent, c as AuthEventType, d as AuthStatus, C as CryptoUnavailableError, D as DeviceIdentityError, O as OperationEncryptionError, e as OperationEncryptor, f as OperationEncryptorConfig, T as TokenPayload, g as TokenType, h as computePublicKeyThumbprint, i as exportPublicKeyJwk, j as fromBase64Url, k as generateDeviceKeyPair, l as isEncryptedField, s as signChallenge, t as toBase64Url, v as verifyChallenge } from './operation-encryptor-DRmKNWpF.js';
|
|
4
|
-
import { KoraError } from '@korajs/core';
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
* Thrown when a device key store operation fails.
|
|
8
|
-
* Provides context about the operation and the underlying cause.
|
|
9
|
-
*/
|
|
10
|
-
declare class DeviceKeyStoreError extends KoraError {
|
|
11
|
-
constructor(message: string, context?: Record<string, unknown>);
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Persistent storage interface for ECDSA P-256 device key pairs.
|
|
15
|
-
*
|
|
16
|
-
* Device key pairs are used for proof-of-possession authentication:
|
|
17
|
-
* the private key never leaves the device, and the public key is
|
|
18
|
-
* registered with the server. This store persists key pairs across
|
|
19
|
-
* page reloads and app restarts.
|
|
20
|
-
*
|
|
21
|
-
* In the browser, CryptoKey objects are structured-cloneable, so they
|
|
22
|
-
* can be stored directly in IndexedDB without serialization. In Node.js
|
|
23
|
-
* or test environments, an in-memory implementation is used instead.
|
|
24
|
-
*/
|
|
25
|
-
interface DeviceKeyStore {
|
|
7
|
+
interface CreateKoraAuthOptions extends Omit<AuthClientConfig, 'storage' | 'deviceIdentity'> {
|
|
26
8
|
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* Overwrites any previously stored key pair for the same device ID.
|
|
30
|
-
*
|
|
31
|
-
* @param deviceId - The unique device identifier (typically a UUID v7)
|
|
32
|
-
* @param keyPair - The ECDSA P-256 CryptoKeyPair to store
|
|
33
|
-
* @throws {DeviceKeyStoreError} If the storage operation fails
|
|
9
|
+
* Complete token storage adapter. Use this for fully custom runtimes.
|
|
10
|
+
* If omitted, `credentialStore` is adapted automatically.
|
|
34
11
|
*/
|
|
35
|
-
|
|
12
|
+
storage?: AuthTokenStorage;
|
|
36
13
|
/**
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* @param deviceId - The unique device identifier
|
|
40
|
-
* @returns The stored CryptoKeyPair, or null if no key pair exists for the device
|
|
41
|
-
* @throws {DeviceKeyStoreError} If the storage operation fails
|
|
14
|
+
* Runtime credential store used for tokens and stable device ID.
|
|
15
|
+
* Examples: Tauri secure storage, Expo SecureStore, iOS Keychain, Android Keystore.
|
|
42
16
|
*/
|
|
43
|
-
|
|
17
|
+
credentialStore?: AuthKeyValueStorage;
|
|
44
18
|
/**
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
* No-op if no key pair exists for the device ID.
|
|
48
|
-
*
|
|
49
|
-
* @param deviceId - The unique device identifier
|
|
50
|
-
* @throws {DeviceKeyStoreError} If the storage operation fails
|
|
19
|
+
* Explicit device identity provider. Set to `false` to disable automatic
|
|
20
|
+
* device binding during sign-up/sign-in.
|
|
51
21
|
*/
|
|
52
|
-
|
|
22
|
+
deviceIdentity?: AuthDeviceIdentityProvider | false;
|
|
53
23
|
/**
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
* @param deviceId - The unique device identifier
|
|
57
|
-
* @returns True if a key pair is stored for the device, false otherwise
|
|
58
|
-
* @throws {DeviceKeyStoreError} If the storage operation fails
|
|
24
|
+
* Device key store for runtimes without IndexedDB, such as React Native.
|
|
59
25
|
*/
|
|
60
|
-
|
|
26
|
+
deviceKeyStore?: DeviceKeyStore;
|
|
61
27
|
}
|
|
62
28
|
/**
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
* CryptoKey objects are structured-cloneable, so they can be stored
|
|
66
|
-
* directly in IndexedDB without needing to export/import them as JWK.
|
|
67
|
-
* This preserves the non-extractable flag on private keys, ensuring
|
|
68
|
-
* they cannot be read even from storage.
|
|
69
|
-
*
|
|
70
|
-
* The database uses a single object store (`keypairs`) with the device ID
|
|
71
|
-
* as the key and the full CryptoKeyPair as the value.
|
|
29
|
+
* Create a production-shaped Kora auth client with minimal setup.
|
|
72
30
|
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
*
|
|
31
|
+
* Defaults:
|
|
32
|
+
* - browser/Tauri WebView: localStorage for tokens, IndexedDB for device keys
|
|
33
|
+
* - desktop/mobile: pass `credentialStore` and optionally `deviceKeyStore`
|
|
34
|
+
* - automatic device identity is enabled when a persistent device ID store exists
|
|
35
|
+
*/
|
|
36
|
+
declare function createKoraAuth(options: CreateKoraAuthOptions): AuthClient;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Minimal auth client surface required for sync integration.
|
|
40
|
+
* Matches {@link AuthClient} without importing implementation details.
|
|
41
|
+
*/
|
|
42
|
+
interface AuthSyncClient {
|
|
43
|
+
getAccessToken(): Promise<string | null>;
|
|
44
|
+
onAuthChange?(callback: (state: AuthState) => void): () => void;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Sync binding returned by {@link createKoraAuthSync}.
|
|
48
|
+
* Passed to `createApp({ sync: { authClient } })` in korajs.
|
|
82
49
|
*/
|
|
83
|
-
|
|
84
|
-
|
|
50
|
+
interface KoraAuthSyncBinding {
|
|
51
|
+
/** Returns the access token for sync handshake (empty string when signed out). */
|
|
52
|
+
auth: () => Promise<{
|
|
53
|
+
token: string;
|
|
54
|
+
}>;
|
|
55
|
+
/** Builds a scope map from the current token and schema. */
|
|
56
|
+
resolveScopeMap?: () => Promise<ScopeMap | undefined>;
|
|
85
57
|
/**
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
* The database connection is lazily initialized on first use and
|
|
89
|
-
* reused for subsequent operations. If the database does not exist,
|
|
90
|
-
* it is created with the `keypairs` object store.
|
|
58
|
+
* Returns the device-bound sync node id from the token `dev` claim.
|
|
59
|
+
* Separate from the user id (`sub`).
|
|
91
60
|
*/
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
|
|
95
|
-
/** @inheritdoc */
|
|
96
|
-
loadKeyPair(deviceId: string): Promise<CryptoKeyPair | null>;
|
|
97
|
-
/** @inheritdoc */
|
|
98
|
-
deleteKeyPair(deviceId: string): Promise<void>;
|
|
99
|
-
/** @inheritdoc */
|
|
100
|
-
hasKeyPair(deviceId: string): Promise<boolean>;
|
|
61
|
+
resolveNodeId?: () => Promise<string | undefined>;
|
|
62
|
+
/** Notifies when auth state changes so sync can refresh scope or reconnect. */
|
|
63
|
+
subscribe?: (listener: () => void) => () => void;
|
|
101
64
|
}
|
|
102
65
|
/**
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
* Key pairs are stored in a plain Map and do not survive process restarts.
|
|
106
|
-
* This is suitable for server-side rendering, Node.js scripts, and unit tests
|
|
107
|
-
* where IndexedDB is not available.
|
|
108
|
-
*
|
|
109
|
-
* @example
|
|
110
|
-
* ```typescript
|
|
111
|
-
* const store = new InMemoryDeviceKeyStore()
|
|
112
|
-
* const keyPair = await generateDeviceKeyPair()
|
|
113
|
-
* await store.saveKeyPair('device-123', keyPair)
|
|
114
|
-
*
|
|
115
|
-
* const loaded = await store.loadKeyPair('device-123')
|
|
116
|
-
* ```
|
|
66
|
+
* Configuration for {@link createKoraAuthSync}.
|
|
117
67
|
*/
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
|
|
68
|
+
interface CreateKoraAuthSyncOptions {
|
|
69
|
+
/** Kora auth client from `createKoraAuth()`. */
|
|
70
|
+
authClient: AuthSyncClient;
|
|
71
|
+
/**
|
|
72
|
+
* Application schema. When provided, scope maps are built automatically
|
|
73
|
+
* from JWT claims and schema scope declarations.
|
|
74
|
+
*/
|
|
75
|
+
schema?: SchemaDefinition;
|
|
76
|
+
/**
|
|
77
|
+
* Custom claim → flat scope value mapping.
|
|
78
|
+
* Defaults to {@link extractScopeValuesFromClaims}.
|
|
79
|
+
*/
|
|
80
|
+
scopeFromClaims?: (claims: Record<string, unknown>) => Record<string, unknown>;
|
|
128
81
|
}
|
|
129
82
|
/**
|
|
130
|
-
* Creates a
|
|
131
|
-
*
|
|
132
|
-
* In browsers where IndexedDB is available, returns an {@link IndexedDBDeviceKeyStore}
|
|
133
|
-
* that persists CryptoKeyPair objects as structured clones. In Node.js, SSR,
|
|
134
|
-
* or environments without IndexedDB, returns an {@link InMemoryDeviceKeyStore}.
|
|
83
|
+
* Creates a sync auth binding for `createApp({ sync: { authClient: binding } })`.
|
|
135
84
|
*
|
|
136
|
-
*
|
|
85
|
+
* Wires token refresh, automatic scope maps from JWT claims, and device-bound
|
|
86
|
+
* sync node ids (`dev` claim) separate from the user id (`sub`).
|
|
137
87
|
*
|
|
138
88
|
* @example
|
|
139
89
|
* ```typescript
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
90
|
+
* import { createKoraAuth, createKoraAuthSync } from '@korajs/auth'
|
|
91
|
+
* import { createApp } from 'korajs'
|
|
92
|
+
*
|
|
93
|
+
* const authClient = createKoraAuth({ serverUrl: 'https://api.example.com' })
|
|
94
|
+
*
|
|
95
|
+
* const app = createApp({
|
|
96
|
+
* schema,
|
|
97
|
+
* sync: {
|
|
98
|
+
* url: 'wss://api.example.com/kora-sync',
|
|
99
|
+
* authClient: createKoraAuthSync({ authClient, schema }),
|
|
100
|
+
* },
|
|
101
|
+
* })
|
|
143
102
|
* ```
|
|
144
103
|
*/
|
|
145
|
-
declare function
|
|
104
|
+
declare function createKoraAuthSync(options: CreateKoraAuthSyncOptions): KoraAuthSyncBinding;
|
|
146
105
|
|
|
147
106
|
/**
|
|
148
107
|
* Client-side token storage for Kora auth tokens.
|
|
@@ -780,4 +739,4 @@ declare class AutoLockManager {
|
|
|
780
739
|
private _clearTimer;
|
|
781
740
|
}
|
|
782
741
|
|
|
783
|
-
export { AuthTokens, type AutoLockConfig, AutoLockManager, type
|
|
742
|
+
export { AuthClient, AuthClientConfig, AuthDeviceIdentityProvider, AuthKeyValueStorage, AuthState, type AuthSyncClient, AuthTokenStorage, AuthTokens, type AutoLockConfig, AutoLockManager, type CreateKoraAuthOptions, type CreateKoraAuthSyncOptions, DeviceKeyStore, EncryptedTokenStore, type EncryptedTokenStoreConfig, EncryptedTokenStoreError, EncryptionError, KeyDerivationError, type KoraAuthSyncBinding, type PasskeyAuthenticationResponse, PasskeyError, type PasskeyRegistrationResponse, PasskeyUnsupportedError, TokenStore, authenticateWithPasskey, createKoraAuth, createKoraAuthSync, createPasskeyCredential, decryptData, deriveEncryptionKey, encryptData, exportKey, generateEncryptionKey, generateSalt, importKey, isPasskeySupported, isPlatformAuthenticatorAvailable };
|