Getting the User id_graph

This document describes how to use the Litentry’s client-sdk to retrieve a user’s the id_graph.

Before continuing, make sure you have completed all the steps from the Installation section.

1. Building the Request

Build a secure trusted request using:

import { request } from "@litentry/enclave";

// The user's account. Typically, the prime identity.
const who = createLitentryIdentityType(api.registry, {
  addressOrHandle: '9oTtQwDrJk5FomPyhoTFyxRC1rmf5Dn6hYD4Ezfgiy6r',
  type: 'Solana',
});

const call = await request.getIdGraph(api, {
  who
});

The call object has the following properties:

  • call.payloadToSign: The hex-encoded trusted call.

  • call.send: A callback function to send the request to the Litentry Enclave.

The trusted call needs to be signed by the prime identity. This ensures the request is legit. The message to sign is found in call.payloadToSign.

The signature should be a hex-encoded string. Optionally accepted formats are: base58-encoded string for Solana and base64-encoded for Bitcoin identities.

2. Sending the Request.

Once the call.payloadToSign message is signed by the prime identity, you can send the transaction.

import { u8aToString } from '@polkadot/util';

const result = await send({
  signedPayload,
});

console.log(`✨ success.`);
console.log(`Received id_graph: `, result.idGraph.toHuman());

The result object has the following properties:

  • result.response: The raw Enclave’s response. A WorkerRpcReturnValue struct.

  • request.idGraph: The representation of the id_graph. A Vec<ITuple<[LitentryIdentity, IdentityContext]>> struct.

3. Calculate the hash of the id_graph

The client-sdk exposes a calculateIdGraphHash helper to get the hash of a given id_graph:

import { calculateIdGraphHash } from "@litentry/enclave";

const hash: `0x${string}` = calculateIdGraphHash(idGraph);

console.log({ hash });

Last updated