Skip to content

Commit

Permalink
fix: changed credentials and grants to mandatory plus renamed the uri…
Browse files Browse the repository at this point in the history
… to url
sksadjad committed Jun 15, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 406c649 commit 2df3612
Showing 2 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions packages/oid4vci-rest-client/src/agent/OID4VCIRestClient.ts
Original file line number Diff line number Diff line change
@@ -20,15 +20,15 @@ export class OID4VCIRestClient implements IAgentPlugin {

private readonly baseUrl?: string

constructor(args?: { baseUrl?: string; definitionId?: string }) {
constructor(args?: { baseUrl?: string }) {
if (args?.baseUrl) {
this.baseUrl = args.baseUrl
}
}

private async vciClientCreateOfferUri(args: IVCIClientCreateOfferUriRequestArgs): Promise<IVCIClientCreateOfferUriResponse> {
if (!args.credentials) {
throw new Error("Can't generate the credential offer uri without credentials param present.")
if (!args.credentials || !args.grants) {
throw new Error("Can't generate the credential offer url without credentials and grants params present.")
}
const baseUrl = this.checkBaseUrlParameter(args.baseUri)
const request: IVCIClientCreateOfferUriRequest = {
@@ -37,7 +37,7 @@ export class OID4VCIRestClient implements IAgentPlugin {
if (args.grants) {
request['grants'] = args.grants
}
const url = this.uriWithBase(`webapp/credential-offers`, baseUrl)
const url = this.urlWithBase(`webapp/credential-offers`, baseUrl)
debug(`OID4VCIRestClient is going to send request: ${JSON.stringify(request)} to ${url}`)
const origResponse = await fetch(url, {
method: 'POST',
@@ -49,7 +49,7 @@ export class OID4VCIRestClient implements IAgentPlugin {
return await origResponse.json()
}

private uriWithBase(path: string, baseUrl?: string): string {
private urlWithBase(path: string, baseUrl?: string): string {
if (!this.baseUrl && !baseUrl) {
throw new Error('You have to provide baseUrl')
}
8 changes: 4 additions & 4 deletions packages/oid4vci-rest-client/src/types/IOID4VCIRestClient.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { IAgentContext, IPluginMethodMap, IResolver } from '@veramo/core'
import { IAgentContext, IPluginMethodMap } from '@veramo/core'
import { CredentialOfferFormat, Grant } from '@sphereon/oid4vci-common'

export interface IOID4VCIRestClient extends IPluginMethodMap {
vciClientCreateOfferUri(args: IVCIClientCreateOfferUriRequestArgs, context: IRequiredContext): Promise<IVCIClientCreateOfferUriResponse>
}

export interface IVCIClientCreateOfferUriRequestArgs {
grants?: Grant
credentials?: (CredentialOfferFormat | string)[]
grants: Grant
credentials: (CredentialOfferFormat | string)[]
baseUri?: string
}

@@ -20,4 +20,4 @@ export interface IVCIClientCreateOfferUriRequest {
grants?: Grant
}

export type IRequiredContext = IAgentContext<IResolver>
export type IRequiredContext = IAgentContext<never>

0 comments on commit 2df3612

Please sign in to comment.