2022-04-05 11:13:34 +00:00
|
|
|
package neofscrypto_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"math/rand"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/refs"
|
|
|
|
neofscrypto "github.com/nspcc-dev/neofs-sdk-go/crypto"
|
|
|
|
neofsecdsa "github.com/nspcc-dev/neofs-sdk-go/crypto/ecdsa"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestSignature(t *testing.T) {
|
|
|
|
data := make([]byte, 512)
|
|
|
|
rand.Read(data)
|
|
|
|
|
|
|
|
k, err := keys.NewPrivateKey()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
var s neofscrypto.Signature
|
|
|
|
var m refs.Signature
|
|
|
|
|
|
|
|
for _, f := range []func() neofscrypto.Signer{
|
|
|
|
func() neofscrypto.Signer {
|
2022-04-19 08:11:29 +00:00
|
|
|
return neofsecdsa.Signer(k.PrivateKey)
|
2022-04-05 11:13:34 +00:00
|
|
|
},
|
|
|
|
func() neofscrypto.Signer {
|
2022-04-19 08:11:29 +00:00
|
|
|
return neofsecdsa.SignerRFC6979(k.PrivateKey)
|
2022-04-05 11:13:34 +00:00
|
|
|
},
|
2022-03-10 12:25:14 +00:00
|
|
|
func() neofscrypto.Signer {
|
|
|
|
return neofsecdsa.SignerWalletConnect(k.PrivateKey)
|
|
|
|
},
|
2022-04-05 11:13:34 +00:00
|
|
|
} {
|
|
|
|
signer := f()
|
|
|
|
|
|
|
|
err := s.Calculate(signer, data)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
s.WriteToV2(&m)
|
|
|
|
|
|
|
|
s.ReadFromV2(m)
|
|
|
|
|
|
|
|
valid := s.Verify(data)
|
2022-03-10 12:25:14 +00:00
|
|
|
require.True(t, valid, "type %T", signer)
|
2022-04-05 11:13:34 +00:00
|
|
|
}
|
|
|
|
}
|