icplazapy


Nameicplazapy JSON
Version 3.0.0 PyPI version JSON
download
home_page
SummaryTools for Icplaza wallet management and offline transaction signing
upload_time2023-03-23 08:29:32
maintainer
docs_urlNone
author
requires_python>=3.7
license
keywords icplaza evmos cosmos blockchain atom cryptocurrency
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
[![PyPI version](https://img.shields.io/pypi/v/icplazapy)](https://pypi.org/project/icplazapy)

# icplazapy
- forked from [hukkin/cosmospy](https://github.com/hukkin/cosmospy)
- modified [hukkin/cosmospy](https://github.com/hukkin/cosmospy) to icplazapy
- icplaza chain is an evmos like chain.
<!--- Don't edit the version line below manually. Let bump2version do it for you. -->

> Version 3.0.0

> Tools for Icplaza wallet management and offline transaction signing

**Table of Contents**  *generated with [mdformat-toc](https://github.com/hukkin/mdformat-toc)*

<!-- mdformat-toc start --slug=github --maxlevel=6 --minlevel=2 -->

- [Installing](#installing)
- [Usage](#usage)
  - [Generating a wallet](#generating-a-wallet)
  - [Converter functions](#converter-functions)
    - [Mnemonic seed to private key](#mnemonic-seed-to-private-key)
    - [Private key to public key](#private-key-to-public-key)
    - [Public key to address](#public-key-to-address)
    - [Private key to address](#private-key-to-address)
    - [Public key to hex address](#public-key-to-hex-address)
    - [Private key to hex address](#private-key-to-hex-address)
    - [address from hex address](#address-from-hex-address)
    - [address to hex address](#address-to-hex-address)
  - [Signing transactions](#signing-transactions)

<!-- mdformat-toc end -->

## Installing<a name="installing"></a>

Installing from PyPI repository (https://pypi.org/project/icplazapy):

```bash
pip install icplazapy
```

## Usage<a name="usage"></a>

### Generating a wallet<a name="generating-a-wallet"></a>

```python
from icplazapy import generate_wallet

wallet = generate_wallet()
```

The value assigned to `wallet` will be a dictionary just like:

```python
{
    'seed': 'loan weapon tone clever party picture spot novel almost change rug primary speak entry usage maximum farm beyond magnet crazy later day addict orchard', 
    'derivation_path': "m/44'/118'/0'/0/0", 
    'private_key': b'\x06\xe5*di\x88q0\xe4\x08Y\x9aL\xcb\xd7\xc0\xac\xc6\x9d\x9a\x18\xc5$\x00\xacM5\xae\x1b\x07\xe7N', 'public_key': b'\x02Jj\xe8>y\xe0\xcb\xe2\x11oIX@29p\xd3\x1c\x83\xcd\xa4i\xb0\x9e\xd7\x9f!\xf5\xbe\xb7\xe1i', 
    'address': 'icplaza1ayuhuzmlkw3dr7ftajxcl9kzg4vvzr0ltwpwjl'
}
```

### Converter functions<a name="converter-functions"></a>

#### Mnemonic seed to private key<a name="mnemonic-seed-to-private-key"></a>

```python
from icplazapy import BIP32DerivationError, seed_to_privkey

seed = (
    "teach there dream chase fatigue abandon lava super senior artefact close upgrade"
)
try:
    privkey = seed_to_privkey(seed, path="m/44'/118'/0'/0/0")
except BIP32DerivationError:
    print("No valid private key in this derivation path!")
```

#### Private key to public key<a name="private-key-to-public-key"></a>

```python
from icplazapy import privkey_to_pubkey

privkey = bytes.fromhex(
    "6dcd05d7ac71e09d3cf7da666709ebd59362486ff9e99db0e8bc663570515afa"
)
pubkey = privkey_to_pubkey(privkey)
```

#### Public key to address<a name="public-key-to-address"></a>

```python
from icplazapy import pubkey_to_address

pubkey = bytes.fromhex(
    "03e8005aad74da5a053602f86e3151d4f3214937863a11299c960c28d3609c4775"
)
addr = pubkey_to_address(pubkey)
```

#### Private key to address<a name="private-key-to-address"></a>

```python
from icplazapy import privkey_to_address

privkey = bytes.fromhex(
    "6dcd05d7ac71e09d3cf7da666709ebd59362486ff9e99db0e8bc663570515afa"
)
addr = privkey_to_address(privkey)
```
#### Public key to hex address<a name="pubkey-to-hex-address"></a>

```python
from icplazapy import pubkey_to_hex_address

pubkey = bytes.fromhex(
    "03e8005aad74da5a053602f86e3151d4f3214937863a11299c960c28d3609c4775"
)
addr = pubkey_to_address(pubkey)
```
#### Private key to hex address<a name="privkey-to-hex-address"></a>
```python
from icplazapy import privkey_to_hex_address

privkey = bytes.fromhex(
    "6dcd05d7ac71e09d3cf7da666709ebd59362486ff9e99db0e8bc663570515afa"
)
addr = privkey_to_address(privkey)
```
#### address from hex address<a name="address-from-hex-address"></a>
```python
from icplazapy import from_hex_address
hex_addr = "0x4790155804CB6fd0D3697CBb367E75397408a587"
addr = from_hex_address(hex_addr)
```
#### address to hex address<a name="address-to-hex-address"></a>
```python
from icplazapy import to_hex_address
addr = "icplaza1g7gp2kqyedhap5mf0janvln4896q3fv87z2dm6"
hex_addr = to_hex_address(addr)
```


### Signing transactions<a name="signing-transactions"></a>

```python
from icplazapy import Transaction

tx = Transaction(
    privkey=bytes.fromhex(
        "26d167d549a4b2b66f766b0d3f2bdbe1cd92708818c338ff453abde316a2bd59"
    ),
    account_num=11335,
    sequence=0,
    fee=1000,
    gas=70000,
    memo="",
    chain_id="icplaza_9000-4",
    sync_mode="sync",
)
tx.add_transfer(
    recipient="icplaza1g7gp2kqyedhap5mf0janvln4896q3fv87z2dm6", amount=387000
)

pushable_tx = tx.get_pushable()


# Optionally submit the transaction using your preferred method.
# This example uses the httpx library.
import httpx

# icplaza rest api
api_base_url = ""
httpx.post(api_base_url + "/txs", data=pushable_tx)
```

One or more token transfers can be added to a transaction by calling the `add_transfer` method.

When the transaction is fully prepared, calling `get_pushable` will return a signed transaction in the form of a JSON string.
This can be used as request body when calling the `POST /txs` endpoint of the [Cosmos REST API](https://cosmos.network/rpc).


            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "icplazapy",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "icplaza,evmos,cosmos,blockchain,atom,cryptocurrency",
    "author": "",
    "author_email": "chuanfoo <442837306@qq.com>",
    "download_url": "https://files.pythonhosted.org/packages/21/2f/0d986fe62a8dc143a35fc60c62c5ccbc88b0fe076c7f9f84d104c952a9a3/icplazapy-3.0.0.tar.gz",
    "platform": null,
    "description": "\n[![PyPI version](https://img.shields.io/pypi/v/icplazapy)](https://pypi.org/project/icplazapy)\n\n# icplazapy\n- forked from [hukkin/cosmospy](https://github.com/hukkin/cosmospy)\n- modified [hukkin/cosmospy](https://github.com/hukkin/cosmospy) to icplazapy\n- icplaza chain is an evmos like chain.\n<!--- Don't edit the version line below manually. Let bump2version do it for you. -->\n\n> Version 3.0.0\n\n> Tools for Icplaza wallet management and offline transaction signing\n\n**Table of Contents**  *generated with [mdformat-toc](https://github.com/hukkin/mdformat-toc)*\n\n<!-- mdformat-toc start --slug=github --maxlevel=6 --minlevel=2 -->\n\n- [Installing](#installing)\n- [Usage](#usage)\n  - [Generating a wallet](#generating-a-wallet)\n  - [Converter functions](#converter-functions)\n    - [Mnemonic seed to private key](#mnemonic-seed-to-private-key)\n    - [Private key to public key](#private-key-to-public-key)\n    - [Public key to address](#public-key-to-address)\n    - [Private key to address](#private-key-to-address)\n    - [Public key to hex address](#public-key-to-hex-address)\n    - [Private key to hex address](#private-key-to-hex-address)\n    - [address from hex address](#address-from-hex-address)\n    - [address to hex address](#address-to-hex-address)\n  - [Signing transactions](#signing-transactions)\n\n<!-- mdformat-toc end -->\n\n## Installing<a name=\"installing\"></a>\n\nInstalling from PyPI repository (https://pypi.org/project/icplazapy):\n\n```bash\npip install icplazapy\n```\n\n## Usage<a name=\"usage\"></a>\n\n### Generating a wallet<a name=\"generating-a-wallet\"></a>\n\n```python\nfrom icplazapy import generate_wallet\n\nwallet = generate_wallet()\n```\n\nThe value assigned to `wallet` will be a dictionary just like:\n\n```python\n{\n    'seed': 'loan weapon tone clever party picture spot novel almost change rug primary speak entry usage maximum farm beyond magnet crazy later day addict orchard', \n    'derivation_path': \"m/44'/118'/0'/0/0\", \n    'private_key': b'\\x06\\xe5*di\\x88q0\\xe4\\x08Y\\x9aL\\xcb\\xd7\\xc0\\xac\\xc6\\x9d\\x9a\\x18\\xc5$\\x00\\xacM5\\xae\\x1b\\x07\\xe7N', 'public_key': b'\\x02Jj\\xe8>y\\xe0\\xcb\\xe2\\x11oIX@29p\\xd3\\x1c\\x83\\xcd\\xa4i\\xb0\\x9e\\xd7\\x9f!\\xf5\\xbe\\xb7\\xe1i', \n    'address': 'icplaza1ayuhuzmlkw3dr7ftajxcl9kzg4vvzr0ltwpwjl'\n}\n```\n\n### Converter functions<a name=\"converter-functions\"></a>\n\n#### Mnemonic seed to private key<a name=\"mnemonic-seed-to-private-key\"></a>\n\n```python\nfrom icplazapy import BIP32DerivationError, seed_to_privkey\n\nseed = (\n    \"teach there dream chase fatigue abandon lava super senior artefact close upgrade\"\n)\ntry:\n    privkey = seed_to_privkey(seed, path=\"m/44'/118'/0'/0/0\")\nexcept BIP32DerivationError:\n    print(\"No valid private key in this derivation path!\")\n```\n\n#### Private key to public key<a name=\"private-key-to-public-key\"></a>\n\n```python\nfrom icplazapy import privkey_to_pubkey\n\nprivkey = bytes.fromhex(\n    \"6dcd05d7ac71e09d3cf7da666709ebd59362486ff9e99db0e8bc663570515afa\"\n)\npubkey = privkey_to_pubkey(privkey)\n```\n\n#### Public key to address<a name=\"public-key-to-address\"></a>\n\n```python\nfrom icplazapy import pubkey_to_address\n\npubkey = bytes.fromhex(\n    \"03e8005aad74da5a053602f86e3151d4f3214937863a11299c960c28d3609c4775\"\n)\naddr = pubkey_to_address(pubkey)\n```\n\n#### Private key to address<a name=\"private-key-to-address\"></a>\n\n```python\nfrom icplazapy import privkey_to_address\n\nprivkey = bytes.fromhex(\n    \"6dcd05d7ac71e09d3cf7da666709ebd59362486ff9e99db0e8bc663570515afa\"\n)\naddr = privkey_to_address(privkey)\n```\n#### Public key to hex address<a name=\"pubkey-to-hex-address\"></a>\n\n```python\nfrom icplazapy import pubkey_to_hex_address\n\npubkey = bytes.fromhex(\n    \"03e8005aad74da5a053602f86e3151d4f3214937863a11299c960c28d3609c4775\"\n)\naddr = pubkey_to_address(pubkey)\n```\n#### Private key to hex address<a name=\"privkey-to-hex-address\"></a>\n```python\nfrom icplazapy import privkey_to_hex_address\n\nprivkey = bytes.fromhex(\n    \"6dcd05d7ac71e09d3cf7da666709ebd59362486ff9e99db0e8bc663570515afa\"\n)\naddr = privkey_to_address(privkey)\n```\n#### address from hex address<a name=\"address-from-hex-address\"></a>\n```python\nfrom icplazapy import from_hex_address\nhex_addr = \"0x4790155804CB6fd0D3697CBb367E75397408a587\"\naddr = from_hex_address(hex_addr)\n```\n#### address to hex address<a name=\"address-to-hex-address\"></a>\n```python\nfrom icplazapy import to_hex_address\naddr = \"icplaza1g7gp2kqyedhap5mf0janvln4896q3fv87z2dm6\"\nhex_addr = to_hex_address(addr)\n```\n\n\n### Signing transactions<a name=\"signing-transactions\"></a>\n\n```python\nfrom icplazapy import Transaction\n\ntx = Transaction(\n    privkey=bytes.fromhex(\n        \"26d167d549a4b2b66f766b0d3f2bdbe1cd92708818c338ff453abde316a2bd59\"\n    ),\n    account_num=11335,\n    sequence=0,\n    fee=1000,\n    gas=70000,\n    memo=\"\",\n    chain_id=\"icplaza_9000-4\",\n    sync_mode=\"sync\",\n)\ntx.add_transfer(\n    recipient=\"icplaza1g7gp2kqyedhap5mf0janvln4896q3fv87z2dm6\", amount=387000\n)\n\npushable_tx = tx.get_pushable()\n\n\n# Optionally submit the transaction using your preferred method.\n# This example uses the httpx library.\nimport httpx\n\n# icplaza rest api\napi_base_url = \"\"\nhttpx.post(api_base_url + \"/txs\", data=pushable_tx)\n```\n\nOne or more token transfers can be added to a transaction by calling the `add_transfer` method.\n\nWhen the transaction is fully prepared, calling `get_pushable` will return a signed transaction in the form of a JSON string.\nThis can be used as request body when calling the `POST /txs` endpoint of the [Cosmos REST API](https://cosmos.network/rpc).\n\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Tools for Icplaza wallet management and offline transaction signing",
    "version": "3.0.0",
    "split_keywords": [
        "icplaza",
        "evmos",
        "cosmos",
        "blockchain",
        "atom",
        "cryptocurrency"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4159334231e659a1aae03a722c597746eeafdf97acfc9d1c78cc7949d7172e97",
                "md5": "6db9849e3ef07748d968303978f96f5f",
                "sha256": "1d46435b9732bdb593e327753d4bbce0e7e0f96074896cbd891b1a17160c79f5"
            },
            "downloads": -1,
            "filename": "icplazapy-3.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6db9849e3ef07748d968303978f96f5f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 7654,
            "upload_time": "2023-03-23T08:29:30",
            "upload_time_iso_8601": "2023-03-23T08:29:30.393172Z",
            "url": "https://files.pythonhosted.org/packages/41/59/334231e659a1aae03a722c597746eeafdf97acfc9d1c78cc7949d7172e97/icplazapy-3.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "212f0d986fe62a8dc143a35fc60c62c5ccbc88b0fe076c7f9f84d104c952a9a3",
                "md5": "2dc7129a3656f45cd10212fe6912fd42",
                "sha256": "151ca2222678cfc4ebe472b957aa844f665e1de96a4852281a55affc983e8dfd"
            },
            "downloads": -1,
            "filename": "icplazapy-3.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "2dc7129a3656f45cd10212fe6912fd42",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 6988,
            "upload_time": "2023-03-23T08:29:32",
            "upload_time_iso_8601": "2023-03-23T08:29:32.850631Z",
            "url": "https://files.pythonhosted.org/packages/21/2f/0d986fe62a8dc143a35fc60c62c5ccbc88b0fe076c7f9f84d104c952a9a3/icplazapy-3.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-03-23 08:29:32",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "icplazapy"
}
        
Elapsed time: 0.08125s