Skip to main content
swift

Privmx Endpoint Swift

Initial Requirements

To start developing end-to-end encrypted applications using PrivMX Endpoint you need:

  • A PrivMX Bridge instance, you can find installation guide here. To connect it to your environment you will need these API keys:

    • SolutionID - created inside your Organization;
    • Platform URL - unique for your Instance;
    • ContextID - there can be one or more depending on the use case.
  • A server for managing users. It can be new or existing, depending on the specific requirements. For more information about how PrivMX Endpoint integrates into your stack check our getting started guide.

Installation

Our Swift packages contain all the necessary assets and helpers to get started with PrivMX Endpoint. Select which level is the best for you. Go to Swift overview to see the descriptions of each package.

Swift Dependencies

Swift Dependencies are managed by Swift Package Manager, and published on Simplito's Github.

  1. Add privmx-endpoint-swift-extra package to your project using Xcode's built-in package management:
https://gitlab.simplito.com/mobile/privmx/iOS/wrappers/privmx-endpoint-swift-extra

It should be present in Package Dependencies as well as in target's "Link Binary With Libraries" section.

  1. Everywhere you want to use PrivMX Package, you need to import:
import PrivMXEndpointSwift
import PrivMXEndpointSwiftExtra
import PrivMXEndpointSwiftNative

Shared Libraries

Our privmx-endpoint-swift-extra package depends on privmx-endpoint-swift package, which depends on a set of native libraries, which are downloaded automatically by Xcode. They are all compiled for arm and Intel architectures for using with iOS, macOS and simulator environments.

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. You can Use PrivMXEndpointContainer and its helper functions or manually instantiate PrivMXEndpoint. This is the most recommended approach.

var platformURL =  "/*URL of Your Bridge Installation*/"
var solutionId = "/*Solution Identifier*/"
var contextId = "/*Context Identifier*/"
var threadId = "/*Thread Identifier*/"
var privateKey = "/*User's Private Key*/"

// Your role is to provide a valid PrivateKey to match the Public Key already assigned to the Bridge's Context.
// Alternatively you can generate it with our helper function such as
// endpointContainer.cryptoApi.derivePrivateKey(from: "/*secret*/", and: "/*salt*/").

var endpointContainer: PrivMXEndpointContainer = PrivMXEndpointContainer()

guard let pathToCerts = Bundle.main.path(forResource: "cacert", ofType: "pem") else {return}


try? endpointContainer.setCertsPath(to: pathToCerts)

guard let privMXEndpoint = try? await endpointContainer.newEndpoint(
enabling: [.thread],
connectingAs: privateKey,
to: solutionId,
on: platformURL) else {return}

guard let connectionId = try? privMXEndpoint?.connection.getConnectionId() else {return}

Certificates should be set up accordingly to the Local Bridge Installation. More details are available here.

The active connection is kept by endpointContainer and can be accessed with getPrivmxEndpoint() function.

let endpoint = endpointContainer.getEndpoint()
//returns first value from dictionary, ...

let endpoint = endpointContainer.getEndpoint(connectionID)
//or value indexed by connectionID

Disconnecting from PrivMX Bridge

While using PrivMXEndpointContainer, you can run disconnect on endpointContainer object. It ends all underlying connections.


var endpointContainer: PrivMXEndpointContainer = PrivMXEndpointContainer()

// ... initialization of endpoints

endpointContainer.disconnect()

Compilation

Compilation requires C++ interoperability turned on in the project settings, which can be found here:

Project > Target > Build Settings > C++ and Objective-C interoperability = C++ / Objective-C++

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 file;
  • Inboxes - for using encrypted, public inboxes.