symbol-sdk-python 3.2.0__py3-none-any.whl → 3.2.3__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.3
4
4
  Summary: Symbol SDK
5
5
  Home-page: https://github.com/symbol/symbol/tree/main/sdk/python
6
6
  License: MIT
@@ -9,19 +9,19 @@ Author: Symbol Contributors
9
9
  Author-email: contributors@symbol.dev
10
10
  Maintainer: Symbol Contributors
11
11
  Maintainer-email: contributors@symbol.dev
12
- Requires-Python: >=3.9,<4.0
12
+ Requires-Python: >=3.9.2,<4.0.0
13
13
  Classifier: License :: OSI Approved :: MIT License
14
14
  Classifier: Programming Language :: Python :: 3
15
- Classifier: Programming Language :: Python :: 3.9
16
15
  Classifier: Programming Language :: Python :: 3.10
17
16
  Classifier: Programming Language :: Python :: 3.11
18
- Requires-Dist: cryptography (>=42.0.2,<42.1.0)
17
+ Classifier: Programming Language :: Python :: 3.9
18
+ Requires-Dist: cryptography (>=44.0.0,<44.1.0)
19
19
  Requires-Dist: mnemonic (>=0.20,<1.0)
20
- Requires-Dist: pillow (>=10.3.0,<10.4.0)
20
+ Requires-Dist: pillow (>=11.0.0,<11.1.0)
21
21
  Requires-Dist: pynacl (>=1.5.0,<1.6.0)
22
22
  Requires-Dist: pyyaml (>=6.0.1,<6.1.0)
23
23
  Requires-Dist: pyzbar (>=0.1.9,<0.2.0)
24
- Requires-Dist: qrcode (>=7.4.2,<7.5.0)
24
+ Requires-Dist: qrcode (>=8.0,<9.0)
25
25
  Requires-Dist: ripemd-hash (>=1.0.1,<1.1.0)
26
26
  Requires-Dist: safe-pysha3 (>=1.0.4,<1.1.0)
27
27
  Project-URL: Repository, https://github.com/symbol/symbol/tree/main/sdk/python
@@ -1,16 +1,16 @@
1
1
  symbolchain/AccountDescriptorRepository.py,sha256=XCIIt6XvxqClQL0R7_-xyFBhb0q9bIUbNTr5-YS5f1o,2508
2
2
  symbolchain/ArrayHelpers.py,sha256=Iu5QqlWW5j_6Qd0oTFO41MfDH_mKwQLT7XeD2frU2mw,3728
3
- symbolchain/BaseValue.py,sha256=AGtUYscbQk-w_rGbd9SS2gh3vnTYhCCwpXBt-9bA4u0,1482
3
+ symbolchain/BaseValue.py,sha256=vc56rclpJtxYIL6Mvo6KWwnA0pUfhtsB71NSEjobQtc,1636
4
4
  symbolchain/Bip32.py,sha256=L8Fs0XTERGWSPX972KUn-AOPwAS2gZMdVTKAq4HOGa8,1787
5
5
  symbolchain/BlockchainSettings.py,sha256=uRHHxi0gW_U9LFUhoDpNMTe2CobLNJQwE9ZMy2o1aX8,723
6
6
  symbolchain/BufferReader.py,sha256=Bcg59ZkUzhgKIo2-B1q7jwtU5x-W5_TuuaOqPnXM1ug,883
7
7
  symbolchain/BufferWriter.py,sha256=JpZkzcxUbbDkGU4Sz-oMhL6dgZ_ovhBVduVB51PEWa4,639
8
- symbolchain/ByteArray.py,sha256=u5FyC6tSxWLXDpT-_Pd3fIYftde1aAK1x5dikROJ0-0,1059
8
+ symbolchain/ByteArray.py,sha256=fVII_BDew55qTU0dQIZWYvWWT_vxfCW_IJzcPglCHr8,1173
9
9
  symbolchain/Cipher.py,sha256=CtNKjLJJPTTI4TV4Q_-bkloGSr20wjzHmaLMAbKp03g,2158
10
10
  symbolchain/CodeWordsEncoder.py,sha256=YydhdbhxTvjXYUp1OkJj7XjTz3WfKVSGi8VIUzGTTHA,1233
11
11
  symbolchain/CryptoTypes.py,sha256=9rMQyYF0xBU5W1vo07fgDqfP4dR3E_Hv5Ec1ozKanUs,1844
12
12
  symbolchain/DiceMnemonicGenerator.py,sha256=F8QU90PQzp-qzNqnnxHowVtG_-rNiqWDALSsi-8I_og,1848
