-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extend package API with features usefule for existing apps (#479)
- Loading branch information
Showing
16 changed files
with
247 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package neofscrypto_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/nspcc-dev/neofs-api-go/v2/refs" | ||
neofscrypto "github.com/nspcc-dev/neofs-sdk-go/crypto" | ||
"github.com/nspcc-dev/neofs-sdk-go/crypto/test" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
const anyUnsupportedScheme = neofscrypto.ECDSA_WALLETCONNECT + 1 | ||
|
||
func TestSignatureLifecycle(t *testing.T) { | ||
data := []byte("Hello, world!") | ||
signer := test.RandomSigner(t) | ||
scheme := signer.Scheme() | ||
pubKey := signer.Public() | ||
bPubKey := neofscrypto.PublicKeyBytes(pubKey) | ||
|
||
var clientSig neofscrypto.Signature | ||
|
||
err := clientSig.Calculate(signer, data) | ||
require.NoError(t, err) | ||
|
||
testSig := func(sig neofscrypto.Signature) { | ||
require.Equal(t, signer.Scheme(), sig.Scheme()) | ||
require.Equal(t, signer.Public(), sig.PublicKey()) | ||
require.Equal(t, bPubKey, sig.PublicKeyBytes()) | ||
require.NotEmpty(t, sig.Value()) | ||
require.True(t, sig.Verify(data)) | ||
} | ||
|
||
testSig(clientSig) | ||
|
||
var sigV2 refs.Signature | ||
clientSig.WriteToV2(&sigV2) | ||
|
||
require.Equal(t, refs.SignatureScheme(scheme), sigV2.GetScheme()) | ||
require.Equal(t, bPubKey, sigV2.GetKey()) | ||
require.Equal(t, clientSig.Value(), sigV2.GetSign()) | ||
|
||
// sigV2 transmitted to server over the network | ||
|
||
var serverSig neofscrypto.Signature | ||
|
||
err = serverSig.ReadFromV2(sigV2) | ||
require.NoError(t, err) | ||
|
||
testSig(serverSig) | ||
|
||
// break the message in different ways | ||
for i, breakSig := range []func(*refs.Signature){ | ||
func(sigV2 *refs.Signature) { sigV2.SetScheme(refs.SignatureScheme(anyUnsupportedScheme)) }, | ||
func(sigV2 *refs.Signature) { | ||
key := sigV2.GetKey() | ||
sigV2.SetKey(key[:len(key)-1]) | ||
}, | ||
func(sigV2 *refs.Signature) { sigV2.SetKey(append(sigV2.GetKey(), 1)) }, | ||
func(sigV2 *refs.Signature) { sigV2.SetSign(nil) }, | ||
} { | ||
sigV2Cp := sigV2 | ||
breakSig(&sigV2Cp) | ||
|
||
err = serverSig.ReadFromV2(sigV2Cp) | ||
require.Errorf(t, err, "break func #%d", i) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package neofscrypto_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys" | ||
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 TestPublicKeyBytes(t *testing.T) { | ||
k, err := keys.NewPrivateKey() | ||
require.NoError(t, err) | ||
|
||
pubKey := neofsecdsa.PublicKey(k.PrivateKey.PublicKey) | ||
|
||
bPubKey := neofscrypto.PublicKeyBytes(&pubKey) | ||
|
||
var restoredPubKey neofsecdsa.PublicKey | ||
|
||
err = restoredPubKey.Decode(bPubKey) | ||
require.NoError(t, err) | ||
|
||
require.Equal(t, pubKey, restoredPubKey) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.