Source commit: e570b80c3a0f4b152a9aa0e7bb8635b3eebcec27 Public tree identity: sha256:cff3388143eb2e9476804cfa1c1246e3a46d485d8aef90f2cdd4df45f2b69abf
43 lines
1.2 KiB
JavaScript
43 lines
1.2 KiB
JavaScript
let requestId = 0;
|
|
|
|
function coordinatorWireRequest(payload, prefix = "acceptance") {
|
|
if (payload && payload.type === "coordinator_request") return payload;
|
|
if (!payload || typeof payload.type !== "string" || !payload.type.trim()) {
|
|
throw new Error("coordinator payload must have a non-empty type");
|
|
}
|
|
requestId += 1;
|
|
return {
|
|
type: "coordinator_request",
|
|
protocol_version: 1,
|
|
request_id: `${prefix}-${process.pid}-${requestId}`,
|
|
operation: payload.type,
|
|
authentication: authenticationMetadata(payload),
|
|
payload,
|
|
};
|
|
}
|
|
|
|
function authenticationMetadata(payload) {
|
|
if (payload.type === "authenticated") {
|
|
return {
|
|
kind: "cli_session",
|
|
session: true,
|
|
request_operation: payload.request?.type || "unknown",
|
|
};
|
|
}
|
|
if (payload.type === "signed_node" || payload.node_signature) {
|
|
return { kind: "node_signature", node: payload.node || null };
|
|
}
|
|
if (payload.agent_signature) {
|
|
return {
|
|
kind: "agent_signature",
|
|
agent: payload.actor_agent || null,
|
|
fingerprint: payload.agent_public_key_fingerprint || null,
|
|
};
|
|
}
|
|
if (payload.admin_token) {
|
|
return { kind: "admin_credential" };
|
|
}
|
|
return { kind: "none" };
|
|
}
|
|
|
|
module.exports = { coordinatorWireRequest };
|