@@ -82,13 +82,23 @@ namespace convo {
8282 c.unread = unread;
8383 }
8484
85- blinded_one_to_one::blinded_one_to_one (std::string&& sid, bool legacy_blinding) :
86- blinded_session_id{std::move (sid)}, legacy_blinding{legacy_blinding} {
87- check_session_id (blinded_session_id, legacy_blinding ? " 15" : " 25" );
85+ blinded_one_to_one::blinded_one_to_one (std::string&& sid) : blinded_session_id{std::move (sid)} {
86+ auto prefix = get_session_id_prefix (blinded_session_id);
87+ legacy_blinding = (prefix == session::SessionIDPrefix::community_blinded_legacy);
88+
89+ if (prefix != session::SessionIDPrefix::community_blinded &&
90+ prefix != session::SessionIDPrefix::community_blinded_legacy)
91+ throw std::invalid_argument{
92+ " Invalid blinded ID: Expected '15' or '25' prefix; got " + blinded_session_id};
8893 }
89- blinded_one_to_one::blinded_one_to_one (std::string_view sid, bool legacy_blinding) :
90- blinded_session_id{sid}, legacy_blinding{legacy_blinding} {
91- check_session_id (blinded_session_id, legacy_blinding ? " 15" : " 25" );
94+ blinded_one_to_one::blinded_one_to_one (std::string_view sid) : blinded_session_id{sid} {
95+ auto prefix = get_session_id_prefix (blinded_session_id);
96+ legacy_blinding = (prefix == session::SessionIDPrefix::community_blinded_legacy);
97+
98+ if (prefix != session::SessionIDPrefix::community_blinded &&
99+ prefix != session::SessionIDPrefix::community_blinded_legacy)
100+ throw std::invalid_argument{
101+ " Invalid blinded ID: Expected '15' or '25' prefix; got " + blinded_session_id};
92102 }
93103 blinded_one_to_one::blinded_one_to_one (const convo_info_volatile_blinded_1to1& c) :
94104 base{c.last_read , c.unread },
@@ -234,25 +244,31 @@ convo::legacy_group ConvoInfoVolatile::get_or_construct_legacy_group(
234244}
235245
236246std::optional<convo::blinded_one_to_one> ConvoInfoVolatile::get_blinded_1to1 (
237- std::string_view pubkey_hex, bool legacy_blinding) const {
238- std::string pubkey = session_id_to_bytes (pubkey_hex, legacy_blinding ? " 15" : " 25" );
247+ std::string_view pubkey_hex) const {
248+ auto prefix = get_session_id_prefix (pubkey_hex);
249+
250+ if (prefix != session::SessionIDPrefix::community_blinded &&
251+ prefix != session::SessionIDPrefix::community_blinded_legacy)
252+ throw std::invalid_argument{
253+ " Invalid blinded ID: Expected '15' or '25' prefix; got " + std::string{pubkey_hex}};
254+
255+ std::string pubkey = session_id_to_bytes (pubkey_hex, to_string (prefix));
239256
240257 auto * info_dict = data[" b" ][pubkey].dict ();
241258 if (!info_dict)
242259 return std::nullopt ;
243260
244- auto result =
245- std::make_optional<convo::blinded_one_to_one>(std::string{pubkey_hex}, legacy_blinding);
261+ auto result = std::make_optional<convo::blinded_one_to_one>(std::string{pubkey_hex});
246262 result->load (*info_dict);
247263 return result;
248264}
249265
250266convo::blinded_one_to_one ConvoInfoVolatile::get_or_construct_blinded_1to1 (
251- std::string_view pubkey_hex, bool legacy_blinding ) const {
252- if (auto maybe = get_blinded_1to1 (pubkey_hex, legacy_blinding ))
267+ std::string_view pubkey_hex) const {
268+ if (auto maybe = get_blinded_1to1 (pubkey_hex))
253269 return *std::move (maybe);
254270
255- return convo::blinded_one_to_one{std::string{pubkey_hex}, legacy_blinding };
271+ return convo::blinded_one_to_one{std::string{pubkey_hex}};
256272}
257273
258274void ConvoInfoVolatile::set (const convo::one_to_one& c) {
@@ -386,9 +402,8 @@ bool ConvoInfoVolatile::erase_group(std::string_view id) {
386402bool ConvoInfoVolatile::erase_legacy_group (std::string_view id) {
387403 return erase (convo::legacy_group{id});
388404}
389- bool ConvoInfoVolatile::erase_blinded_1to1 (
390- std::string_view blinded_session_id, bool legacy_blinding) {
391- return erase (convo::blinded_one_to_one{blinded_session_id, legacy_blinding});
405+ bool ConvoInfoVolatile::erase_blinded_1to1 (std::string_view blinded_session_id) {
406+ return erase (convo::blinded_one_to_one{blinded_session_id});
392407}
393408
394409size_t ConvoInfoVolatile::size_1to1 () const {
@@ -489,11 +504,7 @@ class val_loader {
489504
490505 if (k.size () == 33 && (k[0 ] == prefix || (legacy_prefix && k[0 ] == *legacy_prefix))) {
491506 if (auto * info_dict = std::get_if<dict>(&v)) {
492- if constexpr (std::is_same_v<ConvoType, convo::blinded_one_to_one>)
493- val = std::make_shared<convo::any>(ConvoType{
494- oxenc::to_hex (k), (legacy_prefix && k[0 ] == *legacy_prefix)});
495- else
496- val = std::make_shared<convo::any>(ConvoType{oxenc::to_hex (k)});
507+ val = std::make_shared<convo::any>(ConvoType{oxenc::to_hex (k)});
497508 std::get<ConvoType>(*val).load (*info_dict);
498509 return true ;
499510 }
@@ -693,13 +704,11 @@ LIBSESSION_C_API bool convo_info_volatile_get_or_construct_legacy_group(
693704LIBSESSION_C_API bool convo_info_volatile_get_blinded_1to1 (
694705 config_object* conf,
695706 convo_info_volatile_blinded_1to1* convo,
696- const char * blinded_session_id,
697- bool legacy_blinding) {
707+ const char * blinded_session_id) {
698708 return wrap_exceptions (
699709 conf,
700710 [&] {
701- if (auto c = unbox<ConvoInfoVolatile>(conf)->get_blinded_1to1 (
702- blinded_session_id, legacy_blinding)) {
711+ if (auto c = unbox<ConvoInfoVolatile>(conf)->get_blinded_1to1 (blinded_session_id)) {
703712 c->into (*convo);
704713 return true ;
705714 }
@@ -711,13 +720,12 @@ LIBSESSION_C_API bool convo_info_volatile_get_blinded_1to1(
711720LIBSESSION_C_API bool convo_info_volatile_get_or_construct_blinded_1to1 (
712721 config_object* conf,
713722 convo_info_volatile_blinded_1to1* convo,
714- const char * blinded_session_id,
715- bool legacy_blinding) {
723+ const char * blinded_session_id) {
716724 return wrap_exceptions (
717725 conf,
718726 [&] {
719727 unbox<ConvoInfoVolatile>(conf)
720- ->get_or_construct_blinded_1to1 (blinded_session_id, legacy_blinding )
728+ ->get_or_construct_blinded_1to1 (blinded_session_id)
721729 .into (*convo);
722730 return true ;
723731 },
@@ -799,13 +807,10 @@ LIBSESSION_C_API bool convo_info_volatile_erase_legacy_group(
799807 false );
800808}
801809LIBSESSION_C_API bool convo_info_volatile_erase_blinded_1to1 (
802- config_object* conf, const char * blinded_session_id, bool legacy_blinding ) {
810+ config_object* conf, const char * blinded_session_id) {
803811 return wrap_exceptions (
804812 conf,
805- [&] {
806- return unbox<ConvoInfoVolatile>(conf)->erase_blinded_1to1 (
807- blinded_session_id, legacy_blinding);
808- },
813+ [&] { return unbox<ConvoInfoVolatile>(conf)->erase_blinded_1to1 (blinded_session_id); },
809814 false );
810815}
811816
0 commit comments