@sphereon/ssi-sdk.kms-rest-client 0.36.1-feature.SSISDK.82.and.SSISDK.70.35 → 0.36.1-next.11

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