@sphereon/ssi-sdk.vc-status-list 0.32.1-feature.MWALL.717.jwt.decode.crash.15 → 0.32.1-feature.SDK.56.oauth.status.list.34
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/functions.d.ts +13 -13
- package/dist/functions.d.ts.map +1 -1
- package/dist/functions.js +40 -109
- package/dist/functions.js.map +1 -1
- package/dist/impl/IStatusList.d.ts +22 -0
- package/dist/impl/IStatusList.d.ts.map +1 -0
- package/dist/impl/IStatusList.js +3 -0
- package/dist/impl/IStatusList.js.map +1 -0
- package/dist/impl/OAuthStatusList.d.ts +20 -0
- package/dist/impl/OAuthStatusList.d.ts.map +1 -0
- package/dist/impl/OAuthStatusList.js +147 -0
- package/dist/impl/OAuthStatusList.js.map +1 -0
- package/dist/impl/StatusList2021.d.ts +14 -0
- package/dist/impl/StatusList2021.d.ts.map +1 -0
- package/dist/impl/StatusList2021.js +153 -0
- package/dist/impl/StatusList2021.js.map +1 -0
- package/dist/impl/StatusListFactory.d.ts +12 -0
- package/dist/impl/StatusListFactory.d.ts.map +1 -0
- package/dist/impl/StatusListFactory.js +36 -0
- package/dist/impl/StatusListFactory.js.map +1 -0
- package/dist/impl/encoding/cbor.d.ts +6 -0
- package/dist/impl/encoding/cbor.d.ts.map +1 -0
- package/dist/impl/encoding/cbor.js +128 -0
- package/dist/impl/encoding/cbor.js.map +1 -0
- package/dist/impl/encoding/common.d.ts +12 -0
- package/dist/impl/encoding/common.d.ts.map +1 -0
- package/dist/impl/encoding/common.js +26 -0
- package/dist/impl/encoding/common.js.map +1 -0
- package/dist/impl/encoding/jwt.d.ts +7 -0
- package/dist/impl/encoding/jwt.d.ts.map +1 -0
- package/dist/impl/encoding/jwt.js +56 -0
- package/dist/impl/encoding/jwt.js.map +1 -0
- package/dist/types/index.d.ts +107 -29
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +12 -0
- package/dist/types/index.js.map +1 -1
- package/dist/utils.d.ts +17 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +87 -0
- package/dist/utils.js.map +1 -0
- package/package.json +11 -3
- package/src/functions.ts +59 -158
- package/src/impl/IStatusList.ts +36 -0
- package/src/impl/OAuthStatusList.ts +165 -0
- package/src/impl/StatusList2021.ts +195 -0
- package/src/impl/StatusListFactory.ts +39 -0
- package/src/impl/encoding/cbor.ts +152 -0
- package/src/impl/encoding/common.ts +25 -0
- package/src/impl/encoding/jwt.ts +54 -0
- package/src/types/index.ts +123 -41
- package/src/utils.ts +91 -0
package/src/types/index.ts
CHANGED
|
@@ -4,72 +4,107 @@ import {
|
|
|
4
4
|
ICredentialStatus,
|
|
5
5
|
IIssuer,
|
|
6
6
|
IVerifiableCredential,
|
|
7
|
-
OriginalVerifiableCredential,
|
|
8
7
|
OrPromise,
|
|
8
|
+
ProofFormat,
|
|
9
9
|
StatusListCredentialIdMode,
|
|
10
10
|
StatusListDriverType,
|
|
11
11
|
StatusListIndexingDirection,
|
|
12
12
|
StatusListType,
|
|
13
|
+
StatusListVerifiableCredential,
|
|
13
14
|
StatusPurpose2021,
|
|
14
15
|
} from '@sphereon/ssi-types'
|
|
15
|
-
import {
|
|
16
|
-
CredentialPayload,
|
|
17
|
-
IAgentContext,
|
|
18
|
-
ICredentialIssuer,
|
|
19
|
-
ICredentialPlugin,
|
|
20
|
-
ICredentialVerifier,
|
|
21
|
-
IPluginMethodMap,
|
|
22
|
-
ProofFormat,
|
|
23
|
-
} from '@veramo/core'
|
|
16
|
+
import { CredentialPayload, IAgentContext, ICredentialIssuer, ICredentialPlugin, ICredentialVerifier, IPluginMethodMap } from '@veramo/core'
|
|
24
17
|
import { DataSource } from 'typeorm'
|
|
18
|
+
import { BitsPerStatus } from '@sd-jwt/jwt-status-list/dist'
|
|
25
19
|
|
|
26
|
-
export
|
|
27
|
-
|
|
28
|
-
|
|
20
|
+
export enum StatusOAuth {
|
|
21
|
+
Valid = 0,
|
|
22
|
+
Invalid = 1,
|
|
23
|
+
Suspended = 2,
|
|
29
24
|
}
|
|
30
25
|
|
|
31
|
-
export
|
|
32
|
-
|
|
33
|
-
|
|
26
|
+
export enum Status2021 {
|
|
27
|
+
Valid = 0,
|
|
28
|
+
Invalid = 1,
|
|
34
29
|
}
|
|
35
30
|
|
|
36
|
-
export
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
value: boolean
|
|
31
|
+
export type StatusList2021Args = {
|
|
32
|
+
indexingDirection: StatusListIndexingDirection
|
|
33
|
+
statusPurpose?: StatusPurpose2021
|
|
34
|
+
// todo: validFrom and validUntil
|
|
41
35
|
}
|
|
42
36
|
|
|
43
|
-
export
|
|
44
|
-
|
|
37
|
+
export type OAuthStatusListArgs = {
|
|
38
|
+
bitsPerStatus?: BitsPerStatus
|
|
39
|
+
expiresAt?: string
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export type BaseCreateNewStatusListArgs = {
|
|
43
|
+
type: StatusListType
|
|
45
44
|
id: string
|
|
46
|
-
|
|
45
|
+
issuer: string | IIssuer
|
|
46
|
+
correlationId?: string
|
|
47
|
+
length?: number
|
|
48
|
+
proofFormat?: ProofFormat
|
|
49
|
+
keyRef?: string
|
|
50
|
+
statusList2021?: StatusList2021Args
|
|
51
|
+
oauthStatusList?: OAuthStatusListArgs
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export type UpdateStatusList2021Args = {
|
|
47
55
|
statusPurpose: StatusPurpose2021
|
|
48
|
-
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export type UpdateOAuthStatusListArgs = {
|
|
59
|
+
bitsPerStatus: BitsPerStatus
|
|
60
|
+
expiresAt?: string
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface UpdateStatusListFromEncodedListArgs {
|
|
64
|
+
type?: StatusListType
|
|
65
|
+
statusListIndex: number | string
|
|
66
|
+
value: boolean
|
|
49
67
|
proofFormat?: ProofFormat
|
|
50
68
|
keyRef?: string
|
|
69
|
+
correlationId?: string
|
|
70
|
+
encodedList: string
|
|
71
|
+
issuer: string | IIssuer
|
|
72
|
+
id: string
|
|
73
|
+
statusList2021?: UpdateStatusList2021Args
|
|
74
|
+
oauthStatusList?: UpdateOAuthStatusListArgs
|
|
75
|
+
}
|
|
51
76
|
|
|
52
|
-
|
|
77
|
+
export interface UpdateStatusListFromStatusListCredentialArgs {
|
|
78
|
+
statusListCredential: StatusListVerifiableCredential // | CompactJWT
|
|
79
|
+
keyRef?: string
|
|
80
|
+
statusListIndex: number | string
|
|
81
|
+
value: number | Status2021 | StatusOAuth
|
|
53
82
|
}
|
|
54
83
|
|
|
55
|
-
export interface
|
|
84
|
+
export interface StatusListResult {
|
|
56
85
|
encodedList: string
|
|
86
|
+
statusListCredential: StatusListVerifiableCredential // | CompactJWT
|
|
57
87
|
length: number
|
|
58
88
|
type: StatusListType
|
|
59
89
|
proofFormat: ProofFormat
|
|
60
|
-
statusPurpose: StatusPurpose2021
|
|
61
90
|
id: string
|
|
62
91
|
issuer: string | IIssuer
|
|
63
|
-
|
|
64
|
-
|
|
92
|
+
statusList2021?: StatusList2021Details
|
|
93
|
+
oauthStatusList?: OAuthStatusDetails
|
|
94
|
+
|
|
65
95
|
// These cannot be deduced from the VC, so they are present when callers pass in these values as params
|
|
66
96
|
correlationId?: string
|
|
67
97
|
driverType?: StatusListDriverType
|
|
68
98
|
credentialIdMode?: StatusListCredentialIdMode
|
|
69
99
|
}
|
|
70
100
|
|
|
71
|
-
|
|
72
|
-
|
|
101
|
+
interface StatusList2021Details {
|
|
102
|
+
indexingDirection: StatusListIndexingDirection
|
|
103
|
+
statusPurpose?: StatusPurpose2021
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
interface OAuthStatusDetails {
|
|
107
|
+
bitsPerStatus?: BitsPerStatus
|
|
73
108
|
}
|
|
74
109
|
|
|
75
110
|
export interface StatusList2021EntryCredentialStatus extends ICredentialStatus {
|
|
@@ -79,6 +114,47 @@ export interface StatusList2021EntryCredentialStatus extends ICredentialStatus {
|
|
|
79
114
|
statusListCredential: string
|
|
80
115
|
}
|
|
81
116
|
|
|
117
|
+
export interface StatusListOAuthEntryCredentialStatus extends ICredentialStatus {
|
|
118
|
+
type: 'OAuthStatusListEntry'
|
|
119
|
+
bitsPerStatus: number
|
|
120
|
+
statusListIndex: string
|
|
121
|
+
statusListCredential: string
|
|
122
|
+
expiresAt?: string
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export interface StatusList2021ToVerifiableCredentialArgs {
|
|
126
|
+
issuer: string | IIssuer
|
|
127
|
+
id: string
|
|
128
|
+
type?: StatusListType
|
|
129
|
+
proofFormat?: ProofFormat
|
|
130
|
+
keyRef?: string
|
|
131
|
+
encodedList: string
|
|
132
|
+
statusPurpose: StatusPurpose2021
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export interface CreateStatusListArgs {
|
|
136
|
+
issuer: string | IIssuer
|
|
137
|
+
id: string
|
|
138
|
+
proofFormat?: ProofFormat
|
|
139
|
+
keyRef?: string
|
|
140
|
+
correlationId?: string
|
|
141
|
+
length?: number
|
|
142
|
+
statusList2021?: StatusList2021Args
|
|
143
|
+
oauthStatusList?: OAuthStatusListArgs
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export interface UpdateStatusListIndexArgs {
|
|
147
|
+
statusListCredential: StatusListVerifiableCredential // | CompactJWT
|
|
148
|
+
keyRef?: string
|
|
149
|
+
statusListIndex: number | string
|
|
150
|
+
value: number | Status2021 | StatusOAuth
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export interface CheckStatusIndexArgs {
|
|
154
|
+
statusListCredential: StatusListVerifiableCredential // | CompactJWT
|
|
155
|
+
statusListIndex: string | number
|
|
156
|
+
}
|
|
157
|
+
|
|
82
158
|
/**
|
|
83
159
|
* The interface definition for a plugin that can add statuslist info to a credential
|
|
84
160
|
*
|
|
@@ -95,7 +171,7 @@ export interface IStatusListPlugin extends IPluginMethodMap {
|
|
|
95
171
|
*
|
|
96
172
|
* @returns - The details of the newly created status list
|
|
97
173
|
*/
|
|
98
|
-
slCreateStatusList(args: CreateNewStatusListArgs, context: IRequiredContext): Promise<
|
|
174
|
+
slCreateStatusList(args: CreateNewStatusListArgs, context: IRequiredContext): Promise<StatusListResult>
|
|
99
175
|
|
|
100
176
|
/**
|
|
101
177
|
* Ensures status list info like index and list id is added to a credential
|
|
@@ -114,7 +190,15 @@ export interface IStatusListPlugin extends IPluginMethodMap {
|
|
|
114
190
|
* @param args
|
|
115
191
|
* @param context
|
|
116
192
|
*/
|
|
117
|
-
slGetStatusList(args: GetStatusListArgs, context: IRequiredContext): Promise<
|
|
193
|
+
slGetStatusList(args: GetStatusListArgs, context: IRequiredContext): Promise<StatusListResult>
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export type CreateNewStatusListFuncArgs = BaseCreateNewStatusListArgs
|
|
197
|
+
|
|
198
|
+
export type CreateNewStatusListArgs = BaseCreateNewStatusListArgs & {
|
|
199
|
+
dataSource?: OrPromise<DataSource>
|
|
200
|
+
dbName?: string
|
|
201
|
+
isDefault?: boolean
|
|
118
202
|
}
|
|
119
203
|
|
|
120
204
|
export type IAddStatusToCredentialArgs = Omit<IIssueCredentialStatusOpts, 'dataSource'> & {
|
|
@@ -123,7 +207,6 @@ export type IAddStatusToCredentialArgs = Omit<IIssueCredentialStatusOpts, 'dataS
|
|
|
123
207
|
|
|
124
208
|
export interface IIssueCredentialStatusOpts {
|
|
125
209
|
dataSource?: DataSource
|
|
126
|
-
|
|
127
210
|
credentialId?: string // An id to use for the credential. Normally should be set as the crdential.id value
|
|
128
211
|
statusListId?: string // Explicit status list to use. Determines the id from the credentialStatus object in the VC itself or uses the default otherwise
|
|
129
212
|
statusListIndex?: number | string
|
|
@@ -138,13 +221,12 @@ export type GetStatusListArgs = {
|
|
|
138
221
|
dbName?: string
|
|
139
222
|
}
|
|
140
223
|
|
|
141
|
-
export type CreateNewStatusListArgs = CreateNewStatusListFuncArgs & {
|
|
142
|
-
dataSource?: OrPromise<DataSource>
|
|
143
|
-
dbName?: string
|
|
144
|
-
isDefault?: boolean
|
|
145
|
-
}
|
|
146
|
-
|
|
147
224
|
export type CredentialWithStatusSupport = ICredential | CredentialPayload | IVerifiableCredential
|
|
148
225
|
|
|
226
|
+
export type SignedStatusListData = {
|
|
227
|
+
statusListCredential: StatusListVerifiableCredential
|
|
228
|
+
encodedList: string
|
|
229
|
+
}
|
|
230
|
+
|
|
149
231
|
export type IRequiredPlugins = ICredentialPlugin & IIdentifierResolution
|
|
150
232
|
export type IRequiredContext = IAgentContext<ICredentialIssuer & ICredentialVerifier & IIdentifierResolution>
|
package/src/utils.ts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CredentialMapper,
|
|
3
|
+
IIssuer,
|
|
4
|
+
ProofFormat,
|
|
5
|
+
StatusListType,
|
|
6
|
+
StatusListType as StatusListTypeW3C,
|
|
7
|
+
StatusListVerifiableCredential,
|
|
8
|
+
} from '@sphereon/ssi-types'
|
|
9
|
+
import { jwtDecode } from 'jwt-decode'
|
|
10
|
+
|
|
11
|
+
export function getAssertedStatusListType(type?: StatusListType) {
|
|
12
|
+
const assertedType = type ?? StatusListType.StatusList2021
|
|
13
|
+
if (![StatusListType.StatusList2021, StatusListType.OAuthStatusList].includes(assertedType)) {
|
|
14
|
+
throw Error(`StatusList type ${assertedType} is not supported (yet)`)
|
|
15
|
+
}
|
|
16
|
+
return assertedType
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function getAssertedValue<T>(name: string, value: T): NonNullable<T> {
|
|
20
|
+
if (value === undefined || value === null) {
|
|
21
|
+
throw Error(`Missing required ${name} value`)
|
|
22
|
+
}
|
|
23
|
+
return value
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function getAssertedValues(args: { issuer: string | IIssuer; id: string; type?: StatusListTypeW3C | StatusListType }) {
|
|
27
|
+
const type = getAssertedStatusListType(args?.type)
|
|
28
|
+
const id = getAssertedValue('id', args.id)
|
|
29
|
+
const issuer = getAssertedValue('issuer', args.issuer)
|
|
30
|
+
return { id, issuer, type }
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function getAssertedProperty<T extends object>(propertyName: string, obj: T): NonNullable<any> {
|
|
34
|
+
if (!(propertyName in obj)) {
|
|
35
|
+
throw Error(`The input object does not contain required property: ${propertyName}`)
|
|
36
|
+
}
|
|
37
|
+
return getAssertedValue(propertyName, (obj as any)[propertyName])
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const ValidProofTypeMap = new Map<StatusListType, ProofFormat[]>([
|
|
41
|
+
[StatusListType.StatusList2021, ['jwt', 'lds', 'EthereumEip712Signature2021']],
|
|
42
|
+
[StatusListType.OAuthStatusList, ['jwt', 'cbor']],
|
|
43
|
+
])
|
|
44
|
+
|
|
45
|
+
export function assertValidProofType(type: StatusListType, proofFormat: ProofFormat) {
|
|
46
|
+
const validProofTypes = ValidProofTypeMap.get(type)
|
|
47
|
+
if (!validProofTypes?.includes(proofFormat)) {
|
|
48
|
+
throw Error(`Invalid proof format '${proofFormat}' for status list type ${type}`)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function determineStatusListType(credential: StatusListVerifiableCredential): StatusListType {
|
|
53
|
+
const proofFormat = determineProofFormat(credential)
|
|
54
|
+
switch (proofFormat) {
|
|
55
|
+
case 'jwt':
|
|
56
|
+
const payload: StatusListVerifiableCredential = jwtDecode(credential as string)
|
|
57
|
+
const keys = Object.keys(payload)
|
|
58
|
+
if (keys.includes('status_list')) {
|
|
59
|
+
return StatusListType.OAuthStatusList
|
|
60
|
+
} else if (keys.includes('vc')) {
|
|
61
|
+
return StatusListType.StatusList2021
|
|
62
|
+
}
|
|
63
|
+
break
|
|
64
|
+
case 'lds':
|
|
65
|
+
const uniform = CredentialMapper.toUniformCredential(credential)
|
|
66
|
+
const type = uniform.type.find((t) => {
|
|
67
|
+
return Object.values(StatusListType).some((statusType) => t.includes(statusType))
|
|
68
|
+
})
|
|
69
|
+
if (!type) {
|
|
70
|
+
throw new Error('Invalid status list credential type')
|
|
71
|
+
}
|
|
72
|
+
return type.replace('Credential', '') as StatusListType
|
|
73
|
+
|
|
74
|
+
case 'cbor':
|
|
75
|
+
return StatusListType.OAuthStatusList
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
throw new Error('Cannot determine status list type from credential payload')
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function determineProofFormat(credential: StatusListVerifiableCredential): ProofFormat {
|
|
82
|
+
if (CredentialMapper.isJwtEncoded(credential)) {
|
|
83
|
+
return 'jwt'
|
|
84
|
+
} else if (CredentialMapper.isMsoMdocOid4VPEncoded(credential)) {
|
|
85
|
+
// Just assume Cbor for now, I'd need to decode at least the header to what type of Cbor we have
|
|
86
|
+
return 'cbor'
|
|
87
|
+
} else if (CredentialMapper.isCredential(credential)) {
|
|
88
|
+
return 'lds'
|
|
89
|
+
}
|
|
90
|
+
throw Error('Cannot determine credential payload type')
|
|
91
|
+
}
|