Add docs for blossom, add nip 86 and 98 support
This commit is contained in:
@@ -535,3 +535,13 @@ export declare const hexToBytes: (hex: string) => Uint8Array;
|
||||
export declare const sha256: (data: ArrayBuffer | Uint8Array) => Promise<string>;
|
||||
```
|
||||
|
||||
## Text encoding
|
||||
|
||||
```typescript
|
||||
// TextEncoder instance for encoding strings to bytes
|
||||
export declare const textEncoder: TextEncoder;
|
||||
|
||||
// TextDecoder instance for decoding bytes to strings
|
||||
export declare const textDecoder: TextDecoder;
|
||||
```
|
||||
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
# Blossom
|
||||
|
||||
Client library for interacting with Blossom media servers. Provides utilities for authentication, blob operations, and file encryption.
|
||||
|
||||
## Types
|
||||
|
||||
```typescript
|
||||
export type BlossomAuthAction = "get" | "upload" | "list" | "delete"
|
||||
|
||||
export type BlossomAuthEventOpts = {
|
||||
action: BlossomAuthAction
|
||||
server: string
|
||||
hashes?: string[]
|
||||
expiration?: number
|
||||
content?: string
|
||||
}
|
||||
|
||||
export type BlossomServer = {
|
||||
url: string
|
||||
pubkey?: string
|
||||
}
|
||||
|
||||
export type BlossomErrorResponse = {
|
||||
message: string
|
||||
reason?: string
|
||||
}
|
||||
|
||||
export interface EncryptedFile {
|
||||
key: string
|
||||
nonce: string
|
||||
ciphertext: Uint8Array
|
||||
algorithm: string
|
||||
}
|
||||
```
|
||||
|
||||
## Authentication
|
||||
|
||||
```typescript
|
||||
// Creates a Blossom auth event for server operations
|
||||
export declare const makeBlossomAuthEvent: (opts: BlossomAuthEventOpts) => Event
|
||||
```
|
||||
|
||||
## Blob Operations
|
||||
|
||||
```typescript
|
||||
// Builds URL for accessing a blob
|
||||
export declare const buildBlobUrl: (server: string, sha256: string, extension?: string) => string
|
||||
|
||||
// Checks if a blob exists on server
|
||||
export declare const checkBlobExists: (server: string, sha256: string, options?: { authEvent?: SignedEvent }) => Promise<{exists: boolean; size?: number}>
|
||||
|
||||
// Downloads blob from server
|
||||
export declare const getBlob: (server: string, sha256: string, options?: { authEvent?: SignedEvent; range?: {start: number; end?: number} }) => Promise<Response>
|
||||
|
||||
// Uploads blob to server
|
||||
export declare const uploadBlob: (server: string, blob: Blob | ArrayBuffer, options?: { authEvent?: SignedEvent }) => Promise<Response>
|
||||
|
||||
// Deletes blob from server
|
||||
export declare const deleteBlob: (server: string, sha256: string, options?: { authEvent?: SignedEvent }) => Promise<Response>
|
||||
|
||||
// Lists blobs for a pubkey
|
||||
export declare const listBlobs: (server: string, pubkey: string, options?: { authEvent?: SignedEvent; since?: number; until?: number }) => Promise<Response>
|
||||
```
|
||||
|
||||
## File Encryption
|
||||
|
||||
```typescript
|
||||
// Encrypts a file using AES-GCM
|
||||
export declare function encryptFile(file: Blob): Promise<EncryptedFile>
|
||||
|
||||
// Decrypts an encrypted file
|
||||
export declare function decryptFile(encryptedFile: EncryptedFile): Promise<Uint8Array>
|
||||
```
|
||||
|
||||
## Example
|
||||
|
||||
```typescript
|
||||
import { uploadBlob, makeBlossomAuthEvent } from '@welshman/util'
|
||||
|
||||
// Create auth event for upload
|
||||
const authEvent = makeBlossomAuthEvent({
|
||||
action: "upload",
|
||||
server: "https://blossom.example.com"
|
||||
})
|
||||
|
||||
// Sign the auth event with your signer
|
||||
const signedAuthEvent = await signer.signEvent(authEvent)
|
||||
|
||||
// Upload a file
|
||||
const file = new File(["Hello world"], "hello.txt", { type: "text/plain" })
|
||||
const response = await uploadBlob("https://blossom.example.com", file, {
|
||||
authEvent: signedAuthEvent
|
||||
})
|
||||
```
|
||||
@@ -0,0 +1,57 @@
|
||||
# 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",
|
||||
AllowPubkey = "allowpubkey",
|
||||
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[]
|
||||
}
|
||||
```
|
||||
|
||||
## Functions
|
||||
|
||||
```typescript
|
||||
// Sends a management request to a relay
|
||||
export declare const sendManagementRequest: (url: string, request: ManagementRequest, authEvent: SignedEvent) => Promise<any>
|
||||
```
|
||||
|
||||
## 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)
|
||||
```
|
||||
@@ -0,0 +1,42 @@
|
||||
# NIP-98 HTTP Auth
|
||||
|
||||
Implementation of NIP-98 HTTP Authentication for authenticating HTTP requests with Nostr events.
|
||||
|
||||
## Functions
|
||||
|
||||
```typescript
|
||||
// Creates an HTTP auth event for authenticating requests
|
||||
export declare const makeHttpAuth: (url: string, method?: string, body?: string) => Promise<Event>
|
||||
|
||||
// Creates Authorization header from signed HTTP auth event
|
||||
export declare const makeHttpAuthHeader: (event: SignedEvent) => string
|
||||
```
|
||||
|
||||
## Example
|
||||
|
||||
```typescript
|
||||
import { makeHttpAuth, makeHttpAuthHeader } from '@welshman/util'
|
||||
|
||||
const url = "https://api.example.com/upload"
|
||||
const method = "POST"
|
||||
const body = {data: "example"}
|
||||
|
||||
// Create HTTP auth event
|
||||
const authEvent = await makeHttpAuth(url, method, JSON.stringify(body))
|
||||
|
||||
// Sign the auth event
|
||||
const signedEvent = await signer.signEvent(authEvent)
|
||||
|
||||
// Create Authorization header
|
||||
const authHeader = makeHttpAuthHeader(signedEvent)
|
||||
|
||||
// Use in fetch request
|
||||
const response = await fetch(url, {
|
||||
body,
|
||||
method,
|
||||
headers: {
|
||||
"Authorization": authHeader,
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
})
|
||||
```
|
||||
Reference in New Issue
Block a user