Adds support for versioned profiles

* Add zkgroup library

* tsconfig.json: Prettier wants to mess it up. :0(

* Initial take on versioned profile fetches

* Fix up the logging in getProfiles() - warn instead of error

* Introduce new VERSIONED_PROFILE_FETCH flag

* Update zkgroup dependency to v0.5.0

* Fix lint-deps - new zkgroup library brought in new debug dep

* ts/zkgroup: Introduce some commonly-used helper functions

* Update to latest serverPublicParams

* Don't derive profileKeyVersion unless flag is set
This commit is contained in:
Scott Nonnenberg 2020-04-15 16:12:28 -07:00 committed by GitHub
parent 5f0c07eec2
commit c1dfe3e5b4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 591 additions and 25 deletions

View file

@ -546,10 +546,20 @@ export type WebAPIType = {
) => Promise<ServerKeysType>;
getMessageSocket: () => WebSocket;
getMyKeys: () => Promise<number>;
getProfile: (identifier: string) => Promise<any>;
getProfile: (
identifier: string,
options?: {
profileKeyVersion?: string;
profileKeyCredentialRequest?: string;
}
) => Promise<any>;
getProfileUnauth: (
identifier: string,
options?: { accessKey?: string }
options: {
accessKey: string;
profileKeyVersion?: string;
profileKeyCredentialRequest?: string;
}
) => Promise<any>;
getProvisioningSocket: () => WebSocket;
getSenderCertificate: (withUuid?: boolean) => Promise<any>;
@ -797,22 +807,61 @@ export function initialize({
});
}
async function getProfile(identifier: string) {
function getProfileUrl(
identifier: string,
profileKeyVersion?: string,
profileKeyCredentialRequest?: string
) {
if (profileKeyVersion && profileKeyCredentialRequest) {
return `/${identifier}/${profileKeyVersion}/${profileKeyCredentialRequest}`;
}
return `/${identifier}`;
}
async function getProfile(
identifier: string,
options: {
profileKeyVersion?: string;
profileKeyCredentialRequest?: string;
} = {}
) {
const { profileKeyVersion, profileKeyCredentialRequest } = options;
return _ajax({
call: 'profile',
httpType: 'GET',
urlParameters: `/${identifier}`,
urlParameters: getProfileUrl(
identifier,
profileKeyVersion,
profileKeyCredentialRequest
),
responseType: 'json',
});
}
async function getProfileUnauth(
identifier: string,
{ accessKey }: { accessKey?: string } = {}
options: {
accessKey: string;
profileKeyVersion?: string;
profileKeyCredentialRequest?: string;
}
) {
const {
accessKey,
profileKeyVersion,
profileKeyCredentialRequest,
} = options;
return _ajax({
call: 'profile',
httpType: 'GET',
urlParameters: `/${identifier}`,
urlParameters: getProfileUrl(
identifier,
profileKeyVersion,
profileKeyCredentialRequest
),
responseType: 'json',
unauthenticated: true,
accessKey,