Add Spec for Sovereign Backends

This commit is contained in:
Abhay 2025-09-23 20:43:42 +05:30
parent 0619f370bc
commit eec572f01b
1 changed files with 124 additions and 0 deletions

124
N1.md Normal file
View File

@ -0,0 +1,124 @@
# Remote Procedure Calls over Nostr
NRPC defines a Remote Procedure Call (RPC) mechanism over Nostr events. Requests and responses are expressed as signed events and routed via relays. This enables backend services to be hosted without requiring inbound network access, cloud infrastructure, or centralized API management.
## Problems Addressed
Traditional backend services typically require:
- A publicly reachable server (static IP, port forwarding, or tunneling).
- Domain names and TLS termination.
- Centralized API key or token management.
This specification removes those requirements by using Nostrs event transport. Services can operate with only outbound relay connections, authentication is inherent in event signatures, and requests and responses can be processed asynchronously.
## Specification
### Event Kinds
- Request Event: kind: 22068
- Response Event: kind: 22069
### Request Event (22068)
- Author: Callers pubkey.
- Tags:
```
["p", "<callee_pubkey>"] — target service identity.
["method", "<method_name>"] — method to invoke.
["param", "<key>", "<value>"] — optional, repeatable parameters.
```
- Content: optional payload
### Response Event (22069)
- Author: Callees pubkey.
- Tags:
```
["e", "<request_event_id>"] — ID of the request being answered.
["p", "<caller_pubkey>"] — recipient of this response.
["status", "<http_status_code>"] — HTTP-style status code.
```
On success:
```
["result", "<key>", "<value>"] — repeatable.
["result_json", "<json_string>"] — optional structured payload.
```
On error:
```
["error", "<http_status_code>", "<message>"]
```
- Content: optional payload (e.g., JSON string).
### Examples
Request Example
```
{
"kind": 22068,
"tags": [
[
"p",
"62a904c9c0e4ac1e221dc91202ee3bd98f6fd2460b619d953921108adda1af72"
],
[
"method",
"sendDM"
]
],
"content": "",
"created_at": 1758638576,
"pubkey": "c21b1a6cdb247ccbd938dcb16b15a4fa382d00ffd7b12d5cbbad172a0cd4d170",
"id": "aa05848fac18ecd4e0be17f4e041b808eb949963b03dd128ca7b9d610257639b",
"sig": "8153860b5ddacceff0c89ff3d86c7e323f4e826f8415aa288d587c962ff7b209e40dace4199ff5edb21d69ab14f7f0d74328e36e48d06897d120418eaeec3e8b"
}
```
Response Example
```
RESPONSE EVENT {
kind: 22069,
pubkey: '62a904c9c0e4ac1e221dc91202ee3bd98f6fd2460b619d953921108adda1af72',
created_at: 1758640291,
tags: [
[
'e',
'af955bdb56977df2e0acd43791377cfcf671e334d4a5d5859af810e3c6a5cff6'
],
[
'p',
'c21b1a6cdb247ccbd938dcb16b15a4fa382d00ffd7b12d5cbbad172a0cd4d170'
],
[ 'status', '200' ],
[ 'result_json', '{}' ]
],
content: '',
id: 'ce1fa98bd61128beb2ba3f213086ece096eb75dc30b012d4bd2672f23415ae57',
sig: '2647f1cad66d6a85752cbb1b07feb37077299c089bf5d1dbb79c0fd37b86ac54bbd09960d719c1b7afdcab103e148c30899b90d4367525dbb1be75f7c1c3de07',
[Symbol(verified)]: true
}
```
## TODO
Work out a protocol, for encrypted requests and responses, it will be similar to NIP-17 using NIP-59 Giftwraps, but an implementation is still WIP.