symbol-sdk-python 3.2.0__py3-none-any.whl → 3.2.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: symbol-sdk-python
3
- Version: 3.2.0
3
+ Version: 3.2.2
4
4
  Summary: Symbol SDK
5
5
  Home-page: https://github.com/symbol/symbol/tree/main/sdk/python
6
6
  License: MIT
@@ -25,30 +25,30 @@ symbolchain/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
25
25
  symbolchain/external/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
26
26
  symbolchain/external/ed25519.py,sha256=xpq-UOQ3CNCZp4V2uaHsWeyEfXezCfWe44NKsecZCqU,7833
27
27
  symbolchain/facade/BatchOperations.py,sha256=SQR6fXTi1mI7H7ubJsqYEabWQzzVXhbD8BkzgIpoCII,2983
28
- symbolchain/facade/NemFacade.py,sha256=z8gSD6zAj0UmQunDbKv87yTbVe5WOwxM1UVlqwq6Yh4,2990
29
- symbolchain/facade/SymbolFacade.py,sha256=AtebZnCu0Ui5JGLGLT3cPQTXyN1idYRz4t9JZsT7sTI,5128
28
+ symbolchain/facade/NemFacade.py,sha256=oOvU8hJRNjZAFaoETueyw_R0K-S6AvlNV3pB7ltVOfY,4166
29
+ symbolchain/facade/SymbolFacade.py,sha256=Yz7hIGanNY8iFLeIelRB8-M44gmlvbdc0pB_ouGkNg0,6527
30
30
  symbolchain/facade/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
31
31
  symbolchain/impl/CipherHelpers.py,sha256=KSYH95oie-PxFfGAYfnqHOC1RWIrdxC7Vp6Go-o469Q,2152
32
32
  symbolchain/impl/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
33
33
  symbolchain/nc/__init__.py,sha256=vosYIQt3McpoGpspAl3YoV3_vrpNO-ddiTDmyqk0u-c,106403
34
34
  symbolchain/nem/KeyPair.py,sha256=34VwU7EdroB0nnzTCdTEUAK_DMrcDYzo3JKdniXQMG4,3712
35
- symbolchain/nem/MessageEncoder.py,sha256=U8-X7MczTj-XRvCx1YHXmK389oyf0OLAu7WEBf3gpfc,2583
35
+ symbolchain/nem/MessageEncoder.py,sha256=EGm4mtmyXUXQb-R49Xmrl3w40ye_LbZQ8r5aJusH0WE,2699
36
36
  symbolchain/nem/Network.py,sha256=vD7YEqJHyUPK14UAGBT29cX9Cjvq1uHDfeiYudaxgAw,1746
37
37
  symbolchain/nem/SharedKey.py,sha256=owBUV_XNo1wCby0b4Amz1Bl6uzTeQmiSFy7UcWFo00I,1094
38
- symbolchain/nem/TransactionFactory.py,sha256=k-qyXHa7lL9jrfNrtXCrRVzl2Qv3BuMoTXU7AKYvQow,4017
38
+ symbolchain/nem/TransactionFactory.py,sha256=IaKsLdTmW8ZU9s5kaUcaGl7P91awR8BMDfX_zWTAO04,4170
39
39
  symbolchain/nem/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
40
- symbolchain/ripemd160.py,sha256=rq9A2ohillUGcxM4x31eFxXcfLUi-O3sHK8ff4j1XAI,378
40
+ symbolchain/ripemd160.py,sha256=u2uv8wJY5FY8tll_EfiGE5o65Ri6E-8HbynvJUPBJa8,429
41
41
  symbolchain/sc/__init__.py,sha256=axRbsZf_j33DLTJ2TvIKg6aAxVG5xo1I2w51lzO2h9M,286967
42
42
  symbolchain/symbol/IdGenerator.py,sha256=4CWW5EekbmULDDukscs73ZFN_U179hAacK3luL7Q0TA,1696
43
43
  symbolchain/symbol/KeyPair.py,sha256=CkQh7oOeVRbjKewTfln0t1PZckcTuIXb2roY1zZjVrc,1506
44
44
  symbolchain/symbol/Merkle.py,sha256=FrCwnveXEoXEx7xFP4UC_htjAVuVeUNbvnh8YDdy3z0,7243
