nostr-tools 2.23.12 → 2.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/abstract-pool.js +11 -21
- package/lib/cjs/abstract-pool.js.map +3 -3
- package/lib/cjs/abstract-relay.js +1 -1
- package/lib/cjs/abstract-relay.js.map +2 -2
- package/lib/cjs/core.js +17 -1
- package/lib/cjs/core.js.map +3 -3
- package/lib/cjs/filter.js.map +1 -1
- package/lib/cjs/index.js +124 -123
- package/lib/cjs/index.js.map +4 -4
- package/lib/cjs/kinds.js +17 -1
- package/lib/cjs/kinds.js.map +3 -3
- package/lib/cjs/nip04.js.map +1 -1
- package/lib/cjs/nip10.js +20 -5
- package/lib/cjs/nip10.js.map +3 -3
- package/lib/cjs/nip13.js.map +1 -1
- package/lib/cjs/nip17.js +30 -23
- package/lib/cjs/nip17.js.map +4 -4
- package/lib/cjs/nip18.js +21 -14
- package/lib/cjs/nip18.js.map +4 -4
- package/lib/cjs/nip19.js.map +1 -1
- package/lib/cjs/nip21.js.map +1 -1
- package/lib/cjs/nip22.js +22 -7
- package/lib/cjs/nip22.js.map +3 -3
- package/lib/cjs/nip25.js +21 -14
- package/lib/cjs/nip25.js.map +4 -4
- package/lib/cjs/nip27.js.map +1 -1
- package/lib/cjs/nip28.js +21 -14
- package/lib/cjs/nip28.js.map +4 -4
- package/lib/cjs/nip29.js.map +1 -1
- package/lib/cjs/nip30.js.map +2 -2
- package/lib/cjs/nip42.js.map +2 -2
- package/lib/cjs/nip44.js.map +1 -1
- package/lib/cjs/nip45.js +22 -9
- package/lib/cjs/nip45.js.map +4 -4
- package/lib/cjs/nip46.js +63 -63
- package/lib/cjs/nip46.js.map +4 -4
- package/lib/cjs/nip47.js +25 -18
- package/lib/cjs/nip47.js.map +4 -4
- package/lib/cjs/nip57.js +23 -16
- package/lib/cjs/nip57.js.map +4 -4
- package/lib/cjs/nip58.js.map +2 -2
- package/lib/cjs/nip59.js +16 -7
- package/lib/cjs/nip59.js.map +3 -3
- package/lib/cjs/nip75.js.map +1 -1
- package/lib/cjs/nip94.js.map +1 -1
- package/lib/cjs/nip98.js +23 -16
- package/lib/cjs/nip98.js.map +4 -4
- package/lib/cjs/nip99.js.map +2 -2
- package/lib/cjs/nipb0.js +34 -16
- package/lib/cjs/nipb0.js.map +4 -4
- package/lib/cjs/nipb7.js +13 -7
- package/lib/cjs/nipb7.js.map +2 -2
- package/lib/cjs/pool.js +54 -54
- package/lib/cjs/pool.js.map +4 -4
- package/lib/cjs/pure.js +21 -14
- package/lib/cjs/pure.js.map +4 -4
- package/lib/cjs/references.js.map +1 -1
- package/lib/cjs/relay.js +43 -36
- package/lib/cjs/relay.js.map +4 -4
- package/lib/cjs/signer.js +21 -14
- package/lib/cjs/signer.js.map +4 -4
- package/lib/cjs/utils.js +10 -0
- package/lib/cjs/utils.js.map +2 -2
- package/lib/cjs/wasm.js +16 -2
- package/lib/cjs/wasm.js.map +4 -4
- package/lib/esm/abstract-pool.js +11 -21
- package/lib/esm/abstract-pool.js.map +3 -3
- package/lib/esm/abstract-relay.js +1 -1
- package/lib/esm/abstract-relay.js.map +2 -2
- package/lib/esm/core.js +15 -1
- package/lib/esm/core.js.map +3 -3
- package/lib/esm/filter.js.map +1 -1
- package/lib/esm/index.js +74 -73
- package/lib/esm/index.js.map +4 -4
- package/lib/esm/kinds.js +17 -1
- package/lib/esm/kinds.js.map +3 -3
- package/lib/esm/nip04.js.map +1 -1
- package/lib/esm/nip10.js +18 -5
- package/lib/esm/nip10.js.map +3 -3
- package/lib/esm/nip13.js.map +1 -1
- package/lib/esm/nip17.js +15 -8
- package/lib/esm/nip17.js.map +4 -4
- package/lib/esm/nip18.js +15 -8
- package/lib/esm/nip18.js.map +4 -4
- package/lib/esm/nip19.js.map +1 -1
- package/lib/esm/nip21.js.map +1 -1
- package/lib/esm/nip22.js +20 -7
- package/lib/esm/nip22.js.map +3 -3
- package/lib/esm/nip25.js +15 -8
- package/lib/esm/nip25.js.map +4 -4
- package/lib/esm/nip27.js.map +1 -1
- package/lib/esm/nip28.js +15 -8
- package/lib/esm/nip28.js.map +4 -4
- package/lib/esm/nip29.js.map +1 -1
- package/lib/esm/nip30.js.map +2 -2
- package/lib/esm/nip42.js.map +2 -2
- package/lib/esm/nip44.js.map +1 -1
- package/lib/esm/nip45.js +23 -10
- package/lib/esm/nip45.js.map +4 -4
- package/lib/esm/nip46.js +47 -47
- package/lib/esm/nip46.js.map +4 -4
- package/lib/esm/nip47.js +15 -8
- package/lib/esm/nip47.js.map +4 -4
- package/lib/esm/nip57.js +17 -10
- package/lib/esm/nip57.js.map +4 -4
- package/lib/esm/nip58.js.map +2 -2
- package/lib/esm/nip59.js +10 -1
- package/lib/esm/nip59.js.map +3 -3
- package/lib/esm/nip75.js.map +1 -1
- package/lib/esm/nip94.js.map +1 -1
- package/lib/esm/nip98.js +15 -8
- package/lib/esm/nip98.js.map +4 -4
- package/lib/esm/nip99.js.map +2 -2
- package/lib/esm/nipb0.js +35 -17
- package/lib/esm/nipb0.js.map +4 -4
- package/lib/esm/nipb7.js +13 -7
- package/lib/esm/nipb7.js.map +2 -2
- package/lib/esm/pool.js +47 -47
- package/lib/esm/pool.js.map +4 -4
- package/lib/esm/pure.js +15 -8
- package/lib/esm/pure.js.map +4 -4
- package/lib/esm/references.js.map +1 -1
- package/lib/esm/relay.js +37 -30
- package/lib/esm/relay.js.map +4 -4
- package/lib/esm/signer.js +15 -8
- package/lib/esm/signer.js.map +4 -4
- package/lib/esm/utils.js +10 -0
- package/lib/esm/utils.js.map +2 -2
- package/lib/esm/wasm.js +17 -3
- package/lib/esm/wasm.js.map +4 -4
- package/lib/nostr.bundle.js +73 -70
- package/lib/nostr.bundle.js.map +4 -4
- package/lib/types/abstract-pool.d.ts +6 -4
- package/lib/types/abstract-relay.d.ts +2 -2
- package/lib/types/kinds.d.ts +2 -0
- package/lib/types/nipb0.d.ts +0 -1
- package/lib/types/nipb0.test.d.ts +1 -0
- package/lib/types/nipb7.d.ts +0 -1
- package/lib/types/utils.d.ts +4 -0
- package/package.json +1 -1
- package/lib/types/helpers.d.ts +0 -2
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 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;;;
|
|
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 FavoriteFollowSets = 10021\nexport type FavoriteFollowSets = typeof FavoriteFollowSets\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;;;ACyRO,IAAM,aAAa;;;ADnRnB,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/nip44.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../nip44.ts", "../../utils.ts"],
|
|
4
|
-
"sourcesContent": ["import { chacha20 } from '@noble/ciphers/chacha.js'\nimport { equalBytes } from '@noble/ciphers/utils.js'\nimport { secp256k1 } from '@noble/curves/secp256k1.js'\nimport { extract as hkdf_extract, expand as hkdf_expand } from '@noble/hashes/hkdf.js'\nimport { hmac } from '@noble/hashes/hmac.js'\nimport { sha256 } from '@noble/hashes/sha2.js'\nimport { concatBytes, hexToBytes, randomBytes } from '@noble/hashes/utils.js'\nimport { base64 } from '@scure/base'\n\nimport { utf8Decoder, utf8Encoder } from './utils.ts'\n\nconst minPlaintextSize = 0x0001 // 1b msg => padded to 32b\nconst maxPlaintextSize = 0xffffffff // 4294967295 (2^32-1)\nconst extendedPrefixThreshold = 0x10000 // 65536: lengths below use 2-byte u16 prefix, at or above use 6-byte prefix\n\nexport function getConversationKey(privkeyA: Uint8Array, pubkeyB: string): Uint8Array {\n const sharedX = secp256k1.getSharedSecret(privkeyA, hexToBytes('02' + pubkeyB)).subarray(1, 33)\n return hkdf_extract(sha256, sharedX, utf8Encoder.encode('nip44-v2'))\n}\n\nfunction getMessageKeys(\n conversationKey: Uint8Array,\n nonce: Uint8Array,\n): { chacha_key: Uint8Array; chacha_nonce: Uint8Array; hmac_key: Uint8Array } {\n const keys = hkdf_expand(sha256, conversationKey, nonce, 76)\n return {\n chacha_key: keys.subarray(0, 32),\n chacha_nonce: keys.subarray(32, 44),\n hmac_key: keys.subarray(44, 76),\n }\n}\n\nfunction calcPaddedLen(len: number): number {\n if (!Number.isSafeInteger(len) || len < 1) throw new Error('expected positive integer')\n if (len <= 32) return 32\n const nextPower = 2 ** (Math.floor(Math.log2(len - 1)) + 1)\n const chunk = nextPower <= 256 ? 32 : nextPower / 8\n return chunk * (Math.floor((len - 1) / chunk) + 1)\n}\n\nfunction writeU16BE(num: number): Uint8Array {\n if (!Number.isSafeInteger(num) || num < minPlaintextSize || num > 0xffff)\n throw new Error('invalid plaintext size: must be between 1 and 65535 bytes')\n const arr = new Uint8Array(2)\n new DataView(arr.buffer).setUint16(0, num, false)\n return arr\n}\n\nfunction writeU32BE(num: number): Uint8Array {\n if (!Number.isSafeInteger(num) || num < extendedPrefixThreshold || num > maxPlaintextSize)\n throw new Error('invalid plaintext size: must be between 65536 and 4294967295 bytes')\n const arr = new Uint8Array(4)\n new DataView(arr.buffer).setUint32(0, num, false)\n return arr\n}\n\nfunction pad(plaintext: string): Uint8Array {\n const unpadded = utf8Encoder.encode(plaintext)\n const unpaddedLen = unpadded.length\n if (unpaddedLen < minPlaintextSize || unpaddedLen > maxPlaintextSize)\n throw new Error('invalid plaintext size: must be between 1 and 4294967295 bytes')\n const prefix =\n unpaddedLen >= extendedPrefixThreshold\n ? concatBytes(new Uint8Array([0, 0]), writeU32BE(unpaddedLen)) // 6 bytes\n : writeU16BE(unpaddedLen) // 2 bytes\n const suffix = new Uint8Array(calcPaddedLen(unpaddedLen) - unpaddedLen)\n return concatBytes(prefix, unpadded, suffix)\n}\n\nfunction unpad(padded: Uint8Array): string {\n const dv = new DataView(padded.buffer, padded.byteOffset, padded.byteLength)\n const firstTwo = dv.getUint16(0)\n let unpaddedLen: number\n let prefixLen: number\n if (firstTwo === 0) {\n // Extended format: 2 zero bytes + 4-byte u32 length\n unpaddedLen = dv.getUint32(2)\n if (unpaddedLen < extendedPrefixThreshold) throw new Error('invalid padding')\n prefixLen = 6\n } else {\n unpaddedLen = firstTwo\n prefixLen = 2\n }\n const unpadded = padded.subarray(prefixLen, prefixLen + unpaddedLen)\n if (\n unpaddedLen < minPlaintextSize ||\n unpaddedLen > maxPlaintextSize ||\n unpadded.length !== unpaddedLen ||\n padded.length !== prefixLen + calcPaddedLen(unpaddedLen)\n )\n throw new Error('invalid padding')\n return utf8Decoder.decode(unpadded)\n}\n\nfunction hmacAad(key: Uint8Array, message: Uint8Array, aad: Uint8Array): Uint8Array {\n if (aad.length !== 32) throw new Error('AAD associated data must be 32 bytes')\n const combined = concatBytes(aad, message)\n return hmac(sha256, key, combined)\n}\n\n// metadata: always 65b (version: 1b, nonce: 32b, mac: 32b)\n// plaintext: 1b to 0xffffffff\n// padded plaintext (small, <65536): 32b to 0x10000, with 2b prefix -> 34b to 0x10000+2\n// padded plaintext (large, >=65536): 0x10000 to 0x100000000, with 6b prefix -> 0x10006 to 0x100000000+6\n// ciphertext: same as padded plaintext (chacha20 doesn't change length)\n// raw payload (small): 99 (65+34) to 65603 (65+0x10000+2)\n// raw payload (large): 65607 (65+0x10006) to 4294967367 (65+0x100000000+6)\nfunction decodePayload(payload: string): { nonce: Uint8Array; ciphertext: Uint8Array; mac: Uint8Array } {\n if (typeof payload !== 'string') throw new Error('payload must be a valid string')\n const plen = payload.length\n if (plen < 132) throw new Error('invalid payload length: ' + plen)\n if (payload[0] === '#') throw new Error('unknown encryption version')\n let data: Uint8Array\n try {\n data = base64.decode(payload)\n } catch (error) {\n throw new Error('invalid base64: ' + (error as any).message)\n }\n const dlen = data.length\n if (dlen < 99) throw new Error('invalid data length: ' + dlen)\n const vers = data[0]\n if (vers !== 2) throw new Error('unknown encryption version ' + vers)\n return {\n nonce: data.subarray(1, 33),\n ciphertext: data.subarray(33, -32),\n mac: data.subarray(-32),\n }\n}\n\nexport function encrypt(plaintext: string, conversationKey: Uint8Array, nonce: Uint8Array = randomBytes(32)): string {\n const { chacha_key, chacha_nonce, hmac_key } = getMessageKeys(conversationKey, nonce)\n const padded = pad(plaintext)\n const ciphertext = chacha20(chacha_key, chacha_nonce, padded)\n const mac = hmacAad(hmac_key, ciphertext, nonce)\n return base64.encode(concatBytes(new Uint8Array([2]), nonce, ciphertext, mac))\n}\n\n/** Callers should validate payload size before calling to prevent DoS from oversized inputs. */\nexport function decrypt(payload: string, conversationKey: Uint8Array): string {\n const { nonce, ciphertext, mac } = decodePayload(payload)\n const { chacha_key, chacha_nonce, hmac_key } = getMessageKeys(conversationKey, nonce)\n const calculatedMac = hmacAad(hmac_key, ciphertext, nonce)\n if (!equalBytes(calculatedMac, mac)) throw new Error('invalid MAC')\n const padded = chacha20(chacha_key, chacha_nonce, ciphertext)\n return unpad(padded)\n}\n\nexport const v2 = {\n utils: {\n getConversationKey,\n calcPaddedLen,\n pad,\n unpad,\n },\n encrypt,\n decrypt,\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"],
|
|
4
|
+
"sourcesContent": ["import { chacha20 } from '@noble/ciphers/chacha.js'\nimport { equalBytes } from '@noble/ciphers/utils.js'\nimport { secp256k1 } from '@noble/curves/secp256k1.js'\nimport { extract as hkdf_extract, expand as hkdf_expand } from '@noble/hashes/hkdf.js'\nimport { hmac } from '@noble/hashes/hmac.js'\nimport { sha256 } from '@noble/hashes/sha2.js'\nimport { concatBytes, hexToBytes, randomBytes } from '@noble/hashes/utils.js'\nimport { base64 } from '@scure/base'\n\nimport { utf8Decoder, utf8Encoder } from './utils.ts'\n\nconst minPlaintextSize = 0x0001 // 1b msg => padded to 32b\nconst maxPlaintextSize = 0xffffffff // 4294967295 (2^32-1)\nconst extendedPrefixThreshold = 0x10000 // 65536: lengths below use 2-byte u16 prefix, at or above use 6-byte prefix\n\nexport function getConversationKey(privkeyA: Uint8Array, pubkeyB: string): Uint8Array {\n const sharedX = secp256k1.getSharedSecret(privkeyA, hexToBytes('02' + pubkeyB)).subarray(1, 33)\n return hkdf_extract(sha256, sharedX, utf8Encoder.encode('nip44-v2'))\n}\n\nfunction getMessageKeys(\n conversationKey: Uint8Array,\n nonce: Uint8Array,\n): { chacha_key: Uint8Array; chacha_nonce: Uint8Array; hmac_key: Uint8Array } {\n const keys = hkdf_expand(sha256, conversationKey, nonce, 76)\n return {\n chacha_key: keys.subarray(0, 32),\n chacha_nonce: keys.subarray(32, 44),\n hmac_key: keys.subarray(44, 76),\n }\n}\n\nfunction calcPaddedLen(len: number): number {\n if (!Number.isSafeInteger(len) || len < 1) throw new Error('expected positive integer')\n if (len <= 32) return 32\n const nextPower = 2 ** (Math.floor(Math.log2(len - 1)) + 1)\n const chunk = nextPower <= 256 ? 32 : nextPower / 8\n return chunk * (Math.floor((len - 1) / chunk) + 1)\n}\n\nfunction writeU16BE(num: number): Uint8Array {\n if (!Number.isSafeInteger(num) || num < minPlaintextSize || num > 0xffff)\n throw new Error('invalid plaintext size: must be between 1 and 65535 bytes')\n const arr = new Uint8Array(2)\n new DataView(arr.buffer).setUint16(0, num, false)\n return arr\n}\n\nfunction writeU32BE(num: number): Uint8Array {\n if (!Number.isSafeInteger(num) || num < extendedPrefixThreshold || num > maxPlaintextSize)\n throw new Error('invalid plaintext size: must be between 65536 and 4294967295 bytes')\n const arr = new Uint8Array(4)\n new DataView(arr.buffer).setUint32(0, num, false)\n return arr\n}\n\nfunction pad(plaintext: string): Uint8Array {\n const unpadded = utf8Encoder.encode(plaintext)\n const unpaddedLen = unpadded.length\n if (unpaddedLen < minPlaintextSize || unpaddedLen > maxPlaintextSize)\n throw new Error('invalid plaintext size: must be between 1 and 4294967295 bytes')\n const prefix =\n unpaddedLen >= extendedPrefixThreshold\n ? concatBytes(new Uint8Array([0, 0]), writeU32BE(unpaddedLen)) // 6 bytes\n : writeU16BE(unpaddedLen) // 2 bytes\n const suffix = new Uint8Array(calcPaddedLen(unpaddedLen) - unpaddedLen)\n return concatBytes(prefix, unpadded, suffix)\n}\n\nfunction unpad(padded: Uint8Array): string {\n const dv = new DataView(padded.buffer, padded.byteOffset, padded.byteLength)\n const firstTwo = dv.getUint16(0)\n let unpaddedLen: number\n let prefixLen: number\n if (firstTwo === 0) {\n // Extended format: 2 zero bytes + 4-byte u32 length\n unpaddedLen = dv.getUint32(2)\n if (unpaddedLen < extendedPrefixThreshold) throw new Error('invalid padding')\n prefixLen = 6\n } else {\n unpaddedLen = firstTwo\n prefixLen = 2\n }\n const unpadded = padded.subarray(prefixLen, prefixLen + unpaddedLen)\n if (\n unpaddedLen < minPlaintextSize ||\n unpaddedLen > maxPlaintextSize ||\n unpadded.length !== unpaddedLen ||\n padded.length !== prefixLen + calcPaddedLen(unpaddedLen)\n )\n throw new Error('invalid padding')\n return utf8Decoder.decode(unpadded)\n}\n\nfunction hmacAad(key: Uint8Array, message: Uint8Array, aad: Uint8Array): Uint8Array {\n if (aad.length !== 32) throw new Error('AAD associated data must be 32 bytes')\n const combined = concatBytes(aad, message)\n return hmac(sha256, key, combined)\n}\n\n// metadata: always 65b (version: 1b, nonce: 32b, mac: 32b)\n// plaintext: 1b to 0xffffffff\n// padded plaintext (small, <65536): 32b to 0x10000, with 2b prefix -> 34b to 0x10000+2\n// padded plaintext (large, >=65536): 0x10000 to 0x100000000, with 6b prefix -> 0x10006 to 0x100000000+6\n// ciphertext: same as padded plaintext (chacha20 doesn't change length)\n// raw payload (small): 99 (65+34) to 65603 (65+0x10000+2)\n// raw payload (large): 65607 (65+0x10006) to 4294967367 (65+0x100000000+6)\nfunction decodePayload(payload: string): { nonce: Uint8Array; ciphertext: Uint8Array; mac: Uint8Array } {\n if (typeof payload !== 'string') throw new Error('payload must be a valid string')\n const plen = payload.length\n if (plen < 132) throw new Error('invalid payload length: ' + plen)\n if (payload[0] === '#') throw new Error('unknown encryption version')\n let data: Uint8Array\n try {\n data = base64.decode(payload)\n } catch (error) {\n throw new Error('invalid base64: ' + (error as any).message)\n }\n const dlen = data.length\n if (dlen < 99) throw new Error('invalid data length: ' + dlen)\n const vers = data[0]\n if (vers !== 2) throw new Error('unknown encryption version ' + vers)\n return {\n nonce: data.subarray(1, 33),\n ciphertext: data.subarray(33, -32),\n mac: data.subarray(-32),\n }\n}\n\nexport function encrypt(plaintext: string, conversationKey: Uint8Array, nonce: Uint8Array = randomBytes(32)): string {\n const { chacha_key, chacha_nonce, hmac_key } = getMessageKeys(conversationKey, nonce)\n const padded = pad(plaintext)\n const ciphertext = chacha20(chacha_key, chacha_nonce, padded)\n const mac = hmacAad(hmac_key, ciphertext, nonce)\n return base64.encode(concatBytes(new Uint8Array([2]), nonce, ciphertext, mac))\n}\n\n/** Callers should validate payload size before calling to prevent DoS from oversized inputs. */\nexport function decrypt(payload: string, conversationKey: Uint8Array): string {\n const { nonce, ciphertext, mac } = decodePayload(payload)\n const { chacha_key, chacha_nonce, hmac_key } = getMessageKeys(conversationKey, nonce)\n const calculatedMac = hmacAad(hmac_key, ciphertext, nonce)\n if (!equalBytes(calculatedMac, mac)) throw new Error('invalid MAC')\n const padded = chacha20(chacha_key, chacha_nonce, ciphertext)\n return unpad(padded)\n}\n\nexport const v2 = {\n utils: {\n getConversationKey,\n calcPaddedLen,\n pad,\n unpad,\n },\n encrypt,\n decrypt,\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\n/**\n * Checks if a string is a 64-char lowercase hex string as most Nostr ids and pubkeys.\n */\nexport function isHex32(input: string): boolean {\n for (let i = 0; i < 64; i++) {\n let cc = input.charCodeAt(i)\n if (isNaN(cc) || cc < 48 || cc > 102 || (cc > 57 && cc < 97)) {\n return false\n }\n }\n return true\n}\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAyB;AACzB,IAAAA,gBAA2B;AAC3B,uBAA0B;AAC1B,kBAA+D;AAC/D,kBAAqB;AACrB,kBAAuB;AACvB,IAAAA,gBAAqD;AACrD,kBAAuB;;;ACFvB,mBAAuC;AAHhC,IAAM,cAA2B,IAAI,YAAY,OAAO;AACxD,IAA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,wBAAS,YAAY,cAAc,UAAU;AAC5D,SAAO,MAAM,MAAM;AACrB;AAEO,IAAM,KAAK;AAAA,EAChB,OAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAAA,EACA;AAAA,EACA;AACF;",
|
|
6
6
|
"names": ["import_utils", "hkdf_extract", "hkdf_expand"]
|
|
7
7
|
}
|
package/lib/cjs/nip45.js
CHANGED
|
@@ -33,10 +33,26 @@ __export(nip45_exports, {
|
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(nip45_exports);
|
|
35
35
|
var import_sha2 = require("@noble/hashes/sha2.js");
|
|
36
|
+
var import_utils2 = require("@noble/hashes/utils.js");
|
|
37
|
+
|
|
38
|
+
// utils.ts
|
|
36
39
|
var import_utils = require("@noble/hashes/utils.js");
|
|
40
|
+
var utf8Decoder = new TextDecoder("utf-8");
|
|
41
|
+
var utf8Encoder = new TextEncoder();
|
|
42
|
+
function isHex32(input) {
|
|
43
|
+
for (let i = 0; i < 64; i++) {
|
|
44
|
+
let cc = input.charCodeAt(i);
|
|
45
|
+
if (isNaN(cc) || cc < 48 || cc > 102 || cc > 57 && cc < 97) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// nip45.ts
|
|
37
53
|
var M = 256;
|
|
38
54
|
var HLL_HEX_LENGTH = M * 2;
|
|
39
|
-
var
|
|
55
|
+
var utf8Encoder2 = new TextEncoder();
|
|
40
56
|
function getCountManyFilter(target, directive) {
|
|
41
57
|
switch (directive) {
|
|
42
58
|
case "reactions":
|
|
@@ -57,7 +73,7 @@ function newHll() {
|
|
|
57
73
|
return new Uint8Array(M);
|
|
58
74
|
}
|
|
59
75
|
function hllDecode(hex) {
|
|
60
|
-
if (hex.length !== HLL_HEX_LENGTH || !/^[0-9a-
|
|
76
|
+
if (hex.length !== HLL_HEX_LENGTH || !/^[0-9a-f]+$/.test(hex))
|
|
61
77
|
return void 0;
|
|
62
78
|
const registers = new Uint8Array(M);
|
|
63
79
|
for (let i = 0; i < M; i++) {
|
|
@@ -76,12 +92,12 @@ function hllEncode(registers) {
|
|
|
76
92
|
}
|
|
77
93
|
function computeOffset(filterFirstTagValue) {
|
|
78
94
|
let hex = filterFirstTagValue;
|
|
79
|
-
if (!
|
|
95
|
+
if (!isHex32(hex)) {
|
|
80
96
|
const parts = hex.split(":");
|
|
81
|
-
if (parts.length === 3 &&
|
|
97
|
+
if (parts.length === 3 && isHex32(parts[1])) {
|
|
82
98
|
hex = parts[1];
|
|
83
99
|
} else {
|
|
84
|
-
hex = (0,
|
|
100
|
+
hex = (0, import_utils2.bytesToHex)((0, import_sha2.sha256)(utf8Encoder2.encode(filterFirstTagValue)));
|
|
85
101
|
}
|
|
86
102
|
}
|
|
87
103
|
return parseInt(hex[32], 16) + 8;
|
|
@@ -99,7 +115,7 @@ function getFilterFirstTagValue(filter) {
|
|
|
99
115
|
function feedPubkey(hll, pubkey, offset) {
|
|
100
116
|
if (offset < 0 || offset > 24)
|
|
101
117
|
throw new Error(`invalid offset ${offset}`);
|
|
102
|
-
if (!
|
|
118
|
+
if (!isHex32(pubkey))
|
|
103
119
|
throw new Error("pubkey must be 32-byte hex");
|
|
104
120
|
if (hll.length === 0)
|
|
105
121
|
hll = newHll();
|
|
@@ -143,9 +159,6 @@ function estimateCount(hll) {
|
|
|
143
159
|
return Math.floor(linearCounting(M, v));
|
|
144
160
|
return Math.floor(estimate);
|
|
145
161
|
}
|
|
146
|
-
function isHex64(value) {
|
|
147
|
-
return /^[0-9a-fA-F]{64}$/.test(value);
|
|
148
|
-
}
|
|
149
162
|
function countLeadingZeroBitsAfterOffset(pubkey, offset) {
|
|
150
163
|
let zeroBits = 0;
|
|
151
164
|
for (let i = offset + 1; i < offset + 8; i++) {
|
package/lib/cjs/nip45.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
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-
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAuB;AACvB,
|
|
6
|
-
"names": []
|
|
3
|
+
"sources": ["../../nip45.ts", "../../utils.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'\nimport { isHex32 } from './utils.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-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 (!isHex32(hex)) {\n const parts = hex.split(':')\n if (parts.length === 3 && isHex32(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 (!isHex32(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 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", "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\n/**\n * Checks if a string is a 64-char lowercase hex string as most Nostr ids and pubkeys.\n */\nexport function isHex32(input: string): boolean {\n for (let i = 0; i < 64; i++) {\n let cc = input.charCodeAt(i)\n if (isNaN(cc) || cc < 48 || cc > 102 || (cc > 57 && cc < 97)) {\n return false\n }\n }\n return true\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAuB;AACvB,IAAAA,gBAA2B;;;ACI3B,mBAAuC;AAHhC,IAAM,cAA2B,IAAI,YAAY,OAAO;AACxD,IAAM,cAA2B,IAAI,YAAY;AA8HjD,SAAS,QAAQ,OAAwB;AAC9C,WAAS,IAAI,GAAG,IAAI,IAAI,KAAK;AAC3B,QAAI,KAAK,MAAM,WAAW,CAAC;AAC3B,QAAI,MAAM,EAAE,KAAK,KAAK,MAAM,KAAK,OAAQ,KAAK,MAAM,KAAK,IAAK;AAC5D,aAAO;AAAA,IACT;AAAA,EACF;AACA,SAAO;AACT;;;ADlIA,IA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3B;AAEA,SAAS,kBAAkB,WAA+B;AACxD,MAAI,MAAM;AACV,WAAS,IAAI,GAAG,IAAI,GAAG,KAAK;AAC1B,WAAO,IAAI,KAAK,UAAU;AAAA,EAC5B;AACA,SAAQ,qBAAqB,IAAI,IAAK;AACxC;",
|
|
6
|
+
"names": ["import_utils", "utf8Encoder"]
|
|
7
7
|
}
|
package/lib/cjs/nip46.js
CHANGED
|
@@ -34,7 +34,42 @@ module.exports = __toCommonJS(nip46_exports);
|
|
|
34
34
|
|
|
35
35
|
// pure.ts
|
|
36
36
|
var import_secp256k1 = require("@noble/curves/secp256k1.js");
|
|
37
|
-
var
|
|
37
|
+
var import_utils3 = require("@noble/hashes/utils.js");
|
|
38
|
+
|
|
39
|
+
// utils.ts
|
|
40
|
+
var import_utils = require("@noble/hashes/utils.js");
|
|
41
|
+
var utf8Decoder = new TextDecoder("utf-8");
|
|
42
|
+
var utf8Encoder = new TextEncoder();
|
|
43
|
+
function normalizeURL(url) {
|
|
44
|
+
try {
|
|
45
|
+
if (url.indexOf("://") === -1)
|
|
46
|
+
url = "wss://" + url;
|
|
47
|
+
let p = new URL(url);
|
|
48
|
+
if (p.protocol === "http:")
|
|
49
|
+
p.protocol = "ws:";
|
|
50
|
+
else if (p.protocol === "https:")
|
|
51
|
+
p.protocol = "wss:";
|
|
52
|
+
p.pathname = p.pathname.replace(/\/+/g, "/");
|
|
53
|
+
if (p.pathname.endsWith("/"))
|
|
54
|
+
p.pathname = p.pathname.slice(0, -1);
|
|
55
|
+
if (p.port === "80" && p.protocol === "ws:" || p.port === "443" && p.protocol === "wss:")
|
|
56
|
+
p.port = "";
|
|
57
|
+
p.searchParams.sort();
|
|
58
|
+
p.hash = "";
|
|
59
|
+
return p.toString();
|
|
60
|
+
} catch (e) {
|
|
61
|
+
throw new Error(`Invalid URL: ${url}`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function isHex32(input) {
|
|
65
|
+
for (let i2 = 0; i2 < 64; i2++) {
|
|
66
|
+
let cc = input.charCodeAt(i2);
|
|
67
|
+
if (isNaN(cc) || cc < 48 || cc > 102 || cc > 57 && cc < 97) {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
38
73
|
|
|
39
74
|
// core.ts
|
|
40
75
|
var verifiedSymbol = Symbol("verified");
|
|
@@ -50,7 +85,7 @@ function validateEvent(event) {
|
|
|
50
85
|
return false;
|
|
51
86
|
if (typeof event.pubkey !== "string")
|
|
52
87
|
return false;
|
|
53
|
-
if (!event.pubkey
|
|
88
|
+
if (!isHex32(event.pubkey))
|
|
54
89
|
return false;
|
|
55
90
|
if (!Array.isArray(event.tags))
|
|
56
91
|
return false;
|
|
@@ -68,46 +103,18 @@ function validateEvent(event) {
|
|
|
68
103
|
|
|
69
104
|
// pure.ts
|
|
70
105
|
var import_sha2 = require("@noble/hashes/sha2.js");
|
|
71
|
-
|
|
72
|
-
// utils.ts
|
|
73
|
-
var import_utils = require("@noble/hashes/utils.js");
|
|
74
|
-
var utf8Decoder = new TextDecoder("utf-8");
|
|
75
|
-
var utf8Encoder = new TextEncoder();
|
|
76
|
-
function normalizeURL(url) {
|
|
77
|
-
try {
|
|
78
|
-
if (url.indexOf("://") === -1)
|
|
79
|
-
url = "wss://" + url;
|
|
80
|
-
let p = new URL(url);
|
|
81
|
-
if (p.protocol === "http:")
|
|
82
|
-
p.protocol = "ws:";
|
|
83
|
-
else if (p.protocol === "https:")
|
|
84
|
-
p.protocol = "wss:";
|
|
85
|
-
p.pathname = p.pathname.replace(/\/+/g, "/");
|
|
86
|
-
if (p.pathname.endsWith("/"))
|
|
87
|
-
p.pathname = p.pathname.slice(0, -1);
|
|
88
|
-
if (p.port === "80" && p.protocol === "ws:" || p.port === "443" && p.protocol === "wss:")
|
|
89
|
-
p.port = "";
|
|
90
|
-
p.searchParams.sort();
|
|
91
|
-
p.hash = "";
|
|
92
|
-
return p.toString();
|
|
93
|
-
} catch (e) {
|
|
94
|
-
throw new Error(`Invalid URL: ${url}`);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// pure.ts
|
|
99
106
|
var JS = class {
|
|
100
107
|
generateSecretKey() {
|
|
101
108
|
return import_secp256k1.schnorr.utils.randomSecretKey();
|
|
102
109
|
}
|
|
103
110
|
getPublicKey(secretKey) {
|
|
104
|
-
return (0,
|
|
111
|
+
return (0, import_utils3.bytesToHex)(import_secp256k1.schnorr.getPublicKey(secretKey));
|
|
105
112
|
}
|
|
106
113
|
finalizeEvent(t, secretKey) {
|
|
107
114
|
const event = t;
|
|
108
|
-
event.pubkey = (0,
|
|
115
|
+
event.pubkey = (0, import_utils3.bytesToHex)(import_secp256k1.schnorr.getPublicKey(secretKey));
|
|
109
116
|
event.id = getEventHash(event);
|
|
110
|
-
event.sig = (0,
|
|
117
|
+
event.sig = (0, import_utils3.bytesToHex)(import_secp256k1.schnorr.sign((0, import_utils3.hexToBytes)(getEventHash(event)), secretKey));
|
|
111
118
|
event[verifiedSymbol] = true;
|
|
112
119
|
return event;
|
|
113
120
|
}
|
|
@@ -120,7 +127,7 @@ var JS = class {
|
|
|
120
127
|
event[verifiedSymbol] = false;
|
|
121
128
|
return false;
|
|
122
129
|
}
|
|
123
|
-
const valid = import_secp256k1.schnorr.verify((0,
|
|
130
|
+
const valid = import_secp256k1.schnorr.verify((0, import_utils3.hexToBytes)(event.sig), (0, import_utils3.hexToBytes)(hash), (0, import_utils3.hexToBytes)(event.pubkey));
|
|
124
131
|
event[verifiedSymbol] = valid;
|
|
125
132
|
return valid;
|
|
126
133
|
} catch (err) {
|
|
@@ -136,7 +143,7 @@ function serializeEvent(evt) {
|
|
|
136
143
|
}
|
|
137
144
|
function getEventHash(event) {
|
|
138
145
|
let eventHash = (0, import_sha2.sha256)(utf8Encoder.encode(serializeEvent(event)));
|
|
139
|
-
return (0,
|
|
146
|
+
return (0, import_utils3.bytesToHex)(eventHash);
|
|
140
147
|
}
|
|
141
148
|
var i = new JS();
|
|
142
149
|
var generateSecretKey = i.generateSecretKey;
|
|
@@ -146,18 +153,18 @@ var verifyEvent = i.verifyEvent;
|
|
|
146
153
|
|
|
147
154
|
// nip44.ts
|
|
148
155
|
var import_chacha = require("@noble/ciphers/chacha.js");
|
|
149
|
-
var
|
|
156
|
+
var import_utils5 = require("@noble/ciphers/utils.js");
|
|
150
157
|
var import_secp256k12 = require("@noble/curves/secp256k1.js");
|
|
151
158
|
var import_hkdf = require("@noble/hashes/hkdf.js");
|
|
152
159
|
var import_hmac = require("@noble/hashes/hmac.js");
|
|
153
160
|
var import_sha22 = require("@noble/hashes/sha2.js");
|
|
154
|
-
var
|
|
161
|
+
var import_utils6 = require("@noble/hashes/utils.js");
|
|
155
162
|
var import_base = require("@scure/base");
|
|
156
163
|
var minPlaintextSize = 1;
|
|
157
164
|
var maxPlaintextSize = 4294967295;
|
|
158
165
|
var extendedPrefixThreshold = 65536;
|
|
159
166
|
function getConversationKey(privkeyA, pubkeyB) {
|
|
160
|
-
const sharedX = import_secp256k12.secp256k1.getSharedSecret(privkeyA, (0,
|
|
167
|
+
const sharedX = import_secp256k12.secp256k1.getSharedSecret(privkeyA, (0, import_utils6.hexToBytes)("02" + pubkeyB)).subarray(1, 33);
|
|
161
168
|
return (0, import_hkdf.extract)(import_sha22.sha256, sharedX, utf8Encoder.encode("nip44-v2"));
|
|
162
169
|
}
|
|
163
170
|
function getMessageKeys(conversationKey, nonce) {
|
|
@@ -196,9 +203,9 @@ function pad(plaintext) {
|
|
|
196
203
|
const unpaddedLen = unpadded.length;
|
|
197
204
|
if (unpaddedLen < minPlaintextSize || unpaddedLen > maxPlaintextSize)
|
|
198
205
|
throw new Error("invalid plaintext size: must be between 1 and 4294967295 bytes");
|
|
199
|
-
const prefix = unpaddedLen >= extendedPrefixThreshold ? (0,
|
|
206
|
+
const prefix = unpaddedLen >= extendedPrefixThreshold ? (0, import_utils6.concatBytes)(new Uint8Array([0, 0]), writeU32BE(unpaddedLen)) : writeU16BE(unpaddedLen);
|
|
200
207
|
const suffix = new Uint8Array(calcPaddedLen(unpaddedLen) - unpaddedLen);
|
|
201
|
-
return (0,
|
|
208
|
+
return (0, import_utils6.concatBytes)(prefix, unpadded, suffix);
|
|
202
209
|
}
|
|
203
210
|
function unpad(padded) {
|
|
204
211
|
const dv = new DataView(padded.buffer, padded.byteOffset, padded.byteLength);
|
|
@@ -222,7 +229,7 @@ function unpad(padded) {
|
|
|
222
229
|
function hmacAad(key, message, aad) {
|
|
223
230
|
if (aad.length !== 32)
|
|
224
231
|
throw new Error("AAD associated data must be 32 bytes");
|
|
225
|
-
const combined = (0,
|
|
232
|
+
const combined = (0, import_utils6.concatBytes)(aad, message);
|
|
226
233
|
return (0, import_hmac.hmac)(import_sha22.sha256, key, combined);
|
|
227
234
|
}
|
|
228
235
|
function decodePayload(payload) {
|
|
@@ -251,18 +258,18 @@ function decodePayload(payload) {
|
|
|
251
258
|
mac: data.subarray(-32)
|
|
252
259
|
};
|
|
253
260
|
}
|
|
254
|
-
function encrypt(plaintext, conversationKey, nonce = (0,
|
|
261
|
+
function encrypt(plaintext, conversationKey, nonce = (0, import_utils6.randomBytes)(32)) {
|
|
255
262
|
const { chacha_key, chacha_nonce, hmac_key } = getMessageKeys(conversationKey, nonce);
|
|
256
263
|
const padded = pad(plaintext);
|
|
257
264
|
const ciphertext = (0, import_chacha.chacha20)(chacha_key, chacha_nonce, padded);
|
|
258
265
|
const mac = hmacAad(hmac_key, ciphertext, nonce);
|
|
259
|
-
return import_base.base64.encode((0,
|
|
266
|
+
return import_base.base64.encode((0, import_utils6.concatBytes)(new Uint8Array([2]), nonce, ciphertext, mac));
|
|
260
267
|
}
|
|
261
268
|
function decrypt(payload, conversationKey) {
|
|
262
269
|
const { nonce, ciphertext, mac } = decodePayload(payload);
|
|
263
270
|
const { chacha_key, chacha_nonce, hmac_key } = getMessageKeys(conversationKey, nonce);
|
|
264
271
|
const calculatedMac = hmacAad(hmac_key, ciphertext, nonce);
|
|
265
|
-
if (!(0,
|
|
272
|
+
if (!(0, import_utils5.equalBytes)(calculatedMac, mac))
|
|
266
273
|
throw new Error("invalid MAC");
|
|
267
274
|
const padded = (0, import_chacha.chacha20)(chacha_key, chacha_nonce, ciphertext);
|
|
268
275
|
return unpad(padded);
|
|
@@ -723,7 +730,7 @@ var AbstractRelay = class {
|
|
|
723
730
|
case "EVENT": {
|
|
724
731
|
const so = this.openSubs.get(data[1]);
|
|
725
732
|
const event = data[2];
|
|
726
|
-
if (
|
|
733
|
+
if (matchFilters(so.filters, event) && this.verifyEvent(event, this.url)) {
|
|
727
734
|
so.onevent(event);
|
|
728
735
|
} else {
|
|
729
736
|
so.oninvalidevent?.(event);
|
|
@@ -879,15 +886,9 @@ var Subscription = class {
|
|
|
879
886
|
}
|
|
880
887
|
};
|
|
881
888
|
|
|
882
|
-
// helpers.ts
|
|
883
|
-
var alwaysTrue = (t) => {
|
|
884
|
-
t[verifiedSymbol] = true;
|
|
885
|
-
return true;
|
|
886
|
-
};
|
|
887
|
-
|
|
888
889
|
// nip45.ts
|
|
889
890
|
var import_sha23 = require("@noble/hashes/sha2.js");
|
|
890
|
-
var
|
|
891
|
+
var import_utils9 = require("@noble/hashes/utils.js");
|
|
891
892
|
var M = 256;
|
|
892
893
|
var HLL_HEX_LENGTH = M * 2;
|
|
893
894
|
var utf8Encoder2 = new TextEncoder();
|
|
@@ -911,7 +912,7 @@ function newHll() {
|
|
|
911
912
|
return new Uint8Array(M);
|
|
912
913
|
}
|
|
913
914
|
function hllDecode(hex) {
|
|
914
|
-
if (hex.length !== HLL_HEX_LENGTH || !/^[0-9a-
|
|
915
|
+
if (hex.length !== HLL_HEX_LENGTH || !/^[0-9a-f]+$/.test(hex))
|
|
915
916
|
return void 0;
|
|
916
917
|
const registers = new Uint8Array(M);
|
|
917
918
|
for (let i2 = 0; i2 < M; i2++) {
|
|
@@ -952,7 +953,6 @@ var AbstractSimplePool = class {
|
|
|
952
953
|
enableReconnect;
|
|
953
954
|
idleTimeout = 2e4;
|
|
954
955
|
automaticallyAuth;
|
|
955
|
-
trustedRelayURLs = /* @__PURE__ */ new Set();
|
|
956
956
|
onRelayConnectionFailure;
|
|
957
957
|
onRelayConnectionSuccess;
|
|
958
958
|
allowConnectingToRelay;
|
|
@@ -976,7 +976,7 @@ var AbstractSimplePool = class {
|
|
|
976
976
|
let relay = this.relays.get(url);
|
|
977
977
|
if (!relay) {
|
|
978
978
|
relay = new AbstractRelay(url, {
|
|
979
|
-
verifyEvent: this.
|
|
979
|
+
verifyEvent: this.verifyEvent,
|
|
980
980
|
websocketImplementation: this._WebSocket,
|
|
981
981
|
enablePing: this.enablePing,
|
|
982
982
|
enableReconnect: this.enableReconnect,
|
|
@@ -1060,11 +1060,11 @@ var AbstractSimplePool = class {
|
|
|
1060
1060
|
}
|
|
1061
1061
|
};
|
|
1062
1062
|
const closesReceived = [];
|
|
1063
|
-
let handleClose = (i2, reason) => {
|
|
1063
|
+
let handleClose = (i2, url, reason) => {
|
|
1064
1064
|
if (closesReceived[i2])
|
|
1065
1065
|
return;
|
|
1066
1066
|
handleEose(i2);
|
|
1067
|
-
closesReceived[i2] = reason;
|
|
1067
|
+
closesReceived[i2] = { url, reason };
|
|
1068
1068
|
if (closesReceived.filter((a) => a).length === groupedRequests.length) {
|
|
1069
1069
|
params.onclose?.(closesReceived);
|
|
1070
1070
|
handleClose = () => {
|
|
@@ -1082,7 +1082,7 @@ var AbstractSimplePool = class {
|
|
|
1082
1082
|
const allOpened = Promise.all(
|
|
1083
1083
|
groupedRequests.map(async ({ url, filters }, i2) => {
|
|
1084
1084
|
if (this.allowConnectingToRelay?.(url, ["read", filters]) === false) {
|
|
1085
|
-
handleClose(i2, "connection skipped by allowConnectingToRelay");
|
|
1085
|
+
handleClose(i2, url, "connection skipped by allowConnectingToRelay");
|
|
1086
1086
|
return;
|
|
1087
1087
|
}
|
|
1088
1088
|
let relay;
|
|
@@ -1093,7 +1093,7 @@ var AbstractSimplePool = class {
|
|
|
1093
1093
|
});
|
|
1094
1094
|
} catch (err) {
|
|
1095
1095
|
this.onRelayConnectionFailure?.(url);
|
|
1096
|
-
handleClose(i2, err?.message || String(err));
|
|
1096
|
+
handleClose(i2, url, err?.message || String(err));
|
|
1097
1097
|
return;
|
|
1098
1098
|
}
|
|
1099
1099
|
this.onRelayConnectionSuccess?.(url);
|
|
@@ -1107,17 +1107,17 @@ var AbstractSimplePool = class {
|
|
|
1107
1107
|
...params,
|
|
1108
1108
|
oneose: () => handleEose(i2),
|
|
1109
1109
|
onclose: (reason2) => {
|
|
1110
|
-
handleClose(i2, reason2);
|
|
1110
|
+
handleClose(i2, url, reason2);
|
|
1111
1111
|
},
|
|
1112
1112
|
alreadyHaveEvent: localAlreadyHaveEventHandler,
|
|
1113
1113
|
eoseTimeout: params.maxWait,
|
|
1114
1114
|
abort: params.abort
|
|
1115
1115
|
});
|
|
1116
1116
|
}).catch((err) => {
|
|
1117
|
-
handleClose(i2, `auth was required and attempted, but failed with: ${err}`);
|
|
1117
|
+
handleClose(i2, url, `auth was required and attempted, but failed with: ${err}`);
|
|
1118
1118
|
});
|
|
1119
1119
|
} else {
|
|
1120
|
-
handleClose(i2, reason);
|
|
1120
|
+
handleClose(i2, url, reason);
|
|
1121
1121
|
}
|
|
1122
1122
|
},
|
|
1123
1123
|
alreadyHaveEvent: localAlreadyHaveEventHandler,
|
|
@@ -1145,7 +1145,7 @@ var AbstractSimplePool = class {
|
|
|
1145
1145
|
if (subcloser)
|
|
1146
1146
|
subcloser.close(reason);
|
|
1147
1147
|
else
|
|
1148
|
-
params.onclose?.(relays.map((
|
|
1148
|
+
params.onclose?.(relays.map((url) => ({ url, reason })));
|
|
1149
1149
|
}
|
|
1150
1150
|
});
|
|
1151
1151
|
return subcloser;
|