@sphereon/ssi-sdk.kms-rest-client 0.36.1-next.11 → 0.36.1-next.115

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sphereon/ssi-sdk.kms-rest-client",
3
3
  "description": "contains the client side to call REST endpoints of a KMS server",
4
- "version": "0.36.1-next.11+262d209a",
4
+ "version": "0.36.1-next.115+0fab323a",
5
5
  "source": "src/index.ts",
6
6
  "type": "module",
7
7
  "main": "./dist/index.cjs",
@@ -28,7 +28,7 @@
28
28
  "generate-plugin-schema": "tsx ../../packages/dev/bin/sphereon.js dev generate-plugin-schema"
29
29
  },
30
30
  "dependencies": {
31
- "@sphereon/ssi-types": "0.36.1-next.11+262d209a",
31
+ "@sphereon/ssi-types": "0.36.1-next.115+0fab323a",
32
32
  "cross-fetch": "^3.1.8"
33
33
  },
34
34
  "devDependencies": {
@@ -56,5 +56,5 @@
56
56
  "KMS",
57
57
  "REST"
58
58
  ],
59
- "gitHead": "262d209a803fecfba1ad5878724c4f6f91f86cec"
59
+ "gitHead": "0fab323abf92edba332557800ab79493e3681e1f"
60
60
  }
@@ -1,66 +1,66 @@
1
- import { IAgentPlugin } from '@veramo/core'
2
1
  import { Loggers } from '@sphereon/ssi-types'
2
+ import { IAgentPlugin } from '@veramo/core'
3
3
  import { fetch } from 'cross-fetch'
4
- import type {
5
- kmsClientGetResolverArgs,
6
- KmsClientListResolversArgs,
7
- IKmsRestClient,
8
- KmsClientResolveKeyArgs,
9
- KmsClientCreateRawSignatureArgs,
10
- KmsClientGetKeyArgs,
11
- KmsClientListKeysArgs,
12
- KmsClientStoreKeyArgs,
13
- KmsClientGenerateKeyArgs,
14
- KmsClientDeleteKeyArgs,
15
- KmsClientGetKeyProviderArgs,
16
- KmsClientListKeyProvidersArgs,
17
- KmsClientProviderListKeysArgs,
18
- KmsClientProviderStoreKeyArgs,
19
- KmsClientProviderGenerateKeyArgs,
20
- KmsClientProviderGetKeyArgs,
21
- KmsClientProviderDeleteKeyArgs,
22
- RestClientAuthenticationOpts,
23
- KmsRestClientArgs,
24
- KmsClientIsValidRawSignatureArgs,
25
- } from '../types/IKmsRestClient'
26
4
  import type {
27
5
  CreateRawSignature,
28
6
  CreateRawSignatureResponse,
29
7
  GenerateKey,
30
8
  GenerateKeyGlobal,
9
+ GenerateKeyResponse,
10
+ GetKeyResponse,
11
+ KeyProviderResponse,
31
12
  ListKeyProvidersResponse,
32
13
  ListKeysResponse,
33
14
  ListResolversResponse,
34
15
  ResolvedKeyInfo,
35
16
  ResolvePublicKey,
36
17
  Resolver,
37
- VerifyRawSignatureResponse,
38
18
  StoreKey,
39
- VerifyRawSignature,
40
- KeyProviderResponse,
41
- GenerateKeyResponse,
42
19
  StoreKeyResponse,
43
- GetKeyResponse,
20
+ VerifyRawSignature,
21
+ VerifyRawSignatureResponse,
44
22
  } from '../models'
45
23
  import {
46
24
  CreateRawSignatureResponseFromJSONTyped,
47
25
  CreateRawSignatureToJSONTyped,
48
26
  GenerateKeyGlobalToJSONTyped,
49
- GenerateKeyToJSONTyped,
50
27
  GenerateKeyResponseFromJSONTyped,
28
+ GenerateKeyToJSONTyped,
51
29
  GetKeyResponseFromJSONTyped,
52
30
  KeyProviderResponseFromJSONTyped,
53
31
  ListKeyProvidersResponseFromJSONTyped,
54
32
  ListKeysResponseFromJSONTyped,
55
33
  ListResolversResponseFromJSONTyped,
56
- ResolvePublicKeyToJSONTyped,
57
34
  ResolvedKeyInfoFromJSONTyped,
35
+ ResolvePublicKeyToJSONTyped,
58
36
  ResolverFromJSONTyped,
59
- StoreKeyToJSONTyped,
60
37
  StoreKeyResponseFromJSONTyped,
38
+ StoreKeyToJSONTyped,
61
39
  VerifyRawSignatureResponseFromJSONTyped,
62
40
  VerifyRawSignatureToJSONTyped,
63
41
  } from '../models'
42
+ import {
43
+ IKmsRestClient,
44
+ KmsClientCreateRawSignatureArgs,
45
+ KmsClientDeleteKeyArgs,
46
+ KmsClientGenerateKeyArgs,
47
+ KmsClientGetKeyArgs,
48
+ KmsClientGetKeyProviderArgs,
49
+ KmsClientGetResolverArgs,
50
+ KmsClientIsValidRawSignatureArgs,
51
+ KmsClientListKeyProvidersArgs,
52
+ KmsClientListKeysArgs,
53
+ KmsClientListResolversArgs,
54
+ KmsClientProviderDeleteKeyArgs,
55
+ KmsClientProviderGenerateKeyArgs,
56
+ KmsClientProviderGetKeyArgs,
57
+ KmsClientProviderListKeysArgs,
58
+ KmsClientProviderStoreKeyArgs,
59
+ KmsClientResolveKeyArgs,
60
+ KmsClientStoreKeyArgs,
61
+ KmsRestClientArgs,
62
+ RestClientAuthenticationOpts,
63
+ } from '../types/IKmsRestClient'
64
64
 
65
65
  const logger = Loggers.DEFAULT.get('sphereon:ssi-sdk:kms:rest-client')
66
66
 
@@ -106,12 +106,13 @@ export class KmsRestClient implements IAgentPlugin {
106
106
  }
107
107
 
108
108
  /** {@inheritDoc IKmsRestClient.kmsGetResolver} */
