hive-nectar 0.0.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of hive-nectar might be problematic. Click here for more details.
- hive_nectar-0.0.2.dist-info/METADATA +182 -0
- hive_nectar-0.0.2.dist-info/RECORD +86 -0
- hive_nectar-0.0.2.dist-info/WHEEL +4 -0
- hive_nectar-0.0.2.dist-info/entry_points.txt +2 -0
- hive_nectar-0.0.2.dist-info/licenses/LICENSE.txt +23 -0
- nectar/__init__.py +32 -0
- nectar/account.py +4371 -0
- nectar/amount.py +475 -0
- nectar/asciichart.py +270 -0
- nectar/asset.py +82 -0
- nectar/block.py +446 -0
- nectar/blockchain.py +1178 -0
- nectar/blockchaininstance.py +2284 -0
- nectar/blockchainobject.py +221 -0
- nectar/blurt.py +563 -0
- nectar/cli.py +6285 -0
- nectar/comment.py +1217 -0
- nectar/community.py +513 -0
- nectar/constants.py +111 -0
- nectar/conveyor.py +309 -0
- nectar/discussions.py +1709 -0
- nectar/exceptions.py +149 -0
- nectar/hive.py +546 -0
- nectar/hivesigner.py +420 -0
- nectar/imageuploader.py +72 -0
- nectar/instance.py +129 -0
- nectar/market.py +1013 -0
- nectar/memo.py +449 -0
- nectar/message.py +357 -0
- nectar/nodelist.py +444 -0
- nectar/price.py +557 -0
- nectar/profile.py +65 -0
- nectar/rc.py +308 -0
- nectar/snapshot.py +726 -0
- nectar/steem.py +582 -0
- nectar/storage.py +53 -0
- nectar/transactionbuilder.py +622 -0
- nectar/utils.py +545 -0
- nectar/version.py +2 -0
- nectar/vote.py +557 -0
- nectar/wallet.py +472 -0
- nectar/witness.py +617 -0
- nectarapi/__init__.py +11 -0
- nectarapi/exceptions.py +123 -0
- nectarapi/graphenerpc.py +589 -0
- nectarapi/node.py +178 -0
- nectarapi/noderpc.py +229 -0
- nectarapi/rpcutils.py +97 -0
- nectarapi/version.py +2 -0
- nectarbase/__init__.py +14 -0
- nectarbase/ledgertransactions.py +75 -0
- nectarbase/memo.py +243 -0
- nectarbase/objects.py +429 -0
- nectarbase/objecttypes.py +22 -0
- nectarbase/operationids.py +102 -0
- nectarbase/operations.py +1297 -0
- nectarbase/signedtransactions.py +48 -0
- nectarbase/transactions.py +11 -0
- nectarbase/version.py +2 -0
- nectargrapheneapi/__init__.py +6 -0
- nectargraphenebase/__init__.py +27 -0
- nectargraphenebase/account.py +846 -0
- nectargraphenebase/aes.py +52 -0
- nectargraphenebase/base58.py +192 -0
- nectargraphenebase/bip32.py +494 -0
- nectargraphenebase/bip38.py +134 -0
- nectargraphenebase/chains.py +149 -0
- nectargraphenebase/dictionary.py +3 -0
- nectargraphenebase/ecdsasig.py +326 -0
- nectargraphenebase/objects.py +123 -0
- nectargraphenebase/objecttypes.py +6 -0
- nectargraphenebase/operationids.py +3 -0
- nectargraphenebase/operations.py +23 -0
- nectargraphenebase/prefix.py +11 -0
- nectargraphenebase/py23.py +38 -0
- nectargraphenebase/signedtransactions.py +201 -0
- nectargraphenebase/types.py +419 -0
- nectargraphenebase/unsignedtransactions.py +283 -0
- nectargraphenebase/version.py +2 -0
- nectarstorage/__init__.py +38 -0
- nectarstorage/base.py +306 -0
- nectarstorage/exceptions.py +16 -0
- nectarstorage/interfaces.py +237 -0
- nectarstorage/masterpassword.py +239 -0
- nectarstorage/ram.py +30 -0
- nectarstorage/sqlite.py +334 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
import base64
|
|
3
|
+
import hashlib
|
|
4
|
+
|
|
5
|
+
try:
|
|
6
|
+
from Cryptodome import Random
|
|
7
|
+
from Cryptodome.Cipher import AES
|
|
8
|
+
except ImportError:
|
|
9
|
+
try:
|
|
10
|
+
from Crypto import Random
|
|
11
|
+
from Crypto.Cipher import AES
|
|
12
|
+
except ImportError:
|
|
13
|
+
raise ImportError("Missing dependency: pyCryptodome")
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class AESCipher(object):
|
|
17
|
+
"""
|
|
18
|
+
A classical AES Cipher. Can use any size of data and any size of password thanks to padding.
|
|
19
|
+
Also ensure the coherence and the type of the data with a unicode to byte converter.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
def __init__(self, key):
|
|
23
|
+
self.bs = 32
|
|
24
|
+
self.key = hashlib.sha256(AESCipher.str_to_bytes(key)).digest()
|
|
25
|
+
|
|
26
|
+
@staticmethod
|
|
27
|
+
def str_to_bytes(data):
|
|
28
|
+
u_type = type(b"".decode("utf8"))
|
|
29
|
+
if isinstance(data, u_type):
|
|
30
|
+
return data.encode("utf8")
|
|
31
|
+
return data
|
|
32
|
+
|
|
33
|
+
def _pad(self, s):
|
|
34
|
+
return s + (self.bs - len(s) % self.bs) * AESCipher.str_to_bytes(
|
|
35
|
+
chr(self.bs - len(s) % self.bs)
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
@staticmethod
|
|
39
|
+
def _unpad(s):
|
|
40
|
+
return s[: -ord(s[len(s) - 1 :])]
|
|
41
|
+
|
|
42
|
+
def encrypt(self, raw):
|
|
43
|
+
raw = self._pad(AESCipher.str_to_bytes(raw))
|
|
44
|
+
iv = Random.new().read(AES.block_size)
|
|
45
|
+
cipher = AES.new(self.key, AES.MODE_CBC, iv)
|
|
46
|
+
return base64.b64encode(iv + cipher.encrypt(raw)).decode("utf-8")
|
|
47
|
+
|
|
48
|
+
def decrypt(self, enc):
|
|
49
|
+
enc = base64.b64decode(enc)
|
|
50
|
+
iv = enc[: AES.block_size]
|
|
51
|
+
cipher = AES.new(self.key, AES.MODE_CBC, iv)
|
|
52
|
+
return self._unpad(cipher.decrypt(enc[AES.block_size :])).decode("utf-8")
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
import hashlib
|
|
3
|
+
import logging
|
|
4
|
+
import string
|
|
5
|
+
from binascii import hexlify, unhexlify
|
|
6
|
+
|
|
7
|
+
from .prefix import Prefix
|
|
8
|
+
from .py23 import integer_types, py23_bytes, py23_chr, string_types
|
|
9
|
+
|
|
10
|
+
log = logging.getLogger(__name__)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class Base58(Prefix):
|
|
14
|
+
"""Base58 base class
|
|
15
|
+
|
|
16
|
+
This class serves as an abstraction layer to deal with base58 encoded
|
|
17
|
+
strings and their corresponding hex and binary representation throughout the
|
|
18
|
+
library.
|
|
19
|
+
|
|
20
|
+
:param data: Data to initialize object, e.g. pubkey data, address data, ...
|
|
21
|
+
:type data: hex, wif, bip38 encrypted wif, base58 string
|
|
22
|
+
:param str prefix: Prefix to use for Address/PubKey strings (defaults to ``GPH``)
|
|
23
|
+
:return: Base58 object initialized with ``data``
|
|
24
|
+
:rtype: Base58
|
|
25
|
+
:raises ValueError: if data cannot be decoded
|
|
26
|
+
|
|
27
|
+
* ``bytes(Base58)``: Returns the raw data
|
|
28
|
+
* ``str(Base58)``: Returns the readable ``Base58CheckEncoded`` data.
|
|
29
|
+
* ``repr(Base58)``: Gives the hex representation of the data.
|
|
30
|
+
* ``format(Base58,_format)``: Formats the instance according to ``_format``
|
|
31
|
+
|
|
32
|
+
* ``"btc"``: prefixed with ``0x80``. Yields a valid btc address
|
|
33
|
+
* ``"wif"``: prefixed with ``0x00``. Yields a valid wif key
|
|
34
|
+
* ``"bts"``: prefixed with ``BTS``
|
|
35
|
+
* etc.
|
|
36
|
+
|
|
37
|
+
"""
|
|
38
|
+
|
|
39
|
+
def __init__(self, data, prefix=None):
|
|
40
|
+
self.set_prefix(prefix)
|
|
41
|
+
if isinstance(data, Base58):
|
|
42
|
+
data = repr(data)
|
|
43
|
+
if all(c in string.hexdigits for c in data):
|
|
44
|
+
self._hex = data
|
|
45
|
+
elif data[0] == "5" or data[0] == "6":
|
|
46
|
+
self._hex = base58CheckDecode(data)
|
|
47
|
+
elif data[0] == "K" or data[0] == "L":
|
|
48
|
+
self._hex = base58CheckDecode(data)[:-2]
|
|
49
|
+
elif data[: len(self.prefix)] == self.prefix:
|
|
50
|
+
self._hex = gphBase58CheckDecode(data[len(self.prefix) :])
|
|
51
|
+
else:
|
|
52
|
+
raise ValueError("Error loading Base58 object")
|
|
53
|
+
|
|
54
|
+
def __format__(self, _format):
|
|
55
|
+
"""Format output according to argument _format (wif,btc,...)
|
|
56
|
+
|
|
57
|
+
:param str _format: Format to use
|
|
58
|
+
:return: formatted data according to _format
|
|
59
|
+
:rtype: str
|
|
60
|
+
|
|
61
|
+
"""
|
|
62
|
+
if _format.upper() == "WIF":
|
|
63
|
+
return base58CheckEncode(0x80, self._hex)
|
|
64
|
+
elif _format.upper() == "ENCWIF":
|
|
65
|
+
return base58encode(self._hex)
|
|
66
|
+
elif _format.upper() == "BTC":
|
|
67
|
+
return base58CheckEncode(0x00, self._hex)
|
|
68
|
+
else:
|
|
69
|
+
return _format.upper() + str(self)
|
|
70
|
+
|
|
71
|
+
def __repr__(self):
|
|
72
|
+
"""Returns hex value of object
|
|
73
|
+
|
|
74
|
+
:return: Hex string of instance's data
|
|
75
|
+
:rtype: hex string
|
|
76
|
+
"""
|
|
77
|
+
return self._hex
|
|
78
|
+
|
|
79
|
+
def __str__(self):
|
|
80
|
+
"""Return graphene-base58CheckEncoded string of data
|
|
81
|
+
|
|
82
|
+
:return: Base58 encoded data
|
|
83
|
+
:rtype: str
|
|
84
|
+
"""
|
|
85
|
+
return gphBase58CheckEncode(self._hex)
|
|
86
|
+
|
|
87
|
+
def __bytes__(self):
|
|
88
|
+
"""Return raw bytes
|
|
89
|
+
|
|
90
|
+
:return: Raw bytes of instance
|
|
91
|
+
:rtype: bytes
|
|
92
|
+
|
|
93
|
+
"""
|
|
94
|
+
return unhexlify(self._hex)
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
# https://github.com/tochev/python3-cryptocoins/raw/master/cryptocoins/base58.py
|
|
98
|
+
BASE58_ALPHABET = b"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def base58decode(base58_str):
|
|
102
|
+
base58_text = py23_bytes(base58_str, "ascii")
|
|
103
|
+
n = 0
|
|
104
|
+
leading_zeroes_count = 0
|
|
105
|
+
for b in base58_text:
|
|
106
|
+
if isinstance(b, integer_types):
|
|
107
|
+
n = n * 58 + BASE58_ALPHABET.find(py23_chr(b))
|
|
108
|
+
else:
|
|
109
|
+
n = n * 58 + BASE58_ALPHABET.find(b)
|
|
110
|
+
if n == 0:
|
|
111
|
+
leading_zeroes_count += 1
|
|
112
|
+
res = bytearray()
|
|
113
|
+
while n >= 256:
|
|
114
|
+
div, mod = divmod(n, 256)
|
|
115
|
+
res.insert(0, mod)
|
|
116
|
+
n = div
|
|
117
|
+
else:
|
|
118
|
+
res.insert(0, n)
|
|
119
|
+
return hexlify(bytearray(1) * leading_zeroes_count + res).decode("ascii")
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def base58encode(hexstring):
|
|
123
|
+
byteseq = py23_bytes(unhexlify(py23_bytes(hexstring, "ascii")))
|
|
124
|
+
n = 0
|
|
125
|
+
leading_zeroes_count = 0
|
|
126
|
+
for c in byteseq:
|
|
127
|
+
n = n * 256 + c
|
|
128
|
+
if n == 0:
|
|
129
|
+
leading_zeroes_count += 1
|
|
130
|
+
res = bytearray()
|
|
131
|
+
while n >= 58:
|
|
132
|
+
div, mod = divmod(n, 58)
|
|
133
|
+
res.insert(0, BASE58_ALPHABET[mod])
|
|
134
|
+
n = div
|
|
135
|
+
else:
|
|
136
|
+
res.insert(0, BASE58_ALPHABET[n])
|
|
137
|
+
return (BASE58_ALPHABET[0:1] * leading_zeroes_count + res).decode("ascii")
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def ripemd160(s):
|
|
141
|
+
ripemd160 = hashlib.new("ripemd160")
|
|
142
|
+
ripemd160.update(unhexlify(s))
|
|
143
|
+
return ripemd160.digest()
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def doublesha256(s):
|
|
147
|
+
return hashlib.sha256(hashlib.sha256(unhexlify(s)).digest()).digest()
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def b58encode(v):
|
|
151
|
+
return base58encode(v)
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def b58decode(v):
|
|
155
|
+
return base58decode(v)
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
def base58CheckEncode(version, payload):
|
|
159
|
+
if isinstance(version, string_types):
|
|
160
|
+
s = version + payload
|
|
161
|
+
else:
|
|
162
|
+
s = ("%.2x" % version) + payload
|
|
163
|
+
checksum = doublesha256(s)[:4]
|
|
164
|
+
result = s + hexlify(checksum).decode("ascii")
|
|
165
|
+
return base58encode(result)
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
def base58CheckDecode(s, skip_first_bytes=True):
|
|
169
|
+
s = unhexlify(base58decode(s))
|
|
170
|
+
dec = hexlify(s[:-4]).decode("ascii")
|
|
171
|
+
checksum = doublesha256(dec)[:4]
|
|
172
|
+
if not (s[-4:] == checksum):
|
|
173
|
+
raise AssertionError()
|
|
174
|
+
if skip_first_bytes:
|
|
175
|
+
return dec[2:]
|
|
176
|
+
else:
|
|
177
|
+
return dec
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
def gphBase58CheckEncode(s):
|
|
181
|
+
checksum = ripemd160(s)[:4]
|
|
182
|
+
result = s + hexlify(checksum).decode("ascii")
|
|
183
|
+
return base58encode(result)
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
def gphBase58CheckDecode(s):
|
|
187
|
+
s = unhexlify(base58decode(s))
|
|
188
|
+
dec = hexlify(s[:-4]).decode("ascii")
|
|
189
|
+
checksum = ripemd160(dec)[:4]
|
|
190
|
+
if not (s[-4:] == checksum):
|
|
191
|
+
raise AssertionError()
|
|
192
|
+
return dec
|