-
Notifications
You must be signed in to change notification settings - Fork 180
Auth Adapter + #958
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Auth Adapter + #958
Changes from 14 commits
2f07dc8
5bf7bab
5de2e93
73188a9
313a3f8
add04d4
5280eef
1c779c8
724123d
1b78059
3cccb4d
d168c5d
2b758cd
41791f3
5a124a0
3f0f6f7
402507a
cfa5f39
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,7 +30,7 @@ import { TrackEventParams } from './types/public'; | |
| * own. These defaults are intentionally minimal no-ops suitable for tests and | ||
| * non-production environments. | ||
| */ | ||
| const optionalDefaults: Partial<Adapters> = { | ||
| const optionalDefaults: Required<Pick<Adapters, 'storage' | 'clock' | 'logger'>> = { | ||
| storage: { | ||
| get: async () => null, | ||
| set: async () => {}, | ||
|
|
@@ -47,7 +47,7 @@ const optionalDefaults: Partial<Adapters> = { | |
| }, | ||
| }; | ||
|
|
||
| const REQUIRED_ADAPTERS = ['scanner', 'network', 'crypto', 'documents'] as const; | ||
| const REQUIRED_ADAPTERS = ['auth', 'scanner', 'network', 'crypto', 'documents'] as const; | ||
aaronmgdr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * Creates a fully configured {@link SelfClient} instance. | ||
|
|
@@ -56,14 +56,14 @@ const REQUIRED_ADAPTERS = ['scanner', 'network', 'crypto', 'documents'] as const | |
| * provided configuration with sensible defaults. Missing optional adapters are | ||
| * filled with benign no-op implementations. | ||
| */ | ||
| export function createSelfClient({ config, adapters }: { config: Config; adapters: Partial<Adapters> }): SelfClient { | ||
| export function createSelfClient({ config, adapters }: { config: Config; adapters: Adapters }): SelfClient { | ||
| const cfg = mergeConfig(defaultConfig, config); | ||
|
|
||
| for (const name of REQUIRED_ADAPTERS) { | ||
| if (!(name in adapters) || !adapters[name as keyof Adapters]) throw notImplemented(name); | ||
| } | ||
|
|
||
| const _adapters = { ...optionalDefaults, ...adapters } as Adapters; | ||
| const _adapters = { ...optionalDefaults, ...adapters }; | ||
| const listeners = new Map<SDKEvent, Set<(p: any) => void>>(); | ||
|
|
||
| function on<E extends SDKEvent>(event: E, cb: (payload: SDKEventMap[E]) => void): Unsubscribe { | ||
|
|
@@ -128,10 +128,30 @@ export function createSelfClient({ config, adapters }: { config: Config; adapter | |
| return adapters.analytics.trackEvent(event, payload); | ||
| } | ||
|
|
||
| /** | ||
| * Retrieves the private key via the auth adapter. | ||
| * With great power comes great responsibility | ||
| */ | ||
| async function getPrivateKey(): Promise<string | null> { | ||
| return adapters.auth.getPrivateKey(); | ||
| } | ||
|
Comment on lines
+131
to
+137
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Gate getPrivateKey behind an explicit feature flag to reduce accidental exposure Even in alpha, protect this API behind config.features.devExposePrivateKey === true. async function getPrivateKey(): Promise<string | null> {
- return adapters.auth.getPrivateKey();
+ if (cfg.features?.devExposePrivateKey !== true) {
+ throw new Error('private-key access is disabled by configuration');
+ }
+ return adapters.auth.getPrivateKey();
}
🤖 Prompt for AI Agents |
||
|
|
||
| async function hasPrivateKey(): Promise<boolean> { | ||
| if (!adapters.auth) return false; | ||
| try { | ||
| const key = await adapters.auth.getPrivateKey(); | ||
| return !!key; | ||
| } catch { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| return { | ||
| scanDocument, | ||
| validateDocument, | ||
| trackEvent, | ||
| getPrivateKey, | ||
| hasPrivateKey, | ||
| checkRegistration, | ||
| registerDocument, | ||
| generateProof, | ||
|
|
||
This file was deleted.
This file was deleted.
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.