Refactor, Added documentation, moved from avj-cli to avj, update script and added tests
This commit is contained in:
@@ -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);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user