-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: fetch sd-jwt type metadata (#2092)
Signed-off-by: Timo Glastra <[email protected]>
- Loading branch information
1 parent
17ec6b8
commit 607659a
Showing
13 changed files
with
210 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@credo-ts/core": patch | ||
"@credo-ts/openid4vc": patch | ||
--- | ||
|
||
feat: fetch sd-jwt type metadata |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import type { Key } from '@credo-ts/core' | ||
|
||
import nock, { cleanAll } from 'nock' | ||
|
||
import { getInMemoryAgentOptions } from '../../../../tests' | ||
|
||
import { Agent, DidKey, getJwkFromKey, KeyType, TypedArrayEncoder } from '@credo-ts/core' | ||
|
@@ -37,8 +39,10 @@ describe('sd-jwt-vc end to end test', () => { | |
}) | ||
|
||
test('end to end flow', async () => { | ||
nock('https://example.com').get('/.well-known/vct/vct-type').reply(200, { vct: 'https://example.com/vct-type' }) | ||
|
||
const credential = { | ||
vct: 'IdentityCredential', | ||
vct: 'https://example.com/vct-type', | ||
given_name: 'John', | ||
family_name: 'Doe', | ||
email: '[email protected]', | ||
|
@@ -129,7 +133,7 @@ describe('sd-jwt-vc end to end test', () => { | |
}, | ||
iat: expect.any(Number), | ||
iss: 'did:key:z6MktqtXNG8CDUY9PrrtoStFzeCnhpMmgxYL1gikcW3BzvNW', | ||
vct: 'IdentityCredential', | ||
vct: 'https://example.com/vct-type', | ||
}, | ||
prettyClaims: { | ||
address: { | ||
|
@@ -155,15 +159,20 @@ describe('sd-jwt-vc end to end test', () => { | |
is_over_65: true, | ||
iss: 'did:key:z6MktqtXNG8CDUY9PrrtoStFzeCnhpMmgxYL1gikcW3BzvNW', | ||
phone_number: '+1-202-555-0101', | ||
vct: 'IdentityCredential', | ||
vct: 'https://example.com/vct-type', | ||
}, | ||
typeMetadata: undefined, | ||
}) | ||
|
||
// Verify SD-JWT (does not require key binding) | ||
const { verification } = await holder.sdJwtVc.verify({ | ||
const verificationResult = await holder.sdJwtVc.verify({ | ||
compactSdJwtVc: compact, | ||
fetchTypeMetadata: true, | ||
}) | ||
expect(verificationResult.verification.isValid).toBe(true) | ||
expect(verificationResult.sdJwtVc?.typeMetadata).toEqual({ | ||
vct: 'https://example.com/vct-type', | ||
}) | ||
expect(verification.isValid).toBe(true) | ||
|
||
// Store credential | ||
await holder.sdJwtVc.store(compact) | ||
|
@@ -217,5 +226,7 @@ describe('sd-jwt-vc end to end test', () => { | |
}) | ||
|
||
expect(presentationVerification.isValid).toBeTruthy() | ||
|
||
cleanAll() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import type { SdJwtVcHeader, SdJwtVcPayload } from './SdJwtVcOptions' | ||
import type { SdJwtVcTypeMetadata } from './typeMetadata' | ||
|
||
import { decodeSdJwtSync, getClaimsSync } from '@sd-jwt/decode' | ||
|
||
import { Hasher } from '../../crypto' | ||
|
||
export function sdJwtVcHasher(data: string | ArrayBufferLike, alg: string) { | ||
return Hasher.hash(typeof data === 'string' ? data : new Uint8Array(data), alg) | ||
} | ||
|
||
export function decodeSdJwtVc< | ||
Header extends SdJwtVcHeader = SdJwtVcHeader, | ||
Payload extends SdJwtVcPayload = SdJwtVcPayload | ||
>(compactSdJwtVc: string, typeMetadata?: SdJwtVcTypeMetadata) { | ||
// NOTE: we use decodeSdJwtSync so we can make this method sync | ||
const { jwt, disclosures } = decodeSdJwtSync(compactSdJwtVc, sdJwtVcHasher) | ||
const prettyClaims = getClaimsSync(jwt.payload, disclosures, sdJwtVcHasher) | ||
|
||
return { | ||
compact: compactSdJwtVc, | ||
header: jwt.header as Header, | ||
payload: jwt.payload as Payload, | ||
prettyClaims: prettyClaims as Payload, | ||
typeMetadata, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.