Skip to content

Commit

Permalink
Merge pull request #5 from TimoGlastra/feat/presentation-frame
Browse files Browse the repository at this point in the history
feat!: add presentation frame
  • Loading branch information
berendsliedrecht authored Nov 27, 2023
2 parents dad3afe + e786119 commit dc0345e
Show file tree
Hide file tree
Showing 16 changed files with 939 additions and 210 deletions.
50 changes: 32 additions & 18 deletions example/issuerHolderVerifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,27 +42,29 @@ const verifyCb: Verifier = ({ header, message, signature }) => {
const saltGenerator: SaltGenerator = () =>
getRandomValues(Buffer.alloc(16)).toString('base64url')

const payload = {
iss: 'https://issuer.org/issuer-123',
sub: 'https://holder.org/holder-321',
aud: 'https://verifier.org/verifier-987',
nbf: Math.floor(new Date().getTime() / 1000 - 1000),
exp: Math.floor(new Date().getTime() / 1000 + 1000),
age_over_21: true,
age_over_24: true,
age_over_65: false,
address: {
locality: 'Maxstadt',
postal_code: '12344',
country: 'DE',
street_address: 'Weidenstraße 22'
}
} as const

const issuer = async () => {
console.log('====== ISSUER ======')

const sdJwt = new SdJwt({
header: { alg: SignatureAndEncryptionAlgorithm.EdDSA },
payload: {
iss: 'https://issuer.org/issuer-123',
sub: 'https://holder.org/holder-321',
aud: 'https://verifier.org/verifier-987',
nbf: Math.floor(new Date().getTime() / 1000 - 1000),
exp: Math.floor(new Date().getTime() / 1000 + 1000),
age_over_21: true,
age_over_24: true,
age_over_65: false,
address: {
locality: 'Maxstadt',
postal_code: '12344',
country: 'DE',
street_address: 'Weidenstraße 22'
}
}
payload
})
.withHasher(hasherAndAlgorithm)
.withSigner(signer)
Expand Down Expand Up @@ -91,15 +93,27 @@ const issuer = async () => {
const holder = async (compact: string) => {
console.log('====== HOLDER ======')

const sdJwt = SdJwt.fromCompact(compact).withHasher(hasherAndAlgorithm)
const sdJwt = SdJwt.fromCompact<Record<string, unknown>, typeof payload>(
compact
).withHasher(hasherAndAlgorithm)

console.log('Claims: ')
console.log('========')
console.log(await sdJwt.getPrettyClaims())
console.log('========')
console.log()

const presentation = await sdJwt.present([1])
const presentationFrame = {
age_over_24: true
} as const

console.log('Presentation Frame:')
console.log('========')
console.log(presentationFrame)
console.log('========')
console.log()

const presentation = await sdJwt.present(presentationFrame)

console.log('Presenting: ')
console.log('============')
Expand Down
98 changes: 58 additions & 40 deletions example/vc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,49 +41,51 @@ const verifyCb: Verifier = ({ header, message, signature }) => {
const saltGenerator: SaltGenerator = () =>
getRandomValues(Buffer.alloc(16)).toString('base64url')

const payload = {
'@context': [
'https://www.w3.org/2018/credentials/v1',
'https://w3id.org/citizenship/v1',
'https://w3id.org/security/bbs/v1'
],
id: 'https://issuer.oidp.uscis.gov/credentials/83627465',
vct: ['VerifiableCredential', 'PermanentResidentCard'],
issuer: 'did:key:zUC74VEqqhEHQcgv4zagSPkqFJxuNWuoBPKjJuHETEUeHLoSqWt92viSsmaWjy82y2cgguc8e9hsGBifnVK67pQ4gve3m6iSboDkmJjxVEb1d6mRAx5fpMAejooNzNqqbTMVeUN',
identifier: '83627465',
name: 'Permanent Resident Card',
description: 'Government of Example Permanent Resident Card.',
issuanceDate: '2019-12-03T12:19:52Z',
expirationDate: '2029-12-03T12:19:52Z',
credentialSubject: {
id: 'did:example:b34ca6cd37bbf23',
type: ['PermanentResident', 'Person'],
givenName: 'JOHN',
familyName: 'SMITH',
gender: 'Male',
image: 'data:image/png;base64,iVBORw0KGgokJggg==',
residentSince: '2015-01-01',
lprCategory: 'C09',
lprNumber: '999-999-999',
commuterClassification: 'C1',
birthCountry: 'Bahamas',
birthDate: '1958-07-17'
},
proof: {
type: 'BbsBlsSignature2020',
created: '2022-04-13T13:47:47Z',
verificationMethod:
'did:key:zUC74VEqqhEHQcgv4zagSPkqFJxuNWuoBPKjJuHETEUeHLoSqWt92viSsmaWjy82y2cgguc8e9hsGBifnVK67pQ4gve3m6iSboDkmJjxVEb1d6mRAx5fpMAejooNzNqqbTMVeUN#zUC74VEqqhEHQcgv4zagSPkqFJxuNWuoBPKjJuHETEUeHLoSqWt92viSsmaWjy82y2cgguc8e9hsGBifnVK67pQ4gve3m6iSboDkmJjxVEb1d6mRAx5fpMAejooNzNqqbTMVeUN',
proofPurpose: 'assertionMethod',
proofValue:
'hoNNnnRIoEoaY9Fvg3pGVG2eWTAHnR1kIM01nObEL2FdI2IkkpM3246jn3VBD8KBYUHlKfzccE4m7waZyoLEkBLFiK2g54Q2i+CdtYBgDdkUDsoULSBMcH1MwGHwdjfXpldFNFrHFx/IAvLVniyeMQ=='
}
} as const

const issuer = async () => {
console.log('====== ISSUER ======')

const sdJwt = new SdJwt({
header: { alg: SignatureAndEncryptionAlgorithm.EdDSA },
payload: {
'@context': [
'https://www.w3.org/2018/credentials/v1',
'https://w3id.org/citizenship/v1',
'https://w3id.org/security/bbs/v1'
],
id: 'https://issuer.oidp.uscis.gov/credentials/83627465',
vct: ['VerifiableCredential', 'PermanentResidentCard'],
issuer: 'did:key:zUC74VEqqhEHQcgv4zagSPkqFJxuNWuoBPKjJuHETEUeHLoSqWt92viSsmaWjy82y2cgguc8e9hsGBifnVK67pQ4gve3m6iSboDkmJjxVEb1d6mRAx5fpMAejooNzNqqbTMVeUN',
identifier: '83627465',
name: 'Permanent Resident Card',
description: 'Government of Example Permanent Resident Card.',
issuanceDate: '2019-12-03T12:19:52Z',
expirationDate: '2029-12-03T12:19:52Z',
credentialSubject: {
id: 'did:example:b34ca6cd37bbf23',
type: ['PermanentResident', 'Person'],
givenName: 'JOHN',
familyName: 'SMITH',
gender: 'Male',
image: 'data:image/png;base64,iVBORw0KGgokJggg==',
residentSince: '2015-01-01',
lprCategory: 'C09',
lprNumber: '999-999-999',
commuterClassification: 'C1',
birthCountry: 'Bahamas',
birthDate: '1958-07-17'
},
proof: {
type: 'BbsBlsSignature2020',
created: '2022-04-13T13:47:47Z',
verificationMethod:
'did:key:zUC74VEqqhEHQcgv4zagSPkqFJxuNWuoBPKjJuHETEUeHLoSqWt92viSsmaWjy82y2cgguc8e9hsGBifnVK67pQ4gve3m6iSboDkmJjxVEb1d6mRAx5fpMAejooNzNqqbTMVeUN#zUC74VEqqhEHQcgv4zagSPkqFJxuNWuoBPKjJuHETEUeHLoSqWt92viSsmaWjy82y2cgguc8e9hsGBifnVK67pQ4gve3m6iSboDkmJjxVEb1d6mRAx5fpMAejooNzNqqbTMVeUN',
proofPurpose: 'assertionMethod',
proofValue:
'hoNNnnRIoEoaY9Fvg3pGVG2eWTAHnR1kIM01nObEL2FdI2IkkpM3246jn3VBD8KBYUHlKfzccE4m7waZyoLEkBLFiK2g54Q2i+CdtYBgDdkUDsoULSBMcH1MwGHwdjfXpldFNFrHFx/IAvLVniyeMQ=='
}
}
payload
})
.withHasher(hasherAndAlgorithm)
.withSigner(signer)
Expand Down Expand Up @@ -133,15 +135,31 @@ const issuer = async () => {
const holder = async (compact: string) => {
console.log('====== HOLDER ======')

const sdJwt = SdJwt.fromCompact(compact).withHasher(hasherAndAlgorithm)
const sdJwt = SdJwt.fromCompact<Record<string, unknown>, typeof payload>(
compact
).withHasher(hasherAndAlgorithm)

console.log('Claims: ')
console.log('========')
console.log(await sdJwt.getPrettyClaims())
console.log('========')
console.log()

const presentation = await sdJwt.present([0, 1, 6])
const presentationFrame = {
credentialSubject: {
image: true,
gender: true,
birthCountry: true
}
} as const

console.log('Presentation Frame:')
console.log('========')
console.log(presentationFrame)
console.log('========')
console.log()

const presentation = await sdJwt.present(presentationFrame)

console.log('Presenting: ')
console.log('============')
Expand Down
2 changes: 1 addition & 1 deletion src/sdJwt/disclosureFrame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export const applyDisclosureFrame = async <
}

const payloadClone = { ...payload }
cleanup.forEach((path) => deleteByPath(payloadClone, path.join('.')))
cleanup.forEach((path) => deleteByPath(payloadClone, path))

return { payload: payloadClone, disclosures }
}
Loading

0 comments on commit dc0345e

Please sign in to comment.