startPairing method
Starts sponsoring a device join for the already-open database localId.
Returns a one-time PairingCode to show the user. The other device calls
pairWith with it; a PAKE over the transport authenticates the exchange,
and this device seals the group key to the new one. If localId has no
group key yet (a brand-new database), this founds it first.
Requires a configured Identity and PAKE. The armed session is single-use and replaced by the next startPairing call; cancelPairing drops it.
Implementation
Future<PairingCode> startPairing(
String localId, {
String joinerLabel = 'paired device',
}) async {
final coordinator = _requirePairing();
final db = _databases[localId];
final rosterKey = _databaseKeys[localId];
if (db == null || rosterKey == null) {
throw StateError('Open database "$localId" before starting pairing.');
}
if (db.deviceState != DeviceState.ready) {
await db.foundGroup();
}
return coordinator.arm(
rosterKey: rosterKey,
onAdmit: (joiner) async {
await db.admitDevice(joiner, label: joinerLabel);
return db.exportRosterPins();
},
);
}