PrivMX DOCS
Kotlin

Getting Started

Initial Requirements

Before starting developing using PrivMX Endpoint Kotlin follow our quick start guide

To connect it to your environment, you need:

  • Bridge URL - URL address of the instance of your PrivMX Bridge
  • Solution ID - ID of the Solution provided by PrivMX Bridge during its initialization process
  • User Private Key - the private key from the user's public-private key pair

You also need to use your own application server to manage users (and their keys) and Contexts.

Adding Dependencies

  1. Add mavenCentral() repository to your settings.gradle.kts:
dependencyResolutionManagement {
    repositories {
        mavenCentral()
    }
}
  1. Add dependency to build.gradle.kts:
kotlin {
  sourceSets {
    val commonMain by getting {
      dependencies {
        implementation("com.simplito.kotlin:privmx-endpoint:$privmxLibVersion")
        // optionally you can add privmx-endpoint-extra dependency
//        implementation("com.simplito.kotlin:privmx-endpoint-extra:$privmxLibVersion")
      }
    }
  }
}

JVM

You have to pass path to PrivMX Endpoint native libraries directory by configuring -Djava.library.path=<path-to-your-libraries-dir> system property during run application.

You can download pre-compiled zipped native binaries for each supported JVM platform from GitHub Releases.

Android

Native Libraries

Before build your project you have to attach PrivMX Endpoint native libraries to Android build process by adding them to jniLibs sourceSet directory (src/main/jniLibs by default) for each supported ABI.

You can download pre-compiled zipped native binaries for each supported Android ABI from GitHub Releases.

Required Permissions

PrivMX Endpoint requires to add the following permissions to your AndroidManifest.xml:

  • <uses-permission android:name="android.permission.INTERNET"/>

Initial Assumptions

The initial assumptions for all the code examples below are as follows:

/*
    All the values below like BRIDGE_URL, SOLUTION_ID, CONTEXT_ID
    should be replaced by the ones corresponding to your Bridge Server instance.

    The private keys here are for demonstration purposes only.
    Normally, they should be kept separately by each user and stored in a safe place,
    or generated from a password (see the derivePrivateKey2() method in the Crypto API)
*/

val bridgeUrl = "YOUR_BRIDGE_URL"
val solutionId = "YOUR_SOLUTION_ID"
val contextId = "YOUR_CONTEXT_ID"

val user1Id = "USER_ID_1"
val user1PublicKey = "PUBLIC_KEY_1"
val user1PrivateKey = "PRIVATE_KEY_1"

val user2Id = "USER_ID_2"
val user2PublicKey = "PUBLIC_KEY_2"

Connecting to PrivMX Bridge

To use any of the library's elements, you must first connect to PrivMX Bridge. Use the API keys mentioned earlier:

val pathToCerts = "PATH_TO_CERTS" // Path to .pem ssl certificate to connect with Privmx Bridge
val initModules = setOf(
    Modules.THREAD, // initializes ThreadApi to working with Threads
    Modules.STORE, // initializes StoreApi to working with Stores
    Modules.INBOX // initializes InboxApi to working with Inboxes
) // set of modules to activate in new connection

val endpointContainer = PrivmxEndpointContainer().also {
    it.setCertsPath(pathToCerts)
}

val endpointSession = endpointContainer.connect(
    initModules,
    user1PrivateKey,
    solutionId,
    bridgeUrl
)

The active connection is kept by container and can be accessed using container.getEndpoint(Long) method.

endpointContainer.getEndpoint(endpointSession.connection.getConnectionId()!!)

Disconnecting from PrivMX Bridge

endpointContainer.disconnect(endpointSession.connection.getConnectionId()!!)

Closing PrivmxEndpointContainer

When you finish working with the container, close it to end all connections, close the event loop, and release the resources being used. You can also use a use function in Kotlin.

endpointContainer.close()

Next Steps

With everything ready to go, now it's time to start using all of the platform's capabilities.

Learn how to use:

  • Threads - for exchanging encrypted messages;
  • Stores - for saving and sharing encrypted files;
  • Inboxes - for one way communication with external users.

We use cookies on our website. We use them to ensure the proper functioning of the site and, if you agree, for purposes we set, such as analytics or marketing.

PrivMX Endpoint Kotlin v2.2

This package is not up to date with the core documentation. Some of the features you've seen described in other parts of the documentation might not be mentioned here. Those changes do not influence compatibility, however

On this page