8000 GitHub - papiche/NIP-101: Open NIP-101 - Decentralized Trust System for Nostr - Client/Relay Implementation
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Open NIP-101 - Decentralized Trust System for Nostr - Client/Relay Implementation

License

Notifications You must be signed in to change notification settings

papiche/NIP-101

Repository files navigation

NIP-101: UPlanet Hierarchical Geographic Keys and Tagging

draft optional

This NIP describes a method for generating Nostr keypairs deterministically based on geographic coordinates and a namespace, creating hierarchical "GeoKeys". It also specifies event tags used by the UPlanet application to associate notes with specific locations and grid levels.

Abstract

UPlanet extends Nostr by enabling geographically localized communication. It achieves this through:

  1. Hierarchical GeoKeys: Nostr keypairs (npub/nsec) are derived from a combination of a fixed namespace string (e.g., "UPlanetV1") and geographic coordinates formatted to specific precision levels (e.g., 0.01°, 0.1°, 1.0°). This creates distinct identities for different geographic grid cells.
  2. Geographic Tags: Events published using these GeoKeys, or referencing a location, include specific tags (latitude, longitude) to indicate the precise point of interest.
  3. Application Tag: An application tag identifies events specifically intended for or generated by the UPlanet system.

This allows users and applications to subscribe to messages relevant to specific geographic areas by knowing the corresponding GeoKey npub or by filtering events based on location tags within a certain radius.

Motivation

  • Localized Feeds: Create Nostr feeds relevant only to specific neighborhoods (UMAP), sectors (SECTOR), or regions (REGION).
  • Geo-fencing: Allow applications to filter or react to events occurring within defined geographic boundaries.
  • Mapping Integration: Provide a layer of Nostr events that can be easily displayed on maps.
  • Decentralized Location-Based Services: Enable discovery and interaction based on proximity without relying on centralized servers.
  • Application-Specific Context: The application tag allows UPlanet messages to be distinguished from general Nostr traffic.

Specification

1. GeoKey Derivation

A Nostr keypair (secp256k1) is deterministically derived from a seed string. The seed is constructed by concatenating:

  1. NAMESPACE: A constant string identifying the application and version context (e.g., UPlanetV1). This prevents collisions with other systems or future versions.
  2. FORMATTED_LATITUDE: The latitude, formatted as a string to a specific number of decimal places corresponding to the desired grid level.
  3. FORMATTED_LONGITUDE: The longitude, formatted as a string to the same number of decimal places as the latitude, corresponding to the grid level.

Seed Format: "{NAMESPACE}{FORMATTED_LATITUDE}{FORMATTED_LONGITUDE}"

Grid Levels & Formatting:

UPlanet defines the following initial grid levels:

  • UMAP (Micro-Area): 0.01° precision.
    • Latitude/Longitude Formatting: String representation with exactly two decimal places (e.g., sprintf("%.2f", coordinate) in C, or equivalent). Coordinates should likely be truncated or rounded consistently before formatting.
    • Example Seed: "UPlanetV148.85-2.34" (for Lat 48.853, Lon -2.341)
  • SECTOR: 0.1° precision.
    • Latitude/Longitude Formatting: String representation with exactly one decimal place.
    • Example Seed: "UPlanetV148.8-2.3" (for Lat 48.853, Lon -2.341)
  • REGION: 1.0° precision.
    • Latitude/Longitude Formatting: String representation with exactly zero decimal places (integer part).
    • Example Seed: "UPlanetV148-2" (for Lat 48.853, Lon -2.341)

Key Generation Algorithm: The specific algorithm used by the keygen tool mentioned in IA_UPlanet.sh is not defined here, but any standard, deterministic method for deriving a secp256k1 keypair from a unique seed string MUST be used (e.g., using the seed as input to a KDF like HKDF with a fixed salt, or directly using a SHA256 hash of the seed as the private key, ensuring it falls within the valid secp256k1 range). The chosen method MUST be consistent across the UPlanet ecosystem.

Example (Conceptual): nsec_hex = sha256("UPlanetV148.85-2.34") (Ensure result is valid private key) pubkey = derive_pubkey(nsec_hex)

2. Event Tags

Events related to UPlanet locations SHOULD include the following tags:

  • Latitude Tag: ["latitude", "FLOAT_STRING"]
    • Value: The latitude as a string, typically with higher precision (e.g., 6+ decimal places) than the GeoKey grid level. Example: "48.8534"
  • Longitude Tag: ["longitude", "FLOAT_STRING"]
    • Value: The longitude as a string, typically with higher precision. Example: "-2.3412"
  • Application Tag: ["application", "UPlanet"] or ["application", "UPlanet_Component"]
    • Value: Identifies the event as belonging to the UPlanet system. Allows differentiation (e.g., UPlanet_AIResponder).

