pair method
Implementation
@override
Future<PairingInfo> pair({
required Uri uri,
bool activatePairing = false,
}) async {
_checkInitialized();
// print(uri.queryParameters);
final int expiry = ReownCoreUtils.calculateExpiry(
ReownConstants.FIVE_MINUTES,
);
final URIParseResult parsedUri = ReownCoreUtils.parseUri(uri);
if (parsedUri.version != URIVersion.v2) {
throw Errors.getInternalError(
Errors.MISSING_OR_INVALID,
context: 'URI is not WalletConnect version 2 URI',
);
}
final String topic = parsedUri.topic;
final Relay relay = parsedUri.v2Data!.relay;
final String symKey = parsedUri.v2Data!.symKey;
final PairingInfo pairing = PairingInfo(
topic: topic,
expiry: expiry,
relay: relay,
active: false,
methods: parsedUri.v2Data!.methods,
);
try {
JsonRpcUtils.validateMethods(
parsedUri.v2Data!.methods,
routerMapRequest.values.toList(),
);
} on ReownCoreError catch (e) {
// Tell people that the pairing is invalid
onPairingInvalid.broadcast(
PairingInvalidEvent(
message: e.message,
),
);
// Delete the pairing: "publish internally with reason"
// await _deletePairing(
// topic,
// false,
// );
rethrow;
}
try {
await pairings.set(topic, pairing);
await core.crypto.setSymKey(symKey, overrideTopic: topic);
await core.relayClient.subscribe(topic: topic);
await core.expirer.set(topic, expiry);
onPairingCreate.broadcast(
PairingEvent(
topic: topic,
),
);
if (activatePairing) {
await activate(topic: topic);
}
} catch (e) {
rethrow;
}
return pairing;
}