MCPcopy Create free account
hub / github.com/ElementsProject/lightning / main

Function main

common/test/run-codex32.c:136–581  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

134}
135
136int main(int argc, char *argv[])
137{
138 common_setup(argv[0]);
139 char *fail, *c;
140 struct codex32 *parts;
141
142 /* Test vector for codex32_secret_encode*/
143 u8 seed_b[32] = {
144 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88,
145 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x00,
146 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88,
147 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x00,
148 };
149
150 assert(codex32_secret_encode(tmpctx, "ms", "leet", 0, seed_b, ARRAY_SIZE(seed_b), &c) == NULL);
151 assert(streq(c,
152 "ms10leetsllhdmn9m42vcsamx24zrxgs3qrl7ahwvhw4fnzrhve25gvezzyqqtum9pgv99ycma"));
153
154 /*
155 * Test vector 1
156 *
157 * This example shows the codex32 format, when used without splitting the secret into any shares. The payload contains 26 bech32 characters, which corresponds to 130 bits. We truncate the last two bits in order to obtain a 128-bit master seed.
158 *
159 * codex32 secret (bech32): ms10testsxxxxxxxxxxxxxxxxxxxxxxxxxx4nzvca9cmczlw
160 *
161 * Master secret (hex): 318c6318c6318c6318c6318c6318c631
162 *
163 * * human-readable part: ms
164 * * separator: 1
165 * * k value: 0 (no secret splitting)
166 * * identifier: test
167 * * share index: s (the secret)
168 * * payload: xxxxxxxxxxxxxxxxxxxxxxxxxx
169 * * checksum: 4nzvca9cmczlw
170 * * master node xprv: xprv9s21ZrQH143K3taPNekMd9oV5K6szJ8ND7vVh6fxicRUMDcChr3bFFzuxY8qP3xFFBL6DWc2uEYCfBFZ2nFWbAqKPhtCLRjgv78EZJDEfpL
171 */
172
173 parts = codex32_decode(tmpctx, NULL, "ms10testsxxxxxxxxxxxxxxxxxxxxxxxxxx4nzvca9cmczlw", &fail);
174 if (parts) {
175 assert(streq(parts->hrp, "ms"));
176 assert(parts->threshold == 0);
177 assert(strcmp(parts->id,"test") == 0);
178 assert(parts->share_idx == 's');
179 assert(streq(tal_hexstr(tmpctx, parts->payload, tal_bytelen(parts->payload)),
180 "318c6318c6318c6318c6318c6318c631"));
181 print_cl_vec("Test vector 1", parts);
182 } else {
183 abort();
184 }
185 tal_free(parts);
186
187 /*
188 * Test vector 2
189 * This example shows generating a new master seed using "random" codex32 shares, as well as deriving an additional codex32 share, using k=2 and an identifier of NAME. Although codex32 strings are canonically all lowercase, it's also valid to use all uppercase.
190 *
191 * Share with index A: MS12NAMEA320ZYXWVUTSRQPNMLKJHGFEDCAXRPP870HKKQRM
192 *
193 * Share with index C: MS12NAMECACDEFGHJKLMNPQRSTUVWXYZ023FTR2GDZMPY6PN

Callers

nothing calls this directly

Calls 9

common_setupFunction · 0.85
codex32_secret_encodeFunction · 0.85
codex32_decodeFunction · 0.85
tal_hexstrFunction · 0.85
tal_bytelenFunction · 0.85
print_cl_vecFunction · 0.85
abortFunction · 0.85
tal_freeFunction · 0.85
common_shutdownFunction · 0.85

Tested by

no test coverage detected