did

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2020 License: Apache-2.0 Imports: 16 Imported by: 139

Documentation

Index

Constants

View Source
const (
	// Context of the DID document.
	Context = "https://w3id.org/did/v1"
)

Variables

View Source
var ErrKeyNotFound = errors.New("key not found")

ErrKeyNotFound is returned when key is not found.

View Source
var ErrProofNotFound = errors.New("proof not found")

ErrProofNotFound is returned when proof is not found.

Functions

func CachingJSONLDLoader added in v0.1.4

func CachingJSONLDLoader() ld.DocumentLoader

CachingJSONLDLoader creates JSON-LD CachingDocumentLoader with preloaded base JSON-LD DID and security contexts.

func LookupRecipientKeys added in v0.1.1

func LookupRecipientKeys(didDoc *Doc, serviceType, keyType string) ([]string, bool)

LookupRecipientKeys gets the recipient keys from the did doc which match the given parameters.

Types

type DID added in v0.1.3

type DID struct {
	Scheme           string // Scheme is always "did"
	Method           string // Method is the specific DID methods
	MethodSpecificID string // MethodSpecificID is the unique ID computed or assigned by the DID method
}

DID is parsed according to the generic syntax: https://w3c.github.io/did-core/#generic-did-syntax

func Parse added in v0.1.3

func Parse(did string) (*DID, error)

Parse parses the string according to the generic DID syntax. See https://w3c.github.io/did-core/#generic-did-syntax.

func (*DID) String added in v0.1.3

func (d *DID) String() string

String returns a string representation of this DID.

type Doc

type Doc struct {
	Context              []string
	ID                   string
	PublicKey            []PublicKey
	Service              []Service
	Authentication       []VerificationMethod
	AssertionMethod      []VerificationMethod
	CapabilityDelegation []VerificationMethod
	CapabilityInvocation []VerificationMethod
	KeyAgreement         []VerificationMethod
	Created              *time.Time
	Updated              *time.Time
	Proof                []Proof
}

Doc DID Document definition.

func BuildDoc

func BuildDoc(opts ...DocOption) *Doc

BuildDoc creates the DID Doc from options.

func ParseDocument

func ParseDocument(data []byte) (*Doc, error)

ParseDocument creates an instance of DIDDocument by reading a JSON document from bytes.

func (*Doc) JSONBytes

func (doc *Doc) JSONBytes() ([]byte, error)

JSONBytes converts document to json bytes.

func (*Doc) VerificationMethods added in v0.1.3

func (doc *Doc) VerificationMethods(customVerificationRelationships ...VerificationRelationship) map[VerificationRelationship][]VerificationMethod

VerificationMethods returns verification methods of DID Doc of certain relationship. If customVerificationRelationships is empty, all verification methods are returned. Public keys which are not referred by any verification method are put into special VerificationRelationshipGeneral relationship category. nolint:gocyclo

func (*Doc) VerifyProof

func (doc *Doc) VerifyProof(suites []verifier.SignatureSuite, jsonldOpts ...jsonld.ProcessorOpts) error

VerifyProof verifies document proofs.

type DocOption

type DocOption func(opts *Doc)

DocOption provides options to build DID Doc.

func WithAuthentication

func WithAuthentication(auth []VerificationMethod) DocOption

WithAuthentication DID doc Authentication.

func WithCreatedTime

func WithCreatedTime(t time.Time) DocOption

WithCreatedTime DID doc created time.

func WithPublicKey

func WithPublicKey(pubKey []PublicKey) DocOption

WithPublicKey DID doc PublicKey.

func WithService

func WithService(svc []Service) DocOption

WithService DID doc services.

func WithUpdatedTime

func WithUpdatedTime(t time.Time) DocOption

WithUpdatedTime DID doc updated time.

type Proof

type Proof struct {
	Type         string
	Created      *time.Time
	Creator      string
	ProofValue   []byte
	Domain       string
	Nonce        []byte
	ProofPurpose string
}

Proof is cryptographic proof of the integrity of the DID Document.

type PublicKey

type PublicKey struct {
	ID         string
	Type       string
	Controller string

	Value []byte
	// contains filtered or unexported fields
}

PublicKey DID doc public key. The value of the public key is defined either as raw public key bytes (Value field) or as JSON Web Key. In the first case the Type field can hold additional information to understand the nature of the raw public key.

func LookupPublicKey added in v0.1.1

func LookupPublicKey(id string, didDoc *Doc) (*PublicKey, bool)

LookupPublicKey returns the public key with the given id from the given DID Doc.

func NewPublicKeyFromBytes added in v0.1.3

func NewPublicKeyFromBytes(id, kType, controller string, value []byte) *PublicKey

NewPublicKeyFromBytes creates a new PublicKey based on raw public key bytes.

func NewPublicKeyFromJWK added in v0.1.3

func NewPublicKeyFromJWK(id, kType, controller string, jwk *jose.JWK) (*PublicKey, error)

NewPublicKeyFromJWK creates a new PublicKey based on JSON Web Key.

func (*PublicKey) JSONWebKey added in v0.1.3

func (pk *PublicKey) JSONWebKey() *jose.JWK

JSONWebKey returns JSON Web key if defined.

type Service

type Service struct {
	ID              string
	Type            string
	Priority        uint
	RecipientKeys   []string
	RoutingKeys     []string
	ServiceEndpoint string
	Properties      map[string]interface{}
}

Service DID doc service.

func LookupService added in v0.1.1

func LookupService(didDoc *Doc, serviceType string) (*Service, bool)

LookupService returns the service from the given DIDDoc matching the given service type.

type VerificationMethod

type VerificationMethod struct {
	PublicKey    PublicKey
	Relationship VerificationRelationship
	Embedded     bool
	RelativeURL  bool
}

VerificationMethod authentication verification method.

func NewEmbeddedVerificationMethod added in v0.1.4

func NewEmbeddedVerificationMethod(pk *PublicKey, r VerificationRelationship) *VerificationMethod

NewEmbeddedVerificationMethod creates a new verification method with embedded public key.

func NewReferencedVerificationMethod added in v0.1.4

func NewReferencedVerificationMethod(pk *PublicKey, r VerificationRelationship, isRelativeURL bool) *VerificationMethod

NewReferencedVerificationMethod creates a new verification method with referenced public key.

type VerificationRelationship added in v0.1.3

type VerificationRelationship int

VerificationRelationship defines a verification relationship between DID subject and a verification method.

const (
	// VerificationRelationshipGeneral is a special case of verification relationship: when a public key
	// defined in PublicKey is not used by any VerificationMethod.
	VerificationRelationshipGeneral VerificationRelationship = iota

	// Authentication defines verification relationship.
	Authentication

	// AssertionMethod defines verification relationship.
	AssertionMethod

	// CapabilityDelegation defines verification relationship.
	CapabilityDelegation

	// CapabilityInvocation defines verification relationship.
	CapabilityInvocation

	// KeyAgreement defines verification relationship.
	KeyAgreement
)

Jump to

Keyboard shortcuts

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