TBD54566975 / web5-go

Apache License 2.0
10 stars 6 forks source link

Consider adding did.GetPublicKeyJWK(didURL) method #74

Open KendallWeihe opened 7 months ago

KendallWeihe commented 7 months ago

Originally thought of here https://github.com/TBD54566975/web5-go/pull/60/files/#r1502586768

I'm out of my depth here with the specifics of DID Document concepts, so stubbing this in and can go deeper later if warranted.

The basic idea being, it may be common place for a developer to obtain a fully-qualified DID key-id, for example in a JWT header's kid property, we may have did:dht:{things}#{key-id}, and want the obtain the full Public Key JWK from the given DID Document. In other words, "I have the key ID, but I need the full public key."

For example, in our jws.Verify() method we currently do this:

    did, err := _did.Parse(jws.Header.KID)
    if err != nil {
        return errors.New("malformed JWS header. kid must be a DID URL")
    }

    resolutionResult, err := dids.Resolve(did.URI)
    if err != nil {
        return fmt.Errorf("failed to resolve DID: %w", err)
    }

    vmSelector := didcore.ID(did.URL)
    verificationMethod, err := resolutionResult.Document.SelectVerificationMethod(vmSelector)
    if err != nil {
        return fmt.Errorf("kid does not match any verification method %w", err)
    }

But this may be common-place outside of JWS. So, we could introduce a new function in the did package, something like this:

func GetPublicKeyJWK(didURL string) (JWK, error) { ... }

(Not sure didURL would be the proper name)