rand

package
v0.0.0-...-ea90456 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2023 License: Apache-2.0 Imports: 12 Imported by: 13

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 = iota

	// 安全强度中
	KeyStrengthMiddle

	// 安全强度高
	KeyStrengthHard
)
View Source
const (

	// 简体中文
	SimplifiedChinese = 1

	// 英文
	English = 2
)

定义助记词的语言类型

Variables

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

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

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

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

	// 助记词语句中包含的助记词的数量不合法,只能是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 = 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)

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

func GenerateMnemonic

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

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

func GenerateOldMnemonic

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

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

func GenerateSeedWithErrorChecking

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

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

func GenerateSeedWithStrengthAndKeyLen

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

func GetEntropyFromMnemonic

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

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

func GetEntropyFromOldMnemonic

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

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

func GetWordsFromValidMnemonicSentence

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

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

Types

This section is empty.

Jump to

Keyboard shortcuts

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