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

[proposal] Add temp memory key generation function #1021

Open
nklomp opened this issue Oct 4, 2022 · 1 comment
Open

[proposal] Add temp memory key generation function #1021

nklomp opened this issue Oct 4, 2022 · 1 comment
Labels
enhancement New feature or request pinned don't close this just for being stale

Comments

@nklomp
Copy link
Member

nklomp commented Oct 4, 2022

Is your feature request related to a problem? Please describe.
For the DID ION keys in pr #987 I needed to pre-create keys for rotation and recovery. I also needed to be able to assign specific key ids (kid). As I didn't want to duplicate all the logic to retrieve the public keys from different key types, I ended up basically using an in memory KMS for temporary keys (see below). It might be helpful to others to have this exposed as a function

Describe the solution you'd like
expose a function that allows IKey generation completely in memory

Additional context
Right now the DID Ion Provider is dependant on kms-local. If Veramo would provide this function that coupling could be removed.

The below line is the import one.

  const tmpKey = (await new KeyManagementSystem(new MemoryPrivateKeyStore()).importKey({
    type,
    privateKeyHex,
    kid,
  })) as IKey

The full reference how I used it in the ION provider

/**
 * Create a Veramo Key entirely in Memory. It is not stored
 *
 * Didn't want to recreate the logic to extract the pub key for the different key types
 * So let's create a temp in-mem kms to do it for us
 *
 * @param type
 * @param privateKeyHex
 * @param kid
 * @param kms
 * @param ionMeta
 */
export const tempMemoryKey = async (
  type: KeyType.Ed25519 | KeyType.Secp256k1 | KeyType,
  privateKeyHex: string,
  kid: string,
  kms: string,
  ionMeta: IonKeyMetadata
): Promise<IKey> => {
  const tmpKey = (await new KeyManagementSystem(new MemoryPrivateKeyStore()).importKey({
    type,
    privateKeyHex,
    kid,
  })) as IKey
  tmpKey.meta!.ion = JSON.parse(JSON.stringify(ionMeta))
  tmpKey.meta!.ion.commitment = computeCommitmentFromJwk(toIonPublicKeyJwk(tmpKey.publicKeyHex))
  tmpKey.kms = kms
  // tmpKey.privateKeyHex = privateKeyHex
  return tmpKey
}
@nklomp nklomp added the enhancement New feature or request label Oct 4, 2022
@stale
Copy link

stale bot commented Jun 18, 2023

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 Jun 18, 2023
@mirceanis mirceanis added the pinned don't close this just for being stale label Aug 30, 2023
@stale stale bot removed the wontfix This will not be worked on label Aug 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request pinned don't close this just for being stale
Projects
None yet
Development

No branches or pull requests

2 participants