From 4c68995fe37b1cff7a941a26b82025879d40a914 Mon Sep 17 00:00:00 2001 From: Patrick McClurg Date: Sun, 3 Mar 2024 01:37:13 +0100 Subject: [PATCH] added quicknet-t --- src/App.tsx | 10 +++++-- src/actions/client-utils.ts | 15 +++++++++- src/actions/decrypt-multi.ts | 23 ++++++++++----- src/actions/encrypt-text.ts | 22 +++++++++----- src/actions/encrypt-vulnerability-report.ts | 32 +++++++++++++-------- 5 files changed, 72 insertions(+), 30 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index d9e5bcf..cc3daf5 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -6,7 +6,7 @@ import {VulnerabilityReportEncrypt} from "./views/VulnerabilityReportEncrypt" import {MultiDecrypt} from "./views/MultiDecrypt" import {Dropdown, DropdownItem} from "./components/Dropdown" -export type Network = "quicknet" | "fastnet" | "testnet" +export type Network = "quicknet" | "fastnet" | "testnet-unchained-3s" | "quicknet-t" const networks: Array> = [ { label: "Mainnet (quicknet)", @@ -17,8 +17,12 @@ const networks: Array> = [ value: "fastnet" }, { - label: "Testnet", - value: "testnet" + label: "Testnet (quicknet-t)", + value: "quicknet-t" + }, + { + label: "Testnet (testnet-unchained-3s - deprecated", + value: "testnet-unchained-3s" }, ] const App = () => { diff --git a/src/actions/client-utils.ts b/src/actions/client-utils.ts index 672e092..f1c0312 100644 --- a/src/actions/client-utils.ts +++ b/src/actions/client-utils.ts @@ -27,7 +27,20 @@ export function fastnet(): HttpChainClient { return new HttpChainClient(new HttpCachingChain(MAINNET_CHAIN_URL_NON_RFC, clientOpts), clientOpts, {}) } -export function testnet(): HttpChainClient { +export function testnetQuicknet(): HttpChainClient { + const clientOpts = { + disableBeaconVerification: false, + noCache: false, + chainVerificationParams: { + chainHash: "cc9c398442737cbd141526600919edd69f1d6f9b4adb67e4d912fbc64341a9a5", + publicKey: "b15b65b46fb29104f6a4b5d1e11a8da6344463973d423661bb0804846a0ecd1ef93c25057f1c0baab2ac53e56c662b66072f6d84ee791a3382bfb055afab1e6a375538d8ffc451104ac971d2dc9b168e2d3246b0be2015969cbaac298f6502da" + } + } + + // passing an empty httpOptions arg to strip the user agent header to stop CORS issues + return new HttpChainClient(new HttpCachingChain("https://pl-us.testnet.drand.sh/cc9c398442737cbd141526600919edd69f1d6f9b4adb67e4d912fbc64341a9a5", clientOpts), clientOpts, {}) +} +export function testnetUnchained(): HttpChainClient { const clientOpts = { disableBeaconVerification: false, noCache: false, diff --git a/src/actions/decrypt-multi.ts b/src/actions/decrypt-multi.ts index d23bc4b..1e47b62 100644 --- a/src/actions/decrypt-multi.ts +++ b/src/actions/decrypt-multi.ts @@ -1,7 +1,7 @@ import {HttpChainClient, timelockDecrypt} from "tlock-js" import {vulnerabilityDecryptionSchema} from "../schema/vulnerability-encryption-schema" import {Network} from "../App" -import {fastnet, quicknet, testnet} from "./client-utils" +import {fastnet, quicknet, testnetQuicknet, testnetUnchained} from "./client-utils" type TextContent = { type: "text", value: string } type VulnerabilityReportContent = { @@ -17,13 +17,22 @@ export type DecryptionContent = TextContent | VulnerabilityReportContent export async function decryptMulti(network: Network, ciphertext: string): Promise { let client: HttpChainClient - if (network === "quicknet") { - client = quicknet() - } else if (network === "fastnet") { - client = fastnet() - } else { - client = testnet() + switch (network) { + case "quicknet": + client = quicknet() + break + case "fastnet": + client = fastnet() + break + case "quicknet-t": + client = testnetQuicknet() + break + case "testnet-unchained-3s": + client = testnetUnchained() + break + default: throw Error("unknown network") } + const plaintext = await timelockDecrypt(ciphertext, client) if (await vulnerabilityDecryptionSchema.isValid(plaintext)) { diff --git a/src/actions/encrypt-text.ts b/src/actions/encrypt-text.ts index 11d6c1e..462091c 100644 --- a/src/actions/encrypt-text.ts +++ b/src/actions/encrypt-text.ts @@ -2,19 +2,27 @@ import * as yup from "yup" import {HttpChainClient, roundAt, timelockDecrypt, timelockEncrypt} from "tlock-js" import {textEncryptionSchema} from "../schema/text-encryption-schema" import {Network} from "../App" -import {fastnet, quicknet, testnet} from "./client-utils" +import {fastnet, quicknet, testnetQuicknet, testnetUnchained} from "./client-utils" export type CompletedWebForm = yup.InferType export async function encryptedOrDecryptedFormData(network: Network, form: unknown): Promise { const partialWebForm = await textEncryptionSchema.validate(form) let client: HttpChainClient - if (network === "quicknet") { - client = quicknet() - } else if (network === "fastnet") { - client = fastnet() - } else { - client = testnet() + switch (network) { + case "quicknet": + client = quicknet() + break + case "fastnet": + client = fastnet() + break + case "quicknet-t": + client = testnetQuicknet() + break + case "testnet-unchained-3s": + client = testnetUnchained() + break + default: throw Error("unknown network") } if (partialWebForm.plaintext) { diff --git a/src/actions/encrypt-vulnerability-report.ts b/src/actions/encrypt-vulnerability-report.ts index ef0ff43..1d46fad 100644 --- a/src/actions/encrypt-vulnerability-report.ts +++ b/src/actions/encrypt-vulnerability-report.ts @@ -1,9 +1,8 @@ import {vulnerabilityEncryptionSchema} from "../schema/vulnerability-encryption-schema" -import {roundAt, timelockEncrypt} from "tlock-js" -import {MAINNET_CHAIN_INFO, TESTNET_CHAIN_INFO} from "tlock-js/drand/defaults" +import {HttpChainClient, roundAt, timelockEncrypt} from "tlock-js" import {fileAsBuffer} from "./file-utils" import {Network} from "../App" -import {quicknet, testnet} from "./client-utils" +import {fastnet, quicknet, testnetQuicknet, testnetUnchained} from "./client-utils" export async function encryptVulnerabilityReport(network: Network, form: unknown): Promise { const input = await vulnerabilityEncryptionSchema.validate(form) @@ -30,14 +29,23 @@ export async function encryptVulnerabilityReport(network: Network, form: unknown file }) - if (network === "quicknet") { - const roundNumber = roundAt(input.decryptionTime, MAINNET_CHAIN_INFO) - return await timelockEncrypt(roundNumber, Buffer.from(plaintext), quicknet()) - } else if (network === "fastnet") { - const roundNumber = roundAt(input.decryptionTime, MAINNET_CHAIN_INFO) - return await timelockEncrypt(roundNumber, Buffer.from(plaintext), quicknet()) - } else { - const roundNumber = roundAt(input.decryptionTime, TESTNET_CHAIN_INFO) - return await timelockEncrypt(roundNumber, Buffer.from(plaintext), testnet()) + let client: HttpChainClient + switch (network) { + case "quicknet": + client = quicknet() + break + case "fastnet": + client = fastnet() + break + case "quicknet-t": + client = testnetQuicknet() + break + case "testnet-unchained-3s": + client = testnetUnchained() + break + default: + throw Error("unknown network") } + const roundNumber = roundAt(input.decryptionTime, await client.chain().info()) + return await timelockEncrypt(roundNumber, Buffer.from(plaintext), client) }