45
- symbolchain/symbol/MessageEncoder.py,sha256=A2KX8MxhCMYaxnEnKY0HyVGgB9cjAUiF3FMgDWfXMxk,3766
46
- symbolchain/symbol/Metadata.py,sha256=pBpBo0XmC4I7cjBqGVtdu2Blpey32l_1dZyTYsbmMyA,567
47
- symbolchain/symbol/Network.py,sha256=fKYKYl9gm3cRUcTJA7LxxT3LGQgxb_TUNDVH8rRHR_c,2229
45
+ symbolchain/symbol/MessageEncoder.py,sha256=X4io7OTEJOgy9LtDCzInm4QQFVbNWpkJnba6-S5vrkI,3882
46
+ symbolchain/symbol/Metadata.py,sha256=8DpgwTFy8IYxjNRmT_NBSn3WBhU9z2xlWvsMIh7GgwU,884
47
+ symbolchain/symbol/Network.py,sha256=CFFEFEByLDF-KFD2As5dgj-1MIuKmec5T_yfoxNDHkQ,2933
48
48
  symbolchain/symbol/SharedKey.py,sha256=Bg1qYW_iMNYKtokep5S1m9b7GfywM5OGaCrVUdt01JU,334
49
- symbolchain/symbol/TransactionFactory.py,sha256=HB7rTP57kFlxj8tWZRSChhKh6UN8IUDATdiCtRwGMYQ,3624
49
+ symbolchain/symbol/TransactionFactory.py,sha256=65N6UHDwrzNyHnpxkw-RmjuC32Znto1B9TH5OgcD1Oo,3957
50
50
  symbolchain/symbol/VotingKeysGenerator.py,sha256=tuJ6yl2CqqQ9uupAw3z-GJIW20WOsblcLQb2_fPUCDE,1686
51
51
  symbolchain/symbol/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
52
- symbol_sdk_python-3.2.0.dist-info/METADATA,sha256=GEDOnkuxcdwWMYkh_9DP6Ujk-YnEZfnMb91HtrOFKs4,5584
53
- symbol_sdk_python-3.2.0.dist-info/WHEEL,sha256=Zb28QaM1gQi8f4VCBhsUklF61CTlNYfs9YAZn-TOGFk,88
54
- symbol_sdk_python-3.2.0.dist-info/RECORD,,
52
+ symbol_sdk_python-3.2.2.dist-info/METADATA,sha256=H3eZti6Yn4oq90_uE111bCzAPZkgrfnU2VWN9f1Spzg,5584
53
+ symbol_sdk_python-3.2.2.dist-info/WHEEL,sha256=Zb28QaM1gQi8f4VCBhsUklF61CTlNYfs9YAZn-TOGFk,88
54
+ symbol_sdk_python-3.2.2.dist-info/RECORD,,
@@ -4,11 +4,43 @@ import sha3
4
4
 
5
5
  from ..CryptoTypes import Hash256, PrivateKey, PublicKey
6
6
  from ..nem.KeyPair import KeyPair, Verifier
7
+ from ..nem.MessageEncoder import MessageEncoder
7
8
  from ..nem.Network import Address, Network
8
9
  from ..nem.SharedKey import SharedKey
9
10
  from ..nem.TransactionFactory import TransactionFactory
10
11
  from ..Network import NetworkLocator
11
12
 
13
+ # region NemPublicAccount / NemAccount
14
+
15
+
16
+ class NemPublicAccount:
17
+ """NEM public account."""
18
+
19
+ def __init__(self, facade, public_key):
20
+ """Creates a NEM public account."""
21
+ self._facade = facade
22
+ self.public_key = public_key
23
+ self.address = self._facade.network.public_key_to_address(self.public_key)
24
+
25
+
26
+ class NemAccount(NemPublicAccount):
27
+ """NEM account."""
28
+
29
+ def __init__(self, facade, key_pair):
30
+ """Creates a NEM account."""
31
+ super().__init__(facade, key_pair.public_key)
32
+ self.key_pair = key_pair
33
+
34
+ def message_encoder(self):
35
+ """Creates a message encoder that can be used for encrypting and encoding messages between two parties."""
36
+ return MessageEncoder(self.key_pair)
37
+
38
+ def sign_transaction(self, transaction):
39
+ """Signs a NEM transaction."""
40
+ return self._facade.sign_transaction(self.key_pair, transaction)
41
+
42
+ # endregion
43
+
12
44
 
13
45
  class NemFacade:
14
46
  """Facade used to interact with NEM blockchain."""
@@ -46,6 +78,14 @@ class NemFacade:
46
78
  """Creates a network timestamp representing the current time."""
