doc

package
v0.7.6 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2024 License: GPL-3.0 Imports: 26 Imported by: 8

Documentation

Index

Constants

View Source
const (
	VerificationMethodDefaultTTL = time.Duration(7) * time.Hour * 24
)

Variables

View Source
var (
	ErrPayloadMarshal     = errors.New("error marshalling payload to CBOR")
	ErrPayloadMultiencode = errors.New("error multiencoding hashed payload")
	ErrPayloadSign        = errors.New("error signing payload")

	ErrVerificationMethodFetchFailed       = errors.New("error fetching verification method")
	ErrVerificationMethodMissingType       = errors.New("verification method missing type")
	ErrVerificationMethoddUnkownID         = errors.New("verification method ID unknown")
	ErrVerificationMethodInvalidController = errors.New("verification method invalid controller")

	ErrPublicKeyMultibaseInvalid  = errors.New("failed to decode public key multibase")
	ErrPublicKeyMultibaseEmpty    = errors.New("public key multibase is empty")
	ErrPublicKeyMultibaseMismatch = errors.New("public key multibase mismatch")
	ErrMultiCodecInvalid          = fmt.Errorf("codec must be %s", key.KEY_AGREEMENT_MULTICODEC.String())

	ErrPublicKeyLengthInvalid = fmt.Errorf("public keysize must be %d", ed25519.PublicKeySize)

	ErrDoumentAlreadyPublished = errors.New("document already published")

	ErrControllersIsEmpty = errors.New("controller missing")

	ErrDocumentIsNil            = errors.New("document is nil")
	ErrDocumentInvalid          = errors.New("invalid document")
	ErrDocumentSignatureInvalid = errors.New("invalid document signature")
)
View Source
var DID_CONTEXT = []string{
	"https://w3id.org/did/v1",
}
View Source
var ErrAlreadyPublished = errors.New("Document is already published")
View Source
var (
	ErrInvalidPayload = fmt.Errorf("invalid document payload")
)

Functions

This section is empty.

Types

type Document

type Document struct {
	Context            []string             `cbor:"@context,toarray" json:"@context"`
	ID                 string               `cbor:"id" json:"id"`
	Controller         []string             `cbor:"controller,toarray" json:"controller"`
	VerificationMethod []VerificationMethod `cbor:"verificationMethod,toarray" json:"verificationMethod"`
	AssertionMethod    string               `cbor:"assertionMethod" json:"assertionMethod"`
	KeyAgreement       string               `cbor:"keyAgreement" json:"keyAgreement"`
	Proof              Proof                `cbor:"proof" json:"proof"`
}

func Fetch

func Fetch(didStr string, cached bool) (*Document, cid.Cid, error)

Takes a DID and fetches the document from IPFS. Eg. Fetch("did:ma:k51qzi5uqu5dj9807pbuod1pplf0vxh8m4lfy3ewl9qbm2s8dsf9ugdf9gedhr#bahner") The cached flag determines whether the document should be fetched from IPNS cache or not.

func FetchFromDID added in v0.0.3

func FetchFromDID(d did.DID, cached bool) (*Document, cid.Cid, error)

Fetched the document from IPFS using the DID object. The cached flag determines whether the document should be fetched from IPNS cache or not.

func GetOrCreate added in v0.1.0

func GetOrCreate(identifier string, controller string) (*Document, cid.Cid, error)

GetOrCreate document from cache or create a new one identifier is a did string, eg. "did:ma:k51qzi5uqu5dj9807pbuod1pplf0vxh8m4lfy3ewl9qbm2s8dsf9ugdf9gedhr#foo"

func New

func New(identifier string, controller string) (*Document, error)

func NewFromKeyset

func NewFromKeyset(k set.Keyset) (*Document, error)

Takes a keyset and generates a DID Document. Also takes a controller string which is the DID of the controller of the keyset. This is used to set the controller of the DID Document. It's OK to set it as the DID of the keyset.IPNSKey.DID, but it's not required.

func NewFromKeysetWithController added in v0.0.6

func NewFromKeysetWithController(k set.Keyset, controller string) (*Document, error)

func Payload

func Payload(d Document) (Document, error)

Payload generates the unsigned DID, This is everything non-metadata in the DID document. We don't use a pointer here, so that we don't have to reiterate the struct in the function. We just need to change the signature.

func (*Document) AddController added in v0.1.0

func (d *Document) AddController(controller string) error

func (*Document) AddVerificationMethod

func (d *Document) AddVerificationMethod(method VerificationMethod) error

func (*Document) AssertionMethodPublicKey

func (d *Document) AssertionMethodPublicKey() (ed25519.PublicKey, error)

func (*Document) CID added in v0.7.5

func (d *Document) CID() (cid.Cid, error)

func (*Document) DeleteController added in v0.1.0

func (d *Document) DeleteController(controller string)

func (*Document) DeleteVerificationMethod added in v0.1.0

func (d *Document) DeleteVerificationMethod(method VerificationMethod) error

