From a8ea40b2e167c304ff6c46c9bb092e88bbca33d5 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sun, 22 Mar 2026 21:00:15 +0200 Subject: [PATCH] fix(standalone): missing hmac implementation --- apps/client-standalone/package.json | 1 + .../src/lightweight/crypto_provider.ts | 13 +++++++++++++ pnpm-lock.yaml | 14 ++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/apps/client-standalone/package.json b/apps/client-standalone/package.json index e1b58a0d73..e497b3e47e 100644 --- a/apps/client-standalone/package.json +++ b/apps/client-standalone/package.json @@ -47,6 +47,7 @@ "jquery": "3.7.1", "jquery.fancytree": "2.38.5", "js-sha1": "0.7.0", + "js-sha256": "0.11.1", "js-sha512": "0.9.0", "jsplumb": "2.15.6", "katex": "0.16.27", diff --git a/apps/client-standalone/src/lightweight/crypto_provider.ts b/apps/client-standalone/src/lightweight/crypto_provider.ts index 19dbfca4f6..0acfc1944c 100644 --- a/apps/client-standalone/src/lightweight/crypto_provider.ts +++ b/apps/client-standalone/src/lightweight/crypto_provider.ts @@ -1,5 +1,6 @@ import type { CryptoProvider } from "@triliumnext/core"; import { sha1 } from "js-sha1"; +import { sha256 } from "js-sha256"; import { sha512 } from "js-sha512"; interface Cipher { @@ -52,6 +53,18 @@ export default class BrowserCryptoProvider implements CryptoProvider { } return result; } + + hmac(secret: string | Uint8Array, value: string | Uint8Array): string { + const secretStr = typeof secret === "string" ? secret : new TextDecoder().decode(secret); + const valueStr = typeof value === "string" ? value : new TextDecoder().decode(value); + // sha256.hmac returns hex, convert to base64 to match Node's behavior + const hexHash = sha256.hmac(secretStr, valueStr); + const bytes = new Uint8Array(hexHash.length / 2); + for (let i = 0; i < hexHash.length; i += 2) { + bytes[i / 2] = parseInt(hexHash.substr(i, 2), 16); + } + return btoa(String.fromCharCode(...bytes)); + } } /** diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4ce6f2e10b..be783e46f5 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -510,6 +510,9 @@ importers: js-sha1: specifier: 0.7.0 version: 0.7.0 + js-sha256: + specifier: 0.11.1 + version: 0.11.1 js-sha512: specifier: 0.9.0 version: 0.9.0 @@ -11163,6 +11166,9 @@ packages: js-sha1@0.7.0: resolution: {integrity: sha512-oQZ1Mo7440BfLSv9TX87VNEyU52pXPVG19F9PL3gTgNt0tVxlZ8F4O6yze3CLuLx28TxotxvlyepCNaaV0ZjMw==} + js-sha256@0.11.1: + resolution: {integrity: sha512-o6WSo/LUvY2uC4j7mO50a2ms7E/EAdbP0swigLV+nzHKTTaYnaLIWJ02VdXrsJX0vGedDESQnLsOekr94ryfjg==} + js-sha512@0.9.0: resolution: {integrity: sha512-mirki9WS/SUahm+1TbAPkqvbCiCfOAAsyXeHxK1UkullnJVVqoJG2pL9ObvT05CN+tM7fxhfYm0NbXn+1hWoZg==} @@ -17673,6 +17679,8 @@ snapshots: '@ckeditor/ckeditor5-widget': 47.6.1 ckeditor5: 47.6.1 es-toolkit: 1.39.5 + transitivePeerDependencies: + - supports-color '@ckeditor/ckeditor5-import-word@47.6.1': dependencies: @@ -17708,6 +17716,8 @@ snapshots: '@ckeditor/ckeditor5-ui': 47.6.1 '@ckeditor/ckeditor5-utils': 47.6.1 ckeditor5: 47.6.1 + transitivePeerDependencies: + - supports-color '@ckeditor/ckeditor5-line-height@47.6.1': dependencies: @@ -17802,6 +17812,8 @@ snapshots: '@ckeditor/ckeditor5-utils': 47.6.1 ckeditor5: 47.6.1 es-toolkit: 1.39.5 + transitivePeerDependencies: + - supports-color '@ckeditor/ckeditor5-merge-fields@47.6.1': dependencies: @@ -29177,6 +29189,8 @@ snapshots: js-sha1@0.7.0: {} + js-sha256@0.11.1: {} + js-sha512@0.9.0: {} js-tokens@10.0.0: {}