47
79
  return self.network.from_datetime(datetime.now(timezone.utc))
48
80
 
81
+ def create_public_account(self, public_key):
82
+ """Creates a NEM public account from a public key."""
83
+ return NemPublicAccount(self, public_key)
84
+
85
+ def create_account(self, private_key):
86
+ """Creates a NEM account from a private key."""
87
+ return NemAccount(self, KeyPair(private_key))
88
+
49
89
  @staticmethod
50
90
  def hash_transaction(transaction):
51
91
  """Hashes a NEM transaction."""
@@ -6,6 +6,7 @@ from ..CryptoTypes import Hash256, PublicKey, Signature
6
6
  from ..Network import NetworkLocator
7
7
  from ..symbol.KeyPair import KeyPair, Verifier
8
8
  from ..symbol.Merkle import MerkleHashBuilder
9
+ from ..symbol.MessageEncoder import MessageEncoder
9
10
  from ..symbol.Network import Address, Network
10
11
  from ..symbol.SharedKey import SharedKey
11
12
  from ..symbol.TransactionFactory import TransactionFactory
@@ -26,6 +27,41 @@ AGGREGATE_HASHED_SIZE = sum(field[1] for field in [
26
27
  ])
27
28
 
28
29
 
30
+ # region SymbolPublicAccount / SymbolAccount
31
+
32
+ class SymbolPublicAccount:
33
+ """Symbol public account."""
34
+
35
+ def __init__(self, facade, public_key):
36
+ """Creates a Symbol public account."""
37
+ self._facade = facade
38
+ self.public_key = public_key
39
+ self.address = self._facade.network.public_key_to_address(self.public_key)
40
+
41
+
42
+ class SymbolAccount(SymbolPublicAccount):
43
+ """Symbol account."""
44
+
45
+ def __init__(self, facade, key_pair):
46
+ """Creates a Symbol account."""
47
+ super().__init__(facade, key_pair.public_key)
48
+ self.key_pair = key_pair
49
+
50
+ def message_encoder(self):
51
+ """Creates a message encoder that can be used for encrypting and encoding messages between two parties."""
52
+ return MessageEncoder(self.key_pair)
53
+
54
+ def sign_transaction(self, transaction):
55
+ """Signs a Symbol transaction."""
56
+ return self._facade.sign_transaction(self.key_pair, transaction)
57
+
58
+ def cosign_transaction(self, transaction, detached=False):
59
+ """Cosigns a Symbol transaction."""
60
+ return self._facade.cosign_transaction(self.key_pair, transaction, detached)
61
+
62
+ # endregion
63
+
64
+
29
65
  class SymbolFacade:
30
66
  """Facade used to interact with Symbol blockchain."""
31
67
 
@@ -63,6 +99,14 @@ class SymbolFacade:
63
99
  """Creates a network timestamp representing the current time."""
64
100
  return self.network.from_datetime(datetime.now(timezone.utc))
65
101
 
102
+ def create_public_account(self, public_key):
103
+ """Creates a Symbol public account from a public key."""
104
+ return SymbolPublicAccount(self, public_key)
105
+
106
+ def create_account(self, private_key):
107
+ """Creates a Symbol account from a private key."""
108
+ return SymbolAccount(self, KeyPair(private_key))
109
+
66
110
  def hash_transaction(self, transaction):
67
111
  """Hashes a Symbol transaction."""
68
112
  hasher = hashlib.sha3_256()
@@ -17,6 +17,12 @@ class MessageEncoder:
17
17
 
18
18
  self.key_pair = key_pair
19
19
 
20
+ @property
21
+ def public_key(self):
22
+ """Public key used for message encoding."""
23
+
24
+ return self.key_pair.public_key
25
+
20
26
  def try_decode(self, recipient_public_key, encoded_message: Message):
