Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support 12-word (128 bit) BIP39 mnemonic strings #28

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/karlsenwallet/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type createConfig struct {
KeysFile string `long:"keys-file" short:"f" description:"Keys file location (default: ~/.karlsenwallet/keys.json (*nix), %USERPROFILE%\\AppData\\Local\\karlsenwallet\\key.json (Windows))"`
Password string `long:"password" short:"p" description:"Wallet password"`
Yes bool `long:"yes" short:"y" description:"Assume \"yes\" to all questions"`
ChosenEntropy int `long:"entropy" short:"e" description:"Set 128 for 12-words seed phrase or 256 for 24-words seed phrase" default:"256"`
MinimumSignatures uint32 `long:"min-signatures" short:"m" description:"Minimum required signatures" default:"1"`
NumPrivateKeys uint32 `long:"num-private-keys" short:"k" description:"Number of private keys" default:"1"`
NumPublicKeys uint32 `long:"num-public-keys" short:"n" description:"Total number of keys" default:"1"`
Expand Down
2 changes: 1 addition & 1 deletion cmd/karlsenwallet/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func create(conf *createConfig) error {
var err error
isMultisig := conf.NumPublicKeys > 1
if !conf.Import {
encryptedMnemonics, signerExtendedPublicKeys, err = keys.CreateMnemonics(conf.NetParams(), conf.NumPrivateKeys, conf.Password, isMultisig)
encryptedMnemonics, signerExtendedPublicKeys, err = keys.CreateMnemonics(conf.NetParams(), conf.NumPrivateKeys, conf.Password, isMultisig, conf.ChosenEntropy)
} else {
encryptedMnemonics, signerExtendedPublicKeys, err = keys.ImportMnemonics(conf.NetParams(), conf.NumPrivateKeys, conf.Password, isMultisig)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/karlsenwallet/keys/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ import (
)

// CreateMnemonics generates `numKeys` number of mnemonics.
func CreateMnemonics(params *dagconfig.Params, numKeys uint32, cmdLinePassword string, isMultisig bool) (encryptedPrivateKeys []*EncryptedMnemonic, extendedPublicKeys []string, err error) {
func CreateMnemonics(params *dagconfig.Params, numKeys uint32, cmdLinePassword string, isMultisig bool, chosenEntropy int) (encryptedPrivateKeys []*EncryptedMnemonic, extendedPublicKeys []string, err error) {
mnemonics := make([]string, numKeys)
for i := uint32(0); i < numKeys; i++ {
var err error
mnemonics[i], err = libkaspawallet.CreateMnemonic()
mnemonics[i], err = libkaspawallet.CreateMnemonic(chosenEntropy)
if err != nil {
return nil, nil, err
}
Expand Down
6 changes: 4 additions & 2 deletions cmd/karlsenwallet/libkaspawallet/bip39.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import (
)

// CreateMnemonic creates a new bip-39 compatible mnemonic
func CreateMnemonic() (string, error) {
const bip39BitSize = 256
func CreateMnemonic(bip39BitSize int) (string, error) {
if bip39BitSize == 0 {
bip39BitSize = 256
}
entropy, _ := bip39.NewEntropy(bip39BitSize)
return bip39.NewMnemonic(entropy)
}
Expand Down