add entropyStrength type
This commit is contained in:
parent
3d71a3868a
commit
a1da71e968
|
@ -41,6 +41,21 @@ const (
|
|||
totalAvailableLanguages
|
||||
)
|
||||
|
||||
type entropyStrength int
|
||||
|
||||
const (
|
||||
// EntropyStrength128 defines an entropy strength of 128 bits
|
||||
EntropyStrength128 = entropyStrength(128)
|
||||
// EntropyStrength160 defines an entropy strength of 160 bits
|
||||
EntropyStrength160 = entropyStrength(160)
|
||||
// EntropyStrength192 defines an entropy strength of 192 bits
|
||||
EntropyStrength192 = entropyStrength(192)
|
||||
// EntropyStrength224 defines an entropy strength of 224 bits
|
||||
EntropyStrength224 = entropyStrength(224)
|
||||
// EntropyStrength256 defines an entropy strength of 256 bits
|
||||
EntropyStrength256 = entropyStrength(256)
|
||||
)
|
||||
|
||||
// Languages is a list of supported languages for which mnemonic keys can be generated
|
||||
var Languages = [...]string{
|
||||
"English",
|
||||
|
@ -123,7 +138,7 @@ func (m *Mnemonic) MnemonicSeed(mnemonic string, password string) []byte {
|
|||
}
|
||||
|
||||
// MnemonicPhrase returns a human readable seed for BIP32 Hierarchical Deterministic Wallets
|
||||
func (m *Mnemonic) MnemonicPhrase(strength int, language Language) (string, error) {
|
||||
func (m *Mnemonic) MnemonicPhrase(strength entropyStrength, language Language) (string, error) {
|
||||
wordList, err := m.WordList(language)
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
|
|
@ -22,7 +22,7 @@ func TestMnemonicPhrase(t *testing.T) {
|
|||
mnemonic := NewMnemonic(Salt)
|
||||
|
||||
// test strength validation
|
||||
strengths := []int{127, 129, 257}
|
||||
strengths := []entropyStrength{127, 129, 257}
|
||||
for _, s := range strengths {
|
||||
_, err := mnemonic.MnemonicPhrase(s, EnglishLanguage)
|
||||
if err != ErrInvalidEntropyStrength {
|
||||
|
@ -33,7 +33,7 @@ func TestMnemonicPhrase(t *testing.T) {
|
|||
// test mnemonic generation
|
||||
t.Log("Test mnemonic generation:")
|
||||
for _, language := range mnemonic.AvailableLanguages() {
|
||||
phrase, err := mnemonic.MnemonicPhrase(128, language)
|
||||
phrase, err := mnemonic.MnemonicPhrase(EntropyStrength128, language)
|
||||
t.Logf("Mnemonic (%s): %s", Languages[language], phrase)
|
||||
|
||||
if err != nil {
|
||||
|
|
|
@ -48,7 +48,7 @@ func NewManager(nodeManager common.NodeManager) *Manager {
|
|||
func (m *Manager) CreateAccount(password string) (address, pubKey, mnemonic string, err error) {
|
||||
// generate mnemonic phrase
|
||||
mn := extkeys.NewMnemonic(extkeys.Salt)
|
||||
mnemonic, err = mn.MnemonicPhrase(128, extkeys.EnglishLanguage)
|
||||
mnemonic, err = mn.MnemonicPhrase(extkeys.EntropyStrength128, extkeys.EnglishLanguage)
|
||||
if err != nil {
|
||||
return "", "", "", fmt.Errorf("can not create mnemonic seed: %v", err)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue