nos2x Nostr Signer Extension

repository·master·Indexed 18 days ago

https://github.com/fiatjaf/nos2x

A Chromium browser extension implementing the NIP-07 standard. It provides a window.nostr API allowing web applications to request signatures and encryption/decryption via NIP-04 and NIP-44 without accessing the user's private keys.

Tokens
640
Snippets
3
Records
4
Agent score
14%

What's inside nos2x

  1. Overview of nos2x Nostr Signer Extension

    master
    nos2x is a Chromium-only browser extension that allows web applications to sign Nostr events without the application ever gaining access to your private keys. It implements the NIP-07 standard by providing a window.nostr object to the browser environment.
  2. Develop and run nos2x from source

    master

    To build and run the extension locally for development:

    1. Clone the repository and enter the directory.
    2. Install dependencies using yarn.
    3. Run the build script with the prod argument.
    4. Open chrome://extensions in Chrome.
    5. Enable "developer mode" in the top right.
    6. Click "Load unpackaged" and select the extension/ folder from the repository.
    git clone https://github.com/fiatjaf/nos2x
    cd nos2x
    yarn
    ./build.js prod
  3. Use the window.nostr API to sign Nostr events

    master

    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);