Skip to content

Commit

Permalink
added quicknet-t
Browse files Browse the repository at this point in the history
  • Loading branch information
CluEleSsUK committed Mar 3, 2024
1 parent 818e632 commit 4c68995
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 30 deletions.
10 changes: 7 additions & 3 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<DropdownItem<Network>> = [
{
label: "Mainnet (quicknet)",
Expand All @@ -17,8 +17,12 @@ const networks: Array<DropdownItem<Network>> = [
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 = () => {
Expand Down
15 changes: 14 additions & 1 deletion src/actions/client-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
23 changes: 16 additions & 7 deletions src/actions/decrypt-multi.ts
Original file line number Diff line number Diff line change
@@ -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 = {
Expand All @@ -17,13 +17,22 @@ export type DecryptionContent = TextContent | VulnerabilityReportContent

export async function decryptMulti(network: Network, ciphertext: string): Promise<DecryptionContent> {
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)) {
Expand Down
22 changes: 15 additions & 7 deletions src/actions/encrypt-text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof textEncryptionSchema>

export async function encryptedOrDecryptedFormData(network: Network, form: unknown): Promise<CompletedWebForm> {
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) {
Expand Down
32 changes: 20 additions & 12 deletions src/actions/encrypt-vulnerability-report.ts
Original file line number Diff line number Diff line change
@@ -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<string> {
const input = await vulnerabilityEncryptionSchema.validate(form)
Expand All @@ -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)
}

0 comments on commit 4c68995

Please sign in to comment.