From 10264b0b1812d02c1c4f8398ccb9393e797efe03 Mon Sep 17 00:00:00 2001 From: Danil Ovchinnikov Date: Tue, 16 Sep 2025 23:48:04 +0300 Subject: [PATCH 1/3] added test --- server/src/utils/sha256.test.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 server/src/utils/sha256.test.ts diff --git a/server/src/utils/sha256.test.ts b/server/src/utils/sha256.test.ts new file mode 100644 index 00000000..54fc9d08 --- /dev/null +++ b/server/src/utils/sha256.test.ts @@ -0,0 +1,23 @@ +import {sha256} from "./sha256" + +describe("sha256", () => { + it("should the hash match", () => { + expect(sha256("")).toBe( + BigInt( + "102987336249554097029535212322581322789799900648198034993379397001115665086549", + ), + ) + + expect(sha256("Hello TON!")).toBe( + BigInt("94195310981932109156034286767119480062048721952250870139857035430904055776623"), + ) + + expect(sha256("Привет Tolk :)")).toBe( + BigInt("26146202394857327563828036519278299397380780259413242791903448589012707656815"), + ) + + expect(sha256("Ton 💎")).toBe( + BigInt("15570930988744595092815823450503557295795266945250239353278140775822768066017"), + ) + }) +}) From 79cb0a5a12d8fe1f7f41afca25eae2742fd3cc9d Mon Sep 17 00:00:00 2001 From: Danil Ovchinnikov Date: Tue, 16 Sep 2025 23:48:17 +0300 Subject: [PATCH 2/3] move to `crypto` --- server/src/utils/sha256.ts | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/server/src/utils/sha256.ts b/server/src/utils/sha256.ts index 75944b6e..921feb2f 100644 --- a/server/src/utils/sha256.ts +++ b/server/src/utils/sha256.ts @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT // Copyright © 2025 TON Core -import * as jsSHA from "jssha" +import * as crypto from "node:crypto" const bufferToBigInt = (buffer: Buffer): bigint => buffer.reduce((acc, byte) => (acc << 8n) | BigInt(byte), 0n) @@ -12,11 +12,7 @@ const bufferToBigInt = (buffer: Buffer): bigint => * @returns 256-bit hash as bigint */ export function sha256(str: string): bigint { - // @ts-expect-error strange bug - // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment - const hasher: jsSHA.default = new jsSHA("SHA-256", "HEX") - hasher.update(Buffer.from(str, "utf8").toString("hex")) - const res = hasher.getHash("HEX") + const res = crypto.createHash("sha256").update(str).digest("hex") return bufferToBigInt(Buffer.from(res, "hex")) } From 4f85e2a2a9029d8758c62c2d2364e322ffaead16 Mon Sep 17 00:00:00 2001 From: Danil Ovchinnikov Date: Tue, 16 Sep 2025 23:48:57 +0300 Subject: [PATCH 3/3] remove `jssha` library --- package.json | 1 - yarn.lock | 8 -------- 2 files changed, 9 deletions(-) diff --git a/package.json b/package.json index c6f0dc08..db7c2263 100644 --- a/package.json +++ b/package.json @@ -561,7 +561,6 @@ "@ton/core": "0.60.1", "@ton/crypto": "^3.3.0", "glob": "^11.0.1", - "jssha": "^3.3.1", "tolkfmt-test-dev": "0.0.21", "ton-assembly": "0.2.0", "vscode-languageclient": "^8.0.2", diff --git a/yarn.lock b/yarn.lock index b1cc069e..1775708c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5290,13 +5290,6 @@ __metadata: languageName: node linkType: hard -"jssha@npm:^3.3.1": - version: 3.3.1 - resolution: "jssha@npm:3.3.1" - checksum: 10c0/dccd89d1cb9ffdf27e34edfff6ca261a0b130554839ae1a9601e6c959d050daaac8095f02971ee0e13c624c886cad3e0e4fc52b056f53251a99094fde2a41188 - languageName: node - linkType: hard - "jszip@npm:^3.10.1": version: 3.10.1 resolution: "jszip@npm:3.10.1" @@ -8026,7 +8019,6 @@ __metadata: glob: "npm:^11.0.1" husky: "npm:^9.1.7" jest: "npm:^29.7.0" - jssha: "npm:^3.3.1" mocha: "npm:^10.3.0" prettier: "npm:3.4.2" tolkfmt-test-dev: "npm:0.0.21"