How can I fix this: (Non-canonical signature: S value is unnecessarily high) I've written a small script that will create a bitcoin transaction from scratch, using an ECDSA library. It works, but sometimes I get this error:

64: non-mandatory-script-verify-flag (Non-canonical signature: S value is unnecessarily high)

I found this reply answer on bitcoin talk:


  The signature is composed of two values, the r value and the s value. 
  In your third input, the s value is greater than N/2, which is not
  allowed.  Just add in some code that if s is greater than N/2, then s
  = N - s.


But what exactly is N?
It seems as though N is the order of the elliptic curve.

Or in other words, the number of possible points on the secp256k1 curve.

N = 115792089237316195423570985008687907852837564279074904382605163141518161494337