Changeset View
Changeset View
Standalone View
Standalone View
keyserver/src/user/login.js
// @flow | // @flow | ||||
import type { Account as OlmAccount } from '@commapp/olm'; | import type { Account as OlmAccount } from '@commapp/olm'; | ||||
import { getRustAPI } from 'rust-node-addon'; | import { getRustAPI } from 'rust-node-addon'; | ||||
import type { OLMOneTimeKeys } from 'lib/types/crypto-types'; | |||||
import { getCommConfig } from 'lib/utils/comm-config.js'; | import { getCommConfig } from 'lib/utils/comm-config.js'; | ||||
import { ServerError } from 'lib/utils/errors.js'; | import { ServerError } from 'lib/utils/errors.js'; | ||||
import { values } from 'lib/utils/objects.js'; | import { values } from 'lib/utils/objects.js'; | ||||
import { | import { | ||||
saveIdentityInfo, | saveIdentityInfo, | ||||
fetchIdentityInfo, | fetchIdentityInfo, | ||||
type IdentityInfo, | type IdentityInfo, | ||||
} from './identity.js'; | } from './identity.js'; | ||||
import { getMessageForException } from '../responders/utils.js'; | import { getMessageForException } from '../responders/utils.js'; | ||||
import { fetchCallUpdateOlmAccount } from '../updaters/olm-account-updater.js'; | import { fetchCallUpdateOlmAccount } from '../updaters/olm-account-updater.js'; | ||||
import { validateAccountPrekey } from '../utils/olm-utils.js'; | import { | ||||
getOneTimeKeyValues, | |||||
validateAccountPrekey, | |||||
} from '../utils/olm-utils.js'; | |||||
type UserCredentials = { +username: string, +password: string }; | type UserCredentials = { +username: string, +password: string }; | ||||
export type AccountKeysSet = { | export type AccountKeysSet = { | ||||
+identityKeys: string, | +identityKeys: string, | ||||
+prekey: string, | +prekey: string, | ||||
+prekeySignature: string, | +prekeySignature: string, | ||||
+oneTimeKey: $ReadOnlyArray<string>, | +oneTimeKey: $ReadOnlyArray<string>, | ||||
}; | }; | ||||
function getOneTimeKeyValues(keyBlob: string): $ReadOnlyArray<string> { | |||||
const content: OLMOneTimeKeys = JSON.parse(keyBlob); | |||||
const keys: $ReadOnlyArray<string> = values(content.curve25519); | |||||
return keys; | |||||
} | |||||
function retrieveAccountKeysSet(account: OlmAccount): AccountKeysSet { | function retrieveAccountKeysSet(account: OlmAccount): AccountKeysSet { | ||||
const identityKeys = account.identity_keys(); | const identityKeys = account.identity_keys(); | ||||
validateAccountPrekey(account); | validateAccountPrekey(account); | ||||
const prekeyMap = JSON.parse(account.prekey()).curve25519; | const prekeyMap = JSON.parse(account.prekey()).curve25519; | ||||
const [prekey] = values(prekeyMap); | const [prekey] = values(prekeyMap); | ||||
const prekeySignature = account.prekey_signature(); | const prekeySignature = account.prekey_signature(); | ||||
▲ Show 20 Lines • Show All 133 Lines • Show Last 20 Lines |