A collection of signer classes for applesauce that are compatible with the NIP-07 API.
For detailed documentation and API reference, see:
A secure signer that encrypts private keys using NIP-49.
// Create a new password signer
const signer = new PasswordSigner();
// Set up with a new key and password
const randomBytes = new Uint8Array(64);
window.crypto.getRandomValues(randomBytes);
signer.key = randomBytes;
signer.setPassword("your-password");
// Unlock the signer when needed
await signer.unlock("your-password");
A basic signer that holds the secret key in memory with NIP-04 and NIP-44 encryption support.
// Create new signer with random key
const signer = new PrivateKeySigner();
// Or import existing key
const key = new Uint8Array(32);
window.crypto.getRandomValues(key);
const signer = new PrivateKeySigner(key);
Derives a private key from validated BIP-39 seed words, with the same signing and encryption methods as PrivateKeySigner.
import { SeedWordsSigner } from "applesauce-signers/signers/seed-words-signer";
import { wordlist } from "@scure/bip39/wordlists/english.js";
const signer = SeedWordsSigner.fromWords(words, { wordlist, account: 0, passphrase: "" });
const pubkey = await signer.getPublicKey();
The account defaults to 0 and the passphrase to an empty string. Import the required BIP-39 wordlist explicitly so unused languages stay out of the bundle.
A client-side implementation for remote signing using NIP-46.
// First, set up the required relay communication methods
import { Observable } from "rxjs";
// Define subscription method for receiving events
const subscriptionMethod = (filters, relays) => {
return new Observable((observer) => {
// Create subscription to relays
const cleanup = subscribeToRelays(relays, filters, (event) => {
observer.next(event);
});
return () => cleanup();
});
};
// Define publish method for sending events
const publishMethod = async (event, relays) => {
for (const relay of relays) await publishToRelay(relay, event);
};
// You can set these methods globally at app initialization
NostrConnectSigner.subscriptionMethod = subscriptionMethod;
NostrConnectSigner.publishMethod = publishMethod;
// Now create and use the signer
const signer = new NostrConnectSigner({
remote: "<remote signer pubkey>",
relays: ["wss://relay.example.com"],
// Or pass methods directly to the constructor
subscriptionMethod,
publishMethod,
});
// Create a connection URI for your app
const uri = signer.getNostrConnectURI({
name: "My App",
url: "https://example.com",
permissions: NostrConnectSigner.buildSigningPermissions([0, 1, 3]),
});
// Connect using bunker URI
const bunkerSigner = await NostrConnectSigner.fromBunkerURI("bunker://...your-uri-here...", {
permissions: NostrConnectSigner.buildSigningPermissions([0, 1, 3]),
});
// Import or export a complete NIP-46 client session
const sessionSigner = await NostrConnectSigner.fromNbunksec("nbunksec1...");
const encodedSession = sessionSigner.getNbunksec();
nbunksec values include the local client private key and should be handled like secrets.