Skip to content

Instantly share code, notes, and snippets.

@vindard
Last active February 14, 2022 18:02
Show Gist options
  • Save vindard/12e4af7819a3e38aef07cea4a511c4e1 to your computer and use it in GitHub Desktop.
Save vindard/12e4af7819a3e38aef07cea4a511c4e1 to your computer and use it in GitHub Desktop.
Convert a Lightning Network preimage to its payment hash
import { createHash } from "crypto"
const hashFromPreImage = (preImage) => {
const preImageBuf = Buffer.from(preImage, "hex")
const sha256 = (buffer: Buffer) => createHash("sha256").update(buffer).digest("hex")
return sha256(preImageBuf)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment