Hide buttons when you can't encrypt or decrypt.
This commit is contained in:
parent
9339490e8e
commit
ba7e619bdf
17
src/api/transit/getTransitKey.ts
Normal file
17
src/api/transit/getTransitKey.ts
Normal file
|
@ -0,0 +1,17 @@
|
|||
import { DoesNotExistError } from "../../types/internalErrors";
|
||||
import { appendAPIURL, getHeaders } from "../apiUtils";
|
||||
import { TransitKeyType } from "../types/transit";
|
||||
|
||||
export async function getTransitKey(baseMount: string, name: string): Promise<TransitKeyType> {
|
||||
const request = new Request(appendAPIURL(`/v1/${baseMount}/keys/${name}`), {
|
||||
headers: getHeaders(),
|
||||
});
|
||||
return fetch(request).then(response => {
|
||||
if (response.status == 404) {
|
||||
throw DoesNotExistError;
|
||||
}
|
||||
return response.json();
|
||||
}).then(data => {
|
||||
return data.data;
|
||||
});
|
||||
}
|
33
src/api/types/transit.ts
Normal file
33
src/api/types/transit.ts
Normal file
|
@ -0,0 +1,33 @@
|
|||
export const enum TransitKeyTypes {
|
||||
AES128_GCM96 = "aes128-gcm96",
|
||||
AES256_GCM96 = "aes256-gcm96",
|
||||
CHACHA20_POLY1305 = "chacha20-poly1305",
|
||||
ED25519 = "ed25519",
|
||||
ECDSA_P256 = "ecdsa-p256",
|
||||
ECDSA_P384 = "ecdsa-p384",
|
||||
ECDSA_P521 = "ecdsa-p521",
|
||||
RSA_2048 = "rsa-2048",
|
||||
RSA_3072 = "rsa-3072",
|
||||
RSA_4096 = "rsa-4096",
|
||||
}
|
||||
|
||||
export type TransitKeyBaseType = {
|
||||
name: string;
|
||||
convergent_encryption: Boolean;
|
||||
derived: Boolean;
|
||||
exportable: Boolean;
|
||||
allow_plaintext_backup: Boolean;
|
||||
type: keyof typeof TransitKeyTypes;
|
||||
}
|
||||
|
||||
export type TransitKeyType = TransitKeyBaseType & {
|
||||
keys?: {
|
||||
[version: string]: number;
|
||||
},
|
||||
min_decryption_version: number;
|
||||
min_encryption_version: number;
|
||||
supports_encryption: Boolean;
|
||||
supports_decryption: Boolean;
|
||||
supports_derivation: Boolean;
|
||||
supports_signing: Boolean;
|
||||
}
|
|
@ -3,6 +3,16 @@ import { changePage, setPageContent, setTitleElement } from "../../pageUtils";
|
|||
import { makeElement } from "../../htmlUtils";
|
||||
import { pageState } from "../../globalPageState";
|
||||
import i18next from 'i18next';
|
||||
import { getTransitKey } from "../../api/transit/getTransitKey";
|
||||
|
||||
type TileParams = {
|
||||
condition: Boolean;
|
||||
title: string;
|
||||
description: string;
|
||||
icon: string;
|
||||
iconText: string;
|
||||
onclick: () => void;
|
||||
}
|
||||
|
||||
export class TransitViewSecretPage extends Page {
|
||||
constructor() {
|
||||
|
@ -10,16 +20,12 @@ export class TransitViewSecretPage extends Page {
|
|||
}
|
||||
|
||||
goBack(): void {
|
||||
pageState.currentSecret = "";
|
||||
changePage("TRANSIT_VIEW");
|
||||
}
|
||||
|
||||
makeTile(
|
||||
title: string,
|
||||
description: string,
|
||||
icon: string,
|
||||
iconText: string,
|
||||
onclick: () => void = () => { }
|
||||
): HTMLElement {
|
||||
makeTile(params: TileParams): HTMLElement {
|
||||
if (!params.condition) return;
|
||||
return makeElement({
|
||||
tag: "a",
|
||||
class: "uk-link-heading",
|
||||
|
@ -31,21 +37,21 @@ export class TransitViewSecretPage extends Page {
|
|||
makeElement({
|
||||
tag: "p",
|
||||
class: "uk-h4",
|
||||
text: title,
|
||||
text: params.title,
|
||||
children: makeElement({
|
||||
tag: "span",
|
||||
class: ["uk-icon", "uk-margin-small-left"],
|
||||
attributes: {
|
||||
"uk-icon": `icon: ${icon}`,
|
||||
"uk-icon": `icon: ${params.icon}`,
|
||||
"role": "img",
|
||||
"aria-label": `${title} icon`
|
||||
"aria-label": params.iconText
|
||||
}
|
||||
})
|
||||
}),
|
||||
makeElement({
|
||||
tag: "span",
|
||||
class: "uk-text-muted",
|
||||
text: description
|
||||
text: params.description
|
||||
})
|
||||
]
|
||||
})
|
||||
|
@ -54,6 +60,9 @@ export class TransitViewSecretPage extends Page {
|
|||
|
||||
async render(): Promise<void> {
|
||||
setTitleElement(pageState);
|
||||
|
||||
let transitKey = await getTransitKey(pageState.currentBaseMount, pageState.currentSecret);
|
||||
|
||||
setPageContent(makeElement({
|
||||
tag: "div",
|
||||
class: ["uk-grid", "uk-child-width-expand@s"],
|
||||
|
@ -66,20 +75,22 @@ export class TransitViewSecretPage extends Page {
|
|||
makeElement({
|
||||
tag: "div",
|
||||
children: [
|
||||
this.makeTile(
|
||||
i18next.t("transit_view_encrypt_text"),
|
||||
i18next.t("transit_view_encrypt_description"),
|
||||
"lock",
|
||||
i18next.t("transit_view_encrypt_icon_text"),
|
||||
() => { changePage("TRANSIT_ENCRYPT"); }
|
||||
),
|
||||
this.makeTile(
|
||||
i18next.t("transit_view_decrypt_text"),
|
||||
i18next.t("transit_view_decrypt_description"),
|
||||
"mail",
|
||||
i18next.t("transit_view_decrypt_icon_text"),
|
||||
() => { changePage("TRANSIT_DECRYPT"); }
|
||||
),
|
||||
this.makeTile({
|
||||
condition: transitKey.supports_encryption,
|
||||
title: i18next.t("transit_view_encrypt_text"),
|
||||
description: i18next.t("transit_view_encrypt_description"),
|
||||
icon: "lock",
|
||||
iconText: i18next.t("transit_view_encrypt_icon_text"),
|
||||
onclick: () => { changePage("TRANSIT_ENCRYPT"); }
|
||||
}),
|
||||
this.makeTile({
|
||||
condition: transitKey.supports_decryption,
|
||||
title: i18next.t("transit_view_decrypt_text"),
|
||||
description: i18next.t("transit_view_decrypt_description"),
|
||||
icon: "mail",
|
||||
iconText: i18next.t("transit_view_decrypt_icon_text"),
|
||||
onclick: () => { changePage("TRANSIT_DECRYPT"); }
|
||||
}),
|
||||
]
|
||||
}),
|
||||
]
|
||||
|
|
Loading…
Reference in a new issue