mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-12 11:10:35 +00:00
ddd1d92ff1
The idea here is to preserve the history of `dev` branch development and its code when merging with the `master`. Later this code could be moved into the masters code where appropriate.
33 lines
742 B
Go
Executable file
33 lines
742 B
Go
Executable file
package pubkeytesthelper
|
|
|
|
import (
|
|
"github.com/CityOfZion/neo-go/pkg/crypto/hash"
|
|
"github.com/CityOfZion/neo-go/pkg/crypto/privatekey"
|
|
)
|
|
|
|
// SignDataWithRandomPrivateKey will sign data with
|
|
// a random private key, then verify said data
|
|
// returning true if Verify returns true
|
|
func SignDataWithRandomPrivateKey(data []byte) (bool, error) {
|
|
|
|
hashedData, err := hash.Sha256(data)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
|
|
privKey, err := privatekey.NewPrivateKey()
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
signedData, err := privKey.Sign(data)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
pubKey, err := privKey.PublicKey()
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
result := pubKey.Verify(signedData, hashedData.Bytes())
|
|
|
|
return result, nil
|
|
}
|