Changeset View
Changeset View
Standalone View
Standalone View
keyserver/src/utils/olm-utils.js
// @flow | // @flow | ||||
import olm from '@commapp/olm'; | import olm from '@commapp/olm'; | ||||
import type { | import type { | ||||
Account as OlmAccount, | Account as OlmAccount, | ||||
Utility as OlmUtility, | Utility as OlmUtility, | ||||
Session as OlmSession, | Session as OlmSession, | ||||
} from '@commapp/olm'; | } from '@commapp/olm'; | ||||
import uuid from 'uuid'; | import uuid from 'uuid'; | ||||
import { olmEncryptedMessageTypes } from 'lib/types/crypto-types.js'; | import { | ||||
olmEncryptedMessageTypes, | |||||
type OLMOneTimeKeys, | |||||
} from 'lib/types/crypto-types.js'; | |||||
import { values } from 'lib/utils/objects.js'; | |||||
type PickledOlmAccount = { | type PickledOlmAccount = { | ||||
+picklingKey: string, | +picklingKey: string, | ||||
+pickledAccount: string, | +pickledAccount: string, | ||||
}; | }; | ||||
const maxPublishedPrekeyAge = 30 * 24 * 60 * 60 * 1000; | const maxPublishedPrekeyAge = 30 * 24 * 60 * 60 * 1000; | ||||
const maxOldPrekeyAge = 24 * 60 * 60 * 1000; | const maxOldPrekeyAge = 24 * 60 * 60 * 1000; | ||||
▲ Show 20 Lines • Show All 74 Lines • ▼ Show 20 Lines | function validateAccountPrekey(account: OlmAccount) { | ||||
if ( | if ( | ||||
prekeyPublished && | prekeyPublished && | ||||
currentDate - lastPrekeyPublishDate >= maxOldPrekeyAge | currentDate - lastPrekeyPublishDate >= maxOldPrekeyAge | ||||
) { | ) { | ||||
account.forget_old_prekey(); | account.forget_old_prekey(); | ||||
} | } | ||||
} | } | ||||
function getOneTimeKeyValues(keyBlob: string): $ReadOnlyArray<string> { | |||||
const content: OLMOneTimeKeys = JSON.parse(keyBlob); | |||||
const keys: $ReadOnlyArray<string> = values(content.curve25519); | |||||
return keys; | |||||
} | |||||
export { | export { | ||||
createPickledOlmAccount, | createPickledOlmAccount, | ||||
createPickledOlmSession, | createPickledOlmSession, | ||||
getOlmUtility, | getOlmUtility, | ||||
unpickleOlmAccount, | unpickleOlmAccount, | ||||
unpickleOlmSession, | unpickleOlmSession, | ||||
validateAccountPrekey, | validateAccountPrekey, | ||||
getOneTimeKeyValues, | |||||
}; | }; |