nostr-tools 2.23.7 → 2.23.9
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/lib/cjs/abstract-pool.js +128 -4
- package/lib/cjs/abstract-pool.js.map +4 -4
- package/lib/cjs/abstract-relay.js +29 -4
- package/lib/cjs/abstract-relay.js.map +2 -2
- package/lib/cjs/filter.js.map +1 -1
- package/lib/cjs/index.js +393 -70
- package/lib/cjs/index.js.map +4 -4
- package/lib/cjs/kinds.js +196 -4
- package/lib/cjs/kinds.js.map +2 -2
- package/lib/cjs/nip10.js +5 -4
- package/lib/cjs/nip10.js.map +2 -2
- package/lib/cjs/nip17.js.map +2 -2
- package/lib/cjs/nip18.js.map +2 -2
- package/lib/cjs/nip22.js +11 -5
- package/lib/cjs/nip22.js.map +2 -2
- package/lib/cjs/nip25.js.map +1 -1
- package/lib/cjs/nip28.js.map +2 -2
- package/lib/cjs/nip42.js.map +2 -2
- package/lib/cjs/nip45.js +183 -0
- package/lib/cjs/nip45.js.map +7 -0
- package/lib/cjs/nip46.js +135 -6
- package/lib/cjs/nip46.js.map +4 -4
- package/lib/cjs/nip47.js.map +2 -2
- package/lib/cjs/nip57.js.map +1 -1
- package/lib/cjs/nip58.js.map +2 -2
- package/lib/cjs/nip59.js.map +2 -2
- package/lib/cjs/nip75.js.map +2 -2
- package/lib/cjs/nip94.js.map +2 -2
- package/lib/cjs/nip98.js.map +2 -2
- package/lib/cjs/nip99.js.map +2 -2
- package/lib/cjs/nipb0.js +1064 -0
- package/lib/cjs/nipb0.js.map +7 -0
- package/lib/cjs/pool.js +128 -4
- package/lib/cjs/pool.js.map +4 -4
- package/lib/cjs/relay.js +29 -4
- package/lib/cjs/relay.js.map +2 -2
- package/lib/esm/abstract-pool.js +128 -4
- package/lib/esm/abstract-pool.js.map +4 -4
- package/lib/esm/abstract-relay.js +29 -4
- package/lib/esm/abstract-relay.js.map +2 -2
- package/lib/esm/filter.js.map +1 -1
- package/lib/esm/index.js +369 -46
- package/lib/esm/index.js.map +4 -4
- package/lib/esm/kinds.js +196 -4
- package/lib/esm/kinds.js.map +2 -2
- package/lib/esm/nip10.js +5 -4
- package/lib/esm/nip10.js.map +2 -2
- package/lib/esm/nip17.js.map +2 -2
- package/lib/esm/nip18.js.map +2 -2
- package/lib/esm/nip22.js +11 -5
- package/lib/esm/nip22.js.map +2 -2
- package/lib/esm/nip25.js.map +1 -1
- package/lib/esm/nip28.js.map +2 -2
- package/lib/esm/nip42.js.map +2 -2
- package/lib/esm/nip45.js +162 -0
- package/lib/esm/nip45.js.map +7 -0
- package/lib/esm/nip46.js +135 -6
- package/lib/esm/nip46.js.map +4 -4
- package/lib/esm/nip47.js.map +2 -2
- package/lib/esm/nip57.js.map +1 -1
- package/lib/esm/nip58.js.map +2 -2
- package/lib/esm/nip59.js.map +2 -2
- package/lib/esm/nip75.js.map +2 -2
- package/lib/esm/nip94.js.map +2 -2
- package/lib/esm/nip98.js.map +2 -2
- package/lib/esm/nip99.js.map +2 -2
- package/lib/esm/nipb0.js +1049 -0
- package/lib/esm/nipb0.js.map +7 -0
- package/lib/esm/pool.js +128 -4
- package/lib/esm/pool.js.map +4 -4
- package/lib/esm/relay.js +29 -4
- package/lib/esm/relay.js.map +2 -2
- package/lib/nostr.bundle.js +342 -21
- package/lib/nostr.bundle.js.map +4 -4
- package/lib/types/abstract-pool.d.ts +9 -0
- package/lib/types/abstract-relay.d.ts +10 -1
- package/lib/types/kinds.d.ts +200 -8
- package/lib/types/nip45.d.ts +13 -0
- package/lib/types/nip45.test.d.ts +1 -0
- package/lib/types/nip46.d.ts +7 -5
- package/lib/types/nipb0.d.ts +129 -0
- package/package.json +13 -1
package/lib/cjs/nip28.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../nip28.ts", "../../pure.ts", "../../core.ts", "../../utils.ts", "../../kinds.ts"],
|
|
4
|
-
"sourcesContent": ["import { Event, finalizeEvent } from './pure.ts'\nimport {\n ChannelCreation,\n ChannelHideMessage,\n ChannelMessage,\n ChannelMetadata as KindChannelMetadata,\n ChannelMuteUser,\n} from './kinds.ts'\n\nexport interface ChannelMetadata {\n name: string\n about: string\n picture: string\n}\n\nexport interface ChannelCreateEventTemplate {\n /* JSON string containing ChannelMetadata as defined for Kind 40 and 41 in nip-28. */\n content: string | ChannelMetadata\n created_at: number\n tags?: string[][]\n}\n\nexport interface ChannelMetadataEventTemplate {\n channel_create_event_id: string\n /* JSON string containing ChannelMetadata as defined for Kind 40 and 41 in nip-28. */\n content: string | ChannelMetadata\n created_at: number\n tags?: string[][]\n}\n\nexport interface ChannelMessageEventTemplate {\n channel_create_event_id: string\n reply_to_channel_message_event_id?: string\n relay_url: string\n content: string\n created_at: number\n tags?: string[][]\n}\n\nexport interface ChannelHideMessageEventTemplate {\n channel_message_event_id: string\n content: string | { reason: string }\n created_at: number\n tags?: string[][]\n}\n\nexport interface ChannelMuteUserEventTemplate {\n content: string | { reason: string }\n created_at: number\n pubkey_to_mute: string\n tags?: string[][]\n}\n\nexport const channelCreateEvent = (t: ChannelCreateEventTemplate, privateKey: Uint8Array): Event | undefined => {\n let content: string\n if (typeof t.content === 'object') {\n content = JSON.stringify(t.content)\n } else if (typeof t.content === 'string') {\n content = t.content\n } else {\n return undefined\n }\n\n return finalizeEvent(\n {\n kind: ChannelCreation,\n tags: [...(t.tags ?? [])],\n content: content,\n created_at: t.created_at,\n },\n privateKey,\n )\n}\n\nexport const channelMetadataEvent = (t: ChannelMetadataEventTemplate, privateKey: Uint8Array): Event | undefined => {\n let content: string\n if (typeof t.content === 'object') {\n content = JSON.stringify(t.content)\n } else if (typeof t.content === 'string') {\n content = t.content\n } else {\n return undefined\n }\n\n return finalizeEvent(\n {\n kind: KindChannelMetadata,\n tags: [['e', t.channel_create_event_id], ...(t.tags ?? [])],\n content: content,\n created_at: t.created_at,\n },\n privateKey,\n )\n}\n\nexport const channelMessageEvent = (t: ChannelMessageEventTemplate, privateKey: Uint8Array): Event => {\n const tags = [['e', t.channel_create_event_id, t.relay_url, 'root']]\n\n if (t.reply_to_channel_message_event_id) {\n tags.push(['e', t.reply_to_channel_message_event_id, t.relay_url, 'reply'])\n }\n\n return finalizeEvent(\n {\n kind: ChannelMessage,\n tags: [...tags, ...(t.tags ?? [])],\n content: t.content,\n created_at: t.created_at,\n },\n privateKey,\n )\n}\n\n/* \"e\" tag should be the kind 42 event to hide */\nexport const channelHideMessageEvent = (\n t: ChannelHideMessageEventTemplate,\n privateKey: Uint8Array,\n): Event | undefined => {\n let content: string\n if (typeof t.content === 'object') {\n content = JSON.stringify(t.content)\n } else if (typeof t.content === 'string') {\n content = t.content\n } else {\n return undefined\n }\n\n return finalizeEvent(\n {\n kind: ChannelHideMessage,\n tags: [['e', t.channel_message_event_id], ...(t.tags ?? [])],\n content: content,\n created_at: t.created_at,\n },\n privateKey,\n )\n}\n\nexport const channelMuteUserEvent = (t: ChannelMuteUserEventTemplate, privateKey: Uint8Array): Event | undefined => {\n let content: string\n if (typeof t.content === 'object') {\n content = JSON.stringify(t.content)\n } else if (typeof t.content === 'string') {\n content = t.content\n } else {\n return undefined\n }\n\n return finalizeEvent(\n {\n kind: ChannelMuteUser,\n tags: [['p', t.pubkey_to_mute], ...(t.tags ?? [])],\n content: content,\n created_at: t.created_at,\n },\n privateKey,\n )\n}\n", "import { schnorr } from '@noble/curves/secp256k1.js'\nimport { bytesToHex, hexToBytes } from '@noble/hashes/utils.js'\nimport { Nostr, Event, EventTemplate, UnsignedEvent, VerifiedEvent, verifiedSymbol, validateEvent } from './core.ts'\nimport { sha256 } from '@noble/hashes/sha2.js'\n\nimport { utf8Encoder } from './utils.ts'\n\nclass JS implements Nostr {\n generateSecretKey(): Uint8Array {\n return schnorr.utils.randomSecretKey()\n }\n getPublicKey(secretKey: Uint8Array): string {\n return bytesToHex(schnorr.getPublicKey(secretKey))\n }\n finalizeEvent(t: EventTemplate, secretKey: Uint8Array): VerifiedEvent {\n const event = t as VerifiedEvent\n event.pubkey = bytesToHex(schnorr.getPublicKey(secretKey))\n event.id = getEventHash(event)\n event.sig = bytesToHex(schnorr.sign(hexToBytes(getEventHash(event)), secretKey))\n event[verifiedSymbol] = true\n return event\n }\n verifyEvent(event: Event): event is VerifiedEvent {\n if (typeof event[verifiedSymbol] === 'boolean') return event[verifiedSymbol]\n\n try {\n const hash = getEventHash(event)\n if (hash !== event.id) {\n event[verifiedSymbol] = false\n return false\n }\n\n const valid = schnorr.verify(hexToBytes(event.sig), hexToBytes(hash), hexToBytes(event.pubkey))\n event[verifiedSymbol] = valid\n return valid\n } catch (err) {\n event[verifiedSymbol] = false\n return false\n }\n }\n}\n\nexport function serializeEvent(evt: UnsignedEvent): string {\n if (!validateEvent(evt)) throw new Error(\"can't serialize event with wrong or missing properties\")\n return JSON.stringify([0, evt.pubkey, evt.created_at, evt.kind, evt.tags, evt.content])\n}\n\nexport function getEventHash(event: UnsignedEvent): string {\n let eventHash = sha256(utf8Encoder.encode(serializeEvent(event)))\n return bytesToHex(eventHash)\n}\n\nconst i: JS = new JS()\n\nexport const generateSecretKey = i.generateSecretKey\nexport const getPublicKey = i.getPublicKey\nexport const finalizeEvent = i.finalizeEvent\nexport const verifyEvent = i.verifyEvent\nexport * from './core.ts'\n", "export interface Nostr {\n generateSecretKey(): Uint8Array\n getPublicKey(secretKey: Uint8Array): string\n finalizeEvent(event: EventTemplate, secretKey: Uint8Array): VerifiedEvent\n verifyEvent(event: Event): event is VerifiedEvent\n}\n\n/** Designates a verified event signature. */\nexport const verifiedSymbol = Symbol('verified')\n\nexport type NostrEvent = {\n kind: number\n tags: string[][]\n content: string\n created_at: number\n pubkey: string\n id: string\n sig: string\n [verifiedSymbol]?: boolean\n}\n\nexport type Event = NostrEvent\nexport type EventTemplate = Pick<Event, 'kind' | 'tags' | 'content' | 'created_at'>\nexport type UnsignedEvent = Pick<Event, 'kind' | 'tags' | 'content' | 'created_at' | 'pubkey'>\n\n/** An event whose signature has been verified. */\nexport interface VerifiedEvent extends Event {\n [verifiedSymbol]: true\n}\n\nconst isRecord = (obj: unknown): obj is Record<string, unknown> => obj instanceof Object\n\nexport function validateEvent<T>(event: T): event is T & UnsignedEvent {\n if (!isRecord(event)) return false\n if (typeof event.kind !== 'number') return false\n if (typeof event.content !== 'string') return false\n if (typeof event.created_at !== 'number') return false\n if (typeof event.pubkey !== 'string') return false\n if (!event.pubkey.match(/^[a-f0-9]{64}$/)) return false\n\n if (!Array.isArray(event.tags)) return false\n for (let i = 0; i < event.tags.length; i++) {\n let tag = event.tags[i]\n if (!Array.isArray(tag)) return false\n for (let j = 0; j < tag.length; j++) {\n if (typeof tag[j] !== 'string') return false\n }\n }\n\n return true\n}\n\n/**\n * Sort events in reverse-chronological order by the `created_at` timestamp,\n * and then by the event `id` (lexicographically) in case of ties.\n * This mutates the array.\n */\nexport function sortEvents(events: Event[]): Event[] {\n return events.sort((a: NostrEvent, b: NostrEvent): number => {\n if (a.created_at !== b.created_at) {\n return b.created_at - a.created_at\n }\n return a.id.localeCompare(b.id)\n })\n}\n", "import type { NostrEvent } from './core.ts'\n\nexport const utf8Decoder: TextDecoder = new TextDecoder('utf-8')\nexport const utf8Encoder: TextEncoder = new TextEncoder()\n\nexport { bytesToHex, hexToBytes } from '@noble/hashes/utils.js'\n\nexport function normalizeURL(url: string): string {\n try {\n if (url.indexOf('://') === -1) url = 'wss://' + url\n let p = new URL(url)\n if (p.protocol === 'http:') p.protocol = 'ws:'\n else if (p.protocol === 'https:') p.protocol = 'wss:'\n p.pathname = p.pathname.replace(/\\/+/g, '/')\n if (p.pathname.endsWith('/')) p.pathname = p.pathname.slice(0, -1)\n if ((p.port === '80' && p.protocol === 'ws:') || (p.port === '443' && p.protocol === 'wss:')) p.port = ''\n p.searchParams.sort()\n p.hash = ''\n return p.toString()\n } catch (e) {\n throw new Error(`Invalid URL: ${url}`)\n }\n}\n\nexport function insertEventIntoDescendingList(sortedArray: NostrEvent[], event: NostrEvent): NostrEvent[] {\n const [idx, found] = binarySearch(sortedArray, b => {\n if (event.id === b.id) return 0\n if (event.created_at === b.created_at) return -1\n return b.created_at - event.created_at\n })\n if (!found) {\n sortedArray.splice(idx, 0, event)\n }\n return sortedArray\n}\n\nexport function insertEventIntoAscendingList(sortedArray: NostrEvent[], event: NostrEvent): NostrEvent[] {\n const [idx, found] = binarySearch(sortedArray, b => {\n if (event.id === b.id) return 0\n if (event.created_at === b.created_at) return -1\n return event.created_at - b.created_at\n })\n if (!found) {\n sortedArray.splice(idx, 0, event)\n }\n return sortedArray\n}\n\nexport function binarySearch<T>(arr: T[], compare: (b: T) => number): [number, boolean] {\n let start = 0\n let end = arr.length - 1\n\n while (start <= end) {\n const mid = Math.floor((start + end) / 2)\n const cmp = compare(arr[mid])\n\n if (cmp === 0) {\n return [mid, true]\n }\n\n if (cmp < 0) {\n end = mid - 1\n } else {\n start = mid + 1\n }\n }\n\n return [start, false]\n}\n\nexport function mergeReverseSortedLists(list1: NostrEvent[], list2: NostrEvent[]): NostrEvent[] {\n const result: NostrEvent[] = new Array(list1.length + list2.length)\n result.length = 0\n let i1 = 0\n let i2 = 0\n let sameTimestampIds: string[] = []\n\n while (i1 < list1.length && i2 < list2.length) {\n let next: NostrEvent\n if (list1[i1]?.created_at > list2[i2]?.created_at) {\n next = list1[i1]\n i1++\n } else {\n next = list2[i2]\n i2++\n }\n\n if (result.length > 0 && result[result.length - 1].created_at === next.created_at) {\n if (sameTimestampIds.includes(next.id)) continue\n } else {\n sameTimestampIds.length = 0\n }\n\n result.push(next)\n sameTimestampIds.push(next.id)\n }\n\n while (i1 < list1.length) {\n const next = list1[i1]\n i1++\n\n if (result.length > 0 && result[result.length - 1].created_at === next.created_at) {\n if (sameTimestampIds.includes(next.id)) continue\n } else {\n sameTimestampIds.length = 0\n }\n result.push(next)\n sameTimestampIds.push(next.id)\n }\n\n while (i2 < list2.length) {\n const next = list2[i2]\n i2++\n\n if (result.length > 0 && result[result.length - 1].created_at === next.created_at) {\n if (sameTimestampIds.includes(next.id)) continue\n } else {\n sameTimestampIds.length = 0\n }\n result.push(next)\n sameTimestampIds.push(next.id)\n }\n\n return result\n}\n", "import { NostrEvent, validateEvent } from './pure.ts'\n\n/** Events are **regular**, which means they're all expected to be stored by relays. */\nexport function isRegularKind(kind: number): boolean {\n return kind < 10000 && kind !== 0 && kind !== 3\n}\n\n/** Events are **replaceable**, which means that, for each combination of `pubkey` and `kind`, only the latest event is expected to (SHOULD) be stored by relays, older versions are expected to be discarded. */\nexport function isReplaceableKind(kind: number): boolean {\n return kind === 0 || kind === 3 || (10000 <= kind && kind < 20000)\n}\n\n/** Events are **ephemeral**, which means they are not expected to be stored by relays. */\nexport function isEphemeralKind(kind: number): boolean {\n return 20000 <= kind && kind < 30000\n}\n\n/** Events are **addressable**, which means that, for each combination of `pubkey`, `kind` and the `d` tag, only the latest event is expected to be stored by relays, older versions are expected to be discarded. */\nexport function isAddressableKind(kind: number): boolean {\n return 30000 <= kind && kind < 40000\n}\n\n/** Classification of the event kind. */\nexport type KindClassification = 'regular' | 'replaceable' | 'ephemeral' | 'parameterized' | 'unknown'\n\n/** Determine the classification of this kind of event if known, or `unknown`. */\nexport function classifyKind(kind: number): KindClassification {\n if (isRegularKind(kind)) return 'regular'\n if (isReplaceableKind(kind)) return 'replaceable'\n if (isEphemeralKind(kind)) return 'ephemeral'\n if (isAddressableKind(kind)) return 'parameterized'\n return 'unknown'\n}\n\nexport function isKind<T extends number>(event: unknown, kind: T | Array<T>): event is NostrEvent & { kind: T } {\n const kindAsArray: number[] = kind instanceof Array ? kind : [kind]\n return (validateEvent(event) && kindAsArray.includes(event.kind)) || false\n}\n\nexport const Metadata = 0\nexport type Metadata = typeof Metadata\nexport const ShortTextNote = 1\nexport type ShortTextNote = typeof ShortTextNote\nexport const RecommendRelay = 2\nexport type RecommendRelay = typeof RecommendRelay\nexport const Contacts = 3\nexport type Contacts = typeof Contacts\nexport const EncryptedDirectMessage = 4\nexport type EncryptedDirectMessage = typeof EncryptedDirectMessage\nexport const EventDeletion = 5\nexport type EventDeletion = typeof EventDeletion\nexport const Repost = 6\nexport type Repost = typeof Repost\nexport const Reaction = 7\nexport type Reaction = typeof Reaction\nexport const BadgeAward = 8\nexport type BadgeAward = typeof BadgeAward\nexport const ChatMessage = 9\nexport type ChatMessage = typeof ChatMessage\nexport const ForumThread = 11\nexport type ForumThread = typeof ForumThread\nexport const Seal = 13\nexport type Seal = typeof Seal\nexport const PrivateDirectMessage = 14\nexport type PrivateDirectMessage = typeof PrivateDirectMessage\nexport const FileMessage = 15\nexport type FileMessage = typeof FileMessage\nexport const GenericRepost = 16\nexport type GenericRepost = typeof GenericRepost\nexport const Photo = 20\nexport type Photo = typeof Photo\nexport const NormalVideo = 21\nexport type NormalVideo = typeof NormalVideo\nexport const ShortVideo = 22\nexport type ShortVideo = typeof ShortVideo\nexport const ChannelCreation = 40\nexport type ChannelCreation = typeof ChannelCreation\nexport const ChannelMetadata = 41\nexport type ChannelMetadata = typeof ChannelMetadata\nexport const ChannelMessage = 42\nexport type ChannelMessage = typeof ChannelMessage\nexport const ChannelHideMessage = 43\nexport type ChannelHideMessage = typeof ChannelHideMessage\nexport const ChannelMuteUser = 44\nexport type ChannelMuteUser = typeof ChannelMuteUser\nexport const OpenTimestamps = 1040\nexport type OpenTimestamps = typeof OpenTimestamps\nexport const GiftWrap = 1059\nexport type GiftWrap = typeof GiftWrap\nexport const Poll = 1068\nexport type Poll = typeof Poll\nexport const FileMetadata = 1063\nexport type FileMetadata = typeof FileMetadata\nexport const Comment = 1111\nexport type Comment = typeof Comment\nexport const LiveChatMessage = 1311\nexport type LiveChatMessage = typeof LiveChatMessage\nexport const Voice = 1222\nexport type Voice = typeof Voice\nexport const VoiceComment = 1244\nexport type VoiceComment = typeof VoiceComment\nexport const ProblemTracker = 1971\nexport type ProblemTracker = typeof ProblemTracker\nexport const Report = 1984\nexport type Report = typeof Report\nexport const Reporting = 1984\nexport type Reporting = typeof Reporting\nexport const Label = 1985\nexport type Label = typeof Label\nexport const CommunityPostApproval = 4550\nexport type CommunityPostApproval = typeof CommunityPostApproval\nexport const JobRequest = 5999\nexport type JobRequest = typeof JobRequest\nexport const JobResult = 6999\nexport type JobResult = typeof JobResult\nexport const JobFeedback = 7000\nexport type JobFeedback = typeof JobFeedback\nexport const ZapGoal = 9041\nexport type ZapGoal = typeof ZapGoal\nexport const ZapRequest = 9734\nexport type ZapRequest = typeof ZapRequest\nexport const Zap = 9735\nexport type Zap = typeof Zap\nexport const Highlights = 9802\nexport type Highlights = typeof Highlights\nexport const PollResponse = 1018\nexport type PollResponse = typeof PollResponse\nexport const Mutelist = 10000\nexport type Mutelist = typeof Mutelist\nexport const Pinlist = 10001\nexport type Pinlist = typeof Pinlist\nexport const RelayList = 10002\nexport type RelayList = typeof RelayList\nexport const BookmarkList = 10003\nexport type BookmarkList = typeof BookmarkList\nexport const CommunitiesList = 10004\nexport type CommunitiesList = typeof CommunitiesList\nexport const PublicChatsList = 10005\nexport type PublicChatsList = typeof PublicChatsList\nexport const BlockedRelaysList = 10006\nexport type BlockedRelaysList = typeof BlockedRelaysList\nexport const SearchRelaysList = 10007\nexport type SearchRelaysList = typeof SearchRelaysList\nexport const FavoriteRelays = 10012\nexport type FavoriteRelays = typeof FavoriteRelays\nexport const InterestsList = 10015\nexport type InterestsList = typeof InterestsList\nexport const UserEmojiList = 10030\nexport type UserEmojiList = typeof UserEmojiList\nexport const DirectMessageRelaysList = 10050\nexport type DirectMessageRelaysList = typeof DirectMessageRelaysList\nexport const FileServerPreference = 10096\nexport type FileServerPreference = typeof FileServerPreference\nexport const BlossomServerList = 10063\nexport type BlossomServerList = typeof BlossomServerList\nexport const NWCWalletInfo = 13194\nexport type NWCWalletInfo = typeof NWCWalletInfo\nexport const LightningPubRPC = 21000\nexport type LightningPubRPC = typeof LightningPubRPC\nexport const ClientAuth = 22242\nexport type ClientAuth = typeof ClientAuth\nexport const NWCWalletRequest = 23194\nexport type NWCWalletRequest = typeof NWCWalletRequest\nexport const NWCWalletResponse = 23195\nexport type NWCWalletResponse = typeof NWCWalletResponse\nexport const NostrConnect = 24133\nexport type NostrConnect = typeof NostrConnect\nexport const HTTPAuth = 27235\nexport type HTTPAuth = typeof HTTPAuth\nexport const Followsets = 30000\nexport type Followsets = typeof Followsets\nexport const Genericlists = 30001\nexport type Genericlists = typeof Genericlists\nexport const Relaysets = 30002\nexport type Relaysets = typeof Relaysets\nexport const Bookmarksets = 30003\nexport type Bookmarksets = typeof Bookmarksets\nexport const Curationsets = 30004\nexport type Curationsets = typeof Curationsets\nexport const ProfileBadges = 30008\nexport type ProfileBadges = typeof ProfileBadges\nexport const BadgeDefinition = 30009\nexport type BadgeDefinition = typeof BadgeDefinition\nexport const Interestsets = 30015\nexport type Interestsets = typeof Interestsets\nexport const CreateOrUpdateStall = 30017\nexport type CreateOrUpdateStall = typeof CreateOrUpdateStall\nexport const CreateOrUpdateProduct = 30018\nexport type CreateOrUpdateProduct = typeof CreateOrUpdateProduct\nexport const LongFormArticle = 30023\nexport type LongFormArticle = typeof LongFormArticle\nexport const DraftLong = 30024\nexport type DraftLong = typeof DraftLong\nexport const Emojisets = 30030\nexport type Emojisets = typeof Emojisets\nexport const Application = 30078\nexport type Application = typeof Application\nexport const LiveEvent = 30311\nexport type LiveEvent = typeof LiveEvent\nexport const UserStatuses = 30315\nexport type UserStatuses = typeof UserStatuses\nexport const ClassifiedListing = 30402\nexport type ClassifiedListing = typeof ClassifiedListing\nexport const DraftClassifiedListing = 30403\nexport type DraftClassifiedListing = typeof DraftClassifiedListing\nexport const Date = 31922\nexport type Date = typeof Date\nexport const Time = 31923\nexport type Time = typeof Time\nexport const Calendar = 31924\nexport type Calendar = typeof Calendar\nexport const CalendarEventRSVP = 31925\nexport type CalendarEventRSVP = typeof CalendarEventRSVP\nexport const RelayReview = 31987\nexport type RelayReview = typeof RelayReview\nexport const Handlerrecommendation = 31989\nexport type Handlerrecommendation = typeof Handlerrecommendation\nexport const Handlerinformation = 31990\nexport type Handlerinformation = typeof Handlerinformation\nexport const CommunityDefinition = 34550\nexport type CommunityDefinition = typeof CommunityDefinition\nexport const GroupMetadata = 39000\nexport type GroupMetadata = typeof GroupMetadata\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,uBAAwB;AACxB,IAAAA,gBAAuC;;;ACOhC,IAAM,iBAAiB,OAAO,UAAU;AAsB/C,IAAM,WAAW,CAAC,QAAiD,eAAe;AAE3E,SAAS,cAAiB,OAAsC;AACrE,MAAI,CAAC,SAAS,KAAK;AAAG,WAAO;AAC7B,MAAI,OAAO,MAAM,SAAS;AAAU,WAAO;AAC3C,MAAI,OAAO,MAAM,YAAY;AAAU,WAAO;AAC9C,MAAI,OAAO,MAAM,eAAe;AAAU,WAAO;AACjD,MAAI,OAAO,MAAM,WAAW;AAAU,WAAO;AAC7C,MAAI,CAAC,MAAM,OAAO,MAAM,gBAAgB;AAAG,WAAO;AAElD,MAAI,CAAC,MAAM,QAAQ,MAAM,IAAI;AAAG,WAAO;AACvC,WAASC,KAAI,GAAGA,KAAI,MAAM,KAAK,QAAQA,MAAK;AAC1C,QAAI,MAAM,MAAM,KAAKA;AACrB,QAAI,CAAC,MAAM,QAAQ,GAAG;AAAG,aAAO;AAChC,aAAS,IAAI,GAAG,IAAI,IAAI,QAAQ,KAAK;AACnC,UAAI,OAAO,IAAI,OAAO;AAAU,eAAO;AAAA,IACzC;AAAA,EACF;AAEA,SAAO;AACT;;;AD/CA,kBAAuB;;;AEEvB,mBAAuC;AAHhC,IAAM,cAA2B,IAAI,YAAY,OAAO;AACxD,IAAM,cAA2B,IAAI,YAAY;;;AFIxD,IAAM,KAAN,MAA0B;AAAA,EACxB,oBAAgC;AAC9B,WAAO,yBAAQ,MAAM,gBAAgB;AAAA,EACvC;AAAA,EACA,aAAa,WAA+B;AAC1C,eAAO,0BAAW,yBAAQ,aAAa,SAAS,CAAC;AAAA,EACnD;AAAA,EACA,cAAc,GAAkB,WAAsC;AACpE,UAAM,QAAQ;AACd,UAAM,aAAS,0BAAW,yBAAQ,aAAa,SAAS,CAAC;AACzD,UAAM,KAAK,aAAa,KAAK;AAC7B,UAAM,UAAM,0BAAW,yBAAQ,SAAK,0BAAW,aAAa,KAAK,CAAC,GAAG,SAAS,CAAC;AAC/E,UAAM,kBAAkB;AACxB,WAAO;AAAA,EACT;AAAA,EACA,YAAY,OAAsC;AAChD,QAAI,OAAO,MAAM,oBAAoB;AAAW,aAAO,MAAM;AAE7D,QAAI;AACF,YAAM,OAAO,aAAa,KAAK;AAC/B,UAAI,SAAS,MAAM,IAAI;AACrB,cAAM,kBAAkB;AACxB,eAAO;AAAA,MACT;AAEA,YAAM,QAAQ,yBAAQ,WAAO,0BAAW,MAAM,GAAG,OAAG,0BAAW,IAAI,OAAG,0BAAW,MAAM,MAAM,CAAC;AAC9F,YAAM,kBAAkB;AACxB,aAAO;AAAA,IACT,SAAS,KAAP;AACA,YAAM,kBAAkB;AACxB,aAAO;AAAA,IACT;AAAA,EACF;AACF;AAEO,SAAS,eAAe,KAA4B;AACzD,MAAI,CAAC,cAAc,GAAG;AAAG,UAAM,IAAI,MAAM,wDAAwD;AACjG,SAAO,KAAK,UAAU,CAAC,GAAG,IAAI,QAAQ,IAAI,YAAY,IAAI,MAAM,IAAI,MAAM,IAAI,OAAO,CAAC;AACxF;AAEO,SAAS,aAAa,OAA8B;AACzD,MAAI,gBAAY,oBAAO,YAAY,OAAO,eAAe,KAAK,CAAC,CAAC;AAChE,aAAO,0BAAW,SAAS;AAC7B;AAEA,IAAM,IAAQ,IAAI,GAAG;AAEd,IAAM,oBAAoB,EAAE;AAC5B,IAAM,eAAe,EAAE;AACvB,IAAM,gBAAgB,EAAE;AACxB,IAAM,cAAc,EAAE;;;
|
|
4
|
+
"sourcesContent": ["import { Event, finalizeEvent } from './pure.ts'\nimport {\n ChannelCreation,\n ChannelHideMessage,\n ChannelMessage,\n ChannelMetadata as KindChannelMetadata,\n ChannelMuteUser,\n} from './kinds.ts'\n\nexport interface ChannelMetadata {\n name: string\n about: string\n picture: string\n}\n\nexport interface ChannelCreateEventTemplate {\n /* JSON string containing ChannelMetadata as defined for Kind 40 and 41 in nip-28. */\n content: string | ChannelMetadata\n created_at: number\n tags?: string[][]\n}\n\nexport interface ChannelMetadataEventTemplate {\n channel_create_event_id: string\n /* JSON string containing ChannelMetadata as defined for Kind 40 and 41 in nip-28. */\n content: string | ChannelMetadata\n created_at: number\n tags?: string[][]\n}\n\nexport interface ChannelMessageEventTemplate {\n channel_create_event_id: string\n reply_to_channel_message_event_id?: string\n relay_url: string\n content: string\n created_at: number\n tags?: string[][]\n}\n\nexport interface ChannelHideMessageEventTemplate {\n channel_message_event_id: string\n content: string | { reason: string }\n created_at: number\n tags?: string[][]\n}\n\nexport interface ChannelMuteUserEventTemplate {\n content: string | { reason: string }\n created_at: number\n pubkey_to_mute: string\n tags?: string[][]\n}\n\nexport const channelCreateEvent = (t: ChannelCreateEventTemplate, privateKey: Uint8Array): Event | undefined => {\n let content: string\n if (typeof t.content === 'object') {\n content = JSON.stringify(t.content)\n } else if (typeof t.content === 'string') {\n content = t.content\n } else {\n return undefined\n }\n\n return finalizeEvent(\n {\n kind: ChannelCreation,\n tags: [...(t.tags ?? [])],\n content: content,\n created_at: t.created_at,\n },\n privateKey,\n )\n}\n\nexport const channelMetadataEvent = (t: ChannelMetadataEventTemplate, privateKey: Uint8Array): Event | undefined => {\n let content: string\n if (typeof t.content === 'object') {\n content = JSON.stringify(t.content)\n } else if (typeof t.content === 'string') {\n content = t.content\n } else {\n return undefined\n }\n\n return finalizeEvent(\n {\n kind: KindChannelMetadata,\n tags: [['e', t.channel_create_event_id], ...(t.tags ?? [])],\n content: content,\n created_at: t.created_at,\n },\n privateKey,\n )\n}\n\nexport const channelMessageEvent = (t: ChannelMessageEventTemplate, privateKey: Uint8Array): Event => {\n const tags = [['e', t.channel_create_event_id, t.relay_url, 'root']]\n\n if (t.reply_to_channel_message_event_id) {\n tags.push(['e', t.reply_to_channel_message_event_id, t.relay_url, 'reply'])\n }\n\n return finalizeEvent(\n {\n kind: ChannelMessage,\n tags: [...tags, ...(t.tags ?? [])],\n content: t.content,\n created_at: t.created_at,\n },\n privateKey,\n )\n}\n\n/* \"e\" tag should be the kind 42 event to hide */\nexport const channelHideMessageEvent = (\n t: ChannelHideMessageEventTemplate,\n privateKey: Uint8Array,\n): Event | undefined => {\n let content: string\n if (typeof t.content === 'object') {\n content = JSON.stringify(t.content)\n } else if (typeof t.content === 'string') {\n content = t.content\n } else {\n return undefined\n }\n\n return finalizeEvent(\n {\n kind: ChannelHideMessage,\n tags: [['e', t.channel_message_event_id], ...(t.tags ?? [])],\n content: content,\n created_at: t.created_at,\n },\n privateKey,\n )\n}\n\nexport const channelMuteUserEvent = (t: ChannelMuteUserEventTemplate, privateKey: Uint8Array): Event | undefined => {\n let content: string\n if (typeof t.content === 'object') {\n content = JSON.stringify(t.content)\n } else if (typeof t.content === 'string') {\n content = t.content\n } else {\n return undefined\n }\n\n return finalizeEvent(\n {\n kind: ChannelMuteUser,\n tags: [['p', t.pubkey_to_mute], ...(t.tags ?? [])],\n content: content,\n created_at: t.created_at,\n },\n privateKey,\n )\n}\n", "import { schnorr } from '@noble/curves/secp256k1.js'\nimport { bytesToHex, hexToBytes } from '@noble/hashes/utils.js'\nimport { Nostr, Event, EventTemplate, UnsignedEvent, VerifiedEvent, verifiedSymbol, validateEvent } from './core.ts'\nimport { sha256 } from '@noble/hashes/sha2.js'\n\nimport { utf8Encoder } from './utils.ts'\n\nclass JS implements Nostr {\n generateSecretKey(): Uint8Array {\n return schnorr.utils.randomSecretKey()\n }\n getPublicKey(secretKey: Uint8Array): string {\n return bytesToHex(schnorr.getPublicKey(secretKey))\n }\n finalizeEvent(t: EventTemplate, secretKey: Uint8Array): VerifiedEvent {\n const event = t as VerifiedEvent\n event.pubkey = bytesToHex(schnorr.getPublicKey(secretKey))\n event.id = getEventHash(event)\n event.sig = bytesToHex(schnorr.sign(hexToBytes(getEventHash(event)), secretKey))\n event[verifiedSymbol] = true\n return event\n }\n verifyEvent(event: Event): event is VerifiedEvent {\n if (typeof event[verifiedSymbol] === 'boolean') return event[verifiedSymbol]\n\n try {\n const hash = getEventHash(event)\n if (hash !== event.id) {\n event[verifiedSymbol] = false\n return false\n }\n\n const valid = schnorr.verify(hexToBytes(event.sig), hexToBytes(hash), hexToBytes(event.pubkey))\n event[verifiedSymbol] = valid\n return valid\n } catch (err) {\n event[verifiedSymbol] = false\n return false\n }\n }\n}\n\nexport function serializeEvent(evt: UnsignedEvent): string {\n if (!validateEvent(evt)) throw new Error(\"can't serialize event with wrong or missing properties\")\n return JSON.stringify([0, evt.pubkey, evt.created_at, evt.kind, evt.tags, evt.content])\n}\n\nexport function getEventHash(event: UnsignedEvent): string {\n let eventHash = sha256(utf8Encoder.encode(serializeEvent(event)))\n return bytesToHex(eventHash)\n}\n\nconst i: JS = new JS()\n\nexport const generateSecretKey = i.generateSecretKey\nexport const getPublicKey = i.getPublicKey\nexport const finalizeEvent = i.finalizeEvent\nexport const verifyEvent = i.verifyEvent\nexport * from './core.ts'\n", "export interface Nostr {\n generateSecretKey(): Uint8Array\n getPublicKey(secretKey: Uint8Array): string\n finalizeEvent(event: EventTemplate, secretKey: Uint8Array): VerifiedEvent\n verifyEvent(event: Event): event is VerifiedEvent\n}\n\n/** Designates a verified event signature. */\nexport const verifiedSymbol = Symbol('verified')\n\nexport type NostrEvent = {\n kind: number\n tags: string[][]\n content: string\n created_at: number\n pubkey: string\n id: string\n sig: string\n [verifiedSymbol]?: boolean\n}\n\nexport type Event = NostrEvent\nexport type EventTemplate = Pick<Event, 'kind' | 'tags' | 'content' | 'created_at'>\nexport type UnsignedEvent = Pick<Event, 'kind' | 'tags' | 'content' | 'created_at' | 'pubkey'>\n\n/** An event whose signature has been verified. */\nexport interface VerifiedEvent extends Event {\n [verifiedSymbol]: true\n}\n\nconst isRecord = (obj: unknown): obj is Record<string, unknown> => obj instanceof Object\n\nexport function validateEvent<T>(event: T): event is T & UnsignedEvent {\n if (!isRecord(event)) return false\n if (typeof event.kind !== 'number') return false\n if (typeof event.content !== 'string') return false\n if (typeof event.created_at !== 'number') return false\n if (typeof event.pubkey !== 'string') return false\n if (!event.pubkey.match(/^[a-f0-9]{64}$/)) return false\n\n if (!Array.isArray(event.tags)) return false\n for (let i = 0; i < event.tags.length; i++) {\n let tag = event.tags[i]\n if (!Array.isArray(tag)) return false\n for (let j = 0; j < tag.length; j++) {\n if (typeof tag[j] !== 'string') return false\n }\n }\n\n return true\n}\n\n/**\n * Sort events in reverse-chronological order by the `created_at` timestamp,\n * and then by the event `id` (lexicographically) in case of ties.\n * This mutates the array.\n */\nexport function sortEvents(events: Event[]): Event[] {\n return events.sort((a: NostrEvent, b: NostrEvent): number => {\n if (a.created_at !== b.created_at) {\n return b.created_at - a.created_at\n }\n return a.id.localeCompare(b.id)\n })\n}\n", "import type { NostrEvent } from './core.ts'\n\nexport const utf8Decoder: TextDecoder = new TextDecoder('utf-8')\nexport const utf8Encoder: TextEncoder = new TextEncoder()\n\nexport { bytesToHex, hexToBytes } from '@noble/hashes/utils.js'\n\nexport function normalizeURL(url: string): string {\n try {\n if (url.indexOf('://') === -1) url = 'wss://' + url\n let p = new URL(url)\n if (p.protocol === 'http:') p.protocol = 'ws:'\n else if (p.protocol === 'https:') p.protocol = 'wss:'\n p.pathname = p.pathname.replace(/\\/+/g, '/')\n if (p.pathname.endsWith('/')) p.pathname = p.pathname.slice(0, -1)\n if ((p.port === '80' && p.protocol === 'ws:') || (p.port === '443' && p.protocol === 'wss:')) p.port = ''\n p.searchParams.sort()\n p.hash = ''\n return p.toString()\n } catch (e) {\n throw new Error(`Invalid URL: ${url}`)\n }\n}\n\nexport function insertEventIntoDescendingList(sortedArray: NostrEvent[], event: NostrEvent): NostrEvent[] {\n const [idx, found] = binarySearch(sortedArray, b => {\n if (event.id === b.id) return 0\n if (event.created_at === b.created_at) return -1\n return b.created_at - event.created_at\n })\n if (!found) {\n sortedArray.splice(idx, 0, event)\n }\n return sortedArray\n}\n\nexport function insertEventIntoAscendingList(sortedArray: NostrEvent[], event: NostrEvent): NostrEvent[] {\n const [idx, found] = binarySearch(sortedArray, b => {\n if (event.id === b.id) return 0\n if (event.created_at === b.created_at) return -1\n return event.created_at - b.created_at\n })\n if (!found) {\n sortedArray.splice(idx, 0, event)\n }\n return sortedArray\n}\n\nexport function binarySearch<T>(arr: T[], compare: (b: T) => number): [number, boolean] {\n let start = 0\n let end = arr.length - 1\n\n while (start <= end) {\n const mid = Math.floor((start + end) / 2)\n const cmp = compare(arr[mid])\n\n if (cmp === 0) {\n return [mid, true]\n }\n\n if (cmp < 0) {\n end = mid - 1\n } else {\n start = mid + 1\n }\n }\n\n return [start, false]\n}\n\nexport function mergeReverseSortedLists(list1: NostrEvent[], list2: NostrEvent[]): NostrEvent[] {\n const result: NostrEvent[] = new Array(list1.length + list2.length)\n result.length = 0\n let i1 = 0\n let i2 = 0\n let sameTimestampIds: string[] = []\n\n while (i1 < list1.length && i2 < list2.length) {\n let next: NostrEvent\n if (list1[i1]?.created_at > list2[i2]?.created_at) {\n next = list1[i1]\n i1++\n } else {\n next = list2[i2]\n i2++\n }\n\n if (result.length > 0 && result[result.length - 1].created_at === next.created_at) {\n if (sameTimestampIds.includes(next.id)) continue\n } else {\n sameTimestampIds.length = 0\n }\n\n result.push(next)\n sameTimestampIds.push(next.id)\n }\n\n while (i1 < list1.length) {\n const next = list1[i1]\n i1++\n\n if (result.length > 0 && result[result.length - 1].created_at === next.created_at) {\n if (sameTimestampIds.includes(next.id)) continue\n } else {\n sameTimestampIds.length = 0\n }\n result.push(next)\n sameTimestampIds.push(next.id)\n }\n\n while (i2 < list2.length) {\n const next = list2[i2]\n i2++\n\n if (result.length > 0 && result[result.length - 1].created_at === next.created_at) {\n if (sameTimestampIds.includes(next.id)) continue\n } else {\n sameTimestampIds.length = 0\n }\n result.push(next)\n sameTimestampIds.push(next.id)\n }\n\n return result\n}\n", "import { NostrEvent, validateEvent } from './pure.ts'\n\n/** Events are **regular**, which means they're all expected to be stored by relays. */\nexport function isRegularKind(kind: number): boolean {\n return kind < 10000 && kind !== 0 && kind !== 3\n}\n\n/** Events are **replaceable**, which means that, for each combination of `pubkey` and `kind`, only the latest event is expected to (SHOULD) be stored by relays, older versions are expected to be discarded. */\nexport function isReplaceableKind(kind: number): boolean {\n return kind === 0 || kind === 3 || (10000 <= kind && kind < 20000)\n}\n\n/** Events are **ephemeral**, which means they are not expected to be stored by relays. */\nexport function isEphemeralKind(kind: number): boolean {\n return 20000 <= kind && kind < 30000\n}\n\n/** Events are **addressable**, which means that, for each combination of `pubkey`, `kind` and the `d` tag, only the latest event is expected to be stored by relays, older versions are expected to be discarded. */\nexport function isAddressableKind(kind: number): boolean {\n return 30000 <= kind && kind < 40000\n}\n\n/** Classification of the event kind. */\nexport type KindClassification = 'regular' | 'replaceable' | 'ephemeral' | 'parameterized' | 'unknown'\n\n/** Determine the classification of this kind of event if known, or `unknown`. */\nexport function classifyKind(kind: number): KindClassification {\n if (isRegularKind(kind)) return 'regular'\n if (isReplaceableKind(kind)) return 'replaceable'\n if (isEphemeralKind(kind)) return 'ephemeral'\n if (isAddressableKind(kind)) return 'parameterized'\n return 'unknown'\n}\n\nexport function isKind<T extends number>(event: unknown, kind: T | Array<T>): event is NostrEvent & { kind: T } {\n const kindAsArray: number[] = kind instanceof Array ? kind : [kind]\n return (validateEvent(event) && kindAsArray.includes(event.kind)) || false\n}\n\nexport const Metadata = 0\nexport type Metadata = typeof Metadata\nexport const ShortTextNote = 1\nexport type ShortTextNote = typeof ShortTextNote\nexport const RecommendRelay = 2\nexport type RecommendRelay = typeof RecommendRelay\nexport const Contacts = 3\nexport type Contacts = typeof Contacts\nexport const EncryptedDirectMessage = 4\nexport type EncryptedDirectMessage = typeof EncryptedDirectMessage\nexport const EventDeletion = 5\nexport type EventDeletion = typeof EventDeletion\nexport const Repost = 6\nexport type Repost = typeof Repost\nexport const Reaction = 7\nexport type Reaction = typeof Reaction\nexport const BadgeAward = 8\nexport type BadgeAward = typeof BadgeAward\nexport const ChatMessage = 9\nexport type ChatMessage = typeof ChatMessage\nexport const SimpleGroupThreadedReply = 10\nexport type SimpleGroupThreadedReply = typeof SimpleGroupThreadedReply\nexport const ForumThread = 11\nexport type ForumThread = typeof ForumThread\nexport const SimpleGroupReply = 12\nexport type SimpleGroupReply = typeof SimpleGroupReply\nexport const Seal = 13\nexport type Seal = typeof Seal\nexport const PrivateDirectMessage = 14\nexport type PrivateDirectMessage = typeof PrivateDirectMessage\nexport const FileMessage = 15\nexport type FileMessage = typeof FileMessage\nexport const GenericRepost = 16\nexport type GenericRepost = typeof GenericRepost\nexport const ReactionToWebsite = 17\nexport type ReactionToWebsite = typeof ReactionToWebsite\nexport const Photo = 20\nexport type Photo = typeof Photo\nexport const NormalVideo = 21\nexport type NormalVideo = typeof NormalVideo\nexport const ShortVideo = 22\nexport type ShortVideo = typeof ShortVideo\nexport const PublicMessage = 24\nexport type PublicMessage = typeof PublicMessage\nexport const ChannelCreation = 40\nexport type ChannelCreation = typeof ChannelCreation\nexport const ChannelMetadata = 41\nexport type ChannelMetadata = typeof ChannelMetadata\nexport const ChannelMessage = 42\nexport type ChannelMessage = typeof ChannelMessage\nexport const ChannelHideMessage = 43\nexport type ChannelHideMessage = typeof ChannelHideMessage\nexport const ChannelMuteUser = 44\nexport type ChannelMuteUser = typeof ChannelMuteUser\nexport const PodcastEpisode = 54\nexport type PodcastEpisode = typeof PodcastEpisode\nexport const Chess = 64\nexport type Chess = typeof Chess\nexport const MergeRequests = 818\nexport type MergeRequests = typeof MergeRequests\nexport const PollResponse = 1018\nexport type PollResponse = typeof PollResponse\nexport const Bid = 1021\nexport type Bid = typeof Bid\nexport const BidConfirmation = 1022\nexport type BidConfirmation = typeof BidConfirmation\nexport const OpenTimestamps = 1040\nexport type OpenTimestamps = typeof OpenTimestamps\nexport const GiftWrap = 1059\nexport type GiftWrap = typeof GiftWrap\nexport const FileMetadata = 1063\nexport type FileMetadata = typeof FileMetadata\nexport const Poll = 1068\nexport type Poll = typeof Poll\nexport const Comment = 1111\nexport type Comment = typeof Comment\nexport const Voice = 1222\nexport type Voice = typeof Voice\nexport const Scroll = 1227\nexport type Scroll = typeof Scroll\nexport const VoiceComment = 1244\nexport type VoiceComment = typeof VoiceComment\nexport const LiveChatMessage = 1311\nexport type LiveChatMessage = typeof LiveChatMessage\nexport const CodeSnippet = 1337\nexport type CodeSnippet = typeof CodeSnippet\nexport const Patch = 1617\nexport type Patch = typeof Patch\nexport const GitPullRequest = 1618\nexport type GitPullRequest = typeof GitPullRequest\nexport const GitPullRequestUpdate = 1619\nexport type GitPullRequestUpdate = typeof GitPullRequestUpdate\nexport const Issue = 1621\nexport type Issue = typeof Issue\nexport const Reply = 1622\nexport type Reply = typeof Reply\nexport const StatusOpen = 1630\nexport type StatusOpen = typeof StatusOpen\nexport const StatusApplied = 1631\nexport type StatusApplied = typeof StatusApplied\nexport const StatusClosed = 1632\nexport type StatusClosed = typeof StatusClosed\nexport const StatusDraft = 1633\nexport type StatusDraft = typeof StatusDraft\nexport const ProblemTracker = 1971\nexport type ProblemTracker = typeof ProblemTracker\nexport const Report = 1984\nexport type Report = typeof Report\nexport const Reporting = 1984\nexport type Reporting = typeof Reporting\nexport const Label = 1985\nexport type Label = typeof Label\nexport const RelayReviews = 1986\nexport type RelayReviews = typeof RelayReviews\nexport const AIEmbeddings = 1987\nexport type AIEmbeddings = typeof AIEmbeddings\nexport const Torrent = 2003\nexport type Torrent = typeof Torrent\nexport const TorrentComment = 2004\nexport type TorrentComment = typeof TorrentComment\nexport const CoinjoinPool = 2022\nexport type CoinjoinPool = typeof CoinjoinPool\nexport const DecoupledKeyClientAnnouncement = 4454\nexport type DecoupledKeyClientAnnouncement = typeof DecoupledKeyClientAnnouncement\nexport const DecoupledEncryptionKeyDistribution = 4455\nexport type DecoupledEncryptionKeyDistribution = typeof DecoupledEncryptionKeyDistribution\nexport const CommunityPostApproval = 4550\nexport type CommunityPostApproval = typeof CommunityPostApproval\nexport const JobRequest = 5999\nexport type JobRequest = typeof JobRequest\nexport const JobResult = 6999\nexport type JobResult = typeof JobResult\nexport const JobFeedback = 7000\nexport type JobFeedback = typeof JobFeedback\nexport const ReservedCashuWalletTokens = 7374\nexport type ReservedCashuWalletTokens = typeof ReservedCashuWalletTokens\nexport const CashuWalletTokens = 7375\nexport type CashuWalletTokens = typeof CashuWalletTokens\nexport const CashuWalletHistory = 7376\nexport type CashuWalletHistory = typeof CashuWalletHistory\nexport const GeocacheLog = 7516\nexport type GeocacheLog = typeof GeocacheLog\nexport const GeocacheProofOfFind = 7517\nexport type GeocacheProofOfFind = typeof GeocacheProofOfFind\nexport const SimpleGroupPutUser = 9000\nexport type SimpleGroupPutUser = typeof SimpleGroupPutUser\nexport const SimpleGroupRemoveUser = 9001\nexport type SimpleGroupRemoveUser = typeof SimpleGroupRemoveUser\nexport const SimpleGroupEditMetadata = 9002\nexport type SimpleGroupEditMetadata = typeof SimpleGroupEditMetadata\nexport const SimpleGroupDeleteEvent = 9005\nexport type SimpleGroupDeleteEvent = typeof SimpleGroupDeleteEvent\nexport const SimpleGroupCreateGroup = 9007\nexport type SimpleGroupCreateGroup = typeof SimpleGroupCreateGroup\nexport const SimpleGroupDeleteGroup = 9008\nexport type SimpleGroupDeleteGroup = typeof SimpleGroupDeleteGroup\nexport const SimpleGroupCreateInvite = 9009\nexport type SimpleGroupCreateInvite = typeof SimpleGroupCreateInvite\nexport const SimpleGroupJoinRequest = 9021\nexport type SimpleGroupJoinRequest = typeof SimpleGroupJoinRequest\nexport const SimpleGroupLeaveRequest = 9022\nexport type SimpleGroupLeaveRequest = typeof SimpleGroupLeaveRequest\nexport const ZapGoal = 9041\nexport type ZapGoal = typeof ZapGoal\nexport const NutZap = 9321\nexport type NutZap = typeof NutZap\nexport const TidalLogin = 9467\nexport type TidalLogin = typeof TidalLogin\nexport const ZapRequest = 9734\nexport type ZapRequest = typeof ZapRequest\nexport const Zap = 9735\nexport type Zap = typeof Zap\nexport const Highlights = 9802\nexport type Highlights = typeof Highlights\nexport const Mutelist = 10000\nexport type Mutelist = typeof Mutelist\nexport const Pinlist = 10001\nexport type Pinlist = typeof Pinlist\nexport const RelayList = 10002\nexport type RelayList = typeof RelayList\nexport const BookmarkList = 10003\nexport type BookmarkList = typeof BookmarkList\nexport const CommunitiesList = 10004\nexport type CommunitiesList = typeof CommunitiesList\nexport const PublicChatsList = 10005\nexport type PublicChatsList = typeof PublicChatsList\nexport const BlockedRelaysList = 10006\nexport type BlockedRelaysList = typeof BlockedRelaysList\nexport const SearchRelaysList = 10007\nexport type SearchRelaysList = typeof SearchRelaysList\nexport const SimpleGroupList = 10009\nexport type SimpleGroupList = typeof SimpleGroupList\nexport const FavoriteRelays = 10012\nexport type FavoriteRelays = typeof FavoriteRelays\nexport const PrivateEventRelayList = 10013\nexport type PrivateEventRelayList = typeof PrivateEventRelayList\nexport const InterestsList = 10015\nexport type InterestsList = typeof InterestsList\nexport const NutZapInfo = 10019\nexport type NutZapInfo = typeof NutZapInfo\nexport const MediaFollows = 10020\nexport type MediaFollows = typeof MediaFollows\nexport const UserEmojiList = 10030\nexport type UserEmojiList = typeof UserEmojiList\nexport const DecoupledKeyAnnouncement = 10044\nexport type DecoupledKeyAnnouncement = typeof DecoupledKeyAnnouncement\nexport const DirectMessageRelaysList = 10050\nexport type DirectMessageRelaysList = typeof DirectMessageRelaysList\nexport const FavoritePodcasts = 10054\nexport type FavoritePodcasts = typeof FavoritePodcasts\nexport const BlossomServerList = 10063\nexport type BlossomServerList = typeof BlossomServerList\nexport const FileServerPreference = 10096\nexport type FileServerPreference = typeof FileServerPreference\nexport const GoodWikiAuthorList = 10101\nexport type GoodWikiAuthorList = typeof GoodWikiAuthorList\nexport const GoodWikiRelayList = 10102\nexport type GoodWikiRelayList = typeof GoodWikiRelayList\nexport const PodcastMetadata = 10154\nexport type PodcastMetadata = typeof PodcastMetadata\nexport const AuthoredPodcasts = 10164\nexport type AuthoredPodcasts = typeof AuthoredPodcasts\nexport const RelayMonitorAnnouncement = 10166\nexport type RelayMonitorAnnouncement = typeof RelayMonitorAnnouncement\nexport const RoomPresence = 10312\nexport type RoomPresence = typeof RoomPresence\nexport const UserGraspList = 10317\nexport type UserGraspList = typeof UserGraspList\nexport const ProxyAnnouncement = 10377\nexport type ProxyAnnouncement = typeof ProxyAnnouncement\nexport const TransportMethodAnnouncement = 11111\nexport type TransportMethodAnnouncement = typeof TransportMethodAnnouncement\nexport const NWCWalletInfo = 13194\nexport type NWCWalletInfo = typeof NWCWalletInfo\nexport const NsiteRoot = 15128\nexport type NsiteRoot = typeof NsiteRoot\nexport const CashuWalletEvent = 17375\nexport type CashuWalletEvent = typeof CashuWalletEvent\nexport const LightningPubRPC = 21000\nexport type LightningPubRPC = typeof LightningPubRPC\nexport const ClientAuth = 22242\nexport type ClientAuth = typeof ClientAuth\nexport const NWCWalletRequest = 23194\nexport type NWCWalletRequest = typeof NWCWalletRequest\nexport const NWCWalletResponse = 23195\nexport type NWCWalletResponse = typeof NWCWalletResponse\nexport const NostrConnect = 24133\nexport type NostrConnect = typeof NostrConnect\nexport const BlobsAuth = 24242\nexport type BlobsAuth = typeof BlobsAuth\nexport const HTTPAuth = 27235\nexport type HTTPAuth = typeof HTTPAuth\nexport const Followsets = 30000\nexport type Followsets = typeof Followsets\nexport const Genericlists = 30001\nexport type Genericlists = typeof Genericlists\nexport const Relaysets = 30002\nexport type Relaysets = typeof Relaysets\nexport const Bookmarksets = 30003\nexport type Bookmarksets = typeof Bookmarksets\nexport const Curationsets = 30004\nexport type Curationsets = typeof Curationsets\nexport const CuratedVideoSets = 30005\nexport type CuratedVideoSets = typeof CuratedVideoSets\nexport const MuteSets = 30007\nexport type MuteSets = typeof MuteSets\nexport const ProfileBadges = 30008\nexport type ProfileBadges = typeof ProfileBadges\nexport const BadgeDefinition = 30009\nexport type BadgeDefinition = typeof BadgeDefinition\nexport const Interestsets = 30015\nexport type Interestsets = typeof Interestsets\nexport const CreateOrUpdateStall = 30017\nexport type CreateOrUpdateStall = typeof CreateOrUpdateStall\nexport const CreateOrUpdateProduct = 30018\nexport type CreateOrUpdateProduct = typeof CreateOrUpdateProduct\nexport const MarketplaceUI = 30019\nexport type MarketplaceUI = typeof MarketplaceUI\nexport const ProductSoldAsAuction = 30020\nexport type ProductSoldAsAuction = typeof ProductSoldAsAuction\nexport const LongFormArticle = 30023\nexport type LongFormArticle = typeof LongFormArticle\nexport const DraftLong = 30024\nexport type DraftLong = typeof DraftLong\nexport const Emojisets = 30030\nexport type Emojisets = typeof Emojisets\nexport const ModularArticleHeader = 30040\nexport type ModularArticleHeader = typeof ModularArticleHeader\nexport const ModularArticleContent = 30041\nexport type ModularArticleContent = typeof ModularArticleContent\nexport const ReleaseArtifactSets = 30063\nexport type ReleaseArtifactSets = typeof ReleaseArtifactSets\nexport const Application = 30078\nexport type Application = typeof Application\nexport const RelayDiscovery = 30166\nexport type RelayDiscovery = typeof RelayDiscovery\nexport const AppCurationSet = 30267\nexport type AppCurationSet = typeof AppCurationSet\nexport const LiveEvent = 30311\nexport type LiveEvent = typeof LiveEvent\nexport const InteractiveRoom = 30312\nexport type InteractiveRoom = typeof InteractiveRoom\nexport const ConferenceEvent = 30313\nexport type ConferenceEvent = typeof ConferenceEvent\nexport const UserStatuses = 30315\nexport type UserStatuses = typeof UserStatuses\nexport const SlideSet = 30388\nexport type SlideSet = typeof SlideSet\nexport const ClassifiedListing = 30402\nexport type ClassifiedListing = typeof ClassifiedListing\nexport const DraftClassifiedListing = 30403\nexport type DraftClassifiedListing = typeof DraftClassifiedListing\nexport const RepositoryAnnouncement = 30617\nexport type RepositoryAnnouncement = typeof RepositoryAnnouncement\nexport const RepositoryState = 30618\nexport type RepositoryState = typeof RepositoryState\nexport const WikiArticle = 30818\nexport type WikiArticle = typeof WikiArticle\nexport const Redirects = 30819\nexport type Redirects = typeof Redirects\nexport const DraftEvent = 31234\nexport type DraftEvent = typeof DraftEvent\nexport const LinkSet = 31388\nexport type LinkSet = typeof LinkSet\nexport const Feed = 31890\nexport type Feed = typeof Feed\nexport const Date = 31922\nexport type Date = typeof Date\nexport const Time = 31923\nexport type Time = typeof Time\nexport const Calendar = 31924\nexport type Calendar = typeof Calendar\nexport const CalendarEventRSVP = 31925\nexport type CalendarEventRSVP = typeof CalendarEventRSVP\nexport const RelayReview = 31987\nexport type RelayReview = typeof RelayReview\nexport const Handlerrecommendation = 31989\nexport type Handlerrecommendation = typeof Handlerrecommendation\nexport const Handlerinformation = 31990\nexport type Handlerinformation = typeof Handlerinformation\nexport const SoftwareApplication = 32267\nexport type SoftwareApplication = typeof SoftwareApplication\nexport const LegacyNsiteFile = 34128\nexport type LegacyNsiteFile = typeof LegacyNsiteFile\nexport const VideoViewEvent = 34237\nexport type VideoViewEvent = typeof VideoViewEvent\nexport const CommunityDefinition = 34550\nexport type CommunityDefinition = typeof CommunityDefinition\nexport const NsiteNamed = 35128\nexport type NsiteNamed = typeof NsiteNamed\nexport const GeocacheListing = 37515\nexport type GeocacheListing = typeof GeocacheListing\nexport const GeocacheLogEntry = 37516\nexport type GeocacheLogEntry = typeof GeocacheLogEntry\nexport const CashuMintAnnouncement = 38172\nexport type CashuMintAnnouncement = typeof CashuMintAnnouncement\nexport const FedimintAnnouncement = 38173\nexport type FedimintAnnouncement = typeof FedimintAnnouncement\nexport const PeerToPeerOrderEvents = 38383\nexport type PeerToPeerOrderEvents = typeof PeerToPeerOrderEvents\nexport const GroupMetadata = 39000\nexport type GroupMetadata = typeof GroupMetadata\nexport const SimpleGroupAdmins = 39001\nexport type SimpleGroupAdmins = typeof SimpleGroupAdmins\nexport const SimpleGroupMembers = 39002\nexport type SimpleGroupMembers = typeof SimpleGroupMembers\nexport const SimpleGroupRoles = 39003\nexport type SimpleGroupRoles = typeof SimpleGroupRoles\nexport const SimpleGroupLiveKitParticipants = 39004\nexport type SimpleGroupLiveKitParticipants = typeof SimpleGroupLiveKitParticipants\nexport const StarterPacks = 39089\nexport type StarterPacks = typeof StarterPacks\nexport const MediaStarterPacks = 39092\nexport type MediaStarterPacks = typeof MediaStarterPacks\nexport const WebBookmarks = 39701\nexport type WebBookmarks = typeof WebBookmarks\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
6
|
"names": ["import_utils", "i"]
|
|
7
7
|
}
|
package/lib/cjs/nip42.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../nip42.ts", "../../kinds.ts"],
|
|
4
|
-
"sourcesContent": ["import { EventTemplate } from './core.ts'\nimport { ClientAuth } from './kinds.ts'\n\n/**\n * creates an EventTemplate for an AUTH event to be signed.\n */\nexport function makeAuthEvent(relayURL: string, challenge: string): EventTemplate {\n return {\n kind: ClientAuth,\n created_at: Math.floor(Date.now() / 1000),\n tags: [\n ['relay', relayURL],\n ['challenge', challenge],\n ],\n content: '',\n }\n}\n", "import { NostrEvent, validateEvent } from './pure.ts'\n\n/** Events are **regular**, which means they're all expected to be stored by relays. */\nexport function isRegularKind(kind: number): boolean {\n return kind < 10000 && kind !== 0 && kind !== 3\n}\n\n/** Events are **replaceable**, which means that, for each combination of `pubkey` and `kind`, only the latest event is expected to (SHOULD) be stored by relays, older versions are expected to be discarded. */\nexport function isReplaceableKind(kind: number): boolean {\n return kind === 0 || kind === 3 || (10000 <= kind && kind < 20000)\n}\n\n/** Events are **ephemeral**, which means they are not expected to be stored by relays. */\nexport function isEphemeralKind(kind: number): boolean {\n return 20000 <= kind && kind < 30000\n}\n\n/** Events are **addressable**, which means that, for each combination of `pubkey`, `kind` and the `d` tag, only the latest event is expected to be stored by relays, older versions are expected to be discarded. */\nexport function isAddressableKind(kind: number): boolean {\n return 30000 <= kind && kind < 40000\n}\n\n/** Classification of the event kind. */\nexport type KindClassification = 'regular' | 'replaceable' | 'ephemeral' | 'parameterized' | 'unknown'\n\n/** Determine the classification of this kind of event if known, or `unknown`. */\nexport function classifyKind(kind: number): KindClassification {\n if (isRegularKind(kind)) return 'regular'\n if (isReplaceableKind(kind)) return 'replaceable'\n if (isEphemeralKind(kind)) return 'ephemeral'\n if (isAddressableKind(kind)) return 'parameterized'\n return 'unknown'\n}\n\nexport function isKind<T extends number>(event: unknown, kind: T | Array<T>): event is NostrEvent & { kind: T } {\n const kindAsArray: number[] = kind instanceof Array ? kind : [kind]\n return (validateEvent(event) && kindAsArray.includes(event.kind)) || false\n}\n\nexport const Metadata = 0\nexport type Metadata = typeof Metadata\nexport const ShortTextNote = 1\nexport type ShortTextNote = typeof ShortTextNote\nexport const RecommendRelay = 2\nexport type RecommendRelay = typeof RecommendRelay\nexport const Contacts = 3\nexport type Contacts = typeof Contacts\nexport const EncryptedDirectMessage = 4\nexport type EncryptedDirectMessage = typeof EncryptedDirectMessage\nexport const EventDeletion = 5\nexport type EventDeletion = typeof EventDeletion\nexport const Repost = 6\nexport type Repost = typeof Repost\nexport const Reaction = 7\nexport type Reaction = typeof Reaction\nexport const BadgeAward = 8\nexport type BadgeAward = typeof BadgeAward\nexport const ChatMessage = 9\nexport type ChatMessage = typeof ChatMessage\nexport const ForumThread = 11\nexport type ForumThread = typeof ForumThread\nexport const Seal = 13\nexport type Seal = typeof Seal\nexport const PrivateDirectMessage = 14\nexport type PrivateDirectMessage = typeof PrivateDirectMessage\nexport const FileMessage = 15\nexport type FileMessage = typeof FileMessage\nexport const GenericRepost = 16\nexport type GenericRepost = typeof GenericRepost\nexport const Photo = 20\nexport type Photo = typeof Photo\nexport const NormalVideo = 21\nexport type NormalVideo = typeof NormalVideo\nexport const ShortVideo = 22\nexport type ShortVideo = typeof ShortVideo\nexport const ChannelCreation = 40\nexport type ChannelCreation = typeof ChannelCreation\nexport const ChannelMetadata = 41\nexport type ChannelMetadata = typeof ChannelMetadata\nexport const ChannelMessage = 42\nexport type ChannelMessage = typeof ChannelMessage\nexport const ChannelHideMessage = 43\nexport type ChannelHideMessage = typeof ChannelHideMessage\nexport const ChannelMuteUser = 44\nexport type ChannelMuteUser = typeof ChannelMuteUser\nexport const OpenTimestamps = 1040\nexport type OpenTimestamps = typeof OpenTimestamps\nexport const GiftWrap = 1059\nexport type GiftWrap = typeof GiftWrap\nexport const Poll = 1068\nexport type Poll = typeof Poll\nexport const FileMetadata = 1063\nexport type FileMetadata = typeof FileMetadata\nexport const Comment = 1111\nexport type Comment = typeof Comment\nexport const LiveChatMessage = 1311\nexport type LiveChatMessage = typeof LiveChatMessage\nexport const Voice = 1222\nexport type Voice = typeof Voice\nexport const VoiceComment = 1244\nexport type VoiceComment = typeof VoiceComment\nexport const ProblemTracker = 1971\nexport type ProblemTracker = typeof ProblemTracker\nexport const Report = 1984\nexport type Report = typeof Report\nexport const Reporting = 1984\nexport type Reporting = typeof Reporting\nexport const Label = 1985\nexport type Label = typeof Label\nexport const CommunityPostApproval = 4550\nexport type CommunityPostApproval = typeof CommunityPostApproval\nexport const JobRequest = 5999\nexport type JobRequest = typeof JobRequest\nexport const JobResult = 6999\nexport type JobResult = typeof JobResult\nexport const JobFeedback = 7000\nexport type JobFeedback = typeof JobFeedback\nexport const ZapGoal = 9041\nexport type ZapGoal = typeof ZapGoal\nexport const ZapRequest = 9734\nexport type ZapRequest = typeof ZapRequest\nexport const Zap = 9735\nexport type Zap = typeof Zap\nexport const Highlights = 9802\nexport type Highlights = typeof Highlights\nexport const PollResponse = 1018\nexport type PollResponse = typeof PollResponse\nexport const Mutelist = 10000\nexport type Mutelist = typeof Mutelist\nexport const Pinlist = 10001\nexport type Pinlist = typeof Pinlist\nexport const RelayList = 10002\nexport type RelayList = typeof RelayList\nexport const BookmarkList = 10003\nexport type BookmarkList = typeof BookmarkList\nexport const CommunitiesList = 10004\nexport type CommunitiesList = typeof CommunitiesList\nexport const PublicChatsList = 10005\nexport type PublicChatsList = typeof PublicChatsList\nexport const BlockedRelaysList = 10006\nexport type BlockedRelaysList = typeof BlockedRelaysList\nexport const SearchRelaysList = 10007\nexport type SearchRelaysList = typeof SearchRelaysList\nexport const FavoriteRelays = 10012\nexport type FavoriteRelays = typeof FavoriteRelays\nexport const InterestsList = 10015\nexport type InterestsList = typeof InterestsList\nexport const UserEmojiList = 10030\nexport type UserEmojiList = typeof UserEmojiList\nexport const DirectMessageRelaysList = 10050\nexport type DirectMessageRelaysList = typeof DirectMessageRelaysList\nexport const FileServerPreference = 10096\nexport type FileServerPreference = typeof FileServerPreference\nexport const BlossomServerList = 10063\nexport type BlossomServerList = typeof BlossomServerList\nexport const NWCWalletInfo = 13194\nexport type NWCWalletInfo = typeof NWCWalletInfo\nexport const LightningPubRPC = 21000\nexport type LightningPubRPC = typeof LightningPubRPC\nexport const ClientAuth = 22242\nexport type ClientAuth = typeof ClientAuth\nexport const NWCWalletRequest = 23194\nexport type NWCWalletRequest = typeof NWCWalletRequest\nexport const NWCWalletResponse = 23195\nexport type NWCWalletResponse = typeof NWCWalletResponse\nexport const NostrConnect = 24133\nexport type NostrConnect = typeof NostrConnect\nexport const HTTPAuth = 27235\nexport type HTTPAuth = typeof HTTPAuth\nexport const Followsets = 30000\nexport type Followsets = typeof Followsets\nexport const Genericlists = 30001\nexport type Genericlists = typeof Genericlists\nexport const Relaysets = 30002\nexport type Relaysets = typeof Relaysets\nexport const Bookmarksets = 30003\nexport type Bookmarksets = typeof Bookmarksets\nexport const Curationsets = 30004\nexport type Curationsets = typeof Curationsets\nexport const ProfileBadges = 30008\nexport type ProfileBadges = typeof ProfileBadges\nexport const BadgeDefinition = 30009\nexport type BadgeDefinition = typeof BadgeDefinition\nexport const Interestsets = 30015\nexport type Interestsets = typeof Interestsets\nexport const CreateOrUpdateStall = 30017\nexport type CreateOrUpdateStall = typeof CreateOrUpdateStall\nexport const CreateOrUpdateProduct = 30018\nexport type CreateOrUpdateProduct = typeof CreateOrUpdateProduct\nexport const LongFormArticle = 30023\nexport type LongFormArticle = typeof LongFormArticle\nexport const DraftLong = 30024\nexport type DraftLong = typeof DraftLong\nexport const Emojisets = 30030\nexport type Emojisets = typeof Emojisets\nexport const Application = 30078\nexport type Application = typeof Application\nexport const LiveEvent = 30311\nexport type LiveEvent = typeof LiveEvent\nexport const UserStatuses = 30315\nexport type UserStatuses = typeof UserStatuses\nexport const ClassifiedListing = 30402\nexport type ClassifiedListing = typeof ClassifiedListing\nexport const DraftClassifiedListing = 30403\nexport type DraftClassifiedListing = typeof DraftClassifiedListing\nexport const Date = 31922\nexport type Date = typeof Date\nexport const Time = 31923\nexport type Time = typeof Time\nexport const Calendar = 31924\nexport type Calendar = typeof Calendar\nexport const CalendarEventRSVP = 31925\nexport type CalendarEventRSVP = typeof CalendarEventRSVP\nexport const RelayReview = 31987\nexport type RelayReview = typeof RelayReview\nexport const Handlerrecommendation = 31989\nexport type Handlerrecommendation = typeof Handlerrecommendation\nexport const Handlerinformation = 31990\nexport type Handlerinformation = typeof Handlerinformation\nexport const CommunityDefinition = 34550\nexport type CommunityDefinition = typeof CommunityDefinition\nexport const GroupMetadata = 39000\nexport type GroupMetadata = typeof GroupMetadata\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;
|
|
4
|
+
"sourcesContent": ["import { EventTemplate } from './core.ts'\nimport { ClientAuth } from './kinds.ts'\n\n/**\n * creates an EventTemplate for an AUTH event to be signed.\n */\nexport function makeAuthEvent(relayURL: string, challenge: string): EventTemplate {\n return {\n kind: ClientAuth,\n created_at: Math.floor(Date.now() / 1000),\n tags: [\n ['relay', relayURL],\n ['challenge', challenge],\n ],\n content: '',\n }\n}\n", "import { NostrEvent, validateEvent } from './pure.ts'\n\n/** Events are **regular**, which means they're all expected to be stored by relays. */\nexport function isRegularKind(kind: number): boolean {\n return kind < 10000 && kind !== 0 && kind !== 3\n}\n\n/** Events are **replaceable**, which means that, for each combination of `pubkey` and `kind`, only the latest event is expected to (SHOULD) be stored by relays, older versions are expected to be discarded. */\nexport function isReplaceableKind(kind: number): boolean {\n return kind === 0 || kind === 3 || (10000 <= kind && kind < 20000)\n}\n\n/** Events are **ephemeral**, which means they are not expected to be stored by relays. */\nexport function isEphemeralKind(kind: number): boolean {\n return 20000 <= kind && kind < 30000\n}\n\n/** Events are **addressable**, which means that, for each combination of `pubkey`, `kind` and the `d` tag, only the latest event is expected to be stored by relays, older versions are expected to be discarded. */\nexport function isAddressableKind(kind: number): boolean {\n return 30000 <= kind && kind < 40000\n}\n\n/** Classification of the event kind. */\nexport type KindClassification = 'regular' | 'replaceable' | 'ephemeral' | 'parameterized' | 'unknown'\n\n/** Determine the classification of this kind of event if known, or `unknown`. */\nexport function classifyKind(kind: number): KindClassification {\n if (isRegularKind(kind)) return 'regular'\n if (isReplaceableKind(kind)) return 'replaceable'\n if (isEphemeralKind(kind)) return 'ephemeral'\n if (isAddressableKind(kind)) return 'parameterized'\n return 'unknown'\n}\n\nexport function isKind<T extends number>(event: unknown, kind: T | Array<T>): event is NostrEvent & { kind: T } {\n const kindAsArray: number[] = kind instanceof Array ? kind : [kind]\n return (validateEvent(event) && kindAsArray.includes(event.kind)) || false\n}\n\nexport const Metadata = 0\nexport type Metadata = typeof Metadata\nexport const ShortTextNote = 1\nexport type ShortTextNote = typeof ShortTextNote\nexport const RecommendRelay = 2\nexport type RecommendRelay = typeof RecommendRelay\nexport const Contacts = 3\nexport type Contacts = typeof Contacts\nexport const EncryptedDirectMessage = 4\nexport type EncryptedDirectMessage = typeof EncryptedDirectMessage\nexport const EventDeletion = 5\nexport type EventDeletion = typeof EventDeletion\nexport const Repost = 6\nexport type Repost = typeof Repost\nexport const Reaction = 7\nexport type Reaction = typeof Reaction\nexport const BadgeAward = 8\nexport type BadgeAward = typeof BadgeAward\nexport const ChatMessage = 9\nexport type ChatMessage = typeof ChatMessage\nexport const SimpleGroupThreadedReply = 10\nexport type SimpleGroupThreadedReply = typeof SimpleGroupThreadedReply\nexport const ForumThread = 11\nexport type ForumThread = typeof ForumThread\nexport const SimpleGroupReply = 12\nexport type SimpleGroupReply = typeof SimpleGroupReply\nexport const Seal = 13\nexport type Seal = typeof Seal\nexport const PrivateDirectMessage = 14\nexport type PrivateDirectMessage = typeof PrivateDirectMessage\nexport const FileMessage = 15\nexport type FileMessage = typeof FileMessage\nexport const GenericRepost = 16\nexport type GenericRepost = typeof GenericRepost\nexport const ReactionToWebsite = 17\nexport type ReactionToWebsite = typeof ReactionToWebsite\nexport const Photo = 20\nexport type Photo = typeof Photo\nexport const NormalVideo = 21\nexport type NormalVideo = typeof NormalVideo\nexport const ShortVideo = 22\nexport type ShortVideo = typeof ShortVideo\nexport const PublicMessage = 24\nexport type PublicMessage = typeof PublicMessage\nexport const ChannelCreation = 40\nexport type ChannelCreation = typeof ChannelCreation\nexport const ChannelMetadata = 41\nexport type ChannelMetadata = typeof ChannelMetadata\nexport const ChannelMessage = 42\nexport type ChannelMessage = typeof ChannelMessage\nexport const ChannelHideMessage = 43\nexport type ChannelHideMessage = typeof ChannelHideMessage\nexport const ChannelMuteUser = 44\nexport type ChannelMuteUser = typeof ChannelMuteUser\nexport const PodcastEpisode = 54\nexport type PodcastEpisode = typeof PodcastEpisode\nexport const Chess = 64\nexport type Chess = typeof Chess\nexport const MergeRequests = 818\nexport type MergeRequests = typeof MergeRequests\nexport const PollResponse = 1018\nexport type PollResponse = typeof PollResponse\nexport const Bid = 1021\nexport type Bid = typeof Bid\nexport const BidConfirmation = 1022\nexport type BidConfirmation = typeof BidConfirmation\nexport const OpenTimestamps = 1040\nexport type OpenTimestamps = typeof OpenTimestamps\nexport const GiftWrap = 1059\nexport type GiftWrap = typeof GiftWrap\nexport const FileMetadata = 1063\nexport type FileMetadata = typeof FileMetadata\nexport const Poll = 1068\nexport type Poll = typeof Poll\nexport const Comment = 1111\nexport type Comment = typeof Comment\nexport const Voice = 1222\nexport type Voice = typeof Voice\nexport const Scroll = 1227\nexport type Scroll = typeof Scroll\nexport const VoiceComment = 1244\nexport type VoiceComment = typeof VoiceComment\nexport const LiveChatMessage = 1311\nexport type LiveChatMessage = typeof LiveChatMessage\nexport const CodeSnippet = 1337\nexport type CodeSnippet = typeof CodeSnippet\nexport const Patch = 1617\nexport type Patch = typeof Patch\nexport const GitPullRequest = 1618\nexport type GitPullRequest = typeof GitPullRequest\nexport const GitPullRequestUpdate = 1619\nexport type GitPullRequestUpdate = typeof GitPullRequestUpdate\nexport const Issue = 1621\nexport type Issue = typeof Issue\nexport const Reply = 1622\nexport type Reply = typeof Reply\nexport const StatusOpen = 1630\nexport type StatusOpen = typeof StatusOpen\nexport const StatusApplied = 1631\nexport type StatusApplied = typeof StatusApplied\nexport const StatusClosed = 1632\nexport type StatusClosed = typeof StatusClosed\nexport const StatusDraft = 1633\nexport type StatusDraft = typeof StatusDraft\nexport const ProblemTracker = 1971\nexport type ProblemTracker = typeof ProblemTracker\nexport const Report = 1984\nexport type Report = typeof Report\nexport const Reporting = 1984\nexport type Reporting = typeof Reporting\nexport const Label = 1985\nexport type Label = typeof Label\nexport const RelayReviews = 1986\nexport type RelayReviews = typeof RelayReviews\nexport const AIEmbeddings = 1987\nexport type AIEmbeddings = typeof AIEmbeddings\nexport const Torrent = 2003\nexport type Torrent = typeof Torrent\nexport const TorrentComment = 2004\nexport type TorrentComment = typeof TorrentComment\nexport const CoinjoinPool = 2022\nexport type CoinjoinPool = typeof CoinjoinPool\nexport const DecoupledKeyClientAnnouncement = 4454\nexport type DecoupledKeyClientAnnouncement = typeof DecoupledKeyClientAnnouncement\nexport const DecoupledEncryptionKeyDistribution = 4455\nexport type DecoupledEncryptionKeyDistribution = typeof DecoupledEncryptionKeyDistribution\nexport const CommunityPostApproval = 4550\nexport type CommunityPostApproval = typeof CommunityPostApproval\nexport const JobRequest = 5999\nexport type JobRequest = typeof JobRequest\nexport const JobResult = 6999\nexport type JobResult = typeof JobResult\nexport const JobFeedback = 7000\nexport type JobFeedback = typeof JobFeedback\nexport const ReservedCashuWalletTokens = 7374\nexport type ReservedCashuWalletTokens = typeof ReservedCashuWalletTokens\nexport const CashuWalletTokens = 7375\nexport type CashuWalletTokens = typeof CashuWalletTokens\nexport const CashuWalletHistory = 7376\nexport type CashuWalletHistory = typeof CashuWalletHistory\nexport const GeocacheLog = 7516\nexport type GeocacheLog = typeof GeocacheLog\nexport const GeocacheProofOfFind = 7517\nexport type GeocacheProofOfFind = typeof GeocacheProofOfFind\nexport const SimpleGroupPutUser = 9000\nexport type SimpleGroupPutUser = typeof SimpleGroupPutUser\nexport const SimpleGroupRemoveUser = 9001\nexport type SimpleGroupRemoveUser = typeof SimpleGroupRemoveUser\nexport const SimpleGroupEditMetadata = 9002\nexport type SimpleGroupEditMetadata = typeof SimpleGroupEditMetadata\nexport const SimpleGroupDeleteEvent = 9005\nexport type SimpleGroupDeleteEvent = typeof SimpleGroupDeleteEvent\nexport const SimpleGroupCreateGroup = 9007\nexport type SimpleGroupCreateGroup = typeof SimpleGroupCreateGroup\nexport const SimpleGroupDeleteGroup = 9008\nexport type SimpleGroupDeleteGroup = typeof SimpleGroupDeleteGroup\nexport const SimpleGroupCreateInvite = 9009\nexport type SimpleGroupCreateInvite = typeof SimpleGroupCreateInvite\nexport const SimpleGroupJoinRequest = 9021\nexport type SimpleGroupJoinRequest = typeof SimpleGroupJoinRequest\nexport const SimpleGroupLeaveRequest = 9022\nexport type SimpleGroupLeaveRequest = typeof SimpleGroupLeaveRequest\nexport const ZapGoal = 9041\nexport type ZapGoal = typeof ZapGoal\nexport const NutZap = 9321\nexport type NutZap = typeof NutZap\nexport const TidalLogin = 9467\nexport type TidalLogin = typeof TidalLogin\nexport const ZapRequest = 9734\nexport type ZapRequest = typeof ZapRequest\nexport const Zap = 9735\nexport type Zap = typeof Zap\nexport const Highlights = 9802\nexport type Highlights = typeof Highlights\nexport const Mutelist = 10000\nexport type Mutelist = typeof Mutelist\nexport const Pinlist = 10001\nexport type Pinlist = typeof Pinlist\nexport const RelayList = 10002\nexport type RelayList = typeof RelayList\nexport const BookmarkList = 10003\nexport type BookmarkList = typeof BookmarkList\nexport const CommunitiesList = 10004\nexport type CommunitiesList = typeof CommunitiesList\nexport const PublicChatsList = 10005\nexport type PublicChatsList = typeof PublicChatsList\nexport const BlockedRelaysList = 10006\nexport type BlockedRelaysList = typeof BlockedRelaysList\nexport const SearchRelaysList = 10007\nexport type SearchRelaysList = typeof SearchRelaysList\nexport const SimpleGroupList = 10009\nexport type SimpleGroupList = typeof SimpleGroupList\nexport const FavoriteRelays = 10012\nexport type FavoriteRelays = typeof FavoriteRelays\nexport const PrivateEventRelayList = 10013\nexport type PrivateEventRelayList = typeof PrivateEventRelayList\nexport const InterestsList = 10015\nexport type InterestsList = typeof InterestsList\nexport const NutZapInfo = 10019\nexport type NutZapInfo = typeof NutZapInfo\nexport const MediaFollows = 10020\nexport type MediaFollows = typeof MediaFollows\nexport const UserEmojiList = 10030\nexport type UserEmojiList = typeof UserEmojiList\nexport const DecoupledKeyAnnouncement = 10044\nexport type DecoupledKeyAnnouncement = typeof DecoupledKeyAnnouncement\nexport const DirectMessageRelaysList = 10050\nexport type DirectMessageRelaysList = typeof DirectMessageRelaysList\nexport const FavoritePodcasts = 10054\nexport type FavoritePodcasts = typeof FavoritePodcasts\nexport const BlossomServerList = 10063\nexport type BlossomServerList = typeof BlossomServerList\nexport const FileServerPreference = 10096\nexport type FileServerPreference = typeof FileServerPreference\nexport const GoodWikiAuthorList = 10101\nexport type GoodWikiAuthorList = typeof GoodWikiAuthorList\nexport const GoodWikiRelayList = 10102\nexport type GoodWikiRelayList = typeof GoodWikiRelayList\nexport const PodcastMetadata = 10154\nexport type PodcastMetadata = typeof PodcastMetadata\nexport const AuthoredPodcasts = 10164\nexport type AuthoredPodcasts = typeof AuthoredPodcasts\nexport const RelayMonitorAnnouncement = 10166\nexport type RelayMonitorAnnouncement = typeof RelayMonitorAnnouncement\nexport const RoomPresence = 10312\nexport type RoomPresence = typeof RoomPresence\nexport const UserGraspList = 10317\nexport type UserGraspList = typeof UserGraspList\nexport const ProxyAnnouncement = 10377\nexport type ProxyAnnouncement = typeof ProxyAnnouncement\nexport const TransportMethodAnnouncement = 11111\nexport type TransportMethodAnnouncement = typeof TransportMethodAnnouncement\nexport const NWCWalletInfo = 13194\nexport type NWCWalletInfo = typeof NWCWalletInfo\nexport const NsiteRoot = 15128\nexport type NsiteRoot = typeof NsiteRoot\nexport const CashuWalletEvent = 17375\nexport type CashuWalletEvent = typeof CashuWalletEvent\nexport const LightningPubRPC = 21000\nexport type LightningPubRPC = typeof LightningPubRPC\nexport const ClientAuth = 22242\nexport type ClientAuth = typeof ClientAuth\nexport const NWCWalletRequest = 23194\nexport type NWCWalletRequest = typeof NWCWalletRequest\nexport const NWCWalletResponse = 23195\nexport type NWCWalletResponse = typeof NWCWalletResponse\nexport const NostrConnect = 24133\nexport type NostrConnect = typeof NostrConnect\nexport const BlobsAuth = 24242\nexport type BlobsAuth = typeof BlobsAuth\nexport const HTTPAuth = 27235\nexport type HTTPAuth = typeof HTTPAuth\nexport const Followsets = 30000\nexport type Followsets = typeof Followsets\nexport const Genericlists = 30001\nexport type Genericlists = typeof Genericlists\nexport const Relaysets = 30002\nexport type Relaysets = typeof Relaysets\nexport const Bookmarksets = 30003\nexport type Bookmarksets = typeof Bookmarksets\nexport const Curationsets = 30004\nexport type Curationsets = typeof Curationsets\nexport const CuratedVideoSets = 30005\nexport type CuratedVideoSets = typeof CuratedVideoSets\nexport const MuteSets = 30007\nexport type MuteSets = typeof MuteSets\nexport const ProfileBadges = 30008\nexport type ProfileBadges = typeof ProfileBadges\nexport const BadgeDefinition = 30009\nexport type BadgeDefinition = typeof BadgeDefinition\nexport const Interestsets = 30015\nexport type Interestsets = typeof Interestsets\nexport const CreateOrUpdateStall = 30017\nexport type CreateOrUpdateStall = typeof CreateOrUpdateStall\nexport const CreateOrUpdateProduct = 30018\nexport type CreateOrUpdateProduct = typeof CreateOrUpdateProduct\nexport const MarketplaceUI = 30019\nexport type MarketplaceUI = typeof MarketplaceUI\nexport const ProductSoldAsAuction = 30020\nexport type ProductSoldAsAuction = typeof ProductSoldAsAuction\nexport const LongFormArticle = 30023\nexport type LongFormArticle = typeof LongFormArticle\nexport const DraftLong = 30024\nexport type DraftLong = typeof DraftLong\nexport const Emojisets = 30030\nexport type Emojisets = typeof Emojisets\nexport const ModularArticleHeader = 30040\nexport type ModularArticleHeader = typeof ModularArticleHeader\nexport const ModularArticleContent = 30041\nexport type ModularArticleContent = typeof ModularArticleContent\nexport const ReleaseArtifactSets = 30063\nexport type ReleaseArtifactSets = typeof ReleaseArtifactSets\nexport const Application = 30078\nexport type Application = typeof Application\nexport const RelayDiscovery = 30166\nexport type RelayDiscovery = typeof RelayDiscovery\nexport const AppCurationSet = 30267\nexport type AppCurationSet = typeof AppCurationSet\nexport const LiveEvent = 30311\nexport type LiveEvent = typeof LiveEvent\nexport const InteractiveRoom = 30312\nexport type InteractiveRoom = typeof InteractiveRoom\nexport const ConferenceEvent = 30313\nexport type ConferenceEvent = typeof ConferenceEvent\nexport const UserStatuses = 30315\nexport type UserStatuses = typeof UserStatuses\nexport const SlideSet = 30388\nexport type SlideSet = typeof SlideSet\nexport const ClassifiedListing = 30402\nexport type ClassifiedListing = typeof ClassifiedListing\nexport const DraftClassifiedListing = 30403\nexport type DraftClassifiedListing = typeof DraftClassifiedListing\nexport const RepositoryAnnouncement = 30617\nexport type RepositoryAnnouncement = typeof RepositoryAnnouncement\nexport const RepositoryState = 30618\nexport type RepositoryState = typeof RepositoryState\nexport const WikiArticle = 30818\nexport type WikiArticle = typeof WikiArticle\nexport const Redirects = 30819\nexport type Redirects = typeof Redirects\nexport const DraftEvent = 31234\nexport type DraftEvent = typeof DraftEvent\nexport const LinkSet = 31388\nexport type LinkSet = typeof LinkSet\nexport const Feed = 31890\nexport type Feed = typeof Feed\nexport const Date = 31922\nexport type Date = typeof Date\nexport const Time = 31923\nexport type Time = typeof Time\nexport const Calendar = 31924\nexport type Calendar = typeof Calendar\nexport const CalendarEventRSVP = 31925\nexport type CalendarEventRSVP = typeof CalendarEventRSVP\nexport const RelayReview = 31987\nexport type RelayReview = typeof RelayReview\nexport const Handlerrecommendation = 31989\nexport type Handlerrecommendation = typeof Handlerrecommendation\nexport const Handlerinformation = 31990\nexport type Handlerinformation = typeof Handlerinformation\nexport const SoftwareApplication = 32267\nexport type SoftwareApplication = typeof SoftwareApplication\nexport const LegacyNsiteFile = 34128\nexport type LegacyNsiteFile = typeof LegacyNsiteFile\nexport const VideoViewEvent = 34237\nexport type VideoViewEvent = typeof VideoViewEvent\nexport const CommunityDefinition = 34550\nexport type CommunityDefinition = typeof CommunityDefinition\nexport const NsiteNamed = 35128\nexport type NsiteNamed = typeof NsiteNamed\nexport const GeocacheListing = 37515\nexport type GeocacheListing = typeof GeocacheListing\nexport const GeocacheLogEntry = 37516\nexport type GeocacheLogEntry = typeof GeocacheLogEntry\nexport const CashuMintAnnouncement = 38172\nexport type CashuMintAnnouncement = typeof CashuMintAnnouncement\nexport const FedimintAnnouncement = 38173\nexport type FedimintAnnouncement = typeof FedimintAnnouncement\nexport const PeerToPeerOrderEvents = 38383\nexport type PeerToPeerOrderEvents = typeof PeerToPeerOrderEvents\nexport const GroupMetadata = 39000\nexport type GroupMetadata = typeof GroupMetadata\nexport const SimpleGroupAdmins = 39001\nexport type SimpleGroupAdmins = typeof SimpleGroupAdmins\nexport const SimpleGroupMembers = 39002\nexport type SimpleGroupMembers = typeof SimpleGroupMembers\nexport const SimpleGroupRoles = 39003\nexport type SimpleGroupRoles = typeof SimpleGroupRoles\nexport const SimpleGroupLiveKitParticipants = 39004\nexport type SimpleGroupLiveKitParticipants = typeof SimpleGroupLiveKitParticipants\nexport const StarterPacks = 39089\nexport type StarterPacks = typeof StarterPacks\nexport const MediaStarterPacks = 39092\nexport type MediaStarterPacks = typeof MediaStarterPacks\nexport const WebBookmarks = 39701\nexport type WebBookmarks = typeof WebBookmarks\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACuRO,IAAM,aAAa;;;ADjRnB,SAAS,cAAc,UAAkB,WAAkC;AAChF,SAAO;AAAA,IACL,MAAM;AAAA,IACN,YAAY,KAAK,MAAM,KAAK,IAAI,IAAI,GAAI;AAAA,IACxC,MAAM;AAAA,MACJ,CAAC,SAAS,QAAQ;AAAA,MAClB,CAAC,aAAa,SAAS;AAAA,IACzB;AAAA,IACA,SAAS;AAAA,EACX;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/lib/cjs/nip45.js
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// nip45.ts
|
|
21
|
+
var nip45_exports = {};
|
|
22
|
+
__export(nip45_exports, {
|
|
23
|
+
computeOffset: () => computeOffset,
|
|
24
|
+
estimateCount: () => estimateCount,
|
|
25
|
+
feedEvent: () => feedEvent,
|
|
26
|
+
feedPubkey: () => feedPubkey,
|
|
27
|
+
getCountManyFilter: () => getCountManyFilter,
|
|
28
|
+
getFilterFirstTagValue: () => getFilterFirstTagValue,
|
|
29
|
+
hllDecode: () => hllDecode,
|
|
30
|
+
hllEncode: () => hllEncode,
|
|
31
|
+
mergeHll: () => mergeHll,
|
|
32
|
+
newHll: () => newHll
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(nip45_exports);
|
|
35
|
+
var import_sha2 = require("@noble/hashes/sha2.js");
|
|
36
|
+
var import_utils = require("@noble/hashes/utils.js");
|
|
37
|
+
var M = 256;
|
|
38
|
+
var HLL_HEX_LENGTH = M * 2;
|
|
39
|
+
var utf8Encoder = new TextEncoder();
|
|
40
|
+
function getCountManyFilter(target, directive) {
|
|
41
|
+
switch (directive) {
|
|
42
|
+
case "reactions":
|
|
43
|
+
return { "#e": [target], kinds: [7] };
|
|
44
|
+
case "reposts":
|
|
45
|
+
return { "#e": [target], kinds: [6] };
|
|
46
|
+
case "quotes":
|
|
47
|
+
return { "#q": [target], kinds: [1, 1111] };
|
|
48
|
+
case "replies":
|
|
49
|
+
return { "#e": [target], kinds: [1] };
|
|
50
|
+
case "comments":
|
|
51
|
+
return { "#E": [target], kinds: [1111] };
|
|
52
|
+
case "followers":
|
|
53
|
+
return { "#p": [target], kinds: [3] };
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function newHll() {
|
|
57
|
+
return new Uint8Array(M);
|
|
58
|
+
}
|
|
59
|
+
function hllDecode(hex) {
|
|
60
|
+
if (hex.length !== HLL_HEX_LENGTH || !/^[0-9a-fA-F]+$/.test(hex))
|
|
61
|
+
return void 0;
|
|
62
|
+
const registers = new Uint8Array(M);
|
|
63
|
+
for (let i = 0; i < M; i++) {
|
|
64
|
+
registers[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);
|
|
65
|
+
}
|
|
66
|
+
return registers;
|
|
67
|
+
}
|
|
68
|
+
function hllEncode(registers) {
|
|
69
|
+
if (registers.length !== M)
|
|
70
|
+
throw new Error(`invalid number of registers ${registers.length}`);
|
|
71
|
+
let hex = "";
|
|
72
|
+
for (let i = 0; i < M; i++) {
|
|
73
|
+
hex += registers[i].toString(16).padStart(2, "0");
|
|
74
|
+
}
|
|
75
|
+
return hex;
|
|
76
|
+
}
|
|
77
|
+
function computeOffset(filterFirstTagValue) {
|
|
78
|
+
let hex = filterFirstTagValue;
|
|
79
|
+
if (!isHex64(hex)) {
|
|
80
|
+
const parts = hex.split(":");
|
|
81
|
+
if (parts.length === 3 && isHex64(parts[1])) {
|
|
82
|
+
hex = parts[1];
|
|
83
|
+
} else {
|
|
84
|
+
hex = (0, import_utils.bytesToHex)((0, import_sha2.sha256)(utf8Encoder.encode(filterFirstTagValue)));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return parseInt(hex[32], 16) + 8;
|
|
88
|
+
}
|
|
89
|
+
function getFilterFirstTagValue(filter) {
|
|
90
|
+
for (const key in filter) {
|
|
91
|
+
if (key[0] !== "#")
|
|
92
|
+
continue;
|
|
93
|
+
const values = filter[key];
|
|
94
|
+
if (Array.isArray(values) && typeof values[0] === "string")
|
|
95
|
+
return values[0];
|
|
96
|
+
}
|
|
97
|
+
return void 0;
|
|
98
|
+
}
|
|
99
|
+
function feedPubkey(hll, pubkey, offset) {
|
|
100
|
+
if (offset < 0 || offset > 24)
|
|
101
|
+
throw new Error(`invalid offset ${offset}`);
|
|
102
|
+
if (!isHex64(pubkey))
|
|
103
|
+
throw new Error("pubkey must be 32-byte hex");
|
|
104
|
+
if (hll.length === 0)
|
|
105
|
+
hll = newHll();
|
|
106
|
+
if (hll.length !== M)
|
|
107
|
+
throw new Error(`invalid number of registers ${hll.length}`);
|
|
108
|
+
const ri = parseInt(pubkey.slice(offset * 2, offset * 2 + 2), 16);
|
|
109
|
+
const value = countLeadingZeroBitsAfterOffset(pubkey, offset) + 1;
|
|
110
|
+
if (value > hll[ri])
|
|
111
|
+
hll[ri] = value;
|
|
112
|
+
return hll;
|
|
113
|
+
}
|
|
114
|
+
function feedEvent(hll, event, offset) {
|
|
115
|
+
return feedPubkey(hll, event.pubkey, offset);
|
|
116
|
+
}
|
|
117
|
+
function mergeHll(target, source) {
|
|
118
|
+
if (target.length === 0)
|
|
119
|
+
target = newHll();
|
|
120
|
+
if (target.length !== M)
|
|
121
|
+
throw new Error(`invalid number of registers ${target.length}`);
|
|
122
|
+
if (source.length !== M)
|
|
123
|
+
throw new Error(`invalid number of registers ${source.length}`);
|
|
124
|
+
for (let i = 0; i < M; i++) {
|
|
125
|
+
if (source[i] > target[i])
|
|
126
|
+
target[i] = source[i];
|
|
127
|
+
}
|
|
128
|
+
return target;
|
|
129
|
+
}
|
|
130
|
+
function estimateCount(hll) {
|
|
131
|
+
if (hll.length === 0)
|
|
132
|
+
return 0;
|
|
133
|
+
if (hll.length !== M)
|
|
134
|
+
throw new Error(`invalid number of registers ${hll.length}`);
|
|
135
|
+
const v = countZeros(hll);
|
|
136
|
+
if (v !== 0) {
|
|
137
|
+
const lc = linearCounting(M, v);
|
|
138
|
+
if (lc <= 220)
|
|
139
|
+
return Math.floor(lc);
|
|
140
|
+
}
|
|
141
|
+
const estimate = calculateEstimate(hll);
|
|
142
|
+
if (estimate <= M * 3 && v !== 0)
|
|
143
|
+
return Math.floor(linearCounting(M, v));
|
|
144
|
+
return Math.floor(estimate);
|
|
145
|
+
}
|
|
146
|
+
function isHex64(value) {
|
|
147
|
+
return /^[0-9a-fA-F]{64}$/.test(value);
|
|
148
|
+
}
|
|
149
|
+
function countLeadingZeroBitsAfterOffset(pubkey, offset) {
|
|
150
|
+
let zeroBits = 0;
|
|
151
|
+
for (let i = offset + 1; i < offset + 8; i++) {
|
|
152
|
+
const byte = parseInt(pubkey.slice(i * 2, i * 2 + 2), 16);
|
|
153
|
+
if (byte === 0) {
|
|
154
|
+
zeroBits += 8;
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
let mask = 128;
|
|
158
|
+
while ((byte & mask) === 0) {
|
|
159
|
+
zeroBits++;
|
|
160
|
+
mask >>= 1;
|
|
161
|
+
}
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
return zeroBits;
|
|
165
|
+
}
|
|
166
|
+
function countZeros(registers) {
|
|
167
|
+
let count = 0;
|
|
168
|
+
for (let i = 0; i < M; i++) {
|
|
169
|
+
if (registers[i] === 0)
|
|
170
|
+
count++;
|
|
171
|
+
}
|
|
172
|
+
return count;
|
|
173
|
+
}
|
|
174
|
+
function linearCounting(m, v) {
|
|
175
|
+
return m * Math.log(m / v);
|
|
176
|
+
}
|
|
177
|
+
function calculateEstimate(registers) {
|
|
178
|
+
let sum = 0;
|
|
179
|
+
for (let i = 0; i < M; i++) {
|
|
180
|
+
sum += 1 / 2 ** registers[i];
|
|
181
|
+
}
|
|
182
|
+
return 0.7182725932495458 * M * M / sum;
|
|
183
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../nip45.ts"],
|
|
4
|
+
"sourcesContent": ["import { sha256 } from '@noble/hashes/sha2.js'\nimport { bytesToHex } from '@noble/hashes/utils.js'\n\nimport type { Event } from './core.ts'\nimport type { Filter } from './filter.ts'\n\nconst M = 256\nconst HLL_HEX_LENGTH = M * 2\nconst utf8Encoder = new TextEncoder()\n\nexport type CountManyDirective = 'reactions' | 'reposts' | 'quotes' | 'replies' | 'comments' | 'followers'\n\nexport function getCountManyFilter(target: string, directive: CountManyDirective): Filter {\n switch (directive) {\n case 'reactions':\n return { '#e': [target], kinds: [7] }\n case 'reposts':\n return { '#e': [target], kinds: [6] }\n case 'quotes':\n return { '#q': [target], kinds: [1, 1111] }\n case 'replies':\n return { '#e': [target], kinds: [1] }\n case 'comments':\n return { '#E': [target], kinds: [1111] }\n case 'followers':\n return { '#p': [target], kinds: [3] }\n }\n}\n\nexport function newHll(): Uint8Array {\n return new Uint8Array(M)\n}\n\nexport function hllDecode(hex: string): Uint8Array | undefined {\n if (hex.length !== HLL_HEX_LENGTH || !/^[0-9a-fA-F]+$/.test(hex)) return undefined\n\n const registers = new Uint8Array(M)\n for (let i = 0; i < M; i++) {\n registers[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16)\n }\n return registers\n}\n\nexport function hllEncode(registers: Uint8Array): string {\n if (registers.length !== M) throw new Error(`invalid number of registers ${registers.length}`)\n\n let hex = ''\n for (let i = 0; i < M; i++) {\n hex += registers[i].toString(16).padStart(2, '0')\n }\n return hex\n}\n\nexport function computeOffset(filterFirstTagValue: string): number {\n let hex = filterFirstTagValue\n\n if (!isHex64(hex)) {\n const parts = hex.split(':')\n if (parts.length === 3 && isHex64(parts[1])) {\n hex = parts[1]\n } else {\n hex = bytesToHex(sha256(utf8Encoder.encode(filterFirstTagValue)))\n }\n }\n\n return parseInt(hex[32], 16) + 8\n}\n\nexport function getFilterFirstTagValue(filter: Filter): string | undefined {\n for (const key in filter) {\n if (key[0] !== '#') continue\n\n const values = filter[key as `#${string}`]\n if (Array.isArray(values) && typeof values[0] === 'string') return values[0]\n }\n\n return undefined\n}\n\nexport function feedPubkey(hll: Uint8Array, pubkey: string, offset: number): Uint8Array {\n if (offset < 0 || offset > 24) throw new Error(`invalid offset ${offset}`)\n if (!isHex64(pubkey)) throw new Error('pubkey must be 32-byte hex')\n\n if (hll.length === 0) hll = newHll()\n if (hll.length !== M) throw new Error(`invalid number of registers ${hll.length}`)\n\n const ri = parseInt(pubkey.slice(offset * 2, offset * 2 + 2), 16)\n const value = countLeadingZeroBitsAfterOffset(pubkey, offset) + 1\n if (value > hll[ri]) hll[ri] = value\n\n return hll\n}\n\nexport function feedEvent(hll: Uint8Array, event: Event, offset: number): Uint8Array {\n return feedPubkey(hll, event.pubkey, offset)\n}\n\nexport function mergeHll(target: Uint8Array, source: Uint8Array): Uint8Array {\n if (target.length === 0) target = newHll()\n if (target.length !== M) throw new Error(`invalid number of registers ${target.length}`)\n if (source.length !== M) throw new Error(`invalid number of registers ${source.length}`)\n\n for (let i = 0; i < M; i++) {\n if (source[i] > target[i]) target[i] = source[i]\n }\n\n return target\n}\n\nexport function estimateCount(hll: Uint8Array): number {\n if (hll.length === 0) return 0\n if (hll.length !== M) throw new Error(`invalid number of registers ${hll.length}`)\n\n const v = countZeros(hll)\n if (v !== 0) {\n const lc = linearCounting(M, v)\n if (lc <= 220) return Math.floor(lc)\n }\n\n const estimate = calculateEstimate(hll)\n if (estimate <= M * 3 && v !== 0) return Math.floor(linearCounting(M, v))\n\n return Math.floor(estimate)\n}\n\nfunction isHex64(value: string): boolean {\n return /^[0-9a-fA-F]{64}$/.test(value)\n}\n\nfunction countLeadingZeroBitsAfterOffset(pubkey: string, offset: number): number {\n let zeroBits = 0\n for (let i = offset + 1; i < offset + 8; i++) {\n const byte = parseInt(pubkey.slice(i * 2, i * 2 + 2), 16)\n if (byte === 0) {\n zeroBits += 8\n continue\n }\n\n let mask = 0x80\n while ((byte & mask) === 0) {\n zeroBits++\n mask >>= 1\n }\n break\n }\n return zeroBits\n}\n\nfunction countZeros(registers: Uint8Array): number {\n let count = 0\n for (let i = 0; i < M; i++) {\n if (registers[i] === 0) count++\n }\n return count\n}\n\nfunction linearCounting(m: number, v: number): number {\n return m * Math.log(m / v)\n}\n\nfunction calculateEstimate(registers: Uint8Array): number {\n let sum = 0\n for (let i = 0; i < M; i++) {\n sum += 1 / 2 ** registers[i]\n }\n return (0.7182725932495458 * M * M) / sum\n}\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/lib/cjs/nip46.js
CHANGED
|
@@ -602,19 +602,38 @@ var AbstractRelay = class {
|
|
|
602
602
|
}, this.publishTimeout);
|
|
603
603
|
this.openEventPublishes.set(event.id, { resolve, reject, timeout });
|
|
604
604
|
});
|
|
605
|
-
|
|
605
|
+
try {
|
|
606
|
+
await this.send('["EVENT",' + JSON.stringify(event) + "]");
|
|
607
|
+
} catch (err) {
|
|
608
|
+
const ep = this.openEventPublishes.get(event.id);
|
|
609
|
+
if (ep) {
|
|
610
|
+
ep.reject(err);
|
|
611
|
+
this.openEventPublishes.delete(event.id);
|
|
612
|
+
}
|
|
613
|
+
}
|
|
606
614
|
this.ongoingOperations--;
|
|
607
615
|
if (this.ongoingOperations === 0)
|
|
608
616
|
this.idleSince = Date.now();
|
|
609
617
|
return ret;
|
|
610
618
|
}
|
|
611
619
|
async count(filters, params) {
|
|
620
|
+
return (await this.countWithHLL(filters, params)).count;
|
|
621
|
+
}
|
|
622
|
+
async countWithHLL(filters, params) {
|
|
612
623
|
this.serial++;
|
|
613
624
|
const id = params?.id || "count:" + this.serial;
|
|
614
625
|
const ret = new Promise((resolve, reject) => {
|
|
615
626
|
this.openCountRequests.set(id, { resolve, reject });
|
|
616
627
|
});
|
|
617
|
-
|
|
628
|
+
try {
|
|
629
|
+
await this.send('["COUNT","' + id + '",' + JSON.stringify(filters).substring(1));
|
|
630
|
+
} catch (err) {
|
|
631
|
+
const cr = this.openCountRequests.get(id);
|
|
632
|
+
if (cr) {
|
|
633
|
+
cr.reject(err);
|
|
634
|
+
this.openCountRequests.delete(id);
|
|
635
|
+
}
|
|
636
|
+
}
|
|
618
637
|
return ret;
|
|
619
638
|
}
|
|
620
639
|
subscribe(filters, params) {
|
|
@@ -692,7 +711,7 @@ var AbstractRelay = class {
|
|
|
692
711
|
const payload = data[2];
|
|
693
712
|
const cr = this.openCountRequests.get(id);
|
|
694
713
|
if (cr) {
|
|
695
|
-
cr.resolve(payload
|
|
714
|
+
cr.resolve(payload);
|
|
696
715
|
this.openCountRequests.delete(id);
|
|
697
716
|
}
|
|
698
717
|
return;
|
|
@@ -722,8 +741,14 @@ var AbstractRelay = class {
|
|
|
722
741
|
case "CLOSED": {
|
|
723
742
|
const id = data[1];
|
|
724
743
|
const so = this.openSubs.get(id);
|
|
725
|
-
if (!so)
|
|
744
|
+
if (!so) {
|
|
745
|
+
const cr = this.openCountRequests.get(id);
|
|
746
|
+
if (cr) {
|
|
747
|
+
cr.reject(new Error(data[2]));
|
|
748
|
+
this.openCountRequests.delete(id);
|
|
749
|
+
}
|
|
726
750
|
return;
|
|
751
|
+
}
|
|
727
752
|
so.closed = true;
|
|
728
753
|
so.close(data[2]);
|
|
729
754
|
return;
|
|
@@ -832,6 +857,63 @@ var alwaysTrue = (t) => {
|
|
|
832
857
|
return true;
|
|
833
858
|
};
|
|
834
859
|
|
|
860
|
+
// nip45.ts
|
|
861
|
+
var import_sha23 = require("@noble/hashes/sha2.js");
|
|
862
|
+
var import_utils8 = require("@noble/hashes/utils.js");
|
|
863
|
+
var M = 256;
|
|
864
|
+
var HLL_HEX_LENGTH = M * 2;
|
|
865
|
+
var utf8Encoder2 = new TextEncoder();
|
|
866
|
+
function getCountManyFilter(target, directive) {
|
|
867
|
+
switch (directive) {
|
|
868
|
+
case "reactions":
|
|
869
|
+
return { "#e": [target], kinds: [7] };
|
|
870
|
+
case "reposts":
|
|
871
|
+
return { "#e": [target], kinds: [6] };
|
|
872
|
+
case "quotes":
|
|
873
|
+
return { "#q": [target], kinds: [1, 1111] };
|
|
874
|
+
case "replies":
|
|
875
|
+
return { "#e": [target], kinds: [1] };
|
|
876
|
+
case "comments":
|
|
877
|
+
return { "#E": [target], kinds: [1111] };
|
|
878
|
+
case "followers":
|
|
879
|
+
return { "#p": [target], kinds: [3] };
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
function newHll() {
|
|
883
|
+
return new Uint8Array(M);
|
|
884
|
+
}
|
|
885
|
+
function hllDecode(hex) {
|
|
886
|
+
if (hex.length !== HLL_HEX_LENGTH || !/^[0-9a-fA-F]+$/.test(hex))
|
|
887
|
+
return void 0;
|
|
888
|
+
const registers = new Uint8Array(M);
|
|
889
|
+
for (let i2 = 0; i2 < M; i2++) {
|
|
890
|
+
registers[i2] = parseInt(hex.slice(i2 * 2, i2 * 2 + 2), 16);
|
|
891
|
+
}
|
|
892
|
+
return registers;
|
|
893
|
+
}
|
|
894
|
+
function hllEncode(registers) {
|
|
895
|
+
if (registers.length !== M)
|
|
896
|
+
throw new Error(`invalid number of registers ${registers.length}`);
|
|
897
|
+
let hex = "";
|
|
898
|
+
for (let i2 = 0; i2 < M; i2++) {
|
|
899
|
+
hex += registers[i2].toString(16).padStart(2, "0");
|
|
900
|
+
}
|
|
901
|
+
return hex;
|
|
902
|
+
}
|
|
903
|
+
function mergeHll(target, source) {
|
|
904
|
+
if (target.length === 0)
|
|
905
|
+
target = newHll();
|
|
906
|
+
if (target.length !== M)
|
|
907
|
+
throw new Error(`invalid number of registers ${target.length}`);
|
|
908
|
+
if (source.length !== M)
|
|
909
|
+
throw new Error(`invalid number of registers ${source.length}`);
|
|
910
|
+
for (let i2 = 0; i2 < M; i2++) {
|
|
911
|
+
if (source[i2] > target[i2])
|
|
912
|
+
target[i2] = source[i2];
|
|
913
|
+
}
|
|
914
|
+
return target;
|
|
915
|
+
}
|
|
916
|
+
|
|
835
917
|
// abstract-pool.ts
|
|
836
918
|
var AbstractSimplePool = class {
|
|
837
919
|
relays = /* @__PURE__ */ new Map();
|
|
@@ -1059,6 +1141,48 @@ var AbstractSimplePool = class {
|
|
|
1059
1141
|
events.sort((a, b) => b.created_at - a.created_at);
|
|
1060
1142
|
return events[0] || null;
|
|
1061
1143
|
}
|
|
1144
|
+
async countMany(relays, target, directive, params) {
|
|
1145
|
+
const filter = getCountManyFilter(target, directive);
|
|
1146
|
+
const urls = [];
|
|
1147
|
+
for (let i2 = 0; i2 < relays.length; i2++) {
|
|
1148
|
+
const url = normalizeURL(relays[i2]);
|
|
1149
|
+
if (urls.indexOf(url) === -1)
|
|
1150
|
+
urls.push(url);
|
|
1151
|
+
}
|
|
1152
|
+
const responses = await Promise.all(
|
|
1153
|
+
urls.map(async (url) => {
|
|
1154
|
+
if (this.allowConnectingToRelay?.(url, ["read", [filter]]) === false)
|
|
1155
|
+
return null;
|
|
1156
|
+
let relay;
|
|
1157
|
+
try {
|
|
1158
|
+
relay = await this.ensureRelay(url, {
|
|
1159
|
+
connectionTimeout: this.maxWaitForConnection < (params?.maxWait || 0) ? Math.max(params.maxWait * 0.8, params.maxWait - 1e3) : this.maxWaitForConnection,
|
|
1160
|
+
abort: params?.abort
|
|
1161
|
+
});
|
|
1162
|
+
} catch (err) {
|
|
1163
|
+
this.onRelayConnectionFailure?.(url);
|
|
1164
|
+
return null;
|
|
1165
|
+
}
|
|
1166
|
+
this.onRelayConnectionSuccess?.(url);
|
|
1167
|
+
return relay.countWithHLL([filter], { id: params?.id }).catch(() => null);
|
|
1168
|
+
})
|
|
1169
|
+
);
|
|
1170
|
+
let count = 0;
|
|
1171
|
+
let hll;
|
|
1172
|
+
for (const response of responses) {
|
|
1173
|
+
if (!response)
|
|
1174
|
+
continue;
|
|
1175
|
+
if (response.count > count)
|
|
1176
|
+
count = response.count;
|
|
1177
|
+
if (!response.hll || response.hll.length !== 512)
|
|
1178
|
+
continue;
|
|
1179
|
+
const registers = hllDecode(response.hll);
|
|
1180
|
+
if (!registers)
|
|
1181
|
+
continue;
|
|
1182
|
+
hll = mergeHll(hll || new Uint8Array(0), registers);
|
|
1183
|
+
}
|
|
1184
|
+
return hll ? { count, hll: hllEncode(hll) } : { count };
|
|
1185
|
+
}
|
|
1062
1186
|
publish(relays, event, params) {
|
|
1063
1187
|
return relays.map(normalizeURL).map(async (url, i2, arr) => {
|
|
1064
1188
|
if (arr.indexOf(url) !== i2) {
|
|
@@ -1383,8 +1507,13 @@ var BunkerSigner = class {
|
|
|
1383
1507
|
if (resp !== "pong")
|
|
1384
1508
|
throw new Error(`result is not pong: ${resp}`);
|
|
1385
1509
|
}
|
|
1386
|
-
async connect() {
|
|
1387
|
-
|
|
1510
|
+
async connect(clientMetadata) {
|
|
1511
|
+
const params = [this.bp.pubkey, this.bp.secret || ""];
|
|
1512
|
+
if (clientMetadata) {
|
|
1513
|
+
params.push("");
|
|
1514
|
+
params.push(JSON.stringify(clientMetadata));
|
|
1515
|
+
}
|
|
1516
|
+
await this.sendRequest("connect", params);
|
|
1388
1517
|
}
|
|
1389
1518
|
async logout() {
|
|
1390
1519
|
let resp = await this.sendRequest("logout", []);
|