forked from chmac/nostr-map
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
39 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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,32 @@ | ||
import { TRUSTROOTS_NIP5_URL } from "../constants"; | ||
import { getTrustrootsUsernameFromLocation } from "../router"; | ||
import { alert } from "../utils"; | ||
import { getPublicKey } from "./keys"; | ||
|
||
export const validateNip5 = async () => { | ||
try { | ||
const username = getTrustrootsUsernameFromLocation(); | ||
if (username.length < 3) { | ||
alert( | ||
`Sorry, you need to click to this page from trustroots.org. Without doing that, this site won't work properly. Please go to www.trustroots.org and click the Notes link to come back here. #wBjsEe`, | ||
`You need to click from trustroots` | ||
); | ||
return; | ||
} | ||
|
||
const result = await fetch(`${TRUSTROOTS_NIP5_URL}?name=${username}`); | ||
const nip5 = (await result.json()) as { | ||
names: { [username: string]: string }; | ||
}; | ||
const nip5PublicKey = nip5.names?.[username]; | ||
const localPublicKey = await getPublicKey(); | ||
if (nip5PublicKey !== localPublicKey) { | ||
alert( | ||
`Your key doesn't match trustroots. Posting to the map will not work. Please sign out and sign in again with the nsec key that matches your trustroots npub key. #H9bEe2`, | ||
"Fatal error" | ||
); | ||
} | ||
} catch (error) { | ||
alert(error, `Unexpected error`); | ||
} | ||
}; |
This file contains 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 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