openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 1.51 kB
JavaScript
import{b as ed25519SignerFromSeed,d as formatEd25519PublicKey,y as rawPublicKey}from"./validate-Btv7lFe1.mjs";import"./src-BTTzpNjb.mjs";import{a as loadOrCreateEndpointKey,n as ed25519PublicKeyHex,r as loadBoundKey,s as stagedKeyPath}from"./keyfile-mFhV59Tf.mjs";import path from"node:path";
//!src/gateway/openclaw-id/gateway-key.ts
var GatewayKeyRefusedError=class extends Error{constructor(e){super(e===`keys_missing`?`the Gateway key this claw is bound to is missing`:`the Gateway key file is not the key this claw is bound to`);this.reason=e}};function gatewayKeyPath(e){return path.join(e,`openclaw-id`,`gateway.key`)}async function loadGatewaySigner(e,t){const n=gatewayKeyPath(e);let r;if(t){const e=await loadBoundKey(n,Buffer.from(rawPublicKey(t)).toString(`hex`));if(`refused`in e)throw new GatewayKeyRefusedError(e.refused);r=e.key}else r=(await loadOrCreateEndpointKey(n)).key;const i=await ed25519SignerFromSeed(r);r.fill(0);return{signer:i,pub:formatEd25519PublicKey(i.publicKey)}}async function loadStagedGatewaySigner(e){const{key:t}=await loadOrCreateEndpointKey(stagedKeyPath(gatewayKeyPath(e)));const n=await ed25519SignerFromSeed(t);t.fill(0);return n}async function stageGatewayKey(e){const{key:t}=await loadOrCreateEndpointKey(stagedKeyPath(gatewayKeyPath(e)));const n=formatEd25519PublicKey(Buffer.from(ed25519PublicKeyHex(t),`hex`));t.fill(0);return n}export{stageGatewayKey as a,loadStagedGatewaySigner as i,gatewayKeyPath as n,loadGatewaySigner as r,GatewayKeyRefusedError as t};