-
Notifications
You must be signed in to change notification settings - Fork 9
feat: add nwc supported extensions info field #740
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
frnandu
wants to merge
2
commits into
master
Choose a base branch
from
feat/nwc-extensions-info
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
packages/ndk/lib/domain_layer/usecases/nwc/consts/nwc_extension.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| /// Optional Nostr Wallet Connect extension specifications. | ||
| /// | ||
| /// The identifiers correspond to specification filenames in | ||
| /// https://github.com/nostr-wallet-connect/nwc. | ||
| enum NwcExtension { | ||
| notifications('02'), | ||
| holdInvoices('03'), | ||
| keysend('04'), | ||
| transactionHistory('05'), | ||
| metadata('06'), | ||
| deepLinks('07'), | ||
| bip321('321'); | ||
|
|
||
| /// Identifier advertised by NWC wallet services. | ||
| final String identifier; | ||
|
|
||
| const NwcExtension(this.identifier); | ||
|
|
||
| /// Returns the extension matching [identifier], or `null` when it is not | ||
| /// known by this version of NDK. | ||
| static NwcExtension? fromIdentifier(String identifier) { | ||
| final normalizedIdentifier = identifier.trim(); | ||
| for (final extension in NwcExtension.values) { | ||
| if (extension.identifier == normalizedIdentifier) { | ||
| return extension; | ||
| } | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| /// Parses identifiers from NIP-47 fields. | ||
| /// | ||
| /// Each input may be a single identifier, as used by `get_info`, or a | ||
| /// space-separated list, as used by the kind 13194 info event. | ||
| static Set<NwcExtension> fromIdentifiers(Iterable<String> identifiers) { | ||
| final extensions = <NwcExtension>{}; | ||
| for (final value in identifiers) { | ||
| for (final identifier in value.split(RegExp(r'\s+'))) { | ||
| final extension = fromIdentifier(identifier); | ||
| if (extension != null) { | ||
| extensions.add(extension); | ||
| } | ||
| } | ||
| } | ||
| return extensions; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| import 'package:ndk/ndk.dart'; | ||
| import 'package:test/test.dart'; | ||
|
|
||
| void main() { | ||
| group('NwcExtension', () { | ||
| test('maps the registered NWC extension identifiers', () { | ||
| expect(NwcExtension.fromIdentifier('02'), NwcExtension.notifications); | ||
| expect(NwcExtension.fromIdentifier('03'), NwcExtension.holdInvoices); | ||
| expect(NwcExtension.fromIdentifier('04'), NwcExtension.keysend); | ||
| expect( | ||
| NwcExtension.fromIdentifier('05'), | ||
| NwcExtension.transactionHistory, | ||
| ); | ||
| expect( | ||
| NwcExtension.fromIdentifier('06'), | ||
| NwcExtension.metadata, | ||
| ); | ||
| expect(NwcExtension.fromIdentifier('07'), NwcExtension.deepLinks); | ||
| expect( | ||
| NwcExtension.fromIdentifier('321'), | ||
| NwcExtension.bip321, | ||
| ); | ||
| }); | ||
|
|
||
| test('parses space-separated values and ignores unknown extensions', () { | ||
| expect( | ||
| NwcExtension.fromIdentifiers(['02 03\t321', '999']), | ||
| { | ||
| NwcExtension.notifications, | ||
| NwcExtension.holdInvoices, | ||
| NwcExtension.bip321, | ||
| }, | ||
| ); | ||
| expect(NwcExtension.fromIdentifier('999'), isNull); | ||
| }); | ||
| }); | ||
|
|
||
| group('GetInfoResponse extensions', () { | ||
| test('deserializes and checks supported extensions', () { | ||
| final response = GetInfoResponse.deserialize({ | ||
| 'result_type': 'get_info', | ||
| 'result': { | ||
| 'alias': 'wallet', | ||
| 'network': 'mainnet', | ||
| 'methods': ['pay_invoice'], | ||
| 'extensions': ['02', '05', 'unknown'], | ||
| }, | ||
| }); | ||
|
|
||
| expect( | ||
| response.extensions, | ||
| {NwcExtension.notifications, NwcExtension.transactionHistory}, | ||
| ); | ||
| expect(response.supportsExtension(NwcExtension.notifications), isTrue); | ||
| expect(response.supportsExtension(NwcExtension.holdInvoices), isFalse); | ||
| }); | ||
|
|
||
| test('defaults to no extensions when the optional field is absent', () { | ||
| final response = GetInfoResponse.deserialize({ | ||
| 'result_type': 'get_info', | ||
| 'result': {'alias': 'wallet', 'network': 'mainnet'}, | ||
| }); | ||
|
|
||
| expect(response.extensions, isEmpty); | ||
| }); | ||
| }); | ||
|
|
||
| test('NwcConnection can add and check advertised extensions', () { | ||
| final connection = NwcConnection( | ||
| NostrWalletConnectUri( | ||
| walletPubkey: 'wallet-pubkey', | ||
| relays: ['wss://relay.example.com'], | ||
| secret: 'secret', | ||
| ), | ||
| eventSignerFactory: const Bip340EventSignerFactory(), | ||
| ); | ||
|
|
||
| connection.addSupportedExtensions(['02 04']); | ||
|
|
||
| expect(connection.supportsExtension(NwcExtension.notifications), isTrue); | ||
| expect(connection.supportsExtension(NwcExtension.keysend), isTrue); | ||
| expect(connection.supportsExtension(NwcExtension.holdInvoices), isFalse); | ||
| }); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: relaystr/ndk
Length of output: 9942
🏁 Script executed:
Repository: relaystr/ndk
Length of output: 19738
🌐 Web query:
NIP-47 info event extensions tag get_info extensions semantics wallet capabilities💡 Result:
In NIP-47 (Nostr Wallet Connect), the
infoevent (kind 13194) is a replaceable event published by the wallet service to advertise its capabilities [1][2][3]. Recent updates to the specification have introduced a modular system for extensions to streamline the core protocol [4][5]. Extensions Tag and Semantics Theextensionstag is used to advertise support for optional NWC extension specifications [6]. - Format: It contains a space-separated list of extension identifiers (e.g.,["extensions", "02 03 04"]) [6]. - Semantics: This tag allows clients to discover which modular features a wallet supports, such as notifications, hold invoices, or transaction history, without overloading the core NIP-47 specification [6][4]. - Implementation: Any additional methods supported through these extensions should also be included in the content of theinfoevent, alongside the core methods [6]. Wallet Capabilities andget_infoTheget_infomethod allows clients to retrieve detailed wallet metadata and functional status [6][3]. - Structure: Theresultobject of theget_inforesponse includes: -methods: An array of supported core methods [7][6]. -extensions: An optional array of supported extension identifiers [6]. -notifications: An optional list of supported notification types [7][6]. - Metadata: Additional fields such asalias,color,pubkey,network,block_height, andblock_hash[7][6]. By utilizing thisextensionsframework, developers can create more modular and interoperable NWC implementations, as wallets can selectively advertise support for specific features while maintaining a standardized way for clients to discover them [8][4].Citations:
Refresh
supportedExtensionson eachget_inforesponse.If the info event does not advertise an extension, repeated
getInfocalls useaddAll, so an extension omitted by a later response remains reported byNwcConnection.supportsExtension. Track the info-event andget_infosets separately, then recompute their union. Add a regression test with two differentget_infoextension sets.🤖 Prompt for AI Agents
Source: MCP tools