[#87] go.mod: remove neo-go dependency

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2021-11-22 15:38:15 +03:00 committed by Alex Vanin
parent d821f18b7d
commit a2d342e928
20 changed files with 167 additions and 246 deletions

View file

@ -8,7 +8,7 @@ import (
"crypto/sha512"
"math/big"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/rfc6979"
)
var curve = elliptic.P256()
@ -77,15 +77,31 @@ func SignWithRFC6979() SignOption {
}
func signRFC6979(key *ecdsa.PrivateKey, msg []byte) ([]byte, error) {
p := &keys.PrivateKey{PrivateKey: *key}
return p.Sign(msg), nil
digest := sha256.Sum256(msg)
r, s := rfc6979.SignECDSA(key, digest[:], sha256.New)
return getSignatureSlice(key.Curve, r, s), nil
}
func verifyRFC6979(key *ecdsa.PublicKey, msg []byte, sig []byte) error {
p := (*keys.PublicKey)(key)
func verifyRFC6979(pub *ecdsa.PublicKey, msg []byte, sig []byte) error {
h := sha256.Sum256(msg)
if p.Verify(sig, h[:]) {
if pub.X == nil || pub.Y == nil || len(sig) != 64 {
return ErrInvalidSignature
}
rBytes := new(big.Int).SetBytes(sig[0:32])
sBytes := new(big.Int).SetBytes(sig[32:64])
if ecdsa.Verify(pub, h[:], rBytes, sBytes) {
return nil
}
return ErrInvalidSignature
}
func getSignatureSlice(curve elliptic.Curve, r, s *big.Int) []byte {
params := curve.Params()
curveOrderByteSize := params.P.BitLen() / 8
signature := make([]byte, curveOrderByteSize*2)
_ = r.FillBytes(signature[:curveOrderByteSize])
_ = s.FillBytes(signature[curveOrderByteSize:])
return signature
}