Skip to content

Commit

Permalink
πŸŽ„ Add Mina MerkleTree service
Browse files Browse the repository at this point in the history
  • Loading branch information
KimlikDAO-bot committed May 21, 2024
1 parent af0c37f commit 40118c0
Show file tree
Hide file tree
Showing 24 changed files with 356 additions and 91 deletions.
34 changes: 24 additions & 10 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
branches: ["main", "prod"]

jobs:
check:
checkSignerNode:
strategy:
fail-fast: true

Expand All @@ -17,16 +17,30 @@ jobs:
with:
submodules: recursive

- uses: actions/setup-node@v3
with:
node-version: 18
- name: Install bun
uses: oven-sh/setup-bun@v1

- name: Install dependencies
run: bun i

- name: Build nkoWorker
run: make build/nkoWorker.js

- name: Build signerNode
run: |
yarn
make build/signerNode.js
run: make build/signerNode.js

checkLightNode:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive

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

- name: Install dependencies
run: bun i

- name: Build lightNode
run: |
yarn
make build/lightNode.js
run: make build/lightNode.js
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.DS_Store
*.lock
.wrangler
*lock*
*.vars
/build
/node_modules
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ include signerNode/signerNode.config

WORKER_NAME = $(subst $\",,$(CF_WORKER_NAME))

lib = node_modules/@kimlikdao/lib

include edevlet/Makefile
include lightNode/Makefile
include signerNode/Makefile
include workers/Makefile
include mina/Makefile

build/BEARER_TOKEN:
mkdir -p $(dir $@)
Expand Down
64 changes: 32 additions & 32 deletions edevlet/Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
include edevlet/test/Makefile

build/edevlet/nkoParser.js: edevlet/nkoParser.js edevlet/pdfjs.d.js \
lib/crosschain/*.d.js \
lib/did/*.d.js \
lib/ethereum/*.d.js \
lib/node/error.d.js lib/node/error.js \
lib/node/nvi.d.js
$(lib)/crosschain/*.d.js \
$(lib)/did/*.d.js \
$(lib)/ethereum/*.d.js \
$(lib)/node/error.d.js $(lib)/node/error.js \
$(lib)/node/nvi.d.js
mkdir -p $(dir $@)
yarn google-closure-compiler -W VERBOSE -O ADVANCED --charset UTF-8 \
bun google-closure-compiler -W VERBOSE -O ADVANCED --charset UTF-8 \
--jscomp_error=unusedLocalVariables \
--jscomp_error=strictCheckTypes \
--jscomp_warning=reportUnknownTypes \
Expand All @@ -19,41 +19,41 @@ build/edevlet/nkoParser.js: edevlet/nkoParser.js edevlet/pdfjs.d.js \
--entry_point $< \
--js $^ \
--js_output_file $@
yarn uglifyjs $@ -m -c toplevel,unsafe,drop_console -o $@
bun uglifyjs $@ -m -c toplevel,unsafe,drop_console -o $@
wc $@

build/edevlet/pdfjs.js: edevlet/pdfjs.js \
edevlet/pdf.js/src/pdf.js \
edevlet/pdf.js/src/shared/*.js edevlet/pdf.js/src/display/*.js \
edevlet/pdf.js/src/core/*.js edevlet/pdf.js/src/core/xfa/*.js
mkdir -p $(dir $@)
yarn google-closure-compiler -W VERBOSE -O SIMPLE \
bun google-closure-compiler -W VERBOSE -O SIMPLE \
--language_in ECMASCRIPT_NEXT \
--module_resolution NODE \
--assume_function_wrapper \
--dependency_mode PRUNE \
--entry_point $< \
--js $^ \
--js_output_file $@.tmp
yarn uglifyjs $@.tmp -m -c toplevel,unsafe,drop_console -o $@.tmp
bun uglifyjs $@.tmp -m -c toplevel,unsafe,drop_console -o $@.tmp
printf "'use strict';(()=>{" | cat - $@.tmp > $@
printf "})();" >> $@
wc $@

build/oauth2Worker.js: edevlet/oauth2Worker.js edevlet/oauth2Worker.d.js \
edevlet/validation.js \
lib/api/oauth2.d.js \
lib/cloudflare/types.d.js lib/cloudflare/moduleWorker.d.js \
lib/crosschain/*.js \
lib/crypto/sha3.js \
lib/crypto/modular.js lib/crypto/secp256k1.js \
lib/did/*.d.js lib/did/section.js lib/did/decryptedSections.js \
lib/ethereum/*.d.js lib/ethereum/evm.js \
lib/node/error.d.js lib/node/error.js lib/node/nvi.d.js \
lib/util/Γ§evir.js \
$(lib)/api/oauth2.d.js \
$(lib)/cloudflare/types.d.js $(lib)/cloudflare/moduleWorker.d.js \
$(lib)/crosschain/*.js \
$(lib)/crypto/sha3.js \
$(lib)/crypto/modular.js $(lib)/crypto/secp256k1.js \
$(lib)/did/*.d.js $(lib)/did/section.js $(lib)/did/decryptedSections.js \
$(lib)/ethereum/*.d.js $(lib)/ethereum/evm.js \
$(lib)/node/error.d.js $(lib)/node/error.js $(lib)/node/nvi.d.js \
$(lib)/util/Γ§evir.js \
build/BEARER_TOKEN
mkdir -p $(dir $@)
yarn google-closure-compiler -W VERBOSE -O ADVANCED --charset UTF-8 \
bun google-closure-compiler -W VERBOSE -O ADVANCED --charset UTF-8 \
--define "BEARER_TOKEN\$$\$$module\$$edevlet\$$oauth2Worker=$(shell cat build/BEARER_TOKEN)" \
--define "CF_ACCOUNT_NAME\$$\$$module\$$edevlet\$$oauth2Worker=$(CF_ACCOUNT_NAME)" \
--define "WORKER_NAME\$$\$$module\$$edevlet\$$oauth2Worker=$(WORKER_NAME)" \
Expand All @@ -66,25 +66,25 @@ build/oauth2Worker.js: edevlet/oauth2Worker.js edevlet/oauth2Worker.d.js \
--entry_point $< \
--js $(filter %.js, $^) \
--js_output_file $@
yarn uglifyjs $@ -m -c toplevel,unsafe,drop_console -o $@
bun uglifyjs $@ -m -c toplevel,unsafe,drop_console -o $@
sed -i.bak 's/globalThis.OAuth2Worker=/export default/g' $@
wc $@

build/nkoWorker.js: edevlet/nkoWorker.js \
edevlet/nko.d.js edevlet/nko.js edevlet/validation.js \
edevlet/nkoParser.js edevlet/pdfjs.d.js \
lib/cloudflare/types.d.js lib/cloudflare/moduleWorker.d.js \
lib/crosschain/*.js \
lib/crypto/sha3.js \
lib/crypto/modular.js lib/crypto/secp256k1.js \
lib/did/*.d.js lib/did/section.js lib/did/decryptedSections.js \
lib/ethereum/*.d.js lib/ethereum/evm.js \
lib/node/error.d.js lib/node/error.js lib/node/nvi.d.js \
lib/util/Γ§evir.js \
$(lib)/cloudflare/types.d.js $(lib)/cloudflare/moduleWorker.d.js \
$(lib)/crosschain/*.js \
$(lib)/crypto/sha3.js \
$(lib)/crypto/modular.js $(lib)/crypto/secp256k1.js \
$(lib)/did/*.d.js $(lib)/did/section.js $(lib)/did/decryptedSections.js \
$(lib)/ethereum/*.d.js $(lib)/ethereum/evm.js \
$(lib)/node/error.d.js $(lib)/node/error.js $(lib)/node/nvi.d.js \
$(lib)/util/Γ§evir.js \
build/edevlet/pdfjs.js \
build/BEARER_TOKEN
mkdir -p $(dir $@)
yarn google-closure-compiler -W VERBOSE -O ADVANCED --charset UTF-8 \
bun google-closure-compiler -W VERBOSE -O ADVANCED --charset UTF-8 \
--define "BEARER_TOKEN\$$\$$module\$$edevlet\$$nkoWorker=$(shell cat build/BEARER_TOKEN)" \
--define "CF_ACCOUNT_NAME\$$\$$module\$$edevlet\$$nkoWorker=$(CF_ACCOUNT_NAME)" \
--define "WORKER_NAME\$$\$$module\$$edevlet\$$nkoWorker=$(WORKER_NAME)" \
Expand All @@ -97,7 +97,7 @@ build/nkoWorker.js: edevlet/nkoWorker.js \
--entry_point $< \
--js $(filter-out build/edevlet/pdfjs.js, $(filter %.js, $^)) \
--js_output_file $@.tmp
yarn uglifyjs $@.tmp -m -c toplevel,unsafe,drop_console -o $@.tmp
bun uglifyjs $@.tmp -m -c toplevel,unsafe,drop_console -o $@.tmp
sed -i.bak 's/globalThis.NkoWorker=/export default/g' $@.tmp
cat build/edevlet/pdfjs.js $@.tmp > $@
wc $@
Expand All @@ -106,7 +106,7 @@ build/nkoWorker.deployment: build/nkoWorker.js edevlet/nkoWorker.toml \
signerNode/signerNode.config \
build/exposureReportWorker.deployment \
build/humanIDWorker.deployment
yarn wrangler deploy $< --name $(WORKER_NAME)-nko-worker \
bun wrangler deploy $< --name $(WORKER_NAME)-nko-worker \
--compatibility-date $(shell date -v -1d +%Y-%m-%d) \
--config edevlet/nkoWorker.toml
touch $@
Expand All @@ -115,7 +115,7 @@ build/oauth2Worker.deployment: build/oauth2Worker.js edevlet/nkoWorker.toml \
signerNode/signerNode.config \
build/exposureReportWorker.deployment \
build/humanIDWorker.deployment
yarn wrangler deploy $< --name $(WORKER_NAME)-oauth2-worker \
bun wrangler deploy $< --name $(WORKER_NAME)-oauth2-worker \
--compatibility-date $(shell date -v -1d +%Y-%m-%d) \
--config edevlet/oauth2Worker.toml
touch $@
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 "/lib/util/Γ§evir";

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

/** @const {!Object<string, number>} */
const MONTHS = {
Expand Down Expand Up @@ -355,4 +355,5 @@ const getValidatingTckt = (file, challenge, timeNow) => pdfjs.getDocument(file).
})
});

