aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-02-11 20:10:43 -0800
committerAdam Soltys <[email protected]>2026-02-11 20:10:43 -0800
commit56a04684c1fb77ea7b21afc6b0d2e1c4773906f6 (patch)
treed6bc2557c56b93177bb14aa376847c6e123a4862 /src/lib
parent13466248004327e9a026cb89f94926f9b060d1c1 (diff)
downloadcoinos-ui-56a04684c1fb77ea7b21afc6b0d2e1c4773906f6.tar.gz
coinos-ui-56a04684c1fb77ea7b21afc6b0d2e1c4773906f6.zip
format
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/ark.ts7
-rw-r--r--src/lib/bip21.ts11
-rw-r--r--src/lib/invoice.ts3
-rw-r--r--src/lib/nip07.ts21
-rw-r--r--src/lib/nip17.ts77
-rw-r--r--src/lib/nip44.ts48
-rw-r--r--src/lib/nip51.ts10
-rw-r--r--src/lib/nostr.ts14
-rw-r--r--src/lib/parse.ts18
-rw-r--r--src/lib/passwordCache.ts9
-rw-r--r--src/lib/random.ts7
-rw-r--r--src/lib/store.ts12
-rw-r--r--src/lib/utils.ts37
13 files changed, 61 insertions, 213 deletions
diff --git a/src/lib/ark.ts b/src/lib/ark.ts
index 51e378c3..61668c3a 100644
--- a/src/lib/ark.ts
+++ b/src/lib/ark.ts
@@ -95,14 +95,11 @@ export const syncTransactions = async (aid: string) => {
return post("/post/ark/sync", { transactions, aid });
};
-export const vtxoKey = (v: { txid: string; vout: number }) =>
- `${v.txid}:${v.vout}`;
+export const vtxoKey = (v: { txid: string; vout: number }) => `${v.txid}:${v.vout}`;
export const getProcessedVtxos = (): Set<string> => {
try {
- return new Set(
- JSON.parse(localStorage.getItem("processedArkVtxos") || "[]"),
- );
+ return new Set(JSON.parse(localStorage.getItem("processedArkVtxos") || "[]"));
} catch {
return new Set();
}
diff --git a/src/lib/bip21.ts b/src/lib/bip21.ts
index 842782a5..674fa714 100644
--- a/src/lib/bip21.ts
+++ b/src/lib/bip21.ts
@@ -12,10 +12,7 @@ export function decode(uri, allowedSchemes = ["bitcoin", "liquidnetwork"]) {
// Extract address and query string
const queryStart = uri.indexOf("?");
- const address = uri.slice(
- split + 1,
- queryStart === -1 ? undefined : queryStart,
- );
+ const address = uri.slice(split + 1, queryStart === -1 ? undefined : queryStart);
const query = queryStart === -1 ? "" : uri.slice(queryStart + 1);
const options = Object.fromEntries(new URLSearchParams(query));
@@ -28,11 +25,7 @@ export function decode(uri, allowedSchemes = ["bitcoin", "liquidnetwork"]) {
return { scheme: urnScheme, address, options };
}
-export function encode(
- address,
- options = { amount: "" },
- urnScheme = "bitcoin",
-) {
+export function encode(address, options = { amount: "" }, urnScheme = "bitcoin") {
if (!address || typeof address !== "string") {
throw new TypeError("Invalid address");
}
diff --git a/src/lib/invoice.ts b/src/lib/invoice.ts
index 015f2837..25741639 100644
--- a/src/lib/invoice.ts
+++ b/src/lib/invoice.ts
@@ -30,8 +30,7 @@ export default async ({ cookies, request }) => {
invoice = await post("/invoice", { invoice, user }, auth(cookies));
const { id } = invoice;
- if (invoice.prompt && invoice.tip === null)
- redirect(307, `/invoice/${id}/tip`);
+ if (invoice.prompt && invoice.tip === null) redirect(307, `/invoice/${id}/tip`);
if (invoice.memoPrompt && !invoice.memo) {
redirect(307, `/invoice/${id}/memo`);
diff --git a/src/lib/nip07.ts b/src/lib/nip07.ts
index 4b32512f..c26226d9 100644
--- a/src/lib/nip07.ts
+++ b/src/lib/nip07.ts
@@ -15,16 +15,9 @@ export const signEvent = async (event: any, user: any): Promise<any> => {
};
// Encrypts an event in NIP-44 using NIP-07 if available, otherwise getPrivateKey()
-export const encrypt = async (
- json: any,
- user: any,
- receiverPK: string,
-): Promise<string> => {
+export const encrypt = async (json: any, user: any, receiverPK: string): Promise<string> => {
if ((await (window as any).nostr.getPublicKey()) === user.pubkey) {
- return (window as any).nostr.nip44.encrypt(
- receiverPK,
- JSON.stringify(json),
- );
+ return (window as any).nostr.nip44.encrypt(receiverPK, JSON.stringify(json));
} else {
const senderSK = await getPrivateKey(user);
const senderSKString = bytesToHex(senderSK);
@@ -34,15 +27,9 @@ export const encrypt = async (
};
// Decrypts an event in NIP-44 using NIP-07 if available, otherwise getPrivateKey()
-export const decrypt = async (
- encrypted: string,
- user: any,
- receiverPK: string,
-): Promise<any> => {
+export const decrypt = async (encrypted: string, user: any, receiverPK: string): Promise<any> => {
if ((await (window as any).nostr.getPublicKey()) === user.pubkey) {
- return JSON.parse(
- await (window as any).nostr.nip44.decrypt(receiverPK, encrypted),
- );
+ return JSON.parse(await (window as any).nostr.nip44.decrypt(receiverPK, encrypted));
} else {
const senderSK = await getPrivateKey(user);
const senderSKString = bytesToHex(senderSK);
diff --git a/src/lib/nip17.ts b/src/lib/nip17.ts
index 32a18bd8..49312783 100644
--- a/src/lib/nip17.ts
+++ b/src/lib/nip17.ts
@@ -1,11 +1,6 @@
import { bytesToHex, hexToBytes } from "@noble/hashes/utils.js";
-import {
- finalizeEvent,
- getEventHash,
- generateSecretKey,
- getPublicKey,
-} from "nostr-tools/pure";
+import { finalizeEvent, getEventHash, generateSecretKey, getPublicKey } from "nostr-tools/pure";
import { SimplePool } from "nostr-tools/pool";
import { Relay } from "nostr-tools/relay";
import { unwrapEvent } from "nostr-tools/nip17";
@@ -17,8 +12,7 @@ import { eventToSign, signer } from "$lib/store";
import { get } from "svelte/store";
const TWO_DAYS = 2 * 24 * 60 * 60;
-const randomTimestamp = () =>
- Math.floor(Date.now() / 1000 - Math.random() * TWO_DAYS);
+const randomTimestamp = () => Math.floor(Date.now() / 1000 - Math.random() * TWO_DAYS);
const pool = new SimplePool();
let relayListCache = new Map();
@@ -43,11 +37,7 @@ const ensureSigner = async (userPubkey: string): Promise<Uint8Array | null> => {
// Check if signer already has a valid sk (64 hex chars = 32 bytes)
const currentSigner: any = get(signer);
- if (
- currentSigner?.ready &&
- currentSigner?.params?.sk &&
- currentSigner.params.sk.length === 64
- ) {
+ if (currentSigner?.ready && currentSigner?.params?.sk && currentSigner.params.sk.length === 64) {
return hexToBytes(currentSigner.params.sk);
}
@@ -112,12 +102,7 @@ export const createNIP17MessageSK = (
expiryDays: number | null = null,
) => {
const rumour = createRumour(text, getPublicKey(senderSK), receiverPK);
- const sealed = sealRumourSK(
- rumour,
- senderSK,
- wrapPK || receiverPK,
- expiryDays,
- );
+ const sealed = sealRumourSK(rumour, senderSK, wrapPK || receiverPK, expiryDays);
return giftWrap(sealed, wrapPK || receiverPK, expiryDays);
};
@@ -136,11 +121,7 @@ export const createNIP17MessageNIP07 = async (
expiryDays: number | null = null,
) => {
const rumour = createRumour(text, senderPK, receiverPK);
- const sealed = await sealRumourNip07(
- rumour,
- wrapPK || receiverPK,
- expiryDays,
- );
+ const sealed = await sealRumourNip07(rumour, wrapPK || receiverPK, expiryDays);
return giftWrap(sealed, wrapPK || receiverPK, expiryDays);
};
@@ -207,16 +188,9 @@ const sealRumourNip07 = async (
return (window as any).nostr.signEvent(sealEvent);
};
-const giftWrap = (
- event: any,
- receiverPK: string,
- expiryDays: number | null = null,
-) => {
+const giftWrap = (event: any, receiverPK: string, expiryDays: number | null = null) => {
const secretKey = generateSecretKey();
- const conversationKey = u.getConversationKey(
- bytesToHex(secretKey),
- receiverPK,
- );
+ const conversationKey = u.getConversationKey(bytesToHex(secretKey), receiverPK);
const encryptedEvent = encrypt(JSON.stringify(event), conversationKey);
const created = randomTimestamp();
@@ -236,15 +210,9 @@ const giftWrap = (
};
const decryptNIP17MessageNIP07 = async (wrapped: any): Promise<any> => {
- const sealedText = await (window as any).nostr.nip44.decrypt(
- wrapped.pubkey,
- wrapped.content,
- );
+ const sealedText = await (window as any).nostr.nip44.decrypt(wrapped.pubkey, wrapped.content);
const sealed = JSON.parse(sealedText);
- const rumourText = await (window as any).nostr.nip44.decrypt(
- sealed.pubkey,
- sealed.content,
- );
+ const rumourText = await (window as any).nostr.nip44.decrypt(sealed.pubkey, sealed.content);
return JSON.parse(rumourText);
};
@@ -373,9 +341,7 @@ const publishToPreferred = async (
throw new Error("No relays available to publish to");
}
- const promises = preferredRelays.map((url) =>
- publishWithAuth(url, event, currentSk),
- );
+ const promises = preferredRelays.map((url) => publishWithAuth(url, event, currentSk));
try {
return await (Promise as any).any(promises);
} catch (e) {
@@ -387,12 +353,7 @@ const publishToPreferred = async (
// Sends a NIP-17 message from `user` to `recipient`.
// If expiryDays is set, messages will expire after that many days.
-export const send = async (
- message: string,
- user: any,
- recipient: any,
- expiryDays?: number,
-) => {
+export const send = async (message: string, user: any, recipient: any, expiryDays?: number) => {
let event1, event2;
const sk = await ensureSigner(user.pubkey);
@@ -416,20 +377,8 @@ export const send = async (
expiryDays,
);
} else {
- event1 = createNIP17MessageSK(
- message,
- sk,
- recipient.pubkey,
- recipient.pubkey,
- expiryDays,
- );
- event2 = createNIP17MessageSK(
- message,
- sk,
- recipient.pubkey,
- user.pubkey,
- expiryDays,
- );
+ event1 = createNIP17MessageSK(message, sk, recipient.pubkey, recipient.pubkey, expiryDays);
+ event2 = createNIP17MessageSK(message, sk, recipient.pubkey, user.pubkey, expiryDays);
}
const p1 = publishToPreferred(event1, recipient.pubkey, expiryDays != null);
diff --git a/src/lib/nip44.ts b/src/lib/nip44.ts
index e05fc685..f1f872b5 100644
--- a/src/lib/nip44.ts
+++ b/src/lib/nip44.ts
@@ -5,10 +5,7 @@
import { chacha20 } from "@noble/ciphers/chacha.js";
import { equalBytes } from "@noble/ciphers/utils.js";
import { secp256k1 } from "@noble/curves/secp256k1.js";
-import {
- extract as hkdf_extract,
- expand as hkdf_expand,
-} from "@noble/hashes/hkdf.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";
@@ -27,9 +24,7 @@ export const u = {
},
getConversationKey(privkeyA: string, pubkeyB: string): Uint8Array {
- const sharedX = secp256k1
- .getSharedSecret(privkeyA, "02" + pubkeyB)
- .subarray(1, 33);
+ const sharedX = secp256k1.getSharedSecret(privkeyA, "02" + pubkeyB).subarray(1, 33);
return hkdf_extract(sha256, sharedX, "nip44-v2");
},
@@ -45,8 +40,7 @@ export const u = {
},
calcPaddedLen(len: number): number {
- if (!Number.isSafeInteger(len) || len < 1)
- throw new Error("expected positive integer");
+ if (!Number.isSafeInteger(len) || len < 1) throw new Error("expected positive integer");
if (len <= 32) return 32;
const nextPower = 1 << (Math.floor(Math.log2(len - 1)) + 1);
const chunk = nextPower <= 256 ? 32 : nextPower / 8;
@@ -54,14 +48,8 @@ export const u = {
},
writeU16BE(num: number) {
- if (
- !Number.isSafeInteger(num) ||
- num < u.minPlaintextSize ||
- num > u.maxPlaintextSize
- )
- throw new Error(
- "invalid plaintext size: must be between 1 and 65535 bytes",
- );
+ if (!Number.isSafeInteger(num) || num < u.minPlaintextSize || num > u.maxPlaintextSize)
+ throw new Error("invalid plaintext size: must be between 1 and 65535 bytes");
const arr = new Uint8Array(2);
new DataView(arr.buffer).setUint16(0, num, false);
return arr;
@@ -89,8 +77,7 @@ export const u = {
},
hmacAad(key: Uint8Array, message: Uint8Array, aad: Uint8Array) {
- if (aad.length !== 32)
- throw new Error("AAD associated data must be 32 bytes");
+ if (aad.length !== 32) throw new Error("AAD associated data must be 32 bytes");
const combined = concatBytes(aad, message);
return hmac(sha256, key, combined);
},
@@ -102,11 +89,9 @@ export const u = {
// raw payload: 99 (65+32+2) to 65603 (65+0xffff+2)
// compressed payload (base64): 132b to 87472b
decodePayload(payload: string) {
- if (typeof payload !== "string")
- throw new Error("payload must be a valid string");
+ if (typeof payload !== "string") throw new Error("payload must be a valid string");
const plen = payload.length;
- if (plen < 132 || plen > 87472)
- throw new Error("invalid payload length: " + plen);
+ if (plen < 132 || plen > 87472) throw new Error("invalid payload length: " + plen);
if (payload[0] === "#") throw new Error("unknown encryption version");
let data: Uint8Array;
try {
@@ -115,8 +100,7 @@ export const u = {
throw new Error("invalid base64: " + (error as any).message);
}
const dlen = data.length;
- if (dlen < 99 || dlen > 65603)
- throw new Error("invalid data length: " + dlen);
+ if (dlen < 99 || dlen > 65603) throw new Error("invalid data length: " + dlen);
const vers = data[0];
if (vers !== 2) throw new Error("unknown encryption version " + vers);
return {
@@ -132,24 +116,16 @@ export function encrypt(
conversationKey: Uint8Array,
nonce = randomBytes(32),
): string {
- const { chacha_key, chacha_nonce, hmac_key } = u.getMessageKeys(
- conversationKey,
- nonce,
- );
+ const { chacha_key, chacha_nonce, hmac_key } = u.getMessageKeys(conversationKey, nonce);
const padded = u.pad(plaintext);
const ciphertext = chacha20(chacha_key, chacha_nonce, padded);
const mac = u.hmacAad(hmac_key, ciphertext, nonce);
- return base64.encode(
- concatBytes(new Uint8Array([2]), nonce, ciphertext, mac),
- );
+ return base64.encode(concatBytes(new Uint8Array([2]), nonce, ciphertext, mac));
}
export function decrypt(payload: string, conversationKey: Uint8Array): string {
const { nonce, ciphertext, mac } = u.decodePayload(payload);
- const { chacha_key, chacha_nonce, hmac_key } = u.getMessageKeys(
- conversationKey,
- nonce,
- );
+ const { chacha_key, chacha_nonce, hmac_key } = u.getMessageKeys(conversationKey, nonce);
const calculatedMac = u.hmacAad(hmac_key, ciphertext, nonce);
if (!equalBytes(calculatedMac, mac)) throw new Error("invalid MAC");
const padded = chacha20(chacha_key, chacha_nonce, ciphertext);
diff --git a/src/lib/nip51.ts b/src/lib/nip51.ts
index 7560dd3d..05de1947 100644
--- a/src/lib/nip51.ts
+++ b/src/lib/nip51.ts
@@ -57,17 +57,11 @@ const getMuteLists = async (user: any): Promise<any> => {
return {
shown: listEvents[0].tags,
hidden:
- listEvents[0].content == ""
- ? []
- : await decrypt(listEvents[0].content, user, user.pubkey),
+ listEvents[0].content == "" ? [] : await decrypt(listEvents[0].content, user, user.pubkey),
};
};
-const publishMuteList = async (
- user: any,
- shown: string[],
- hidden: string[],
-) => {
+const publishMuteList = async (user: any, shown: string[], hidden: string[]) => {
const event = await signEvent(
{
kind: 10000,
diff --git a/src/lib/nostr.ts b/src/lib/nostr.ts
index 50df6408..2a8975ec 100644
--- a/src/lib/nostr.ts
+++ b/src/lib/nostr.ts
@@ -46,11 +46,7 @@ export const decrypt = async ({ event, user }: { event: any; user: any }) => {
if (pubkey === user.pubkey) pubkey = event.tags[0][1];
const { nip04 } = await loadNostrTools();
- const message = await nip04.decrypt(
- await getPrivateKey(user),
- pubkey,
- content,
- );
+ const message = await nip04.decrypt(await getPrivateKey(user), pubkey, content);
cache[id] = Buffer.from(message).toString("utf8");
decrypted.set(cache);
@@ -151,10 +147,7 @@ const getPassword = async (): Promise<string> => {
export const nostrConnectRelay = "wss://relay.nsec.app";
-const signingMethods: Record<
- string,
- (event: any, params: any) => Promise<any>
-> = {
+const signingMethods: Record<string, (event: any, params: any) => Promise<any>> = {
async connect(event: any, { sk, pk, pubkey }: any) {
const id = crypto.randomUUID();
const signEvent = {
@@ -191,8 +184,7 @@ const signingMethods: Record<
const { nip04 } = await loadNostrTools();
response = JSON.parse(await nip04.decrypt(sk, pk, event.content));
} catch {
- const { getConversationKey, decrypt: nip44decrypt } =
- await loadNip44();
+ const { getConversationKey, decrypt: nip44decrypt } = await loadNip44();
const ck = await getConversationKey(sk, pk);
response = JSON.parse(await nip44decrypt(event.content, ck));
}
diff --git a/src/lib/parse.ts b/src/lib/parse.ts
index 38c32a54..2af661a3 100644
--- a/src/lib/parse.ts
+++ b/src/lib/parse.ts
@@ -3,11 +3,8 @@ import { decode } from "$lib/bip21";
import { auth, get, isLiquid, post, sats } from "$lib/utils";
import { redirect } from "@sveltejs/kit";
-let validatePromise:
- | Promise<typeof import("bitcoin-address-validation")>
- | undefined;
-const loadValidate = () =>
- (validatePromise ||= import("bitcoin-address-validation"));
+let validatePromise: Promise<typeof import("bitcoin-address-validation")> | undefined;
+const loadValidate = () => (validatePromise ||= import("bitcoin-address-validation"));
export default async (s, host, cookies) => {
if (!s) return;
@@ -16,8 +13,7 @@ export default async (s, host, cookies) => {
let invoice;
let user;
- if (t.startsWith("ark") || t.startsWith("tark"))
- redirect(307, `/send/ark/${t}`);
+ if (t.startsWith("ark") || t.startsWith("tark")) redirect(307, `/send/ark/${t}`);
if (t.startsWith("http")) redirect(307, t);
if (t.startsWith(host)) redirect(307, `http://${t}`);
@@ -44,10 +40,7 @@ export default async (s, host, cookies) => {
if (["nprofile", "npub"].some((p) => t.startsWith(p))) redirect(307, `/${t}`);
// bitcoin
- if (
- t.toLowerCase().startsWith("bitcoin:") ||
- t.toLowerCase().startsWith("liquidnetwork:")
- ) {
+ if (t.toLowerCase().startsWith("bitcoin:") || t.toLowerCase().startsWith("liquidnetwork:")) {
({
address: t,
options: { amount },
@@ -62,8 +55,7 @@ export default async (s, host, cookies) => {
}
// lightning
- if (t.toLowerCase().startsWith("lightning:"))
- t = t.toLowerCase().replace("lightning:", "");
+ if (t.toLowerCase().startsWith("lightning:")) t = t.toLowerCase().replace("lightning:", "");
if (t.toLowerCase().startsWith("lnurl")) redirect(307, `/ln/${t}`);
if (t.includes(":")) t = t.split(":")[1];
diff --git a/src/lib/passwordCache.ts b/src/lib/passwordCache.ts
index a67113e3..5a2a4796 100644
--- a/src/lib/passwordCache.ts
+++ b/src/lib/passwordCache.ts
@@ -34,14 +34,9 @@ const loadStoredPassword = () => {
return password;
};
-export const walletPassword = writable<string | undefined>(
- loadStoredPassword(),
-);
+export const walletPassword = writable<string | undefined>(loadStoredPassword());
-export const rememberWalletPassword = (
- password: string,
- durationMs: number,
-) => {
+export const rememberWalletPassword = (password: string, durationMs: number) => {
if (!browser) return;
if (!durationMs) {
clearStoredPassword();
diff --git a/src/lib/random.ts b/src/lib/random.ts
index 605471ac..4c8dbda3 100644
--- a/src/lib/random.ts
+++ b/src/lib/random.ts
@@ -1,9 +1,4 @@
-import {
- NumberDictionary,
- animals,
- colors,
- uniqueNamesGenerator,
-} from "unique-names-generator";
+import { NumberDictionary, animals, colors, uniqueNamesGenerator } from "unique-names-generator";
export const randomName = () =>
uniqueNamesGenerator({
diff --git a/src/lib/store.ts b/src/lib/store.ts
index e14d107f..3d688535 100644
--- a/src/lib/store.ts
+++ b/src/lib/store.ts
@@ -3,9 +3,7 @@ import { writable } from "svelte/store";
export const persistSession = (key, defaultValue = undefined) => {
const s = writable(
- browser &&
- sessionStorage.getItem(key) &&
- sessionStorage.getItem(key) !== "undefined"
+ browser && sessionStorage.getItem(key) && sessionStorage.getItem(key) !== "undefined"
? JSON.parse(sessionStorage.getItem(key) || "")
: defaultValue,
);
@@ -19,9 +17,7 @@ export const persistSession = (key, defaultValue = undefined) => {
export const persistLocal = (key, defaultValue: any = undefined) => {
const s = writable(
- browser &&
- localStorage.getItem(key) &&
- localStorage.getItem(key) !== "undefined"
+ browser && localStorage.getItem(key) && localStorage.getItem(key) !== "undefined"
? JSON.parse(localStorage.getItem(key) || "")
: defaultValue,
);
@@ -46,9 +42,7 @@ export const persistLocal = (key, defaultValue: any = undefined) => {
export const persistLocalValue = (key, defaultValue: any = undefined) => {
const s = writable(
- browser &&
- localStorage.getItem(key) &&
- localStorage.getItem(key) !== "undefined"
+ browser && localStorage.getItem(key) && localStorage.getItem(key) !== "undefined"
? JSON.parse(localStorage.getItem(key) || "")
: defaultValue,
);
diff --git a/src/lib/utils.ts b/src/lib/utils.ts
index ebec6caa..c1514d6b 100644
--- a/src/lib/utils.ts
+++ b/src/lib/utils.ts
@@ -31,8 +31,7 @@ const ipHeaders = (): Record<string, string> => {
return ip ? { "cf-connecting-ip": ip } : {};
};
-export const punk = (k: string) =>
- `${Math.floor((parseInt(k.slice(-2), 16) / 256) * 64) + 1}.webp`;
+export const punk = (k: string) => `${Math.floor((parseInt(k.slice(-2), 16) / 256) * 64) + 1}.webp`;
export const g = (url: string, fetch: any, headers: object) =>
fetch(base + url, { headers: { ...ipHeaders(), ...headers } })
@@ -234,17 +233,14 @@ export const isInvalidTokenError = (e: unknown) => {
);
};
-export const btc = (fiat: number, rate: number): number =>
- Math.round((fiat * sats) / rate);
+export const btc = (fiat: number, rate: number): number => Math.round((fiat * sats) / rate);
-export const toFiat = (amount: number, rate: number): number =>
- (amount * rate) / sats;
+export const toFiat = (amount: number, rate: number): number => (amount * rate) / sats;
export const fd = async (req: Request): Promise<any> => {
const obj: Record<string, any> = Object.fromEntries(await req.formData());
for (const k in obj)
- (obj[k] === "undefined" && (obj[k] = undefined)) ||
- (obj[k] === "false" && (obj[k] = false));
+ (obj[k] === "undefined" && (obj[k] = undefined)) || (obj[k] === "false" && (obj[k] = false));
return obj;
};
@@ -338,8 +334,7 @@ export const f = (
const l = typeof locale === "function" ? locale() : locale || "en-US";
const cur = currency || "USD";
const region = l.length >= 2 ? l.slice(-2) : "";
- const currencyDisplay =
- region && cur.startsWith(region) ? "narrowSymbol" : "symbol";
+ const currencyDisplay = region && cur.startsWith(region) ? "narrowSymbol" : "symbol";
return new Intl.NumberFormat(l, {
style: "currency",
currency: cur,
@@ -356,11 +351,7 @@ export const s = (s: number, locale = "en-US"): string => {
export const sat = (s: number): string => `${si(Math.abs(s)).toString()}`;
-export const si = (
- n: number,
- minimumFractionDigits = 1,
- maximumFractionDigits = 2,
-) => {
+export const si = (n: number, minimumFractionDigits = 1, maximumFractionDigits = 2) => {
const units = ["", "K", "M", "G", "T", "P", "E", "Z"];
let s = n;
@@ -380,8 +371,7 @@ export const si = (
export const sats = 100000000;
-export const back = (): any =>
- browser && (history.length ? history.go(-1) : goto("/"));
+export const back = (): any => browser && (history.length ? history.go(-1) : goto("/"));
export const focus = (el: HTMLElement): any =>
browser && screen.width > 1280 && setTimeout(() => el.focus(), 1);
@@ -389,8 +379,7 @@ export const focus = (el: HTMLElement): any =>
export const select = (el: HTMLInputElement): any =>
browser && screen.width > 1280 && setTimeout(() => el.select(), 1);
-export const sleep = (n: number): Promise<void> =>
- new Promise((r) => setTimeout(r, n));
+export const sleep = (n: number): Promise<void> => new Promise((r) => setTimeout(r, n));
export const wait = async (
f: () => boolean | Promise<boolean>,
@@ -417,8 +406,7 @@ export const types = {
bolt12: "bolt12",
};
-export const ease = (t: number): number =>
- t < 0.5 ? 8 * t * t * t * t : 1 - 8 * --t * t * t * t;
+export const ease = (t: number): number => (t < 0.5 ? 8 * t * t * t * t : 1 - 8 * --t * t * t * t);
export function shuffleArray<T>(array: T[]): void {
for (let i = array.length - 1; i > 0; i--) {
@@ -428,9 +416,7 @@ export function shuffleArray<T>(array: T[]): void {
}
export const closest = (a: number[], n: number): number =>
- a.reduce((prev, curr) =>
- Math.abs(curr - n) < Math.abs(prev - n) ? curr : prev,
- );
+ a.reduce((prev, curr) => (Math.abs(curr - n) < Math.abs(prev - n) ? curr : prev));
export const isLiquid = (text: string): boolean =>
text.startsWith("Az") ||
@@ -439,8 +425,7 @@ export const isLiquid = (text: string): boolean =>
text.startsWith("VT") ||
text.startsWith("XR") ||
text.startsWith("XC") ||
- ((text.startsWith("H") || text.startsWith("G") || text.startsWith("Q")) &&
- text.length === 34) ||
+ ((text.startsWith("H") || text.startsWith("G") || text.startsWith("Q")) && text.length === 34) ||
(text.startsWith("ert1q") && text.length === 43) ||
(text.startsWith("ex1q") && text.length === 42) ||
text.startsWith("el1qq") ||