@receiz/mcp-server
Version:
MCP server for agents building and verifying Receiz proof-native applications through the canonical Receiz SDK rails.
90 lines • 7.41 kB
JavaScript
import { verifyReceizOfflineSealedFile } from "@receiz/sdk/offline";
import { createHash } from "node:crypto";
import { createReceizDeviceMaterialHost } from "./deviceMaterialHost.js";
import { createReceizSdkMutationConsent } from "./v127SdkOperations.js";
import { persistReceizSealedOutput, registerReceizSealedOutput, RECEIZ_SEALED_OUTPUT_URI } from "./sealedArtifactOutput.js";
const authority = "MCP is not authority. MCP consent and file locators are not proof authority. Existing enclosing sealed artifact verification, delegated scopes, carried ownership continuity and canonical claim coordination govern admission.";
const outputMeta = { ui: { resourceUri: RECEIZ_SEALED_OUTPUT_URI }, "openai/outputTemplate": RECEIZ_SEALED_OUTPUT_URI };
export const RECEIZ_FINANCIAL_ARTIFACT_TOOLS = Object.freeze([
{ name: "receiz_connect_note_download", description: `Download an existing selected wallet-note sealed PNG through SDK connect.downloadNote. Verify its enclosing artifact and retain the exact bytes in private workspace custody; do not issue, claim, decode, or reseal a note. ${authority}`,
inputSchema: { type: "object", additionalProperties: false, properties: { noteId: { type: "string", minLength: 1 } }, required: ["noteId"] },
annotations: { readOnlyHint: false, destructiveHint: false, openWorldHint: true }, _meta: outputMeta },
{ name: "receiz_bearer_artifact_claim", description: `Claim a selected canonical bearer artifact using a device-held artifactReference. Verify the complete enclosing artifact and retain its SDK-issued sealed object during preview. Execute the existing ownership.claimBearerAsset coordinator only with this preview's exact single-use confirmationDigest. Reverify the returned enclosing artifact and retain exact claimed bytes privately. Raw model proof bytes, serialized custody and retired claim aliases do not grant admission. ${authority}`,
inputSchema: { type: "object", additionalProperties: false, properties: { artifactReference: { type: "string", pattern: "^receiz:file:[a-f0-9]{64}:.+$" }, confirmation: { type: "string", minLength: 1 } }, required: ["artifactReference"] },
annotations: { readOnlyHint: false, destructiveHint: true, openWorldHint: true }, _meta: outputMeta },
]);
function argumentsFor(raw, keys) {
if (!raw || typeof raw !== "object" || Array.isArray(raw) || Object.getPrototypeOf(raw) !== Object.prototype
|| Object.keys(raw).some(key => !keys.includes(key)))
throw Error("financial_artifact_arguments_invalid");
const args = raw;
for (const key of keys)
if (key !== "confirmation" || args[key] !== undefined) {
if (typeof args[key] !== "string" || !args[key].trim())
throw Error("financial_artifact_arguments_invalid");
}
return { ...args };
}
/** Closed current SDK composition; the SDK-issued object stays in host custody. */
export function createReceizFinancialArtifactOperations(input) {
const consent = createReceizSdkMutationConsent();
const held = new Map();
const persist = async (exactBytes, filename, mimeType) => {
const result = await persistReceizSealedOutput(input.workspace, { exactBytes, filename, mimeType });
const transferToken = registerReceizSealedOutput(input.runtime, result.artifactReference, result.artifactSha256, { exactBytes, filename, mimeType });
return { result, transferToken };
};
return {
async call(name, raw) {
input.ensureDelegated();
if (name === "receiz_connect_note_download") {
const args = argumentsFor(raw, ["noteId"]);
const artifact = await input.client.connect.downloadNote(args.noteId);
const filename = `settlement-note-${args.noteId.replace(/[^a-zA-Z0-9._-]/g, "_").slice(0, 120)}.png`;
if (!(artifact instanceof Blob) || artifact.type !== "image/png" || artifact.size === 0)
throw Error("financial_artifact_download_invalid");
const exactBytes = new Uint8Array(await artifact.arrayBuffer());
const artifactSha256 = createHash("sha256").update(exactBytes).digest("hex");
// Wallet PNG delivery verifies its complete enclosing seal. Ownership
// admission remains on the stronger SDK opener below for bearer claims.
const verification = await verifyReceizOfflineSealedFile({ bytes: exactBytes, filename, mimeType: artifact.type });
if (!verification.ok || !verification.integrity.ok || verification.kind !== "png"
|| createHash("sha256").update(exactBytes).digest("hex") !== artifactSha256)
throw Error("financial_artifact_verification_failed");
return persist(exactBytes, filename, artifact.type);
}
if (name !== "receiz_bearer_artifact_claim")
throw Error("financial_artifact_tool_unknown");
const args = argumentsFor(raw, ["artifactReference", "confirmation"]);
const exactArgs = { artifactReference: args.artifactReference };
if (args.confirmation === undefined) {
// Resolve and verify before local consent; an unverified subpayload or
// changed locator cannot create a preview or reach claim coordination.
const source = await createReceizDeviceMaterialHost(input.workspace).resolveProofReference(args.artifactReference);
const opened = await input.client.artifacts.verifyAndOpen(new File([new Uint8Array(source.exactBytes).buffer], source.filename, { type: source.mimeType }));
if (!opened.sealedArtifact || !(opened.sealedArtifact.artifact instanceof Blob)
|| opened.sealedArtifact.artifactSha256 !== createHash("sha256").update(source.exactBytes).digest("hex"))
throw Error("financial_artifact_verification_failed");
const preview = consent("ownership.claimBearerAsset", exactArgs);
while (held.size >= 4)
held.delete(held.keys().next().value);
held.set(preview.confirmationDigest, opened.sealedArtifact);
return { result: preview, transferToken: undefined };
}
consent("ownership.claimBearerAsset", exactArgs, args.confirmation);
const source = held.get(args.confirmation);
held.delete(args.confirmation);
if (!source)
throw Error("financial_artifact_custody_required");
const claimed = await input.client.ownership.claimBearerAsset({ artifact: source });
const reopened = await input.client.artifacts.verifyAndOpen(claimed.artifact);
if (reopened.sealedArtifact.artifactSha256 !== claimed.artifactSha256
|| reopened.sealedArtifact.payloadSha256 !== claimed.payloadSha256
|| reopened.sealedArtifact.continuity.ownerReceizId !== claimed.continuity.ownerReceizId
|| reopened.sealedArtifact.continuity.claimId !== claimed.continuity.claimId)
throw Error("financial_artifact_claim_verification_failed");
return persist(new Uint8Array(await claimed.artifact.arrayBuffer()), claimed.filename, claimed.mimeType);
},
};
}
//# sourceMappingURL=financialArtifactOperations.js.map