Skip to content

Fix/external signer returned event - #700

Merged
nogringo merged 2 commits into
masterfrom
fix/external-signer-returned-event
Aug 5, 2026
Merged

Fix/external signer returned event#700
nogringo merged 2 commits into
masterfrom
fix/external-signer-returned-event

Conversation

@nogringo

@nogringo nogringo commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • Bug Fixes
    • Improved event signing through browser and external signers by preserving all signer-provided event details, including public keys, timestamps, content, tags, IDs, and signatures.
    • Added support for signed event data returned by external signing services, with a safe fallback when no complete event is provided.
    • Improved account switching and optional client-tag removal during browser-based signing.
  • Tests
    • Expanded coverage for external signing, signature validation, account changes, and client-tag handling.

@nogringo
nogringo requested review from 1-leo and frnandu July 30, 2026 23:32
@nogringo nogringo self-assigned this Jul 30, 2026
@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

NIP-55 signing now uses externally returned serialized events when available, while NIP-07 propagates all signer-returned fields. Tests cover event identity, signature validation, client-tag stripping, and account changes.

Changes

Signer event propagation

Layer / File(s) Summary
NIP-55 signed event handling
packages/ndk_flutter/lib/data_layer/repositories/signers/nip55_event_signer.dart, packages/ndk_flutter/test/nip55_event_signer_test.dart
NIP-55 decodes and returns non-empty signer-provided event JSON, with signature-only fallback coverage.
NIP-07 signed event propagation
packages/ndk_flutter/lib/signers/src/nip07_event_signer_web.dart, packages/ndk_flutter/test/nip07_event_signer_test.dart
NIP-07 copies signer-returned event fields, with tests for client-tag filtering and account switching.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Nip55EventSigner
  participant Nip55Signer
  participant NostrEvent
  Nip55EventSigner->>Nip55Signer: sign event
  Nip55Signer-->>Nip55EventSigner: signature and serialized event
  Nip55EventSigner->>NostrEvent: decode returned event
  NostrEvent-->>Nip55EventSigner: signed event
Loading

Possibly related PRs

Suggested reviewers: frnandu, 1-leo

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: fixing handling of events returned by external signers.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/external-signer-returned-event

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/ndk_flutter/lib/signers/src/nip07_event_signer_web.dart`:
- Around line 237-245: Update the signing flow around the event.copyWith return
to refresh cachedPublicKey from the signer-returned signedEvent.pubkey before
returning the event. Extend the account-switch test to assert that
getPublicKey() returns the new pubkey after switching accounts.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: ca82cf11-7279-47c0-be0f-44dcef5ad3ed

📥 Commits

Reviewing files that changed from the base of the PR and between e4a7319 and c29a666.

📒 Files selected for processing (4)
  • packages/ndk_flutter/lib/data_layer/repositories/signers/nip55_event_signer.dart
  • packages/ndk_flutter/lib/signers/src/nip07_event_signer_web.dart
  • packages/ndk_flutter/test/nip07_event_signer_test.dart
  • packages/ndk_flutter/test/nip55_event_signer_test.dart

Comment on lines +237 to +245
return event.copyWith(
id: signedEvent.id!,
sig: signedEvent.sig!,
pubKey: signedEvent.pubkey,
createdAt: signedEvent.created_at,
kind: signedEvent.kind,
content: signedEvent.content,
tags: signedEvent.tagsList,
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Refresh the cached account from the signed event.

After an extension account switch, this returns the new pubkey but leaves cachedPublicKey stale. Subsequent getPublicKey() calls still identify the old account. Update the cache from the signer-returned pubkey and assert it in the account-switch test.

Proposed fix
       final signedEvent = await js.nostr!.signEvent(jsEvent).toDart;
+      final signerPubKey = signedEvent.pubkey;
+      if (signerPubKey != null) {
+        cachedPublicKey = signerPubKey;
+      }

       return event.copyWith(
         id: signedEvent.id!,
         sig: signedEvent.sig!,
-        pubKey: signedEvent.pubkey,
+        pubKey: signerPubKey,
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/ndk_flutter/lib/signers/src/nip07_event_signer_web.dart` around
lines 237 - 245, Update the signing flow around the event.copyWith return to
refresh cachedPublicKey from the signer-returned signedEvent.pubkey before
returning the event. Extend the account-switch test to assert that
getPublicKey() returns the new pubkey after switching accounts.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't this important @nogringo ?

@codecov

codecov Bot commented Jul 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 71.32%. Comparing base (e4a7319) to head (c29a666).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #700   +/-   ##
=======================================
  Coverage   71.32%   71.32%           
=======================================
  Files         225      225           
  Lines       13201    13201           
=======================================
  Hits         9415     9415           
  Misses       3786     3786           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment on lines +237 to +245
return event.copyWith(
id: signedEvent.id!,
sig: signedEvent.sig!,
pubKey: signedEvent.pubkey,
createdAt: signedEvent.created_at,
kind: signedEvent.kind,
content: signedEvent.content,
tags: signedEvent.tagsList,
);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't this important @nogringo ?

@nogringo
nogringo merged commit 4e28d2e into master Aug 5, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants