13

I've recently been implementing a simple Bitcoin wallet and some libraries seem to disagree with address derivation from the same WIF private key, and thus wouldn't sign transactions. After that, I used different libraries to implement the same thing and they successfully signed transactions, but then the network refused to accept them. When I did it with a private key that was derived from a mnemonic (in a specific way), it worked.

So, I'm really wondering whether there is a specific requirement imposed on Bitcoin's private keys.

Andrew T.
  • 121
  • 1
  • 6
kuco 23
  • 255
  • 1
  • 7

1 Answers1

22

A secp256k1 private key is an integer between 1 and 115792089237316195423570985008687907852837564279074904382605163141518161494336, inclusive. The latter can be written as 2256 - 432420386565659656852420866394968145600, or in hexadecimal as 0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140.

Usually private keys are encoded using 256-bit big endian encodings, yielding 32 bytes. Almost all of the possible 32-byte values are thus valid keys, but a tiny fraction (the all-zero one, and those encoding a number above the limit above), together around 0.0000000000000000000000000000000000003734455345%.

Pieter Wuille
  • 98,249
  • 9
  • 183
  • 287