MCPcopy Create free account
hub / github.com/CommE2E/comm / validateAndGetPrekeys

Method validateAndGetPrekeys

native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp:1061–1147  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1059}
1060
1061jsi::Value CommCoreModule::validateAndGetPrekeys(jsi::Runtime &rt) {
1062 return createPromiseAsJSIValue(
1063 rt, [=](jsi::Runtime &innerRt, std::shared_ptr<Promise> promise) {
1064 taskType job = [=, &innerRt]() {
1065 std::string error;
1066 std::string contentPrekey, notifPrekey, contentPrekeySignature,
1067 notifPrekeySignature;
1068 std::optional<std::string> contentPrekeyBlob;
1069 std::optional<std::string> notifPrekeyBlob;
1070
1071 if (this->contentCryptoModule == nullptr ||
1072 !NotificationsCryptoModule::isNotificationsAccountInitialized()) {
1073 this->jsInvoker_->invokeAsync([=, &innerRt]() {
1074 promise->reject("user has not been initialized");
1075 });
1076 return;
1077 }
1078
1079 std::optional<
1080 std::pair<std::shared_ptr<crypto::CryptoModule>, std::string>>
1081 notifsCryptoModuleWithPicklingKey;
1082 try {
1083 notifsCryptoModuleWithPicklingKey =
1084 NotificationsCryptoModule::fetchNotificationsAccount();
1085 contentPrekeyBlob = this->contentCryptoModule->validatePrekey();
1086 if (!contentPrekeyBlob) {
1087 contentPrekeyBlob =
1088 this->contentCryptoModule->getUnpublishedPrekey();
1089 }
1090 if (!contentPrekeyBlob) {
1091 contentPrekeyBlob = this->contentCryptoModule->getPrekey();
1092 }
1093
1094 notifPrekeyBlob = notifsCryptoModuleWithPicklingKey.value()
1095 .first->validatePrekey();
1096 if (!notifPrekeyBlob) {
1097 notifPrekeyBlob = notifsCryptoModuleWithPicklingKey.value()
1098 .first->getUnpublishedPrekey();
1099 }
1100 if (!notifPrekeyBlob) {
1101 notifPrekeyBlob =
1102 notifsCryptoModuleWithPicklingKey.value().first->getPrekey();
1103 }
1104 this->persistCryptoModules(true, notifsCryptoModuleWithPicklingKey);
1105
1106 contentPrekeySignature =
1107 this->contentCryptoModule->getPrekeySignature();
1108 notifPrekeySignature = notifsCryptoModuleWithPicklingKey.value()
1109 .first->getPrekeySignature();
1110
1111 contentPrekey = contentPrekeyBlob.value();
1112 notifPrekey = notifPrekeyBlob.value();
1113 } catch (const std::exception &e) {
1114 error = e.what();
1115 }
1116
1117 this->jsInvoker_->invokeAsync([=, &innerRt]() {
1118 if (error.size()) {

Callers

nothing calls this directly

Calls 8

persistCryptoModulesMethod · 0.95
rejectMethod · 0.80
validatePrekeyMethod · 0.80
getUnpublishedPrekeyMethod · 0.80
getPrekeyMethod · 0.80
getPrekeySignatureMethod · 0.80
resolveMethod · 0.80
scheduleTaskMethod · 0.80

Tested by

no test coverage detected