SecureBankKit.initialize constructor
SecureBankKit.initialize({
- bool enableRootDetection = true,
- bool enablePinning = false,
- bool enableAppIntegrity = true,
- bool enableEmulatorDetection = true,
- bool enableScreenRecordingDetection = false,
- bool enableTamperDetection = true,
- bool enableRuntimeProtection = true,
- bool enableLogging = false,
- Map<
String, List< certificatePins = const {},String> > - PinningMode pinningMode = PinningMode.publicKey,
- SecurityContext? pinningSecurityContext,
- String tokenNamespace = 'sbk',
Creates and returns a fully-wired SecureBankKit instance.
Implementation
factory SecureBankKit.initialize({
bool enableRootDetection = true,
bool enablePinning = false,
bool enableAppIntegrity = true,
bool enableEmulatorDetection = true,
bool enableScreenRecordingDetection = false,
bool enableTamperDetection = true,
bool enableRuntimeProtection = true,
bool enableLogging = false,
Map<String, List<String>> certificatePins = const {},
/// What the pins in [certificatePins] are hashes of: the certificate's
/// public key (default, survives certificate renewal) or the whole
/// certificate.
PinningMode pinningMode = PinningMode.publicKey,
/// Trust store used for pinned connections. Leave `null` to use the
/// platform trust store; pass one to trust a private CA.
SecurityContext? pinningSecurityContext,
/// Prefix for the secure-storage keys used by [tokenStorage] and
/// [tokenExpiry].
String tokenNamespace = 'sbk',
}) {
if (enableLogging) {
SecurityLogger.enable();
}
final channel = MethodChannelSecurity();
// Datasources
final certDs = CertificatePinningDatasource(
mode: pinningMode,
securityContext: pinningSecurityContext,
);
final rootDs = RootDetectionDatasource(channel);
final screenshotDs = ScreenshotProtectionDatasource(channel);
final integrityDs = AppIntegrityDatasource(channel);
final storageDs = SecureStorageDatasource(channel);
final emulatorDs = EmulatorDetectionDatasource(channel);
final recordingDs = ScreenRecordingDatasource(channel);
final tamperDs = TamperDetectionDatasource(channel);
final runtimeDs = RuntimeProtectionDatasource(channel);
final antiTamperDs = AntiTamperDatasource(channel);
final screenCaptureDs = ScreenCaptureDatasource(channel);
final pasteboardDs = PasteboardDatasource(channel);
final biometricDs = BiometricDatasource(channel);
// Repositories
final certRepo = CertificatePinningRepositoryImpl(certDs);
final rootRepo = RootDetectionRepositoryImpl(rootDs);
final screenshotRepo = ScreenshotProtectionRepositoryImpl(screenshotDs);
final integrityRepo = AppIntegrityRepositoryImpl(integrityDs);
final storageRepo = SecureStorageRepositoryImpl(storageDs);
final emulatorRepo = EmulatorDetectionRepositoryImpl(emulatorDs);
final recordingRepo = ScreenRecordingRepositoryImpl(recordingDs);
final tamperRepo = TamperDetectionRepositoryImpl(tamperDs);
final runtimeRepo = RuntimeProtectionRepositoryImpl(runtimeDs);
final antiTamperRepo = AntiTamperRepositoryImpl(antiTamperDs);
final captureRepo = ScreenCaptureRepositoryImpl(screenCaptureDs);
final pasteboardRepo = PasteboardRepositoryImpl(pasteboardDs);
final biometricRepo = BiometricRepositoryImpl(biometricDs);
// Use cases
final checkRoot = CheckRootStatusUseCase(rootRepo);
final validateCert = ValidateCertificateUseCase(certRepo);
final checkIntegrity = CheckAppIntegrityUseCase(integrityRepo);
final toggleScreenshot = ToggleScreenshotProtectionUseCase(screenshotRepo);
final secureStorageUc = SecureStorageUseCase(storageRepo);
final checkEmulator = CheckEmulatorUseCase(emulatorRepo);
final checkRecording = CheckScreenRecordingUseCase(recordingRepo);
final checkTamper = CheckTamperUseCase(tamperRepo);
final checkRuntime = CheckRuntimeProtectionUseCase(runtimeRepo);
final checkAntiTamper = CheckAntiTamperUseCase(antiTamperRepo);
final monitorCapture = MonitorScreenCaptureUseCase(captureRepo);
final pasteboardUc = PasteboardUseCase(pasteboardRepo);
final biometricAuth = BiometricAuthUseCase(biometricRepo);
// Managers
final tokenStorage = SecureTokenStorage(
storageRepo,
namespace: tokenNamespace,
);
final tokenExpiry = TokenExpiryManager(
storage: storageRepo,
tokenStorage: tokenStorage,
);
SecurityLogger.info('SecureBankKit initialized');
return SecureBankKit._(
enableRootDetection: enableRootDetection,
enablePinning: enablePinning,
enableAppIntegrity: enableAppIntegrity,
enableEmulatorDetection: enableEmulatorDetection,
enableScreenRecordingDetection: enableScreenRecordingDetection,
enableTamperDetection: enableTamperDetection,
enableRuntimeProtection: enableRuntimeProtection,
certificatePins: certificatePins,
checkRoot: checkRoot,
validateCertificate: validateCert,
checkAppIntegrity: checkIntegrity,
checkEmulator: checkEmulator,
checkScreenRecording: checkRecording,
checkTamper: checkTamper,
checkRuntimeProtection: checkRuntime,
toggleScreenshot: toggleScreenshot,
secureStorageUseCase: secureStorageUc,
checkAntiTamper: checkAntiTamper,
monitorScreenCapture: monitorCapture,
pasteboardUseCase: pasteboardUc,
biometricAuth: biometricAuth,
biometricRepository: biometricRepo,
tokenStorage: tokenStorage,
tokenExpiry: tokenExpiry,
pinningMode: pinningMode,
pinningSecurityContext: pinningSecurityContext,
);
}