Quickstart Tutorial
Step 1: Initialize The SDK
- iOS
- Android
The SDK requires an API key to communicate with the Sasha backend. The API key is passed during the init
call.
Before any SDK operations can be performed, you must initialize SashaSDK
. It is recommended to create a single instance of SashaSDK
and share it throughout your application.
import SashaSDK
private let sashaSDK: SashaSDK
let configuration = SashaSDK.Configuration(
apiKey: "your-production-api-key-here",
environment: .production
)
self.sashaSDK = try SashaSDK(configuration: configuration)
Initializing SashaSDK comes with no performance or memory penalty. The initializer doesn't allocate heavy resources, start background tasks, or perform any network calls.
Initialization is an asynchronous operation and must be called from a coroutine scope.
val sashaSDK = SashaSDK()
fun initializeSasha() {
viewModelScope.launch {
val configuration = SashaSDK.Configuration(
apiKey = "your-production-api-key-here",
environment = SashaSDK.Environment.PRODUCTION
)
sashaSDK.init(configuration)
.onSuccess {
// SDK initialized successfully
}
.onFailure { error ->
// Handle initialization error
}
}
}
You can check if the device is supported by calling the static method SashaSDK.isDeviceSupported() before initialization. The SDK requires a minimum Android API level of 28 (Android 9.0 Pie).
Step 2: Embed a Signature
To embed a signature, use the embedSignature
method. This operation embeds a verifiable signature into the image data.
- iOS
- Android
// Perform signing (runs on background threads)
let result = try await sashaSDK.embedSignature(image)
// Access results
let protectedImage = result.processedImage // CIImage
let signatureId = result.signatureId.value // UInt64
print("Signature embedded with ID: \(signatureId)")
suspend fun signImage(imageUri: Uri) {
val imageSource = ImageSource.Uri(context, imageUri)
sashaSDK.embedSignature(imageSource)
.onSuccess { response ->
val signedBitmap = response.data.toBitmap()
// Use the signed bitmap
}
.onFailure { error ->
// Handle signing error
}
}
Step 3: Verify the Signature
To verify a signature, use the lookupSignature
method. This operation checks for the presence of a valid signature.
- iOS
- Android
do {
// Scan for existing signature (non-blocking)
let signature = try await sashaSDK.lookupSignature(in: protectedImage)
print("Found signature with ID: \(signature.value)")
// Should match the signatureId from Step 2!
} catch SashaSDK.ProcessError.decodingError {
// No protection detected
print("No signature found in image")
}
suspend fun lookupSignature(imageUri: Uri) {
val imageSource = ImageSource.Uri(context, imageUri)
sashaSDK.lookupSignature(imageSource)
.onSuccess { response ->
if (response.signatureId != null) {
// Signature found
} else {
// No signature found
}
}
.onFailure { error ->
// Handle lookup error
}
}
✅ Success!
Congratulations! You've successfully protected your first image with SASHA on-device. You should now have:
- ✅ An initialized SDK instance
- ✅ A
signature_id
that uniquely identifies this protection - ✅ A protected image that looks identical to the original but contains the embedded signature
- ✅ Verified the signature can be detected
What you learned
- How to initialize the SASHA SDK
- How to embed a signature into an image
- How to verify a signature exists in an image
- All processing happens on-device without server calls
Next Steps
Now that you've protected your first image, explore these topics:
- Signature Concepts - Deep dive into how signatures work
- API Reference - Complete SDK method documentation
- Advanced Usage - Preemptive warmup, memory management, environment setup
- Error Handling - Handle errors gracefully