Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotFound = errors.New("not found") ErrWrongSignature = errors.New("wrong signature") ErrSlotIdTooBig = errors.New("slot id is too big") ErrPayloadTooBig = errors.New("payload is too big") ErrPastExpiration = errors.New("past expiration") ErrVersionTooLow = errors.New("version too low") )
Functions ¶
This section is empty.
Types ¶
type Constraints ¶
Constraints specifies the global storage constraints.
type Envelope ¶
type Envelope struct { Address []byte `json:"address"` SlotID uint `json:"slotid"` Payload []byte `json:"payload"` Version uint64 `json:"version"` Expiration int64 `json:"expiration"` }
Envelope represents a JSON object that is signed for address verification. All []byte values are encoded as base64 (default JSON behavior). Hex is not used to avoid confusion due to case-sensivity and 0x prefix. A signer is responsible for generating a JSON that has no whitespace and the keys appear in this exact order: {"address":base64,"slotid":int,"payload":base64,"version":int,"expiration":int}
func NewEnvelopeFromRecord ¶
func (Envelope) GetSignerAddress ¶
GetSignerAddress verifies the signature and returns the signing address.
type Key ¶
type Key struct { // Address is a user address Address common.Address // SlotId is a slot number SlotId uint // Version is a data version Version uint64 }
Key identifies a versioned user record.
type Metadata ¶
type Metadata struct { // Confirmed turns true once consensus is reached. Confirmed bool // Signature contains the original user signature. Signature []byte }
Metadata is the internal S4 data associated with a Record
type ORM ¶
type ORM interface { // Get reads a row for the given address and slotId. // If a row is missing, ErrNotFound is returned. // Returned row is a clone, safe to modify. Get(address common.Address, slotId uint, qopts ...pg.QOpt) (*Row, error) // Put inserts (or updates) a row identified by the specified address and slotId. // No validation is applied for signature, version, etc. // Implementation clones the given Row when persisting. Upsert(address common.Address, slotId uint, row *Row, qopts ...pg.QOpt) error // DeleteExpired deletes any entries having HighestExpiration < now(). // The function can be called by OCR plugin on every round. // (shall be cheap for postgres implementation, given the right columns are indexed). DeleteExpired(qopts ...pg.QOpt) error }
ORM represents S4 persistence layer. All functions are thread-safe.
func NewInMemoryORM ¶
func NewInMemoryORM() ORM
type Record ¶
type Record struct { // Arbitrary user data Payload []byte // Expiration timestamp assigned by user (unix time in milliseconds) Expiration int64 }
Record represents a user record persisted by S4.
type Storage ¶
type Storage interface { // Constraints returns a copy of Constraints struct specified during service creation. // The implementation is thread-safe. Constraints() Constraints // Get returns a copy of record (with metadata) associated with the specified key. // The returned Record & Metadata are always a copy. Get(ctx context.Context, key *Key) (*Record, *Metadata, error) // Put creates (or updates) a record identified by the specified key. // For signature calculation see envelope.go Put(ctx context.Context, key *Key, record *Record, signature []byte) error }
Storage represents S4 storage access interface. All functions are thread-safe.
func NewStorage ¶
func NewStorage(lggr logger.Logger, contraints Constraints, orm ORM) Storage