did

package module
v0.0.0-...-bcaa7ae Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2024 License: MIT Imports: 18 Imported by: 16

README

go-did

A basic DID implementation in go, complete with a simple server and command line client.

Documentation

Index

Constants

View Source
const (
	CtxDIDv1             = "https://www.w3.org/ns/did/v1"
	CtxSecEd25519_2020v1 = "https://w3id.org/security/suites/ed25519-2020/v1"
	CtxSecX25519_2019v1  = "https://w3id.org/security/suites/x25519-2019/v1"
)
View Source
const (
	MCed25519   = 0xED
	MCP256      = 0x1200
	MCSecp256k1 = 0xe7

	KeyTypeSecp256k1 = "EcdsaSecp256k1VerificationKey2019"
	KeyTypeP256      = "EcdsaSecp256r1VerificationKey2019"
	KeyTypeEd25519   = "Ed25519VerificationKey2020"
	KeyTypeMultikey  = "Multikey"
)
View Source
const (
	TEd25519 = "ed25519"
)

Variables

View Source
var (
	ErrInvalidSignature = fmt.Errorf("invalid signature")
)

Functions

func VerifyDocumentSignature

func VerifyDocumentSignature(sd *SignedDocument, pubk ed25519.PublicKey) error

Types

type DID

type DID struct {
	// contains filtered or unexported fields
}

func DIDFromKey

func DIDFromKey(k any) (DID, error)

func OldDIDFromKey

func OldDIDFromKey(k interface{}) (DID, error)

OldDIDFromKey is specific to ed25519.PublicKey and is the other way this package used to construct DIDs, using an encoding method that was inconsistent with itself.

func ParseDID

func ParseDID(s string) (DID, error)

func (DID) MarshalJSON

func (d DID) MarshalJSON() ([]byte, error)

func (*DID) Protocol

func (d *DID) Protocol() string

func (*DID) String

func (d *DID) String() string

func (*DID) UnmarshalJSON

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

func (*DID) Value

func (d *DID) Value() string

type Document

type Document struct {
	Context []string `json:"@context"`

	ID DID `json:"id"`

	AlsoKnownAs []string `json:"alsoKnownAs"`

	Authentication []interface{} `json:"authentication"`

	VerificationMethod []VerificationMethod `json:"verificationMethod"`

	Service []Service `json:"service"`
}

func (*Document) GetPublicKey

func (d *Document) GetPublicKey(id string) (*PubKey, error)

func (*Document) Serialize

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

TODO: this needs to be a 'canonical' serialization

type PrivKey

type PrivKey struct {
	Raw  any
	Type string
}

func GeneratePrivKey

func GeneratePrivKey(rng io.Reader, keyType string) (*PrivKey, error)

func PrivKeyFromRawBytes

func PrivKeyFromRawBytes(keyType string, raw []byte) (*PrivKey, error)

func (*PrivKey) KeyType

func (k *PrivKey) KeyType() string

func (*PrivKey) Public

func (k *PrivKey) Public() *PubKey

func (*PrivKey) RawBytes

func (k *PrivKey) RawBytes() ([]byte, error)

func (*PrivKey) Sign

func (k *PrivKey) Sign(b []byte) ([]byte, error)

type PubKey

type PubKey struct {
	Raw  any
	Type string
}

func PubKeyFromCrypto

func PubKeyFromCrypto(k crypto.PublicKey) (*PubKey, error)

func PubKeyFromDIDString

func PubKeyFromDIDString(s string) (*PubKey, error)

func PubKeyFromMultibaseString

func PubKeyFromMultibaseString(s string) (*PubKey, error)

func (*PubKey) DID

func (k *PubKey) DID() string

func (*PubKey) Equal

func (k *PubKey) Equal(x *PubKey) bool

func (*PubKey) MultibaseString

func (k *PubKey) MultibaseString() string

func (*PubKey) Verify

func (k *PubKey) Verify(msg, sig []byte) error

type PublicKeyJwk

type PublicKeyJwk struct {
	Key jwk.Key
}

func (*PublicKeyJwk) GetRawKey

func (pk *PublicKeyJwk) GetRawKey() (interface{}, error)

func (*PublicKeyJwk) MarshalJSON

func (pkj *PublicKeyJwk) MarshalJSON() ([]byte, error)

func (*PublicKeyJwk) UnmarshalJSON

func (pkj *PublicKeyJwk) UnmarshalJSON(b []byte) error

type Service

type Service struct {
	ID              DID    `json:"id"`
	Type            string `json:"type"`
	ServiceEndpoint string `json:"serviceEndpoint"`
}

type Signature

type Signature struct {
	Bytes []byte
	Type  string
}

type SignedDocument

type SignedDocument struct {
	Signature *Signature `json:"signature"`
	Document  *Document  `json:"document"`
}

func SignDocument

func SignDocument(doc *Document, k ed25519.PrivateKey) (*SignedDocument, error)

type VerificationMethod

type VerificationMethod struct {
	ID                 string        `json:"id"`
	Type               string        `json:"type"`
	Controller         string        `json:"controller"`
	PublicKeyJwk       *PublicKeyJwk `json:"publicKeyJwk,omitempty"`
	PublicKeyMultibase *string       `json:"publicKeyMultibase,omitempty"`
	// contains filtered or unexported fields
}

func VerificationMethodFromKey

func VerificationMethodFromKey(k *PubKey) (*VerificationMethod, error)

func (*VerificationMethod) GetPublicKey

func (vm *VerificationMethod) GetPublicKey() (*PubKey, error)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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