Documentation ¶
Index ¶
- Variables
- func GetRandom(in []string, n int) []string
- func Hash(text string) string
- func HashStringToBytes(hash string) []byte
- func MHash(h1 string, h2 string) string
- func MaxInt(x, y int) int
- func MaxInt64(x, y int64) int64
- func MinInt(x, y int) int
- func MinInt64(x, y int64) int64
- func Shuffle(in []string) (shuffle []string)
- func ToHex(buf []byte) string
- func VerifyMerklePath(hash string, path *MTPath, root string) bool
- type CompactMerkleTree
- type FixedMerkleTree
- type GetRequest
- type GetResponse
- type Hashable
- type HttpClient
- type MTPath
- type MerkleTree
- func (mt *MerkleTree) ComputeTree(hashes []Hashable)
- func (mt *MerkleTree) GetLeafIndex(hash Hashable) int
- func (mt *MerkleTree) GetPath(hash Hashable) *MTPath
- func (mt *MerkleTree) GetPathByIndex(idx int) *MTPath
- func (mt *MerkleTree) GetRoot() string
- func (mt *MerkleTree) GetTree() []string
- func (mt *MerkleTree) SetTree(leavesCount int, tree []string) error
- func (mt *MerkleTree) VerifyPath(hash Hashable, path *MTPath) bool
- type MerkleTreeI
- type PostRequest
- type PostResponse
- type Rand
- type SecureSerializableValue
- type SecureSerializableValueI
- type Serializable
- type StringHashable
Constants ¶
This section is empty.
Variables ¶
var ( // ErrLeafExists leaf has been computed, it can be skipped now ErrLeafExists = goErrors.New("merkle: leaf exists, it can be skipped") // ErrLeafNoSequenced leaf MUST be pushed one by one ErrLeafNoSequenced = goErrors.New("merkle: leaf must be pushed with sequence") )
var ( // ErrNoItem there is no item anymore ErrNoItem = errors.New("rand: there is no item anymore") )
Functions ¶
func HashStringToBytes ¶
HashStringToBytes - convert a hex hash string to bytes
Types ¶
type CompactMerkleTree ¶ added in v1.2.88
type CompactMerkleTree struct { Tree []string `json:"tree"` //node tree with computed as many parent hashes as it can Hash func(left, right string) string `json:"-"` //it should be set once CompactMerkleTree is created Initialized bool `json:"initialized"` LastIndex int `json:"last_index"` //how many leaves has been pushed }
CompactMerkleTree it is a stateful algorithm. It takes data in (leaf nodes), hashes it, and computes as many parent hashes as it can. see detail on https://github.com/0chain/blobber/wiki/Protocols#what-is-compactmerkletree
func NewCompactMerkleTree ¶ added in v1.2.88
func NewCompactMerkleTree(hash func(left, right string) string) *CompactMerkleTree
NewCompactMerkleTree create a CompactMerkleTree with specify hash method
func (*CompactMerkleTree) AddDataBlocks ¶ added in v1.2.88
func (cmt *CompactMerkleTree) AddDataBlocks(buf []byte, index int) error
AddLeaf add leaf hash and update the the Merkle tree.
func (*CompactMerkleTree) AddLeaf ¶ added in v1.2.88
func (cmt *CompactMerkleTree) AddLeaf(leaf string, index int) error
AddLeaf add leaf hash and update the the Merkle tree.
func (*CompactMerkleTree) GetMerkleRoot ¶ added in v1.2.88
func (cmt *CompactMerkleTree) GetMerkleRoot() string
GetMerkleRoot calculate the Merkle root when all leave has been added, For the last, lowest-level hash, we hash it with itself. From there, the nodes are hashed to the top level to calculate the Merkle root.
type FixedMerkleTree ¶ added in v1.2.88
type FixedMerkleTree struct { // ChunkSize size of chunk ChunkSize int `json:"chunk_size,omitempty"` // Leaves a leaf is a CompactMerkleTree for 1/1024 shard data Leaves []*CompactMerkleTree `json:"leaves,omitempty"` }
FixedMerkleTree A trusted mekerl tree for outsourcing attack protection. see section 1.8 on whitepager see detail on https://github.com/0chain/blobber/wiki/Protocols#what-is-fixedmerkletree
func NewFixedMerkleTree ¶ added in v1.2.88
func NewFixedMerkleTree(chunkSize int) *FixedMerkleTree
NewFixedMerkleTree create a FixedMerkleTree with specify hash method
func (*FixedMerkleTree) GetMerkleRoot ¶ added in v1.2.88
func (fmt *FixedMerkleTree) GetMerkleRoot() string
GetMerkleRoot get merkle root
func (*FixedMerkleTree) GetMerkleTree ¶ added in v1.2.88
func (fmt *FixedMerkleTree) GetMerkleTree() MerkleTreeI
GetMerkleRoot get merkle tree
type GetRequest ¶
type GetRequest struct {
*PostRequest
}
func NewHTTPGetRequest ¶
func NewHTTPGetRequest(url string) (*GetRequest, error)
NewHTTPGetRequest create a GetRequest instance with 60s timeout
func NewHTTPGetRequestContext ¶
func NewHTTPGetRequestContext(ctx context.Context, url string) (*GetRequest, error)
NewHTTPGetRequestContext create a GetRequest with context and url
func (*GetRequest) Get ¶
func (r *GetRequest) Get() (*GetResponse, error)
type GetResponse ¶
type GetResponse struct {
*PostResponse
}
type HttpClient ¶
var Client HttpClient
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 Rand ¶ added in v1.2.82
type Rand struct {
// contains filtered or unexported fields
}
Rand a progressive rand
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 ¶
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