Update docs
This commit is contained in:
@@ -64,28 +64,3 @@ async function example() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Request Serialization
|
|
||||||
The signer implements a lock mechanism to prevent concurrent calls to the extension:
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
class Nip07Signer implements ISigner {
|
|
||||||
#lock = Promise.resolve()
|
|
||||||
|
|
||||||
#then = async <T>(f: (ext: Nip07) => T | Promise<T>) => {
|
|
||||||
const promise = this.#lock.then(() => {
|
|
||||||
const ext = getNip07()
|
|
||||||
if (!ext) throw new Error("Nip07 is not enabled")
|
|
||||||
return f(ext)
|
|
||||||
})
|
|
||||||
|
|
||||||
// Reset lock after completion or error
|
|
||||||
this.#lock = promise.then(
|
|
||||||
() => undefined,
|
|
||||||
() => undefined
|
|
||||||
)
|
|
||||||
|
|
||||||
return promise
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|||||||
@@ -47,19 +47,22 @@ export declare const makeBlossomAuthEvent: (opts: BlossomAuthEventOpts) => Event
|
|||||||
export declare const buildBlobUrl: (server: string, sha256: string, extension?: string) => string
|
export declare const buildBlobUrl: (server: string, sha256: string, extension?: string) => string
|
||||||
|
|
||||||
// Checks if a blob exists on server
|
// Checks if a blob exists on server
|
||||||
export declare const checkBlobExists: (server: string, sha256: string, options?: { authEvent?: SignedEvent }) => Promise<{exists: boolean; size?: number}>
|
export declare const checkBlobExists: (server: string, sha256: string, options?: { headers?: Record<string, string>; authEvent?: SignedEvent }) => Promise<{exists: boolean; size?: number}>
|
||||||
|
|
||||||
// Downloads blob from server
|
// Downloads blob from server
|
||||||
export declare const getBlob: (server: string, sha256: string, options?: { authEvent?: SignedEvent; range?: {start: number; end?: number} }) => Promise<Response>
|
export declare const getBlob: (server: string, sha256: string, options?: { headers?: Record<string, string>; authEvent?: SignedEvent; range?: {start: number; end?: number} }) => Promise<Response>
|
||||||
|
|
||||||
|
// Checks if uploads are allowed (HEAD request to /upload)
|
||||||
|
export declare const canUploadBlob: (server: string, options?: { headers?: Record<string, string>; authEvent?: SignedEvent }) => Promise<Response>
|
||||||
|
|
||||||
// Uploads blob to server
|
// Uploads blob to server
|
||||||
export declare const uploadBlob: (server: string, blob: Blob | ArrayBuffer, options?: { authEvent?: SignedEvent }) => Promise<Response>
|
export declare const uploadBlob: (server: string, blob: Blob | ArrayBuffer, options?: { headers?: Record<string, string>; authEvent?: SignedEvent }) => Promise<Response>
|
||||||
|
|
||||||
// Deletes blob from server
|
// Deletes blob from server
|
||||||
export declare const deleteBlob: (server: string, sha256: string, options?: { authEvent?: SignedEvent }) => Promise<Response>
|
export declare const deleteBlob: (server: string, sha256: string, options?: { headers?: Record<string, string>; authEvent?: SignedEvent }) => Promise<Response>
|
||||||
|
|
||||||
// Lists blobs for a pubkey
|
// Lists blobs for a pubkey
|
||||||
export declare const listBlobs: (server: string, pubkey: string, options?: { authEvent?: SignedEvent; since?: number; until?: number }) => Promise<Response>
|
export declare const listBlobs: (server: string, pubkey: string, options?: { headers?: Record<string, string>; authEvent?: SignedEvent; since?: number; until?: number }) => Promise<Response>
|
||||||
```
|
```
|
||||||
|
|
||||||
## File Encryption
|
## File Encryption
|
||||||
|
|||||||
@@ -0,0 +1,76 @@
|
|||||||
|
# Wallet
|
||||||
|
|
||||||
|
Types and utilities for working with Lightning wallet integrations in Nostr applications.
|
||||||
|
|
||||||
|
## Types
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
export enum WalletType {
|
||||||
|
WebLN = "webln",
|
||||||
|
NWC = "nwc",
|
||||||
|
}
|
||||||
|
|
||||||
|
export type WebLNInfo = {
|
||||||
|
enabled: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
export type NWCInfo = {
|
||||||
|
pubkey: string
|
||||||
|
relay: string
|
||||||
|
secret: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export type WebLNWallet = {
|
||||||
|
type: WalletType.WebLN
|
||||||
|
info: WebLNInfo
|
||||||
|
}
|
||||||
|
|
||||||
|
export type NWCWallet = {
|
||||||
|
type: WalletType.NWC
|
||||||
|
info: NWCInfo
|
||||||
|
}
|
||||||
|
|
||||||
|
export type Wallet = WebLNWallet | NWCWallet
|
||||||
|
```
|
||||||
|
|
||||||
|
## Type Guards
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// Check if a wallet is a WebLN wallet
|
||||||
|
export declare const isWebLNWallet: (wallet: Wallet) => wallet is WebLNWallet
|
||||||
|
|
||||||
|
// Check if a wallet is a Nostr Wallet Connect wallet
|
||||||
|
export declare const isNWCWallet: (wallet: Wallet) => wallet is NWCWallet
|
||||||
|
```
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import { Wallet, WalletType, isWebLNWallet, isNWCWallet } from '@welshman/util'
|
||||||
|
|
||||||
|
function handleWallet(wallet: Wallet) {
|
||||||
|
if (isWebLNWallet(wallet)) {
|
||||||
|
// TypeScript knows wallet.info is WebLNInfo
|
||||||
|
console.log('WebLN enabled:', wallet.info.enabled)
|
||||||
|
} else if (isNWCWallet(wallet)) {
|
||||||
|
// TypeScript knows wallet.info is NWCInfo
|
||||||
|
console.log('NWC relay:', wallet.info.relay)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a WebLN wallet
|
||||||
|
const weblnWallet: Wallet = {
|
||||||
|
type: WalletType.WebLN,
|
||||||
|
info: { enabled: true }
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create an NWC wallet
|
||||||
|
const nwcWallet: Wallet = {
|
||||||
|
type: WalletType.NWC,
|
||||||
|
info: {
|
||||||
|
pubkey: "...",
|
||||||
|
relay: "wss://relay.example.com",
|
||||||
|
secret: "..."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
Reference in New Issue
Block a user