Merge branch 'spike/block2-derisking'
This commit is contained in:
commit
5b59670c47
7 changed files with 149 additions and 13 deletions
25
apps/app_seeds/lib/services/profile_cache.dart
Normal file
25
apps/app_seeds/lib/services/profile_cache.dart
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
import '../security/secret_store.dart';
|
||||
|
||||
/// Remembers the display names peers have published (their NIP-01 kind:0
|
||||
/// `name`), so the inbox and chat show a human name instead of a raw key —
|
||||
/// even offline. Keystore-backed (no plaintext at rest).
|
||||
class ProfileCache {
|
||||
ProfileCache(this._store);
|
||||
|
||||
final SecretStore _store;
|
||||
static const _prefix = 'tane.social.name.';
|
||||
|
||||
/// The cached name for [pubkeyHex], or null if none is known.
|
||||
Future<String?> name(String pubkeyHex) async {
|
||||
final value = await _store.read('$_prefix$pubkeyHex');
|
||||
return (value == null || value.isEmpty) ? null : value;
|
||||
}
|
||||
|
||||
Future<void> setName(String pubkeyHex, String name) =>
|
||||
_store.write('$_prefix$pubkeyHex', name.trim());
|
||||
}
|
||||
|
||||
/// A compact, human-ish rendering of a public key when no name is known yet.
|
||||
String shortPubkey(String pubkeyHex) => pubkeyHex.length <= 12
|
||||
? pubkeyHex
|
||||
: '${pubkeyHex.substring(0, 6)}…${pubkeyHex.substring(pubkeyHex.length - 4)}';
|
||||
Loading…
Add table
Add a link
Reference in a new issue