mcard-js
Version:
MCard - Content-addressable storage with cryptographic hashing, handle resolution, and vector search for Node.js and browsers
48 lines (46 loc) • 1.47 kB
JavaScript
import {
ALGORITHM_HIERARCHY,
EVENT_CONSTANTS
} from "./chunk-KEC7YFG3.js";
import {
GTime,
HashValidator
} from "./chunk-7NKII2JA.js";
import "./chunk-MLKGABMK.js";
// src/model/EventProducer.ts
async function generateCollisionEvent(card) {
const currentHashFunction = GTime.getHashAlgorithm(card.g_time);
const nextAlgo = nextHashFunction(currentHashFunction);
const upgradedHash = await HashValidator.computeHash(card.content, nextAlgo);
const event = {
[]: EVENT_CONSTANTS.COLLISION_EVENT_TYPE,
[]: card.hash,
[]: card.g_time,
[]: card.g_time,
// Using original card's time as per Python logic reference
[]: card.content.length,
[]: nextAlgo,
[]: upgradedHash
};
return JSON.stringify(event);
}
function generateDuplicationEvent(card) {
const event = {
[]: EVENT_CONSTANTS.DUPLICATE_EVENT_TYPE,
[]: card.hash,
[]: card.g_time
};
return JSON.stringify(event);
}
function nextHashFunction(current) {
const currentLower = current.toLowerCase();
const entry = ALGORITHM_HIERARCHY[currentLower];
if (entry && entry.next) {
return entry.next;
}
return "sha256";
}
export {
generateCollisionEvent,
generateDuplicationEvent
};