Update nip98_utils.py

This commit is contained in:
dbth 2024-12-17 17:36:23 +01:00
parent 3e8f22017f
commit a2ea048cce

View File

@ -10,6 +10,27 @@ def sha256sum(filename):
async def generate_nip98_header(pkeys_hex, url="", kind="POST", filepath=""):
"""
Generates a NIP-98 authentication header for a Nostr-based server. This header is
intended to be used for authenticating requests by signing events with specific
keys and including necessary metadata tags. The resulting header is encoded into
a format suitable for HTTP authorization headers.
:param pkeys_hex: The private keys in hexadecimal format, used for signing the
event.
:type pkeys_hex: str
:param url: The URL that the NIP-98 header should apply to. Defaults to an empty
string.
:type url: str, optional
:param kind: The HTTP method type for which the header is generated (e.g.,
"POST"). Defaults to "POST".
:type kind: str, optional
:param filepath: The path to a file whose content will be hashed and included in
the payload as a tag if the method is "POST". Defaults to an empty string.
:type filepath: str, optional
:return: The generated NIP-98 header in the format "Nostr <Base64 encoded event>".
:rtype: str
"""
keys = Keys.parse(pkeys_hex)
utag = Tag.parse(["u", url])
methodtag = Tag.parse(["method", kind])