Skip to main content

Integration Services SDK

In this example, you will learn how to authenticate your identity using the IOTA IS-Client npm package. Since the package will handle decoding, hashing, and signing, this is the simplest way to authenticate your identity. Make sure to read the general authentication concept, so you can fully understand the Authentication Workflow.

This example uses the following identity:

{
identityId: 'did:iota:8BAmUqAg4aUjV3T9WUhPpDnFVbJSk16oLyFq3m3e62MF',
secretKey: '5N3SxG4UzVDpNe4LyDoZyb6bSgE9tk3pE2XP5znXo5bF'
}

Prerequisites

  • A recent version of Node.js (>v16.17.0).

Installation

npm install @iota/is-client@latest

Authentication Workflow

info

You can find your current API version using the http://localhost:3000/info endpoint. This example uses v0.1.

danger

Never save your secret key in plain text in your code. Use local environment variables or IOTA Stronghold to store your secret keys securely.

Depending on the functionality you are going to use, it may be sufficient to only authenticate the IdentityClient() or the ChannelClient(). Each of the clients has its own authentication state. This means that when you authenticate on the IdentityClient(), you are not automatically authenticated on the ChannelClient().

"./authenticate.js
import { IdentityClient, ChannelClient, ApiVersion } from '@iota/is-client';

const authenticate = async (identityId, secretKey) => {
const config = {
ssiBridgeUrl: 'http://localhost:3001',
auditTrailUrl: 'http://localhost:3002',
useGatewayUrl: false,
apiVersion: ApiVersion.v01
};

// Authenticate identity client
const identity = new IdentityClient(config);
await identity.authenticate(identityId, secretKey);

// Authenticate channel client
const channel = new ChannelClient(config);
await channel.authenticate(identityId, secretKey);
};

const identityId = 'did:iota:8BAmUqAg4aUjV3T9WUhPpDnFVbJSk16oLyFq3m3e62MF';
const secretKey = '5N3SxG4UzVDpNe4LyDoZyb6bSgE9tk3pE2XP5znXo5bF';
authenticate(identityId, secretKey);

You can find the complete code example at this repository: https://github.com/Schereo/is-sdk-authentication.