Developer documentation · Optional
Optional identity, credentials, and privacy proofs.
Use the Advanced Identity SDK only when your application needs portable identity, credentials, authentication, or privacy-preserving proofs. It is not required for the standard Trust ID website deployment.
01 · Advanced Identity SDK · Getting started
A three-tier architecture by default.
Applies to the Advanced Identity SDK only. The standard JavaScript tag needs no account, credentials, app IDs or backend.Trust ID uses a three-tier architecture. Your frontend application communicates with your backend server, which in turn communicates with the Trust ID platform. This architecture ensures sensitive API keys remain server-side and never reach the client. Once initialized, the frontend SDK also emits the live event stream — connections, clicks, scrolls, form submits, performance, and identity events — automatically, with no additional calls.
Your frontend app.
Web, React Native, or browser extension. Uses @dcid/sdk.
Your backend server.
Express, FastAPI, or Gin. Uses @dcid/server-sdk.
Trust ID platform.
iden3, HSM, IPFS, blockchain.
Prerequisites
- A Trust ID account with API credentials.
- Signing App ID and Encryption App ID. Request from info@tracerlabs.com.
- Node.js 16+, Python 3.8+, or Go 1.21+.
- A backend server. Required — API keys must not be exposed client-side.
02 · Advanced Identity SDK · Installation
Pick your package manager.
Frontend
npm install @dcid/sdk
Backend (Node)
npm install @dcid/server-sdk
Backend (Python)
pip install dcid-server-sdk
Backend (Go)
go get github.com/gettrustid/dcid-backend-sdk/golang
Frontend SDK
npm install @dcid/sdkBackend SDK
npm install @dcid/server-sdkEnvironment variables
| Variable | Required | Description |
|---|---|---|
| TRUSTID_APP_ID | Yes | Signing application ID (Identity SDK only). |
| TRUSTID_APP_ID_ENCRYPTION | Yes | Encryption application ID. |
| TRUSTID_API_KEY | Yes (backend) | Server-side API key. |
| TRUSTID_ENV | Yes | dev or prod. |
| TRUSTID_API_URL | Yes | API endpoint URL. |
03 · Advanced Identity SDK · Authentication
Optional OTP sign-in and session management.
Applies to the Advanced Identity SDK only. The standard JavaScript tag does not authenticate users and does not require a Trust ID account. The SDK offers OTP sign-in as one option for issuing sessions. It is not required. If you already authenticate your users, keep your existing flow.
Frontend auth flow
const client = new DCIDClient({
appId: process.env.TRUSTID_APP_ID,
appIdEncryption: process.env.TRUSTID_APP_ID_ENCRYPTION,
env: 'prod',
apiUrl: 'https://api.trustid.life'
});
await client.initialize();
// Step 1: Send OTP to user
await client.auth.initiateSignIn('user@example.com');
// Step 2: Confirm OTP code
const tokens = await client.auth.confirmCode('user@example.com', '123456');
// Step 3: Complete authentication
await client.auth.login(tokens.accessToken, tokens.refreshToken);Backend auth
const sdk = new DCIDServerSDK({
apiKey: process.env.TRUSTID_API_KEY,
environment: 'prod'
});
// Send OTP
const result = await sdk.auth.registerOTP({ email: 'user@example.com' });
// Confirm OTP
const tokens = await sdk.auth.confirmOTP({
email: 'user@example.com',
otp: '123456'
});Auth methods
initiateSignIn(login)
Send an OTP code to the user's email or phone number.
Promise<void>
confirmCode(login, code)
Validate the OTP code and receive access and refresh tokens.
TokenResponse
login(accessToken, refreshToken)
Complete authentication and establish the user session.
Promise<void>
logout()
Sign out the current user and clear all stored tokens.
Promise<void>
getAccessToken()
Get the current access token. Automatically refreshes if expired.
Promise<string>
isAuthenticated()
Check whether the user is currently authenticated.
boolean
onAuthStateChanged(callback)
Subscribe to auth state changes. Fires whenever the user logs in or out.
Unsubscribe
04 · Advanced Identity SDK · Identity
Decentralized identifiers, self-custodial keys.
Trust ID creates decentralized identities (DIDs) using the iden3 protocol. Each identity is self-custodial and cryptographically secured. The first call to createIdentity generates the user's Baby JubJub key pair and registers the DID on-chain. Subsequent calls retrieve the existing identity.
const identity = await client.identity.createIdentity(
'user@example.com',
accessToken
);
// identity.did → "did:iden3:trustid:main:{identifier}"
// identity.wallet → Wallet object
// identity.publicKey → BJJ hex public keyDID format
Trust ID DIDs follow the pattern did:iden3:trustid:main:{identifier} where the identifier is derived from the user’s cryptographic key material. The DID is permanent and portable across all Trust ID-integrated applications.
Looking for visitor identity resolution on the live data feed? That is a separate surface — see Identity events.
05 · Advanced Identity SDK · Credentials
W3C verifiable credentials, wallet-held.
Trust ID supports W3C Verifiable Credentials for storing and sharing proof of verification events. Credentials are stored in the user's self-custodial wallet and can be backed up to IPFS with encryption.
Credential methods
handleCredentialOffer()
Process and store an incoming credential offer from an issuer.
Promise<void>
getCredentials()
Retrieve all credentials stored in the user's wallet.
Promise<Credential[]>
storeCredential(credential)
Store a W3C verifiable credential directly in the user's wallet.
Promise<void>
hasCredentialType(type)
Check if a credential of the specified type exists in the wallet.
Promise<boolean>
backupAllCredentials()
Create an encrypted backup of all credentials to IPFS.
Promise<string>
recoverCredentialsFromIPFS()
Restore credentials from an encrypted IPFS backup.
Promise<void>
Supported credential types
DocumentVerification.
Government-issued ID verification.
ProofOfAge.
Age verification for age-gated content and products.
Custom schemas.
Define your own credential types with custom JSON-LD schemas.
06 · Advanced Identity SDK · Zero-knowledge proofs
Prove without revealing.
Trust ID enables zero-knowledge proof generation and verification, allowing users to prove attributes about themselves without revealing the underlying data. Proofs are generated client-side using ZK circuits and verified against the blockchain.
const proof = await client.proofs.createAndVerifyProof({
emailOrPhone: 'user@example.com',
did: identity.did,
proofRequestUrl: 'https://api.trustid.life/proof-request/...',
accessToken: tokens.accessToken
});
// proof.verified → boolean
// proof.submitted → booleanQuery types
| Type | Description | Example |
|---|---|---|
| Comparison | Numeric comparisons (<, >, =, range). | Age >= 21. |
| Set membership | Value in allowed set. | Country in [US, UK, CA]. |
| Selective disclosure | Reveal specific fields only. | Share name without DOB. |
Error codes
| Code | Description |
|---|---|
| CREDENTIAL_NOT_FOUND | No matching credential in the user's wallet. |
| CIRCUIT_LOAD_FAILED | ZK circuit files are unavailable or could not be loaded. |
| PROOF_GENERATION_FAILED | Proof computation encountered an error. |
| VERIFICATION_FAILED | Proof did not pass verification. |
07 · Advanced Identity SDK · Platform guides
Web, mobile, and extensions.
React Native
The Trust ID SDK is production-ready for React Native with platform-specific security features.
Peer dependencies
- @react-native-async-storage/async-storage
- react-native-keychain
iOS setup
- Run cd ios && pod install after installing dependencies.
- Use .xcworkspace (not .xcodeproj) to open the project.
- Requires iOS 15.1+.
Android setup
- minSdkVersion 24 required.
Critical
You must call client.setMkHSM() before client.initialize() in React Native. This configures the HSM bridge for native key storage. Circuit caching via MMKV storage is recommended for performance.
Browser extension
- Manifest V3 required.
- Content security policy: wasm-unsafe-eval is needed for ZK proof circuits.
- Storage: use chrome.storage.local for credential persistence.
Web application
import { trustidPlugin } from '@dcid/sdk/vite-plugin-web';
export default defineConfig({
plugins: [trustidPlugin()]
});08 · Advanced Identity SDK · Backend server setup
Minimal sample servers.
Your backend server acts as the secure intermediary between your frontend application and the Trust ID platform. Below are minimal server implementations in Express, FastAPI, and Gin.
import express from 'express';
import cors from 'cors';
import { DCIDServerSDK } from '@dcid/server-sdk';
const app = express();
app.use(cors());
app.use(express.json());
const sdk = new DCIDServerSDK({
apiKey: process.env.TRUSTID_API_KEY!,
environment: process.env.TRUSTID_ENV as 'dev' | 'prod'
});
app.post('/auth/initiate', async (req, res) => {
const result = await sdk.auth.registerOTP({ email: req.body.email });
res.json(result);
});
app.post('/auth/confirm', async (req, res) => {
const tokens = await sdk.auth.confirmOTP({
email: req.body.email,
otp: req.body.otp
});
res.json(tokens);
});
app.listen(3001, () => console.log('Server running on :3001'));09 · Advanced Identity SDK · Frontend API reference
The complete @dcid/sdk surface.
Complete reference for all methods available in the @dcid/sdk frontend package. Event capture needs no method calls: once the SDK is initialized, it streams the events documented in the event stream reference on its own.
| Module | Method | Parameters | Returns | Description |
|---|---|---|---|---|
| auth.initiateSignIn | initiateSignIn | login: string | Promise<void> | Send OTP to email/phone. |
| auth.confirmCode | confirmCode | login: string, code: string | TokenResponse | Validate OTP code. |
| auth.login | login | accessToken: string, refreshToken: string | Promise<void> | Complete authentication. |
| auth.logout | logout | — | Promise<void> | Clear session. |
| auth.getAccessToken | getAccessToken | — | Promise<string> | Get token (auto-refresh). |
| auth.getRefreshToken | getRefreshToken | — | Promise<string> | Get refresh token. |
| auth.refreshTokens | refreshTokens | — | Promise<TokenResponse> | Manual token refresh. |
| auth.isAuthenticated | isAuthenticated | — | boolean | Check auth status. |
| auth.onAuthStateChanged | onAuthStateChanged | callback: Function | Unsubscribe | Auth state listener. |
| identity.createIdentity | createIdentity | emailOrPhone: string, accessToken?: string | IdentityResult | Create or retrieve identity. |
| credentials.handleCredentialOffer | handleCredentialOffer | — | Promise<void> | Process credential offer. |
| credentials.getCredentials | getCredentials | — | Promise<Credential[]> | Get all credentials. |
| credentials.storeCredential | storeCredential | credential: object | Promise<void> | Store W3C credential. |
| credentials.hasCredentialType | hasCredentialType | type: string | Promise<boolean> | Check credential exists. |
| credentials.backupAllCredentials | backupAllCredentials | — | Promise<string> | IPFS backup. |
| credentials.recoverCredentialsFromIPFS | recoverCredentialsFromIPFS | — | Promise<void> | Restore from IPFS. |
| proofs.createAndVerifyProof | createAndVerifyProof | config: ProofConfig | ProofResult | Generate and verify ZK proof. |
| proofs.verifyProof | verifyProof | wallet, proof, pubSignals, circuitId | Promise<boolean> | Local proof verification. |
10 · Advanced Identity SDK · Backend API reference
The complete @dcid/server-sdk surface.
Complete reference for all methods available in the @dcid/server-sdk backend package.
| Module | Method | Parameters | Returns | Description |
|---|---|---|---|---|
| auth.registerOTP | registerOTP | { email/phone } | InitiateOTPResponse | Send OTP. |
| auth.confirmOTP | confirmOTP | { email/phone, otp } | TokenResponse | Validate OTP. |
| auth.refreshToken | refreshToken | { refreshToken } | TokenResponse | Refresh access token. |
| identity.encryption.generateKey | generateKey | { did } | KeyResponse | Generate HSM key. |
| identity.encryption.getKey | getKey | { did } | KeyResponse | Retrieve key. |
| identity.issuer.issueCredential | issueCredential | { recipientDid, name, values, ownerEmail } | CredentialResponse | Issue credential. |
| identity.issuer.getCredentialOffer | getCredentialOffer | { claimId, transactionId } | OfferResponse | Get credential offer URL. |
| identity.ipfs.storeCredential | storeCredential | { did, credential, encrypt? } | StorageResponse | Store to IPFS. |
| identity.ipfs.retrieveUserCredential | retrieveUserCredential | { did, type } | CredentialResponse | Fetch by type. |
| identity.ipfs.getAllUserCredentials | getAllUserCredentials | { did } | CredentialResponse[] | Fetch all. |
| identity.verification.verifySignIn | verifySignIn | { credentialName } | VerifyResponse | Start verification. |
| identity.verification.getLinkStore | getLinkStore | { sessionId } | ProofRequest | Get proof request. |
| identity.verification.verifyCallback | verifyCallback | { sessionId, jwzToken } | VerifyResult | Verify proof. |
11 · Advanced Identity SDK · Configuration
Constructor options.
DCIDClient options
Constructor options for the frontend SDK.
| Option | Type | Required | Description |
|---|---|---|---|
| appId | string | Yes | Signing application ID (Identity SDK only). |
| appIdEncryption | string | Yes | Encryption application ID. |
| env | 'dev' | 'prod' | Yes | Environment. |
| apiUrl | string | Yes | API endpoint URL. |
| wsUrl | string | No | WebSocket URL. |
| platform | string | No | Override platform detection. |
| timeout | number | No | Request timeout (ms). |
| maxRetries | number | No | Max retry attempts. |
| logger | object | No | Custom logger. |
DCIDServerSDK options
Constructor options for the backend SDK.
| Option | Type | Required | Description |
|---|---|---|---|
| apiKey | string | Yes | Server-side API key. |
| environment | 'dev' | 'prod' | Yes | Environment. |
| timeout | number | No | Request timeout (ms). |
| defaultHeaders | object | No | Custom headers. |
| logger | object | No | Custom logger. |
| enableRequestLogging | boolean | No | Log all requests. |
12 · Advanced Identity SDK · Resources
Packages, examples, and support.
Need help?
Contact our engineering team at info@tracerlabs.com for integration support, or talk to a solutions engineer.
