render_example_test.gno
1.67 Kb · 46 lines
1package bech32demo
2
3// ExampleRender pins the realm's Render output as a testable example. The
4// vectors are BIP-173's and BIP-350's, so this doubles as a conformance test,
5// and the last table is the length-extension weakness reproduced in full.
6func ExampleRender() {
7 print(Render(""))
8 // Output:
9 // # Bech32
10 //
11 // Addresses that carry their own error-detecting checksum, demoing the [`p/moul/x/daily/bech32`](/p/moul/x/daily/bech32/v0) library.
12 //
13 // ## A gno.land address, taken apart
14 //
15 // Decoding g1manfred47kzduec920z88wfr64ylksmdcedlf5:
16 //
17 // | field | value |
18 // | --- | --- |
19 // | human-readable part | g |
20 // | variant | bech32 |
21 // | payload | 20 bytes |
22 // | payload (hex) | `df6691e5b5f584de670553c473b923d549fb436d` |
23 //
24 // ## The two variants
25 //
26 // Same string shape, same data, different checksum constant: `1` for Bech32, `0x2bc830a3` for Bech32m.
27 //
28 // | Bech32 (BIP-173) | Bech32m (BIP-350) |
29 // | --- | --- |
30 // | `a12uel5l` | `a1lqfn3a` |
31 // | `?1ezyfcl` | `?1v759aa` |
32 // | `split1checkupstagehandshakeupstreamerranterredcaperred2y9e3w` | `split1checkupstagehandshakeupstreamerranterredcaperredlc445v` |
33 //
34 // ## Why Bech32m exists
35 //
36 // A Bech32 string ending in `p` keeps a valid checksum when `q` characters are inserted in front of that final `p`, so a reader accepts a string nobody wrote. Bech32m's constant closes it:
37 //
38 // | string | variant | verdict |
39 // | --- | --- | --- |
40 // | `a1q3g6mnsp` | bech32 | accepted |
41 // | `a1q3g6mnsqp` | bech32 | accepted |
42 // | `a1q6dp699p` | bech32m | accepted |
43 // | `a1q6dp699qp` | - | rejected: bech32: bad checksum |
44 //
45 // Pass a string of your own to decode it: `Render("/<bech32 string>")`.
46}