In Soapbox and Ditto, the NIP-46 remote signing protocol is employed for handling Nostr private key (nsec) logins. This process allows users to authenticate and sign events without exposing their private keys directly, enhancing security.
Here's a breakdown of how this works:
1. Authorization: When a Mastodon client attempts to authorize with Ditto, the user must input a bunker:// URI into the OAuth form.
2. Keypair Generation: Ditto generates a NIP-46 "local keypair" on the server. This keypair is used to facilitate the secure signing process.
3. Bearer Token: After the local keypair is generated, Ditto issues a bearer token to the Mastodon client, allowing the client to proceed with authorized actions.
4. Signing Events: When a user needs to sign a Nostr event, such as posting a status, the client sends the bearer token to Ditto's API. Ditto then emits a NIP-46 request on its relay, signed by the generated keypair and tagging the user's pubkey.
5. Remote Signer: A remote signer (such as a browser extension or application) must sign the event and respond within 60 seconds, or else the request will timeout in Ditto.
To implement this login flow in another app:
* Generate a Local Keypair: The app must generate a NIP-46 "local keypair" each time a new session is initiated with Ditto.
* Handle OAuth Authorization: Implement the OAuth authorization process to receive a bearer token after the user enters the bunker:// URI.
* Emit NIP-46 Requests: The app must be capable of emitting NIP-46 requests on the relay, signing them with the local keypair.
* Integrate Remote Signer: Ensure the app can listen for signing requests and respond within the required timeframe, possibly using a browser extension or another mechanism for secure signing.
For more information on signing and the integration process, visit this page in the documentation: https://docs.soapbox.pub/ditto/signing