Sign generates an ECDSA signature for the provided hash (which should be the result of hashing a larger message) using the private key. Produced signature is deterministic (same message and same key yield the same signature) and canonical in accordance with RFC6979 and BIP0062.
(hash []byte)
| 75 | // a larger message) using the private key. Produced signature is deterministic (same message and |
| 76 | // same key yield the same signature) and canonical in accordance with RFC6979 and BIP0062. |
| 77 | func (private *PrivateKey) Sign(hash []byte) (*Signature, error) { |
| 78 | if len(hash) != 32 { |
| 79 | return nil, errors.New("only hash can be signed") |
| 80 | } |
| 81 | if BypassSignature { |
| 82 | return bypassS, nil |
| 83 | } |
| 84 | seckey := utils.PaddedBigBytes(private.D, private.Params().BitSize/8) |
| 85 | defer zeroBytes(seckey) |
| 86 | sb, e := secp256k1.Sign(hash, seckey) |
| 87 | s := &Signature{ |
| 88 | R: new(big.Int).SetBytes(sb[:32]), |
| 89 | S: new(big.Int).SetBytes(sb[32:64]), |
| 90 | } |
| 91 | //s, e := (*ec.PrivateKey)(private).Sign(hash) |
| 92 | |
| 93 | return (*Signature)(s), e |
| 94 | } |
| 95 | |
| 96 | // Verify calls ecdsa.Verify to verify the signature of hash using the public key. It returns true |
| 97 | // if the signature is valid, false otherwise. |