Skip to content

Commit 89a292e

Browse files
authored
Merge pull request #6 from caido-community/webcryptoapi-fix
fix: WebcryptoAPI is not avaliable on non secure contexts Great work Bebiks
2 parents 813eb9a + 3659b77 commit 89a292e

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,
@@ -225,16 +226,6 @@ const createSignature = async (data: string): Promise<string> => {
225226
return String(signature);
226227
};
227228

228-
const calculateSHA256 = async (data: string): Promise<string> => {
229-
const hashBuffer = await crypto.subtle.digest(
230-
"SHA-256",
231-
new TextEncoder().encode(data),
232-
);
233-
return Array.from(new Uint8Array(hashBuffer))
234-
.map((b) => b.toString(16).padStart(2, "0"))
235-
.join("");
236-
};
237-
238229
const handleClaimEvent = async (data: {
239230
payload: DropPayload;
240231
alias: string;
@@ -321,7 +312,7 @@ const handleDropEvent = async (data: {
321312
try {
322313
// Calculate SHA256 hash
323314
logger.log("Calculating SHA256 hash for payload");
324-
payload.sha256 = await calculateSHA256(
315+
payload.sha256 = sha256(
325316
JSON.stringify({
326317
id: payload.id,
327318
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)