code: func signRFC6979(privateKey *PrivateKey, hash []byte) (*Signature, error) {
  
  	privkey := privateKey.ToECDSA()
  	N := S256().N
  	halfOrder := S256().halfOrder
  	k := nonceRFC6979(privkey.D, hash)
  	inv := new(big.Int).ModInverse(k, N)
  	r, _ := privkey.Curve.ScalarBaseMult(k.Bytes())
  	r.Mod(r, N)
  
  	if r.Sign() == 0 {
  		return nil, errors.New("calculated R is zero")
  	}
  
  	e := hashToInt(hash, privkey.Curve)
  	s := new(big.Int).Mul(privkey.D, r)
  	s.Add(s, e)
  	s.Mul(s, inv)
  	s.Mod(s, N)
  
  	if s.Cmp(halfOrder) == 1 {
  		s.Sub(N, s)
  	}
  	if s.Sign() == 0 {
  		return nil, errors.New("calculated S is zero")
  	}
  	return &Signature{R: r, S: s}, nil
  }
docs: // signRFC6979 generates a deterministic ECDSA signature according to RFC 6979 and BIP 62.