applesauce-common 6.0.2 → 6.2.0

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.
Files changed (103) hide show
  1. package/dist/casts/_circular-import.d.ts +2 -0
  2. package/dist/casts/_circular-import.js +2 -0
  3. package/dist/casts/git-grasp-list.d.ts +8 -0
  4. package/dist/casts/git-grasp-list.js +13 -0
  5. package/dist/casts/git-lists.d.ts +42 -0
  6. package/dist/casts/git-lists.js +94 -0
  7. package/dist/casts/git-repository.d.ts +29 -0
  8. package/dist/casts/git-repository.js +68 -0
  9. package/dist/casts/index.d.ts +3 -0
  10. package/dist/casts/index.js +3 -0
  11. package/dist/casts/reaction.d.ts +3 -1
  12. package/dist/casts/reaction.js +6 -2
  13. package/dist/casts/relay-lists.d.ts +6 -2
  14. package/dist/casts/relay-lists.js +11 -2
  15. package/dist/casts/trusted-assertions.d.ts +2 -2
  16. package/dist/casts/trusted-assertions.js +1 -1
  17. package/dist/casts/user.d.ts +4 -0
  18. package/dist/casts/user.js +23 -1
  19. package/dist/factories/calendar-event.d.ts +0 -5
  20. package/dist/factories/calendar-event.js +0 -9
  21. package/dist/factories/calendar-rsvp.d.ts +1 -0
  22. package/dist/factories/calendar-rsvp.js +1 -0
  23. package/dist/factories/code-snippet.d.ts +0 -2
  24. package/dist/factories/code-snippet.js +0 -5
  25. package/dist/factories/comment.d.ts +0 -2
  26. package/dist/factories/comment.js +5 -8
  27. package/dist/factories/favorite-git-repos.d.ts +17 -0
  28. package/dist/factories/favorite-git-repos.js +43 -0
  29. package/dist/factories/gift-wrap.js +2 -2
  30. package/dist/factories/git-authors.d.ts +17 -0
  31. package/dist/factories/git-authors.js +24 -0
  32. package/dist/factories/git-grasp-list.d.ts +14 -0
  33. package/dist/factories/git-grasp-list.js +25 -0
  34. package/dist/factories/git-repository.d.ts +51 -0
  35. package/dist/factories/git-repository.js +96 -0
  36. package/dist/factories/group.d.ts +5 -7
  37. package/dist/factories/group.js +8 -14
  38. package/dist/factories/highlight.d.ts +1 -10
  39. package/dist/factories/highlight.js +2 -12
  40. package/dist/factories/index.d.ts +6 -4
  41. package/dist/factories/index.js +6 -4
  42. package/dist/factories/legacy-message.d.ts +0 -1
  43. package/dist/factories/list.d.ts +0 -10
  44. package/dist/factories/list.js +0 -21
  45. package/dist/factories/nostr-web-token.d.ts +39 -0
  46. package/dist/factories/nostr-web-token.js +95 -0
  47. package/dist/factories/picture-post.d.ts +3 -4
  48. package/dist/factories/picture-post.js +3 -7
  49. package/dist/factories/poll-response.d.ts +0 -2
  50. package/dist/factories/poll-response.js +0 -5
  51. package/dist/factories/poll.d.ts +9 -6
  52. package/dist/factories/poll.js +12 -9
  53. package/dist/factories/relay-lists.d.ts +46 -0
  54. package/dist/factories/relay-lists.js +93 -0
  55. package/dist/factories/relay-set.d.ts +1 -1
  56. package/dist/factories/relay-set.js +1 -1
  57. package/dist/factories/share.d.ts +0 -7
  58. package/dist/factories/share.js +0 -11
  59. package/dist/factories/stream-chat-message.d.ts +0 -3
  60. package/dist/factories/stream-chat-message.js +0 -5
  61. package/dist/factories/torrent.d.ts +0 -2
  62. package/dist/factories/torrent.js +0 -5
  63. package/dist/factories/zap-goal.d.ts +0 -2
  64. package/dist/factories/zap-goal.js +0 -5
  65. package/dist/helpers/external-id.d.ts +1 -0
  66. package/dist/helpers/external-id.js +8 -27
  67. package/dist/helpers/git-grasp-list.d.ts +8 -0
  68. package/dist/helpers/git-grasp-list.js +15 -0
  69. package/dist/helpers/git-lists.d.ts +20 -0
  70. package/dist/helpers/git-lists.js +28 -0
  71. package/dist/helpers/git-repository.d.ts +39 -0
  72. package/dist/helpers/git-repository.js +104 -0
  73. package/dist/helpers/index.d.ts +4 -0
  74. package/dist/helpers/index.js +4 -0
  75. package/dist/helpers/nostr-web-token.d.ts +54 -0
  76. package/dist/helpers/nostr-web-token.js +124 -0
  77. package/dist/helpers/relay-list.d.ts +5 -0
  78. package/dist/helpers/relay-list.js +8 -0
  79. package/dist/observable/cast-stream.d.ts +1 -8
  80. package/dist/observable/cast-stream.js +2 -29
  81. package/dist/observable/chainable.d.ts +1 -1
  82. package/dist/observable/chainable.js +1 -1
  83. package/dist/operations/git-grasp-list.d.ts +7 -0
  84. package/dist/operations/git-grasp-list.js +18 -0
  85. package/dist/operations/git-repository.d.ts +45 -0
  86. package/dist/operations/git-repository.js +160 -0
  87. package/dist/operations/hashtags.d.ts +2 -0
  88. package/dist/operations/hashtags.js +7 -0
  89. package/dist/operations/index.d.ts +3 -0
  90. package/dist/operations/index.js +3 -0
  91. package/dist/operations/nostr-web-token.d.ts +27 -0
  92. package/dist/operations/nostr-web-token.js +58 -0
  93. package/dist/operations/poll.d.ts +3 -2
  94. package/dist/operations/poll.js +4 -3
  95. package/package.json +4 -4
  96. package/dist/factories/blocked-relays.d.ts +0 -10
  97. package/dist/factories/blocked-relays.js +0 -16
  98. package/dist/factories/dm-relays.d.ts +0 -10
  99. package/dist/factories/dm-relays.js +0 -16
  100. package/dist/factories/favorite-relays.d.ts +0 -16
  101. package/dist/factories/favorite-relays.js +0 -31
  102. package/dist/factories/search-relays.d.ts +0 -10
  103. package/dist/factories/search-relays.js +0 -16
