aboutsummaryrefslogtreecommitdiffstats
path: root/ethcrypto/mnemonic.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-08-21 21:46:26 +0800
committerobscuren <geffobscura@gmail.com>2014-08-21 21:46:26 +0800
commit0af0f0d890120e007ce42f072e1ee179a62115d3 (patch)
tree5ae9ecafbb729d1636fadfcfa49fd9100959560c /ethcrypto/mnemonic.go
parentd761af84c83ae8d9d723e6766abb7950ff59cdf3 (diff)
parentc173e9f4ab463cf3a44d35215bc29d846d6f6b02 (diff)
downloaddexon-0af0f0d890120e007ce42f072e1ee179a62115d3.tar.gz
dexon-0af0f0d890120e007ce42f072e1ee179a62115d3.tar.zst
dexon-0af0f0d890120e007ce42f072e1ee179a62115d3.zip
Merge branch 'release/0.6.3'
Diffstat (limited to 'ethcrypto/mnemonic.go')
-rw-r--r--ethcrypto/mnemonic.go43
1 files changed, 6 insertions, 37 deletions
diff --git a/ethcrypto/mnemonic.go b/ethcrypto/mnemonic.go
index b8df2ad6f..5fb620219 100644
--- a/ethcrypto/mnemonic.go
+++ b/ethcrypto/mnemonic.go
@@ -2,40 +2,9 @@ package ethcrypto
import (
"fmt"
- "io/ioutil"
- "os"
- "path"
- "path/filepath"
"strconv"
- "strings"
)
-func InitWords(wordsPath string) {
- filename := path.Join(wordsPath, "mnemonic.words.lst")
- if _, err := os.Stat(filename); os.IsNotExist(err) {
- fmt.Printf("reading mnemonic word list file from supplied path not found. Looked in %s. Trying next option.\n", filename)
-
- dir := path.Join(os.Getenv("GOPATH"), "src", "github.com", "ethereum", "eth-go", "ethcrypto")
- filename = path.Join(dir, "mnemonic.words.lst")
- if _, err := os.Stat(filename); os.IsNotExist(err) {
- fmt.Printf("reading mnemonic word list file 'mnemonic.words.lst' from source folder failed: %s.\n", filename)
- dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
- if err != nil {
- panic(fmt.Errorf("problem getting current folder: ", err))
- }
- filename = path.Join(dir, "mnemonic.words.lst")
- }
- }
-
- content, err := ioutil.ReadFile(filename)
- if err != nil {
- panic(fmt.Errorf("All options for finding the mnemonic word list file 'mnemonic.words.lst' failed: ", err))
- }
- words = strings.Split(string(content), "\n")
-}
-
-var words []string
-
// TODO: See if we can refactor this into a shared util lib if we need it multiple times
func IndexOf(slice []string, value string) int64 {
for p, v := range slice {
@@ -48,7 +17,7 @@ func IndexOf(slice []string, value string) int64 {
func MnemonicEncode(message string) []string {
var out []string
- n := int64(len(words))
+ n := int64(len(MnemonicWords))
for i := 0; i < len(message); i += (len(message) / 8) {
x := message[i : i+8]
@@ -56,22 +25,22 @@ func MnemonicEncode(message string) []string {
w1 := (bit % n)
w2 := ((bit / n) + w1) % n
w3 := ((bit / n / n) + w2) % n
- out = append(out, words[w1], words[w2], words[w3])
+ out = append(out, MnemonicWords[w1], MnemonicWords[w2], MnemonicWords[w3])
}
return out
}
func MnemonicDecode(wordsar []string) string {
var out string
- n := int64(len(words))
+ n := int64(len(MnemonicWords))
for i := 0; i < len(wordsar); i += 3 {
word1 := wordsar[i]
word2 := wordsar[i+1]
word3 := wordsar[i+2]
- w1 := IndexOf(words, word1)
- w2 := IndexOf(words, word2)
- w3 := IndexOf(words, word3)
+ w1 := IndexOf(MnemonicWords, word1)
+ w2 := IndexOf(MnemonicWords, word2)
+ w3 := IndexOf(MnemonicWords, word3)
y := (w2 - w1) % n
z := (w3 - w2) % n