Skip to content

Commit de0f4ce

Browse files
committed
fix: prevent duplicate signatures in _signature_map
Signed-off-by: Mohit Yadav <ymohit799057@gmail.com>
1 parent ce4713d commit de0f4ce

2 files changed

Lines changed: 27 additions & 2 deletions

File tree

src/hiero_sdk_python/transaction/transaction.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,12 @@ def sign(self, private_key: PrivateKey) -> Transaction:
192192
# We initialize the signature map for this body_bytes if it doesn't exist yet
193193
self._signature_map.setdefault(body_bytes, basic_types_pb2.SignatureMap())
194194

195-
# Append the signature pair to the signature map for this transaction body
196-
self._signature_map[body_bytes].sigPair.append(sig_pair)
195+
# deduplication check
196+
already_signed = any(sp.pubKeyPrefix == public_key_bytes for sp in self._signature_map[body_bytes].sigPair)
197+
198+
# append only if not already signed
199+
if not already_signed:
200+
self._signature_map[body_bytes].sigPair.append(sig_pair)
197201

198202
return self
199203

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from __future__ import annotations
2+
3+
from hiero_sdk_python.crypto.private_key import PrivateKey
4+
from hiero_sdk_python.token.token_mint_transaction import TokenMintTransaction
5+
6+
7+
def test_multiple_keys_still_work():
8+
tx = TokenMintTransaction()
9+
10+
key1 = PrivateKey.generate_ed25519()
11+
key2 = PrivateKey.generate_ed25519()
12+
13+
tx.freeze()
14+
15+
tx.sign(key1)
16+
tx.sign(key2)
17+
18+
body_bytes = next(iter(tx._signature_map.keys()))
19+
sig_pairs = tx._signature_map[body_bytes].sigPair
20+
21+
assert len(sig_pairs) == 2

0 commit comments

Comments
 (0)