@@ -0,0 +1,28 @@
1
+ import { setHiddenTagsEncryptionMethod } from "applesauce-core/helpers/hidden-tags";
2
+ import { GIT_REPOSITORY_KIND } from "./git-repository.js";
3
+ import { getAddressPointersFromList, getProfilePointersFromList } from "./lists.js";
4
+ /** NIP-51 git authors list kind */
5
+ export const GIT_AUTHORS_KIND = 10017;
6
+ /** NIP-51 git repositories list kind */
7
+ export const FAVORITE_GIT_REPOS_KIND = 10018;
8
+ /** NIP-34 repository announcement event kind */
9
+ export const REPOSITORY_ANNOUNCEMENT_KIND = GIT_REPOSITORY_KIND;
10
+ // Set the default encrypted content method for the kinds
11
+ setHiddenTagsEncryptionMethod(GIT_AUTHORS_KIND, "nip44");
12
+ setHiddenTagsEncryptionMethod(FAVORITE_GIT_REPOS_KIND, "nip44");
13
+ /** Validates that an event is a NIP-51 git authors list */
14
+ export function isValidGitAuthorsList(event) {
15
+ return event.kind === GIT_AUTHORS_KIND;
16
+ }
17
+ /** Validates that an event is a NIP-51 git repositories list */
18
+ export function isValidFavoriteGitReposList(event) {
19
+ return event.kind === FAVORITE_GIT_REPOS_KIND;
20
+ }
21
+ /** Returns git author profile pointers from a git authors list */
22
+ export function getGitAuthors(list, type) {
23
+ return getProfilePointersFromList(list, type);
24
+ }
25
+ /** Returns NIP-34 repository pointers from a git repositories list */
26
+ export function getFavoriteGitReposPointers(list, type) {
27
+ return getAddressPointersFromList(list, type).filter((pointer) => pointer.kind === REPOSITORY_ANNOUNCEMENT_KIND);
28
+ }
@@ -0,0 +1,39 @@
1
+ import { KnownEvent, NostrEvent } from "applesauce-core/helpers/event";
2
+ import { AddressPointer } from "applesauce-core/helpers/pointers";
3
+ export declare const GIT_REPOSITORY_KIND = 30617;
4
+ export type GitRepositoryEvent = KnownEvent<typeof GIT_REPOSITORY_KIND>;
5
+ export type GitRepositoryPointer = AddressPointer & {
6
+ kind: typeof GIT_REPOSITORY_KIND;
7
+ };
8
+ export declare const GitRepositoryWebUrlsSymbol: unique symbol;
9
+ export declare const GitRepositoryCloneUrlsSymbol: unique symbol;
10
+ export declare const GitRepositoryRelaysSymbol: unique symbol;
11
+ export declare const GitRepositoryMaintainersSymbol: unique symbol;
12
+ export declare const GitRepositoryHashtagsSymbol: unique symbol;
13
+ export declare const GitRepositoryUpstreamSymbol: unique symbol;
14
+ /** Checks if an event is a valid NIP-34 repository announcement. */
15
+ export declare function isValidGitRepository(event?: NostrEvent): event is GitRepositoryEvent;
16
+ /** Returns the repository identifier from the `d` tag. */
17
+ export declare function getGitRepositoryIdentifier(event: GitRepositoryEvent): string;
18
+ export declare function getGitRepositoryIdentifier(event?: NostrEvent): string | undefined;
19
+ /** Returns the repository display name. */
20
+ export declare function getGitRepositoryName(event?: NostrEvent): string | undefined;
21
+ /** Returns the repository description. */
22
+ export declare function getGitRepositoryDescription(event?: NostrEvent): string | undefined;
23
+ /** Returns all web URLs declared by the repository announcement. */
24
+ export declare function getGitRepositoryWebUrls(event?: NostrEvent): string[];
25
+ /** Returns all clone URLs declared by the repository announcement. */
26
+ export declare function getGitRepositoryCloneUrls(event?: NostrEvent): string[];
27
+ /** Returns relays monitored by the repository. */
28
+ export declare function getGitRepositoryRelays(event?: NostrEvent): string[];
29
+ /** Returns the earliest unique commit ID, if declared. */
30
+ export declare function getGitRepositoryEarliestUniqueCommit(event?: NostrEvent): string | undefined;
31
+ /** Returns all recognized maintainer pubkeys including the author of the repository event. */
32
+ export declare function getGitRepositoryMaintainers(event?: NostrEvent): string[];
33
+ /** Returns repository topic tags (NIP-34: values from each `["t", ...]` tag). */
34
+ export declare function getGitRepositoryHashtags(event?: NostrEvent): string[];
35
+ /**
36
+ * Returns the upstream repository pointer (the repo this one was forked from), if declared.
37
+ * Parsed from the `["u", "30617:<pubkey>:<identifier>", "<relay hint>"]` tag.
38
+ */
39
+ export declare function getGitRepositoryUpstream(event?: NostrEvent): GitRepositoryPointer | undefined;
@@ -0,0 +1,104 @@
1
+ import { isHexKey, relaySet } from "applesauce-core/helpers";
2
+ import { getOrComputeCachedValue } from "applesauce-core/helpers/cache";
3
+ import { getReplaceableIdentifier, getTagValue } from "applesauce-core/helpers/event";
4
+ import { isSafeRelayURL } from "applesauce-core/helpers/relays";
5
+ import { normalizeURL } from "applesauce-core/helpers/url";
6
+ export const GIT_REPOSITORY_KIND = 30617;
7
+ export const GitRepositoryWebUrlsSymbol = Symbol.for("git-repository-web-urls");
8
+ export const GitRepositoryCloneUrlsSymbol = Symbol.for("git-repository-clone-urls");
9
+ export const GitRepositoryRelaysSymbol = Symbol.for("git-repository-relays");
10
+ export const GitRepositoryMaintainersSymbol = Symbol.for("git-repository-maintainers");
11
+ export const GitRepositoryHashtagsSymbol = Symbol.for("git-repository-hashtags");
12
+ export const GitRepositoryUpstreamSymbol = Symbol.for("git-repository-upstream");
13
+ function getTagValues(event, name) {
14
+ return event.tags.filter((tag) => tag[0] === name && tag[1]).flatMap((tag) => tag.slice(1));
15
+ }
16
+ /** Checks if an event is a valid NIP-34 repository announcement. */
17
+ export function isValidGitRepository(event) {
18
+ return !!event && event.kind === GIT_REPOSITORY_KIND && !!getReplaceableIdentifier(event);
19
+ }
20
+ export function getGitRepositoryIdentifier(event) {
21
+ if (!isValidGitRepository(event))
22
+ return undefined;
23
+ return getReplaceableIdentifier(event) || undefined;
24
+ }
25
+ /** Returns the repository display name. */
26
+ export function getGitRepositoryName(event) {
27
+ if (!isValidGitRepository(event))
28
+ return undefined;
29
+ return getTagValue(event, "name") || undefined;
30
+ }
31
+ /** Returns the repository description. */
32
+ export function getGitRepositoryDescription(event) {
33
+ if (!isValidGitRepository(event))
34
+ return undefined;
35
+ return getTagValue(event, "description") || undefined;
36
+ }
37
+ /** Returns all web URLs declared by the repository announcement. */
38
+ export function getGitRepositoryWebUrls(event) {
39
+ if (!isValidGitRepository(event))
40
+ return [];
41
+ return getOrComputeCachedValue(event, GitRepositoryWebUrlsSymbol, () => getTagValues(event, "web"));
42
+ }
43
+ /** Returns all clone URLs declared by the repository announcement. */
44
+ export function getGitRepositoryCloneUrls(event) {
45
+ if (!isValidGitRepository(event))
46
+ return [];
47
+ return getOrComputeCachedValue(event, GitRepositoryCloneUrlsSymbol, () => getTagValues(event, "clone"));
48
+ }
49
+ /** Returns relays monitored by the repository. */
50
+ export function getGitRepositoryRelays(event) {
51
+ if (!isValidGitRepository(event))
52
+ return [];
53
+ return getOrComputeCachedValue(event, GitRepositoryRelaysSymbol, () => relaySet(getTagValues(event, "relays")));
54
+ }
55
+ /** Returns the earliest unique commit ID, if declared. */
56
+ export function getGitRepositoryEarliestUniqueCommit(event) {
57
+ if (!isValidGitRepository(event))
58
+ return undefined;
59
+ return event.tags.find((tag) => tag[0] === "r" && tag[2] === "euc")?.[1];
60
+ }
61
+ /** Returns all recognized maintainer pubkeys including the author of the repository event. */
62
+ export function getGitRepositoryMaintainers(event) {
63
+ if (!isValidGitRepository(event))
64
+ return [];
65
+ return getOrComputeCachedValue(event, GitRepositoryMaintainersSymbol, () => {
66
+ const pubkeys = getTagValues(event, "maintainers").filter(isHexKey);
67
+ return pubkeys.includes(event.pubkey) ? pubkeys : [event.pubkey, ...pubkeys];
68
+ });
69
+ }
70
+ /** Returns repository topic tags (NIP-34: values from each `["t", ...]` tag). */
71
+ export function getGitRepositoryHashtags(event) {
72
+ if (!isValidGitRepository(event))
73
+ return [];
74
+ return getOrComputeCachedValue(event, GitRepositoryHashtagsSymbol, () => getTagValues(event, "t"));
75
+ }
76
+ /**
77
+ * Returns the upstream repository pointer (the repo this one was forked from), if declared.
78
+ * Parsed from the `["u", "30617:<pubkey>:<identifier>", "<relay hint>"]` tag.
79
+ */
80
+ export function getGitRepositoryUpstream(event) {
81
+ if (!isValidGitRepository(event))
82
+ return undefined;
83
+ return getOrComputeCachedValue(event, GitRepositoryUpstreamSymbol, () => {
84
+ const tag = event.tags.find((t) => t[0] === "u" && t[1]);
85
+ if (!tag || !tag[1])
86
+ return undefined;
87
+ const parts = tag[1].split(":");
88
+ if (parts.length < 3)
89
+ return undefined;
90
+ const kind = parseInt(parts[0]);
91
+ const pubkey = parts[1];
92
+ const identifier = parts.slice(2).join(":");
93
+ if (kind !== GIT_REPOSITORY_KIND)
94
+ return undefined;
95
+ if (!pubkey || !/^[0-9a-f]{64}$/i.test(pubkey))
96
+ return undefined;
97
+ if (!identifier)
98
+ return undefined;
99
+ const pointer = { kind: GIT_REPOSITORY_KIND, pubkey: pubkey.toLowerCase(), identifier };
100
+ if (tag[2] && isSafeRelayURL(tag[2]))
101
+ pointer.relays = [normalizeURL(tag[2])];
102
+ return pointer;
103
+ });
104
+ }
@@ -16,6 +16,9 @@ export * from "./emoji-pack.js";
16
16
  export * from "./encrypted-content-cache.js";
