@@ -8,34 +8,15 @@ import { defaultConfig } from './config/defaults';
88import { mergeConfig } from './config/merge' ;
99import { notImplemented } from './errors' ;
1010import { extractMRZInfo as parseMRZInfo } from './processing/mrz' ;
11- import { SDKEvent , SDKEventMap , SdkEvents } from './types/events' ;
12- import type {
13- Adapters ,
14- Config ,
15- Progress ,
16- ProofHandle ,
17- ProofRequest ,
18- RegistrationInput ,
19- RegistrationStatus ,
20- ScanOpts ,
21- ScanResult ,
22- SelfClient ,
23- Unsubscribe ,
24- ValidationInput ,
25- ValidationResult ,
26- } from './types/public' ;
11+ import { SDKEvent , SDKEventMap } from './types/events' ;
12+ import type { Adapters , Config , ScanOpts , ScanResult , SelfClient , Unsubscribe } from './types/public' ;
2713import { TrackEventParams } from './types/public' ;
2814/**
2915 * Optional adapter implementations used when a consumer does not provide their
3016 * own. These defaults are intentionally minimal no-ops suitable for tests and
3117 * non-production environments.
3218 */
33- const optionalDefaults : Required < Pick < Adapters , 'storage' | 'clock' | 'logger' > > = {
34- storage : {
35- get : async ( ) => null ,
36- set : async ( ) => { } ,
37- remove : async ( ) => { } ,
38- } ,
19+ const optionalDefaults : Required < Pick < Adapters , 'clock' | 'logger' > > = {
3920 clock : {
4021 now : ( ) => Date . now ( ) ,
4122 sleep : async ( ms : number ) => {
@@ -115,39 +96,14 @@ export function createSelfClient({
11596 }
11697
11798 async function scanDocument ( opts : ScanOpts & { signal ?: AbortSignal } ) : Promise < ScanResult > {
118- return _adapters . scanner . scan ( opts ) ;
119- }
120-
121- async function validateDocument ( _input : ValidationInput ) : Promise < ValidationResult > {
122- return { ok : false , reason : 'SELF_ERR_VALIDATION_STUB' } ;
123- }
124-
125- async function checkRegistration ( _input : RegistrationInput ) : Promise < RegistrationStatus > {
126- return { registered : false , reason : 'SELF_REG_STATUS_STUB' } ;
127- }
128-
129- async function registerDocument ( _input : RegistrationInput ) : Promise < RegistrationStatus > {
130- return { registered : false , reason : 'SELF_REG_STATUS_STUB' } ;
131- }
99+ // Apply scanner timeout from config if no signal provided
100+ if ( ! opts . signal && cfg . timeouts . scanMs ) {
101+ const controller = new AbortController ( ) ;
102+ setTimeout ( ( ) => controller . abort ( ) , cfg . timeouts . scanMs ) ;
103+ return _adapters . scanner . scan ( { ...opts , signal : controller . signal } ) ;
104+ }
132105
133- async function generateProof (
134- _req : ProofRequest ,
135- opts : {
136- signal ?: AbortSignal ;
137- onProgress ?: ( p : Progress ) => void ;
138- timeoutMs ?: number ;
139- } = { } ,
140- ) : Promise < ProofHandle > {
141- if ( ! adapters . network ) throw notImplemented ( 'network' ) ;
142- if ( ! adapters . crypto ) throw notImplemented ( 'crypto' ) ;
143- const timeoutMs = opts . timeoutMs ?? cfg . timeouts ?. proofMs ?? defaultConfig . timeouts . proofMs ;
144- void _adapters . clock . sleep ( timeoutMs ! , opts . signal ) . then ( ( ) => emit ( SdkEvents . ERROR , new Error ( 'timeout' ) ) ) ;
145- return {
146- id : 'stub' ,
147- status : 'pending' ,
148- result : async ( ) => ( { ok : false , reason : 'SELF_ERR_PROOF_STUB' } ) ,
149- cancel : ( ) => { } ,
150- } ;
106+ return _adapters . scanner . scan ( opts ) ;
151107 }
152108
153109 async function trackEvent ( event : string , payload ?: TrackEventParams ) : Promise < void > {
@@ -177,13 +133,9 @@ export function createSelfClient({
177133
178134 return {
179135 scanDocument,
180- validateDocument,
181136 trackEvent,
182137 getPrivateKey,
183138 hasPrivateKey,
184- checkRegistration,
185- registerDocument,
186- generateProof,
187139 extractMRZInfo : parseMRZInfo ,
188140 on,
189141 emit,
0 commit comments