2

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?

2
  • The link you provided mentions something called 'bech32' encoding. The string 8yjm.. appears to be some kind of 32-character encoding, so I'd guess that's the ticket. It would be encoding the 32 bytes of the digest, not the hex version of the digest. But I'm not motivated to look up bech32 encoding. Commented May 24, 2022 at 17:15
  • @PresidentJamesK.Polk I think bech32 is used to encode whole invoice, not parts of it so I am afraid it doesn't give a clue. Commented May 24, 2022 at 17:29

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

This indeed helps! A lot of documentation is missing on how to build around lightning but your answer is just to the point!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.