17
17
  export * from "./file-metadata.js";
18
18
  export * from "./gift-wrap.js";
19
+ export * from "./git-grasp-list.js";
20
+ export * from "./git-lists.js";
21
+ export * from "./git-repository.js";
19
22
  export * from "./groups.js";
20
23
  export * from "./hashtag.js";
21
24
  export * from "./highlight.js";
@@ -24,6 +27,7 @@ export * from "./lists.js";
24
27
  export * from "./lnurl.js";
25
28
  export * from "./messages.js";
26
29
  export * from "./mute.js";
30
+ export * from "./nostr-web-token.js";
27
31
  export * from "./picture-post.js";
28
32
  export * from "./poll.js";
29
33
  export * from "./profile-badges.js";
@@ -16,6 +16,9 @@ export * from "./emoji-pack.js";
16
16
  export * from "./encrypted-content-cache.js";
17
17
  export * from "./file-metadata.js";
18
18
  export * from "./gift-wrap.js";
19
+ export * from "./git-grasp-list.js";
20
+ export * from "./git-lists.js";
21
+ export * from "./git-repository.js";
19
22
  export * from "./groups.js";
20
23
  export * from "./hashtag.js";
21
24
  export * from "./highlight.js";
@@ -24,6 +27,7 @@ export * from "./lists.js";
24
27
  export * from "./lnurl.js";
