// Forumer review probe (against lib/forumer_core at cde75b1): persona-index reuse after a restore. // Claim to check: after restoring from the recovery phrase, anonymous posts can be signed by a key that already // signed public posts, or the "current" public persona becomes a former anonymous one. #include "forumer_core/identity.h" #include #include using namespace forumer; static std::string hex(const Bytes& b) { static const char* X = "0123456789abcdef"; std::string s; for (auto c : b) { s += X[c >> 4]; s += X[c & 15]; } return s; } int main() { auto acct = identity::Account::create("alice"); auto pub = acct.personaForPost(identity::Disclosure::Persona); // a public post (persona 0) auto anon1 = acct.personaForPost(identity::Disclosure::Anonymous); // an anonymous post auto anon2 = acct.personaForPost(identity::Disclosure::Anonymous); // another one std::cout << "original device: public persona index " << pub.index << ", anonymous posts used indices " << anon1.index << ", " << anon2.index << "\n"; SecretBytes master = acct.masterSecret(); // New device, phrase restored BEFORE any post has synced (empty local log). std::set none; auto r1 = identity::Account::restore(master, "alice", [&](const Bytes& pk) { return none.count(hex(pk)) > 0; }); auto n1 = r1->personaForPost(identity::Disclosure::Anonymous); std::cout << "Q1 restore with an empty local log: next anonymous post is signed by persona index " << n1.index << (n1.publicKey() == pub.publicKey() ? " == the key of the PUBLIC post (linkable)" : "") << (n1.publicKey() == anon1.publicKey() ? " == the key of an earlier ANONYMOUS post (linkable)" : "") << "\n"; // New device, the public post and the first anonymous post have synced (both are public on the network). std::set known{hex(pub.publicKey()), hex(anon1.publicKey())}; auto r2 = identity::Account::restore(master, "alice", [&](const Bytes& pk) { return known.count(hex(pk)) > 0; }); std::cout << "Q2 restore knowing public(0)+anon(" << anon1.index << "): currentIndex=" << r2->state().currentIndex << " nextIndex=" << r2->state().nextIndex << "; next PUBLIC post is signed by index " << r2->currentPersona().index << (r2->currentPersona().publicKey() == anon1.publicKey() ? " == the former ANONYMOUS key (links public to anonymous)" : "") << "\n"; return 0; }