transmute-industries / did-key.js

A DID Key Implementation in TypeScript
https://did.key.transmute.industries/
Apache License 2.0
53 stars 15 forks source link

Typescript issue for bbs key together with BBS Signature JsonLD #129

Open vongohren opened 3 years ago

vongohren commented 3 years ago

So, I like that all the good crypto is collected in this library, but starting to use external libraries quickly breaks the typescriptness of things

If you use: https://github.com/mattrglobal/jsonld-signatures-bbs/blob/master/src/BbsBlsSignature2020.ts And want to send in a key, it is not possible to send in this repos keyType, because it complains on certain methods variables that this class signature dont have. Here, the instance check is this bls key pair, but if I send that into the Signature function, I will get errors. I had to reconstruct it doing the things below to get it to work together.

    if(key instanceof Bls12381G2KeyPair) {
      const jwk = key.toJsonWebKeyPair(true);
      const keyPair = key.toKeyPair(true);
      const recontstructedKey = {
        ...key,
        publicKey: keyPair.publicKeyBase58,
        publicKeyJwk: jwk.publicKeyJwk,
        privateKey: keyPair.privateKeyBase58,
        privateKeyJwk: jwk.privateKeyJwk,
        signer: key.signer,
        verifier: key.verifier,
        fingerprint: key.fingerprint,
        addEncodedPublicKey: ()=>{},
        verifyFingerprint: () => {}
      }
      return new BbsBlsSignature2020({ key: recontstructedKey })

What would be best approach to get this to be a bit more seamless? So that this key is accepted as a type for the key from BbsBlsSignature package?

@OR13 @tplooker @kdenhartog

vongohren commented 3 years ago

I did reuse the mattr key lib to reconstruct from a key.toKeyPair(true); So not need to look at that earlier reconstruction. But what would be best practise for this?

OR13 commented 3 years ago

Ideally, we would all agree to a concrete interface for LDKeyPair, which defined required members and methods...

something like:

https://github.com/transmute-industries/verifiable-data/blob/main/packages/ld-key-pair/src/types/KeyPair.ts

We are basically trying to do this here:

We're getting ready to refactor or did-key.js library to use these key pair classes, see this issue:

vongohren commented 3 years ago

@OR13 great to hear that you are on the case! Anything I can support with?