25
28
  export * from "./messages.js";
26
29
  export * from "./mute.js";
30
+ export * from "./nostr-web-token.js";
27
31
  export * from "./picture-post.js";
28
32
  export * from "./poll.js";
29
33
  export * from "./profile-badges.js";
@@ -0,0 +1,54 @@
1
+ import { KnownEvent, NostrEvent } from "applesauce-core/helpers/event";
2
+ /** @see https://github.com/Open-Ranking/nostr-web-tokens */
3
+ export declare const NOSTR_WEB_TOKEN_KIND = 27519;
4
+ export type NostrWebTokenEvent = KnownEvent<typeof NOSTR_WEB_TOKEN_KIND>;
5
+ export type NostrWebTokenClaims = {
6
+ /** Issuer claim, defaults to the signing pubkey when omitted */
7
+ issuer: string;
8
+ /** Subject claim, defaults to the signing pubkey when omitted */
9
+ subject: string;
10
+ /** Audience claims */
11
+ audiences: string[];
12
+ /** Issued-at timestamp, defaults to the event created_at when omitted */
13
+ issuedAt: number;
14
+ /** Expiration timestamp */
15
+ expiration?: number;
16
+ /** Not-before timestamp */
17
+ notBefore?: number;
18
+ /** Additional application-defined claims */
19
+ claims: Record<string, string[]>;
20
+ };
21
+ export declare const NostrWebTokenClaimsSymbol: unique symbol;
22
+ /** Parses all registered and custom claims from a Nostr Web Token event. */
23
+ export declare function parseNostrWebTokenClaims(event: NostrWebTokenEvent): NostrWebTokenClaims;
24
+ export declare function parseNostrWebTokenClaims(event: NostrEvent): NostrWebTokenClaims | undefined;
25
+ /** Gets the issuer claim, or the signing pubkey when absent. */
26
+ export declare function getNostrWebTokenIssuer(event: NostrWebTokenEvent): string;
27
+ export declare function getNostrWebTokenIssuer(event: NostrEvent): string | undefined;
28
+ /** Gets the subject claim, or the signing pubkey when absent. */
29
+ export declare function getNostrWebTokenSubject(event: NostrWebTokenEvent): string;
30
+ export declare function getNostrWebTokenSubject(event: NostrEvent): string | undefined;
31
+ /** Gets all audience claims. */
32
+ export declare function getNostrWebTokenAudiences(event: NostrWebTokenEvent): string[];
33
+ export declare function getNostrWebTokenAudiences(event: NostrEvent): string[] | undefined;
34
+ /** Gets the issued-at claim, or the event created_at when absent. */
35
+ export declare function getNostrWebTokenIssuedAt(event: NostrWebTokenEvent): number;
36
+ export declare function getNostrWebTokenIssuedAt(event: NostrEvent): number | undefined;
37
+ /** Gets the expiration claim. */
38
+ export declare function getNostrWebTokenExpiration(event: NostrEvent): number | undefined;
39
+ /** Gets the not-before claim. */
40
+ export declare function getNostrWebTokenNotBefore(event: NostrEvent): number | undefined;
41
+ /** Checks if an event is structurally a valid Nostr Web Token. Does not verify the event signature. */
42
+ export declare function isValidNostrWebToken(event?: NostrEvent): event is NostrWebTokenEvent;
43
+ /** Checks the exp and nbf claims against a timestamp. */
44
+ export declare function isNostrWebTokenActive(event: NostrEvent, now?: number, clockSkew?: number): boolean;
45
+ /** Checks if a token contains a matching audience claim. */
46
+ export declare function hasNostrWebTokenAudience(event: NostrEvent, audience: string): boolean;
47
+ /** Encodes a Nostr Web Token event for HTTP Authorization transport. */
48
+ export declare function encodeNostrWebToken(event: NostrEvent): string;
49
+ /** Decodes a Nostr Web Token from Base64URL transport encoding. */
50
+ export declare function decodeNostrWebToken(token: string): NostrEvent | undefined;
51
+ /** Creates an HTTP Authorization header value for a Nostr Web Token event. */
52
+ export declare function createNostrWebTokenAuthorizationHeader(event: NostrEvent): string;
53
+ /** Parses an HTTP Authorization header value containing a Nostr Web Token. */
54
+ export declare function parseNostrWebTokenAuthorizationHeader(header: string | null | undefined): NostrEvent | undefined;
@@ -0,0 +1,124 @@
1
+ import { base64urlnopad, utf8 } from "@scure/base";
2
+ import { getOrComputeCachedValue } from "applesauce-core/helpers/cache";
3
+ import { getTagValue, isEvent } from "applesauce-core/helpers/event";
4
+ /** @see https://github.com/Open-Ranking/nostr-web-tokens */
5
+ export const NOSTR_WEB_TOKEN_KIND = 27519;
6
+ export const NostrWebTokenClaimsSymbol = Symbol.for("nostr-web-token-claims");
7
+ const singletonClaims = new Set(["iss", "sub", "iat", "exp", "nbf"]);
8
+ const registeredClaims = new Set(["iss", "sub", "aud", "iat", "exp", "nbf"]);
9
+ function parseTimestamp(value) {
10
+ if (value === undefined || !/^\d+$/.test(value))
11
+ return undefined;
12
+ return Number.parseInt(value, 10);
13
+ }
14
+ function isValidTimestamp(value) {
15
+ return parseTimestamp(value) !== undefined;
16
+ }
17
+ export function parseNostrWebTokenClaims(event) {
18
+ if (event.kind !== NOSTR_WEB_TOKEN_KIND)
19
+ return undefined;
20
+ return getOrComputeCachedValue(event, NostrWebTokenClaimsSymbol, () => {
21
+ const claims = {};
22
+ const audiences = [];
23
+ for (const tag of event.tags) {
24
+ const [name, value] = tag;
25
+ if (value === undefined)
26
+ continue;
27
+ if (name === "aud")
28
+ audiences.push(value);
29
+ else if (!registeredClaims.has(name))
30
+ claims[name] = claims[name] ? [...claims[name], value] : [value];
31
+ }
32
+ return {
33
+ issuer: getTagValue(event, "iss") ?? event.pubkey,
34
+ subject: getTagValue(event, "sub") ?? event.pubkey,
35
+ audiences,
36
+ issuedAt: parseTimestamp(getTagValue(event, "iat")) ?? event.created_at,
37
+ expiration: parseTimestamp(getTagValue(event, "exp")),
38
+ notBefore: parseTimestamp(getTagValue(event, "nbf")),
39
+ claims,
40
+ };
41
+ });
42
+ }
43
+ export function getNostrWebTokenIssuer(event) {
44
+ return parseNostrWebTokenClaims(event)?.issuer;
45
+ }
46
+ export function getNostrWebTokenSubject(event) {
47
+ return parseNostrWebTokenClaims(event)?.subject;
48
+ }
49
+ export function getNostrWebTokenAudiences(event) {
50
+ return parseNostrWebTokenClaims(event)?.audiences;
51
+ }
52
+ export function getNostrWebTokenIssuedAt(event) {
53
+ return parseNostrWebTokenClaims(event)?.issuedAt;
54
+ }
55
+ /** Gets the expiration claim. */
56
+ export function getNostrWebTokenExpiration(event) {
57
+ return parseNostrWebTokenClaims(event)?.expiration;
58
+ }
59
+ /** Gets the not-before claim. */
60
+ export function getNostrWebTokenNotBefore(event) {
61
+ return parseNostrWebTokenClaims(event)?.notBefore;
62
+ }
63
+ /** Checks if an event is structurally a valid Nostr Web Token. Does not verify the event signature. */
64
+ export function isValidNostrWebToken(event) {
65
+ if (!event || event.kind !== NOSTR_WEB_TOKEN_KIND)
66
+ return false;
67
+ if (!isEvent(event))
68
+ return false;
69
+ for (const name of registeredClaims) {
70
+ const tags = event.tags.filter((tag) => tag[0] === name);
71
+ if (tags.some((tag) => tag[1] === undefined))
72
+ return false;
73
+ if (singletonClaims.has(name) && tags.length > 1)
74
+ return false;
75
+ }
76
+ for (const name of ["iat", "exp", "nbf"]) {
77
+ const tag = event.tags.find((t) => t[0] === name);
78
+ if (tag && !isValidTimestamp(tag[1]))
79
+ return false;
80
+ }
81
+ return true;
82
+ }
83
+ /** Checks the exp and nbf claims against a timestamp. */
84
+ export function isNostrWebTokenActive(event, now = Math.floor(Date.now() / 1000), clockSkew = 60) {
85
+ if (!isValidNostrWebToken(event))
86
+ return false;
87
+ const claims = parseNostrWebTokenClaims(event);
88
+ if (!claims)
89
+ return false;
90
+ if (claims.expiration !== undefined && now - clockSkew >= claims.expiration)
91
+ return false;
92
+ if (claims.notBefore !== undefined && now + clockSkew < claims.notBefore)
93
+ return false;
94
+ return true;
95
+ }
96
+ /** Checks if a token contains a matching audience claim. */
97
+ export function hasNostrWebTokenAudience(event, audience) {
98
+ return parseNostrWebTokenClaims(event)?.audiences.includes(audience) ?? false;
99
+ }
100
+ /** Encodes a Nostr Web Token event for HTTP Authorization transport. */
101
+ export function encodeNostrWebToken(event) {
102
+ return base64urlnopad.encode(utf8.decode(JSON.stringify(event)));
103
+ }
104
+ /** Decodes a Nostr Web Token from Base64URL transport encoding. */
105
+ export function decodeNostrWebToken(token) {
106
+ try {
107
+ const event = JSON.parse(utf8.encode(base64urlnopad.decode(token)));
108
+ return isEvent(event) ? event : undefined;
109
+ }
110
+ catch {
111
+ return undefined;
112
+ }
113
+ }
114
+ /** Creates an HTTP Authorization header value for a Nostr Web Token event. */
115
+ export function createNostrWebTokenAuthorizationHeader(event) {
116
+ return `Nostr ${encodeNostrWebToken(event)}`;
117
+ }
118
+ /** Parses an HTTP Authorization header value containing a Nostr Web Token. */
119
+ export function parseNostrWebTokenAuthorizationHeader(header) {
120
+ const match = header?.match(/^Nostr\s+(.+)$/i);
121
+ if (!match)
122
+ return undefined;
123
+ return decodeNostrWebToken(match[1]);
124
+ }
@@ -1,11 +1,16 @@
1
1
  import { kinds, KnownEvent, NostrEvent } from "applesauce-core/helpers/event";
