Create a P2PKH bitcoin address from a pubkey Raises CBitcoinAddressError if pubkey is invalid, unless accept_invalid is True. The pubkey must be a bytes instance; CECKey instances are not accepted.
(cls, pubkey, accept_invalid=False)
| 196 | |
| 197 | @classmethod |
| 198 | def from_pubkey(cls, pubkey, accept_invalid=False): |
| 199 | """Create a P2PKH bitcoin address from a pubkey |
| 200 | |
| 201 | Raises CBitcoinAddressError if pubkey is invalid, unless accept_invalid |
| 202 | is True. |
| 203 | |
| 204 | The pubkey must be a bytes instance; CECKey instances are not accepted. |
| 205 | """ |
| 206 | if not isinstance(pubkey, bytes): |
| 207 | raise TypeError('pubkey must be bytes instance; got %r' % pubkey.__class__) |
| 208 | |
| 209 | if not accept_invalid: |
| 210 | if not isinstance(pubkey, bitcoin.core.key.CPubKey): |
| 211 | pubkey = bitcoin.core.key.CPubKey(pubkey) |
| 212 | if not pubkey.is_fullyvalid: |
| 213 | raise CBitcoinAddressError('invalid pubkey') |
| 214 | |
| 215 | pubkey_hash = bitcoin.core.Hash160(pubkey) |
| 216 | return P2PKHBitcoinAddress.from_bytes(pubkey_hash) |
| 217 | |
| 218 | @classmethod |
| 219 | def from_scriptPubKey(cls, scriptPubKey, accept_non_canonical_pushdata=True, accept_bare_checksig=True): |