1

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?

Sergei Basharov
  • 51,276
  • 73
  • 200
  • 335
  • 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. – President James K. Polk May 24 '22 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. – Sergei Basharov May 24 '22 at 17:29

1 Answers1

1

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

President James K. Polk
  • 40,516
  • 21
  • 95
  • 125
Lee
  • 29,398
  • 28
  • 117
  • 170