Files
xo-cash-utils/source/script.ts

18 lines
553 B
TypeScript

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 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);
};