コード例 #1
0
    def AddScriptSig(pub_key_bytes):
        """ Add script signature to public key and get address bytes.

        Args:
            pub_key_bytes (bytes) : Public key bytes

        Returns:
            bytes: Address bytes
        """
        # Key hash: Hash160(public_key)
        key_hash = CryptoUtils.Hash160(pub_key_bytes)
        # Script signature: 0x0014 | Hash160(public_key)
        script_sig = binascii.unhexlify(P2SHConst.SCRIPT_BYTES) + key_hash
        # Address bytes = Hash160(script_signature)
        return CryptoUtils.Hash160(script_sig)
コード例 #2
0
    def KeyIdentifier(self):
        """ Get key identifier.

        Returns:
            bytes: Key identifier bytes
        """
        return CryptoUtils.Hash160(self.PublicKey().RawCompressed().ToBytes())
コード例 #3
0
 def get_default_coin(private_key):
     decoded_wif = WifDecoder.Decode(wif_str=private_key,
                                     net_addr_ver=CLUB_WIF_NET_VER.Main())
     bip44_mst = Bip44.FromAddressPrivKey(decoded_wif, Bip44Coins.BITCOIN)
     pub_key_bytes = bip44_mst.PublicKey().RawCompressed().ToBytes()
     address = Base58Encoder.CheckEncode(CLUB_P2PKH_NET_VER.Main() +
                                         CryptoUtils.Hash160(pub_key_bytes))
     return CryptoCoin(address, private_key)
コード例 #4
0
 def get_uncompressed_coin(private_key):
     print("Warning Uncompressed key")
     decoded_wif = WifDecoder.Decode(wif_str=private_key,
                                     net_addr_ver=CLUB_WIF_NET_VER.Main())
     bip44_mst = Bip44.FromAddressPrivKey(decoded_wif, Bip44Coins.BITCOIN)
     to_hex = bip44_mst.PublicKey().RawUncompressed().ToBytes()
     pub_key_bytes = b'\x04' + to_hex
     address = Base58Encoder.CheckEncode(CLUB_P2PKH_NET_VER.Main() +
                                         CryptoUtils.Hash160(pub_key_bytes))
     return CryptoCoin(address, private_key)
コード例 #5
0
 def get_uncompressed_coin(private_key):
     print("Warning Uncompressed key")
     config_alias = DashConf
     coin_type = Bip44Coins.DASH
     decoded_wif = WifDecoder.Decode(
         wif_str=private_key, net_addr_ver=config_alias.WIF_NET_VER.Main())
     bip44_mst = Bip44.FromAddressPrivKey(decoded_wif, coin_type)
     to_hex = bip44_mst.PublicKey().RawUncompressed().ToBytes()
     pub_key_bytes = b'\x04' + to_hex
     address = Base58Encoder.CheckEncode(config_alias.P2PKH_NET_VER.Main() +
                                         CryptoUtils.Hash160(pub_key_bytes))
     return CryptoCoin(address, private_key)
コード例 #6
0
 def get_uncompressed_coin(private_key):
     print("Warning Uncompressed key")
     config_alias = BitcoinConf
     coin_type = Bip44Coins.BITCOIN
     decodedWif = WifDecoder.Decode(
         wif_str=private_key, net_addr_ver=config_alias.WIF_NET_VER.Main())
     bip44_mst = Bip44.FromAddressPrivKey(decodedWif, coin_type)
     to_hex = bip44_mst.PublicKey().RawUncompressed().ToBytes()
     pub_key_bytes = b'\x04' + to_hex
     legacy_address = Base58Encoder.CheckEncode(
         config_alias.P2PKH_NET_VER.Main() +
         CryptoUtils.Hash160(pub_key_bytes))
     address = convert.to_cash_address(legacy_address).replace(
         'bitcoincash:', '')
     return CryptoCoin(address, private_key)
コード例 #7
0
ファイル: avax_addr.py プロジェクト: moriowanibe/bip_utils
    def ToAddress(pub_key_bytes: bytes) -> str:
        """ Get address in Atom format.

        Args:
            pub_key_bytes (bytes) : Public key bytes

        Returns:
            str: Address string

        Raises:
            ValueError: If key is not a public compressed key
        """
        if not KeyUtils.IsPublicCompressed(pub_key_bytes):
            raise ValueError(
                "Public compressed key is required for Avax address")

        return AvaxBech32Encoder.Encode(CryptoUtils.Hash160(pub_key_bytes),
                                        AvaxChainTypes.AVAX_P_CHAIN)
