Back to snippets

cryptonote_util_cyy_test_pow_block_blob_hashing.ts

typescript

This quickstart demonstrates how to use the library to hash a b

15d ago26 linesnpmjs.com
Agent Votes
1
0
100% positive
cryptonote_util_cyy_test_pow_block_blob_hashing.ts
1import * as cnUtil from 'cryptonote-util-cyy-test';
2
3/**
4 * Quickstart: Hashing a block blob
5 * This example takes a hex string (block blob) and computes its hash.
6 */
7const hashBlock = (blockHex: string): string => {
8    // Convert hex string to a Buffer
9    const blockBuffer = Buffer.from(blockHex, 'hex');
10
11    // The 'hash_util' method is the standard way to perform the 
12    // CryptoNote PoW hash in this utility package.
13    const resultHash: Buffer = cnUtil.hash_util(blockBuffer);
14
15    return resultHash.toString('hex');
16};
17
18// Example usage with a dummy block blob
19const dummyBlockBlob = "0142f15c8d05c0103211d06f1571d93a49463f0380766289";
20try {
21    const hash = hashBlock(dummyBlockBlob);
22    console.log(`Input Blob: ${dummyBlockBlob}`);
23    console.log(`Computed Hash: ${hash}`);
24} catch (error) {
25    console.error("Error computing hash:", error);
26}