-
Notifications
You must be signed in to change notification settings - Fork 32
/
addresses.py
68 lines (57 loc) · 1.88 KB
/
addresses.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from embit import script
from embit import ec
from embit.networks import NETWORKS
from binascii import unhexlify, hexlify
def main():
# all from the same private key
prv = ec.PrivateKey.from_wif("L2e5y14ZD3U1J7Yr62t331RtYe2hRW2TBBP8qNQHB8nSPBNgt6dM")
pub = prv.get_public_key()
print("Public key:")
print(hexlify(pub.serialize()))
# we will generate regtest addresses
network = NETWORKS["regtest"]
print("Legacy (pay to pubkey hash):")
sc = script.p2pkh(pub)
# default network is main
print(sc.address(network))
print("Segwit (pay to witness pubkey hash):")
sc = script.p2wpkh(pub)
print(sc.address(network))
print("Nested segwit (p2sh-p2wpkh):")
sc = script.p2sh(script.p2wpkh(pub))
print(sc.address(network))
print("\nMultisig address (2 of 3):")
# unsorted
pubs = [
ec.PublicKey.parse(
unhexlify(
"02edd7a58d2ff1e483d35f92a32e53607423f936b29bf95613cab24b0b7f92e0f1"
)
),
ec.PublicKey.parse(
unhexlify(
"03a4a6d360acc45cb281e0022b03218fad6ee93881643488ae39d22b854d9fa261"
)
),
ec.PublicKey.parse(
unhexlify(
"02e1fdc3b011effbba4b0771eb0f7193dee24cfe101ab7e8b64516d83f7116a615"
)
),
]
# 2 of 3 multisig script
sc = script.multisig(2, pubs)
print("Legacy, unsorted (p2sh):")
redeem_sc = script.p2sh(sc)
print(redeem_sc.address(network))
print("Native segwit, sorted (p2wsh):")
sc = script.multisig(2, sorted(pubs))
witness_sc = script.p2wsh(sc)
print(witness_sc.address(network))
print("Nested segwit, sorted (p2sh-p2wsh):")
sc = script.multisig(2, sorted(pubs))
witness_sc = script.p2wsh(sc)
redeem_sc = script.p2sh(witness_sc)
print(redeem_sc.address(network))
if __name__ == "__main__":
main()