mcdallas / cryptotools

MIT License
206 stars 80 forks source link

It makes P2WSH not right. #14

Closed Andy19999999999999 closed 3 years ago

Andy19999999999999 commented 3 years ago

from cryptotools.BTC import generate_keypair, pubkey_to_address, push, script_to_address, OP

private, public = generate_keypair() print(private.hex()) print(private.wif()) print(private.wif(compressed=True))

script = push(public.encode(compressed=True)) + OP.CHECKSIG.byte print(public.hex()) print(public.hex(compressed=True)) print(pubkey_to_address(public, 'P2PKH')) print(public.to_address('P2PKH', compressed=True)) print(public.to_address('P2WPKH')) print(script_to_address(script, 'P2WSH')) print(script_to_address(script, 'P2WSH-P2SH')) print(script_to_address(script, 'P2SH')) Снимок экрана (15)

mcdallas commented 3 years ago

Hey Andy, to calculate a P2WSH address you need a script. I see you are using the very basic script from the Readme but that's probably not what the other tool you are comparing to is using.

Andy19999999999999 commented 3 years ago

But the right one is correct not cryptotools.

mcdallas commented 3 years ago

If you use the same script you'll get the same result

Andy19999999999999 commented 3 years ago

if hex1=hex2 then address1=addres2 How you see it is not so.

mcdallas commented 3 years ago

I am trying to explain to you that this line of your code is wrong:

script = push(public.encode(compressed=True)) + OP.CHECKSIG.byte

Andy19999999999999 commented 3 years ago

Excuse me, maybe I don't understand something. This line is from your sample "Create keys/addresses (including segwit)":

Simple script

script = push(public.encode(compressed=True)) + OP.CHECKSIG.byte script_to_address(script, 'P2WSH') 'bc1q8yh8l8ft3220q328hlapqhflpzy6xvkq6u36mctk8gq5pyxm3rwqv5h5dg'

mcdallas commented 3 years ago

Yes that's a nonsense script I made up as an example, no one generates addresses with that script it's just for demonstration purposes. You need to substitute your own script.

Andy19999999999999 commented 3 years ago

Thank you I see.