Refactor, Added documentation, moved from avj-cli to avj, update script and added tests

This commit is contained in:
Kuldeep
2026-04-19 09:33:48 +00:00
parent cfd4c6a43b
commit 013583e7f8
26 changed files with 4216 additions and 9970 deletions

View File

@@ -0,0 +1,22 @@
import { binToHex, sha256, utf8ToBin } from '@bitauth/libauth';
import type { XOTemplate } from '@xo-cash/types';
import { serializeTemplate } from './serialization.ts';
/**
* Generates a deterministic template identifier by hashing the template.
*
* Note: This expects a template that has been validated by `parseTemplate`.
*
* @param template - The template to generate an identifier for.
* @returns The sha256 hex identifier for the template.
*/
export const generateTemplateIdentifier = (template: XOTemplate): string => {
// Serialize the template.
const serializedTemplate = serializeTemplate(template);
// Hash the serialized template.
const hash = sha256.hash(utf8ToBin(serializedTemplate));
// Convert the hash to hex and return it.
return binToHex(hash);
};