13
- symbolchain/Network.py,sha256=LCMIkYo5yTlV-8_gqIjOZTSGeCBJuBZ7YisJJ1G36z4,3368
13
+ symbolchain/Network.py,sha256=6FK2qOGYsGz7qMEpu7hCcvjvnl6tQKjdMTVx9PwTjOI,3398
14
14
  symbolchain/NetworkTimestamp.py,sha256=M3T2HFYJT5v9B_tkGn2FkjW6C9hueXmdTjyWWSr9rXw,1595
15
15
  symbolchain/NodeDescriptorRepository.py,sha256=DVqhj_D6KWgaYiJC3jKv2ne-AJTvpJrKruhiRmGgtQE,1019
16
16
  symbolchain/Ordered.py,sha256=--tQ_aZpXhZYcsRLgMjUNHPYlAH7BMfuss2CSxMvNhY,397
@@ -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=qCaFie17Q1R4wRQqiedKEywJH8yq_CjY_-b9dLgiZQk,4226
29
+ symbolchain/facade/SymbolFacade.py,sha256=YH1WHfZUKZpX2lkHauRe1Kbnyvf1CJbwfLJPV73Vntc,6996
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
- symbolchain/nc/__init__.py,sha256=vosYIQt3McpoGpspAl3YoV3_vrpNO-ddiTDmyqk0u-c,106403
33
+ symbolchain/nc/__init__.py,sha256=ROTctT787pDzqlnJkavy5vAmVe_JLUwj5e9GprFklXM,121192
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
41
- symbolchain/sc/__init__.py,sha256=axRbsZf_j33DLTJ2TvIKg6aAxVG5xo1I2w51lzO2h9M,286967
40
+ symbolchain/ripemd160.py,sha256=u2uv8wJY5FY8tll_EfiGE5o65Ri6E-8HbynvJUPBJa8,429
41
+ symbolchain/sc/__init__.py,sha256=7LmLmA9UxXcwPHIerp8YjUoTplHAUjV1vtEqx007adc,309662
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.3.dist-info/METADATA,sha256=E-Q5OZVVupO5MjneN1tpBwQ0OUTAcj7JOY4tdb65Ujk,5584
53
+ symbol_sdk_python-3.2.3.dist-info/WHEEL,sha256=Zb28QaM1gQi8f4VCBhsUklF61CTlNYfs9YAZn-TOGFk,88
54
+ symbol_sdk_python-3.2.3.dist-info/RECORD,,
symbolchain/BaseValue.py CHANGED
@@ -49,3 +49,7 @@ class BaseValue(Ordered):
49
49
  unsigned_value = self.value + upper_bound_plus_one
50
50
 
51
51
  return f'0x{unsigned_value:0{self.size * 2}X}'
52
+
53
+ def to_json(self):
54
+ """Returns representation of this object that can be stored in JSON."""
55
+ return str(self.value) if 8 <= self.size else self.value
symbolchain/ByteArray.py CHANGED
@@ -37,3 +37,7 @@ class ByteArray(Ordered):
37
37
 
38
38
  def __str__(self):
39
39
  return hexlify(self.bytes).decode('utf8').upper()
40
+
41
+ def to_json(self):
42
+ """Returns representation of this object that can be stored in JSON."""
43
+ return str(self)
symbolchain/Network.py CHANGED
@@ -9,7 +9,7 @@ class Network:
9
9
  """Represents a network."""
10
10
 
11
11
  def __init__(self, name, identifier, datetime_converter, address_class, network_timestamp_class):
12
- # pylint: disable=too-many-arguments
12
+ # pylint: disable=too-many-arguments,too-many-positional-arguments
13
13
 
14
14
  """Creates a new network with the specified properties."""
15
15
  self.name = name
