Skip to content

Commit

Permalink
fix connection bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Kukks committed May 14, 2024
1 parent af6d41a commit 03dda5e
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 6 deletions.
8 changes: 8 additions & 0 deletions NNostr.Client/IsExternalInit.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

#if !NET5_0_OR_GREATER
namespace System.Runtime.CompilerServices
{
internal static class IsExternalInit {}
}

#endif
2 changes: 1 addition & 1 deletion NNostr.Client/NNostr.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Nullable>enable</Nullable>
<LangVersion>11</LangVersion>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageVersion>0.0.44</PackageVersion>
<PackageVersion>0.0.45</PackageVersion>
<Title>Nostr Client</Title>
<Description>A client for Nostr</Description>
<Copyright>MIT</Copyright>
Expand Down
5 changes: 0 additions & 5 deletions NNostr.Client/NostrClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,6 @@ public void Dispose()
}


public async Task ConnectAndWaitUntilConnected(CancellationToken token = default)
{

}

public async Task ConnectAndWaitUntilConnected(CancellationToken connectionCancellationToken = default,
CancellationToken lifetimeCancellationToken = default)
{
Expand Down
51 changes: 51 additions & 0 deletions NNostr.Client/Protocols/NIP67.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System.Web;
using NBitcoin.Secp256k1;

namespace NNostr.Client.Protocols;

public static class NIP67
{
public static int EventKind = 33194;
public record NIP67UriPayload(
ECXOnlyPubKey Pubkey,
ECPrivKey Secret,
string[] Relays,
string[] RequiredCommands,
string[] OptionalCommands,
string? Budget,
string? Identity)
{
public override string ToString()
{
var result =
$"nostr+walletauth://{Pubkey.ToHex()}?relay={string.Join("&relay=", Relays)}&secret={Secret.CreateXOnlyPubKey().ToHex()}&required_commands={string.Join(" ", RequiredCommands)}";

if(OptionalCommands.Length > 0)
result += $"&optional_commands={string.Join(" ", OptionalCommands)}";
if(Budget is not null)
result += $"&budget={Budget}";
if(Identity is not null)
result += $"&identity={Identity}";
return result;
}
}


public const string UriScheme = "nostr+walletconnect";

//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

public static NIP67UriPayload ParseUri(Uri uri)
{
var query = HttpUtility.ParseQueryString(uri.Query);

var relays = query.GetValues("relay") ?? Array.Empty<string>();
var secret = NostrExtensions.ParseKey(query["secret"]);
var requiredCommands = query.GetValues("required_commands")?.SelectMany(s => s.Split(" ")).Distinct().ToArray() ?? Array.Empty<string>();
var optionalCommands = query.GetValues("optional_commands")?.SelectMany(s => s.Split(" ")).Distinct().ToArray() ?? Array.Empty<string>();
var budget = query.GetValues("budget")?.FirstOrDefault();
var identity = query.GetValues("identity")?.FirstOrDefault();

return new NIP67UriPayload(NostrExtensions.ParsePubKey(uri.Host), secret, relays, requiredCommands, optionalCommands, budget, identity);
}
}

0 comments on commit 03dda5e

Please sign in to comment.