utils

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

This module contains the utility function that are used for various hashing functionality

This module contains the utility function that are used to encode binary objects to different formats and to convert structs into their binary gob formats

Index

Constants

View Source
const DBfile string = "./tmp/db/blocks/MANIFEST"

TODO: MOVE TO A LOCATION OUTSIDE OF THE REPO DIR

View Source
const DBpath string = "./tmp/db/blocks"
View Source
const WalletDB = "./tmp/walletstore.data"
View Source
const WeavePOS = "samite"

Represents the Proof Of Work weave net

View Source
const WeavePOW = "fustian"

Represents the Proof Of Work weave net ID

View Source
const WeaverVersion = "v0.5.0"

Represents the Package Version

Variables

View Source
var UTXOprefix = []byte("utxo-")

Functions

func Base58Decode

func Base58Decode(encodeddata []byte) []byte

A function to decode a Base58 bytes payload into a regular bytes payload

func Base58Encode

func Base58Encode(payload []byte) []byte

A function to encode a bytes payload into a Base58 bytes payload

func CheckSum32

func CheckSum32(payload []byte) []byte

A function that generates a 32bit checksum for a given slice of bytes payload. Generated by truncating a double hashed payload.

checksum32 = first 32 bits of [SHA3-256(SHA3-256(payload))]

func HandleErrorLog

func HandleErrorLog(err error, msg string)

A function that logs a given error and message with the fatal log level and an error field

func Hash160

func Hash160(payload []byte) []byte

A function that generates a 160bit hash output for a given slice of bytes payload.

Generated by hashing the payload with 256 bit hash algorithm, then a 224 bit algorithm and finally truncated to 160bits.

This is equivalent in terms of security to the Bitcoin method of using SHA256 followed by RIPEMD160. The RIPEMD160 algorithm was rejected because of its deprecated nature in the Golang crypto library along with the fact that truncated SHA3 algortithms are equally safe as their full length versions Hence the choice to use truncated SHA3-224 over the SHA1 which outputs 20 byte hashes directly.

hash160 = first 160 bits of [SHA3-224(SHA3-256(payload))]

References: https://bitcoin.stackexchange.com/questions/16543/why-was-the-ripemd-160-hash-algorithms-chosen-before-sha-1 https://crypto.stackexchange.com/questions/3153/sha-256-vs-any-256-bits-of-sha-512-which-is-more-secure

func Hash256

func Hash256(payload []byte) []byte

A function that generates a 256 bit hash output for a given slice of bytes payload.

Generated by double hashing the payload with a 256bit hash algorithm.

The choice to use SHA3 instead of SHA2 is governed by the additional safety offered due to Keccak Sponge Algorithm that breaks away from the common design scheme shared between the SHA2 (current standard) and the SHA1 (broken standard). Additionally, SHA3 is resistant to length extension attacks and is likely to be secure for several generations of computing hardware.

hash256 = SHA3-256(SHA3-256(payload))

References: https://crypto.stackexchange.com/questions/68307/what-is-the-difference-between-sha-3-and-sha-256

func HexDecode

func HexDecode(src []byte) int

A function that decodes and returns an int as from its hex/byte representation

func HexEncode

func HexEncode(number int) []byte

A function that encodes and returns an int as its hex/byte representation

func KeyGenECDSA

func KeyGenECDSA() (ecdsa.PrivateKey, []byte)

A function that generates a pair of digital signature keys based on the ECDSA algorithm using the secp256r1 elliptic curve.

This method of generating cryptographic key pairs creates a pair with 1 in 10^77 chance of collision.

func LogInitialize

func LogInitialize(loglevel logrus.Level)

A function that initializes the log level, formatter and output

Types

This section is empty.

Jump to

Keyboard shortcuts

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