Skip to content

Commit

Permalink
Bump to 1.0.2 (#7)
Browse files Browse the repository at this point in the history
* Cleanup naming, add examples to readme

* Bump ecdsa
  • Loading branch information
ksiazkowicz authored Apr 10, 2020
1 parent 5da2137 commit 57deb86
Show file tree
Hide file tree
Showing 15 changed files with 198 additions and 76 deletions.
75 changes: 75 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,81 @@ Library is available on PyPi, you can simply install it using `pip`.
$ pip install aioeos
```

## Usage

### Importing a private key

```
from aioeos import EosAccount
account = EosAccount(private_key='your key')
```

### Transferring funds

```
from aioeos import EosJsonRpc, EosTransaction
from aioeos.contracts import eosio_token
rpc = EosJsonRpc(url='http://127.0.0.1:8888')
block = await rpc.get_head_block()
transaction = EosTransaction(
ref_block_num=block['block_num'] & 65535,
ref_block_prefix=block['ref_block_prefix'],
actions=[
eosio_token.transfer(
from_addr=account.name,
to_addr='mysecondacc1',
quantity='1.0000 EOS',
authorization=[account.authorization('active')]
)
]
)
await rpc.sign_and_push_transaction(transaction, keys=[account.key])
```

### Creating a new account

```
from aioeos import EosJsonRpc, EosTransaction, EosAuthority
from aioeos.contracts import eosio
main_account = EosAccount(name='mainaccount1', private_key='private key')
new_account = EosAccount(name='mysecondacc1')
owner = EosAuthority(
threshold=1,
keys=[new_account.key.to_key_weight(1)]
)
rpc = EosJsonRpc(url='http://127.0.0.1:8888')
block = await rpc.get_head_block()
await rpc.sign_and_push_transaction(
EosTransaction(
ref_block_num=block['block_num'] & 65535,
ref_block_prefix=block['ref_block_prefix'],
actions=[
eosio.newaccount(
main_account.name,
new_account.name,
owner=owner,
authorization=[main_account.authorization('active')]
),
eosio.buyrambytes(
main_account.name,
new_account.name,
2048,
authorization=[main_account.authorization('active')]
)
],
),
keys=[main_account.key]
)
```

## Documentation

Docs and usage examples are available [here](https://aioeos.readthedocs.io/en/latest).
Expand Down
37 changes: 37 additions & 0 deletions aioeos/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from . import serializer, exceptions # noqa
from .account import EosAccount # noqa
from .keys import EosKey # noqa
from .rpc import EosJsonRpc # noqa
from .types import (
UInt8, UInt16, UInt32, UInt64, Int8, Int16, Int32, Int64, VarUInt, Float32,
Float64, TimePointSec, TimePoint, Name, AbiBytes, BaseAbiObject,
is_abi_object, EosPermissionLevel, EosKeyWeight, EosPermissionLevelWeight,
EosWaitWeight, EosAuthority, AbiActionPayload, EosAction, EosTransaction
) # noqa

__all__ = [
'serializer',
'exceptions',

# Account
'EosAccount',

# Keys
'EosKey',

# RPC
'EosJsonRpc',

# types
# base ABI types
'UInt8', 'UInt16', 'UInt32', 'UInt64', 'Int8', 'Int16', 'Int32', 'Int64',
'VarUInt', 'Float32', 'Float64', 'TimePointSec', 'TimePoint', 'Name',
'AbiBytes', 'BaseAbiObject', 'is_abi_object',

# authority
'EosPermissionLevel', 'EosKeyWeight', 'EosPermissionLevelWeight',
'EosWaitWeight', 'EosAuthority',

# transaction
'AbiActionPayload', 'EosAction', 'EosTransaction'
]
18 changes: 9 additions & 9 deletions aioeos/account.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from typing import Optional

from aioeos.keys import EOSKey
from aioeos.keys import EosKey
from aioeos.types import EosPermissionLevel, EosPermissionLevelWeight


class EOSAccount:
class EosAccount:
"""
Describes account on EOS blockchain. Contrary to other blockchains such as
Bitcoin or Ethereum, public key is not an address. An account can have
Expand All @@ -17,20 +17,20 @@ class EOSAccount:
:param name: name of the account,
Please provide key in one of the formats - EOSKey instance, private key in
WIF format and public key. Only one of these is accepted. If no key is
provided, a new one will be generated.
Please provide key in one of the formats - EosKey instance, private key in
WIF or PVT format and public key. Only one of these is accepted. If no key
is provided, a new one will be generated.
;param key: EOSKey instance,
:param private_key: private key in wif format,
;param key: EosKey instance,
:param private_key: private key in WIF or PVT format,
:param public_key: public key
"""

def __init__(
self,
name: str,
*,
key: Optional[EOSKey] = None,
key: Optional[EosKey] = None,
private_key: str = '',
public_key: str = '',
):
Expand All @@ -47,7 +47,7 @@ def __init__(

self.name = name
self.key = (
key or EOSKey(public_key=public_key, private_key=private_key)
key or EosKey(public_key=public_key, private_key=private_key)
)

def authorization(self, permission: str) -> EosPermissionLevel:
Expand Down
19 changes: 6 additions & 13 deletions aioeos/keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
from aioeos.types import EosKeyWeight


class EOSKey:
class EosKey:
"""
EOSKey instance.
EosKey instance.
Depends on which kwargs are given, this works in a different way:
- No kwargs - generates a new private key
- Only private_key - public key is being derived from private key
- Only public_key - EOSKey instance has no private key
- Only public_key - EosKey instance has no private key
"""

def __init__(self, *, private_key: str = None, public_key: str = None):
Expand Down Expand Up @@ -143,17 +143,10 @@ def _recovery_pubkey_param(self, digest, signature):
if p.to_string() == self._vk.to_string():
return i

def _compress_pubkey(self):
order = self._vk.curve.generator.order()
point = self._vk.pubkey.point
return (
bytes([2 + (point.y() & 1)])
+ ecdsa.util.number_to_string(point.x(), order)
)

def to_public(self):
"""Returns compressed, base58 encoded public key prefixed with EOS"""
return f'EOS{self._check_encode(self._compress_pubkey())}'
compressed = self._vk.to_string(encoding='compressed')
return f'EOS{self._check_encode(compressed)}'

def to_wif(self):
"""Converts private key to legacy WIF format"""
Expand Down Expand Up @@ -230,5 +223,5 @@ def to_key_weight(self, weight: int) -> EosKeyWeight:
return EosKeyWeight(key=self.to_public(), weight=weight)

def __eq__(self, other) -> bool:
assert isinstance(other, EOSKey), 'Can compare only to EOSKey instance'
assert isinstance(other, EosKey), 'Can compare only to EosKey instance'
return self.to_public() == other.to_public()
4 changes: 2 additions & 2 deletions aioeos/rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from aiohttp import ClientSession
from aioeos import exceptions, serializer
from aioeos.keys import EOSKey
from aioeos.keys import EosKey
from aioeos.types import EosTransaction, is_abi_object


Expand Down Expand Up @@ -206,7 +206,7 @@ async def sign_and_push_transaction(
transaction: EosTransaction,
*,
context_free_bytes: bytes = bytes(32),
keys: List[EOSKey] = []
keys: List[EosKey] = []
):
for action in transaction.actions:
if isinstance(action.data, dict):
Expand Down
11 changes: 11 additions & 0 deletions docs/source/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
Changelog
=========

1.0.2 (10.04.2020)
------------------

- Tested library against RPC node,
- EosAccount API,
- Support using EOS ABI objects as action payloads,
- Signing support in RPC client,
- Cached chain ID,
- Simplified Getting Started guide,
- EOSKey renamed to EosKey

1.0.1 (03.04.2020)
------------------

Expand Down
14 changes: 5 additions & 9 deletions docs/source/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,10 @@ account.

::

from aioeos.account import EOSAccount
from aioeos import EosAccount, EosTransaction
from aioeos.contracts import eosio_token
from aioeos.types import EosTransaction

test_account = EOSAccount(
test_account = EosAccount(
name='eostest12345',
private_key='5JeaxignXEg3mGwvgmwxG6w6wHcRp9ooPw81KjrP2ah6TWSECDN'
)
Expand All @@ -135,7 +134,7 @@ blockchain, we need to ask our RPC node to convert it for us.

::

from aioeos.rpc import EosJsonRpc
from aioeos import EosJsonRpc

rpc = EosJsonRpc(url='http://127.0.0.1:8888')

Expand Down Expand Up @@ -184,14 +183,11 @@ Complete example code::

import asyncio

from aioeos.account import EOSAccount
from aioeos import EosAccount, EosJsonRpc, EosTransaction
from aioeos.contracts import eosio_token
from aioeos.rpc import EosJsonRpc
from aioeos.types import EosTransaction


async def example():
test_account = EOSAccount(
test_account = EosAccount(
name='eostest12345',
private_key='5JeaxignXEg3mGwvgmwxG6w6wHcRp9ooPw81KjrP2ah6TWSECDN'
)
Expand Down
39 changes: 23 additions & 16 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 57deb86

Please sign in to comment.