I am looking at some docs for Lightning invoices creation at https://github.com/lightning/bolts/blob/master/11-payment-encoding.md#now-send-24-for-an-entire-list-of-things-hashed.
They say a SHA256 hash of
One piece of chocolate cake, one icecream cone, one pickle, one slice of swiss cheese, one slice of salami, one lollypop, one piece of cherry pie, one sausage, one cupcake, and one slice of watermelon
is
8yjmdan79s6qqdhdzgynm4zwqd5d7xmw5fk98klysy043l2ahrqs
When I create an invoice with a LND, it returns an invoice which is when decoded, shows the same value, but when I try to hash the source string with JavaScript or with online tools, I never get a string like that.
Here is what I get with JavaScript:
createHash('sha256').update(str).digest('hex')
3925b6f67e2c340036ed12093dd44e0368df1b6ea26c53dbe4811f58fd5db8c1
Online tools gives no the result I expect as well.
So, I suppose there is some extra encode/decode procedure happening under the hood.
How do I turn One piece of chocolate cake, one icecream cone, one pickle, one slice of swiss cheese, one slice of salami, one lollypop, one piece of cherry pie, one sausage, one cupcake, and one slice of watermelon
into 8yjmdan79s6qqdhdzgynm4zwqd5d7xmw5fk98klysy043l2ahrqs
?
I used the bech32-converting
lib to check this:
conv = require('bech32-converting')
conv("").toBech32("3925b6f67e2c340036ed12093dd44e0368df1b6ea26c53dbe4811f58fd5db8c1")
> '18yjmdan79s6qqdhdzgynm4zwqd5d7xmw5fk98klysy043l2ahrqspe7lh6'
which contains the result... Note there is a 1
is prepended and pe7lh6
:
The first char (1
) is the Bech32 separator which is always 1
(using conv("bc")
above would prepend bc
for example)
The last six characters (pe7lh6
) are the Bech32 checksum