Documentation ¶
Index ¶
- Constants
- Variables
- func AuthInSlice(auth DocAuthenicationWrapper, auths []DocAuthenicationWrapper) bool
- func CopyDID(d *didlib.DID) *didlib.DID
- func DocPublicKeyToEcdsaKeys(pks []DocPublicKey) []*ecdsa.PublicKey
- func KeyFromType(pk *DocPublicKey) (*string, error)
- func MethodIDOnly(did *didlib.DID) string
- func MethodIDOnlyFromString(did string) (string, error)
- func PublicKeyInSlice(pk DocPublicKey, pks []DocPublicKey) bool
- func ServiceInSlice(srv DocService, srvs []DocService) bool
- func ValidDid(did string) bool
- func ValidDocPublicKey(pk *DocPublicKey) bool
- type BigCacheResolverCache
- type DocAuthenicationWrapper
- type DocPublicKey
- type DocService
- type Document
- func (d *Document) AddAuthentication(auth *DocAuthenicationWrapper, addFragment bool) error
- func (d *Document) AddPublicKey(pk *DocPublicKey, addRefToAuth bool, addFragment bool) error
- func (d *Document) AddService(srv *DocService) error
- func (d *Document) GetPublicKeyFromFragment(fragment string) (*DocPublicKey, error)
- func (d *Document) MarshalJSON() ([]byte, error)
- func (d *Document) NextKeyFragment() string
- func (d Document) String() string
- func (d *Document) UnmarshalJSON(b []byte) error
- type HTTPUniversalResolver
- type Resolver
- type ResolverCache
- type Service
- type UniversalResolverMetadata
- type UniversalResolverResponse
Constants ¶
const (
// DefaultDIDContextV1 is the default context for DID documents
DefaultDIDContextV1 = "https://www.w3.org/2019/did/v1"
)
Variables ¶
var ( // ErrResolverDIDNotFound error indicating that DID not found by resolver ErrResolverDIDNotFound = errors.New("did doc not found") // ErrResolverCacheDIDNotFound error indicating that DID not found in cache ErrResolverCacheDIDNotFound = errors.New("did doc not found in cache") )
Functions ¶
func AuthInSlice ¶
func AuthInSlice(auth DocAuthenicationWrapper, auths []DocAuthenicationWrapper) bool
AuthInSlice checks to see if a DocAuthenticationWrapper is in a slice of DocAuthenticationWrapper XXX(PN): ugh, there should be an easier way to handle the key fields here.
func DocPublicKeyToEcdsaKeys ¶
func DocPublicKeyToEcdsaKeys(pks []DocPublicKey) []*ecdsa.PublicKey
DocPublicKeyToEcdsaKeys converts a slice of DocPublicKey to slice of corresponding ecdsa.PublicKey
func KeyFromType ¶
func KeyFromType(pk *DocPublicKey) (*string, error)
KeyFromType returns the correct key as a string given the public key type. For instance, get the PublicKeyHex field if the key type is LDSuiteTypeSecp256k1Verification
func MethodIDOnly ¶
MethodIDOnly returns did string without any fragments or paths from a DID object
func MethodIDOnlyFromString ¶
MethodIDOnlyFromString returns did string without any fragments or paths from a full DID string
func PublicKeyInSlice ¶
func PublicKeyInSlice(pk DocPublicKey, pks []DocPublicKey) bool
PublicKeyInSlice checks to see if a DocPublicKey is in a slice of DocPublicKeys XXX(PN): ugh, should be an easier way to handle the key fields here.
func ServiceInSlice ¶
func ServiceInSlice(srv DocService, srvs []DocService) bool
ServiceInSlice checks to see if a DocService is in a slice of DocService
func ValidDocPublicKey ¶
func ValidDocPublicKey(pk *DocPublicKey) bool
ValidDocPublicKey ensures that the given DocPublicKey is of a supported type, has a valid key for that type and is using the correct public key field. Returns true if it is valid, false if not.
Types ¶
type BigCacheResolverCache ¶
type BigCacheResolverCache struct {
// contains filtered or unexported fields
}
BigCacheResolverCache implements a ResolverCache using allegro/bigcache
func NewBigCacheResolverCache ¶
func NewBigCacheResolverCache(cache *bigcache.BigCache) *BigCacheResolverCache
NewBigCacheResolverCache is a convenience function to init and return a new BigCacheResolverCache
type DocAuthenicationWrapper ¶
type DocAuthenicationWrapper struct { DocPublicKey IDOnly bool `json:"-"` }
DocAuthenicationWrapper allows us to handle two different types for an authentication value. This can either be an ID to a public key or a public key.
func (*DocAuthenicationWrapper) MarshalJSON ¶
func (a *DocAuthenicationWrapper) MarshalJSON() ([]byte, error)
MarshalJSON implements the Marshaler interface for DocAuthenticationWrapper
func (*DocAuthenicationWrapper) SetIDFragment ¶
func (a *DocAuthenicationWrapper) SetIDFragment(fragment string) *DocAuthenicationWrapper
SetIDFragment sets the ID fragment of the authentication. For convenience, returns the DocAuthenticationWrapper for inline-ing.
func (*DocAuthenicationWrapper) UnmarshalJSON ¶
func (a *DocAuthenicationWrapper) UnmarshalJSON(b []byte) error
UnmarshalJSON implements the Unmarshaler interface for DocAuthenticationWrapper
type DocPublicKey ¶
type DocPublicKey struct { ID *didlib.DID `json:"id,omitempty"` Type linkeddata.SuiteType `json:"type,omitempty"` Owner *didlib.DID `json:"owner,omitempty"` Controller *didlib.DID `json:"controller,omitempty"` PublicKeyPem *string `json:"publicKeyPem,omitempty"` PublicKeyJwk *string `json:"publicKeyJwk,omitempty"` PublicKeyHex *string `json:"publicKeyHex,omitempty"` PublicKeyBase64 *string `json:"publicKeyBase64,omitempty"` PublicKeyBase58 *string `json:"publicKeyBase58,omitempty"` PublicKeyMultibase *string `json:"publicKeyMultibase,omitempty"` EthereumAddress *string `json:"ethereumAddress,omitempty"` // NOTE(PN): This field does not seem to be in DID spec, but is commonly // returned by universal resolver implementations, so we'll support it. // Used to alias a key to a list of other key ids. PublicKey []string `json:"publicKey,omitempty"` }
DocPublicKey defines a publickey within a DID document
func (*DocPublicKey) AsEcdsaPubKey ¶
func (p *DocPublicKey) AsEcdsaPubKey() (*ecdsa.PublicKey, error)
AsEcdsaPubKey returns this key as an ECDSA public key. Will return error if not ECDSA and Secp256k1 or Secp256r1 parameters
func (*DocPublicKey) MarshalJSON ¶
func (p *DocPublicKey) MarshalJSON() ([]byte, error)
MarshalJSON implements the Marshaler interface for DocPublicKey
func (*DocPublicKey) SetIDFragment ¶
func (p *DocPublicKey) SetIDFragment(fragment string) *DocPublicKey
SetIDFragment sets the ID fragment of the public key. For convenience, returns the DocPublicKey for inline-ing.
func (*DocPublicKey) UnmarshalJSON ¶
func (p *DocPublicKey) UnmarshalJSON(b []byte) error
UnmarshalJSON implements the Unmarshaler interface for DocPublicKey
type DocService ¶
type DocService struct { ID didlib.DID `json:"id"` Type string `json:"type"` Description string `json:"description,omitempty"` PublicKey string `json:"publicKey,omitempty"` // DocServiceEndpoint could be a JSON-LD object or a URI // https://github.com/piprate/json-gold // string or map[string]interface{} ServiceEndpoint interface{} `json:"serviceEndpoint"` // DocServiceEndpoint values stored here as the correct type // Use these to access the values for DocServiceEndpoint ServiceEndpointURI *string `json:"-"` ServiceEndpointLD map[string]interface{} `json:"-"` }
DocService defines a service endpoint within a DID document
func (*DocService) MarshalJSON ¶
func (s *DocService) MarshalJSON() ([]byte, error)
MarshalJSON implements the Marshaler interface for DocService
func (*DocService) PopulateServiceEndpointVals ¶
func (s *DocService) PopulateServiceEndpointVals() error
PopulateServiceEndpointVals populate the ServiceEndpointURI or ServiceEndpointLD based on the ServiceEndpoint interface{} value.
func (*DocService) UnmarshalJSON ¶
func (s *DocService) UnmarshalJSON(b []byte) error
UnmarshalJSON implements the Unmarshaler interface for DocService
type Document ¶
type Document struct { Context string `json:"@context"` ID didlib.DID `json:"id"` Controller *didlib.DID `json:"controller,omitempty"` PublicKeys []DocPublicKey `json:"publicKey"` Authentications []DocAuthenicationWrapper `json:"authentication,omitempty"` Services []DocService `json:"service,omitempty"` Created *time.Time `json:"created,omitempty"` Updated *time.Time `json:"updated,omitempty"` Proof *linkeddata.Proof `json:"proof,omitempty"` }
Document is the base definition of a DID document https://w3c-ccg.github.io/did-spec/#did-documents
func (*Document) AddAuthentication ¶
func (d *Document) AddAuthentication(auth *DocAuthenicationWrapper, addFragment bool) error
AddAuthentication adds another authentication value to the list. Could be just a reference to an existing key or a key only used for authentication
func (*Document) AddPublicKey ¶
func (d *Document) AddPublicKey(pk *DocPublicKey, addRefToAuth bool, addFragment bool) error
AddPublicKey adds another public key. If addRefToAuth is true, also adds a reference to the key in the authentication field.
func (*Document) AddService ¶
func (d *Document) AddService(srv *DocService) error
AddService adds another service value to the doc.
func (*Document) GetPublicKeyFromFragment ¶
func (d *Document) GetPublicKeyFromFragment(fragment string) (*DocPublicKey, error)
GetPublicKeyFromFragment returns the public key doc with the given fragment if it exists
func (*Document) MarshalJSON ¶
MarshalJSON implements the Marshaller interface for Document
func (*Document) NextKeyFragment ¶
NextKeyFragment looks at all the authentication and public keys and finds the next incremented key fragment to use when adding a publicKey or authentication. Only supports key fragments (#key-*) right now.
func (*Document) UnmarshalJSON ¶
UnmarshalJSON implements the Unmarshaller interface for Document
type HTTPUniversalResolver ¶
type HTTPUniversalResolver struct {
// contains filtered or unexported fields
}
HTTPUniversalResolver implements Resolver for making requests to the identityfoundation/universal-resolver service.
func NewHTTPUniversalResolver ¶
func NewHTTPUniversalResolver(resolverHost *string, resolverPort *int, cache ResolverCache) *HTTPUniversalResolver
NewHTTPUniversalResolver initializes and returns a new HTTPUniversalResolver
func (*HTTPUniversalResolver) RawResolve ¶
func (h *HTTPUniversalResolver) RawResolve(d *did.DID) (*UniversalResolverResponse, error)
RawResolve returns the full universal resolver resp given the DID
type Resolver ¶
type Resolver interface { // Resolve returns the DID document given the DID. Expects // ErrResolverDIDNotFound as error when DID is not found. Resolve(d *didlib.DID) (*Document, error) }
Resolver interface that defines a DID resolver
type ResolverCache ¶
type ResolverCache interface { Get(d *didlib.DID) (*Document, error) Set(d *didlib.DID, doc *Document) error }
ResolverCache interface defines a DID document cache for the resolver
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is the service module for DIDs. It is the direct interface for managing DIDs and DID documents and should be used when possible.
func NewService ¶
NewService is a convenience function to return a new populated did.Service object
func (*Service) GetDocument ¶
GetDocument retrieves the DID document given the DID as a string id If document is not found, will return a nil Document.
func (*Service) GetDocumentFromDID ¶
GetDocumentFromDID retrieves the DID document given the DID as a DID object If document is not found, will return a nil Document.
func (*Service) GetKeyFromDIDDocument ¶
func (s *Service) GetKeyFromDIDDocument(did *didlib.DID) (*DocPublicKey, error)
GetKeyFromDIDDocument returns a public key document from a did with a fragment if it can be found errors if fragment is empty
type UniversalResolverMetadata ¶
type UniversalResolverMetadata struct { Duration int `json:"duration"` Identifier string `json:"identifier"` DriverID string `json:"driverId"` DidURL struct { DidURLString string `json:"didUrlString"` Did struct { DidString string `json:"didString"` Method string `json:"method"` MethodSpecificID string `json:"methodSpecificId"` ParseTree string `json:"parseTree"` ParseRuleCount string `json:"parseRuleCount"` } `json:"did"` Parameters string `json:"parameters"` ParametersMap map[string]interface{} `json:"parametersMap"` Path string `json:"path"` Query string `json:"query"` Fragment string `json:"fragment"` ParseTree string `json:"parseTree"` ParseRuleCount string `json:"parseRuleCount"` } `json:"didUrl"` }
UniversalResolverMetadata is the metadata response for the universal resolver response
type UniversalResolverResponse ¶
type UniversalResolverResponse struct { DidDocument *Document `json:"didDocument"` Metadata *UniversalResolverMetadata `json:"resolverMetadata"` Content *string `json:"content"` ContentType *string `json:"contentType"` MethodMetadata *map[string]interface{} `json:"methodMetadata"` }
UniversalResolverResponse is the response from the universal resolver