Created
October 6, 2021 09:01
-
-
Save hal0x2328/3fde316874a2985993d3662ac513c86d to your computer and use it in GitHub Desktop.
Verify N3 transaction signature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from neo3.network.payloads.transaction import Transaction | |
from neo3.core import cryptography | |
import binascii | |
import base64 | |
import json | |
import sys | |
MAINNET=860833102 | |
TESTNET=877933390 | |
if len(sys.argv) != 2: | |
print(f"Usage: {sys.argv[0]} <raw N3 transaction>") | |
sys.exit(1) | |
txraw = sys.argv[1] | |
deserialized_tx = Transaction.deserialize_from_bytes(base64.b64decode(txraw)) | |
print(json.dumps(deserialized_tx.to_json(), indent=4)) | |
witnesses = deserialized_tx.witnesses | |
signature = witnesses[0].invocation_script[2:] | |
public_key = witnesses[0].verification_script[2:35] | |
hash_data = deserialized_tx.get_hash_data(MAINNET) | |
print("SIGNATURE:" + binascii.hexlify(signature).decode()) | |
print("PUBKEY:" + binascii.hexlify(public_key).decode()) | |
print("HASH_DATA:" +binascii.hexlify(hash_data).decode()) | |
res = cryptography.verify_signature( | |
hash_data, | |
signature, | |
public_key, | |
cryptography.ECCCurve.SECP256R1 | |
) | |
print(f"Verified: {res}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment