setup static method

Future<void> setup({
  1. required String organizationId,
  2. required String projectId,
  3. required String publicKey,
  4. Uri? configurationURL,
  5. TrustPinMode mode = TrustPinMode.strict,
})

Initializes the TrustPin SDK with the specified configuration.

This method configures TrustPin with your organization credentials and fetches the pinning configuration from the TrustPin service. The configuration is cached for 10 minutes to optimize performance and reduce network requests.

Example Usage

// Production setup with strict mode
await TrustPin.setup(
  organizationId: 'prod-org-123',
  projectId: 'mobile-app-v2',
  publicKey: 'LS0tLS1CRUdJTi...',
  mode: TrustPinMode.strict,
);

// Development setup with permissive mode
await TrustPin.setup(
  organizationId: 'dev-org-456',
  projectId: 'mobile-app-staging',
  publicKey: 'LS0tLS1CRUdJTk...',
  mode: TrustPinMode.permissive,
);

Security Considerations

  • Production: Always use TrustPinMode.strict mode to ensure all connections are validated
  • Development: Use TrustPinMode.permissive mode to allow connections to unregistered domains
  • Credentials: Keep your public key secure and never commit it to version control in plain text

Network Requirements

This method requires network access to fetch the pinning configuration from https://cdn.trustpin.cloud. Ensure your app has appropriate network permissions and can reach this endpoint.

  • Parameter organizationId: Your organization identifier from the TrustPin dashboard

  • Parameter projectId: Your project identifier from the TrustPin dashboard

  • Parameter publicKey: Base64-encoded ECDSA P-256 public key for JWS signature verification

  • Parameter configurationURL: Custom URL for the signed payload (JWS). CDN Managed project should not use this method. Defaults to null for CDN Managed Projects

  • Parameter mode: The pinning mode controlling behavior for unregistered domains (default: TrustPinMode.strict)

  • Throws TrustPinException with code INVALID_PROJECT_CONFIG if credentials are invalid or empty

  • Throws TrustPinException with code ERROR_FETCHING_PINNING_INFO if network request fails

  • Throws TrustPinException with code JWS_VALIDATION_FAILED if JWS signature verification fails

  • Important: This method must be called before any certificate verification operations.

  • Note: Configuration is automatically cached for 10 minutes to improve performance.

Implementation

static Future<void> setup({
  required String organizationId,
  required String projectId,
  required String publicKey,
  Uri? configurationURL,
  TrustPinMode mode = TrustPinMode.strict,
}) async {
  try {
    await TrustPinSDKPlatform.instance.setup(
      organizationId,
      projectId,
      publicKey,
      configurationURL: configurationURL,
      mode: mode.value,
    );
  } catch (e) {
    throw TrustPinException.fromPlatformException(e);
  }
}