Note: While GeoKeys provide identity for grid cells, the latitude and longitude tags specify the precise point of interest within or related to that cell. Events published from a UMAP GeoKey might contain tags pointing to a very specific coordinate within that 0.01°x0.01° cell.

3. Publishing

  • To post as a specific location grid cell (e.g., an automated bot reporting for a UMAP cell), derive the appropriate GeoKey nsec using the method in Specification 1 and publish a kind 1 event signed with it. The event SHOULD include the latitude, longitude, and application tags.
  • Regular users posting about a location SHOULD publish from their personal key but include the latitude, longitude, and application tags to make the event discoverable by UPlanet clients. They MAY also include p tags referencing the relevant GeoKey npubs (UMAP, SECTOR, REGION) to notify those "location identities".

4. Subscribing and Filtering

Clients can discover UPlanet content in several ways:

  • Subscribe by GeoKey: Subscribe directly to the npub of the desired UMAP, SECTOR, or REGION GeoKey(s).
  • Filter by Tags: Subscribe to kind: 1 events filtered by the application tag (#a: ["UPlanet"]) and optionally filter client-side based on the latitude and longitude tags to find events within a specific geographic radius.
  • Filter by Geo-Reference: Subscribe to events that tag (#p) specific GeoKey npubs.

Client Implementation Guide

  • Key Generation: Implement the deterministic key generation logic specified (or provide access to the keygen tool). Users might need to generate keys for areas they want to monitor or post from (if acting as a location).
  • Posting: When posting, determine the relevant coordinates. Include latitude, longitude, and application tags. Optionally derive and include p tags for relevant GeoKeys. If posting as a location, use the derived GeoKey nsec for signing.
  • Receiving: Filter incoming events based on subscribed GeoKeys or tags. Display location information, potentially on a map. Parse latitude and longitude tags for precise positioning.
  • Coordinate Formatting: Strictly adhere to the specified decimal places for each grid level when deriving keys. Use standard functions for formatting (e.g., sprintf("%.2f", coord)). Consistency in truncation or rounding is crucial.

Relay Implementation Considerations

Relays MAY implement indexing for the latitude, longitude, and application tags to support efficient filtering (REQ messages with #a, #latitude, #longitude filters), but this is optional. The core mechanism relies on clients knowing or deriving the GeoKey npubs or filtering standard tag queries.

Use Cases Illustrated

  • Local Chat: Alice posts from her phone using her personal key but tags the UMAP GeoKey npub for her current block and includes latitude/longitude tags. Bob, subscribed to that UMAP GeoKey, sees her message.
  • Automated Weather Alert: An automated service derives the REGION GeoKey for Paris ("UPlanetV1482"), signs a weather alert using that key's nsec, and includes precise latitude/longitude tags for the storm's center. Users subscribed to the Paris REGION GeoKey receive the alert.
  • AI Responder: An AI service monitors messages tagged with application: UPlanet. When it sees a message from a user (pubkey_A) tagged with latitude/longitude, it derives the corresponding UMAP GeoKey (pubkey_UMAP), generates a response, signs it with the UMAP GeoKey's nsec, and includes e and p tags referencing the original event (event_id) and the user (pubkey_A).

Security and Privacy Considerations

  • Location Disclosure: Publishing with precise latitude/longitude tags reveals location. Users must be aware of this. Using broader grid keys (SECTOR, REGION) for posting offers less precision.
  • Tracking: Consistent use of GeoKeys or tags could allow tracking of users' movements if they post frequently from different locations using their personal key with geo-tags.
  • Namespace Security: Control over the NAMESPACE string is important. If compromised or changed, it could disrupt the system or lead to impersonation of locations.
  • Key Management: Managing potentially many GeoKey nsecs (if acting as multiple locations) requires secure storage.

Compatibility

This NIP is compatible with existing Nostr concepts:

  • Uses standard kind 1 events.
  • Uses standard e and p tags for replies and user references (NIP-10).
  • Can be used alongside other NIPs defining content or tags.

References

  • NIP-01: Basic protocol flow description
  • NIP-10: Conventions for use of e and p tags in text events
  • (Implied): secp256k1, SHA256

About

Open NIP-101 - Decentralized Trust System for Nostr - Client/Relay Implementation

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
0