Skip to content

Commit

Permalink
feat: added optional issuer callback to parameters of issueCredential…
Browse files Browse the repository at this point in the history
…FromIssueRequest

Signed-off-by: sksadjad <[email protected]>
  • Loading branch information
sksadjad committed Apr 6, 2023
1 parent ed4fe7c commit a7a9e4a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
3 changes: 2 additions & 1 deletion packages/issuer-rest/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ export class RestAPI {

constructor(opts?: { metadata: IssuerMetadata; userPinRequired: boolean }) {
dotenv.config()
this._vcIssuer = opts ? (this._vcIssuer = new VcIssuer(opts.metadata, opts.userPinRequired)) : buildVCIFromEnvironment()
// todo: we probably want to pass a dummy issuance callback function here
this._vcIssuer = opts ? (this._vcIssuer = new VcIssuer(opts.metadata, { userPinRequired: opts.userPinRequired })) : buildVCIFromEnvironment()
this.express = express()
const port = process.env.PORT || 3000
const secret = process.env.COOKIE_SIGNING_KEY
Expand Down
19 changes: 15 additions & 4 deletions packages/issuer/lib/VcIssuer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,19 @@ export class VcIssuer {
return this._issuerMetadata
}

public async issueCredentialFromIssueRequest(issueCredentialRequest: CredentialRequest): Promise<CredentialResponse> {
/**
* issueCredentialFromIssueRequest
* @param issueCredentialRequest a credential issuance request
* @param issuerCallback OPTIONAL. if provided will use this callback instead what is configured in the VcIssuer
*/
public async issueCredentialFromIssueRequest(
issueCredentialRequest: CredentialRequest,
issuerCallback?: CredentialIssuerCallback
): Promise<CredentialResponse> {
//TODO: do we want additional validations here?
if (this.isMetadataSupportCredentialRequestFormat(issueCredentialRequest.format)) {
return {
credential: await this.issueCredential({ credentialRequest: issueCredentialRequest }),
credential: await this.issueCredential({ credentialRequest: issueCredentialRequest }, issuerCallback),
format: issueCredentialRequest.format,
}
}
Expand All @@ -41,10 +49,13 @@ export class VcIssuer {
}
return false
}
private async issueCredential(opts: { credentialRequest?: CredentialRequest; credential?: ICredential }): Promise<W3CVerifiableCredential> {
private async issueCredential(
opts: { credentialRequest?: CredentialRequest; credential?: ICredential },
issuerCallback?: CredentialIssuerCallback
): Promise<W3CVerifiableCredential> {
if ((!opts.credential && !opts.credentialRequest) || !this._issuerCallback) {
throw new Error('Issuer not configured correctly.')
}
return await this._issuerCallback(opts)
return issuerCallback ? await issuerCallback(opts) : this._issuerCallback(opts)
}
}

0 comments on commit a7a9e4a

Please sign in to comment.