dwn

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DidNotString = "DidNotString"
	DidNotValid  = "DidNotValid"
)

Variables

This section is empty.

Functions

func Validate

func Validate(did string) error

TODO implement/remove this

Types

type AllowAllTenants

type AllowAllTenants struct{}

func (AllowAllTenants) IsTenant

func (o AllowAllTenants) IsTenant(tenant string) (bool, error)

type Authorization

type Authorization interface {
	// contains filtered or unexported methods
}

type AuthorizationDelegatedGrant

type AuthorizationDelegatedGrant struct {
	Signature            GeneralJws      `json:"signature"`
	AuthorDelegatedGrant *DelegatedGrant `json:"authorDelegatedGrant"`
}

func (*AuthorizationDelegatedGrant) Author

func (m *AuthorizationDelegatedGrant) Author() string

type AuthorizationOwner

type AuthorizationOwner struct {
	Signature      GeneralJws `json:"signature"`
	OwnerSignature GeneralJws `json:"ownerSignature"`

	AuthorDelegatedGrant *DelegatedGrant `json:"authorDelegatedGrant,omitempty"`
	OwnerDelegatedGrant  *DelegatedGrant `json:"ownerDelegatedGrant,omitempty"`
}

type B

type B bool

type Blob

type Blob []byte

Blob represents a binary large object

type Cache

type Cache interface {
	Get(key string) (DidResolutionResult, bool)
	Set(key string, value DidResolutionResult)
}

Cache interface

type DID

type DID string

Types that are part of the public interface of the DWN.

type DataCid

type DataCid string

type DataStore

type DataStore interface {
	Open() error
	Close() error

	// Put a data blob into the data store.  The DataCID is calculated from the
	// dataStream, and returned.  If it doesn't match dataCid input,
	// an error results, and nothing is written.
	Put(tenant Tenant, messageCid MessageCid, dataCid DataCid,
		dataStream io.Reader) (resultCid DataCid, dataSize int64, err error)

	Get(Tenant, MessageCid, DataCid) (dataCid DataCid,
		dataSize int64, dataStream io.Reader,
		err error)

	Associate(Tenant, MessageCid, DataCid) (dataCid DataCid,
		dataSize int64, err error)

	Delete(Tenant, MessageCid, DataCid) (err error)

	// Test purposes
	Clear() (err error)
}

func NewMemoryDatastore

func NewMemoryDatastore() DataStore

type DelegatedGrant

type DelegatedGrant struct {
	// Authorization -> Signature --- ??
	Authorization PlainAuthorization       `json:"authorization"`
	Descriptor    DelegatedGrantDescriptor `json:"descriptor"`
}

type DelegatedGrantDescriptor

type DelegatedGrantDescriptor struct {
	RecordId    string `json:"recordId"`
	EncodedData string `json:"encodedData"`
}

type Descriptor

type Descriptor struct {
	// Required
	Interface        string
	Method           string
	DataCid          DataCid
	DataSize         int64
	DateCreated      string
	MessageTimestamp string
	DataFormat       string

	Recipient     DID
	Protocol      string
	ProtocolPath  string
	Schema        string
	Tags          map[string]interface{}
	ParentId      MessageCid
	Published     bool
	DatePublished string
}

type Did

type Did struct{}

func (*Did) GetMethodName

func (d *Did) GetMethodName(did string) (string, error)

GetMethodName gets the method name from a DID. ie. did:<method-name>:<method-specific-id>

func (*Did) GetMethodSpecificId

func (d *Did) GetMethodSpecificId(did string) (string, error)

GetMethodSpecificId gets the method specific ID segment of a DID. ie. did:<method-name>:<method-specific-id>

func (*Did) Validate

func (d *Did) Validate(did interface{}) error

Validate validates the given DID

type DidMethodResolver

type DidMethodResolver interface {
	Method() string
	Resolve(did string) (DidResolutionResult, error)
}

DidMethodResolver interface

type DidResolutionResult

type DidResolutionResult struct {
	DidDocument           interface{}
	DidResolutionMetadata struct {
		Error string
	}
}

