Fix/external signer returned event - #700
Conversation
📝 WalkthroughWalkthroughNIP-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. ChangesSigner event propagation
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
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (4)
packages/ndk_flutter/lib/data_layer/repositories/signers/nip55_event_signer.dartpackages/ndk_flutter/lib/signers/src/nip07_event_signer_web.dartpackages/ndk_flutter/test/nip07_event_signer_test.dartpackages/ndk_flutter/test/nip55_event_signer_test.dart
| 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, | ||
| ); |
There was a problem hiding this comment.
🎯 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.
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
| 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, | ||
| ); |
Summary by CodeRabbit