@@ -3,12 +3,32 @@ import { ClaimSet } from "../ClaimSet";
33import { Credential } from "../Credential" ;
44import { Verifier } from "./Verifier" ;
55
6+ /**
7+ * Redirect verification requests to the relevant verifier by matching the credential format
8+ * to the keys of the internal verifier map.
9+ * In case the credential format is the meta type, it is assumed the value is a key/value map
10+ * with keys being credential formats, and values the associated tokens.
11+ * These results will be merged, if multiple credentials map to the same claim,
12+ * the result will depend on the execution order.
13+ */
614export class TypedVerifier implements Verifier {
715 private readonly logger = getLoggerFor ( this ) ;
816
9- constructor ( protected verifiers : Record < string , Verifier > ) { }
17+ constructor (
18+ protected readonly verifiers : Record < string , Verifier > ,
19+ protected readonly metaType ?: string ,
20+ ) { }
1021
1122 public async verify ( credential : Credential ) : Promise < ClaimSet > {
23+ // Recursively verify in case of a meta credential token
24+ if ( credential . format === this . metaType ) {
25+ const metaClaims = { } ;
26+ for ( const [ format , token ] of Object . entries ( credential . token ) ) {
27+ Object . assign ( metaClaims , await this . verify ( { format, token } ) ) ;
28+ }
29+ return metaClaims ;
30+ }
31+
1232 const verifier = this . verifiers [ credential . format ] ;
1333 this . logger . debug ( `Verifying credential with typed verifier ${ JSON . stringify ( credential ) } ` ) ;
1434
0 commit comments