From 1b20573d3e2cb6e4ed4ebd517b673ece7cdd459f Mon Sep 17 00:00:00 2001 From: b5 Date: Fri, 4 Dec 2020 11:17:57 -0500 Subject: [PATCH] docs: ensure all exported symbols are documented makes golint happy. --- attenuation.go | 4 ++-- token.go | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/attenuation.go b/attenuation.go index 545ab81..43a8d0a 100644 --- a/attenuation.go +++ b/attenuation.go @@ -36,10 +36,10 @@ LOOP: return true } -// AttenuationConstructor is a function that creates an attenuation from a map +// AttenuationConstructorFunc is a function that creates an attenuation from a map // Users of this package provide an Attenuation Constructor to the parser to // bind attenuation logic to a UCAN -type AttenuationConstructor func(v map[string]interface{}) (Attenuation, error) +type AttenuationConstructorFunc func(v map[string]interface{}) (Attenuation, error) // Attenuation is a capability on a resource type Attenuation struct { diff --git a/token.go b/token.go index 49997d3..e639bb5 100644 --- a/token.go +++ b/token.go @@ -128,7 +128,7 @@ type pkSource struct { verifyKey *rsa.PublicKey signKey *rsa.PrivateKey - ap AttenuationConstructor + ap AttenuationConstructorFunc resolver CIDBytesResolver store TokenStore } @@ -250,10 +250,13 @@ func (a *pkSource) newToken(subjectDID string, prf []Proof, att Attenuations, fc }, nil } +// DIDPubKeyResolver turns did:key Decentralized IDentifiers into a public key, +// possibly using a network request type DIDPubKeyResolver interface { ResolveDIDKey(ctx context.Context, did string) (crypto.PubKey, error) } +// DIDStringFromPublicKey creates a did:key identifier string from a public key func DIDStringFromPublicKey(pub crypto.PubKey) (string, error) { rawPubBytes, err := pub.Raw() if err != nil { @@ -262,8 +265,12 @@ func DIDStringFromPublicKey(pub crypto.PubKey) (string, error) { return fmt.Sprintf("did:key:%s", base64.URLEncoding.EncodeToString(rawPubBytes)), nil } +// StringDIDPubKeyResolver implements the DIDPubKeyResolver interface without +// any network backing. Works if the key string given contains the public key +// itself type StringDIDPubKeyResolver struct{} +// ResolveDIDKey extracts a public key from a did:key string func (StringDIDPubKeyResolver) ResolveDIDKey(ctx context.Context, didStr string) (crypto.PubKey, error) { // id, err := did.Parse(didStr) // if err != nil { @@ -278,13 +285,15 @@ func (StringDIDPubKeyResolver) ResolveDIDKey(ctx context.Context, didStr string) return crypto.UnmarshalRsaPublicKey(data) } +// TokenParser parses a raw string into a Token type TokenParser struct { - ap AttenuationConstructor + ap AttenuationConstructorFunc cidr CIDBytesResolver didr DIDPubKeyResolver } -func NewTokenParser(ap AttenuationConstructor, didr DIDPubKeyResolver, cidr CIDBytesResolver) *TokenParser { +// NewTokenParser constructs a token parser +func NewTokenParser(ap AttenuationConstructorFunc, didr DIDPubKeyResolver, cidr CIDBytesResolver) *TokenParser { return &TokenParser{ ap: ap, cidr: cidr,