hash

package
v0.0.0-...-f94ef0f Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalcMerkleRoot

func CalcMerkleRoot(hashes []common.Hash) common.Hash

CalcMerkleRoot calculcates Merkle root hash value for a given slice of hashes. It doesn't create a full MerkleTree structure and it uses given slice as a scratchpad, so it will destroy its contents in the process. But it's much more memory efficient if you only need root hash value, while NewMerkleTree would make 3*N allocations for N hashes, this function will only make 4. It also is an error to call this function for zero-length hashes slice, the function will panic.

func CalcProofRoot

func CalcProofRoot(target common.Hash, hashes []common.Hash, path uint32) common.Hash

func Checksum

func Checksum(data []byte) []byte

Checksum returns the checksum for a given piece of data using sha256 twice as the hash algorithm.

func DoubleKeccak256

func DoubleKeccak256(data []byte) common.Hash

DoubleSha256 performs sha256 twice on the given data.

func DoubleSha256

func DoubleSha256(data []byte) common.Hash

DoubleSha256 performs sha256 twice on the given data.

func Hash160

func Hash160(data []byte) common.Address

Hash160 performs sha256 and then ripemd160 on the given data.

func Keccak256

func Keccak256(data ...[]byte) (h common.Hash)

Keccak256Hash calculates and returns the Keccak256 hash of the input data, converting it to an internal Hash data structure.

func NetKeccak256

func NetKeccak256(chainId uint64, hh Hashable) common.Hash

NetSha256 calculates network-specific hash of Hashable item that can then be signed/verified.

func NetSha256

func NetSha256(net uint64, hh Hashable) common.Hash

NetSha256 calculates network-specific hash of Hashable item that can then be signed/verified.

func RipeMD160

func RipeMD160(data []byte) common.Address

RipeMD160 performs the RIPEMD160 hash algorithm on the given data.

func RlpHash

func RlpHash(v interface{}) (h common.Hash)

func Sha256

func Sha256(data []byte) common.Hash

Sha256 hashes the incoming byte slice using the sha256 algorithm.

func VerifyMerkleProof

func VerifyMerkleProof(root common.Hash, target common.Hash, hashes []common.Hash, path uint32) bool

Types

type Hashable

type Hashable interface {
	Hash() common.Hash
}

Hashable represents an object which can be hashed. Usually these objects are io.Serializable and signable. They tend to cache the hash inside for effectiveness, providing this accessor method. Anything that can be identified with a hash can then be signed and verified.

type KeccakState

type KeccakState interface {
	hash.Hash
	Read([]byte) (int, error)
}

func NewKeccakState

func NewKeccakState() KeccakState

NewKeccakState creates a new KeccakState

type MerkleTree

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

MerkleTree implementation.

func NewMerkleTree

func NewMerkleTree(hashes []common.Hash) (*MerkleTree, error)

NewMerkleTree returns new MerkleTree object.

func (*MerkleTree) Prove

func (t *MerkleTree) Prove(target common.Hash) ([]common.Hash, uint32, error)

func (*MerkleTree) Root

func (t *MerkleTree) Root() common.Hash

Root returns the computed root hash of the MerkleTree.

type MerkleTreeNode

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

MerkleTreeNode represents a node in the MerkleTree.

func (*MerkleTreeNode) IsLeaf

func (n *MerkleTreeNode) IsLeaf() bool

IsLeaf returns whether this node is a leaf node or not.

func (*MerkleTreeNode) IsRoot

func (n *MerkleTreeNode) IsRoot() bool

IsRoot returns whether this node is a root node or not.

Jump to

Keyboard shortcuts

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