Skip to content

Commit

Permalink
EdX25519Key.PaperKey
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriel committed Apr 1, 2021
1 parent 474087d commit 1f5d721
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
8 changes: 8 additions & 0 deletions edx25519.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ func (k *EdX25519Key) Signer() crypto.Signer {
return ed25519.PrivateKey(k.Private())
}

func (k *EdX25519Key) PaperKey() string {
s, err := encoding.BytesToPhrase(k.Seed()[:])
if err != nil {
panic(err)
}
return s
}

// MarshalText for encoding.TextMarshaler interface.
func (k *EdX25519Key) MarshalText() ([]byte, error) {
return []byte(encoding.MustEncode(k.Seed()[:], encoding.Base64)), nil
Expand Down
8 changes: 7 additions & 1 deletion edx25519_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,16 @@ func TestEdX25519KeySeed(t *testing.T) {
require.Equal(t, sk.PrivateKey(), skOut.PrivateKey())
require.True(t, sk.Equal(skOut))

sk2 := keys.NewEdX25519KeyFromSeed(keys.Rand32())
sk2 := keys.NewEdX25519KeyFromSeed(testSeed(0x01))
require.False(t, sk.Equal(sk2))
}

func TestEdX25519KeyPaperKey(t *testing.T) {
k := keys.NewEdX25519KeyFromSeed(testSeed(0x01))
paperKey := k.PaperKey()
require.Equal(t, "absurd amount doctor acoustic avoid letter advice cage absurd amount doctor acoustic avoid letter advice cage absurd amount doctor acoustic avoid letter advice comic", paperKey)
}

func TestEdX25519KeySignVerify(t *testing.T) {
signKey := keys.GenerateEdX25519Key()

Expand Down

0 comments on commit 1f5d721

Please sign in to comment.