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 { makeElement } from "../../htmlUtils";
|
||||||
import { pageState } from "../../globalPageState";
|
import { pageState } from "../../globalPageState";
|
||||||
import i18next from 'i18next';
|
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 {
|
export class TransitViewSecretPage extends Page {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
@ -10,16 +20,12 @@ export class TransitViewSecretPage extends Page {
|
||||||
}
|
}
|
||||||
|
|
||||||
goBack(): void {
|
goBack(): void {
|
||||||
|
pageState.currentSecret = "";
|
||||||
changePage("TRANSIT_VIEW");
|
changePage("TRANSIT_VIEW");
|
||||||
}
|
}
|
||||||
|
|
||||||
makeTile(
|
makeTile(params: TileParams): HTMLElement {
|
||||||
title: string,
|
if (!params.condition) return;
|
||||||
description: string,
|
|
||||||
icon: string,
|
|
||||||
iconText: string,
|
|
||||||
onclick: () => void = () => { }
|
|
||||||
): HTMLElement {
|
|
||||||
return makeElement({
|
return makeElement({
|
||||||
tag: "a",
|
tag: "a",
|
||||||
class: "uk-link-heading",
|
class: "uk-link-heading",
|
||||||
|
@ -31,21 +37,21 @@ export class TransitViewSecretPage extends Page {
|
||||||
makeElement({
|
makeElement({
|
||||||
tag: "p",
|
tag: "p",
|
||||||
class: "uk-h4",
|
class: "uk-h4",
|
||||||
text: title,
|
text: params.title,
|
||||||
children: makeElement({
|
children: makeElement({
|
||||||
tag: "span",
|
tag: "span",
|
||||||
class: ["uk-icon", "uk-margin-small-left"],
|
class: ["uk-icon", "uk-margin-small-left"],
|
||||||
attributes: {
|
attributes: {
|
||||||
"uk-icon": `icon: ${icon}`,
|
"uk-icon": `icon: ${params.icon}`,
|
||||||
"role": "img",
|
"role": "img",
|
||||||
"aria-label": `${title} icon`
|
"aria-label": params.iconText
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}),
|
}),
|
||||||
makeElement({
|
makeElement({
|
||||||
tag: "span",
|
tag: "span",
|
||||||
class: "uk-text-muted",
|
class: "uk-text-muted",
|
||||||
text: description
|
text: params.description
|
||||||
})
|
})
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
@ -54,6 +60,9 @@ export class TransitViewSecretPage extends Page {
|
||||||
|
|
||||||
async render(): Promise<void> {
|
async render(): Promise<void> {
|
||||||
setTitleElement(pageState);
|
setTitleElement(pageState);
|
||||||
|
|
||||||
|
let transitKey = await getTransitKey(pageState.currentBaseMount, pageState.currentSecret);
|
||||||
|
|
||||||
setPageContent(makeElement({
|
setPageContent(makeElement({
|
||||||
tag: "div",
|
tag: "div",
|
||||||
class: ["uk-grid", "uk-child-width-expand@s"],
|
class: ["uk-grid", "uk-child-width-expand@s"],
|
||||||
|
@ -66,20 +75,22 @@ export class TransitViewSecretPage extends Page {
|
||||||
makeElement({
|
makeElement({
|
||||||
tag: "div",
|
tag: "div",
|
||||||
children: [
|
children: [
|
||||||
this.makeTile(
|
this.makeTile({
|
||||||
i18next.t("transit_view_encrypt_text"),
|
condition: transitKey.supports_encryption,
|
||||||
i18next.t("transit_view_encrypt_description"),
|
title: i18next.t("transit_view_encrypt_text"),
|
||||||
"lock",
|
description: i18next.t("transit_view_encrypt_description"),
|
||||||
i18next.t("transit_view_encrypt_icon_text"),
|
icon: "lock",
|
||||||
() => { changePage("TRANSIT_ENCRYPT"); }
|
iconText: i18next.t("transit_view_encrypt_icon_text"),
|
||||||
),
|
onclick: () => { changePage("TRANSIT_ENCRYPT"); }
|
||||||
this.makeTile(
|
}),
|
||||||
i18next.t("transit_view_decrypt_text"),
|
this.makeTile({
|
||||||
i18next.t("transit_view_decrypt_description"),
|
condition: transitKey.supports_decryption,
|
||||||
"mail",
|
title: i18next.t("transit_view_decrypt_text"),
|
||||||
i18next.t("transit_view_decrypt_icon_text"),
|
description: i18next.t("transit_view_decrypt_description"),
|
||||||
() => { changePage("TRANSIT_DECRYPT"); }
|
icon: "mail",
|
||||||
),
|
iconText: i18next.t("transit_view_decrypt_icon_text"),
|
||||||
|
onclick: () => { changePage("TRANSIT_DECRYPT"); }
|
||||||
|
}),
|
||||||
]
|
]
|
||||||
}),
|
}),
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in a new issue