openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
49 lines (48 loc) • 2.38 kB
JavaScript
import { o as registerSecretValueForRedaction } from "./secret-redaction-registry-Cy0acctn.mjs";
import { r as captureOpenClawStateWorkerContext } from "./openclaw-state-worker-context-DAKL_dnZ.mjs";
import { i as runOpenClawStateWorkerOperation } from "./openclaw-state-worker-store-2LoAv_8B.mjs";
import { createHmac, randomBytes } from "node:crypto";
//#region src/gateway/config-revision-token.ts
const CONFIG_REVISION_KEY_BYTES = 32;
const CONFIG_REVISION_RAW_DOMAIN = "openclaw.gateway.config-revision.raw.v1";
const CONFIG_REVISION_RESOLVED_DOMAIN = "openclaw.gateway.config-revision.resolved.v1";
function registerConfigRevisionKeyForRedaction(e) {
const t = Buffer.from(e);
registerSecretValueForRedaction(t.toString("hex"));
registerSecretValueForRedaction(t.toString("base64url"));
}
function parseConfigRevisionKey(e) {
if (!(e instanceof Uint8Array) || e.byteLength !== CONFIG_REVISION_KEY_BYTES) throw new Error("config revision key is corrupt");
const t = Buffer.from(e);
registerConfigRevisionKeyForRedaction(t);
return t;
}
function projectRevision(e, t, n) {
return `hmac-sha256:v1:${createHmac("sha256", e).update(JSON.stringify([t, n]), "utf8").digest("base64url")}`;
}
function createGatewayConfigRevisionProjector(e) {
if (e.byteLength !== CONFIG_REVISION_KEY_BYTES) throw new Error("config revision key must be 32 bytes");
return {
projectRawHash: (t) => projectRevision(e, CONFIG_REVISION_RAW_DOMAIN, t),
projectResolvedHash: (t) => projectRevision(e, CONFIG_REVISION_RESOLVED_DOMAIN, t),
hashResponseSessionBearer: (t) => hashGatewayResponseSessionBearer(t, e)
};
}
/** Loads the durable installation key once for the Gateway request lifecycle. */
async function loadGatewayConfigRevisionProjector(e = {}) {
const t = captureOpenClawStateWorkerContext(e);
return createGatewayConfigRevisionProjector(parseConfigRevisionKey(await runOpenClawStateWorkerOperation(t, (e) => e.execute({
type: "machineState.configRevisionKey",
input: { candidateKey: randomBytes(CONFIG_REVISION_KEY_BYTES) }
}))));
}
function hashGatewayResponseSessionBearer(e, t) {
const n = createHmac("sha256", t).update("openresponses-session-scope", "utf8").digest();
try {
return `hmac-sha256:v1:${createHmac("sha256", n).update(e, "utf8").digest("hex")}`;
} finally {
n.fill(0);
}
}
//#endregion
export { loadGatewayConfigRevisionProjector as t };