hash

package
v0.107.1 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2024 License: MIT Imports: 5 Imported by: 16

Documentation

Overview

Package hash contains wrappers for Neo hashing algorithms.

It also implements Merkle tree.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalcMerkleRoot added in v0.92.0

func CalcMerkleRoot(hashes []util.Uint256) util.Uint256

CalcMerkleRoot calculates the Merkle root hash value for the given slice of hashes. It doesn't create a full MerkleTree structure and it uses the 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 a root hash value. While NewMerkleTree would make 3*N allocations for N hashes, this function will only make 4.

func Checksum

func Checksum(data []byte) []byte

Checksum returns the checksum for a given piece of data using DoubleSha256 as the hash algorithm. It returns the first 4 bytes of the resulting slice.

func DoubleSha256

func DoubleSha256(data []byte) util.Uint256

DoubleSha256 performs sha256 twice on the given data.

func GetSignedData added in v0.106.0

func GetSignedData(net uint32, hh Hashable) []byte

GetSignedData returns the concatenated byte slice containing of the network magic in constant-length 4-bytes LE representation and hashable item hash in BE representation.

func Hash160

func Hash160(data []byte) util.Uint160

Hash160 performs sha256 and then ripemd160 on the given data.

func NetSha256 added in v0.94.1

func NetSha256(net uint32, hh Hashable) util.Uint256

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

func RipeMD160

func RipeMD160(data []byte) util.Uint160

RipeMD160 performs the RIPEMD160 hash algorithm on the given data.

func Sha256

func Sha256(data []byte) util.Uint256

Sha256 hashes the incoming byte slice using the sha256 algorithm.

Types

type Hashable added in v0.94.1

type Hashable interface {
	Hash() util.Uint256
}

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 MerkleTree

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

MerkleTree implementation.

func NewMerkleTree

func NewMerkleTree(hashes []util.Uint256) (*MerkleTree, error)

NewMerkleTree returns a new MerkleTree object.

func (*MerkleTree) Root

func (t *MerkleTree) Root() util.Uint256

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