Skip to content

Commit

Permalink
[native] remove device ID getter and setter functions
Browse files Browse the repository at this point in the history
Summary:
a device's ID is their content ed25519 signing public key. this gets created when the content olm account is created in the CryptoModule.

it seems like we can safely deprecate getDeviceID and setDeviceID and remove the callsite in sqlite-data-handler.js

Test Plan: successfully ran the app. tried logging in and out, registering and deleting an account. everything worked fine.

Reviewers: inka, kamil, marcin

Reviewed By: inka, kamil, marcin

Subscribers: ashoat, tomek, wyilio

Differential Revision: https://phab.comm.dev/D9556
  • Loading branch information
vdhanan committed Oct 26, 2023
1 parent edcd029 commit 193f73f
Show file tree
Hide file tree
Showing 13 changed files with 0 additions and 154 deletions.
22 changes: 0 additions & 22 deletions native/cpp/CommonCpp/CryptoTools/DeviceID.cpp

This file was deleted.

16 changes: 0 additions & 16 deletions native/cpp/CommonCpp/CryptoTools/DeviceID.h

This file was deleted.

2 changes: 0 additions & 2 deletions native/cpp/CommonCpp/DatabaseManagers/DatabaseQueryExecutor.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ class DatabaseQueryExecutor {
virtual void clearNotifyToken() const = 0;
virtual void setCurrentUserID(std::string userID) const = 0;
virtual std::string getCurrentUserID() const = 0;
virtual void setDeviceID(std::string deviceID) const = 0;
virtual std::string getDeviceID() const = 0;
virtual void setMetadata(std::string entry_name, std::string data) const = 0;
virtual void clearMetadata(std::string entry_name) const = 0;
virtual std::string getMetadata(std::string entry_name) const = 0;
Expand Down
8 changes: 0 additions & 8 deletions native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1299,14 +1299,6 @@ std::string SQLiteQueryExecutor::getCurrentUserID() const {
return this->getMetadata("current_user_id");
}

void SQLiteQueryExecutor::setDeviceID(std::string deviceID) const {
this->setMetadata("device_id", deviceID);
};

std::string SQLiteQueryExecutor::getDeviceID() const {
return this->getMetadata("device_id");
};

void SQLiteQueryExecutor::setMetadata(std::string entry_name, std::string data)
const {
Metadata entry{
Expand Down
2 changes: 0 additions & 2 deletions native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ class SQLiteQueryExecutor : public DatabaseQueryExecutor {
void clearNotifyToken() const override;
void setCurrentUserID(std::string userID) const override;
std::string getCurrentUserID() const override;
void setDeviceID(std::string deviceID) const override;
std::string getDeviceID() const override;
void setMetadata(std::string entry_name, std::string data) const override;
void clearMetadata(std::string entry_name) const override;
std::string getMetadata(std::string entry_name) const override;
Expand Down
67 changes: 0 additions & 67 deletions native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "CommCoreModule.h"
#include "../CryptoTools/DeviceID.h"
#include "../Notifications/BackgroundDataStorage/NotificationsCryptoModule.h"
#include "BaseDataStore.h"
#include "DatabaseManager.h"
Expand Down Expand Up @@ -791,72 +790,6 @@ jsi::Value CommCoreModule::getCurrentUserID(jsi::Runtime &rt) {
});
}

jsi::Value
CommCoreModule::setDeviceID(jsi::Runtime &rt, jsi::String deviceType) {
std::string type = deviceType.utf8(rt);
std::string deviceID;
std::string deviceIDGenerationError;

try {
deviceID = DeviceIDGenerator::generateDeviceID(type);
} catch (std::invalid_argument &e) {
deviceIDGenerationError =
"setDeviceID: incorrect function argument. Must be one of: KEYSERVER, "
"WEB, MOBILE.";
}

return createPromiseAsJSIValue(
rt, [=](jsi::Runtime &innerRt, std::shared_ptr<Promise> promise) {
taskType job = [this,
&innerRt,
promise,
deviceIDGenerationError,
deviceID]() {
std::string error = deviceIDGenerationError;
if (!error.size()) {
try {
DatabaseManager::getQueryExecutor().setDeviceID(deviceID);
} catch (const std::exception &e) {
error = e.what();
}
}
this->jsInvoker_->invokeAsync([&innerRt, promise, error, deviceID]() {
if (error.size()) {
promise->reject(error);
} else {
promise->resolve(jsi::String::createFromUtf8(innerRt, deviceID));
}
});
};
GlobalDBSingleton::instance.scheduleOrRunCancellable(
job, promise, this->jsInvoker_);
});
}

jsi::Value CommCoreModule::getDeviceID(jsi::Runtime &rt) {
return createPromiseAsJSIValue(
rt, [this](jsi::Runtime &innerRt, std::shared_ptr<Promise> promise) {
taskType job = [this, &innerRt, promise]() {
std::string error;
std::string result;
try {
result = DatabaseManager::getQueryExecutor().getDeviceID();
} catch (const std::exception &e) {
error = e.what();
}
this->jsInvoker_->invokeAsync([&innerRt, error, result, promise]() {
if (error.size()) {
promise->reject(error);
} else {
promise->resolve(jsi::String::createFromUtf8(innerRt, result));
}
});
};
GlobalDBSingleton::instance.scheduleOrRunCancellable(
job, promise, this->jsInvoker_);
});
}

jsi::Value CommCoreModule::clearSensitiveData(jsi::Runtime &rt) {
return createPromiseAsJSIValue(
rt, [this](jsi::Runtime &innerRt, std::shared_ptr<Promise> promise) {
Expand Down
3 changes: 0 additions & 3 deletions native/cpp/CommonCpp/NativeModules/CommCoreModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,6 @@ class CommCoreModule : public facebook::react::CommCoreModuleSchemaCxxSpecJSI {
virtual jsi::Value
setCurrentUserID(jsi::Runtime &rt, jsi::String userID) override;
virtual jsi::Value getCurrentUserID(jsi::Runtime &rt) override;
virtual jsi::Value
setDeviceID(jsi::Runtime &rt, jsi::String deviceType) override;
virtual jsi::Value getDeviceID(jsi::Runtime &rt) override;
virtual jsi::Value clearSensitiveData(jsi::Runtime &rt) override;
virtual bool checkIfDatabaseNeedsDeletion(jsi::Runtime &rt) override;
virtual void reportDBOperationsFailure(jsi::Runtime &rt) override;
Expand Down
8 changes: 0 additions & 8 deletions native/cpp/CommonCpp/_generated/commJSI-generated.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,6 @@ static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_setCurrentUserID
static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getCurrentUserID(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
return static_cast<CommCoreModuleSchemaCxxSpecJSI *>(&turboModule)->getCurrentUserID(rt);
}
static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_setDeviceID(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
return static_cast<CommCoreModuleSchemaCxxSpecJSI *>(&turboModule)->setDeviceID(rt, args[0].asString(rt));
}
static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getDeviceID(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
return static_cast<CommCoreModuleSchemaCxxSpecJSI *>(&turboModule)->getDeviceID(rt);
}
static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_clearSensitiveData(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
return static_cast<CommCoreModuleSchemaCxxSpecJSI *>(&turboModule)->clearSensitiveData(rt);
}
Expand Down Expand Up @@ -161,8 +155,6 @@ CommCoreModuleSchemaCxxSpecJSI::CommCoreModuleSchemaCxxSpecJSI(std::shared_ptr<C
methodMap_["clearNotifyToken"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_clearNotifyToken};
methodMap_["setCurrentUserID"] = MethodMetadata {1, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_setCurrentUserID};
methodMap_["getCurrentUserID"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getCurrentUserID};
methodMap_["setDeviceID"] = MethodMetadata {1, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_setDeviceID};
methodMap_["getDeviceID"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getDeviceID};
methodMap_["clearSensitiveData"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_clearSensitiveData};
methodMap_["checkIfDatabaseNeedsDeletion"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_checkIfDatabaseNeedsDeletion};
methodMap_["reportDBOperationsFailure"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_reportDBOperationsFailure};
Expand Down
18 changes: 0 additions & 18 deletions native/cpp/CommonCpp/_generated/commJSI.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ class JSI_EXPORT CommCoreModuleSchemaCxxSpecJSI : public TurboModule {
virtual jsi::Value clearNotifyToken(jsi::Runtime &rt) = 0;
virtual jsi::Value setCurrentUserID(jsi::Runtime &rt, jsi::String userID) = 0;
virtual jsi::Value getCurrentUserID(jsi::Runtime &rt) = 0;
virtual jsi::Value setDeviceID(jsi::Runtime &rt, jsi::String deviceType) = 0;
virtual jsi::Value getDeviceID(jsi::Runtime &rt) = 0;
virtual jsi::Value clearSensitiveData(jsi::Runtime &rt) = 0;
virtual bool checkIfDatabaseNeedsDeletion(jsi::Runtime &rt) = 0;
virtual void reportDBOperationsFailure(jsi::Runtime &rt) = 0;
Expand Down Expand Up @@ -295,22 +293,6 @@ class JSI_EXPORT CommCoreModuleSchemaCxxSpec : public TurboModule {
return bridging::callFromJs<jsi::Value>(
rt, &T::getCurrentUserID, jsInvoker_, instance_);
}
jsi::Value setDeviceID(jsi::Runtime &rt, jsi::String deviceType) override {
static_assert(
bridging::getParameterCount(&T::setDeviceID) == 2,
"Expected setDeviceID(...) to have 2 parameters");

return bridging::callFromJs<jsi::Value>(
rt, &T::setDeviceID, jsInvoker_, instance_, std::move(deviceType));
}
jsi::Value getDeviceID(jsi::Runtime &rt) override {
static_assert(
bridging::getParameterCount(&T::getDeviceID) == 1,
"Expected getDeviceID(...) to have 1 parameters");

return bridging::callFromJs<jsi::Value>(
rt, &T::getDeviceID, jsInvoker_, instance_);
}
jsi::Value clearSensitiveData(jsi::Runtime &rt) override {
static_assert(
bridging::getParameterCount(&T::clearSensitiveData) == 1,
Expand Down
4 changes: 0 additions & 4 deletions native/data/sqlite-data-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,6 @@ function SQLiteDataHandler(): React.Node {
if (currentLoggedInUserID) {
await commCoreModule.setCurrentUserID(currentLoggedInUserID);
}
const databaseDeviceID = await commCoreModule.getDeviceID();
if (!databaseDeviceID) {
await commCoreModule.setDeviceID('MOBILE');
}
} catch (e) {
if (isTaskCancelledError(e)) {
return;
Expand Down
2 changes: 0 additions & 2 deletions native/ios/Comm.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
724995D527B4103A00323FCE /* NotificationService.mm in Sources */ = {isa = PBXBuildFile; fileRef = 724995D427B4103A00323FCE /* NotificationService.mm */; };
724995D927B4103A00323FCE /* NotificationService.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = 724995D127B4103A00323FCE /* NotificationService.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
724995FB27BA9E8D00323FCE /* UserNotifications.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 724995FA27BA9E8C00323FCE /* UserNotifications.framework */; };
75291F0428F9A0D400F4C80E /* DeviceID.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 75291F0328F9A0AE00F4C80E /* DeviceID.cpp */; };
7F0C6E31291C4468002AA2D9 /* ExpoModulesProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3EEB3E70587B0ADAD05237B0 /* ExpoModulesProvider.swift */; };
7F761E602201141E001B6FB7 /* JavaScriptCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7F761E292201141E001B6FB7 /* JavaScriptCore.framework */; };
7F788C2C248AA2140098F071 /* SplashScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 7F788C2B248AA2130098F071 /* SplashScreen.storyboard */; };
Expand Down Expand Up @@ -1049,7 +1048,6 @@
CB7EF17E295C674300B17035 /* CommIOSNotifications.mm in Sources */,
CB7EF180295C674300B17035 /* CommIOSNotificationsBridgeQueue.mm in Sources */,
7F0C6E31291C4468002AA2D9 /* ExpoModulesProvider.swift in Sources */,
75291F0428F9A0D400F4C80E /* DeviceID.cpp in Sources */,
8EF775682A74032C0046A385 /* CommRustModule.cpp in Sources */,
8E43C32C291E5B4A009378F5 /* TerminateApp.mm in Sources */,
8BC9568529FC49B00060AE4A /* JSIRust.cpp in Sources */,
Expand Down
2 changes: 0 additions & 2 deletions native/schema/CommCoreModuleSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ interface Spec extends TurboModule {
+clearNotifyToken: () => Promise<void>;
+setCurrentUserID: (userID: string) => Promise<void>;
+getCurrentUserID: () => Promise<string>;
+setDeviceID: (deviceType: string) => Promise<string>;
+getDeviceID: () => Promise<string>;
+clearSensitiveData: () => Promise<void>;
+checkIfDatabaseNeedsDeletion: () => boolean;
+reportDBOperationsFailure: () => void;
Expand Down
Binary file modified web/database/_generated/comm_query_executor.wasm
Binary file not shown.

0 comments on commit 193f73f

Please sign in to comment.