Open Source (Self-hosted)

Affinidi provides an open-sourced Control Plane implementation that can be self-hosted.

You can explore, customise, and deploy it locally to understand how message handling and encryption works under the hood.

To deploy the Control Plane API Server from the open-sourced version, follow the steps below:

1. Prerequisites

Before you begin, install the following applications.

  1. Install Dart SDK^3.6.0 or later on your machine if you haven’t installed it yet using this guide.

  2. Install Docker on your machine if you haven’t installed it yet using this guide. We will need this to run your self-hosted Control Plane.

2. Clone the Control Plane Repository

  1. Clone the GitHub repo on your local.
git clone git@github.com:affinidi/affinidi-meetingplace-controlplane-api-dart.git
  1. Navigate to the affinidi-meetingplace-controlplane-api-dart folder.
cd affinidi-meetingplace-controlplane-api-dart

3. Set up the Control Plane Instance

  1. Copy the example Docker Compose file to a new docker-compose.yml file:
cp examples/docker/local/docker-compose.example.yml docker-compose.yml
  1. Create a copy of config.yml by copying the file from examples/config folder.
cp examples/config/config.example.yml config.yml
  1. Copy the .env.example file to a new .env file
cp examples/env/.env.example .env
  1. Set environment variables in the docker file.

    • Open the newly copied docker-compose.yml file and update the necessary environment variables, such as storage, API endpoint, and secrets.
    • For more information about environment variables, refer to environment variables section.

    You will be able to setup your own Control Plane DID directly from the environment variable in the docker-compose.yml file. This will be the same DID that you can use for testing.

  2. Create the key pairs to generate JSON Web Keys (JWKs) for DIDComm Auth.

mkdir -p ./keys mkdir -p ./params mkdir -p ./secrets openssl ecparam -name secp256k1 -genkey -noout -out ./keys/secp256k1.pem openssl ecparam -name prime256v1 -genkey -noout -out ./keys/p256.pem openssl genpkey -algorithm Ed25519 -out ./keys/ed25519.pem openssl pkey -in keys/ed25519.pem -pubout -out ./keys/ed25519-pub.pem
  1. Run the setup script to generate the JWKSs from the key pairs.
dart run script/setup.dart

The script will generate the required secrets files to run the API server.

  1. Start the Control Plane Server using docker compose build command:
docker-compose up --build

Navigate to http://localhost:3000 or whichever host and port you use in the configuration to verify if the Control Plane API is running.

You should see the page below indicating that the instance is up and running:

Meeting Place App

Control Plane API Server

4. Test the Control Plane Connection

You have two options to test the Control Plane server you just created.

4.1 Using Affinidi Control Plane SDK for Dart

To test using the Control Plane SDK, follow the steps below.

You also need to setup a DIDComm Mediator to proceed with the testing via Control Plane SDK.

4.1.1. Set up Environment

  1. Install Dart SDK version ^3.6.0 on your machine.

  2. Create a dart project repository by running the command below.

dart create my_project_name
  1. Add the Control Plane SDK and SSI dart packages.
dart pub add meeting_place_control_plane dart pub add ssi

4.1.2. Create a Dart Script

  1. Create a controlPlane.dart file with the following code.
import 'package:meeting_place_control_plane/meeting_place_control_plane.dart'; import 'package:ssi/ssi.dart'; void main() async { // Create a persistent wallet final wallet = PersistentWallet(InMemoryKeyStore()); // Create a DIDManager final didManager = DidKeyManager( wallet: wallet, store: InMemoryDidStore(), ); await didManager.addVerificationMethod( (await wallet.generateKey()).id, ); // Set your Control Plane DID final controlPlaneDid = '<REPLACE_CONTROLPLANE_DID>'; // Set your Mediator DID final mediatorDid = '<REPLACE_MEDIATOR_DID>'; // Create an instance of ControlPlaneSDK final sdk = ControlPlaneSDK( didManager: didManager, controlPlaneDid: controlPlaneDid, mediatorDid: mediatorDid, didResolver: UniversalDIDResolver(), ); // Create an authenticate command final command = AuthenticateCommand(controlPlaneDid: controlPlaneDid); // Test using the Authenticate Command final result = await sdk.execute(command); // Display the Command Result print("Generated Access Token: ${result.credentials.accessToken}"); }
  1. Replace the controlPlaneDid variable with the Control Plane DID generated from the Affinidi Portal.

You also need to set the Mediator DID variable.

final controlPlaneDid = 'did:web:<UNIQUE_ID>:mpx.affinidi.io'; final mediatorDid = 'did:web:<UNIQUE_ID>.atlas.affinidi.io:.well-known';

4.1.3. Run the Test Script

After setting up all the necessary codes and parameters, run the Dart script.

dart run controlPlane.dart

After running the script, the logs should display the access token generated after executing the Authentication Command.

4.2. Using REST API

To test the Control Plane using REST API, run the command below in your terminal:

Replace the <REPLACE_CONTROLPLANE_URL> with the generated Control Plane URL.

curl -X POST \ -H "Content-Type: application/json" \ -d '{"did": "did:peer:<UNIQUE_ID>"}' \ <REPLACE_CONTROLPLANE_URL>/v1/authenticate/challenge

Running the command should return result like below:

{"challenge":"<JWT>"}

This means that the API Server is able to respond via REST API.

For more details about how you can use REST API, you may refer to the Control Plane OSS repository.

What’s Next

  Integrate Affinidi Meeting Place into your applications

  Configure DIDComm Mediator to send messages