nostr-core 0.3.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +88 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +93 -3
- package/dist/index.js.map +1 -1
- package/dist/lnurl.d.ts +161 -0
- package/dist/lnurl.d.ts.map +1 -0
- package/dist/lnurl.js +343 -0
- package/dist/lnurl.js.map +1 -0
- package/dist/nip02.d.ts +27 -0
- package/dist/nip02.d.ts.map +1 -0
- package/dist/nip02.js +55 -0
- package/dist/nip02.js.map +1 -0
- package/dist/nip05.d.ts +24 -0
- package/dist/nip05.d.ts.map +1 -0
- package/dist/nip05.js +57 -0
- package/dist/nip05.js.map +1 -0
- package/dist/nip06.d.ts +26 -0
- package/dist/nip06.d.ts.map +1 -0
- package/dist/nip06.js +49 -0
- package/dist/nip06.js.map +1 -0
- package/dist/nip07.d.ts +8 -0
- package/dist/nip07.d.ts.map +1 -1
- package/dist/nip07.js +24 -0
- package/dist/nip07.js.map +1 -1
- package/dist/nip09.d.ts +34 -0
- package/dist/nip09.d.ts.map +1 -0
- package/dist/nip09.js +66 -0
- package/dist/nip09.js.map +1 -0
- package/dist/nip10.d.ts +40 -0
- package/dist/nip10.d.ts.map +1 -0
- package/dist/nip10.js +69 -0
- package/dist/nip10.js.map +1 -0
- package/dist/nip11.d.ts +41 -0
- package/dist/nip11.d.ts.map +1 -0
- package/dist/nip11.js +38 -0
- package/dist/nip11.js.map +1 -0
- package/dist/nip13.d.ts +26 -0
- package/dist/nip13.d.ts.map +1 -0
- package/dist/nip13.js +75 -0
- package/dist/nip13.js.map +1 -0
- package/dist/nip18.d.ts +28 -0
- package/dist/nip18.d.ts.map +1 -0
- package/dist/nip18.js +66 -0
- package/dist/nip18.js.map +1 -0
- package/dist/nip21.d.ts +14 -0
- package/dist/nip21.d.ts.map +1 -0
- package/dist/nip21.js +24 -0
- package/dist/nip21.js.map +1 -0
- package/dist/nip22.d.ts +26 -0
- package/dist/nip22.d.ts.map +1 -0
- package/dist/nip22.js +109 -0
- package/dist/nip22.js.map +1 -0
- package/dist/nip23.d.ts +24 -0
- package/dist/nip23.d.ts.map +1 -0
- package/dist/nip23.js +70 -0
- package/dist/nip23.js.map +1 -0
- package/dist/nip24.d.ts +31 -0
- package/dist/nip24.d.ts.map +1 -0
- package/dist/nip24.js +75 -0
- package/dist/nip24.js.map +1 -0
- package/dist/nip25.d.ts +32 -0
- package/dist/nip25.d.ts.map +1 -0
- package/dist/nip25.js +54 -0
- package/dist/nip25.js.map +1 -0
- package/dist/nip27.d.ts +16 -0
- package/dist/nip27.d.ts.map +1 -0
- package/dist/nip27.js +44 -0
- package/dist/nip27.js.map +1 -0
- package/dist/nip28.d.ts +52 -0
- package/dist/nip28.d.ts.map +1 -0
- package/dist/nip28.js +118 -0
- package/dist/nip28.js.map +1 -0
- package/dist/nip29.d.ts +60 -0
- package/dist/nip29.d.ts.map +1 -0
- package/dist/nip29.js +122 -0
- package/dist/nip29.js.map +1 -0
- package/dist/nip30.d.ts +18 -0
- package/dist/nip30.d.ts.map +1 -0
- package/dist/nip30.js +24 -0
- package/dist/nip30.js.map +1 -0
- package/dist/nip31.d.ts +11 -0
- package/dist/nip31.d.ts.map +1 -0
- package/dist/nip31.js +15 -0
- package/dist/nip31.js.map +1 -0
- package/dist/nip36.d.ts +14 -0
- package/dist/nip36.d.ts.map +1 -0
- package/dist/nip36.js +24 -0
- package/dist/nip36.js.map +1 -0
- package/dist/nip40.d.ts +14 -0
- package/dist/nip40.d.ts.map +1 -0
- package/dist/nip40.js +26 -0
- package/dist/nip40.js.map +1 -0
- package/dist/nip42.d.ts +20 -0
- package/dist/nip42.d.ts.map +1 -0
- package/dist/nip42.js +38 -0
- package/dist/nip42.js.map +1 -0
- package/dist/nip46.d.ts +17 -4
- package/dist/nip46.d.ts.map +1 -1
- package/dist/nip46.js +78 -38
- package/dist/nip46.js.map +1 -1
- package/dist/nip48.d.ts +23 -0
- package/dist/nip48.d.ts.map +1 -0
- package/dist/nip48.js +30 -0
- package/dist/nip48.js.map +1 -0
- package/dist/nip50.d.ts +23 -0
- package/dist/nip50.d.ts.map +1 -0
- package/dist/nip50.js +47 -0
- package/dist/nip50.js.map +1 -0
- package/dist/nip51.d.ts +57 -0
- package/dist/nip51.d.ts.map +1 -0
- package/dist/nip51.js +118 -0
- package/dist/nip51.js.map +1 -0
- package/dist/nip56.d.ts +28 -0
- package/dist/nip56.d.ts.map +1 -0
- package/dist/nip56.js +60 -0
- package/dist/nip56.js.map +1 -0
- package/dist/nip57.d.ts +48 -0
- package/dist/nip57.d.ts.map +1 -0
- package/dist/nip57.js +140 -0
- package/dist/nip57.js.map +1 -0
- package/dist/nip58.d.ts +82 -0
- package/dist/nip58.d.ts.map +1 -0
- package/dist/nip58.js +195 -0
- package/dist/nip58.js.map +1 -0
- package/dist/nip59.js +1 -1
- package/dist/nip65.d.ts +28 -0
- package/dist/nip65.d.ts.map +1 -0
- package/dist/nip65.js +83 -0
- package/dist/nip65.js.map +1 -0
- package/dist/nip98.d.ts +24 -0
- package/dist/nip98.d.ts.map +1 -0
- package/dist/nip98.js +68 -0
- package/dist/nip98.js.map +1 -0
- package/dist/relay.d.ts +2 -0
- package/dist/relay.d.ts.map +1 -1
- package/dist/relay.js +20 -0
- package/dist/relay.js.map +1 -1
- package/dist/signer.d.ts +4 -0
- package/dist/signer.d.ts.map +1 -1
- package/dist/signer.js +11 -0
- package/dist/signer.js.map +1 -1
- package/package.json +33 -4
package/dist/nip22.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type NostrEvent, type EventTemplate } from './event.js';
|
|
2
|
+
export type CommentScope = {
|
|
3
|
+
rootType: 'event' | 'address' | 'external';
|
|
4
|
+
rootId: string;
|
|
5
|
+
rootKind?: number;
|
|
6
|
+
rootPubkey?: string;
|
|
7
|
+
parentType?: 'event' | 'address' | 'external';
|
|
8
|
+
parentId?: string;
|
|
9
|
+
parentKind?: number;
|
|
10
|
+
parentPubkey?: string;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Create a kind 1111 comment event template (unsigned).
|
|
14
|
+
*/
|
|
15
|
+
export declare function createCommentEventTemplate(content: string, scope: CommentScope): EventTemplate;
|
|
16
|
+
/**
|
|
17
|
+
* Create and sign a kind 1111 comment event.
|
|
18
|
+
*/
|
|
19
|
+
export declare function createCommentEvent(content: string, scope: CommentScope, secretKey: Uint8Array): NostrEvent;
|
|
20
|
+
/**
|
|
21
|
+
* Parse a kind 1111 comment event.
|
|
22
|
+
*/
|
|
23
|
+
export declare function parseComment(event: NostrEvent): CommentScope & {
|
|
24
|
+
content: string;
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=nip22.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nip22.d.ts","sourceRoot":"","sources":["../src/nip22.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,UAAU,EAAE,KAAK,aAAa,EAAE,MAAM,YAAY,CAAA;AAE/E,MAAM,MAAM,YAAY,GAAG;IACzB,QAAQ,EAAE,OAAO,GAAG,SAAS,GAAG,UAAU,CAAA;IAC1C,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,UAAU,CAAC,EAAE,OAAO,GAAG,SAAS,GAAG,UAAU,CAAA;IAC7C,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB,CAAA;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,GAAG,aAAa,CAyC9F;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,UAAU,GAAG,UAAU,CAE1G;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,UAAU,GAAG,YAAY,GAAG;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,CA6ClF"}
|
package/dist/nip22.js
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { finalizeEvent } from './event.js';
|
|
2
|
+
/**
|
|
3
|
+
* Create a kind 1111 comment event template (unsigned).
|
|
4
|
+
*/
|
|
5
|
+
export function createCommentEventTemplate(content, scope) {
|
|
6
|
+
const tags = [];
|
|
7
|
+
// Root tag
|
|
8
|
+
if (scope.rootType === 'event') {
|
|
9
|
+
const rootTag = ['E', scope.rootId];
|
|
10
|
+
if (scope.rootPubkey)
|
|
11
|
+
rootTag.push('', scope.rootPubkey);
|
|
12
|
+
tags.push(rootTag);
|
|
13
|
+
if (scope.rootKind !== undefined)
|
|
14
|
+
tags.push(['K', String(scope.rootKind)]);
|
|
15
|
+
}
|
|
16
|
+
else if (scope.rootType === 'address') {
|
|
17
|
+
tags.push(['A', scope.rootId]);
|
|
18
|
+
if (scope.rootKind !== undefined)
|
|
19
|
+
tags.push(['K', String(scope.rootKind)]);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
tags.push(['I', scope.rootId]);
|
|
23
|
+
}
|
|
24
|
+
if (scope.rootPubkey)
|
|
25
|
+
tags.push(['p', scope.rootPubkey]);
|
|
26
|
+
// Parent tag (if replying to a comment)
|
|
27
|
+
if (scope.parentId) {
|
|
28
|
+
if (scope.parentType === 'event') {
|
|
29
|
+
const parentTag = ['e', scope.parentId];
|
|
30
|
+
if (scope.parentPubkey)
|
|
31
|
+
parentTag.push('', scope.parentPubkey);
|
|
32
|
+
tags.push(parentTag);
|
|
33
|
+
if (scope.parentKind !== undefined)
|
|
34
|
+
tags.push(['k', String(scope.parentKind)]);
|
|
35
|
+
}
|
|
36
|
+
else if (scope.parentType === 'address') {
|
|
37
|
+
tags.push(['a', scope.parentId]);
|
|
38
|
+
if (scope.parentKind !== undefined)
|
|
39
|
+
tags.push(['k', String(scope.parentKind)]);
|
|
40
|
+
}
|
|
41
|
+
else if (scope.parentType === 'external') {
|
|
42
|
+
tags.push(['i', scope.parentId]);
|
|
43
|
+
}
|
|
44
|
+
if (scope.parentPubkey)
|
|
45
|
+
tags.push(['p', scope.parentPubkey]);
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
kind: 1111,
|
|
49
|
+
tags,
|
|
50
|
+
content,
|
|
51
|
+
created_at: Math.floor(Date.now() / 1000),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Create and sign a kind 1111 comment event.
|
|
56
|
+
*/
|
|
57
|
+
export function createCommentEvent(content, scope, secretKey) {
|
|
58
|
+
return finalizeEvent(createCommentEventTemplate(content, scope), secretKey);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Parse a kind 1111 comment event.
|
|
62
|
+
*/
|
|
63
|
+
export function parseComment(event) {
|
|
64
|
+
const result = {
|
|
65
|
+
rootType: 'external',
|
|
66
|
+
rootId: '',
|
|
67
|
+
content: event.content,
|
|
68
|
+
};
|
|
69
|
+
for (const tag of event.tags) {
|
|
70
|
+
switch (tag[0]) {
|
|
71
|
+
case 'E':
|
|
72
|
+
result.rootType = 'event';
|
|
73
|
+
result.rootId = tag[1];
|
|
74
|
+
if (tag[3])
|
|
75
|
+
result.rootPubkey = tag[3];
|
|
76
|
+
break;
|
|
77
|
+
case 'A':
|
|
78
|
+
result.rootType = 'address';
|
|
79
|
+
result.rootId = tag[1];
|
|
80
|
+
break;
|
|
81
|
+
case 'I':
|
|
82
|
+
result.rootType = 'external';
|
|
83
|
+
result.rootId = tag[1];
|
|
84
|
+
break;
|
|
85
|
+
case 'K':
|
|
86
|
+
result.rootKind = parseInt(tag[1], 10);
|
|
87
|
+
break;
|
|
88
|
+
case 'e':
|
|
89
|
+
result.parentType = 'event';
|
|
90
|
+
result.parentId = tag[1];
|
|
91
|
+
if (tag[3])
|
|
92
|
+
result.parentPubkey = tag[3];
|
|
93
|
+
break;
|
|
94
|
+
case 'a':
|
|
95
|
+
result.parentType = 'address';
|
|
96
|
+
result.parentId = tag[1];
|
|
97
|
+
break;
|
|
98
|
+
case 'i':
|
|
99
|
+
result.parentType = 'external';
|
|
100
|
+
result.parentId = tag[1];
|
|
101
|
+
break;
|
|
102
|
+
case 'k':
|
|
103
|
+
result.parentKind = parseInt(tag[1], 10);
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return result;
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=nip22.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nip22.js","sourceRoot":"","sources":["../src/nip22.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAuC,MAAM,YAAY,CAAA;AAa/E;;GAEG;AACH,MAAM,UAAU,0BAA0B,CAAC,OAAe,EAAE,KAAmB;IAC7E,MAAM,IAAI,GAAe,EAAE,CAAA;IAE3B,WAAW;IACX,IAAI,KAAK,CAAC,QAAQ,KAAK,OAAO,EAAE,CAAC;QAC/B,MAAM,OAAO,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;QACnC,IAAI,KAAK,CAAC,UAAU;YAAE,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE,KAAK,CAAC,UAAU,CAAC,CAAA;QACxD,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QAClB,IAAI,KAAK,CAAC,QAAQ,KAAK,SAAS;YAAE,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAA;IAC5E,CAAC;SAAM,IAAI,KAAK,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;QACxC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,MAAM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YACP,KAAK,GAAG;gBACN,MAAM,CAAC,QAAQ,GAAG,UAAU,CAAA;gBAC5B,MAAM,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,CAAA;gBACtB,MAAK;YACP,KAAK,GAAG;gBACN,MAAM,CAAC,QAAQ,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAA;gBACtC,MAAK;YACP,KAAK,GAAG;gBACN,MAAM,CAAC,UAAU,GAAG,OAAO,CAAA;gBAC3B,MAAM,CAAC,QAAQ,GAAG,GAAG,CAAC,CAAC,CAAC,CAAA;gBACxB,IAAI,GAAG,CAAC,CAAC,CAAC;oBAAE,MAAM,CAAC,YAAY,GAAG,GAAG,CAAC,CAAC,CAAC,CAAA;gBACxC,MAAK;YACP,KAAK,GAAG;gBACN,MAAM,CAAC,UAAU,GAAG,SAAS,CAAA;gBAC7B,MAAM,CAAC,QAAQ,GAAG,GAAG,CAAC,CAAC,CAAC,CAAA;gBACxB,MAAK;YACP,KAAK,GAAG;gBACN,MAAM,CAAC,UAAU,GAAG,UAAU,CAAA;gBAC9B,MAAM,CAAC,QAAQ,GAAG,GAAG,CAAC,CAAC,CAAC,CAAA;gBACxB,MAAK;YACP,KAAK,GAAG;gBACN,MAAM,CAAC,UAAU,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAA;gBACxC,MAAK;QACT,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC"}
|
package/dist/nip23.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type NostrEvent, type EventTemplate } from './event.js';
|
|
2
|
+
export type LongFormContent = {
|
|
3
|
+
identifier: string;
|
|
4
|
+
title?: string;
|
|
5
|
+
image?: string;
|
|
6
|
+
summary?: string;
|
|
7
|
+
publishedAt?: number;
|
|
8
|
+
hashtags?: string[];
|
|
9
|
+
content: string;
|
|
10
|
+
isDraft?: boolean;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Create a kind 30023 (or 30024 draft) long-form content event template.
|
|
14
|
+
*/
|
|
15
|
+
export declare function createLongFormEventTemplate(article: LongFormContent): EventTemplate;
|
|
16
|
+
/**
|
|
17
|
+
* Create and sign a long-form content event.
|
|
18
|
+
*/
|
|
19
|
+
export declare function createLongFormEvent(article: LongFormContent, secretKey: Uint8Array): NostrEvent;
|
|
20
|
+
/**
|
|
21
|
+
* Parse a kind 30023 or 30024 long-form content event.
|
|
22
|
+
*/
|
|
23
|
+
export declare function parseLongForm(event: NostrEvent): LongFormContent;
|
|
24
|
+
//# sourceMappingURL=nip23.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nip23.d.ts","sourceRoot":"","sources":["../src/nip23.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,UAAU,EAAE,KAAK,aAAa,EAAE,MAAM,YAAY,CAAA;AAE/E,MAAM,MAAM,eAAe,GAAG;IAC5B,UAAU,EAAE,MAAM,CAAA;IAClB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAA;IACnB,OAAO,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB,CAAA;AAED;;GAEG;AACH,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,eAAe,GAAG,aAAa,CAkBnF;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,UAAU,GAAG,UAAU,CAE/F;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,UAAU,GAAG,eAAe,CAmChE"}
|
package/dist/nip23.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { finalizeEvent } from './event.js';
|
|
2
|
+
/**
|
|
3
|
+
* Create a kind 30023 (or 30024 draft) long-form content event template.
|
|
4
|
+
*/
|
|
5
|
+
export function createLongFormEventTemplate(article) {
|
|
6
|
+
const kind = article.isDraft ? 30024 : 30023;
|
|
7
|
+
const tags = [['d', article.identifier]];
|
|
8
|
+
if (article.title)
|
|
9
|
+
tags.push(['title', article.title]);
|
|
10
|
+
if (article.image)
|
|
11
|
+
tags.push(['image', article.image]);
|
|
12
|
+
if (article.summary)
|
|
13
|
+
tags.push(['summary', article.summary]);
|
|
14
|
+
if (article.publishedAt !== undefined)
|
|
15
|
+
tags.push(['published_at', String(article.publishedAt)]);
|
|
16
|
+
if (article.hashtags) {
|
|
17
|
+
for (const tag of article.hashtags)
|
|
18
|
+
tags.push(['t', tag]);
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
kind,
|
|
22
|
+
tags,
|
|
23
|
+
content: article.content,
|
|
24
|
+
created_at: Math.floor(Date.now() / 1000),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Create and sign a long-form content event.
|
|
29
|
+
*/
|
|
30
|
+
export function createLongFormEvent(article, secretKey) {
|
|
31
|
+
return finalizeEvent(createLongFormEventTemplate(article), secretKey);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Parse a kind 30023 or 30024 long-form content event.
|
|
35
|
+
*/
|
|
36
|
+
export function parseLongForm(event) {
|
|
37
|
+
const result = {
|
|
38
|
+
identifier: '',
|
|
39
|
+
content: event.content,
|
|
40
|
+
isDraft: event.kind === 30024,
|
|
41
|
+
};
|
|
42
|
+
const hashtags = [];
|
|
43
|
+
for (const tag of event.tags) {
|
|
44
|
+
switch (tag[0]) {
|
|
45
|
+
case 'd':
|
|
46
|
+
result.identifier = tag[1] ?? '';
|
|
47
|
+
break;
|
|
48
|
+
case 'title':
|
|
49
|
+
result.title = tag[1];
|
|
50
|
+
break;
|
|
51
|
+
case 'image':
|
|
52
|
+
result.image = tag[1];
|
|
53
|
+
break;
|
|
54
|
+
case 'summary':
|
|
55
|
+
result.summary = tag[1];
|
|
56
|
+
break;
|
|
57
|
+
case 'published_at':
|
|
58
|
+
result.publishedAt = parseInt(tag[1], 10);
|
|
59
|
+
break;
|
|
60
|
+
case 't':
|
|
61
|
+
if (tag[1])
|
|
62
|
+
hashtags.push(tag[1]);
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (hashtags.length > 0)
|
|
67
|
+
result.hashtags = hashtags;
|
|
68
|
+
return result;
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=nip23.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nip23.js","sourceRoot":"","sources":["../src/nip23.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAuC,MAAM,YAAY,CAAA;AAa/E;;GAEG;AACH,MAAM,UAAU,2BAA2B,CAAC,OAAwB;IAClE,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAA;IAC5C,MAAM,IAAI,GAAe,CAAC,CAAC,GAAG,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC,CAAA;IAEpD,IAAI,OAAO,CAAC,KAAK;QAAE,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC,CAAA;IACtD,IAAI,OAAO,CAAC,KAAK;QAAE,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC,CAAA;IACtD,IAAI,OAAO,CAAC,OAAO;QAAE,IAAI,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC,CAAA;IAC5D,IAAI,OAAO,CAAC,WAAW,KAAK,SAAS;QAAE,IAAI,CAAC,IAAI,CAAC,CAAC,cAAc,EAAE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GAAG,GAAG,CAAC,CAAC,CAAC,CAAA;gBACvB,MAAK;YACP,KAAK,cAAc;gBACjB,MAAM,CAAC,WAAW,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAA;gBACzC,MAAK;YACP,KAAK,GAAG;gBACN,IAAI,GAAG,CAAC,CAAC,CAAC;oBAAE,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;gBACjC,MAAK;QACT,CAAC;IACH,CAAC;IAED,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC;QAAE,MAAM,CAAC,QAAQ,GAAG,QAAQ,CAAA;IAEnD,OAAO,MAAM,CAAA;AACf,CAAC"}
|
package/dist/nip24.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { NostrEvent } from './event.js';
|
|
2
|
+
export type ExtendedMetadata = {
|
|
3
|
+
display_name?: string;
|
|
4
|
+
website?: string;
|
|
5
|
+
banner?: string;
|
|
6
|
+
bot?: boolean;
|
|
7
|
+
birthday?: string;
|
|
8
|
+
[key: string]: unknown;
|
|
9
|
+
};
|
|
10
|
+
export type UniversalTags = {
|
|
11
|
+
references?: string[];
|
|
12
|
+
hashtags?: string[];
|
|
13
|
+
title?: string;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Parse extended metadata fields from a kind 0 event content JSON.
|
|
17
|
+
*/
|
|
18
|
+
export declare function parseExtendedMetadata(event: NostrEvent): ExtendedMetadata;
|
|
19
|
+
/**
|
|
20
|
+
* Build a JSON content string from extended metadata.
|
|
21
|
+
*/
|
|
22
|
+
export declare function buildMetadataContent(metadata: ExtendedMetadata): string;
|
|
23
|
+
/**
|
|
24
|
+
* Parse universal tags (r, t, title) from any event.
|
|
25
|
+
*/
|
|
26
|
+
export declare function parseUniversalTags(event: NostrEvent): UniversalTags;
|
|
27
|
+
/**
|
|
28
|
+
* Build universal tags (r, t, title) from structured input.
|
|
29
|
+
*/
|
|
30
|
+
export declare function buildUniversalTags(tags: UniversalTags): string[][];
|
|
31
|
+
//# sourceMappingURL=nip24.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nip24.d.ts","sourceRoot":"","sources":["../src/nip24.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAE5C,MAAM,MAAM,gBAAgB,GAAG;IAC7B,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,GAAG,CAAC,EAAE,OAAO,CAAA;IACb,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACvB,CAAA;AAED,MAAM,MAAM,aAAa,GAAG;IAC1B,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;IACrB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAA;IACnB,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAA;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,UAAU,GAAG,gBAAgB,CAsBzE;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,gBAAgB,GAAG,MAAM,CAEvE;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,UAAU,GAAG,aAAa,CAgBnE;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,aAAa,GAAG,MAAM,EAAE,EAAE,CAclE"}
|
package/dist/nip24.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parse extended metadata fields from a kind 0 event content JSON.
|
|
3
|
+
*/
|
|
4
|
+
export function parseExtendedMetadata(event) {
|
|
5
|
+
try {
|
|
6
|
+
const content = JSON.parse(event.content);
|
|
7
|
+
const result = {};
|
|
8
|
+
if (typeof content.display_name === 'string')
|
|
9
|
+
result.display_name = content.display_name;
|
|
10
|
+
if (typeof content.website === 'string')
|
|
11
|
+
result.website = content.website;
|
|
12
|
+
if (typeof content.banner === 'string')
|
|
13
|
+
result.banner = content.banner;
|
|
14
|
+
if (typeof content.bot === 'boolean')
|
|
15
|
+
result.bot = content.bot;
|
|
16
|
+
if (typeof content.birthday === 'string')
|
|
17
|
+
result.birthday = content.birthday;
|
|
18
|
+
// Include any other fields
|
|
19
|
+
for (const [key, value] of Object.entries(content)) {
|
|
20
|
+
if (!(key in result)) {
|
|
21
|
+
result[key] = value;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return {};
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Build a JSON content string from extended metadata.
|
|
32
|
+
*/
|
|
33
|
+
export function buildMetadataContent(metadata) {
|
|
34
|
+
return JSON.stringify(metadata);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Parse universal tags (r, t, title) from any event.
|
|
38
|
+
*/
|
|
39
|
+
export function parseUniversalTags(event) {
|
|
40
|
+
const result = {};
|
|
41
|
+
const references = [];
|
|
42
|
+
const hashtags = [];
|
|
43
|
+
for (const tag of event.tags) {
|
|
44
|
+
if (tag[0] === 'r' && tag[1])
|
|
45
|
+
references.push(tag[1]);
|
|
46
|
+
else if (tag[0] === 't' && tag[1])
|
|
47
|
+
hashtags.push(tag[1]);
|
|
48
|
+
else if (tag[0] === 'title' && tag[1])
|
|
49
|
+
result.title = tag[1];
|
|
50
|
+
}
|
|
51
|
+
if (references.length > 0)
|
|
52
|
+
result.references = references;
|
|
53
|
+
if (hashtags.length > 0)
|
|
54
|
+
result.hashtags = hashtags;
|
|
55
|
+
return result;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Build universal tags (r, t, title) from structured input.
|
|
59
|
+
*/
|
|
60
|
+
export function buildUniversalTags(tags) {
|
|
61
|
+
const result = [];
|
|
62
|
+
if (tags.references) {
|
|
63
|
+
for (const ref of tags.references)
|
|
64
|
+
result.push(['r', ref]);
|
|
65
|
+
}
|
|
66
|
+
if (tags.hashtags) {
|
|
67
|
+
for (const ht of tags.hashtags)
|
|
68
|
+
result.push(['t', ht]);
|
|
69
|
+
}
|
|
70
|
+
if (tags.title) {
|
|
71
|
+
result.push(['title', tags.title]);
|
|
72
|
+
}
|
|
73
|
+
return result;
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=nip24.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nip24.js","sourceRoot":"","sources":["../src/nip24.ts"],"names":[],"mappings":"AAiBA;;GAEG;AACH,MAAM,UAAU,qBAAqB,CAAC,KAAiB;IACrD,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAA4B,CAAA;QACpE,MAAM,MAAM,GAAqB,EAAE,CAAA;QAEnC,IAAI,OAAO,OAAO,CAAC,YAAY,KAAK,QAAQ;YAAE,MAAM,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,CAAA;QACxF,IAAI,OAAO,OAAO,CAAC,OAAO,KAAK,QAAQ;YAAE,MAAM,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAA;QACzE,IAAI,OAAO,OAAO,CAAC,MAAM,KAAK,QAAQ;YAAE,MAAM,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAA;QACtE,IAAI,OAAO,OAAO,CAAC,GAAG,KAAK,SAAS;YAAE,MAAM,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,CAAA;QAC9D,IAAI,OAAO,OAAO,CAAC,QAAQ,KAAK,QAAQ;YAAE,MAAM,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAA;QAE5E,2BAA2B;QAC3B,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,C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QAAQ,CAAA;IAEnD,OAAO,MAAM,CAAA;AACf,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,IAAmB;IACpD,MAAM,MAAM,GAAe,EAAE,CAAA;IAE7B,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;QACpB,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,UAAU;YAAE,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAA;IAC5D,CAAC;IACD,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;QAClB,KAAK,MAAM,EAAE,IAAI,IAAI,CAAC,QAAQ;YAAE,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,CAAA;IACxD,CAAC;IACD,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;QACf,MAAM,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAA;IACpC,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC"}
|
package/dist/nip25.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type NostrEvent, type EventTemplate } from './event.js';
|
|
2
|
+
export type Reaction = {
|
|
3
|
+
targetEvent?: {
|
|
4
|
+
id: string;
|
|
5
|
+
pubkey: string;
|
|
6
|
+
kind?: number;
|
|
7
|
+
};
|
|
8
|
+
targetAddress?: string;
|
|
9
|
+
content: string;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Create a kind 7 reaction event template (unsigned).
|
|
13
|
+
*/
|
|
14
|
+
export declare function createReactionEventTemplate(reaction: Reaction): EventTemplate;
|
|
15
|
+
/**
|
|
16
|
+
* Create and sign a kind 7 reaction event.
|
|
17
|
+
*/
|
|
18
|
+
export declare function createReactionEvent(reaction: Reaction, secretKey: Uint8Array): NostrEvent;
|
|
19
|
+
/**
|
|
20
|
+
* Parse a kind 7 reaction event.
|
|
21
|
+
*/
|
|
22
|
+
export declare function parseReaction(event: NostrEvent): {
|
|
23
|
+
targetEventId?: string;
|
|
24
|
+
targetPubkey?: string;
|
|
25
|
+
targetKind?: number;
|
|
26
|
+
targetAddress?: string;
|
|
27
|
+
content: string;
|
|
28
|
+
isPositive: boolean;
|
|
29
|
+
isNegative: boolean;
|
|
30
|
+
emoji?: string;
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=nip25.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nip25.d.ts","sourceRoot":"","sources":["../src/nip25.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,UAAU,EAAE,KAAK,aAAa,EAAE,MAAM,YAAY,CAAA;AAE/E,MAAM,MAAM,QAAQ,GAAG;IACrB,WAAW,CAAC,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;IAC3D,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,OAAO,EAAE,MAAM,CAAA;CAChB,CAAA;AAED;;GAEG;AACH,wBAAgB,2BAA2B,CAAC,QAAQ,EAAE,QAAQ,GAAG,aAAa,CAqB7E;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,UAAU,GAAG,UAAU,CAEzF;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,UAAU,GAAG;IAChD,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,OAAO,EAAE,MAAM,CAAA;IACf,UAAU,EAAE,OAAO,CAAA;IACnB,UAAU,EAAE,OAAO,CAAA;IACnB,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAmBA"}
|
package/dist/nip25.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { finalizeEvent } from './event.js';
|
|
2
|
+
/**
|
|
3
|
+
* Create a kind 7 reaction event template (unsigned).
|
|
4
|
+
*/
|
|
5
|
+
export function createReactionEventTemplate(reaction) {
|
|
6
|
+
const tags = [];
|
|
7
|
+
if (reaction.targetEvent) {
|
|
8
|
+
tags.push(['e', reaction.targetEvent.id]);
|
|
9
|
+
tags.push(['p', reaction.targetEvent.pubkey]);
|
|
10
|
+
if (reaction.targetEvent.kind !== undefined) {
|
|
11
|
+
tags.push(['k', String(reaction.targetEvent.kind)]);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
if (reaction.targetAddress) {
|
|
15
|
+
tags.push(['a', reaction.targetAddress]);
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
kind: 7,
|
|
19
|
+
tags,
|
|
20
|
+
content: reaction.content,
|
|
21
|
+
created_at: Math.floor(Date.now() / 1000),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Create and sign a kind 7 reaction event.
|
|
26
|
+
*/
|
|
27
|
+
export function createReactionEvent(reaction, secretKey) {
|
|
28
|
+
return finalizeEvent(createReactionEventTemplate(reaction), secretKey);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Parse a kind 7 reaction event.
|
|
32
|
+
*/
|
|
33
|
+
export function parseReaction(event) {
|
|
34
|
+
let targetEventId;
|
|
35
|
+
let targetPubkey;
|
|
36
|
+
let targetKind;
|
|
37
|
+
let targetAddress;
|
|
38
|
+
for (const tag of event.tags) {
|
|
39
|
+
if (tag[0] === 'e')
|
|
40
|
+
targetEventId = tag[1];
|
|
41
|
+
else if (tag[0] === 'p')
|
|
42
|
+
targetPubkey = tag[1];
|
|
43
|
+
else if (tag[0] === 'k')
|
|
44
|
+
targetKind = parseInt(tag[1], 10);
|
|
45
|
+
else if (tag[0] === 'a')
|
|
46
|
+
targetAddress = tag[1];
|
|
47
|
+
}
|
|
48
|
+
const content = event.content;
|
|
49
|
+
const isPositive = content === '+' || content === '';
|
|
50
|
+
const isNegative = content === '-';
|
|
51
|
+
const emoji = !isPositive && !isNegative ? content : undefined;
|
|
52
|
+
return { targetEventId, targetPubkey, targetKind, targetAddress, content, isPositive, isNegative, emoji };
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=nip25.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nip25.js","sourceRoot":"","sources":["../src/nip25.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAuC,MAAM,YAAY,CAAA;AAQ/E;;GAEG;AACH,MAAM,UAAU,2BAA2B,CAAC,QAAkB;IAC5D,MAAM,IAAI,GAAe,EAAE,CAAA;IAE3B,IAAI,QAAQ,CAAC,WAAW,EAAE,CAAC;QACzB,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC,CAAA;QACzC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,QAAQ,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAA;QAC7C,IAAI,QAAQ,CAAC,WAAW,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;YAC5C,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;QACrD,CAAC;IACH,CAAC;IAED,IAAI,QAAQ,CAAC,aAAa,EAAE,CAAC;QAC3B,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,QAAQ,CAAC,aAAa,CAAC,CAAC,CAAA;IAC1C,CAAC;IAED,OAAO;QACL,IAAI,EAAE,CAAC;QACP,IAAI;QACJ,OAAO,EAAE,QAAQ,CAAC,OAAO;QACzB,UAAU,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,G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AAC3G,CAAC"}
|
package/dist/nip27.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type DecodedResult } from './nip19.js';
|
|
2
|
+
export type ContentReference = {
|
|
3
|
+
uri: string;
|
|
4
|
+
decoded: DecodedResult;
|
|
5
|
+
start: number;
|
|
6
|
+
end: number;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Extract all nostr: references from content text.
|
|
10
|
+
*/
|
|
11
|
+
export declare function extractReferences(content: string): ContentReference[];
|
|
12
|
+
/**
|
|
13
|
+
* Replace all nostr: references in content using a replacer function.
|
|
14
|
+
*/
|
|
15
|
+
export declare function replaceReferences(content: string, replacer: (ref: ContentReference) => string): string;
|
|
16
|
+
//# sourceMappingURL=nip27.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nip27.d.ts","sourceRoot":"","sources":["../src/nip27.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,aAAa,EAAE,MAAM,YAAY,CAAA;AAEvD,MAAM,MAAM,gBAAgB,GAAG;IAC7B,GAAG,EAAE,MAAM,CAAA;IACX,OAAO,EAAE,aAAa,CAAA;IACtB,KAAK,EAAE,MAAM,CAAA;IACb,GAAG,EAAE,MAAM,CAAA;CACZ,CAAA;AAID;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,gBAAgB,EAAE,CAqBrE;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,GAAG,EAAE,gBAAgB,KAAK,MAAM,GAAG,MAAM,CAetG"}
|
package/dist/nip27.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { decode } from './nip19.js';
|
|
2
|
+
const NOSTR_MENTION_REGEX = /nostr:(npub|nprofile|note|nevent|naddr)1[qpzry9x8gf2tvdw0s3jn54khce6mua7l]+/g;
|
|
3
|
+
/**
|
|
4
|
+
* Extract all nostr: references from content text.
|
|
5
|
+
*/
|
|
6
|
+
export function extractReferences(content) {
|
|
7
|
+
const refs = [];
|
|
8
|
+
let match;
|
|
9
|
+
const regex = new RegExp(NOSTR_MENTION_REGEX.source, 'g');
|
|
10
|
+
while ((match = regex.exec(content)) !== null) {
|
|
11
|
+
try {
|
|
12
|
+
const entity = match[0].slice(6); // remove "nostr:" prefix
|
|
13
|
+
const decoded = decode(entity);
|
|
14
|
+
refs.push({
|
|
15
|
+
uri: match[0],
|
|
16
|
+
decoded,
|
|
17
|
+
start: match.index,
|
|
18
|
+
end: match.index + match[0].length,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
// skip invalid entities
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return refs;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Replace all nostr: references in content using a replacer function.
|
|
29
|
+
*/
|
|
30
|
+
export function replaceReferences(content, replacer) {
|
|
31
|
+
const refs = extractReferences(content);
|
|
32
|
+
if (refs.length === 0)
|
|
33
|
+
return content;
|
|
34
|
+
let result = '';
|
|
35
|
+
let lastIndex = 0;
|
|
36
|
+
for (const ref of refs) {
|
|
37
|
+
result += content.slice(lastIndex, ref.start);
|
|
38
|
+
result += replacer(ref);
|
|
39
|
+
lastIndex = ref.end;
|
|
40
|
+
}
|
|
41
|
+
result += content.slice(lastIndex);
|
|
42
|
+
return result;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=nip27.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nip27.js","sourceRoot":"","sources":["../src/nip27.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAsB,MAAM,YAAY,CAAA;AASvD,MAAM,mBAAmB,GAAG,8EAA8E,CAAA;AAE1G;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,OAAe;IAC/C,MAAM,IAAI,GAAuB,EAAE,CAAA;IACnC,IAAI,KAA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C,CAAA;IAClC,OAAO,MAAM,CAAA;AACf,CAAC"}
|
package/dist/nip28.d.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { type NostrEvent, type EventTemplate } from './event.js';
|
|
2
|
+
export type ChannelMetadata = {
|
|
3
|
+
name: string;
|
|
4
|
+
about?: string;
|
|
5
|
+
picture?: string;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Create a kind 40 channel creation event template.
|
|
9
|
+
*/
|
|
10
|
+
export declare function createChannelEventTemplate(metadata: ChannelMetadata): EventTemplate;
|
|
11
|
+
/**
|
|
12
|
+
* Create and sign a kind 40 channel creation event.
|
|
13
|
+
*/
|
|
14
|
+
export declare function createChannelEvent(metadata: ChannelMetadata, secretKey: Uint8Array): NostrEvent;
|
|
15
|
+
/**
|
|
16
|
+
* Create a kind 41 channel metadata update event template.
|
|
17
|
+
*/
|
|
18
|
+
export declare function createChannelMetadataEventTemplate(channelId: string, metadata: ChannelMetadata, recommendedRelay?: string): EventTemplate;
|
|
19
|
+
/**
|
|
20
|
+
* Create and sign a kind 41 channel metadata update event.
|
|
21
|
+
*/
|
|
22
|
+
export declare function createChannelMetadataEvent(channelId: string, metadata: ChannelMetadata, secretKey: Uint8Array, recommendedRelay?: string): NostrEvent;
|
|
23
|
+
/**
|
|
24
|
+
* Create a kind 42 channel message event template.
|
|
25
|
+
*/
|
|
26
|
+
export declare function createChannelMessageEventTemplate(channelId: string, content: string, recommendedRelay?: string, replyTo?: string): EventTemplate;
|
|
27
|
+
/**
|
|
28
|
+
* Create and sign a kind 42 channel message event.
|
|
29
|
+
*/
|
|
30
|
+
export declare function createChannelMessageEvent(channelId: string, content: string, secretKey: Uint8Array, recommendedRelay?: string, replyTo?: string): NostrEvent;
|
|
31
|
+
/**
|
|
32
|
+
* Create a kind 43 channel hide message event template.
|
|
33
|
+
*/
|
|
34
|
+
export declare function createChannelHideMessageEventTemplate(messageId: string, reason?: string): EventTemplate;
|
|
35
|
+
/**
|
|
36
|
+
* Create a kind 44 channel mute user event template.
|
|
37
|
+
*/
|
|
38
|
+
export declare function createChannelMuteUserEventTemplate(pubkey: string, reason?: string): EventTemplate;
|
|
39
|
+
/**
|
|
40
|
+
* Parse channel metadata from a kind 40 or 41 event.
|
|
41
|
+
*/
|
|
42
|
+
export declare function parseChannelMetadata(event: NostrEvent): ChannelMetadata;
|
|
43
|
+
/**
|
|
44
|
+
* Parse a channel message event (kind 42).
|
|
45
|
+
* Returns the channel ID, content, and optional reply reference.
|
|
46
|
+
*/
|
|
47
|
+
export declare function parseChannelMessage(event: NostrEvent): {
|
|
48
|
+
channelId?: string;
|
|
49
|
+
content: string;
|
|
50
|
+
replyTo?: string;
|
|
51
|
+
};
|
|
52
|
+
//# sourceMappingURL=nip28.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nip28.d.ts","sourceRoot":"","sources":["../src/nip28.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,UAAU,EAAE,KAAK,aAAa,EAAE,MAAM,YAAY,CAAA;AAE/E,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB,CAAA;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,QAAQ,EAAE,eAAe,GAAG,aAAa,CAOnF;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,eAAe,EAAE,SAAS,EAAE,UAAU,GAAG,UAAU,CAE/F;AAED;;GAEG;AACH,wBAAgB,kCAAkC,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,eAAe,EAAE,gBAAgB,CAAC,EAAE,MAAM,GAAG,aAAa,CAOzI;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,eAAe,EAAE,SAAS,EAAE,UAAU,E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