Skip to content

Commit

Permalink
feat: apply new version of SD JWT package (#1787)
Browse files Browse the repository at this point in the history
Signed-off-by: Lukas.J.Han <[email protected]>
Signed-off-by: Lukas <[email protected]>
  • Loading branch information
lukasjhan authored Apr 25, 2024
1 parent ca383c2 commit b41e158
Show file tree
Hide file tree
Showing 21 changed files with 830 additions and 222 deletions.
2 changes: 1 addition & 1 deletion demo-openid/src/Issuer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ function getCredentialRequestToCredentialMapper({
method: 'did',
didUrl: `${issuerDidKey.did}#${issuerDidKey.key.fingerprint}`,
},
disclosureFrame: { university: true, degree: true },
disclosureFrame: { _sd: ['university', 'degree'] },
}
}

Expand Down
6 changes: 4 additions & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@
"@digitalcredentials/jsonld-signatures": "^9.4.0",
"@digitalcredentials/vc": "^6.0.1",
"@multiformats/base-x": "^4.0.1",
"@sd-jwt/core": "^0.2.1",
"@sd-jwt/decode": "^0.2.1",
"@sd-jwt/core": "^0.6.1",
"@sd-jwt/decode": "^0.6.1",
"@sd-jwt/types": "^0.6.1",
"@sd-jwt/utils": "^0.6.1",
"@sphereon/pex": "^3.3.2",
"@sphereon/pex-models": "^2.2.4",
"@sphereon/ssi-types": "^0.23.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -516,8 +516,8 @@ export class DifPresentationExchangeService {
const sdJwtVcApi = this.getSdJwtVcApi(agentContext)
const sdJwtVc = await sdJwtVcApi.present({
compactSdJwtVc: sdJwtInput.compactSdJwtVc,
// SD is already handled by PEX
presentationFrame: true,
// SD is already handled by PEX, so we presents all keys
presentationFrame: undefined,
verifierMetadata: {
audience: domain,
nonce: challenge,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {
import type { IPresentationDefinition, SelectResults, SubmissionRequirementMatch, PEX } from '@sphereon/pex'
import type { InputDescriptorV1, InputDescriptorV2, SubmissionRequirement } from '@sphereon/pex-models'

import { decodeSdJwtVc } from '@sd-jwt/decode'
import { decodeSdJwt, decodeSdJwtSync, getClaimsSync } from '@sd-jwt/decode'

Check warning on line 10 in packages/core/src/modules/dif-presentation-exchange/utils/credentialSelection.ts

View workflow job for this annotation

GitHub Actions / Validate

'decodeSdJwt' is defined but never used
import { Rules } from '@sphereon/pex-models'
import { default as jp } from 'jsonpath'

Expand Down Expand Up @@ -59,12 +59,13 @@ export async function getCredentialsForRequest(
if (credentialRecord instanceof SdJwtVcRecord) {
// selectedEncoded always string when SdJwtVcRecord
// Get the decoded payload from the the selected credential, this already has SD applied
const { decodedPayload } = decodeSdJwtVc(selectedEncoded as string, Hasher.hash)
const { jwt, disclosures } = decodeSdJwtSync(selectedEncoded as string, Hasher.hash)
const prettyClaims = getClaimsSync(jwt.payload, disclosures, Hasher.hash)

return {
type: ClaimFormat.SdJwtVc,
credentialRecord,
disclosedPayload: decodedPayload,
disclosedPayload: prettyClaims as Record<string, unknown>,
}
} else if (credentialRecord instanceof W3cCredentialRecord) {
return {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/modules/sd-jwt-vc/SdJwtVcApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ export class SdJwtVcApi {
*
* Also, whether to include the holder key binding.
*/
public async present<Header extends SdJwtVcHeader, Payload extends SdJwtVcPayload>(
public async present<Payload extends SdJwtVcPayload = SdJwtVcPayload>(
options: SdJwtVcPresentOptions<Payload>
): Promise<string> {
return await this.sdJwtVcService.present<Header, Payload>(this.agentContext, options)
return await this.sdJwtVcService.present(this.agentContext, options)
}

/**
Expand Down
17 changes: 14 additions & 3 deletions packages/core/src/modules/sd-jwt-vc/SdJwtVcOptions.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import type { JwkJson, Jwk } from '../../crypto'
import type { HashName } from '../../utils'
import type { DisclosureFrame, PresentationFrame } from '@sd-jwt/core'

// TODO: extend with required claim names for input (e.g. vct)
export type SdJwtVcPayload = Record<string, unknown>
export type SdJwtVcHeader = Record<string, unknown>

export interface IDisclosureFrame {
_sd?: string[]
_sd_decoy?: number
[x: string]: string[] | number | IDisclosureFrame | undefined
}

export interface IPresentationFrame {
[x: string]: boolean | IPresentationFrame
}

export interface SdJwtVcHolderDidBinding {
method: 'did'
didUrl: string
Expand Down Expand Up @@ -33,21 +42,23 @@ export interface SdJwtVcSignOptions<Payload extends SdJwtVcPayload = SdJwtVcPayl
payload: Payload
holder: SdJwtVcHolderBinding
issuer: SdJwtVcIssuer
disclosureFrame?: DisclosureFrame<Payload>
disclosureFrame?: IDisclosureFrame

/**
* Default of sha-256 will be used if not provided
*/
hashingAlgorithm?: HashName
}

// TODO: use the payload type once types are fixed
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export type SdJwtVcPresentOptions<Payload extends SdJwtVcPayload = SdJwtVcPayload> = {
compactSdJwtVc: string

/**
* Use true to disclose everything
*/
presentationFrame: PresentationFrame<Payload> | true
presentationFrame?: IPresentationFrame

/**
* This information is received out-of-band from the verifier.
Expand Down
Loading

0 comments on commit b41e158

Please sign in to comment.