Files
welshman/docs/util/nip86.md
T
2026-06-10 14:12:47 -07:00

65 lines
1.8 KiB
Markdown

# NIP-86 Relay Management
Implementation of NIP-86 for managing Nostr relays through authenticated RPC requests.
## Types
```typescript
export enum ManagementMethod {
SupportedMethods = "supportedmethods",
BanPubkey = "banpubkey",
UnbanPubkey = "unbanpubkey",
AllowPubkey = "allowpubkey",
UnallowPubkey = "unallowpubkey",
ListBannedPubkeys = "listbannedpubkeys",
ListAllowedPubkeys = "listallowedpubkeys",
ListEventsNeedingModeration = "listeventsneedingmoderation",
AllowEvent = "allowevent",
BanEvent = "banevent",
ListBannedEvents = "listbannedevents",
ChangeRelayName = "changerelayname",
ChangeRelayDescription = "changerelaydescription",
ChangeRelayIcon = "changerelayicon",
AllowKind = "allowkind",
DisallowKind = "disallowkind",
ListAllowedKinds = "listallowedkinds",
BlockIp = "blockip",
UnblockIp = "unblockip",
ListBlockedIps = "listblockedips",
}
export type ManagementRequest = {
method: ManagementMethod
params: string[]
}
export type ManagementResponse = {
result?: any
error?: string
}
```
## Functions
```typescript
// Sends a management request to a relay
export declare const sendManagementRequest: (url: string, request: ManagementRequest, authEvent: SignedEvent) => Promise<ManagementResponse>
```
## Example
```typescript
import { sendManagementRequest, ManagementMethod, makeHttpAuth } from '@welshman/util'
// Set up our url and params
const url = "https://relay.example.com/"
const payload = {method: ManagementMethod.SupportedMethods, params: []}
// Create auth event for the management endpoint
const authEvent = await makeHttpAuth(url, "POST", JSON.stringify(payload))
const signedAuthEvent = await signer.signEvent(authEvent)
// Get a list of supported methods
const response = await sendManagementRequest(url, payload, signedAuthEvent)
```