109
- private async kmsClientGetResolver(args: kmsClientGetResolverArgs): Promise<Resolver> {
109
+ private async kmsClientGetResolver(args: KmsClientGetResolverArgs): Promise<Resolver> {
110
110
  const baseUrl = this.assertedAgentBaseUrl(args.baseUrl)
111
111
  const url = KmsRestClient.urlWithBase(`/resolvers/${args.resolverId}`, baseUrl)
112
112
 
113
113
  const response = await fetch(url, {
114
114
  method: 'GET',
115
+ headers: await this.createHeaders({ tenantId: args.tenantId, userId: args.userId }),
115
116
  })
116
117
  logger.debug(`get resolver response: ${response}`)
117
118
 
@@ -129,6 +130,7 @@ export class KmsRestClient implements IAgentPlugin {
129
130
 
130
131
  const response = await fetch(url, {
131
132
  method: 'GET',
133
+ headers: await this.createHeaders({ tenantId: args?.tenantId, userId: args?.userId }),
132
134
  })
133
135
  logger.debug(`list resolvers response: ${response}`)
134
136
 
@@ -152,7 +154,7 @@ export class KmsRestClient implements IAgentPlugin {
152
154
  } satisfies ResolvePublicKey
153
155
  const response = await fetch(url, {
154
156
  method: 'POST',
155
- headers: await this.createHeaders({ 'Content-Type': 'application/json' }),
157
+ headers: await this.createHeaders({ contentType: 'application/json', tenantId: args.tenantId, userId: args.userId }),
156
158
  body: JSON.stringify(ResolvePublicKeyToJSONTyped(body)),
157
159
  })
158
160
  logger.debug(`resolve key response: ${response}`)
@@ -167,7 +169,7 @@ export class KmsRestClient implements IAgentPlugin {
167
169
  /** {@inheritDoc IKmsRestClient.kmsCreateRawSignature} */
168
170
  private async kmsClientCreateRawSignature(args: KmsClientCreateRawSignatureArgs): Promise<CreateRawSignatureResponse> {
169
171
  const baseUrl = this.assertedAgentBaseUrl(args.baseUrl)
170
- const url = KmsRestClient.urlWithBase(`/signatures/raw`, baseUrl)
172
+ const url = KmsRestClient.urlWithBase(`/signatures/raw/create`, baseUrl)
171
173
 
172
174
  const body = {
173
175
  keyInfo: args.keyInfo,
@@ -175,7 +177,7 @@ export class KmsRestClient implements IAgentPlugin {
175
177
  } satisfies CreateRawSignature
176
178
  const response = await fetch(url, {
177
179
  method: 'POST',
178
- headers: await this.createHeaders({ 'Content-Type': 'application/json' }),
180
+ headers: await this.createHeaders({ contentType: 'application/json', tenantId: args.tenantId, userId: args.userId }),
179
181
  body: JSON.stringify(CreateRawSignatureToJSONTyped(body)),
180
182
  })
181
183
  logger.debug(`create raw signature response: ${response}`)
@@ -199,7 +201,7 @@ export class KmsRestClient implements IAgentPlugin {
199
201
  } satisfies VerifyRawSignature
200
202
  const response = await fetch(url, {
201
203
  method: 'POST',
202
- headers: await this.createHeaders({ 'Content-Type': 'application/json' }),
204
+ headers: await this.createHeaders({ contentType: 'application/json', tenantId: args.tenantId, userId: args.userId }),
203
205
  body: JSON.stringify(VerifyRawSignatureToJSONTyped(body)),
204
206
  })
205
207
  logger.debug(`verify raw signature response: ${response}`)
@@ -218,6 +220,7 @@ export class KmsRestClient implements IAgentPlugin {
218
220
 
219
221
  const response = await fetch(url, {
220
222
  method: 'GET',
223
+ headers: await this.createHeaders({ tenantId: args.tenantId, userId: args.userId }),
221
224
  })
222
225
  logger.debug(`get key response: ${response}`)
223
226
 
@@ -234,6 +237,7 @@ export class KmsRestClient implements IAgentPlugin {
234
237
  const url = this.addSearchParams(KmsRestClient.urlWithBase('/keys', baseUrl), { ...(args?.providerId && { providerId: args.providerId }) })
235
238
  const response = await fetch(url, {
236
239
  method: 'GET',
240
+ headers: await this.createHeaders({ tenantId: args?.tenantId, userId: args?.userId }),
237
241
  })
238
242
  logger.debug(`list keys response: ${response}`)
239
243
 
@@ -255,7 +259,7 @@ export class KmsRestClient implements IAgentPlugin {
255
259
  } satisfies StoreKey
256
260
  const response = await fetch(url, {
257
261
  method: 'POST',
258
- headers: await this.createHeaders({ 'Content-Type': 'application/json' }),
262
+ headers: await this.createHeaders({ contentType: 'application/json', tenantId: args.tenantId, userId: args.userId }),
259
263
  body: JSON.stringify(StoreKeyToJSONTyped(body)),
260
264
  })
261
265
  logger.debug(`store key response: ${response}`)
@@ -280,7 +284,7 @@ export class KmsRestClient implements IAgentPlugin {
280
284
  } satisfies GenerateKeyGlobal
281
285
  const response = await fetch(url, {
282
286
  method: 'POST',
283
- headers: await this.createHeaders({ 'Content-Type': 'application/json' }),
287
+ headers: await this.createHeaders({ contentType: 'application/json', tenantId: args.tenantId, userId: args.userId }),
284
288
  body: JSON.stringify(GenerateKeyGlobalToJSONTyped(body)),
285
289
  })
286
290
  logger.debug(`generate key response: ${response}`)
@@ -299,6 +303,7 @@ export class KmsRestClient implements IAgentPlugin {
299
303
 
300
304
  const response = await fetch(url, {
301
305
  method: 'DELETE',
306
+ headers: await this.createHeaders({ tenantId: args.tenantId, userId: args.userId }),
302
307
  })
303
308
  logger.debug(`delete key response: ${response}`)
304
309
 
@@ -316,6 +321,7 @@ export class KmsRestClient implements IAgentPlugin {
316
321
 
317
322
  const response = await fetch(url, {
318
323
  method: 'GET',
324
+ headers: await this.createHeaders({ tenantId: args.tenantId, userId: args.userId }),
319
325
  })
320
326
  logger.debug(`get provider response: ${response}`)
321
327
 
@@ -333,6 +339,7 @@ export class KmsRestClient implements IAgentPlugin {
333
339
 
334
340
  const response = await fetch(url, {
335
341
  method: 'GET',
342
+ headers: await this.createHeaders({ tenantId: args?.tenantId, userId: args?.userId }),
336
343
  })
337
344
  logger.debug(`list providers response: ${response}`)
338
345
 
@@ -350,6 +357,7 @@ export class KmsRestClient implements IAgentPlugin {
350
357
 
351
358
  const response = await fetch(url, {
352
359
  method: 'GET',
360
+ headers: await this.createHeaders({ tenantId: args.tenantId, userId: args.userId }),
353
361
  })
354
362
  logger.debug(`list provider keys response: ${response}`)
355
363
 
@@ -371,7 +379,7 @@ export class KmsRestClient implements IAgentPlugin {
371
379
  } satisfies StoreKey
372
380
  const response = await fetch(url, {
373
381
  method: 'POST',
374
- headers: await this.createHeaders({ 'Content-Type': 'application/json' }),
382
+ headers: await this.createHeaders({ contentType: 'application/json', tenantId: args.tenantId, userId: args.userId }),
375
383
  body: JSON.stringify(StoreKeyToJSONTyped(body)),
376
384
  })
377
385
  logger.debug(`provider store key response: ${response}`)
@@ -396,7 +404,7 @@ export class KmsRestClient implements IAgentPlugin {
396
404
  } satisfies GenerateKey
397
405
  const response = await fetch(url, {
398
406
  method: 'POST',
399
- headers: await this.createHeaders({ 'Content-Type': 'application/json' }),
407
+ headers: await this.createHeaders({ contentType: 'application/json', tenantId: args.tenantId, userId: args.userId }),
400
408
  body: JSON.stringify(GenerateKeyToJSONTyped(body)),
401
409
  })
402
410
  logger.debug(`provider generate key response: ${response}`)
@@ -415,6 +423,7 @@ export class KmsRestClient implements IAgentPlugin {
415
423
 
416
424
  const response = await fetch(url, {
417
425
  method: 'GET',
426
+ headers: await this.createHeaders({ tenantId: args.tenantId, userId: args.userId }),
418
427
  })
419
428
  logger.debug(`get provider key response: ${response}`)
420
429
 
@@ -432,6 +441,7 @@ export class KmsRestClient implements IAgentPlugin {
432
441
 
433
442
  const response = await fetch(url, {
434
443
  method: 'DELETE',
444
+ headers: await this.createHeaders({ tenantId: args.tenantId, userId: args.userId }),
435
445
  })
436
446
  logger.debug(`delete key response: ${response}`)
437
447
 
@@ -451,11 +461,14 @@ export class KmsRestClient implements IAgentPlugin {
451
461
  throw new Error('No base url has been provided')
452
462
  }
453
463
 
454
- private async createHeaders(existing?: Record<string, any>): Promise<HeadersInit> {
464
+ private async createHeaders(args?: { contentType?: string; tenantId?: string; userId?: string }): Promise<HeadersInit> {
455
465
  const headers: HeadersInit = {
456
- ...existing,
466
+ ...(args?.contentType ? { 'Content-Type': args.contentType } : {}),
467
+ ...(args?.tenantId ? { 'X-Tenant-ID': args.tenantId } : {}),
468
+ ...(args?.userId ? { 'X-User-ID': args.userId } : {}),
457
469
  Accept: 'application/json',
458
470
  }
471
+
459
472
  if (this.authOpts?.enabled === true) {
460
473
  if (!this.authOpts.bearerToken) {
461
474
  throw Error(`Cannot have authentication enabled, whilst not enabling static bearer tokens at this point`)
@@ -26,6 +26,9 @@ export const SignatureAlgorithm = {
26
26
  HmacSha256: 'HMAC_SHA256',
27
27
  HmacSha384: 'HMAC_SHA384',
28
28
  HmacSha512: 'HMAC_SHA512',
29
+ RsaSha256: 'RSA_SHA256',
30
+ RsaSha384: 'RSA_SHA384',
31
+ RsaSha512: 'RSA_SHA512',
29
32
  RsaSsaPssSha256Mgf1: 'RSA_SSA_PSS_SHA256_MGF1',
30
33
  RsaSsaPssSha384Mgf1: 'RSA_SSA_PSS_SHA384_MGF1',
31
34
  RsaSsaPssSha512Mgf1: 'RSA_SSA_PSS_SHA512_MGF1',
@@ -1,5 +1,5 @@
1
- import { IAgentContext, IPluginMethodMap } from '@veramo/core'
2
1
  import type { BearerTokenArg } from '@sphereon/ssi-types'
2
+ import { IAgentContext, IPluginMethodMap } from '@veramo/core'
3
3
  import {
4
4
  CreateRawSignature,
5
5
  CreateRawSignatureResponse,
@@ -21,7 +21,7 @@ import {
21
21
  } from '../models'
22
22
 
23
23
  export interface IKmsRestClient extends IPluginMethodMap {
24
- kmsClientGetResolver(args: kmsClientGetResolverArgs): Promise<Resolver>
24
+ kmsClientGetResolver(args: KmsClientGetResolverArgs): Promise<Resolver>
25
25
  kmsClientListResolvers(args?: KmsClientListResolversArgs): Promise<ListResolversResponse>
26
26
  kmsClientResolveKey(args: KmsClientResolveKeyArgs): Promise<ResolvedKeyInfo>
27
27
  kmsClientCreateRawSignature(args: KmsClientCreateRawSignatureArgs): Promise<CreateRawSignatureResponse>
@@ -40,86 +40,69 @@ export interface IKmsRestClient extends IPluginMethodMap {
40
40
  kmsClientProviderDeleteKey(args: KmsClientProviderDeleteKeyArgs): Promise<boolean>
41
41
  }
42
42
 
43
- export type KmsClientListResolversArgs = {
43
+ export type BaseArgs = {
44
44
  baseUrl?: string
45
+ tenantId?: string
46
+ userId?: string
45
47
  }
46
48
 
47
- export type kmsClientGetResolverArgs = {
48
- baseUrl?: string
49
+ export type OptionalProviderContextArgs = BaseArgs & {
50
+ providerId?: string
51
+ }
52
+
53
+ export type ProviderContextArgs = BaseArgs & {
54
+ providerId: string
55
+ }
56
+
57
+ export type KmsClientListResolversArgs = BaseArgs
58
+
59
+ export type KmsClientGetResolverArgs = BaseArgs & {
49
60
  resolverId: string
50
61
  }
51
62
 
52
- export type KmsClientResolveKeyArgs = {
53
- baseUrl?: string
63
+ export type KmsClientResolveKeyArgs = BaseArgs & {
54
64
  resolverId: String
55
65
  } & ResolvePublicKey
56
66
 
57
- export type KmsClientCreateRawSignatureArgs = {
58
- baseUrl?: string
59
- } & CreateRawSignature
67
+ export type KmsClientCreateRawSignatureArgs = BaseArgs & CreateRawSignature
60
68
 
61
- export type KmsClientIsValidRawSignatureArgs = {
62
- baseUrl?: string
63
- } & VerifyRawSignature
69
+ export type KmsClientIsValidRawSignatureArgs = BaseArgs & VerifyRawSignature
64
70
 
65
- export type KmsClientGetKeyArgs = {
66
- baseUrl?: string
67
- aliasOrKid: string
68
- }
71
+ export type KmsClientGetKeyArgs = BaseArgs &
72
+ OptionalProviderContextArgs & {
73
+ aliasOrKid: string
74
+ }
69
75
 
70
- export type KmsClientListKeysArgs = {
71
- baseUrl?: string
72
- providerId?: string
73
- }
76
+ export type KmsClientListKeysArgs = BaseArgs & OptionalProviderContextArgs
74
77
 
75
- export type KmsClientStoreKeyArgs = {
76
- baseUrl?: string
77
- } & StoreKey
78
+ export type KmsClientStoreKeyArgs = BaseArgs & StoreKey
78
79
 
79
- export type KmsClientGenerateKeyArgs = {
80
- baseUrl?: string
81
- } & GenerateKeyGlobal
80
+ export type KmsClientGenerateKeyArgs = BaseArgs & OptionalProviderContextArgs & GenerateKeyGlobal
82
81
 
83
- export type KmsClientDeleteKeyArgs = {
84
- baseUrl?: string
85
- aliasOrKid: string
86
- }
82
+ export type KmsClientDeleteKeyArgs = BaseArgs &
83
+ OptionalProviderContextArgs & {
84
+ aliasOrKid: string
85
+ }
87
86
 
88
- export type KmsClientGetKeyProviderArgs = {
89
- baseUrl?: string
90
- providerId: string
91
- }
87
+ export type KmsClientGetKeyProviderArgs = BaseArgs & ProviderContextArgs
92
88
 
93
- export type KmsClientListKeyProvidersArgs = {
94
- baseUrl?: string
95
- }
89
+ export type KmsClientListKeyProvidersArgs = BaseArgs
96
90
 
97
- export type KmsClientProviderListKeysArgs = {
98
- baseUrl?: string
99
- providerId: string
100
- }
91
+ export type KmsClientProviderListKeysArgs = BaseArgs & ProviderContextArgs
101
92
 
102
- export type KmsClientProviderStoreKeyArgs = {
103
- baseUrl?: string
104
- providerId: string
105
- } & StoreKey
93
+ export type KmsClientProviderStoreKeyArgs = BaseArgs & ProviderContextArgs & StoreKey
106
94
 
107
- export type KmsClientProviderGenerateKeyArgs = {
108
- baseUrl?: string
109
- providerId: string
110
- } & GenerateKey
95
+ export type KmsClientProviderGenerateKeyArgs = BaseArgs & ProviderContextArgs & GenerateKey
111
96
 
112
- export type KmsClientProviderGetKeyArgs = {
113
- baseUrl?: string
114
- providerId: string
115
- aliasOrKid: string
116
- }
97
+ export type KmsClientProviderGetKeyArgs = BaseArgs &
98
+ ProviderContextArgs & {
99
+ aliasOrKid: string
100
+ }
117
101
 
118
- export type KmsClientProviderDeleteKeyArgs = {
119
- baseUrl?: string
120
- providerId: string
121
- aliasOrKid: string
122
- }
102
+ export type KmsClientProviderDeleteKeyArgs = BaseArgs &
103
+ ProviderContextArgs & {
104
+ aliasOrKid: string
105
+ }
123
106
 
124
107
  export type RestClientAuthenticationOpts = {
125
108
  enabled?: boolean