util

package
v1.0.65 Latest Latest
Warning

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

Go to latest
Published: May 18, 2020 License: MIT Imports: 12 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetRandom

func GetRandom(in []string, n int) []string

GetRandom returns n random slice from in

func Hash

func Hash(text string) string

Hash - the hashing used for the merkle tree construction

func HashStringToBytes

func HashStringToBytes(hash string) []byte

HashStringToBytes - convert a hex hash string to bytes

func MHash

func MHash(h1 string, h2 string) string

MHash - merkle hashing of a pair of child hashes

func MaxInt

func MaxInt(x, y int) int

func MaxInt64

func MaxInt64(x, y int64) int64

func MinInt

func MinInt(x, y int) int

func MinInt64

func MinInt64(x, y int64) int64

func ToHex

func ToHex(buf []byte) string

ToHex - converts a byte array to hex encoding with upper case

func VerifyMerklePath

func VerifyMerklePath(hash string, path *MTPath, root string) bool

Types

type GetRequest

type GetRequest struct {
	*PostRequest
}

func NewHTTPGetRequest

func NewHTTPGetRequest(url string) (*GetRequest, error)

func NewHTTPGetRequestContext

func NewHTTPGetRequestContext(ctx context.Context, url string) (
	gr *GetRequest, err error)

func (*GetRequest) Get

func (r *GetRequest) Get() (*GetResponse, error)

type GetResponse

type GetResponse struct {
	*PostResponse
}

type Hashable

type Hashable interface {
	GetHash() string
	GetHashBytes() []byte
}

Hashable - anything that can provide it's hash

type MTPath

type MTPath struct {
	Nodes     []string `json:"nodes"`
	LeafIndex int      `json:"leaf_index"`
}

MTPath - The merkle tree path

type MerkleTree

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

MerkleTree - A data structure that implements MerkleTreeI interface

func (*MerkleTree) ComputeTree

func (mt *MerkleTree) ComputeTree(hashes []Hashable)

ComputeTree - given the leaf nodes, compute the merkle tree

func (*MerkleTree) GetLeafIndex

func (mt *MerkleTree) GetLeafIndex(hash Hashable) int

GetLeafIndex - Get the index of the leaf node in the tree

func (*MerkleTree) GetPath

func (mt *MerkleTree) GetPath(hash Hashable) *MTPath

GetPath - get the path that can be used to verify the merkle tree

func (*MerkleTree) GetPathByIndex

func (mt *MerkleTree) GetPathByIndex(idx int) *MTPath

GetPathByIndex - get the path of a leaf node at index i

func (*MerkleTree) GetRoot

func (mt *MerkleTree) GetRoot() string

GetRoot - get the root of the merkle tree

func (*MerkleTree) GetTree

func (mt *MerkleTree) GetTree() []string

GetTree - get the entire merkle tree

func (*MerkleTree) SetTree

func (mt *MerkleTree) SetTree(leavesCount int, tree []string) error

SetTree - set the entire merkle tree

func (*MerkleTree) VerifyPath

func (mt *MerkleTree) VerifyPath(hash Hashable, path *MTPath) bool

VerifyPath - given a leaf node and the path, verify that the node is part of the tree

type MerkleTreeI

type MerkleTreeI interface {
	//API to create a tree from leaf nodes
	ComputeTree(hashes []Hashable)
	GetRoot() string
	GetTree() []string

	//API to load an existing tree
	SetTree(leavesCount int, tree []string) error

	// API for verification when the leaf node is known
	GetPath(hash Hashable) *MTPath               // Server needs to provide this
	VerifyPath(hash Hashable, path *MTPath) bool //This is only required by a client but useful for testing

	/* API for random verification when the leaf node is uknown
	(verification of the data to hash used as leaf node is outside this API) */
	GetPathByIndex(idx int) *MTPath
}

MerkleTreeI - a merkle tree interface required for constructing and providing verification

type PostRequest

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

func NewHTTPPostRequest

func NewHTTPPostRequest(url string, data interface{}) (*PostRequest, error)

func (*PostRequest) Post

func (r *PostRequest) Post() (*PostResponse, error)

type PostResponse

type PostResponse struct {
	Url        string
	StatusCode int
	Status     string
	Body       string
}

type SecureSerializableValue

type SecureSerializableValue struct {
	Buffer []byte
}

SecureSerializableValue - a proxy persisted value that just tracks the encoded bytes of a persisted value

func (*SecureSerializableValue) Decode

func (spv *SecureSerializableValue) Decode(buf []byte) error

Decode - implement interface

func (*SecureSerializableValue) Encode

func (spv *SecureSerializableValue) Encode() []byte

Encode - implement interface

func (*SecureSerializableValue) GetHash

func (spv *SecureSerializableValue) GetHash() string

GetHash - implement interface

func (*SecureSerializableValue) GetHashBytes

func (spv *SecureSerializableValue) GetHashBytes() []byte

GetHashBytes - implement interface

type SecureSerializableValueI

type SecureSerializableValueI interface {
	Serializable
	Hashable
}

SecureSerializableValueI an interface that makes a serializable value secure with hashing

type Serializable

type Serializable interface {
	Encode() []byte
	Decode([]byte) error
}

Serializable interface

type StringHashable

type StringHashable struct {
	Hash string
}

func NewStringHashable

func NewStringHashable(hash string) *StringHashable

func (*StringHashable) GetHash

func (sh *StringHashable) GetHash() string

func (*StringHashable) GetHashBytes

func (sh *StringHashable) GetHashBytes() []byte

Jump to

Keyboard shortcuts

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