Skip to content

Commit d18ffa9

Browse files
committed
fix md5 hashing for web platform
1 parent 77071a1 commit d18ffa9

File tree

3 files changed

+19
-32
lines changed

3 files changed

+19
-32
lines changed

packages/hypergraph-react/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@
4242
"@automerge/automerge-repo": "^2.0.0-alpha.14",
4343
"@automerge/automerge-repo-react-hooks": "^2.0.0-alpha.14",
4444
"@graphprotocol/grc-20": "^0.10.0",
45+
"@noble/hashes": "^1.8.0",
4546
"@tanstack/react-query": "^5.67.1",
46-
"crypto": "^1.0.1",
4747
"effect": "^3.12.4",
4848
"graphql-request": "^7.1.2",
4949
"siwe": "^2.3.2",
Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,14 @@
1-
// biome-ignore lint/style/useNodejsImportProtocol: using a package
2-
import { createHash } from 'crypto';
3-
// needed to fix sorting issues
41
import { Base58 } from '@graphprotocol/grc-20';
2+
import { md5 } from '@noble/hashes/legacy';
53
import { v4 } from 'uuid';
64

75
function createIdFromUniqueString(text: string) {
8-
const hashed = createHash('md5').update(text).digest('hex');
9-
const bytes = hexToBytesArray(hashed);
10-
// @ts-expect-error
11-
const uuid = v4({ random: bytes });
6+
const encoded = new TextEncoder().encode(text);
7+
const hashed = md5(encoded);
8+
const uuid = v4({ random: hashed });
129
return Base58.encodeBase58(uuid.split('-').join(''));
1310
}
1411

15-
function hexToBytesArray(hex: string) {
16-
const bytes: number[] = [];
17-
18-
for (let character = 0; character < hex.length; character += 2) {
19-
bytes.push(Number.parseInt(hex.slice(character, character + 2), 16));
20-
}
21-
22-
return bytes;
23-
}
24-
2512
export function createVersionId({ proposalId, entityId }: { proposalId: string; entityId: string }): string {
2613
return createIdFromUniqueString(`${proposalId}:${entityId}`);
2714
}

pnpm-lock.yaml

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

0 commit comments

Comments
 (0)