cs

package
v0.3.0-rc2 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2018 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package cs defines types to work with Chainscripts.

Package cs defines types to work with Chainscripts.

Package cs defines types to work with Chainscripts.

Index

Constants

View Source
const (
	// ErrBadJMESPATHQuery is returned when the JMESPATH engine fails to execute the query
	ErrBadJMESPATHQuery = "failed to execute JMESPATH query"

	// ErrEmptyJMESPATHResult is returned when the JMESPATH query does not match any part of the link
	ErrEmptyJMESPATHResult = "JMESPATH query does not match any link data"
)

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(ctx context.Context, linkHash *types.Bytes32) (*Segment, error)

GetSegmentFunc is the function signature to retrieve a Segment

type Link struct {
	State      map[string]interface{} `json:"state"`
	Meta       LinkMeta               `json:"meta"`
	Signatures []*Signature           `json:"signatures"`
}

Link contains a state and meta data about the state.

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(ctx context.Context, getSegment GetSegmentFunc) error

Validate checks for errors in a link. It checks the validity of: format, signatures and references.

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 LinkMeta added in v0.3.0

type LinkMeta struct {
	MapID        string                 `json:"mapId"`
	Process      string                 `json:"process"`
	Action       string                 `json:"action"`
	Type         string                 `json:"type"`
	Inputs       []interface{}          `json:"inputs"`
	Tags         []string               `json:"tags"`
	Priority     float64                `json:"priority"`
	PrevLinkHash string                 `json:"prevLinkHash"`
	Refs         []SegmentReference     `json:"refs"`
	Data         map[string]interface{} `json:"data"`
}

LinkMeta contains the typed meta data of a Link and data

func (*LinkMeta) GetPrevLinkHash added in v0.3.0

func (m *LinkMeta) GetPrevLinkHash() *types.Bytes32

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

func (*LinkMeta) GetTagMap added in v0.3.0

func (m *LinkMeta) GetTagMap() map[string]struct{}

GetTagMap returns the tags as a map of string to empty structs (a set).

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(ctx context.Context, 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 SegmentReference added in v0.3.0

type SegmentReference struct {
	Segment  *Segment `json:"segment"`
	Process  string   `json:"process"`
	LinkHash string   `json:"linkHash"`
}

SegmentReference is a reference to a segment or a linkHash

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.

type Signature added in v0.3.0

type Signature struct {
	// Type of the signature (eg: "EdDSA")
	Type string `json:"type"`

	// PublicKey is the base64 encoded public key that signed the payload
	PublicKey string `json:"publicKey"`

	// Signature is the base64 encoded string containg the signature bytes
	Signature string `json:"signature"`

	// Payload describes what has been signed, It is expressed using the JMESPATH query language.
	Payload string `json:"payload"`
}

Signature contains a user-provided signature of a certain part of the link.

func NewSignature added in v0.3.0

func NewSignature(payloadPath string, privateKey []byte, l *Link) (*Signature, error)

NewSignature creates a new signature for a link. Only the data matching the JMESPATH query will be signed

func (Signature) Verify added in v0.3.0

func (s Signature) Verify(l *Link) error

Verify takes a link as input, computes the signed part using the signature payload and runs the signature verification depending on its type.

type Signatures added in v0.3.0

type Signatures []*Signature

Signatures is a slice of Signature

func (*Signatures) Get added in v0.3.0

func (s *Signatures) Get(publicKey string) *Signature

Get returns the signature matching the provided public key

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