Documentation
¶
Index ¶
- Constants
- Variables
- type Document
- func Fetch(didStr string, cached bool) (*Document, cid.Cid, error)
- func FetchFromDID(d did.DID, cached bool) (*Document, cid.Cid, error)
- func GetOrCreate(identifier string, controller string) (*Document, cid.Cid, error)
- func New(identifier string, controller string) (*Document, error)
- func NewFromKeyset(k set.Keyset) (*Document, error)
- func NewFromKeysetWithController(k set.Keyset, controller string) (*Document, error)
- func Payload(d Document) (Document, error)
- func (d *Document) AddController(controller string) error
- func (d *Document) AddVerificationMethod(method VerificationMethod) error
- func (d *Document) AssertionMethodPublicKey() (ed25519.PublicKey, error)
- func (d *Document) CID() (cid.Cid, error)
- func (d *Document) DeleteController(controller string)
- func (d *Document) DeleteVerificationMethod(method VerificationMethod) error
- func (d *Document) Equal(other *Document) bool
- func (d *Document) GetAssertionMethod() (VerificationMethod, error)
- func (d *Document) GetKeyAgreementMethod() (VerificationMethod, error)
- func (d *Document) GetVerificationMethodByID(vmid string) (VerificationMethod, error)
- func (d *Document) KeyAgreementPublicKeyBytes() ([]byte, error)
- func (d *Document) MarshalPayloadToCBOR() ([]byte, error)
- func (d *Document) MarshalToCBOR() ([]byte, error)
- func (d *Document) Node() (*cbor.Node, error)
- func (d *Document) PayloadHash() ([]byte, error)
- func (d *Document) Publish(o ...*PublishOptions) (ipns.Name, error)
- func (d *Document) PublishGoroutine(wg *sync.WaitGroup, cancel context.CancelFunc, opts *PublishOptions)
- func (d *Document) Sign(signKey key.SigningKey, vm VerificationMethod) error
- func (d *Document) String() string
- func (d *Document) Verify() error
- type Proof
- type PublishOptions
- type VerificationMethod
- func (v *VerificationMethod) AddController(controller string) error
- func (v *VerificationMethod) DeleteController(controller string)
- func (vm VerificationMethod) Equal(other VerificationMethod) bool
- func (vm VerificationMethod) Fragment() string
- func (vm VerificationMethod) IsValid() bool
- func (vm VerificationMethod) ValidateControllers() error
- func (vm VerificationMethod) Verify() error
Constants ¶
const (
VerificationMethodDefaultTTL = time.Duration(7) * time.Hour * 24
)
Variables ¶
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") )
var DID_CONTEXT = []string{
"https://w3id.org/did/v1",
}
var ErrAlreadyPublished = errors.New("Document is already published")
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 ¶
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
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
GetOrCreate document from cache or create a new one identifier is a did string, eg. "did:ma:k51qzi5uqu5dj9807pbuod1pplf0vxh8m4lfy3ewl9qbm2s8dsf9ugdf9gedhr#foo"
func NewFromKeyset ¶
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 Payload ¶
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 (*Document) AddVerificationMethod ¶
func (d *Document) AddVerificationMethod(method VerificationMethod) error
func (*Document) AssertionMethodPublicKey ¶
func (*Document) DeleteController ¶ added in v0.1.0
func (*Document) DeleteVerificationMethod ¶ added in v0.1.0
func (d *Document) DeleteVerificationMethod(method VerificationMethod) error
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 (*Document) MarshalPayloadToCBOR ¶
Marshals the payload to CBOR for publication
func (*Document) MarshalToCBOR ¶ added in v0.1.0
func (*Document) Node ¶ added in v0.0.6
IPFSDagAddCBOR takes a CBOR encoded byte array and adds it to IPFS.
func (*Document) PayloadHash ¶
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
type Proof ¶
type PublishOptions ¶ added in v0.2.0
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