code review
This commit is contained in:
parent
fd3dddf2ed
commit
719aaca022
10 changed files with 117 additions and 68 deletions
|
|
@ -1,9 +1,7 @@
|
|||
import 'dart:convert';
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:actors/actors.dart';
|
||||
import 'package:bip340/bip340.dart' as bip340;
|
||||
import 'package:crypto/crypto.dart';
|
||||
|
||||
import 'nostr_event.dart';
|
||||
|
||||
sealed class SignerMessage {
|
||||
const SignerMessage();
|
||||
|
|
@ -60,26 +58,13 @@ class NostrSignerActor with Handler<SignerMessage, SignerResult> {
|
|||
List<List<String>> tags,
|
||||
String content,
|
||||
int? createdAt,
|
||||
) {
|
||||
final ts = createdAt ?? DateTime.now().millisecondsSinceEpoch ~/ 1000;
|
||||
final ser = jsonEncode([0, _publicKey, ts, kind, tags, content]);
|
||||
final idBytes = sha256.convert(utf8.encode(ser)).bytes;
|
||||
final id = idBytes.map((b) => b.toRadixString(16).padLeft(2, '0')).join();
|
||||
|
||||
final rng = Random.secure();
|
||||
final auxBytes = List.generate(32, (_) => rng.nextInt(256));
|
||||
final aux = auxBytes.map((b) => b.toRadixString(16).padLeft(2, '0')).join();
|
||||
|
||||
final sig = bip340.sign(_privateKey, id, aux);
|
||||
|
||||
return EventSigned(jsonEncode({
|
||||
'id': id,
|
||||
'pubkey': _publicKey,
|
||||
'created_at': ts,
|
||||
'kind': kind,
|
||||
'tags': tags,
|
||||
'content': content,
|
||||
'sig': sig,
|
||||
}));
|
||||
}
|
||||
) =>
|
||||
EventSigned(signNostrEvent(
|
||||
privateKey: _privateKey,
|
||||
publicKey: _publicKey,
|
||||
kind: kind,
|
||||
tags: tags,
|
||||
content: content,
|
||||
createdAt: createdAt,
|
||||
));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue