did

package
v0.0.0-...-cda998f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 29, 2020 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultDIDContextV1 is the default context for DID documents
	DefaultDIDContextV1 = "https://www.w3.org/2019/did/v1"
)

Variables

View Source
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")
)
View Source
var (
	// DefaultBigCacheConfig is a default cache config to use
	DefaultBigCacheConfig = bigcache.Config{
		Shards: 1024,

		LifeWindow:         5 * time.Minute,
		CleanWindow:        5 * time.Minute,
		MaxEntriesInWindow: 1000 * 10 * 60,
		MaxEntrySize:       500,
		Verbose:            true,
		HardMaxCacheSize:   16384,
	}
)

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 CopyDID

func CopyDID(d *didlib.DID) *didlib.DID

CopyDID is a convenience function to make a copy a DID struct

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

func MethodIDOnly(did *didlib.DID) string

MethodIDOnly returns did string without any fragments or paths from a DID object

func MethodIDOnlyFromString

func MethodIDOnlyFromString(did string) (string, error)

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 ValidDid

func ValidDid(did string) bool

ValidDid returns true if the given did string is of a valid DID format

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

func (*BigCacheResolverCache) Get

Get retrieves the did document out of the cache

func (*BigCacheResolverCache) Set

func (c *BigCacheResolverCache) Set(d *didlib.DID, doc *Document) error

Set sets the did document in the cache given the did

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

func (d *Document) MarshalJSON() ([]byte, error)

MarshalJSON implements the Marshaller interface for Document

func (*Document) NextKeyFragment

func (d *Document) NextKeyFragment() string

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) String

func (d Document) String() string

func (*Document) UnmarshalJSON

func (d *Document) UnmarshalJSON(b []byte) error

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

RawResolve returns the full universal resolver resp given the DID

func (*HTTPUniversalResolver) Resolve

func (h *HTTPUniversalResolver) Resolve(d *did.DID) (*Document, error)

Resolve returns the DID document given the DID Implements the Resolver interface.

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

func NewService(resolvers []Resolver) *Service

NewService is a convenience function to return a new populated did.Service object

func (*Service) GetDocument

func (s *Service) GetDocument(did string) (*Document, error)

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

func (s *Service) GetDocumentFromDID(did *didlib.DID) (*Document, error)

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL