1
+ using System . Web ;
2
+ using NBitcoin . Secp256k1 ;
3
+
4
+ namespace NNostr . Client . Protocols ;
5
+
6
+ public static class NIP67
7
+ {
8
+ public static int EventKind = 33194 ;
9
+ public record NIP67UriPayload (
10
+ ECXOnlyPubKey Pubkey ,
11
+ ECPrivKey Secret ,
12
+ string [ ] Relays ,
13
+ string [ ] RequiredCommands ,
14
+ string [ ] OptionalCommands ,
15
+ string ? Budget ,
16
+ string ? Identity )
17
+ {
18
+ public override string ToString ( )
19
+ {
20
+ var result =
21
+ $ "nostr+walletauth://{ Pubkey . ToHex ( ) } ?relay={ string . Join ( "&relay=" , Relays ) } &secret={ Secret . CreateXOnlyPubKey ( ) . ToHex ( ) } &required_commands={ string . Join ( " " , RequiredCommands ) } ";
22
+
23
+ if ( OptionalCommands . Length > 0 )
24
+ result += $ "&optional_commands={ string . Join ( " " , OptionalCommands ) } ";
25
+ if ( Budget is not null )
26
+ result += $ "&budget={ Budget } ";
27
+ if ( Identity is not null )
28
+ result += $ "&identity={ Identity } ";
29
+ return result ;
30
+ }
31
+ }
32
+
33
+
34
+ public const string UriScheme = "nostr+walletconnect" ;
35
+
36
+ //nostr+walletauth://b889ff5b1513b641e2a139f661a661364979c5beee91842f8f0ef42ab558e9d4?relay=wss%3A%2F%2Frelay.damus.io&secret=b8a30fafa48d4795b6c0eec169a383de&required_commands=pay_invoice%20pay_keysend%20make_invoice%20lookup_invoice&optional_commands=list_transactions&budget=10000%2Fdaily
37
+
38
+ public static NIP67UriPayload ParseUri ( Uri uri )
39
+ {
40
+ var query = HttpUtility . ParseQueryString ( uri . Query ) ;
41
+
42
+ var relays = query . GetValues ( "relay" ) ?? Array . Empty < string > ( ) ;
43
+ var secret = NostrExtensions . ParseKey ( query [ "secret" ] ) ;
44
+ var requiredCommands = query . GetValues ( "required_commands" ) ? . SelectMany ( s => s . Split ( " " ) ) . Distinct ( ) . ToArray ( ) ?? Array . Empty < string > ( ) ;
45
+ var optionalCommands = query . GetValues ( "optional_commands" ) ? . SelectMany ( s => s . Split ( " " ) ) . Distinct ( ) . ToArray ( ) ?? Array . Empty < string > ( ) ;
46
+ var budget = query . GetValues ( "budget" ) ? . FirstOrDefault ( ) ;
47
+ var identity = query . GetValues ( "identity" ) ? . FirstOrDefault ( ) ;
48
+
49
+ return new NIP67UriPayload ( NostrExtensions . ParsePubKey ( uri . Host ) , secret , relays , requiredCommands , optionalCommands , budget , identity ) ;
50
+ }
51
+ }
0 commit comments