]> Untitled Git - bitcoindevkit.org/blob
6295f75adc38bf3bffabf2534b0d8daf96571855
[bitcoindevkit.org] /
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-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.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-9960930a.css"><link rel="stylesheet" href="../../../../../static.files/rustdoc-46132b98.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.85.0-nightly (4ba4ac612 2024-12-18)" data-channel="nightly" data-search-js="search-036cda7a.js" data-settings-js="settings-0f613d39.js" ><script src="../../../../../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../../../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../../../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../../../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../../../../static.files/favicon-044be391.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_<wbr>chain</a><span class="version">0.21.1</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Checksum</a></h2><h3><a href="#required-associated-consts">Required Associated Constants</a></h3><ul class="block"><li><a href="#associatedconstant.CHECKSUM_LENGTH" title="CHECKSUM_LENGTH">CHECKSUM_LENGTH</a></li><li><a href="#associatedconstant.CODE_LENGTH" title="CODE_LENGTH">CODE_LENGTH</a></li><li><a href="#associatedconstant.GENERATOR_SH" title="GENERATOR_SH">GENERATOR_SH</a></li><li><a href="#associatedconstant.TARGET_RESIDUE" title="TARGET_RESIDUE">TARGET_RESIDUE</a></li></ul><h3><a href="#required-associated-types">Required Associated Types</a></h3><ul class="block"><li><a href="#associatedtype.MidstateRepr" title="MidstateRepr">MidstateRepr</a></li></ul><h3><a href="#provided-methods">Provided Methods</a></h3><ul class="block"><li><a href="#method.sanity_check" title="sanity_check">sanity_check</a></li></ul><h3><a href="#dyn-compatibility">Dyn Compatibility</a></h3><h3><a href="#implementors">Implementors</a></h3></section><div id="rustdoc-modnav"><h2><a href="index.html">In bdk_<wbr>chain::<wbr>bitcoin::<wbr>bech32::<wbr>primitives::<wbr>checksum</a></h2></div></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"><span class="rustdoc-breadcrumbs"><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></span><h1>Trait <span class="trait">Checksum</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"></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>;
3
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>;
8
9 // Provided method
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-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>
15 <p>The length of the code is how long a coded message can be (including the
16 checksum!) for the code to retain its error-correcting properties.</p>
17 </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>
18 <p>Alternately, the degree of the generator polynomial. This is <strong>not</strong> the same
19 as <code>Self::CODE_LENGTH</code>.</p>
20 </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,
21 in “big-endian” (highest-degree coefficients get leftmost bits) order, along
22 with the 4 shifts of the generator.</p>
23 <p>The shifts are literally the generator polynomial left-shifted (i.e. multiplied
24 by the appropriate power of 2) in the field. That is, the 5 entries in this
25 array are the generator times { P, Z, Y, G, S } in that order.</p>
26 <p>These cannot be usefully pre-computed because of Rust’s limited constfn support
27 as of 1.67, so they must be specified manually for each checksum. To check the
28 values for consistency, run <code>Self::sanity_check()</code>.</p>
29 </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>
30 </div></details></div><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
31 polynomial (without its leading 1) and target residue (which will have the
32 same width).</p>
33 <p>Generally, this is the number of characters in the checksum times 5. So e.g.
34 for bech32, which has a 6-character checksum, we need 30 bits, so we can use
35 u32 here.</p>
36 <p>The smallest type possible should be used, for efficiency reasons, but the
37 only operations we do on these types are bitwise xor and shifts, so it should
38 be pretty efficient no matter what.</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="dyn-compatibility" class="section-header">Dyn Compatibility<a href="#dyn-compatibility" class="anchor">§</a></h2><div class="dyn-compatibility-info"><p>This trait is <b>not</b> <a href="https://doc.rust-lang.org/nightly/reference/items/traits.html#object-safety">dyn compatible</a>.</p><p><i>In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.</i></p></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="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><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></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="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><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></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="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><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></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>