This section will guide you through integrating Albus into your workflow. The on-chain part is implemented in Rust, while the off-chain part is built with TypeScript.
Web3 protocols (business users) are referred to as service providers in this section. For all definitions, please refer to the Glossary.
On-Chain Component (Rust)
Installation
Add this code to install the albus-verifier crate.
[dependencies]albus-solana-verifier ="0.1.2"
Usage
Verify user compliance on-chain
This method verifies on-chain that a proof request (Certificate) is not expired and contains a valid ZK Proof. If both conditions are met, Albus proceeds to execute the code. If it's not, Albus returns an error.
Example
use albus_solana_verifier::AlbusCompliant;AlbusCompliant::new(&ctx.accounts.proof_request)// (Optional) checks association with a user.with_user(ctx.accounts.sender.key("<USER_ADDRESS>"))// (Optional) checks association with a policy.with_policy(ctx.accounts.policy.key("<POLICY_ADDRESS>")).check()?;
Retrieve a proof request's address
This method retrieves an address of a proof request (Certificate).
It's a non-unique address of an account created on-chain when a user requests a Certificate on the frontend of the Albus application. It's associated with a specific user, policy, and service provider. It can be found by addresses of the user and the policy it is associated with.
Example
let user =Pubkey::new("<USER_ADDRESS>");let policy =Pubkey::new("<POLICY_ADDRESS>");// (Optional) retrieves a policy's address by a service provider's address and policy's codelet (policy, _) = albus_solana_verifier::find_policy_address(&service, "<POLICY_CODE>");let (proof_request, _) = albus_solana_verifier::find_proof_request_address(&policy, &user);
Retrieve a policy's address
This method retrieves an address of a policy by its code stored in our database.
Example
let service =Pubkey::new("SERVICE_PROVIDER_ADDRESS");// (Optional) retrieves a service provider's address by its codelet (service, _) =find_service_provider_address("service_provider_code");let (policy, _) = albus_solana_verifier::find_policy_address(&service, "<POLICY_CODE>");
Retrieve a service provider's address
This method retrieves an address of a service provider by its unique code stored in our database.
Example
let (service_provider, _) = albus_solana_verifier::find_service_provider_address("<SERVICE_PROVIDER_CODE>");
Off-Chain Component (TypeScript)
Installation
Install the @albus/sdk package (yarn and npm package managers can also be used).
This method creates a proof request (Certificate) on-chain based on codes of a service provider and a policy. The codes can be added from a config file or retrieved with the find method.
import { SERVICE_CODE, POLICY_CODE } from'@/config'// Retrieves a service provider's code via a list of all service providersconstservices=awaitclient.service.find()constservice=services.find(s =>s.data.code ==='<SERVICE_PROVIDER_CODE>')constserviceCode=service?.data?.code ??SERVICE_CODE// Retrieves a policy's code via a list of all policiesconstpolicies=awaitalbus.client.policy.find({ serviceCode })constpolicy=policies.find(p =>p.data.code ==='<POLICY_CODE>')constpolicyCode=policy.data.code ??POLICY_CODEawaitclient.proofRequest.create({ serviceCode, policyCode })
Generate a ZK Proof for a proof request
This method generates a Zero-Knowledge Proof for a specific proof request (Certificate). Once the ZK Proof is generated and verified, the user is issued the Certificate on the frontend.
proofRequest: address of the proof request for which the ZK Proof is to be generated.
vc: address of the credential to be used to generate the ZK Proof.
userPrivateKey: key generated from a seed phrase and used to encrypt and decrypt credentials of a user.
Example
constcertificates=awaitclient.proofRequest.find()constcertificate= certificates[0] // The first proof request (Certificate) is usedconstproofRequest=certificate.addressconst ekp = Keypair.fromSeed('<SEED_PHRASE>') // Contains the seed phrase used to generate a decryption key when creating a credential
constdecryptionKey=ekp.secretKeyconstcredentials=awaitclient.credential.loadAll({ decryptionKey }) // Retrieves a list of all credentials of a userconstcredential= credentials[0] // The first credential is usedconstvc=credential.addressconstprops= { proofRequest, vc, userPrivateKey }awaitclient.proofRequest.fullProve(props)
credential: credentials contain specific user data required for a specific ZK Proof. If a credential doesn't contain this data, ZK Proof generation will fail.
decryptionKey: same as userPrivateKey above. If a wrong key is passed, ZK Proof generation will fail.
Delete a proof request
This method deletes a proof request (Certificate).
constcertificate= certificates[0] // The first proof request (Certificate) is usedconstproofRequest=certificate.addressawaitclient.proofRequest.delete({ proofRequest })
decryptionKey: a key generated from a seed phrase and used to encrypt and decrypt credentials of an end user.
Example
import { Keypair } from'@solana/web3.js'const ekp = Keypair.fromSeed('<SEED_PHRASE>') // Contains the seed phrase used to generate a decryption key when creating the credential
awaitclient.credential.loadAll({ decryptionKey:ekp.secretKey,})
Revoke a credential
This method revokes a credential issued for a user. Credential NFTs can only be deleted using the revoke method.
The props are the same as above (create a policy).
Delete policy
This method deletes a policy.
constserviceCode=service.data.code // Service provider's codeconstpolicy= policies[0] // The first policy is usedconstcode=policy.data.code // Policy's codeclient.policy.delete({ serviceCode: string, code: string })