Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions heka-wallet/app/__tests__/credentials/useOpenIdHandlers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ describe('useOpenIdHandlers', () => {
accessToken: fixture.tokenResponse,
})


expect(credentialRecord).toMatchObject({ id: 'mock-record' })

expect(mockAgent.openid4vc.holder.requestCredentials).toHaveBeenCalledWith(
Expand All @@ -247,6 +248,64 @@ describe('useOpenIdHandlers', () => {
)
expect(mockAgent.openid4vc.holder.requestCredentials).toHaveBeenCalledTimes(1)
})
it('should preserve complete credential configuration metadata on the record', async () => {
const credentialConfiguration =
fixture.resolvedCredentialOfferPreAuth.offeredCredentialConfigurations['mock-id-2']

const metadataSetMock = jest.fn()

mockFunction(mockAgent.openid4vc.holder.requestCredentials).mockResolvedValueOnce({
credentials: [
{ record: { id: 'mock-record', metadata: { set: metadataSetMock } }, credentialConfiguration },
],
})

const { receiveCredentialFromOpenId4VciOffer } = renderOpenIdHandlersHookValue()
await receiveCredentialFromOpenId4VciOffer({
resolvedCredentialOffer: fixture.resolvedCredentialOfferPreAuth,
accessToken: fixture.tokenResponse,
credentialConfigurationIdToRequest: 'mock-id-2',
})

expect(metadataSetMock).toHaveBeenCalledWith(
'_heka-wallet/openId4VcCredentialMetadata',
expect.objectContaining({
credentialConfiguration,
})
)
})

it('should still store existing extracted metadata fields alongside credentialConfiguration', async () => {
const credentialConfiguration =
fixture.resolvedCredentialOfferPreAuth.offeredCredentialConfigurations['mock-id-2']

const metadataSetMock = jest.fn()

mockFunction(mockAgent.openid4vc.holder.requestCredentials).mockResolvedValueOnce({
credentials: [
{ record: { id: 'mock-record', metadata: { set: metadataSetMock } }, credentialConfiguration },
],
})

const { receiveCredentialFromOpenId4VciOffer } = renderOpenIdHandlersHookValue()
await receiveCredentialFromOpenId4VciOffer({
resolvedCredentialOffer: fixture.resolvedCredentialOfferPreAuth,
accessToken: fixture.tokenResponse,
credentialConfigurationIdToRequest: 'mock-id-2',
})

expect(metadataSetMock).toHaveBeenCalledWith(
'_heka-wallet/openId4VcCredentialMetadata',
expect.objectContaining({
credential: expect.any(Object),
issuer: expect.objectContaining({
id: fixture.resolvedCredentialOfferPreAuth.metadata.credentialIssuer.credential_issuer,
}),
})
)
})



it('should throw if explicitly requested credential uses an unsupported format', async () => {
const { receiveCredentialFromOpenId4VciOffer } = renderOpenIdHandlersHookValue()
Expand Down
5 changes: 4 additions & 1 deletion heka-wallet/app/src/credentials/metadata.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {
import OpenId4VcCredentialMetadatat type {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win

The import declaration is still syntactically invalid.

Restore a normal type-only import, such as import type { ... } from '@credo-ts/openid4vc'; the current line causes the TypeScript parser to fail.

#!/bin/bash
set -euo pipefail
sed -n '1,5p' heka-wallet/app/src/credentials/metadata.ts
🧰 Tools
🪛 Biome (2.5.3)

[error] 1-1: expected from but instead found type

(parse)


[error] 1-1: Expected a semicolon or an implicit semicolon after a statement, but found none

(parse)

Source: Linters/SAST tools

OpenId4VciCredentialConfigurationSupported,
OpenId4VciCredentialIssuerMetadataDisplay,
} from '@credo-ts/openid4vc'
Expand All @@ -17,9 +17,12 @@ export interface OpenId4VcCredentialMetadata {
issuer: {
display?: OpenId4VciCredentialIssuerMetadataDisplay[]
id: string

}
credentialConfiguration?: OpenId4VciCredentialConfigurationSupported
}


const OID4VC_CREDENTIAL_METADATA_KEY = '_heka-wallet/openId4VcCredentialMetadata'

export function extractOpenId4VcCredentialMetadata(
Expand Down
5 changes: 4 additions & 1 deletion heka-wallet/app/src/credentials/useOpenIdHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,10 @@ export const useOpenIdHandlers = () => {
issuerId: openId4VcMetadata.issuer.id,
})

setOpenId4VcCredentialMetadata(record, openId4VcMetadata)
setOpenId4VcCredentialMetadata(record, {
...openId4VcMetadata,
credentialConfiguration,
})

return record
},
Expand Down
Loading