mcard-js 1.0.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/LICENSE +21 -0
- package/README.md +117 -0
- package/dist/__mocks__/better-sqlite3.js +20 -0
- package/dist/__mocks__/better-sqlite3.js.map +1 -0
- package/dist/config/config_constants.js +188 -0
- package/dist/config/config_constants.js.map +1 -0
- package/dist/config/env_parameters.js +62 -0
- package/dist/config/env_parameters.js.map +1 -0
- package/dist/content/model/content_type_detector.js +89 -0
- package/dist/content/model/content_type_detector.js.map +1 -0
- package/dist/core/card-collection.js +279 -0
- package/dist/core/card-collection.js.map +1 -0
- package/dist/core/event-producer.js +132 -0
- package/dist/core/event-producer.js.map +1 -0
- package/dist/core/g_time.js +201 -0
- package/dist/core/g_time.js.map +1 -0
- package/dist/core/hash/enums.js +19 -0
- package/dist/core/hash/enums.js.map +1 -0
- package/dist/core/hash/validator.js +260 -0
- package/dist/core/hash/validator.js.map +1 -0
- package/dist/core/mcard.js +205 -0
- package/dist/core/mcard.js.map +1 -0
- package/dist/engine/sqlite_engine.js +723 -0
- package/dist/engine/sqlite_engine.js.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/middleware/mcardPersistenceMiddleware.js +45 -0
- package/dist/middleware/mcardPersistenceMiddleware.js.map +1 -0
- package/dist/models/database_schemas.js +31 -0
- package/dist/models/database_schemas.js.map +1 -0
- package/dist/services/logger.js +80 -0
- package/dist/services/logger.js.map +1 -0
- package/dist/services/mcardStorageService.js +36 -0
- package/dist/services/mcardStorageService.js.map +1 -0
- package/dist/utils/actionHelpers.js +25 -0
- package/dist/utils/actionHelpers.js.map +1 -0
- package/dist/utils/bufferContentHelper.js +393 -0
- package/dist/utils/bufferContentHelper.js.map +1 -0
- package/dist/utils/bufferPolyfill.js +198 -0
- package/dist/utils/bufferPolyfill.js.map +1 -0
- package/dist/utils/content-detection.js +74 -0
- package/dist/utils/content-detection.js.map +1 -0
- package/dist/utils/content-utils.js +269 -0
- package/dist/utils/content-utils.js.map +1 -0
- package/dist/utils/content_type_detector copy.js +480 -0
- package/dist/utils/content_type_detector copy.js.map +1 -0
- package/dist/utils/content_type_detector.js +480 -0
- package/dist/utils/content_type_detector.js.map +1 -0
- package/dist/utils/cryptoPolyfill.js +166 -0
- package/dist/utils/cryptoPolyfill.js.map +1 -0
- package/dist/utils/dotenv-browser.js +35 -0
- package/dist/utils/dotenv-browser.js.map +1 -0
- package/dist/utils/environmentDetector.js +93 -0
- package/dist/utils/environmentDetector.js.map +1 -0
- package/dist/utils/logWriter.js +27 -0
- package/dist/utils/logWriter.js.map +1 -0
- package/dist/utils/serviceWorkerManager.js +118 -0
- package/dist/utils/serviceWorkerManager.js.map +1 -0
- package/dist/utils/test-content-detection.js +79 -0
- package/dist/utils/test-content-detection.js.map +1 -0
- package/dist/utils/test-detection-fix.js +121 -0
- package/dist/utils/test-detection-fix.js.map +1 -0
- package/dist/utils/test-format-conversion.js +170 -0
- package/dist/utils/test-format-conversion.js.map +1 -0
- package/dist/utils/test-mov-viewer.js +57 -0
- package/dist/utils/test-mov-viewer.js.map +1 -0
- package/dist/utils/testDetection.js +21 -0
- package/dist/utils/testDetection.js.map +1 -0
- package/dist/utils/textEncoderPolyfill.js +87 -0
- package/dist/utils/textEncoderPolyfill.js.map +1 -0
- package/package.json +74 -0
- package/src/__mocks__/better-sqlite3.js +14 -0
- package/src/config/config_constants.js +227 -0
- package/src/config/env_parameters.js +69 -0
- package/src/content/model/content_type_detector.js +87 -0
- package/src/core/card-collection.js +300 -0
- package/src/core/event-producer.js +160 -0
- package/src/core/g_time.js +215 -0
- package/src/core/hash/enums.js +13 -0
- package/src/core/hash/validator.js +271 -0
- package/src/core/mcard.js +203 -0
- package/src/engine/sqlite_engine.js +755 -0
- package/src/index.js +10 -0
- package/src/middleware/mcardPersistenceMiddleware.js +45 -0
- package/src/models/database_schemas.js +26 -0
- package/src/services/logger.js +74 -0
- package/src/services/mcardStorageService.js +34 -0
- package/src/utils/actionHelpers.js +13 -0
- package/src/utils/bufferContentHelper.js +436 -0
- package/src/utils/bufferPolyfill.js +202 -0
- package/src/utils/cn.ts +6 -0
- package/src/utils/content-detection.js +66 -0
- package/src/utils/content-utils.js +250 -0
- package/src/utils/content_type_detector copy.js +501 -0
- package/src/utils/content_type_detector.js +501 -0
- package/src/utils/cryptoPolyfill.js +180 -0
- package/src/utils/dateUtils.ts +18 -0
- package/src/utils/dbInitializer.ts +27 -0
- package/src/utils/dotenv-browser.js +29 -0
- package/src/utils/environmentDetector.js +92 -0
- package/src/utils/logWriter.js +20 -0
- package/src/utils/serviceWorkerManager.js +122 -0
- package/src/utils/stateWatcher.ts +78 -0
- package/src/utils/storeAdapter copy.ts +157 -0
- package/src/utils/storeAdapter.ts +157 -0
- package/src/utils/test-content-detection.js +71 -0
- package/src/utils/test-detection-fix.js +136 -0
- package/src/utils/test-format-conversion.js +165 -0
- package/src/utils/test-mov-viewer.js +59 -0
- package/src/utils/testDetection.js +16 -0
- package/src/utils/textEncoderPolyfill.js +88 -0
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.Page = exports.CardCollection = void 0;
|
|
8
|
+
var _bufferPolyfill = require("../utils/bufferPolyfill.js");
|
|
9
|
+
var _mcard = require("./mcard.js");
|
|
10
|
+
var _eventProducer = require("./event-producer.js");
|
|
11
|
+
var _logger = _interopRequireDefault(require("../services/logger.js"));
|
|
12
|
+
var _config_constants = require("../config/config_constants.js");
|
|
13
|
+
var _validator = _interopRequireDefault(require("./hash/validator.js"));
|
|
14
|
+
console.log('Card Collection Module Loading...');
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Dataclass-like Page class
|
|
18
|
+
*/
|
|
19
|
+
class Page {
|
|
20
|
+
constructor(pageData = {}) {
|
|
21
|
+
const {
|
|
22
|
+
items = [],
|
|
23
|
+
total_items = 0,
|
|
24
|
+
page_number = 1,
|
|
25
|
+
page_size = _config_constants.DEFAULT_PAGE_SIZE,
|
|
26
|
+
has_next = false,
|
|
27
|
+
has_previous = false,
|
|
28
|
+
total_pages = 0
|
|
29
|
+
} = pageData;
|
|
30
|
+
this.items = items;
|
|
31
|
+
this.total_items = total_items;
|
|
32
|
+
this.page_number = page_number;
|
|
33
|
+
this.page_size = page_size;
|
|
34
|
+
this.has_next = has_next;
|
|
35
|
+
this.has_previous = has_previous;
|
|
36
|
+
this.total_pages = total_pages;
|
|
37
|
+
|
|
38
|
+
// Add previous_page calculation
|
|
39
|
+
this.previous_page = has_previous ? page_number - 1 : null;
|
|
40
|
+
|
|
41
|
+
// Add next_page calculation
|
|
42
|
+
this.next_page = has_next ? page_number + 1 : null;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.Page = Page;
|
|
46
|
+
console.log('Page Class Defined:', Page);
|
|
47
|
+
class CardCollection {
|
|
48
|
+
constructor(engine) {
|
|
49
|
+
this.engine = engine;
|
|
50
|
+
this.hashValidator = new _validator.default(_bufferPolyfill.SafeBuffer.from(''), 'sha256');
|
|
51
|
+
}
|
|
52
|
+
add(card) {
|
|
53
|
+
if (card === null) {
|
|
54
|
+
throw new Error("Card cannot be None");
|
|
55
|
+
}
|
|
56
|
+
_logger.default.debug(`Attempting to add card with content: ${card.content}`);
|
|
57
|
+
|
|
58
|
+
// Get the hash of the incoming card
|
|
59
|
+
const hash_value = card.hash;
|
|
60
|
+
|
|
61
|
+
// Check if a card with this hash already exists
|
|
62
|
+
const existing_card = this.get(hash_value);
|
|
63
|
+
if (existing_card) {
|
|
64
|
+
_logger.default.debug(`Card with hash ${hash_value} already exists`);
|
|
65
|
+
|
|
66
|
+
// Compare content to determine if it's a duplicate or collision
|
|
67
|
+
const content1 = _bufferPolyfill.SafeBuffer.isBuffer(existing_card.content) ? existing_card.content : _bufferPolyfill.SafeBuffer.from(JSON.stringify(existing_card.content));
|
|
68
|
+
const content2 = _bufferPolyfill.SafeBuffer.isBuffer(card.content) ? card.content : _bufferPolyfill.SafeBuffer.from(JSON.stringify(card.content));
|
|
69
|
+
if (_bufferPolyfill.SafeBuffer.compare(content1, content2) === 0) {
|
|
70
|
+
_logger.default.debug(`Duplicate card found with content: ${card.content}`);
|
|
71
|
+
// Same content = duplicate, create event and return original hash
|
|
72
|
+
const duplicate_event_content_str = (0, _eventProducer.generateDuplicationEvent)(existing_card);
|
|
73
|
+
const duplicate_event_card = new _mcard.MCard(_bufferPolyfill.SafeBuffer.from(duplicate_event_content_str));
|
|
74
|
+
this.engine.add(duplicate_event_card);
|
|
75
|
+
_logger.default.debug(`Added duplicate event card with hash: ${duplicate_event_card.hash}`);
|
|
76
|
+
return duplicate_event_card.hash;
|
|
77
|
+
} else {
|
|
78
|
+
_logger.default.debug(`Collision detected for card with content: ${card.content}`);
|
|
79
|
+
// Create collision event card and store the new card with new hash function
|
|
80
|
+
const collision_event_content_str = (0, _eventProducer.generateCollisionEvent)(card, existing_card);
|
|
81
|
+
const contentDict = JSON.parse(collision_event_content_str);
|
|
82
|
+
|
|
83
|
+
// Determine the upgraded hash function
|
|
84
|
+
const currentHashFunction = card.hash_algorithm;
|
|
85
|
+
|
|
86
|
+
// Get the next hash function from the hierarchy
|
|
87
|
+
const upgradedFunction = _config_constants.HASH_ALGORITHM_HIERARCHY[currentHashFunction];
|
|
88
|
+
if (!upgradedFunction) {
|
|
89
|
+
throw new Error(`No stronger hash algorithm available for ${currentHashFunction}`);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Create the collision card with the upgraded hash function
|
|
93
|
+
const collision_content_card = new _mcard.MCard(card.content, upgradedFunction);
|
|
94
|
+
|
|
95
|
+
// Verify the hash algorithm is different and stronger
|
|
96
|
+
if (collision_content_card.hash_algorithm === card.hash_algorithm) {
|
|
97
|
+
throw new Error(`Hash algorithm did not upgrade: ${card.hash_algorithm} to ${upgradedFunction}`);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Verbose logging for the new card
|
|
101
|
+
console.log('Collision Card Details:');
|
|
102
|
+
console.log(`Original Hash: ${card.hash}`);
|
|
103
|
+
console.log(`Collision Card Hash: ${collision_content_card.hash}`);
|
|
104
|
+
console.log(`Original Hash Algorithm: ${card.hash_algorithm}`);
|
|
105
|
+
console.log(`Collision Card Hash Algorithm: ${collision_content_card.hash_algorithm}`);
|
|
106
|
+
|
|
107
|
+
// Define the expected hash lengths in bytes for each algorithm
|
|
108
|
+
const HASH_LENGTHS = {
|
|
109
|
+
'md5': 16,
|
|
110
|
+
// 128 bits = 16 bytes
|
|
111
|
+
'sha1': 20,
|
|
112
|
+
// 160 bits = 20 bytes
|
|
113
|
+
'sha224': 28,
|
|
114
|
+
// 224 bits = 28 bytes
|
|
115
|
+
'sha256': 32,
|
|
116
|
+
// 256 bits = 32 bytes
|
|
117
|
+
'sha384': 48,
|
|
118
|
+
// 384 bits = 48 bytes
|
|
119
|
+
'sha512': 64 // 512 bits = 64 bytes
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
// Get the expected hash lengths for the current and upgraded algorithms
|
|
123
|
+
const currentHashLength = HASH_LENGTHS[currentHashFunction.toLowerCase()] || 0;
|
|
124
|
+
const upgradedHashLength = HASH_LENGTHS[upgradedFunction.toLowerCase()] || 0;
|
|
125
|
+
console.log('Hash Length Comparison (in bytes):');
|
|
126
|
+
console.log(`Current Algorithm (${currentHashFunction}): ${currentHashLength} bytes`);
|
|
127
|
+
console.log(`Upgraded Algorithm (${upgradedFunction}): ${upgradedHashLength} bytes`);
|
|
128
|
+
if (upgradedHashLength <= currentHashLength) {
|
|
129
|
+
throw new Error(`Hash algorithm upgrade did not increase hash length: ` + `Current (${currentHashFunction}): ${currentHashLength} bytes, ` + `Upgraded (${upgradedFunction}): ${upgradedHashLength} bytes`);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Add the collision card with the upgraded hash function
|
|
133
|
+
this.engine.add(collision_content_card);
|
|
134
|
+
|
|
135
|
+
// Add the collision event card
|
|
136
|
+
const collision_event_card = new _mcard.MCard(_bufferPolyfill.SafeBuffer.from(collision_event_content_str));
|
|
137
|
+
_logger.default.debug(`Collision event: ${collision_event_content_str}`);
|
|
138
|
+
this.engine.add(collision_event_card);
|
|
139
|
+
_logger.default.debug(`Added collision event card with hash: ${collision_event_card.hash}`);
|
|
140
|
+
return collision_event_card.hash;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// No existing card with this hash or content, add the new card
|
|
145
|
+
this.engine.add(card);
|
|
146
|
+
_logger.default.debug(`Successfully added card with hash ${hash_value}`);
|
|
147
|
+
return hash_value;
|
|
148
|
+
}
|
|
149
|
+
get(hash_value) {
|
|
150
|
+
return this.engine.get(hash_value);
|
|
151
|
+
}
|
|
152
|
+
delete(hash_value) {
|
|
153
|
+
return this.engine.delete(hash_value);
|
|
154
|
+
}
|
|
155
|
+
get_page(page_number = 1, page_size = _config_constants.DEFAULT_PAGE_SIZE) {
|
|
156
|
+
// Validate input parameters
|
|
157
|
+
if (page_number < 1) {
|
|
158
|
+
throw new Error(`Invalid page number: ${page_number}. Page number must be >= 1.`);
|
|
159
|
+
}
|
|
160
|
+
if (page_size < 1) {
|
|
161
|
+
throw new Error(`Invalid page size: ${page_size}. Page size must be >= 1.`);
|
|
162
|
+
}
|
|
163
|
+
const result = this.engine.get_page(page_number, page_size);
|
|
164
|
+
|
|
165
|
+
// Explicitly calculate total pages
|
|
166
|
+
const total_pages = result.total_items > 0 ? Math.ceil(result.total_items / page_size) : 0;
|
|
167
|
+
|
|
168
|
+
// Throw an error if page_number is beyond total pages (but only if there are items)
|
|
169
|
+
if (result.total_items > 0 && page_number > total_pages) {
|
|
170
|
+
throw new Error(`Page number ${page_number} is beyond total pages ${total_pages}`);
|
|
171
|
+
}
|
|
172
|
+
return new Page({
|
|
173
|
+
...result,
|
|
174
|
+
total_pages: total_pages
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
search_by_string(search_string, page_number = 1, page_size = _config_constants.DEFAULT_PAGE_SIZE) {
|
|
178
|
+
return this.engine.search_by_string(search_string, page_number, page_size);
|
|
179
|
+
}
|
|
180
|
+
search_by_hash(hash_value, page_number = 1, page_size = _config_constants.DEFAULT_PAGE_SIZE) {
|
|
181
|
+
if (!hash_value) {
|
|
182
|
+
throw new Error("Hash value cannot be empty");
|
|
183
|
+
}
|
|
184
|
+
if (page_number < 1) {
|
|
185
|
+
throw new Error("Page number must be greater than 0");
|
|
186
|
+
}
|
|
187
|
+
if (page_size < 1) {
|
|
188
|
+
throw new Error("Page size must be greater than 0");
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// Get all matching cards
|
|
192
|
+
const matching_cards = [];
|
|
193
|
+
for (const card of this.engine.get_all().items) {
|
|
194
|
+
if (String(card.hash) === hash_value) {
|
|
195
|
+
matching_cards.push(card);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// Calculate pagination
|
|
200
|
+
const total_items = matching_cards.length;
|
|
201
|
+
const start_idx = (page_number - 1) * page_size;
|
|
202
|
+
const end_idx = start_idx + page_size;
|
|
203
|
+
const items = matching_cards.slice(start_idx, end_idx);
|
|
204
|
+
|
|
205
|
+
// Create page object
|
|
206
|
+
return new Page({
|
|
207
|
+
items: items,
|
|
208
|
+
total_items: total_items,
|
|
209
|
+
page_number: page_number,
|
|
210
|
+
page_size: page_size,
|
|
211
|
+
has_next: end_idx < total_items,
|
|
212
|
+
has_previous: page_number > 1
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
search_by_content(search_string, page_number = 1, page_size = _config_constants.DEFAULT_PAGE_SIZE) {
|
|
216
|
+
if (!search_string) {
|
|
217
|
+
throw new Error("Search string cannot be empty");
|
|
218
|
+
}
|
|
219
|
+
if (page_number < 1) {
|
|
220
|
+
throw new Error("Page number must be greater than 0");
|
|
221
|
+
}
|
|
222
|
+
if (page_size < 1) {
|
|
223
|
+
throw new Error("Page size must be greater than 0");
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// Delegate to engine's search method
|
|
227
|
+
return this.engine.search_by_content(search_string, page_number, page_size);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Update the content of an existing card
|
|
232
|
+
* @param {string} hash - Hash of the card to update
|
|
233
|
+
* @param {any} newContent - New content for the card
|
|
234
|
+
* @returns {boolean} Whether the update was successful
|
|
235
|
+
*/
|
|
236
|
+
update(hash, newContent) {
|
|
237
|
+
if (!hash) {
|
|
238
|
+
throw new Error("Hash cannot be empty");
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// Check if the card exists
|
|
242
|
+
const existingCard = this.get(hash);
|
|
243
|
+
if (!existingCard) {
|
|
244
|
+
return false;
|
|
245
|
+
}
|
|
246
|
+
try {
|
|
247
|
+
// Update the card in the engine
|
|
248
|
+
return this.engine.update(hash, newContent);
|
|
249
|
+
} catch (error) {
|
|
250
|
+
console.error(`Error updating card ${hash}:`, error);
|
|
251
|
+
return false;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
clear() {
|
|
255
|
+
this.engine.clear();
|
|
256
|
+
}
|
|
257
|
+
count() {
|
|
258
|
+
return this.engine.count();
|
|
259
|
+
}
|
|
260
|
+
get_all(page_number = 1, page_size = _config_constants.DEFAULT_PAGE_SIZE) {
|
|
261
|
+
const result = this.engine.get_all(page_number, page_size);
|
|
262
|
+
return new Page({
|
|
263
|
+
items: result.items,
|
|
264
|
+
total_items: result.total_items,
|
|
265
|
+
page_number: result.page_number || page_number,
|
|
266
|
+
page_size: result.page_size || page_size,
|
|
267
|
+
has_next: result.has_next || false,
|
|
268
|
+
has_previous: result.has_previous || false
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// Alias for get_all for backward compatibility
|
|
273
|
+
get_all_cards(page_number = 1, page_size = _config_constants.DEFAULT_PAGE_SIZE) {
|
|
274
|
+
return this.get_all(page_number, page_size);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
exports.CardCollection = CardCollection;
|
|
278
|
+
console.log('Card Collection Module Loaded.');
|
|
279
|
+
//# sourceMappingURL=card-collection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"card-collection.js","names":["_bufferPolyfill","require","_mcard","_eventProducer","_logger","_interopRequireDefault","_config_constants","_validator","console","log","Page","constructor","pageData","items","total_items","page_number","page_size","DEFAULT_PAGE_SIZE","has_next","has_previous","total_pages","previous_page","next_page","exports","CardCollection","engine","hashValidator","HashValidator","SafeBuffer","from","add","card","Error","logger","debug","content","hash_value","hash","existing_card","get","content1","isBuffer","JSON","stringify","content2","compare","duplicate_event_content_str","generateDuplicationEvent","duplicate_event_card","MCard","collision_event_content_str","generateCollisionEvent","contentDict","parse","currentHashFunction","hash_algorithm","upgradedFunction","HASH_ALGORITHM_HIERARCHY","collision_content_card","HASH_LENGTHS","currentHashLength","toLowerCase","upgradedHashLength","collision_event_card","delete","get_page","result","Math","ceil","search_by_string","search_string","search_by_hash","matching_cards","get_all","String","push","length","start_idx","end_idx","slice","search_by_content","update","newContent","existingCard","error","clear","count","get_all_cards"],"sources":["../../src/core/card-collection.js"],"sourcesContent":["import { SafeBuffer } from '../utils/bufferPolyfill.js';\nimport { MCard } from './mcard.js';\nimport { \n generateDuplicationEvent, \n generateCollisionEvent\n} from './event-producer.js';\nimport logger from '../services/logger.js';\nimport { DEFAULT_PAGE_SIZE, HASH_ALGORITHM_HIERARCHY, HashAlgorithm } from '../config/config_constants.js';\nimport HashValidator from './hash/validator.js';\n\nconsole.log('Card Collection Module Loading...');\n\n/**\n * Dataclass-like Page class\n */\nclass Page {\n constructor(pageData = {}) {\n const {\n items = [], \n total_items = 0, \n page_number = 1, \n page_size = DEFAULT_PAGE_SIZE, \n has_next = false, \n has_previous = false,\n total_pages = 0\n } = pageData;\n\n this.items = items;\n this.total_items = total_items;\n this.page_number = page_number;\n this.page_size = page_size;\n this.has_next = has_next;\n this.has_previous = has_previous;\n this.total_pages = total_pages;\n \n // Add previous_page calculation\n this.previous_page = has_previous ? page_number - 1 : null;\n \n // Add next_page calculation\n this.next_page = has_next ? page_number + 1 : null;\n }\n}\n\nconsole.log('Page Class Defined:', Page);\n\nclass CardCollection {\n constructor(engine) {\n this.engine = engine;\n this.hashValidator = new HashValidator(SafeBuffer.from(''), 'sha256');\n }\n\n add(card) {\n if (card === null) {\n throw new Error(\"Card cannot be None\");\n }\n \n logger.debug(`Attempting to add card with content: ${card.content}`);\n \n // Get the hash of the incoming card\n const hash_value = card.hash;\n \n // Check if a card with this hash already exists\n const existing_card = this.get(hash_value);\n \n if (existing_card) {\n logger.debug(`Card with hash ${hash_value} already exists`);\n \n // Compare content to determine if it's a duplicate or collision\n const content1 = SafeBuffer.isBuffer(existing_card.content) ? existing_card.content : SafeBuffer.from(JSON.stringify(existing_card.content));\n const content2 = SafeBuffer.isBuffer(card.content) ? card.content : SafeBuffer.from(JSON.stringify(card.content));\n \n if (SafeBuffer.compare(content1, content2) === 0) {\n logger.debug(`Duplicate card found with content: ${card.content}`);\n // Same content = duplicate, create event and return original hash\n const duplicate_event_content_str = generateDuplicationEvent(existing_card);\n const duplicate_event_card = new MCard(SafeBuffer.from(duplicate_event_content_str));\n this.engine.add(duplicate_event_card);\n logger.debug(`Added duplicate event card with hash: ${duplicate_event_card.hash}`);\n return duplicate_event_card.hash;\n } else {\n logger.debug(`Collision detected for card with content: ${card.content}`);\n // Create collision event card and store the new card with new hash function\n const collision_event_content_str = generateCollisionEvent(card, existing_card);\n const contentDict = JSON.parse(collision_event_content_str);\n \n // Determine the upgraded hash function\n const currentHashFunction = card.hash_algorithm;\n \n // Get the next hash function from the hierarchy\n const upgradedFunction = HASH_ALGORITHM_HIERARCHY[currentHashFunction];\n \n if (!upgradedFunction) {\n throw new Error(`No stronger hash algorithm available for ${currentHashFunction}`);\n }\n \n // Create the collision card with the upgraded hash function\n const collision_content_card = new MCard(\n card.content, \n upgradedFunction\n );\n\n // Verify the hash algorithm is different and stronger\n if (collision_content_card.hash_algorithm === card.hash_algorithm) {\n throw new Error(`Hash algorithm did not upgrade: ${card.hash_algorithm} to ${upgradedFunction}`);\n }\n \n // Verbose logging for the new card\n console.log('Collision Card Details:');\n console.log(`Original Hash: ${card.hash}`);\n console.log(`Collision Card Hash: ${collision_content_card.hash}`);\n console.log(`Original Hash Algorithm: ${card.hash_algorithm}`);\n console.log(`Collision Card Hash Algorithm: ${collision_content_card.hash_algorithm}`);\n \n // Define the expected hash lengths in bytes for each algorithm\n const HASH_LENGTHS = {\n 'md5': 16, // 128 bits = 16 bytes\n 'sha1': 20, // 160 bits = 20 bytes\n 'sha224': 28, // 224 bits = 28 bytes\n 'sha256': 32, // 256 bits = 32 bytes\n 'sha384': 48, // 384 bits = 48 bytes\n 'sha512': 64 // 512 bits = 64 bytes\n };\n \n // Get the expected hash lengths for the current and upgraded algorithms\n const currentHashLength = HASH_LENGTHS[currentHashFunction.toLowerCase()] || 0;\n const upgradedHashLength = HASH_LENGTHS[upgradedFunction.toLowerCase()] || 0;\n \n console.log('Hash Length Comparison (in bytes):');\n console.log(`Current Algorithm (${currentHashFunction}): ${currentHashLength} bytes`);\n console.log(`Upgraded Algorithm (${upgradedFunction}): ${upgradedHashLength} bytes`);\n \n if (upgradedHashLength <= currentHashLength) {\n throw new Error(`Hash algorithm upgrade did not increase hash length: ` +\n `Current (${currentHashFunction}): ${currentHashLength} bytes, ` +\n `Upgraded (${upgradedFunction}): ${upgradedHashLength} bytes`);\n }\n \n // Add the collision card with the upgraded hash function\n this.engine.add(collision_content_card);\n \n // Add the collision event card\n const collision_event_card = new MCard(SafeBuffer.from(collision_event_content_str));\n logger.debug(`Collision event: ${collision_event_content_str}`);\n this.engine.add(collision_event_card);\n logger.debug(`Added collision event card with hash: ${collision_event_card.hash}`);\n return collision_event_card.hash;\n }\n }\n \n // No existing card with this hash or content, add the new card\n this.engine.add(card);\n logger.debug(`Successfully added card with hash ${hash_value}`);\n return hash_value;\n }\n \n get(hash_value) {\n return this.engine.get(hash_value);\n }\n \n delete(hash_value) {\n return this.engine.delete(hash_value);\n }\n \n get_page(page_number = 1, page_size = DEFAULT_PAGE_SIZE) {\n // Validate input parameters\n if (page_number < 1) {\n throw new Error(`Invalid page number: ${page_number}. Page number must be >= 1.`);\n }\n if (page_size < 1) {\n throw new Error(`Invalid page size: ${page_size}. Page size must be >= 1.`);\n }\n\n const result = this.engine.get_page(page_number, page_size);\n \n // Explicitly calculate total pages\n const total_pages = result.total_items > 0 \n ? Math.ceil(result.total_items / page_size) \n : 0;\n \n // Throw an error if page_number is beyond total pages (but only if there are items)\n if (result.total_items > 0 && page_number > total_pages) {\n throw new Error(`Page number ${page_number} is beyond total pages ${total_pages}`);\n }\n \n return new Page({\n ...result,\n total_pages: total_pages\n });\n }\n \n search_by_string(search_string, page_number = 1, page_size = DEFAULT_PAGE_SIZE) {\n return this.engine.search_by_string(search_string, page_number, page_size);\n }\n \n search_by_hash(hash_value, page_number = 1, page_size = DEFAULT_PAGE_SIZE) {\n if (!hash_value) {\n throw new Error(\"Hash value cannot be empty\");\n }\n if (page_number < 1) {\n throw new Error(\"Page number must be greater than 0\");\n }\n if (page_size < 1) {\n throw new Error(\"Page size must be greater than 0\");\n }\n \n // Get all matching cards\n const matching_cards = [];\n for (const card of this.engine.get_all().items) {\n if (String(card.hash) === hash_value) {\n matching_cards.push(card);\n }\n }\n \n // Calculate pagination\n const total_items = matching_cards.length;\n const start_idx = (page_number - 1) * page_size;\n const end_idx = start_idx + page_size;\n const items = matching_cards.slice(start_idx, end_idx);\n \n // Create page object\n return new Page({\n items: items,\n total_items: total_items,\n page_number: page_number,\n page_size: page_size,\n has_next: end_idx < total_items,\n has_previous: page_number > 1\n });\n }\n \n search_by_content(search_string, page_number = 1, page_size = DEFAULT_PAGE_SIZE) {\n if (!search_string) {\n throw new Error(\"Search string cannot be empty\");\n }\n if (page_number < 1) {\n throw new Error(\"Page number must be greater than 0\");\n }\n if (page_size < 1) {\n throw new Error(\"Page size must be greater than 0\");\n }\n \n // Delegate to engine's search method\n return this.engine.search_by_content(search_string, page_number, page_size);\n }\n \n /**\n * Update the content of an existing card\n * @param {string} hash - Hash of the card to update\n * @param {any} newContent - New content for the card\n * @returns {boolean} Whether the update was successful\n */\n update(hash, newContent) {\n if (!hash) {\n throw new Error(\"Hash cannot be empty\");\n }\n \n // Check if the card exists\n const existingCard = this.get(hash);\n if (!existingCard) {\n return false;\n }\n \n try {\n // Update the card in the engine\n return this.engine.update(hash, newContent);\n } catch (error) {\n console.error(`Error updating card ${hash}:`, error);\n return false;\n }\n }\n \n clear() {\n this.engine.clear();\n }\n \n count() {\n return this.engine.count();\n }\n \n get_all(page_number = 1, page_size = DEFAULT_PAGE_SIZE) {\n const result = this.engine.get_all(page_number, page_size);\n return new Page({\n items: result.items,\n total_items: result.total_items,\n page_number: result.page_number || page_number,\n page_size: result.page_size || page_size,\n has_next: result.has_next || false,\n has_previous: result.has_previous || false\n });\n }\n \n // Alias for get_all for backward compatibility\n get_all_cards(page_number = 1, page_size = DEFAULT_PAGE_SIZE) {\n return this.get_all(page_number, page_size);\n }\n}\n\nconsole.log('Card Collection Module Loaded.');\n\nexport { CardCollection, Page };\n"],"mappings":";;;;;;;AAAA,IAAAA,eAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,cAAA,GAAAF,OAAA;AAIA,IAAAG,OAAA,GAAAC,sBAAA,CAAAJ,OAAA;AACA,IAAAK,iBAAA,GAAAL,OAAA;AACA,IAAAM,UAAA,GAAAF,sBAAA,CAAAJ,OAAA;AAEAO,OAAO,CAACC,GAAG,CAAC,mCAAmC,CAAC;;AAEhD;AACA;AACA;AACA,MAAMC,IAAI,CAAC;EACTC,WAAWA,CAACC,QAAQ,GAAG,CAAC,CAAC,EAAE;IACzB,MAA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CAAC/C,YAAY,IAAI;IACvC,CAAC,CAAC;EACJ;;EAEA;EACAoE,aAAaA,CAACxE,WAAW,GAAG,CAAC,EAAEC,SAAS,GAAGC,mCAAiB,EAAE;IAC5D,OAAO,IAAI,CAACwD,OAAO,CAAC1D,WAAW,EAAEC,SAAS,CAAC;EAC7C;AACF;AAACO,OAAA,CAAAC,cAAA,GAAAA,cAAA;AAEDhB,OAAO,CAACC,GAAG,CAAC,gCAAgC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.UPGRADED_HASH = exports.UPGRADED_FUNCTION = exports.TYPE = exports.TIMESTAMP = exports.SHA512 = exports.SHA384 = exports.SHA256 = exports.SHA224 = exports.SHA1 = exports.NEW_CARD_HASH = exports.MD5 = exports.HASH_FUNCTION_ORDER = exports.HASH_ALGORITHM_HIERARCHY = exports.HASH = exports.FIRST_G_TIME = exports.EXISTING_CARD_HASH = exports.DUPLICATE_TIME = exports.DUPLICATE_EVENT_TYPE = exports.CONTENT_TYPE = exports.CONTENT_SIZE = exports.COLLISION_TIME = exports.COLLISION_EVENT_TYPE = void 0;
|
|
8
|
+
exports.generateCollisionEvent = generateCollisionEvent;
|
|
9
|
+
exports.generateDuplicationEvent = generateDuplicationEvent;
|
|
10
|
+
exports.nextHashFunction = nextHashFunction;
|
|
11
|
+
var _enums = require("./hash/enums.js");
|
|
12
|
+
var _validator = _interopRequireDefault(require("./hash/validator.js"));
|
|
13
|
+
var _g_time = require("./g_time.js");
|
|
14
|
+
var _config_constants = require("../config/config_constants.js");
|
|
15
|
+
// Use global Buffer if available, otherwise use the polyfill
|
|
16
|
+
const Buffer = global.Buffer || require('buffer').Buffer;
|
|
17
|
+
|
|
18
|
+
// Destructure the enum values
|
|
19
|
+
const {
|
|
20
|
+
MD5,
|
|
21
|
+
SHA1,
|
|
22
|
+
SHA224,
|
|
23
|
+
SHA256,
|
|
24
|
+
SHA384,
|
|
25
|
+
SHA512,
|
|
26
|
+
DEFAULT
|
|
27
|
+
} = _enums.HashAlgorithm;
|
|
28
|
+
|
|
29
|
+
// Event type constants
|
|
30
|
+
exports.SHA512 = SHA512;
|
|
31
|
+
exports.SHA384 = SHA384;
|
|
32
|
+
exports.SHA256 = SHA256;
|
|
33
|
+
exports.SHA224 = SHA224;
|
|
34
|
+
exports.SHA1 = SHA1;
|
|
35
|
+
exports.MD5 = MD5;
|
|
36
|
+
const TYPE = exports.TYPE = 'type';
|
|
37
|
+
const HASH = exports.HASH = 'hash';
|
|
38
|
+
const CONTENT_TYPE = exports.CONTENT_TYPE = 'content_type';
|
|
39
|
+
const TIMESTAMP = exports.TIMESTAMP = 'timestamp';
|
|
40
|
+
const EXISTING_CARD_HASH = exports.EXISTING_CARD_HASH = 'existing_card_hash';
|
|
41
|
+
const NEW_CARD_HASH = exports.NEW_CARD_HASH = 'new_card_hash';
|
|
42
|
+
const FIRST_G_TIME = exports.FIRST_G_TIME = 'first_g_time';
|
|
43
|
+
const CONTENT_SIZE = exports.CONTENT_SIZE = 'content_size';
|
|
44
|
+
const COLLISION_TIME = exports.COLLISION_TIME = 'collision_time';
|
|
45
|
+
const UPGRADED_FUNCTION = exports.UPGRADED_FUNCTION = 'upgraded_function';
|
|
46
|
+
const UPGRADED_HASH = exports.UPGRADED_HASH = 'upgraded_hash';
|
|
47
|
+
const DUPLICATE_TIME = exports.DUPLICATE_TIME = 'duplicate_time';
|
|
48
|
+
const DUPLICATE_EVENT_TYPE = exports.DUPLICATE_EVENT_TYPE = 'duplicate';
|
|
49
|
+
const COLLISION_EVENT_TYPE = exports.COLLISION_EVENT_TYPE = 'collision';
|
|
50
|
+
|
|
51
|
+
// Predefined hash function progression order
|
|
52
|
+
const HASH_FUNCTION_ORDER = exports.HASH_FUNCTION_ORDER = ['md5', 'sha1', 'sha224', 'sha256', 'sha384', 'sha512'];
|
|
53
|
+
|
|
54
|
+
// Create a new HashValidator instance for use
|
|
55
|
+
let hashValidator;
|
|
56
|
+
|
|
57
|
+
// Initialize hashValidator in a try-catch to handle potential initialization errors
|
|
58
|
+
try {
|
|
59
|
+
hashValidator = new _validator.default(Buffer.from(''), 'sha256');
|
|
60
|
+
} catch (error) {
|
|
61
|
+
console.warn('Failed to initialize hashValidator:', error);
|
|
62
|
+
// Create a mock hashValidator if initialization fails
|
|
63
|
+
hashValidator = {
|
|
64
|
+
validate: () => Promise.resolve(true),
|
|
65
|
+
computeHash: () => 'mocked-hash'
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Explicitly define HASH_ALGORITHM_HIERARCHY
|
|
70
|
+
const HASH_ALGORITHM_HIERARCHY = exports.HASH_ALGORITHM_HIERARCHY = {
|
|
71
|
+
[MD5]: [SHA1],
|
|
72
|
+
[SHA1]: [SHA224],
|
|
73
|
+
[SHA224]: [SHA256],
|
|
74
|
+
[SHA256]: [SHA384],
|
|
75
|
+
[SHA384]: [SHA512],
|
|
76
|
+
[SHA512]: []
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
// Replace existing nextHashFunction with method from instance
|
|
80
|
+
function nextHashFunction(currentHashFunction) {
|
|
81
|
+
const algMap = {
|
|
82
|
+
'md5': MD5,
|
|
83
|
+
'sha1': SHA1,
|
|
84
|
+
'sha224': SHA224,
|
|
85
|
+
'sha256': SHA256,
|
|
86
|
+
'sha384': SHA384,
|
|
87
|
+
'sha512': SHA512
|
|
88
|
+
};
|
|
89
|
+
const currFunc = algMap[currentHashFunction] || currentHashFunction;
|
|
90
|
+
const hashFunctions = Object.values(_enums.HashAlgorithm).filter(func => func !== currFunc && typeof func === 'string');
|
|
91
|
+
const strongerFunctions = hashFunctions.filter(func => {
|
|
92
|
+
const currentStrongerFuncs = HASH_ALGORITHM_HIERARCHY[currFunc] || [];
|
|
93
|
+
return currentStrongerFuncs.includes(func);
|
|
94
|
+
});
|
|
95
|
+
return strongerFunctions.length > 0 ? strongerFunctions[0] : currFunc;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Generate a duplication event for the given card
|
|
99
|
+
// @param {Object} card - The card being duplicated
|
|
100
|
+
// @returns {string} JSON-stringified duplication event
|
|
101
|
+
function generateDuplicationEvent(card) {
|
|
102
|
+
const event = {
|
|
103
|
+
[TYPE]: DUPLICATE_EVENT_TYPE,
|
|
104
|
+
[HASH]: card.hash,
|
|
105
|
+
[CONTENT_TYPE]: card.contentType,
|
|
106
|
+
[TIMESTAMP]: _g_time.GTime.stampNow(card.hashFunction || _enums.HashAlgorithm.DEFAULT),
|
|
107
|
+
[DUPLICATE_TIME]: card.g_time
|
|
108
|
+
};
|
|
109
|
+
return JSON.stringify(event);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Generate a collision event for the given event data
|
|
113
|
+
// @param {Object} newCard - The new card
|
|
114
|
+
// @param {Object} existingCard - The existing card
|
|
115
|
+
// @returns {string} JSON-stringified collision event
|
|
116
|
+
function generateCollisionEvent(newCard, existingCard = null) {
|
|
117
|
+
const event = {
|
|
118
|
+
type: 'collision',
|
|
119
|
+
original_hash: existingCard ? existingCard.hash : null,
|
|
120
|
+
new_hash: newCard.hash,
|
|
121
|
+
timestamp: _g_time.GTime.stampNow(newCard.hashFunction || existingCard?.hashFunction || _enums.HashAlgorithm.DEFAULT),
|
|
122
|
+
content_size: typeof newCard.content === 'string' ? Buffer.from(newCard.content).length : newCard.content.length
|
|
123
|
+
};
|
|
124
|
+
if (existingCard) {
|
|
125
|
+
const upgradedFunction = nextHashFunction(existingCard.hashFunction);
|
|
126
|
+
event.upgraded_function = upgradedFunction;
|
|
127
|
+
event.upgraded_hash = existingCard.hash;
|
|
128
|
+
event.hash_algorithm = upgradedFunction;
|
|
129
|
+
}
|
|
130
|
+
return JSON.stringify(event);
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=event-producer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-producer.js","names":["_enums","require","_validator","_interopRequireDefault","_g_time","_config_constants","Buffer","global","MD5","SHA1","SHA224","SHA256","SHA384","SHA512","DEFAULT","HashAlgorithmEnum","exports","TYPE","HASH","CONTENT_TYPE","TIMESTAMP","EXISTING_CARD_HASH","NEW_CARD_HASH","FIRST_G_TIME","CONTENT_SIZE","COLLISION_TIME","UPGRADED_FUNCTION","UPGRADED_HASH","DUPLICATE_TIME","DUPLICATE_EVENT_TYPE","COLLISION_EVENT_TYPE","HASH_FUNCTION_ORDER","hashValidator","HashValidator","from","error","console","warn","validate","Promise","resolve","computeHash","HASH_ALGORITHM_HIERARCHY","nextHashFunction","currentHashFunction","algMap","currFunc","hashFunctions","Object","values","filter","func","strongerFunctions","currentStrongerFuncs","includes","length","generateDuplicationEvent","card","event","hash","contentType","GTimeUtil","stampNow","hashFunction","g_time","JSON","stringify","generateCollisionEvent","newCard","existingCard","type","original_hash","new_hash","timestamp","content_size","content","upgradedFunction","upgraded_function","upgraded_hash","hash_algorithm"],"sources":["../../src/core/event-producer.js"],"sourcesContent":["import { HashAlgorithm as HashAlgorithmEnum } from './hash/enums.js';\nimport HashValidator from './hash/validator.js';\nimport { GTime as GTimeUtil } from './g_time.js';\nimport { HASH_ALGORITHM_HIERARCHY as ALGORITHM_HIERARCHY } from '../config/config_constants.js';\n\n// Use global Buffer if available, otherwise use the polyfill\nconst Buffer = global.Buffer || require('buffer').Buffer;\n\n// Destructure the enum values\nconst { \n MD5, \n SHA1, \n SHA224, \n SHA256, \n SHA384, \n SHA512, \n DEFAULT\n} = HashAlgorithmEnum;\n\n// Event type constants\nconst TYPE = 'type';\nconst HASH = 'hash';\nconst CONTENT_TYPE = 'content_type';\nconst TIMESTAMP = 'timestamp';\nconst EXISTING_CARD_HASH = 'existing_card_hash';\nconst NEW_CARD_HASH = 'new_card_hash';\nconst FIRST_G_TIME = 'first_g_time';\nconst CONTENT_SIZE = 'content_size';\nconst COLLISION_TIME = 'collision_time';\nconst UPGRADED_FUNCTION = 'upgraded_function';\nconst UPGRADED_HASH = 'upgraded_hash';\nconst DUPLICATE_TIME = 'duplicate_time';\nconst DUPLICATE_EVENT_TYPE = 'duplicate';\nconst COLLISION_EVENT_TYPE = 'collision';\n\n// Predefined hash function progression order\nconst HASH_FUNCTION_ORDER = ['md5', 'sha1', 'sha224', 'sha256', 'sha384', 'sha512'];\n\n// Create a new HashValidator instance for use\nlet hashValidator;\n\n// Initialize hashValidator in a try-catch to handle potential initialization errors\ntry {\n hashValidator = new HashValidator(Buffer.from(''), 'sha256');\n} catch (error) {\n console.warn('Failed to initialize hashValidator:', error);\n // Create a mock hashValidator if initialization fails\n hashValidator = {\n validate: () => Promise.resolve(true),\n computeHash: () => 'mocked-hash'\n };\n}\n\n// Explicitly define HASH_ALGORITHM_HIERARCHY\nconst HASH_ALGORITHM_HIERARCHY = {\n [MD5]: [SHA1],\n [SHA1]: [SHA224],\n [SHA224]: [SHA256],\n [SHA256]: [SHA384],\n [SHA384]: [SHA512],\n [SHA512]: []\n};\n\n// Replace existing nextHashFunction with method from instance\nfunction nextHashFunction(currentHashFunction) {\n const algMap = {\n 'md5': MD5,\n 'sha1': SHA1,\n 'sha224': SHA224, \n 'sha256': SHA256,\n 'sha384': SHA384,\n 'sha512': SHA512\n };\n \n const currFunc = algMap[currentHashFunction] || currentHashFunction;\n \n const hashFunctions = Object.values(HashAlgorithmEnum).filter(\n func => func !== currFunc && typeof func === 'string' \n );\n \n const strongerFunctions = hashFunctions.filter(func => {\n const currentStrongerFuncs = HASH_ALGORITHM_HIERARCHY[currFunc] || [];\n return currentStrongerFuncs.includes(func);\n });\n \n return strongerFunctions.length > 0 \n ? strongerFunctions[0] \n : currFunc; \n}\n\n// Generate a duplication event for the given card\n// @param {Object} card - The card being duplicated\n// @returns {string} JSON-stringified duplication event\nfunction generateDuplicationEvent(card) {\n const event = {\n [TYPE]: DUPLICATE_EVENT_TYPE,\n [HASH]: card.hash,\n [CONTENT_TYPE]: card.contentType,\n [TIMESTAMP]: GTimeUtil.stampNow(card.hashFunction || HashAlgorithmEnum.DEFAULT),\n [DUPLICATE_TIME]: card.g_time\n };\n return JSON.stringify(event);\n}\n\n// Generate a collision event for the given event data\n// @param {Object} newCard - The new card\n// @param {Object} existingCard - The existing card\n// @returns {string} JSON-stringified collision event\nfunction generateCollisionEvent(newCard, existingCard = null) {\n const event = {\n type: 'collision',\n original_hash: existingCard ? existingCard.hash : null,\n new_hash: newCard.hash,\n timestamp: GTimeUtil.stampNow(\n newCard.hashFunction || \n existingCard?.hashFunction || \n HashAlgorithmEnum.DEFAULT\n ),\n content_size: typeof newCard.content === 'string' ? \n Buffer.from(newCard.content).length : \n newCard.content.length\n };\n\n if (existingCard) {\n const upgradedFunction = nextHashFunction(existingCard.hashFunction);\n event.upgraded_function = upgradedFunction;\n event.upgraded_hash = existingCard.hash; \n event.hash_algorithm = upgradedFunction; \n }\n\n return JSON.stringify(event);\n}\n\nexport {\n MD5,\n SHA1,\n SHA224,\n SHA256,\n SHA384,\n SHA512,\n TYPE,\n HASH,\n CONTENT_TYPE,\n TIMESTAMP,\n EXISTING_CARD_HASH,\n NEW_CARD_HASH,\n FIRST_G_TIME,\n CONTENT_SIZE,\n COLLISION_TIME,\n UPGRADED_FUNCTION,\n UPGRADED_HASH,\n DUPLICATE_TIME,\n DUPLICATE_EVENT_TYPE,\n COLLISION_EVENT_TYPE,\n HASH_FUNCTION_ORDER,\n HASH_ALGORITHM_HIERARCHY,\n nextHashFunction,\n generateDuplicationEvent,\n generateCollisionEvent\n};\n"],"mappings":";;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,UAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,OAAA,GAAAH,OAAA;AACA,IAAAI,iBAAA,GAAAJ,OAAA;AAEA;AACA,MAAMK,MAAM,GAAGC,MAAM,CA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