nostr tools added

This commit is contained in:
gitea
2025-11-06 14:46:59 +01:00
parent d8c90cb105
commit f8aa20eb5c
14 changed files with 1146 additions and 141 deletions
+130 -2
View File
@@ -24,8 +24,10 @@ class _SessionScreenState extends State<SessionScreen> {
final TextEditingController _userIdController = TextEditingController();
final TextEditingController _emailController = TextEditingController();
final TextEditingController _passwordController = TextEditingController();
final TextEditingController _nostrKeyController = TextEditingController();
bool _isLoading = false;
bool _useFirebaseAuth = false;
bool _useNostrLogin = false;
@override
void initState() {
@@ -41,6 +43,7 @@ class _SessionScreenState extends State<SessionScreen> {
_userIdController.dispose();
_emailController.dispose();
_passwordController.dispose();
_nostrKeyController.dispose();
super.dispose();
}
@@ -52,6 +55,50 @@ class _SessionScreenState extends State<SessionScreen> {
});
try {
// Handle Nostr login
if (_useNostrLogin) {
final nostrKey = _nostrKeyController.text.trim();
if (nostrKey.isEmpty) {
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Please enter nsec or npub key'),
),
);
}
return;
}
// Validate format
if (!nostrKey.startsWith('nsec') && !nostrKey.startsWith('npub')) {
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Invalid key format. Expected nsec or npub.'),
backgroundColor: Colors.red,
),
);
}
return;
}
// Login with Nostr
await widget.sessionService!.loginWithNostr(nostrKey);
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Nostr login successful'),
),
);
setState(() {});
widget.onSessionChanged?.call();
}
return;
}
// Handle Firebase or regular login
if (_useFirebaseAuth && widget.firebaseService != null) {
// Use Firebase Auth for authentication
final email = _emailController.text.trim();
@@ -246,7 +293,56 @@ class _SessionScreenState extends State<SessionScreen> {
),
),
const SizedBox(height: 12),
Text('User ID: ${currentUser.id}'),
// Display Nostr profile if available
if (currentUser.nostrProfile != null) ...[
Row(
children: [
if (currentUser.nostrProfile!.picture != null)
CircleAvatar(
radius: 30,
backgroundImage: NetworkImage(
currentUser.nostrProfile!.picture!,
),
onBackgroundImageError: (_, __) {},
)
else
const CircleAvatar(
radius: 30,
child: Icon(Icons.person),
),
const SizedBox(width: 12),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
currentUser.nostrProfile!.name ??
currentUser.nostrProfile!.displayName,
style: const TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
if (currentUser.nostrProfile!.about != null)
Text(
currentUser.nostrProfile!.about!,
style: TextStyle(
fontSize: 14,
color: Colors.grey[600],
),
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
],
),
),
],
),
const SizedBox(height: 12),
const Divider(),
const SizedBox(height: 12),
],
Text('User ID: ${currentUser.id.substring(0, currentUser.id.length > 32 ? 32 : currentUser.id.length)}${currentUser.id.length > 32 ? '...' : ''}'),
Text('Username: ${currentUser.username}'),
Text(
'Created: ${DateTime.fromMillisecondsSinceEpoch(currentUser.createdAt).toString().split('.')[0]}',
@@ -306,7 +402,39 @@ class _SessionScreenState extends State<SessionScreen> {
),
],
const SizedBox(height: 24),
if (_useFirebaseAuth) ...[
// Login method selector
SegmentedButton<bool>(
segments: const [
ButtonSegment<bool>(
value: false,
label: Text('Regular'),
),
ButtonSegment<bool>(
value: true,
label: Text('Nostr'),
),
],
selected: {_useNostrLogin},
onSelectionChanged: (Set<bool> newSelection) {
setState(() {
_useNostrLogin = newSelection.first;
});
},
),
const SizedBox(height: 24),
if (_useNostrLogin) ...[
TextField(
controller: _nostrKeyController,
decoration: const InputDecoration(
labelText: 'Nostr Key (nsec or npub)',
hintText: 'Enter your nsec or npub key',
border: OutlineInputBorder(),
helperText: 'Enter your Nostr private key (nsec) or public key (npub)',
),
maxLines: 3,
minLines: 1,
),
] else if (_useFirebaseAuth) ...[
TextField(
controller: _emailController,
decoration: const InputDecoration(