1
0
mirror of https://github.com/bitcoinbook/bitcoinbook synced 2024-12-23 15:18:11 +00:00
Commit Graph

13 Commits

Author SHA1 Message Date
Andreas M. Antonopoulos
a3229bbbc0 bitcoin/Bitcoin capitalization changed everywhere 2021-10-25 23:51:17 +02:00
Samir Sadek
989cb006f1 remove reference to the old library bitcoin for the new library cryptos 2021-04-07 16:43:45 +02:00
Will Binns
06b8fe01cc
Merge branch 'develop' into patch-1 2021-03-10 08:16:25 +01:00
Will Binns
39d663ed30
ch04: Fix 'key-to-address-ecc-example'
The 'pybitcointools' library is deprecated. Vitalik mentions using the
fork from 'primal100'. This updates the code sample which is currently
broken, to use the Python package for that fork.

Runs all good now.
2021-03-08 15:59:01 +01:00
drakos
6b041e5341
Fix for Private Key (WIF-Compressed)
When testing with a `private_key = '0000000000000000000000000000000000000000000000000000000000000001'` instead of `private_key = bitcoin.random_key()`,
the generated Private Key (WIF-Compressed) is wrong `5HpHagT65TZzG1PH3CSu63k8DbpvD8s5ip4nEB3kEsrefhvB5QZ`, it should be `KwDiBf89QgGbjEhKnhXJuH7LrciVrZi3qYjgd9M7rFU73sVHnoWn`. As it turns out, the proper way to get the correct compressed WIF is to pass `'wif_compressed'` and not `'wif'` to the `bitcoin.encode_privkey` function, as pointed out in the Main.py from the bitcoin python package.

```
def encode_privkey(priv, formt, vbyte=0):
    if not isinstance(priv, int_types):
        return encode_privkey(decode_privkey(priv), formt, vbyte)
    if formt == 'decimal': return priv
    elif formt == 'bin': return encode(priv, 256, 32)
    elif formt == 'bin_compressed': return encode(priv, 256, 32)+b'\x01'
    elif formt == 'hex': return encode(priv, 16, 64)
    elif formt == 'hex_compressed': return encode(priv, 16, 64)+'01'
    elif formt == 'wif':
        return bin_to_b58check(encode(priv, 256, 32), 128+int(vbyte))
    elif formt == 'wif_compressed':
        return bin_to_b58check(encode(priv, 256, 32)+b'\x01', 128+int(vbyte))
    else: raise Exception("Invalid format!")
```

The fix can be done in a couple ways:

`bitcoin.encode_privkey(bitcoin.decode_privkey(compressed_private_key, 'hex'), 'wif')` -> 5HpHagT65TZzG1PH3CSu63k8DbpvD8s5ip4nEB3kEsrefhvB5QZ (WRONG)

`bitcoin.encode_privkey(bitcoin.decode_privkey(compressed_private_key, 'hex'), 'wif_compressed')` -> KwDiBf89QgGbjEhKnhXJuH7LrciVrZi3qYjgd9M7rFU9FMLM39zT (WRONG)

`bitcoin.encode_privkey(bitcoin.decode_privkey(compressed_private_key, 'hex_compressed'), 'wif_compressed')` -> KwDiBf89QgGbjEhKnhXJuH7LrciVrZi3qYjgd9M7rFU73sVHnoWn (CORRECT)

`bitcoin.encode_privkey(bitcoin.decode_privkey(private_key, 'hex'), 'wif_compressed')` -> KwDiBf89QgGbjEhKnhXJuH7LrciVrZi3qYjgd9M7rFU73sVHnoWn (CORRECT)
2021-02-27 23:37:29 -05:00
Fan
c6fa743597
Update key-to-address-ecc-example.py
If line#24 use 'wif_compressed', it will produce a wrong Key (WIF-Compressed) started with 2.

So there should be 'wif', unless :
wif_compressed_private_key = bitcoin.encode_privkey(
    bitcoin.decode_privkey(private_key, 'hex'), 'wif_compressed')
This is also right. 
However, use the 'compressed_private_key' and 'wif_compressed' is wrong.
2019-12-04 11:39:59 +08:00
MaloneGod
b01acc076b
correct an error line 24 'wif' to 'wif_compressed' 2018-02-08 20:42:50 +08:00
ZhaoChunsheng
5460eb7a8d
Update key-to-address-ecc-example.py
The code is very possible to miss a leading '0'.
E.g:
Private Key (hex) is: 57c003d31cca32f79a22e70334fff37875617e89c04d2746b5efc22067ccb8fd
Before: Compressed Public Key (hex) is: 03 8f0de2360796ae0fe17f1a2b0be30af6fb45eccc4a1c7afb5ebea21d041b6e0
After: Compressed Public Key (hex) is: 03 08f0de2360796ae0fe17f1a2b0be30af6fb45eccc4a1c7afb5ebea21d041b6e0

The bug is in the pybitcointools, but it is not updated, we can only repair it ourselves.
2018-01-27 21:56:25 +08:00
cclauss
a47fa095cf from __future__ import print_function
`from __future__ import print_function` to bring the print function from Python 3 into Python 2.6 and 2.7.

Properly deals with comma separated values in print() function.
2017-09-06 06:44:52 +02:00
cclauss
cb1053f905 print() function for Python 3
Also ternary if
2017-08-24 18:27:27 +02:00
Andreas M. Antonopoulos
6040e26579 Addressing errata 152498 2015-03-03 11:57:53 -05:00
Cody Scott
e970ea97ee Fixing long lines that are cut off in PDF 2014-08-27 16:08:43 -04:00
Andreas M. Antonopoulos
4ab26920b9 added python code sample for key and address generation in various formats 2014-06-02 15:04:18 -04:00