Backend SDK
The Backend SDK (`@dcid/server-sdk`) enables developers to construct servers managing identity operations. Frontend applications communicate with your server, which utilizes this SDK to interface with the DCID Platform.
Installation
npm install @dcid/server-sdkQuick Start
Initialize the SDK
import { DCIDServerSDK } from '@dcid/server-sdk';
const sdk = new DCIDServerSDK({
apiKey: process.env.DCID_API_KEY, // Required
environment: 'prod', // 'dev' or 'prod'
timeout: 30000 // Optional
});Authentication
Initiate OTP
// Send OTP to user's email
const result = await sdk.auth.registerOTP({
email: 'user@example.com'
});
// Or send to phone
const result = await sdk.auth.registerOTP({
phone: '+1234567890'
});Confirm OTP
const tokens = await sdk.auth.confirmOTP({
email: 'user@example.com',
otp: '123456'
});
// tokens.access_token - JWT access token
// tokens.refresh_token - JWT refresh tokenRefresh Tokens
const newTokens = await sdk.auth.refreshToken({
refreshToken: tokens.refresh_token
});Encryption Keys
Generate Key
const keyResult = await sdk.identity.encryption.generateKey({
did: 'did:iden3:dcid:main:...',
ownerEmail: 'user@example.com'
});
// keyResult.encryptedKey - HSM encrypted keyCredentials
Issue Credential
const credential = await sdk.identity.issuer.issueCredential({
did: 'did:iden3:dcid:main:...',
credentialName: 'KYCAgeCredential',
values: {
birthday: 25,
documentType: 2
},
ownerEmail: 'user@example.com'
});
// For SIG: credential.qrCodeLink
// For MTP: credential.txId, credential.claimIdStore to IPFS
const stored = await sdk.identity.ipfs.storeCredential({
did: 'did:iden3:dcid:main:...',
credential: credentialData,
credentialType: 'ProofOfAge'
});
// stored.cid - IPFS Content IdentifierVerification
Initiate Verification
const session = await sdk.identity.verification.verifySignIn({
credentialName: 'ProofOfAgeCredential'
});
// session.proofRequestUrl - URL to fetch proof request
// session.iden3commUrl - Deep link for wallet apps
// session.sessionId - Session identifierVerify Callback
const verified = await sdk.identity.verification.verifyCallback({
sessionId: session.sessionId,
jwzToken: 'user-submitted-token'
});
// verified.from - User's DID
// verified.body.scope - Proof resultsError Handling
import {
DCIDServerSDKError,
AuthenticationError,
NetworkError,
ServerError
} from '@dcid/server-sdk';
try {
await sdk.auth.registerOTP({ email });
} catch (error) {
if (error instanceof AuthenticationError) {
if (error.isApiKeyError) {
console.error('Invalid API key');
}
} else if (error instanceof NetworkError) {
console.error('Network error');
} else if (error instanceof ServerError) {
console.error('Server error');
}
}Next Steps
- Installation Guide — Detailed setup instructions for all platforms
- Server Setup — Complete server implementation example
- API Reference — Full SDK API documentation