Skip to content

Commit

Permalink
Merge pull request #28 from dfinity/enzoh/24-word-seed-phrases
Browse files Browse the repository at this point in the history
Support seed phrases of different sizes.
  • Loading branch information
enzoh authored Sep 27, 2021
2 parents 74c20ed + cc06703 commit 9241ee3
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 5 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ jobs:
strategy:
matrix:
os:
- ubuntu-16.04
- ubuntu-18.04
- ubuntu-20.04
- ubuntu-latest
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## v1.6.2

- Add support for seed phrases of different sizes.

## v1.6.1

- Upgrade encoding library.
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MAJOR ?= 1
MINOR ?= 6
PATCH ?= 1
PATCH ?= 2

LDFLAGS := -X=main.MAJOR=$(MAJOR)
LDFLAGS += -X=main.MINOR=$(MINOR)
Expand Down
4 changes: 3 additions & 1 deletion cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,22 @@ type GenerateCmd struct {
}

type GenerateCmdArgs struct {
Bits *int
OutputFile *string
}

func NewGenerateCmd() *GenerateCmd {
fset := flag.NewFlagSet(GENERATE_CMD, flag.ExitOnError)
args := &GenerateCmdArgs{
Bits: fset.Int("b", 128, "Bits of entropy."),
OutputFile: fset.String("o", "seed.txt", "Seed file."),
}
return &GenerateCmd{fset, args}
}

func (cmd *GenerateCmd) Run() error {
cmd.FlagSet.Parse(os.Args[2:])
entropy, err := bip39.NewEntropy(128)
entropy, err := bip39.NewEntropy(*cmd.Args.Bits)
if err != nil {
return err
}
Expand Down
19 changes: 17 additions & 2 deletions e2e/bash/test.bats
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,21 @@ teardown() {
assert_command $keysmith generate -o=alternate.txt
assert_command cat alternate.txt
assert_match "^([a-z]+( |$)){12}"
assert_command $keysmith generate -b=128 -o=alternate12.txt
assert_command cat alternate12.txt
assert_match "^([a-z]+( |$)){12}"
assert_command $keysmith generate -b=160 -o=alternate15.txt
assert_command cat alternate15.txt
assert_match "^([a-z]+( |$)){15}"
assert_command $keysmith generate -b=192 -o=alternate18.txt
assert_command cat alternate18.txt
assert_match "^([a-z]+( |$)){18}"
assert_command $keysmith generate -b=224 -o=alternate21.txt
assert_command cat alternate21.txt
assert_match "^([a-z]+( |$)){21}"
assert_command $keysmith generate -b=256 -o=alternate24.txt
assert_command cat alternate24.txt
assert_match "^([a-z]+( |$)){24}"
}

@test "Can generate the seed phrase and print it to stdout" {
Expand Down Expand Up @@ -58,7 +73,7 @@ teardown() {

@test "Can derive the extended private key and print it to stdout" {
assert_command $keysmith generate -o=alternate.txt
assert_command $keysmith x-private-key -f=alternate.txt -o=-
assert_command $keysmith x-private-key -f=alternate.txt -o=-
assert_match "^xprv[A-HJ-NP-Za-km-z1-9]"
}

Expand Down Expand Up @@ -288,7 +303,7 @@ N3d26cRxD99TPtm8uo2OuzKhSiq6EQ==

@test "Can derive the private key and print it to stdout" {
assert_command $keysmith generate -o=alternate.txt
assert_command $keysmith private-key -f=alternate.txt -o=-
assert_command $keysmith private-key -f=alternate.txt -o=-
assert_match "^-----BEGIN EC PARAMETERS-----
BgUrgQQACg==
-----END EC PARAMETERS-----
Expand Down

0 comments on commit 9241ee3

Please sign in to comment.