Skip to content

Commit 1e9e397

Browse files
committed
feat: Update hashCacheKey to use crypto.hash for Node.js v20.12.0+
1 parent 911cbb7 commit 1e9e397

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

  • packages/connectivity/src/scp-cf

packages/connectivity/src/scp-cf/cache.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createHash } from 'node:crypto';
1+
import * as crypto from 'node:crypto';
22
import { stringify } from 'safe-stable-stringify';
33

44
interface CacheInterface<T> {
@@ -164,7 +164,14 @@ export class Cache<T> implements CacheInterface<T> {
164164
*/
165165
export function hashCacheKey(value: Record<string, unknown>): string {
166166
const serialized = stringify(value);
167-
return createHash('blake2s256').update(serialized).digest('hex');
167+
168+
// TODO: crypto.hash is available in Node.js v20.12.0 and later.
169+
// Remove the fallback to crypto.createHash once Node.js 22 is the minimum supported version.
170+
if (typeof crypto.hash === 'function') {
171+
return crypto.hash('blake2s256', serialized, 'base64url');
172+
}
173+
174+
return crypto.createHash('blake2s256').update(serialized).digest('base64url');
168175
}
169176

170177
function isExpired<T>(item: CacheEntry<T>): boolean {

0 commit comments

Comments
 (0)