https://github.com/stacks-archive/keylib-py
Library for elliptic curve (ECDSA) private keys, public keys, and bitcoin addresses.
https://github.com/stacks-archive/keylib-py
Last synced: about 2 months ago
JSON representation
Library for elliptic curve (ECDSA) private keys, public keys, and bitcoin addresses.
- Host: GitHub
- URL: https://github.com/stacks-archive/keylib-py
- Owner: stacks-network
- License: mit
- Created: 2016-03-14T18:11:44.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2023-09-10T14:44:38.000Z (almost 2 years ago)
- Last Synced: 2024-10-14T00:51:06.512Z (9 months ago)
- Language: Python
- Homepage:
- Size: 23.4 KB
- Stars: 13
- Watchers: 8
- Forks: 21
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Keylib
[](https://circleci.com/gh/blockstack/keylib-py/tree/master)
[](https://pypi.python.org/pypi/keylib/)
[](https://github.com/namesystem/keylib/blob/master/LICENSE)
[](http://slack.blockstack.org/)## Installation
```bash
$ pip install keylib
```## Usage
### Private Keys
```python
>>> from keylib import ECPrivateKey
```#### New Private Keys
```python
>>> private_key = ECPrivateKey()
>>> private_key.to_hex()
'c4bbcb1fbec99d65bf59d85c8cb62ee2db963f0fe106f483d9afa73bd4e39a8a01'
>>> private_key.to_wif()
'L3p8oAcQTtuokSCRHQ7i4MhjWc9zornvpJLfmg62sYpLRJF9woSu'
```#### Imported Private Keys
```python
>>> imported_private_key = ECPrivateKey(private_key.to_hex())
>>> print private_key.to_wif() == imported_private_key.to_wif()
True
```### Public Keys
```python
>>> from keylib import ECPublicKey
```#### Public Keys from Private Keys
```python
>>> public_key = private_key.public_key()
>>> public_key.to_hex()
'03019979ec442e61ace8d47c6a344d791cee12d4e7bbde05fa91a62c0cda51c834'
```#### Imported Public Keys
```python
>>> imported_public_key = ECPublicKey(public_key.to_hex())
>>> print public_key.to_hex() == imported_public_key.to_hex()
True
```### Addresses
```python
>>> from keylib import public_key_to_address
```#### Addresses from Public Key Objects
```python
>>> public_key.address()
'12WDrxysCBDtVxaP1n4HHj8BLqqqfaqANd'
```#### RIPEMD160 Hashes from Public Key Objects
```python
>>> public_key.hash160()
'107eecc5868111ba06e6bd9309b2db90c555cb6e'
```#### Addresses from Hex Public Keys
```python
>>> public_key_to_address("030589ee559348bd6a7325994f9c8eff12bd5d73cc683142bd0dd1a17abc99b0dc")
'1KbUJ4x8epz6QqxkmZbTc4f79JbWWz6g37'
```