@@ -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."""
@@ -53,16 +93,18 @@ class NemFacade:
53
93
  return Hash256(sha3.keccak_256(non_verifiable_transaction.serialize()).digest())
54
94
 
55
95
  @staticmethod
56
- def sign_transaction(key_pair, transaction):
57
- """Signs a NEM transaction."""
96
+ def extract_signing_payload(transaction):
97
+ """Gets the payload to sign given a NEM transaction."""
58
98
  non_verifiable_transaction = TransactionFactory.to_non_verifiable_transaction(transaction)
59
- return key_pair.sign(non_verifiable_transaction.serialize())
99
+ return non_verifiable_transaction.serialize()
60
100
 
61
- @staticmethod
62
- def verify_transaction(transaction, signature):
101
+ def sign_transaction(self, key_pair, transaction):
102
+ """Signs a NEM transaction."""
103
+ return key_pair.sign(self.extract_signing_payload(transaction))
104
+
105
+ def verify_transaction(self, transaction, signature):
63
106
  """Verifies a NEM transaction."""
64
- non_verifiable_transaction = TransactionFactory.to_non_verifiable_transaction(transaction)
65
- return Verifier(transaction.signer_public_key).verify(non_verifiable_transaction.serialize(), signature)
107
+ return Verifier(transaction.signer_public_key).verify(self.extract_signing_payload(transaction), signature)
66
108
 
67
109
  def bip32_path(self, account_id):
68
110
  """Creates a network compatible BIP32 path for the specified account."""
@@ -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,45 @@ 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
+ def cosign_transaction_hash(self, transaction_hash, detached=False):
63
+ """Cosigns a Symbol transaction hash."""
64
+ return self._facade.cosign_transaction_hash(self.key_pair, transaction_hash, detached)
65
+
66
+ # endregion
67
+
68
+
29
69
  class SymbolFacade:
30
70
  """Facade used to interact with Symbol blockchain."""
31
71
 
@@ -63,6 +103,14 @@ class SymbolFacade:
63
103
  """Creates a network timestamp representing the current time."""
64
104
  return self.network.from_datetime(datetime.now(timezone.utc))
65
105
 
106
+ def create_public_account(self, public_key):
107
+ """Creates a Symbol public account from a public key."""
108
+ return SymbolPublicAccount(self, public_key)
109
+
110
+ def create_account(self, private_key):
111
+ """Creates a Symbol account from a private key."""
112
+ return SymbolAccount(self, KeyPair(private_key))
113
+
66
114
  def hash_transaction(self, transaction):
67
115
  """Hashes a Symbol transaction."""
68
116
  hasher = hashlib.sha3_256()
@@ -72,22 +120,23 @@ class SymbolFacade:
72
120
  hasher.update(self._transaction_data_buffer(transaction.serialize()))
73
121
  return Hash256(hasher.digest())
74
122
 
75
- def sign_transaction(self, key_pair, transaction):
76
- """Signs a Symbol transaction."""
123
+ def extract_signing_payload(self, transaction):
124
+ """Gets the payload to sign given a Symbol transaction."""
77
125
  sign_buffer = self.network.generation_hash_seed.bytes
78
126
  sign_buffer += self._transaction_data_buffer(transaction.serialize())
79
- return key_pair.sign(sign_buffer)
127
+ return sign_buffer
128
+
129
+ def sign_transaction(self, key_pair, transaction):
130
+ """Signs a Symbol transaction."""
131
+ return key_pair.sign(self.extract_signing_payload(transaction))
80
132
 
81
133
  def verify_transaction(self, transaction, signature):
82
134
  """Verifies a Symbol transaction."""
83
- verify_buffer = self.network.generation_hash_seed.bytes
84
- verify_buffer += self._transaction_data_buffer(transaction.serialize())
85
- return Verifier(transaction.signer_public_key).verify(verify_buffer, signature)
86
-
87
- def cosign_transaction(self, key_pair, transaction, detached=False):
88
- """Cosigns a Symbol transaction."""
89
- transaction_hash = self.hash_transaction(transaction)
135
+ return Verifier(transaction.signer_public_key).verify(self.extract_signing_payload(transaction), signature)
90
136
 
137
+ @staticmethod
138
+ def cosign_transaction_hash(key_pair, transaction_hash, detached=False):
139
+ """Cosigns a Symbol transaction hash."""
91
140
  cosignature = sc.DetachedCosignature() if detached else sc.Cosignature()
92
141
  if detached:
93
142
  cosignature.parent_hash = sc.Hash256(transaction_hash.bytes)
@@ -97,6 +146,11 @@ class SymbolFacade:
97
146
  cosignature.signature = sc.Signature(key_pair.sign(transaction_hash.bytes).bytes)
98
147
  return cosignature
99
148
 
149
+ def cosign_transaction(self, key_pair, transaction, detached=False):
150
+ """Cosigns a Symbol transaction."""
151
+ transaction_hash = self.hash_transaction(transaction)
152
+ return self.cosign_transaction_hash(key_pair, transaction_hash, detached)
153
+
100
154
  @staticmethod
101
155
  def hash_embedded_transactions(embedded_transactions):
102
156
  """Hashes embedded transactions of an aggregate."""