Skip to content

Commit

Permalink
Minimal changes for OpenID V12 spec
Browse files Browse the repository at this point in the history
  • Loading branch information
sanderPostma committed Jan 10, 2024
1 parent 566f8a9 commit 7304c06
Show file tree
Hide file tree
Showing 37 changed files with 259 additions and 447 deletions.
4 changes: 2 additions & 2 deletions packages/callback-example/lib/IssuerCallback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Ed25519Signature2020 } from '@digitalcredentials/ed25519-signature-2020
import { Ed25519VerificationKey2020 } from '@digitalcredentials/ed25519-verification-key-2020'
import { securityLoader } from '@digitalcredentials/security-document-loader'
import vc from '@digitalcredentials/vc'
import { CredentialRequestV1_0_11 } from '@sphereon/oid4vci-common'
import { CredentialRequestV1_0_12 } from '@sphereon/oid4vci-common'
import { ICredential, W3CVerifiableCredential } from '@sphereon/ssi-types'

// Example on how to generate a did:key to issue a verifiable credential
Expand All @@ -19,7 +19,7 @@ export const getIssuerCallback = (credential: ICredential, keyPair: any, verific
throw new Error('A credential needs to be provided')
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
return async (_opts: { credentialRequest?: CredentialRequestV1_0_11; credential?: ICredential }): Promise<W3CVerifiableCredential> => {
return async (_opts: { credentialRequest?: CredentialRequestV1_0_12; credential?: ICredential }): Promise<W3CVerifiableCredential> => {
const documentLoader = securityLoader().build()
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const verificationKey: any = Array.from(keyPair.values())[0]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
ProofOfPossession,
} from '@sphereon/oid4vci-common'
import { CredentialOfferSession } from '@sphereon/oid4vci-common/dist'
import { CredentialSupportedBuilderV1_11, VcIssuer, VcIssuerBuilder } from '@sphereon/oid4vci-issuer'
import { CredentialSupportedBuilderV1_12, VcIssuer, VcIssuerBuilder } from '@sphereon/oid4vci-issuer'
import { MemoryStates } from '@sphereon/oid4vci-issuer'
import { CredentialDataSupplierResult } from '@sphereon/oid4vci-issuer/dist/types'
import { ICredential, IProofPurpose, IProofType, W3CVerifiableCredential } from '@sphereon/ssi-types'
Expand Down Expand Up @@ -85,7 +85,7 @@ describe('issuerCallback', () => {
const clientId = 'sphereon:wallet'

beforeAll(async () => {
const credentialsSupported: CredentialSupported = new CredentialSupportedBuilderV1_11()
const credentialsSupported: CredentialSupported = new CredentialSupportedBuilderV1_12()
.withCryptographicSuitesSupported('ES256K')
.withCryptographicBindingMethod('did')
.withFormat('jwt_vc_json')
Expand Down Expand Up @@ -236,7 +236,7 @@ describe('issuerCallback', () => {
callbacks: {
signCallback: proofOfPossessionCallbackFunction,
},
version: OpenId4VCIVersion.VER_1_0_11,
version: OpenId4VCIVersion.VER_1_0_12,
})
.withClientId(clientId)
.withKid(kid)
Expand All @@ -247,7 +247,7 @@ describe('issuerCallback', () => {
credentialTypes: ['VerifiableCredential'],
format: 'jwt_vc_json',
proofInput: proof,
version: OpenId4VCIVersion.VER_1_0_11,
version: OpenId4VCIVersion.VER_1_0_12,
})
expect(credentialRequest).toEqual({
format: 'jwt_vc_json',
Expand Down
2 changes: 1 addition & 1 deletion packages/client/lib/AccessTokenClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export class AccessTokenClient {
metadata: metadata
? metadata
: issuerOpts?.fetchMetadata
? await MetadataClient.retrieveAllMetadata(issuerOpts.issuer, { errorOnNotFound: false })
? await MetadataClient.retrieveAllMetadata([issuerOpts.issuer], { errorOnNotFound: false }) // TODO multi-server support?
: undefined,
});

Expand Down
30 changes: 8 additions & 22 deletions packages/client/lib/CredentialOfferClient.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import {
CredentialOffer,
CredentialOfferPayload,
CredentialOfferPayloadV1_0_09,
CredentialOfferRequestWithBaseUrl,
CredentialOfferV1_0_12,
determineSpecVersionFromURI,
Expand All @@ -24,24 +22,12 @@ export class CredentialOfferClient {
const scheme = uri.split('://')[0];
const baseUrl = uri.split('?')[0];
const version = determineSpecVersionFromURI(uri);
let credentialOffer: CredentialOffer;
let credentialOfferPayload: CredentialOfferPayload;
if (version < OpenId4VCIVersion.VER_1_0_11) {
credentialOfferPayload = convertURIToJsonObject(uri, {
arrayTypeProperties: ['credential_type'],
requiredProperties: uri.includes('credential_offer_uri=') ? ['credential_offer_uri'] : ['issuer', 'credential_type'],
}) as CredentialOfferPayloadV1_0_09;
credentialOffer = {
credential_offer: credentialOfferPayload,
};
} else {
credentialOffer = convertURIToJsonObject(uri, {
arrayTypeProperties: ['credentials'],
requiredProperties: uri.includes('credential_offer_uri=') ? ['credential_offer_uri'] : ['credential_offer'],
}) as CredentialOfferV1_0_11;
if (credentialOffer?.credential_offer_uri === undefined && !credentialOffer?.credential_offer) {
throw Error('Either a credential_offer or credential_offer_uri should be present in ' + uri);
}
const credentialOffer: CredentialOffer = convertURIToJsonObject(uri, {
arrayTypeProperties: ['credentials'],
requiredProperties: uri.includes('credential_offer_uri=') ? ['credential_offer_uri'] : ['credential_offer'],
}) as CredentialOfferV1_0_12;
if (credentialOffer?.credential_offer_uri === undefined && !credentialOffer?.credential_offer) {
throw Error('Either a credential_offer or credential_offer_uri should be present in ' + uri);
}
const request = await toUniformCredentialOfferRequest(credentialOffer, {
...opts,
Expand Down Expand Up @@ -77,7 +63,7 @@ export class CredentialOfferClient {

const isUri = requestWithBaseUrl.credential_offer_uri !== undefined;

if (version.valueOf() >= OpenId4VCIVersion.VER_1_0_11.valueOf()) {
if (version.valueOf() >= OpenId4VCIVersion.VER_1_0_12.valueOf()) {
// v11 changed from encoding every param to a encoded json object with a credential_offer param key
if (!baseUrl.includes('?')) {
param = isUri ? 'credential_offer_uri' : 'credential_offer';
Expand All @@ -98,7 +84,7 @@ export class CredentialOfferClient {
arrayTypeProperties: isUri ? [] : ['credential_type'],
uriTypeProperties: isUri
? ['credential_offer_uri']
: version >= OpenId4VCIVersion.VER_1_0_11
: version >= OpenId4VCIVersion.VER_1_0_12
? ['credential_issuer', 'credential_type']
: ['issuer', 'credential_type'],
param,
Expand Down
4 changes: 2 additions & 2 deletions packages/client/lib/CredentialRequestClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@ export class CredentialRequestClient {
}

private version(): OpenId4VCIVersion {
return this.credentialRequestOpts?.version ?? OpenId4VCIVersion.VER_1_0_11;
return this.credentialRequestOpts?.version ?? OpenId4VCIVersion.VER_1_0_12;
}

private isV11OrHigher(): boolean {
return this.version() >= OpenId4VCIVersion.VER_1_0_11;
return this.version() >= OpenId4VCIVersion.VER_1_0_12;
}
}
12 changes: 3 additions & 9 deletions packages/client/lib/CredentialRequestClientBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
AccessTokenResponse,
CredentialIssuerMetadata,
CredentialOfferPayloadV1_0_08,
CredentialOfferRequestWithBaseUrl,
determineSpecVersionFromOffer,
EndpointMetadata,
Expand Down Expand Up @@ -42,13 +41,8 @@ export class CredentialRequestClientBuilder {
builder.withVersion(version);
builder.withCredentialEndpoint(metadata?.credential_endpoint ?? (issuer.endsWith('/') ? `${issuer}credential` : `${issuer}/credential`));

if (version <= OpenId4VCIVersion.VER_1_0_08) {
//todo: This basically sets all types available during initiation. Probably the user only wants a subset. So do we want to do this?
builder.withCredentialType((request.original_credential_offer as CredentialOfferPayloadV1_0_08).credential_type);
} else {
// todo: look whether this is correct
builder.withCredentialType(getTypesFromOffer(request.credential_offer));
}
// todo: look whether this is correct
builder.withCredentialType(getTypesFromOffer(request.credential_offer));

return builder;
}
Expand Down Expand Up @@ -104,7 +98,7 @@ export class CredentialRequestClientBuilder {

public build(): CredentialRequestClient {
if (!this.version) {
this.withVersion(OpenId4VCIVersion.VER_1_0_11);
this.withVersion(OpenId4VCIVersion.VER_1_0_12);
}
return new CredentialRequestClient(this);
}
Expand Down
Loading

0 comments on commit 7304c06

Please sign in to comment.