phpjsonapachemod-rewritenostr

NOSTR NIP-05 Send get request parameter to a json file and return an appropriate response


NIP-05 Mapping Nostr keys to DNS-based internet identifiers describes a requirement to be able to handle GET requests to a .json file. For obvious security reason I want to return a json only if requested name exists; otherwise return an error.

Let's say I have a nostr.json file that looks like this

{
  "names": {
    "user_name_1": "user_pubkey_1",
    "user_name_2": "user_pubkey_2"
  },
  "relays": {
    "user_pubkey_1": [ "wss://relay1", "wss://relay2" ],
    "user_pubkey_2": [ "wss://relay3", "wss://relay4" ]
  }
}

Request from a Nostr relay is: https://example.com/.well-known/nostr.json?name=user_name_1 and what I want is to return the appropriate response

{
  "names": {
    "user_name_1":"user_pubkey_1"
  },
  "relays": {
    "user_pubkey_1":[ "wss://relay1", "wss://relay2" ]
  }
}

only in case the name exists; otherwise return

{
  "error":"user not found"
}

or in case of a wrong GET parameter return

{
  "error":"Missing name parameter"
}

What is the best way to do it?

Edit: Found a working example


Solution

  • A way around is to RewriteRule to point to some secret_name.php file.