Add nostr settings
This commit is contained in:
parent
2363d98965
commit
2ed559aa84
5 changed files with 177 additions and 2 deletions
|
@ -1 +1,44 @@
|
|||
// place files you want to import through the `$lib` alias in this folder.
|
||||
import * as nip19 from 'nostr-tools/nip19';
|
||||
import { Relay } from 'nostr-tools';
|
||||
|
||||
/**
|
||||
* Validates if the given npub is a valid Nostr Public Key.
|
||||
* @param npub - The npub (Nostr Public Key) to validate.
|
||||
* @returns A boolean indicating if the npub is valid.
|
||||
*/
|
||||
const isValidNpub = (npub: string): boolean => {
|
||||
try {
|
||||
// Decode the npub using NIP-19
|
||||
const { type, data } = nip19.decode(npub);
|
||||
// Check if the type is 'npub' and the data length is 32 bytes
|
||||
return type === 'npub' && data.length === 64;
|
||||
} catch (e) {
|
||||
// If any error is thrown, the npub is not valid
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Validates if the given URL is a valid Nostr relay.
|
||||
* @param url - The URL of the Nostr relay to validate.
|
||||
* @returns A Promise<boolean> indicating if the URL is a valid Nostr relay.
|
||||
*/
|
||||
const isValidNostrRelay = async (url: string): Promise<boolean> => {
|
||||
try {
|
||||
const relay: Relay = await Relay.connect(url);
|
||||
|
||||
// If the relay is successfully connected, it's a valid Nostr relay
|
||||
if (relay.connected) {
|
||||
// Close the connection to clean up
|
||||
relay.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
} catch (e) {
|
||||
// If any error is thrown, the URL is not a valid Nostr relay
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
export { isValidNpub, isValidNostrRelay };
|
||||
|
|
|
@ -36,7 +36,9 @@
|
|||
"flFlashOnUpd": "Frontlight flash on new block",
|
||||
"mempoolInstanceHelpText": "Only effective when BTClock data-source is disabled. A restart is required to apply.",
|
||||
"luxLightToggle": "Auto toggle frontlight at lux",
|
||||
"wpTimeout": "WiFi-config portal timeout"
|
||||
"wpTimeout": "WiFi-config portal timeout",
|
||||
"nostrPubKey": "Nostr source pubkey",
|
||||
"nostrRelay": "Nostr Relay"
|
||||
},
|
||||
"control": {
|
||||
"systemInfo": "System info",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue