Data Storage¶
Important
Before setting up your data storage, credential wallet, and identity wallet ensure that you have downloaded circuits.
Data Storage allows us to store information relevant to the issuer.
Install Packages¶
In Memory Data Storage¶
We implement In Memory Storage for issuer. In memory data storage stores and retrieves data directly in the system's main memory (RAM), enabling faster access and processing for applications running on a server.
Warning
Using In Memory Data Storage for new credential storage is not recommended for the production environment.
Function Definition¶
export function initInMemoryDataStorage(): IDataStorage {
let conf: EthConnectionConfig = defaultEthConnectionConfig;
conf.contractAddress = process.env.STATE_CONTRACT_ADDRESS as string;
conf.url = process.env.RHS_URL as string;
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 stores credentials issued by the Issuer.
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¶
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 = initInMemoryDataStorage();
const credentialWallet = await initCredentialWallet(dataStorage);
const identityWallet = await initIdentityWallet(
dataStorage,
credentialWallet
);
return {
dataStorage,
credentialWallet,
identityWallet,
};
}