Closed agraebe closed 3 years ago
This is described in https://github.com/blockstack/docs/blob/8da7f4f53ffe05e23c2730642bea30aec09b2daa/src/pages/stacks-blockchain/integrate-stacking.md#L245
Is this issue still valid? What should be changed?
Basically explaining the version
and hashbytes
outside of the JS code (in case someone would implement in a different language). It would also make sense to explain why the version is needed. Just some more guidance on what this address format is and why it is like that
@kantai or @lgalabru could you maybe give us a braindump of the bitcoin address format? why versions? why is it 0
, etc? Would love to document this so that anyone can implement, even if they're not using JS/TS
The version bytes are one of the following:
SerializeP2PKH = 0x00, // hash160(public-key), same as bitcoin's p2pkh
SerializeP2SH = 0x01, // hash160(multisig-redeem-script), same as bitcoin's multisig p2sh
SerializeP2WPKH = 0x02, // hash160(segwit-program-00(p2pkh)), same as bitcoin's p2sh-p2wpkh
SerializeP2WSH = 0x03, // hash160(segwit-program-00(public-keys)), same as bitcoin's p2sh-p2wsh
Indicating what kind of Bitcoin address it is being submitted.
The hash bytes are the 20 hash bytes of the Bitcoin address, you can get that from a normal Bitcoin library, e.g.
$ node -e "const btc = require('bitcoinjs-lib'); console.log('0x' + btc.address.fromBase58Check('1C56LYirKa3PFXFsvhSESgDy2acEHVAEt6').hash.toString('hex'))"
The reason that the PoX contract needs this special format is that it needs to ensure that miners will be able to correctly construct the Bitcoin transaction containing the reward address. An invalid reward address could cause miners to be unable to mine a block.
The reward bitcoin address needs to be in a specific format, currently not documented:
Here's an example when the address is derived from an STX address: