Skip to content

Commit 300c692

Browse files
Copilothotlong
andcommitted
Replace simple hash with SHA-256 in hot-reload checksum calculation
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 363fcf3 commit 300c692

1 file changed

Lines changed: 4 additions & 12 deletions

File tree

packages/core/src/hot-reload.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
22

3+
import { createHash } from 'node:crypto';
4+
35
import type {
46
HotReloadConfig,
57
PluginStateSnapshot
@@ -136,21 +138,11 @@ class PluginStateManager {
136138
}
137139

138140
/**
139-
* Calculate simple checksum for state verification
140-
* WARNING: This is a simple hash for demo purposes.
141-
* In production, use a cryptographic hash like SHA-256.
141+
* Calculate checksum for state verification using SHA-256.
142142
*/
143143
private calculateChecksum(state: Record<string, any>): string {
144-
// Simple checksum using JSON serialization
145-
// TODO: Replace with crypto.createHash('sha256') for production
146144
const stateStr = JSON.stringify(state);
147-
let hash = 0;
148-
for (let i = 0; i < stateStr.length; i++) {
149-
const char = stateStr.charCodeAt(i);
150-
hash = ((hash << 5) - hash) + char;
151-
hash = hash & hash; // Convert to 32-bit integer
152-
}
153-
return hash.toString(16);
145+
return createHash('sha256').update(stateStr).digest('hex');
154146
}
155147

156148
/**

0 commit comments

Comments
 (0)