Skip to main content

Tools for Cosmos wallet management and offline transaction signing

Project description

Build Status codecov.io PyPI version Code style: black

cosmospy

Version 5.1.1

Tools for Cosmos wallet management and offline transaction signing

Table of Contents generated with mdformat-toc

Installing

Installing from PyPI repository (https://pypi-hypernode.com/project/cosmospy):

pip install cosmospy

Usage

Generating a wallet

from cosmospy import generate_wallet

wallet = generate_wallet()

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

{
    "seed": "arch skill acquire abuse frown reject front second album pizza hill slogan guess random wonder benefit industry custom green ill moral daring glow elevator",
    "derivation_path": "m/44'/118'/0'/0/0",
    "private_key": b"\xbb\xec^\xf6\xdcg\xe6\xb5\x89\xed\x8cG\x05\x03\xdf0:\xc9\x8b \x85\x8a\x14\x12\xd7\xa6a\x01\xcd\xf8\x88\x93",
    "public_key": b"\x03h\x1d\xae\xa7\x9eO\x8e\xc5\xff\xa3sAw\xe6\xdd\xc9\xb8b\x06\x0eo\xc5a%z\xe3\xff\x1e\xd2\x8e5\xe7",
    "address": "cosmos1uuhna3psjqfxnw4msrfzsr0g08yuyfxeht0qfh",
}

Converter functions

Mnemonic seed to private key

from cosmospy 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

from cosmospy import privkey_to_pubkey

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

Public key to address

from cosmospy import pubkey_to_address

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

Private key to address

from cosmospy import privkey_to_address

privkey = bytes.fromhex(
    "6dcd05d7ac71e09d3cf7da666709ebd59362486ff9e99db0e8bc663570515afa"
)
addr = privkey_to_address(privkey)

Signing transactions

from cosmospy import Transaction

tx = Transaction(
    privkey=bytes.fromhex(
        "26d167d549a4b2b66f766b0d3f2bdbe1cd92708818c338ff453abde316a2bd59"
    ),
    account_num=11335,
    sequence=0,
    fee=1000,
    gas=70000,
    memo="",
    chain_id="cosmoshub-3",
    sync_mode="sync",
)
tx.add_transfer(
    recipient="cosmos103l758ps7403sd9c0y8j6hrfw4xyl70j4mmwkf", amount=387000
)
tx.add_transfer(recipient="cosmos1lzumfk6xvwf9k9rk72mqtztv867xyem393um48", amount=123)
pushable_tx = tx.get_pushable()

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cosmospy-5.1.1.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

cosmospy-5.1.1-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file cosmospy-5.1.1.tar.gz.

File metadata

  • Download URL: cosmospy-5.1.1.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.8.0 Linux/5.4.0-52-generic

File hashes

Hashes for cosmospy-5.1.1.tar.gz
Algorithm Hash digest
SHA256 2cc151d4a3ea279260f4fe11438d482617604b18fe1d7c64fe60a587429c0f14
MD5 3e7e0ea9d634ce45cd1bbb70ee3fa2d3
BLAKE2b-256 56d55d7e1b2a96a53bb79f1d7f4e2244e03c278e1cfdd382df185d4866be20d9

See more details on using hashes here.

Provenance

File details

Details for the file cosmospy-5.1.1-py3-none-any.whl.

File metadata

  • Download URL: cosmospy-5.1.1-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.8.0 Linux/5.4.0-52-generic

File hashes

Hashes for cosmospy-5.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 105073aef381d4f2842b136411d6726d0652320907dc478d7a45987c4e64c2a8
MD5 1c0646b51b536c1e64b89d9881aebcbf
BLAKE2b-256 05472e0a496928961854ee615be932757a8736bfbb79b0628b2a7700bcb0f289

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page