<p>You can take a look at the file <code>bitcoin/test/functional/test_framework/descriptors.py</code>, there  is a function to create the checksum:</p>
<pre><code>def descsum_create(s):
    &quot;&quot;&quot;Add a checksum to a descriptor without&quot;&quot;&quot;
    symbols = descsum_expand(s) + [0, 0, 0, 0, 0, 0, 0, 0]
    checksum = descsum_polymod(symbols) ^ 1
    return s + '#' + ''.join(CHECKSUM_CHARSET[(checksum &gt;&gt; (5 * (7 - i))) &amp; 31] for i in range(8))
</code></pre>
<p>It has dependencies to  <code>descsum_expand</code> and <code>descsum_polymod</code> but both are included in the same file.</p>
<p>Here is the Python code you will need:</p>
<pre><code>from test_framework.descriptors import descsum_create

descriptor = 'addr(mkmZxiEcEd8ZqjQWVZuC6so5dFMKEFpN2j)'

descriptor_with_checksum = descsum_create(descriptor)
print(descriptor_with_checksum)
</code></pre>
<p>result:</p>
<p><code>addr(mkmZxiEcEd8ZqjQWVZuC6so5dFMKEFpN2j)#02wpgw69</code></p>

CC BY-SA 4.0
2022-03-08T16:15:17.690Z
2024-09-13T12:42:11.283Z
2024-09-13T12:42:11.283Z
Bitcoin_1o1
<p>In the docs it says: <code>The checksum for a descriptor without one can be computed using the getdescriptorinfo RPC.</code></p>
<p>I would like to build a recovery tool where many descriptors are imported, calling <code>getdescriptorinfo</code> for each is cumbersome. Manually calculating the checksum would save a lot of time and network calls.</p>
<p>Do I just double sha256 the entire descriptor and convert the first 4 bytes to hex?</p>
<p>Thanks :)</p>
<p>EDIT: I found this, seems quite a bit more complex than a double hash... <a href="https://github.com/bitcoin/bitcoin/blob/master/src/script/descriptor.cpp#L95" rel="nofollow noreferrer">https://github.com/bitcoin/bitcoin/blob/master/src/script/descriptor.cpp#L95</a></p>

<bitcoin-core><json-rpc><bitcoin-cli><output-script-descriptors><checksum>
How to manually compute a descriptors checksum?
Fontaine
# How to manually compute a descriptors checksum?

(Asked by: username_0 on 2020-06-29)

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>

**Tags:** bitcoin-core, json-rpc, bitcoin-cli, output-script-descriptors, checksum


---

## 1 answers

### Answer by username_1 on 2022-03-08. Score: 1

You can take a look at the file `bitcoin/test/functional/test_framework/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`


---