export { getValidatingTckt, ValidatingTckt };
export { ValidatingTckt, getValidatingTckt };

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/decryptedSections";
import { err, ErrorCode, errorResponse, reject } from "/lib/node/error";
import { base64, base64ten } from "/lib/util/Γ§evir";

/** @const {!Object<string, string>} */
const HEADERS = {
Expand Down
3 changes: 3 additions & 0 deletions edevlet/nkoWorker.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ logpush = false

[vars]
KIMLIKDAO_POW_THRESHOLD = "20000"

[placement]
mode = "smart"
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/decryptedSections";
import { err, ErrorCode } from "/lib/node/error";
import { base64, base64ten } from "/lib/util/Γ§evir";

/**
* @const {string}
Expand Down
3 changes: 3 additions & 0 deletions edevlet/oauth2Worker.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ logpush = false

[vars]
KIMLIKDAO_POW_THRESHOLD = "20000"

[placement]
mode = "smart"
4 changes: 2 additions & 2 deletions edevlet/validation.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { keccak256Uint32 } from "/lib/crypto/sha3";
import { ErrorCode, errWithMessage } from "/lib/node/error";
import { keccak256Uint32 } from "@kimlikdao/lib/crypto/sha3";
import { ErrorCode, errWithMessage } from "@kimlikdao/lib/node/error";

/**
* @param {number} remoteTs
Expand Down
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 '/lib/node/ipfs';
import ipfs from '@kimlikdao/lib/node/ipfs';

/**
* @param {!Request} req
Expand Down
2 changes: 1 addition & 1 deletion lib
Submodule lib updated 122 files
18 changes: 9 additions & 9 deletions lightNode/Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
build/lightNode.js: lightNode/lightNode.js lightNode/lightNode.d.js \
ipfs/ipfs.d.js ipfs/ipfs.js \
lib/cloudflare/types.d.js lib/cloudflare/moduleWorker.d.js \
lib/node/error.d.js lib/node/error.js \
lib/node/ipfs.d.js lib/node/ipfs.js \
lib/util/Γ§evir.js
$(lib)/cloudflare/types.d.js $(lib)/cloudflare/moduleWorker.d.js \
$(lib)/node/error.d.js $(lib)/node/error.js \
$(lib)/node/ipfs.d.js $(lib)/node/ipfs.js \
$(lib)/util/Γ§evir.js $(lib)/util/base58.js
mkdir -p $(dir $@)
yarn google-closure-compiler -W VERBOSE -O ADVANCED --charset UTF-8 \
bun google-closure-compiler -W VERBOSE -O ADVANCED --charset UTF-8 \
--jscomp_error=unusedLocalVariables \
--jscomp_error=strictCheckTypes \
--jscomp_error=checkTypes \
Expand All @@ -18,12 +18,12 @@ build/lightNode.js: lightNode/lightNode.js lightNode/lightNode.d.js \
--entry_point $< \
--js $^ \
--js_output_file $@
yarn uglifyjs $@ -m -c toplevel,unsafe -o $@
bun uglifyjs $@ -m -c toplevel,unsafe -o $@
sed -i.bak 's/globalThis.LightNodeWorker=/export default/g' $@
wc $@

build/lightNode.deployment: build/lightNode.js
yarn wrangler deploy $< \
bun wrangler deploy $< \
--compatibility-date $(shell date -v -1d +%Y-%m-%d) \
--config build/lightNode.toml
touch $@
--config lightNode/lightNode.toml
touch $@
1 change: 0 additions & 1 deletion lightNode/lightNode.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# and the route.
name = "kimlikdao-ipfs"
main = "../build/lightNode.js"
compatibility_date = "2023-01-01"
workers_dev = false
no_bundle = true
minify = false
Expand Down
36 changes: 36 additions & 0 deletions mina/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
build/mina/mina.js: mina/mina.js mina/mina.d.js \
mina/MerkleTree.js \
$(lib)/cloudflare/moduleWorker.d.js \
$(lib)/cloudflare/durableObject.d.js \
$(lib)/cloudflare/types.d.js \
$(lib)/crypto/poseidon.js \
$(lib)/crypto/modular.js \
$(lib)/mina/merkleTree.d.js $(lib)/mina/mina.d.js \
$(lib)/util/hex.js
mkdir -p $(dir $@)
mkdir -p build/input/mina && cp -rf mina/* build/input/mina/
mkdir -p build/input/node_modules/@kimlikdao
ln -sfn ../../../../$(lib) build/input/node_modules/@kimlikdao/lib
sed -i.bak '/cloudflare:workers/d' build/input/mina/MerkleTree.js
echo 'globalThis["MinaWorker"] = MinaWorker;\nglobalThis["MerkleTree"] = MerkleTree;' >> build/input/mina/mina.js
cd build/input; bun google-closure-compiler -W VERBOSE -O ADVANCED --charset UTF-8 \
--jscomp_error=checkTypes \
--jscomp_error=strictCheckTypes \
--jscomp_error=unusedLocalVariables \
--jscomp_error=reportUnknownTypes \
--emit_use_strict \
--language_in ECMASCRIPT_NEXT \
--module_resolution NODE \
--assume_function_wrapper \
--dependency_mode PRUNE \
--entry_point mina/mina.js \
--js $^ \
--js_output_file ../../$@
rm -rf build/input/mina
bun uglifyjs $@ -m -c toplevel,unsafe,drop_console -o $@
bun $(lib)/birimler/bigintCompressor.js $@
wc $@

build/mina.deployment: build/mina/mina.js mina/prod.toml
bun wrangler deploy $< --compatibility-date $(shell date -v -1d +%Y-%m-%d) \
--config mina/prod.toml
Loading

0 comments on commit 40118c0

Please sign in to comment.