Signer avec une extension ou un compte distant
Signer avec une extension ou un compte distant
Utilisez nostr-wot-sdk/signers pour l’identité et les signatures. Nip07Signer utilise l’extension installée ; Nip46Signer se connecte à un signataire distant. Réutilisez le même signataire dans les outils du SDK pendant la session.
terminal
$npm install nostr-wot-sdk@3.0.0 nostr-tools
Exemple
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;
}Notes d’intégration
L’exemple renvoie une note signée, pas publiée. Gérez les refus dans le bouton et laissez l’utilisateur réessayer. PrivateKeySigner convient aux applications qui détiennent elles-mêmes les clés ; une intégration avec l’extension ne demande ni phrase de récupération ni clé privée.