A Flutter plugin that provides signing capabilities for Nostr applications, implementing NIP-55. This plugin allows developers to sign Nostr events with their Flutter apps and an installed Android Signer like Amber, securely and efficiently.
- Introduction
- Features
- Installation
- Usage
- API Reference
- Example
- NIP-55 Compliance
- Contributing
- License
The Flutter Nostr Signer Plugin enables Flutter applications to interact with Nostr decentralized protocol by providing native signing capabilities. By adhering to NIP-55, this plugin ensures secure and standardized signing of Nostr events, facilitating seamless integration with Android Signer apps.
- Sign Nostr Events: Securely sign events to interact with the Nostr protocol.
- Retrieve Public Keys: Access the user's public key for identity verification.
- NIP-55 Compliance: Fully implements the NIP-55 specification for application-level signing.
Add the plugin to your project's pubspec.yaml file:
dependencies:
signer_plugin: ^0.0.2Then, run the following command to fetch the plugin:
flutter pub getImport the plugin in your Dart code:
import 'package:signer_plugin/signer_plugin.dart';You can create an instance of the plugin if needed:
final nostrSigner = SignerPlugin();Retrieve the user's public key:
final signer = SignerPlugin();
// Optionally set a preferred signer package once
await signer.setPackageName('com.example.signer');
final res = await signer.getPublicKey();
final publicKey = res['npub'] as String; // bech32 npub
print('Public Key length: ${publicKey.length}');Sign a Nostr event represented as a JSON string:
final signer = SignerPlugin();
final pubRes = await signer.getPublicKey();
final npub = pubRes['npub'] as String;
final eventId = '...computed id...';
final eventJson = '{"id":"$eventId","kind":1,"content":"Hello","tags":[],"pubkey":"...hex..."}';
final signRes = await signer.signEvent(eventJson, eventId, npub);
// keys: signature, id, event
print('Signed event length: ${signRes['event'].toString().length}');All methods return Future<Map<String, dynamic>> with consistent keys.
getPublicKey({String? permissionsJson})→{ npub, package }signEvent(String eventJson, String eventId, String npub)→{ signature, id, event }nip04Encrypt(String plainText, String id, String npub, String pubKey)→{ result, id }nip04Decrypt(String encryptedText, String id, String npub, String pubKey)→{ result, id }nip44Encrypt(String plainText, String id, String npub, String pubKey)→{ result, id }nip44Decrypt(String encryptedText, String id, String npub, String pubKey)→{ result, id }decryptZapEvent(String eventJson, String id, String npub)→{ result, id }getRelays(String id, String npub)→{ result, id }
Utilities:
setPackageName(String packageName)sets a preferred signer package used by subsequent calls.getInstalledSignerApps()returns installed signers with{name, packageName, iconData, iconUrl?}.isExternalSignerInstalled(String packageName)returnsbool.
See example/ for a runnable app demonstrating:
- Listing installed signer apps and selecting one
- Getting public key
- Signing an event
- NIP-04/NIP-44 encrypt/decrypt
- Getting relays
All examples avoid logging sensitive payloads; only lengths are printed.
This plugin implements the NIP-55 specification, which defines the protocol for application-level signing of Nostr events on Android. By adhering to NIP-55, the plugin ensures secure and standardized interactions with the Nostr network, promoting interoperability between different Nostr clients and services.
Contributions are welcome! If you'd like to contribute to this project, please follow these steps:
-
Fork the Repository: Click the 'Fork' button at the top right of the repository page.
-
Clone Your Fork:
git clone https://github.com/chebizarro/flutter-signer-plugin.git cd flutter-signer-plugin -
Create a New Branch:
git checkout -b feature/your-feature-name
-
Make Your Changes: Implement your feature or bug fix.
-
Commit Your Changes:
git commit -am 'Add some feature' -
Push to the Branch:
git push origin feature/your-feature-name
-
Open a Pull Request: Go to the repository on GitHub and click 'New pull request'.
This project is licensed under the MIT License. See the LICENSE file for details.
Note: For any issues or questions, please open an issue on the GitHub repository.