from flask import Flask, request, jsonify, abort

app = Flask(__name__)

# Example: Load from file, database, etc. Here, using a hardcoded dict.
names = {
    "jenna": "b1b4258a36b34761ee4b06c3803b9678978063f0b52b1a00ea321cbcc0ef6f19",
    "daann": "261028e6ca5448334bc3882a4a18080da0aa0d9c9a860ca18c933c74981dcda0"
}

@app.route('/.well-known/nostr.json')
def nostr_json():
    username = request.args.get('name')
    if not username:
        # Optionally, return an empty mapping or 400
        return jsonify({"names": {}})
    if username in names:
        return jsonify({"names": {username: names[username]}})
    else:
        # If user is not found, return empty or 404
        return jsonify({"names": {}})
        # Or: abort(404)
        
if __name__ == '__main__':
    app.run(host="0.0.0.0", port=8000)
