1 <!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Trait defining a particular checksum."><title>Checksum in bdk_chain::bitcoin::bech32::primitives::checksum - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-46f98efaafac5295.ttf.woff2,FiraSans-Regular-018c141bf0843ffd.woff2,FiraSans-Medium-8f9a781e4970d388.woff2,SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2,SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../../../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../../../../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../../../../../static.files/rustdoc-dd39b87e5fcfba68.css"><meta name="rustdoc-vars" data-root-path="../../../../../" data-static-root-path="../../../../../static.files/" data-current-crate="bdk_chain" data-themes="" data-resource-suffix="" data-rustdoc-version="1.80.0-nightly (78a775127 2024-05-11)" data-channel="nightly" data-search-js="search-d52510db62a78183.js" data-settings-js="settings-4313503d2e1961c2.js" ><script src="../../../../../static.files/storage-118b08c4c78b968e.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../../../../static.files/main-20a3ad099b048cf2.js"></script><noscript><link rel="stylesheet" href="../../../../../static.files/noscript-df360f571f6edeae.css"></noscript><link rel="alternate icon" type="image/png" href="../../../../../static.files/favicon-32x32-422f7d1d52889060.png"><link rel="icon" type="image/svg+xml" href="../../../../../static.files/favicon-2c020d218678b618.svg"></head><body class="rustdoc trait"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button><a class="logo-container" href="../../../../../bdk_chain/index.html"><img src="https://github.com/bitcoindevkit/bdk/raw/master/static/bdk.png" alt=""></a></nav><nav class="sidebar"><div class="sidebar-crate"><a class="logo-container" href="../../../../../bdk_chain/index.html"><img src="https://github.com/bitcoindevkit/bdk/raw/master/static/bdk.png" alt="logo"></a><h2><a href="../../../../../bdk_chain/index.html">bdk_chain</a><span class="version">0.20.0</span></h2></div><h2 class="location"><a href="#">Checksum</a></h2><div class="sidebar-elems"><section><h3><a href="#required-associated-types">Required Associated Types</a></h3><ul class="block"><li><a href="#associatedtype.MidstateRepr">MidstateRepr</a></li></ul><h3><a href="#required-associated-consts">Required Associated Constants</a></h3><ul class="block"><li><a href="#associatedconstant.CHECKSUM_LENGTH">CHECKSUM_LENGTH</a></li><li><a href="#associatedconstant.CODE_LENGTH">CODE_LENGTH</a></li><li><a href="#associatedconstant.GENERATOR_SH">GENERATOR_SH</a></li><li><a href="#associatedconstant.TARGET_RESIDUE">TARGET_RESIDUE</a></li></ul><h3><a href="#provided-methods">Provided Methods</a></h3><ul class="block"><li><a href="#method.sanity_check">sanity_check</a></li></ul><h3><a href="#object-safety">Object Safety</a></h3><h3><a href="#implementors">Implementors</a></h3></section><h2><a href="index.html">In bdk_chain::bitcoin::bech32::primitives::checksum</a></h2></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><h1>Trait <a href="../../../../index.html">bdk_chain</a>::<wbr><a href="../../../index.html">bitcoin</a>::<wbr><a href="../../index.html">bech32</a>::<wbr><a href="../index.html">primitives</a>::<wbr><a href="index.html">checksum</a>::<wbr><a class="trait" href="#">Checksum</a><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><span class="out-of-band"><button id="toggle-all-docs" title="collapse all docs">[<span>−</span>]</button></span></div><pre class="rust item-decl"><code>pub trait Checksum {
2 type <a href="#associatedtype.MidstateRepr" class="associatedtype">MidstateRepr</a>: <a class="trait" href="trait.PackedFe32.html" title="trait bdk_chain::bitcoin::bech32::primitives::checksum::PackedFe32">PackedFe32</a>;
4 const <a href="#associatedconstant.CODE_LENGTH" class="constant">CODE_LENGTH</a>: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>;
5 const <a href="#associatedconstant.CHECKSUM_LENGTH" class="constant">CHECKSUM_LENGTH</a>: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>;
6 const <a href="#associatedconstant.GENERATOR_SH" class="constant">GENERATOR_SH</a>: [Self::<a class="associatedtype" href="../../trait.Checksum.html#associatedtype.MidstateRepr" title="type bdk_chain::bitcoin::bech32::Checksum::MidstateRepr">MidstateRepr</a>; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.array.html">5</a>];
7 const <a href="#associatedconstant.TARGET_RESIDUE" class="constant">TARGET_RESIDUE</a>: Self::<a class="associatedtype" href="../../trait.Checksum.html#associatedtype.MidstateRepr" title="type bdk_chain::bitcoin::bech32::Checksum::MidstateRepr">MidstateRepr</a>;
10 fn <a href="#method.sanity_check" class="fn">sanity_check</a>() { ... }
11 }</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Trait defining a particular checksum.</p>
12 <p>For users, this can be treated as a marker trait; none of the associated data
13 are end-user relevant.</p>
14 </div></details><h2 id="required-associated-types" class="section-header">Required Associated Types<a href="#required-associated-types" class="anchor">§</a></h2><div class="methods"><details class="toggle" open><summary><section id="associatedtype.MidstateRepr" class="method"><h4 class="code-header">type <a href="#associatedtype.MidstateRepr" class="associatedtype">MidstateRepr</a>: <a class="trait" href="trait.PackedFe32.html" title="trait bdk_chain::bitcoin::bech32::primitives::checksum::PackedFe32">PackedFe32</a></h4></section></summary><div class="docblock"><p>An unsigned integer type capable of holding a packed version of the generator
15 polynomial (without its leading 1) and target residue (which will have the
17 <p>Generally, this is the number of characters in the checksum times 5. So e.g.
18 for bech32, which has a 6-character checksum, we need 30 bits, so we can use
20 <p>The smallest type possible should be used, for efficiency reasons, but the
21 only operations we do on these types are bitwise xor and shifts, so it should
22 be pretty efficient no matter what.</p>
23 </div></details></div><h2 id="required-associated-consts" class="section-header">Required Associated Constants<a href="#required-associated-consts" class="anchor">§</a></h2><div class="methods"><details class="toggle" open><summary><section id="associatedconstant.CODE_LENGTH" class="method"><h4 class="code-header">const <a href="#associatedconstant.CODE_LENGTH" class="constant">CODE_LENGTH</a>: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a></h4></section></summary><div class="docblock"><p>The length of the code.</p>
24 <p>The length of the code is how long a coded message can be (including the
25 checksum!) for the code to retain its error-correcting properties.</p>
26 </div></details><details class="toggle" open><summary><section id="associatedconstant.CHECKSUM_LENGTH" class="method"><h4 class="code-header">const <a href="#associatedconstant.CHECKSUM_LENGTH" class="constant">CHECKSUM_LENGTH</a>: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a></h4></section></summary><div class="docblock"><p>The number of characters in the checksum.</p>
27 <p>Alternately, the degree of the generator polynomial. This is <strong>not</strong> the same
28 as <code>Self::CODE_LENGTH</code>.</p>
29 </div></details><details class="toggle" open><summary><section id="associatedconstant.GENERATOR_SH" class="method"><h4 class="code-header">const <a href="#associatedconstant.GENERATOR_SH" class="constant">GENERATOR_SH</a>: [Self::<a class="associatedtype" href="../../trait.Checksum.html#associatedtype.MidstateRepr" title="type bdk_chain::bitcoin::bech32::Checksum::MidstateRepr">MidstateRepr</a>; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.array.html">5</a>]</h4></section></summary><div class="docblock"><p>The coefficients of the generator polynomial, except the leading monic term,
30 in “big-endian” (highest-degree coefficients get leftmost bits) order, along
31 with the 4 shifts of the generator.</p>
32 <p>The shifts are literally the generator polynomial left-shifted (i.e. multiplied
33 by the appropriate power of 2) in the field. That is, the 5 entries in this
34 array are the generator times { P, Z, Y, G, S } in that order.</p>
35 <p>These cannot be usefully pre-computed because of Rust’s limited constfn support
36 as of 1.67, so they must be specified manually for each checksum. To check the
37 values for consistency, run <code>Self::sanity_check()</code>.</p>
38 </div></details><details class="toggle" open><summary><section id="associatedconstant.TARGET_RESIDUE" class="method"><h4 class="code-header">const <a href="#associatedconstant.TARGET_RESIDUE" class="constant">TARGET_RESIDUE</a>: Self::<a class="associatedtype" href="../../trait.Checksum.html#associatedtype.MidstateRepr" title="type bdk_chain::bitcoin::bech32::Checksum::MidstateRepr">MidstateRepr</a></h4></section></summary><div class="docblock"><p>The residue, modulo the generator polynomial, that a valid codeword will have.</p>
39 </div></details></div><h2 id="provided-methods" class="section-header">Provided Methods<a href="#provided-methods" class="anchor">§</a></h2><div class="methods"><details class="toggle method-toggle" open><summary><section id="method.sanity_check" class="method"><h4 class="code-header">fn <a href="#method.sanity_check" class="fn">sanity_check</a>()</h4></section></summary><div class="docblock"><p>Sanity checks that the various constants of the trait are set in a way that they
40 are consistent with each other.</p>
41 <p>This function never needs to be called by users, but anyone defining a checksum
42 should add a unit test to their codebase which calls this.</p>
43 </div></details></div><h2 id="object-safety" class="section-header">Object Safety<a href="#object-safety" class="anchor">§</a></h2><div class="object-safety-info">This trait is <b>not</b> <a href="https://doc.rust-lang.org/nightly/reference/items/traits.html#object-safety">object safe</a>.</div><h2 id="implementors" class="section-header">Implementors<a href="#implementors" class="anchor">§</a></h2><div id="implementors-list"><details class="toggle implementors-toggle"><summary><section id="impl-Checksum-for-Bech32" class="impl"><a href="#impl-Checksum-for-Bech32" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="../../trait.Checksum.html" title="trait bdk_chain::bitcoin::bech32::Checksum">Checksum</a> for <a class="enum" href="../../enum.Bech32.html" title="enum bdk_chain::bitcoin::bech32::Bech32">Bech32</a></h3></section></summary><div class="impl-items"><section id="associatedtype.MidstateRepr-1" class="associatedtype trait-impl"><a href="#associatedtype.MidstateRepr-1" class="anchor">§</a><h4 class="code-header">type <a href="#associatedtype.MidstateRepr" class="associatedtype">MidstateRepr</a> = <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a></h4></section><section id="associatedconstant.CODE_LENGTH-1" class="associatedconstant trait-impl"><a href="#associatedconstant.CODE_LENGTH-1" class="anchor">§</a><h4 class="code-header">const <a href="#associatedconstant.CODE_LENGTH" class="constant">CODE_LENGTH</a>: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a> = 1_023usize</h4></section><section id="associatedconstant.CHECKSUM_LENGTH-1" class="associatedconstant trait-impl"><a href="#associatedconstant.CHECKSUM_LENGTH-1" class="anchor">§</a><h4 class="code-header">const <a href="#associatedconstant.CHECKSUM_LENGTH" class="constant">CHECKSUM_LENGTH</a>: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a> = 6usize</h4></section><section id="associatedconstant.GENERATOR_SH-1" class="associatedconstant trait-impl"><a href="#associatedconstant.GENERATOR_SH-1" class="anchor">§</a><h4 class="code-header">const <a href="#associatedconstant.GENERATOR_SH" class="constant">GENERATOR_SH</a>: [<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.array.html">5</a>] = GEN</h4></section><section id="associatedconstant.TARGET_RESIDUE-1" class="associatedconstant trait-impl"><a href="#associatedconstant.TARGET_RESIDUE-1" class="anchor">§</a><h4 class="code-header">const <a href="#associatedconstant.TARGET_RESIDUE" class="constant">TARGET_RESIDUE</a>: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a> = 1u32</h4></section></div></details><details class="toggle implementors-toggle"><summary><section id="impl-Checksum-for-Bech32m" class="impl"><a href="#impl-Checksum-for-Bech32m" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="../../trait.Checksum.html" title="trait bdk_chain::bitcoin::bech32::Checksum">Checksum</a> for <a class="enum" href="../../enum.Bech32m.html" title="enum bdk_chain::bitcoin::bech32::Bech32m">Bech32m</a></h3></section></summary><div class="impl-items"><section id="associatedtype.MidstateRepr-2" class="associatedtype trait-impl"><a href="#associatedtype.MidstateRepr-2" class="anchor">§</a><h4 class="code-header">type <a href="#associatedtype.MidstateRepr" class="associatedtype">MidstateRepr</a> = <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a></h4></section><section id="associatedconstant.CODE_LENGTH-2" class="associatedconstant trait-impl"><a href="#associatedconstant.CODE_LENGTH-2" class="anchor">§</a><h4 class="code-header">const <a href="#associatedconstant.CODE_LENGTH" class="constant">CODE_LENGTH</a>: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a> = 1_023usize</h4></section><section id="associatedconstant.CHECKSUM_LENGTH-2" class="associatedconstant trait-impl"><a href="#associatedconstant.CHECKSUM_LENGTH-2" class="anchor">§</a><h4 class="code-header">const <a href="#associatedconstant.CHECKSUM_LENGTH" class="constant">CHECKSUM_LENGTH</a>: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a> = 6usize</h4></section><section id="associatedconstant.GENERATOR_SH-2" class="associatedconstant trait-impl"><a href="#associatedconstant.GENERATOR_SH-2" class="anchor">§</a><h4 class="code-header">const <a href="#associatedconstant.GENERATOR_SH" class="constant">GENERATOR_SH</a>: [<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.array.html">5</a>] = GEN</h4></section><section id="associatedconstant.TARGET_RESIDUE-2" class="associatedconstant trait-impl"><a href="#associatedconstant.TARGET_RESIDUE-2" class="anchor">§</a><h4 class="code-header">const <a href="#associatedconstant.TARGET_RESIDUE" class="constant">TARGET_RESIDUE</a>: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a> = 734_539_939u32</h4></section></div></details><details class="toggle implementors-toggle"><summary><section id="impl-Checksum-for-NoChecksum" class="impl"><a href="#impl-Checksum-for-NoChecksum" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="../../trait.Checksum.html" title="trait bdk_chain::bitcoin::bech32::Checksum">Checksum</a> for <a class="enum" href="../../enum.NoChecksum.html" title="enum bdk_chain::bitcoin::bech32::NoChecksum">NoChecksum</a></h3></section></summary><div class="impl-items"><section id="associatedtype.MidstateRepr-3" class="associatedtype trait-impl"><a href="#associatedtype.MidstateRepr-3" class="anchor">§</a><h4 class="code-header">type <a href="#associatedtype.MidstateRepr" class="associatedtype">MidstateRepr</a> = <a class="struct" href="struct.PackedNull.html" title="struct bdk_chain::bitcoin::bech32::primitives::checksum::PackedNull">PackedNull</a></h4></section><section id="associatedconstant.CODE_LENGTH-3" class="associatedconstant trait-impl"><a href="#associatedconstant.CODE_LENGTH-3" class="anchor">§</a><h4 class="code-header">const <a href="#associatedconstant.CODE_LENGTH" class="constant">CODE_LENGTH</a>: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a> = 18_446_744_073_709_551_615usize</h4></section><section id="associatedconstant.CHECKSUM_LENGTH-3" class="associatedconstant trait-impl"><a href="#associatedconstant.CHECKSUM_LENGTH-3" class="anchor">§</a><h4 class="code-header">const <a href="#associatedconstant.CHECKSUM_LENGTH" class="constant">CHECKSUM_LENGTH</a>: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a> = 0usize</h4></section><section id="associatedconstant.GENERATOR_SH-3" class="associatedconstant trait-impl"><a href="#associatedconstant.GENERATOR_SH-3" class="anchor">§</a><h4 class="code-header">const <a href="#associatedconstant.GENERATOR_SH" class="constant">GENERATOR_SH</a>: [<a class="struct" href="struct.PackedNull.html" title="struct bdk_chain::bitcoin::bech32::primitives::checksum::PackedNull">PackedNull</a>; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.array.html">5</a>] = _</h4></section><section id="associatedconstant.TARGET_RESIDUE-3" class="associatedconstant trait-impl"><a href="#associatedconstant.TARGET_RESIDUE-3" class="anchor">§</a><h4 class="code-header">const <a href="#associatedconstant.TARGET_RESIDUE" class="constant">TARGET_RESIDUE</a>: <a class="struct" href="struct.PackedNull.html" title="struct bdk_chain::bitcoin::bech32::primitives::checksum::PackedNull">PackedNull</a> = PackedNull</h4></section></div></details></div><script src="../../../../../trait.impl/bech32/primitives/checksum/trait.Checksum.js" data-ignore-extern-crates="bech32" async></script></section></div></main></body></html>