Skip to content

Instantly share code, notes, and snippets.

@reemuru
reemuru / preimage.js
Created August 27, 2021 00:47
Node.js - create preimage and preimage hash for LND hold invoice
// import crypto module
const crypto = require("crypto")
// use cryptographically secure random bytes generation
const preimage = crypto.randomBytes(32)
// get the raw bytes from the buffer
const preimageRaw = JSON.parse(JSON.stringify(preimage)).data
// log the preimage raw bytes
console.log(`preimage bytes: ${preimageRaw}`)
// create SHA-256 hash
const hash = crypto.createHash('sha256')