From ed4fe7cff1f717d5b667da70d43b58d04651334d Mon Sep 17 00:00:00 2001 From: sksadjad <86593551+sksadjad@users.noreply.github.com> Date: Thu, 6 Apr 2023 10:52:16 +0200 Subject: [PATCH] feat: added issuer callback to arguments of the issuer builder Signed-off-by: sksadjad <86593551+sksadjad@users.noreply.github.com> --- packages/issuer/lib/VcIssuer.ts | 5 +++-- packages/issuer/lib/builder/VcIssuerBuilder.ts | 10 ++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/issuer/lib/VcIssuer.ts b/packages/issuer/lib/VcIssuer.ts index d35b4129..619f4745 100644 --- a/packages/issuer/lib/VcIssuer.ts +++ b/packages/issuer/lib/VcIssuer.ts @@ -6,9 +6,10 @@ export class VcIssuer { _userPinRequired?: boolean _issuerCallback?: CredentialIssuerCallback - constructor(issuerMetadata: IssuerMetadata, userPinRequired?: boolean) { + constructor(issuerMetadata: IssuerMetadata, args?: { userPinRequired?: boolean; callback?: CredentialIssuerCallback }) { this._issuerMetadata = issuerMetadata - this._userPinRequired = userPinRequired + this._userPinRequired = args && args.userPinRequired ? args.userPinRequired : false + this._issuerCallback = args && args.callback ? args.callback : undefined } public getIssuerMetadata() { diff --git a/packages/issuer/lib/builder/VcIssuerBuilder.ts b/packages/issuer/lib/builder/VcIssuerBuilder.ts index ade35b52..9e969fde 100644 --- a/packages/issuer/lib/builder/VcIssuerBuilder.ts +++ b/packages/issuer/lib/builder/VcIssuerBuilder.ts @@ -1,4 +1,4 @@ -import { CredentialSupported, Display, IssuerMetadata, TokenErrorResponse } from '@sphereon/openid4vci-common' +import { CredentialIssuerCallback, CredentialSupported, Display, IssuerMetadata, TokenErrorResponse } from '@sphereon/openid4vci-common' import { VcIssuer } from '../VcIssuer' @@ -11,6 +11,7 @@ export class VcIssuerBuilder { issuerDisplay?: Display[] credentialsSupported?: CredentialSupported[] userPinRequired?: boolean + issuerCallback?: CredentialIssuerCallback public withCredentialIssuer(issuer: string): VcIssuerBuilder { this.credentialIssuer = issuer @@ -68,6 +69,11 @@ export class VcIssuerBuilder { return this } + withIssuerCallback(cb: CredentialIssuerCallback): VcIssuerBuilder { + this.issuerCallback = cb + return this + } + public build(): VcIssuer { if (!this.credentialEndpoint || !this.credentialIssuer || !this.credentialsSupported) { throw new Error(TokenErrorResponse.invalid_request) @@ -92,6 +98,6 @@ export class VcIssuerBuilder { if (this.tokenEndpoint) { metadata.token_endpoint = this.tokenEndpoint } - return new VcIssuer(metadata, this.userPinRequired) + return new VcIssuer(metadata, { userPinRequired: this.userPinRequired, callback: this.issuerCallback }) } }