doc

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2024 License: GPL-3.0 Imports: 22 Imported by: 7

Documentation

Index

Constants

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

Variables

View Source
var DID_CONTEXT = []string{
	"https://w3id.org/did/v1",
}

Functions

This section is empty.

Types

type Document

type Document struct {
	Context            []string             `cbor:"@context,toarray" json:"@context"`
	Version            string               `cbor:"version" json:"version"`
	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 GetOrCreate added in v0.1.0

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

GetOrCreate document from cache or fetch from IPFS identifier is a did string, eg. "did:ma:k51qzi5uqu5dj9807pbuod1pplf0vxh8m4lfy3ewl9qbm2s8dsf9ugdf9gedhr#foo"

func GetOrFetch added in v0.2.0

func GetOrFetch(id string) (*Document, error)

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)

func (*Document) AddVerificationMethod

func (d *Document) AddVerificationMethod(method VerificationMethod)

func (*Document) AssertionMethodPublicKey

func (d *Document) AssertionMethodPublicKey() (ed25519.PublicKey, 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

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(opts *PublishOptions) (ipns.Name, error)

Publish publishes the document to IPFS and returns the CID If the opts is nil, the default options are used.

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 {
	Created            string `cbor:"created" json:"created"`
	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"`
	// Created is the time the verification method was created
	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)

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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