Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for User Defined kid on KeyManagerCreate #1353

Open
radleylewis opened this issue Feb 29, 2024 · 3 comments
Open

Allow for User Defined kid on KeyManagerCreate #1353

radleylewis opened this issue Feb 29, 2024 · 3 comments
Labels
enhancement New feature or request key-manager pinned don't close this just for being stale triage

Comments

@radleylewis
Copy link
Contributor

radleylewis commented Feb 29, 2024

Problem

Presently, the keyManagerCreate method automatically generates a kid. However, there are plausible use-cases whereby the user may wish to define this manually.

Solution
The solution to this current limitation requires only basic changes to the code, which would not be breaking (noting that the provision of a manual kid would be optional and would be provided in the keyManagerCreateArgs (see below diff):

diff --git a/packages/key-manager/src/key-manager.ts b/packages/key-manager/src/key-manager.ts
index 21088ff3..1ba68ba6 100644
--- a/packages/key-manager/src/key-manager.ts
+++ b/packages/key-manager/src/key-manager.ts
@@ -22,7 +22,7 @@ import * as u8a from 'uint8arrays'
 import { createAnonDecrypter, createAnonEncrypter, createJWE, decryptJWE, type ECDH, type JWE } from 'did-jwt'
 import { convertEd25519PublicKeyToX25519 } from '@veramo/utils'
 import Debug from 'debug'
-import {getBytes, hexlify, toUtf8Bytes, toUtf8String, computeAddress, Transaction} from "ethers";
+import { getBytes, hexlify, toUtf8Bytes, toUtf8String, computeAddress, Transaction } from 'ethers'
 
 const debug = Debug('veramo:key-manager')
 
@@ -87,7 +87,8 @@ export class KeyManager implements IAgentPlugin {
   async keyManagerCreate(args: IKeyManagerCreateArgs): Promise<ManagedKeyInfo> {
     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 }
     }
diff --git a/packages/core-types/src/types/IKeyManager.ts b/packages/core-types/src/types/IKeyManager.ts
index 939c43c6..edb88f82 100644
--- a/packages/core-types/src/types/IKeyManager.ts
+++ b/packages/core-types/src/types/IKeyManager.ts
@@ -28,6 +28,11 @@ export type ManagedKeyInfo = Omit<IKey, 'privateKeyHex'>
  * @public
  */
 export interface IKeyManagerCreateArgs {
+  /**
+   * Kid
+   */
+  kid?: string
+
   /**
    * Key type
    *
    
@radleylewis radleylewis added the enhancement New feature or request label Feb 29, 2024
@pauldesmondparker
Copy link

pauldesmondparker commented Feb 29, 2024

@radleylewis Where's the diff for the IKeyManagerCreateArgs definition?
Probably need a change to packages/core-types/src/plugin.schema.json:512 as well.
EDIT: Put it all in one place:

diff --git a/packages/core-types/src/plugin.schema.ts b/packages/core-types/src/plugin.schema.ts
index 738bf62a..0ebabe75 100644
--- a/packages/core-types/src/plugin.schema.ts
+++ b/packages/core-types/src/plugin.schema.ts
@@ -537,6 +537,10 @@ export const schema = {
               "type": "string",
               "description": "Key Management System"
             },
+            "kid": {
+              "type": "string",
+              "description": "Key ID"
+            },
             "meta": {
               "$ref": "#/components/schemas/KeyMetadata",
               "description": "Optional. Key meta data"
diff --git a/packages/core-types/src/types/IKeyManager.ts b/packages/core-types/src/types/IKeyManager.ts
index 939c43c6..f0e820c8 100644
--- a/packages/core-types/src/types/IKeyManager.ts
+++ b/packages/core-types/src/types/IKeyManager.ts
@@ -38,6 +38,11 @@ export interface IKeyManagerCreateArgs {
    */
   kms: string
 
+  /**
+   * Key ID
+   */
+  kid?: string
+
   /**
    * Optional. Key meta data
    */
diff --git a/packages/key-manager/src/key-manager.ts b/packages/key-manager/src/key-manager.ts
index 21088ff3..1ba68ba6 100644
--- a/packages/key-manager/src/key-manager.ts
+++ b/packages/key-manager/src/key-manager.ts
@@ -22,7 +22,7 @@ import * as u8a from 'uint8arrays'
 import { createAnonDecrypter, createAnonEncrypter, createJWE, decryptJWE, type ECDH, type JWE } from 'did-jwt'
 import { convertEd25519PublicKeyToX25519 } from '@veramo/utils'
 import Debug from 'debug'
-import {getBytes, hexlify, toUtf8Bytes, toUtf8String, computeAddress, Transaction} from "ethers";
+import { getBytes, hexlify, toUtf8Bytes, toUtf8String, computeAddress, Transaction } from 'ethers'
 
 const debug = Debug('veramo:key-manager')
 
@@ -87,7 +87,8 @@ export class KeyManager implements IAgentPlugin {
   async keyManagerCreate(args: IKeyManagerCreateArgs): Promise<ManagedKeyInfo> {
     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 }
     }    

Copy link

stale bot commented May 9, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix This will not be worked on label May 9, 2024
@stale stale bot closed this as completed May 17, 2024
@mirceanis mirceanis added triage and removed wontfix This will not be worked on labels May 30, 2024
@mirceanis mirceanis reopened this May 30, 2024
Copy link

stale bot commented Aug 4, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix This will not be worked on label Aug 4, 2024
@stale stale bot closed this as completed Aug 14, 2024
@mirceanis mirceanis reopened this Aug 14, 2024
@stale stale bot removed the wontfix This will not be worked on label Aug 14, 2024
@mirceanis mirceanis added the pinned don't close this just for being stale label Aug 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request key-manager pinned don't close this just for being stale triage
Projects
None yet
Development

No branches or pull requests

4 participants