Add Mechanism for Service Introspection

This commit is contained in:
Abhay 2025-09-24 09:39:40 +05:30
parent eec572f01b
commit a69a9ea2c5
1 changed files with 89 additions and 0 deletions

89
N1.md
View File

@ -119,6 +119,95 @@ RESPONSE EVENT {
} }
``` ```
## Service Introspection
It is recommended for services to provide a special getMethods runtime introspection of the services available RPC calls.
A client may invoke it at any time to discover supported methods, required parameters, possible results, and error conditions.
### Request
A getMethods request is a standard Request Event (kind: 22068) with:
```
["p", "<callee_pubkey>"]
["method", "getMethods"]
```
No additional ["param", ...] tags are required.
### Response
The callee returns a Response Event (kind: 22069) with status 200.
Supported methods are described in repeated result tags using the following schema:
```
["result", "method", "<method_name>"]
["result", "param", "<param_name>", "<param_type>", "<required_flag>"]
["result", "return", "<field_name>", "<field_type>"]
["result", "error", "<status_code>", "<description>"]
```
### Real World Examples
### Request
```
{
"kind": 22068,
"pubkey": "65b078fb5f4183c0538f84321ff14c0b468ded7dd45ede80d84a2ffe3a9a44dc",
"created_at": 1758686491,
"tags": [
[
"p",
"62a904c9c0e4ac1e221dc91202ee3bd98f6fd2460b619d953921108adda1af72"
],
[
"method",
"getMethods"
]
],
"content": "",
"id": "d15fac11a463331f342e723fe312c992ba4ec53835b86ff3418c19932d6f5acc",
"sig": "9a8b1d0733c75475110a1dba09d59167430949f24148ee16bb431ea672412d4195f758fe3eda882f6c90032f4bdc2856653c230836988d9bec72aa918039b39c"
}
```
### Response
```
{
"content": "",
"created_at": 1758686639,
"id": "fd333cfcfb364e5d7056a9b18e7e279b45b7abca4a12c4fb7497062e619dc330",
"kind": 22069,
"pubkey": "62a904c9c0e4ac1e221dc91202ee3bd98f6fd2460b619d953921108adda1af72",
"sig": "6630d10fb5792b42aac7897119b94271d85e339bc7e34a39eedcfbe2ead9e283dd7919a8311d18bb79f2c829b5184dc789e19b5479b1933f1dbcf3a7756f3599",
"tags": [
[
"e",
"e1bcf745b55bebbe33ea5f9f8a22d7f0b9bb1bb365cd41b53d936dfd7fb28734"
],
[
"p",
"4e74e8c9c9c0dee32331c2d0245542fa93bef155e9d0339e2a7fd1f86eed9c11"
],
["status", "200"],
["result", "method", "createReminder"],
["result", "param", "createReminder", "Time", "string", "required"],
["result", "param", "createReminder", "Text", "string", "required"],
["result", "param", "createReminder", "Date", "string", "required"],
["result", "returns", "createReminder", "reminder_id", "string"],
["result", "returns", "createReminder", "scheduled_at", "string"],
["result", "returns", "createReminder","text","string"],
["result", "returns", "createReminder", "owner", "string"],
["result", "error", "createReminder", "400", "time and text required"],
["result", "method","getMethods"],
["result", "method", "sendDM"]
]
}
```
## TODO ## 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. 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.