Skip to content

Commit

Permalink
[CommCoreModule] add backup secret param to restoreUser
Browse files Browse the repository at this point in the history
Summary:
Part of [ENG-10112](https://linear.app/comm/issue/ENG-10112/generate-user-keys-backup-an-a-client-during-restoration) and [ENG-10113](https://linear.app/comm/issue/ENG-10113/send-the-user-keys-backup-to-identity-service-in-a-single-rpc)

We need backup secret to encrypt User Keys during restore user RPC.

Depends on D14263

Test Plan: Build app

Reviewers: bartek, tomek

Reviewed By: tomek

Subscribers: ashoat

Differential Revision: https://phab.comm.dev/D14271
  • Loading branch information
xsanm committed Jan 30, 2025
1 parent e7424f4 commit 4a832bd
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 9 deletions.
1 change: 1 addition & 0 deletions lib/types/identity-service-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ export interface IdentityServiceClient {
userID: string,
deviceList: SignedDeviceList,
siweSocialProof?: SignedMessage,
backupSecret: string,
) => Promise<IdentityAuthResult>;
// on native, publishing prekeys to Identity is called directly from C++,
// there is no need to expose it to JS
Expand Down
1 change: 1 addition & 0 deletions native/account/restore.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ function useRestoreProtocol(): (
userID,
signedDeviceList,
siweSocialProof,
secret,
);

//6. Mark keys as published
Expand Down
4 changes: 3 additions & 1 deletion native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3395,7 +3395,8 @@ jsi::Value CommCoreModule::restoreUser(
jsi::String notifPrekeySignature,
jsi::Array contentOneTimeKeys,
jsi::Array notifOneTimeKeys,
jsi::String deviceList) {
jsi::String deviceList,
jsi::String backupSecret) {
rust::String siweSocialProofMessageRust = "";
if (siweSocialProofMessage.has_value()) {
siweSocialProofMessageRust =
Expand All @@ -3418,6 +3419,7 @@ jsi::Value CommCoreModule::restoreUser(
auto contentOneTimeKeysRust = jsiStringArrayToRustVec(contentOneTimeKeys, rt);
auto notifOneTimeKeysRust = jsiStringArrayToRustVec(notifOneTimeKeys, rt);
auto deviceListRust = jsiStringToRustString(deviceList, rt);
auto backupSecretRust = jsiStringToRustString(backupSecret, rt);

return createPromiseAsJSIValue(
rt, [=, this](jsi::Runtime &innerRt, std::shared_ptr<Promise> promise) {
Expand Down
3 changes: 2 additions & 1 deletion native/cpp/CommonCpp/NativeModules/CommCoreModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,8 @@ class CommCoreModule : public facebook::react::CommCoreModuleSchemaCxxSpecJSI {
jsi::String notifPrekeySignature,
jsi::Array contentOneTimeKeys,
jsi::Array notifOneTimeKeys,
jsi::String deviceList) override;
jsi::String deviceList,
jsi::String backupSecret) override;

public:
CommCoreModule(std::shared_ptr<facebook::react::CallInvoker> jsInvoker);
Expand Down
4 changes: 2 additions & 2 deletions native/cpp/CommonCpp/_generated/commJSI-generated.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_fetchMessages(js
return static_cast<CommCoreModuleSchemaCxxSpecJSI *>(&turboModule)->fetchMessages(rt, args[0].asString(rt), args[1].asNumber(), args[2].asNumber());
}
static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_restoreUser(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
return static_cast<CommCoreModuleSchemaCxxSpecJSI *>(&turboModule)->restoreUser(rt, args[0].asString(rt), args[1].isNull() || args[1].isUndefined() ? std::nullopt : std::make_optional(args[1].asString(rt)), args[2].isNull() || args[2].isUndefined() ? std::nullopt : std::make_optional(args[2].asString(rt)), args[3].asString(rt), args[4].asString(rt), args[5].asString(rt), args[6].asString(rt), args[7].asString(rt), args[8].asString(rt), args[9].asObject(rt).asArray(rt), args[10].asObject(rt).asArray(rt), args[11].asString(rt));
return static_cast<CommCoreModuleSchemaCxxSpecJSI *>(&turboModule)->restoreUser(rt, args[0].asString(rt), args[1].isNull() || args[1].isUndefined() ? std::nullopt : std::make_optional(args[1].asString(rt)), args[2].isNull() || args[2].isUndefined() ? std::nullopt : std::make_optional(args[2].asString(rt)), args[3].asString(rt), args[4].asString(rt), args[5].asString(rt), args[6].asString(rt), args[7].asString(rt), args[8].asString(rt), args[9].asObject(rt).asArray(rt), args[10].asObject(rt).asArray(rt), args[11].asString(rt), args[12].asString(rt));
}

CommCoreModuleSchemaCxxSpecJSI::CommCoreModuleSchemaCxxSpecJSI(std::shared_ptr<CallInvoker> jsInvoker)
Expand Down Expand Up @@ -329,7 +329,7 @@ CommCoreModuleSchemaCxxSpecJSI::CommCoreModuleSchemaCxxSpecJSI(std::shared_ptr<C
methodMap_["getRelatedMessages"] = MethodMetadata {1, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getRelatedMessages};
methodMap_["searchMessages"] = MethodMetadata {4, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_searchMessages};
methodMap_["fetchMessages"] = MethodMetadata {3, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_fetchMessages};
methodMap_["restoreUser"] = MethodMetadata {12, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_restoreUser};
methodMap_["restoreUser"] = MethodMetadata {13, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_restoreUser};
}


Expand Down
10 changes: 5 additions & 5 deletions native/cpp/CommonCpp/_generated/commJSI.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class JSI_EXPORT CommCoreModuleSchemaCxxSpecJSI : public TurboModule {
virtual jsi::Value getRelatedMessages(jsi::Runtime &rt, jsi::String messageID) = 0;
virtual jsi::Value searchMessages(jsi::Runtime &rt, jsi::String query, jsi::String threadID, std::optional<jsi::String> timestampCursor, std::optional<jsi::String> messageIDCursor) = 0;
virtual jsi::Value fetchMessages(jsi::Runtime &rt, jsi::String threadID, double limit, double offset) = 0;
virtual jsi::Value restoreUser(jsi::Runtime &rt, jsi::String userID, std::optional<jsi::String> siweSocialProofMessage, std::optional<jsi::String> siweSocialProofSignature, jsi::String keyPayload, jsi::String keyPayloadSignature, jsi::String contentPrekey, jsi::String contentPrekeySignature, jsi::String notifPrekey, jsi::String notifPrekeySignature, jsi::Array contentOneTimeKeys, jsi::Array notifOneTimeKeys, jsi::String deviceList) = 0;
virtual jsi::Value restoreUser(jsi::Runtime &rt, jsi::String userID, std::optional<jsi::String> siweSocialProofMessage, std::optional<jsi::String> siweSocialProofSignature, jsi::String keyPayload, jsi::String keyPayloadSignature, jsi::String contentPrekey, jsi::String contentPrekeySignature, jsi::String notifPrekey, jsi::String notifPrekeySignature, jsi::Array contentOneTimeKeys, jsi::Array notifOneTimeKeys, jsi::String deviceList, jsi::String backupSecret) = 0;

};

Expand Down Expand Up @@ -726,13 +726,13 @@ class JSI_EXPORT CommCoreModuleSchemaCxxSpec : public TurboModule {
return bridging::callFromJs<jsi::Value>(
rt, &T::fetchMessages, jsInvoker_, instance_, std::move(threadID), std::move(limit), std::move(offset));
}
jsi::Value restoreUser(jsi::Runtime &rt, jsi::String userID, std::optional<jsi::String> siweSocialProofMessage, std::optional<jsi::String> siweSocialProofSignature, jsi::String keyPayload, jsi::String keyPayloadSignature, jsi::String contentPrekey, jsi::String contentPrekeySignature, jsi::String notifPrekey, jsi::String notifPrekeySignature, jsi::Array contentOneTimeKeys, jsi::Array notifOneTimeKeys, jsi::String deviceList) override {
jsi::Value restoreUser(jsi::Runtime &rt, jsi::String userID, std::optional<jsi::String> siweSocialProofMessage, std::optional<jsi::String> siweSocialProofSignature, jsi::String keyPayload, jsi::String keyPayloadSignature, jsi::String contentPrekey, jsi::String contentPrekeySignature, jsi::String notifPrekey, jsi::String notifPrekeySignature, jsi::Array contentOneTimeKeys, jsi::Array notifOneTimeKeys, jsi::String deviceList, jsi::String backupSecret) override {
static_assert(
bridging::getParameterCount(&T::restoreUser) == 13,
"Expected restoreUser(...) to have 13 parameters");
bridging::getParameterCount(&T::restoreUser) == 14,
"Expected restoreUser(...) to have 14 parameters");

return bridging::callFromJs<jsi::Value>(
rt, &T::restoreUser, jsInvoker_, instance_, std::move(userID), std::move(siweSocialProofMessage), std::move(siweSocialProofSignature), std::move(keyPayload), std::move(keyPayloadSignature), std::move(contentPrekey), std::move(contentPrekeySignature), std::move(notifPrekey), std::move(notifPrekeySignature), std::move(contentOneTimeKeys), std::move(notifOneTimeKeys), std::move(deviceList));
rt, &T::restoreUser, jsInvoker_, instance_, std::move(userID), std::move(siweSocialProofMessage), std::move(siweSocialProofSignature), std::move(keyPayload), std::move(keyPayloadSignature), std::move(contentPrekey), std::move(contentPrekeySignature), std::move(notifPrekey), std::move(notifPrekeySignature), std::move(contentOneTimeKeys), std::move(notifOneTimeKeys), std::move(deviceList), std::move(backupSecret));
}

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,7 @@ function IdentityServiceContextProvider(props: Props): React.Node {
userID: string,
deviceList: SignedDeviceList,
siweSocialProof?: SignedMessage,
backupSecret: string,
) => {
await commCoreModule.initializeCryptoAccount();
const [
Expand All @@ -577,6 +578,7 @@ function IdentityServiceContextProvider(props: Props): React.Node {
getOneTimeKeyValues(contentOneTimeKeys),
getOneTimeKeyValues(notificationsOneTimeKeys),
JSON.stringify(deviceList),
backupSecret,
);

return await processAuthResult(
Expand Down
1 change: 1 addition & 0 deletions native/schema/CommCoreModuleSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ interface Spec extends TurboModule {
contentOneTimeKeys: $ReadOnlyArray<string>,
notifOneTimeKeys: $ReadOnlyArray<string>,
deviceList: string,
backupSecret: string,
) => Promise<string>;
}

Expand Down

0 comments on commit 4a832bd

Please sign in to comment.