NwcRequest.fromEvent constructor

NwcRequest.fromEvent(
  1. Nip01Event event,
  2. String contentDecryptionPrivateKey
)

Implementation

factory NwcRequest.fromEvent(
    Nip01Event event, String contentDecryptionPrivateKey) {
  final connectionPubkey = event.pubKey;
  final decryptedContent = Nip04.decrypt(
    event.content,
    contentDecryptionPrivateKey,
    connectionPubkey,
  );

  final content = jsonDecode(decryptedContent);
  final method = content['method'] as String;
  final params = content['params'] as Map<String, dynamic>? ?? {};

  return NwcRequest.fromMap({
    'method': method,
    'created_at': event.createdAt,
    ...params,
  });
}