Add more Nostr settings

This commit is contained in:
Djuri 2024-07-11 21:48:50 +02:00
parent 2ed559aa84
commit ee4d6d88c7
7 changed files with 68 additions and 9 deletions

View file

@ -41,4 +41,41 @@ const isValidNostrRelay = async (url: string): Promise<boolean> => {
}
};
export { isValidNpub, isValidNostrRelay };
/**
* Validates if the given parameter is a valid hex public key.
* @param pubkey - The public key to validate.
* @returns A boolean indicating if the public key is valid.
*/
const isValidHexPubKey = (pubkey: string): boolean => {
return /^[0-9a-f]{64}$/i.test(pubkey);
};
/**
* Checks if a parameter is a valid pubkey or npub and converts npub to pubkey.
* @param input - The input string to check and convert.
* @returns The pubkey if valid, otherwise null.
*/
const getPubKey = (input: string): string | null => {
try {
// If input is a valid hex public key
if (isValidHexPubKey(input)) {
return input;
}
// Try to decode the input as npub
const { type, data } = nip19.decode(input);
// Check if the decoded type is 'npub' and the data length is 64 characters (32 bytes in hex)
if (type === 'npub' && data.length === 64) {
return data;
}
return null;
} catch (e) {
// If any error is thrown, the input is not valid
return null;
}
};
export { isValidNpub, isValidNostrRelay, isValidHexPubKey, getPubKey };

View file

@ -36,7 +36,8 @@
"flFlashOnUpd": "Displaybeleuchting bei neuem Block",
"mempoolInstanceHelpText": "Nur wirksam, wenn die BTClock-Datenquelle deaktiviert ist. \nZur Anwendung ist ein Neustart erforderlich.",
"luxLightToggle": "Automatisches Umschalten des Frontlichts bei Lux",
"wpTimeout": "WiFi-Konfigurationsportal timeout"
"wpTimeout": "WiFi-Konfigurationsportal timeout",
"useNostr": "Nostr-Datenquelle verwenden"
},
"control": {
"systemInfo": "Systeminfo",

View file

@ -38,7 +38,8 @@
"luxLightToggle": "Auto toggle frontlight at lux",
"wpTimeout": "WiFi-config portal timeout",
"nostrPubKey": "Nostr source pubkey",
"nostrRelay": "Nostr Relay"
"nostrRelay": "Nostr Relay",
"useNostr": "Use Nostr datasource"
},
"control": {
"systemInfo": "System info",

View file

@ -35,7 +35,8 @@
"flFlashOnUpd": "Luz de la pantalla parpadea con un nuevo bloque",
"mempoolInstanceHelpText": "Solo es efectivo cuando la fuente de datos BTClock está deshabilitada. \nEs necesario reiniciar para aplicar.",
"luxLightToggle": "Cambio automático de luz frontal en lux",
"wpTimeout": "Portal de configuración WiFi timeout"
"wpTimeout": "Portal de configuración WiFi timeout",
"useNostr": "Utilice la fuente de datos Nostr"
},
"control": {
"turnOff": "Apagar",

View file

@ -36,7 +36,8 @@
"flFlashOnUpd": "Knipper displaylicht bij nieuw blok",
"mempoolInstanceHelpText": "Alleen effectief als de BTClock-gegevensbron is uitgeschakeld. \nOm toe te passen is een herstart nodig.",
"luxLightToggle": "Schakelen displaylicht op lux",
"wpTimeout": "WiFi-config-portal timeout"
"wpTimeout": "WiFi-config-portal timeout",
"useNostr": "Gebruik Nostr-gegevensbron"
},
"control": {
"systemInfo": "Systeeminformatie",