DidResolutionResult struct

func FetchDidDocument

func FetchDidDocument(url string) (DidResolutionResult, error)

FetchDidDocument fetches a DID document from a URL

func ParseDidDocument

func ParseDidDocument(filePath string) (DidResolutionResult, error)

ParseDidDocument parses a DID document from a JSON file

type DidResolver

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

DidResolver struct

func NewDidResolver

func NewDidResolver(resolvers []DidMethodResolver, cache Cache) *DidResolver

func NewStaticDidResolver

func NewStaticDidResolver(didjson string) *DidResolver

func (*DidResolver) Resolve

func (r *DidResolver) Resolve(did string) (DidResolutionResult, error)

func (*DidResolver) ResolveFromFile

func (r *DidResolver) ResolveFromFile(filePath string) (DidResolutionResult, error)

func (*DidResolver) ResolveFromURL

func (r *DidResolver) ResolveFromURL(url string) (DidResolutionResult, error)

type Dwn

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

func NewDwn

func NewDwn(config DwnConfig) (*Dwn, error)

func (*Dwn) Close

func (d *Dwn) Close() error

func (*Dwn) Open

func (d *Dwn) Open() error

func (*Dwn) ProcessMessage

func (d *Dwn) ProcessMessage(tenant string, rawMessage map[string]interface{}, dataStream io.Reader) (UnionMessageReply, error)

type DwnConfig

type DwnConfig struct {
	DidResolver        *DidResolver
	TenantGate         TenantGate
	MessageStore       MessageStore
	DataStore          DataStore
	EventLog           EventLog
	BlockstoreLocation string // Add this field
}

Update the DwnConfig struct

type DwnError

type DwnError struct {
	Code    string
	Message string
}

func (*DwnError) Error

func (e *DwnError) Error() string

type EqualFilter

type EqualFilter struct {
	EqualTo IndexableValue
}

type Event

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

MessageStore

type EventLog

type EventLog interface {
	Open() error
	Close() error

	Append(Tenant, MessageCid, IndexableKeyValues) (err error)

	GetEvents(Tenant) ([]string, error)

	QueryEvents(Tenant, []Filter, EventLogCursor) ([]string, error)

	DeleteEventsByCid(Tenant, []MessageCid) error

	// Test purposes
	Clear() error
}

func NewMemoryEventLog

func NewMemoryEventLog() EventLog

type EventLogCursor

type EventLogCursor string

type F

type F float64

type Filter

type Filter interface {
	// The property this filter is for
	Property() string
	Value() FilterValue
}

A filter applies a given FilterValue to a given property.

type FilterValue

type FilterValue interface {
	// contains filtered or unexported methods
}

A Filter compares either:

  • equality (exactly matches an indexable value)
  • one of a list of equality
  • a range filter, which is an operator and a RangeValue. The range value is a subset of indexable values: it's numbers and strings only.

type GT

type GT struct {
	GT RangeValue
}

Range Filter pieces below:

type GTE

type GTE struct {
	GTE RangeValue
}

type GeneralJws

type GeneralJws struct {
	Payload    string      `json:"payload"`
	Signatures []Signature `json:"signatures"`
}

type HandlerRequest

type HandlerRequest struct {
	Tenant     string
	Message    map[string]interface{}
	DataStream io.Reader
}

type I

type I int64

type IndexableKeyValues

type IndexableKeyValues map[string]IndexableValue

The storage calls take a map of string keys to values.

type IndexableValue

type IndexableValue interface {
	// contains filtered or unexported methods
}

Indexable values are string | number | boolean, but Go doesn't have 'sum' types or unions. This is the best alternative according to https://www.jerf.org/iri/post/2917/

type LT

type LT struct {
	LT RangeValue
}

type LTE

type LTE struct {
	LTE RangeValue
}

type MemoryCache

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

MemoryCache struct

func NewMemoryCache

func NewMemoryCache(expiry time.Duration) *MemoryCache

func (*MemoryCache) Get

func (c *MemoryCache) Get(key string) (DidResolutionResult, bool)

