UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 2.09 kB
import{o as registerSecretValueForRedaction}from"./secret-redaction-registry-DospXE4m.mjs";import{r as captureOpenClawStateWorkerContext}from"./openclaw-state-worker-context-Dx8YjqO2.mjs";import{i as runOpenClawStateWorkerOperation}from"./openclaw-state-worker-store-7se2aIrr.mjs";import{createHmac,randomBytes}from"node:crypto"; //!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)}}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)}}export{loadGatewayConfigRevisionProjector as t};