From fa18f5ede71932191b87063a5cd56405b05d6039 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Tue, 6 Oct 2020 09:56:28 +0300 Subject: [PATCH] [#165] pkg/owner: Add ID constructor from wallet Signed-off-by: Alex Vanin --- pkg/owner/id.go | 8 ++++++++ pkg/owner/id_test.go | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/pkg/owner/id.go b/pkg/owner/id.go index d333963..4862b67 100644 --- a/pkg/owner/id.go +++ b/pkg/owner/id.go @@ -43,3 +43,11 @@ func ScriptHashBE(id *ID) ([]byte, error) { return addr.BytesBE(), nil } + +// NewIDFromNeo3Wallet creates new owner identity from 25-byte neo wallet. +func NewIDFromNeo3Wallet(v *NEO3Wallet) *ID { + id := NewID() + id.SetNeo3Wallet(v) + + return id +} diff --git a/pkg/owner/id_test.go b/pkg/owner/id_test.go index e0b0f8a..581d9f2 100644 --- a/pkg/owner/id_test.go +++ b/pkg/owner/id_test.go @@ -4,6 +4,7 @@ import ( "crypto/rand" "testing" + "github.com/nspcc-dev/neofs-crypto/test" "github.com/stretchr/testify/require" ) @@ -21,3 +22,11 @@ func TestIDV2(t *testing.T) { require.Equal(t, wallet.Bytes(), idV2.GetValue()) } + +func TestNewIDFromNeo3Wallet(t *testing.T) { + wallet, err := NEO3WalletFromPublicKey(&test.DecodeKey(1).PublicKey) + require.NoError(t, err) + + id := NewIDFromNeo3Wallet(wallet) + require.Equal(t, id.ToV2().GetValue(), wallet.Bytes()) +}