nostr_tools.sig_event_id

nostr_tools.sig_event_id(event_id, private_key)[source]

Sign an event ID with a private key using Schnorr signatures (secp256k1).

This function creates a Schnorr signature of the event ID using the provided private key. The signature can be verified using verify_sig() with the corresponding public key.

Parameters:
  • event_id (str) – Event ID in hexadecimal format (64 characters). This is the SHA-256 hash of the serialized event.

  • private_key (str) – Private key in hexadecimal format (64 characters). Must be a valid secp256k1 private key.

Returns:

Schnorr signature as hexadecimal string (128 characters).

Return type:

str

Examples

Sign an event:

>>> event_id = calc_event_id(pubkey, timestamp, kind, tags, content)
>>> signature = sig_event_id(event_id, private_key)
>>> len(signature)
128

Create complete signed event:

>>> event_id = calc_event_id(public_key, timestamp, kind, tags, content)
>>> signature = sig_event_id(event_id, private_key)
>>> event = {
...     "id": event_id,
...     "pubkey": public_key,
...     "created_at": timestamp,
...     "kind": kind,
...     "tags": tags,
...     "content": content,
...     "sig": signature
... }

Verify your own signature:

>>> sig = sig_event_id(event_id, private_key)
>>> assert verify_sig(event_id, public_key, sig)