Authentication

The Authentication process with Index Network is vital for enabling secure and decentralized identity management. By creating and signing a SIWE (Sign in With Ethereum) message for a DID session, users engage in a secure authentication method that aligns with the principles of decentralization and data ownership inherent to Index Network.

This process ensures that users can interact with the network's features, such as creating and managing indexes, in a way that maintains their privacy and autonomy.

Authenticating using SDK

To start, instantiate the IndexClient by providing the necessary configuration parameters:

import IndexClient from '@indexnetwork/sdk';
import { Wallet } from "ethers";

// Init your wallet
const wallet = new Wallet(process.env.PRIVATE_KEY);

const client = new IndexClient({
  domain: 'yourdomain.com',
  network: 'ethereum' // Optional, default is 'ethereum'
  wallet, // or provide session
});

// Perform authentication
await client.authenticate();

Alternatively, the client can be initialized with a session string, which you can obtain by signing in with a wallet yourself.

const client = new IndexClient({
  domain: 'yourdomain.com',
  session: 'a0c...34e',
});

Under the hood, the method streamlines secure authentication by using an Ethereum wallet provided for signing and blockchain interactions, generating a unique DID key for decentralized identity, and constructing and signing a SIWE message to request data access. It then creates a DID session using this message and DID key, containing an authentication token for future requests.

Finally, it stores this token within the IndexClient, automatically including it in API request headers for user authentication.

Sending the Signature in Requests

GET /identity/verify HTTP/1.1
Host: index.network
Authorization: Bearer YOUR_SIGNATURE_HERE

Last updated