applesauce-core 0.0.0-next-20241119173145 → 0.0.0-next-20241122170522

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,5 +13,6 @@ export * from "./lru.js";
13
13
  export * from "./hashtag.js";
14
14
  export * from "./url.js";
15
15
  export * from "./zap.js";
16
- export * from "./bolt11.js";
17
16
  export * from "./hidden-tags.js";
17
+ export * from "./bolt11.js";
18
+ export * from "./lnurl.js";
@@ -13,5 +13,6 @@ export * from "./lru.js";
13
13
  export * from "./hashtag.js";
14
14
  export * from "./url.js";
15
15
  export * from "./zap.js";
16
- export * from "./bolt11.js";
17
16
  export * from "./hidden-tags.js";
17
+ export * from "./bolt11.js";
18
+ export * from "./lnurl.js";
@@ -0,0 +1,4 @@
1
+ export declare function parseLightningAddress(address: string): URL | undefined;
2
+ export declare function decodeLNURL(lnurl: string): URL | undefined;
3
+ export declare function parseLNURLOrAddress(addressOrLNURL: string): URL | undefined;
4
+ export declare function getInvoice(callback: URL): Promise<string>;
@@ -0,0 +1,40 @@
1
+ import { bech32 } from "@scure/base";
2
+ import { parseBolt11 } from "./bolt11.js";
3
+ const decoder = new TextDecoder();
4
+ export function parseLightningAddress(address) {
5
+ let [name, domain] = address.split("@");
6
+ if (!name || !domain)
7
+ return;
8
+ return new URL(`https://${domain}/.well-known/lnurlp/${name}`);
9
+ }
10
+ export function decodeLNURL(lnurl) {
11
+ try {
12
+ const { words, prefix } = bech32.decode(lnurl);
13
+ if (prefix !== "lnurl")
14
+ return;
15
+ const str = decoder.decode(bech32.fromWords(words));
16
+ return new URL(str);
17
+ }
18
+ catch (error) { }
19
+ return undefined;
20
+ }
21
+ export function parseLNURLOrAddress(addressOrLNURL) {
22
+ if (addressOrLNURL.includes("@")) {
23
+ return parseLightningAddress(addressOrLNURL);
24
+ }
25
+ return decodeLNURL(addressOrLNURL);
26
+ }
27
+ export async function getInvoice(callback) {
28
+ const { pr: payRequest } = await fetch(callback).then((res) => res.json());
29
+ const amount = callback.searchParams.get("amount");
30
+ if (!amount)
31
+ throw new Error("Missing amount");
32
+ if (payRequest) {
33
+ const parsed = parseBolt11(payRequest);
34
+ if (parsed.amount !== parseInt(amount))
35
+ throw new Error("Incorrect amount");
36
+ return payRequest;
37
+ }
38
+ else
39
+ throw new Error("Failed to get invoice");
40
+ }
@@ -9,7 +9,7 @@ export function getProfileContent(event) {
9
9
  if (profile.nip05 && typeof profile.nip05 !== "string")
10
10
  profile.nip05 = String(profile.nip05);
11
11
  // add missing protocol to website
12
- if (profile.website?.startsWith("http") === false) {
12
+ if (profile.website && profile.website?.length > 0 && profile.website?.startsWith("http") === false) {
13
13
  profile.website = "https://" + profile.website;
14
14
  }
15
15
  return profile;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "applesauce-core",
3
- "version": "0.0.0-next-20241119173145",
3
+ "version": "0.0.0-next-20241122170522",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -52,11 +52,12 @@
52
52
  }
53
53
  },
54
54
  "dependencies": {
55
+ "@scure/base": "^1.1.9",
55
56
  "debug": "^4.3.7",
56
57
  "json-stringify-deterministic": "^1.0.12",
57
58
  "light-bolt11-decoder": "^3.2.0",
58
59
  "nanoid": "^5.0.7",
59
- "nostr-tools": "^2.10.1",
60
+ "nostr-tools": "^2.10.3",
60
61
  "rxjs": "^7.8.1"
61
62
  },
62
63
  "devDependencies": {