digitalbazaar / did-method-key

A did-io driver for the DID "key" method
Other
25 stars 10 forks source link

A KeyAgreement key is required to generate a DID document, even though KeyAgreement is an optional field #64

Open wip-abramson opened 11 months ago

wip-abramson commented 11 months ago

I am attempting to use this library with https://github.com/digitalbazaar/ecdsa-secp256k1-verification-key-2019.

This requires a few tweaks like adding the fromFingerprint method. But after I get round that I run into an error when running:

const secpDidController = await didKeyDriverSecp.fromKeyPair({
    verificationKeyPair: secpKeyPair
});

The error is Error: Cannot derive key agreement key from verification key type "EcdsaSecp256k1VerificationKey2019". After digging into the code it appears that the error comes from here https://github.com/digitalbazaar/did-method-key/blob/9bc1839b1a954e967ca6480cd30005eb284bfada/lib/helpers.js#L86

My question is why is this an error, can't you just generate the DID document without a key agreement key?

I added a specific case for EcdsaSecp256k1VerificationKey2019 with just a break, similar to the Multikey case and the DID doc generated fine.

dlongley commented 11 months ago

I agree that it should be possible to generate a DID doc without a key agreement key. It's not clear what the default behavior ought to be or if it should be different per key type, but we can sort that out over time.

We're trying to make this driver more key agnostic with a plugin-based approach, so adding more special exceptions for certain key types isn't something we want. Ideally we'd just call into the key-specific plugin here and let it do whatever it's going to do. In other words, it's a goal to get any key-specific code out of the core driver code and into plugin space.