@welshman/net 0.9.0-pre1 → 0.9.0-pre2
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/lib/src/Tools.d.ts +9 -0
- package/dist/lib/src/Tools.d.ts.map +1 -1
- package/dist/lib/src/Tools.js +26 -1
- package/dist/lib/src/Tools.js.map +1 -1
- package/dist/net/src/context.d.ts +1 -1
- package/dist/net/src/context.d.ts.map +1 -1
- package/dist/net/src/message.d.ts +1 -1
- package/dist/net/src/message.d.ts.map +1 -1
- package/dist/net/src/message.js +1 -1
- package/dist/net/src/message.js.map +1 -1
- package/dist/net/src/repository.d.ts +3 -0
- package/dist/net/src/repository.d.ts.map +1 -1
- package/dist/net/src/repository.js +49 -12
- package/dist/net/src/repository.js.map +1 -1
- package/dist/net/src/request.d.ts +2 -1
- package/dist/net/src/request.d.ts.map +1 -1
- package/dist/net/src/request.js.map +1 -1
- package/dist/util/src/Events.d.ts +0 -12
- package/dist/util/src/Events.d.ts.map +1 -1
- package/dist/util/src/Events.js +3 -25
- package/dist/util/src/Events.js.map +1 -1
- package/dist/util/src/Kinds.d.ts +3 -1
- package/dist/util/src/Kinds.d.ts.map +1 -1
- package/dist/util/src/Kinds.js +5 -2
- package/dist/util/src/Kinds.js.map +1 -1
- package/dist/util/src/Lightning.d.ts +6 -0
- package/dist/util/src/Lightning.d.ts.map +1 -0
- package/dist/util/src/Lightning.js +59 -0
- package/dist/util/src/Lightning.js.map +1 -0
- package/dist/util/src/Nip86.d.ts +74 -30
- package/dist/util/src/Nip86.d.ts.map +1 -1
- package/dist/util/src/Nip86.js +169 -30
- package/dist/util/src/Nip86.js.map +1 -1
- package/dist/util/src/Pow.js +2 -2
- package/dist/util/src/Pow.js.map +1 -1
- package/dist/util/src/Pubkey.d.ts.map +1 -1
- package/dist/util/src/Pubkey.js +2 -1
- package/dist/util/src/Pubkey.js.map +1 -1
- package/dist/util/src/Relay.d.ts +0 -29
- package/dist/util/src/Relay.d.ts.map +1 -1
- package/dist/util/src/Relay.js +0 -10
- package/dist/util/src/Relay.js.map +1 -1
- package/dist/util/src/RelaySelection.d.ts +101 -0
- package/dist/util/src/RelaySelection.d.ts.map +1 -0
- package/dist/util/src/RelaySelection.js +98 -0
- package/dist/util/src/RelaySelection.js.map +1 -0
- package/dist/util/src/Tags.d.ts +16 -35
- package/dist/util/src/Tags.d.ts.map +1 -1
- package/dist/util/src/Tags.js +23 -74
- package/dist/util/src/Tags.js.map +1 -1
- package/dist/util/src/Topics.d.ts +2 -0
- package/dist/util/src/Topics.d.ts.map +1 -0
- package/dist/util/src/Topics.js +2 -0
- package/dist/util/src/Topics.js.map +1 -0
- package/dist/util/src/index.d.ts +2 -1
- package/dist/util/src/index.d.ts.map +1 -1
- package/dist/util/src/index.js +2 -1
- package/dist/util/src/index.js.map +1 -1
- package/package.json +5 -5
- package/dist/util/src/Zaps.d.ts +0 -86
- package/dist/util/src/Zaps.d.ts.map +0 -1
- package/dist/util/src/Zaps.js +0 -184
- package/dist/util/src/Zaps.js.map +0 -1
package/dist/util/src/Tags.d.ts
CHANGED
|
@@ -1,37 +1,18 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export declare const getEventTags: (tags: string[][]) => string[][];
|
|
6
|
-
export declare const getEventTagValues: (tags: string[][]) => string[];
|
|
7
|
-
export declare const getAddressTags: (tags: string[][]) => string[][];
|
|
8
|
-
export declare const getAddressTagValues: (tags: string[][]) => string[];
|
|
9
|
-
export declare const getPubkeyTags: (tags: string[][]) => string[][];
|
|
10
|
-
export declare const getPubkeyTagValues: (tags: string[][]) => string[];
|
|
11
|
-
export declare const getTopicTags: (tags: string[][]) => string[][];
|
|
12
|
-
export declare const getTopicTagValues: (tags: string[][]) => string[];
|
|
13
|
-
export declare const getRelayTags: (tags: string[][]) => string[][];
|
|
14
|
-
export declare const getRelayTagValues: (tags: string[][]) => string[];
|
|
15
|
-
export declare const getGroupTags: (tags: string[][]) => string[][];
|
|
16
|
-
export declare const getGroupTagValues: (tags: string[][]) => string[];
|
|
17
|
-
export declare const getKindTags: (tags: string[][]) => string[][];
|
|
18
|
-
export declare const getKindTagValues: (tags: string[][]) => number[];
|
|
19
|
-
export declare const getCommentTags: (tags: string[][]) => {
|
|
20
|
-
roots: string[][];
|
|
21
|
-
replies: string[][];
|
|
1
|
+
export type TagSpec<T = string> = {
|
|
2
|
+
keys: string[];
|
|
3
|
+
matchValue?: (value: string) => boolean;
|
|
4
|
+
normalizeValue?: (value: string) => T;
|
|
22
5
|
};
|
|
23
|
-
export declare const
|
|
24
|
-
export declare const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
export declare const
|
|
30
|
-
export declare const
|
|
31
|
-
export declare const
|
|
32
|
-
export declare const
|
|
33
|
-
export declare const
|
|
34
|
-
export declare const
|
|
35
|
-
export declare const tagsFromIMeta: (imeta: string[]) => string[][];
|
|
36
|
-
export declare const tagger: (name: string) => (value: string, ...args: unknown[]) => string[];
|
|
6
|
+
export declare const tagSpec: <T = string>(keys: string | string[], matchValue?: (value: string) => boolean, normalizeValue?: (value: string) => T) => TagSpec<T>;
|
|
7
|
+
export declare const hexTags: (keys: string | string[]) => TagSpec<string>;
|
|
8
|
+
export declare const kindTags: (keys: string | string[]) => TagSpec<number | undefined>;
|
|
9
|
+
export declare const topicTags: (keys: string | string[]) => TagSpec<string>;
|
|
10
|
+
export declare const addressTags: (keys: string | string[]) => TagSpec<string>;
|
|
11
|
+
export declare const relayTags: (keys: string | string[]) => TagSpec<string>;
|
|
12
|
+
export declare const tagMatcher: (spec: TagSpec<any>) => (tag: string[]) => boolean;
|
|
13
|
+
export declare const matchTags: <T>(spec: TagSpec<T>, tags: string[][]) => string[][];
|
|
14
|
+
export declare const matchTag: <T>(spec: TagSpec<T>, tags: string[][]) => string[] | undefined;
|
|
15
|
+
export declare const tagValueExtractor: <T>(spec: TagSpec<T>) => (tag: string[]) => T;
|
|
16
|
+
export declare const tagValues: <T>(spec: TagSpec<T>, tags: string[][]) => NonNullable<T>[];
|
|
17
|
+
export declare const tagValue: <T>(spec: TagSpec<T>, tags: string[][]) => T | undefined;
|
|
37
18
|
//# sourceMappingURL=Tags.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tags.d.ts","sourceRoot":"","sources":["../../../../util/src/Tags.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Tags.d.ts","sourceRoot":"","sources":["../../../../util/src/Tags.ts"],"names":[],"mappings":"AAMA,MAAM,MAAM,OAAO,CAAC,CAAC,GAAG,MAAM,IAAI;IAChC,IAAI,EAAE,MAAM,EAAE,CAAA;IACd,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAA;IACvC,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,CAAC,CAAA;CACtC,CAAA;AAGD,eAAO,MAAM,OAAO,GAAI,CAAC,GAAC,MAAM,EAC9B,MAAM,MAAM,GAAG,MAAM,EAAE,EACvB,aAAa,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,EACvC,iBAAiB,CAAC,KAAK,EAAE,MAAM,KAAK,CAAC,KACpC,OAAO,CAAC,CAAC,CAA6D,CAAA;AAEzE,eAAO,MAAM,OAAO,GAAI,MAAM,MAAM,GAAG,MAAM,EAAE,oBAA2B,CAAA;AAE1E,eAAO,MAAM,QAAQ,GAAI,MAAM,MAAM,GAAG,MAAM,EAAE,gCAAyC,CAAA;AAEzF,eAAO,MAAM,SAAS,GAAI,MAAM,MAAM,GAAG,MAAM,EAAE,oBAA6C,CAAA;AAE9F,eAAO,MAAM,WAAW,GAAI,MAAM,MAAM,GAAG,MAAM,EAAE,oBACD,CAAA;AAElD,eAAO,MAAM,SAAS,GAAI,MAAM,MAAM,GAAG,MAAM,EAAE,oBAA8B,CAAA;AAE/E,eAAO,MAAM,UAAU,GAAI,MAAM,OAAO,CAAC,GAAG,CAAC,MAAM,KAAK,MAAM,EAAE,YAK/D,CAAA;AAED,eAAO,MAAM,SAAS,GAAI,CAAC,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAAE,MAAM,MAAM,EAAE,EAAE,eAAkC,CAAA;AAEjG,eAAO,MAAM,QAAQ,GAAI,CAAC,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAAE,MAAM,MAAM,EAAE,EAAE,yBAAgC,CAAA;AAE9F,eAAO,MAAM,iBAAiB,GAC3B,CAAC,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,MACnB,KAAK,MAAM,EAAE,KAAG,CACkD,CAAA;AAErE,eAAO,MAAM,SAAS,GAAI,CAAC,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAAE,MAAM,MAAM,EAAE,EAAE,KAAG,WAAW,CAAC,CAAC,CAAC,EACX,CAAA;AAErE,eAAO,MAAM,QAAQ,GAAI,CAAC,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAAE,MAAM,MAAM,EAAE,EAAE,KAAG,CAAC,GAAG,SAIpE,CAAA"}
|
package/dist/util/src/Tags.js
CHANGED
|
@@ -1,79 +1,28 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ensurePlural, isHex32, removeUndefined } from "@welshman/lib";
|
|
2
2
|
import { isRelayUrl } from "./Relay.js";
|
|
3
3
|
import { Address } from "./Address.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
import { isKind, normalizeKind } from "./Kinds.js";
|
|
5
|
+
import { normalizeTopic } from "./Topics.js";
|
|
6
|
+
// prettier-ignore
|
|
7
|
+
export const tagSpec = (keys, matchValue, normalizeValue) => ({ keys: ensurePlural(keys), matchValue, normalizeValue });
|
|
8
|
+
export const hexTags = (keys) => tagSpec(keys, isHex32);
|
|
9
|
+
export const kindTags = (keys) => tagSpec(keys, isKind, normalizeKind);
|
|
10
|
+
export const topicTags = (keys) => tagSpec(keys, undefined, normalizeTopic);
|
|
11
|
+
export const addressTags = (keys) => tagSpec(keys, value => Address.isAddress(value));
|
|
12
|
+
export const relayTags = (keys) => tagSpec(keys, isRelayUrl);
|
|
13
|
+
export const tagMatcher = (spec) => (tag) => {
|
|
14
|
+
if (!spec.keys.includes(tag[0]))
|
|
15
|
+
return false;
|
|
16
|
+
if (spec.matchValue && (!tag[1] || !spec.matchValue(tag[1])))
|
|
17
|
+
return false;
|
|
18
|
+
return true;
|
|
7
19
|
};
|
|
8
|
-
export const
|
|
9
|
-
|
|
10
|
-
|
|
20
|
+
export const matchTags = (spec, tags) => tags.filter(tagMatcher(spec));
|
|
21
|
+
export const matchTag = (spec, tags) => tags.find(tagMatcher(spec));
|
|
22
|
+
export const tagValueExtractor = (spec) => (tag) => (spec.normalizeValue ? spec.normalizeValue(tag[1]) : tag[1]);
|
|
23
|
+
export const tagValues = (spec, tags) => removeUndefined(matchTags(spec, tags).map(tagValueExtractor(spec)));
|
|
24
|
+
export const tagValue = (spec, tags) => {
|
|
25
|
+
const tag = matchTag(spec, tags);
|
|
26
|
+
return tag ? tagValueExtractor(spec)(tag) : undefined;
|
|
11
27
|
};
|
|
12
|
-
export const getTagValues = (types, tags) => getTags(types, tags).map(nth(1));
|
|
13
|
-
export const getTagValue = (types, tags) => getTag(types, tags)?.[1];
|
|
14
|
-
export const getEventTags = (tags) => tags.filter(t => ["e"].includes(t[0]) && t[1].length === 64);
|
|
15
|
-
export const getEventTagValues = (tags) => getEventTags(tags).map(nth(1));
|
|
16
|
-
export const getAddressTags = (tags) => tags.filter(t => ["a"].includes(t[0]) && Address.isAddress(t[1]));
|
|
17
|
-
export const getAddressTagValues = (tags) => getAddressTags(tags).map(nth(1));
|
|
18
|
-
export const getPubkeyTags = (tags) => tags.filter(t => ["p"].includes(t[0]) && t[1].length === 64);
|
|
19
|
-
export const getPubkeyTagValues = (tags) => getPubkeyTags(tags).map(nth(1));
|
|
20
|
-
export const getTopicTags = (tags) => tags.filter(nthEq(0, "t"));
|
|
21
|
-
export const getTopicTagValues = (tags) => getTopicTags(tags).map(t => t[1].replace(/^#/, ""));
|
|
22
|
-
export const getRelayTags = (tags) => tags.filter(t => ["r", "relay"].includes(t[0]) && isRelayUrl(t[1] || ""));
|
|
23
|
-
export const getRelayTagValues = (tags) => getRelayTags(tags).map(nth(1));
|
|
24
|
-
export const getGroupTags = (tags) => tags.filter(t => ["h", "group"].includes(t[0]) && t[1] && isRelayUrl(t[2] || ""));
|
|
25
|
-
export const getGroupTagValues = (tags) => getGroupTags(tags).map(nth(1));
|
|
26
|
-
export const getKindTags = (tags) => tags.filter(t => ["k"].includes(t[0]) && t[1].match(/^\d+$/));
|
|
27
|
-
export const getKindTagValues = (tags) => getKindTags(tags).map(t => parseInt(t[1]));
|
|
28
|
-
export const getCommentTags = (tags) => {
|
|
29
|
-
const roots = tags.filter(t => ["A", "E", "P", "K"].includes(t[0]));
|
|
30
|
-
const replies = tags.filter(t => ["a", "e", "p", "k"].includes(t[0]));
|
|
31
|
-
return { roots, replies };
|
|
32
|
-
};
|
|
33
|
-
export const getCommentTagValues = (tags) => mapVals(tags => tags.filter(t => ["a", "e"].includes(t[0].toLowerCase())).map(nth(1)), getCommentTags(tags));
|
|
34
|
-
export const getReplyTags = (tags) => {
|
|
35
|
-
const validTags = tags.filter(t => ["a", "e", "q"].includes(t[0]));
|
|
36
|
-
const mentionTags = validTags.filter(nthEq(0, "q"));
|
|
37
|
-
const roots = [];
|
|
38
|
-
const replies = [];
|
|
39
|
-
const mentions = [];
|
|
40
|
-
const dispatchTags = (thisTags) => thisTags.forEach((t, i) => {
|
|
41
|
-
if (t[3] === "root") {
|
|
42
|
-
if (validTags.filter(nthEq(3, "reply")).length === 0) {
|
|
43
|
-
replies.push(t);
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
roots.push(t);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
else if (t[3] === "reply") {
|
|
50
|
-
replies.push(t);
|
|
51
|
-
}
|
|
52
|
-
else if (t[3] === "mention") {
|
|
53
|
-
mentions.push(t);
|
|
54
|
-
}
|
|
55
|
-
else if (i === thisTags.length - 1) {
|
|
56
|
-
replies.push(t);
|
|
57
|
-
}
|
|
58
|
-
else if (i === 0) {
|
|
59
|
-
roots.push(t);
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
mentions.push(t);
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
// Add different types separately so positional logic works
|
|
66
|
-
dispatchTags(validTags.filter(nthEq(0, "e")));
|
|
67
|
-
dispatchTags(validTags.filter(nthEq(0, "a")).filter(t => Boolean(t[3])));
|
|
68
|
-
mentionTags.forEach((t) => mentions.push(t));
|
|
69
|
-
return { roots, replies, mentions };
|
|
70
|
-
};
|
|
71
|
-
export const getReplyTagValues = (tags) => mapVals(tags => tags.map(nth(1)), getReplyTags(tags));
|
|
72
|
-
export const getEmojiTags = (name, tags) => tags.filter(spec(["emoji", name]));
|
|
73
|
-
export const getEmojiTag = (name, tags) => first(getEmojiTags(name, tags));
|
|
74
|
-
export const getEmojiTagUrls = (name, tags) => getEmojiTags(name, tags).map(nth(2));
|
|
75
|
-
export const getEmojiTagUrl = (name, tags) => first(getEmojiTagUrls(name, tags));
|
|
76
|
-
export const uniqTags = (tags) => uniqBy(t => t.slice(0, 2).join(":"), tags);
|
|
77
|
-
export const tagsFromIMeta = (imeta) => imeta.map((m) => m.split(" "));
|
|
78
|
-
export const tagger = (name) => (value, ...args) => [name, value];
|
|
79
28
|
//# sourceMappingURL=Tags.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tags.js","sourceRoot":"","sources":["../../../../util/src/Tags.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"Tags.js","sourceRoot":"","sources":["../../../../util/src/Tags.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAE,OAAO,EAAE,eAAe,EAAC,MAAM,eAAe,CAAA;AACpE,OAAO,E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
|
|
|
1
|
+
{"version":3,"file":"Topics.d.ts","sourceRoot":"","sources":["../../../../util/src/Topics.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,GAAI,GAAG,MAAM,WAAwB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Topics.js","sourceRoot":"","sources":["../../../../util/src/Topics.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAA"}
|
package/dist/util/src/index.d.ts
CHANGED
|
@@ -12,7 +12,8 @@ export * from "./Nip98.js";
|
|
|
12
12
|
export * from "./Pow.js";
|
|
13
13
|
export * from "./Pubkey.js";
|
|
14
14
|
export * from "./Relay.js";
|
|
15
|
+
export * from "./RelaySelection.js";
|
|
15
16
|
export * from "./Tags.js";
|
|
16
17
|
export * from "./Wallet.js";
|
|
17
|
-
export * from "./
|
|
18
|
+
export * from "./Lightning.js";
|
|
18
19
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../util/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA;AAC5B,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,UAAU,CAAA;AACxB,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,WAAW,CAAA;AACzB,cAAc,aAAa,CAAA;AAC3B,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../util/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA;AAC5B,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,UAAU,CAAA;AACxB,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,qBAAqB,CAAA;AACnC,cAAc,WAAW,CAAA;AACzB,cAAc,aAAa,CAAA;AAC3B,cAAc,gBAAgB,CAAA"}
|
package/dist/util/src/index.js
CHANGED
|
@@ -12,7 +12,8 @@ export * from "./Nip98.js";
|
|
|
12
12
|
export * from "./Pow.js";
|
|
13
13
|
export * from "./Pubkey.js";
|
|
14
14
|
export * from "./Relay.js";
|
|
15
|
+
export * from "./RelaySelection.js";
|
|
15
16
|
export * from "./Tags.js";
|
|
16
17
|
export * from "./Wallet.js";
|
|
17
|
-
export * from "./
|
|
18
|
+
export * from "./Lightning.js";
|
|
18
19
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../util/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA;AAC5B,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,UAAU,CAAA;AACxB,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,WAAW,CAAA;AACzB,cAAc,aAAa,CAAA;AAC3B,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../util/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA;AAC5B,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,UAAU,CAAA;AACxB,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,qBAAqB,CAAA;AACnC,cAAc,WAAW,CAAA;AACzB,cAAc,aAAa,CAAA;AAC3B,cAAc,gBAAgB,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@welshman/net",
|
|
3
|
-
"version": "0.9.0-
|
|
3
|
+
"version": "0.9.0-pre2",
|
|
4
4
|
"author": "hodlbod",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "Utilities for connecting with nostr relays.",
|
|
@@ -18,14 +18,14 @@
|
|
|
18
18
|
"isomorphic-ws": "^5.0.0"
|
|
19
19
|
},
|
|
20
20
|
"peerDependencies": {
|
|
21
|
-
"@welshman/lib": "0.9.0-
|
|
22
|
-
"@welshman/util": "0.9.0-
|
|
21
|
+
"@welshman/lib": "0.9.0-pre2",
|
|
22
|
+
"@welshman/util": "0.9.0-pre2"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"rimraf": "~6.0.0",
|
|
26
26
|
"typescript": "~5.8.0",
|
|
27
|
-
"@welshman/lib": "0.9.0-
|
|
28
|
-
"@welshman/util": "0.9.0-
|
|
27
|
+
"@welshman/lib": "0.9.0-pre2",
|
|
28
|
+
"@welshman/util": "0.9.0-pre2"
|
|
29
29
|
},
|
|
30
30
|
"scripts": {
|
|
31
31
|
"build": "pnpm run clean && pnpm run compile --force",
|
package/dist/util/src/Zaps.d.ts
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import type { Filter } from "./Filters.js";
|
|
2
|
-
import type { TrustedEvent, SignedEvent } from "./Events.js";
|
|
3
|
-
export declare const toMsats: (sats: number) => number;
|
|
4
|
-
export declare const fromMsats: (msats: number) => number;
|
|
5
|
-
export declare const hrpToMillisat: (hrpString: string) => bigint;
|
|
6
|
-
export declare const getInvoiceAmount: (bolt11: string) => number;
|
|
7
|
-
export declare const getLnUrl: (address: string) => string | undefined;
|
|
8
|
-
export type Zapper = {
|
|
9
|
-
lnurl: string;
|
|
10
|
-
pubkey?: string;
|
|
11
|
-
callback?: string;
|
|
12
|
-
minSendable?: number;
|
|
13
|
-
maxSendable?: number;
|
|
14
|
-
nostrPubkey?: string;
|
|
15
|
-
allowsNostr?: boolean;
|
|
16
|
-
};
|
|
17
|
-
export type Zap = {
|
|
18
|
-
request: TrustedEvent;
|
|
19
|
-
response: TrustedEvent;
|
|
20
|
-
invoiceAmount: number;
|
|
21
|
-
};
|
|
22
|
-
export declare const zapFromEvent: (response: TrustedEvent, zapper: Zapper | undefined) => Zap | undefined;
|
|
23
|
-
/**
|
|
24
|
-
* A single recipient of an event's zaps, parsed from a NIP-57 Appendix G `zap`
|
|
25
|
-
* tag of the form `["zap", <pubkey>, <relay hint>, <weight>]`.
|
|
26
|
-
*/
|
|
27
|
-
export type ZapSplit = {
|
|
28
|
-
pubkey: string;
|
|
29
|
-
relay?: string;
|
|
30
|
-
weight: number;
|
|
31
|
-
};
|
|
32
|
-
export type ZapSplitAmount = ZapSplit & {
|
|
33
|
-
amount: number;
|
|
34
|
-
};
|
|
35
|
-
/**
|
|
36
|
-
* Resolve an event's zap-split recipients per NIP-57 Appendix G:
|
|
37
|
-
*
|
|
38
|
-
* - With no `zap` tags the whole zap goes to the event's author.
|
|
39
|
-
* - If no recipient carries a weight, the zap is split equally (weight 1 each).
|
|
40
|
-
* - If weights are only partially present, unweighted recipients drop to weight
|
|
41
|
-
* 0 (i.e. they should not be zapped).
|
|
42
|
-
*
|
|
43
|
-
* Weight-0 recipients are still returned so callers have the full recipient set;
|
|
44
|
-
* they simply receive 0 from `splitZapAmount`.
|
|
45
|
-
*/
|
|
46
|
-
export declare const getZapSplits: (event: TrustedEvent) => ZapSplit[];
|
|
47
|
-
/**
|
|
48
|
-
* Divide `total` (in any integer unit, e.g. millisats) across an event's
|
|
49
|
-
* zap-split recipients proportionally to their weights. Any rounding remainder
|
|
50
|
-
* is handed to the highest-weighted recipient so the parts sum back to exactly
|
|
51
|
-
* `total`. If every weight is 0, nobody is zapped.
|
|
52
|
-
*/
|
|
53
|
-
export declare const splitZapAmount: (event: TrustedEvent, total: number) => ZapSplitAmount[];
|
|
54
|
-
export type ZapRequestParams = {
|
|
55
|
-
msats: number;
|
|
56
|
-
zapper: Zapper;
|
|
57
|
-
pubkey: string;
|
|
58
|
-
relays: string[];
|
|
59
|
-
content?: string;
|
|
60
|
-
eventId?: string;
|
|
61
|
-
anonymous?: boolean;
|
|
62
|
-
};
|
|
63
|
-
export declare const makeZapRequest: ({ msats, zapper, pubkey, relays, content, eventId, anonymous, }: ZapRequestParams) => {
|
|
64
|
-
kind: number;
|
|
65
|
-
content: string;
|
|
66
|
-
tags: string[][];
|
|
67
|
-
created_at: number;
|
|
68
|
-
};
|
|
69
|
-
export type RequestInvoiceParams = {
|
|
70
|
-
zapper: Zapper;
|
|
71
|
-
event: SignedEvent;
|
|
72
|
-
};
|
|
73
|
-
export declare const requestZap: ({ zapper, event }: RequestInvoiceParams) => Promise<{
|
|
74
|
-
invoice: any;
|
|
75
|
-
error?: undefined;
|
|
76
|
-
} | {
|
|
77
|
-
error: any;
|
|
78
|
-
invoice?: undefined;
|
|
79
|
-
}>;
|
|
80
|
-
export type ZapResponseFilterParams = {
|
|
81
|
-
zapper: Zapper;
|
|
82
|
-
pubkey: string;
|
|
83
|
-
eventId?: string;
|
|
84
|
-
};
|
|
85
|
-
export declare const getZapResponseFilter: ({ zapper, pubkey, eventId }: ZapResponseFilterParams) => Filter;
|
|
86
|
-
//# sourceMappingURL=Zaps.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Zaps.d.ts","sourceRoot":"","sources":["../../../../util/src/Zaps.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,cAAc,CAAA;AACxC,OAAO,KAAK,EAAC,YAAY,EAAE,WAAW,EAAC,MAAM,aAAa,CAAA;AAc1D,eAAO,MAAM,OAAO,GAAI,MAAM,MAAM,WAAgB,CAAA;AAEpD,eAAO,MAAM,SAAS,GAAI,OAAO,MAAM,WAA6B,CAAA;AAEpE,eAAO,MAAM,aAAa,GAAI,WAAW,MAAM,WA2B9C,CAAA;AAED,eAAO,MAAM,gBAAgB,GAAI,QAAQ,MAAM,WAI9C,CAAA;AAED,eAAO,MAAM,QAAQ,GAAI,SAAS,MAAM,uBAqBvC,CAAA;AAED,MAAM,MAAM,MAAM,GAAG;IACnB,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,WAAW,CAAC,EAAE,OAAO,CAAA;CACtB,CAAA;AAED,MAAM,MAAM,GAAG,GAAG;IAChB,OAAO,EAAE,YAAY,CAAA;IACrB,QAAQ,EAAE,YAAY,CAAA;IACtB,aAAa,EAAE,MAAM,CAAA;CACtB,CAAA;AAED,eAAO,MAAM,YAAY,GAAI,UAAU,YAAY,EAAE,QAAQ,MAA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now, tryCatch, fetchJson, hexToBech32, fromPairs, sum, allPass, nthEq, nth, } from "@welshman/lib";
|
|
2
|
-
import { ZAP_RECEIPT, ZAP_REQUEST } from "./Kinds.js";
|
|
3
|
-
import { getTagValue } from "./Tags.js";
|
|
4
|
-
import { makeEvent } from "./Events.js";
|
|
5
|
-
const DIVISORS = {
|
|
6
|
-
m: BigInt(1e3),
|
|
7
|
-
u: BigInt(1e6),
|
|
8
|
-
n: BigInt(1e9),
|
|
9
|
-
p: BigInt(1e12),
|
|
10
|
-
};
|
|
11
|
-
const MAX_MILLISATS = BigInt("2100000000000000000");
|
|
12
|
-
const MILLISATS_PER_BTC = BigInt(1e11);
|
|
13
|
-
export const toMsats = (sats) => sats * 1000;
|
|
14
|
-
export const fromMsats = (msats) => Math.floor(msats / 1000);
|
|
15
|
-
export const hrpToMillisat = (hrpString) => {
|
|
16
|
-
let divisor, value;
|
|
17
|
-
if (hrpString.slice(-1).match(/^[munp]$/)) {
|
|
18
|
-
divisor = hrpString.slice(-1);
|
|
19
|
-
value = hrpString.slice(0, -1);
|
|
20
|
-
}
|
|
21
|
-
else if (hrpString.slice(-1).match(/^[^munp0-9]$/)) {
|
|
22
|
-
throw new Error("Not a valid multiplier for the amount");
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
value = hrpString;
|
|
26
|
-
}
|
|
27
|
-
if (!value.match(/^\d+$/))
|
|
28
|
-
throw new Error("Not a valid human readable amount");
|
|
29
|
-
const valueBN = BigInt(value);
|
|
30
|
-
const millisatoshisBN = divisor
|
|
31
|
-
? (valueBN * MILLISATS_PER_BTC) / DIVISORS[divisor]
|
|
32
|
-
: valueBN * MILLISATS_PER_BTC;
|
|
33
|
-
if ((divisor === "p" && !(valueBN % BigInt(10) === BigInt(0))) ||
|
|
34
|
-
millisatoshisBN > MAX_MILLISATS) {
|
|
35
|
-
throw new Error("Amount is outside of valid range");
|
|
36
|
-
}
|
|
37
|
-
return millisatoshisBN;
|
|
38
|
-
};
|
|
39
|
-
export const getInvoiceAmount = (bolt11) => {
|
|
40
|
-
const hrp = bolt11.match(/lnbc(\d+\w)/);
|
|
41
|
-
const bn = hrpToMillisat(hrp[1]);
|
|
42
|
-
return Number(bn);
|
|
43
|
-
};
|
|
44
|
-
export const getLnUrl = (address) => {
|
|
45
|
-
address = address.toLowerCase();
|
|
46
|
-
// If it's already a lud06 we're good
|
|
47
|
-
if (address.startsWith("lnurl1")) {
|
|
48
|
-
return address;
|
|
49
|
-
}
|
|
50
|
-
// If it's a regular url, encode it
|
|
51
|
-
if (address.includes("://")) {
|
|
52
|
-
return hexToBech32("lnurl", address);
|
|
53
|
-
}
|
|
54
|
-
// Try to parse it as a lud16 address
|
|
55
|
-
if (address.includes("@")) {
|
|
56
|
-
const [name, domain] = address.split("@");
|
|
57
|
-
if (domain && name) {
|
|
58
|
-
return hexToBech32("lnurl", `https://${domain}/.well-known/lnurlp/${name}`);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
export const zapFromEvent = (response, zapper) => {
|
|
63
|
-
const responseMeta = fromPairs(response.tags);
|
|
64
|
-
let zap;
|
|
65
|
-
try {
|
|
66
|
-
zap = {
|
|
67
|
-
response,
|
|
68
|
-
invoiceAmount: getInvoiceAmount(responseMeta.bolt11),
|
|
69
|
-
request: JSON.parse(responseMeta.description),
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
catch (e) {
|
|
73
|
-
return undefined;
|
|
74
|
-
}
|
|
75
|
-
// Don't count zaps that the user requested for himself
|
|
76
|
-
if (zap.request.pubkey === zapper?.pubkey) {
|
|
77
|
-
return undefined;
|
|
78
|
-
}
|
|
79
|
-
const { amount, lnurl } = fromPairs(zap.request.tags);
|
|
80
|
-
// Verify that the zapper actually sent the requested amount (if it was supplied)
|
|
81
|
-
if (amount && parseInt(amount) !== zap.invoiceAmount) {
|
|
82
|
-
return undefined;
|
|
83
|
-
}
|
|
84
|
-
// If the recipient and the zapper are the same person, it's legit
|
|
85
|
-
if (responseMeta.p === response.pubkey) {
|
|
86
|
-
return zap;
|
|
87
|
-
}
|
|
88
|
-
// If the sending client provided an lnurl tag, verify that too
|
|
89
|
-
if (lnurl && lnurl !== zapper?.lnurl) {
|
|
90
|
-
return undefined;
|
|
91
|
-
}
|
|
92
|
-
// Verify that the request actually came from the recipient's zapper
|
|
93
|
-
if (zap.response.pubkey !== zapper?.nostrPubkey) {
|
|
94
|
-
return undefined;
|
|
95
|
-
}
|
|
96
|
-
return zap;
|
|
97
|
-
};
|
|
98
|
-
const parseWeight = (weight) => {
|
|
99
|
-
const n = weight === undefined ? NaN : parseFloat(weight);
|
|
100
|
-
return Number.isFinite(n) && n > 0 ? n : 0;
|
|
101
|
-
};
|
|
102
|
-
/**
|
|
103
|
-
* Resolve an event's zap-split recipients per NIP-57 Appendix G:
|
|
104
|
-
*
|
|
105
|
-
* - With no `zap` tags the whole zap goes to the event's author.
|
|
106
|
-
* - If no recipient carries a weight, the zap is split equally (weight 1 each).
|
|
107
|
-
* - If weights are only partially present, unweighted recipients drop to weight
|
|
108
|
-
* 0 (i.e. they should not be zapped).
|
|
109
|
-
*
|
|
110
|
-
* Weight-0 recipients are still returned so callers have the full recipient set;
|
|
111
|
-
* they simply receive 0 from `splitZapAmount`.
|
|
112
|
-
*/
|
|
113
|
-
export const getZapSplits = (event) => {
|
|
114
|
-
const zapTags = event.tags.filter(allPass(nthEq(0, "zap"), nth(1)));
|
|
115
|
-
if (zapTags.length === 0) {
|
|
116
|
-
return [{ pubkey: event.pubkey, weight: 1 }];
|
|
117
|
-
}
|
|
118
|
-
const anyWeighted = zapTags.some(nth(3));
|
|
119
|
-
return zapTags.map(([, pubkey, relay, weight]) => ({
|
|
120
|
-
pubkey,
|
|
121
|
-
relay: relay || undefined,
|
|
122
|
-
weight: anyWeighted ? parseWeight(weight) : 1,
|
|
123
|
-
}));
|
|
124
|
-
};
|
|
125
|
-
/**
|
|
126
|
-
* Divide `total` (in any integer unit, e.g. millisats) across an event's
|
|
127
|
-
* zap-split recipients proportionally to their weights. Any rounding remainder
|
|
128
|
-
* is handed to the highest-weighted recipient so the parts sum back to exactly
|
|
129
|
-
* `total`. If every weight is 0, nobody is zapped.
|
|
130
|
-
*/
|
|
131
|
-
export const splitZapAmount = (event, total) => {
|
|
132
|
-
const splits = getZapSplits(event);
|
|
133
|
-
const totalWeight = sum(splits.map(split => split.weight));
|
|
134
|
-
if (totalWeight === 0) {
|
|
135
|
-
return splits.map(split => ({ ...split, amount: 0 }));
|
|
136
|
-
}
|
|
137
|
-
const amounts = splits.map(split => Math.floor((total * split.weight) / totalWeight));
|
|
138
|
-
let maxIndex = 0;
|
|
139
|
-
splits.forEach((split, i) => {
|
|
140
|
-
if (split.weight > splits[maxIndex].weight) {
|
|
141
|
-
maxIndex = i;
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
amounts[maxIndex] += total - sum(amounts);
|
|
145
|
-
return splits.map((split, i) => ({ ...split, amount: amounts[i] }));
|
|
146
|
-
};
|
|
147
|
-
export const makeZapRequest = ({ msats, zapper, pubkey, relays, content = "", eventId, anonymous, }) => {
|
|
148
|
-
const tags = [
|
|
149
|
-
["relays", ...relays],
|
|
150
|
-
["amount", String(msats)],
|
|
151
|
-
["lnurl", zapper.lnurl],
|
|
152
|
-
["p", pubkey],
|
|
153
|
-
];
|
|
154
|
-
if (eventId) {
|
|
155
|
-
tags.push(["e", eventId]);
|
|
156
|
-
}
|
|
157
|
-
if (anonymous) {
|
|
158
|
-
tags.push(["anon"]);
|
|
159
|
-
}
|
|
160
|
-
return makeEvent(ZAP_REQUEST, { content, tags });
|
|
161
|
-
};
|
|
162
|
-
export const requestZap = async ({ zapper, event }) => {
|
|
163
|
-
const zapString = encodeURI(JSON.stringify(event));
|
|
164
|
-
const msats = parseInt(getTagValue("amount", event.tags));
|
|
165
|
-
const qs = `?amount=${msats}&nostr=${zapString}&lnurl=${zapper.lnurl}`;
|
|
166
|
-
const res = await tryCatch(() => fetchJson(zapper.callback + qs));
|
|
167
|
-
return res?.pr ? { invoice: res.pr } : { error: res.reason || "Failed to request invoice" };
|
|
168
|
-
};
|
|
169
|
-
export const getZapResponseFilter = ({ zapper, pubkey, eventId }) => {
|
|
170
|
-
if (!zapper.nostrPubkey) {
|
|
171
|
-
throw new Error("Zapper did not have a nostr pubkey");
|
|
172
|
-
}
|
|
173
|
-
const filter = {
|
|
174
|
-
kinds: [ZAP_RECEIPT],
|
|
175
|
-
authors: [zapper.nostrPubkey],
|
|
176
|
-
since: now() - 30,
|
|
177
|
-
"#p": [pubkey],
|
|
178
|
-
};
|
|
179
|
-
if (eventId) {
|
|
180
|
-
filter["#e"] = [eventId];
|
|
181
|
-
}
|
|
182
|
-
return filter;
|
|
183
|
-
};
|
|
184
|
-
//# sourceMappingURL=Zaps.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Zaps.js","sourceRoot":"","sources":["../../../../util/src/Zaps.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,GAAG,EACH,QAAQ,EACR,SAAS,EACT,WAAW,EACX,SAAS,EACT,GAAG,EACH,OAAO,EACP,KAAK,EACL,GAAG,GACJ,MAAM,eAAe,CAAA;AACtB,OAAO,EAAC,WAAW,EAAE,WAAW,EAAC,MAAM,YAAY,CAAA;AACnD,OAAO,EAAC,WAAW,EAAC,MAAM,WAAW,CAAA;AAGrC,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAA;AAErC,MAAM,QAAQ,GAAG;IACf,CAAC,EAAE,MAAM,CAAC,GAAG,CAAC;IACd,CAAC,EAAE,MAAM,CAAC,GAAG,CAAC;IACd,CAAC,EAAE,MAAM,CAAC,GAAG,CAAC;IACd,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC;CAChB,CAAA;AAED,MAAM,aAAa,GAAG,MAAM,CAAC,qBAAqB,CAAC,CAAA;AAEnD,MAAM,iBAAiB,GAAG,MAAM,CAAC,IAAI,CAAC,CAAA;AAEtC,MAAM,CAAC,MAAM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