2

In the docs it says: The checksum for a descriptor without one can be computed using the getdescriptorinfo RPC.

I would like to build a recovery tool where many descriptors are imported, calling getdescriptorinfo for each is cumbersome. Manually calculating the checksum would save a lot of time and network calls.

Do I just double sha256 the entire descriptor and convert the first 4 bytes to hex?

Thanks :)

EDIT: I found this, seems quite a bit more complex than a double hash... https://github.com/bitcoin/bitcoin/blob/master/src/script/descriptor.cpp#L95

Michael Folkson
  • 14,337
  • 3
  • 11
  • 45
Fontaine
  • 466
  • 2
  • 10

1 Answers1

1

You can take a look at the file bitcoin/test/functional/descriptors.py, there is a function to create the checksum:

def descsum_create(s):
    """Add a checksum to a descriptor without"""
    symbols = descsum_expand(s) + [0, 0, 0, 0, 0, 0, 0, 0]
    checksum = descsum_polymod(symbols) ^ 1
    return s + '#' + ''.join(CHECKSUM_CHARSET[(checksum >> (5 * (7 - i))) & 31] for i in range(8))

It has dependencies to descsum_expand and descsum_polymod but both are included in the same file.

Here is the Python code you will need:

from test_framework.descriptors import descsum_create

descriptor = 'addr(mkmZxiEcEd8ZqjQWVZuC6so5dFMKEFpN2j)'

descriptor_with_checksum = descsum_create(descriptor)
print(descriptor_with_checksum)

result:

addr(mkmZxiEcEd8ZqjQWVZuC6so5dFMKEFpN2j)#02wpgw69

Bitcoin_1o1
  • 343
  • 1
  • 12