diff --git a/duniterpy/documents/transaction.py b/duniterpy/documents/transaction.py index fb565bd0f7b7559d1c117cb6c4da2c19a497080c..ff0a45ea71b0c1e67d6dbb2e9cc297a328cf7ae6 100644 --- a/duniterpy/documents/transaction.py +++ b/duniterpy/documents/transaction.py @@ -929,11 +929,17 @@ Currency: {1} return signed_raw def sign(self, key: SigningKey) -> None: - raise Exception("sign() is not implemented, use multi_sign()") + """ + Add a signature to the document from key + + :param key: SigningKey instance + :return: + """ + self.multi_sign(key) def multi_sign(self, keys: Union[SigningKey, List[SigningKey]]) -> None: """ - Sign the current document with multiple keys + Add signature(s) to the document from one key or a list of multiple keys :param keys: Libnacl key or list of them """ @@ -945,12 +951,18 @@ Currency: {1} logging.debug("Signature : \n%s", signature.decode("ascii")) self.signatures.append(signature.decode("ascii")) - def check_signature(self, pubkey: str): - raise Exception("check_signature() is not implemented, use check_signatures()") + def check_signature(self, pubkey: str) -> bool: + """ + Check if document is signed by pubkey + + :param pubkey: Base58 pubkey + :return: + """ + return self.check_signatures(pubkey) - def check_signatures(self, pubkeys: Union[str, List[str]]): + def check_signatures(self, pubkeys: Union[str, List[str]]) -> bool: """ - Check if the signatures matches the pubkeys + Check if the signatures matches a public key or a list of public keys :param pubkeys: Base58 public key or list of them diff --git a/tests/documents/test_transaction.py b/tests/documents/test_transaction.py index b1baa85e4b9cef036b08889a9b8c470009fd4e98..58be4321256f383a85d7f95bb0ac70d3c538d834 100644 --- a/tests/documents/test_transaction.py +++ b/tests/documents/test_transaction.py @@ -485,6 +485,30 @@ class TestTransaction(unittest.TestCase): unlock2 = Unlock.from_inline("0:SIG(0)") self.assertEqual(unlock1, unlock2) + def test_check_signature(self): + # create 3 wallets + signing_key = SigningKey.from_credentials("1", "1") + + issuer = signing_key.pubkey + + transaction = Transaction( + block_id=BlockID( + 8979, "000041DF0CCA173F09B5FBA48F619D4BC934F12ADF1D0B798639EB2149C4A8CC" + ), + locktime=0, + issuers=[issuer], + inputs=[InputSource.from_inline(input_source_str)], + unlocks=[Unlock(index=0, parameters=[SIGParameter(0)])], + outputs=[OutputSource.from_inline(output_source_str)], + comment="", + currency=G1_TEST_CURRENCY_CODENAME, + ) + + # multi-signature on the transaction + transaction.sign(signing_key) + + self.assertTrue(transaction.check_signature(issuer)) + def test_check_signatures(self): # create 3 wallets signing_key_01 = SigningKey.from_credentials("1", "1")