Documentation
¶
Index ¶
- Constants
- Variables
- type DIDIdentifier
- type DIDVerifier
- type Document
- type IdentifierDID
- type KeyPair
- type Metadata
- type PeerKeyPair
- func (k *PeerKeyPair) GenerateAddr() string
- func (k *PeerKeyPair) GenerateID() string
- func (k *PeerKeyPair) GetEd25519PublicKey() []byte
- func (k *PeerKeyPair) GetX25519PublicKey() []byte
- func (k *PeerKeyPair) Shake(peerPublicKey *ecdh.PublicKey) ([]byte, error)
- func (k *PeerKeyPair) SignData(data []byte) ([]byte, error)
- func (k *PeerKeyPair) Unshake(peerPublicKey *ecdh.PublicKey, signature []byte, ...) ([]byte, error)
- func (k *PeerKeyPair) VerifyData(data []byte, signature []byte) (bool, error)
- type ServiceEndpoint
- type VerificationMethod
- type VerificationResult
- type VerificationStats
- type VerifierConfig
- type VerifierDID
Constants ¶
const ( VerificationID = "#keys-1" KeyAgreementID = "#keys-2" VerificationType = "Ed25519VerificationKey2018" KeyAgreementType = "X25519KeyAgreementKey2019" DIDContext = "https://www.w3.org/ns/did/v1" )
const ( // New Ed25519VerificationKey2020 = "Ed25519VerificationKey2020" X25519KeyAgreementKey2020 = "X25519KeyAgreementKey2020" // Old Ed25519VerificationKey2018 = "Ed25519VerificationKey2018" X25519KeyAgreementKey2019 = "X25519KeyAgreementKey2019" )
Variables ¶
var ( ErrExpired = errors.New("verification result expired") ErrNotFound = errors.New("verification result not found") ErrMissingCreatedAt = errors.New("document missing createdAt field") ErrMissingTrustedRoot = errors.New("document not signed by trusted root") ErrDocNotController = errors.New("document controller not in trusted roots") ErrTimestampInvalid = errors.New("document timestamp is invalid") )
var (
DIDVersion = 1
)
Functions ¶
This section is empty.
Types ¶
type DIDIdentifier ¶
type DIDIdentifier struct {
ID string
Address string
KeyPair KeyPair
Metadata Metadata
Services []ServiceEndpoint
}
DIDIdentifier represents a Decentralized Identifier.
func (*DIDIdentifier) Document ¶
func (d *DIDIdentifier) Document() *Document
Document converts the DID to a DID Document.
func (*DIDIdentifier) SignDocument ¶
func (d *DIDIdentifier) SignDocument() ([]byte, error)
SignDocument signs the DID Document.
func (*DIDIdentifier) SignMessage ¶
func (d *DIDIdentifier) SignMessage(data []byte) ([]byte, error)
SignMessage signs a message using the DID's key pair.
type DIDVerifier ¶
type DIDVerifier struct {
// contains filtered or unexported fields
}
DIDVerifier implements the VerifierDID interface.
func (*DIDVerifier) AddTrustedRoot ¶
func (v *DIDVerifier) AddTrustedRoot(rootDID string)
AddTrustedRoot adds a trusted root DID to the verifier.
func (*DIDVerifier) ClearCache ¶
func (v *DIDVerifier) ClearCache()
ClearCache clears the verification result cache.
func (*DIDVerifier) GetStats ¶
func (v *DIDVerifier) GetStats() VerificationStats
GetStats returns the current verification statistics.
func (*DIDVerifier) VerifyDocument ¶
func (v *DIDVerifier) VerifyDocument(doc *Document, signature []byte) (bool, error)
VerifyDocument verifies the DID Document using the provided signature.
type Document ¶
type Document struct {
Context []string `json:"@context"`
ID string `json:"id"`
VerificationMethod []VerificationMethod `json:"verificationMethod"`
Authentication []string `json:"authentication"`
AssertionMethod []string `json:"assertionMethod"`
KeyAgreement []string `json:"keyAgreement"`
CapabilityInvocation []string `json:"capabilityInvocation"`
CapabilityDelegation []string `json:"capabilityDelegation"`
Service []ServiceEndpoint `json:"service,omitempty"`
Created string `json:"created,omitempty"`
Updated string `json:"updated,omitempty"`
}
Document represents the DID's Document structure following W3C DID spec.
func NewDocument ¶
func NewDocument(did DIDIdentifier, createdAt time.Time) *Document
NewDocument creates a new DID Document based on the provided DIDIdentifier and creation time.
func NewDocumentWithNewStandards ¶
func NewDocumentWithNewStandards(did DIDIdentifier, createdAt time.Time) *Document
NewDocumentWithNewStandards creates a new DID Document following the latest W3C DID standards.
func (*Document) JSONMarshal ¶
func (*Document) JSONUnmarshal ¶
type IdentifierDID ¶
type IdentifierDID interface {
Addr() string
Document() *Document
SignDocument() ([]byte, error)
SignMessage(data []byte) ([]byte, error)
}
IdentifierDID defines the interface for a Identifier DID.
func NewDIDIdentifier ¶
func NewDIDIdentifier(services []ServiceEndpoint) IdentifierDID
NewDID creates a new IdentifierDID instance.
type KeyPair ¶
type KeyPair interface {
GenerateID() string
GenerateAddr() string
GetEd25519PublicKey() []byte
GetX25519PublicKey() []byte
SignData(data []byte) ([]byte, error)
VerifyData(data []byte, signature []byte) (bool, error)
Shake(peerPublicKey *ecdh.PublicKey) ([]byte, error)
Unshake(peerPublicKey *ecdh.PublicKey, signature []byte, peerEdPublicKey ed25519.PublicKey) ([]byte, error)
}
KeyPair defines the interface for key pair operations.
type PeerKeyPair ¶
type PeerKeyPair struct {
EdPublic ed25519.PublicKey
EdPrivate ed25519.PrivateKey
XPublic *ecdh.PublicKey
XPrivate *ecdh.PrivateKey
}
PeerKeyPair holds the key pairs for a Peer DID.
func (*PeerKeyPair) GenerateAddr ¶
func (k *PeerKeyPair) GenerateAddr() string
GenerateAddr generates an address from the ED25519 public key.
func (*PeerKeyPair) GenerateID ¶
func (k *PeerKeyPair) GenerateID() string
GenerateDID generates a DID from the Ed25519 public key.
func (*PeerKeyPair) GetEd25519PublicKey ¶
func (k *PeerKeyPair) GetEd25519PublicKey() []byte
GetEd25519PublicKey returns the Ed25519 public key.
func (*PeerKeyPair) GetX25519PublicKey ¶
func (k *PeerKeyPair) GetX25519PublicKey() []byte
GetX25519PublicKey returns the X25519 public key.
func (*PeerKeyPair) Shake ¶
func (k *PeerKeyPair) Shake(peerPublicKey *ecdh.PublicKey) ([]byte, error)
Shake sign own X25519 public key using own Ed25519 private key
func (*PeerKeyPair) SignData ¶
func (k *PeerKeyPair) SignData(data []byte) ([]byte, error)
using Ed25519 private key sign data
func (*PeerKeyPair) Unshake ¶
func (k *PeerKeyPair) Unshake(peerPublicKey *ecdh.PublicKey, signature []byte, peerEdPublicKey ed25519.PublicKey) ([]byte, error)
Unshake verify peer's X25519 public key signature using peer's Ed25519 public key and generate shared secret
func (*PeerKeyPair) VerifyData ¶
func (k *PeerKeyPair) VerifyData(data []byte, signature []byte) (bool, error)
using Ed25519 public key verify data signature
type ServiceEndpoint ¶
type ServiceEndpoint struct {
ID string `json:"id"`
Type string `json:"type"`
ServiceEndpoint interface{} `json:"serviceEndpoint"`
}
ServiceEndpoint represents a service endpoint in the DID Document.
type VerificationMethod ¶
type VerificationMethod struct {
ID string `json:"id"`
Type string `json:"type"`
Controller string `json:"controller"`
PublicKeyMultibase string `json:"publicKeyMultibase"`
}
VerificationMethod represents a verification method in the DID Document.
type VerificationResult ¶
type VerificationResult struct {
IsValid bool
DID string
VerifiedAt time.Time
ExpiresAt time.Time
ErrorMsg string
Signature []byte
PublicKey ed25519.PublicKey
}
VerificationResult holds the result of a DID verification attempt.
type VerificationStats ¶
type VerificationStats struct {
TotalVerifications int64
SuccessfulVerifications int64
FailedVerifications int64
CacheHits int64
CacheMisses int64
}
VerificationStats holds statistics about the verification process.
type VerifierConfig ¶
type VerifierConfig struct {
EnableCache bool
CacheTTL time.Duration
MaxCacheSize int
ValidateTimestamp bool
TimestampTolerance time.Duration
RequireTrustedRoot bool
}
VerifierConfig holds configuration for the DID verifier.
type VerifierDID ¶
type VerifierDID interface {
VerifyDocument(doc *Document, signature []byte) (bool, error)
GetStats() VerificationStats
AddTrustedRoot(did string)
ClearCache()
}
VerifierDID defines the interface for verifying a DID Document.
func NewDIDVerifier ¶
func NewDIDVerifier(config VerifierConfig) VerifierDID
func NewDefaultDIDVerifier ¶
func NewDefaultDIDVerifier() VerifierDID