From 1f5d721f42c05fafeef65ebf0c2970472dc853e1 Mon Sep 17 00:00:00 2001 From: Gabriel Handford Date: Thu, 1 Apr 2021 13:57:43 -0700 Subject: [PATCH] EdX25519Key.PaperKey --- edx25519.go | 8 ++++++++ edx25519_test.go | 8 +++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/edx25519.go b/edx25519.go index efacab2..31245a4 100644 --- a/edx25519.go +++ b/edx25519.go @@ -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 diff --git a/edx25519_test.go b/edx25519_test.go index 2e10be1..445b574 100644 --- a/edx25519_test.go +++ b/edx25519_test.go @@ -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()