rand

package
v0.0.0-...-d9e9996 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2019 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// int8 类型
	KeyLengthInt8 = 8

	// int16 类型
	KeyLengthInt16 = 16

	// int32 类型
	KeyLengthInt32 = 32

	// int64 类型
	KeyLengthInt64 = 64
)

定义不同int类型对应的key length

View Source
const (
	// KeyStrengthEasy 安全强度低
	KeyStrengthEasy = iota

	// KeyStrengthMiddle 安全强度中
	KeyStrengthMiddle

	// KeyStrengthHard 安全强度高
	KeyStrengthHard
)
View Source
const (
	// 不同语言标准不一样,这里用const直接定义值还是好一些
	// 简体中文
	SimplifiedChinese = 1

	// 英文
	English = 2
)

定义助记词的语言类型

Variables

View Source
var (
	// ErrInvalidRawEntropyLength 原始熵的长度不在 [120, 248]以内或者+8后的长度不是32的倍数
	ErrInvalidRawEntropyLength = errors.New("Entropy length must within [120, 248] and after +8 be multiples of 32")

	// ErrInvalidEntropyLength 熵的长度不在 [128, 256]以内或者长度不是32的倍数
	ErrInvalidEntropyLength = errors.New("Entropy length must within [128, 256] and be multiples of 32")

	// ErrStrengthNotSupported 助记词的强度暂未被支持
	// Strength required for generating Mnemonic not supported yet.
	ErrStrengthNotSupported = fmt.Errorf("This strength has not been supported yet")

	// ErrLanguageNotSupported 助记词的语言类型暂未被支持
	// Language required for generating Mnemonic not supported yet.
	ErrLanguageNotSupported = fmt.Errorf("This language has not been supported yet")

	// ErrMnemonicNumNotValid 助记词语句中包含的助记词的数量不合法,只能是12, 15, 18, 21, 24
	ErrMnemonicNumNotValid = fmt.Errorf("The number of words in the Mnemonic sentence is not valid. It must be within [12, 15, 18, 21, 24]")

	// ErrMnemonicChecksumIncorrect 助记词语句中包含的校验位的格式不合法
	ErrMnemonicChecksumIncorrect = errors.New("The checksum within the Mnemonic sentence incorrect")
)
View Source
var (
	// 11111111111 - 11个1,当一个大的bigint和它进行“And”比特运算的时候,就会获得大的bigint最右边11位的比特位
	Last11BitsMask = big.NewInt(2047)

	// 100000000000 - 除以这个带有11个0的数等于右移11个比特位
	RightShift11BitsDivider = big.NewInt(2048)

	// 1
	BigOne = big.NewInt(1)

	// 10
	BigTwo = big.NewInt(2)
)

BigInt相关的比特位运算常量

Functions

func GenerateEntropy

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

GenerateEntropy 底层调用跟操作系统相关的函数(读取系统熵)来产生一些伪随机数, 对外建议管这个返回值叫做“熵”

func GenerateMnemonic

func GenerateMnemonic(entropy []byte, language int) (string, error)

GenerateMnemonic 根据参数中提供的熵来生成一串助记词。 参数中的熵应该是调用GenerateEntropy函数生成的熵。

func GenerateOldMnemonic

func GenerateOldMnemonic(entropy []byte, language int) (string, error)

GenerateOldMnemonic 根据参数中提供的熵来生成一串助记词。 参数中的熵应该是调用GenerateEntropy函数生成的熵。

func GenerateSeedWithErrorChecking

func GenerateSeedWithErrorChecking(mnemonic string, password string, keyLen int, language int) ([]byte, error)

GenerateSeedWithErrorChecking 带有错误检查。通过用户输入的助记词串(之前函数生成的)和用户指定的密码,来生成一个随机数种子 会校验助记词串是否

func GenerateSeedWithStrengthAndKeyLen

func GenerateSeedWithStrengthAndKeyLen(strength int, keyLength int) ([]byte, error)

GenerateSeedWithStrengthAndKeyLen generates key seed with specified strength and length

func GetEntropyFromMnemonic

func GetEntropyFromMnemonic(mnemonic string, language int) ([]byte, error)

GetEntropyFromMnemonic 从助记词提取原始熵的byte数组

func GetEntropyFromOldMnemonic

func GetEntropyFromOldMnemonic(mnemonic string, language int) ([]byte, error)

GetEntropyFromOldMnemonic 从助记词提取原始熵的byte数组

func GetWordsFromValidMnemonicSentence

func GetWordsFromValidMnemonicSentence(mnemonic string, language int) ([]string, error)

GetWordsFromValidMnemonicSentence 检查助记词字符串是否有效,如果有效,返回助记词

Types

This section is empty.

Jump to

Keyboard shortcuts

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