diff --git a/go.mod b/go.mod index 8c862a0ba1..966f5eaeef 100644 --- a/go.mod +++ b/go.mod @@ -17,6 +17,7 @@ require ( cosmossdk.io/x/evidence v0.1.0 cosmossdk.io/x/feegrant v0.1.0 cosmossdk.io/x/upgrade v0.1.1 + filippo.io/age v1.1.1 github.com/99designs/keyring v1.2.2 github.com/cometbft/cometbft v0.38.7-0.20240412124004-1f67e396cf45 github.com/cosmos/cosmos-db v1.0.3-0.20240408151834-e75f6e4b28d8 diff --git a/go.sum b/go.sum index dafe0d1901..461207efa4 100644 --- a/go.sum +++ b/go.sum @@ -211,6 +211,8 @@ cosmossdk.io/x/feegrant v0.1.0/go.mod h1:4r+FsViJRpcZif/yhTn+E0E6OFfg4n0Lx+6cCtn cosmossdk.io/x/upgrade v0.1.1 h1:aoPe2gNvH+Gwt/Pgq3dOxxQVU3j5P6Xf+DaUJTDZATc= cosmossdk.io/x/upgrade v0.1.1/go.mod h1:MNLptLPcIFK9CWt7Ra//8WUZAxweyRDNcbs5nkOcQy0= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= +filippo.io/age v1.1.1 h1:pIpO7l151hCnQ4BdyBujnGP2YlUo0uj6sAVNHGBvXHg= +filippo.io/age v1.1.1/go.mod h1:l03SrzDUrBkdBx8+IILdnn2KZysqQdbEBUQ4p3sqEQE= filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 h1:/vQbFIOMbk2FiG/kXiLl8BRyzTWDw7gX/Hz7Dd5eDMs= diff --git a/x/e2ee/keyring/keyring_test.go b/x/e2ee/keyring/keyring_test.go index 43d09d4de4..56ef87ee74 100644 --- a/x/e2ee/keyring/keyring_test.go +++ b/x/e2ee/keyring/keyring_test.go @@ -1,19 +1,47 @@ package keyring import ( + "bytes" + "io" "testing" - "github.com/cosmos/cosmos-sdk/crypto/keyring" + "filippo.io/age" "github.com/test-go/testify/require" + + "github.com/cosmos/cosmos-sdk/crypto/keyring" ) func TestKeyring(t *testing.T) { kr, err := New("cronosd", keyring.BackendTest, t.TempDir(), nil) require.NoError(t, err) - require.NoError(t, kr.Set("test", []byte("test"))) + identity, err := age.GenerateX25519Identity() + require.NoError(t, err) + + var ciphertext []byte + { + dst := bytes.NewBuffer(nil) + writer, err := age.Encrypt(dst, identity.Recipient()) + require.NoError(t, err) + writer.Write([]byte("test")) + writer.Close() + ciphertext = dst.Bytes() + } + + require.NoError(t, kr.Set("test", []byte(identity.String()))) secret, err := kr.Get("test") require.NoError(t, err) - require.Equal(t, []byte("test"), secret) + + identity, err = age.ParseX25519Identity(string(secret)) + require.NoError(t, err) + + { + reader, err := age.Decrypt(bytes.NewReader(ciphertext), identity) + require.NoError(t, err) + bz, err := io.ReadAll(reader) + require.NoError(t, err) + + require.Equal(t, []byte("test"), bz) + } }