A spec-compliant NIP-55 library for Android. Communicate with any external signer (Amber, Signet, etc.) to sign Nostr events without exposing private keys.
// settings.gradle.kts
dependencyResolutionManagement {
repositories {
maven { url = uri("https://jitpack.io") }
}
}
// build.gradle.kts
dependencies {
implementation("com.github.Letdown2491:nip55-android:1.0.0")
}Add to AndroidManifest.xml (required for Android 11+):
<queries>
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="nostrsigner" />
</intent>
</queries>class MyActivity : AppCompatActivity() {
private val getPublicKey = registerForActivityResult(GetPublicKeyContract()) { result ->
result
.onSuccess { login(it.pubkey) }
.onError { showError(it.message) }
}
private val signEvent = registerForActivityResult(SignEventContract()) { result ->
result
.onSuccess { publish(it.signedEventJson) }
.onError { showError(it.message) }
}
fun login() {
if (!Nip55.isSignerAvailable(this)) return
getPublicKey.launch(GetPublicKeyContract.Input())
}
fun sign(eventJson: String, userPubkey: String) {
signEvent.launch(SignEventContract.Input(eventJson, userPubkey))
}
// Encrypt/decrypt (NIP-44)
private val encrypt = registerForActivityResult(Nip44EncryptContract()) { result ->
result.onSuccess { sendMessage(it.ciphertext) }
}
fun encryptMessage(plaintext: String, recipientPubkey: String, userPubkey: String) {
encrypt.launch(Nip44EncryptContract.Input(plaintext, recipientPubkey, userPubkey))
}
}See API.md for all contracts and options.