py-near 1.1.51__py3-none-any.whl → 1.1.52__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.
py_near/mpc/wallet.py CHANGED
@@ -1,3 +1,4 @@
1
+ import json
1
2
  from hashlib import sha256
2
3
  from typing import List, Optional
3
4
 
@@ -80,6 +81,25 @@ class MPCWallet:
80
81
  return WalletModel.build(wallet.result)
81
82
 
82
83
  async def create_wallet_with_keys_auth(self, public_key: bytes, key_gen=1):
84
+ """
85
+ Create wallet with keys.auth.hot.tg auth method.
86
+ :param public_key: Public key for auth future signs on keys.auth.hot.tg
87
+ """
88
+ wallet = await self.get_wallet()
89
+ if wallet and wallet.access_list[0].account_id != "default.auth.hot.tg":
90
+ raise ValueError(
91
+ "MPCWallet already exists with different auth method, please use another wallet_id"
92
+ )
93
+ auth_to_add_msg = json.dumps(
94
+ dict(public_keys=[base58.b58encode(public_key).decode()], rules=[])
95
+ ).replace(" ", "")
96
+ return await self.create_wallet(
97
+ "keys.auth.hot.tg", None, auth_to_add_msg, key_gen
98
+ )
99
+
100
+ async def create_wallet(
101
+ self, auth_account_id: str, metadata: str = "", auth_to_add_msg="", key_gen=1
102
+ ):
83
103
  """
84
104
  Create wallet with keys.auth.hot.tg auth method.
85
105
  :param public_key: Public key for auth future signs on keys.auth.hot.tg
@@ -90,19 +110,27 @@ class MPCWallet:
90
110
  "MPCWallet already exists with different auth method, please use another wallet_id"
91
111
  )
92
112
  root_pk = self.derive_private_key(0)
93
- proof_hash = sha256(f"CREATE_WALLET:{self.wallet_id}".encode("utf-8")).digest()
113
+ proof_hash = sha256(
114
+ f"CREATE_WALLET:{self.wallet_id}:{auth_account_id}:{metadata}:{auth_to_add_msg}".encode(
115
+ "utf-8"
116
+ )
117
+ ).digest()
94
118
  signature = base58.b58encode(root_pk.sign(proof_hash).signature).decode("utf-8")
95
119
 
96
120
  s = await self._client.post(
97
121
  f"{self.hot_rpc}/create_wallet",
98
122
  json=dict(
99
- public_key=base58.b58encode(public_key).decode(),
100
123
  wallet_id=self.wallet_id,
101
124
  key_gen=key_gen,
102
125
  signature=signature,
103
126
  wallet_derive_public_key=base58.b58encode(
104
127
  root_pk.verify_key.encode()
105
128
  ).decode(),
129
+ auth={
130
+ "auth_account_id": auth_account_id,
131
+ "msg": auth_to_add_msg,
132
+ "metadata": metadata or None,
133
+ },
106
134
  ),
107
135
  timeout=30,
108
136
  )
@@ -126,7 +154,8 @@ class MPCWallet:
126
154
 
127
155
  async def sign_message(
128
156
  self,
129
- message_body: bytes,
157
+ msg_hash: bytes,
158
+ message_body: Optional[bytes] = None,
130
159
  curve_type: CurveType = CurveType.SECP256K1,
131
160
  auth_methods: List[AuthContract] = None,
132
161
  ):
@@ -134,38 +163,33 @@ class MPCWallet:
134
163
  raise ValueError("Default auth key is required")
135
164
  wallet = await self.get_wallet()
136
165
  user_payloads = []
137
- msg_hash = keccak(message_body)
138
166
  if len(auth_methods) != len(wallet.access_list):
139
167
  raise ValueError("Auth methods count should be equal to wallet access list")
140
168
 
141
169
  for auth_contract, auth_method in zip(auth_methods, wallet.access_list):
142
- auth_class = AUTH_CLASS[auth_method.account_id]
143
- if not isinstance(auth_contract, auth_class):
144
- raise ValueError(
145
- f"Auth method {auth_method.account_id} is not supported for this auth class"
146
- )
147
170
  user_payloads.append(auth_contract.generate_user_payload(msg_hash))
148
171
 
149
172
  proof = {
150
173
  "auth_id": 0,
151
174
  "curve_type": curve_type,
152
175
  "user_payloads": user_payloads,
153
- "message_body": message_body.hex(),
176
+ "message_body": message_body.hex() if message_body else "",
154
177
  }
155
178
 
156
- resp = (
157
- await self._client.post(
158
- f"{self.hot_rpc}/sign_raw",
159
- json=dict(
160
- uid=self.derive.hex(),
161
- message=msg_hash.hex(),
162
- proof=proof,
163
- key_type=curve_type,
164
- ),
165
- timeout=10,
166
- follow_redirects=True,
167
- )
168
- ).json()
179
+ resp = await self._client.post(
180
+ f"{self.hot_rpc}/sign_raw",
181
+ json=dict(
182
+ uid=self.derive.hex(),
183
+ message=msg_hash.hex(),
184
+ proof=proof,
185
+ key_type=curve_type,
186
+ ),
187
+ timeout=10,
188
+ follow_redirects=True,
189
+ )
190
+ resp = resp.json()
191
+ if "Ecdsa" not in resp:
192
+ raise ValueError(f"Invalid response from server: {resp}")
169
193
  resp = resp["Ecdsa"]
170
194
  r = int(resp["big_r"][2:], 16)
171
195
  s = int(resp["signature"], 16)
@@ -234,4 +258,4 @@ class MPCWallet:
234
258
  "user_payloads": user_payloads,
235
259
  },
236
260
  included=True,
237
- )
261
+ )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: py-near
3
- Version: 1.1.51
3
+ Version: 1.1.52
4
4
  Summary: Pretty simple and fully asynchronous framework for working with NEAR blockchain
5
5
  Author: pvolnov
6
6
  Author-email: petr@herewallet.app
@@ -28,11 +28,11 @@ py_near/mpc/auth/core.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
28
28
  py_near/mpc/auth/default_auth.py,sha256=i70412yXYx3MlFSsPxHLKbF0CXTjC39Qtl34et8kAEw,751
29
29
  py_near/mpc/auth/keys_auth.py,sha256=DJPi37DnV6r6cSskHEhHBiR_QiaAQJkg0AEsYp6cePA,2359
30
30
  py_near/mpc/models.py,sha256=9MSfBDqfqkaJu6eJxnwyjgihsexZboehbJ6vAGa4BTU,663
31
- py_near/mpc/wallet.py,sha256=Nihr4TR7MQURyI2wvoNIQ77Dx2_mR797RgyN91UHB8Q,8906
31
+ py_near/mpc/wallet.py,sha256=sNr9UlcyVDPF_Zho_4iTupbUoZct3paQlxxDHlHK67k,9768
32
32
  py_near/providers.py,sha256=X_GfddFzmafBatqFJH41Dp_lYvTNcz1Q3Ko2tEnN0VU,16193
33
33
  py_near/transactions.py,sha256=QwEP3qOGxb8OB2vZA_rU20jvkPA0FmJowUKDxbuzOuI,3251
34
34
  py_near/utils.py,sha256=FirRH93ydH1cwjn0-sNrZeIn3BRD6QHedrP2VkAdJ6g,126
35
- py_near-1.1.51.dist-info/LICENSE,sha256=I_GOA9xJ35FiL-KnYXZJdATkbO2KcV2dK2enRGVxzKM,1023
36
- py_near-1.1.51.dist-info/METADATA,sha256=0Tcfm023KquhJIWBY5JWhcBb_cyHQsmmIpv3eqloP6A,4846
37
- py_near-1.1.51.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
38
- py_near-1.1.51.dist-info/RECORD,,
35
+ py_near-1.1.52.dist-info/LICENSE,sha256=I_GOA9xJ35FiL-KnYXZJdATkbO2KcV2dK2enRGVxzKM,1023
36
+ py_near-1.1.52.dist-info/METADATA,sha256=A_pG9PjBofHZQSJFoimIFb33ljVJgC7qT1OCnhlDR9U,4846
37
+ py_near-1.1.52.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
38
+ py_near-1.1.52.dist-info/RECORD,,