forked from btclock/webui
Add nostr settings
This commit is contained in:
parent
2363d98965
commit
2ed559aa84
5 changed files with 177 additions and 2 deletions
|
@ -48,8 +48,10 @@
|
|||
"@fontsource/antonio": "^5.0.17",
|
||||
"@fontsource/oswald": "^5.0.17",
|
||||
"@fontsource/ubuntu": "^5.0.8",
|
||||
"@noble/secp256k1": "^2.1.0",
|
||||
"@playwright/test": "^1.40.0",
|
||||
"bootstrap": "^5.3.2",
|
||||
"nostr-tools": "^2.7.1",
|
||||
"patch-package": "^8.0.0",
|
||||
"svelte-i18n": "^4.0.0",
|
||||
"sveltestrap": "^5.11.2",
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<script lang="ts">
|
||||
import { isValidNpub, isValidNostrRelay } from '$lib';
|
||||
import { PUBLIC_BASE_URL } from '$lib/config';
|
||||
import { uiSettings } from '$lib/uiSettings';
|
||||
import { createEventDispatcher } from 'svelte';
|
||||
|
@ -78,6 +79,11 @@
|
|||
});
|
||||
};
|
||||
|
||||
let validNostrRelay = false;
|
||||
const testNostrRelay = async () => {
|
||||
validNostrRelay = await isValidNostrRelay($settings.nostrRelay);
|
||||
};
|
||||
|
||||
const onFlBrightnessChange = async () => {
|
||||
await fetch(`${PUBLIC_BASE_URL}/api/frontlight/brightness/${$settings.flMaxBrightness}`, {
|
||||
method: 'GET',
|
||||
|
@ -273,6 +279,43 @@
|
|||
</Col>
|
||||
</Row>
|
||||
{/if}
|
||||
{#if $settings.nostrPubKey}
|
||||
<Row>
|
||||
<Label md={6} for="nostrPubKey" size={$uiSettings.inputSize}
|
||||
>{$_('section.settings.nostrPubKey')}</Label
|
||||
>
|
||||
<Col md="6">
|
||||
<Input
|
||||
type="text"
|
||||
bind:value={$settings.nostrPubKey}
|
||||
name="nostrPubKey"
|
||||
id="nostrPubKey"
|
||||
invalid={!isValidNpub($settings.nostrPubKey)}
|
||||
bsSize={$uiSettings.inputSize}
|
||||
></Input>
|
||||
</Col>
|
||||
</Row>
|
||||
<Row>
|
||||
<Label md={6} for="nostrRelay" size={$uiSettings.inputSize}
|
||||
>{$_('section.settings.nostrRelay')}</Label
|
||||
>
|
||||
<Col md="6">
|
||||
<InputGroup size={$uiSettings.inputSize}>
|
||||
<Input
|
||||
type="text"
|
||||
bind:value={$settings.nostrRelay}
|
||||
name="nostrRelay"
|
||||
id="nostrRelay"
|
||||
valid={validNostrRelay}
|
||||
bsSize={$uiSettings.inputSize}
|
||||
></Input>
|
||||
<Button type="button" color="success" on:click={testNostrRelay}
|
||||
>{$_('test', { default: 'Test' })}</Button
|
||||
>
|
||||
</InputGroup>
|
||||
</Col>
|
||||
</Row>
|
||||
{/if}
|
||||
<Row>
|
||||
<Label md={6} for="mempoolInstance" size="sm"
|
||||
>{$_('section.settings.mempoolnstance')}</Label
|
||||
|
|
85
yarn.lock
85
yarn.lock
|
@ -568,6 +568,45 @@
|
|||
"@jridgewell/resolve-uri" "^3.1.0"
|
||||
"@jridgewell/sourcemap-codec" "^1.4.14"
|
||||
|
||||
"@noble/ciphers@^0.5.1":
|
||||
version "0.5.3"
|
||||
resolved "https://registry.yarnpkg.com/@noble/ciphers/-/ciphers-0.5.3.tgz#48b536311587125e0d0c1535f73ec8375cd76b23"
|
||||
integrity sha512-B0+6IIHiqEs3BPMT0hcRmHvEj2QHOLu+uwt+tqDDeVd0oyVzh7BPrDcPjRnV1PV/5LaknXJJQvOuRGR0zQJz+w==
|
||||
|
||||
"@noble/curves@1.2.0":
|
||||
version "1.2.0"
|
||||
resolved "https://registry.yarnpkg.com/@noble/curves/-/curves-1.2.0.tgz#92d7e12e4e49b23105a2555c6984d41733d65c35"
|
||||
integrity sha512-oYclrNgRaM9SsBUBVbb8M6DTV7ZHRTKugureoYEncY5c65HOmRzvSiTE3y5CYaPYJA/GVkrhXEoF0M3Ya9PMnw==
|
||||
dependencies:
|
||||
"@noble/hashes" "1.3.2"
|
||||
|
||||
"@noble/curves@~1.1.0":
|
||||
version "1.1.0"
|
||||
resolved "https://registry.yarnpkg.com/@noble/curves/-/curves-1.1.0.tgz#f13fc667c89184bc04cccb9b11e8e7bae27d8c3d"
|
||||
integrity sha512-091oBExgENk/kGj3AZmtBDMpxQPDtxQABR2B9lb1JbVTs6ytdzZNwvhxQ4MWasRNEzlbEH8jCWFCwhF/Obj5AA==
|
||||
dependencies:
|
||||
"@noble/hashes" "1.3.1"
|
||||
|
||||
"@noble/hashes@1.3.1":
|
||||
version "1.3.1"
|
||||
resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.3.1.tgz#8831ef002114670c603c458ab8b11328406953a9"
|
||||
integrity sha512-EbqwksQwz9xDRGfDST86whPBgM65E0OH/pCgqW0GBVzO22bNE+NuIbeTb714+IfSjU3aRk47EUvXIb5bTsenKA==
|
||||
|
||||
"@noble/hashes@1.3.2":
|
||||
version "1.3.2"
|
||||
resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.3.2.tgz#6f26dbc8fbc7205873ce3cee2f690eba0d421b39"
|
||||
integrity sha512-MVC8EAQp7MvEcm30KWENFjgR+Mkmf+D189XJTkFIlwohU5hcBbn1ZkKq7KVTi2Hme3PMGF390DaL52beVrIihQ==
|
||||
|
||||
"@noble/hashes@~1.3.0", "@noble/hashes@~1.3.1":
|
||||
version "1.3.3"
|
||||
resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.3.3.tgz#39908da56a4adc270147bb07968bf3b16cfe1699"
|
||||
integrity sha512-V7/fPHgl+jsVPXqqeOzT8egNj2iBIVt+ECeMMG8TdcnTikP3oaBtUVqpT/gYCR68aEBJSF+XbYUxStjbFMqIIA==
|
||||
|
||||
"@noble/secp256k1@^2.1.0":
|
||||
version "2.1.0"
|
||||
resolved "https://registry.yarnpkg.com/@noble/secp256k1/-/secp256k1-2.1.0.tgz#71d829a0b8ce84aea137708f82273977eea84597"
|
||||
integrity sha512-XLEQQNdablO0XZOIniFQimiXsZDNwaYgL96dZwC54Q30imSbAOFf3NKtepc+cXyuZf5Q1HCgbqgZ2UFFuHVcEw==
|
||||
|
||||
"@nodelib/fs.scandir@2.1.5":
|
||||
version "2.1.5"
|
||||
resolved "https://registry.yarnpkg.com/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz#7619c2eb21b25483f6d167548b4cfd5a7488c3d5"
|
||||
|
@ -782,6 +821,33 @@
|
|||
resolved "https://registry.yarnpkg.com/@rollup/rollup-win32-x64-msvc/-/rollup-win32-x64-msvc-4.18.1.tgz#0cb240c147c0dfd0e3eaff4cc060a772d39e155c"
|
||||
integrity sha512-yjk2MAkQmoaPYCSu35RLJ62+dz358nE83VfTePJRp8CG7aMg25mEJYpXFiD+NcevhX8LxD5OP5tktPXnXN7GDw==
|
||||
|
||||
"@scure/base@1.1.1":
|
||||
version "1.1.1"
|
||||
resolved "https://registry.yarnpkg.com/@scure/base/-/base-1.1.1.tgz#ebb651ee52ff84f420097055f4bf46cfba403938"
|
||||
integrity sha512-ZxOhsSyxYwLJj3pLZCefNitxsj093tb2vq90mp2txoYeBqbcjDjqFhyM8eUjq/uFm6zJ+mUuqxlS2FkuSY1MTA==
|
||||
|
||||
"@scure/base@~1.1.0":
|
||||
version "1.1.7"
|
||||
resolved "https://registry.yarnpkg.com/@scure/base/-/base-1.1.7.tgz#fe973311a5c6267846aa131bc72e96c5d40d2b30"
|
||||
integrity sha512-PPNYBslrLNNUQ/Yad37MHYsNQtK67EhWb6WtSvNLLPo7SdVZgkUjD6Dg+5On7zNwmskf8OX7I7Nx5oN+MIWE0g==
|
||||
|
||||
"@scure/bip32@1.3.1":
|
||||
version "1.3.1"
|
||||
resolved "https://registry.yarnpkg.com/@scure/bip32/-/bip32-1.3.1.tgz#7248aea723667f98160f593d621c47e208ccbb10"
|
||||
integrity sha512-osvveYtyzdEVbt3OfwwXFr4P2iVBL5u1Q3q4ONBfDY/UpOuXmOlbgwc1xECEboY8wIays8Yt6onaWMUdUbfl0A==
|
||||
dependencies:
|
||||
"@noble/curves" "~1.1.0"
|
||||
"@noble/hashes" "~1.3.1"
|
||||
"@scure/base" "~1.1.0"
|
||||
|
||||
"@scure/bip39@1.2.1":
|
||||
version "1.2.1"
|
||||
resolved "https://registry.yarnpkg.com/@scure/bip39/-/bip39-1.2.1.tgz#5cee8978656b272a917b7871c981e0541ad6ac2a"
|
||||
integrity sha512-Z3/Fsz1yr904dduJD0NpiyRHhRYHdcnyh73FZWiV+/qhWi83wNJ3NWolYqCEN+ZWsUz2TWwajJggcRE9r1zUYg==
|
||||
dependencies:
|
||||
"@noble/hashes" "~1.3.0"
|
||||
"@scure/base" "~1.1.0"
|
||||
|
||||
"@sinclair/typebox@^0.27.8":
|
||||
version "0.27.8"
|
||||
resolved "https://registry.yarnpkg.com/@sinclair/typebox/-/typebox-0.27.8.tgz#6667fac16c436b5434a387a34dedb013198f6e6e"
|
||||
|
@ -3522,6 +3588,25 @@ normalize-path@^3.0.0, normalize-path@~3.0.0:
|
|||
resolved "https://registry.yarnpkg.com/normalize-path/-/normalize-path-3.0.0.tgz#0dcd69ff23a1c9b11fd0978316644a0388216a65"
|
||||
integrity sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==
|
||||
|
||||
nostr-tools@^2.7.1:
|
||||
version "2.7.1"
|
||||
resolved "https://registry.yarnpkg.com/nostr-tools/-/nostr-tools-2.7.1.tgz#cfedfe6c7ebf7f127f3ac32a5b57c7e570c35f67"
|
||||
integrity sha512-4qAvlHSqBAA8lQMwRWE6dalSNdQT77Xut9lPiJZgEcb9RAlR69wR2+KVBAgnZVaabVYH7FJ7gOQXLw/jQBAYBg==
|
||||
dependencies:
|
||||
"@noble/ciphers" "^0.5.1"
|
||||
"@noble/curves" "1.2.0"
|
||||
"@noble/hashes" "1.3.1"
|
||||
"@scure/base" "1.1.1"
|
||||
"@scure/bip32" "1.3.1"
|
||||
"@scure/bip39" "1.2.1"
|
||||
optionalDependencies:
|
||||
nostr-wasm v0.1.0
|
||||
|
||||
nostr-wasm@v0.1.0:
|
||||
version "0.1.0"
|
||||
resolved "https://registry.yarnpkg.com/nostr-wasm/-/nostr-wasm-0.1.0.tgz#17af486745feb2b7dd29503fdd81613a24058d94"
|
||||
integrity sha512-78BTryCLcLYv96ONU8Ws3Q1JzjlAt+43pWQhIl86xZmWeegYCNLPml7yQ+gG3vR6V5h4XGj+TxO+SS5dsThQIA==
|
||||
|
||||
nwsapi@^2.2.4:
|
||||
version "2.2.7"
|
||||
resolved "https://registry.yarnpkg.com/nwsapi/-/nwsapi-2.2.7.tgz#738e0707d3128cb750dddcfe90e4610482df0f30"
|
||||
|
|
Loading…
Reference in a new issue