-
Notifications
You must be signed in to change notification settings - Fork 82
feat: credo v6.1 upgrade #1554
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: credo v6.1 upgrade #1554
Changes from all commits
de264c8
b51bfca
a7f4a5e
f34d8a5
c9f3696
457c699
2fec541
5326a3c
05ef3f5
76f750f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,3 @@ | ||
| import { AccessTokenSignerKeyType } from '../interfaces/oid4vc-issuance.interfaces'; | ||
|
|
||
| export const dpopSigningAlgValuesSupported = ['RS256', 'ES256', 'EdDSA']; | ||
| export const credentialConfigurationsSupported = {}; | ||
| export const accessTokenSignerKeyType = 'ed25519' as AccessTokenSignerKeyType; | ||
| export const batchCredentialIssuanceDefault = 0; |
| Original file line number | Diff line number | Diff line change | |||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,12 +3,7 @@ import { oidc_issuer, Prisma } from '@prisma/client'; | ||||||||||||||||||||||
| import { batchCredentialIssuanceDefault } from '../../constant/issuance'; | |||||||||||||||||||||||
| import { CreateOidcCredentialOffer } from '../../interfaces/oid4vc-issuer-sessions.interfaces'; | |||||||||||||||||||||||
| import { IssuerResponse } from 'apps/oid4vc-issuance/interfaces/oid4vc-issuance.interfaces'; | |||||||||||||||||||||||
| import { | |||||||||||||||||||||||
| Claim, | |||||||||||||||||||||||
| CredentialAttribute, | |||||||||||||||||||||||
| MdocTemplate, | |||||||||||||||||||||||
| SdJwtTemplate | |||||||||||||||||||||||
| } from 'apps/oid4vc-issuance/interfaces/oid4vc-template.interfaces'; | |||||||||||||||||||||||
| import { Claim, MdocTemplate, SdJwtTemplate } from 'apps/oid4vc-issuance/interfaces/oid4vc-template.interfaces'; | |||||||||||||||||||||||
| import { CredentialFormat } from '@credebl/enum/enum'; | |||||||||||||||||||||||
|
|
|||||||||||||||||||||||
| type AttributeDisplay = { name: string; locale: string }; | |||||||||||||||||||||||
|
|
@@ -44,19 +39,25 @@ type CredentialConfig = { | ||||||||||||||||||||||
| vct?: string; | |||||||||||||||||||||||
| scope: string; | |||||||||||||||||||||||
| doctype?: string; | |||||||||||||||||||||||
| claims: Claim[]; | |||||||||||||||||||||||
| credential_signing_alg_values_supported: string[]; | |||||||||||||||||||||||
|
|
|||||||||||||||||||||||
| credential_signing_alg_values_supported: string[] | number[]; | |||||||||||||||||||||||
| cryptographic_binding_methods_supported: string[]; | |||||||||||||||||||||||
| display: { name: string; description?: string; locale?: string }[]; | |||||||||||||||||||||||
|
|
|||||||||||||||||||||||
| credential_metadata: { | |||||||||||||||||||||||
| claims: Claim[]; | |||||||||||||||||||||||
| display: CredentialDisplayItem[]; | |||||||||||||||||||||||
| }; | |||||||||||||||||||||||
| }; | |||||||||||||||||||||||
|
|
|||||||||||||||||||||||
| type CredentialConfigurationsSupported = { | |||||||||||||||||||||||
| credentialConfigurationsSupported: Record<string, CredentialConfig>; | |||||||||||||||||||||||
| }; | |||||||||||||||||||||||
|
|
|||||||||||||||||||||||
| // ---- Static Lists (as requested) ---- | |||||||||||||||||||||||
| const STATIC_CREDENTIAL_ALGS = ['ES256', 'EdDSA'] as const; | |||||||||||||||||||||||
| const STATIC_BINDING_METHODS = ['did:key'] as const; | |||||||||||||||||||||||
| const STATIC_CREDENTIAL_ALGS_FOR_SDJWT = ['ES256', 'EdDSA'] as const; | |||||||||||||||||||||||
| const STATIC_CREDENTIAL_ALGS_FOR_MDOC = [-7, -9] as const; | |||||||||||||||||||||||
| const STATIC_BINDING_METHODS_FOR_SDJWT = ['did:key', 'did:web', 'did:jwk', 'jwk'] as const; | |||||||||||||||||||||||
| const STATIC_BINDING_METHODS_FOR_MDOC = ['cose_key'] as const; // We need to test 'did:key', 'did:web', 'did:jwk', 'jwk', | |||||||||||||||||||||||
|
Comment on lines
+57
to
+60
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🌐 Web query:
💡 Result:
Sources: [1] IANA COSE registries page, [2] RFC 9052, [3] RFC 9053. 🌐 Web query:
💡 Result: In the IANA COSE Algorithms registry, algorithm identifier -9 is:
Source: IANA “CBOR Object Signing and Encryption (COSE)” registry (COSE Algorithms table) [1] 🌐 Web query:
💡 Result: From the IANA “COSE Algorithms” registry, the complete entries for algorithm values -7 and -8 are: [1]
Source 🏁 Script executed: cat -n apps/oid4vc-issuance/libs/helpers/issuer.metadata.ts | head -80Repository: credebl/platform Length of output: 3192 Change COSE algorithm identifier for EdDSA from According to the IANA COSE Algorithms registry (RFC 9053), EdDSA is assigned the identifier This ensures the algorithm list correctly pairs ES256 ( 🤖 Prompt for AI Agents |
|||||||||||||||||||||||
|
|
|||||||||||||||||||||||
| // Safe coercion helpers | |||||||||||||||||||||||
| function coerceJsonObject<T>(v: Prisma.JsonValue): T | null { | |||||||||||||||||||||||
|
|
@@ -206,98 +207,60 @@ export function encodeIssuerPublicId(publicIssuerId: string): string { | ||||||||||||||||||||||
| return encodeURIComponent(publicIssuerId.trim()); | |||||||||||||||||||||||
| } | |||||||||||||||||||||||
|
|
|||||||||||||||||||||||
| ///--------------------------------------------------------- | |||||||||||||||||||||||
|
|
|||||||||||||||||||||||
| // function buildClaimsFromAttributesWithPath(attributes: CredentialAttribute[], parentPath: string[] = []): Claim[] { | |||||||||||||||||||||||
| // const claims: Claim[] = []; | |||||||||||||||||||||||
|
|
|||||||||||||||||||||||
| // for (const attr of attributes) { | |||||||||||||||||||||||
| // const currentPath = [...parentPath, attr.key]; | |||||||||||||||||||||||
|
|
|||||||||||||||||||||||
| // // 1️⃣ Add the parent attribute itself if it has display or mandatory metadata | |||||||||||||||||||||||
| // if ((attr.display && 0 < attr.display.length) || attr.mandatory) { | |||||||||||||||||||||||
| // const parentClaim: Claim = { path: currentPath }; | |||||||||||||||||||||||
|
|
|||||||||||||||||||||||
| // if (attr.display?.length) { | |||||||||||||||||||||||
| // parentClaim.display = attr.display.map((d) => ({ | |||||||||||||||||||||||
| // name: d.name, | |||||||||||||||||||||||
| // locale: d.locale | |||||||||||||||||||||||
| // })); | |||||||||||||||||||||||
| // } | |||||||||||||||||||||||
|
|
|||||||||||||||||||||||
| // if (attr.mandatory) { | |||||||||||||||||||||||
| // parentClaim.mandatory = true; | |||||||||||||||||||||||
| // } | |||||||||||||||||||||||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | |||||||||||||||||||||||
| function generateClaims(attributes: any[], namespace?: string, parentPath: string[] = []): Claim[] { | |||||||||||||||||||||||
| const result: Claim[] = []; | |||||||||||||||||||||||
|
|
|||||||||||||||||||||||
| // claims.push(parentClaim); | |||||||||||||||||||||||
| // } | |||||||||||||||||||||||
| for (const attr of attributes) { | |||||||||||||||||||||||
| const currentPath = [...parentPath, attr.key]; | |||||||||||||||||||||||
|
|
|||||||||||||||||||||||
| // // 2️⃣ If this attribute has nested children, recurse into them | |||||||||||||||||||||||
| // if (attr.children && 0 < attr.children.length) { | |||||||||||||||||||||||
| // claims.push(...buildClaimsFromAttributes(attr.children, currentPath)); | |||||||||||||||||||||||
| // } | |||||||||||||||||||||||
| // } | |||||||||||||||||||||||
| // return claims; | |||||||||||||||||||||||
| // } | |||||||||||||||||||||||
| const path = namespace ? [namespace, ...currentPath] : currentPath; | |||||||||||||||||||||||
|
|
|||||||||||||||||||||||
| /** | |||||||||||||||||||||||
| * Recursively builds a nested claims object from a list of attributes. | |||||||||||||||||||||||
| */ | |||||||||||||||||||||||
| function buildNestedClaims(attributes: CredentialAttribute[]): Record<string, Claim> { | |||||||||||||||||||||||
| const claims: Record<string, Claim> = {}; | |||||||||||||||||||||||
| const claim: Claim = { path }; | |||||||||||||||||||||||
|
|
|||||||||||||||||||||||
| for (const attr of attributes) { | |||||||||||||||||||||||
| const node: Claim = {}; | |||||||||||||||||||||||
|
|
|||||||||||||||||||||||
| // ✅ include display info | |||||||||||||||||||||||
| if (attr.display?.length) { | |||||||||||||||||||||||
| node.display = attr.display.map((d) => ({ | |||||||||||||||||||||||
| name: d.name, | |||||||||||||||||||||||
| locale: d.locale | |||||||||||||||||||||||
| })); | |||||||||||||||||||||||
| if (attr.display) { | |||||||||||||||||||||||
| claim.display = attr.display; | |||||||||||||||||||||||
| } | |||||||||||||||||||||||
|
|
|||||||||||||||||||||||
| // ✅ include mandatory flag | |||||||||||||||||||||||
| if (attr.mandatory) { | |||||||||||||||||||||||
| node.mandatory = true; | |||||||||||||||||||||||
| if (true === attr.mandatory) { | |||||||||||||||||||||||
| claim.mandatory = true; | |||||||||||||||||||||||
| } | |||||||||||||||||||||||
|
|
|||||||||||||||||||||||
| // ✅ handle nested children recursively | |||||||||||||||||||||||
| // Always push the claim (even if it only has path) | |||||||||||||||||||||||
| result.push(claim); | |||||||||||||||||||||||
|
|
|||||||||||||||||||||||
| // Handle nested children | |||||||||||||||||||||||
| if (attr.children?.length) { | |||||||||||||||||||||||
| const childClaims = buildNestedClaims(attr.children); | |||||||||||||||||||||||
| Object.assign(node, childClaims); // merge children into current node | |||||||||||||||||||||||
| result.push(...generateClaims(attr.children, namespace, currentPath)); | |||||||||||||||||||||||
| } | |||||||||||||||||||||||
|
|
|||||||||||||||||||||||
| claims[attr.key] = node; | |||||||||||||||||||||||
| } | |||||||||||||||||||||||
|
|
|||||||||||||||||||||||
| return claims; | |||||||||||||||||||||||
| return result; | |||||||||||||||||||||||
| } | |||||||||||||||||||||||
|
|
|||||||||||||||||||||||
| /** | |||||||||||||||||||||||
| * Builds claims object for both SD-JWT and MDOC credential templates. | |||||||||||||||||||||||
| */ | |||||||||||||||||||||||
| //TODO: Remove any type | |||||||||||||||||||||||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | |||||||||||||||||||||||
| function buildClaimsFromTemplate(template: SdJwtTemplate | MdocTemplate): Record<string, any> { | |||||||||||||||||||||||
| function buildClaimsFromTemplate(template: SdJwtTemplate | MdocTemplate): Claim[] { | |||||||||||||||||||||||
| // ✅ MDOC case — handle namespaces | |||||||||||||||||||||||
| if ((template as MdocTemplate).namespaces) { | |||||||||||||||||||||||
| const mdocTemplate = template as MdocTemplate; | |||||||||||||||||||||||
|
|
|||||||||||||||||||||||
| //TODO: Remove any type | |||||||||||||||||||||||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | |||||||||||||||||||||||
| const claims: Record<string, any> = {}; | |||||||||||||||||||||||
|
|
|||||||||||||||||||||||
| const claims: Claim[] = []; | |||||||||||||||||||||||
| for (const ns of mdocTemplate.namespaces) { | |||||||||||||||||||||||
| claims[ns.namespace] = buildNestedClaims(ns.attributes); | |||||||||||||||||||||||
| } | |||||||||||||||||||||||
| const generated = generateClaims(ns.attributes, ns.namespace); | |||||||||||||||||||||||
|
|
|||||||||||||||||||||||
| claims.push(...generated); | |||||||||||||||||||||||
| } | |||||||||||||||||||||||
| return claims; | |||||||||||||||||||||||
| } | |||||||||||||||||||||||
|
|
|||||||||||||||||||||||
| // ✅ SD-JWT case — flat attributes | |||||||||||||||||||||||
| const sdjwtTemplate = template as SdJwtTemplate; | |||||||||||||||||||||||
| return buildNestedClaims(sdjwtTemplate.attributes); | |||||||||||||||||||||||
| const claims = generateClaims(sdjwtTemplate.attributes); | |||||||||||||||||||||||
| return claims; | |||||||||||||||||||||||
| } | |||||||||||||||||||||||
|
|
|||||||||||||||||||||||
| //TODO: Fix this eslint issue | |||||||||||||||||||||||
|
|
@@ -316,14 +279,17 @@ export function buildSdJwtCredentialConfig(name: string, template: SdJwtTemplate | ||||||||||||||||||||||
| format: CredentialFormat.SdJwtVc, | |||||||||||||||||||||||
| scope: credentialScope, | |||||||||||||||||||||||
| vct: template.vct, | |||||||||||||||||||||||
| credential_signing_alg_values_supported: [...STATIC_CREDENTIAL_ALGS], | |||||||||||||||||||||||
| cryptographic_binding_methods_supported: [...STATIC_BINDING_METHODS], | |||||||||||||||||||||||
| // proof_types_supported: { | |||||||||||||||||||||||
| // jwt: { | |||||||||||||||||||||||
| // proof_signing_alg_values_supported: ['ES256'] | |||||||||||||||||||||||
| // } | |||||||||||||||||||||||
| // }, | |||||||||||||||||||||||
| claims | |||||||||||||||||||||||
| credential_signing_alg_values_supported: [...STATIC_CREDENTIAL_ALGS_FOR_SDJWT], | |||||||||||||||||||||||
| cryptographic_binding_methods_supported: [...STATIC_BINDING_METHODS_FOR_SDJWT], | |||||||||||||||||||||||
| proof_types_supported: { | |||||||||||||||||||||||
| jwt: { | |||||||||||||||||||||||
| proof_signing_alg_values_supported: ['ES256', 'EdDSA'] | |||||||||||||||||||||||
| } | |||||||||||||||||||||||
| }, | |||||||||||||||||||||||
| credential_metadata: { | |||||||||||||||||||||||
| claims, | |||||||||||||||||||||||
| display: [] | |||||||||||||||||||||||
| } | |||||||||||||||||||||||
| } | |||||||||||||||||||||||
| }; | |||||||||||||||||||||||
| } | |||||||||||||||||||||||
|
|
@@ -339,7 +305,6 @@ export function buildMdocCredentialConfig(name: string, template: MdocTemplate) | ||||||||||||||||||||||
| const credentialScope = `openid4vc:${template.doctype}-${formatSuffix}`; | |||||||||||||||||||||||
|
|
|||||||||||||||||||||||
| const claims = buildClaimsFromTemplate(template); | |||||||||||||||||||||||
|
|
|||||||||||||||||||||||
| // for (const ns of template.namespaces) { | |||||||||||||||||||||||
| // claims.push(...buildClaimsFromAttributes(ns.attributes, [ns.namespace])); | |||||||||||||||||||||||
| // } | |||||||||||||||||||||||
|
|
@@ -349,9 +314,17 @@ export function buildMdocCredentialConfig(name: string, template: MdocTemplate) | ||||||||||||||||||||||
| format: CredentialFormat.Mdoc, | |||||||||||||||||||||||
| scope: credentialScope, | |||||||||||||||||||||||
| doctype: template.doctype, | |||||||||||||||||||||||
| credential_signing_alg_values_supported: [...STATIC_CREDENTIAL_ALGS], | |||||||||||||||||||||||
| cryptographic_binding_methods_supported: [...STATIC_BINDING_METHODS], | |||||||||||||||||||||||
| claims | |||||||||||||||||||||||
| credential_signing_alg_values_supported: [...STATIC_CREDENTIAL_ALGS_FOR_MDOC], | |||||||||||||||||||||||
| cryptographic_binding_methods_supported: [...STATIC_BINDING_METHODS_FOR_MDOC], | |||||||||||||||||||||||
| proof_types_supported: { | |||||||||||||||||||||||
| jwt: { | |||||||||||||||||||||||
| proof_signing_alg_values_supported: ['ES256', 'EdDSA'] | |||||||||||||||||||||||
| } | |||||||||||||||||||||||
| }, | |||||||||||||||||||||||
| credential_metadata: { | |||||||||||||||||||||||
| claims, | |||||||||||||||||||||||
| display: [] | |||||||||||||||||||||||
| } | |||||||||||||||||||||||
| } | |||||||||||||||||||||||
| }; | |||||||||||||||||||||||
| } | |||||||||||||||||||||||
|
|
@@ -387,7 +360,6 @@ export function buildCredentialConfigurationsSupported(templateRows: any): Recor | ||||||||||||||||||||||
| templateToBuild, | |||||||||||||||||||||||
| format === CredentialFormat.Mdoc ? CredentialFormat.Mdoc : CredentialFormat.SdJwtVc | |||||||||||||||||||||||
| ); | |||||||||||||||||||||||
|
|
|||||||||||||||||||||||
| const appearanceJson = coerceJsonObject<unknown>(templateRow.appearance); | |||||||||||||||||||||||
|
|
|||||||||||||||||||||||
| // Prepare the display configuration | |||||||||||||||||||||||
|
|
@@ -406,12 +378,11 @@ export function buildCredentialConfigurationsSupported(templateRows: any): Recor | ||||||||||||||||||||||
|
|
|||||||||||||||||||||||
| // eslint-disable-next-line prefer-destructuring | |||||||||||||||||||||||
| const dynamicKey = Object.keys(credentialConfig)[0]; | |||||||||||||||||||||||
| Object.assign(credentialConfig[dynamicKey], { | |||||||||||||||||||||||
| Object.assign(credentialConfig[dynamicKey].credential_metadata, { | |||||||||||||||||||||||
| display: displayConfigurations | |||||||||||||||||||||||
| }); | |||||||||||||||||||||||
|
|
|||||||||||||||||||||||
| Object.assign(credentialConfigMap, credentialConfig); | |||||||||||||||||||||||
| } | |||||||||||||||||||||||
|
|
|||||||||||||||||||||||
| return credentialConfigMap; // ✅ Return flat map, not nested object | |||||||||||||||||||||||
| } | |||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.