Skip to content

Instantly share code, notes, and snippets.

Date: 2013-07-15
Description: (1) <dooglus> lost 1300 BTC
23:38:37 (34725) <florence> no new name
23:38:37 (20153) <unknown> flory. please don't gamble with any of doogs money, and if anyone here is up in investment consider donating to doog
23:38:59 (2458) <usagi> I gave money away when I was up
23:39:02 (34458) <florence> so doog did a charity, and let flory gamble with free 1300 btc
23:39:03 (1601) <willphase> if flory pays it back then he's still up, and doog doesn't take a huge hit
23:39:05 (34458) <florence> is that what happened today ?
23:39:17 (34725) <florence> guys

SIGHASH_ALL

This is the default. It indicates that everything about the transaction is signed, except for the input scripts. Signing the input scripts as well would obviously make it impossible to construct a transaction, so they are always blanked out. Note, though, that other properties of the input, like the connected output and sequence numbers, are signed; it's only the scripts that are not. Intuitively, it means "I agree to put my money in, if everyone puts their money in and the outputs are this".

SIGHASH_NONE

The outputs are not signed and can be anything. Use this to indicate "I agree to put my money in, as long as everyone puts their money in, but I don't care what's done with the output". This mode allows others to update the transaction by changing their inputs sequence numbers.

SIGHASH_SINGLE

Like SIGHASH_NONE, the inputs are signed, but the sequence numbers are blanked, so others can create new versions of the transaction. However, the only output that is signed is the one at the s

# -*- Mode: Python -*-
# OpenSSL wrapper
# https://github.com/joric/brutus/blob/master/ecdsa_ssl.py
import ctypes
import ctypes.util
ssl = ctypes.cdll.LoadLibrary (ctypes.util.find_library ('ssl') or 'libeay32')

compressed and uncompressed pubkey

The private key is always exactly 256 bits, or 32 bytes. The exact same private key corresponds to two different public keys. One is uncompressed in the form of (x,y), and the other is compressed in the form of (x,p). The two forms have different representations, and thus different hashes, and thus different addresses. The compression flag just tells the system which of the two possible addresses to use.

You should pretty much always do compressed keys for new generation. There is no reason to ever use uncompressed keys, at least none that I'm aware of.

So, to create the WIF, suitable for importing later, you take the 32 byte binary private key, prepend the 0x80 bytes, and append the 0x01 flag for compression, then run through base58encode and the output is the WIF. For reference, to create an uncompressed WIF, just don't append the 0x01 before encoding.

To create the matching address, calculate the public key as usual, but when you go to encode it, check the pa

Bitcoin/public point to address

Bitcoin uses a specific encoding format to encode the digest of an elliptic curve public point into a short ASCII string. The purpose of this task is to perform such a conversion.

The encoding steps are:

  • take the X and Y coordinates of the given public point, and concatenate them in order to have a 64 byte-longed string ;

create raw transaction

  • bitcoindtest = bitcoind -testnet

one input, one output

$ bitcoindtest createrawtransaction '[{"txid":"f5583dcb7ee8881e37110912f6163ddab9ffcc02e739b8683667b64c597bd635", "vout":0}]' '{"mq7se9wy2egettFxPbmn99cK8v5AFq55Lx":1}'

output hex:

2-of-2 escrow example
Carbide81 wants to pay carbide80 50tnbtc but prevent carebide80 from cheating him.
First each party creates a new address, and then shares them. Then uses the
resulting addresses to make a p2sh address (begins with '3' for bitcoin,
'2' for testnet) that requires both parties to sign to release:
The distributed redemption here (where no party has all the required keys
With Bitcoin 0.7 it's possible to keep your private keys
entirely offline without third party software.
In this example we have two hosts [offline] which is
totally offline and without a copy of the blockchain
and [online] which is a regular online node, both
running bitcoin 0.7.
This example uses the CLI, but it works equally well with