2
2
  export declare const FAVORITE_RELAYS_KIND = 10012;
3
+ /** Indexer / lookup relays: where to fetch or publish kinds 0 and 10002 (NIP-51 `relay` tags). */
4
+ export declare const LOOKUP_RELAY_LIST_KIND = 10086;
3
5
  export type FavoriteRelaysListEvent = KnownEvent<typeof FAVORITE_RELAYS_KIND>;
6
+ export type LookupRelayListEvent = KnownEvent<typeof LOOKUP_RELAY_LIST_KIND>;
4
7
  export type SearchRelaysListEvent = KnownEvent<typeof kinds.SearchRelaysList>;
5
8
  export type BlockedRelaysListEvent = KnownEvent<typeof kinds.BlockedRelaysList>;
6
9
  export type DMRelaysListEvent = KnownEvent<typeof kinds.DirectMessageRelaysList>;
7
10
  /** Validates that an event is a valid favorite relays list (kind 10012) */
8
11
  export declare function isValidFavoriteRelaysList(event: NostrEvent): event is FavoriteRelaysListEvent;
12
+ /** Validates that an event is a valid lookup / indexer relays list (kind 10086) */
13
+ export declare function isValidLookupRelayList(event: NostrEvent): event is LookupRelayListEvent;
9
14
  /** Validates that an event is a valid search relays list (kind 10007) */
