[#165] pkg/owner: Add ID constructor from wallet

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2020-10-06 09:56:28 +03:00 committed by Alex Vanin
parent cf70026c7e
commit fa18f5ede7
2 changed files with 17 additions and 0 deletions

View file

@ -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
}

View file

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