diff options
| author | Sebastian <sebasjm@gmail.com> | 2023-05-18 20:32:20 -0300 |
|---|---|---|
| committer | Sebastian <sebasjm@gmail.com> | 2023-05-18 20:32:20 -0300 |
| commit | 38c65cc84ad0b41ccccf479fd55d0df21f0afe86 (patch) | |
| tree | 49961a87a48f4e88959058023e2c2e389e3c5ad7 /packages/exchange-backoffice-ui/src/pages | |
| parent | 20c3d4ef149268887107ddcc2b20a84db363dee6 (diff) | |
priv and pub key generation
Diffstat (limited to 'packages/exchange-backoffice-ui/src/pages')
4 files changed, 192 insertions, 20 deletions
diff --git a/packages/exchange-backoffice-ui/src/pages/AntiMoneyLaunderingForm.tsx b/packages/exchange-backoffice-ui/src/pages/AntiMoneyLaunderingForm.tsx new file mode 100644 index 000000000..ee9d1ce30 --- /dev/null +++ b/packages/exchange-backoffice-ui/src/pages/AntiMoneyLaunderingForm.tsx @@ -0,0 +1,71 @@ +import { h } from "preact"; +import { NiceForm } from "../NiceForm.js"; +import { v1 as form_902_11e_v1 } from "../forms/902_11e.js"; +import { v1 as form_902_12e_v1 } from "../forms/902_12e.js"; +import { v1 as form_902_13e_v1 } from "../forms/902_13e.js"; +import { v1 as form_902_15e_v1 } from "../forms/902_15e.js"; +import { v1 as form_902_1e_v1 } from "../forms/902_1e.js"; +import { v1 as form_902_4e_v1 } from "../forms/902_4e.js"; +import { v1 as form_902_5e_v1 } from "../forms/902_5e.js"; +import { v1 as form_902_9e_v1 } from "../forms/902_9e.js"; +import { DocumentDuplicateIcon } from "@heroicons/react/24/solid"; + +export function AntiMoneyLaunderingForm({ number }: { number?: string }) { + const selectedForm = Number.parseInt(number ?? "0", 10); + if (Number.isNaN(selectedForm)) { + return <div>WHAT! {number}</div>; + } + const showingFrom = allForms[selectedForm].impl; + const storedValue = { + fullName: "loggedIn_user_fullname", + when: { + t_ms: new Date().getTime(), + }, + }; + return ( + <NiceForm initial={storedValue} form={showingFrom} onUpdate={() => {}} /> + ); +} + +export const allForms = [ + { + name: "Identification form (902.1e)", + icon: DocumentDuplicateIcon, + impl: form_902_1e_v1, + }, + { + name: "Operational legal entity or partnership (902.11e)", + icon: DocumentDuplicateIcon, + impl: form_902_11e_v1, + }, + { + name: "Foundations (902.12e)", + icon: DocumentDuplicateIcon, + impl: form_902_12e_v1, + }, + { + name: "Declaration for trusts (902.13e)", + icon: DocumentDuplicateIcon, + impl: form_902_13e_v1, + }, + { + name: "Information on life insurance policies (902.15e)", + icon: DocumentDuplicateIcon, + impl: form_902_15e_v1, + }, + { + name: "Declaration of beneficial owner (902.9e)", + icon: DocumentDuplicateIcon, + impl: form_902_9e_v1, + }, + { + name: "Customer profile (902.5e)", + icon: DocumentDuplicateIcon, + impl: form_902_5e_v1, + }, + { + name: "Risk profile (902.4e)", + icon: DocumentDuplicateIcon, + impl: form_902_4e_v1, + }, +]; diff --git a/packages/exchange-backoffice-ui/src/pages/Info.tsx b/packages/exchange-backoffice-ui/src/pages/Info.tsx new file mode 100644 index 000000000..661ab02a7 --- /dev/null +++ b/packages/exchange-backoffice-ui/src/pages/Info.tsx @@ -0,0 +1,5 @@ +import { h } from "preact"; + +export function Info() { + return <div>Show key and wire info</div>; +} diff --git a/packages/exchange-backoffice-ui/src/pages/Officer.tsx b/packages/exchange-backoffice-ui/src/pages/Officer.tsx new file mode 100644 index 000000000..c72ca0720 --- /dev/null +++ b/packages/exchange-backoffice-ui/src/pages/Officer.tsx @@ -0,0 +1,116 @@ +import { useLocalStorage } from "@gnu-taler/web-util/browser"; +import { h } from "preact"; +import { useEffect, useState } from "preact/hooks"; + +const oldKey = + "MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDPQVq8F0Ce6kTXKQ5Ea2fZRoap6poFYs0FOln8o8+ehGI8rDdMBzNU3pLIlOMKs/vKvhDNMG4m4xxb92wDbvefDxkxaEkbRSZnRiJd4MIbh8Lx8zvFbLp03rkXu9KPN8IprKOXxgN7xbxm0KKcu03rtqLiOvC1gMqja2LMIPCi32nyNneduszHZ57d+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NenA6FlctsAeUYm+yXLgersrvcIsh3C2BJRGJf5t+w0ygFJewwGXff1pensfUq8Jqr5gy/WCSE135lOOuxDVzDI/Pif5YW6KQWQI3e/ScSaQRmIDINbrLcHXGdLMOzw9+LSdE4eqQKBgQDe86MfzwMLPoDH07WC09dCcoIUSYMThYrFwUK3qgEiYaJMZJvdAIwr12szVwVRYIX4wHBObFsQZLTaY5+O/REnze6Q1AQa2H6eH1TalC1r6jBS5/LhIrVWl/0VSdsUIe41tc8xPDWrm9hmLeJLZk+xb5/hAm3REsDM1Iif9O7zzg=="; +export function Officer() { + const storage = useLocalStorage("officer"); + const [keys, setKeys] = useState({ priv: "", pub: "" }); + useEffect(() => { + loadPreviousSession(oldKey).then((keys) => + setKeys(keys ?? { priv: "", pub: "" }), + ); + // generateNewId().then((keys) => setKeys(keys)); + }, []); + + console.log(keys.pub); + console.log(keys.priv); + return ( + <div> + <div>Officer</div> + <h1 class="my-2 text-3xl font-bold tracking-tight text-gray-900 "> + Public key + </h1> + <div> + -----BEGIN PUBLIC KEY----- + <p class="mt-6 leading-8 text-gray-700 break-all">{keys.pub}</p> + -----END PUBLIC KEY----- + </div> + <h1 class="my-2 text-3xl font-bold tracking-tight text-gray-900 "> + Private key + </h1> + <div> + -----BEGIN PRIVATE KEY----- + <p class="mt-6 leading-8 text-gray-700 break-all">{keys.priv}</p> + -----END PRIVATE KEY----- + </div> + </div> + ); +} + +const rsaAlgorithm: RsaHashedKeyGenParams = { + name: "RSA-OAEP", + modulusLength: 2048, + publicExponent: new Uint8Array([0x01, 0x00, 0x01]), + hash: "SHA-256", +}; + +async function generateNewId() { + const key = await crypto.subtle.generateKey(rsaAlgorithm, true, [ + "encrypt", + "decrypt", + ]); + + if (key instanceof CryptoKey) { + throw Error("unexpected key without pair"); + } + const { privateKey, publicKey } = key; + const privRaw = await crypto.subtle.exportKey("pkcs8", privateKey); + + const pubRaw = await crypto.subtle.exportKey("spki", publicKey); + + const priv = btoa(ab2str(privRaw)); + + const pub = btoa(ab2str(pubRaw)); + return { priv, pub }; +} + +async function loadPreviousSession(priv: string) { + const key = str2ab(window.atob(priv)); + const privateKey = await window.crypto.subtle + .importKey("pkcs8", key, rsaAlgorithm, true, ["decrypt"]) + .catch(throwErrorWithStack); + + if (!privateKey) return undefined; + + // export private key to JWK + const jwk = await crypto.subtle + .exportKey("jwk", privateKey) + .catch(throwErrorWithStack); + + // remove private data from JWK + delete jwk.d; + delete jwk.dp; + delete jwk.dq; + delete jwk.q; + delete jwk.qi; + jwk.key_ops = ["encrypt"]; + + const publicKey = await crypto.subtle + .importKey("jwk", jwk, rsaAlgorithm, true, ["encrypt"]) + .catch(throwErrorWithStack); + + const pubRaw = await crypto.subtle + .exportKey("spki", publicKey) + .catch(throwErrorWithStack); + + const pub = btoa(ab2str(pubRaw)); + + return { priv, pub }; +} + +function ab2str(buf: ArrayBuffer) { + return String.fromCharCode.apply(null, Array.from(new Uint8Array(buf))); +} +function str2ab(str: string) { + const buf = new ArrayBuffer(str.length); + const bufView = new Uint8Array(buf); + for (let i = 0, strLen = str.length; i < strLen; i++) { + bufView[i] = str.charCodeAt(i); + } + return buf; +} +function throwErrorWithStack(e: Error): never { + throw new Error(e.message); +} diff --git a/packages/exchange-backoffice-ui/src/pages/ShowForm.tsx b/packages/exchange-backoffice-ui/src/pages/ShowForm.tsx deleted file mode 100644 index 5440ab7e1..000000000 --- a/packages/exchange-backoffice-ui/src/pages/ShowForm.tsx +++ /dev/null @@ -1,20 +0,0 @@ -import { h } from "preact"; -import { allForms } from "../Dashboard.js"; -import { NiceForm } from "../NiceForm.js"; - -export function ShowForm({ number }: { number?: string }) { - const selectedForm = Number.parseInt(number ?? "0", 10); - if (Number.isNaN(selectedForm)) { - return <div>WHAT! {number}</div>; - } - const showingFrom = allForms[selectedForm].impl; - const storedValue = { - fullName: "loggedIn_user_fullname", - when: { - t_ms: new Date().getTime(), - }, - }; - return ( - <NiceForm initial={storedValue} form={showingFrom} onUpdate={() => {}} /> - ); -} |