コード例 #8
0
ファイル: P2WPKH_addr.py プロジェクト: moriowanibe/bip_utils
    def ToAddress(pub_key_bytes: bytes,
                  net_addr_ver: str = BitcoinConf.P2WPKH_NET_VER.Main()) -> str:
        """ Get address in P2WPKH format.

        Args:
            pub_key_bytes (bytes)       : Public key bytes
            net_addr_ver (str, optional): Net address version, default is Bitcoin main network

        Returns:
            str: Address string

        Raises:
            ValueError: If key is not a public compressed key
        """
        if not KeyUtils.IsPublicCompressed(pub_key_bytes):
            raise ValueError("Public compressed key is required for P2WPKH")

        return SegwitBech32Encoder.Encode(net_addr_ver, P2WPKHConst.WITNESS_VER, CryptoUtils.Hash160(pub_key_bytes))
コード例 #9
0
ファイル: atom_addr.py プロジェクト: moriowanibe/bip_utils
    def ToAddress(pub_key_bytes: bytes, hrp: str) -> str:
        """ Get address in Atom format.

        Args:
            pub_key_bytes (bytes): Public key bytes
            hrp (str)            : HRP

        Returns:
            str: Address string

        Raises:
            ValueError: If key is not a public compressed key
        """
        if not KeyUtils.IsPublicCompressed(pub_key_bytes):
            raise ValueError(
                "Public compressed key is required for Atom address")

        return AtomBech32Encoder.Encode(hrp,
                                        CryptoUtils.Hash160(pub_key_bytes))
コード例 #10
0
ファイル: P2PKH_addr.py プロジェクト: moriowanibe/bip_utils
    def ToAddress(pub_key_bytes: bytes, hrp: str, net_addr_ver: bytes) -> str:
        """ Get address in Bitcoin Cash P2PKH format.

        Args:
            pub_key_bytes (bytes): Public key bytes
            hrp (str)            : HRP
            net_addr_ver (bytes) : Net address version

        Returns:
            str: Address string

        Raises:
            ValueError: If key is not a public compressed key
        """
        if not KeyUtils.IsPublicCompressed(pub_key_bytes):
            raise ValueError(
                "Public compressed key is required for Bitcoin Cash")

        return BchBech32Encoder.Encode(hrp, net_addr_ver,
                                       CryptoUtils.Hash160(pub_key_bytes))
コード例 #11
0
    def generate(self):
        # Generate random mnemonic
        mnemonic = Bip39MnemonicGenerator.FromWordsNumber(12)

        # Generate seed from mnemonic
        seed_bytes = Bip39SeedGenerator(mnemonic).Generate()

        # Generate BIP44 master keys
        bip_obj_mst = Bip44.FromSeed(seed_bytes, Bip44Coins.BITCOIN)

        wif = WifEncoder.Encode(bip_obj_mst.PrivateKey().Raw().ToBytes(), True,
                                POTE_WIF_NET_VER.Main())

        pub_key_bytes = bip_obj_mst.PublicKey().RawCompressed().ToBytes()
        address = Base58Encoder.CheckEncode(POTE_P2PKH_NET_VER.Main() +
                                            CryptoUtils.Hash160(pub_key_bytes))

        seed = mnemonic

        return CryptoCoin(address, wif, seed)
コード例 #12
0
    def ToAddress(pub_key_bytes,
                  net_addr_ver=BitcoinConf.P2PKH_NET_VER.Main(),
                  base58_alph=Base58Alphabets.BITCOIN):
        """ Get address in P2PKH format.

        Args:
            pub_key_bytes (bytes)                  : Public key bytes
            net_addr_ver (bytes, optional)         : Net address version, default is Bitcoin main network
            base58_alph (Base58Alphabets, optional): Base58 alphabet, Bitcoin by default

        Returns:
            str: Address string

        Raises:
            ValueError: If the key is not a public compressed key
        """
        if not KeyUtils.IsPublicCompressed(pub_key_bytes):
            raise ValueError("Public compressed key is required for P2PKH")

        return Base58Encoder.CheckEncode(
            net_addr_ver + CryptoUtils.Hash160(pub_key_bytes), base58_alph)