hash

package
v1.0.23 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2023 License: ISC Imports: 15 Imported by: 6

README

MeerXKeccakV1

Meer Header

version parent_root tx_root state_root difficulty time pow_type nonce
4 bytes 32 bytes 32 bytes 32 bytes 4 bytes 4 bytes 1 byte 8 bytes
QitmeerKeccak256(NewLegacyKeccak512(NewLegacyKeccak512(header))^1)
MeerXKeccakV1 See Golang Code
QitmeerKeccak256 Use PaddingFix See C Code
QitmeerKeccak256 Use PaddingFix See Golang Code
NewLegacyKeccak512 Use Standard Keccak512
Example
input : 117 bytes
HashMeerXKeccakV1(helloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhel)
result: 046bb4ee0e487afb53c428f5d18f2875951f80330fe39870011ddac6a9c06b1c

Header assemble example
# example 1
header(117 bytes):12000000c24900a189710157b8d020f2d09068ec4ee1eacae6b38753a6304894d0e2104b80eb912fbeb3b6735a4acfb89fd199e0f0abc50a48dccd52e2245e0619755468000000000000000000000000000000000000000000000000000000000000000068db061fda20d75f088f10000000000000
version : 12000000
parent_root :c24900a189710157b8d020f2d09068ec4ee1eacae6b38753a6304894d0e2104b
tx_root :80eb912fbeb3b6735a4acfb89fd199e0f0abc50a48dccd52e2245e0619755468
state_root :0000000000000000000000000000000000000000000000000000000000000000
difficulty : 68db061f
time :da20d75f
pow_type :08
nonce :8f10000000000000(4239)

target: 
0006db6800000000000000000000000000000000000000000000000000000000

meerHash:84499238afb6b544e01032f2ea73d5692ef5d29775daa3a778bfbd2efbb90000

meerHash(reverse):0000b9fb2ebdbf78a7a3da7597d2f52e69d573eaf23210e044b5b6af38924984

Compliance target difficulty

# example 2
header(117 bytes):120000005b42f3a292059337e2097c4077d6578adf4253c63ab74a51d57a3cf330003267b012b719ebfb86d8ea7864307bd0b743980ead38d1f2c06919fc45d6eb604ed9000000000000000000000000000000000000000000000000000000000000000068db061fa421d75f086605000000000000
version : 12000000
parent_root :5b42f3a292059337e2097c4077d6578adf4253c63ab74a51d57a3cf330003267
tx_root :b012b719ebfb86d8ea7864307bd0b743980ead38d1f2c06919fc45d6eb604ed9
state_root :0000000000000000000000000000000000000000000000000000000000000000
difficulty : 68db061f
time :a421d75f
pow_type :08
nonce :6605000000000000(1382)

target: 
0006db6800000000000000000000000000000000000000000000000000000000

meerHash:3b94fab4d25980aca4512b86b32bc96fd7cb8f8fdf3f265ffde45f72688e0100

meerHash(reverse):00018e68725fe4fd5f263fdf8f8fcbd76fc92bb3862b51a4ac8059d2b4fa943b

Compliance target difficulty

Documentation

Overview

Copyright (c) 2017-2018 The qitmeer developers

Copyright (c) 2017-2018 The qitmeer developers

Index

Constants

View Source
const HashSize = 32
View Source
const MaxHashStringSize = HashSize * 2

MaxHashStringSize is the maximum length of a Hash hash string.

Variables

View Source
var ErrHashStrSize = fmt.Errorf("max hash string length is %v bytes", MaxHashStringSize)

ErrHashStrSize describes an error that indicates the caller specified a hash string that has too many characters.

View Source
var ZeroHash = Hash([32]byte{
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
})

Functions

func CalcHash

func CalcHash(buf []byte, hasher h.Hash) []byte

Calculate the hash of hasher over buf.

func Decode

func Decode(dst *Hash, src string) error

Decode decodes the byte-reversed hexadecimal string encoding of a Hash to a destination.

func DoubleHashB

func DoubleHashB(b []byte) []byte

DoubleHashB calculates hash(hash(b)) and returns the resulting bytes.

func DoubleHashB_pool

func DoubleHashB_pool(b []byte) []byte

func Hash160

func Hash160(buf []byte) []byte

Hash160 calculates the hash ripemd160(hash256(b)).

func Hash512B

