decentralized-identity / decentralized-identity/veramo
[proposal] Add temp memory key generation function
- Dominant language
- TypeScript
- Stars
- 543
- Forks
- 137
- Avg merge
- 12m
- Merged PRs (30d)
- 2
Description
**Is your feature request related to a problem? Please describe.**
For the DID ION keys in pr https://github.com/uport-project/veramo/pull/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.
````typescript
const tmpKey = (await new KeyManagementSystem(new MemoryPrivateKeyStore()).importKey({
type,
privateKeyHex,
kid,
})) as IKey
````
The full reference how I used it in the ION provider
````typescript
/**
* 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 => {
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
}
````
Contributor guide
Assessment
This issue has not been assessed yet.