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/kinds.js
CHANGED
|
@@ -71,6 +71,7 @@ __export(kinds_exports, {
|
|
|
71
71
|
Emojisets: () => Emojisets,
|
|
72
72
|
EncryptedDirectMessage: () => EncryptedDirectMessage,
|
|
73
73
|
EventDeletion: () => EventDeletion,
|
|
74
|
+
FavoriteFollowSets: () => FavoriteFollowSets,
|
|
74
75
|
FavoritePodcasts: () => FavoritePodcasts,
|
|
75
76
|
FavoriteRelays: () => FavoriteRelays,
|
|
76
77
|
FedimintAnnouncement: () => FedimintAnnouncement,
|
|
@@ -217,6 +218,20 @@ __export(kinds_exports, {
|
|
|
217
218
|
});
|
|
218
219
|
module.exports = __toCommonJS(kinds_exports);
|
|
219
220
|
|
|
221
|
+
// utils.ts
|
|
222
|
+
var import_utils = require("@noble/hashes/utils.js");
|
|
223
|
+
var utf8Decoder = new TextDecoder("utf-8");
|
|
224
|
+
var utf8Encoder = new TextEncoder();
|
|
225
|
+
function isHex32(input) {
|
|
226
|
+
for (let i = 0; i < 64; i++) {
|
|
227
|
+
let cc = input.charCodeAt(i);
|
|
228
|
+
if (isNaN(cc) || cc < 48 || cc > 102 || cc > 57 && cc < 97) {
|
|
229
|
+
return false;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return true;
|
|
233
|
+
}
|
|
234
|
+
|
|
220
235
|
// core.ts
|
|
221
236
|
var verifiedSymbol = Symbol("verified");
|
|
222
237
|
var isRecord = (obj) => obj instanceof Object;
|
|
@@ -231,7 +246,7 @@ function validateEvent(event) {
|
|
|
231
246
|
return false;
|
|
232
247
|
if (typeof event.pubkey !== "string")
|
|
233
248
|
return false;
|
|
234
|
-
if (!event.pubkey
|
|
249
|
+
if (!isHex32(event.pubkey))
|
|
235
250
|
return false;
|
|
236
251
|
if (!Array.isArray(event.tags))
|
|
237
252
|
return false;
|
|
@@ -376,6 +391,7 @@ var PrivateEventRelayList = 10013;
|
|
|
376
391
|
var InterestsList = 10015;
|
|
377
392
|
var NutZapInfo = 10019;
|
|
378
393
|
var MediaFollows = 10020;
|
|
394
|
+
var FavoriteFollowSets = 10021;
|
|
379
395
|
var UserEmojiList = 10030;
|
|
380
396
|
var DecoupledKeyAnnouncement = 10044;
|
|
381
397
|
var DirectMessageRelaysList = 10050;
|
package/lib/cjs/kinds.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../kinds.ts", "../../core.ts"],
|
|
4
|
-
"sourcesContent": ["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", "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"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;
|
|
3
|
+
"sources": ["../../kinds.ts", "../../utils.ts", "../../core.ts"],
|
|
4
|
+
"sourcesContent": ["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", "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", "import { isHex32 } from './utils.ts'\n\nexport 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 (!isHex32(event.pubkey)) 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"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAA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IAAM,kBAAkB;AAExB,IAAM,eAAe;AAErB,IAAM,WAAW;AAEjB,IAAM,oBAAoB;AAE1B,IAAM,yBAAyB;AAE/B,IAAM,yBAAyB;AAE/B,IAAM,kBAAkB;AAExB,IAAM,cAAc;AAEpB,IAAM,YAAY;AAElB,IAAM,aAAa;AAEnB,IAAM,UAAU;AAEhB,IAAM,OAAO;AAEb,IAAM,OAAO;AAEb,IAAM,OAAO;AAEb,IAAM,WAAW;AAEjB,IAAM,oBAAoB;AAE1B,IAAM,cAAc;AAEpB,IAAM,wBAAwB;AAE9B,IAAM,qBAAqB;AAE3B,IAAM,sBAAsB;AAE5B,IAAM,kBAAkB;AAExB,IAAM,iBAAiB;AAEvB,IAAM,sBAAsB;AAE5B,IAAM,aAAa;AAEnB,IAAM,kBAAkB;AAExB,IAAM,mBAAmB;AAEzB,IAAM,wBAAwB;AAE9B,IAAM,uBAAuB;AAE7B,IAAM,wBAAwB;AAE9B,IAAM,gBAAgB;AAEtB,IAAM,oBAAoB;AAE1B,IAAM,qBAAqB;AAE3B,IAAM,mBAAmB;AAEzB,IAAM,iCAAiC;AAEvC,IAAM,eAAe;AAErB,IAAM,oBAAoB;AAE1B,IAAM,eAAe;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/lib/cjs/nip04.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../nip04.ts", "../../utils.ts"],
|
|
4
|
-
"sourcesContent": ["import { hexToBytes, randomBytes } from '@noble/hashes/utils.js'\nimport { secp256k1 } from '@noble/curves/secp256k1.js'\nimport { cbc } from '@noble/ciphers/aes.js'\nimport { base64 } from '@scure/base'\n\nimport { utf8Decoder, utf8Encoder } from './utils.ts'\n\nexport function encrypt(secretKey: string | Uint8Array, pubkey: string, text: string): string {\n const privkey: Uint8Array = secretKey instanceof Uint8Array ? secretKey : hexToBytes(secretKey)\n const key = secp256k1.getSharedSecret(privkey, hexToBytes('02' + pubkey))\n const normalizedKey = getNormalizedX(key)\n\n let iv = Uint8Array.from(randomBytes(16))\n let plaintext = utf8Encoder.encode(text)\n\n let ciphertext = cbc(normalizedKey, iv).encrypt(plaintext)\n\n let ctb64 = base64.encode(new Uint8Array(ciphertext))\n let ivb64 = base64.encode(new Uint8Array(iv.buffer))\n\n return `${ctb64}?iv=${ivb64}`\n}\n\nexport function decrypt(secretKey: string | Uint8Array, pubkey: string, data: string): string {\n const privkey: Uint8Array = secretKey instanceof Uint8Array ? secretKey : hexToBytes(secretKey)\n let [ctb64, ivb64] = data.split('?iv=')\n let key = secp256k1.getSharedSecret(privkey, hexToBytes('02' + pubkey))\n let normalizedKey = getNormalizedX(key)\n\n let iv = base64.decode(ivb64)\n let ciphertext = base64.decode(ctb64)\n\n let plaintext = cbc(normalizedKey, iv).decrypt(ciphertext)\n\n return utf8Decoder.decode(plaintext)\n}\n\nfunction getNormalizedX(key: Uint8Array): Uint8Array {\n return key.slice(1, 33)\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 { hexToBytes, randomBytes } from '@noble/hashes/utils.js'\nimport { secp256k1 } from '@noble/curves/secp256k1.js'\nimport { cbc } from '@noble/ciphers/aes.js'\nimport { base64 } from '@scure/base'\n\nimport { utf8Decoder, utf8Encoder } from './utils.ts'\n\nexport function encrypt(secretKey: string | Uint8Array, pubkey: string, text: string): string {\n const privkey: Uint8Array = secretKey instanceof Uint8Array ? secretKey : hexToBytes(secretKey)\n const key = secp256k1.getSharedSecret(privkey, hexToBytes('02' + pubkey))\n const normalizedKey = getNormalizedX(key)\n\n let iv = Uint8Array.from(randomBytes(16))\n let plaintext = utf8Encoder.encode(text)\n\n let ciphertext = cbc(normalizedKey, iv).encrypt(plaintext)\n\n let ctb64 = base64.encode(new Uint8Array(ciphertext))\n let ivb64 = base64.encode(new Uint8Array(iv.buffer))\n\n return `${ctb64}?iv=${ivb64}`\n}\n\nexport function decrypt(secretKey: string | Uint8Array, pubkey: string, data: string): string {\n const privkey: Uint8Array = secretKey instanceof Uint8Array ? secretKey : hexToBytes(secretKey)\n let [ctb64, ivb64] = data.split('?iv=')\n let key = secp256k1.getSharedSecret(privkey, hexToBytes('02' + pubkey))\n let normalizedKey = getNormalizedX(key)\n\n let iv = base64.decode(ivb64)\n let ciphertext = base64.decode(ctb64)\n\n let plaintext = cbc(normalizedKey, iv).decrypt(ciphertext)\n\n return utf8Decoder.decode(plaintext)\n}\n\nfunction getNormalizedX(key: Uint8Array): Uint8Array {\n return key.slice(1, 33)\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,IAAAA,gBAAwC;AACxC,uBAA0B;AAC1B,iBAAoB;AACpB,kBAAuB;;;ACEvB,mBAAuC;AAHhC,IAAM,cAA2B,IAAI,YAAY,OAAO;AACxD,IAAM,cAA2B,IAAI,YAAY;;;ADIjD,SAAS,QAAQ,WAAgC,QAAgB,MAAsB;AAC5F,QAAM,UAAsB,qBAAqB,aAAa,gBAAY,0BAAW,SAAS;AAC9F,QAAM,MAAM,2BAAU,gBAAgB,aAAS,0BAAW,OAAO,MAAM,CAAC;AACxE,QAAM,gBAAgB,eAAe,GAAG;AAExC,MAAI,KAAK,WAAW,SAAK,2BAAY,EAAE,CAAC;AACxC,MAAI,YAAY,YAAY,OAAO,IAAI;AAEvC,MAAI,iBAAa,gBAAI,eAAe,EAAE,EAAE,QAAQ,SAAS;AAEzD,MAAI,QAAQ,mBAAO,OAAO,IAAI,WAAW,UAAU,CAAC;AACpD,MAAI,QAAQ,mBAAO,OAAO,IAAI,WAAW,GAAG,MAAM,CAAC;AAEnD,SAAO,GAAG,YAAY;AACxB;AAEO,SAAS,QAAQ,WAAgC,QAAgB,MAAsB;AAC5F,QAAM,UAAsB,qBAAqB,aAAa,gBAAY,0BAAW,SAAS;AAC9F,MAAI,CAAC,OAAO,KAAK,IAAI,KAAK,MAAM,MAAM;AACtC,MAAI,MAAM,2BAAU,gBAAgB,aAAS,0BAAW,OAAO,MAAM,CAAC;AACtE,MAAI,gBAAgB,eAAe,GAAG;AAEtC,MAAI,KAAK,mBAAO,OAAO,KAAK;AAC5B,MAAI,aAAa,mBAAO,OAAO,KAAK;AAEpC,MAAI,gBAAY,gBAAI,eAAe,EAAE,EAAE,QAAQ,UAAU;AAEzD,SAAO,YAAY,OAAO,SAAS;AACrC;AAEA,SAAS,eAAe,KAA6B;AACnD,SAAO,IAAI,MAAM,GAAG,EAAE;AACxB;",
|
|
6
6
|
"names": ["import_utils"]
|
|
7
7
|
}
|
package/lib/cjs/nip10.js
CHANGED
|
@@ -23,7 +23,22 @@ __export(nip10_exports, {
|
|
|
23
23
|
parse: () => parse
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(nip10_exports);
|
|
26
|
-
|
|
26
|
+
|
|
27
|
+
// utils.ts
|
|
28
|
+
var import_utils = require("@noble/hashes/utils.js");
|
|
29
|
+
var utf8Decoder = new TextDecoder("utf-8");
|
|
30
|
+
var utf8Encoder = new TextEncoder();
|
|
31
|
+
function isHex32(input) {
|
|
32
|
+
for (let i = 0; i < 64; i++) {
|
|
33
|
+
let cc = input.charCodeAt(i);
|
|
34
|
+
if (isNaN(cc) || cc < 48 || cc > 102 || cc > 57 && cc < 97) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// nip10.ts
|
|
27
42
|
function parse(event) {
|
|
28
43
|
const result = {
|
|
29
44
|
reply: void 0,
|
|
@@ -36,12 +51,12 @@ function parse(event) {
|
|
|
36
51
|
let maybeRoot;
|
|
37
52
|
for (let i = event.tags.length - 1; i >= 0; i--) {
|
|
38
53
|
const tag = event.tags[i];
|
|
39
|
-
if (tag[0] === "e" && tag[1] &&
|
|
54
|
+
if (tag[0] === "e" && tag[1] && isHex32(tag[1])) {
|
|
40
55
|
const [_, eTagEventId, eTagRelayUrl, eTagMarker, eTagAuthor] = tag;
|
|
41
56
|
const eventPointer = {
|
|
42
57
|
id: eTagEventId,
|
|
43
58
|
relays: eTagRelayUrl ? [eTagRelayUrl] : [],
|
|
44
|
-
author: eTagAuthor &&
|
|
59
|
+
author: eTagAuthor && isHex32(eTagAuthor) ? eTagAuthor : void 0
|
|
45
60
|
};
|
|
46
61
|
if (eTagMarker === "root") {
|
|
47
62
|
result.root = eventPointer;
|
|
@@ -63,14 +78,14 @@ function parse(event) {
|
|
|
63
78
|
result.mentions.push(eventPointer);
|
|
64
79
|
continue;
|
|
65
80
|
}
|
|
66
|
-
if (tag[0] === "q" && tag[1] &&
|
|
81
|
+
if (tag[0] === "q" && tag[1] && isHex32(tag[1])) {
|
|
67
82
|
const [_, eTagEventId, eTagRelayUrl] = tag;
|
|
68
83
|
result.quotes.push({
|
|
69
84
|
id: eTagEventId,
|
|
70
85
|
relays: eTagRelayUrl ? [eTagRelayUrl] : []
|
|
71
86
|
});
|
|
72
87
|
}
|
|
73
|
-
if (tag[0] === "p" && tag[1] &&
|
|
88
|
+
if (tag[0] === "p" && tag[1] && isHex32(tag[1])) {
|
|
74
89
|
result.profiles.push({
|
|
75
90
|
pubkey: tag[1],
|
|
76
91
|
relays: tag[2] ? [tag[2]] : []
|
package/lib/cjs/nip10.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../nip10.ts"],
|
|
4
|
-
"sourcesContent": ["import type { Event } from './core.ts'\nimport type { EventPointer, ProfilePointer } from './nip19.ts'\
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
3
|
+
"sources": ["../../nip10.ts", "../../utils.ts"],
|
|
4
|
+
"sourcesContent": ["import type { Event } from './core.ts'\nimport type { EventPointer, ProfilePointer } from './nip19.ts'\nimport { isHex32 } from './utils.ts'\n\nexport function parse(event: Pick<Event, 'tags'>): {\n /**\n * Pointer to the root of the thread.\n */\n root: EventPointer | undefined\n\n /**\n * Pointer to a \"parent\" event that parsed event replies to (responded to).\n */\n reply: EventPointer | undefined\n\n /**\n * Pointers to events that may or may not be in the reply chain.\n */\n mentions: EventPointer[]\n\n /**\n * Pointers to events that were directly quoted.\n */\n quotes: EventPointer[]\n\n /**\n * List of pubkeys that are involved in the thread in no particular order.\n */\n profiles: ProfilePointer[]\n} {\n const result: ReturnType<typeof parse> = {\n reply: undefined,\n root: undefined,\n mentions: [],\n profiles: [],\n quotes: [],\n }\n\n let maybeParent: EventPointer | undefined\n let maybeRoot: EventPointer | undefined\n\n for (let i = event.tags.length - 1; i >= 0; i--) {\n const tag = event.tags[i]\n\n if (tag[0] === 'e' && tag[1] && isHex32(tag[1])) {\n const [_, eTagEventId, eTagRelayUrl, eTagMarker, eTagAuthor] = tag as [\n string,\n string,\n undefined | string,\n undefined | string,\n undefined | string,\n ]\n\n const eventPointer: EventPointer = {\n id: eTagEventId,\n relays: eTagRelayUrl ? [eTagRelayUrl] : [],\n author: eTagAuthor && isHex32(eTagAuthor) ? eTagAuthor : undefined,\n }\n\n if (eTagMarker === 'root') {\n result.root = eventPointer\n continue\n }\n\n if (eTagMarker === 'reply') {\n result.reply = eventPointer\n continue\n }\n\n if (eTagMarker === 'mention') {\n result.mentions.push(eventPointer)\n continue\n }\n\n if (!maybeParent) {\n maybeParent = eventPointer\n } else {\n maybeRoot = eventPointer\n }\n\n result.mentions.push(eventPointer)\n continue\n }\n\n if (tag[0] === 'q' && tag[1] && isHex32(tag[1])) {\n const [_, eTagEventId, eTagRelayUrl] = tag as [string, string, undefined | string]\n result.quotes.push({\n id: eTagEventId,\n relays: eTagRelayUrl ? [eTagRelayUrl] : [],\n })\n }\n\n if (tag[0] === 'p' && tag[1] && isHex32(tag[1])) {\n result.profiles.push({\n pubkey: tag[1],\n relays: tag[2] ? [tag[2]] : [],\n })\n continue\n }\n }\n\n // get legacy (positional) markers, set reply to root and vice-versa if one of them is missing\n if (!result.root) {\n result.root = maybeRoot || maybeParent || result.reply\n }\n if (!result.reply) {\n result.reply = maybeParent || result.root\n }\n\n // remove root and reply from mentions, inherit relay hints from authors if any\n ;[result.reply, result.root].forEach(ref => {\n if (!ref) return\n\n let idx = result.mentions.indexOf(ref)\n if (idx !== -1) {\n result.mentions.splice(idx, 1)\n }\n if (ref.author) {\n let author = result.profiles.find(p => p.pubkey === ref.author)\n if (author && author.relays) {\n if (!ref.relays) {\n ref.relays = []\n }\n author.relays.forEach(url => {\n if (ref.relays!?.indexOf(url) === -1) ref.relays!.push(url)\n })\n author.relays = ref.relays\n }\n }\n })\n\n result.mentions.forEach(ref => {\n if (ref!.author) {\n let author = result.profiles.find(p => p.pubkey === ref.author)\n if (author && author.relays) {\n if (!ref.relays) {\n ref.relays = []\n }\n author.relays.forEach(url => {\n if (ref.relays!.indexOf(url) === -1) ref.relays!.push(url)\n })\n author.relays = ref.relays\n }\n }\n })\n\n return result\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;;;ACKA,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;;;ADrIO,SAAS,MAAM,OAyBpB;AACA,QAAM,SAAmC;AAAA,IACvC,OAAO;AAAA,IACP,MAAM;AAAA,IACN,UAAU,CAAC;AAAA,IACX,UAAU,CAAC;AAAA,IACX,QAAQ,CAAC;AAAA,EACX;AAEA,MAAI;AACJ,MAAI;AAEJ,WAAS,IAAI,MAAM,KAAK,SAAS,GAAG,KAAK,GAAG,KAAK;AAC/C,UAAM,MAAM,MAAM,KAAK;AAEvB,QAAI,IAAI,OAAO,OAAO,IAA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C,QAAI,CAAC;AAAK;AAEV,QAAI,MAAM,OAAO,SAAS,QAAQ,GAAG;AACrC,QAAI,QAAQ,IAAI;AACd,aAAO,SAAS,OAAO,KAAK,CAAC;AAAA,IAC/B;AACA,QAAI,IAAI,QAAQ;AACd,UAAI,SAAS,OAAO,SAAS,KAAK,OAAK,EAAE,WAAW,IAAI,MAAM;AAC9D,UAAI,UAAU,OAAO,QAAQ;AAC3B,YAAI,CAAC,IAAI,QAAQ;AACf,cAAI,SAAS,CAAC;AAAA,QAChB;AACA,eAAO,OAAO,QAAQ,SAAO;AAC3B,cAAI,IAAI,QAAS,QAAQ,GAAG,MAAM;AAAI,gBAAI,OAAQ,KAAK,GAAG;AAAA,QAC5D,CAAC;AACD,eAAO,SAAS,IAAI;AAAA,MACtB;AAAA,IACF;AAAA,EACF,CAAC;AAED,SAAO,SAAS,QAAQ,SAAO;AAC7B,QAAI,IAAK,QAAQ;AACf,UAAI,SAAS,OAAO,SAAS,KAAK,OAAK,EAAE,WAAW,IAAI,MAAM;AAC9D,UAAI,UAAU,OAAO,QAAQ;AAC3B,YAAI,CAAC,IAAI,QAAQ;AACf,cAAI,SAAS,CAAC;AAAA,QAChB;AACA,eAAO,OAAO,QAAQ,SAAO;AAC3B,cAAI,IAAI,OAAQ,QAAQ,GAAG,MAAM;AAAI,gBAAI,OAAQ,KAAK,GAAG;AAAA,QAC3D,CAAC;AACD,eAAO,SAAS,IAAI;AAAA,MACtB;AAAA,IACF;AAAA,EACF,CAAC;AAED,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/lib/cjs/nip13.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../nip13.ts", "../../utils.ts"],
|
|
4
|
-
"sourcesContent": ["import { bytesToHex } from '@noble/hashes/utils.js'\nimport { type UnsignedEvent, type Event } from './pure.ts'\nimport { sha256 } from '@noble/hashes/sha2.js'\n\nimport { utf8Encoder } from './utils.ts'\n\n/** Get POW difficulty from a Nostr hex ID. */\nexport function getPow(hex: string): number {\n let count = 0\n\n for (let i = 0; i < 64; i += 8) {\n const nibble = parseInt(hex.substring(i, i + 8), 16)\n if (nibble === 0) {\n count += 32\n } else {\n count += Math.clz32(nibble)\n break\n }\n }\n\n return count\n}\n\n/** Get POW difficulty directly from a Uint8Array hash. */\nfunction getPowFromBytes(hash: Uint8Array): number {\n let count = 0\n\n for (let i = 0; i < hash.length; i++) {\n const byte = hash[i]\n if (byte === 0) {\n count += 8\n } else {\n count += Math.clz32(byte) - 24\n break\n }\n }\n\n return count\n}\n\n/**\n * Mine an event with the desired POW. This function mutates the event.\n * Note that this operation is synchronous and should be run in a worker context to avoid blocking the main thread.\n */\nexport function minePow(unsigned: UnsignedEvent, difficulty: number): Omit<Event, 'sig'> {\n let count = 0\n\n const event = unsigned as Omit<Event, 'sig'>\n const tag = ['nonce', count.toString(), difficulty.toString()]\n\n event.tags.push(tag)\n\n while (true) {\n const now = Math.floor(new Date().getTime() / 1000)\n\n if (now !== event.created_at) {\n count = 0\n event.created_at = now\n }\n\n tag[1] = (++count).toString()\n\n const hash = sha256(\n utf8Encoder.encode(JSON.stringify([0, event.pubkey, event.created_at, event.kind, event.tags, event.content])),\n )\n\n if (getPowFromBytes(hash) >= difficulty) {\n event.id = bytesToHex(hash)\n break\n }\n }\n\n return event\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 { bytesToHex } from '@noble/hashes/utils.js'\nimport { type UnsignedEvent, type Event } from './pure.ts'\nimport { sha256 } from '@noble/hashes/sha2.js'\n\nimport { utf8Encoder } from './utils.ts'\n\n/** Get POW difficulty from a Nostr hex ID. */\nexport function getPow(hex: string): number {\n let count = 0\n\n for (let i = 0; i < 64; i += 8) {\n const nibble = parseInt(hex.substring(i, i + 8), 16)\n if (nibble === 0) {\n count += 32\n } else {\n count += Math.clz32(nibble)\n break\n }\n }\n\n return count\n}\n\n/** Get POW difficulty directly from a Uint8Array hash. */\nfunction getPowFromBytes(hash: Uint8Array): number {\n let count = 0\n\n for (let i = 0; i < hash.length; i++) {\n const byte = hash[i]\n if (byte === 0) {\n count += 8\n } else {\n count += Math.clz32(byte) - 24\n break\n }\n }\n\n return count\n}\n\n/**\n * Mine an event with the desired POW. This function mutates the event.\n * Note that this operation is synchronous and should be run in a worker context to avoid blocking the main thread.\n */\nexport function minePow(unsigned: UnsignedEvent, difficulty: number): Omit<Event, 'sig'> {\n let count = 0\n\n const event = unsigned as Omit<Event, 'sig'>\n const tag = ['nonce', count.toString(), difficulty.toString()]\n\n event.tags.push(tag)\n\n while (true) {\n const now = Math.floor(new Date().getTime() / 1000)\n\n if (now !== event.created_at) {\n count = 0\n event.created_at = now\n }\n\n tag[1] = (++count).toString()\n\n const hash = sha256(\n utf8Encoder.encode(JSON.stringify([0, event.pubkey, event.created_at, event.kind, event.tags, event.content])),\n )\n\n if (getPowFromBytes(hash) >= difficulty) {\n event.id = bytesToHex(hash)\n break\n }\n }\n\n return event\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,IAAAA,gBAA2B;AAE3B,kBAAuB;;;ACGvB,mBAAuC;AAHhC,IAAM,cAA2B,IAAI,YAAY,OAAO;AACxD,IAAM,cAA2B,IAAI,YAAY;;;ADIjD,SAAS,OAAO,KAAqB;AAC1C,MAAI,QAAQ;AAEZ,WAAS,IAAI,GAAG,IAAI,IAAI,KAAK,GAAG;AAC9B,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
31
31
|
var import_secp256k1 = require("@noble/curves/secp256k1.js");
|
|
32
|
-
var
|
|
32
|
+
var import_utils3 = require("@noble/hashes/utils.js");
|
|
33
|
+
|
|
34
|
+
// utils.ts
|
|
35
|
+
var import_utils = require("@noble/hashes/utils.js");
|
|
36
|
+
var utf8Decoder = new TextDecoder("utf-8");
|
|
37
|
+
var utf8Encoder = new TextEncoder();
|
|
38
|
+
function isHex32(input) {
|
|
39
|
+
for (let i2 = 0; i2 < 64; i2++) {
|
|
40
|
+
let cc = input.charCodeAt(i2);
|
|
41
|
+
if (isNaN(cc) || cc < 48 || cc > 102 || cc > 57 && cc < 97) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
33
47
|
|
|
34
48
|
// core.ts
|
|
35
49
|
var verifiedSymbol = Symbol("verified");
|
|
@@ -45,7 +59,7 @@ function validateEvent(event) {
|
|
|
45
59
|
return false;
|
|
46
60
|
if (typeof event.pubkey !== "string")
|
|
47
61
|
return false;
|
|
48
|
-
if (!event.pubkey
|
|
62
|
+
if (!isHex32(event.pubkey))
|
|
49
63
|
return false;
|
|
50
64
|
if (!Array.isArray(event.tags))
|
|
51
65
|
return false;
|
|
@@ -63,25 +77,18 @@ function validateEvent(event) {
|
|
|
63
77
|
|
|
64
78
|
// pure.ts
|
|
65
79
|
var import_sha2 = require("@noble/hashes/sha2.js");
|
|
66
|
-
|
|
67
|
-
// utils.ts
|
|
68
|
-
var import_utils = require("@noble/hashes/utils.js");
|
|
69
|
-
var utf8Decoder = new TextDecoder("utf-8");
|
|
70
|
-
var utf8Encoder = new TextEncoder();
|
|
71
|
-
|
|
72
|
-
// pure.ts
|
|
73
80
|
var JS = class {
|
|
74
81
|
generateSecretKey() {
|
|
75
82
|
return import_secp256k1.schnorr.utils.randomSecretKey();
|
|
76
83
|
}
|
|
77
84
|
getPublicKey(secretKey) {
|
|
78
|
-
return (0,
|
|
85
|
+
return (0, import_utils3.bytesToHex)(import_secp256k1.schnorr.getPublicKey(secretKey));
|
|
79
86
|
}
|
|
80
87
|
finalizeEvent(t, secretKey) {
|
|
81
88
|
const event = t;
|
|
82
|
-
event.pubkey = (0,
|
|
89
|
+
event.pubkey = (0, import_utils3.bytesToHex)(import_secp256k1.schnorr.getPublicKey(secretKey));
|
|
83
90
|
event.id = getEventHash(event);
|
|
84
|
-
event.sig = (0,
|
|
91
|
+
event.sig = (0, import_utils3.bytesToHex)(import_secp256k1.schnorr.sign((0, import_utils3.hexToBytes)(getEventHash(event)), secretKey));
|
|
85
92
|
event[verifiedSymbol] = true;
|
|
86
93
|
return event;
|
|
87
94
|
}
|
|
@@ -94,7 +101,7 @@ var JS = class {
|
|
|
94
101
|
event[verifiedSymbol] = false;
|
|
95
102
|
return false;
|
|
96
103
|
}
|
|
97
|
-
const valid = import_secp256k1.schnorr.verify((0,
|
|
104
|
+
const valid = import_secp256k1.schnorr.verify((0, import_utils3.hexToBytes)(event.sig), (0, import_utils3.hexToBytes)(hash), (0, import_utils3.hexToBytes)(event.pubkey));
|
|
98
105
|
event[verifiedSymbol] = valid;
|
|
99
106
|
return valid;
|
|
100
107
|
} catch (err) {
|
|
@@ -110,7 +117,7 @@ function serializeEvent(evt) {
|
|
|
110
117
|
}
|
|
111
118
|
function getEventHash(event) {
|
|
112
119
|
let eventHash = (0, import_sha2.sha256)(utf8Encoder.encode(serializeEvent(event)));
|
|
113
|
-
return (0,
|
|
120
|
+
return (0, import_utils3.bytesToHex)(eventHash);
|
|
114
121
|
}
|
|
115
122
|
var i = new JS();
|
|
116
123
|
var generateSecretKey = i.generateSecretKey;
|
|
@@ -125,18 +132,18 @@ var GiftWrap = 1059;
|
|
|
125
132
|
|
|
126
133
|
// nip44.ts
|
|
127
134
|
var import_chacha = require("@noble/ciphers/chacha.js");
|
|
128
|
-
var
|
|
135
|
+
var import_utils5 = require("@noble/ciphers/utils.js");
|
|
129
136
|
var import_secp256k12 = require("@noble/curves/secp256k1.js");
|
|
130
137
|
var import_hkdf = require("@noble/hashes/hkdf.js");
|
|
131
138
|
var import_hmac = require("@noble/hashes/hmac.js");
|
|
132
139
|
var import_sha22 = require("@noble/hashes/sha2.js");
|
|
133
|
-
var
|
|
140
|
+
var import_utils6 = require("@noble/hashes/utils.js");
|
|
134
141
|
var import_base = require("@scure/base");
|
|
135
142
|
var minPlaintextSize = 1;
|
|
136
143
|
var maxPlaintextSize = 4294967295;
|
|
137
144
|
var extendedPrefixThreshold = 65536;
|
|
138
145
|
function getConversationKey(privkeyA, pubkeyB) {
|
|
139
|
-
const sharedX = import_secp256k12.secp256k1.getSharedSecret(privkeyA, (0,
|
|
146
|
+
const sharedX = import_secp256k12.secp256k1.getSharedSecret(privkeyA, (0, import_utils6.hexToBytes)("02" + pubkeyB)).subarray(1, 33);
|
|
140
147
|
return (0, import_hkdf.extract)(import_sha22.sha256, sharedX, utf8Encoder.encode("nip44-v2"));
|
|
141
148
|
}
|
|
142
149
|
function getMessageKeys(conversationKey, nonce) {
|
|
@@ -175,9 +182,9 @@ function pad(plaintext) {
|
|
|
175
182
|
const unpaddedLen = unpadded.length;
|
|
176
183
|
if (unpaddedLen < minPlaintextSize || unpaddedLen > maxPlaintextSize)
|
|
177
184
|
throw new Error("invalid plaintext size: must be between 1 and 4294967295 bytes");
|
|
178
|
-
const prefix = unpaddedLen >= extendedPrefixThreshold ? (0,
|
|
185
|
+
const prefix = unpaddedLen >= extendedPrefixThreshold ? (0, import_utils6.concatBytes)(new Uint8Array([0, 0]), writeU32BE(unpaddedLen)) : writeU16BE(unpaddedLen);
|
|
179
186
|
const suffix = new Uint8Array(calcPaddedLen(unpaddedLen) - unpaddedLen);
|
|
180
|
-
return (0,
|
|
187
|
+
return (0, import_utils6.concatBytes)(prefix, unpadded, suffix);
|
|
181
188
|
}
|
|
182
189
|
function unpad(padded) {
|
|
183
190
|
const dv = new DataView(padded.buffer, padded.byteOffset, padded.byteLength);
|
|
@@ -201,7 +208,7 @@ function unpad(padded) {
|
|
|
201
208
|
function hmacAad(key, message, aad) {
|
|
202
209
|
if (aad.length !== 32)
|
|
203
210
|
throw new Error("AAD associated data must be 32 bytes");
|
|
204
|
-
const combined = (0,
|
|
211
|
+
const combined = (0, import_utils6.concatBytes)(aad, message);
|
|
205
212
|
return (0, import_hmac.hmac)(import_sha22.sha256, key, combined);
|
|
206
213
|
}
|
|
207
214
|
function decodePayload(payload) {
|
|
@@ -230,18 +237,18 @@ function decodePayload(payload) {
|
|
|
230
237
|
mac: data.subarray(-32)
|
|
231
238
|
};
|
|
232
239
|
}
|
|
233
|
-
function encrypt(plaintext, conversationKey, nonce = (0,
|
|
240
|
+
function encrypt(plaintext, conversationKey, nonce = (0, import_utils6.randomBytes)(32)) {
|
|
234
241
|
const { chacha_key, chacha_nonce, hmac_key } = getMessageKeys(conversationKey, nonce);
|
|
235
242
|
const padded = pad(plaintext);
|
|
236
243
|
const ciphertext = (0, import_chacha.chacha20)(chacha_key, chacha_nonce, padded);
|
|
237
244
|
const mac = hmacAad(hmac_key, ciphertext, nonce);
|
|
238
|
-
return import_base.base64.encode((0,
|
|
245
|
+
return import_base.base64.encode((0, import_utils6.concatBytes)(new Uint8Array([2]), nonce, ciphertext, mac));
|
|
239
246
|
}
|
|
240
247
|
function decrypt(payload, conversationKey) {
|
|
241
248
|
const { nonce, ciphertext, mac } = decodePayload(payload);
|
|
242
249
|
const { chacha_key, chacha_nonce, hmac_key } = getMessageKeys(conversationKey, nonce);
|
|
243
250
|
const calculatedMac = hmacAad(hmac_key, ciphertext, nonce);
|
|
244
|
-
if (!(0,
|
|
251
|
+
if (!(0, import_utils5.equalBytes)(calculatedMac, mac))
|
|
245
252
|
throw new Error("invalid MAC");
|
|
246
253
|
const padded = (0, import_chacha.chacha20)(chacha_key, chacha_nonce, ciphertext);
|
|
247
254
|
return unpad(padded);
|