An Android library that provides implementations of Nostr Improvement Proposals (NIPs), specifically designed to be used in plugins for cross-platform toolkits like Capacitor or Flutter, but can also be easily integrated into existing Android projects. Currently, the library implements NIP-55.
The Nostr Android Library enables Android applications to interact with the Nostr decentralized protocol by providing native implementations of Nostr Improvement Proposals (NIPs). The library is designed to be modular and easily integrated into cross-platform toolkits such as Capacitor or Flutter, as well as into existing Android projects.
Currently, the library implements NIP-55, which defines the protocol for application-level signing of Nostr events.
- NIP-55 Implementation: Provides methods for signing Nostr events as per NIP-55.
- Easy Integration: Designed to be easily integrated into Android projects or cross-platform plugins.
- Modular Design: Built to accommodate future implementations of additional NIPs.
Add the library to your project's build.gradle
dependencies:
dependencies {
implementation 'biz.nostr:nip55:1.0.0'
}
If the library is hosted on JitPack, add the JitPack repository to your root build.gradle
:
allprojects {
repositories {
google()
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Then add the dependency:
dependencies {
implementation 'com.github.chebizarro:nostr-android-library:1.0.0'
}
import biz.nostr.nip55.Signer;
Signer signer = new Signer(context);
try {
String publicKey = signer.getPublicKey();
// Use the public key as needed
} catch (Exception e) {
// Handle exception
}
String eventJson = "{ \"content\": \"Hello, Nostr!\" ... }";
try {
String signedEvent = signer.signEvent(eventJson);
// Use the signed event as needed
} catch (Exception e) {
// Handle exception
}
Signer()
Creates a new instance of the NostrPlugin
class.
-
String getPublicKey()
Retrieves the user's public key.
Returns:
- The public key as a string.
Throws:
Exception
if the public key cannot be retrieved.
-
String signEvent(String eventJson)
Signs a Nostr event represented as a JSON string.
Parameters:
eventJson
: A JSON string representing the event to be signed.
Returns:
- The signed event as a JSON string.
Throws:
Exception
if the event cannot be signed.
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/yourusername/NostrAndroid.git cd nostr-android-library
-
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.
- Android SDK: API Level 24 or higher
- Java Version: Java 8 or higher
- Android: Supported
- Cross-Platform Toolkits: Compatible with Capacitor, Flutter, and others
Ensure that any required permissions are declared in your application's AndroidManifest.xml
file.
If you need to build the library locally:
-
Clone the Repository:
git clone https://github.com/chebizarro/NostrAndroid.git cd nostr-android-library
-
Build the Library:
./gradlew build
-
Publish to Local Maven Repository (Optional):
./gradlew publishToMavenLocal
To use the library in cross-platform plugins:
- Flutter: Add the library as a dependency in your Flutter plugin's
build.gradle
file. - Capacitor: Include the library in your Capacitor plugin's Android module.
Thank you for using the Nostr Android Library!