@sphereon/ssi-types 0.23.5-unstable.88 → 0.24.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- export * from './credential-mapper'
2
- export * from './jsonld-language-values'
1
+ export * from './credential-mapper'
2
+ export * from './jsonld-language-values'
@@ -1,91 +1,91 @@
1
- import { ObjectUtils } from '../utils'
2
-
3
- export type LanguageValueClaim = {
4
- language: string
5
- value: string | string[] | number | number[]
6
- }
7
-
8
- export const isLanguageValueObject = (claim?: unknown): claim is LanguageValueClaim => {
9
- if (!claim || !ObjectUtils.isObject(claim) || Array.isArray(claim)) {
10
- return false
11
- }
12
- const keys = Object.keys(claim)
13
- if (keys.length !== 2) {
14
- return false // Only 'language' and 'value' for now
15
- } else if (!('language' in claim && !!claim.language)) {
16
- return false
17
- } else if (!('value' in claim && !!claim.value)) {
18
- return false
19
- }
20
- return true
21
- }
22
-
23
- export const isLanguageValueObjects = (claim?: unknown): claim is LanguageValueClaim[] => {
24
- if (!claim || !Array.isArray(claim)) {
25
- return false
26
- }
27
- return claim.every((val) => isLanguageValueObject(val))
28
- }
29
-
30
- export const toLanguageValueObject = (claim?: unknown): LanguageValueClaim | undefined => {
31
- return isLanguageValueObject(claim) ? claim : undefined
32
- }
33
-
34
- export const toLanguageValueObjects = (claim?: unknown): LanguageValueClaim[] | undefined => {
35
- if (isLanguageValueObject(claim)) {
36
- return ObjectUtils.asArray(toLanguageValueObject(claim) as LanguageValueClaim)
37
- } else if (isLanguageValueObjects(claim)) {
38
- return claim
39
- }
40
- return undefined // no empty array on purpose, as this really would not be a language value object
41
- }
42
-
43
- export const mapLanguageValue = (
44
- claim?: unknown,
45
- opts?: {
46
- language?: string
47
- fallbackToFirstObject?: boolean
48
- },
49
- ): any => {
50
- const langValues = toLanguageValueObjects(claim)
51
- if (Array.isArray(langValues)) {
52
- if (langValues.length === 0) {
53
- // should not happen, but let's return original claim to be sure
54
- return claim
55
- }
56
- const filteredLangValues = langValues.filter((val) => (opts?.language ? val.language.toLowerCase().includes(opts.language.toLowerCase()) : true))
57
-
58
- let langValue: LanguageValueClaim
59
- if (filteredLangValues.length > 0) {
60
- langValue = filteredLangValues[0]
61
- } else {
62
- if (opts?.fallbackToFirstObject === false) {
63
- // No match and we also do not fallback to the first value, so return the original claim
64
- return claim
65
- }
66
- // Fallback to the first value
67
- langValue = langValues[0]
68
- }
69
- return langValue.value
70
- }
71
-
72
- return claim
73
- }
74
-
75
- export const mapLanguageValues = <T extends object>(
76
- claimsOrCredential: T,
77
- opts?: {
78
- language?: string
79
- fallbackToFirstObject?: boolean
80
- noDeepClone?: boolean
81
- },
82
- ): T => {
83
- const result = opts?.noDeepClone ? claimsOrCredential : JSON.parse(JSON.stringify(claimsOrCredential))
84
- Object.keys(claimsOrCredential).forEach((key) => {
85
- result[key] = mapLanguageValue(result[key], opts)
86
- if (ObjectUtils.isObject(result[key]) || Array.isArray(result[key])) {
87
- result[key] = mapLanguageValues(result[key], { ...opts, noDeepClone: true })
88
- }
89
- })
90
- return result
91
- }
1
+ import { ObjectUtils } from '../utils'
2
+
3
+ export type LanguageValueClaim = {
4
+ language: string
5
+ value: string | string[] | number | number[]
6
+ }
7
+
8
+ export const isLanguageValueObject = (claim?: unknown): claim is LanguageValueClaim => {
9
+ if (!claim || !ObjectUtils.isObject(claim) || Array.isArray(claim)) {
10
+ return false
11
+ }
12
+ const keys = Object.keys(claim)
13
+ if (keys.length !== 2) {
14
+ return false // Only 'language' and 'value' for now
15
+ } else if (!('language' in claim && !!claim.language)) {
16
+ return false
17
+ } else if (!('value' in claim && !!claim.value)) {
18
+ return false
19
+ }
20
+ return true
21
+ }
22
+
23
+ export const isLanguageValueObjects = (claim?: unknown): claim is LanguageValueClaim[] => {
24
+ if (!claim || !Array.isArray(claim)) {
25
+ return false
26
+ }
27
+ return claim.every((val) => isLanguageValueObject(val))
28
+ }
29
+
30
+ export const toLanguageValueObject = (claim?: unknown): LanguageValueClaim | undefined => {
31
+ return isLanguageValueObject(claim) ? claim : undefined
32
+ }
33
+
34
+ export const toLanguageValueObjects = (claim?: unknown): LanguageValueClaim[] | undefined => {
35
+ if (isLanguageValueObject(claim)) {
36
+ return ObjectUtils.asArray(toLanguageValueObject(claim) as LanguageValueClaim)
37
+ } else if (isLanguageValueObjects(claim)) {
38
+ return claim
39
+ }
40
+ return undefined // no empty array on purpose, as this really would not be a language value object
41
+ }
42
+
43
+ export const mapLanguageValue = (
44
+ claim?: unknown,
45
+ opts?: {
46
+ language?: string
47
+ fallbackToFirstObject?: boolean
48
+ },
49
+ ): any => {
50
+ const langValues = toLanguageValueObjects(claim)
51
+ if (Array.isArray(langValues)) {
52
+ if (langValues.length === 0) {
53
+ // should not happen, but let's return original claim to be sure
54
+ return claim
55
+ }
56
+ const filteredLangValues = langValues.filter((val) => (opts?.language ? val.language.toLowerCase().includes(opts.language.toLowerCase()) : true))
57
+
58
+ let langValue: LanguageValueClaim
59
+ if (filteredLangValues.length > 0) {
60
+ langValue = filteredLangValues[0]
61
+ } else {
62
+ if (opts?.fallbackToFirstObject === false) {
63
+ // No match and we also do not fallback to the first value, so return the original claim
64
+ return claim
65
+ }
66
+ // Fallback to the first value
67
+ langValue = langValues[0]
68
+ }
69
+ return langValue.value
70
+ }
71
+
72
+ return claim
73
+ }
74
+
75
+ export const mapLanguageValues = <T extends object>(
76
+ claimsOrCredential: T,
77
+ opts?: {
78
+ language?: string
79
+ fallbackToFirstObject?: boolean
80
+ noDeepClone?: boolean
81
+ },
82
+ ): T => {
83
+ const result = opts?.noDeepClone ? claimsOrCredential : JSON.parse(JSON.stringify(claimsOrCredential))
84
+ Object.keys(claimsOrCredential).forEach((key) => {
85
+ result[key] = mapLanguageValue(result[key], opts)
86
+ if (ObjectUtils.isObject(result[key]) || Array.isArray(result[key])) {
87
+ result[key] = mapLanguageValues(result[key], { ...opts, noDeepClone: true })
88
+ }
89
+ })
90
+ return result
91
+ }
@@ -1,9 +1,9 @@
1
- /**
2
- * Accept a Type or a Promise of that Type.
3
- *
4
- * @internal
5
- */
6
- export type OrPromise<T> = T | Promise<T>
7
- export type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>
8
-
9
- export type BearerTokenArg = (() => Promise<string>) | string
1
+ /**
2
+ * Accept a Type or a Promise of that Type.
3
+ *
4
+ * @internal
5
+ */
6
+ export type OrPromise<T> = T | Promise<T>
7
+ export type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>
8
+
9
+ export type BearerTokenArg = (() => Promise<string>) | string
@@ -1,6 +1,6 @@
1
- export * from './did'
2
- export * from './pex'
3
- export * from './vc'
4
- export * from './generic'
5
- export * from './sd-jwt-vc'
6
- export * from './w3c-vc'
1
+ export * from './did'
2
+ export * from './pex'
3
+ export * from './vc'
4
+ export * from './generic'
5
+ export * from './sd-jwt-vc'
6
+ export * from './w3c-vc'
package/src/types/pex.ts CHANGED
@@ -1,36 +1,36 @@
1
- /**
2
- * It expresses how the inputs are presented as proofs to a Verifier.
3
- */
4
- export interface PresentationSubmission {
5
- /**
6
- * A UUID or some other unique ID to identify this Presentation Submission
7
- */
8
- id: string
9
- /**
10
- * A UUID or some other unique ID to identify this Presentation Definition
11
- */
12
- definition_id: string
13
- /**
14
- * List of descriptors of how the claims are being mapped to presentation definition
15
- */
16
- descriptor_map: Array<Descriptor>
17
- }
18
-
19
- /**
20
- * descriptor map laying out the structure of the presentation submission.
21
- */
22
- export interface Descriptor {
23
- /**
24
- * ID to identify the descriptor from Presentation Definition Input Descriptor it coresponds to.
25
- */
26
- id: string
27
- /**
28
- * The path where the verifiable credential is located in the presentation submission json
29
- */
30
- path: string
31
- path_nested?: Descriptor
32
- /**
33
- * The Proof or JWT algorith that the proof is in
34
- */
35
- format: string
36
- }
1
+ /**
2
+ * It expresses how the inputs are presented as proofs to a Verifier.
3
+ */
4
+ export interface PresentationSubmission {
5
+ /**
6
+ * A UUID or some other unique ID to identify this Presentation Submission
7
+ */
8
+ id: string
9
+ /**
10
+ * A UUID or some other unique ID to identify this Presentation Definition
11
+ */
12
+ definition_id: string
13
+ /**
14
+ * List of descriptors of how the claims are being mapped to presentation definition
15
+ */
16
+ descriptor_map: Array<Descriptor>
17
+ }
18
+
19
+ /**
20
+ * descriptor map laying out the structure of the presentation submission.
21
+ */
22
+ export interface Descriptor {
23
+ /**
24
+ * ID to identify the descriptor from Presentation Definition Input Descriptor it coresponds to.
25
+ */
26
+ id: string
27
+ /**
28
+ * The path where the verifiable credential is located in the presentation submission json
29
+ */
30
+ path: string
31
+ path_nested?: Descriptor
32
+ /**
33
+ * The Proof or JWT algorith that the proof is in
34
+ */
35
+ format: string
36
+ }