spasm.js 1.0.2 → 2.0.0-alpha
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 +454 -113
- package/lib.commonjs/convert/convertToEventForSpasmid.d.ts +4 -0
- package/lib.commonjs/convert/convertToEventForSpasmid.d.ts.map +1 -0
- package/lib.commonjs/convert/convertToEventForSpasmid.js +171 -0
- package/lib.commonjs/convert/convertToEventForSpasmid.js.map +1 -0
- package/lib.commonjs/convert/convertToSpasm.d.ts +17 -15
- package/lib.commonjs/convert/convertToSpasm.d.ts.map +1 -1
- package/lib.commonjs/convert/convertToSpasm.js +772 -265
- package/lib.commonjs/convert/convertToSpasm.js.map +1 -1
- package/lib.commonjs/convert/convertToSpasmEventDatabase.d.ts +4 -0
- package/lib.commonjs/convert/convertToSpasmEventDatabase.d.ts.map +1 -0
- package/lib.commonjs/convert/convertToSpasmEventDatabase.js +130 -0
- package/lib.commonjs/convert/convertToSpasmEventDatabase.js.map +1 -0
- package/lib.commonjs/convert/index.d.ts +2 -0
- package/lib.commonjs/convert/index.d.ts.map +1 -1
- package/lib.commonjs/convert/index.js +5 -1
- package/lib.commonjs/convert/index.js.map +1 -1
- package/lib.commonjs/id/getSpasmId.d.ts +4 -0
- package/lib.commonjs/id/getSpasmId.d.ts.map +1 -0
- package/lib.commonjs/id/getSpasmId.js +31 -0
- package/lib.commonjs/id/getSpasmId.js.map +1 -0
- package/lib.commonjs/id/index.d.ts +2 -0
- package/lib.commonjs/id/index.d.ts.map +1 -0
- package/lib.commonjs/id/index.js +6 -0
- package/lib.commonjs/id/index.js.map +1 -0
- package/lib.commonjs/identify/identifyEvent.d.ts.map +1 -1
- package/lib.commonjs/identify/identifyEvent.js +13 -5
- package/lib.commonjs/identify/identifyEvent.js.map +1 -1
- package/lib.commonjs/sort/index.d.ts +2 -0
- package/lib.commonjs/sort/index.d.ts.map +1 -0
- package/lib.commonjs/sort/index.js +6 -0
- package/lib.commonjs/sort/index.js.map +1 -0
- package/lib.commonjs/sort/sortEventForSpasmid.d.ts +3 -0
- package/lib.commonjs/sort/sortEventForSpasmid.d.ts.map +1 -0
- package/lib.commonjs/sort/sortEventForSpasmid.js +15 -0
- package/lib.commonjs/sort/sortEventForSpasmid.js.map +1 -0
- package/lib.commonjs/spasm.d.ts +5 -3
- package/lib.commonjs/spasm.d.ts.map +1 -1
- package/lib.commonjs/spasm.js +4 -5
- package/lib.commonjs/spasm.js.map +1 -1
- package/lib.commonjs/types/index.d.ts +1 -1
- package/lib.commonjs/types/index.d.ts.map +1 -1
- package/lib.commonjs/types/interfaces.d.ts +468 -90
- package/lib.commonjs/types/interfaces.d.ts.map +1 -1
- package/lib.commonjs/types/interfaces.js +2 -0
- package/lib.commonjs/types/interfaces.js.map +1 -1
- package/lib.commonjs/utils/nostrUtils.d.ts +10 -2
- package/lib.commonjs/utils/nostrUtils.d.ts.map +1 -1
- package/lib.commonjs/utils/nostrUtils.js +122 -22
- package/lib.commonjs/utils/nostrUtils.js.map +1 -1
- package/lib.commonjs/utils/utils.d.ts +26 -1
- package/lib.commonjs/utils/utils.d.ts.map +1 -1
- package/lib.commonjs/utils/utils.js +723 -3
- package/lib.commonjs/utils/utils.js.map +1 -1
- package/lib.esm/convert/convertToEventForSpasmid.d.ts +4 -0
- package/lib.esm/convert/convertToEventForSpasmid.d.ts.map +1 -0
- package/lib.esm/convert/convertToEventForSpasmid.js +168 -0
- package/lib.esm/convert/convertToEventForSpasmid.js.map +1 -0
- package/lib.esm/convert/convertToSpasm.d.ts +17 -15
- package/lib.esm/convert/convertToSpasm.d.ts.map +1 -1
- package/lib.esm/convert/convertToSpasm.js +759 -251
- package/lib.esm/convert/convertToSpasm.js.map +1 -1
- package/lib.esm/convert/convertToSpasmEventDatabase.d.ts +4 -0
- package/lib.esm/convert/convertToSpasmEventDatabase.d.ts.map +1 -0
- package/lib.esm/convert/convertToSpasmEventDatabase.js +137 -0
- package/lib.esm/convert/convertToSpasmEventDatabase.js.map +1 -0
- package/lib.esm/convert/index.d.ts +2 -0
- package/lib.esm/convert/index.d.ts.map +1 -1
- package/lib.esm/convert/index.js +2 -0
- package/lib.esm/convert/index.js.map +1 -1
- package/lib.esm/id/getSpasmId.d.ts +4 -0
- package/lib.esm/id/getSpasmId.d.ts.map +1 -0
- package/lib.esm/id/getSpasmId.js +31 -0
- package/lib.esm/id/getSpasmId.js.map +1 -0
- package/lib.esm/id/index.d.ts +2 -0
- package/lib.esm/id/index.d.ts.map +1 -0
- package/lib.esm/id/index.js +2 -0
- package/lib.esm/id/index.js.map +1 -0
- package/lib.esm/identify/identifyEvent.d.ts.map +1 -1
- package/lib.esm/identify/identifyEvent.js +13 -5
- package/lib.esm/identify/identifyEvent.js.map +1 -1
- package/lib.esm/sort/index.d.ts +2 -0
- package/lib.esm/sort/index.d.ts.map +1 -0
- package/lib.esm/sort/index.js +2 -0
- package/lib.esm/sort/index.js.map +1 -0
- package/lib.esm/sort/sortEventForSpasmid.d.ts +3 -0
- package/lib.esm/sort/sortEventForSpasmid.d.ts.map +1 -0
- package/lib.esm/sort/sortEventForSpasmid.js +17 -0
- package/lib.esm/sort/sortEventForSpasmid.js.map +1 -0
- package/lib.esm/spasm.d.ts +5 -3
- package/lib.esm/spasm.d.ts.map +1 -1
- package/lib.esm/spasm.js +4 -2
- package/lib.esm/spasm.js.map +1 -1
- package/lib.esm/types/index.d.ts +1 -1
- package/lib.esm/types/index.d.ts.map +1 -1
- package/lib.esm/types/interfaces.d.ts +468 -90
- package/lib.esm/types/interfaces.d.ts.map +1 -1
- package/lib.esm/types/interfaces.js +2 -0
- package/lib.esm/types/interfaces.js.map +1 -1
- package/lib.esm/utils/nostrUtils.d.ts +10 -2
- package/lib.esm/utils/nostrUtils.d.ts.map +1 -1
- package/lib.esm/utils/nostrUtils.js +119 -21
- package/lib.esm/utils/nostrUtils.js.map +1 -1
- package/lib.esm/utils/utils.d.ts +26 -1
- package/lib.esm/utils/utils.d.ts.map +1 -1
- package/lib.esm/utils/utils.js +701 -2
- package/lib.esm/utils/utils.js.map +1 -1
- package/package.json +9 -2
- package/src.ts/convert/convertToEventForSpasmid.ts +289 -0
- package/src.ts/convert/convertToSpasm.ts +962 -292
- package/src.ts/convert/convertToSpasmEventDatabase.ts +204 -0
- package/src.ts/convert/index.ts +2 -0
- package/src.ts/docs/architecture.md +413 -0
- package/src.ts/id/getSpasmId.ts +56 -0
- package/src.ts/id/index.ts +1 -0
- package/src.ts/identify/identifyEvent.ts +12 -5
- package/src.ts/sort/index.ts +1 -0
- package/src.ts/sort/sortEventForSpasmid.ts +30 -0
- package/src.ts/spasm.ts +5 -3
- package/src.ts/types/index.ts +1 -1
- package/src.ts/types/interfaces.ts +729 -125
- package/src.ts/utils/nostrUtils.ts +150 -22
- package/src.ts/utils/utils.ts +1005 -4
|
@@ -1,34 +1,116 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.convertToSpasmStatus = exports.addFieldsFromEnvelopeSpasmEventV0_V2 = exports.standardizeSpasmWithRssItemV0_V2 = exports.standardizeSpasmNostrSpasmEventSignedOpenedV0_V2 = exports.standardizeSpasmNostrEventSignedOpenedV0_V2 = exports.standardizeSpasmDmpEventSignedClosedV0_V2 = exports.standardizeNostrSpasmEventSignedOpenedV2 = exports.standardizeNostrEventSignedOpenedV2 = exports.standardizeNostrSpasmEventV2 = exports.standardizeNostrEventV2 = exports.standardizeDmpEventSignedOpenedV2 = exports.standardizeDmpEventSignedClosedV2 = exports.standardizeDmpEventV2 = exports.standardizeEventV2 = exports.assignSpasmId = exports.convertToSpasm = void 0;
|
|
4
|
+
const nostrUtils_js_1 = require("./../utils/nostrUtils.js");
|
|
4
5
|
const utils_js_1 = require("./../utils/utils.js");
|
|
5
|
-
const index_js_1 = require("./../utils/index.js");
|
|
6
6
|
const identifyEvent_js_1 = require("./../identify/identifyEvent.js");
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
|
|
7
|
+
const getSpasmId_1 = require("./../id/getSpasmId");
|
|
8
|
+
const nostr_tools_1 = require("nostr-tools");
|
|
9
|
+
// const latestSpasmVersion = "2.0.0"
|
|
10
|
+
// Spasm V2
|
|
11
|
+
const convertToSpasm = (unknownEvent, version = "2.0.0", spasmIdVersions = ["01"]) => {
|
|
12
|
+
if (version === "2.0.0") {
|
|
13
|
+
const standardizedEventV2 = (0, exports.standardizeEventV2)(unknownEvent, version);
|
|
14
|
+
if (standardizedEventV2) {
|
|
15
|
+
const spasmEventV2 = (0, exports.assignSpasmId)(standardizedEventV2, spasmIdVersions);
|
|
16
|
+
return spasmEventV2;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return null;
|
|
20
|
+
};
|
|
21
|
+
exports.convertToSpasm = convertToSpasm;
|
|
22
|
+
const assignSpasmId = (spasmEventV2, spasmIdVersions = ["01"]) => {
|
|
23
|
+
if (!(0, utils_js_1.isObjectWithValues)(spasmEventV2))
|
|
24
|
+
return null;
|
|
25
|
+
spasmIdVersions.forEach(spasmIdVersion => {
|
|
26
|
+
const spasmId = (0, getSpasmId_1.getSpasmId)(spasmEventV2, spasmIdVersion);
|
|
27
|
+
if (spasmId && typeof (spasmId) === "string") {
|
|
28
|
+
// Create ids if it's null or undefined
|
|
29
|
+
spasmEventV2.ids ??= [];
|
|
30
|
+
// Prepend the new Spasm ID to an array of other IDs
|
|
31
|
+
spasmEventV2.ids.unshift({
|
|
32
|
+
value: spasmId,
|
|
33
|
+
format: {
|
|
34
|
+
name: "spasmid",
|
|
35
|
+
version: "01"
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
return spasmEventV2;
|
|
41
|
+
};
|
|
42
|
+
exports.assignSpasmId = assignSpasmId;
|
|
43
|
+
const standardizeEventV2 = (unknownEvent, version = "2.0.0", info) => {
|
|
44
|
+
if (!(0, utils_js_1.isObjectWithValues)(unknownEvent))
|
|
10
45
|
return null;
|
|
46
|
+
let standardizedEvent = {
|
|
47
|
+
type: "SpasmEventV2"
|
|
48
|
+
};
|
|
49
|
+
// TODO convert Spasm events V2
|
|
50
|
+
// SpasmEventV2, SpasmBodyV2, SpasmEnvelopeV2,
|
|
51
|
+
// SpasmEnvelopeWithTreeV2, SpasmEventDatabaseV2
|
|
52
|
+
if ('type' in unknownEvent &&
|
|
53
|
+
typeof (unknownEvent.type) === "string") {
|
|
54
|
+
if (unknownEvent.type === "SpasmEventV2") {
|
|
55
|
+
// standardizedEvent =
|
|
56
|
+
// standardizeSpasmEventV2(
|
|
57
|
+
// unknownEvent
|
|
58
|
+
// )
|
|
59
|
+
return unknownEvent;
|
|
60
|
+
}
|
|
61
|
+
else if (unknownEvent.type === "SpasmEventBodyV2") {
|
|
62
|
+
// standardizedEvent =
|
|
63
|
+
// standardizeSpasmEventBodyV2(
|
|
64
|
+
// unknownEvent
|
|
65
|
+
// )
|
|
66
|
+
}
|
|
67
|
+
else if (unknownEvent.type === "SpasmEventEnvelopeV2") {
|
|
68
|
+
// standardizedEvent =
|
|
69
|
+
// standardizeSpasmEventEnvelopeV2(
|
|
70
|
+
// unknownEvent
|
|
71
|
+
// )
|
|
72
|
+
}
|
|
73
|
+
else if (unknownEvent.type === "SpasmEventEnvelopeWithTreeV2") {
|
|
74
|
+
// standardizedEvent =
|
|
75
|
+
// standardizeSpasmEventEnvelopeWithTreeV2(
|
|
76
|
+
// unknownEvent
|
|
77
|
+
// )
|
|
78
|
+
}
|
|
79
|
+
else if (unknownEvent.type === "SpasmEventDatabaseV2") {
|
|
80
|
+
// standardizedEvent =
|
|
81
|
+
// standardizeSpasmEventV2(
|
|
82
|
+
// unknownEvent
|
|
83
|
+
// )
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
// If unknown event is not any of V2,
|
|
87
|
+
// then proceed with SpasmEventV0 (Post)
|
|
88
|
+
// and UnknownEventV1 like DpmEvent, NostrSpasmEvent, etc.
|
|
89
|
+
unknownEvent = unknownEvent;
|
|
11
90
|
// Info about post/event might be provided.
|
|
12
91
|
// If not, then we should identify an event.
|
|
13
92
|
if (!info) {
|
|
14
|
-
info = (0, identifyEvent_js_1.identifyPostOrEvent)(
|
|
93
|
+
info = (0, identifyEvent_js_1.identifyPostOrEvent)(unknownEvent);
|
|
15
94
|
}
|
|
16
95
|
if (!info || !info.webType)
|
|
17
96
|
return null;
|
|
18
|
-
let standardizedEvent = {};
|
|
19
97
|
// DmpEvent
|
|
20
98
|
// DMP event without signature
|
|
21
99
|
if (info.eventInfo &&
|
|
22
100
|
info.eventInfo.type === "DmpEvent" &&
|
|
23
101
|
info.eventIsSealed === false) {
|
|
24
|
-
|
|
102
|
+
if (version === "2.0.0") {
|
|
103
|
+
standardizedEvent = (0, exports.standardizeDmpEventV2)(unknownEvent);
|
|
104
|
+
}
|
|
25
105
|
}
|
|
26
106
|
// DmpEventSignedClosed
|
|
27
107
|
// DMP event with signature
|
|
28
108
|
if (info.eventInfo &&
|
|
29
109
|
info.eventInfo.type === "DmpEventSignedClosed" &&
|
|
30
110
|
info.eventIsSealed === false) {
|
|
31
|
-
|
|
111
|
+
if (version === "2.0.0") {
|
|
112
|
+
standardizedEvent = (0, exports.standardizeDmpEventSignedClosedV2)(unknownEvent);
|
|
113
|
+
}
|
|
32
114
|
}
|
|
33
115
|
// DmpEventSignedOpened
|
|
34
116
|
// DMP event with signature after the signed string
|
|
@@ -36,105 +118,134 @@ const standardizePostOrEvent = (unknownPostOrEvent, info) => {
|
|
|
36
118
|
if (info.eventInfo &&
|
|
37
119
|
info.eventInfo.type === "DmpEventSignedOpened" &&
|
|
38
120
|
info.eventIsSealed === false) {
|
|
39
|
-
standardizedEvent = (0, exports.
|
|
121
|
+
standardizedEvent = (0, exports.standardizeDmpEventSignedOpenedV2)(unknownEvent);
|
|
40
122
|
}
|
|
41
123
|
// NostrEvent
|
|
42
124
|
// Nostr event without signature
|
|
43
125
|
if (info.eventInfo &&
|
|
44
126
|
info.eventInfo.type === "NostrEvent" &&
|
|
45
127
|
info.eventIsSealed === false) {
|
|
46
|
-
standardizedEvent = (0, exports.
|
|
128
|
+
standardizedEvent = (0, exports.standardizeNostrEventV2)(unknownEvent);
|
|
47
129
|
}
|
|
48
130
|
// NostrSpasmEvent
|
|
49
131
|
// Nostr event without signature, with extra Spasm fields
|
|
50
132
|
if (info.eventInfo &&
|
|
51
133
|
info.eventInfo.type === "NostrSpasmEvent" &&
|
|
52
134
|
info.eventIsSealed === false) {
|
|
53
|
-
standardizedEvent = (0, exports.
|
|
135
|
+
standardizedEvent = (0, exports.standardizeNostrSpasmEventV2)(unknownEvent);
|
|
54
136
|
}
|
|
55
137
|
// NostrEventSignedOpened
|
|
56
138
|
// Nostr event with signature, without extra Spasm fields
|
|
57
139
|
if (info.eventInfo &&
|
|
58
140
|
info.eventInfo.type === "NostrEventSignedOpened" &&
|
|
59
141
|
info.eventIsSealed === false) {
|
|
60
|
-
standardizedEvent = (0, exports.
|
|
142
|
+
standardizedEvent = (0, exports.standardizeNostrEventSignedOpenedV2)(unknownEvent);
|
|
61
143
|
}
|
|
62
144
|
// NostrSpasmEventSignedOpened
|
|
63
145
|
// Nostr event with signature and extra Spasm fields
|
|
64
146
|
if (info.eventInfo &&
|
|
65
147
|
info.eventInfo.type === "NostrSpasmEventSignedOpened" &&
|
|
66
148
|
info.eventIsSealed === false) {
|
|
67
|
-
standardizedEvent = (0, exports.
|
|
149
|
+
standardizedEvent = (0, exports.standardizeNostrSpasmEventSignedOpenedV2)(unknownEvent);
|
|
68
150
|
}
|
|
69
|
-
//
|
|
151
|
+
// SpasmEventV0 with sealed DMP event with signature
|
|
70
152
|
// (received e.g. via SPASM module)
|
|
71
153
|
if (info.eventInfo &&
|
|
72
154
|
info.eventInfo.type === "DmpEventSignedClosed" &&
|
|
73
155
|
info.eventIsSealed === true) {
|
|
74
|
-
standardizedEvent = (0, exports.
|
|
156
|
+
standardizedEvent = (0, exports.standardizeSpasmDmpEventSignedClosedV0_V2)(unknownEvent);
|
|
75
157
|
}
|
|
76
|
-
//
|
|
158
|
+
// SpasmEventV0 with sealed Nostr event with signature
|
|
77
159
|
// (received e.g. via SPASM module)
|
|
78
160
|
if (info.eventInfo &&
|
|
79
161
|
info.eventInfo.type === "NostrEventSignedOpened" &&
|
|
80
162
|
info.eventIsSealed === true) {
|
|
81
|
-
standardizedEvent = (0, exports.
|
|
163
|
+
standardizedEvent = (0, exports.standardizeSpasmNostrEventSignedOpenedV0_V2)(unknownEvent);
|
|
82
164
|
}
|
|
83
|
-
//
|
|
165
|
+
// SpasmEventV0 with sealed Nostr Spasm event with signature
|
|
84
166
|
// (received e.g. via SPASM module)
|
|
85
167
|
if (info.eventInfo &&
|
|
86
168
|
info.eventInfo.type === "NostrSpasmEventSignedOpened" &&
|
|
87
169
|
info.eventIsSealed === true) {
|
|
88
|
-
standardizedEvent = (0, exports.
|
|
170
|
+
standardizedEvent = (0, exports.standardizeSpasmNostrSpasmEventSignedOpenedV0_V2)(unknownEvent);
|
|
89
171
|
}
|
|
90
|
-
//
|
|
172
|
+
// SpasmEventV0 with RSS item without signature
|
|
91
173
|
// (received e.g. via RSS module)
|
|
92
174
|
if (!info.eventInfo &&
|
|
93
175
|
info.webType === "web2" &&
|
|
94
176
|
info.eventIsSealed === false &&
|
|
95
177
|
info.eventIsSealedUnderKeyName === false) {
|
|
96
|
-
standardizedEvent = (0, exports.
|
|
178
|
+
standardizedEvent = (0, exports.standardizeSpasmWithRssItemV0_V2)(unknownEvent);
|
|
97
179
|
if (standardizedEvent) {
|
|
98
|
-
standardizedEvent = (0, exports.
|
|
180
|
+
standardizedEvent = (0, exports.addFieldsFromEnvelopeSpasmEventV0_V2)(unknownEvent, standardizedEvent);
|
|
99
181
|
}
|
|
100
182
|
}
|
|
101
183
|
if (info.eventInfo &&
|
|
102
184
|
info.eventIsSealed === true &&
|
|
103
185
|
standardizedEvent) {
|
|
104
|
-
standardizedEvent = (0, exports.
|
|
186
|
+
standardizedEvent = (0, exports.addFieldsFromEnvelopeSpasmEventV0_V2)(unknownEvent, standardizedEvent);
|
|
105
187
|
}
|
|
106
188
|
return standardizedEvent;
|
|
107
189
|
};
|
|
108
|
-
exports.
|
|
109
|
-
|
|
110
|
-
const standardizeDmpEvent = (event) => {
|
|
190
|
+
exports.standardizeEventV2 = standardizeEventV2;
|
|
191
|
+
const standardizeDmpEventV2 = (event) => {
|
|
111
192
|
if (!(0, utils_js_1.isObjectWithValues)(event))
|
|
112
193
|
return null;
|
|
113
194
|
if (!(0, identifyEvent_js_1.isDmpEvent)(event))
|
|
114
195
|
return null;
|
|
115
|
-
const
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
196
|
+
const protocolVersion = (0, utils_js_1.extractVersion)(event.version);
|
|
197
|
+
const spasmEventV2 = {
|
|
198
|
+
type: "SpasmEventV2",
|
|
199
|
+
// action: event.action,
|
|
200
|
+
// title: event.title,
|
|
201
|
+
// content: event.text,
|
|
202
|
+
// timestamp: toBeTimestamp(event.time),
|
|
203
|
+
// license: event.license,
|
|
204
|
+
siblings: [
|
|
205
|
+
{
|
|
206
|
+
type: "SiblingDmpV2",
|
|
207
|
+
protocol: {
|
|
208
|
+
name: "dmp",
|
|
209
|
+
version: protocolVersion
|
|
210
|
+
},
|
|
211
|
+
signedString: JSON.stringify(event),
|
|
212
|
+
}
|
|
213
|
+
]
|
|
132
214
|
};
|
|
133
|
-
|
|
215
|
+
if (event.action) {
|
|
216
|
+
spasmEventV2.action = event.action;
|
|
217
|
+
}
|
|
218
|
+
if (event.title) {
|
|
219
|
+
spasmEventV2.title = event.title;
|
|
220
|
+
}
|
|
221
|
+
if (event.text) {
|
|
222
|
+
spasmEventV2.content = event.text;
|
|
223
|
+
}
|
|
224
|
+
if (event.license) {
|
|
225
|
+
spasmEventV2.license = event.license;
|
|
226
|
+
}
|
|
227
|
+
if (event.time) {
|
|
228
|
+
spasmEventV2.timestamp = (0, utils_js_1.toBeTimestamp)(event.time);
|
|
229
|
+
}
|
|
230
|
+
if (event.target) {
|
|
231
|
+
spasmEventV2.parent = {
|
|
232
|
+
ids: [
|
|
233
|
+
{
|
|
234
|
+
value: event.target,
|
|
235
|
+
// Create a new format field only if a
|
|
236
|
+
// format can be determined from a string.
|
|
237
|
+
...((0, utils_js_1.getFormatFromId)(event.target)
|
|
238
|
+
? { format: (0, utils_js_1.getFormatFromId)(event.target) }
|
|
239
|
+
: {})
|
|
240
|
+
}
|
|
241
|
+
]
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
return spasmEventV2;
|
|
134
245
|
};
|
|
135
|
-
exports.
|
|
136
|
-
//
|
|
137
|
-
const
|
|
246
|
+
exports.standardizeDmpEventV2 = standardizeDmpEventV2;
|
|
247
|
+
// standardizeDmpEventSignedClosedV2
|
|
248
|
+
const standardizeDmpEventSignedClosedV2 = (event) => {
|
|
138
249
|
if (!(0, utils_js_1.isObjectWithValues)(event))
|
|
139
250
|
return null;
|
|
140
251
|
if (!(0, identifyEvent_js_1.isDmpEventSignedClosed)(event))
|
|
@@ -144,27 +255,99 @@ const standardizeDmpEventSignedClosed = (event) => {
|
|
|
144
255
|
typeof (event.signature) !== "string" ||
|
|
145
256
|
typeof (event.signer) !== "string")
|
|
146
257
|
return null;
|
|
258
|
+
const isEthereumSignatureValid = (0, utils_js_1.verifyEthereumSignature)(event.signedString, event.signature, event.signer);
|
|
259
|
+
if (!isEthereumSignatureValid)
|
|
260
|
+
return null;
|
|
147
261
|
const dmpEvent = JSON.parse(event.signedString);
|
|
148
|
-
const
|
|
149
|
-
if (!
|
|
150
|
-
return null;
|
|
151
|
-
const
|
|
152
|
-
...
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
262
|
+
const dmpEventConvertedToSpasmV2 = (0, exports.standardizeDmpEventV2)(dmpEvent);
|
|
263
|
+
if (!dmpEventConvertedToSpasmV2)
|
|
264
|
+
return null;
|
|
265
|
+
const dmpEventSignedClosedConvertedToSpasmV2 = {
|
|
266
|
+
...dmpEventConvertedToSpasmV2,
|
|
267
|
+
authors: [
|
|
268
|
+
{
|
|
269
|
+
addresses: [
|
|
270
|
+
{
|
|
271
|
+
value: event.signer,
|
|
272
|
+
// Create a new format field only if a
|
|
273
|
+
// format can be determined from a string.
|
|
274
|
+
...((0, utils_js_1.getFormatFromAddress)(event.signer)
|
|
275
|
+
? { format: (0, utils_js_1.getFormatFromAddress)(event.signer) }
|
|
276
|
+
: {})
|
|
277
|
+
// TODO add a function to verify signatures
|
|
278
|
+
// verified: true
|
|
279
|
+
}
|
|
280
|
+
]
|
|
281
|
+
}
|
|
282
|
+
],
|
|
283
|
+
ids: [
|
|
284
|
+
{
|
|
285
|
+
value: event.signature,
|
|
286
|
+
// Create a new format field only if a
|
|
287
|
+
// format can be determined from a string.
|
|
288
|
+
...((0, utils_js_1.getFormatFromId)(event.signature)
|
|
289
|
+
? {
|
|
290
|
+
format: (0, utils_js_1.getFormatFromId)(event.signature),
|
|
291
|
+
}
|
|
292
|
+
: {})
|
|
293
|
+
},
|
|
294
|
+
],
|
|
295
|
+
signatures: [
|
|
296
|
+
{
|
|
297
|
+
value: event.signature,
|
|
298
|
+
pubkey: event.signer,
|
|
299
|
+
// Create a new format field only if a
|
|
300
|
+
// format can be determined from a string.
|
|
301
|
+
...((0, utils_js_1.getFormatFromSignature)(event.signature)
|
|
302
|
+
? {
|
|
303
|
+
format: (0, utils_js_1.getFormatFromSignature)(event.signature),
|
|
304
|
+
}
|
|
305
|
+
: {})
|
|
306
|
+
}
|
|
307
|
+
]
|
|
160
308
|
};
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
309
|
+
const spasmEventV2 = dmpEventSignedClosedConvertedToSpasmV2;
|
|
310
|
+
// Add 'verified' flag to the address that was verified
|
|
311
|
+
(0, utils_js_1.markSpasmEventAddressAsVerified)(spasmEventV2, event.signer);
|
|
312
|
+
if (spasmEventV2) {
|
|
313
|
+
// Create siblings if it's null or undefined
|
|
314
|
+
spasmEventV2.siblings ??= [];
|
|
315
|
+
spasmEventV2.siblings[0] ??=
|
|
316
|
+
{ type: "SiblingDmpSignedV2" };
|
|
317
|
+
spasmEventV2.siblings[0] =
|
|
318
|
+
spasmEventV2.siblings[0];
|
|
319
|
+
spasmEventV2.siblings[0].type = "SiblingDmpSignedV2";
|
|
320
|
+
spasmEventV2.siblings[0].signatures = [
|
|
321
|
+
{
|
|
322
|
+
value: event.signature,
|
|
323
|
+
pubkey: event.signer,
|
|
324
|
+
// Create a new format field only if a
|
|
325
|
+
// format can be determined from a string.
|
|
326
|
+
...((0, utils_js_1.getFormatFromSignature)(event.signature)
|
|
327
|
+
? {
|
|
328
|
+
format: (0, utils_js_1.getFormatFromSignature)(event.signature),
|
|
329
|
+
}
|
|
330
|
+
: {})
|
|
331
|
+
}
|
|
332
|
+
];
|
|
333
|
+
spasmEventV2.siblings[0].ids = [
|
|
334
|
+
{
|
|
335
|
+
value: event.signature,
|
|
336
|
+
// Create a new format field only if a
|
|
337
|
+
// format can be determined from a string.
|
|
338
|
+
...((0, utils_js_1.getFormatFromId)(event.signature)
|
|
339
|
+
? {
|
|
340
|
+
format: (0, utils_js_1.getFormatFromId)(event.signature),
|
|
341
|
+
}
|
|
342
|
+
: {})
|
|
343
|
+
}
|
|
344
|
+
];
|
|
345
|
+
}
|
|
346
|
+
return spasmEventV2;
|
|
164
347
|
};
|
|
165
|
-
exports.
|
|
166
|
-
//
|
|
167
|
-
const
|
|
348
|
+
exports.standardizeDmpEventSignedClosedV2 = standardizeDmpEventSignedClosedV2;
|
|
349
|
+
// standardizeDmpEventSignedOpenedV2
|
|
350
|
+
const standardizeDmpEventSignedOpenedV2 = (event) => {
|
|
168
351
|
if (!(0, utils_js_1.isObjectWithValues)(event))
|
|
169
352
|
return null;
|
|
170
353
|
if (!(0, identifyEvent_js_1.isDmpEventSignedOpened)(event))
|
|
@@ -179,73 +362,188 @@ const standardizeDmpEventSignedOpened = (event) => {
|
|
|
179
362
|
signature: event.signature,
|
|
180
363
|
signer: event.signer
|
|
181
364
|
};
|
|
182
|
-
const
|
|
183
|
-
if (!
|
|
365
|
+
const DmpEventSignedOpenedConvertedToSpasmV2 = (0, exports.standardizeDmpEventSignedClosedV2)(dmpEventSignedClosed);
|
|
366
|
+
if (!DmpEventSignedOpenedConvertedToSpasmV2)
|
|
184
367
|
return null;
|
|
185
|
-
|
|
186
|
-
.meta.convertedFrom = "DmpEventSignedOpened";
|
|
187
|
-
return DmpEventSignedOpenedConvertedToSpasm;
|
|
368
|
+
return DmpEventSignedOpenedConvertedToSpasmV2;
|
|
188
369
|
};
|
|
189
|
-
exports.
|
|
190
|
-
|
|
191
|
-
const standardizeNostrEvent = (event) => {
|
|
370
|
+
exports.standardizeDmpEventSignedOpenedV2 = standardizeDmpEventSignedOpenedV2;
|
|
371
|
+
const standardizeNostrEventV2 = (event) => {
|
|
192
372
|
if (!(0, utils_js_1.isObjectWithValues)(event))
|
|
193
373
|
return null;
|
|
194
374
|
if (!(0, identifyEvent_js_1.isNostrEvent)(event))
|
|
195
375
|
return null;
|
|
196
|
-
const
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
hasExtraSpasmFields: false,
|
|
200
|
-
convertedFrom: "NostrEvent",
|
|
201
|
-
},
|
|
202
|
-
spasmVersion: latestSpasmVersion,
|
|
203
|
-
eventId: event.id,
|
|
376
|
+
const spasmEventV2 = {
|
|
377
|
+
type: "SpasmEventV2",
|
|
378
|
+
// action
|
|
204
379
|
content: event.content,
|
|
205
380
|
timestamp: event.created_at,
|
|
206
|
-
|
|
381
|
+
authors: [
|
|
382
|
+
{
|
|
383
|
+
addresses: [
|
|
384
|
+
{
|
|
385
|
+
value: (0, nostrUtils_js_1.toBeHex)(event.pubkey),
|
|
386
|
+
format: {
|
|
387
|
+
name: "nostr-hex"
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
]
|
|
391
|
+
}
|
|
392
|
+
],
|
|
393
|
+
siblings: [
|
|
394
|
+
{
|
|
395
|
+
type: "SiblingNostrV2",
|
|
396
|
+
originalObject: event,
|
|
397
|
+
protocol: {
|
|
398
|
+
name: "nostr",
|
|
399
|
+
// hasExtraSpasmFields: false
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
]
|
|
207
403
|
};
|
|
404
|
+
if (event.id && typeof (event.id) === "string") {
|
|
405
|
+
spasmEventV2.ids = [
|
|
406
|
+
{
|
|
407
|
+
value: (0, nostrUtils_js_1.toBeHex)(event.id),
|
|
408
|
+
format: {
|
|
409
|
+
name: "nostr-hex"
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
],
|
|
413
|
+
// Create siblings if it's null or undefined
|
|
414
|
+
spasmEventV2.siblings ??= [];
|
|
415
|
+
spasmEventV2.siblings[0] ??= {
|
|
416
|
+
type: "SiblingNostrV2",
|
|
417
|
+
protocol: {
|
|
418
|
+
name: "nostr",
|
|
419
|
+
}
|
|
420
|
+
};
|
|
421
|
+
spasmEventV2.siblings[0] =
|
|
422
|
+
spasmEventV2.siblings[0];
|
|
423
|
+
spasmEventV2.siblings[0].ids = [
|
|
424
|
+
{
|
|
425
|
+
value: (0, nostrUtils_js_1.toBeHex)(event.id),
|
|
426
|
+
format: {
|
|
427
|
+
name: "nostr-hex"
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
];
|
|
431
|
+
}
|
|
208
432
|
let referencedEvents = [];
|
|
433
|
+
let mentionedAuthors = [];
|
|
209
434
|
if (event.tags && Array.isArray(event.tags)) {
|
|
210
435
|
event.tags.forEach(function (tag) {
|
|
211
|
-
|
|
212
|
-
|
|
436
|
+
// References
|
|
437
|
+
// ["e", <event-id>, <relay-url>, <marker>]
|
|
438
|
+
if (Array.isArray(tag) && tag[0] === "e" &&
|
|
439
|
+
tag[1] && typeof (tag[1]) === 'string') {
|
|
440
|
+
// <event-id>
|
|
441
|
+
const referencedEvent = {
|
|
442
|
+
ids: [
|
|
443
|
+
{
|
|
444
|
+
value: (0, nostrUtils_js_1.toBeHex)(tag[1]),
|
|
445
|
+
// Create a new format field only if a
|
|
446
|
+
// format can be determined from a string.
|
|
447
|
+
...((0, utils_js_1.getFormatFromId)(tag[1])
|
|
448
|
+
? { format: (0, utils_js_1.getFormatFromId)(tag[1]) }
|
|
449
|
+
: {})
|
|
450
|
+
}
|
|
451
|
+
]
|
|
452
|
+
};
|
|
453
|
+
// <relay-url>
|
|
454
|
+
if (tag[2] && typeof (tag[2]) === "string") {
|
|
455
|
+
referencedEvent.ids[0].hosts = [
|
|
456
|
+
{ value: tag[2] }
|
|
457
|
+
];
|
|
458
|
+
}
|
|
459
|
+
// <marker>
|
|
460
|
+
if (tag[3] && typeof (tag[3]) === 'string') {
|
|
461
|
+
referencedEvent.marker = tag[3];
|
|
462
|
+
if (tag[3] === 'reply') {
|
|
463
|
+
spasmEventV2.action = 'reply';
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
referencedEvents.push(referencedEvent);
|
|
467
|
+
}
|
|
468
|
+
// Mentions
|
|
469
|
+
// ["p", <event-id>, <relay-url>, <marker>]
|
|
470
|
+
if (Array.isArray(tag) && tag[0] === "p" &&
|
|
471
|
+
tag[1] && typeof (tag[1]) === 'string') {
|
|
472
|
+
// <pubkey>
|
|
473
|
+
const mentionedAuthor = {
|
|
474
|
+
addresses: [
|
|
475
|
+
{
|
|
476
|
+
value: (0, nostrUtils_js_1.toBeHex)(tag[1]),
|
|
477
|
+
// Create a new format field only if a
|
|
478
|
+
// format can be determined from a string.
|
|
479
|
+
...((0, utils_js_1.getFormatFromAddress)(tag[1])
|
|
480
|
+
? { format: (0, utils_js_1.getFormatFromAddress)(tag[1]) }
|
|
481
|
+
: {})
|
|
482
|
+
}
|
|
483
|
+
]
|
|
484
|
+
};
|
|
485
|
+
// <relay-url>
|
|
486
|
+
if (tag[2] && typeof (tag[2]) === "string") {
|
|
487
|
+
// Create addresses if it's null or undefined
|
|
488
|
+
mentionedAuthor.addresses ??= [];
|
|
489
|
+
mentionedAuthor.addresses[0].hosts = [
|
|
490
|
+
{ value: tag[2] }
|
|
491
|
+
];
|
|
492
|
+
}
|
|
493
|
+
// <marker>
|
|
494
|
+
if (tag[3] && typeof (tag[3]) === 'string') {
|
|
495
|
+
mentionedAuthor.marker = tag[3];
|
|
496
|
+
}
|
|
497
|
+
mentionedAuthors.push(mentionedAuthor);
|
|
213
498
|
}
|
|
214
499
|
});
|
|
215
500
|
}
|
|
501
|
+
if (mentionedAuthors &&
|
|
502
|
+
mentionedAuthors[0] &&
|
|
503
|
+
(0, utils_js_1.hasValue)(mentionedAuthors)) {
|
|
504
|
+
// spasmEventV2.mentions ??= [];
|
|
505
|
+
spasmEventV2.mentions = mentionedAuthors;
|
|
506
|
+
}
|
|
216
507
|
if (referencedEvents && referencedEvents[0]) {
|
|
217
|
-
|
|
508
|
+
// The first reference is always assigned as a parent
|
|
509
|
+
// while all other references are assigned as references.
|
|
510
|
+
spasmEventV2.parent = referencedEvents[0];
|
|
511
|
+
const restOfReferencedEvents = referencedEvents.slice(1);
|
|
512
|
+
if (restOfReferencedEvents &&
|
|
513
|
+
(0, utils_js_1.hasValue)(restOfReferencedEvents) &&
|
|
514
|
+
restOfReferencedEvents[0]) {
|
|
515
|
+
// TODO write tests for multiple references
|
|
516
|
+
// spasmEventV2.references ??= [];
|
|
517
|
+
spasmEventV2.references = restOfReferencedEvents;
|
|
518
|
+
}
|
|
218
519
|
}
|
|
219
|
-
|
|
220
|
-
if (!spasmEvent.action && event.kind === 1) {
|
|
520
|
+
if (!spasmEventV2.action && event.kind === 1) {
|
|
221
521
|
// Kind 1 event without referenced events is usually "post"
|
|
222
|
-
if (!event.tags || !
|
|
223
|
-
|
|
522
|
+
if (!event.tags || !(0, utils_js_1.hasValue)(spasmEventV2.parent)) {
|
|
523
|
+
spasmEventV2.action = "post";
|
|
224
524
|
// It's usually a reply if any other event is referenced
|
|
225
525
|
}
|
|
226
|
-
else if (
|
|
227
|
-
|
|
526
|
+
else if ((0, utils_js_1.hasValue)(spasmEventV2.parent)) {
|
|
527
|
+
spasmEventV2.action = "reply";
|
|
228
528
|
}
|
|
229
529
|
}
|
|
230
|
-
|
|
231
|
-
spasmEvent.originalEventString = JSON.stringify(event);
|
|
232
|
-
return spasmEvent;
|
|
530
|
+
return spasmEventV2;
|
|
233
531
|
};
|
|
234
|
-
exports.
|
|
235
|
-
//
|
|
236
|
-
const
|
|
532
|
+
exports.standardizeNostrEventV2 = standardizeNostrEventV2;
|
|
533
|
+
// standardizeNostrSpasmEventV2
|
|
534
|
+
const standardizeNostrSpasmEventV2 = (event) => {
|
|
237
535
|
if (!(0, utils_js_1.isObjectWithValues)(event))
|
|
238
536
|
return null;
|
|
239
537
|
if (!(0, identifyEvent_js_1.isNostrSpasmEvent)(event))
|
|
240
538
|
return null;
|
|
241
|
-
const
|
|
242
|
-
if (!
|
|
539
|
+
const spasmEventV2 = (0, exports.standardizeNostrEventV2)(event);
|
|
540
|
+
if (!spasmEventV2)
|
|
243
541
|
return null;
|
|
244
542
|
let extraFieldsSpasmVersion = (0, utils_js_1.getNostrSpasmVersion)(event);
|
|
245
543
|
let spasmTarget = "";
|
|
246
|
-
let spasmAction =
|
|
247
|
-
let spasmTitle =
|
|
248
|
-
let license =
|
|
544
|
+
let spasmAction = null;
|
|
545
|
+
let spasmTitle = null;
|
|
546
|
+
let license = null;
|
|
249
547
|
if (event.tags &&
|
|
250
548
|
Array.isArray(event.tags)) {
|
|
251
549
|
event.tags.forEach(function (tag) {
|
|
@@ -266,240 +564,449 @@ const standardizeNostrSpasmEvent = (event) => {
|
|
|
266
564
|
}
|
|
267
565
|
});
|
|
268
566
|
}
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
spasmEvent.meta.convertedFrom = "NostrSpasmEvent";
|
|
272
|
-
if (spasmTarget || spasmAction ||
|
|
273
|
-
spasmTitle || extraFieldsSpasmVersion) {
|
|
274
|
-
spasmEvent.meta.hasExtraSpasmFields = true;
|
|
275
|
-
}
|
|
276
|
-
if (extraFieldsSpasmVersion) {
|
|
277
|
-
spasmEvent.meta
|
|
278
|
-
.extraSpasmFieldsVersion = extraFieldsSpasmVersion;
|
|
279
|
-
}
|
|
280
|
-
if (license) {
|
|
281
|
-
spasmEvent.meta.license = license;
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
if (spasmTarget) {
|
|
285
|
-
spasmEvent.parentEvent = spasmTarget;
|
|
567
|
+
if (license) {
|
|
568
|
+
spasmEventV2.license = license;
|
|
286
569
|
}
|
|
287
570
|
if (spasmAction) {
|
|
288
|
-
|
|
571
|
+
spasmEventV2.action = spasmAction;
|
|
289
572
|
}
|
|
290
573
|
if (spasmTitle) {
|
|
291
|
-
|
|
574
|
+
spasmEventV2.title = spasmTitle;
|
|
575
|
+
}
|
|
576
|
+
if (spasmTarget && typeof (spasmTarget) === "string") {
|
|
577
|
+
// Create parent if it's null or undefined
|
|
578
|
+
spasmEventV2.parent ??= { ids: [] };
|
|
579
|
+
const parentId = {
|
|
580
|
+
value: spasmTarget,
|
|
581
|
+
format: (0, utils_js_1.getFormatFromId)(spasmTarget)
|
|
582
|
+
};
|
|
583
|
+
spasmEventV2.parent.ids.push(parentId);
|
|
584
|
+
}
|
|
585
|
+
if (spasmTarget || spasmAction ||
|
|
586
|
+
spasmTitle || extraFieldsSpasmVersion) {
|
|
587
|
+
// Create siblings if it's null or undefined
|
|
588
|
+
spasmEventV2.siblings ??= [];
|
|
589
|
+
spasmEventV2.siblings[0] ??=
|
|
590
|
+
{ type: "SiblingNostrSpasmV2" };
|
|
591
|
+
spasmEventV2.siblings[0] =
|
|
592
|
+
spasmEventV2.siblings[0];
|
|
593
|
+
spasmEventV2.siblings[0].type = "SiblingNostrSpasmV2";
|
|
594
|
+
spasmEventV2.siblings[0].protocol.hasExtraSpasmFields = true;
|
|
595
|
+
if (extraFieldsSpasmVersion) {
|
|
596
|
+
spasmEventV2.siblings[0]
|
|
597
|
+
.protocol.extraSpasmFieldsVersion = extraFieldsSpasmVersion;
|
|
598
|
+
}
|
|
292
599
|
}
|
|
293
|
-
return
|
|
600
|
+
return spasmEventV2;
|
|
294
601
|
};
|
|
295
|
-
exports.
|
|
296
|
-
//
|
|
297
|
-
const
|
|
602
|
+
exports.standardizeNostrSpasmEventV2 = standardizeNostrSpasmEventV2;
|
|
603
|
+
// standardizeNostrEventSignedOpenedV2
|
|
604
|
+
const standardizeNostrEventSignedOpenedV2 = (event) => {
|
|
298
605
|
if (!(0, utils_js_1.isObjectWithValues)(event))
|
|
299
606
|
return null;
|
|
300
607
|
if (!(0, identifyEvent_js_1.isNostrEventSignedOpened)(event))
|
|
301
608
|
return null;
|
|
302
|
-
const
|
|
303
|
-
if (!
|
|
609
|
+
const spasmEventV2 = (0, exports.standardizeNostrEventV2)(event);
|
|
610
|
+
if (!spasmEventV2)
|
|
304
611
|
return null;
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
612
|
+
/**
|
|
613
|
+
* nostr-tools v2 creates a `[Symbol("verified")]: true` on
|
|
614
|
+
* the Nostr object during verification process, which messes
|
|
615
|
+
* up tests, so the deep copy of the object is verified using
|
|
616
|
+
* JSON stringify/parse to make sure that the original Nostr
|
|
617
|
+
* event stays untouched.
|
|
618
|
+
*/
|
|
619
|
+
const eventCopy = JSON.parse(JSON.stringify(event));
|
|
620
|
+
const isNostrSignatureValid = (0, nostr_tools_1.verifyEvent)(eventCopy);
|
|
621
|
+
if (!isNostrSignatureValid)
|
|
622
|
+
return null;
|
|
623
|
+
if (event.sig && typeof (event.sig) &&
|
|
624
|
+
event.pubkey && typeof (event.pubkey) === "string") {
|
|
625
|
+
// Create signatures if it's null or undefined
|
|
626
|
+
spasmEventV2.signatures ??= [];
|
|
627
|
+
spasmEventV2.signatures.push({
|
|
628
|
+
value: event.sig,
|
|
629
|
+
pubkey: event.pubkey,
|
|
630
|
+
format: { name: "nostr-sig" }
|
|
631
|
+
});
|
|
632
|
+
// Create parent if it's null or undefined
|
|
633
|
+
spasmEventV2.siblings ??= [];
|
|
634
|
+
spasmEventV2.siblings[0] ??=
|
|
635
|
+
{ type: "SiblingNostrSignedV2" };
|
|
636
|
+
spasmEventV2.siblings[0] =
|
|
637
|
+
spasmEventV2.siblings[0];
|
|
638
|
+
spasmEventV2.siblings[0].type = "SiblingNostrSignedV2";
|
|
639
|
+
spasmEventV2.siblings[0].signatures ??= [];
|
|
640
|
+
spasmEventV2.siblings[0].signatures.push({
|
|
641
|
+
value: event.sig,
|
|
642
|
+
pubkey: event.pubkey,
|
|
643
|
+
format: { name: "nostr-sig" }
|
|
644
|
+
});
|
|
645
|
+
// Add 'verified' flag to the address that was verified
|
|
646
|
+
(0, utils_js_1.markSpasmEventAddressAsVerified)(spasmEventV2, event.pubkey);
|
|
317
647
|
}
|
|
318
|
-
return
|
|
648
|
+
return spasmEventV2;
|
|
319
649
|
};
|
|
320
|
-
exports.
|
|
321
|
-
//
|
|
322
|
-
const
|
|
650
|
+
exports.standardizeNostrEventSignedOpenedV2 = standardizeNostrEventSignedOpenedV2;
|
|
651
|
+
// standardizeNostrSpasmEventSignedOpenedV2
|
|
652
|
+
const standardizeNostrSpasmEventSignedOpenedV2 = (event) => {
|
|
323
653
|
if (!(0, utils_js_1.isObjectWithValues)(event))
|
|
324
654
|
return null;
|
|
325
655
|
if (!(0, identifyEvent_js_1.isNostrSpasmEventSignedOpened)(event))
|
|
326
656
|
return null;
|
|
327
|
-
const
|
|
328
|
-
if (!
|
|
657
|
+
const spasmEventV2 = (0, exports.standardizeNostrSpasmEventV2)(event);
|
|
658
|
+
if (!spasmEventV2)
|
|
329
659
|
return null;
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
660
|
+
/**
|
|
661
|
+
* nostr-tools v2 creates a `[Symbol("verified")]: true` on
|
|
662
|
+
* the Nostr object during verification process, which messes
|
|
663
|
+
* up tests, so the deep copy of the object is verified using
|
|
664
|
+
* JSON stringify/parse to make sure that the original Nostr
|
|
665
|
+
* event stays untouched.
|
|
666
|
+
*/
|
|
667
|
+
const eventCopy = JSON.parse(JSON.stringify(event));
|
|
668
|
+
const isNostrSignatureValid = (0, nostr_tools_1.verifyEvent)(eventCopy);
|
|
669
|
+
if (!isNostrSignatureValid)
|
|
670
|
+
return null;
|
|
671
|
+
if (event.sig && typeof (event.sig) &&
|
|
672
|
+
event.pubkey && typeof (event.pubkey) === "string") {
|
|
673
|
+
// Create signatures if it's null or undefined
|
|
674
|
+
spasmEventV2.signatures ??= [];
|
|
675
|
+
spasmEventV2.signatures.push({
|
|
676
|
+
value: event.sig,
|
|
677
|
+
pubkey: event.pubkey,
|
|
678
|
+
format: { name: "nostr-sig" }
|
|
679
|
+
});
|
|
680
|
+
// Create siblings if it's null or undefined
|
|
681
|
+
spasmEventV2.siblings ??= [];
|
|
682
|
+
spasmEventV2.siblings[0] ??= {
|
|
683
|
+
type: "SiblingNostrSpasmSignedV2",
|
|
684
|
+
protocol: { name: "nostr" }
|
|
685
|
+
};
|
|
686
|
+
spasmEventV2.siblings[0] =
|
|
687
|
+
spasmEventV2.siblings[0];
|
|
688
|
+
spasmEventV2.siblings[0].type = "SiblingNostrSpasmSignedV2";
|
|
689
|
+
spasmEventV2.siblings[0].signatures ??= [];
|
|
690
|
+
spasmEventV2.siblings[0].signatures.push({
|
|
691
|
+
value: event.sig,
|
|
692
|
+
pubkey: event.pubkey,
|
|
693
|
+
format: { name: "nostr-sig" }
|
|
694
|
+
});
|
|
695
|
+
// Add 'verified' flag to the address that was verified
|
|
696
|
+
(0, utils_js_1.markSpasmEventAddressAsVerified)(spasmEventV2, event.pubkey);
|
|
333
697
|
}
|
|
334
698
|
// NostrSpasm versions prior to 2.0.0 assigned sig as event id
|
|
335
|
-
if (event.sig &&
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
699
|
+
if (event.sig && typeof (event.sig) === "string" &&
|
|
700
|
+
(0, utils_js_1.getNostrSpasmVersion)(event) === "1.0.0") {
|
|
701
|
+
// Create ids if it's null or undefined
|
|
702
|
+
spasmEventV2.ids ??= [];
|
|
703
|
+
spasmEventV2.ids.push({
|
|
704
|
+
value: event.sig,
|
|
705
|
+
format: {
|
|
706
|
+
name: "nostr-sig"
|
|
707
|
+
}
|
|
708
|
+
});
|
|
709
|
+
// Create siblings if it's null or undefined
|
|
710
|
+
spasmEventV2.siblings ??= [];
|
|
711
|
+
spasmEventV2.siblings[0] ??= {
|
|
712
|
+
type: "SiblingNostrSpasmSignedV2",
|
|
713
|
+
protocol: { name: "nostr" }
|
|
714
|
+
};
|
|
715
|
+
spasmEventV2.siblings[0] =
|
|
716
|
+
spasmEventV2.siblings[0];
|
|
717
|
+
spasmEventV2.siblings[0].type = "SiblingNostrSpasmSignedV2";
|
|
718
|
+
spasmEventV2.siblings[0].ids ??= [];
|
|
719
|
+
spasmEventV2.siblings[0].ids.push({
|
|
720
|
+
value: event.sig,
|
|
721
|
+
format: {
|
|
722
|
+
name: "nostr-sig"
|
|
723
|
+
}
|
|
724
|
+
});
|
|
343
725
|
}
|
|
344
|
-
return
|
|
726
|
+
return spasmEventV2;
|
|
345
727
|
};
|
|
346
|
-
exports.
|
|
347
|
-
//
|
|
348
|
-
const
|
|
349
|
-
if (!(0, utils_js_1.isObjectWithValues)(
|
|
728
|
+
exports.standardizeNostrSpasmEventSignedOpenedV2 = standardizeNostrSpasmEventSignedOpenedV2;
|
|
729
|
+
// standardizeSpasmDmpEventSignedClosedV0_V2
|
|
730
|
+
const standardizeSpasmDmpEventSignedClosedV0_V2 = (spasmEventV0) => {
|
|
731
|
+
if (!(0, utils_js_1.isObjectWithValues)(spasmEventV0))
|
|
350
732
|
return null;
|
|
351
|
-
if (!('signed_message' in
|
|
352
|
-
typeof (
|
|
733
|
+
if (!('signed_message' in spasmEventV0) ||
|
|
734
|
+
typeof (spasmEventV0.signed_message) !== "string") {
|
|
353
735
|
return null;
|
|
354
736
|
}
|
|
355
737
|
const dmpEvent = {
|
|
356
|
-
signedString:
|
|
738
|
+
signedString: spasmEventV0.signed_message,
|
|
357
739
|
signature: "",
|
|
358
740
|
signer: ""
|
|
359
741
|
};
|
|
360
|
-
if (
|
|
361
|
-
|
|
742
|
+
if (spasmEventV0.signature &&
|
|
743
|
+
typeof (spasmEventV0.signature) === "string") {
|
|
744
|
+
dmpEvent.signature = spasmEventV0.signature;
|
|
362
745
|
}
|
|
363
|
-
if (
|
|
364
|
-
|
|
746
|
+
if (spasmEventV0.signer &&
|
|
747
|
+
typeof (spasmEventV0.signer) === "string") {
|
|
748
|
+
dmpEvent.signer = spasmEventV0.signer;
|
|
365
749
|
}
|
|
366
|
-
const
|
|
367
|
-
return
|
|
750
|
+
const spasmEventV2 = (0, exports.standardizeDmpEventSignedClosedV2)(dmpEvent);
|
|
751
|
+
return spasmEventV2;
|
|
368
752
|
};
|
|
369
|
-
exports.
|
|
370
|
-
//
|
|
371
|
-
const
|
|
372
|
-
if (!(0, utils_js_1.isObjectWithValues)(
|
|
753
|
+
exports.standardizeSpasmDmpEventSignedClosedV0_V2 = standardizeSpasmDmpEventSignedClosedV0_V2;
|
|
754
|
+
// standardizeSpasmNostrEventSignedOpenedV0_V2
|
|
755
|
+
const standardizeSpasmNostrEventSignedOpenedV0_V2 = (spasmEventV0) => {
|
|
756
|
+
if (!(0, utils_js_1.isObjectWithValues)(spasmEventV0))
|
|
373
757
|
return null;
|
|
374
|
-
if (!('signed_message' in
|
|
375
|
-
typeof (
|
|
758
|
+
if (!('signed_message' in spasmEventV0) ||
|
|
759
|
+
typeof (spasmEventV0.signed_message) !== "string") {
|
|
376
760
|
return null;
|
|
377
761
|
}
|
|
378
762
|
// Extract the event
|
|
379
|
-
const event = (0, utils_js_1.extractSealedEvent)(
|
|
380
|
-
return (0, exports.
|
|
763
|
+
const event = (0, utils_js_1.extractSealedEvent)(spasmEventV0);
|
|
764
|
+
return (0, exports.standardizeNostrEventSignedOpenedV2)(event);
|
|
381
765
|
};
|
|
382
|
-
exports.
|
|
383
|
-
//
|
|
384
|
-
const
|
|
385
|
-
if (!(0, utils_js_1.isObjectWithValues)(
|
|
766
|
+
exports.standardizeSpasmNostrEventSignedOpenedV0_V2 = standardizeSpasmNostrEventSignedOpenedV0_V2;
|
|
767
|
+
// standardizeSpasmNostrSpasmEventSignedOpenedV0_V2
|
|
768
|
+
const standardizeSpasmNostrSpasmEventSignedOpenedV0_V2 = (spasmEventV0) => {
|
|
769
|
+
if (!(0, utils_js_1.isObjectWithValues)(spasmEventV0))
|
|
386
770
|
return null;
|
|
387
|
-
if (!('signed_message' in
|
|
388
|
-
typeof (
|
|
771
|
+
if (!('signed_message' in spasmEventV0) ||
|
|
772
|
+
typeof (spasmEventV0.signed_message) !== "string") {
|
|
389
773
|
return null;
|
|
390
774
|
}
|
|
391
775
|
// Extract the event
|
|
392
|
-
const event = (0, utils_js_1.extractSealedEvent)(
|
|
393
|
-
return (0, exports.
|
|
776
|
+
const event = (0, utils_js_1.extractSealedEvent)(spasmEventV0);
|
|
777
|
+
return (0, exports.standardizeNostrSpasmEventSignedOpenedV2)(event);
|
|
394
778
|
};
|
|
395
|
-
exports.
|
|
396
|
-
//
|
|
397
|
-
const
|
|
398
|
-
if (!(0, utils_js_1.isObjectWithValues)(
|
|
399
|
-
return null;
|
|
400
|
-
const
|
|
401
|
-
|
|
402
|
-
hasExtraSpasmFields: false,
|
|
403
|
-
convertedFrom: "unknown",
|
|
404
|
-
},
|
|
405
|
-
spasmVersion: "1.0.0",
|
|
779
|
+
exports.standardizeSpasmNostrSpasmEventSignedOpenedV0_V2 = standardizeSpasmNostrSpasmEventSignedOpenedV0_V2;
|
|
780
|
+
// standardizeSpasmWithRssItemV0_V2
|
|
781
|
+
const standardizeSpasmWithRssItemV0_V2 = (spasmEventV0) => {
|
|
782
|
+
if (!(0, utils_js_1.isObjectWithValues)(spasmEventV0))
|
|
783
|
+
return null;
|
|
784
|
+
const spasmEventV2 = {
|
|
785
|
+
type: "SpasmEventV2",
|
|
406
786
|
action: "post",
|
|
407
787
|
};
|
|
408
|
-
if (
|
|
409
|
-
|
|
410
|
-
}
|
|
411
|
-
if (post.title) {
|
|
412
|
-
spasmEvent.title = post.title;
|
|
788
|
+
if (spasmEventV0.title) {
|
|
789
|
+
spasmEventV2.title = spasmEventV0.title;
|
|
413
790
|
}
|
|
414
|
-
if (
|
|
415
|
-
|
|
791
|
+
if (spasmEventV0.pubdate) {
|
|
792
|
+
spasmEventV2.timestamp = (0, utils_js_1.toBeTimestamp)(spasmEventV0.pubdate);
|
|
416
793
|
}
|
|
417
|
-
if (
|
|
418
|
-
|
|
794
|
+
if (spasmEventV0.description) {
|
|
795
|
+
spasmEventV2.content = spasmEventV0.description;
|
|
419
796
|
}
|
|
420
|
-
if (
|
|
421
|
-
|
|
797
|
+
if (spasmEventV0.tags) {
|
|
798
|
+
if (Array.isArray(spasmEventV0.tags)) {
|
|
799
|
+
// Create ids if it's null or undefined
|
|
800
|
+
spasmEventV2.keywords ??= [];
|
|
801
|
+
spasmEventV2.keywords =
|
|
802
|
+
spasmEventV2.keywords?.concat(spasmEventV0.tags);
|
|
803
|
+
}
|
|
422
804
|
}
|
|
423
|
-
if (
|
|
424
|
-
|
|
805
|
+
if (spasmEventV0.tickers) {
|
|
806
|
+
if (typeof (spasmEventV0.tickers) === "string") {
|
|
807
|
+
// Create ids if it's null or undefined
|
|
808
|
+
spasmEventV2.keywords ??= [];
|
|
809
|
+
spasmEventV2.keywords.push(spasmEventV0.tickers);
|
|
810
|
+
}
|
|
811
|
+
else if (Array.isArray(spasmEventV0.tickers)) {
|
|
812
|
+
spasmEventV2.keywords =
|
|
813
|
+
spasmEventV2.keywords?.concat(spasmEventV0.tickers);
|
|
814
|
+
}
|
|
425
815
|
}
|
|
426
|
-
|
|
816
|
+
let siblingIds = [];
|
|
817
|
+
if (spasmEventV0.url &&
|
|
818
|
+
typeof (spasmEventV0.url) === "string") {
|
|
819
|
+
// Create ids if it's null or undefined
|
|
820
|
+
spasmEventV2.ids ??= [];
|
|
821
|
+
spasmEventV2.ids.push({
|
|
822
|
+
value: spasmEventV0.url,
|
|
823
|
+
format: {
|
|
824
|
+
name: "url"
|
|
825
|
+
}
|
|
826
|
+
});
|
|
827
|
+
siblingIds.push({
|
|
828
|
+
value: spasmEventV0.url,
|
|
829
|
+
format: {
|
|
830
|
+
name: "url"
|
|
831
|
+
}
|
|
832
|
+
});
|
|
427
833
|
// Create links if it's null or undefined
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
834
|
+
spasmEventV2.links ??= [];
|
|
835
|
+
const linkObject = (0, utils_js_1.createLinkObjectFromUrl)(spasmEventV0.url);
|
|
836
|
+
if (linkObject) {
|
|
837
|
+
linkObject.originalProtocolKey = "url";
|
|
838
|
+
spasmEventV2.links.push(linkObject);
|
|
839
|
+
}
|
|
431
840
|
}
|
|
432
|
-
if (
|
|
433
|
-
// Create
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
841
|
+
if (spasmEventV0.guid) {
|
|
842
|
+
// Create ids if it's null or undefined
|
|
843
|
+
spasmEventV2.ids ??= [];
|
|
844
|
+
spasmEventV2.ids.push({
|
|
845
|
+
value: spasmEventV0.guid,
|
|
846
|
+
format: {
|
|
847
|
+
name: "guid"
|
|
848
|
+
}
|
|
849
|
+
});
|
|
850
|
+
siblingIds.push({
|
|
851
|
+
value: spasmEventV0.guid,
|
|
852
|
+
format: {
|
|
853
|
+
name: "guid"
|
|
854
|
+
}
|
|
855
|
+
});
|
|
856
|
+
if (typeof (spasmEventV0.guid) === "string") {
|
|
857
|
+
// Create links if it's null or undefined
|
|
858
|
+
spasmEventV2.links ??= [];
|
|
859
|
+
const linkObject = (0, utils_js_1.createLinkObjectFromUrl)(spasmEventV0.guid);
|
|
860
|
+
if (linkObject) {
|
|
861
|
+
linkObject.originalProtocolKey = "guid";
|
|
862
|
+
spasmEventV2.links.push(linkObject);
|
|
863
|
+
}
|
|
439
864
|
}
|
|
440
865
|
}
|
|
441
|
-
|
|
866
|
+
if (spasmEventV0.author) {
|
|
867
|
+
// Create ids if it's null or undefined
|
|
868
|
+
spasmEventV2.authors ??= [];
|
|
869
|
+
spasmEventV2.authors.push({
|
|
870
|
+
usernames: [
|
|
871
|
+
{
|
|
872
|
+
value: spasmEventV0.author
|
|
873
|
+
}
|
|
874
|
+
]
|
|
875
|
+
});
|
|
876
|
+
}
|
|
877
|
+
// siblings
|
|
878
|
+
// Create siblings if it's null or undefined
|
|
879
|
+
spasmEventV2.siblings ??= [];
|
|
880
|
+
spasmEventV2.siblings[0] ??= {
|
|
881
|
+
type: "SiblingWeb2V2",
|
|
882
|
+
protocol: { name: "web2" }
|
|
883
|
+
};
|
|
884
|
+
spasmEventV2.siblings[0] =
|
|
885
|
+
spasmEventV2.siblings[0];
|
|
886
|
+
spasmEventV2.siblings[0].type = "SiblingWeb2V2";
|
|
887
|
+
spasmEventV2.siblings[0].protocol = { name: "web2" };
|
|
888
|
+
// Add IDs (e.g., URL and guid) to siblings
|
|
889
|
+
// spasmEventV2.siblings[0].ids ??= [];
|
|
890
|
+
spasmEventV2.siblings[0].ids = siblingIds;
|
|
891
|
+
// Destruct spasmEventV0 to exclude children
|
|
892
|
+
// to avoid infinite recursion loop.
|
|
893
|
+
const { children, ...originalObjectWithoutChildren } = spasmEventV0;
|
|
894
|
+
spasmEventV2.siblings[0].originalObject =
|
|
895
|
+
originalObjectWithoutChildren;
|
|
896
|
+
return spasmEventV2;
|
|
442
897
|
};
|
|
443
|
-
exports.
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
898
|
+
exports.standardizeSpasmWithRssItemV0_V2 = standardizeSpasmWithRssItemV0_V2;
|
|
899
|
+
// addFieldsFromEnvelopeSpasmEventV0_V2
|
|
900
|
+
const addFieldsFromEnvelopeSpasmEventV0_V2 = (spasmEventV0, spasmEventV2) => {
|
|
901
|
+
if (!spasmEventV0)
|
|
902
|
+
return spasmEventV2;
|
|
903
|
+
if (!spasmEventV2)
|
|
904
|
+
return spasmEventV2;
|
|
905
|
+
if (!(0, utils_js_1.isObjectWithValues)(spasmEventV0))
|
|
906
|
+
return spasmEventV2;
|
|
907
|
+
if (!(0, utils_js_1.isObjectWithValues)(spasmEventV2))
|
|
908
|
+
return spasmEventV2;
|
|
909
|
+
// db.key
|
|
910
|
+
if (spasmEventV0.id) {
|
|
911
|
+
if (typeof (spasmEventV0.id) === "number") {
|
|
912
|
+
// Create db if it's null or undefined
|
|
913
|
+
spasmEventV2.db ??= {};
|
|
914
|
+
spasmEventV2.db.key = spasmEventV0.id;
|
|
915
|
+
}
|
|
916
|
+
else if (typeof (spasmEventV0.id) === "string" &&
|
|
917
|
+
Number(spasmEventV0.id)) {
|
|
918
|
+
// Create db if it's null or undefined
|
|
919
|
+
spasmEventV2.db ??= {};
|
|
920
|
+
spasmEventV2.db.key = Number(spasmEventV0.id);
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
// db.addedTimestamp
|
|
924
|
+
if (spasmEventV0.added_time) {
|
|
925
|
+
if (typeof (spasmEventV0.added_time) === "number") {
|
|
926
|
+
// Create db if it's null or undefined
|
|
927
|
+
spasmEventV2.db ??= {};
|
|
928
|
+
spasmEventV2.db.addedTimestamp =
|
|
929
|
+
(0, utils_js_1.toBeTimestamp)(spasmEventV0.added_time);
|
|
930
|
+
}
|
|
931
|
+
else if (typeof (spasmEventV0.added_time) === "string") {
|
|
932
|
+
// Create db if it's null or undefined
|
|
933
|
+
spasmEventV2.db ??= {};
|
|
934
|
+
spasmEventV2.db.addedTimestamp =
|
|
935
|
+
(0, utils_js_1.toBeTimestamp)(spasmEventV0.added_time);
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
if (spasmEventV0.source && !spasmEventV2.source) {
|
|
939
|
+
spasmEventV2.source = {
|
|
940
|
+
name: spasmEventV0.source
|
|
941
|
+
};
|
|
942
|
+
}
|
|
943
|
+
if (spasmEventV0.category && !spasmEventV2.categories) {
|
|
944
|
+
// Create categories if it's null or undefined
|
|
945
|
+
spasmEventV2.categories ??= [];
|
|
946
|
+
spasmEventV2.categories.push({
|
|
947
|
+
name: spasmEventV0.category
|
|
948
|
+
});
|
|
464
949
|
}
|
|
465
950
|
// Reactions (e.g., upvote, downvote, etc.)
|
|
466
951
|
const addReactions = (reaction) => {
|
|
467
952
|
if (
|
|
468
|
-
//
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
// 0 is a valid number
|
|
472
|
-
post[reaction] !== undefined &&
|
|
473
|
-
typeof (post[reaction]) === "number")) {
|
|
953
|
+
// 0 is a valid number
|
|
954
|
+
// spasmEventV0[reaction] !== undefined &&
|
|
955
|
+
typeof (spasmEventV0[reaction]) === "number") {
|
|
474
956
|
// Create reactions if it's null or undefined
|
|
475
|
-
|
|
476
|
-
|
|
957
|
+
spasmEventV2.stats ??= [];
|
|
958
|
+
spasmEventV2.stats[0] ??= { action: "react" };
|
|
959
|
+
spasmEventV2.stats[0].contents ??= [];
|
|
960
|
+
spasmEventV2.stats[0].contents.push({
|
|
961
|
+
value: reaction,
|
|
962
|
+
total: spasmEventV0[reaction]
|
|
963
|
+
});
|
|
477
964
|
}
|
|
478
965
|
};
|
|
479
966
|
const reactions = [
|
|
480
967
|
"upvote", "downvote",
|
|
481
968
|
"bullish", "bearish",
|
|
482
969
|
"important", "scam",
|
|
483
|
-
"
|
|
970
|
+
"laugh",
|
|
484
971
|
"toxic", "clown", "moon",
|
|
485
972
|
"rocket"
|
|
486
973
|
];
|
|
487
974
|
reactions.forEach(reaction => {
|
|
488
975
|
addReactions(reaction);
|
|
489
976
|
});
|
|
977
|
+
// "comments_count",
|
|
978
|
+
if (
|
|
979
|
+
// 0 is a valid number
|
|
980
|
+
// spasmEventV0["comments_count"] !== undefined &&
|
|
981
|
+
typeof (spasmEventV0["comments_count"]) === "number") {
|
|
982
|
+
// Create reactions if it's null or undefined
|
|
983
|
+
spasmEventV2.stats ??= [];
|
|
984
|
+
spasmEventV2.stats.push({
|
|
985
|
+
action: "reply",
|
|
986
|
+
total: spasmEventV0["comments_count"]
|
|
987
|
+
});
|
|
988
|
+
}
|
|
490
989
|
// Comments
|
|
491
|
-
if (
|
|
492
|
-
Array.isArray(
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
990
|
+
if (spasmEventV0.children &&
|
|
991
|
+
Array.isArray(spasmEventV0.children) &&
|
|
992
|
+
spasmEventV0.children.length > 0) {
|
|
993
|
+
const childrenAsSpasmAndNullV2 = spasmEventV0.children.map(child => (0, exports.convertToSpasm)(child));
|
|
994
|
+
childrenAsSpasmAndNullV2.forEach((event) => {
|
|
995
|
+
if (event !== null) {
|
|
996
|
+
// Create children if it's null or undefined
|
|
997
|
+
spasmEventV2.children ??= [];
|
|
998
|
+
spasmEventV2.children.push({
|
|
999
|
+
ids: event.ids,
|
|
1000
|
+
event: event
|
|
1001
|
+
});
|
|
1002
|
+
}
|
|
1003
|
+
});
|
|
1004
|
+
}
|
|
1005
|
+
return spasmEventV2;
|
|
499
1006
|
};
|
|
500
|
-
exports.
|
|
501
|
-
const
|
|
502
|
-
|
|
1007
|
+
exports.addFieldsFromEnvelopeSpasmEventV0_V2 = addFieldsFromEnvelopeSpasmEventV0_V2;
|
|
1008
|
+
const convertToSpasmStatus = () => {
|
|
1009
|
+
console.log("spasm.js convertToSpasm status: success");
|
|
503
1010
|
};
|
|
504
|
-
exports.
|
|
1011
|
+
exports.convertToSpasmStatus = convertToSpasmStatus;
|
|
505
1012
|
//# sourceMappingURL=convertToSpasm.js.map
|