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()