@qntx/nostr 0.13.0 → 0.15.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.
- package/dist/{builder-CGgM_QHT.mjs → builder-70CC2EBq.mjs} +4 -4
- package/dist/{builder-CGgM_QHT.mjs.map → builder-70CC2EBq.mjs.map} +1 -1
- package/dist/{builder-C72nJITG.d.mts → builder-Dk00TdNf.d.mts} +2 -2
- package/dist/{client-COkEihj_.mjs → client-BXmvZ7vU.mjs} +45 -30
- package/dist/client-BXmvZ7vU.mjs.map +1 -0
- package/dist/client.d.mts +1 -1
- package/dist/client.mjs +1 -2
- package/dist/core.d.mts +8 -7
- package/dist/core.mjs +8 -8
- package/dist/{error-Dyb89ahb.mjs → error-CoP2myne.mjs} +2 -2
- package/dist/{error-Dyb89ahb.mjs.map → error-CoP2myne.mjs.map} +1 -1
- package/dist/{error-BPqAU5RB.d.mts → error-DE1UCZ2J.d.mts} +6 -2
- package/dist/{error-BjSUsx6M.d.mts → error-IHMcLy8-.d.mts} +2 -2
- package/dist/{error-QyECUDIp.mjs → error-VDn7Nv-6.mjs} +2 -2
- package/dist/{error-QyECUDIp.mjs.map → error-VDn7Nv-6.mjs.map} +1 -1
- package/dist/{event-DvM1f03b.mjs → event-DHtcm0jM.mjs} +17 -6
- package/dist/event-DHtcm0jM.mjs.map +1 -0
- package/dist/{filter-3jOh4uLN.mjs → filter-BbShkmc4.mjs} +34 -28
- package/dist/filter-BbShkmc4.mjs.map +1 -0
- package/dist/{filter-oYG2zjJ3.d.mts → filter-w1R-mU63.d.mts} +8 -6
- package/dist/{gossip-BvCItMVZ.d.mts → gossip-C-7WhJ7v.d.mts} +3 -3
- package/dist/{gossip-CRyhK6E6.mjs → gossip-CejMm_QM.mjs} +13 -11
- package/dist/gossip-CejMm_QM.mjs.map +1 -0
- package/dist/gossip.d.mts +1 -1
- package/dist/gossip.mjs +1 -2
- package/dist/{index-B2JlP2Jf.d.mts → index-11znTLM0.d.mts} +4 -4
- package/dist/{index-DzHmhHqD.d.mts → index-B7nMjbyt.d.mts} +3 -3
- package/dist/{index-muydfuYD.d.mts → index-BuNI8JH_.d.mts} +13 -13
- package/dist/{index-Dpj_MUxb.d.mts → index-C5QomO2D.d.mts} +10 -3
- package/dist/{index-DCobP2Jj.d.mts → index-DDZjqV48.d.mts} +10 -10
- package/dist/{index-YID-zPDF.d.mts → index-DYk24u9o.d.mts} +24 -18
- package/dist/index.d.mts +21 -20
- package/dist/index.mjs +19 -19
- package/dist/{key-D_oEutQ6.mjs → key-Bt0ow7mI.mjs} +33 -11
- package/dist/key-Bt0ow7mI.mjs.map +1 -0
- package/dist/{key-DojW2QZl.d.mts → key-E0AJKMRB.d.mts} +19 -11
- package/dist/{loaders-BRh2riV9.mjs → loaders-COGGrZY4.mjs} +7 -7
- package/dist/loaders-COGGrZY4.mjs.map +1 -0
- package/dist/loaders.d.mts +2 -2
- package/dist/loaders.mjs +1 -2
- package/dist/{memory-D_GdEQYG.mjs → memory-Dq4dg-U4.mjs} +2 -2
- package/dist/{memory-D_GdEQYG.mjs.map → memory-Dq4dg-U4.mjs.map} +1 -1
- package/dist/{memory-index-3GSrPIWj.mjs → memory-index-DhlmbqWx.mjs} +19 -18
- package/dist/memory-index-DhlmbqWx.mjs.map +1 -0
- package/dist/{message-BMfreCQc.mjs → message-D6k16gtg.mjs} +20 -20
- package/dist/message-D6k16gtg.mjs.map +1 -0
- package/dist/{verifier-DhAbqVJF.d.mts → message-u_7KOq6Q.d.mts} +3 -22
- package/dist/{nip17-BZvFQLcs.d.mts → nip17--YwFSuph.d.mts} +4 -4
- package/dist/{nip19-D4RKn6GC.d.mts → nip19-qtyc5sCl.d.mts} +2 -2
- package/dist/{nip46-i8L8_nIm.d.mts → nip46-C_ZFQprM.d.mts} +2 -2
- package/dist/{nip51-C_kTYcud.d.mts → nip51-yi9w8FsM.d.mts} +2 -2
- package/dist/{nip59-DfJ6Moeu.d.mts → nip59-B6Ey8L9z.d.mts} +12 -3
- package/dist/{nip65-CPNE0SV0.d.mts → nip65-XrBjV9WM.d.mts} +2 -2
- package/dist/{nip77-DhpoL7d8.d.mts → nip77-BAXijIt_.d.mts} +2 -2
- package/dist/nips/blossom.d.mts +3 -2
- package/dist/nips/blossom.mjs +11 -11
- package/dist/nips/blossom.mjs.map +1 -1
- package/dist/nips/nip04.d.mts +3 -2
- package/dist/nips/nip04.mjs +10 -12
- package/dist/nips/nip04.mjs.map +1 -1
- package/dist/nips/nip05.d.mts +2 -2
- package/dist/nips/nip05.mjs +9 -8
- package/dist/nips/nip05.mjs.map +1 -1
- package/dist/nips/nip10.d.mts +3 -2
- package/dist/nips/nip10.mjs +19 -19
- package/dist/nips/nip10.mjs.map +1 -1
- package/dist/nips/nip11.d.mts +2 -1
- package/dist/nips/nip11.mjs +6 -4
- package/dist/nips/nip11.mjs.map +1 -1
- package/dist/nips/nip13.d.mts +1 -1
- package/dist/nips/nip13.mjs +2 -2
- package/dist/nips/nip13.mjs.map +1 -1
- package/dist/nips/nip17.d.mts +1 -1
- package/dist/nips/nip17.mjs +6 -6
- package/dist/nips/nip17.mjs.map +1 -1
- package/dist/nips/nip19.d.mts +1 -1
- package/dist/nips/nip19.mjs +1 -1
- package/dist/nips/nip21.d.mts +2 -2
- package/dist/nips/nip21.mjs +3 -3
- package/dist/nips/nip21.mjs.map +1 -1
- package/dist/nips/nip27.d.mts +3 -3
- package/dist/nips/nip27.mjs +308 -85
- package/dist/nips/nip27.mjs.map +1 -1
- package/dist/nips/nip42.mjs +1 -1
- package/dist/nips/nip44.d.mts +2 -1
- package/dist/nips/nip44.mjs +4 -4
- package/dist/nips/nip44.mjs.map +1 -1
- package/dist/nips/nip46.d.mts +1 -1
- package/dist/nips/nip46.mjs +9 -8
- package/dist/nips/nip46.mjs.map +1 -1
- package/dist/nips/nip49.d.mts +1 -1
- package/dist/nips/nip49.mjs +1 -1
- package/dist/nips/nip51.d.mts +1 -1
- package/dist/nips/nip51.mjs +14 -14
- package/dist/nips/nip51.mjs.map +1 -1
- package/dist/nips/nip57.mjs +10 -10
- package/dist/nips/nip57.mjs.map +1 -1
- package/dist/nips/nip59.d.mts +1 -1
- package/dist/nips/nip59.mjs +14 -11
- package/dist/nips/nip59.mjs.map +1 -1
- package/dist/nips/nip65.d.mts +1 -1
- package/dist/nips/nip65.mjs +2 -2
- package/dist/nips/nip77.d.mts +1 -1
- package/dist/nips/nip77.mjs +2 -2
- package/dist/nips/nip77.mjs.map +1 -1
- package/dist/nips/nip98.d.mts +1 -1
- package/dist/nips/nip98.mjs +5 -5
- package/dist/nips/nip98.mjs.map +1 -1
- package/dist/{pool-MehgIIzm.d.mts → pool-BMfTQZjM.d.mts} +5 -4
- package/dist/{pool-lMT_mvzn.mjs → pool-D13eVCqc.mjs} +5 -5
- package/dist/{pool-lMT_mvzn.mjs.map → pool-D13eVCqc.mjs.map} +1 -1
- package/dist/{put-BEM5j8xK.mjs → put-DuymazkT.mjs} +5 -5
- package/dist/put-DuymazkT.mjs.map +1 -0
- package/dist/{reactive-B7lPFgTS.d.mts → reactive-BkzOsSwU.d.mts} +3 -3
- package/dist/{reactive-DFHY-f00.mjs → reactive-C0-rTqN9.mjs} +10 -9
- package/dist/reactive-C0-rTqN9.mjs.map +1 -0
- package/dist/{relay-DIR77xQ2.mjs → relay-CbgToreY.mjs} +6 -6
- package/dist/{relay-DIR77xQ2.mjs.map → relay-CbgToreY.mjs.map} +1 -1
- package/dist/relay.d.mts +3 -3
- package/dist/relay.mjs +2 -2
- package/dist/{signer-DJcmC4nA.mjs → signer-DQzjm3pt.mjs} +119 -77
- package/dist/signer-DQzjm3pt.mjs.map +1 -0
- package/dist/signer.d.mts +2 -2
- package/dist/signer.mjs +2 -2
- package/dist/{storage-n2BE1bdY.mjs → storage-DvDAuxzC.mjs} +26 -41
- package/dist/storage-DvDAuxzC.mjs.map +1 -0
- package/dist/storage.d.mts +3 -3
- package/dist/storage.mjs +4 -4
- package/dist/store.d.mts +1 -1
- package/dist/store.mjs +1 -2
- package/dist/testing.d.mts +2 -2
- package/dist/testing.mjs +7 -7
- package/dist/{types-DiVVyf1e.d.mts → types-COupAqtN.d.mts} +2 -2
- package/dist/{types-BJ4wZ7JJ.d.mts → types-DF8yT6EG.d.mts} +7 -1
- package/dist/{util-DfsyJ9nz.mjs → util-BcRBO6o-.mjs} +18 -3
- package/dist/util-BcRBO6o-.mjs.map +1 -0
- package/dist/{verifier-DEHUy4AD.mjs → verifier-DBSPHzGg.mjs} +6 -15
- package/dist/verifier-DBSPHzGg.mjs.map +1 -0
- package/dist/verifier-Or2nDvHb.d.mts +16 -0
- package/package.json +3 -3
- package/dist/client-COkEihj_.mjs.map +0 -1
- package/dist/event-DvM1f03b.mjs.map +0 -1
- package/dist/filter-3jOh4uLN.mjs.map +0 -1
- package/dist/gossip-CRyhK6E6.mjs.map +0 -1
- package/dist/key-D_oEutQ6.mjs.map +0 -1
- package/dist/loaders-BRh2riV9.mjs.map +0 -1
- package/dist/memory-index-3GSrPIWj.mjs.map +0 -1
- package/dist/message-BMfreCQc.mjs.map +0 -1
- package/dist/put-BEM5j8xK.mjs.map +0 -1
- package/dist/reactive-DFHY-f00.mjs.map +0 -1
- package/dist/signer-DJcmC4nA.mjs.map +0 -1
- package/dist/storage-n2BE1bdY.mjs.map +0 -1
- package/dist/util-DfsyJ9nz.mjs.map +0 -1
- package/dist/verifier-DEHUy4AD.mjs.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-DHtcm0jM.mjs","names":[],"sources":["../src/core/tag.ts","../src/core/event.ts"],"sourcesContent":["import { isAddressableKind, isReplaceableKind } from \"./kind.ts\";\nimport { isHex32, lowerAscii } from \"./util.ts\";\n\n/** A NIP-01 tag: first element is the name, rest are values. */\nexport type Tag = ReadonlyArray<string>;\n\n/** Mutable tag builder input. */\nexport type TagInput = string[];\n\n/** Type guard: a non-empty array of strings. */\nexport function isTag(value: unknown): value is Tag {\n if (!Array.isArray(value) || value.length === 0) {\n return false;\n }\n for (const item of value) {\n if (typeof item !== \"string\") {\n return false;\n }\n }\n return true;\n}\n\n/** First element of a tag (its name). */\nexport function tagName(tag: Tag): string {\n return tag[0] ?? \"\";\n}\n\n/** Second element of a tag (its primary value), or undefined for a bare name tag. */\nexport function tagValue(tag: Tag): string | undefined {\n return tag[1];\n}\n\n/**\n * Push positional tag values: \"\" for absent slots before a present one, trailing absent slots\n * omitted.\n */\nfunction pushPositions(t: string[], positions: Array<string | undefined>): void {\n let end = positions.length;\n while (end > 0 && positions[end - 1] === undefined) {\n end -= 1;\n }\n for (let i = 0; i < end; i += 1) {\n t.push(positions[i] ?? \"\");\n }\n}\n\n/** Construct common tags. */\nexport const Tag = {\n e(id: string, relay?: string, marker?: string, pubkey?: string): Tag {\n const t: string[] = [\"e\", lowerAscii(id)];\n pushPositions(t, [relay, marker, pubkey?.toLowerCase()]);\n return t;\n },\n p(pubkey: string, relay?: string, petname?: string): Tag {\n const t: string[] = [\"p\", pubkey.toLowerCase()];\n pushPositions(t, [relay, petname]);\n return t;\n },\n a(coordinate: string, relay?: string): Tag {\n const t: string[] = [\"a\", coordinate];\n if (relay !== undefined) {\n t.push(relay);\n }\n return t;\n },\n d(identifier: string): Tag {\n return [\"d\", identifier];\n },\n t(hashtag: string): Tag {\n return [\"t\", hashtag];\n },\n r(url: string, marker?: string): Tag {\n const t: string[] = [\"r\", url];\n if (marker !== undefined) {\n t.push(marker);\n }\n return t;\n },\n k(kind: number | string): Tag {\n return [\"k\", String(kind)];\n },\n} as const;\n\n/** First tag value with the given name, or undefined when no such tag has a value. */\nexport function firstTagValue(tags: ReadonlyArray<Tag>, name: string): string | undefined {\n for (const tag of tags) {\n if (tag[0] === name && tag[1] !== undefined) {\n return tag[1];\n }\n }\n return undefined;\n}\n\n/** First `d` tag value on an event, if any. */\nexport function getDTag(tags: ReadonlyArray<Tag>): string | undefined {\n return firstTagValue(tags, \"d\");\n}\n\n/** NIP-01 `a` tag: `kind:pubkey:identifier` (identifier may be empty and may contain extra colons). */\nexport type EventAddress = {\n kind: number;\n pubkey: string;\n identifier: string;\n};\n\n/** Parse a NIP-01 addressable/replaceable coordinate. */\nexport function parseEventAddress(value: string): EventAddress | undefined {\n const first = value.indexOf(\":\");\n if (first <= 0) {\n return undefined;\n }\n const second = value.indexOf(\":\", first + 1);\n if (second === -1) {\n return undefined;\n }\n const kindText = value.slice(0, first);\n // Strict decimal: Number() also accepts \"1e4\", \"0x10\", \" 1\", \"+1\" — none are NIP-19 kinds.\n if (!/^\\d{1,5}$/.test(kindText)) {\n return undefined;\n }\n const kind = Number(kindText);\n if (kind > 65535) {\n return undefined;\n }\n const pubkey = value.slice(first + 1, second);\n if (!isHex32(pubkey)) {\n return undefined;\n }\n return { kind, pubkey, identifier: value.slice(second + 1) };\n}\n\n/**\n * Caller-input form of {@link parseEventAddress}: the pubkey segment accepts any hex case; the\n * case-sensitive `d` identifier stays verbatim. Protocol text must use {@link parseEventAddress},\n * which is lowercase-only.\n */\nexport function parseEventAddressInput(value: string): EventAddress | undefined {\n const first = value.indexOf(\":\");\n const second = first === -1 ? -1 : value.indexOf(\":\", first + 1);\n if (second < 0) {\n return undefined;\n }\n return parseEventAddress(\n `${value.slice(0, first + 1)}${value.slice(first + 1, second).toLowerCase()}${value.slice(second)}`,\n );\n}\n\n/** Format an address as a `kind:pubkey:dTag` coordinate string. */\nexport function formatEventAddress(kind: number, pubkey: string, identifier = \"\"): string {\n return `${kind}:${pubkey.toLowerCase()}:${identifier}`;\n}\n\n/**\n * Coordinate for replaceable (`kind:pubkey:`) and addressable (`kind:pubkey:d`) events. Undefined\n * for regular/ephemeral kinds.\n */\nexport function eventAddress(event: {\n kind: number;\n pubkey: string;\n tags: ReadonlyArray<Tag>;\n}): string | undefined {\n if (isAddressableKind(event.kind)) {\n return formatEventAddress(event.kind, event.pubkey, getDTag(event.tags) ?? \"\");\n }\n if (isReplaceableKind(event.kind)) {\n return formatEventAddress(event.kind, event.pubkey, \"\");\n }\n return undefined;\n}\n","import { sha256 } from \"@noble/hashes/sha2.js\";\n\nimport { EventValidationError } from \"./error.ts\";\nimport type { Tag } from \"./tag.ts\";\nimport { isTag } from \"./tag.ts\";\nimport { bytesToHex, hasLoneSurrogate, isHex32, isHex64, isRecord, utf8Encoder } from \"./util.ts\";\n\n/** Wire event template before pubkey/id/sig. */\nexport type EventTemplate = {\n readonly kind: number;\n readonly tags: ReadonlyArray<Tag>;\n readonly content: string;\n readonly created_at: number;\n};\n\n/** Event with pubkey, ready to hash and sign. */\nexport type UnsignedEvent = EventTemplate & {\n readonly pubkey: string;\n};\n\n/**\n * Fully formed NIP-01 event (JSON-friendly plain object). Fields are readonly at the type level;\n * wire interop remains plain JSON.\n */\nexport type Event = UnsignedEvent & {\n readonly id: string;\n readonly sig: string;\n};\n\n/** Cache of events whose signatures have been verified successfully. */\nconst verifiedEvents = new WeakSet<Event>();\n\n/** Cache of events known to fail verification. */\nconst failedEvents = new WeakSet<Event>();\n\n/** Cache of object identities that already passed {@link validateSignedEvent}. */\nconst validatedEvents = new WeakSet<Record<string, unknown>>();\n\nexport function markVerified(event: Event): void {\n verifiedEvents.add(event);\n failedEvents.delete(event);\n}\n\nexport function markUnverified(event: Event): void {\n failedEvents.add(event);\n verifiedEvents.delete(event);\n}\n\nexport function isMarkedVerified(event: Event): boolean {\n return verifiedEvents.has(event);\n}\n\nexport function isMarkedFailed(event: Event): boolean {\n return failedEvents.has(event);\n}\n\n/** Structural validation of an unsigned event (no crypto). */\nexport function validateEvent(event: unknown): event is UnsignedEvent {\n if (!isRecord(event)) {\n return false;\n }\n if (\n typeof event[\"kind\"] !== \"number\" ||\n !Number.isSafeInteger(event[\"kind\"]) ||\n event[\"kind\"] < 0 ||\n event[\"kind\"] > 65535\n ) {\n return false;\n }\n // Lone surrogates are rejected per NIP-01: after JSON.parse they differ from\n // what serde_json (and thus Rust) can express, so the event id would diverge.\n if (typeof event[\"content\"] !== \"string\" || hasLoneSurrogate(event[\"content\"])) {\n return false;\n }\n if (\n typeof event[\"created_at\"] !== \"number\" ||\n !Number.isSafeInteger(event[\"created_at\"]) ||\n event[\"created_at\"] < 0\n ) {\n return false;\n }\n if (typeof event[\"pubkey\"] !== \"string\" || !isHex32(event[\"pubkey\"])) {\n return false;\n }\n if (!Array.isArray(event[\"tags\"])) {\n return false;\n }\n for (const tag of event[\"tags\"]) {\n if (!isTag(tag)) {\n return false;\n }\n for (const item of tag) {\n if (hasLoneSurrogate(item)) {\n return false;\n }\n }\n }\n return true;\n}\n\n/** Structural validation of a full event including id and sig hex shape. */\nexport function validateSignedEvent(event: unknown): event is Event {\n if (isRecord(event) && validatedEvents.has(event)) {\n return true;\n }\n if (!validateEvent(event)) {\n return false;\n }\n const e = event as Record<string, unknown>;\n if (typeof e[\"id\"] !== \"string\" || !isHex32(e[\"id\"])) {\n return false;\n }\n if (typeof e[\"sig\"] !== \"string\" || !isHex64(e[\"sig\"])) {\n return false;\n }\n validatedEvents.add(e);\n return true;\n}\n\n/**\n * Canonical NIP-01 serialization used for hashing: JSON array `[0, pubkey, created_at, kind, tags,\n * content]` with no extra whitespace.\n */\nexport function serializeEvent(event: UnsignedEvent): string {\n if (!validateEvent(event)) {\n throw new EventValidationError(\"cannot serialize event with invalid shape\");\n }\n return serializeValidatedEvent(event);\n}\n\n/**\n * Canonical serialization for an event already known valid (after {@link validateEvent} or\n * {@link validateSignedEvent}); identical output to {@link serializeEvent} without re-walking the\n * structural checks.\n */\nexport function serializeValidatedEvent(event: UnsignedEvent): string {\n return JSON.stringify([0, event.pubkey, event.created_at, event.kind, event.tags, event.content]);\n}\n\n/** SHA-256 of the canonical serialization, lowercase hex. */\nexport function getEventHash(event: UnsignedEvent): string {\n const serialized = serializeEvent(event);\n return bytesToHex(sha256(utf8Encoder.encode(serialized)));\n}\n\n/** Id tie-break: plain code-unit order (ids are canonical lowercase hex, so `<` is lexical). */\nfunction compareIds(a: { id: string }, b: { id: string }): number {\n if (a.id < b.id) {\n return -1;\n }\n if (a.id > b.id) {\n return 1;\n }\n return 0;\n}\n\n/**\n * NIP-01 newest-first order: `created_at` descending, then `id` in plain code-unit order (ids are\n * canonical lowercase hex, so `<` is lexical order).\n */\nexport function compareEventsDesc(\n a: { id: string; created_at: number },\n b: { id: string; created_at: number },\n): number {\n if (a.created_at !== b.created_at) {\n return b.created_at - a.created_at;\n }\n return compareIds(a, b);\n}\n\n/**\n * Sort events reverse-chronologically by `created_at`, then by `id` lexicographically. Mutates and\n * returns the array.\n */\nexport function sortEvents(events: Event[]): Event[] {\n return events.sort(compareEventsDesc);\n}\n\n/** Non-mutating sort; returns a new array. */\nexport function sortedEvents(events: ReadonlyArray<Event>): Event[] {\n return [...events].sort(compareEventsDesc);\n}\n\n/**\n * Negentropy item order: `created_at` ascending, then `id` lexicographic (`<`/`>`). Time axis is\n * opposite {@link sortEvents}; id tie-break is the same direction.\n */\nexport function itemCompare(\n a: { id: string; created_at: number },\n b: { id: string; created_at: number },\n): number {\n if (a.created_at !== b.created_at) {\n return a.created_at - b.created_at;\n }\n return compareIds(a, b);\n}\n\n/**\n * NIP-01 replaceable/addressable winner: higher `created_at`, or equal timestamp and\n * lexicographically lower `id`.\n */\nexport function isReplaceableWinner(\n candidate: { created_at: number; id: string },\n incumbent: { created_at: number; id: string },\n): boolean {\n if (candidate.created_at !== incumbent.created_at) {\n return candidate.created_at > incumbent.created_at;\n }\n return candidate.id < incumbent.id;\n}\n\n/** True when a signed event is the signed form of `unsigned` (kind/tags/content/time/pubkey). */\nexport function signedMatchesUnsigned(signed: Event, unsigned: UnsignedEvent): boolean {\n if (signed.kind !== unsigned.kind) {\n return false;\n }\n if (signed.content !== unsigned.content) {\n return false;\n }\n if (signed.created_at !== unsigned.created_at) {\n return false;\n }\n if (JSON.stringify(signed.tags) !== JSON.stringify(unsigned.tags)) {\n return false;\n }\n if (unsigned.pubkey && signed.pubkey !== unsigned.pubkey) {\n return false;\n }\n return true;\n}\n"],"mappings":";;;;;AAUA,SAAgB,MAAM,OAA8B;CAClD,IAAI,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Ae,UAAU,YACrC,OAAO,UAAU,aAAa,UAAU;CAE1C,OAAO,UAAU,KAAK,UAAU;AAClC;;AAGA,SAAgB,sBAAsB,QAAe,UAAkC;CACrF,IAAI,OAAO,SAAS,SAAS,MAC3B,OAAO;CAET,IAAI,OAAO,YAAY,SAAS,SAC9B,OAAO;CAET,IAAI,OAAO,eAAe,SAAS,YACjC,OAAO;CAET,IAAI,KAAK,UAAU,OAAO,IAAI,MAAM,KAAK,UAAU,SAAS,IAAI,GAC9D,OAAO;CAET,IAAI,SAAS,UAAU,OAAO,WAAW,SAAS,QAChD,OAAO;CAET,OAAO;AACT"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { c as isHex32, x as FilterError } from "./util-BcRBO6o-.mjs";
|
|
1
2
|
import { o as isReplaceableKind, r as isAddressableKind } from "./kind-I2Tvbe82.mjs";
|
|
2
3
|
//#region src/core/filter.ts
|
|
3
4
|
/** NIP-01 only defines single-letter tag conditions. */
|
|
@@ -10,30 +11,32 @@ const compiledFilters = /* @__PURE__ */ new WeakMap();
|
|
|
10
11
|
* package; not exported from the index.
|
|
11
12
|
*/
|
|
12
13
|
function filterTagConditions(filter) {
|
|
14
|
+
const canonical = canonicalizeFilter(filter);
|
|
13
15
|
const conditions = [];
|
|
14
|
-
for (const key of Object.keys(
|
|
16
|
+
for (const key of Object.keys(canonical)) {
|
|
15
17
|
if (!SINGLE_LETTER_TAG.test(key)) continue;
|
|
16
18
|
const name = key.slice(1);
|
|
17
|
-
const values =
|
|
19
|
+
const values = canonical[`#${name}`];
|
|
18
20
|
if (values === void 0) continue;
|
|
19
21
|
conditions.push({
|
|
20
22
|
name,
|
|
21
|
-
values
|
|
23
|
+
values
|
|
22
24
|
});
|
|
23
25
|
}
|
|
24
26
|
return conditions;
|
|
25
27
|
}
|
|
26
28
|
function compileFilter(filter) {
|
|
29
|
+
const canonical = canonicalizeFilter(filter);
|
|
27
30
|
return {
|
|
28
|
-
ids:
|
|
29
|
-
kinds:
|
|
30
|
-
authors:
|
|
31
|
-
tags: filterTagConditions(
|
|
31
|
+
ids: canonical.ids ? new Set(canonical.ids) : void 0,
|
|
32
|
+
kinds: canonical.kinds ? new Set(canonical.kinds) : void 0,
|
|
33
|
+
authors: canonical.authors ? new Set(canonical.authors) : void 0,
|
|
34
|
+
tags: filterTagConditions(canonical).map(({ name, values }) => ({
|
|
32
35
|
name,
|
|
33
36
|
values: new Set(values)
|
|
34
37
|
})),
|
|
35
|
-
since:
|
|
36
|
-
until:
|
|
38
|
+
since: canonical.since,
|
|
39
|
+
until: canonical.until
|
|
37
40
|
};
|
|
38
41
|
}
|
|
39
42
|
/** Local NIP-01 match. `search` is ignored; relays interpret NIP-50. */
|
|
@@ -64,19 +67,16 @@ function matchFilters(filters, event) {
|
|
|
64
67
|
* unbounded.
|
|
65
68
|
*/
|
|
66
69
|
function getFilterLimit(filter) {
|
|
67
|
-
|
|
68
|
-
if (filter.kinds && filter.kinds.length === 0) return 0;
|
|
69
|
-
if (filter.authors && filter.authors.length === 0) return 0;
|
|
70
|
+
const f = canonicalizeFilter(filter);
|
|
70
71
|
let limit = Number.POSITIVE_INFINITY;
|
|
71
|
-
if (
|
|
72
|
-
if (
|
|
73
|
-
if (
|
|
74
|
-
const kinds = new Set(
|
|
72
|
+
if (f.ids) limit = Math.min(limit, new Set(f.ids).size);
|
|
73
|
+
if (f.limit !== void 0) limit = Math.min(limit, f.limit);
|
|
74
|
+
if (f.kinds && f.authors) {
|
|
75
|
+
const kinds = new Set(f.kinds);
|
|
75
76
|
if ([...kinds].every((k) => isReplaceableKind(k) || isAddressableKind(k))) {
|
|
76
|
-
const dTags =
|
|
77
|
-
const perAuthor = dTags
|
|
78
|
-
|
|
79
|
-
limit = Math.min(limit, authors * kinds.size * perAuthor);
|
|
77
|
+
const dTags = f["#d"];
|
|
78
|
+
const perAuthor = dTags === void 0 ? 1 : new Set(dTags).size;
|
|
79
|
+
limit = Math.min(limit, f.authors.length * kinds.size * perAuthor);
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
return limit;
|
|
@@ -98,9 +98,11 @@ const KNOWN_FILTER_KEYS = /* @__PURE__ */ new Set([
|
|
|
98
98
|
"search"
|
|
99
99
|
]);
|
|
100
100
|
/**
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
101
|
+
* The caller-input normalizer shared by `matchFilter`, the stores, `encodeClientMessage`,
|
|
102
|
+
* `canonicalizeFilter` and `filterFingerprint`: known fields kept, hex lists lowercased, every list
|
|
103
|
+
* sorted and deduplicated — then validated. Throws {@link FilterError} when any list is empty or
|
|
104
|
+
* when an `ids`/`authors`/`#e`/`#p` value is not 64-hex (the caller-input hex profile: any case in,
|
|
105
|
+
* lowercase out).
|
|
104
106
|
*/
|
|
105
107
|
function canonicalizeFilter(filter) {
|
|
106
108
|
const raw = filter;
|
|
@@ -112,8 +114,12 @@ function canonicalizeFilter(filter) {
|
|
|
112
114
|
const value = raw[key];
|
|
113
115
|
if (value === void 0) continue;
|
|
114
116
|
if (Array.isArray(value)) {
|
|
115
|
-
if (
|
|
116
|
-
|
|
117
|
+
if (value.length === 0) throw new FilterError(`filter ${key} must not be empty`);
|
|
118
|
+
if (HEX_LIST_KEYS.has(key)) {
|
|
119
|
+
const list = [...new Set(value.map((v) => String(v).toLowerCase()))].sort();
|
|
120
|
+
if (!list.every((v) => isHex32(v))) throw new FilterError(`filter ${key} values must be 64-char hex`);
|
|
121
|
+
out[key] = list;
|
|
122
|
+
} else if (key === "kinds") out[key] = [...new Set(value.map(Number))].sort((a, b) => a - b);
|
|
117
123
|
else out[key] = [...new Set(value.map(String))].sort();
|
|
118
124
|
} else out[key] = value;
|
|
119
125
|
}
|
|
@@ -124,8 +130,8 @@ function canonicalizeFilters(filters) {
|
|
|
124
130
|
return filters.map(canonicalizeFilter);
|
|
125
131
|
}
|
|
126
132
|
/**
|
|
127
|
-
* Canonical identity for live REQ coalescing.
|
|
128
|
-
* `
|
|
133
|
+
* Canonical identity for live REQ coalescing. Filters carry no empty list fields —
|
|
134
|
+
* `canonicalizeFilter` rejects them.
|
|
129
135
|
*/
|
|
130
136
|
function filterFingerprint(filters) {
|
|
131
137
|
const parts = filters.map((filter) => JSON.stringify(canonicalizeFilter(filter)));
|
|
@@ -135,4 +141,4 @@ function filterFingerprint(filters) {
|
|
|
135
141
|
//#endregion
|
|
136
142
|
export { getFilterLimit as a, filterTagConditions as i, canonicalizeFilters as n, matchFilter as o, filterFingerprint as r, matchFilters as s, canonicalizeFilter as t };
|
|
137
143
|
|
|
138
|
-
//# sourceMappingURL=filter-
|
|
144
|
+
//# sourceMappingURL=filter-BbShkmc4.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filter-BbShkmc4.mjs","names":[],"sources":["../src/core/filter.ts"],"sourcesContent":["import { FilterError } from \"./error.ts\";\nimport type { Event } from \"./event.ts\";\nimport { isAddressableKind, isReplaceableKind } from \"./kind.ts\";\nimport { isHex32 } from \"./util.ts\";\n\n/**\n * NIP-01 filter object (immutable-friendly; callers may still pass plain objects). Filters are\n * treated as immutable once used: `matchFilter` and the event stores cache a compiled form keyed on\n * the object, so mutating a filter after it has been matched yields stale results.\n */\nexport type Filter = {\n readonly ids?: ReadonlyArray<string> | undefined;\n readonly kinds?: ReadonlyArray<number> | undefined;\n readonly authors?: ReadonlyArray<string> | undefined;\n readonly since?: number | undefined;\n readonly until?: number | undefined;\n readonly limit?: number | undefined;\n /** NIP-50 full-text search. Relays interpret this. Local `matchFilter` / `query` ignore it. */\n readonly search?: string | undefined;\n readonly [key: `#${string}`]: ReadonlyArray<string> | undefined;\n};\n\n/** NIP-01 only defines single-letter tag conditions. */\nconst SINGLE_LETTER_TAG = /^#[a-zA-Z]$/;\n\ntype CompiledTagCondition = {\n readonly name: string;\n readonly values: ReadonlySet<string>;\n};\n\n/** `matchFilter` condition form: `Set` lookups instead of per-element scans and `toLowerCase`. */\ntype CompiledFilter = {\n readonly ids: ReadonlySet<string> | undefined;\n readonly kinds: ReadonlySet<number> | undefined;\n readonly authors: ReadonlySet<string> | undefined;\n readonly tags: ReadonlyArray<CompiledTagCondition>;\n readonly since: number | undefined;\n readonly until: number | undefined;\n};\n\nconst compiledFilters = new WeakMap<Filter, CompiledFilter>();\n\n/**\n * Single-letter `#x` conditions shared by `matchFilter` and the event stores: `#e`/`#p` values are\n * lowercased (they hold hex ids, same as `encodeClientMessage`), other tag values stay verbatim —\n * relays match tag values literally. Multi-letter `#` keys are outside NIP-01. Internal to the\n * package; not exported from the index.\n */\nexport function filterTagConditions(\n filter: Filter,\n): Array<{ name: string; values: ReadonlyArray<string> }> {\n const canonical = canonicalizeFilter(filter);\n const conditions: Array<{ name: string; values: ReadonlyArray<string> }> = [];\n for (const key of Object.keys(canonical)) {\n if (!SINGLE_LETTER_TAG.test(key)) {\n continue;\n }\n const name = key.slice(1);\n const values = canonical[`#${name}`];\n if (values === undefined) {\n continue;\n }\n conditions.push({ name, values });\n }\n return conditions;\n}\n\nfunction compileFilter(filter: Filter): CompiledFilter {\n const canonical = canonicalizeFilter(filter);\n return {\n ids: canonical.ids ? new Set(canonical.ids) : undefined,\n kinds: canonical.kinds ? new Set(canonical.kinds) : undefined,\n authors: canonical.authors ? new Set(canonical.authors) : undefined,\n tags: filterTagConditions(canonical).map(({ name, values }) => ({\n name,\n values: new Set(values),\n })),\n since: canonical.since,\n until: canonical.until,\n };\n}\n\n/** Local NIP-01 match. `search` is ignored; relays interpret NIP-50. */\nexport function matchFilter(filter: Filter, event: Event): boolean {\n let compiled = compiledFilters.get(filter);\n if (compiled === undefined) {\n compiled = compileFilter(filter);\n compiledFilters.set(filter, compiled);\n }\n if (compiled.ids !== undefined && !compiled.ids.has(event.id)) {\n return false;\n }\n if (compiled.kinds !== undefined && !compiled.kinds.has(event.kind)) {\n return false;\n }\n if (compiled.authors !== undefined && !compiled.authors.has(event.pubkey)) {\n return false;\n }\n\n for (const { name, values } of compiled.tags) {\n const hit = event.tags.some((tag) => {\n const [tagKey, tagValue] = tag;\n return tagKey === name && tagValue !== undefined && values.has(tagValue);\n });\n if (!hit) {\n return false;\n }\n }\n\n if (compiled.since !== undefined && event.created_at < compiled.since) {\n return false;\n }\n if (compiled.until !== undefined && event.created_at > compiled.until) {\n return false;\n }\n\n return true;\n}\n\n/** True when the event matches any of the filters (NIP-01 OR semantics). */\nexport function matchFilters(filters: ReadonlyArray<Filter>, event: Event): boolean {\n for (const filter of filters) {\n if (matchFilter(filter, event)) {\n return true;\n }\n }\n return false;\n}\n\n/**\n * Intrinsic upper bound implied by the filter alone. Returns a positive integer, or `Infinity` when\n * unbounded.\n */\nexport function getFilterLimit(filter: Filter): number {\n const f = canonicalizeFilter(filter);\n let limit = Number.POSITIVE_INFINITY;\n if (f.ids) {\n limit = Math.min(limit, new Set(f.ids).size);\n }\n if (f.limit !== undefined) {\n limit = Math.min(limit, f.limit);\n }\n\n if (f.kinds && f.authors) {\n const kinds = new Set(f.kinds);\n const allReplaceable = [...kinds].every((k) => isReplaceableKind(k) || isAddressableKind(k));\n if (allReplaceable) {\n const dTags = f[\"#d\"];\n const perAuthor = dTags === undefined ? 1 : new Set(dTags).size;\n limit = Math.min(limit, f.authors.length * kinds.size * perAuthor);\n }\n }\n\n return limit;\n}\n\nconst HEX_LIST_KEYS = new Set([\"ids\", \"authors\", \"#e\", \"#p\"]);\n\n/** NIP-01 known fields; everything else (incl. multi-letter `#` keys) is dropped. */\nconst KNOWN_FILTER_KEYS = new Set([\"ids\", \"authors\", \"kinds\", \"since\", \"until\", \"limit\", \"search\"]);\n\n/**\n * The caller-input normalizer shared by `matchFilter`, the stores, `encodeClientMessage`,\n * `canonicalizeFilter` and `filterFingerprint`: known fields kept, hex lists lowercased, every list\n * sorted and deduplicated — then validated. Throws {@link FilterError} when any list is empty or\n * when an `ids`/`authors`/`#e`/`#p` value is not 64-hex (the caller-input hex profile: any case in,\n * lowercase out).\n */\nexport function canonicalizeFilter(filter: Filter): Filter {\n const raw = filter as Record<string, unknown>;\n const out: Record<string, unknown> = {};\n for (const key of Object.keys(raw).sort()) {\n if (key.startsWith(\"#\")) {\n if (!SINGLE_LETTER_TAG.test(key)) {\n continue;\n }\n } else if (!KNOWN_FILTER_KEYS.has(key)) {\n continue;\n }\n const value = raw[key];\n if (value === undefined) {\n continue;\n }\n if (Array.isArray(value)) {\n if (value.length === 0) {\n throw new FilterError(`filter ${key} must not be empty`);\n }\n if (HEX_LIST_KEYS.has(key)) {\n const list = [...new Set(value.map((v) => String(v).toLowerCase()))].sort();\n if (!list.every((v) => isHex32(v))) {\n throw new FilterError(`filter ${key} values must be 64-char hex`);\n }\n out[key] = list;\n } else if (key === \"kinds\") {\n out[key] = [...new Set(value.map(Number))].sort((a, b) => a - b);\n } else {\n out[key] = [...new Set(value.map(String))].sort();\n }\n } else {\n out[key] = value;\n }\n }\n // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- built key by key above; the record is filter-shaped by construction\n return out as Filter;\n}\n\n/** Apply {@link canonicalizeFilter} to each filter. */\nexport function canonicalizeFilters(filters: ReadonlyArray<Filter>): Filter[] {\n return filters.map(canonicalizeFilter);\n}\n\n/**\n * Canonical identity for live REQ coalescing. Filters carry no empty list fields —\n * `canonicalizeFilter` rejects them.\n */\nexport function filterFingerprint(filters: ReadonlyArray<Filter>): string {\n const parts = filters.map((filter) => JSON.stringify(canonicalizeFilter(filter)));\n parts.sort();\n return `[${parts.join(\",\")}]`;\n}\n"],"mappings":";;;;AAuBA,MAAM,oBAAoB;AAiB1B,MAAM,kCAAkB,IAAI,QAAgC;;;;;;;AAQ5D,SAAgB,oBACd,QACwD;CACxD,MAAM,YAAY,mBAAmB,MAAM;CAC3C,MAAM,aAAqE,CAAC;CAC5E,KAAK,MAAM,OAAO,OAAO,KAAK,SAAS,GAAG;EACxC,IAAI,CAAC,kBAAkB,KAAK,GAAG,GAC7B;EAEF,MAAM,OAAO,IAAI,MAAM,CAAC;EACxB,MAAM,SAAS,UAAU,IAAI;EAC7B,IAAI,WAAW,KAAA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AAI;EAClB,IAAI,UAAU,KAAA,GACZ;EAEF,IAAI,MAAM,QAAQ,KAAK,GAAG;GACxB,IAAI,MAAM,WAAW,GACnB,MAAM,IAAI,YAAY,UAAU,IAAI,mBAAmB;GAEzD,IAAI,cAAc,IAAI,GAAG,GAAG;IAC1B,MAAM,OAAO,CAAC,GAAG,IAAI,IAAI,MAAM,KAAK,MAAM,OAAO,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK;IAC1E,IAAI,CAAC,KAAK,OAAO,MAAM,QAAQ,CAAC,CAAC,GAC/B,MAAM,IAAI,YAAY,UAAU,IAAI,4BAA4B;IAElE,IAAI,OAAO;GACb,OAAO,IAAI,QAAQ,SACjB,IAAI,OAAO,CAAC,GAAG,IAAI,IAAI,MAAM,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,GAAG,MAAM,IAAI,CAAC;QAE/D,IAAI,OAAO,CAAC,GAAG,IAAI,IAAI,MAAM,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK;EAEpD,OACE,IAAI,OAAO;CAEf;CAEA,OAAO;AACT;;AAGA,SAAgB,oBAAoB,SAA0C;CAC5E,OAAO,QAAQ,IAAI,kBAAkB;AACvC;;;;;AAMA,SAAgB,kBAAkB,SAAwC;CACxE,MAAM,QAAQ,QAAQ,KAAK,WAAW,KAAK,UAAU,mBAAmB,MAAM,CAAC,CAAC;CAChF,MAAM,KAAK;CACX,OAAO,IAAI,MAAM,KAAK,GAAG,EAAE;AAC7B"}
|
|
@@ -26,18 +26,20 @@ declare function matchFilters(filters: ReadonlyArray<Filter>, event: Event): boo
|
|
|
26
26
|
*/
|
|
27
27
|
declare function getFilterLimit(filter: Filter): number;
|
|
28
28
|
/**
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
29
|
+
* The caller-input normalizer shared by `matchFilter`, the stores, `encodeClientMessage`,
|
|
30
|
+
* `canonicalizeFilter` and `filterFingerprint`: known fields kept, hex lists lowercased, every list
|
|
31
|
+
* sorted and deduplicated — then validated. Throws {@link FilterError} when any list is empty or
|
|
32
|
+
* when an `ids`/`authors`/`#e`/`#p` value is not 64-hex (the caller-input hex profile: any case in,
|
|
33
|
+
* lowercase out).
|
|
32
34
|
*/
|
|
33
35
|
declare function canonicalizeFilter(filter: Filter): Filter;
|
|
34
36
|
/** Apply {@link canonicalizeFilter} to each filter. */
|
|
35
37
|
declare function canonicalizeFilters(filters: ReadonlyArray<Filter>): Filter[];
|
|
36
38
|
/**
|
|
37
|
-
* Canonical identity for live REQ coalescing.
|
|
38
|
-
* `
|
|
39
|
+
* Canonical identity for live REQ coalescing. Filters carry no empty list fields —
|
|
40
|
+
* `canonicalizeFilter` rejects them.
|
|
39
41
|
*/
|
|
40
42
|
declare function filterFingerprint(filters: ReadonlyArray<Filter>): string;
|
|
41
43
|
//#endregion
|
|
42
44
|
export { getFilterLimit as a, filterFingerprint as i, canonicalizeFilter as n, matchFilter as o, canonicalizeFilters as r, matchFilters as s, Filter as t };
|
|
43
|
-
//# sourceMappingURL=filter-
|
|
45
|
+
//# sourceMappingURL=filter-w1R-mU63.d.mts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as Event } from "./event-j3BwI5dF.mjs";
|
|
2
|
-
import { t as Filter } from "./filter-
|
|
3
|
-
import { t as RelayListItem } from "./nip65-
|
|
2
|
+
import { t as Filter } from "./filter-w1R-mU63.mjs";
|
|
3
|
+
import { t as RelayListItem } from "./nip65-XrBjV9WM.mjs";
|
|
4
4
|
//#region src/gossip/gossip.d.ts
|
|
5
5
|
/** Relay routing state for one pubkey: NIP-65 outbox/inbox plus NIP-17 DM relays. */
|
|
6
6
|
type PubkeyRoutes = {
|
|
@@ -82,4 +82,4 @@ declare class Gossip {
|
|
|
82
82
|
}
|
|
83
83
|
//#endregion
|
|
84
84
|
export { RoutedFilter as i, GossipOptions as n, PubkeyRoutes as r, Gossip as t };
|
|
85
|
-
//# sourceMappingURL=gossip-
|
|
85
|
+
//# sourceMappingURL=gossip-C-7WhJ7v.d.mts.map
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { f as normalizeRelayUrls, m as nowSeconds, p as normalizeURL } from "./util-BcRBO6o-.mjs";
|
|
2
2
|
import { t as Kind } from "./kind-I2Tvbe82.mjs";
|
|
3
|
-
import { a as isReplaceableWinner } from "./event-
|
|
3
|
+
import { a as isReplaceableWinner } from "./event-DHtcm0jM.mjs";
|
|
4
|
+
import { t as canonicalizeFilter } from "./filter-BbShkmc4.mjs";
|
|
4
5
|
import { parseRelayList } from "./nips/nip65.mjs";
|
|
5
6
|
import { i as trimOldest, r as touchKey } from "./collections-DtwMc1NU.mjs";
|
|
6
7
|
import { parseDmRelayList } from "./nips/nip17.mjs";
|
|
@@ -141,16 +142,17 @@ var Gossip = class {
|
|
|
141
142
|
* - Mixed → remainder is the narrowed leftover; all routed → no remainder
|
|
142
143
|
*/
|
|
143
144
|
route(filter) {
|
|
144
|
-
const
|
|
145
|
-
const
|
|
146
|
-
|
|
145
|
+
const f = canonicalizeFilter(filter);
|
|
146
|
+
const { authors } = f;
|
|
147
|
+
const pTags = f["#p"];
|
|
148
|
+
if (authors === void 0 && pTags === void 0) return {
|
|
147
149
|
perRelay: /* @__PURE__ */ new Map(),
|
|
148
|
-
remainder:
|
|
150
|
+
remainder: f
|
|
149
151
|
};
|
|
150
|
-
if (authors
|
|
151
|
-
if (pTags
|
|
152
|
-
const { authors: _authors, ...base } =
|
|
153
|
-
return this.#breakAuthors(base, pTags, "read", (b, pubkeys) => ({
|
|
152
|
+
if (authors !== void 0 && pTags === void 0) return this.#breakAuthors(f, [...authors], "write");
|
|
153
|
+
if (pTags !== void 0 && authors === void 0) {
|
|
154
|
+
const { authors: _authors, ...base } = f;
|
|
155
|
+
return this.#breakAuthors(base, [...pTags], "read", (b, pubkeys) => ({
|
|
154
156
|
...b,
|
|
155
157
|
"#p": pubkeys
|
|
156
158
|
}));
|
|
@@ -225,4 +227,4 @@ var Gossip = class {
|
|
|
225
227
|
//#endregion
|
|
226
228
|
export { Gossip as t };
|
|
227
229
|
|
|
228
|
-
//# sourceMappingURL=gossip-
|
|
230
|
+
//# sourceMappingURL=gossip-CejMm_QM.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gossip-CejMm_QM.mjs","names":[],"sources":["../src/gossip/gossip.ts"],"sourcesContent":["import { touchKey, trimOldest } from \"../core/collections.ts\";\nimport type { Event } from \"../core/event.ts\";\nimport { isReplaceableWinner } from \"../core/event.ts\";\nimport type { Filter } from \"../core/filter.ts\";\nimport { canonicalizeFilter } from \"../core/filter.ts\";\nimport { Kind } from \"../core/kind.ts\";\nimport { normalizeRelayUrls, normalizeURL, nowSeconds } from \"../core/util.ts\";\nimport { parseDmRelayList } from \"../nips/nip17.ts\";\nimport { parseRelayList } from \"../nips/nip65.ts\";\nimport type { RelayListItem } from \"../nips/nip65.ts\";\n\n/** Relay routing state for one pubkey: NIP-65 outbox/inbox plus NIP-17 DM relays. */\nexport type PubkeyRoutes = {\n /** Relays the user writes to (outbox). NIP-65. */\n readonly write: ReadonlyArray<string>;\n /** Relays the user reads from (inbox). NIP-65. */\n readonly read: ReadonlyArray<string>;\n /** Relays for NIP-17 gift-wrap delivery. Kind 10050. */\n readonly dm: ReadonlyArray<string>;\n /** `created_at` of the last accepted kind:10002 list. */\n readonly updatedAt: number;\n /** `created_at` of the last accepted kind:10050 list. */\n readonly dmUpdatedAt: number;\n /** Event id of the last accepted kind:10002 (NIP-01 equal-timestamp tie-break). */\n readonly relayListId?: string | undefined;\n /** Event id of the last accepted kind:10050. */\n readonly dmListId?: string | undefined;\n};\n\n/** A filter split by gossip routes: per-relay narrowed filters plus the unrouted remainder. */\nexport type RoutedFilter = {\n /** Url → already-narrowed filter. Empty when nothing routed. */\n readonly perRelay: ReadonlyMap<string, Filter>;\n /**\n * Unrouted work for the caller:\n *\n * - No authors and no #p: original filter (\"generic\")\n * - Authors/#p all unrouted: original filter (\"orphan\")\n * - Mixed: narrowed leftover (\"fallback\")\n * - All routed: undefined\n */\n readonly remainder?: Filter | undefined;\n};\n\nexport type GossipOptions = {\n /**\n * Max relays kept per direction; the first N in list order win (NIP-65 defines no ranking).\n * Default 4.\n */\n maxRelaysPerPubkey?: number | undefined;\n /**\n * Max pubkeys with tracked routes; the map is LRU — writes and lookups refresh recency, and\n * inserting beyond the cap drops the oldest entry. Default 10_000.\n */\n maxPubkeys?: number | undefined;\n};\n\nfunction emptyRoutes(): PubkeyRoutes {\n return {\n write: [],\n read: [],\n dm: [],\n updatedAt: 0,\n dmUpdatedAt: 0,\n };\n}\n\n/**\n * Routing table for NIP-65 (10002) and NIP-17 DM relays (10050). Ingest replaceable list events,\n * then route filters into per-relay REQs.\n */\nexport class Gossip {\n readonly #routes = new Map<string, PubkeyRoutes>();\n readonly #maxRelays: number;\n readonly #maxPubkeys: number;\n\n constructor(opts: GossipOptions = {}) {\n this.#maxRelays = opts.maxRelaysPerPubkey ?? 4;\n this.#maxPubkeys = opts.maxPubkeys ?? 10_000;\n }\n\n /**\n * Ingest a routing list event.\n *\n * - Kind:10002 → write/read (NIP-65)\n * - Kind:10050 → dm (NIP-17)\n *\n * Returns true if routes for that list type were updated.\n */\n ingest(event: Event): boolean {\n if (event.kind === Kind.RelayList) {\n let items: RelayListItem[];\n try {\n items = parseRelayList(event);\n } catch {\n return false;\n }\n return this.setRoutes(event.pubkey, items, event.created_at, event.id);\n }\n if (event.kind === Kind.DirectMessageRelaysList) {\n let relays: string[];\n try {\n relays = parseDmRelayList(event);\n } catch {\n return false;\n }\n return this.setDmRoutes(event.pubkey, relays, event.created_at, event.id);\n }\n return false;\n }\n\n setRoutes(\n pubkey: string,\n items: ReadonlyArray<RelayListItem>,\n updatedAt: number = nowSeconds(),\n eventId?: string,\n ): boolean {\n const pk = pubkey.toLowerCase();\n const prev = this.#lookup(pk) ?? emptyRoutes();\n if (prev.updatedAt > updatedAt) {\n return false;\n }\n if (\n eventId !== undefined &&\n prev.relayListId !== undefined &&\n prev.updatedAt === updatedAt &&\n !isReplaceableWinner(\n { created_at: updatedAt, id: eventId },\n { created_at: prev.updatedAt, id: prev.relayListId },\n )\n ) {\n return false;\n }\n\n const write: string[] = [];\n const read: string[] = [];\n for (const item of items) {\n let url: string;\n try {\n url = normalizeURL(item.url);\n } catch {\n continue;\n }\n if (item.marker !== \"read\" && !write.includes(url)) {\n write.push(url);\n }\n if (item.marker !== \"write\" && !read.includes(url)) {\n read.push(url);\n }\n }\n\n this.#put(pk, {\n write: write.slice(0, this.#maxRelays),\n read: read.slice(0, this.#maxRelays),\n dm: prev.dm,\n updatedAt,\n dmUpdatedAt: prev.dmUpdatedAt,\n relayListId: eventId ?? prev.relayListId,\n dmListId: prev.dmListId,\n });\n return true;\n }\n\n setDmRoutes(\n pubkey: string,\n relays: ReadonlyArray<string>,\n updatedAt: number = nowSeconds(),\n eventId?: string,\n ): boolean {\n const pk = pubkey.toLowerCase();\n const prev = this.#lookup(pk) ?? emptyRoutes();\n if (prev.dmUpdatedAt > updatedAt) {\n return false;\n }\n if (\n eventId !== undefined &&\n prev.dmListId !== undefined &&\n prev.dmUpdatedAt === updatedAt &&\n !isReplaceableWinner(\n { created_at: updatedAt, id: eventId },\n { created_at: prev.dmUpdatedAt, id: prev.dmListId },\n )\n ) {\n return false;\n }\n\n const dm = normalizeRelayUrls(relays);\n\n this.#put(pk, {\n write: prev.write,\n read: prev.read,\n dm: dm.slice(0, this.#maxRelays),\n updatedAt: prev.updatedAt,\n dmUpdatedAt: updatedAt,\n relayListId: prev.relayListId,\n dmListId: eventId ?? prev.dmListId,\n });\n return true;\n }\n\n getRoutes(pubkey: string): Readonly<PubkeyRoutes> | undefined {\n return this.#lookup(pubkey.toLowerCase());\n }\n\n outboxRelays(pubkey: string): ReadonlyArray<string> {\n return this.#lookup(pubkey.toLowerCase())?.write ?? [];\n }\n\n inboxRelays(pubkey: string): ReadonlyArray<string> {\n return this.#lookup(pubkey.toLowerCase())?.read ?? [];\n }\n\n /** NIP-17 kind:10050 delivery relays for gift-wraps. */\n dmRelays(pubkey: string): ReadonlyArray<string> {\n return this.#lookup(pubkey.toLowerCase())?.dm ?? [];\n }\n\n clear(pubkey?: string): void {\n if (pubkey !== undefined && pubkey !== \"\") {\n this.#routes.delete(pubkey.toLowerCase());\n } else {\n this.#routes.clear();\n }\n }\n\n get size(): number {\n return this.#routes.size;\n }\n\n /**\n * Route a user-facing filter into per-relay sub-filters plus leftover.\n *\n * - Authors → outbox relays, filter narrowed per relay's authors\n * - #p only → inbox relays of those pubkeys\n * - Neither / all unrouted → remainder is the original filter\n * - Mixed → remainder is the narrowed leftover; all routed → no remainder\n */\n route(filter: Filter): RoutedFilter {\n const f = canonicalizeFilter(filter);\n const { authors } = f;\n const pTags = f[\"#p\"];\n\n if (authors === undefined && pTags === undefined) {\n return { perRelay: new Map(), remainder: f };\n }\n\n if (authors !== undefined && pTags === undefined) {\n return this.#breakAuthors(f, [...authors], \"write\");\n }\n\n if (pTags !== undefined && authors === undefined) {\n const { authors: _authors, ...base } = f;\n return this.#breakAuthors(base, [...pTags], \"read\", (b, pubkeys) => ({\n ...b,\n \"#p\": pubkeys,\n }));\n }\n\n // both authors and #p: send full filter to union of routes\n const unionKeys = new Set([...(authors ?? []), ...(pTags ?? [])]);\n const relays = new Set<string>();\n let anyUnrouted = false;\n for (const pk of unionKeys) {\n const r = this.#lookup(pk);\n const urls = r ? [...r.write, ...r.read] : [];\n if (urls.length === 0) {\n anyUnrouted = true;\n continue;\n }\n for (const u of urls) {\n relays.add(u);\n }\n }\n if (relays.size === 0) {\n return { perRelay: new Map(), remainder: filter };\n }\n const map = new Map<string, Filter>();\n for (const url of relays) {\n map.set(url, { ...filter });\n }\n return anyUnrouted ? { perRelay: map, remainder: filter } : { perRelay: map };\n }\n\n #breakAuthors(\n filter: Filter,\n pubkeys: string[],\n direction: \"read\" | \"write\",\n narrow: (base: Filter, pubkeys: string[]) => Filter = (base, pks) => ({\n ...base,\n authors: pks,\n }),\n ): RoutedFilter {\n const perRelay = new Map<string, string[]>();\n const unrouted: string[] = [];\n let anyRoute = false;\n\n for (const pk of pubkeys) {\n const routes = this.#lookup(pk);\n const urls = direction === \"write\" ? routes?.write : routes?.read;\n if (!urls || urls.length === 0) {\n unrouted.push(pk);\n continue;\n }\n anyRoute = true;\n for (const url of urls) {\n const list = perRelay.get(url) ?? [];\n list.push(pk);\n perRelay.set(url, list);\n }\n }\n\n if (!anyRoute) {\n return { perRelay: new Map(), remainder: filter };\n }\n\n const map = new Map<string, Filter>();\n for (const [url, pks] of perRelay) {\n map.set(url, narrow(filter, pks));\n }\n return unrouted.length > 0\n ? { perRelay: map, remainder: narrow(filter, unrouted) }\n : { perRelay: map };\n }\n\n /** Read that refreshes LRU recency. */\n #lookup(pk: string): PubkeyRoutes | undefined {\n const routes = this.#routes.get(pk);\n if (routes !== undefined) {\n touchKey(this.#routes, pk, routes);\n }\n return routes;\n }\n\n /** Write at the newest LRU end, then trim the oldest beyond the cap. */\n #put(pk: string, routes: PubkeyRoutes): void {\n touchKey(this.#routes, pk, routes);\n trimOldest(this.#routes, this.#maxPubkeys);\n }\n}\n"],"mappings":";;;;;;;;AAyDA,SAAS,cAA4B;CACnC,OAAO;EACL,OAAO,CAAC;EACR,MAAM,CAAC;EACP,IAAI,CAAC;EACL,WAAW;EACX,aAAa;CACf;AACF;;;;;AAMA,IAAa,SAAb,MAAoB;CAClB,0BAAmB,IAAI,IAA0B;CACjD;CACA;CAEA,YAAY,OAAsB,CAAC,GAAG;EACpC,KAAK,aAAa,KAAK,sBAAsB;EAC7C,KAAK,cAAc,KAAK,cAAc;CACxC;;;;;;;;;CAUA,OAAO,OAAuB;EAC5B,IAAI,MAAM,SAAS,KAAK,WAAW;GACjC,IAAI;GACJ,IAAI;IACF,QAAQ,eAAe,KAAK;GAC9B,QAAQ;IACN,OAAO;GACT;GACA,OAAO,KAAK,UAAU,MAAM,QAAQ,OAAO,M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AI,CAAC,QAAQ,KAAK,WAAW,GAAG;IAC9B,SAAS,KAAK,EAAE;IAChB;GACF;GACA,WAAW;GACX,KAAK,MAAM,OAAO,MAAM;IACtB,MAAM,OAAO,SAAS,IAAI,GAAG,KAAK,CAAC;IACnC,KAAK,KAAK,EAAE;IACZ,SAAS,IAAI,KAAK,IAAI;GACxB;EACF;EAEA,IAAI,CAAC,UACH,OAAO;GAAE,0BAAU,IAAI,IAAI;GAAG,WAAW;EAAO;EAGlD,MAAM,sBAAM,IAAI,IAAoB;EACpC,KAAK,MAAM,CAAC,KAAK,QAAQ,UACvB,IAAI,IAAI,KAAK,OAAO,QAAQ,GAAG,CAAC;EAElC,OAAO,SAAS,SAAS,IACrB;GAAE,UAAU;GAAK,WAAW,OAAO,QAAQ,QAAQ;EAAE,IACrD,EAAE,UAAU,IAAI;CACtB;;CAGA,QAAQ,IAAsC;EAC5C,MAAM,SAAS,KAAK,QAAQ,IAAI,EAAE;EAClC,IAAI,WAAW,KAAA,GACb,SAAS,KAAK,SAAS,IAAI,MAAM;EAEnC,OAAO;CACT;;CAGA,KAAK,IAAY,QAA4B;EAC3C,SAAS,KAAK,SAAS,IAAI,MAAM;EACjC,WAAW,KAAK,SAAS,KAAK,WAAW;CAC3C;AACF"}
|
package/dist/gossip.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { i as RoutedFilter, n as GossipOptions, r as PubkeyRoutes, t as Gossip } from "./gossip-
|
|
1
|
+
import { i as RoutedFilter, n as GossipOptions, r as PubkeyRoutes, t as Gossip } from "./gossip-C-7WhJ7v.mjs";
|
|
2
2
|
import "./index-CaxrMD1A.mjs";
|
|
3
3
|
export { Gossip, type GossipOptions, type PubkeyRoutes, type RoutedFilter };
|
package/dist/gossip.mjs
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { Gossip };
|
|
1
|
+
export { t as Gossip } from "./gossip-CejMm_QM.mjs";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { t as Event } from "./event-j3BwI5dF.mjs";
|
|
2
|
-
import { t as Filter } from "./filter-
|
|
3
|
-
import {
|
|
4
|
-
import { _ as Closer, n as Pool } from "./pool-
|
|
2
|
+
import { t as Filter } from "./filter-w1R-mU63.mjs";
|
|
3
|
+
import { o as NostrError } from "./error-DE1UCZ2J.mjs";
|
|
4
|
+
import { _ as Closer, n as Pool } from "./pool-BMfTQZjM.mjs";
|
|
5
5
|
//#region src/relay/error.d.ts
|
|
6
6
|
/** Base class for relay errors; carries the relay URL when known. */
|
|
7
7
|
declare class RelayError extends NostrError {
|
|
@@ -79,4 +79,4 @@ declare function fetchRouted(pool: Pool, jobs: ReadonlyArray<RoutedJob>, opts?:
|
|
|
79
79
|
}): Promise<Event[]>;
|
|
80
80
|
//#endregion
|
|
81
81
|
export { isInsecureRelayUrl as a, RelayError as c, RelayTimeoutError as d, fetchRouted as i, RelayPublishError as l, RoutedJob as n, RelayClosedError as o, fanIn as r, RelayConnectionError as s, FanInOptions as t, RelaySuspendedError as u };
|
|
82
|
-
//# sourceMappingURL=index-
|
|
82
|
+
//# sourceMappingURL=index-11znTLM0.d.mts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as Event } from "./event-j3BwI5dF.mjs";
|
|
2
|
-
import { t as Filter } from "./filter-
|
|
3
|
-
import { i as PutResult, n as NegentropyItem, r as OutboxBound, t as EventStore } from "./types-
|
|
2
|
+
import { t as Filter } from "./filter-w1R-mU63.mjs";
|
|
3
|
+
import { i as PutResult, n as NegentropyItem, r as OutboxBound, t as EventStore } from "./types-COupAqtN.mjs";
|
|
4
4
|
//#region src/storage/memory-index.d.ts
|
|
5
5
|
type MemoryIndexOptions = {
|
|
6
6
|
/**
|
|
@@ -188,4 +188,4 @@ declare class SqliteEventStore implements EventStore {
|
|
|
188
188
|
}
|
|
189
189
|
//#endregion
|
|
190
190
|
export { IndexedDbEventStoreOptions as a, MemoryIndexOptions as c, IndexedDbEventStore as i, SqlValue as n, MemoryEventStore as o, SqliteEventStore as r, MemoryIndex as s, SqlDriver as t };
|
|
191
|
-
//# sourceMappingURL=index-
|
|
191
|
+
//# sourceMappingURL=index-B7nMjbyt.d.mts.map
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { n as EventTemplate, r as UnsignedEvent, t as Event } from "./event-j3BwI5dF.mjs";
|
|
2
|
-
import { t as EventBuilder } from "./builder-
|
|
3
|
-
import { t as Filter } from "./filter-
|
|
4
|
-
import { t as Gossip } from "./gossip-
|
|
5
|
-
import {
|
|
6
|
-
import { _ as Closer, a as PoolFetchResult, n as Pool, o as PoolOptions, s as PoolPublishResult } from "./pool-
|
|
7
|
-
import { t as EventStore } from "./types-
|
|
8
|
-
import { t as ReactiveEventStore } from "./reactive-
|
|
9
|
-
import { a as OutboxFeed, n as Loaders } from "./index-
|
|
10
|
-
import { a as Rumor } from "./nip59-
|
|
11
|
-
import { i as ReplyTo, r as Recipient } from "./nip17
|
|
12
|
-
import { t as NostrSigner } from "./types-
|
|
13
|
-
import { t as StorageError } from "./error-
|
|
2
|
+
import { t as EventBuilder } from "./builder-Dk00TdNf.mjs";
|
|
3
|
+
import { t as Filter } from "./filter-w1R-mU63.mjs";
|
|
4
|
+
import { t as Gossip } from "./gossip-C-7WhJ7v.mjs";
|
|
5
|
+
import { o as NostrError } from "./error-DE1UCZ2J.mjs";
|
|
6
|
+
import { _ as Closer, a as PoolFetchResult, n as Pool, o as PoolOptions, s as PoolPublishResult } from "./pool-BMfTQZjM.mjs";
|
|
7
|
+
import { t as EventStore } from "./types-COupAqtN.mjs";
|
|
8
|
+
import { t as ReactiveEventStore } from "./reactive-BkzOsSwU.mjs";
|
|
9
|
+
import { a as OutboxFeed, n as Loaders } from "./index-DDZjqV48.mjs";
|
|
10
|
+
import { a as Rumor } from "./nip59-B6Ey8L9z.mjs";
|
|
11
|
+
import { i as ReplyTo, r as Recipient } from "./nip17--YwFSuph.mjs";
|
|
12
|
+
import { t as NostrSigner } from "./types-DF8yT6EG.mjs";
|
|
13
|
+
import { t as StorageError } from "./error-IHMcLy8-.mjs";
|
|
14
14
|
//#region src/client/types.d.ts
|
|
15
15
|
/** Direction of a {@link Client.sync} run: upload, download, or both. */
|
|
16
16
|
declare const SyncDirection: {
|
|
@@ -290,4 +290,4 @@ declare class Client {
|
|
|
290
290
|
}
|
|
291
291
|
//#endregion
|
|
292
292
|
export { SyncSummary as _, FetchEachOptions as a, PrivateMessageSendResult as c, SendPrivateMessageOptions as d, SubscribeOptions as f, SyncOptions as g, SyncDirectionName as h, ClientOptions as i, PublishOptions as l, SyncDirection as m, ClientError as n, FetchEventsOptions as o, SubscribePrivateMessagesOptions as p, ClientEventMap as r, FetchPrivateMessagesOptions as s, Client as t, ReceivedPrivateMessage as u };
|
|
293
|
-
//# sourceMappingURL=index-
|
|
293
|
+
//# sourceMappingURL=index-BuNI8JH_.d.mts.map
|
|
@@ -17,7 +17,14 @@ declare function bytesToHex(bytes: Uint8Array): string;
|
|
|
17
17
|
declare function randomBytes(length: number): Uint8Array;
|
|
18
18
|
/** Decode lowercase or mixed-case hex to bytes. */
|
|
19
19
|
declare function hexToBytes(hex: string): Uint8Array;
|
|
20
|
-
/**
|
|
20
|
+
/** `String.prototype.trim()` restricted to ASCII whitespace. */
|
|
21
|
+
declare function trimAscii(value: string): string;
|
|
22
|
+
/**
|
|
23
|
+
* ASCII-only lowercase — protocol tokens and identifiers fold A-Z→a-z byte-wise, matching Rust
|
|
24
|
+
* `to_ascii_lowercase`. Unicode case folding is reserved for natural-language text (NIP-51 mute
|
|
25
|
+
* words).
|
|
26
|
+
*/
|
|
27
|
+
declare function lowerAscii(value: string): string;
|
|
21
28
|
declare function isHex32(value: string): boolean;
|
|
22
29
|
/** True when value is canonical NIP-01 lowercase hex of 64 bytes (128 chars). */
|
|
23
30
|
declare function isHex64(value: string): boolean;
|
|
@@ -94,5 +101,5 @@ type KindName = keyof typeof Kind;
|
|
|
94
101
|
/** Union of the numeric kind values on {@link Kind}. */
|
|
95
102
|
type KnownKind = (typeof Kind)[KindName];
|
|
96
103
|
//#endregion
|
|
97
|
-
export {
|
|
98
|
-
//# sourceMappingURL=index-
|
|
104
|
+
export { SECRET_KEY_BYTES as C, PUBLIC_KEY_BYTES as S, SUBSCRIPTION_ID_MAX_CHARS as T, normalizeRelayUrls as _, classifyKind as a, trimAscii as b, isRegularKind as c, assertSecretKeyBytes as d, bytesToHex as f, lowerAscii as g, isHex64 as h, KnownKind as i, isReplaceableKind as l, isHex32 as m, KindClassification as n, isAddressableKind as o, hexToBytes as p, KindName as r, isEphemeralKind as s, Kind as t, assertHex32 as u, normalizeURL as v, SIGNATURE_BYTES as w, EVENT_ID_BYTES as x, randomBytes as y };
|
|
105
|
+
//# sourceMappingURL=index-C5QomO2D.d.mts.map
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { t as Event } from "./event-j3BwI5dF.mjs";
|
|
2
|
-
import { n as ProfileMetadata } from "./builder-
|
|
3
|
-
import { t as RelayListItem } from "./nip65-
|
|
4
|
-
import { t as Gossip } from "./gossip-
|
|
5
|
-
import {
|
|
6
|
-
import { _ as Closer, n as Pool } from "./pool-
|
|
7
|
-
import { r as OutboxBound, t as EventStore } from "./types-
|
|
8
|
-
import { t as ReactiveEventStore } from "./reactive-
|
|
9
|
-
import { i as EventPointer, t as AddressPointer } from "./nip19-
|
|
10
|
-
import { t as MuteItem } from "./nip51-
|
|
2
|
+
import { n as ProfileMetadata } from "./builder-Dk00TdNf.mjs";
|
|
3
|
+
import { t as RelayListItem } from "./nip65-XrBjV9WM.mjs";
|
|
4
|
+
import { t as Gossip } from "./gossip-C-7WhJ7v.mjs";
|
|
5
|
+
import { o as NostrError } from "./error-DE1UCZ2J.mjs";
|
|
6
|
+
import { _ as Closer, n as Pool } from "./pool-BMfTQZjM.mjs";
|
|
7
|
+
import { r as OutboxBound, t as EventStore } from "./types-COupAqtN.mjs";
|
|
8
|
+
import { t as ReactiveEventStore } from "./reactive-BkzOsSwU.mjs";
|
|
9
|
+
import { i as EventPointer, t as AddressPointer } from "./nip19-qtyc5sCl.mjs";
|
|
10
|
+
import { t as MuteItem } from "./nip51-yi9w8FsM.mjs";
|
|
11
11
|
//#region src/loaders/event.d.ts
|
|
12
12
|
type EventRef = string | EventPointer | AddressPointer;
|
|
13
13
|
/**
|
|
@@ -186,4 +186,4 @@ type CreateLoadersOptions = {
|
|
|
186
186
|
declare function createLoaders(opts: CreateLoadersOptions): Loaders;
|
|
187
187
|
//#endregion
|
|
188
188
|
export { EventRef as _, OutboxFeed as a, NostrUser as c, ListLoaders as d, ListResult as f, EventLoader as g, ReplaceableLoader as h, OutboxError as i, ProfileLoader as l, ReplaceableLoadResult as m, Loaders as n, OutboxFeedOptions as o, LoadStyle as p, createLoaders as r, groupAuthorsByOutboxRelay as s, CreateLoadersOptions as t, bareNostrUser as u };
|
|
189
|
-
//# sourceMappingURL=index-
|
|
189
|
+
//# sourceMappingURL=index-DDZjqV48.d.mts.map
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { n as EventTemplate, r as UnsignedEvent, t as Event } from "./event-j3BwI5dF.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import { t as Filter } from "./filter-
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
2
|
+
import { a as SecretKeyInput, n as NostrBackend, t as Keys } from "./key-E0AJKMRB.mjs";
|
|
3
|
+
import { t as Filter } from "./filter-w1R-mU63.mjs";
|
|
4
|
+
import { o as NostrError } from "./error-DE1UCZ2J.mjs";
|
|
5
|
+
import { a as Rumor } from "./nip59-B6Ey8L9z.mjs";
|
|
6
|
+
import { t as NostrSigner } from "./types-DF8yT6EG.mjs";
|
|
7
|
+
import { n as ClientMetadata, t as BunkerPointer } from "./nip46-C_ZFQprM.mjs";
|
|
7
8
|
//#region src/signer/error.d.ts
|
|
8
9
|
/**
|
|
9
10
|
* Thrown by a lazy NIP-42 AUTH sign function when no signer is configured at challenge time.
|
|
@@ -59,7 +60,9 @@ declare class DelegatedSigner implements NostrSigner {
|
|
|
59
60
|
/** Local secret-key signer with NIP-04 (legacy) and NIP-44 support. */
|
|
60
61
|
declare class KeysSigner implements NostrSigner {
|
|
61
62
|
#private;
|
|
62
|
-
constructor(secretKey: SecretKeyInput | Keys
|
|
63
|
+
constructor(secretKey: SecretKeyInput | Keys, options?: {
|
|
64
|
+
backend?: NostrBackend | undefined;
|
|
65
|
+
});
|
|
63
66
|
/**
|
|
64
67
|
* The live {@link Keys} instance holding the secret material. {@link KeysSigner.dispose} zeroizes
|
|
65
68
|
* it, so a reference obtained earlier reports a zeroized secret afterwards.
|
|
@@ -71,6 +74,8 @@ declare class KeysSigner implements NostrSigner {
|
|
|
71
74
|
nip04Decrypt(peer: string, ciphertext: string): Promise<string>;
|
|
72
75
|
nip44Encrypt(peer: string, plaintext: string): Promise<string>;
|
|
73
76
|
nip44Decrypt(peer: string, payload: string): Promise<string>;
|
|
77
|
+
/** Unwraps each gift wrap independently — a bad wrap yields an Error, never fails the batch. */
|
|
78
|
+
unwrapGiftWraps(events: ReadonlyArray<Event>): Promise<ReadonlyArray<Rumor | Error>>;
|
|
74
79
|
/**
|
|
75
80
|
* Zeroize the wrapped secret key and every cached NIP-44 conversation key. All later calls reject
|
|
76
81
|
* with {@link SignerDisposedError}. Idempotent.
|
|
@@ -153,8 +158,12 @@ type Nip46SignerOptions = {
|
|
|
153
158
|
relays?: ReadonlyArray<string> | undefined;
|
|
154
159
|
/** Bunker connection secret when the pointer or bunker:// URL has none. */
|
|
155
160
|
secret?: string | undefined;
|
|
156
|
-
/**
|
|
157
|
-
|
|
161
|
+
/**
|
|
162
|
+
* Local client identity used to encrypt and sign RPC (not the remote user key). Must implement
|
|
163
|
+
* `nip44Encrypt`/`nip44Decrypt` — the NIP-46 encryption layer is NIP-44. Construction rejects a
|
|
164
|
+
* signer without them.
|
|
165
|
+
*/
|
|
166
|
+
clientSigner: NostrSigner;
|
|
158
167
|
/** Called when bunker returns `auth_url` for a pending request. */
|
|
159
168
|
onAuthUrl?: ((url: string) => void) | undefined;
|
|
160
169
|
/** Per-request timeout in ms. Default 30s. */
|
|
@@ -180,25 +189,22 @@ declare class Nip46Signer implements NostrSigner {
|
|
|
180
189
|
get clientPublicKey(): string;
|
|
181
190
|
/**
|
|
182
191
|
* Subscribe to an already-known bunker pointer. Does not send the `connect` RPC (reconnect
|
|
183
|
-
* without a new handshake). Requires `
|
|
184
|
-
* identity.
|
|
192
|
+
* without a new handshake). Requires `clientSigner` — reconnect must reuse the original client
|
|
193
|
+
* identity. Async because the client public key comes from the signer.
|
|
185
194
|
*/
|
|
186
|
-
static fromBunker(pointer: BunkerPointer, opts: Nip46SignerOptions
|
|
187
|
-
clientSecretKey: SecretKeyInput;
|
|
188
|
-
}): Nip46Signer;
|
|
195
|
+
static fromBunker(pointer: BunkerPointer, opts: Nip46SignerOptions): Promise<Nip46Signer>;
|
|
189
196
|
/**
|
|
190
197
|
* Connect using a `bunker://` URL or pre-parsed pointer. Invalid strings throw. A NIP-05
|
|
191
198
|
* identifier is not a bunker pointer. When both pointer and `opts.relays` are nonempty, unique
|
|
192
199
|
* `opts.relays` are appended.
|
|
193
200
|
*/
|
|
194
|
-
static connect(input: string | BunkerPointer, opts
|
|
201
|
+
static connect(input: string | BunkerPointer, opts: Nip46SignerOptions): Promise<Nip46Signer>;
|
|
195
202
|
/**
|
|
196
203
|
* Wait for a bunker to complete a client-initiated `nostrconnect://` handshake. Requires
|
|
197
|
-
* `
|
|
198
|
-
* {@link createNostrConnectURI}
|
|
204
|
+
* `clientSigner` whose pubkey matches the URI client pubkey (build the URI with
|
|
205
|
+
* {@link createNostrConnectURI} and the signer's public key).
|
|
199
206
|
*/
|
|
200
207
|
static fromNostrConnectURI(connectionURI: string, opts: Nip46SignerOptions & {
|
|
201
|
-
clientSecretKey: SecretKeyInput;
|
|
202
208
|
signal?: AbortSignal;
|
|
203
209
|
handshakeTimeoutMs?: number;
|
|
204
210
|
}): Promise<Nip46Signer>;
|
|
@@ -224,4 +230,4 @@ declare class Nip46Signer implements NostrSigner {
|
|
|
224
230
|
}
|
|
225
231
|
//#endregion
|
|
226
232
|
export { Nip07Signer as a, isNip07Available as c, NostrKeyOperations as d, NoSignerError as f, Nip46Transport as i, KeysSigner as l, Nip46SignerOptions as n, WindowNostr as o, SignerDisposedError as p, Nip46SubscribeOptions as r, getWindowNostr as s, Nip46Signer as t, DelegatedSigner as u };
|
|
227
|
-
//# sourceMappingURL=index-
|
|
233
|
+
//# sourceMappingURL=index-DYk24u9o.d.mts.map
|