From 0784df09a38a10cd66a83485e047770b427d8648 Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 30 Oct 2024 12:25:17 +0000 Subject: [PATCH] feat(key-manager): allow user defined kid on keyManagerCreate (#1426) fixes #1353 --- packages/core-types/src/plugin.schema.ts | 4 ++++ packages/core-types/src/types/IKeyManager.ts | 5 +++++ packages/key-manager/src/key-manager.ts | 6 +++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/core-types/src/plugin.schema.ts b/packages/core-types/src/plugin.schema.ts index 4a4a16a7e..15cc2923c 100644 --- a/packages/core-types/src/plugin.schema.ts +++ b/packages/core-types/src/plugin.schema.ts @@ -540,6 +540,10 @@ export const schema = { "meta": { "$ref": "#/components/schemas/KeyMetadata", "description": "Optional. Key meta data" + }, + "kid": { + "type": "string", + "description": "Key ID" } }, "required": [ diff --git a/packages/core-types/src/types/IKeyManager.ts b/packages/core-types/src/types/IKeyManager.ts index 939c43c68..c46d4aa17 100644 --- a/packages/core-types/src/types/IKeyManager.ts +++ b/packages/core-types/src/types/IKeyManager.ts @@ -42,6 +42,11 @@ export interface IKeyManagerCreateArgs { * Optional. Key meta data */ meta?: KeyMetadata + + /** + * Optional. Key ID + */ + kid?: string; } /** diff --git a/packages/key-manager/src/key-manager.ts b/packages/key-manager/src/key-manager.ts index b66488ad5..521a625b4 100644 --- a/packages/key-manager/src/key-manager.ts +++ b/packages/key-manager/src/key-manager.ts @@ -87,7 +87,11 @@ export class KeyManager implements IAgentPlugin { async keyManagerCreate(args: IKeyManagerCreateArgs): Promise { const kms = this.getKms(args.kms) const partialKey = await kms.createKey({ type: args.type, meta: args.meta }) - const key: IKey = { ...partialKey, kms: args.kms } + const key: IKey = { + ...partialKey, + kms: args.kms, + kid: args.kid ?? partialKey.kid + } if (args.meta || key.meta) { key.meta = { ...args.meta, ...key.meta } }