Skip to content

Commit

Permalink
feat: Add jwt as signature when decoding JWT VCs/VPs
Browse files Browse the repository at this point in the history
  • Loading branch information
nklomp committed Mar 7, 2023
1 parent b12912b commit f089ac1
Show file tree
Hide file tree
Showing 11 changed files with 161 additions and 188 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ export class OpSession {
/* if (!responseOpts.signer) {
throw Error('Signer needs to be present when creating the response')
}*/
//fixme: Remove ignore once support is in ICredential
// @ts-ignore
const authResponse = await op.createAuthorizationResponse(await this.getAuthorizationRequest(), responseOpts)
const response = await op.submitAuthorizationResponse(authResponse)

Expand Down
15 changes: 13 additions & 2 deletions packages/did-auth-siop-op-authenticator/src/session/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,34 @@ import { IVerifyCallbackArgs, IVerifyCredentialResult } from '@sphereon/wellknow
export async function createPresentationSignCallback({
presentationSignCallback,
kid,
domain,
challenge,
context,
}: {
presentationSignCallback?: PresentationSignCallback
kid: string
domain?: string,
challenge?: string,
context: IRequiredContext
}): Promise<PresentationSignCallback> {
// fixme: Remove once IPresentation in proper form is available in PEX
// @ts-ignore
return presentationSignCallback
? presentationSignCallback
: async (args: PresentationSignCallBackParams): Promise<W3CVerifiablePresentation> => {

const presentation: PresentationPayload = args.presentation as PresentationPayload
const format = args.presentationDefinition.format
return (await context.agent.createVerifiablePresentation({

const vp = await context.agent.createVerifiablePresentation({
presentation,
keyRef: kid,
domain,
challenge,
fetchRemoteContexts: true,
proofFormat: format && (format.ldp || format.ldp_vp) ? 'lds' : 'jwt',
})) as W3CVerifiablePresentation
})
return vp as W3CVerifiablePresentation
}
}

Expand Down
3 changes: 1 addition & 2 deletions packages/ssi-sdk-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
"dependencies": {
"@scure/base": "^1.1.1",
"@sphereon/ssi-types": "^0.8.0",
"@veramo/core": "4.2.0",
"typeorm": "^0.3.10"
"@veramo/core": "4.2.0"
},
"devDependencies": {
"@types/debug": "4.1.7",
Expand Down
8 changes: 3 additions & 5 deletions packages/ssi-sdk-core/src/utils/database.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { MigrationInterface } from 'typeorm'
export const flattenArray = <T>(args: { items: Array<T | Array<T>> }): Array<T> => args.items.flat() as Array<T>

export const flattenArray = (args: { items: Array<unknown | Array<unknown>> }): Array<unknown> => args.items.flat()

export const flattenMigrations = (args: { migrations: Array<MigrationInterface | Array<MigrationInterface>> }): Array<MigrationInterface> =>
args.migrations.flat()
export const flattenMigrations = <T>(args: { migrations: Array<T | Array<T>> }): Array<T> =>
args.migrations.flat() as Array<T>
3 changes: 3 additions & 0 deletions packages/ssi-types/__tests__/encoding.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ describe('Encoding - Decoding', () => {
})

it('Decoded JsonLd VP should have sub', () => {
if (!Array.isArray(decodedLdpVp.verifiableCredential) || decodedLdpVp.verifiableCredential.length < 2) {
throw Error('Should have at least 2 VCs')
}
expect((decodedLdpVp.verifiableCredential[1] as IVerifiableCredential).issuer).toEqual('did:foo:123')
})
it('Decoded Jsonld VC should have sub', () => {
Expand Down
8 changes: 4 additions & 4 deletions packages/ssi-types/__tests__/uniform-claims.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ describe('Uniform VP claims', () => {
// vp should be decoded
expect(vp.holder).toEqual('did:example:ebfeb1f712ebc6f1c276e12ec21')
// vc should be decoded for a uniform vp
const vc = vp.verifiableCredential[0] as IVerifiableCredential
const vc = vp.verifiableCredential?.[0] as IVerifiableCredential
expect(!Array.isArray(vc.credentialSubject) && vc.credentialSubject.degree.type).toEqual('BachelorDegree')
})

Expand All @@ -142,20 +142,20 @@ describe('Uniform VP claims', () => {
// vp should be decoded
expect(vp.holder).toEqual('did:example:ebfeb1f712ebc6f1c276e12ec21')
// vc should be decoded for a uniform vp
const vc = vp.verifiableCredential[0] as IVerifiableCredential
const vc = vp.verifiableCredential?.[0] as IVerifiableCredential
expect(!Array.isArray(vc.credentialSubject) && vc.credentialSubject.degree.type).toEqual('BachelorDegree')
})

it('JSON-LD VP String should populate response', () => {
const jsonLdVpAsStr = getFile('./packages/ssi-types/__tests__/vc_vp_examples/vp/vp_subject_is_holder.json')
const vp = CredentialMapper.toUniformPresentation(jsonLdVpAsStr)
// vp should be decoded
expect((vp.verifiableCredential[0] as IVerifiableCredential).issuer).toEqual('did:example:123')
expect((vp.verifiableCredential?.[0] as IVerifiableCredential).issuer).toEqual('did:example:123')
})
it('JSON-LD VP Object should populate response', () => {
const jsonLdVp = getFileAsJson('./packages/ssi-types/__tests__/vc_vp_examples/vp/vp_subject_is_holder.json')
const vp = CredentialMapper.toUniformPresentation(jsonLdVp)
// vp should be decoded
expect((vp.verifiableCredential[0] as IVerifiableCredential).issuer).toEqual('did:example:123')
expect((vp.verifiableCredential?.[0] as IVerifiableCredential).issuer).toEqual('did:example:123')
})
})
4 changes: 2 additions & 2 deletions packages/ssi-types/__tests__/wrapped-claims.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ describe('Wrapped VP', () => {
const vp = CredentialMapper.toWrappedVerifiablePresentation(jsonLdVpAsStr)
// vp should be decoded
expect(vp.original).toEqual(jsonLdVpAsStr)
expect(((vp.decoded as IVerifiablePresentation).verifiableCredential[1] as IVerifiableCredential).issuer).toEqual('did:foo:123')
expect(((vp.decoded as IVerifiablePresentation).verifiableCredential?.[1] as IVerifiableCredential).issuer).toEqual('did:foo:123')
expect(vp.type).toEqual(OriginalType.JSONLD)
expect(vp.format).toEqual('ldp_vp')
expect(vp.presentation.verifiableCredential[1].credential.issuer).toEqual('did:foo:123')
Expand All @@ -159,7 +159,7 @@ describe('Wrapped VP', () => {
const vp = CredentialMapper.toWrappedVerifiablePresentation(jsonLdVp)
// vp should be decoded
expect(vp.original).toEqual(jsonLdVp)
expect(((vp.decoded as IVerifiablePresentation).verifiableCredential[1] as IVerifiableCredential).issuer).toEqual('did:foo:123')
expect(((vp.decoded as IVerifiablePresentation).verifiableCredential?.[1] as IVerifiableCredential).issuer).toEqual('did:foo:123')
expect(vp.type).toEqual(OriginalType.JSONLD)
expect(vp.format).toEqual('ldp_vp')
expect(vp.presentation.verifiableCredential[1].credential.issuer).toEqual('did:foo:123')
Expand Down
Loading

0 comments on commit f089ac1

Please sign in to comment.