MCPcopy Create free account
hub / github.com/deepnote/vscode-deepnote / computeHashInternal

Function computeHashInternal

src/platform/common/crypto.ts:72–87  ·  view source on GitHub ↗
(data: string, algorithm: 'SHA-512' | 'SHA-256' | 'SHA-1')

Source from the content-addressed store, hash-verified

70}
71
72async function computeHashInternal(data: string, algorithm: 'SHA-512' | 'SHA-256' | 'SHA-1'): Promise<string> {
73 // Ensure crypto provider is initialized
74 if (!cryptoProvider) {
75 if (!cryptoProviderPromise) {
76 cryptoProviderPromise = initCryptoProvider();
77 }
78 cryptoProvider = await cryptoProviderPromise;
79 }
80
81 const inputBuffer = new TextEncoder().encode(data);
82 const hashBuffer = await cryptoProvider.subtle.digest({ name: algorithm }, inputBuffer);
83
84 // Turn into hash string (got this logic from https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest)
85 const hashArray = Array.from(new Uint8Array(hashBuffer));
86 return hashArray.map((b) => b.toString(16).padStart(2, '0')).join('');
87}

Callers 1

computeHashFunction · 0.85

Calls 5

initCryptoProviderFunction · 0.85
joinMethod · 0.80
mapMethod · 0.80
toStringMethod · 0.65
fromMethod · 0.45

Tested by

no test coverage detected