binary

package
v6.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2019 License: ISC Imports: 6 Imported by: 0

Documentation

Overview

Package binary contains hashing/base encoding code shared throughout the codebase.

Index

Examples

Constants

View Source
const (
	Base58c = ObjectEncoding("b58c")
	Base64c = ObjectEncoding("b64c")
)

Base58/Base64 encoding definitions

View Source
const (
	// Prefix separator
	PrefixSeparator = "_"

	// Base58 encoded bytearrays
	PrefixAccountPubkey         = HashPrefix("ak_")
	PrefixBlockProofOfFraudHash = HashPrefix("bf_")
	PrefixBlockStateHash        = HashPrefix("bs_")
	PrefixBlockTransactionHash  = HashPrefix("bx_")
	PrefixChannel               = HashPrefix("ch_")
	PrefixCommitment            = HashPrefix("cm_")
	PrefixContractPubkey        = HashPrefix("ct_")
	PrefixKeyBlockHash          = HashPrefix("kh_")
	PrefixMicroBlockHash        = HashPrefix("mh_")
	PrefixName                  = HashPrefix("nm_")
	PrefixOraclePubkey          = HashPrefix("ok_")
	PrefixOracleQueryID         = HashPrefix("oq_")
	PrefixPeerPubkey            = HashPrefix("pp_")
	PrefixSignature             = HashPrefix("sg_")
	PrefixTransactionHash       = HashPrefix("th_")

	// Base64 encoded bytearrays
	PrefixByteArray         = HashPrefix("ba_")
	PrefixContractByteArray = HashPrefix("cb_")
	PrefixOracleResponse    = HashPrefix("or_")
	PrefixOracleQuery       = HashPrefix("ov_")
	PrefixProofOfInclusion  = HashPrefix("pi_")
	PrefixStateTrees        = HashPrefix("ss_")
	PrefixState             = HashPrefix("st_")
	PrefixTransaction       = HashPrefix("tx_")
)

Prefixes

Variables

This section is empty.

Functions

func Blake2bHash

func Blake2bHash(in []byte) (out []byte, err error)

Blake2bHash calculates the blake2b 32bit hash of the input byte array

func Decode

func Decode(in string) (out []byte, err error)

Decode a string encoded with base58/base64 + checksum to a byte array

in aeternity, bytearrays are always base-encoded with a prefix that indicates what the bytearray is. For example, accounts "ak_...." are a plain bytearray that is base58 encoded and prefixed with "ak_" to indicate that it is an account.

Example
b, err := Decode("ak_Egp9yVdpxmvAfQ7vsXGvpnyfNq71msbdUpkMNYGTeTe8kPL3v")
if err != nil {
	return
}
fmt.Println(b)
Output:

[31 19 163 176 139 240 1 64 6 98 166 139 105 216 117 247 128 60 236 76 8 100 127 110 213 216 76 120 151 189 80 163]

func DecodeRLPMessage

func DecodeRLPMessage(rawBytes []byte) []interface{}

DecodeRLPMessage takes an RLP serialized bytearray and parses the RLP to return the deserialized, structured data as bytearrays ([]interfaces that should be later coerced into specific types). Only meant for debugging purposes - to parse serialized RLP into a useful type, see DeseralizeTx.

func Encode

func Encode(prefix HashPrefix, data []byte) string

Encode a byte array into base58/base64 with checksum and a prefix.

in aeternity, bytearrays are always base-encoded with a prefix that indicates what the bytearray is. For example, accounts "ak_...." are a plain bytearray that is base58 encoded and prefixed with "ak_" to indicate that it is an account.

Example
addrB := []byte{31, 19, 163, 176, 139, 240, 1, 64, 6, 98, 166, 139, 105, 216, 117, 247, 128, 60, 236, 76, 8, 100, 127, 110, 213, 216, 76, 120, 151, 189, 80, 163}

addr := Encode("ak_", addrB)
fmt.Println(addr)
Output:

ak_Egp9yVdpxmvAfQ7vsXGvpnyfNq71msbdUpkMNYGTeTe8kPL3v

Types

type HashPrefix

type HashPrefix string

HashPrefix describes a prefix that is attached to every base-encoded bytearray used in aeternity to describe its function.

For example, the "ak_" HashPrefix describes an account address and "ct_" HashPrefix describes a contract address.

func GetHashPrefix

func GetHashPrefix(hash string) (p HashPrefix)

GetHashPrefix returns a HashPrefix of a string. It panics if the hash contains only the prefix (length 3).

type ObjectEncoding

type ObjectEncoding string

ObjectEncoding is an enum string that describes whether a bytearray is base58 or base64 encoded

Jump to

Keyboard shortcuts

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