Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/uix-deploy-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ name: Deploy prod
on: push
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
HOST_TOKEN: ${{secrets.HOST_TOKEN}}
jobs:
deploy:
runs-on: ubuntu-latest
Expand All @@ -15,4 +16,4 @@ jobs:
- name: Setup Deno
uses: "denoland/setup-deno@v1"
- name: Deploy UIX App
run: "deno run --importmap ./importmap.json -Aqr https://cdn.unyt.org/uix@0.2.x/run.ts --stage prod --detach"
run: "deno run --importmap ./importmap.json -Aqr https://cdn.unyt.org/uix@0.3.x/run.ts --stage prod --detach"
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"deno.enable": true
}
2 changes: 1 addition & 1 deletion backend/.dx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ endpoint: stage {
},

location: stage {
prod: @+unyt-host-4
prod: @+unyt-private-1
},

domain: stage {
Expand Down
3 changes: 1 addition & 2 deletions common/TOR-Worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const ed = await import("https://unpkg.com/@noble/[email protected]/index.js");
const base32 = await import("https://cdn.jsdelivr.net/npm/[email protected]/+esm");
await import("https://cdn.jsdelivr.net/npm/[email protected]/src/sha3.min.js");


export type AddressData = {
address: string;
public: {
Expand Down Expand Up @@ -81,7 +80,7 @@ async function generateOnionV3(keys: KeyPair | Promise<KeyPair> = generateKeys()
hash.update(version);

const checksum = hash.digest().slice(0, 2);

const decoded = new Uint8Array([...publicKey, ...checksum, ...version]);
const address = base32.encode(Array.from(decoded)).toLowerCase().concat(".onion");
const _publicKey = getPublicKey(address);
Expand Down
87 changes: 87 additions & 0 deletions common/components/MainPage.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@

:host {
display: flex;
flex-direction: column;
font-size: x-large;
padding: 10px;
width: 70%;
margin: auto;
align-items: center;
margin-top: 40px;
text-align: center;
&>div {
margin-top: 30px;
width: 100%;
flex-wrap: wrap;
justify-content: center;
&>h2 {
width: 100%;
}
grid-gap: 20px;
gap: 20px;
display: flex;
border-bottom: 1px solid gray;
padding-bottom: 30px;
&>input {
flex: 1;
padding: 20px;
border-radius: var(--standard-border-radius);
max-width: 300px;
background-color: transparent;
color: var(--text_highlight);
padding-left: 20px;
font-size: x-large;
border: 2px solid var(--accent);
}

&.hidden {
&>.button {
opacity: 0.4;
background-color: transparent;
border-color: var(--red);
color: var(--text_highlight);
}
}
&>div {
transition: opacity 0.2s;
background-color: var(--text_highlight);
border: 3px solid var(--text_highlight);
border-radius: var(--standard-border-radius);
padding: 10px;
cursor: pointer;
transition: background-color 0.2s;
box-sizing: border-box;
color: var(--accent);
&:hover {
color: var(--text_highlight);
background-color: transparent;
}
}
&>.results {
text-align: left;
word-break: break-word;
width: 100%;
gap: 6px;
font-family: monospace;
display: flex;
flex-direction: column;
}
}
&>#tor {
span {
max-width: 1000px;
margin: auto;
width: 100%;
display: flex;
flex-wrap: wrap;
b {
width: 50%;
}
a {
margin: auto;
margin-bottom: 10px;
text-align: center;
}
}
}
}
89 changes: 0 additions & 89 deletions common/components/MainPage.scss

This file was deleted.

90 changes: 56 additions & 34 deletions common/components/MainPage.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,43 @@
import { template } from "uix/html/template.ts";
import { Component } from "uix/components/Component.ts";
import { spawnThreads, spawnThread } from "unyt_core/threads/threads.ts";
import { always, map } from "unyt_core/functions.ts";
import { spawnThreads, spawnThread, run } from "datex-core-legacy/threads/threads.ts";
import type { AddressData } from "common/TOR-Worker.ts";

@template(function(this: MainPage) {
return <div>
<div id="tor" class={always(()=>this.calculatingAddress?'hidden':'')}>
return <>
<div id="run" class={this.calculatingPI ? 'hidden': ''}>
<h2>Use Console</h2>
<div onclick={() => this.runConsole()} class="button">
Run in Thread
</div>
</div>
<div id="pi" class={this.calculatingPI ? 'hidden': ''}>
<h2>Calculate PI</h2>
<input id="inputPiDigits"
type="number"
placeholder="Number of digits"
value={this.piDigits}/>
<div onclick={() => this.computePI()} class="button">{
this.calculatingPI ? "Waiting" : "Calculate"
}</div>
<section class="results">
{this.resultPIs.map(pi =>
<span>{pi}</span>
)}
</section>
</div>
<div id="tor" class={this.calculatingAddress ? 'hidden': ''}>
<h2>Create TOR Address</h2>
<input id="torAddress" maxlength="3" type="text" placeholder="Prefix of vanity address" value={this.$.addressPrefix}/>
<div onclick={() => this.createVanityAddress()} class="button">Compute</div>
<input id="torAddress"
maxlength="3"
type="text"
placeholder="Prefix of vanity address"
value={this.addressPrefix}/>
<div onclick={() => this.createVanityAddress()} class="button">{
this.calculatingAddress ? "Waiting" : "Calculate"
}</div>
<section class="results">
{map(this.resultAddresses, (address: AddressData) =>
{this.resultAddresses.map(address =>
<span>
<a>{address.address}</a>
<b>Pub: {address.public.b64}</b>
Expand All @@ -20,44 +46,26 @@ import type { AddressData } from "common/TOR-Worker.ts";
)}
</section>
</div>
<div id="pi" class={always(()=>this.calculatingPI?'hidden':'')}>
<h2>Calculate PI</h2>
<input id="inputPiDigits" type="number" placeholder="Number of digits" value={this.$.piDigits}/>
<div onclick={() => this.computePI()} class="button">Compute</div>
<section class="results">
{map(this.resultPIs, (pi: string) =>
<span>{pi}</span>
)}
</section>
</div>
</div>
</>
})
export class MainPage extends Component {

// reference properties for input values
@property piDigits = 5;
@property addressPrefix = "";
@property addressPrefix = '';

// reference properties for calculation state
@property calculatingPI = false
@property calculatingAddress = false

// arrays containing history of calculated results
@property resultPIs:string[] = []
@property resultAddresses:AddressData[] = []

async createVanityAddress() {
this.calculatingAddress = true;
@property resultPIs: string[] = []
@property resultAddresses: AddressData[] = []

// spawn 10 new threads
using threads = await spawnThreads<typeof import('../TOR-Worker.ts')>('../TOR-Worker.ts', 10);
// try to find an address in parallel
const address = await Promise.any(
threads.map(thread => thread.generateVanityAddress(this.addressPrefix))
);
this.resultAddresses.unshift(address);

this.calculatingAddress = false;
runConsole() {
run(() => {
console.log("Hello, main thread!");
globalThis.console.log("Hello, worker!");
});
}

async computePI() {
Expand All @@ -71,4 +79,18 @@ export class MainPage extends Component {

this.calculatingPI = false;
}

async createVanityAddress() {
this.calculatingAddress = true;

// spawn 10 new threads
using threads = await spawnThreads<typeof import('../TOR-Worker.ts')>('../TOR-Worker.ts', 10);
// try to find an address in parallel
const address = await Promise.any(
threads.map(thread => thread.generateVanityAddress(this.addressPrefix))
);
this.resultAddresses.unshift(address);

this.calculatingAddress = false;
}
}
5 changes: 2 additions & 3 deletions deno.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{
"_publicImportMap": "./importmap.json",
"importMap": "./.datex-cache/importmap.lock.json",
"importMap": "./importmap.json",
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "uix",
"jsxImportSource": "jusix",
"lib": [
"dom",
"deno.window"
Expand Down
2 changes: 1 addition & 1 deletion frontend/entrypoint.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
slot#main {
overflow-y: scroll;
}
.button {
div.button {
display: flex;
align-items: center;
}
Expand Down
5 changes: 3 additions & 2 deletions frontend/entrypoint.tsx
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
import { MainPage } from "../common/components/MainPage.tsx";
export default <MainPage/>
import { type Entrypoint } from "uix/providers/entrypoints.ts";
import { MainPage } from "common/components/MainPage.tsx";
export default <MainPage/> satisfies Entrypoint;
13 changes: 0 additions & 13 deletions importmap.dev.json

This file was deleted.

Loading
Loading