Nostr WoT

Firmare con un’estensione o un account remoto

Firmare con un’estensione o un account remoto

Usa nostr-wot-sdk/signers per identità e firme. Nip07Signer usa l’estensione installata; Nip46Signer collega un firmatario remoto. Riutilizza lo stesso firmatario negli strumenti SDK durante la sessione.

terminale
$npm install nostr-wot-sdk@3.0.0 nostr-tools

Esempio

typescript
import { Nip07Signer, isNip07Available } from "nostr-wot-sdk/signers";

// Call from a browser button handler, not during server rendering.
export async function signNote(content: string) {
  if (!isNip07Available()) throw new Error("Install or enable a NIP-07 signer");
  const signer = new Nip07Signer();
  const pubkey = await signer.getPublicKey();
  const event = await signer.signEvent({
    kind: 1, content, tags: [],
    created_at: Math.floor(Date.now() / 1000),
  });
  if (event.pubkey !== pubkey) throw new Error("Account changed; review again");
  return event;
}

Note di integrazione

L’esempio restituisce una nota firmata, non pubblicata. Gestisci il rifiuto nel pulsante e consenti un nuovo tentativo esplicito. PrivateKeySigner serve alle app che custodiscono le chiavi; l’integrazione con l’estensione non richiede seed o chiavi private.

Riferimento e altre opzioni