applesauce-core 0.0.0-next-20241119160247 → 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.
package/dist/helpers/event.d.ts
CHANGED
|
@@ -24,7 +24,10 @@ export declare function getEventUID(event: NostrEvent): string;
|
|
|
24
24
|
export declare function getReplaceableUID(kind: number, pubkey: string, d?: string): string;
|
|
25
25
|
/** Returns a Set of tag names and values that are indexable */
|
|
26
26
|
export declare function getIndexableTags(event: NostrEvent): Set<string>;
|
|
27
|
-
/**
|
|
27
|
+
/**
|
|
28
|
+
* Returns the second index ( tag[1] ) of the first tag that matches the name
|
|
29
|
+
* If the event has any hidden tags they will be searched first
|
|
30
|
+
*/
|
|
28
31
|
export declare function getTagValue(event: NostrEvent, name: string): string | undefined;
|
|
29
32
|
/** Sets events verified flag without checking anything */
|
|
30
33
|
export declare function fakeVerifyEvent(event: NostrEvent): event is VerifiedEvent;
|
package/dist/helpers/event.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { kinds, verifiedSymbol } from "nostr-tools";
|
|
2
2
|
import { INDEXABLE_TAGS } from "../event-store/common.js";
|
|
3
|
+
import { getHiddenTags } from "./hidden-tags.js";
|
|
3
4
|
export const EventUIDSymbol = Symbol.for("event-uid");
|
|
4
5
|
export const EventIndexableTagsSymbol = Symbol.for("indexable-tags");
|
|
5
6
|
export const FromCacheSymbol = Symbol.for("from-cache");
|
|
@@ -46,8 +47,15 @@ export function getIndexableTags(event) {
|
|
|
46
47
|
}
|
|
47
48
|
return indexable;
|
|
48
49
|
}
|
|
49
|
-
/**
|
|
50
|
+
/**
|
|
51
|
+
* Returns the second index ( tag[1] ) of the first tag that matches the name
|
|
52
|
+
* If the event has any hidden tags they will be searched first
|
|
53
|
+
*/
|
|
50
54
|
export function getTagValue(event, name) {
|
|
55
|
+
const hidden = getHiddenTags(event);
|
|
56
|
+
const hiddenValue = hidden?.find((t) => t[0] === name)?.[1];
|
|
57
|
+
if (hiddenValue)
|
|
58
|
+
return hiddenValue;
|
|
51
59
|
return event.tags.find((t) => t[0] === name)?.[1];
|
|
52
60
|
}
|
|
53
61
|
/** Sets events verified flag without checking anything */
|
package/dist/helpers/index.d.ts
CHANGED
package/dist/helpers/index.js
CHANGED
|
@@ -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
|
+
}
|
package/dist/helpers/profile.js
CHANGED
|
@@ -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-
|
|
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.
|
|
60
|
+
"nostr-tools": "^2.10.3",
|
|
60
61
|
"rxjs": "^7.8.1"
|
|
61
62
|
},
|
|
62
63
|
"devDependencies": {
|