cs

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2018 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package cs defines types to work with Chainscripts.

Package cs defines types to work with Chainscripts.

Index

Constants

This section is empty.

Variables

View Source
var DeserializeMethods = make(map[string]func(json.RawMessage) (Proof, error), 0)

DeserializeMethods maps a proof backend (like "TMPop") to a deserializer function returning a specific proof

Functions

This section is empty.

Types

type Evidence added in v0.2.0

type Evidence struct {
	Backend  string `json:"backend"`  // can either be "TMPop", "bitcoin", "dummy"...
	Provider string `json:"provider"` // can either be a chainId (in case of a blockchain) or an identifier for a trusted third-party (timestamping authority, regulator...)
	Proof    Proof  `json:"proof"`
}

Evidence contains data that can be used to externally verify a segment's proof of existence

func (*Evidence) MarshalRQL added in v0.2.0

func (e *Evidence) MarshalRQL() (interface{}, error)

MarshalRQL serializes an Evidence into an JSON-formatted byte array

func (*Evidence) UnmarshalJSON added in v0.2.0

func (e *Evidence) UnmarshalJSON(data []byte) error

UnmarshalJSON serializes bytes into an Evidence

func (*Evidence) UnmarshalRQL added in v0.2.0

func (e *Evidence) UnmarshalRQL(data interface{}) error

UnmarshalRQL serializes an interface{} into an Evidence

type Evidences added in v0.2.0

type Evidences []*Evidence

Evidences encapsulates a list of evidences contained in Segment.Meta

func (*Evidences) AddEvidence added in v0.2.0

func (e *Evidences) AddEvidence(evidence Evidence) error

AddEvidence sets the segment evidence

func (*Evidences) FindEvidences added in v0.2.0

func (e *Evidences) FindEvidences(backend string) (res Evidences)

FindEvidences find all evidences generated by a specified backend ("TMPop", "bcbatchfossilizer"...)

func (*Evidences) GetEvidence added in v0.2.0

func (e *Evidences) GetEvidence(provider string) *Evidence

GetEvidence gets an evidence from a provider

type GenericProof added in v0.2.0

type GenericProof struct {
	Timestamp uint64      `json:"timestamp"`
	Data      interface{} `json:"data"`
	Pubkey    []byte      `json:"pubkey"`
	Signature []byte      `json:"signature"` //sign(hash(time+data))
}

GenericProof implements the Proof interface

func (*GenericProof) FullProof added in v0.2.0

func (p *GenericProof) FullProof() []byte

FullProof returns a JSON formatted proof

func (*GenericProof) Time added in v0.2.0

func (p *GenericProof) Time() uint64

Time returns the timestamp from the block header

func (*GenericProof) Verify added in v0.2.0

func (p *GenericProof) Verify(_ interface{}) bool

Verify returns true if the proof of a given linkHash is correct

type GetSegmentFunc added in v0.2.0

type GetSegmentFunc func(linkHash *types.Bytes32) (*Segment, error)

GetSegmentFunc is the function signature to retrieve a Segment

type Link struct {
	State map[string]interface{} `json:"state"`
	Meta  map[string]interface{} `json:"meta"`
}

Link contains a state and meta data about the state.

func (*Link) GetMapID

func (l *Link) GetMapID() string

GetMapID returns the map ID as a string. It assumes the link is valid.

func (*Link) GetPrevLinkHash

func (l *Link) GetPrevLinkHash() *types.Bytes32

GetPrevLinkHash returns the previous link hash as a bytes. It assumes the link is valid. It will return nil if the previous link hash is null.

func (*Link) GetPrevLinkHashString

func (l *Link) GetPrevLinkHashString() string

GetPrevLinkHashString returns the previous link hash as a string. It assumes the link is valid. It will return an empty string if the previous link hash is null.

func (*Link) GetPriority

func (l *Link) GetPriority() float64

GetPriority returns the priority as a float64 It assumes the link is valid. If priority is nil, it will return -Infinity.

func (*Link) GetProcess

func (l *Link) GetProcess() string

GetProcess returns the process name as a string. It assumes the link is valid.

func (*Link) GetTagMap

func (l *Link) GetTagMap() map[string]struct{}

GetTagMap returns the tags as a map of string to empty structs (a set). It assumes the link is valid.

func (*Link) GetTags

func (l *Link) GetTags() []string

GetTags returns the tags as an array of string. It assumes the link is valid. It will return nil if there are no tags.

