dcid/server-sdk

PHP SDK for the DCID Backend API

Maintainers

Package info

github.com/gettrustid/dcid-backend-sdk-php

pkg:composer/dcid/server-sdk

Statistics

Installs: 4

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v0.1.0 2026-04-14 01:08 UTC

This package is auto-updated.

Last update: 2026-04-14 01:08:55 UTC


README

PHP SDK for the DCID Backend API. Provides authentication, identity management, encrypted credential storage (IPFS/blob storage), verification, and analytics capabilities.

Requirements

  • PHP 8.1+
  • Composer

Installation

composer require dcid/server-sdk

Quick Start

use DCID\ServerSDK\DCIDServerSDK;
use DCID\ServerSDK\Types\InitiateOTPOptions;
use DCID\ServerSDK\Types\ConfirmOTPOptions;

$sdk = new DCIDServerSDK([
    'apiKey' => 'your-api-key',
    'environment' => 'prod', // or 'dev'
]);

// Step 1: Initiate OTP
$result = $sdk->auth->registerOtp(new InitiateOTPOptions(email: 'user@example.com'));

// Step 2: Confirm OTP (tokens are automatically stored)
$tokens = $sdk->auth->confirmOtp(new ConfirmOTPOptions(
    otp: '123456',
    email: 'user@example.com',
));

// Step 3: Use authenticated endpoints
$key = $sdk->identity->encryption->generateKey(
    new \DCID\ServerSDK\Types\GenerateEncryptionKeyOptions(
        did: 'did:iden3:trustid:main:...',
        ownerEmail: 'user@example.com',
    )
);

Configuration

$sdk = new DCIDServerSDK([
    'apiKey' => 'your-api-key',          // Required
    'environment' => 'prod',              // 'dev' or 'prod' (default: 'prod')
    'timeout' => 30000,                   // Request timeout in ms (default: 30000)
    'defaultHeaders' => [],               // Custom headers
    'logger' => new ConsoleLogger(),      // Custom logger
    'enableRequestLogging' => false,      // Enable request/response logging
]);

Modules

Authentication ($sdk->auth)

Method Description
registerOtp(InitiateOTPOptions) Initiate OTP registration/sign-in
confirmOtp(ConfirmOTPOptions) Confirm OTP and receive tokens
adminLogin(InitiateOTPOptions) Initiate admin login
refreshToken(RefreshTokenOptions) Refresh access token

Identity - Encryption ($sdk->identity->encryption)

Method Description
generateKey(GenerateEncryptionKeyOptions) Generate encryption key for a DID
getKey(GetEncryptedKeyOptions) Retrieve encrypted key

Identity - Issuer ($sdk->identity->issuer)

Method Description
issueCredential(IssueCredentialOptions) Issue a verifiable credential
getCredentialOffer(GetCredentialOfferOptions) Get credential offer status

Identity - Encrypted Storage ($sdk->identity->ipfs)

Credential storage backed by IPFS or blob storage. All data is assumed to be pre-encrypted by the client before storage.

Method Description
storeCredential(StoreCredentialOptions) Store an encrypted credential to IPFS/blob storage
retrieveUserCredential(RetrieveUserCredentialOptions) Retrieve an encrypted credential
getAllUserCredentials(GetAllUserCredentialsOptions) Get all encrypted credentials for a user

Identity - Verification ($sdk->identity->verification)

Method Description
verifySignIn(VerifySignInOptions) Initiate sign-in verification
getLinkStore(GetLinkStoreOptions) Get stored proof request
postLinkStore(PostLinkStoreOptions) Store proof request
verifyCallback(VerifyCallbackOptions) Submit and verify proof response

Analytics ($sdk->analytics)

Method Description
startSession(?StartSessionEvent) Start analytics session
endSession(EndSessionEvent) End analytics session

Error Handling

use DCID\ServerSDK\Errors\AuthenticationError;
use DCID\ServerSDK\Errors\NetworkError;
use DCID\ServerSDK\Errors\ServerError;
use DCID\ServerSDK\Errors\DCIDServerSDKError;

try {
    $result = $sdk->identity->encryption->generateKey($options);
} catch (AuthenticationError $e) {
    if ($e->isApiKeyError) {
        // Invalid API key
    } else {
        // JWT token issue (expired, invalid)
    }
} catch (NetworkError $e) {
    // Connection timeout, DNS failure, etc.
    echo $e->errorCode; // e.g., 'ECONNREFUSED'
} catch (ServerError $e) {
    if ($e->isBackendConnectivityError) {
        // Backend service unreachable (via KrakenD)
    }
} catch (DCIDServerSDKError $e) {
    // Other API errors (4xx)
    echo $e->statusCode;
    echo $e->context?->url;
}

Token Management

Tokens are automatically managed after confirmOtp() or refreshToken(). You can also manage them manually:

$sdk->setAuthToken('your-access-token');
$sdk->setRefreshToken('your-refresh-token');

$accessToken = $sdk->getAuthToken();
$refreshToken = $sdk->getRefreshToken();

The SDK automatically refreshes expired access tokens on 401 responses.

License

MIT