@sphereon/ssi-sdk-ext.jwt-service 0.26.1-next.3 → 0.26.1-next.30
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/agent/JwtService.d.ts.map +1 -1
- package/dist/agent/JwtService.js +8 -5
- package/dist/agent/JwtService.js.map +1 -1
- package/dist/functions/JWE.d.ts +6 -6
- package/dist/functions/JWE.d.ts.map +1 -1
- package/dist/functions/JWE.js +13 -13
- package/dist/functions/JWE.js.map +1 -1
- package/dist/functions/index.d.ts.map +1 -1
- package/dist/functions/index.js +2 -2
- package/dist/functions/index.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/tsdoc-metadata.json +1 -1
- package/dist/types/IJwtService.d.ts +2 -2
- package/dist/types/IJwtService.d.ts.map +1 -1
- package/dist/types/IJwtService.js +20 -2
- package/dist/types/IJwtService.js.map +1 -1
- package/package.json +10 -10
- package/plugin.schema.json +12 -0
- package/src/agent/JwtService.ts +99 -90
- package/src/functions/JWE.ts +281 -282
- package/src/functions/index.ts +8 -10
- package/src/index.ts +1 -1
- package/src/types/IJwtService.ts +166 -170
package/src/functions/index.ts
CHANGED
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
ManagedIdentifierResult,
|
|
11
11
|
resolveExternalJwkIdentifier,
|
|
12
12
|
} from '@sphereon/ssi-sdk-ext.identifier-resolution'
|
|
13
|
-
import { keyTypeFromCryptographicSuite,
|
|
13
|
+
import { keyTypeFromCryptographicSuite, verifyRawSignature } from '@sphereon/ssi-sdk-ext.key-utils'
|
|
14
14
|
import { contextHasPlugin } from '@sphereon/ssi-sdk.agent-config'
|
|
15
15
|
import { JWK } from '@sphereon/ssi-types'
|
|
16
16
|
import { IAgentContext } from '@veramo/core'
|
|
@@ -32,11 +32,13 @@ import {
|
|
|
32
32
|
JwsJsonFlattened,
|
|
33
33
|
JwsJsonGeneral,
|
|
34
34
|
JwsJsonGeneralWithIdentifiers,
|
|
35
|
-
JwsJsonSignature,
|
|
35
|
+
JwsJsonSignature,
|
|
36
|
+
JwsJsonSignatureWithIdentifier,
|
|
36
37
|
JwsHeader,
|
|
37
38
|
JwsPayload,
|
|
38
39
|
PreparedJwsObject,
|
|
39
|
-
VerifyJwsArgs,
|
|
40
|
+
VerifyJwsArgs,
|
|
41
|
+
JweHeader,
|
|
40
42
|
} from '../types/IJwtService'
|
|
41
43
|
|
|
42
44
|
const payloadToBytes = (payload: string | JwsPayload | Uint8Array): Uint8Array => {
|
|
@@ -321,12 +323,12 @@ export const verifyJws = async (args: VerifyJwsArgs, context: IAgentContext<IIde
|
|
|
321
323
|
signature: sigWithId.signature,
|
|
322
324
|
data,
|
|
323
325
|
publicKeyHex,
|
|
324
|
-
type: keyTypeFromCryptographicSuite({
|
|
326
|
+
type: keyTypeFromCryptographicSuite({ crv: jwkInfo.jwk.crv ?? 'ES256' }),
|
|
325
327
|
// no kms arg, as the current key manager needs a bit more work
|
|
326
328
|
})
|
|
327
329
|
} else {
|
|
328
330
|
const signature = base64ToBytes(sigWithId.signature)
|
|
329
|
-
valid = await
|
|
331
|
+
valid = await verifyRawSignature({ data, signature, key: jwkInfo.jwk })
|
|
330
332
|
}
|
|
331
333
|
if (!valid) {
|
|
332
334
|
errorMessages.push(`Signature ${index} was not valid`)
|
|
@@ -412,11 +414,7 @@ async function resolveExternalIdentifierFromJwsHeader(
|
|
|
412
414
|
}
|
|
413
415
|
}
|
|
414
416
|
|
|
415
|
-
function loadJWK(
|
|
416
|
-
providedJwk: JWK | undefined,
|
|
417
|
-
protectedHeader: JwsHeader,
|
|
418
|
-
jws: JwsJsonGeneral,
|
|
419
|
-
): JWK | undefined {
|
|
417
|
+
function loadJWK(providedJwk: JWK | undefined, protectedHeader: JwsHeader, jws: JwsJsonGeneral): JWK | undefined {
|
|
420
418
|
if (providedJwk) {
|
|
421
419
|
return providedJwk
|
|
422
420
|
}
|
package/src/index.ts
CHANGED
package/src/types/IJwtService.ts
CHANGED
|
@@ -1,67 +1,60 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
ExternalIdentifierDidOpts,
|
|
3
|
+
ExternalIdentifierResult,
|
|
4
|
+
ExternalIdentifierX5cOpts,
|
|
5
|
+
IIdentifierResolution,
|
|
6
|
+
ManagedIdentifierOptsOrResult,
|
|
7
|
+
ManagedIdentifierResult,
|
|
8
8
|
} from '@sphereon/ssi-sdk-ext.identifier-resolution'
|
|
9
|
-
import {ClientIdScheme} from '@sphereon/ssi-sdk-ext.x509-utils'
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
IValidationResult,
|
|
13
|
-
JoseSignatureAlgorithm,
|
|
14
|
-
JoseSignatureAlgorithmString,
|
|
15
|
-
JWK
|
|
16
|
-
} from '@sphereon/ssi-types'
|
|
17
|
-
import {IAgentContext, IKeyManager, IPluginMethodMap} from '@veramo/core'
|
|
9
|
+
import { ClientIdScheme } from '@sphereon/ssi-sdk-ext.x509-utils'
|
|
10
|
+
import { BaseJWK, IValidationResult, JoseSignatureAlgorithm, JoseSignatureAlgorithmString, JWK } from '@sphereon/ssi-types'
|
|
11
|
+
import { IAgentContext, IKeyManager, IPluginMethodMap } from '@veramo/core'
|
|
18
12
|
|
|
19
13
|
export type IRequiredContext = IAgentContext<IIdentifierResolution & IKeyManager> // could we still interop with Veramo?
|
|
20
14
|
|
|
21
15
|
export const jwtServiceContextMethods: Array<string> = [
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
16
|
+
'jwtPrepareJws',
|
|
17
|
+
'jwtCreateJwsJsonGeneralSignature',
|
|
18
|
+
'jwtCreateJwsJsonFlattenedSignature',
|
|
19
|
+
'jwtCreateJwsCompactSignature',
|
|
20
|
+
'jwtVerifyJwsSignature',
|
|
21
|
+
'jwtEncryptJweCompactJwt',
|
|
22
|
+
'jwtDecryptJweCompactJwt',
|
|
29
23
|
]
|
|
30
24
|
|
|
31
25
|
export interface IJwtService extends IPluginMethodMap {
|
|
32
|
-
|
|
26
|
+
jwtPrepareJws(args: CreateJwsJsonArgs, context: IRequiredContext): Promise<PreparedJwsObject>
|
|
33
27
|
|
|
34
|
-
|
|
28
|
+
jwtCreateJwsJsonGeneralSignature(args: CreateJwsJsonArgs, context: IRequiredContext): Promise<JwsJsonGeneral>
|
|
35
29
|
|
|
36
|
-
|
|
30
|
+
jwtCreateJwsJsonFlattenedSignature(args: CreateJwsFlattenedArgs, context: IRequiredContext): Promise<JwsJsonFlattened>
|
|
37
31
|
|
|
38
|
-
|
|
32
|
+
jwtCreateJwsCompactSignature(args: CreateJwsCompactArgs, context: IRequiredContext): Promise<JwtCompactResult>
|
|
39
33
|
|
|
40
|
-
|
|
34
|
+
jwtVerifyJwsSignature(args: VerifyJwsArgs, context: IRequiredContext): Promise<IJwsValidationResult>
|
|
41
35
|
|
|
42
|
-
|
|
36
|
+
jwtEncryptJweCompactJwt(args: EncryptJweCompactJwtArgs, context: IRequiredContext): Promise<JwtCompactResult>
|
|
43
37
|
|
|
44
|
-
|
|
38
|
+
jwtDecryptJweCompactJwt(args: DecryptJweCompactJwtArgs, context: IRequiredContext): Promise<JwtCompactResult>
|
|
45
39
|
|
|
46
|
-
|
|
40
|
+
// TODO: JWE/encryption general methods
|
|
47
41
|
}
|
|
48
42
|
|
|
49
43
|
export type IJwsValidationResult = IValidationResult & {
|
|
50
|
-
|
|
51
|
-
|
|
44
|
+
jws: JwsJsonGeneralWithIdentifiers // We always translate to general as that is the most flexible format allowing multiple sigs
|
|
52
45
|
}
|
|
53
46
|
|
|
54
47
|
export interface PreparedJws {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
48
|
+
protectedHeader: JwsHeader
|
|
49
|
+
payload: Uint8Array
|
|
50
|
+
unprotectedHeader?: JwsHeader // only for jws json and also then optional
|
|
51
|
+
existingSignatures?: Array<JwsJsonSignature> // only for jws json and also then optional
|
|
59
52
|
}
|
|
60
53
|
|
|
61
54
|
export interface JwsJsonSignature {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
55
|
+
protected: string
|
|
56
|
+
header?: JwsHeader
|
|
57
|
+
signature: string
|
|
65
58
|
}
|
|
66
59
|
|
|
67
60
|
/**
|
|
@@ -74,258 +67,261 @@ export type EphemeralPublicKey = Omit<BaseJWK, 'alg'>
|
|
|
74
67
|
// export function isEcJWK(v)
|
|
75
68
|
|
|
76
69
|
export interface JweHeader extends Omit<BaseJwtHeader, 'alg'> {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
[k: string]: any
|
|
70
|
+
alg: string
|
|
71
|
+
enc: string
|
|
72
|
+
jku?: string
|
|
73
|
+
jwk?: BaseJWK
|
|
74
|
+
epk?: EphemeralPublicKey
|
|
75
|
+
x5u?: string
|
|
76
|
+
x5c?: string[]
|
|
77
|
+
x5t?: string
|
|
78
|
+
cty?: string
|
|
79
|
+
crit?: string[]
|
|
89
80
|
|
|
81
|
+
[k: string]: any
|
|
90
82
|
}
|
|
91
83
|
|
|
92
|
-
|
|
93
84
|
export interface JweRecipientUnprotectedHeader {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
85
|
+
alg: string
|
|
86
|
+
iv: string
|
|
87
|
+
tag: string
|
|
88
|
+
epk?: EphemeralPublicKey
|
|
89
|
+
kid?: string
|
|
90
|
+
apv?: string
|
|
91
|
+
apu?: string
|
|
101
92
|
}
|
|
102
93
|
|
|
103
94
|
export interface JweProtectedHeader extends Partial<JweHeader> {
|
|
104
|
-
|
|
95
|
+
zip?: 'DEF' | string
|
|
105
96
|
}
|
|
106
97
|
|
|
107
|
-
|
|
108
98
|
export type Jws = JwsCompact | JwsJsonFlattened | JwsJsonGeneral
|
|
109
99
|
|
|
110
100
|
export type JwsCompact = string
|
|
111
101
|
|
|
112
102
|
export interface JwsJsonFlattened {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
103
|
+
payload: string
|
|
104
|
+
protected: string
|
|
105
|
+
header?: JwsHeader
|
|
106
|
+
signature: string
|
|
117
107
|
}
|
|
118
108
|
|
|
119
109
|
export interface JwsJsonGeneral {
|
|
120
|
-
|
|
121
|
-
|
|
110
|
+
payload: string
|
|
111
|
+
signatures: Array<JwsJsonSignature>
|
|
122
112
|
}
|
|
123
113
|
|
|
124
114
|
export interface JwsJsonGeneralWithIdentifiers extends JwsJsonGeneral {
|
|
125
|
-
|
|
115
|
+
signatures: Array<JwsJsonSignatureWithIdentifier>
|
|
126
116
|
}
|
|
127
117
|
|
|
128
118
|
export interface JwsJsonSignatureWithIdentifier extends JwsJsonSignature {
|
|
129
|
-
|
|
119
|
+
identifier: ExternalIdentifierResult
|
|
130
120
|
}
|
|
131
121
|
|
|
132
|
-
|
|
133
122
|
export type Jwe = JweCompact | JweJsonFlattened | JweJsonGeneral
|
|
134
123
|
export type JweCompact = string
|
|
135
124
|
|
|
136
125
|
export interface JweJsonFlattened {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
126
|
+
protected: string
|
|
127
|
+
unprotected: JweHeader
|
|
128
|
+
header: JweHeader | JweRecipientUnprotectedHeader
|
|
129
|
+
encrypted_key?: string
|
|
130
|
+
aad?: string
|
|
131
|
+
iv: string
|
|
132
|
+
ciphertext: string
|
|
133
|
+
tag?: string
|
|
145
134
|
}
|
|
146
135
|
|
|
147
|
-
|
|
148
136
|
export interface JweRecipient {
|
|
149
|
-
|
|
150
|
-
|
|
137
|
+
header?: JweRecipientUnprotectedHeader
|
|
138
|
+
encrypted_key?: string
|
|
151
139
|
}
|
|
152
140
|
|
|
153
141
|
export interface JweJsonGeneral {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
142
|
+
protected: string
|
|
143
|
+
unprotected?: JweHeader
|
|
144
|
+
recipients: Array<JweRecipient>
|
|
145
|
+
aad?: string
|
|
146
|
+
iv: string
|
|
147
|
+
ciphertext: string
|
|
148
|
+
tag?: string
|
|
161
149
|
}
|
|
162
150
|
|
|
163
|
-
|
|
164
151
|
export interface PreparedJwsObject {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
152
|
+
jws: PreparedJws
|
|
153
|
+
b64: { payload: string; protectedHeader: string } // header is always json, as it can only be used in JwsJson
|
|
154
|
+
identifier: ManagedIdentifierResult
|
|
168
155
|
}
|
|
169
156
|
|
|
170
157
|
export interface BaseJwtHeader {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
158
|
+
typ?: string
|
|
159
|
+
alg?: string
|
|
160
|
+
kid?: string
|
|
174
161
|
}
|
|
175
162
|
|
|
176
163
|
export interface BaseJwtPayload {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
164
|
+
iss?: string
|
|
165
|
+
sub?: string
|
|
166
|
+
aud?: string[] | string
|
|
167
|
+
exp?: number
|
|
168
|
+
nbf?: number
|
|
169
|
+
iat?: number
|
|
170
|
+
jti?: string
|
|
184
171
|
}
|
|
185
172
|
|
|
186
173
|
export interface JwsHeader extends BaseJwtHeader {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
174
|
+
kid?: string
|
|
175
|
+
jwk?: JWK
|
|
176
|
+
x5c?: string[]
|
|
190
177
|
|
|
191
|
-
|
|
178
|
+
[key: string]: unknown
|
|
192
179
|
}
|
|
193
180
|
|
|
194
181
|
export interface JwsPayload extends BaseJwtPayload {
|
|
195
|
-
|
|
182
|
+
[key: string]: unknown
|
|
196
183
|
}
|
|
197
184
|
|
|
198
185
|
export interface JwsHeaderOpts {
|
|
199
|
-
|
|
186
|
+
alg: JoseSignatureAlgorithm | JoseSignatureAlgorithmString
|
|
200
187
|
}
|
|
201
188
|
|
|
202
189
|
export type JwsIdentifierMode = 'x5c' | 'kid' | 'jwk' | 'did' | 'auto'
|
|
203
190
|
|
|
204
191
|
export type EncryptJweCompactJwtArgs = {
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
192
|
+
payload: JwsPayload
|
|
193
|
+
protectedHeader?: JweProtectedHeader | undefined
|
|
194
|
+
aad?: Uint8Array | undefined
|
|
195
|
+
recipientKey: ExternalIdentifierResult & { kid?: string }
|
|
196
|
+
alg?: JweAlg
|
|
197
|
+
enc?: JweEnc
|
|
198
|
+
apu?: string // base64url
|
|
199
|
+
apv?: string // base64url
|
|
200
|
+
expirationTime?: number | string | Date
|
|
201
|
+
issuer?: string
|
|
202
|
+
audience?: string | string[]
|
|
216
203
|
}
|
|
217
204
|
|
|
218
205
|
export type DecryptJweCompactJwtArgs = {
|
|
219
|
-
|
|
220
|
-
|
|
206
|
+
jwe: JweCompact
|
|
207
|
+
idOpts: ManagedIdentifierOptsOrResult
|
|
221
208
|
}
|
|
222
209
|
|
|
223
210
|
export type CreateJwsArgs = {
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
211
|
+
mode?: JwsIdentifierMode
|
|
212
|
+
issuer: ManagedIdentifierOptsOrResult & {
|
|
213
|
+
noIssPayloadUpdate?: boolean
|
|
214
|
+
noIdentifierInHeader?: boolean
|
|
215
|
+
}
|
|
216
|
+
clientId?: string
|
|
217
|
+
clientIdScheme?: ClientIdScheme | 'did' | string
|
|
218
|
+
protectedHeader: JwsHeader
|
|
219
|
+
payload: JwsPayload | Uint8Array | string
|
|
233
220
|
}
|
|
234
221
|
|
|
235
|
-
|
|
236
222
|
export type CreateJweArgs = {
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
223
|
+
mode?: JwsIdentifierMode
|
|
224
|
+
issuer: ManagedIdentifierOptsOrResult & {
|
|
225
|
+
noIssPayloadUpdate?: boolean
|
|
226
|
+
noIdentifierInHeader?: boolean
|
|
227
|
+
}
|
|
228
|
+
protectedHeader: JweProtectedHeader
|
|
229
|
+
encryptedKey: string | EphemeralPublicKey // In case it is a string it is already encrypted; otherwise encrypt //TODO ??
|
|
230
|
+
iv: string
|
|
231
|
+
ciphertext: string
|
|
232
|
+
tag: string
|
|
247
233
|
}
|
|
248
234
|
export type CreateJwsCompactArgs = CreateJwsArgs
|
|
249
235
|
|
|
250
236
|
export type CreateJwsFlattenedArgs = Exclude<CreateJwsJsonArgs, 'existingSignatures'>
|
|
251
237
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
238
|
export type VerifyJwsArgs = {
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
239
|
+
jws: Jws
|
|
240
|
+
jwk?: JWK // Jwk will be resolved from jws, but you can also provide one
|
|
241
|
+
opts?: { x5c?: Omit<ExternalIdentifierX5cOpts, 'identifier'>; did?: Omit<ExternalIdentifierDidOpts, 'identifier'> }
|
|
259
242
|
}
|
|
260
243
|
|
|
261
244
|
/**
|
|
262
245
|
* @public
|
|
263
246
|
*/
|
|
264
247
|
export type CreateJwsJsonArgs = CreateJwsArgs & {
|
|
265
|
-
|
|
266
|
-
|
|
248
|
+
unprotectedHeader?: JwsHeader // only for jws json
|
|
249
|
+
existingSignatures?: Array<JwsJsonSignature> // Only for jws json
|
|
267
250
|
}
|
|
268
251
|
|
|
269
252
|
export type CreateJweJsonArgs = CreateJweArgs & {
|
|
270
|
-
|
|
253
|
+
unprotectedHeader?: JweHeader
|
|
271
254
|
}
|
|
272
255
|
|
|
273
256
|
/**
|
|
274
257
|
* @public
|
|
275
258
|
*/
|
|
276
259
|
export interface JwtCompactResult {
|
|
277
|
-
|
|
260
|
+
jwt: JwsCompact | JweCompact
|
|
278
261
|
}
|
|
279
262
|
|
|
280
263
|
export function isJwsCompact(jws: Jws): jws is JwsCompact {
|
|
281
|
-
|
|
264
|
+
return typeof jws === 'string' && jws.split('~')[0].match(COMPACT_JWS_REGEX) !== null
|
|
282
265
|
}
|
|
283
266
|
|
|
284
267
|
export function isJweCompact(jwe: Jwe): jwe is JweCompact {
|
|
285
|
-
|
|
268
|
+
return typeof jwe === 'string' && jwe.split('~')[0].match(COMPACT_JWE_REGEX) !== null
|
|
286
269
|
}
|
|
287
270
|
|
|
288
|
-
|
|
289
271
|
export function isJwsJsonFlattened(jws: Jws): jws is JwsJsonFlattened {
|
|
290
|
-
|
|
272
|
+
return typeof jws === 'object' && 'signature' in jws && 'protected' in jws && !('ciphertext' in jws)
|
|
291
273
|
}
|
|
292
274
|
|
|
293
275
|
export function isJwsJsonGeneral(jws: Jws): jws is JwsJsonGeneral {
|
|
294
|
-
|
|
276
|
+
return typeof jws === 'object' && 'signatures' in jws && !('ciphertext' in jws)
|
|
295
277
|
}
|
|
296
278
|
|
|
297
|
-
|
|
298
279
|
export function isJweJsonFlattened(jwe: Jwe): jwe is JweJsonFlattened {
|
|
299
|
-
|
|
280
|
+
return typeof jwe === 'object' && 'signature' in jwe && 'ciphertext' in jwe && !('payload' in jwe)
|
|
300
281
|
}
|
|
301
282
|
|
|
302
283
|
export function isJweJsonGeneral(jwe: Jwe): jwe is JweJsonGeneral {
|
|
303
|
-
|
|
284
|
+
return typeof jwe === 'object' && 'signatures' in jwe && 'ciphertext' in jwe && !('payload' in jwe)
|
|
304
285
|
}
|
|
305
286
|
|
|
306
|
-
|
|
307
287
|
export function isJwsHeader(header: BaseJwtHeader & Record<string, any>): header is JwsHeader {
|
|
308
|
-
|
|
288
|
+
return header && !isJweHeader(header)
|
|
309
289
|
}
|
|
310
290
|
|
|
311
291
|
export function isJweHeader(header: BaseJwtHeader & Record<string, any>): header is JweHeader {
|
|
312
|
-
|
|
292
|
+
return ('enc' in header && header.enc && jweEnc(header.enc)) || (header.alg && jweAlg(header.alg))
|
|
313
293
|
}
|
|
314
294
|
|
|
315
295
|
export const COMPACT_JWS_REGEX = /^([a-zA-Z0-9_=-]+).([a-zA-Z0-9_=-]+)?.([a-zA-Z0-9_=-]+)?$/
|
|
316
296
|
export const COMPACT_JWE_REGEX = /^([a-zA-Z0-9_=-]+)\.([a-zA-Z0-9_=-]+)?\.([a-zA-Z0-9_=-]+)\.([a-zA-Z0-9_=-]+)?\.([a-zA-Z0-9_=-]+)?$/
|
|
317
297
|
|
|
318
|
-
export const JweAlgs = [
|
|
319
|
-
|
|
298
|
+
export const JweAlgs = [
|
|
299
|
+
'RSA1_5',
|
|
300
|
+
'RSA-OAEP',
|
|
301
|
+
'RSA-OAEP-256',
|
|
302
|
+
'A128KW',
|
|
303
|
+
'A192KW',
|
|
304
|
+
'A256KW',
|
|
305
|
+
'dir',
|
|
306
|
+
'ECDH-ES' /*interop value*/,
|
|
307
|
+
'ECDH-ES+A128KW',
|
|
308
|
+
'ECDH-ES+A192KW',
|
|
309
|
+
'ECDH-ES+A256KW',
|
|
310
|
+
'A128GCMKW',
|
|
311
|
+
'A192GCMKW',
|
|
312
|
+
'A256GCMKW',
|
|
313
|
+
'PBES2-HS256+A128KW',
|
|
314
|
+
'PBES2-HS384+A192KW',
|
|
315
|
+
'PBES2-HS512+A256KW',
|
|
316
|
+
] as const
|
|
317
|
+
export type JweAlg = (typeof JweAlgs)[number]
|
|
320
318
|
export function jweAlg(alg?: string | JweAlg): JweAlg | undefined {
|
|
321
|
-
|
|
319
|
+
return JweAlgs.find((supportedVal) => supportedVal === alg)
|
|
322
320
|
}
|
|
323
321
|
|
|
324
|
-
|
|
325
|
-
export
|
|
326
|
-
export type JweEnc = typeof JweEncs[number]
|
|
322
|
+
export const JweEncs = ['A128CBC-HS256', 'A192CBC-HS384', 'A256CBC-HS512', 'A128GCM', 'A192GCM', 'A256GCM' /*interop value*/] as const
|
|
323
|
+
export type JweEnc = (typeof JweEncs)[number]
|
|
327
324
|
|
|
328
325
|
export function jweEnc(alg?: string | JweEnc): JweEnc | undefined {
|
|
329
|
-
|
|
326
|
+
return JweEncs.find((supportedVal) => supportedVal === alg)
|
|
330
327
|
}
|
|
331
|
-
|