setup method

Future<void> setup(
  1. TrustPinConfiguration configuration
)

Initializes this instance with the given configuration. Must be called before verify or validateConnection.

const config = TrustPinConfiguration(
  organizationId: 'your-org-id',
  projectId: 'your-project-id',
  publicKey: 'your-base64-public-key',
  mode: TrustPinMode.strict,
);
await TrustPin.shared.setup(config);

setup performs local validation only: it checks the credential shapes, stores them, and starts a background preload of the pinning configuration. It does not wait for the network, so it no longer throws fetch or validation errors. Those surface later — fail-closed — from validateConnection / verify, or eagerly from awaitConfiguration.

Setup is one-shot: once an instance is configured, a second call throws ALREADY_INITIALIZED. To use different credentials, create a new named instance via instance.

  • Throws TrustPinException with code INVALID_PROJECT_CONFIG if credentials are invalid or empty.
  • Throws TrustPinException with code ALREADY_INITIALIZED if this instance has already completed setup.

Implementation

Future<void> setup(TrustPinConfiguration configuration) async {
  try {
    await TrustPinSDKPlatform.instance.setup(
      configuration.organizationId,
      configuration.projectId,
      configuration.publicKey,
      configurationURL: configuration.configurationURL,
      mode: configuration.mode.value,
      instanceId: _instanceId,
    );
  } catch (e) {
    throw TrustPinException.fromPlatformException(e);
  }
}