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

@@ -3,11 +3,15 @@ import { binToHex, sha256 } from '@bitauth/libauth';
/**
* Converts a script to a scriptHash.
* @param {Uint8Array} script - The script to convert.
* @returns {string} The scriptHash as a hexadecimal string.
* @returns {string} The scriptHash as a reversed hex string.
*/
export const scriptToScriptHash = (script: Uint8Array): string => {
// Hash the script.
const hash = sha256.hash(script);
// Reverse the hash. (Electrum style, reverse switches to little endian representation)
const reversed = hash.reverse();
// Convert the reversed hash to hex.
return binToHex(reversed);
};