func (*MemoryCache) Set

func (c *MemoryCache) Set(key string, value DidResolutionResult)

type MemoryDatastore

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

DataStore MemoryDatastore implements the DataStore interface using in-memory storage

func (*MemoryDatastore) Associate

func (m *MemoryDatastore) Associate(Tenant, MessageCid, DataCid) (dataCid DataCid,
	dataSize int64, err error)

func (*MemoryDatastore) Clear

func (m *MemoryDatastore) Clear() (err error)

func (*MemoryDatastore) Close

func (*MemoryDatastore) Close() error

func (*MemoryDatastore) Delete

func (m *MemoryDatastore) Delete(Tenant, MessageCid, DataCid) (err error)

func (*MemoryDatastore) Get

func (m *MemoryDatastore) Get(Tenant, MessageCid, DataCid) (dataCid DataCid,
	dataSize int64, dataStream io.Reader,
	err error)

func (*MemoryDatastore) Open

func (*MemoryDatastore) Open() error

func (*MemoryDatastore) Put

func (m *MemoryDatastore) Put(tenant Tenant, messageCid MessageCid, dataCid DataCid,
	dataStream io.Reader) (resultCid DataCid, dataSize int64, err error)

type MemoryEventLog

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

func (*MemoryEventLog) Append

func (*MemoryEventLog) Clear

func (l *MemoryEventLog) Clear() error

Test purposes

func (*MemoryEventLog) Close

func (*MemoryEventLog) Close() error

func (*MemoryEventLog) DeleteEventsByCid

func (*MemoryEventLog) DeleteEventsByCid(Tenant, []MessageCid) error

func (*MemoryEventLog) GetEvents

func (*MemoryEventLog) GetEvents(Tenant) ([]string, error)

func (*MemoryEventLog) Open

func (*MemoryEventLog) Open() error

func (*MemoryEventLog) QueryEvents

func (*MemoryEventLog) QueryEvents(Tenant, []Filter, EventLogCursor) ([]string, error)

type MemoryMessageStore

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

func (*MemoryMessageStore) Clear

func (m *MemoryMessageStore) Clear() (err error)

Test purposes

func (*MemoryMessageStore) Close

func (*MemoryMessageStore) Close() error

func (*MemoryMessageStore) Delete

func (*MemoryMessageStore) Delete(Tenant, MessageCid) (err error)

func (*MemoryMessageStore) Get

func (*MemoryMessageStore) Get(Tenant, MessageCid) (msg interface{}, err error)

func (*MemoryMessageStore) Open

func (*MemoryMessageStore) Open() error

func (*MemoryMessageStore) Put

func (*MemoryMessageStore) Put(Tenant,
	interface{},
	IndexableKeyValues) (err error)

func (*MemoryMessageStore) Query

func (*MemoryMessageStore) Query(tenant Tenant, filters []Filter,
	sort MessageSort,
	pagination Pagination) (err error)

type Message

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

MessageStore

type MessageCid

type MessageCid string

type MessageHandler

type MessageHandler interface {
	Handle(dwn *Dwn) error
}

TODO beef this up

type MessageSort

type MessageSort struct {
	DateCreated      SortDirection
	DatePublished    SortDirection
	MessageTimestamp SortDirection
}

type MessageStore

type MessageStore interface {

	// interface[} -> DwnMessage
	Put(Tenant,
		interface{},
		IndexableKeyValues) (err error)

	Get(Tenant, MessageCid) (msg interface{}, err error)

	Query(tenant Tenant, filters []Filter,
		sort MessageSort,
		pagination Pagination) (err error)

	Delete(Tenant, MessageCid) (err error)

	// Test purposes
	Clear() (err error)

	Open() error
	Close() error
}

func NewMemoryMessageStore

func NewMemoryMessageStore() MessageStore

type MessagesGet

type MessagesGet struct {
	Authorization PlainAuthorization `json:"authorization"`
	Descriptor    struct {
		Interface        string // const==Messages
		Method           string // const==Get
		MessageTimestamp string
		MessageCids      []string `json:"messageCids,omitempty"`
	} `json:"descriptor"`
}

