PoP SDK - Android

This is a library that allows you to easily integrate PoP into your Android application.

Installation

1 - Add the JitPack repository to your build file

allprojects {
  repositories {
    ...
    maven { url 'https://jitpack.io' }
  }
}

2 - Add the dependency

dependencies {
  implementation 'com.github.anima-protocol:personhood-sdk-android:v0.1.7'
}

Usage

Add the personhood button in your layout

<io.synaps.PersonhoodButton
  android:id="@+id/personhoodButton"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
/>

Configure the button

The onFinish callback will be called when the user has finished the PoP flow or if the session is already validated. Its parameters follows the ones sent from the Personhood API session object.

INFO: Providing a wallet and the onSign callback is optional (the user won't be able to use the anima protocol).

The onSign callback will be called when the user has to sign a message. You have to sign the message and call the sign method of the button with the message and the signature. You must use the personal sign (EIP 191) method to sign the message.

Kotlin

val personhoodButton = findViewById<PersonhoodButton>(R.id.personhoodButton)

personhoodButton.setOnFinishListener { session ->
  // Do something when the user has finished the PoP flow
  Log.d("Personhood", "onFinish: " + session.info)
}

personhoodButton.setOnSignListener { message, onSuccess, onError ->
  try {
    // Sign the message
    val signature = signMessage(message)
    onSuccess.Sign(signature)
  } catch (e: Exception) {
    onError.Error()
  }
}

try {
  // Launch the button, the first parameter is the session ID and the second is the public address of the user (optional)
  personhoodButton.launch("01234567-8901-2345-6789-012345678901", "0x1234567890123456789012345678901234567890")
} catch (e: CameraAccessException) {
  // Handle the exception
  ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.CAMERA), 10)
}

Java

PersonhoodButton personhoodButton = findViewById(R.id.personhoodButton);

personhoodButton.setOnFinishListener((session) -> {
  // Do something when the user has finished the PoP flow
  Log.d("Personhood", "onFinish: " + session.info);
});

personhoodButton.setOnSignListener((message, onSuccess, onError) -> {
  try {
    // Sign the message
    String signature = signMessage(message);
    onSuccess.Sign(signature);
  } catch (Exception e) {
    onError.Error();
  }
});

try {
  // Launch the button, the first parameter is the session ID and the second is the public address of the user (optional)
  personhoodButton.launch("01234567-8901-2345-6789-012345678901", "0x1234567890123456789012345678901234567890");
} catch (CameraAccessException e) {
  // Handle the exception
  ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA}, 10);
}