@sphereon/ssi-sdk-ext.jwt-service 0.24.1-unstable.89 → 0.24.1-unstable.90
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.map +1 -1
- package/dist/functions/index.d.ts +1 -1
- package/dist/functions/index.d.ts.map +1 -1
- package/dist/functions/index.js +8 -8
- package/dist/functions/index.js.map +1 -1
- package/dist/types/IJwtService.d.ts +2 -2
- package/dist/types/IJwtService.d.ts.map +1 -1
- package/dist/types/IJwtService.js.map +1 -1
- package/package.json +10 -10
- package/plugin.schema.json +789 -590
- package/src/agent/JwtService.ts +4 -7
- package/src/functions/index.ts +221 -227
- package/src/types/IJwtService.ts +16 -20
package/src/agent/JwtService.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {IAgentPlugin} from '@veramo/core'
|
|
1
|
+
import { IAgentPlugin } from '@veramo/core'
|
|
2
2
|
import {
|
|
3
3
|
createJwsCompact,
|
|
4
4
|
CreateJwsCompactArgs,
|
|
@@ -7,7 +7,8 @@ import {
|
|
|
7
7
|
createJwsJsonFlattened,
|
|
8
8
|
createJwsJsonGeneral,
|
|
9
9
|
IJwtService,
|
|
10
|
-
IRequiredContext,
|
|
10
|
+
IRequiredContext,
|
|
11
|
+
JwsCompactResult,
|
|
11
12
|
JwsJsonFlattened,
|
|
12
13
|
JwsJsonGeneral,
|
|
13
14
|
PreparedJwsObject,
|
|
@@ -15,7 +16,6 @@ import {
|
|
|
15
16
|
schema,
|
|
16
17
|
} from '..'
|
|
17
18
|
|
|
18
|
-
|
|
19
19
|
/**
|
|
20
20
|
* @public
|
|
21
21
|
*/
|
|
@@ -40,10 +40,7 @@ export class JwtService implements IAgentPlugin {
|
|
|
40
40
|
return await createJwsJsonFlattened(args, context)
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
private async jwtCreateJwsCompactSignature(
|
|
44
|
-
args: CreateJwsCompactArgs,
|
|
45
|
-
context: IRequiredContext
|
|
46
|
-
): Promise<JwsCompactResult> {
|
|
43
|
+
private async jwtCreateJwsCompactSignature(args: CreateJwsCompactArgs, context: IRequiredContext): Promise<JwsCompactResult> {
|
|
47
44
|
// We wrap it in a json object for remote REST calls
|
|
48
45
|
return { jwt: await createJwsCompact(args, context) }
|
|
49
46
|
}
|
package/src/functions/index.ts
CHANGED
|
@@ -1,113 +1,107 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
isManagedIdentifierDidResult,
|
|
3
|
+
isManagedIdentifierX5cResult,
|
|
4
|
+
ManagedIdentifierMethod,
|
|
5
|
+
ManagedIdentifierResult,
|
|
6
|
+
ensureManagedIdentifierResult,
|
|
6
7
|
} from '@sphereon/ssi-sdk-ext.identifier-resolution'
|
|
7
|
-
import {bytesToBase64url, encodeJoseBlob} from '@veramo/utils'
|
|
8
|
+
import { bytesToBase64url, encodeJoseBlob } from '@veramo/utils'
|
|
8
9
|
import * as u8a from 'uint8arrays'
|
|
9
10
|
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
11
|
+
CreateJwsCompactArgs,
|
|
12
|
+
CreateJwsFlattenedArgs,
|
|
13
|
+
CreateJwsJsonArgs,
|
|
14
|
+
CreateJwsMode,
|
|
15
|
+
IRequiredContext,
|
|
16
|
+
JwsCompact,
|
|
17
|
+
JwsJsonFlattened,
|
|
18
|
+
JwsJsonGeneral,
|
|
19
|
+
JwsJsonSignature,
|
|
20
|
+
JwtHeader,
|
|
21
|
+
PreparedJwsObject,
|
|
21
22
|
} from '../types/IJwtService'
|
|
22
23
|
|
|
23
24
|
export const prepareJwsObject = async (args: CreateJwsJsonArgs, context: IRequiredContext): Promise<PreparedJwsObject> => {
|
|
24
|
-
|
|
25
|
-
existingSignatures,
|
|
26
|
-
protectedHeader,
|
|
27
|
-
unprotectedHeader,
|
|
28
|
-
issuer,
|
|
29
|
-
payload,
|
|
30
|
-
mode = 'auto'
|
|
31
|
-
} = args
|
|
25
|
+
const { existingSignatures, protectedHeader, unprotectedHeader, issuer, payload, mode = 'auto' } = args
|
|
32
26
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
27
|
+
const { noIdentifierInHeader = false } = issuer
|
|
28
|
+
const combinedHeader = { ...unprotectedHeader, ...protectedHeader }
|
|
29
|
+
if (!combinedHeader.alg) {
|
|
30
|
+
return Promise.reject(`No 'alg' key present in the JWS header`)
|
|
31
|
+
}
|
|
32
|
+
const identifier = await ensureManagedIdentifierResult(issuer, context)
|
|
33
|
+
await checkAndUpdateJwtHeader({ mode, identifier, noIdentifierInHeader, header: protectedHeader }, context)
|
|
40
34
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
35
|
+
const isBytes = payload instanceof Uint8Array
|
|
36
|
+
const isString = typeof payload === 'string'
|
|
37
|
+
if (!isBytes && !isString) {
|
|
38
|
+
if (issuer.noIssPayloadUpdate !== true && !payload.iss && identifier.issuer) {
|
|
39
|
+
payload.iss = identifier.issuer
|
|
47
40
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
41
|
+
}
|
|
42
|
+
const payloadBytes = isBytes ? payload : isString ? u8a.fromString(payload, 'base64url') : u8a.fromString(JSON.stringify(payload), 'utf-8')
|
|
43
|
+
const base64urlHeader = encodeJoseBlob(protectedHeader)
|
|
44
|
+
const base64urlPayload = bytesToBase64url(payloadBytes)
|
|
51
45
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
46
|
+
return {
|
|
47
|
+
jws: {
|
|
48
|
+
unprotectedHeader,
|
|
49
|
+
protectedHeader,
|
|
50
|
+
payload: payloadBytes,
|
|
51
|
+
existingSignatures,
|
|
52
|
+
},
|
|
53
|
+
b64: {
|
|
54
|
+
protectedHeader: base64urlHeader,
|
|
55
|
+
payload: base64urlPayload,
|
|
56
|
+
},
|
|
57
|
+
identifier,
|
|
58
|
+
}
|
|
65
59
|
}
|
|
66
60
|
|
|
67
61
|
export const createJwsCompact = async (args: CreateJwsCompactArgs, context: IRequiredContext): Promise<JwsCompact> => {
|
|
68
|
-
|
|
69
|
-
|
|
62
|
+
const { protected: protectedHeader, payload, signature } = await createJwsJsonFlattened(args, context)
|
|
63
|
+
return `${protectedHeader}.${payload}.${signature}`
|
|
70
64
|
}
|
|
71
65
|
|
|
72
66
|
export const createJwsJsonFlattened = async (args: CreateJwsFlattenedArgs, context: IRequiredContext): Promise<JwsJsonFlattened> => {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
67
|
+
const jws = await createJwsJsonGeneral(args, context)
|
|
68
|
+
if (jws.signatures.length !== 1) {
|
|
69
|
+
return Promise.reject(Error(`JWS flattened signature can only contain 1 signature. Found ${jws.signatures.length}`))
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
...jws.signatures[0],
|
|
73
|
+
payload: jws.payload,
|
|
74
|
+
} satisfies JwsJsonFlattened
|
|
81
75
|
}
|
|
82
76
|
|
|
83
77
|
export const createJwsJsonGeneral = async (args: CreateJwsJsonArgs, context: IRequiredContext): Promise<JwsJsonGeneral> => {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
78
|
+
const { payload, protectedHeader, unprotectedHeader, existingSignatures, mode, issuer } = args
|
|
79
|
+
const { b64, identifier } = await prepareJwsObject(
|
|
80
|
+
{
|
|
81
|
+
protectedHeader,
|
|
82
|
+
unprotectedHeader,
|
|
83
|
+
payload,
|
|
84
|
+
existingSignatures,
|
|
85
|
+
issuer,
|
|
86
|
+
mode,
|
|
87
|
+
},
|
|
88
|
+
context
|
|
89
|
+
)
|
|
90
|
+
// const algorithm = await signatureAlgorithmFromKey({ key: identifier.key })
|
|
91
|
+
const signature = await context.agent.keyManagerSign({
|
|
92
|
+
keyRef: identifier.kmsKeyRef,
|
|
93
|
+
data: `${b64.protectedHeader}.${b64.payload}`,
|
|
94
|
+
encoding: undefined,
|
|
95
|
+
})
|
|
96
|
+
const jsonSignature = {
|
|
97
|
+
protected: b64.protectedHeader,
|
|
98
|
+
header: unprotectedHeader,
|
|
99
|
+
signature,
|
|
100
|
+
} satisfies JwsJsonSignature
|
|
101
|
+
return {
|
|
102
|
+
payload: b64.payload,
|
|
103
|
+
signatures: [...(existingSignatures ?? []), jsonSignature],
|
|
104
|
+
} satisfies JwsJsonGeneral
|
|
111
105
|
}
|
|
112
106
|
|
|
113
107
|
/**
|
|
@@ -120,166 +114,166 @@ export const createJwsJsonGeneral = async (args: CreateJwsJsonArgs, context: IRe
|
|
|
120
114
|
*/
|
|
121
115
|
|
|
122
116
|
export const checkAndUpdateJwtHeader = async (
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
117
|
+
{
|
|
118
|
+
mode = 'auto',
|
|
119
|
+
identifier,
|
|
120
|
+
header,
|
|
121
|
+
noIdentifierInHeader = false,
|
|
122
|
+
}: {
|
|
123
|
+
mode?: CreateJwsMode
|
|
124
|
+
identifier: ManagedIdentifierResult
|
|
125
|
+
noIdentifierInHeader?: boolean
|
|
126
|
+
header: JwtHeader
|
|
127
|
+
},
|
|
128
|
+
context: IRequiredContext
|
|
135
129
|
) => {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
130
|
+
if (isMode(mode, identifier.method, 'did')) {
|
|
131
|
+
// kid is VM of the DID
|
|
132
|
+
// @see https://datatracker.ietf.org/doc/html/rfc7515#section-4.1.4
|
|
133
|
+
await checkAndUpdateDidHeader({ header, identifier, noIdentifierInHeader }, context)
|
|
134
|
+
} else if (isMode(mode, identifier.method, 'x5c')) {
|
|
135
|
+
// Include the x5c in the header. No kid
|
|
136
|
+
// @see https://datatracker.ietf.org/doc/html/rfc7515#section-4.1.6
|
|
137
|
+
await checkAndUpdateX5cHeader({ header, identifier, noIdentifierInHeader }, context)
|
|
138
|
+
} else if (isMode(mode, identifier.method, 'kid', false)) {
|
|
139
|
+
await checkAndUpdateKidHeader({ header, identifier, noIdentifierInHeader }, context)
|
|
140
|
+
} else if (isMode(mode, identifier.method, 'jwk', false)) {
|
|
141
|
+
// Include the JWK in the header as well as its kid if present
|
|
142
|
+
// @see https://datatracker.ietf.org/doc/html/rfc7515#section-4.1.3
|
|
143
|
+
// @see https://datatracker.ietf.org/doc/html/rfc7515#section-4.1.4
|
|
144
|
+
await checkAndUpdateJwkHeader({ header, identifier, noIdentifierInHeader }, context)
|
|
145
|
+
} else {
|
|
146
|
+
// Better safe than sorry. We could let it pass, but we want to force implementers to make a conscious choice
|
|
147
|
+
return Promise.reject(`Invalid combination of JWS creation mode ${mode} and identifier method ${identifier.method} chosen`)
|
|
148
|
+
}
|
|
155
149
|
}
|
|
156
150
|
|
|
157
151
|
const checkAndUpdateX5cHeader = async (
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
152
|
+
{
|
|
153
|
+
header,
|
|
154
|
+
identifier,
|
|
155
|
+
noIdentifierInHeader = false,
|
|
156
|
+
}: {
|
|
157
|
+
header: JwtHeader
|
|
158
|
+
identifier: ManagedIdentifierResult
|
|
159
|
+
noIdentifierInHeader?: boolean
|
|
160
|
+
},
|
|
161
|
+
context: IRequiredContext
|
|
168
162
|
) => {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
}
|
|
182
|
-
header.x5c = identifier.x5c
|
|
163
|
+
const { x5c } = header
|
|
164
|
+
if (x5c) {
|
|
165
|
+
// let's resolve the provided x5c to be sure
|
|
166
|
+
const x5cIdentifier = await context.agent.identifierManagedGetByX5c({ identifier: x5c })
|
|
167
|
+
if (x5cIdentifier.kmsKeyRef !== identifier.kmsKeyRef) {
|
|
168
|
+
return Promise.reject(Error(`An x5c header was present, but its issuer public key did not match the provided signing public key!`))
|
|
169
|
+
}
|
|
170
|
+
} else if (!noIdentifierInHeader) {
|
|
171
|
+
if (!isManagedIdentifierX5cResult(identifier)) {
|
|
172
|
+
return Promise.reject(Error('No x5c header in the JWT, but mode was x5c and also no x5x identifier was provided!'))
|
|
173
|
+
} else if (header.jwk || header.kid) {
|
|
174
|
+
return Promise.reject(Error('x5c mode was choosen, but jwk or kid headers were provided. These cannot be used together!'))
|
|
183
175
|
}
|
|
176
|
+
header.x5c = identifier.x5c
|
|
177
|
+
}
|
|
184
178
|
}
|
|
185
179
|
|
|
186
180
|
const checkAndUpdateDidHeader = async (
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
181
|
+
{
|
|
182
|
+
header,
|
|
183
|
+
identifier,
|
|
184
|
+
noIdentifierInHeader = false,
|
|
185
|
+
}: {
|
|
186
|
+
header: JwtHeader
|
|
187
|
+
identifier: ManagedIdentifierResult
|
|
188
|
+
noIdentifierInHeader?: boolean
|
|
189
|
+
},
|
|
190
|
+
context: IRequiredContext
|
|
197
191
|
) => {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
}
|
|
211
|
-
header.kid = identifier.kid
|
|
192
|
+
const { kid } = header
|
|
193
|
+
if (kid) {
|
|
194
|
+
// let's resolve the provided x5c to be sure
|
|
195
|
+
const vmIdentifier = await context.agent.identifierManagedGetByDid({ identifier: kid })
|
|
196
|
+
if (vmIdentifier.kmsKeyRef !== identifier.kmsKeyRef) {
|
|
197
|
+
return Promise.reject(Error(`A kid header was present, but its value did not match the provided signing kid!`))
|
|
198
|
+
}
|
|
199
|
+
} else if (!noIdentifierInHeader) {
|
|
200
|
+
if (!isManagedIdentifierDidResult(identifier)) {
|
|
201
|
+
return Promise.reject(Error('No kid header in the JWT, but mode was did and also no DID identifier was provided!'))
|
|
202
|
+
} else if (header.jwk || header.x5c) {
|
|
203
|
+
return Promise.reject(Error('did mode was chosen, but jwk or x5c headers were provided. These cannot be used together!'))
|
|
212
204
|
}
|
|
205
|
+
header.kid = identifier.kid
|
|
206
|
+
}
|
|
213
207
|
}
|
|
214
208
|
|
|
215
209
|
const checkAndUpdateJwkHeader = async (
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
210
|
+
{
|
|
211
|
+
header,
|
|
212
|
+
identifier,
|
|
213
|
+
noIdentifierInHeader = false,
|
|
214
|
+
}: {
|
|
215
|
+
header: JwtHeader
|
|
216
|
+
identifier: ManagedIdentifierResult
|
|
217
|
+
noIdentifierInHeader?: boolean
|
|
218
|
+
},
|
|
219
|
+
context: IRequiredContext
|
|
226
220
|
) => {
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
}
|
|
239
|
-
header.jwk = identifier.jwk
|
|
221
|
+
const { jwk } = header
|
|
222
|
+
if (jwk) {
|
|
223
|
+
// let's resolve the provided x5c to be sure
|
|
224
|
+
const jwkIdentifier = await context.agent.identifierManagedGetByJwk({ identifier: jwk })
|
|
225
|
+
if (jwkIdentifier.kmsKeyRef !== identifier.kmsKeyRef) {
|
|
226
|
+
return Promise.reject(Error(`A jwk header was present, but its value did not match the provided signing jwk or kid!`))
|
|
227
|
+
}
|
|
228
|
+
} else if (!noIdentifierInHeader) {
|
|
229
|
+
// We basically accept everything for this mode, as we can always create JWKs from any key
|
|
230
|
+
if (header.x5c) {
|
|
231
|
+
return Promise.reject(Error('jwk mode was chosen, but x5c headers were provided. These cannot be used together!'))
|
|
240
232
|
}
|
|
233
|
+
header.jwk = identifier.jwk
|
|
234
|
+
}
|
|
241
235
|
}
|
|
242
236
|
|
|
243
237
|
const checkAndUpdateKidHeader = async (
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
238
|
+
{
|
|
239
|
+
header,
|
|
240
|
+
identifier,
|
|
241
|
+
noIdentifierInHeader = false,
|
|
242
|
+
}: {
|
|
243
|
+
header: JwtHeader
|
|
244
|
+
identifier: ManagedIdentifierResult
|
|
245
|
+
noIdentifierInHeader?: boolean
|
|
246
|
+
},
|
|
247
|
+
context: IRequiredContext
|
|
254
248
|
) => {
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
}
|
|
267
|
-
header.kid = identifier.kid
|
|
249
|
+
const { kid } = header
|
|
250
|
+
if (kid) {
|
|
251
|
+
// let's resolve the provided x5c to be sure
|
|
252
|
+
const kidIdentifier = await context.agent.identifierManagedGetByKid({ identifier: kid })
|
|
253
|
+
if (kidIdentifier.kmsKeyRef !== identifier.kmsKeyRef) {
|
|
254
|
+
return Promise.reject(Error(`A kid header was present, but its value did not match the provided signing kid!`))
|
|
255
|
+
}
|
|
256
|
+
} else if (!noIdentifierInHeader) {
|
|
257
|
+
// We basically accept everything for this mode, as we can always create JWKs from any key
|
|
258
|
+
if (header.x5c) {
|
|
259
|
+
return Promise.reject(Error('kid mode was chosen, but x5c headers were provided. These cannot be used together!'))
|
|
268
260
|
}
|
|
261
|
+
header.kid = identifier.kid
|
|
262
|
+
}
|
|
269
263
|
}
|
|
270
264
|
|
|
271
265
|
const isMode = (mode: CreateJwsMode, identifierMethod: ManagedIdentifierMethod, checkMode: CreateJwsMode, loose = true) => {
|
|
272
|
-
|
|
273
|
-
// we always have the kid and jwk at hand no matter the identifier method, so we are okay with that
|
|
274
|
-
// todo: check the impact on the above expressions, as this will now always return true for the both of them
|
|
275
|
-
return true
|
|
276
|
-
}
|
|
277
|
-
if (mode === checkMode) {
|
|
278
|
-
if (checkMode !== 'auto' && mode !== identifierMethod) {
|
|
279
|
-
throw Error(`Provided mode ${mode} conflicts with identifier method ${identifierMethod}`)
|
|
280
|
-
}
|
|
281
|
-
return true
|
|
282
|
-
}
|
|
266
|
+
if (loose && (checkMode === 'jwk' || checkMode === 'kid')) {
|
|
283
267
|
// we always have the kid and jwk at hand no matter the identifier method, so we are okay with that
|
|
284
|
-
return
|
|
268
|
+
// todo: check the impact on the above expressions, as this will now always return true for the both of them
|
|
269
|
+
return true
|
|
270
|
+
}
|
|
271
|
+
if (mode === checkMode) {
|
|
272
|
+
if (checkMode !== 'auto' && mode !== identifierMethod) {
|
|
273
|
+
throw Error(`Provided mode ${mode} conflicts with identifier method ${identifierMethod}`)
|
|
274
|
+
}
|
|
275
|
+
return true
|
|
276
|
+
}
|
|
277
|
+
// we always have the kid and jwk at hand no matter the identifier method, so we are okay with that
|
|
278
|
+
return mode === 'auto' && identifierMethod === checkMode
|
|
285
279
|
}
|
package/src/types/IJwtService.ts
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
} from '@sphereon/ssi-sdk-ext.identifier-resolution'
|
|
6
|
-
import {ISphereonKeyManager} from '@sphereon/ssi-sdk-ext.key-manager'
|
|
7
|
-
import {JWK, SignatureAlgorithmJwa} from '@sphereon/ssi-sdk-ext.key-utils'
|
|
8
|
-
import {IAgentContext, IPluginMethodMap} from '@veramo/core'
|
|
1
|
+
import { IIdentifierResolution, ManagedIdentifierOptsOrResult, ManagedIdentifierResult } from '@sphereon/ssi-sdk-ext.identifier-resolution'
|
|
2
|
+
import { ISphereonKeyManager } from '@sphereon/ssi-sdk-ext.key-manager'
|
|
3
|
+
import { JWK, SignatureAlgorithmJwa } from '@sphereon/ssi-sdk-ext.key-utils'
|
|
4
|
+
import { IAgentContext, IPluginMethodMap } from '@veramo/core'
|
|
9
5
|
|
|
10
6
|
export type IRequiredContext = IAgentContext<IIdentifierResolution & ISphereonKeyManager> // could we still interop with Veramo?
|
|
11
7
|
export interface IJwtService extends IPluginMethodMap {
|
|
@@ -56,18 +52,18 @@ export interface PreparedJwsObject {
|
|
|
56
52
|
}
|
|
57
53
|
|
|
58
54
|
export interface BaseJwtHeader {
|
|
59
|
-
typ?: string
|
|
60
|
-
alg?: string
|
|
61
|
-
kid?: string
|
|
55
|
+
typ?: string
|
|
56
|
+
alg?: string
|
|
57
|
+
kid?: string
|
|
62
58
|
}
|
|
63
59
|
export interface BaseJwtPayload {
|
|
64
|
-
iss?: string
|
|
65
|
-
sub?: string
|
|
66
|
-
aud?: string[] | string
|
|
67
|
-
exp?: number
|
|
68
|
-
nbf?: number
|
|
69
|
-
iat?: number
|
|
70
|
-
jti?: string
|
|
60
|
+
iss?: string
|
|
61
|
+
sub?: string
|
|
62
|
+
aud?: string[] | string
|
|
63
|
+
exp?: number
|
|
64
|
+
nbf?: number
|
|
65
|
+
iat?: number
|
|
66
|
+
jti?: string
|
|
71
67
|
}
|
|
72
68
|
|
|
73
69
|
export interface JwtHeader extends BaseJwtHeader {
|
|
@@ -90,7 +86,7 @@ export type CreateJwsMode = 'x5c' | 'kid' | 'jwk' | 'did' | 'auto'
|
|
|
90
86
|
|
|
91
87
|
export type CreateJwsArgs = {
|
|
92
88
|
mode?: CreateJwsMode
|
|
93
|
-
issuer:
|
|
89
|
+
issuer: ManagedIdentifierOptsOrResult & { noIssPayloadUpdate?: boolean; noIdentifierInHeader?: boolean }
|
|
94
90
|
protectedHeader: JwtHeader
|
|
95
91
|
payload: JwtPayload | Uint8Array | string
|
|
96
92
|
}
|
|
@@ -111,7 +107,7 @@ export type CreateJwsJsonArgs = CreateJwsArgs & {
|
|
|
111
107
|
* @public
|
|
112
108
|
*/
|
|
113
109
|
export interface JwsCompactResult {
|
|
114
|
-
jwt: JwsCompact
|
|
110
|
+
jwt: JwsCompact
|
|
115
111
|
}
|
|
116
112
|
|
|
117
113
|
// export const COMPACT_JWS_REGEX = /^([a-zA-Z0-9_=-]+)\.([a-zA-Z0-9_=-]+)?\.([a-zA-Z0-9_=-]+)$/
|