git.frostfs.info/TrueCloudLab/frostfs-sdk-go@v0.0.0-20241022124111-5361f0ecebd3/user/util_test.go (about)

     1  package user_test
     2  
     3  import (
     4  	"crypto/ecdsa"
     5  	"crypto/elliptic"
     6  	"encoding/hex"
     7  	"testing"
     8  
     9  	"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/user"
    10  	"github.com/stretchr/testify/require"
    11  )
    12  
    13  func TestIDFromKey(t *testing.T) {
    14  	// examples are taken from https://docs.neo.org/docs/en-us/basic/concept/wallets.html
    15  	rawPub, _ := hex.DecodeString("03cdb067d930fd5adaa6c68545016044aaddec64ba39e548250eaea551172e535c")
    16  	x, y := elliptic.UnmarshalCompressed(elliptic.P256(), rawPub)
    17  	require.True(t, x != nil && y != nil)
    18  
    19  	var id user.ID
    20  
    21  	user.IDFromKey(&id, ecdsa.PublicKey{Curve: elliptic.P256(), X: x, Y: y})
    22  
    23  	require.Equal(t, "NNLi44dJNXtDNSBkofB48aTVYtb1zZrNEs", id.EncodeToString())
    24  }