Addresses

Collection of base classes that implement the work with Bitcoin addresses and address keys. Supports addresses types PUBKEY, P2PKH, P2SH, P2SH-PWPKH, P2WPKH, P2WSH.



class pybgl.PrivateKey(key=None, compressed=True, testnet=False)[source]

The class for creating private key object.

Parameters
  • key – (optional) private key in HEX, bytes string or WIF format. In case no key specified new random private key will be created.

  • compressed – (optional) if set to True private key corresponding compressed public key, by default is True. Recommended use only compressed public key.

  • testnet – (optional) flag for testnet network, by default is False.

compressed

flag for compressed type of corresponding public key (boolean)

hex

private key in HEX (string)

key

private key in bytes (bytes)

testnet

flag for testnet network private key (boolean)

wif

private key in WIF format (string)



class pybgl.PublicKey(key, compressed=True, testnet=False)[source]

The class for public key object.

Parameters
  • key

    one of this types allowed:

    • private key is instance of PrivateKey class

    • private key HEX encoded string

    • private key 32 bytes string

    • private key in WIF format

    • public key in HEX encoded string

    • public key [33/65] bytes string

    In case no key specified with HEX or bytes string you have to provide flag for testnet and compressed key. WIF format and PrivateKey instance already contain this flags. For HEX or bytes public key only testnet flag has the meaning, comressed flag is determined according to the length of key.

  • compressed – (optional) if set to True private key corresponding compressed public key, by default is True. Recommended use only compressed public key.

  • testnet – (optional) flag for testnet network, by default is False.

compressed

flag for compressed type of corresponding public key (boolean)

hex

public key in HEX (string)

key

public key in bytes (bytes)

testnet

flag for testnet network private key (boolean)



class pybgl.Address(key=None, address_type='P2WPKH', testnet=False, compressed=True)[source]

The class for Address object.

Parameters
  • key

    (optional) one of this types allowed:

    • private key WIF format

    • instance of PrivateKey

    • private key HEX encoded string

    • instance of PublicKey

    In case no key specified new Address will be created with random keys.

  • address_type – (optional) P2PKH, PUBKEY, P2WPKH, P2SH_P2WPKH, by default is P2WPKH.

  • testnet – (optional) flag for testnet network, by default is False.

  • compressed – (optional) if set to True private key corresponding compressed public key, by default is True. Recommended use only compressed public key.

In case instance is created from WIF private key, PrivateKey or PublicKey compressed and testnet flags already contain in initial key parameter and will be ignored.

address

address in base58 or bech32 encoding (string)

hash

address hash

hash_hex

address hash HEX (string)

private_key

instance of PrivateKey class

public_key

instance of PublicKey class

redeem_script

redeeem script, only for P2SH_P2WPKH (bytes)

redeem_script_hex

redeeem script HEX, only for P2SH_P2WPKH (string)

script_hash

flag for script hash address (boolean)

testnet

flag for testnet network address (boolean)

type

address type (string)

witness_version

version of witness program for SEGWIT address (string)