21
27
  """Tries to decode encoded message, returns tuple:
22
28
  * True, message - if message has been decoded and decrypted
@@ -39,6 +39,11 @@ class TransactionFactory:
39
39
 
40
40
  return transaction
41
41
 
42
+ @staticmethod
43
+ def deserialize(payload):
44
+ """Deserializes a transaction from a binary payload."""
45
+ return nc.TransactionFactory.deserialize(payload)
46
+
42
47
  @staticmethod
43
48
  def to_non_verifiable_transaction(transaction):
44
49
  """Converts a transaction to a non-verifiable transaction."""
symbolchain/ripemd160.py CHANGED
@@ -5,6 +5,7 @@ if 'ripemd160' not in hashlib.algorithms_guaranteed:
5
5
 
6
6
 
7
7
  def _factory():
8
+ # pylint: disable=possibly-used-before-assignment
8
9
  return hashlib.new('ripemd160') if 'ripemd160' in hashlib.algorithms_guaranteed else ripemd160_impl.new()
9
10
 
10
11
 
@@ -20,6 +20,12 @@ class MessageEncoder:
20
20
 
21
21
  self.key_pair = key_pair
22
22
 
23
+ @property
24
+ def public_key(self):
25
+ """Public key used for message encoding."""
26
+
27
+ return self.key_pair.public_key
28
+
23
29
  def try_decode(self, recipient_public_key, encoded_message):
24
30
  """Tries to decode encoded message, returns tuple:
25
31
  * True, message - if message has been decoded and decrypted
@@ -1,3 +1,17 @@
1
+ import hashlib
2
+
3
+
4
+ def metadata_generate_key(seed):
5
+ """Generates a metadata key from a string."""
6
+
7
+ hash_result = hashlib.sha3_256(seed.encode('utf8')).digest()
8
+
9
+ key_bytes = bytearray(hash_result[:8])
10
+ key_bytes[7] |= 0x80 # set high bit to match SDK V2 implementation
11
+
12
+ return int.from_bytes(key_bytes, 'little')
13
+
14
+
1
15
  def metadata_update_value(old_value, new_value):
2
16
  """Creates a metadata payload for updating old value to new value."""
3
17
 
@@ -1,12 +1,14 @@
1
1
  import base64
2
2
  import datetime
3
3
  import hashlib
4
+ from binascii import unhexlify
4
5
 
5
6
  from ..ByteArray import ByteArray
6
7
  from ..CryptoTypes import Hash256
7
8
  from ..Network import Network as BasicNetwork
8
9
  from ..NetworkTimestamp import NetworkTimestamp as BasicNetworkTimestamp
9
10
  from ..NetworkTimestamp import NetworkTimestampDatetimeConverter
11
+ from ..sc import NamespaceId
10
12
 
11
13
 
12
14
  class NetworkTimestamp(BasicNetworkTimestamp):
@@ -36,12 +38,32 @@ class Address(ByteArray):
36
38
 
37
39
  super().__init__(self.SIZE, raw_bytes, Address)
38
40
 
41
+ def to_namespace_id(self):
42
+ """Attempts to convert this address into a namespace id."""
43
+
44
+ if not self.bytes[0] & 0x01:
45
+ return None
46
+
47
+ return NamespaceId(int.from_bytes(self.bytes[1:9], 'little'))
48
+
39
49
  def __str__(self):
40
50
  return base64.b32encode(self.bytes + bytes(0)).decode('utf8')[0:-1]
41
51
 
42
52
  def __repr__(self):
43
53
  return f'Address(\'{str(self)}\')'
44
54
 
55
+ @staticmethod
56
+ def from_decoded_address_hex_string(hex_string):
57
+ """Creates an address from a decoded address hex string (typically from REST)."""
58
+
59
+ return Address(unhexlify(hex_string))
60
+
61
+ @staticmethod
62
+ def from_namespace_id(namespace_id, network_identifier):
63
+ """Creates an address from a namespace id."""
64
+
65
+ return Address(bytes([network_identifier + 1]) + namespace_id.value.to_bytes(8, 'little') + bytes([0] * (Address.SIZE - 9)))
66
+
45
67
 
46
68
  class Network(BasicNetwork):
47
69
  """Represents a Symbol network."""
@@ -55,6 +55,16 @@ class TransactionFactory:
55
55
  """
56
56
  return self._create_and_extend(transaction_descriptor, autosort, sc.EmbeddedTransactionFactory)
57
57
 
58
+ @staticmethod
59
+ def deserialize(payload):
60
+ """Deserializes a transaction from a binary payload."""
61
+ return sc.TransactionFactory.deserialize(payload)
62
+
63
+ @staticmethod
64
+ def deserialize_embedded(payload):
65
+ """Deserializes an embedded transaction from a binary payload."""
66
+ return sc.EmbeddedTransactionFactory.deserialize(payload)
67
+
58
68
  @staticmethod
59
69
  def attach_signature(transaction, signature):
60
70
  """Attaches a signature to a transaction."""