WalletConnectSession.fromUri constructor

WalletConnectSession.fromUri(
  1. String uri
)

Implementation

factory WalletConnectSession.fromUri(String uri) {
  final protocolSeparator = uri.indexOf(':');
  final topicSeparator = uri.indexOf('@', protocolSeparator);
  final versionSeparator = uri.indexOf('?');
  final protocol = uri.substring(0, protocolSeparator);
  final handshakeTopic = uri.substring(protocolSeparator + 1, topicSeparator);

  final version = uri.substring(topicSeparator + 1, versionSeparator);
  final params = Uri.dataFromString(uri).queryParameters;
  final bridge = params['bridge'] ??
      (throw WalletConnectException('Missing bridge param in URI'));

  final key = params['key'] ??
      (throw WalletConnectException('Missing key param in URI'));

  return WalletConnectSession(
    protocol: protocol,
    version: int.tryParse(version) ?? 1,
    handshakeTopic: handshakeTopic,
    bridge: Uri.decodeFull(bridge),
    key: Uint8List.fromList(hex.decode(key)),
    accounts: [],
  );
}