func (*Document) Equal added in v0.2.0

func (d *Document) Equal(other *Document) bool

func (*Document) GetAssertionMethod

func (d *Document) GetAssertionMethod() (VerificationMethod, error)

func (*Document) GetKeyAgreementMethod

func (d *Document) GetKeyAgreementMethod() (VerificationMethod, error)

func (*Document) GetVerificationMethodByID added in v0.6.0

func (d *Document) GetVerificationMethodByID(vmid string) (VerificationMethod, error)

func (*Document) KeyAgreementPublicKeyBytes

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

func (*Document) MarshalPayloadToCBOR

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

Marshals the payload to CBOR for publication

func (*Document) MarshalToCBOR added in v0.1.0

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

func (*Document) Node added in v0.0.6

func (d *Document) Node() (*cbor.Node, error)

IPFSDagAddCBOR takes a CBOR encoded byte array and adds it to IPFS.

func (*Document) PayloadHash

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

func (*Document) Publish

func (d *Document) Publish(o ...*PublishOptions) (ipns.Name, error)

Publish publishes the document to IPFS and returns the CID If the opts is nil, the default options are used. NB! Publication is more than simply adding the document to IPFS. It's about publishing the document to IPNS and possibly pinning it.

func (*Document) PublishGoroutine added in v0.2.0

func (d *Document) PublishGoroutine(wg *sync.WaitGroup, cancel context.CancelFunc, opts *PublishOptions)

The Goroutine version of Publish must get a cancel function as argument. This is to force the caller to use a context with a cancel function. Obviously this should probably be a timeout context. Other than that it is the same as Publish.

func (*Document) Sign

func (d *Document) Sign(signKey key.SigningKey, vm VerificationMethod) error

func (*Document) String

func (d *Document) String() string

Simple string representation of the document JSON or empty string on error

func (*Document) Verify

func (d *Document) Verify() error

type Proof

type Proof struct {
	Type               string `cbor:"type" json:"type"`
	VerificationMethod string `cbor:"verificationMethod" json:"verificationMethod"`
	ProofPurpose       string `cbor:"proofPurpose" json:"proofPurpose"`
	ProofValue         string `cbor:"proofValue" json:"proofValue"`
}

func NewProof

func NewProof(proofValue string, vm string) Proof

type PublishOptions added in v0.2.0

type PublishOptions struct {
	Ctx           context.Context
	Pin           bool
	Force         bool
	AllowBigBlock bool
}

func DefaultPublishOptions added in v0.2.0

func DefaultPublishOptions() *PublishOptions

type VerificationMethod

type VerificationMethod struct {
	// The full name of the verification method, eg. did:ma:123456789abcdefghi#signature-key-id
	ID string `cbor:"id" json:"id"`
	// The type of verification method. We only use MultiKey. It's unofficial, but it works.
	// https://w3c-ccg.github.io/did-method-key/
	Type string `cbor:"type" json:"type"`
	// The controller of the verification method. This is the DID of the entity that controls the key.
	// Should probably always be the DID itself, but maybe the DID controller.
	Controller []string `cbor:"controller,toarray" json:"controller"`
	// PubLicKeyMultibase is the public key of the verification method, encoded in multibase
	// according to https://www.w3.org/TR/did-core/#dfn-publickeymultibase
	PublicKeyMultibase string `cbor:"publicKeyMultibase" json:"publicKeyMultibase"`
}

VerificationMethod defines the structure of a Verification Method

func NewVerificationMethod

func NewVerificationMethod(

	id string,

	controller string,

	vmType string,

	fragment string,

	publicKeyMultibase string,
) (VerificationMethod, error)

NewVerificationMethod creates a new VerificationMethod id is the identifier of the verification method, eg. k51qzi5uqu5dj9807pbuod1pplf0vxh8m4lfy3ewl9qbm2s8dsf9ugdf9gedhr id must be a valid IPNS name. A random fragment will be added to the id vmType must be of type MultiKey, so that the format never changes - even if the underlying key type changes.

func (*VerificationMethod) AddController added in v0.1.0

func (v *VerificationMethod) AddController(controller string) error

Add a controller to the verification method. The DID will be checked for validity before adding it to the slice.

func (*VerificationMethod) DeleteController added in v0.1.0

func (v *VerificationMethod) DeleteController(controller string)

func (VerificationMethod) Equal added in v0.2.0

func (vm VerificationMethod) Equal(other VerificationMethod) bool

func (VerificationMethod) Fragment

func (vm VerificationMethod) Fragment() string

func (VerificationMethod) IsValid added in v0.3.5

func (vm VerificationMethod) IsValid() bool

func (VerificationMethod) ValidateControllers added in v0.3.5

func (vm VerificationMethod) ValidateControllers() error

func (VerificationMethod) Verify added in v0.3.5

func (vm VerificationMethod) Verify() error

Simply verify that the verification method seems valid

Jump to

Keyboard shortcuts

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