From a1a4c04a180f737081a28572b05961ee279728c2 Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Wed, 27 Nov 2024 01:12:57 -0300 Subject: [PATCH] nip05: identifier to url. --- nip05/nip05.go | 8 ++++++++ nip05/nip05_test.go | 6 +++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/nip05/nip05.go b/nip05/nip05.go index ca5fd07..6e48d54 100644 --- a/nip05/nip05.go +++ b/nip05/nip05.go @@ -95,3 +95,11 @@ func NormalizeIdentifier(fullname string) string { return fullname } + +func IdentifierToURL(address string) string { + spl := strings.Split(address, "@") + if len(spl) == 1 { + return fmt.Sprintf("https://%s/.well-known/nostr.json?name=_", spl[0]) + } + return fmt.Sprintf("https://%s/.well-known/nostr.json?name=%s", spl[1], spl[0]) +} diff --git a/nip05/nip05_test.go b/nip05/nip05_test.go index 4d755d0..d3e49e8 100644 --- a/nip05/nip05_test.go +++ b/nip05/nip05_test.go @@ -47,10 +47,10 @@ func TestQuery(t *testing.T) { for _, test := range tests { pp, err := QueryIdentifier(context.Background(), test.input) if test.expectError { - assert.Error(t, err, "Expected error for input: %s", test.input) + assert.Error(t, err, "expected error for input: %s", test.input) } else { - assert.NoError(t, err, "Did not expect error for input: %s", test.input) - assert.Equal(t, test.expectedKey, pp.PublicKey, "For input: %s", test.input) + assert.NoError(t, err, "did not expect error for input: %s", test.input) + assert.Equal(t, test.expectedKey, pp.PublicKey, "for input: %s", test.input) } } }