@sphereon/ssi-types 0.8.0 → 0.8.1-next.117
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.
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/mapper/credential-mapper.d.ts +37 -0
- package/dist/mapper/credential-mapper.d.ts.map +1 -0
- package/dist/mapper/credential-mapper.js +221 -0
- package/dist/mapper/credential-mapper.js.map +1 -0
- package/dist/mapper/index.d.ts +2 -0
- package/dist/mapper/index.d.ts.map +1 -0
- package/dist/mapper/index.js +18 -0
- package/dist/mapper/index.js.map +1 -0
- package/dist/types/did.d.ts +1 -0
- package/dist/types/did.d.ts.map +1 -1
- package/dist/types/did.js +49 -1
- package/dist/types/did.js.map +1 -1
- package/dist/types/pex.d.ts +1 -12
- package/dist/types/pex.d.ts.map +1 -1
- package/dist/types/vc.d.ts +83 -34
- package/dist/types/vc.d.ts.map +1 -1
- package/dist/types/vc.js +7 -7
- package/dist/types/vc.js.map +1 -1
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +18 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/object.d.ts +7 -0
- package/dist/utils/object.d.ts.map +1 -0
- package/dist/utils/object.js +21 -0
- package/dist/utils/object.js.map +1 -0
- package/package.json +16 -3
- package/src/index.ts +2 -0
- package/src/mapper/credential-mapper.ts +275 -0
- package/src/mapper/index.ts +1 -0
- package/src/types/did.ts +48 -0
- package/src/types/pex.ts +1 -13
- package/src/types/vc.ts +91 -33
- package/src/utils/index.ts +1 -0
- package/src/utils/object.ts +19 -0
package/src/types/vc.ts
CHANGED
|
@@ -1,39 +1,40 @@
|
|
|
1
1
|
import { PresentationSubmission } from './pex'
|
|
2
2
|
import { IProofPurpose, IProofType } from './did'
|
|
3
3
|
|
|
4
|
+
export type AdditionalClaims = Record<string, any>
|
|
5
|
+
|
|
6
|
+
export type IIssuerId = string
|
|
7
|
+
|
|
4
8
|
export interface ICredential {
|
|
5
|
-
|
|
6
|
-
|
|
9
|
+
'@context': ICredentialContextType | ICredentialContextType[]
|
|
10
|
+
type: string[]
|
|
11
|
+
credentialSchema?: undefined | ICredentialSchemaType | ICredentialSchemaType[]
|
|
7
12
|
// If iss is present, the value MUST be used to set the issuer property of the new credential JSON object or the holder property of the new presentation JSON object.
|
|
8
|
-
issuer:
|
|
13
|
+
issuer: IIssuerId | IIssuer
|
|
9
14
|
// If nbf is present, the UNIX timestamp MUST be converted to an [XMLSCHEMA11-2] date-time, and MUST be used to set the value of the issuanceDate property of the new JSON object.
|
|
10
15
|
issuanceDate: string
|
|
11
16
|
// If sub is present, the value MUST be used to set the value of the id property of credentialSubject of the new credential JSON object.
|
|
12
|
-
credentialSubject: ICredentialSubject
|
|
17
|
+
credentialSubject: (ICredentialSubject & AdditionalClaims) | (ICredentialSubject & AdditionalClaims)[]
|
|
18
|
+
// If exp is present, the UNIX timestamp MUST be converted to an [XMLSCHEMA11-2] date-time, and MUST be used to set the value of the expirationDate property of credentialSubject of the new JSON object.
|
|
19
|
+
expirationDate?: string
|
|
13
20
|
// If jti is present, the value MUST be used to set the value of the id property of the new JSON object.
|
|
14
|
-
id
|
|
15
|
-
'@context': ICredentialContextType[] | ICredentialContextType
|
|
21
|
+
id?: string
|
|
16
22
|
credentialStatus?: ICredentialStatus
|
|
17
|
-
credentialSchema?: undefined | ICredentialSchemaType | ICredentialSchemaType[]
|
|
18
23
|
description?: string
|
|
19
24
|
name?: string
|
|
20
|
-
type: string[]
|
|
21
25
|
|
|
22
|
-
[x: string]:
|
|
26
|
+
[x: string]: any
|
|
23
27
|
}
|
|
24
28
|
|
|
25
29
|
export interface ICredentialSubject {
|
|
26
30
|
id?: string
|
|
27
|
-
|
|
28
|
-
[x: string]: unknown
|
|
29
31
|
}
|
|
30
32
|
|
|
31
|
-
export type ICredentialContextType = ICredentialContext | string
|
|
33
|
+
export type ICredentialContextType = (ICredentialContext & AdditionalClaims) | string
|
|
32
34
|
|
|
33
35
|
export interface ICredentialContext {
|
|
34
36
|
name?: string
|
|
35
37
|
did?: string
|
|
36
|
-
[x: string]: unknown
|
|
37
38
|
}
|
|
38
39
|
|
|
39
40
|
export type ICredentialSchemaType = ICredentialSchema | string
|
|
@@ -55,7 +56,7 @@ export interface IProof {
|
|
|
55
56
|
nonce?: string // Similar to challenge. A nonce to protect against replay attacks, used in some ZKP proofs
|
|
56
57
|
requiredRevealStatements?: string[] // The parts of the proof that must be revealed in a derived proof
|
|
57
58
|
|
|
58
|
-
[x: string]:
|
|
59
|
+
[x: string]: any // Any because we want to be able to access value1.value2.value3, which unknown does not allow for without a cast
|
|
59
60
|
}
|
|
60
61
|
|
|
61
62
|
export interface ICredentialStatus {
|
|
@@ -66,7 +67,7 @@ export interface ICredentialStatus {
|
|
|
66
67
|
export interface IIssuer {
|
|
67
68
|
id: string
|
|
68
69
|
|
|
69
|
-
[x: string]:
|
|
70
|
+
[x: string]: any
|
|
70
71
|
}
|
|
71
72
|
|
|
72
73
|
export interface IHasProof {
|
|
@@ -75,50 +76,95 @@ export interface IHasProof {
|
|
|
75
76
|
|
|
76
77
|
export type IVerifiableCredential = ICredential & IHasProof
|
|
77
78
|
|
|
79
|
+
/**
|
|
80
|
+
* Represents a Json Web Token in compact form.
|
|
81
|
+
*/
|
|
82
|
+
export type CompactJWT = string
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Represents a signed Verifiable Credential (includes proof), in either JSON or compact JWT format.
|
|
86
|
+
* See {@link https://www.w3.org/TR/vc-data-model/#credentials | VC data model}
|
|
87
|
+
* See {@link https://www.w3.org/TR/vc-data-model/#proof-formats | proof formats}
|
|
88
|
+
*/
|
|
89
|
+
export type W3CVerifiableCredential = IVerifiableCredential | CompactJWT
|
|
90
|
+
|
|
78
91
|
export interface IPresentation {
|
|
92
|
+
id?: string
|
|
79
93
|
'@context': ICredentialContextType | ICredentialContextType[]
|
|
80
94
|
type: string[]
|
|
81
|
-
verifiableCredential:
|
|
95
|
+
verifiableCredential: W3CVerifiableCredential[] // we relax to ICredential for internal decoded stable representations without proofs
|
|
82
96
|
presentation_submission?: PresentationSubmission
|
|
83
97
|
holder?: string
|
|
98
|
+
|
|
99
|
+
[x: string]: any
|
|
84
100
|
}
|
|
85
101
|
|
|
86
102
|
export type IVerifiablePresentation = IPresentation & IHasProof
|
|
87
103
|
|
|
104
|
+
/**
|
|
105
|
+
* Represents a signed Verifiable Presentation (includes proof), in either JSON or compact JWT format.
|
|
106
|
+
* See {@link https://www.w3.org/TR/vc-data-model/#presentations | VC data model}
|
|
107
|
+
* See {@link https://www.w3.org/TR/vc-data-model/#proof-formats | proof formats}
|
|
108
|
+
*/
|
|
109
|
+
export type W3CVerifiablePresentation = IVerifiablePresentation | CompactJWT
|
|
110
|
+
|
|
88
111
|
export interface WrappedVerifiableCredential {
|
|
89
112
|
/**
|
|
90
113
|
* Original VC that we've received
|
|
91
114
|
*/
|
|
92
|
-
original:
|
|
115
|
+
original: OriginalVerifiableCredential
|
|
93
116
|
/**
|
|
94
117
|
* In case of JWT credential it will be the decoded version. In other cases it will be the same as original one
|
|
95
118
|
*/
|
|
96
|
-
decoded:
|
|
119
|
+
decoded: JwtDecodedVerifiableCredential | IVerifiableCredential
|
|
97
120
|
/**
|
|
98
|
-
* Type of this credential. Supported types are json-ld and jwt
|
|
121
|
+
* Type of this credential. Supported types are json-ld and jwt (decoded/encoded)
|
|
99
122
|
*/
|
|
100
|
-
type:
|
|
123
|
+
type: OriginalType
|
|
101
124
|
/**
|
|
102
|
-
*
|
|
125
|
+
* The claim format, typically used during exchange transport protocols
|
|
103
126
|
*/
|
|
104
|
-
|
|
127
|
+
format: CredentialFormat
|
|
128
|
+
/**
|
|
129
|
+
* Internal stable representation of a Credential without Proofs, created based on https://www.w3.org/TR/vc-data-model/#jwt-decoding
|
|
130
|
+
*/
|
|
131
|
+
credential: ICredential
|
|
105
132
|
}
|
|
106
133
|
|
|
107
134
|
export interface WrappedVerifiablePresentation {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
135
|
+
/**
|
|
136
|
+
* Original VP that we've received
|
|
137
|
+
*/
|
|
138
|
+
original: OriginalVerifiablePresentation
|
|
139
|
+
/**
|
|
140
|
+
* In case of JWT VP it will be the decoded version. In other cases it will be the same as original one
|
|
141
|
+
*/
|
|
142
|
+
decoded: JwtDecodedVerifiablePresentation | IVerifiablePresentation
|
|
143
|
+
/**
|
|
144
|
+
* Type of this Presentation. Supported types are json-ld and jwt (decoded/encoded)
|
|
145
|
+
*/
|
|
146
|
+
type: OriginalType
|
|
147
|
+
/**
|
|
148
|
+
* The claim format, typically used during exchange transport protocols
|
|
149
|
+
*/
|
|
150
|
+
format: PresentationFormat
|
|
151
|
+
/**
|
|
152
|
+
* Internal stable representation of a Presentation without proofs, created based on https://www.w3.org/TR/vc-data-model/#jwt-decoding
|
|
153
|
+
*/
|
|
154
|
+
presentation: UniformVerifiablePresentation
|
|
155
|
+
/**
|
|
156
|
+
* Wrapped Verifiable Credentials belonging to the Presentation
|
|
157
|
+
*/
|
|
112
158
|
vcs: WrappedVerifiableCredential[]
|
|
113
159
|
}
|
|
114
160
|
|
|
115
|
-
export enum
|
|
116
|
-
JSONLD,
|
|
117
|
-
JWT_ENCODED,
|
|
118
|
-
JWT_DECODED,
|
|
161
|
+
export enum OriginalType {
|
|
162
|
+
JSONLD = 'json-ld',
|
|
163
|
+
JWT_ENCODED = 'jwt-encoded',
|
|
164
|
+
JWT_DECODED = 'jwt-decoded',
|
|
119
165
|
}
|
|
120
166
|
|
|
121
|
-
export interface
|
|
167
|
+
export interface UniformVerifiablePresentation {
|
|
122
168
|
'@context': ICredentialContextType | ICredentialContextType[]
|
|
123
169
|
type: string[]
|
|
124
170
|
verifiableCredential: WrappedVerifiableCredential[]
|
|
@@ -126,20 +172,32 @@ export interface InternalPresentation {
|
|
|
126
172
|
holder?: string
|
|
127
173
|
}
|
|
128
174
|
|
|
129
|
-
export interface
|
|
175
|
+
export interface JwtDecodedVerifiableCredential {
|
|
130
176
|
vc: ICredential
|
|
131
177
|
exp: string
|
|
132
178
|
iss: string
|
|
133
179
|
nbf: string
|
|
134
180
|
sub: string
|
|
135
181
|
jti: string
|
|
182
|
+
|
|
183
|
+
[x: string]: any
|
|
136
184
|
}
|
|
137
185
|
|
|
138
|
-
export interface
|
|
186
|
+
export interface JwtDecodedVerifiablePresentation {
|
|
139
187
|
vp: IVerifiablePresentation
|
|
140
188
|
exp: string
|
|
141
189
|
iss: string
|
|
142
190
|
nbf: string
|
|
143
191
|
sub: string
|
|
144
192
|
jti: string
|
|
193
|
+
|
|
194
|
+
[x: string]: any
|
|
145
195
|
}
|
|
196
|
+
|
|
197
|
+
export type CredentialFormat = 'jwt' | 'ldp' | 'jwt_vc' | 'ldp_vc' | string
|
|
198
|
+
export type PresentationFormat = 'jwt' | 'ldp' | 'jwt_vp' | 'ldp_vp' | string
|
|
199
|
+
export type ClaimFormat = CredentialFormat | PresentationFormat
|
|
200
|
+
|
|
201
|
+
export type OriginalVerifiableCredential = W3CVerifiableCredential | JwtDecodedVerifiableCredential
|
|
202
|
+
export type OriginalVerifiablePresentation = W3CVerifiablePresentation | JwtDecodedVerifiablePresentation
|
|
203
|
+
export type Original = OriginalVerifiablePresentation | OriginalVerifiableCredential
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './object'
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export class ObjectUtils {
|
|
2
|
+
public static asArray(value: unknown) {
|
|
3
|
+
return Array.isArray(value) ? value : [value]
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
public static isObject(value: unknown) {
|
|
7
|
+
return Object.prototype.toString.call(value) === '[object Object]'
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
public static isUrlAbsolute(url: string) {
|
|
11
|
+
// regex to check for absolute IRI (starting scheme and ':') or blank node IRI
|
|
12
|
+
const isAbsoluteRegex = /^([A-Za-z][A-Za-z0-9+-.]*|_):[^\s]*$/
|
|
13
|
+
ObjectUtils.isString(url) && isAbsoluteRegex.test(url)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
public static isString(value: unknown): boolean {
|
|
17
|
+
return typeof value === 'string' || Object.prototype.toString.call(value) === '[object String]'
|
|
18
|
+
}
|
|
19
|
+
}
|