From a2ea048cce763f9c0c01e88fca7d0432fbe8baa9 Mon Sep 17 00:00:00 2001 From: dbth <1097224+believethehype@users.noreply.github.com> Date: Tue, 17 Dec 2024 17:36:23 +0100 Subject: [PATCH] Update nip98_utils.py --- nostr_dvm/utils/nip98_utils.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/nostr_dvm/utils/nip98_utils.py b/nostr_dvm/utils/nip98_utils.py index ed0c7eb..6d16c77 100644 --- a/nostr_dvm/utils/nip98_utils.py +++ b/nostr_dvm/utils/nip98_utils.py @@ -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 ". + :rtype: str + """ keys = Keys.parse(pkeys_hex) utag = Tag.parse(["u", url]) methodtag = Tag.parse(["method", kind])