From 4c7984970ca000dd695dfc2ea6cbb8ebc9a4ff1c Mon Sep 17 00:00:00 2001 From: Aryan0699 Date: Sun, 5 Apr 2026 14:20:10 +0530 Subject: [PATCH 1/3] fix: update file buffer handling to use BinaryLike for improved data integrity --- mcp/tools/write-tools.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/mcp/tools/write-tools.ts b/mcp/tools/write-tools.ts index 43396a45..328ac219 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"; const resolveCname = promisify(dns.resolveCname); const resolve4 = promisify(dns.resolve4); @@ -2410,9 +2411,10 @@ export function registerWriteTools(server: McpServer, apiKey: ApiKeyRecord) { try { const fileBuffer = Buffer.from(params.fileBase64, "base64"); + const binaryData: BinaryLike = Uint8Array.from(fileBuffer); const { createHash: cryptoCreateHash } = await import("crypto"); const hash = cryptoCreateHash("sha256") - .update(fileBuffer) + .update(binaryData) .digest("hex"); const authEvent: EventTemplate = { @@ -2422,7 +2424,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(), @@ -2465,7 +2467,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 From af5214d7286f8d916fef8cb5456d85cd0db499f3 Mon Sep 17 00:00:00 2001 From: Aryan0699 Date: Sun, 5 Apr 2026 14:36:00 +0530 Subject: [PATCH 2/3] fix: made required changes for memory efficiency --- mcp/tools/write-tools.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mcp/tools/write-tools.ts b/mcp/tools/write-tools.ts index 328ac219..0a192479 100644 --- a/mcp/tools/write-tools.ts +++ b/mcp/tools/write-tools.ts @@ -2411,8 +2411,8 @@ export function registerWriteTools(server: McpServer, apiKey: ApiKeyRecord) { try { const fileBuffer = Buffer.from(params.fileBase64, "base64"); - const binaryData: BinaryLike = Uint8Array.from(fileBuffer); - 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(binaryData) .digest("hex"); From e134df28ea01f5b6ed3f5d4909e0b1d1f1bc472e Mon Sep 17 00:00:00 2001 From: Aryan0699 Date: Fri, 10 Apr 2026 16:21:15 +0530 Subject: [PATCH 3/3] removed unncessary git lines --- mcp/tools/write-tools.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/mcp/tools/write-tools.ts b/mcp/tools/write-tools.ts index b75f855a..8c9ccb14 100644 --- a/mcp/tools/write-tools.ts +++ b/mcp/tools/write-tools.ts @@ -16,9 +16,7 @@ import { canActorSendShippingUpdate, canActorUpdateMcpOrderStatus, } from "./order-status-auth"; -<<<<<<< fix/binarylike-buffer import type { BinaryLike } from "node:crypto"; -======= import { buildDiscountCodeCreateProof, buildDiscountCodeDeleteProof, @@ -26,7 +24,6 @@ import { buildSignedHttpRequestProofTemplate, SIGNED_EVENT_HEADER, } from "@/utils/nostr/request-auth"; ->>>>>>> main const resolveCname = promisify(dns.resolveCname); const resolve4 = promisify(dns.resolve4);