func Hash512B(b []byte) []byte

Hash512B using blake2b calculates 512 bits hash and returns the resulting bytes.

func HashB

func HashB(b []byte) []byte

HashB using blake2b calculates 256 bits hash and returns the resulting bytes.

func HashB_pool

func HashB_pool(b []byte) []byte

using pool

Types

type Hash

type Hash [HashSize]byte

func DoubleHashH

func DoubleHashH(b []byte) Hash

DoubleHashH calculates hash(hash(b)) and returns the resulting bytes as a Hash.

func DoubleHashH_pool

func DoubleHashH_pool(b []byte) Hash

func HashCryptoNight

func HashCryptoNight(b []byte) Hash

CryptoNight calculates hash(b) and returns the resulting bytes as a Hash.

func HashH

func HashH(b []byte) Hash

HashH calculates hash(b) and returns the resulting bytes as a Hash.

func HashH_pool

func HashH_pool(b []byte) Hash

func HashMeerXKeccakV1

func HashMeerXKeccakV1(input []byte) Hash

Meer X Keccak V1 calculates hash(b) and returns the resulting bytes as a Hash. 2 round of NewLegacyKeccak512 1 round of NewQitmeerKeccak256

func HashQitmeerKeccak256

func HashQitmeerKeccak256(b []byte) Hash

Qitmeer Keccak256 calculates hash(b) and returns the resulting bytes as a Hash.

func HashX16rv3

func HashX16rv3(b []byte) Hash

HashX16rv3 calculates hash(b) and returns the resulting bytes as a Hash.

func HashX8r16

func HashX8r16(b []byte) Hash

HashX8r16 calculates hash(b) and returns the resulting bytes as a Hash.

func MustBytesToDecodeHash

func MustBytesToDecodeHash(b []byte) Hash

convert []byte to a byte-reversed hash, Must means it panics for invalid input.

func MustBytesToHash

func MustBytesToHash(b []byte) Hash

convert []byte to a hash, Must means it panics for invalid input.

func MustHexToDecodedHash

func MustHexToDecodedHash(i string) Hash

convert hex string to a byte-reversed hash, Must means it panics for invalid input.

func MustHexToHash

func MustHexToHash(i string) Hash

convert hex string to a hash. Must means it panics for invalid input.

func NewHash

func NewHash(newHash []byte) (*Hash, error)

NewHash returns a new Hash from a byte slice. An error is returned if the number of bytes passed in is not HashSize.

func NewHashFromStr

func NewHashFromStr(hash string) (*Hash, error)

NewHashFromStr creates a Hash from a hash string. The string should be the hexadecimal string of a byte-reversed hash, but any missing characters result in zero padding at the end of the Hash.

func (Hash) Bytes

func (h Hash) Bytes() []byte

func (*Hash) CloneBytes

func (hash *Hash) CloneBytes() []byte

CloneBytes returns a copy of the bytes which represent the hash as a byte slice.

NOTE: It is generally cheaper to just slice the hash directly thereby reusing the same bytes rather than calling this method.

func (*Hash) IsEqual

func (hash *Hash) IsEqual(target *Hash) bool

IsEqual returns true if target is the same as hash.

func (*Hash) Less added in v1.0.18

func (h *Hash) Less(other *Hash) bool

Less returns true if hash is less than other

func (*Hash) SetBytes

func (hash *Hash) SetBytes(newHash []byte) error

SetBytes sets the bytes which represent the hash. An error is returned if the number of bytes passed in is not HashSize.

func (Hash) String

func (hash Hash) String() string

String returns the Hash as the hexadecimal string of the byte-reversed hash.

func (*Hash) UnmarshalText

func (h *Hash) UnmarshalText(input []byte) error

UnmarshalText decodes the hash from hex. The 0x prefix is optional. TODO clean-up the byte-reverse hash

type Hash256

type Hash256 [32]byte

type Hash512

type Hash512 [64]byte

type HashType

type HashType byte
const (
	SHA256 HashType = iota
	Keccak_256
	SHA3_256
	SHA3_512
	Ripemd160
	Blake2b_256
	Blake2b_512
)

TODO refactoring hasher consider to integrated https://github.com/multiformats/go-multihash

type Hasher

type Hasher interface {
	hash.Hash
}

func GetHasher

func GetHasher(ht HashType) Hasher

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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