Skip to content

Commit

Permalink
feat: added setDefaultTokenEndpoint to VcIssuer constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
sksadjad committed Jun 13, 2024
1 parent 96608ec commit f16affc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
8 changes: 8 additions & 0 deletions packages/issuer/lib/VcIssuer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
CreateCredentialOfferURIResult,
CREDENTIAL_MISSING_ERROR,
CredentialDataSupplierInput,
CredentialIssuerMetadata,
CredentialIssuerMetadataOpts,
CredentialOfferFormat,
CredentialOfferPayloadV1_0_11,
Expand Down Expand Up @@ -69,6 +70,7 @@ export class VcIssuer<DIDDoc extends object> {
cNonceExpiresIn?: number | undefined // expiration duration in seconds
},
) {
this.setDefaultTokenEndpoint(issuerMetadata)
this._issuerMetadata = issuerMetadata
this._defaultCredentialOfferBaseUri = args.defaultCredentialOfferBaseUri
this._credentialOfferSessions = args.credentialOfferSessions
Expand Down Expand Up @@ -603,6 +605,12 @@ export class VcIssuer<DIDDoc extends object> {
return credential
}

private setDefaultTokenEndpoint(issuerMetadata: Partial<CredentialIssuerMetadata>) {
if (!issuerMetadata.token_endpoint) {
issuerMetadata.token_endpoint = `${issuerMetadata.credential_issuer}/token`
}
}

get userPinRequired(): boolean {
return this._userPinRequired
}
Expand Down
7 changes: 0 additions & 7 deletions packages/issuer/lib/builder/VcIssuerBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,6 @@ export class VcIssuerBuilder<DIDDoc extends object> {
return this
}

private setDefaultTokenEndpoint(issuerMetadata: Partial<CredentialIssuerMetadata>) {
if (!issuerMetadata.token_endpoint) {
issuerMetadata.token_endpoint = `${issuerMetadata.credential_issuer}/token`
}
}

public build(): VcIssuer<DIDDoc> {
if (!this.credentialOfferStateManager) {
throw new Error(TokenErrorResponse.invalid_request)
Expand All @@ -161,7 +155,6 @@ export class VcIssuerBuilder<DIDDoc extends object> {

const builder = this.issuerMetadataBuilder?.build()
const metadata: Partial<CredentialIssuerMetadata> = { ...this.issuerMetadata, ...builder }
this.setDefaultTokenEndpoint(metadata)
// Let's make sure these get merged correctly:
metadata.credentials_supported = [...(this.issuerMetadata.credentials_supported ?? []), ...(builder?.credentials_supported ?? [])]
metadata.display = [...(this.issuerMetadata.display ?? []), ...(builder?.display ?? [])]
Expand Down

0 comments on commit f16affc

Please sign in to comment.