Skip to content

Initialise holder

Initialise Holder by adding and using the following components.

In Memory Data Storage

We use in memory data storage which allows us to store data relevant to the holder which allows direct storage and retrieval of data in the server's RAM for faster access and processing.

Function Definition

export function initDataStorage(): IDataStorage {
  let conf: EthConnectionConfig = defaultEthConnectionConfig;
  conf.contractAddress = contractAddress;
  conf.url = rpcUrl;

  var dataStorage = {
    credential: new CredentialStorage(new InMemoryDataSource<W3CCredential>()),
    identity: new IdentityStorage(
      new InMemoryDataSource<Identity>(),
      new InMemoryDataSource<Profile>()
    ),
    mt: new InMemoryMerkleTreeStorage(40),

    states: new EthStateStorage(defaultEthConnectionConfig),
  };

  return dataStorage;
}

Credential Wallet

The credential wallet securely retains the credentials that have been issued to the Holder, including those chosen by the holder to be stored within their wallet.

Function Definition

export async function initCredentialWallet(
  dataStorage: IDataStorage
): Promise<CredentialWallet> {
  const resolvers = new CredentialStatusResolverRegistry();
  resolvers.register(
    CredentialStatusType.SparseMerkleTreeProof,
    new IssuerResolver()
  );
  resolvers.register(
    CredentialStatusType.Iden3ReverseSparseMerkleTreeProof,
    new RHSResolver(dataStorage.states)
  );
  resolvers.register(
    CredentialStatusType.Iden3OnchainSparseMerkleTreeProof2023,
    new OnChainResolver([defaultEthConnectionConfig])
  );
  resolvers.register(
    CredentialStatusType.Iden3commRevocationStatusV1,
    new AgentResolver()
  );

  return new CredentialWallet(dataStorage, resolvers);
}

Identity Wallet

The identity wallet contains holder's information like their identity, DID, BJJ information etc.

Function Definition

export async function initIdentityWallet(
  dataStorage: IDataStorage,
  credentialWallet: ICredentialWallet
): Promise<IIdentityWallet> {
  const memoryKeyStore = new InMemoryPrivateKeyStore();
  const bjjProvider = new BjjProvider(KmsKeyType.BabyJubJub, memoryKeyStore);
  const kms = new KMS();
  kms.registerKeyProvider(KmsKeyType.BabyJubJub, bjjProvider);

  return new IdentityWallet(kms, dataStorage, credentialWallet);
}

Wallet and Memory Setup

Function Definition

export async function initInMemoryDataStorageAndWallets() {
  const dataStorage = initDataStorage();
  const credentialWallet = await initCredentialWallet(dataStorage);
  const identityWallet = await initIdentityWallet(
    dataStorage,
    credentialWallet
  );

  return {
    dataStorage,
    credentialWallet,
    identityWallet,
  };
}

Iden3 Circuits

Function Definition

export async function initCircuitStorage(): Promise<ICircuitStorage> {
  return new FSCircuitStorage({
    dirname: process.env.CIRCUITS_PATH,
  });
}

Initialisation

const circuitStorage = new FSCircuitStorage({
  dirname: "./circuits", // path of the circuit directory
});

Proof Service

The above initialised components are used to create and initialise the Proof Service which allows us to generate proof for credential request created by the verifier.

Function Definition

export async function initProofService(
  identityWallet: IIdentityWallet,
  credentialWallet: ICredentialWallet,
  stateStorage: IStateStorage,
  circuitStorage: ICircuitStorage
): Promise<ProofService> {
  return new ProofService(
    identityWallet,
    credentialWallet,
    circuitStorage,
    stateStorage,
    { ipfsGatewayURL: "https://ipfs.io" }
  );
}

Initialisation

const proofService = await initProofService(
  identityWallet,
  credentialWallet,
  dataStorage.states,
  circuitStorage
);

Next Up: Create DID →