func (*Link) Hash added in v0.2.0

func (l *Link) Hash() (*types.Bytes32, error)

Hash hashes the link

func (*Link) HashString added in v0.2.0

func (l *Link) HashString() (string, error)

HashString hashes the link and returns a string

func (Link) Segmentify added in v0.2.0

func (l Link) Segmentify() *Segment

Segmentify returns a segment from a link, filling the link hash and appropriate meta.

func (*Link) Validate added in v0.2.0

func (l *Link) Validate(getSegment GetSegmentFunc) error

Validate checks for errors in a link.

type LinkHashes added in v0.2.0

type LinkHashes []*types.Bytes32

LinkHashes is a slice of Bytes32-formatted link hashes

func NewLinkHashesFromStrings added in v0.2.0

func NewLinkHashesFromStrings(linkHashesStr []string) (LinkHashes, error)

NewLinkHashesFromStrings creates a slice of bytes-formatted link hashes from a slice of string-formatted link hashes

type Proof added in v0.2.0

type Proof interface {
	Time() uint64            // returns the timestamp (UNIX format) contained in the proof
	FullProof() []byte       // returns data to independently validate the proof
	Verify(interface{}) bool // Checks the validity of the proof
}

Proof is the generic interface which a custom proof type has to implement

type Segment

type Segment struct {
	Link Link        `json:"link"`
	Meta SegmentMeta `json:"meta"`
}

Segment contains a link and meta data about the link.

func (*Segment) GetLinkHash

func (s *Segment) GetLinkHash() *types.Bytes32

GetLinkHash returns the link ID as bytes. It assumes the segment is valid.

func (*Segment) GetLinkHashString

func (s *Segment) GetLinkHashString() string

GetLinkHashString returns the link ID as a string. It assumes the segment is valid.

func (s *Segment) HashLink() (string, error)

HashLink hashes the segment link and stores it into the Meta

func (*Segment) IsEmpty

func (s *Segment) IsEmpty() bool

IsEmpty checks if a segment is empty (nil)

func (*Segment) SetLinkHash added in v0.2.0

func (s *Segment) SetLinkHash() error

SetLinkHash overwrites the segment LinkHash using HashLink()

func (*Segment) Validate

func (s *Segment) Validate(getSegment GetSegmentFunc) error

Validate checks for errors in a segment

type SegmentMeta added in v0.2.0

type SegmentMeta struct {
	Evidences Evidences `json:"evidences"`
	LinkHash  string    `json:"linkHash"`
}

SegmentMeta contains additional information about the segment and a proof of existence

func (*SegmentMeta) AddEvidence added in v0.2.0

func (s *SegmentMeta) AddEvidence(evidence Evidence) error

AddEvidence sets the segment evidence

func (*SegmentMeta) FindEvidences added in v0.2.0

func (s *SegmentMeta) FindEvidences(backend string) (res Evidences)

FindEvidences find all evidences generated by a specified backend ("TMPop", "bcbatchfossilizer"...)

func (*SegmentMeta) GetEvidence added in v0.2.0

func (s *SegmentMeta) GetEvidence(provider string) *Evidence

GetEvidence gets an evidence from a provider

func (*SegmentMeta) GetLinkHash added in v0.2.0

func (s *SegmentMeta) GetLinkHash() *types.Bytes32

GetLinkHash returns the link ID as bytes. It assumes the segment is valid.

func (*SegmentMeta) GetLinkHashString added in v0.2.0

func (s *SegmentMeta) GetLinkHashString() string

GetLinkHashString returns the link ID as a string. It assumes the segment is valid.

type SegmentSlice

type SegmentSlice []*Segment

SegmentSlice is a slice of segment pointers.

func (SegmentSlice) Len

func (s SegmentSlice) Len() int

Len implements sort.Interface.Len.

func (SegmentSlice) Less

func (s SegmentSlice) Less(i, j int) bool

Less implements sort.Interface.Less.

func (SegmentSlice) Swap

func (s SegmentSlice) Swap(i, j int)

Swap implements sort.Interface.Swap.

Directories

Path Synopsis
Package cstesting defines helpers to test Chainscripts.
Package cstesting defines helpers to test Chainscripts.
Package evidences defines any type of proof that can be used in a chainscript segment It is needed by a store to know how to deserialize a segment containing any type of proof
Package evidences defines any type of proof that can be used in a chainscript segment It is needed by a store to know how to deserialize a segment containing any type of proof

Jump to

Keyboard shortcuts

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