There does not seem to exist a format for full file bitcoin signatures, at least have I not found any.
It is a bit surprising that bitcoin uses signatures at the core of its functionality,
but bitcoin developers seem to use PGP signatures for distributed software instead of bitcoin signatures.
There are a couple of message formats for bitcoin signatures, but they seem to be mostly used for
signatures of short messages where the result of the signature operation is a new file where the message is included.
However, it would be very useful to be able to sign an existing file which might be very large,
for example en exe-file or a source code archive.
This would provide PGP-like signature functionality using the bitcoin elliptic curve.
I have therefore created and implemented such a signature format which is included in the bitgen software package:
http://bitcoin-gen.org/A signature might look like this:
------ BEGIN BITCOIN SEPC256K1 SIGNATURE ------
feu
14F0668D7FE8938F6A23F8FE1A4FB906C558A3FBDB967222B929158487F34183
6C50D34A304A3227035CEE1ADE006B5502CC41BF639609201F75919F1B3F560E
------ END BITCOIN SEPC256K1 SIGNATURE ------
The signature includes the r and s values of the signature as well as three boolean values.
The public key x and y values are not included since the sepc256k1 curve allows public key recovery
from the r and s values and the hash sum.
The three letters in the first line give information about which public address should be choosen since there are
eight possible public addresses when (r, s, hash) are given.
The first letter can be "f" or "s", which stands for "first" and "second".
With "f", the first value should be choosen, with "s" the second value is the correct one.
The second letter is "e" or "o" for "odd" or "even", and will together with the first boolean value give the correct public key.
The public address can be derived from a compressed or uncompressed public key.
The third character specifies "u" for uncompressed or "c" for compressed.
The second and third lines are the r and s values as hex encoded values.
The double sha256 hash of the file is performed using the string "Bitcoin Signed File " followed by the
byte length of the file contents in decimal ascii, followed by " bytes:" and finally the file contents:
"Bitcoin Signed File " + ascii(length) + " bytes:" + file_content
The file format uses unix style newline with a single linefeed character.
Building the project will give two executable files, one which is
bitsigIn order to create and store a new private key, use for example:
$ bitsig randomWhen this is done, the signature of any file can be created:
$ echo "bitgen test" > btest.txt$ bitsig sign btest.txtThis will give output similar to the following:
========================
Signing message file: btest.txt
No key specified, using default key: 17RjaCGZQbe2Cw984YdWcMcWDgM86kM7EN
Generating 32 random bytes.
Press random keys or move the mouse if needed
32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17
16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
Signing in progress...
Trying even...
Parity is even
Result written to: btest.txt.bitsig
========================
In order to verify the signature of the file, give the following command:
$ bitsig verify btest.txt btest.txt.bitsigThis will give:
========================
The signed file : btest.txt
The signature file : btest.txt.bitsig
Calculated address : 17RjaCGZQbe2Cw984YdWcMcWDgM86kM7EN
No public address given, looking in keychain
This is our own address
Found the address in the keychain
Verifying signature....
Verify OK for address: 17RjaCGZQbe2Cw984YdWcMcWDgM86kM7EN
Address alias: MY KEY
========================