nostr-comments 0.1.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/README.md +294 -0
- package/dist/NostrComments.d.ts +2 -0
- package/dist/components/Avatar.d.ts +7 -0
- package/dist/components/CommentEditor.d.ts +14 -0
- package/dist/components/CommentItem.d.ts +14 -0
- package/dist/components/CommentList.d.ts +18 -0
- package/dist/components/LoginModal/BunkerLogin.d.ts +5 -0
- package/dist/components/LoginModal/Nip07Login.d.ts +5 -0
- package/dist/components/LoginModal/index.d.ts +9 -0
- package/dist/components/Username.d.ts +6 -0
- package/dist/components/index.d.ts +6 -0
- package/dist/hooks/index.d.ts +4 -0
- package/dist/hooks/useComments.d.ts +20 -0
- package/dist/hooks/useProfile.d.ts +4 -0
- package/dist/hooks/useSigner.d.ts +18 -0
- package/dist/i18n/index.d.ts +35 -0
- package/dist/i18n/locales/ar.d.ts +2 -0
- package/dist/i18n/locales/de.d.ts +2 -0
- package/dist/i18n/locales/en.d.ts +2 -0
- package/dist/i18n/locales/es.d.ts +2 -0
- package/dist/i18n/locales/fr.d.ts +2 -0
- package/dist/i18n/locales/hi.d.ts +2 -0
- package/dist/i18n/locales/id.d.ts +2 -0
- package/dist/i18n/locales/it.d.ts +2 -0
- package/dist/i18n/locales/ja.d.ts +2 -0
- package/dist/i18n/locales/ko.d.ts +2 -0
- package/dist/i18n/locales/nl.d.ts +2 -0
- package/dist/i18n/locales/pl.d.ts +2 -0
- package/dist/i18n/locales/pt.d.ts +2 -0
- package/dist/i18n/locales/ru.d.ts +2 -0
- package/dist/i18n/locales/th.d.ts +2 -0
- package/dist/i18n/locales/tr.d.ts +2 -0
- package/dist/i18n/locales/uk.d.ts +2 -0
- package/dist/i18n/locales/vi.d.ts +2 -0
- package/dist/i18n/locales/zh-CN.d.ts +2 -0
- package/dist/i18n/locales/zh-TW.d.ts +2 -0
- package/dist/index.d.ts +14 -0
- package/dist/nostr-comments.cjs +96 -0
- package/dist/nostr-comments.js +10257 -0
- package/dist/nostr-comments.umd.js +96 -0
- package/dist/services/comment.d.ts +32 -0
- package/dist/services/nostr.d.ts +6 -0
- package/dist/services/reaction.d.ts +18 -0
- package/dist/signers/BunkerSigner.d.ts +13 -0
- package/dist/signers/Nip07Signer.d.ts +16 -0
- package/dist/signers/TempSigner.d.ts +19 -0
- package/dist/signers/index.d.ts +4 -0
- package/dist/signers/types.d.ts +10 -0
- package/dist/types/index.d.ts +80 -0
- package/dist/utils/avatar.d.ts +3 -0
- package/dist/utils/ensureStyles.d.ts +1 -0
- package/dist/utils/nip22.d.ts +17 -0
- package/package.json +64 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { NostrEvent } from "nostr-tools";
|
|
2
|
+
import type { Signer } from "../signers/types";
|
|
3
|
+
import type { Comment } from "../types";
|
|
4
|
+
export interface FetchCommentsOptions {
|
|
5
|
+
url: string;
|
|
6
|
+
relays: string[];
|
|
7
|
+
limit?: number;
|
|
8
|
+
until?: number;
|
|
9
|
+
}
|
|
10
|
+
export interface SubscribeCommentsOptions {
|
|
11
|
+
url: string;
|
|
12
|
+
relays: string[];
|
|
13
|
+
limit?: number;
|
|
14
|
+
onEvent: (event: NostrEvent) => void;
|
|
15
|
+
onEose?: () => void;
|
|
16
|
+
}
|
|
17
|
+
export declare function subscribeComments(options: SubscribeCommentsOptions): () => void;
|
|
18
|
+
export declare function fetchComments(options: FetchCommentsOptions): Promise<NostrEvent[]>;
|
|
19
|
+
export declare function publishComment(signer: Signer, options: {
|
|
20
|
+
url: string;
|
|
21
|
+
content: string;
|
|
22
|
+
relays?: string[];
|
|
23
|
+
authorPubkeys?: string[];
|
|
24
|
+
}): Promise<NostrEvent>;
|
|
25
|
+
export declare function publishReply(signer: Signer, options: {
|
|
26
|
+
url: string;
|
|
27
|
+
content: string;
|
|
28
|
+
parentEvent: NostrEvent;
|
|
29
|
+
relays?: string[];
|
|
30
|
+
authorPubkeys?: string[];
|
|
31
|
+
}): Promise<NostrEvent>;
|
|
32
|
+
export declare function buildCommentTree(events: NostrEvent[]): Comment[];
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Filter, NostrEvent } from "nostr-tools";
|
|
2
|
+
export declare function getDefaultRelays(): string[];
|
|
3
|
+
export declare function queryEvents(relays: string[], filter: Filter): Promise<NostrEvent[]>;
|
|
4
|
+
export declare function subscribeEvents(relays: string[], filter: Filter, onEvent: (event: NostrEvent) => void, onEose?: () => void): () => void;
|
|
5
|
+
export declare function publishEvent(relays: string[], event: NostrEvent): Promise<void>;
|
|
6
|
+
export declare function getRelays(relays?: string[], authors?: string[]): Promise<string[]>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { NostrEvent, EventTemplate } from 'nostr-tools';
|
|
2
|
+
import type { Signer } from '../signers/types';
|
|
3
|
+
export interface FetchReactionsOptions {
|
|
4
|
+
eventIds: string[];
|
|
5
|
+
relays: string[];
|
|
6
|
+
}
|
|
7
|
+
export interface SubscribeReactionsOptions {
|
|
8
|
+
eventIds: string[];
|
|
9
|
+
relays: string[];
|
|
10
|
+
onEvent: (event: NostrEvent) => void;
|
|
11
|
+
onEose?: () => void;
|
|
12
|
+
}
|
|
13
|
+
export declare function subscribeReactions(options: SubscribeReactionsOptions): () => void;
|
|
14
|
+
export declare function fetchReactions(options: FetchReactionsOptions): Promise<NostrEvent[]>;
|
|
15
|
+
export declare function buildReactionEvent(targetEvent: NostrEvent, content?: string): EventTemplate;
|
|
16
|
+
export declare function publishReaction(signer: Signer, relays: string[], targetEvent: NostrEvent, content?: string): Promise<NostrEvent>;
|
|
17
|
+
export declare function countLikes(reactions: NostrEvent[], eventId: string): number;
|
|
18
|
+
export declare function hasLiked(reactions: NostrEvent[], eventId: string, pubkey: string): boolean;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { EventTemplate, VerifiedEvent } from "nostr-tools";
|
|
2
|
+
import { BunkerSigner as Nip46Signer } from "nostr-tools/nip46";
|
|
3
|
+
import type { Signer } from "./types";
|
|
4
|
+
export declare class BunkerSigner implements Signer {
|
|
5
|
+
private signer;
|
|
6
|
+
private cachedPubKey;
|
|
7
|
+
constructor(signer: Nip46Signer);
|
|
8
|
+
connect(): Promise<void>;
|
|
9
|
+
getPublicKey(): Promise<string>;
|
|
10
|
+
signEvent(event: EventTemplate): Promise<VerifiedEvent>;
|
|
11
|
+
close(): Promise<void>;
|
|
12
|
+
static create(bunkerUrl: string): Promise<BunkerSigner>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { EventTemplate, VerifiedEvent } from 'nostr-tools';
|
|
2
|
+
import type { Signer } from './types';
|
|
3
|
+
declare global {
|
|
4
|
+
interface Window {
|
|
5
|
+
nostr?: {
|
|
6
|
+
getPublicKey: () => Promise<string>;
|
|
7
|
+
signEvent: (event: EventTemplate) => Promise<VerifiedEvent>;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export declare class Nip07Signer implements Signer {
|
|
12
|
+
private cachedPubKey;
|
|
13
|
+
static isAvailable(): boolean;
|
|
14
|
+
getPublicKey(): Promise<string>;
|
|
15
|
+
signEvent(event: EventTemplate): Promise<VerifiedEvent>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { EventTemplate, VerifiedEvent } from 'nostr-tools';
|
|
2
|
+
import type { Signer } from './types';
|
|
3
|
+
export declare class TempSigner implements Signer {
|
|
4
|
+
private secretKey;
|
|
5
|
+
private pubkey;
|
|
6
|
+
constructor(secretKey?: Uint8Array);
|
|
7
|
+
getPublicKey(): Promise<string>;
|
|
8
|
+
signEvent(event: EventTemplate): Promise<VerifiedEvent>;
|
|
9
|
+
getNsec(): string;
|
|
10
|
+
getNpub(): string;
|
|
11
|
+
exportKeyFile(): {
|
|
12
|
+
nsec: string;
|
|
13
|
+
npub: string;
|
|
14
|
+
pubkey: string;
|
|
15
|
+
};
|
|
16
|
+
downloadKeyFile(): void;
|
|
17
|
+
copyNsec(): Promise<void>;
|
|
18
|
+
static fromNsec(nsec: string): TempSigner;
|
|
19
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { EventTemplate, VerifiedEvent } from 'nostr-tools';
|
|
2
|
+
export interface Signer {
|
|
3
|
+
getPublicKey(): Promise<string>;
|
|
4
|
+
signEvent(event: EventTemplate): Promise<VerifiedEvent>;
|
|
5
|
+
}
|
|
6
|
+
export type SignerType = 'nip07' | 'bunker' | 'temp';
|
|
7
|
+
export interface SignerInfo {
|
|
8
|
+
type: SignerType;
|
|
9
|
+
pubkey: string;
|
|
10
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { NostrEvent } from "nostr-tools";
|
|
2
|
+
export interface Comment {
|
|
3
|
+
event: NostrEvent;
|
|
4
|
+
children: Comment[];
|
|
5
|
+
/** Parent comment event when this is a nested reply (depth >= 2) */
|
|
6
|
+
replyTo?: NostrEvent;
|
|
7
|
+
}
|
|
8
|
+
export interface Profile {
|
|
9
|
+
pubkey: string;
|
|
10
|
+
name?: string;
|
|
11
|
+
displayName?: string;
|
|
12
|
+
picture?: string;
|
|
13
|
+
nip05?: string;
|
|
14
|
+
about?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface Translations {
|
|
17
|
+
comments: string;
|
|
18
|
+
writeComment: string;
|
|
19
|
+
reply: string;
|
|
20
|
+
replyTo: string;
|
|
21
|
+
publish: string;
|
|
22
|
+
publishing: string;
|
|
23
|
+
cancel: string;
|
|
24
|
+
login: string;
|
|
25
|
+
logout: string;
|
|
26
|
+
loginRequired: string;
|
|
27
|
+
loginDescription: string;
|
|
28
|
+
extensionLogin: string;
|
|
29
|
+
extensionLoginDesc: string;
|
|
30
|
+
bunkerLogin: string;
|
|
31
|
+
bunkerLoginDesc: string;
|
|
32
|
+
bunkerUrlPlaceholder: string;
|
|
33
|
+
connect: string;
|
|
34
|
+
connecting: string;
|
|
35
|
+
tempAccount: string;
|
|
36
|
+
tempAccountDesc: string;
|
|
37
|
+
tempAccountCreated: string;
|
|
38
|
+
createAccount: string;
|
|
39
|
+
copyKey: string;
|
|
40
|
+
keyCopied: string;
|
|
41
|
+
downloadKey: string;
|
|
42
|
+
keyCompatibility: string;
|
|
43
|
+
startCommenting: string;
|
|
44
|
+
importKey: string;
|
|
45
|
+
importKeyDesc: string;
|
|
46
|
+
importKeyPlaceholder: string;
|
|
47
|
+
importKeyError: string;
|
|
48
|
+
like: string;
|
|
49
|
+
liked: string;
|
|
50
|
+
loadMore: string;
|
|
51
|
+
loading: string;
|
|
52
|
+
noComments: string;
|
|
53
|
+
error: string;
|
|
54
|
+
retry: string;
|
|
55
|
+
anonymous: string;
|
|
56
|
+
timeJustNow: string;
|
|
57
|
+
timeMinutesAgo: string;
|
|
58
|
+
timeHoursAgo: string;
|
|
59
|
+
timeDaysAgo: string;
|
|
60
|
+
}
|
|
61
|
+
export interface NostrCommentsProps {
|
|
62
|
+
url: string;
|
|
63
|
+
authorPubkeys?: string[];
|
|
64
|
+
relays?: string[];
|
|
65
|
+
pageSize?: number;
|
|
66
|
+
locale?: string;
|
|
67
|
+
translations?: Partial<Translations>;
|
|
68
|
+
theme?: "light" | "dark" | "auto";
|
|
69
|
+
headless?: boolean;
|
|
70
|
+
classNames?: {
|
|
71
|
+
root?: string;
|
|
72
|
+
list?: string;
|
|
73
|
+
item?: string;
|
|
74
|
+
editor?: string;
|
|
75
|
+
loginModal?: string;
|
|
76
|
+
};
|
|
77
|
+
enabledSigners?: ("nip07" | "bunker" | "temp")[];
|
|
78
|
+
onCommentPublished?: (event: NostrEvent) => void;
|
|
79
|
+
onError?: (error: Error) => void;
|
|
80
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function ensureStyles(): void;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { EventTemplate, NostrEvent } from "nostr-tools";
|
|
2
|
+
export interface WebCommentOptions {
|
|
3
|
+
url: string;
|
|
4
|
+
content: string;
|
|
5
|
+
authorPubkeys?: string[];
|
|
6
|
+
}
|
|
7
|
+
export interface ReplyCommentOptions {
|
|
8
|
+
url: string;
|
|
9
|
+
content: string;
|
|
10
|
+
parentEvent: NostrEvent;
|
|
11
|
+
authorPubkeys?: string[];
|
|
12
|
+
}
|
|
13
|
+
export declare function buildWebComment(options: WebCommentOptions): EventTemplate;
|
|
14
|
+
export declare function buildReplyComment(options: ReplyCommentOptions): EventTemplate;
|
|
15
|
+
export declare function isReply(event: NostrEvent): boolean;
|
|
16
|
+
export declare function getParentId(event: NostrEvent): string | null;
|
|
17
|
+
export declare function getRootUrl(event: NostrEvent): string | null;
|
package/package.json
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "nostr-comments",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A Nostr-based web comment component using NIP-22 protocol",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/nostr-comments.cjs",
|
|
7
|
+
"module": "./dist/nostr-comments.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/nostr-comments.js",
|
|
13
|
+
"require": "./dist/nostr-comments.cjs"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"dev": "vite",
|
|
21
|
+
"build": "vite build && tsc --emitDeclarationOnly",
|
|
22
|
+
"preview": "vite preview",
|
|
23
|
+
"storybook": "storybook dev -p 6006",
|
|
24
|
+
"build-storybook": "storybook build"
|
|
25
|
+
},
|
|
26
|
+
"keywords": [
|
|
27
|
+
"nostr",
|
|
28
|
+
"comments",
|
|
29
|
+
"nip-22",
|
|
30
|
+
"react",
|
|
31
|
+
"web-component"
|
|
32
|
+
],
|
|
33
|
+
"author": "",
|
|
34
|
+
"license": "MIT",
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"react": "^18.0.0 || ^19.0.0",
|
|
37
|
+
"react-dom": "^18.0.0 || ^19.0.0"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@nostr/gadgets": "npm:@jsr/nostr__gadgets@^0.0.46",
|
|
41
|
+
"lucide-react": "^0.563.0",
|
|
42
|
+
"nostr-tools": "^2.10.4"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@chromatic-com/storybook": "^5.0.0",
|
|
46
|
+
"@storybook/addon-a11y": "^10.2.0",
|
|
47
|
+
"@storybook/addon-docs": "^10.2.0",
|
|
48
|
+
"@storybook/addon-vitest": "^10.2.0",
|
|
49
|
+
"@storybook/react-vite": "^10.2.0",
|
|
50
|
+
"@types/react": "^19.1.6",
|
|
51
|
+
"@types/react-dom": "^19.1.5",
|
|
52
|
+
"@vitejs/plugin-react": "^4.5.1",
|
|
53
|
+
"@vitest/browser-playwright": "^4.0.18",
|
|
54
|
+
"@vitest/coverage-v8": "^4.0.18",
|
|
55
|
+
"playwright": "^1.58.0",
|
|
56
|
+
"react": "^19.1.0",
|
|
57
|
+
"react-dom": "^19.1.0",
|
|
58
|
+
"storybook": "^10.2.0",
|
|
59
|
+
"typescript": "^5.7.3",
|
|
60
|
+
"vite": "^6.0.11",
|
|
61
|
+
"vite-plugin-css-injected-by-js": "^3.5.2",
|
|
62
|
+
"vitest": "^4.0.18"
|
|
63
|
+
}
|
|
64
|
+
}
|