-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathmetadata.ts
More file actions
61 lines (52 loc) · 1.79 KB
/
Copy pathmetadata.ts
File metadata and controls
61 lines (52 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import OpenId4VcCredentialMetadatat type {
OpenId4VciCredentialConfigurationSupported,
OpenId4VciCredentialIssuerMetadataDisplay,
} from '@credo-ts/openid4vc'
import { CredentialRecord } from './types'
type CredentialMetadataDisplay = NonNullable<
NonNullable<OpenId4VciCredentialConfigurationSupported['credential_metadata']>['display']
>
export interface OpenId4VcCredentialMetadata {
credential: {
display?: CredentialMetadataDisplay
order?: OpenId4VciCredentialConfigurationSupported['order']
}
issuer: {
display?: OpenId4VciCredentialIssuerMetadataDisplay[]
id: string
}
credentialConfiguration?: OpenId4VciCredentialConfigurationSupported
}
const OID4VC_CREDENTIAL_METADATA_KEY = '_heka-wallet/openId4VcCredentialMetadata'
export function extractOpenId4VcCredentialMetadata(
credentialMetadata: OpenId4VciCredentialConfigurationSupported,
serverMetadata: { display?: any[]; id: string }
): OpenId4VcCredentialMetadata {
return {
credential: {
display: credentialMetadata.credential_metadata?.display,
order: credentialMetadata.order,
},
issuer: {
display: serverMetadata.display,
id: serverMetadata.id,
},
}
}
/**
* Gets the OpenId4Vc credential metadata from the given W3C credential record.
*/
export function getOpenId4VcCredentialMetadata(credentialRecord: CredentialRecord): OpenId4VcCredentialMetadata | null {
return credentialRecord.metadata.get(OID4VC_CREDENTIAL_METADATA_KEY)
}
/**
* Sets the OpenId4Vc credential metadata on the given W3cCredentialRecord or SdJwtVcRecord.
*
* NOTE: this does not save the record.
*/
export function setOpenId4VcCredentialMetadata(
credentialRecord: CredentialRecord,
metadata: OpenId4VcCredentialMetadata
) {
credentialRecord.metadata.set(OID4VC_CREDENTIAL_METADATA_KEY, metadata)
}