-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic.cpp
More file actions
49 lines (39 loc) · 1.8 KB
/
Copy pathbasic.cpp
File metadata and controls
49 lines (39 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Minimal smoke test exercising the public mhda API.
#include <iostream>
#include "mhda/mhda.hpp"
int main() {
using namespace mhda;
// Lenient parsing: structural validation only.
auto addr = parse_urn("urn:mhda:nt:evm:ci:1");
std::cout << "network : " << addr.get_chain().network().str() << "\n";
std::cout << "algorithm : " << addr.resolved_algorithm().str() << "\n";
std::cout << "format : " << addr.resolved_format().str() << "\n";
// Strict parsing rejects nonsensical (network, algorithm, format) combos.
try {
parse_urn_strict("urn:mhda:nt:evm:ci:1:aa:ed25519");
} catch (const parse_error& e) {
if (e.code() == error_code::incompatible) {
std::cout << "evm + ed25519 rejected, as expected\n";
}
}
// Type-agnostic level-by-level path inspection.
auto bip = parse_urn("urn:mhda:nt:evm:ci:1:dt:bip44:dp:m/44'/60'/0'/0/0");
int i = 0;
for (const auto& lvl : bip.path()->levels()) {
std::cout << "level[" << i++ << "] = " << lvl.index
<< (lvl.is_hardened ? " (hardened)" : "") << "\n";
}
// Hashing for content-addressing or deduplication.
std::cout << "sha256 : " << bip.hash256() << "\n";
// The chain identity (nt, ci) is itself a parseable key. Keys never carry
// the optional ct metadata; a pre-1.1 key with ct fails loudly with
// error_code::coin_type_in_chain_key.
auto key = bip.get_chain().key();
auto parsed = chain::from_key(key);
std::cout << "chain key : " << parsed.str() << "\n";
// Optional wallet context: client type + wallet instance id.
auto wallet = parse_urn("urn:mhda:nt:evm:ci:1:wt:web3:wi:5f2a8c31");
std::cout << "wallet : " << wallet.wallet_type()
<< " " << wallet.wallet_id() << "\n";
return 0;
}