Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions mcp/tools/write-tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
canActorSendShippingUpdate,
canActorUpdateMcpOrderStatus,
} from "./order-status-auth";
import type { BinaryLike } from "node:crypto";
import {
buildDiscountCodeCreateProof,
buildDiscountCodeDeleteProof,
Expand Down Expand Up @@ -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 = {
Expand All @@ -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(),
Expand Down Expand Up @@ -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
Expand Down