digitalbazaar / did-method-key

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

methodFor helper function no longer accessing public / private key pair #63

Open wip-abramson opened 1 year ago

wip-abramson commented 1 year ago

Previously when I used this library the methodFor function would act as a

convenience function that returns the public/private key pair instance for a given purpose (authentication, assertionMethod, keyAgreement, etc). - See current code comment here

It no longer appears to do this.

Is there now a different way to use this library to get the requisite private keys (with id and controller) required for the vc.js library?

dmitrizagidulin commented 1 year ago

@wip-abramson Can you say more about "it no longer appears to do this"? Looking at the current code, it's still returning the keypair (this line here https://github.com/digitalbazaar/did-method-key/blob/main/lib/DidKeyDriver.js#L70C7-L70C36 )

What behavior are you encountering? (Give us reproduce steps.)

wip-abramson commented 1 year ago

Apologies. I did misread the code, although i still am not getting expected results.

Here is my code

const didKeyDriver2018 = driver();

didKeyDriver2018.use({
  multibaseMultikeyHeader: 'z6Mk',
  fromMultibase: createFromMultibase(Ed25519VerificationKey2018)
});

const edKeyPair = await Ed25519VerificationKey2018.generate();
const {didDocument, keyPairs, methodFor} = await didKeyDriver2018.fromKeyPair({
  verificationKeyPair: edKeyPair
});

let methodKeyPair = methodFor({purpose: 'authentication', privateKey:true});
console.log("method privkey", methodKeyPair.privateKeyBase58); // is null
console.log("keypair privkey", edKeyPair.privateKeyBase58); // is a private key

Probably I am just doing something wrong.

dmitrizagidulin commented 1 year ago

@wip-abramson Thanks. Yeah, this seems to be a bug in the newer code. The _keyPairToDidDocument method here only converts the public key, but not the private key.

/cc @davidlehn