From 13f9ef7f26fff64c2bd54c8f9aa14e6ffac67121 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Wed, 11 Feb 2026 23:23:32 -0800 Subject: fix svelte errors --- src/lib/nip11.ts | 2 +- src/lib/nip40.ts | 4 ++-- src/lib/nip44.ts | 6 +++--- src/lib/nostr.ts | 11 +++++------ src/lib/parse.ts | 6 +++--- src/lib/store.ts | 4 ++-- src/lib/utils.ts | 4 ++-- 7 files changed, 18 insertions(+), 19 deletions(-) (limited to 'src/lib') diff --git a/src/lib/nip11.ts b/src/lib/nip11.ts index 6e827ccb..7c5b335a 100644 --- a/src/lib/nip11.ts +++ b/src/lib/nip11.ts @@ -2,7 +2,7 @@ import { fetchRelayInformation } from "nostr-tools/nip11"; // Accepts a list of relays, and returns a list of the relays that support all the provided NIPs. export const relaysSupporting = async (relays: string[], nips: number[]) => { - let supportingRelays = []; + let supportingRelays: string[] = []; for (const relay of relays) { const relayInfo = await fetchRelayInformation(relay); diff --git a/src/lib/nip40.ts b/src/lib/nip40.ts index 760a6680..e384b565 100644 --- a/src/lib/nip40.ts +++ b/src/lib/nip40.ts @@ -1,12 +1,12 @@ // Returns true if the message has an expiration in the past, false otherwise. -export const expired = (event: object): boolean => { +export const expired = (event: { tags: string[][] }): boolean => { const expiryTime = expiration(event); return expiryTime !== null && Date.now() / 1000 >= expiryTime; }; // Returns the provided event's expiration time, as a Unix ms integer. // If it has none, returns null. -export const expiration = (event: object): number | null => { +export const expiration = (event: { tags: string[][] }): number | null => { for (const tag of event.tags) { if (tag[0] == "expiration") { return parseInt(tag[1]); diff --git a/src/lib/nip44.ts b/src/lib/nip44.ts index f1f872b5..6025a54f 100644 --- a/src/lib/nip44.ts +++ b/src/lib/nip44.ts @@ -8,7 +8,7 @@ import { secp256k1 } from "@noble/curves/secp256k1.js"; import { extract as hkdf_extract, expand as hkdf_expand } from "@noble/hashes/hkdf.js"; import { hmac } from "@noble/hashes/hmac.js"; import { sha256 } from "@noble/hashes/sha2.js"; -import { concatBytes, randomBytes, utf8ToBytes } from "@noble/hashes/utils.js"; +import { concatBytes, hexToBytes, randomBytes, utf8ToBytes } from "@noble/hashes/utils.js"; import { base64 } from "@scure/base"; declare const TextDecoder: any; @@ -24,8 +24,8 @@ export const u = { }, getConversationKey(privkeyA: string, pubkeyB: string): Uint8Array { - const sharedX = secp256k1.getSharedSecret(privkeyA, "02" + pubkeyB).subarray(1, 33); - return hkdf_extract(sha256, sharedX, "nip44-v2"); + const sharedX = secp256k1.getSharedSecret(hexToBytes(privkeyA), hexToBytes("02" + pubkeyB)).subarray(1, 33); + return hkdf_extract(sha256, sharedX, utf8ToBytes("nip44-v2")); }, getMessageKeys(conversationKey: Uint8Array, nonce: Uint8Array) { diff --git a/src/lib/nostr.ts b/src/lib/nostr.ts index 2a8975ec..d2e95a6d 100644 --- a/src/lib/nostr.ts +++ b/src/lib/nostr.ts @@ -63,7 +63,7 @@ export const getPrivateKey = async (user: User): Promise => { k = localStorage.getItem("nsec"); if (k) { const { nip19 } = await loadNostrTools(); - return nip19.decode(k).data as Uint8Array; + return nip19.decode(k).data as unknown as Uint8Array; } } @@ -118,8 +118,8 @@ export const sign = async (event: any, user?: any) => { } eventToSign.set(event); - let unsubscribe; - const { method, params } = await new Promise((r, j) => { + let unsubscribe: (() => void) | undefined; + const { method, params } = await new Promise<{ method: string; params: any }>((r, j) => { unsubscribe = $signer.subscribe((v) => { if (v === "cancel") { j("cancelled"); @@ -128,7 +128,7 @@ export const sign = async (event: any, user?: any) => { v?.ready && r(v); }); }); - await unsubscribe(); + await unsubscribe?.(); const signedEvent = await signingMethods[method](event, params); eventToSign.set(signedEvent); setTimeout(() => eventToSign.set(null), 1000); @@ -163,10 +163,9 @@ const signingMethods: Record Promise> { created_at: Math.round(Date.now() / 1000), kind: 24133, - pubkey, content, tags: [["p", pk]], - }, + } as EventTemplate, sk, ); diff --git a/src/lib/parse.ts b/src/lib/parse.ts index 2af661a3..48541728 100644 --- a/src/lib/parse.ts +++ b/src/lib/parse.ts @@ -80,10 +80,10 @@ export default async (s, host, cookies) => { if (invoice) redirect(307, `/invoice/${invoice.id}`); if (t.match(/^🥜([\uFE00-\uFE0F]|[\uE0100-\uE01EF]+)$/)) { - t = Array.from(t) + t = (Array.from(t) as string[]) .slice(1) - .map((char) => { - const codePoint = char.codePointAt(0); + .map((char: string) => { + const codePoint = char.codePointAt(0)!; // Handle Variation Selectors (VS1-VS16): U+FE00 to U+FE0F if (codePoint >= 0xfe00 && codePoint <= 0xfe0f) { diff --git a/src/lib/store.ts b/src/lib/store.ts index 3d688535..7499e148 100644 --- a/src/lib/store.ts +++ b/src/lib/store.ts @@ -1,5 +1,5 @@ import { browser } from "$app/environment"; -import { writable } from "svelte/store"; +import { writable, type Writable } from "svelte/store"; export const persistSession = (key, defaultValue = undefined) => { const s = writable( @@ -72,7 +72,7 @@ export const banner = writable(); export const event = writable(); export const events = writable({}); export const fiat = persistLocalValue("fiat", true); -export const installPrompt = writable(); +export const installPrompt: Writable = writable(); export const invoice = writable(); export const last = writable(); export const loginRedirect = writable(); diff --git a/src/lib/utils.ts b/src/lib/utils.ts index c1514d6b..a96db03d 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -331,7 +331,7 @@ export const f = ( minimumFractionDigits = 2, maximumFractionDigits = 2, ) => { - const l = typeof locale === "function" ? locale() : locale || "en-US"; + const l = typeof locale === "function" ? (locale as () => string)() : locale || "en-US"; const cur = currency || "USD"; const region = l.length >= 2 ? l.slice(-2) : ""; const currencyDisplay = region && cur.startsWith(region) ? "narrowSymbol" : "symbol"; @@ -345,7 +345,7 @@ export const f = ( }; export const s = (s: number, locale = "en-US"): string => { - const l = typeof locale === "function" ? locale() : locale || "en-US"; + const l = typeof locale === "function" ? (locale as () => string)() : locale || "en-US"; return new Intl.NumberFormat(l, { maximumFractionDigits: 0 }).format(s); }; -- cgit v1.2.3