Low Level

HttpClient

A fast urllib3 based HTTP client that features:

  • Connection Pooling
  • Concurrent Processing
  • Automatic Node Failover

The functionality of HttpClient is encapsulated by Steem class. You shouldn’t be using HttpClient directly, unless you know exactly what you’re doing.

class steembase.http_client.HttpClient(nodes, **kwargs)

Simple Steem JSON-HTTP-RPC API

This class serves as an abstraction layer for easy use of the Steem API.

Parameters:nodes (list) – A list of Steem HTTP RPC nodes to connect to.
from steem.http_client import HttpClient
rpc = HttpClient(['https://steemd-node1.com', 'https://steemd-node2.com'])

any call available to that port can be issued using the instance via the syntax rpc.exec('command', *parameters).

Example:

rpc.exec(
    'get_followers',
    'furion', 'abit', 'blog', 10,
    api='follow_api'
)
exec(name, *args, api=None, return_with_args=None, _ret_cnt=0)

Execute a method against steemd RPC.

Warning

This command will auto-retry in case of node failure, as well as handle node fail-over, unless we are broadcasting a transaction. In latter case, the exception is re-raised.

static json_rpc_body(name, *args, api=None, as_json=True, _id=0)

Build request body for steemd RPC requests.

Parameters:
  • name (str) – Name of a method we are trying to call. (ie: get_accounts)
  • args – A list of arguments belonging to the calling method.
  • api (None, str) – If api is provided (ie: follow_api), we generate a body that uses call method appropriately.
  • as_json (bool) – Should this function return json as dictionary or string.
  • _id (int) – This is an arbitrary number that can be used for request/response tracking in multi-threaded scenarios.
Returns:

If as_json is set to True, we get json formatted as a string. Otherwise, a Python dictionary is returned.

Return type:

(dict,str)

next_node()

Switch to the next available node.

This method will change base URL of our requests. Use it when the current node goes down to change to a fallback node.

set_node(node_url)

Change current node to provided node URL.


steembase

SteemBase contains various primitives for building higher level abstractions. This module should only be used by library developers or people with deep domain knowledge.

Warning: Not all methods are documented. Please see source.

https://i.imgur.com/A9urMG9.png

Account

class steembase.account.Address(address=None, pubkey=None, prefix='STM')

Address class

This class serves as an address representation for Public Keys.

Parameters:
  • address (str) – Base58 encoded address (defaults to None)
  • pubkey (str) – Base58 encoded pubkey (defaults to None)
  • prefix (str) – Network prefix (defaults to GPH)

Example:

Address("GPHFN9r6VYzBK8EKtMewfNbfiGCr56pHDBFi")
derivesha256address()

Derive address using RIPEMD160(SHA256(x))

derivesha512address()

Derive address using RIPEMD160(SHA512(x))

class steembase.account.BrainKey(brainkey=None, sequence=0)

Brainkey implementation similar to the graphene-ui web-wallet.

Parameters:
  • brainkey (str) – Brain Key
  • sequence (int) – Sequence number for consecutive keys

Keys in Graphene are derived from a seed brain key which is a string of 16 words out of a predefined dictionary with 49744 words. It is a simple single-chain key derivation scheme that is not compatible with BIP44 but easy to use.

Given the brain key, a private key is derived as:

privkey = SHA256(SHA512(brainkey + " " + sequence))

Incrementing the sequence number yields a new key that can be regenerated given the brain key.

get_brainkey()

Return brain key of this instance

get_private()

Derive private key from the brain key and the current sequence number

next_sequence()

Increment the sequence number by 1

normalize(brainkey)

Correct formating with single whitespace syntax and no trailing space

suggest()

Suggest a new random brain key. Randomness is provided by the operating system using os.urandom().

class steembase.account.PasswordKey(account, password, role='active')

This class derives a private key given the account name, the role and a password. It leverages the technology of Brainkeys and allows people to have a secure private key by providing a passphrase only.

get_private()

Derive private key from the brain key and the current sequence number

class steembase.account.PrivateKey(wif=None, prefix='STM')

Derives the compressed and uncompressed public keys and constructs two instances of PublicKey:

Parameters:
  • wif (str) – Base58check-encoded wif key
  • prefix (str) – Network prefix (defaults to GPH)

Example::

PrivateKey("5HqUkGuo62BfcJU5vNhTXKJRXuUi9QSE6jp8C3uBJ2BVHtB8WSd")

Compressed vs. Uncompressed:

  • PrivateKey("w-i-f").pubkey:
    Instance of PublicKey using compressed key.
  • PrivateKey("w-i-f").pubkey.address:
    Instance of Address using compressed key.
  • PrivateKey("w-i-f").uncompressed:
    Instance of PublicKey using uncompressed key.
  • PrivateKey("w-i-f").uncompressed.address:
    Instance of Address using uncompressed key.
compressedpubkey()

Derive uncompressed public key

class steembase.account.PublicKey(pk, prefix='STM')

This class deals with Public Keys and inherits Address.

Parameters:
  • pk (str) – Base58 encoded public key
  • prefix (str) – Network prefix (defaults to GPH)

Example::

PublicKey("GPH6UtYWWs3rkZGV8JA86qrgkG6tyFksgECefKE1MiH4HkLD8PFGL")

Note

By default, graphene-based networks deal with compressed public keys. If an uncompressed key is required, the method unCompressed can be used:

PublicKey("xxxxx").unCompressed()
compressed()

Derive compressed public key

point()

Return the point for the public key

unCompressed()

Derive uncompressed key


Base58

class steembase.base58.Base58(data, prefix='STM')

Base58 base class

This class serves as an abstraction layer to deal with base58 encoded strings and their corresponding hex and binary representation throughout the library.

Parameters:
  • data (hex, wif, bip38 encrypted wif, base58 string) – Data to initialize object, e.g. pubkey data, address data, …
  • prefix (str) – Prefix to use for Address/PubKey strings (defaults to GPH)
Returns:

Base58 object initialized with data

Return type:

Base58

Raises:

ValueError – if data cannot be decoded

  • bytes(Base58): Returns the raw data
  • str(Base58): Returns the readable Base58CheckEncoded data.
  • repr(Base58): Gives the hex representation of the data.
  • format(Base58,_format) Formats the instance according to _format:
    • "btc": prefixed with 0x80. Yields a valid btc address
    • "wif": prefixed with 0x00. Yields a valid wif key
    • "bts": prefixed with BTS
    • etc.

Bip38

steembase.bip38.decrypt(encrypted_privkey, passphrase)

BIP0038 non-ec-multiply decryption. Returns WIF privkey.

Parameters:
  • encrypted_privkey (Base58) – Private key
  • passphrase (str) – UTF-8 encoded passphrase for decryption
Returns:

BIP0038 non-ec-multiply decrypted key

Return type:

Base58

Raises:

SaltException – if checksum verification failed (e.g. wrong password)

steembase.bip38.encrypt(privkey, passphrase)

BIP0038 non-ec-multiply encryption. Returns BIP0038 encrypted privkey.

Parameters:
  • privkey (Base58) – Private key
  • passphrase (str) – UTF-8 encoded passphrase for encryption
Returns:

BIP0038 non-ec-multiply encrypted wif key

Return type:

Base58


Memo

steembase.memo.decode_memo(priv, message)

Decode a message with a shared secret between Alice and Bob

Parameters:
  • priv (PrivateKey) – Private Key (of Bob)
  • message (base58encoded) – Encrypted Memo message
Returns:

Decrypted message

Return type:

str

Raises:

ValueError – if message cannot be decoded as valid UTF-8 string

steembase.memo.encode_memo(priv, pub, nonce, message, **kwargs)

Encode a message with a shared secret between Alice and Bob

Parameters:
  • priv (PrivateKey) – Private Key (of Alice)
  • pub (PublicKey) – Public Key (of Bob)
  • nonce (int) – Random nonce
  • message (str) – Memo message
Returns:

Encrypted message

Return type:

hex

steembase.memo.get_shared_secret(priv, pub)

Derive the share secret between priv and pub

Parameters:
Returns:

Shared secret

Return type:

hex

The shared secret is generated such that:

Pub(Alice) * Priv(Bob) = Pub(Bob) * Priv(Alice)
steembase.memo.init_aes(shared_secret, nonce)

Initialize AES instance

Parameters:
  • shared_secret (hex) – Shared Secret to use as encryption key
  • nonce (int) – Random nonce
Returns:

AES instance and checksum of the encryption key

Return type:

length 2 tuple

steembase.memo.involved_keys(message)

decode structure


Operations

class steembase.operations.CommentOptionExtensions(o)

Serialize Comment Payout Beneficiaries.

Parameters:beneficiaries (list) – A static_variant containing beneficiaries.

Example

[0,
    {'beneficiaries': [
        {'account': 'furion', 'weight': 10000}
    ]}
]
class steembase.operations.GrapheneObject(data=None)

Core abstraction class

This class is used for any JSON reflected object in Graphene.

  • instance.__json__(): encodes data into json format
  • bytes(instance): encodes data into wire format
  • str(instances): dumps json object as string

Transactions

class steembase.transactions.SignedTransaction(*args, **kwargs)

Create a signed transaction and offer method to create the signature

Parameters:
  • refNum (num) – parameter ref_block_num (see getBlockParams)
  • refPrefix (num) – parameter ref_block_prefix (see getBlockParams)
  • expiration (str) – expiration date
  • operations (Array) – array of operations
derSigToHexSig(s)

Format DER to HEX signature

recoverPubkeyParameter(digest, signature, pubkey)

Use to derive a number that allows to easily recover the public key from the signature

recover_public_key(digest, signature, i)

Recover the public key from the the signature

sign(wifkeys, chain=None)

Sign the transaction with the provided private keys.

Parameters:
  • wifkeys (list) – Array of wif keys
  • chain (str) – identifier for the chain
steembase.transactions.fmt_time_from_now(secs=0)

Properly Format Time that is x seconds in the future

Parameters:secs (int) – Seconds to go in the future (x>0) or the past (x<0)
Returns:Properly formated time for Graphene (%Y-%m-%dT%H:%M:%S)
Return type:str
steembase.transactions.get_block_params(steem)

Auxiliary method to obtain ref_block_num and ref_block_prefix. Requires a websocket connection to a witness node!


Types

steembase.types.JsonObj(data)

Returns json object from data

class steembase.types.ObjectId(object_str, type_verify=None)

Encodes object/protocol ids

steembase.types.variable_buffer(s)

Encode variable length buffer

steembase.types.varint(n)

Varint encoding

steembase.types.varintdecode(data)

Varint decoding


Exceptions

steembase.exceptions.decodeRPCErrorMsg(e)

Helper function to decode the raised Exception and give it a python Exception class