diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d20e6fd..5282273 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,7 +7,7 @@ on: branches: ["main", "prod"] jobs: - check: + checkSignerNode: strategy: fail-fast: true @@ -18,15 +18,27 @@ jobs: submodules: recursive - uses: actions/setup-node@v3 - with: - node-version: 18 + + - 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 + + - uses: actions/setup-node@v3 + + - name: Install dependencies + run: bun i - name: Build lightNode - run: | - yarn - make build/lightNode.js + run: make build/lightNode.js diff --git a/.gitignore b/.gitignore index dba2db4..e91c643 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .DS_Store -*.lock +.wrangler +*lock* *.vars /build /node_modules diff --git a/Makefile b/Makefile index d133b40..d3c395b 100644 --- a/Makefile +++ b/Makefile @@ -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 $@) diff --git a/edevlet/Makefile b/edevlet/Makefile index e2fd450..722012d 100644 --- a/edevlet/Makefile +++ b/edevlet/Makefile @@ -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 \ @@ -19,7 +19,7 @@ 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 \ @@ -27,7 +27,7 @@ build/edevlet/pdfjs.js: edevlet/pdfjs.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 \ @@ -35,25 +35,25 @@ build/edevlet/pdfjs.js: edevlet/pdfjs.js \ --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)" \ @@ -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)" \ @@ -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 $@ @@ -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 $@ @@ -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 $@ diff --git a/edevlet/nko.js b/edevlet/nko.js index be11775..6f8b5ef 100644 --- a/edevlet/nko.js +++ b/edevlet/nko.js @@ -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} */ const STATIC_HEADERS = { diff --git a/edevlet/nkoParser.js b/edevlet/nkoParser.js index ceca48e..a66684e 100644 --- a/edevlet/nkoParser.js +++ b/edevlet/nkoParser.js @@ -1,4 +1,4 @@ -import { ErrorCode, reject } from "/lib/node/error"; +import { ErrorCode, reject } from "@kimlikdao/lib/node/error"; /** @const {!Object} */ const MONTHS = { @@ -355,4 +355,5 @@ const getValidatingTckt = (file, challenge, timeNow) => pdfjs.getDocument(file). }) }); -export { getValidatingTckt, ValidatingTckt }; +export { ValidatingTckt, getValidatingTckt }; + diff --git a/edevlet/nkoWorker.js b/edevlet/nkoWorker.js index 6b93d80..d12412d 100644 --- a/edevlet/nkoWorker.js +++ b/edevlet/nkoWorker.js @@ -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} */ const HEADERS = { diff --git a/edevlet/nkoWorker.toml b/edevlet/nkoWorker.toml index 6e5c8d7..98122b0 100644 --- a/edevlet/nkoWorker.toml +++ b/edevlet/nkoWorker.toml @@ -7,3 +7,6 @@ logpush = false [vars] KIMLIKDAO_POW_THRESHOLD = "20000" + +[placement] +mode = "smart" diff --git a/edevlet/oauth2Worker.js b/edevlet/oauth2Worker.js index 0e2fca4..34bb4dc 100644 --- a/edevlet/oauth2Worker.js +++ b/edevlet/oauth2Worker.js @@ -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} diff --git a/edevlet/oauth2Worker.toml b/edevlet/oauth2Worker.toml index 6e5c8d7..98122b0 100644 --- a/edevlet/oauth2Worker.toml +++ b/edevlet/oauth2Worker.toml @@ -7,3 +7,6 @@ logpush = false [vars] KIMLIKDAO_POW_THRESHOLD = "20000" + +[placement] +mode = "smart" diff --git a/edevlet/validation.js b/edevlet/validation.js index d65e533..9d70aa4 100644 --- a/edevlet/validation.js +++ b/edevlet/validation.js @@ -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 diff --git a/ipfs/ipfs.js b/ipfs/ipfs.js index 0a4aaec..c2c502d 100644 --- a/ipfs/ipfs.js +++ b/ipfs/ipfs.js @@ -1,4 +1,4 @@ -import ipfs from '/lib/node/ipfs'; +import ipfs from '@kimlikdao/lib/node/ipfs'; /** * @param {!Request} req diff --git a/lib b/lib index 183ebbd..ae8db56 160000 --- a/lib +++ b/lib @@ -1 +1 @@ -Subproject commit 183ebbd3ef6236cce83a590869f6df1c99db783c +Subproject commit ae8db5603b5da1af6f643fc58556698ad71648b7 diff --git a/lightNode/Makefile b/lightNode/Makefile index 9939a02..63dd3e7 100644 --- a/lightNode/Makefile +++ b/lightNode/Makefile @@ -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 \ @@ -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 $@ \ No newline at end of file + --config lightNode/lightNode.toml + touch $@ diff --git a/lightNode/lightNode.toml b/lightNode/lightNode.toml index af47b3a..c76ba09 100644 --- a/lightNode/lightNode.toml +++ b/lightNode/lightNode.toml @@ -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 diff --git a/mina/Makefile b/mina/Makefile new file mode 100644 index 0000000..1ac7cf3 --- /dev/null +++ b/mina/Makefile @@ -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 diff --git a/mina/MerkleTree.js b/mina/MerkleTree.js new file mode 100644 index 0000000..299d0e7 --- /dev/null +++ b/mina/MerkleTree.js @@ -0,0 +1,124 @@ +import { poseidon } from "@kimlikdao/lib/crypto/poseidon"; +import { DurableObject } from "cloudflare:workers"; + +/** @typedef {string} */ +const BinaryKey = {}; + +/** + * In InvKey, the last bit is inverted. This achieves some optimizations + * with how batch data loads are handled with DurableObjects. + * + * @typedef {string} + */ +const InvKey = {}; + +/** + * @param {BinaryKey} key + * @return {InvKey} + */ +const toInvKey = (key) => key + ? key.slice(0, -1) + +(key.charCodeAt(key.length - 1) == 48) + : "r"; + +/** + * @implements {cloudflare.DurableObject} + */ +class MerkleTree extends DurableObject { + /** + * @override + * + * @param {!cloudflare.DurableObjectState} state + * @param {!cloudflare.Environment} env + */ + constructor(state, env) { + super(state, env); + /** @const {!cloudflare.DurableObjectStorage} */ + this.storage = state.storage; + /** @type {number} */ + this.height = 0; + /** @type {!Array} */ + this.zeros = []; + + state.blockConcurrencyWhile(() => state.storage.get("height") + .then((/** number */ height) => this._setHeight(height || 0))); + } + + /** + * @private + * + * @param {number} height + */ + _setHeight(height) { + if (this.height) throw `Initialized ${this.height}`; + /** @const {!Array} */ + const zeros = Array(height + 1); + /** @const {!Array} */ + zeros[height] = 0n; + for (let i = height; i > 0; --i) + zeros[i - 1] = poseidon([zeros[i], zeros[i]]); + this.height = height; + this.zeros = zeros; + } + + /** + * @param {number} height + * @return {!Promise} + */ + setHeight(height) { + this._setHeight(height); + return this.storage.put("height", height); + } + + /** + * @param {BinaryKey} key + * @return {!Promise} + */ + getNode(key) { + return this.storage.get(toInvKey(key)).then((/** !bigint */ val) => val || this.zeros[key.length]); + } + + /** + * @param {BinaryKey} key + * @param {!bigint} val + * @return {!Promise} the root after insertion + */ + setLeaf(key, val) { + return this.getWitness(key).then((witness) => { + /** @const {!Object} */ + const entries = {}; + for (const w of witness) { + key = key.slice(0, -1); + entries[key + (+w.isLeft)] = val; + val = poseidon(w.isLeft ? [val, w.sibling] : [w.sibling, val]); + } + entries["r"] = val; + return this.storage.put(entries).then(() => val); + }); + } + + /** + * @param {BinaryKey} key + * @return {!Promise>} + */ + getWitness(key) { + const h = key.length; + /** @const {!Array} */ + const keys = Array(h); + for (let i = 0; i < h; ++i) + keys[i] = key.slice(0, i + 1); + return this.storage.get(keys).then((/** !Map */ map) => { + /** @const {!Array} */ + const witness = Array(h); + /** @type {number} */ + let i = 0; + for (const k of keys) + witness[h - ++i] = { + isLeft: k.charCodeAt(i - 1) == 48, + sibling: map.get(k) || this.zeros[i] + } + return witness; + }); + } +} + +export { MerkleTree }; diff --git a/mina/mina.d.js b/mina/mina.d.js new file mode 100644 index 0000000..1cd6f71 --- /dev/null +++ b/mina/mina.d.js @@ -0,0 +1,19 @@ +/** @externs */ + +/** + * @constructor + * @implements {cloudflare.DurableObject} + * + * @param {!cloudflare.DurableObjectState} state + * @param {!cloudflare.Environment} env + */ +const DurableObject = function (state, env) { } + +/** + * @interface + * @extends {cloudflare.Environment} + */ +const MinaEnv = function () { } + +/** @const {!cloudflare.DurableObjectBinding} */ +MinaEnv.prototype.MerkleTree; diff --git a/mina/mina.js b/mina/mina.js new file mode 100644 index 0000000..72cd497 --- /dev/null +++ b/mina/mina.js @@ -0,0 +1,34 @@ +import hex from "@kimlikdao/lib/util/hex"; +import { MerkleTree } from "./MerkleTree"; + +/** @define {string} */ +const NODE_URL = "mina.kimlikdao.org"; + +/** + * @implements {cloudflare.ModuleWorker} + */ +const MinaWorker = { + /** + * @override + * @param {!Request} req + * @param {!MinaEnv} env + */ + async fetch(req, env) { + /** @const {string} */ + const pathname = req.url.slice(NODE_URL.length + 8); + + if (pathname.startsWith("/witness")) { + const address = pathname.slice("/witness/".length, "/witness/".length + 55); + const index = hex.toBin(pathname.slice("/witness/".length + 56)); + + /** @const {!MerkleTree} */ + const merkleTree = /** @type {!MerkleTree} */( + env.MerkleTree.get(env.MerkleTree.idFromName(address))); + + return merkleTree.getWitness(index).then(Response.json); + } + } +}; + +export default MinaWorker; +export { MerkleTree }; diff --git a/mina/prod.toml b/mina/prod.toml new file mode 100644 index 0000000..fe607c9 --- /dev/null +++ b/mina/prod.toml @@ -0,0 +1,22 @@ +account_id = "8f0c2f2271ff857947d9a5b2c38595a0" + +main = "./mina.js" +name = "kimlikdao-node-mina" +route = { pattern = "mina.kimlikdao.org", custom_domain = true } + +workers_dev = false +# no_bundle = true +minify = false +send_metrics = false +node_compat = false +logpush = false + +rules = [{ type = "Text", globs = [], fallthrough = false }] + +[[durable_objects.bindings]] +name = "MerkleTree" +class_name = "MerkleTree" + +[[migrations]] +tag = "v1" +new_classes = ["MerkleTree"] diff --git a/package.json b/package.json index 0b7ce8c..230abbb 100644 --- a/package.json +++ b/package.json @@ -3,9 +3,12 @@ "version": "0.0.0", "type": "module", "devDependencies": { - "google-closure-compiler": "^20230802.0.0", + "@cloudflare/workers-types": "^4.20240512.0", + "@kimlikdao/lib": "github:KimlikDAO/kimlikdao-js", + "google-closure-compiler": "^20240317.0.0", "uglify-js": "^3.17.4", - "wrangler": "^3.22.0" + "vitest": "^1.6.0", + "wrangler": "^3.57.1" }, "private": true } diff --git a/signerNode/Makefile b/signerNode/Makefile index 79da520..95962be 100644 --- a/signerNode/Makefile +++ b/signerNode/Makefile @@ -2,24 +2,25 @@ build/signerNode.js: signerNode/signerNode.js signerNode/signerNode.d.js \ edevlet/nko.d.js edevlet/nko.js edevlet/validation.js \ ipfs/ipfs.d.js ipfs/ipfs.js \ meetgreet/yo.d.js meetgreet/yo.js \ - lib/cloudflare/types.d.js lib/cloudflare/moduleWorker.d.js \ - lib/crypto/sha3.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)/crypto/sha3.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 \ - --jscomp_error=unusedLocalVariables \ - --jscomp_error=strictCheckTypes \ - --language_in ECMASCRIPT_NEXT \ - --module_resolution NODE \ - --dependency_mode PRUNE \ - --assume_function_wrapper \ - --emit_use_strict \ - --entry_point $< \ - --js $^ \ - --js_output_file $@ - yarn uglifyjs $@ -m -c toplevel,unsafe,drop_console -o $@ + bun google-closure-compiler -W VERBOSE -O ADVANCED --charset UTF-8 \ + --define "NODE_URL\$$\$$module\$$signerNode\$$signerNode=$(NODE_URL)" \ + --jscomp_error=unusedLocalVariables \ + --jscomp_error=strictCheckTypes \ + --language_in ECMASCRIPT_NEXT \ + --module_resolution NODE \ + --dependency_mode PRUNE \ + --assume_function_wrapper \ + --emit_use_strict \ + --entry_point $< \ + --js $^ \ + --js_output_file $@ + bun uglifyjs $@ -m -c toplevel,unsafe,drop_console -o $@ sed -i.bak 's/globalThis.SignerNodeWorker=/export default/g' $@ wc $@ @@ -34,7 +35,7 @@ build/signerNode.toml: signerNode/signerNode.toml signerNode/signerNode.config build/signerNode.deployment: build/signerNode.js build/signerNode.toml \ build/nkoWorker.deployment \ build/oauth2Worker.deployment - yarn wrangler deploy $< --name $(WORKER_NAME) \ + bun wrangler deploy $< --name $(WORKER_NAME) \ --compatibility-date $(shell date -v -1d +%Y-%m-%d) \ --config build/signerNode.toml touch $@ diff --git a/signerNode/signerNode.config b/signerNode/signerNode.config index ced33c4..943ba26 100644 --- a/signerNode/signerNode.config +++ b/signerNode/signerNode.config @@ -1,4 +1,4 @@ -NODE_URL = "node.kimlikdao.org" +NODE_URL = "node.dobbyinu.org" CF_WORKER_NAME = "kimlikdao-node" CF_ACCOUNT_NAME = "kimlikdao" CF_KV_NAMESPACE_ID = "52b51a1db0ce4508a144633d407dab93" diff --git a/signerNode/signerNode.js b/signerNode/signerNode.js index 62c3308..ade2cfc 100644 --- a/signerNode/signerNode.js +++ b/signerNode/signerNode.js @@ -7,14 +7,16 @@ import { commit } from "/edevlet/nko"; import ipfs from "/ipfs/ipfs"; import { yo } from "/meetgreet/yo"; +/** @define {string} */ +const NODE_URL = "node.kimlikdao.org"; + /** * @param {string} url * @return {string} the pathname extracted from the url. */ const pathname = (url) => { const j = url.indexOf("?"); - url = j == -1 ? url.slice(8) : url.slice(8, j); - url = url.slice(url.indexOf("/")); + url = j == -1 ? url.slice(8 + NODE_URL.length) : url.slice(8 + NODE_URL.length, j); return url.startsWith("/ipfs") ? "/ipfs" : url; }