Update docs
This commit is contained in:
@@ -15,6 +15,7 @@ interface ISigner {
|
||||
// Core signing functionality
|
||||
sign: SignWithOptions
|
||||
getPubkey: () => Promise<string>
|
||||
cleanup?: () => Promise<void>
|
||||
|
||||
// Encryption capabilities
|
||||
nip04: {
|
||||
|
||||
@@ -29,8 +29,7 @@ The NIP-01 implementation extends the base interface with two static utility met
|
||||
### Usage Example
|
||||
|
||||
```typescript
|
||||
import { ISigner } from './interfaces'
|
||||
import { Nip01Signer } from './signers/nip01'
|
||||
import { ISigner, Nip01Signer } from '@welshman/signer'
|
||||
|
||||
// Using the standard interface
|
||||
const signer: ISigner = new Nip01Signer(mySecret)
|
||||
|
||||
@@ -30,7 +30,7 @@ const signer = new Nip07Signer()
|
||||
|
||||
```typescript
|
||||
import { Nip07Signer, getNip07 } from '@welshman/signer'
|
||||
import { createEvent, NOTE } from '@welshman/util'
|
||||
import { makeEvent, NOTE } from '@welshman/util'
|
||||
|
||||
async function example() {
|
||||
// Check for NIP-07 provider
|
||||
@@ -47,7 +47,7 @@ async function example() {
|
||||
console.log('Public key:', pubkey)
|
||||
|
||||
// Create and sign an event (will prompt user)
|
||||
const event = createEvent(NOTE, {
|
||||
const event = makeEvent(NOTE, {
|
||||
content: "Hello via browser extension!",
|
||||
tags: [["t", "test"]]
|
||||
})
|
||||
|
||||
+11
-10
@@ -16,13 +16,13 @@ import {
|
||||
Nip46Broker,
|
||||
Nip46Signer
|
||||
} from '@welshman/signer'
|
||||
import { createEvent, NOTE } from '@welshman/util'
|
||||
import { makeEvent, NOTE } from '@welshman/util'
|
||||
|
||||
async function connectToRemoteSigner() {
|
||||
// Initial setup
|
||||
const clientSecret = makeSecret()
|
||||
const relays = ['wss://relay.example.com']
|
||||
const broker = Nip46Broker.get({ relays, clientSecret })
|
||||
const broker = new Nip46Broker({ relays, clientSecret })
|
||||
const signer = new Nip46Signer(broker)
|
||||
|
||||
// Generate connection URL
|
||||
@@ -36,9 +36,10 @@ async function connectToRemoteSigner() {
|
||||
|
||||
try {
|
||||
// Wait for connection
|
||||
const abortController = new AbortController()
|
||||
const response = await broker.waitForNostrconnect(
|
||||
ncUrl,
|
||||
new AbortController()
|
||||
abortController.signal
|
||||
)
|
||||
|
||||
// Store signer info for later
|
||||
@@ -46,7 +47,7 @@ async function connectToRemoteSigner() {
|
||||
localStorage.setItem('bunkerUrl', bunkerUrl)
|
||||
|
||||
// Use the signer
|
||||
const event = createEvent(NOTE, {
|
||||
const event = makeEvent(NOTE, {
|
||||
content: "Signed with remote signer!",
|
||||
tags: [["t", "test"]]
|
||||
})
|
||||
@@ -72,7 +73,7 @@ async function reconnect() {
|
||||
relays
|
||||
} = Nip46Broker.parseBunkerUrl(bunkerUrl)
|
||||
|
||||
const broker = Nip46Broker.get({
|
||||
const broker = new Nip46Broker({
|
||||
relays,
|
||||
clientSecret: makeSecret(),
|
||||
signerPubkey,
|
||||
@@ -88,8 +89,8 @@ async function reconnect() {
|
||||
### Constructor and Factory
|
||||
|
||||
```typescript
|
||||
// Recommended: use the singleton factory
|
||||
const broker = Nip46Broker.get({
|
||||
// Direct instantiation
|
||||
new Nip46Broker({
|
||||
relays: string[],
|
||||
clientSecret: string,
|
||||
connectSecret?: string,
|
||||
@@ -97,8 +98,8 @@ const broker = Nip46Broker.get({
|
||||
algorithm?: "nip04" | "nip44"
|
||||
})
|
||||
|
||||
// Direct instantiation (not recommended)
|
||||
new Nip46Broker(params)
|
||||
// Static factory: create a broker from a bunker:// URL
|
||||
Nip46Broker.fromBunkerUrl(url: string): Nip46Broker
|
||||
```
|
||||
|
||||
### Connection Methods
|
||||
@@ -110,7 +111,7 @@ broker.makeNostrconnectUrl(metadata: Record<string, string>): Promise<string>
|
||||
// Wait for connection approval
|
||||
broker.waitForNostrconnect(
|
||||
url: string,
|
||||
abort?: AbortController
|
||||
signal: AbortSignal
|
||||
): Promise<Nip46ResponseWithResult>
|
||||
|
||||
// Get bunker URL for later reconnection
|
||||
|
||||
@@ -51,7 +51,7 @@ Creates a new signer instance that will communicate with the specified native ap
|
||||
|
||||
```typescript
|
||||
import { Nip55Signer, getNip55 } from '@welshman/signer'
|
||||
import { createEvent, NOTE } from '@welshman/util'
|
||||
import { makeEvent, NOTE } from '@welshman/util'
|
||||
|
||||
async function example() {
|
||||
try {
|
||||
@@ -69,7 +69,7 @@ async function example() {
|
||||
console.log('Public key:', pubkey)
|
||||
|
||||
// Sign an event
|
||||
const event = createEvent(NOTE, {
|
||||
const event = makeEvent(NOTE, {
|
||||
content: "Hello from native app!",
|
||||
tags: [["t", "test"]]
|
||||
})
|
||||
|
||||
+15
-21
@@ -14,23 +14,20 @@ The `Nip59` class provides utilities for implementing the Gift Wrap protocol (NI
|
||||
|
||||
```typescript
|
||||
import { Nip59 } from '@welshman/signer'
|
||||
import { createEvent, DIRECT_MESSAGE } from '@welshman/util'
|
||||
import { makeEvent, DIRECT_MESSAGE } from '@welshman/util'
|
||||
|
||||
// Create a NIP-59 instance from any signer
|
||||
const nip59 = Nip59.fromSigner(mySigner)
|
||||
|
||||
// Wrap an event
|
||||
const rumor = await nip59.wrap(
|
||||
// Wrap an event — returns the gift-wrap SignedEvent to publish
|
||||
const wrappedEvent = await nip59.wrap(
|
||||
recipientPubkey,
|
||||
createEvent(DIRECT_MESSAGE, {
|
||||
makeEvent(DIRECT_MESSAGE, {
|
||||
content: "Secret message",
|
||||
tags: [["p", recipientPubkey]]
|
||||
})
|
||||
)
|
||||
|
||||
// The wrapped event to publish
|
||||
const wrappedEvent = rumor.wrap
|
||||
|
||||
// Unwrap a received event
|
||||
const unwrapped = await nip59.unwrap(receivedWrappedEvent)
|
||||
```
|
||||
@@ -51,11 +48,12 @@ export const wrap = async (
|
||||
template: StampedEvent,
|
||||
tags: string[][] = []
|
||||
) => {
|
||||
const rumor = await getRumor(signer, template)
|
||||
const author = await signer.getPubkey()
|
||||
const rumor = await prep(template, author)
|
||||
const seal = await getSeal(signer, pubkey, rumor)
|
||||
const wrap = await getWrap(wrapper, pubkey, seal, tags)
|
||||
|
||||
return Object.assign(rumor, {wrap})
|
||||
return wrap
|
||||
}
|
||||
```
|
||||
|
||||
@@ -79,20 +77,20 @@ class Nip59 {
|
||||
* @param pubkey Recipient's public key
|
||||
* @param template The event to wrap
|
||||
* @param tags Additional tags for the wrap event (optional)
|
||||
* @returns Promise<UnwrappedEvent> Original event and its wrapped version
|
||||
* @returns Promise<SignedEvent> The gift-wrap event to publish
|
||||
*/
|
||||
wrap(
|
||||
pubkey: string,
|
||||
template: StampedEvent,
|
||||
tags?: string[][]
|
||||
): Promise<UnwrappedEvent>
|
||||
): Promise<SignedEvent>
|
||||
|
||||
/**
|
||||
* Unwraps a received wrapped event
|
||||
* @param event The wrapped event to decrypt
|
||||
* @returns Promise<UnwrappedEvent> The original unwrapped event
|
||||
* @returns Promise<HashedEvent> The original unwrapped event
|
||||
*/
|
||||
unwrap(event: SignedEvent): Promise<UnwrappedEvent>
|
||||
unwrap(event: SignedEvent): Promise<HashedEvent>
|
||||
|
||||
/**
|
||||
* Creates a new instance with a specific wrapper signer
|
||||
@@ -109,24 +107,20 @@ class Nip59 {
|
||||
|
||||
```typescript
|
||||
import { Nip59, Nip01Signer } from '@welshman/signer'
|
||||
import { createEvent, DIRECT_MESSAGE } from '@welshman/util'
|
||||
import { makeEvent, DIRECT_MESSAGE } from '@welshman/util'
|
||||
|
||||
async function example() {
|
||||
// Create NIP-59 instance
|
||||
const signer = new Nip01Signer(mySecret)
|
||||
const nip59 = Nip59.fromSigner(signer)
|
||||
|
||||
// Create and wrap an event
|
||||
const event = createEvent(DIRECT_MESSAGE, {
|
||||
// Create and wrap an event — returns the gift-wrap SignedEvent to publish
|
||||
const event = makeEvent(DIRECT_MESSAGE, {
|
||||
content: "Secret message",
|
||||
tags: [["p", recipientPubkey]]
|
||||
})
|
||||
|
||||
const rumor = await nip59.wrap(recipientPubkey, event)
|
||||
|
||||
// rumor contains:
|
||||
// - The original event (rumor)
|
||||
// - The wrapped version to publish (rumor.wrap)
|
||||
const wrappedEvent = await nip59.wrap(recipientPubkey, event)
|
||||
|
||||
// Later, unwrap a received event
|
||||
const unwrapped = await nip59.unwrap(receivedEvent)
|
||||
|
||||
Reference in New Issue
Block a user