enableRecovery method
Mints a recovery phrase for the open database localId and registers it
in the roster: 24 BIP39 words whose derived keypair is admitted as a
virtual device holding a wrap of the group key, so a fresh install can
later regain access with recoverFrom — even when the device that called
this is gone.
Returns the words. Show them to the user once and never store them;
they are equivalent to a device that can read everything. Calling this
again mints an independent second phrase (each is its own roster entry).
A phrase is withdrawn like a device: pass its device id (labelled
label in devices) to revokeDevice.
Requires PassnoteConfig.recoveryEnabled, a configured recovery
derivation (see Passnote.builder / recoveryIdentity: on
passnoteLowLevel), and a database in DeviceState.ready; throws
StateError otherwise.
Implementation
Future<List<String>> enableRecovery(
String localId, {
String label = 'recovery phrase',
}) async {
final derive = _requireRecovery();
final db = _database(localId);
if (db.deviceState != DeviceState.ready) {
throw StateError(
'Database "$localId" does not hold the group key '
'(deviceState is ${db.deviceState}); pair or found it first.',
);
}
final words = _mnemonicGenerator(24);
final recovery = await derive(words.join(' '), _config.salt);
await db.admitDevice(await recovery.publicKey, label: label);
return words;
}