diff --git a/src/pointers.ts b/src/pointers.ts index e2d63c6..365d41c 100644 --- a/src/pointers.ts +++ b/src/pointers.ts @@ -1,5 +1,7 @@ +// This is Node-only code due to use of crypto. +import crypto from 'crypto'; import path from 'path'; -import { SPEC_URL, toHex } from './util'; +import { SPEC_URL } from './util'; export interface PointerInfo { @@ -74,6 +76,6 @@ export function formatPointerInfo(info: PointerInfo): Buffer { export async function buildPointerInfo(content: Buffer): Promise { const size = Buffer.byteLength(content); - const hash = await crypto.subtle.digest('SHA-1', content); - return { oid: toHex(hash), size }; + const hash = crypto.createHash('sha256').update(content).digest('hex'); + return { oid: hash, size }; } diff --git a/src/util.ts b/src/util.ts index 0564b9c..a9a864b 100644 --- a/src/util.ts +++ b/src/util.ts @@ -77,14 +77,3 @@ export async function bodyToBuffer(body: Uint8Array[]): Promise { } return Buffer.from(result.buffer); } - - -// Borrowed from Isomorphic Git core, it is not importable. -export function toHex(buffer: ArrayBuffer): string { - let hex = '' - for (const byte of new Uint8Array(buffer)) { - if (byte < 16) hex += '0' - hex += byte.toString(16) - } - return hex -}