Add KYC Certificate
This guide shows the steps needed to obtain and add a KYC certificate to an account. It uses the Footprint sandbox anchor for demonstration purposes and the Anchor Resolver to search for the provider.
Create an Anchor KYC Client
Anchor clients use a UserClient and add Anchor specific interactions like KYC, FX and Asset Movement
const kycClient = new KeetaAnchor.KYC.Client(userClient);using KycClient kycClient = runtime.CreateKycClient(
TestnetEndpoints.NodeApi,
userClient.NetworkAddress,
userAccount);Get available providers
This will search the Anchor Registry for KYC Anchors that support the provided details (eg. US country code in this example)
const providers = await kycClient.createVerification({
countryCodes: ['US'],
account: userAccount
});IReadOnlyList<KycProvider> providers = await kycClient.GetProviders(Countries, cancellationToken);Start the KYC Verification
We'll use the provider matching the "Footprint" id in this step. Sandbox has 2 providers, a basic demo provider as well as the Footprint provider. Then start the verification. The result of starting verification returns a webURL that can be used to complete the KYC Verification with the KYC Anchor.
const provider = providers.find((p) => p.id === "Footprint");
const verification = await provider.startVerification();
console.log(verification.webURL);KycProvider? provider = providers.FirstOrDefault(candidate => candidate.Id == "Footprint");
VerificationOutcome created = await kycClient.StartVerification(provider, Countries, cancellationToken: cancellationToken);
if (created.Ready is null) {
Verification verification = created.Ready;
Console.WriteLine(verification.WebUrl);
}Add KYC Certificate to User Account
The KYC Anchor returns the leaf certificate and intermediates that can be used to construct the chain of authority. We can then add the certificates to the account. If the Anchor returns multiple certificates we can iterate through all of them.
for (const [i, certGroup] of certificates.results.entries()) {
// Re-wrap with the user's account as the subject key so sensitive
// attributes (PII) can be decrypted
const cert = new KeetaAnchor.lib.Certificates.Certificate(
certGroup.certificate.toPEM(),
{ subjectKey: userAccount }
);
// Construct the Certificate Bundle from Intermediates
const intermediates = certGroup.intermediates
? new KeetaAnchor.KeetaNet.lib.Utils.Certificate.CertificateBundle([...certGroup.intermediates])
: null;
// Attach the certificate to the user's account onchain
await userClient.modifyCertificate(
KeetaAnchor.KeetaNet.lib.Block.AdjustMethod.ADD,
cert,
intermediates
);
}foreach (IssuedCertificate issued in results.Ready.Results)
{
index++;
using KycCertificate certificate = runtime.KycCertificates.Parse(issued.Value);
Console.WriteLine($"\n Certificate {index}:");
using CryptoCertificate baseCertificate = certificate.Base();
Console.WriteLine($" Subject: {baseCertificate.Subject}");
Console.WriteLine($" Valid: {certificate.IsValidAt(DateTimeOffset.UtcNow)}");
if (issued.Intermediates.Count > 0)
{
Console.WriteLine($" Intermediate certificates: {issued.Intermediates.Count}");
}
if (certificate.GetAttributeNames().Contains("fullName", StringComparer.Ordinal))
{
KycAttributeValue fullName = certificate.GetAttribute("fullName", userAccount);
Console.WriteLine($" Full name (decrypted): {fullName.AsText()}");
}
await userClient.ModifyCertificateAsync(
runtime,
issued.Value,
issued.Intermediates,
cancellationToken: cancellationToken).ConfigureAwait(false);
}Read Certificates from User Account
const onChain = await userClient.client.getAllCertificates(userAccount);
console.log(`\nOn-chain certificates for this account: ${onChain.length}`);IReadOnlyList<IssuedCertificate> onChain = await nodeClient.GetAllCertificates(userAccount, cancellationToken);
Console.WriteLine($"\nOn-chain certificates for this account: {onChain.Count}");Full Code Example
Last updated