diff --git a/mcp/tools/write-tools.ts b/mcp/tools/write-tools.ts index c0aa0b8b..8c9ccb14 100644 --- a/mcp/tools/write-tools.ts +++ b/mcp/tools/write-tools.ts @@ -16,6 +16,7 @@ import { canActorSendShippingUpdate, canActorUpdateMcpOrderStatus, } from "./order-status-auth"; +import type { BinaryLike } from "node:crypto"; import { buildDiscountCodeCreateProof, buildDiscountCodeDeleteProof, @@ -2421,9 +2422,10 @@ export function registerWriteTools(server: McpServer, apiKey: ApiKeyRecord) { try { const fileBuffer = Buffer.from(params.fileBase64, "base64"); - const { createHash: cryptoCreateHash } = await import("crypto"); + const binaryData: BinaryLike = new Uint8Array(fileBuffer.buffer, fileBuffer.byteOffset, fileBuffer.byteLength); + const { createHash: cryptoCreateHash } = await import("node:crypto"); const hash = cryptoCreateHash("sha256") - .update(fileBuffer) + .update(binaryData) .digest("hex"); const authEvent: EventTemplate = { @@ -2433,7 +2435,7 @@ export function registerWriteTools(server: McpServer, apiKey: ApiKeyRecord) { tags: [ ["t", "upload"], ["x", hash], - ["size", fileBuffer.length.toString()], + ["size", binaryData.length.toString()], [ "expiration", Math.floor((Date.now() + 24 * 60 * 60 * 1000) / 1000).toString(), @@ -2476,7 +2478,7 @@ export function registerWriteTools(server: McpServer, apiKey: ApiKeyRecord) { { url: result.url, sha256: result.sha256 || hash, - size: result.size || fileBuffer.length, + size: result.size || binaryData.length, serverUrl, }, startTime