@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/dist/index.d.cts CHANGED
@@ -1,148 +1,107 @@
1
- export { A as AuthClient, a as AuthClientConfig, b as AuthError, c as AuthState, d as AuthUser, C as ClientInvitation, e as ClientMembership, f as ClientOrganization, O as OrgClient, g as OrgClientConfig, h as OrgClientError } from './org-client-BVTLKcIk.cjs';
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
- * Persist a key pair for the given device.
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
- saveKeyPair(deviceId: string, keyPair: CryptoKeyPair): Promise<void>;
12
+ storage?: AuthTokenStorage;
36
13
  /**
37
- * Load a previously stored key pair for the given device.
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
- loadKeyPair(deviceId: string): Promise<CryptoKeyPair | null>;
17
+ credentialStore?: AuthKeyValueStorage;
44
18
  /**
45
- * Delete a stored key pair for the given device.
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
- deleteKeyPair(deviceId: string): Promise<void>;
22
+ deviceIdentity?: AuthDeviceIdentityProvider | false;
53
23
  /**
54
- * Check whether a key pair exists for the given device.
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
- hasKeyPair(deviceId: string): Promise<boolean>;
26
+ deviceKeyStore?: DeviceKeyStore;
61
27
  }
62
28
  /**
63
- * Browser-based device key store backed by IndexedDB.
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
- * @example
74
- * ```typescript
75
- * const store = new IndexedDBDeviceKeyStore()
76
- * const keyPair = await generateDeviceKeyPair()
77
- * await store.saveKeyPair('device-123', keyPair)
78
- *
79
- * const loaded = await store.loadKeyPair('device-123')
80
- * // loaded.privateKey is still non-extractable
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
- declare class IndexedDBDeviceKeyStore implements DeviceKeyStore {
84
- private dbPromise;
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
- * Opens (or creates) the IndexedDB database.
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
- private openDatabase;
93
- /** @inheritdoc */
94
- saveKeyPair(deviceId: string, keyPair: CryptoKeyPair): Promise<void>;
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
- * In-memory device key store for Node.js and testing environments.
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
- declare class InMemoryDeviceKeyStore implements DeviceKeyStore {
119
- private readonly store;
120
- /** @inheritdoc */
121
- saveKeyPair(deviceId: string, keyPair: CryptoKeyPair): Promise<void>;
122
- /** @inheritdoc */
123
- loadKeyPair(deviceId: string): Promise<CryptoKeyPair | null>;
124
- /** @inheritdoc */
125
- deleteKeyPair(deviceId: string): Promise<void>;
126
- /** @inheritdoc */
127
- hasKeyPair(deviceId: string): Promise<boolean>;
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 DeviceKeyStore appropriate for the current environment.
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
- * @returns A DeviceKeyStore instance for the current environment
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
- * const store = createDeviceKeyStore()
141
- * const keyPair = await generateDeviceKeyPair()
142
- * await store.saveKeyPair(deviceId, keyPair)
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 createDeviceKeyStore(): DeviceKeyStore;
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 DeviceKeyStore, DeviceKeyStoreError, EncryptedTokenStore, type EncryptedTokenStoreConfig, EncryptedTokenStoreError, EncryptionError, InMemoryDeviceKeyStore, IndexedDBDeviceKeyStore, KeyDerivationError, type PasskeyAuthenticationResponse, PasskeyError, type PasskeyRegistrationResponse, PasskeyUnsupportedError, TokenStore, authenticateWithPasskey, createDeviceKeyStore, createPasskeyCredential, decryptData, deriveEncryptionKey, encryptData, exportKey, generateEncryptionKey, generateSalt, importKey, isPasskeySupported, isPlatformAuthenticatorAvailable };
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
- export { A as AuthClient, a as AuthClientConfig, b as AuthError, c as AuthState, d as AuthUser, C as ClientInvitation, e as ClientMembership, f as ClientOrganization, O as OrgClient, g as OrgClientConfig, h as OrgClientError } from './org-client-BVTLKcIk.js';
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
- * Persist a key pair for the given device.
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
- saveKeyPair(deviceId: string, keyPair: CryptoKeyPair): Promise<void>;
12
+ storage?: AuthTokenStorage;
36
13
  /**
37
- * Load a previously stored key pair for the given device.
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
- loadKeyPair(deviceId: string): Promise<CryptoKeyPair | null>;
17
+ credentialStore?: AuthKeyValueStorage;
44
18
  /**
45
- * Delete a stored key pair for the given device.
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
- deleteKeyPair(deviceId: string): Promise<void>;
22
+ deviceIdentity?: AuthDeviceIdentityProvider | false;
53
23
  /**
54
- * Check whether a key pair exists for the given device.
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
- hasKeyPair(deviceId: string): Promise<boolean>;
26
+ deviceKeyStore?: DeviceKeyStore;
61
27
  }
62
28
  /**
63
- * Browser-based device key store backed by IndexedDB.
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
- * @example
74
- * ```typescript
75
- * const store = new IndexedDBDeviceKeyStore()
76
- * const keyPair = await generateDeviceKeyPair()
77
- * await store.saveKeyPair('device-123', keyPair)
78
- *
79
- * const loaded = await store.loadKeyPair('device-123')
80
- * // loaded.privateKey is still non-extractable
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
- declare class IndexedDBDeviceKeyStore implements DeviceKeyStore {
84
- private dbPromise;
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
- * Opens (or creates) the IndexedDB database.
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
- private openDatabase;
93
- /** @inheritdoc */
94
- saveKeyPair(deviceId: string, keyPair: CryptoKeyPair): Promise<void>;
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
- * In-memory device key store for Node.js and testing environments.
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
- declare class InMemoryDeviceKeyStore implements DeviceKeyStore {
119
- private readonly store;
120
- /** @inheritdoc */
121
- saveKeyPair(deviceId: string, keyPair: CryptoKeyPair): Promise<void>;
122
- /** @inheritdoc */
123
- loadKeyPair(deviceId: string): Promise<CryptoKeyPair | null>;
124
- /** @inheritdoc */
125
- deleteKeyPair(deviceId: string): Promise<void>;
126
- /** @inheritdoc */
127
- hasKeyPair(deviceId: string): Promise<boolean>;
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 DeviceKeyStore appropriate for the current environment.
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
- * @returns A DeviceKeyStore instance for the current environment
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
- * const store = createDeviceKeyStore()
141
- * const keyPair = await generateDeviceKeyPair()
142
- * await store.saveKeyPair(deviceId, keyPair)
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 createDeviceKeyStore(): DeviceKeyStore;
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 DeviceKeyStore, DeviceKeyStoreError, EncryptedTokenStore, type EncryptedTokenStoreConfig, EncryptedTokenStoreError, EncryptionError, InMemoryDeviceKeyStore, IndexedDBDeviceKeyStore, KeyDerivationError, type PasskeyAuthenticationResponse, PasskeyError, type PasskeyRegistrationResponse, PasskeyUnsupportedError, TokenStore, authenticateWithPasskey, createDeviceKeyStore, createPasskeyCredential, decryptData, deriveEncryptionKey, encryptData, exportKey, generateEncryptionKey, generateSalt, importKey, isPasskeySupported, isPlatformAuthenticatorAvailable };
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 };