func (*MessagesGet) Handle

func (message *MessagesGet) Handle(tenant Tenant, dwn *Dwn) error

type MethodHandler

type MethodHandler interface {
	Handle(request *HandlerRequest) (UnionMessageReply, error)
}

type OneOfFilter

type OneOfFilter struct {
	OneOf []EqualFilter
}

type Pagination

type Pagination struct {
	Cursor string
	Limit  int
}

type PermissionsGrant

type PermissionsGrant struct {
}

type PlainAuthorization

type PlainAuthorization struct {
	Signature GeneralJws `json:"signature"`
}

func (*PlainAuthorization) Author

func (m *PlainAuthorization) Author() string

type RangeFilter

type RangeFilter interface {
	RangeValue() RangeValue
	// contains filtered or unexported methods
}

A Range Filter is one of: - GT (some value) - LT (some value) - GTE (some value) - LTE (some value)

The value is a subset of indexable values, since you can't do a meaningful comparison on booleans.

type RangeValue

type RangeValue interface {
	// contains filtered or unexported methods
}

A range value is: `string | number` numbers are either float64 or int64.

type RawDwnMessage

type RawDwnMessage map[string]interface{}

A Raw Dwn message is just a parsed JSON placeholder.

type RecordsRead

type RecordsRead struct {
	Authorization AuthorizationDelegatedGrant `json:"authorization"`
	Descriptor    struct {
		Interface string
		Method    string
		// iso timestamp
		MessageTimestamp string
		// TODO make this properly typed.
		Filter map[string]interface{}
	} `json:"descriptor"`
}

type RecordsWrite

type RecordsWrite struct {
	// These three are required
	RecordId      string             `json:"recordId"`
	Authorization AuthorizationOwner `json:"authorization"`
	Descriptor    Descriptor         `json:"descriptor"`

	ContextId   string     `json:"contextId,omitempty"`
	Attestation GeneralJws `json:"attestation,omitempty"`
	Encryption  struct {
		Algorithm            string `json:"algorithm"`
		InitializationVector string `json:"initializationVector"`
		KeyEncryption        []struct {
			RootKeyId string
			// string-based enum of:
			// dataFormats | protocolContext | protocolPath | schemas
			DerivationScheme          string
			DerivedPublicKey          map[string]interface{}
			Algorithm                 string
			EncryptedKey              string
			InitializationVector      string
			EmphemeralPublicKey       map[string]interface{}
			MessageAuthenticationCode string
		} `json:"keyEncryption"`
	} `json:"encryption"`
}

func (*RecordsWrite) Handle

func (message *RecordsWrite) Handle(dwn *Dwn) error

type S

type S string

type ServiceEndpoint

type ServiceEndpoint struct {
	Nodes          []string `json:"nodes"`
	SigningKeys    []string `json:"signingKeys"`
	EncryptionKeys []string `json:"encryptionKeys"`
}

type Signature

type Signature struct {
	Protected string `json:"protected"`
	Signature string `json:"signature"`
}

type SortDirection

type SortDirection int

Sort options

const (
	// these values are from query-types.ts
	Descending SortDirection = -1
	Ascending  SortDirection = 1
)

type StaticDidResolver

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

DID Resolver for test purposes

func (StaticDidResolver) Method

func (o StaticDidResolver) Method() string

func (StaticDidResolver) Resolve

type Status

type Status struct {
	Code   int
	Detail string
}

type StoredMessage

type StoredMessage struct {
	Authorization map[string]interface{}
	Descriptor    map[string]interface{}
}

What are we storing in the MessageStore? What's in the DwnMessage?

type Tenant

type Tenant string

type TenantGate

type TenantGate interface {
	IsTenant(tenant string) (bool, error)
}

func NewAllowAllTenantGate

func NewAllowAllTenantGate() TenantGate

type UnionMessageReply

type UnionMessageReply struct {
	Status Status
}

Jump to

Keyboard shortcuts

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