Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
23 changes: 23 additions & 0 deletions server/src/utils/sha256.test.ts
Original file line number Diff line number Diff line change
@@ -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"),
)
})
})
8 changes: 2 additions & 6 deletions server/src/utils/sha256.ts
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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"))
}

Expand Down
8 changes: 0 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
Loading