entropy

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2019 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEntropyLengthInvalid = errors.New("entropy length must be [128, 256] and a multiple of 32")
	ErrBitsChecksumLength   = errors.New("bits and checksum length error")
)

Functions

func FromHex

func FromHex(input string) ([]byte, error)

FromHex creates entropy bits from a hex string

func Random

func Random(bitSize int) ([]byte, error)

Random creates a random entropy of the given length 助记词长度和随机值位数之间的关系 -----|----------|---------------|-------| bits | checksum | bits+checksum | words | -----|----------|---------------|-------| 128 | 4 | 132 | 12 | -----|----------|---------------|-------| 160 | 5 | 165 | 15 | -----|----------|---------------|-------| 192 | 6 | 198 | 18 | -----|----------|---------------|-------| 224 | 7 | 231 | 21 | -----|----------|---------------|-------| 256 | 8 | 264 | 24 | -----|----------|---------------|-------|

Types

type Bits

type Bits []byte

Bits represents a byte slice of individual bits

func BitsToBytes

func BitsToBytes(bits Bits) (ent []byte, chksum Bits)

助记词长度和随机值位数之间的关系 -----|----------|---------------|-------| bits | checksum | bits+checksum | words | -----|----------|---------------|-------| 128 | 4 | 132 | 12 | -----|----------|---------------|-------| 160 | 5 | 165 | 15 | -----|----------|---------------|-------| 192 | 6 | 198 | 18 | -----|----------|---------------|-------| 224 | 7 | 231 | 21 | -----|----------|---------------|-------| 256 | 8 | 264 | 24 | -----|----------|---------------|-------| length := len(bits) // bits+checksum chks := length / 32 // checksum bits bitsLen := length - chks // bits length

func CheckSum

func CheckSum(ent []byte) Bits

CheckSum returns a slice of bits from the given entropy

func CheckSummed

func CheckSummed(ent []byte) Bits

CheckSummed returns a bit slice of entropy with an appended check sum

Jump to

Keyboard shortcuts

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