Skip to content

Commit

Permalink
Implements mnemonic for full key
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashy5000 committed Apr 10, 2024
1 parent 60ed130 commit 061d186
Show file tree
Hide file tree
Showing 12 changed files with 21 additions and 19 deletions.
Binary file modified builds/node/node_darwin-amd64
Binary file not shown.
Binary file modified builds/node/node_darwin-arm64
Binary file not shown.
Binary file modified builds/node/node_linux-386
Binary file not shown.
Binary file modified builds/node/node_linux-amd64
Binary file not shown.
Binary file modified builds/node/node_linux-arm
Binary file not shown.
Binary file modified builds/node/node_linux-arm64
Binary file not shown.
Binary file modified builds/node/node_windows-386
Binary file not shown.
Binary file modified builds/node/node_windows-amd64
Binary file not shown.
Binary file modified builds/node/node_windows-arm
Binary file not shown.
Binary file modified builds/node/node_windows-arm64
Binary file not shown.
13 changes: 11 additions & 2 deletions cmdline.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,17 @@ func RunCmd(input string) {
if err != nil {
panic(err)
}
mnemonic := GetMnemonic(privateKey)
fmt.Println("Mnemonic: " + mnemonic)
mnemonic0 := GetMnemonic(*privateKey.X)
mnemonic1 := GetMnemonic(*privateKey.PublicKey.Y)
mnemonic2 := GetMnemonic(*privateKey.PublicKey.Parameters.P)
mnemonic3 := GetMnemonic(*privateKey.PublicKey.Parameters.Q)
mnemonic4 := GetMnemonic(*privateKey.PublicKey.Parameters.G)
fmt.Println("Mnemonic:")
fmt.Println("Part 0: " + mnemonic0)
fmt.Println("Part 1: " + mnemonic1)
fmt.Println("Part 2: " + mnemonic2)
fmt.Println("Part 3: " + mnemonic3)
fmt.Println("Part 4: " + mnemonic4)
fmt.Println("Write down the mnemonic and keep it safe, or better yet memorize it. It is the ONLY WAY to recover your private key.")
} else if action == "encrypt" {
// Ask the user for a password
Expand Down
27 changes: 10 additions & 17 deletions mnemonic.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ You should have received a copy of the GNU General Public License along with thi
package main

import (
"crypto/dsa"
"fmt"
"math/big"
"strings"
)
Expand Down Expand Up @@ -129,31 +127,29 @@ var words = map[string]string{
"9!": "banana",
}

func GetMnemonic(key dsa.PrivateKey) string {
func GetMnemonic(source big.Int) string {
// Get each group of 2 digits from the key and convert it to a word.
// Convert the key to a string.
keyString := key.X.String()
sourceString := source.String()
// Split the string into groups of 2 digits.
var groups []string
if len(keyString)%2 != 0 {
keyString = keyString + "!"
if len(sourceString)%2 != 0 {
sourceString += "!"
}
for i := 0; i < len(keyString); i += 2 {
groups = append(groups, keyString[i:i+2])
for i := 0; i < len(sourceString); i += 2 {
groups = append(groups, sourceString[i:i+2])
}
fmt.Println(groups)
// Convert each group of 2 digits to a word.
var mnemonic string

for _, group := range groups {
mnemonic += words[group] + " "
}

fmt.Println(mnemonic)
return mnemonic
}

func RestoreMnemonic(mnemonic string) dsa.PrivateKey {
func RestoreMnemonic(mnemonic string) big.Int {
// Split the mnemonic into words.
mnemonicWords := strings.Split(mnemonic, " ")
// Convert each word to a group of 2 digits.
Expand All @@ -172,10 +168,7 @@ func RestoreMnemonic(mnemonic string) dsa.PrivateKey {
keyString = keyString[:len(keyString)-1]
}
// Convert the string to a big.Int.
key := dsa.PrivateKey{
PublicKey: dsa.PublicKey{},
X: big.NewInt(0),
}
key.X.SetString(keyString, 10)
return key
var restored big.Int
restored.SetString(keyString, 10)
return restored
}

0 comments on commit 061d186

Please sign in to comment.