christroutner

Accessing Crypto Class in bch-js

Jul 24th, 2020
1,291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const BCHJS = require('@chris.troutner/bch-js')
  2. const bchjs = new BCHJS()
  3.  
  4. async function runTest() {
  5.   try {
  6.     const numNum = 123; // 7B in hex
  7.     console.log(`numNum: `, numNum);
  8.  
  9.     const numHex = numNum.toString(16);
  10.     console.log(`numHex: ${numHex}`);
  11.  
  12.     const numBuf = Buffer.from(numHex, "hex");
  13.     console.log(`numBuf: `, numBuf);
  14.  
  15.     const hash = bchjs.Crypto.sha256(numBuf)
  16.     console.log(`hash: `, hash)
  17.  
  18.     const hashStr = hash.toString("hex")
  19.     console.log(`hashStr: ${hashStr}`)
  20.   } catch(err) {
  21.     console.error(err)
  22.   }
  23. }
  24. runTest()
Advertisement
Add Comment
Please, Sign In to add comment