| 155 | } |
| 156 | |
| 157 | int main(int argc, char *argv[]) |
| 158 | { |
| 159 | char *json; |
| 160 | size_t i; |
| 161 | jsmn_parser parser; |
| 162 | jsmntok_t toks[5000]; |
| 163 | const jsmntok_t *t, *hops_tok; |
| 164 | struct pubkey *ids; |
| 165 | u8 **enctlvs; |
| 166 | struct privkey path_key; |
| 167 | |
| 168 | common_setup(argv[0]); |
| 169 | |
| 170 | if (argv[1]) |
| 171 | json = grab_file_str(tmpctx, argv[1]); |
| 172 | else { |
| 173 | char *dir = getenv("BOLTDIR"); |
| 174 | json = grab_file_str(tmpctx, |
| 175 | path_join(tmpctx, |
| 176 | dir ? dir : ".tmp.lightningrfc", |
| 177 | "bolt04/route-blinding-test.json")); |
| 178 | if (!json) { |
| 179 | printf("test file not found, skipping\n"); |
| 180 | goto out; |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | jsmn_init(&parser); |
| 185 | if (jsmn_parse(&parser, json, strlen(json), toks, ARRAY_SIZE(toks)) < 0) |
| 186 | abort(); |
| 187 | |
| 188 | hops_tok = json_get_member(json, json_get_member(json, toks, "generate"), "hops"); |
| 189 | ids = tal_arr(tmpctx, struct pubkey, hops_tok->size); |
| 190 | enctlvs = tal_arr(tmpctx, u8 *, hops_tok->size); |
| 191 | |
| 192 | json_for_each_arr(i, t, hops_tok) { |
| 193 | u8 *expected; |
| 194 | assert(json_to_pubkey(json, json_get_member(json, t, "node_id"), |
| 195 | &ids[i])); |
| 196 | enctlvs[i] = json_tok_bin_from_hex(enctlvs, json, |
| 197 | json_get_member(json, t, "encoded_tlvs")); |
| 198 | expected = json_to_enctlvs(tmpctx, json, |
| 199 | json_get_member(json, t, "tlvs")); |
| 200 | assert(tal_arr_eq(expected, enctlvs[i])); |
| 201 | } |
| 202 | |
| 203 | /* Now do the blinding. */ |
| 204 | json_for_each_arr(i, t, hops_tok) { |
| 205 | struct secret s; |
| 206 | struct pubkey pubkey, expected_pubkey; |
| 207 | u8 *enctlv, *expected_enctlv; |
| 208 | struct pubkey alias, expected_alias; |
| 209 | |
| 210 | assert(json_to_secret(json, |
| 211 | json_get_member(json, t, "path_privkey"), |
| 212 | &s)); |
| 213 | |
| 214 | /* First blinding/replacement is stated, remainder are |
nothing calls this directly
no test coverage detected