Skip to content

Commit 3659b77

Browse files
committed
use sha256 instead of window.crypto
1 parent d655c1c commit 3659b77

3 files changed

Lines changed: 12 additions & 12 deletions

File tree

packages/frontend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
},
88
"dependencies": {
99
"@caido/primevue": "0.1.2",
10+
"js-sha256": "^0.11.1",
1011
"mitt": "3.0.1",
1112
"openpgp": "6.1.1",
1213
"pinia": "3.0.2",

packages/frontend/src/plugins/drop.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { sha256 } from "js-sha256";
12
import {
23
createMessage,
34
decrypt,
@@ -99,7 +100,7 @@ const processMessages = async (
99100
const payload = JSON.parse(decryptedData) as DropPayload;
100101

101102
// Verify SHA256 hash
102-
const calculatedHash = await calculateSHA256(
103+
const calculatedHash = sha256(
103104
JSON.stringify({
104105
id: payload.id,
105106
objects: payload.objects,
@@ -233,16 +234,6 @@ const createSignature = async (data: string): Promise<string> => {
233234
return String(signature);
234235
};
235236

236-
const calculateSHA256 = async (data: string): Promise<string> => {
237-
const hashBuffer = await crypto.subtle.digest(
238-
"SHA-256",
239-
new TextEncoder().encode(data),
240-
);
241-
return Array.from(new Uint8Array(hashBuffer))
242-
.map((b) => b.toString(16).padStart(2, "0"))
243-
.join("");
244-
};
245-
246237
const handleClaimEvent = async (data: {
247238
payload: DropPayload;
248239
alias: string;
@@ -307,7 +298,7 @@ const handleDropEvent = async (data: {
307298
try {
308299
// Calculate SHA256 hash
309300
logger.log("Calculating SHA256 hash for payload");
310-
payload.sha256 = await calculateSHA256(
301+
payload.sha256 = sha256(
311302
JSON.stringify({
312303
id: payload.id,
313304
objects: payload.objects,

pnpm-lock.yaml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)