forked from rubblelabs/ripple
-
Notifications
You must be signed in to change notification settings - Fork 0
/
signing.go
31 lines (28 loc) · 775 Bytes
/
signing.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package data
import "github.com/rubblelabs/ripple/crypto"
func Sign(s Signer, key crypto.Key, sequence *uint32) error {
s.InitialiseForSigning()
copy(s.GetPublicKey().Bytes(), key.Public(sequence))
hash, msg, err := SigningHash(s)
if err != nil {
return err
}
sig, err := crypto.Sign(key.Private(sequence), hash.Bytes(), append(s.SigningPrefix().Bytes(), msg...))
if err != nil {
return err
}
*s.GetSignature() = VariableLength(sig)
hash, _, err = Raw(s)
if err != nil {
return err
}
copy(s.GetHash().Bytes(), hash.Bytes())
return nil
}
func CheckSignature(s Signer) (bool, error) {
hash, msg, err := SigningHash(s)
if err != nil {
return false, err
}
return crypto.Verify(s.GetPublicKey().Bytes(), hash.Bytes(), msg, s.GetSignature().Bytes())
}