Skip to content

Commit

Permalink
⚙️ Add rust crate_server
Browse files Browse the repository at this point in the history
 - Soon each node will serve the dapp individually
   the canonical dapp url will resolve to a
   random node serving the dapp.
  • Loading branch information
KimlikDAO-bot committed Sep 1, 2024
1 parent 334248d commit 9fd1c27
Show file tree
Hide file tree
Showing 19 changed files with 330 additions and 35 deletions.
22 changes: 13 additions & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:

jobs:
checkSignerNode:
if: false
strategy:
fail-fast: true

Expand Down Expand Up @@ -39,6 +40,7 @@ jobs:
run: make build/signerNode.js

checkLightNode:
if: false
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -54,18 +56,20 @@ jobs:
- name: Build lightNode
run: make build/lightNode.js

runUnitTests:
checkCrateServer:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Checkout repository
uses: actions/checkout@v3
with:
submodules: recursive

- name: Install bun
uses: oven-sh/setup-bun@v1

- name: Install dependencies
run: bun i
- name: Set up Rust
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
override: true

- name: Run Mina unit tests
run: make mina.test
- name: Run tests
run: cargo test --all --verbose
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
/build
/target
node_modules
.vscode
/crate

# Contains confidential test data such as actual e-devlet pdfs.
/edevlet/testdata
21 changes: 19 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
cargo-features = ["edition2024"]

[package]
name = "kimlikdao-node"
version = "0.1.0"
edition = "2021"
version = "0.0.1"
edition = "2024"

[[bin]]
name = "crate_server"
path = "rust/crate_server/main.rs"

[dependencies]
hyper = { version = "0.14.12", features = ["http1", "server", "tcp"] }
lazy_static = "1.5.0"
phf = { version = "0.11.2", features = ["macros"] }
serde = { version = "1.0", features = ["derive"] }
serde_yaml = "0.9"
tokio = { version = "1", features = ["full"] }

