Documentation
¶
Index ¶
- Constants
- Variables
- func Parse(str string) (did.DID, error)
- func SumOperation(op *SignedOperation) (cid.Cid, error)
- func VerifyOperationSignature(verifier Verifier, signedOp *SignedOperation) error
- func VerifyTombstoneSignature(verifier Verifier, signedOp *SignedTombstone) error
- type Cache
- type DeactivatedDIDError
- type DirectoryClient
- type Operation
- type OperationOption
- func WithAlsoKnownAs(alsoKnownAs ...string) OperationOption
- func WithRotationKeys(keys ...did.DID) OperationOption
- func WithServices(services map[string]Service) OperationOption
- func WithVerificationMethods(methods map[string]did.DID) OperationOption
- func WithoutAlsoKnownAs(alsoKnownAs ...string) OperationOption
- func WithoutRotationKeys(keys ...did.DID) OperationOption
- func WithoutServices(services map[string]Service) OperationOption
- func WithoutVerificationMethods(methods map[string]did.DID) OperationOption
- type Option
- type Resolver
- type Service
- type SignedOperation
- type SignedTombstone
- type Signer
- type Tombstone
- type Verifier
Constants ¶
const ( OperationType = "plc_operation" TombstoneType = "plc_tombstone" )
const IdentifierLength = 24
IdentifierLength is the length in characters of the method-specific identifier of a did:plc DID.
const Method = "plc"
Variables ¶
var ErrMissingRotationKeys = fmt.Errorf("at least one rotation key is required")
Functions ¶
func Parse ¶
Parse parses a did:plc DID string, verifying the method is "plc" and the identifier is 24 characters of base32 (lowercase, no padding).
func SumOperation ¶
func SumOperation(op *SignedOperation) (cid.Cid, error)
SumOperation computes the CID of a signed operation, as used to link the next operation in the chain to its predecessor.
func VerifyOperationSignature ¶
func VerifyOperationSignature(verifier Verifier, signedOp *SignedOperation) error
VerifyOperationSignature verifies the signature of a SignedOperation using the provided Verifier.
func VerifyTombstoneSignature ¶
func VerifyTombstoneSignature(verifier Verifier, signedOp *SignedTombstone) error
Types ¶
type Cache ¶
type Cache interface {
Get(key string) (interface{}, bool)
Set(key string, value interface{}, ttl time.Duration)
}
Cache is a TTL cache interface used by the Resolver to store resolved documents and their ETags for conditional revalidation. The cache is keyed by the DID string.
type DeactivatedDIDError ¶
type DeactivatedDIDError struct {
Operation *SignedTombstone
}
func (*DeactivatedDIDError) Error ¶
func (e *DeactivatedDIDError) Error() string
type DirectoryClient ¶
type DirectoryClient struct {
Resolver
}
func NewDirectoryClient ¶
func NewDirectoryClient(endpoint url.URL, options ...Option) (*DirectoryClient, error)
NewDirectoryClient creates a new DirectoryClient that can be used to fetch, update, and deactivate PLC operations at a directory at the given endpoint. The client can be configured with options such as timeout and transport.
func (*DirectoryClient) Deactivate ¶
func (c *DirectoryClient) Deactivate(ctx context.Context, d did.DID, op *SignedTombstone) error
Deactivate publishes the given signed tombstone to the configured directory, deactivating the DID.
func (*DirectoryClient) Last ¶
func (c *DirectoryClient) Last(ctx context.Context, d did.DID) (*SignedOperation, error)
Last fetches the last operation for the given did:plc DID from the configured directory.
func (*DirectoryClient) Update ¶
func (c *DirectoryClient) Update(ctx context.Context, d did.DID, op *SignedOperation) error
Update publishes the given signed operation to the configured directory.
type Operation ¶
type Operation struct {
Type string `cborgen:"type,const=plc_operation" dagjsongen:"type,const=plc_operation"`
VerificationMethods map[string]did.DID `cborgen:"verificationMethods" dagjsongen:"verificationMethods"`
RotationKeys []did.DID `cborgen:"rotationKeys" dagjsongen:"rotationKeys"`
AlsoKnownAs []string `cborgen:"alsoKnownAs" dagjsongen:"alsoKnownAs"`
Services map[string]Service `cborgen:"services" dagjsongen:"services"`
// String encoded CID of the previous operation in the chain, if any. If this
// is the first operation in the chain, this field is null.
Previous *string `cborgen:"prev" dagjsongen:"prev"`
}
Operation represents a PLC operation that can be used to create or update a PLC DID.
func NewOperation ¶
func NewOperation(prev *cid.Cid, options ...OperationOption) (*Operation, error)
NewOperation creates a new PLC operation with the given previous operation CID and options.
func NewOperationFromPrevious ¶
func NewOperationFromPrevious(prev *SignedOperation, options ...OperationOption) (*Operation, error)
NewOperationFromPrevious creates a new PLC operation that updates the given previous operation with the provided options. The new operation will have the previous verification methods, rotation keys, also known as, and services as the previous operation, merged with the values passed in the options.
type OperationOption ¶
type OperationOption func(*opConfig)
func WithAlsoKnownAs ¶
func WithAlsoKnownAs(alsoKnownAs ...string) OperationOption
WithAlsoKnownAs adds also known as entries to the PLC operation.
func WithRotationKeys ¶
func WithRotationKeys(keys ...did.DID) OperationOption
WithRotationKeys adds rotation keys to the PLC operation.
func WithServices ¶
func WithServices(services map[string]Service) OperationOption
WithServices adds services to the PLC operation.
func WithVerificationMethods ¶
func WithVerificationMethods(methods map[string]did.DID) OperationOption
WithVerificationMethod adds a verification method to the PLC operation.
func WithoutAlsoKnownAs ¶
func WithoutAlsoKnownAs(alsoKnownAs ...string) OperationOption
WithoutAlsoKnownAs removes the given also known as entries from the PLC operation.
func WithoutRotationKeys ¶
func WithoutRotationKeys(keys ...did.DID) OperationOption
WithoutRotationKeys removes the given rotation keys from the PLC operation.
func WithoutServices ¶
func WithoutServices(services map[string]Service) OperationOption
WithoutServices removes the given services from the PLC operation.
func WithoutVerificationMethods ¶
func WithoutVerificationMethods(methods map[string]did.DID) OperationOption
WithoutVerificationMethods removes the given verification methods from the PLC operation.
type Option ¶
type Option func(*config)
func WithCache ¶
WithCache configures the resolver to cache resolved DID documents. When set, the resolver stores the document alongside the ETag returned by the directory and issues conditional requests (If-None-Match) on subsequent resolutions, returning the cached document when the directory responds 304 Not Modified.
func WithCacheTTL ¶
WithCacheTTL sets the time to live duration passed to the cache's Set when storing a resolved document. It only has an effect alongside WithCache. The value is passed through to the configured Cache implementation; consult your Cache's documentation for the meaning of 0 or negative durations.
func WithTimeout ¶
func WithTransport ¶
func WithTransport(transport http.RoundTripper) Option
type Resolver ¶
type Resolver struct {
// contains filtered or unexported fields
}
Resolver resolves a did:plc DID to a DID Document by fetching the document from the configured directory.
type Service ¶
type SignedOperation ¶
type SignedOperation struct {
Type string `cborgen:"type,const=plc_operation" dagjsongen:"type,const=plc_operation"`
VerificationMethods map[string]did.DID `cborgen:"verificationMethods" dagjsongen:"verificationMethods"`
RotationKeys []did.DID `cborgen:"rotationKeys" dagjsongen:"rotationKeys"`
AlsoKnownAs []string `cborgen:"alsoKnownAs" dagjsongen:"alsoKnownAs"`
Services map[string]Service `cborgen:"services" dagjsongen:"services"`
// String encoded CID of the previous operation in the chain, if any. If this
// is the first operation in the chain, this field is null.
Previous *string `cborgen:"prev" dagjsongen:"prev"`
Signature string `cborgen:"sig" dagjsongen:"sig"`
}
func New ¶
func New(signer Signer, options ...OperationOption) (did.DID, *SignedOperation, error)
func SignOperation ¶
func SignOperation(signer Signer, op *Operation) (*SignedOperation, error)
SignOperation signs a PLC operation with the given signer and returns a SignedOperation.
func (*SignedOperation) MarshalCBOR ¶
func (t *SignedOperation) MarshalCBOR(w io.Writer) error
func (*SignedOperation) MarshalDagJSON ¶
func (t *SignedOperation) MarshalDagJSON(w io.Writer) error
func (*SignedOperation) UnmarshalCBOR ¶
func (t *SignedOperation) UnmarshalCBOR(r io.Reader) (err error)
func (*SignedOperation) UnmarshalDagJSON ¶
func (t *SignedOperation) UnmarshalDagJSON(r io.Reader) (err error)
type SignedTombstone ¶
type SignedTombstone struct {
Type string `cborgen:"type,const=plc_tombstone" dagjsongen:"type,const=plc_tombstone"`
Previous string `cborgen:"prev" dagjsongen:"prev"`
Signature string `cborgen:"sig" dagjsongen:"sig"`
}
func SignTombstone ¶
func SignTombstone(signer Signer, op *Tombstone) (*SignedTombstone, error)
SignTombstone signs a PLC tombstone with the given signer and returns a SignedTombstone.
func (*SignedTombstone) MarshalCBOR ¶
func (t *SignedTombstone) MarshalCBOR(w io.Writer) error
func (*SignedTombstone) MarshalDagJSON ¶
func (t *SignedTombstone) MarshalDagJSON(w io.Writer) error
func (*SignedTombstone) UnmarshalCBOR ¶
func (t *SignedTombstone) UnmarshalCBOR(r io.Reader) (err error)
func (*SignedTombstone) UnmarshalDagJSON ¶
func (t *SignedTombstone) UnmarshalDagJSON(r io.Reader) (err error)
type Signer ¶
type Signer interface {
// Sign takes a byte encoded message and produces a verifiable signature.
Sign(msg []byte) []byte
}
Signer is an entity that can sign a payload.
type Tombstone ¶
type Tombstone struct {
Type string `cborgen:"type,const=plc_tombstone" dagjsongen:"type,const=plc_tombstone"`
Previous string `cborgen:"prev" dagjsongen:"prev"`
}
func NewTombstone ¶
NewTombstone creates a new PLC tombstone with the given previous operation CID. The tombstone indicates that the DID has been deactivated and should no longer be used.
func NewTombstoneFromPrevious ¶
func NewTombstoneFromPrevious(prev *SignedOperation) (*Tombstone, error)
NewTombstoneFromPrevious creates a new PLC tombstone that deactivates the DID, linking to the given previous operation by its computed CID. It is a convenience over NewTombstone for the common case where you have fetched the last signed operation (e.g. via DirectoryClient.Last) rather than its CID.