Low-level Server-Side SDK

The Virto Server-Side SDK provides functionality specifically designed for server environments. Unlike the client-side SDK, these functions do not depend on browser APIs and can be executed in a Node.js environment.

Configuration

import ServerSDK from '@virtonetwork/sdk/server';

const serverSdk = new ServerSDK({
  federate_server: 'http://your-federate-server.com/api',
  provider_url: 'ws://your-blockchain-provider:12281',
  config: {
    wallet: 'polkadotjs',
    jwt: {
      secret: 'your-jwt-secret',
      expiresIn: '1h'  // Optional, defaults to '10m'
    }
  }
});

Auth Methods

The serverSdk.auth object provides the following methods for handling authentication on the server side:

completeRegistration(preparedData)

Completes the user registration process on the server side after registration data has been prepared by the client.

Parameters:

  • preparedData: Object containing the registration data prepared by the client

Returns: Promise that resolves to the server's response to the registration.

Example:

completeConnection(preparedData)

Completes the connection process on the server side after authentication data has been prepared by the client. Creates a session for the user and returns a JWT token if configured.

Parameters:

  • preparedData: Object containing the connection data prepared by the client

Returns: Promise with the server's response, session information, and JWT token (if configured).

Example:

signWithToken(token, command)

Signs a blockchain extrinsic after verifying the provided JWT token.

Parameters:

  • token: String - The JWT token to verify

  • command: Object containing the extrinsic details

Returns: Promise with the signing result including user ID, signed extrinsic, and original command.

Example:

verifyToken(token)

Verifies a JWT token and returns the decoded payload if valid.

Parameters:

  • token: String - The JWT token to verify

Returns: The decoded token payload if valid.

Example:

isRegistered(userId)

Checks if a user is registered with the federate server.

Parameters:

  • userId: String - The unique identifier for the user

Returns: Promise with a boolean indicating if the user is registered.

Example:

Error Handling

All methods may throw errors that should be handled appropriately:

Common error codes include:

  • E_CANT_GET_CREDENTIAL: User wallet not found

  • E_NO_JWT_CONFIG: JWT configuration not provided

  • E_JWT_EXPIRED: Token has expired

  • E_JWT_INVALID: Invalid token

  • E_JWT_UNKNOWN: Token verification failed

  • E_SESSION_NOT_FOUND: Session not found for this token

  • E_ADDRESS_MISMATCH: Token address does not match session address

Sequence Diagram

Last updated