[profile.release]
opt-level = 3
lto = "fat"
codegen-units = 1
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ WORKER_NAME = $(subst $\",,$(CF_WORKER_NAME))

lib = node_modules/@kimlikdao/lib

include lib/util/Makefile
include edevlet/Makefile
include lightNode/Makefile
include signerNode/Makefile
Expand Down
Empty file added edevlet/build.js
Empty file.
6 changes: 3 additions & 3 deletions edevlet/nko.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { keccak256Uint32 } from "@kimlikdao/lib/crypto/sha3";
import { err, ErrorCode } from "@kimlikdao/lib/node/error";
import { base64ten, uint8ArrayeBase64ten } from "@kimlikdao/lib/util/çevir";
import { validatePoW } from "./validation";
import { keccak256Uint32 } from "/lib/crypto/sha3";
import { err, ErrorCode } from "/lib/node/error";
import { base64ten, uint8ArrayeBase64ten } from "/util/çevir";

/** @const {!Object<string, string>} */
const STATIC_HEADERS = {
Expand Down
2 changes: 1 addition & 1 deletion edevlet/nkoParser.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ErrorCode, reject } from "@kimlikdao/lib/node/error";
import { ErrorCode, reject } from "/lib/node/error";

/** @const {!Object<string, number>} */
const MONTHS = {
Expand Down
6 changes: 3 additions & 3 deletions edevlet/nkoWorker.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { sign } from "@kimlikdao/lib/did/decryptedSections";
import { err, ErrorCode, errorResponse, reject } from "@kimlikdao/lib/node/error";
import { base64, base64ten } from "@kimlikdao/lib/util/çevir";
import { generateCommitment } from "./nko";
import { getValidatingTckt, ValidatingTckt } from "./nkoParser";
import { validatePoW, validateTimestamp } from "./validation";
import { sign } from "/lib/did/sectionSigner";
import { err, ErrorCode, errorResponse, reject } from "/lib/node/error";
import { base64, base64ten } from "/lib/util/çevir";

/** @const {!Object<string, string>} */
const HEADERS = {
Expand Down
6 changes: 3 additions & 3 deletions edevlet/oauth2Worker.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { sign } from "@kimlikdao/lib/did/decryptedSections";
import { err, ErrorCode } from "@kimlikdao/lib/node/error";
import { base64, base64ten } from "@kimlikdao/lib/util/çevir";
import { validateTimestamp } from "./validation";
import { sign } from "/lib/did/sectionSigner";
import { err, ErrorCode } from "/lib/node/error";
import { base64, base64ten } from "/lib/util/çevir";

/**
* @const {string}
Expand Down
6 changes: 3 additions & 3 deletions edevlet/validation.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { keccak256Uint32 } from "@kimlikdao/lib/crypto/sha3";
import { ErrorCode, errWithMessage } from "@kimlikdao/lib/node/error";
import { keccak256Uint32 } from "/lib/crypto/sha3";
import { ErrorCode, errWithMessage } from "/lib/node/error";

/**
* @param {number} remoteTs
Expand Down Expand Up @@ -28,4 +28,4 @@ const validatePoW = (commitPow, powThreshold) => {
return errWithMessage(406, ErrorCode.INVALID_POW, ["" + digit, "" + powThreshold]);
}

export { validateTimestamp, validatePoW };
export { validatePoW, validateTimestamp };
2 changes: 1 addition & 1 deletion ipfs/ipfs.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ipfs from '@kimlikdao/lib/node/ipfs';
import ipfs from "/lib/node/ipfs";

/**
* @param {!Request} req
Expand Down
10 changes: 10 additions & 0 deletions jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"/*": [
"*"
]
}
}
}
2 changes: 1 addition & 1 deletion lib
Submodule lib updated 254 files
1 change: 0 additions & 1 deletion lightNode/lightNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,4 @@ const LightNodeWorker = {
}
};

globalThis["LightNodeWorker"] = LightNodeWorker;
export default LightNodeWorker;
8 changes: 4 additions & 4 deletions mina/MerkleTree.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { poseidon } from "@kimlikdao/lib/crypto/poseidon";
import hex from "@kimlikdao/lib/util/hex";
import { DurableObject } from "cloudflare:workers";
import { poseidon } from "/lib/crypto/minaPoseidon";
import hex from "/lib/util/hex";
import {
BinaryKey,
HexKey,
MerkleTree as IMerkleTree,
Value,
WitnessElem,
} from "@kimlikdao/lib/util/merkleTree";
import { DurableObject } from "cloudflare:workers";
} from "/lib/util/merkleTree";

/**
* In InvKey, the last bit is inverted. This achieves some optimizations
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DurableObjectState } from "@kimlikdao/lib/cloudflare/mock/durableObject";
import { MinaMerkleTree } from "@kimlikdao/lib/mina/merkleTree";
import { assertArrayEq, assertEq } from "@kimlikdao/lib/testing/assert";
import { DurableObjectState } from "/lib/birimler/cloudflare/mock/durableObject";
import { MinaMerkleTree } from "/lib/mina/merkleTree";
import { assertArrayEq, assertEq } from "/lib/testing/assert";
import { HexKey, MerkleTree, WitnessElem } from "../MerkleTree";

/**
Expand Down
55 changes: 55 additions & 0 deletions rust/crate_server/crates.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
use serde::Deserialize;
use std::collections::HashMap;
use std::fs;
use std::fs::File;

#[derive(Debug, Deserialize)]
struct CrateRecipe {
dizin: String,
sayfalar: Vec<Sayfa>,
}

#[derive(Debug, Deserialize)]
struct Sayfa {
tr: String,
en: String,
}

pub fn load(path: &str) -> HashMap<String, &'static [u8]> {
let mut files = HashMap::new();
for entry in fs::read_dir(path).unwrap() {
let entry = entry.unwrap();
let path = entry.path();
if path.is_file() {
let filename = path.file_name().unwrap().to_string_lossy().to_string();
let content: &'static [u8] = Box::leak(fs::read(&path).unwrap().into_boxed_slice());
files.insert(filename, content);
}
}
let file = File::open("./crate/crate.yaml").unwrap();
let recipe: CrateRecipe = serde_yaml::from_reader(file).unwrap();

let mut insert_alias = |alias: &str, key_base: &str, lang: &str, ext: &str| {
if let Some(&content) = files.get(&format!("{}-{}.html{}", key_base, lang, ext)) {
files.insert(format!("{}{}", alias, ext), content);
}
};

insert_alias("?en", &recipe.dizin, "en", "");
insert_alias("?en", &recipe.dizin, "en", ".br");
insert_alias("?en", &recipe.dizin, "en", ".gz");
insert_alias("?tr", &recipe.dizin, "tr", "");
insert_alias("?tr", &recipe.dizin, "tr", ".br");
insert_alias("?tr", &recipe.dizin, "tr", ".gz");

for sayfa in &recipe.sayfalar {
insert_alias(&sayfa.en, &sayfa.tr, "en", "");
insert_alias(&sayfa.tr, &sayfa.tr, "tr", "");
insert_alias(&sayfa.en, &sayfa.tr, "en", ".br");
insert_alias(&sayfa.tr, &sayfa.tr, "tr", ".br");
insert_alias(&sayfa.en, &sayfa.tr, "en", ".gz");
insert_alias(&sayfa.tr, &sayfa.tr, "tr", ".gz");
}

files
}
Loading

0 comments on commit 9fd1c27

Please sign in to comment.