10
15
  export declare function isValidSearchRelaysList(event: NostrEvent): event is SearchRelaysListEvent;
11
16
  /** Validates that an event is a valid blocked relays list (kind 10006) */
@@ -1,9 +1,17 @@
1
+ import { setHiddenTagsEncryptionMethod } from "applesauce-core/helpers/hidden-tags";
1
2
  import { kinds } from "applesauce-core/helpers/event";
2
3
  export const FAVORITE_RELAYS_KIND = 10012;
4
+ /** Indexer / lookup relays: where to fetch or publish kinds 0 and 10002 (NIP-51 `relay` tags). */
5
+ export const LOOKUP_RELAY_LIST_KIND = 10086;
6
+ setHiddenTagsEncryptionMethod(LOOKUP_RELAY_LIST_KIND, "nip04");
3
7
  /** Validates that an event is a valid favorite relays list (kind 10012) */
4
8
  export function isValidFavoriteRelaysList(event) {
5
9
  return event.kind === FAVORITE_RELAYS_KIND;
6
10
  }
11
+ /** Validates that an event is a valid lookup / indexer relays list (kind 10086) */
12
+ export function isValidLookupRelayList(event) {
13
+ return event.kind === LOOKUP_RELAY_LIST_KIND;
14
+ }
7
15
  /** Validates that an event is a valid search relays list (kind 10007) */
