-
Notifications
You must be signed in to change notification settings - Fork 2
/
carlisle.py
35 lines (27 loc) · 918 Bytes
/
carlisle.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import hashlib
import bitcoin
def carlisle_method(data, compress=False):
"""
Use the Carlisle method to generate a bitcoin address the hash of data.
Args:
data: bytes, data to hash
compress: bool, whether to compress the public key
Returns:
dictionary with address generation information
"""
# Compute the sha256 hash of the data
sha256_hash = hashlib.sha256(data)
private_key = sha256_hash.hexdigest()
# Generate public key
public_key = bitcoin.privkey_to_pubkey(private_key)
if compress:
public_key = bitcoin.compress(public_key)
# Generate bitcoin address
address = bitcoin.pubkey_to_address(public_key)
return {
'private_key': private_key,
'public_key': public_key,
'compressed': compress,
'address': address,
'url ': 'https://blockchain.info/address/{}'.format(address),
}