From d8422de94e7b12779a32db08e316220abb82e18c Mon Sep 17 00:00:00 2001 From: Sosthene Date: Mon, 30 Jun 2025 22:45:25 +0200 Subject: [PATCH 01/10] Add getMerkleProofForFile --- src/services/service.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/services/service.ts b/src/services/service.ts index 022d873..3d08856 100755 --- a/src/services/service.ts +++ b/src/services/service.ts @@ -1414,6 +1414,10 @@ export default class Services { return this.sdkClient.hash_value(fileBlob, commitedIn, label); } + public getMerkleProofForFile(processState: ProcessState, attributeName: string): MerkleProofResult { + return this.sdkClient.get_merkle_proof(processState, attributeName); + } + public getLastCommitedState(process: Process): ProcessState | null { if (process.states.length === 0) return null; const processTip = process.states[process.states.length - 1].commited_in; From 337a6adc601576cabf46e8b2f5454d6d13ebbf87 Mon Sep 17 00:00:00 2001 From: Sosthene Date: Mon, 30 Jun 2025 22:45:50 +0200 Subject: [PATCH 02/10] Add HASH_VALUE and GET_MERKLE_PROOF --- src/router.ts | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/src/router.ts b/src/router.ts index b6da5a8..8f6d549 100755 --- a/src/router.ts +++ b/src/router.ts @@ -691,6 +691,62 @@ export async function registerAllListeners() { } } + const handleHashValue = async (event: MessageEvent) => { + if (event.data.type !== MessageType.HASH_VALUE) return; + + console.log('handleHashValue', event.data); + + try { + const { accessToken, commitedIn, label, fileBlob } = event.data; + + if (!accessToken || !(await tokenService.validateToken(accessToken, event.origin))) { + throw new Error('Invalid or expired session token'); + } + + const hash = services.getHashForFile(commitedIn, label, fileBlob); + + window.parent.postMessage( + { + type: MessageType.VALUE_HASHED, + hash, + messageId: event.data.messageId + }, + event.origin + ); + } catch (e) { + const errorMsg = `Failed to hash value: ${e}`; + errorResponse(errorMsg, event.origin, event.data.messageId); + } + } + + const handleGetMerkleProof = async (event: MessageEvent) => { + if (event.data.type !== MessageType.GET_MERKLE_PROOF) return; + + console.log('handleGetMerkleProof', event.data); + + try { + const { accessToken, processState, attributeName } = event.data; + + if (!accessToken || !(await tokenService.validateToken(accessToken, event.origin))) { + throw new Error('Invalid or expired session token'); + } + + const proof = services.getMerkleProofForFile(processState, attributeName); + + window.parent.postMessage( + { + type: MessageType.MERKLE_PROOF_RETRIEVED, + proof, + messageId: event.data.messageId + }, + event.origin + ); + } catch (e) { + const errorMsg = `Failed to get merkle proof: ${e}`; + errorResponse(errorMsg, event.origin, event.data.messageId); + } + } + window.removeEventListener('message', handleMessage); window.addEventListener('message', handleMessage); @@ -733,6 +789,12 @@ export async function registerAllListeners() { case MessageType.DECODE_PUBLIC_DATA: await handleDecodePublicData(event); break; + case MessageType.HASH_VALUE: + await handleHashValue(event); + break; + case MessageType.GET_MERKLE_PROOF: + await handleGetMerkleProof(event); + break; default: console.warn(`Unhandled message type: ${event.data.type}`); } From 67cd7a1662cccaf1f44d6479428ef231c57835a2 Mon Sep 17 00:00:00 2001 From: omaroughriss Date: Wed, 2 Jul 2025 15:36:42 +0200 Subject: [PATCH 03/10] Add Dockerfile --- Dockerfile | 74 ++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 61 insertions(+), 13 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8925bd5..4bd4841 100755 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,61 @@ -FROM node:20 - -ENV TZ=Europe/Paris -RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone - -# use this user because he have uid et gid 1000 like theradia -USER node - -WORKDIR /app - -CMD ["npm", "start"] -# "--disable-host-check", "--host", "0.0.0.0", "--ssl", "--ssl-cert", "/ssl/certs/site.crt", "--ssl-key", "/ssl/private/site.dec.key"] - +# syntax=docker/dockerfile:1.4 +FROM rust:1.82-alpine AS wasm-builder +WORKDIR /build + +# Installation des dépendances nécessaires pour la compilation +RUN apk update && apk add --no-cache \ + git \ + openssh-client \ + curl \ + nodejs \ + npm \ + build-base \ + pkgconfig \ + clang \ + llvm \ + musl-dev \ + nginx + +# Installation de wasm-pack +RUN curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh + +# Configuration SSH basique +RUN mkdir -p /root/.ssh && \ + ssh-keyscan git.4nkweb.com >> /root/.ssh/known_hosts + +# On se place dans le bon répertoire parent +WORKDIR /build +# Copie du projet ihm_client +COPY . ihm_client/ + +# Clonage du sdk_client au même niveau que ihm_client en utilisant la clé SSH montée +RUN --mount=type=ssh git clone -b cicd ssh://git@git.4nkweb.com/4nk/sdk_client.git + +# Build du WebAssembly avec accès SSH pour les dépendances +WORKDIR /build/sdk_client +RUN --mount=type=ssh wasm-pack build --out-dir ../ihm_client/pkg --target bundler --dev + +FROM node:20-alpine +WORKDIR /app + +# Installation des dépendances nécessaires +RUN apk update && apk add --no-cache git nginx + +# Copie des fichiers du projet +COPY --from=wasm-builder /build/ihm_client/pkg ./pkg +COPY . . + +# Installation des dépendances Node.js +RUN npm install + +# Copie de la configuration nginx +COPY nginx.dev.conf /etc/nginx/http.d/default.conf + +# Script de démarrage +COPY start-dev.sh /start-dev.sh +RUN chmod +x /start-dev.sh + +EXPOSE 3001 80 + +CMD ["/start-dev.sh"] + From 1a87a4db142b4cd75015119618a2963142203019 Mon Sep 17 00:00:00 2001 From: omaroughriss Date: Wed, 2 Jul 2025 15:37:34 +0200 Subject: [PATCH 04/10] Add nginx config --- nginx.dev.conf | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 nginx.dev.conf diff --git a/nginx.dev.conf b/nginx.dev.conf new file mode 100644 index 0000000..d5dcba5 --- /dev/null +++ b/nginx.dev.conf @@ -0,0 +1,48 @@ +server { + listen 80; + server_name localhost; + + # Redirection des requêtes HTTP vers Vite + location / { + proxy_pass http://localhost:3001; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "Upgrade"; + proxy_set_header Host $host; + } + + location /ws/ { + proxy_pass http://localhost:8090; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "Upgrade"; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-NginX-Proxy true; + proxy_read_timeout 86400; + } + + location /storage/ { + rewrite ^/storage(/.*)$ $1 break; + proxy_pass http://localhost:8080; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "Upgrade"; + proxy_set_header Host $host; + } + + location /api/ { + proxy_pass http://localhost:8091; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + + # CORS headers + add_header Access-Control-Allow-Origin "*" always; + add_header Access-Control-Allow-Methods "GET, POST, OPTIONS, PUT, DELETE" always; + add_header Access-Control-Allow-Headers "Authorization,Content-Type,Accept,X-Requested-With" always; + } +} \ No newline at end of file From 0dc3c83c3c41c81f87f37dda6af576af824d09bb Mon Sep 17 00:00:00 2001 From: omaroughriss Date: Wed, 2 Jul 2025 15:39:32 +0200 Subject: [PATCH 05/10] Add a start script --- start-dev.sh | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 start-dev.sh diff --git a/start-dev.sh b/start-dev.sh new file mode 100644 index 0000000..40ba375 --- /dev/null +++ b/start-dev.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +# Démarrer nginx en arrière-plan +nginx + +# Démarrer le serveur de développement Vite +npm run start \ No newline at end of file From a8b0248b5f89be11fd10392072f3386fc5f2f4b9 Mon Sep 17 00:00:00 2001 From: omaroughriss Date: Wed, 2 Jul 2025 15:39:51 +0200 Subject: [PATCH 06/10] Minor updates --- package.json | 2 +- vite.config.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index e9bc61e..076150b 100755 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "dist/index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", - "build_wasm": "wasm-pack build --out-dir ../ihm_client_dev3/pkg ../sdk_client --target bundler --dev", + "build_wasm": "wasm-pack build --out-dir ../ihm_client/pkg ../sdk_client --target bundler --dev", "start": "vite --host 0.0.0.0", "build": "tsc && vite build", "deploy": "sudo cp -r dist/* /var/www/html/", diff --git a/vite.config.ts b/vite.config.ts index bd73a52..cfd621e 100755 --- a/vite.config.ts +++ b/vite.config.ts @@ -57,7 +57,7 @@ export default defineConfig({ fs: { cachedChecks: false, }, - port: 3004, + port: 3001, proxy: { '/storage': { target: 'https://demo.4nkweb.com', From 0a860bd559570b059eec329f9c733b3f691b04a7 Mon Sep 17 00:00:00 2001 From: omaroughriss Date: Wed, 2 Jul 2025 15:40:44 +0200 Subject: [PATCH 07/10] Add CICD --- .github/workflows/cicd.yml | 43 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 .github/workflows/cicd.yml diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml new file mode 100644 index 0000000..5ce3f43 --- /dev/null +++ b/.github/workflows/cicd.yml @@ -0,0 +1,43 @@ +name: Build and Push to Registry + +on: + push: + branches: [ cicd ] + +env: + REGISTRY: git.4nkweb.com + IMAGE_NAME: 4nk/ihm_client + +jobs: + build-and-push: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up SSH agent + uses: webfactory/ssh-agent@v0.9.1 + with: + ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to Container Registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ secrets.USER }} + password: ${{ secrets.TOKEN }} + + - name: Build and push + uses: docker/build-push-action@v5 + with: + context: . + push: true + ssh: default + build-args: | + ENV_VARS=${{ secrets.ENV_VARS }} + tags: | + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ gitea.sha }} \ No newline at end of file From 13b605a8505455089397da714339fd5ee827b461 Mon Sep 17 00:00:00 2001 From: omaroughriss Date: Thu, 3 Jul 2025 11:38:40 +0200 Subject: [PATCH 08/10] Update port --- Dockerfile | 2 +- nginx.dev.conf | 2 +- vite.config.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4bd4841..cefaff8 100755 --- a/Dockerfile +++ b/Dockerfile @@ -55,7 +55,7 @@ COPY nginx.dev.conf /etc/nginx/http.d/default.conf COPY start-dev.sh /start-dev.sh RUN chmod +x /start-dev.sh -EXPOSE 3001 80 +EXPOSE 3003 80 CMD ["/start-dev.sh"] diff --git a/nginx.dev.conf b/nginx.dev.conf index d5dcba5..c125de3 100644 --- a/nginx.dev.conf +++ b/nginx.dev.conf @@ -4,7 +4,7 @@ server { # Redirection des requêtes HTTP vers Vite location / { - proxy_pass http://localhost:3001; + proxy_pass http://localhost:3003; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "Upgrade"; diff --git a/vite.config.ts b/vite.config.ts index cfd621e..e842295 100755 --- a/vite.config.ts +++ b/vite.config.ts @@ -57,7 +57,7 @@ export default defineConfig({ fs: { cachedChecks: false, }, - port: 3001, + port: 3003, proxy: { '/storage': { target: 'https://demo.4nkweb.com', From 9a601056b70c856366fbb227e75f996c29683358 Mon Sep 17 00:00:00 2001 From: omaroughriss Date: Wed, 23 Jul 2025 13:22:53 +0200 Subject: [PATCH 09/10] Update cicd branche to dev --- .github/workflows/{cicd.yml => dev.yml} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename .github/workflows/{cicd.yml => dev.yml} (97%) diff --git a/.github/workflows/cicd.yml b/.github/workflows/dev.yml similarity index 97% rename from .github/workflows/cicd.yml rename to .github/workflows/dev.yml index 5ce3f43..91afb7b 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/dev.yml @@ -2,7 +2,7 @@ name: Build and Push to Registry on: push: - branches: [ cicd ] + branches: [ dev ] env: REGISTRY: git.4nkweb.com From b072495ceaaf9963c9f6a3b8c1977e117784ad63 Mon Sep 17 00:00:00 2001 From: Omar Date: Wed, 23 Jul 2025 11:26:52 +0000 Subject: [PATCH 10/10] revert 9a601056b70c856366fbb227e75f996c29683358 revert Update cicd branche to dev --- .github/workflows/{dev.yml => cicd.yml} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename .github/workflows/{dev.yml => cicd.yml} (97%) diff --git a/.github/workflows/dev.yml b/.github/workflows/cicd.yml similarity index 97% rename from .github/workflows/dev.yml rename to .github/workflows/cicd.yml index 91afb7b..5ce3f43 100644 --- a/.github/workflows/dev.yml +++ b/.github/workflows/cicd.yml @@ -2,7 +2,7 @@ name: Build and Push to Registry on: push: - branches: [ dev ] + branches: [ cicd ] env: REGISTRY: git.4nkweb.com