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()

nostr:nevent1qvzqqqqqqypzpzyg3zyfqjf7p34xuj3y4ce3ngxhl3v4eg7cuh9wrx25uyfeqzxnqy2hwumn8ghj7un9d3shjtnyv9kh2uewd9hj7qg4waehxw309ajxjar5duh8qatz9aex2mrp0yqzpc5djz8yk07tnkza2pwwsxq7lzxv209krpd52355m6efell6wn35ggm35a

Reply to this note

Please Login to reply.

Discussion

试试

# Prepare the event structure

event_data = [

0,

nostr_pubkey_hex,

created_at,

kind,

tags,

content,

]

# Serialize to JSON without extra whitespace

json_string = json.dumps(event_data, separators=(",", ":"), ensure_ascii=False)