authenticate method

Future<void> authenticate()

Implementation

Future<void> authenticate() async {
  try {
    _newIdentity = await Ed25519KeyIdentity.generate(null);
    Ed25519PublicKey publicKey = _newIdentity!.getPublicKey();
    var publicKeyDer = publicKey.toDer();
    publicKeyString = bytesToHex(publicKeyDer);

    const baseUrl = 'https://nplfj-4yaaa-aaaag-qjucq-cai.icp0.io';
    final url =
        '$baseUrl?sessionkey=$publicKeyString&host=${widget.host}&scheme=${widget.scheme}';

    await launchUrl(
      Uri.parse(url),
      customTabsOptions: CustomTabsOptions(
        colorSchemes: CustomTabsColorSchemes.defaults(
          toolbarColor: Colors.blue,
          navigationBarColor: Colors.black,
        ),
        shareState: CustomTabsShareState.on,
        urlBarHidingEnabled: true,
        showTitle: true,
      ),
      safariVCOptions: const SafariViewControllerOptions(
        preferredBarTintColor: Colors.blue,
        preferredControlTintColor: Colors.black,
        barCollapsingEnabled: true,
        entersReaderIfAvailable: false,
      ),
    );
  } catch (e) {
    setState(() {
      _error = 'Failed to open URL: $e';
    });
    log('Error: $_error');
  }
}