Page MenuHomePhabricator

D8475.diff
No OneTemporary

D8475.diff

diff --git a/keyserver/src/user/identity.js b/keyserver/src/user/identity.js
new file mode 100644
--- /dev/null
+++ b/keyserver/src/user/identity.js
@@ -0,0 +1,38 @@
+// @flow
+
+import type { QueryResults } from 'mysql';
+
+import { SQL, dbQuery } from '../database/database.js';
+
+const userIDMetadataKey = 'user_id';
+const accessTokenMetadataKey = 'access_token';
+
+// This information is minted when registering with identity service
+// Naming should reflect the rust-bindings: userId -> user_id
+export type IdentityInfo = { +userId: string, +accessToken: string };
+
+async function fetchIdentityInfo(): Promise<?IdentityInfo> {
+ const versionQuery = SQL`
+ SELECT data
+ FROM metadata
+ WHERE name IN (${userIDMetadataKey}, ${accessTokenMetadataKey})
+ `;
+
+ const [[userID, accessToken]] = await dbQuery(versionQuery);
+ if (!userID || !accessToken) {
+ return null;
+ }
+ return { userId: userID.data, accessToken: accessToken.data };
+}
+
+function saveIdentityInfo(userInfo: IdentityInfo): Promise<QueryResults> {
+ const updateQuery = SQL`
+ REPLACE INTO metadata (name, data)
+ VALUES (${userIDMetadataKey}, ${userInfo.userId}),
+ (${accessTokenMetadataKey}, ${userInfo.accessToken})
+ `;
+
+ return dbQuery(updateQuery);
+}
+
+export { fetchIdentityInfo, saveIdentityInfo };
diff --git a/keyserver/src/user/login.js b/keyserver/src/user/login.js
--- a/keyserver/src/user/login.js
+++ b/keyserver/src/user/login.js
@@ -1,7 +1,6 @@
// @flow
import type { Account as OlmAccount } from '@commapp/olm';
-import type { QueryResults } from 'mysql';
import { getRustAPI } from 'rust-node-addon';
import type { OLMOneTimeKeys } from 'lib/types/crypto-types';
@@ -9,16 +8,16 @@
import { ServerError } from 'lib/utils/errors.js';
import { values } from 'lib/utils/objects.js';
-import { SQL, dbQuery } from '../database/database.js';
+import {
+ saveIdentityInfo,
+ fetchIdentityInfo,
+ type IdentityInfo,
+} from './identity.js';
import { getMessageForException } from '../responders/utils.js';
import { fetchCallUpdateOlmAccount } from '../updaters/olm-account-updater.js';
import { validateAccountPrekey } from '../utils/olm-utils.js';
type UserCredentials = { +username: string, +password: string };
-type IdentityInfo = { +userId: string, +accessToken: string };
-
-const userIDMetadataKey = 'user_id';
-const accessTokenMetadataKey = 'access_token';
export type AccountKeysSet = {
+identityKeys: string,
@@ -60,30 +59,6 @@
account.mark_keys_as_published();
}
-async function fetchIdentityInfo(): Promise<?IdentityInfo> {
- const versionQuery = SQL`
- SELECT data
- FROM metadata
- WHERE name IN (${userIDMetadataKey}, ${accessTokenMetadataKey})
- `;
-
- const [[userId, accessToken]] = await dbQuery(versionQuery);
- if (!userId || !accessToken) {
- return null;
- }
- return { userId, accessToken };
-}
-
-function saveIdentityInfo(userInfo: IdentityInfo): Promise<QueryResults> {
- const updateQuery = SQL`
- REPLACE INTO metadata (name, data)
- VALUES (${userIDMetadataKey}, ${userInfo.userId}),
- (${accessTokenMetadataKey}, ${userInfo.accessToken})
- `;
-
- return dbQuery(updateQuery);
-}
-
async function verifyUserLoggedIn(): Promise<IdentityInfo> {
const result = await fetchIdentityInfo();

File Metadata

Mime Type
text/plain
Expires
Fri, Nov 22, 11:53 PM (13 h, 13 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2566707
Default Alt Text
D8475.diff (3 KB)

Event Timeline