import { IExpectedIdToken } from '../options/IExpected' ; import { IdTokenValidationResponse } from './IdTokenValidationResponse' ; import { IValidationOptions } from '../options/IValidationOptions' ; import ClaimToken , { TokenType } from '../verifiable_credential/ClaimToken' ; import { BaseIdTokenValidation } from './BaseIdTokenValidation' ; import ErrorHelpers from '../error_handling/ErrorHelpers' ; const errorCode = ( error ) => ErrorHelpers . errorCode ( 'VCSDKIDVa' , error ) ; /**
 * Class for id token validation for the Verifiable Credential attestation scenario
 */ export class IdTokenValidation extends BaseIdTokenValidation { param options param expected param siopContract constructor ( options , private expected , private siopContract ) { super ( options , expected ) ; } param expected param siopContract private getIssuersFromExpected ( ) { if ( ! this . expected . configuration ) { return { result : false , status : 500 , code : errorCode ( 1 ) , detailedError : `Expected should have configuration issuers set for idToken` } ; } let issuers ; if ( this . expected . configuration instanceof Array ) { if ( this . expected . configuration . length === 0 ) { return { result : false , status : 500 , code : errorCode ( 2 ) , detailedError : `Expected should have configuration issuers set for idToken. Empty array presented.` } ; } issuers = < string [ ] > this . expected . configuration ; } else { if ( ! this . siopContract ) { return { result : false , status : 500 , code : errorCode ( 3 ) , detailedError : `The siopContract needs to be specified to validate the idTokens.` } ; } if ( ! ( < { [ contract ] : string [ ] ; } > this . expected . configuration ) [ this . siopContract ] ) { return { result : false , status : 500 , code : errorCode ( 4 ) , detailedError : `Expected should have configuration issuers set for idToken. Missing configuration for '${ this . siopContract }'.` } ; } issuers = < string [ ] > this . expected . configuration [ this . siopContract ] ; } return issuers ; } protected downloadConfigurationAndValidate ( validationResponse , idToken ) { const issuers = this . getIssuersFromExpected ( ) ; if ( ! ( issuers instanceof Array ) ) { return Promise . resolve ( < IdTokenValidationResponse > issuers ) ; } const { id } = idToken ; if ( issuers . indexOf ( id ) < 0 ) { return Promise . resolve ( { code : errorCode ( 5 ) , detailedError : `'${ id }' is not configured as a trusted OpenID Provider.` , result : false , status : 403 , } ) ; } return this . options . fetchKeyAndValidateSignatureOnIdTokenDelegate ( validationResponse , idToken ) ; } }