The extension exposes a window.nostr object that web apps can use to interact with the user's keys. The following methods are available:
async window.nostr.getPublicKey(): Returns the user's public key as a hex string.async window.nostr.signEvent(event): Returns the full event object signed.async window.nostr.nip04.encrypt(pubkey, plaintext): Returns ciphertext+iv as specified in NIP-04.async window.nostr.nip04.decrypt(pubkey, ciphertext): Takes ciphertext+iv as specified in NIP-04 and returns plaintext.async window.nostr.nip44.encrypt(pubkey, plaintext): Takes pubkey and plaintext, returns ciphertext as specified in NIP-44.async window.nostr.nip44.decrypt(pubkey, ciphertext): Takes pubkey and ciphertext, returns plaintext as specified in NIP-44.
// Example usage of the window.nostr API
const pubkey = await window.nostr.getPublicKey();
const signedEvent = await window.nostr.signEvent(event);
// NIP-04 encryption
const encrypted = await window.nostr.nip04.encrypt(pubkey, "hello");
const decrypted = await window.nostr.nip04.decrypt(pubkey, encrypted);