8
16
  export function isValidSearchRelaysList(event) {
9
17
  return event.kind === kinds.SearchRelaysList;
@@ -1,8 +1 @@
1
- import type { NostrEvent } from "applesauce-core/helpers/event";
2
- import { OperatorFunction } from "rxjs";
3
- import type { CastConstructor, CastRefEventStore } from "../casts/cast.js";
4
- import { EventCast } from "../casts/cast.js";
5
- /** Casts an event to a specific type */
6
- export declare function castEventStream<C extends EventCast>(cls: CastConstructor<C>, store?: CastRefEventStore): OperatorFunction<NostrEvent | undefined, C | undefined>;
7
- /** Casts and array of events to an array of casted events and filters out undefined values */
8
- export declare function castTimelineStream<C extends EventCast>(cls: CastConstructor<C>, store?: CastRefEventStore): OperatorFunction<NostrEvent[], C[]>;
1
+ export * from "applesauce-core/observable/cast-stream";
@@ -1,29 +1,2 @@
1
- import { defined } from "applesauce-core/observable/defined";
2
- import { map } from "rxjs";
3
- import { castEvent } from "../casts/cast.js";
4
- /** Casts an event to a specific type */
5
- export function castEventStream(cls, store) {
6
- return (source) => source.pipe(map((event) => {
7
- if (!event)
8
- return undefined;
9
- try {
10
- return castEvent(event, cls, store);
11
- }
12
- catch { }
13
- return undefined;
14
- }));
15
- }
16
- /** Casts and array of events to an array of casted events and filters out undefined values */
17
- export function castTimelineStream(cls, store) {
18
- return (source) => source.pipe(map((events) => {
19
- const castedEvents = [];
20
- for (const event of events) {
21
- try {
22
- const casted = castEvent(event, cls, store);
23
- castedEvents.push(casted);
24
- }
25
- catch { }
26
- }
27
- return castedEvents;
28
- }), defined());
29
- }
1
+ // Re-exported from applesauce-core — chainable now lives in the core package
2
+ export * from "applesauce-core/observable/cast-stream";
@@ -1 +1 @@
1
- export { chainable, type ChainableObservable } from "applesauce-core/observable";
1
+ export * from "applesauce-core/observable/chainable";
@@ -1,2 +1,2 @@
1
1
  // Re-exported from applesauce-core — chainable now lives in the core package
2
- export { chainable } from "applesauce-core/observable";
2
+ export * from "applesauce-core/observable/chainable";
@@ -0,0 +1,7 @@
1
+ import { EventOperation } from "applesauce-core/factories";
2
+ /** Adds a grasp server URL. */
3
+ export declare function addGitGraspServer(url: string): EventOperation;
4
+ /** Removes a grasp server URL. */
5
+ export declare function removeGitGraspServer(url: string): EventOperation;
6
+ /** Replaces all grasp servers. */
7
+ export declare function setGitGraspServers(urls: string[]): EventOperation;
@@ -0,0 +1,18 @@
1
+ import { normalizeRelayUrl, relaySet } from "applesauce-core/helpers/relays";
2
+ import { addRelayTag, removeRelayTag } from "applesauce-core/operations/tag/relay";
3
+ import { modifyPublicTags } from "applesauce-core/operations/tags";
4
+ /** Adds a grasp server URL. */
5
+ export function addGitGraspServer(url) {
6
+ return modifyPublicTags(addRelayTag(normalizeRelayUrl(url), "g"));
7
+ }
8
+ /** Removes a grasp server URL. */
9
+ export function removeGitGraspServer(url) {
10
+ return modifyPublicTags(removeRelayTag(normalizeRelayUrl(url), "g"));
11
+ }
12
+ /** Replaces all grasp servers. */
13
+ export function setGitGraspServers(urls) {
14
+ return modifyPublicTags((tags) => [
15
+ ...tags.filter((tag) => tag[0] !== "g"),
16
+ ...relaySet(urls).map((url) => ["g", url]),
17
+ ]);
18
+ }
@@ -0,0 +1,45 @@
1
+ import { EventOperation } from "applesauce-core/factories";
2
+ import { GitRepositoryPointer } from "../helpers/git-repository.js";
3
+ /** Sets the repository identifier `d` tag. */
4
+ export declare function setGitRepositoryIdentifier(identifier: string): EventOperation;
5
+ /** Sets or removes the repository name. */
6
+ export declare function setGitRepositoryName(name: string | null): EventOperation;
7
+ /** Sets or removes the repository description. */
8
+ export declare function setGitRepositoryDescription(description: string | null): EventOperation;
9
+ /** Sets the repository web URLs (single `web` tag, NIP-34 flat list). */
10
+ export declare function setGitRepositoryWebUrls(urls: string[]): EventOperation;
11
+ /** Sets the git clone URLs (single `clone` tag). */
12
+ export declare function setGitRepositoryCloneUrls(urls: string[]): EventOperation;
13
+ /** Sets the repository relay URLs (single `relays` tag, normalized). */
14
+ export declare function setGitRepositoryRelays(relays: string[]): EventOperation;
15
+ /** Adds a web browsing URL. */
16
+ export declare function addGitRepositoryWebUrl(url: string): EventOperation;
17
+ /** Removes a web browsing URL. */
18
+ export declare function removeGitRepositoryWebUrl(url: string): EventOperation;
19
+ /** Adds a git clone URL. */
20
+ export declare function addGitRepositoryCloneUrl(url: string): EventOperation;
21
+ /** Removes a git clone URL. */
22
+ export declare function removeGitRepositoryCloneUrl(url: string): EventOperation;
23
+ /** Adds a repository relay URL. */
24
+ export declare function addGitRepositoryRelay(relay: string): EventOperation;
25
+ /** Removes a repository relay URL. */
26
+ export declare function removeGitRepositoryRelay(relay: string): EventOperation;
27
+ /** Sets or removes the earliest unique commit marker. */
28
+ export declare function setGitRepositoryEarliestUniqueCommit(commit: string | null): EventOperation;
29
+ /** Sets the recognized maintainer pubkeys (single `maintainers` tag). */
30
+ export declare function setGitRepositoryMaintainers(pubkeys: string[]): EventOperation;
31
+ /** Adds a recognized maintainer pubkey. */
32
+ export declare function addGitRepositoryMaintainer(pubkey: string): EventOperation;
33
+ /** Removes a recognized maintainer pubkey. */
34
+ export declare function removeGitRepositoryMaintainer(pubkey: string): EventOperation;
35
+ /** Sets repository hashtags (NIP-34: multiple `["t", "<topic>"]` tags). */
36
+ export declare function setGitRepositoryHashtags(hashtags: string[]): EventOperation;
37
+ /** Adds a repository hashtag (NIP-34: `["t", "<topic>"]`). */
38
+ export declare function addGitRepositoryHashtag(hashtag: string): EventOperation;
39
+ /** Removes a repository hashtag. */
40
+ export declare function removeGitRepositoryHashtag(hashtag: string): EventOperation;
41
+ /**
42
+ * Sets or clears the upstream repository pointer (the repo this one was forked from).
43
+ * Writes a `["u", "30617:<pubkey>:<identifier>", "<relay hint>"]` tag.
44
+ */
45
+ export declare function setGitRepositoryUpstream(pointer: GitRepositoryPointer | null): EventOperation;