def generate_event_id_and_sig():
# Prepare the event structure
event_data = [
0,
nostr_pubkey_hex,
created_at,
kind,
tags,
escape_content(content),
]
# Serialize to JSON without extra whitespace
json_string = json.dumps(event_data, separators=(',', ':'), sort_keys=True)
#Debug: Print the serialized JSON
print("Serialized JSON:", json_string)
# Create SHA-256 object
hash_object = hashlib.sha256()
# Update hash object
hash_object.update(json_string.encode('utf-8'))
# 32 bytes hash
hash_bytes = hash_object.digest()
# Compute SHA-256 hash
event_id = hash_object.hexdigest()
#Print event ID
print("Event ID:", event_id)
# Sign the hash
signature = nostr_privkey.sign(hash_object.digest())
# get sig hex
sig_hex = signature.hex()
# Print signature
print("Signature:", sig_hex)
return event_id, sig_hex
# Generate even ID and signature
event_id, sig_hex = generate_event_id_and_sig()