create method

  1. @override
Future<CreateResponse> create({
  1. List<List<String>>? methods,
})
override

Implementation

@override
Future<CreateResponse> create({List<List<String>>? methods}) async {
  _checkInitialized();
  final String symKey = core.crypto.getUtils().generateRandomBytes32();
  final String topic = await core.crypto.setSymKey(symKey);
  final int expiry = ReownCoreUtils.calculateExpiry(
    ReownConstants.FIVE_MINUTES,
  );
  final Relay relay = Relay(ReownConstants.RELAYER_DEFAULT_PROTOCOL);
  final PairingInfo pairing = PairingInfo(
    topic: topic,
    expiry: expiry,
    relay: relay,
    active: false,
    methods: methods?.expand((e) => e).toList() ?? [],
  );
  final Uri uri = ReownCoreUtils.formatUri(
    protocol: core.protocol,
    version: core.version,
    topic: topic,
    symKey: symKey,
    relay: relay,
    methods: methods,
    expiry: expiry,
  );

  onPairingCreate.broadcast(
    PairingEvent(
      topic: topic,
    ),
  );

  await pairings.set(topic, pairing);
  await core.relayClient.subscribe(topic: topic);
  await core.expirer.set(topic, expiry);

  return CreateResponse(
    topic: topic,
    uri: uri,
    pairingInfo: pairing,
  );
}