connect method
Connects to the Calljmp project and establishes device attestation.
This method performs the initial connection to your Calljmp project, including device attestation to verify the app's authenticity. It should be called early in your app's lifecycle to establish secure communication.
The method uses platform-specific attestation (App Attestation on iOS, Play Integrity on Android) to prove the app's identity and integrity.
Throws
- HttpException if there's a network error
CalljmpExceptionif the project connection failsAttestationExceptionif device attestation fails (in production)
Example
try {
await calljmp.project.connect();
print('Successfully connected to Calljmp project');
} catch (e) {
print('Failed to connect: $e');
}
Note
In debug mode, attestation failures are logged but do not prevent the connection from succeeding. In production, attestation failures will cause the connection to fail for security reasons.
Implementation
Future<void> connect() async {
final attest = await _attestation
.attest({'platform': Platform.operatingSystem})
.catchError((error) {
developer.log(
"Failed to attest, this is fatal error unless it is in debug mode",
name: "calljmp",
error: error,
);
return Null;
});
final attestationToken = base64.encode(utf8.encode(jsonEncode(attest)));
await http
.request("${_config.projectUrl}/app/connect")
.use(http.context(_config))
.post({"attestationToken": attestationToken})
.json();
}