UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

55 lines (54 loc) • 2.19 kB
import { s as pathMayExistSync } from "./path-existence-Co7-GyVr.mjs"; import { c as normalizeEd25519PublicKeyBase64Url, d as verifyEd25519Signature } from "./ed25519-signature-CUaH7IDK.mjs"; import { n as generateStoredDeviceIdentity } from "./device-identity-material-BGzHHiUD.mjs"; import { n as resolveDeviceIdentityStore } from "./device-identity-store-options-Bz70uEBm.mjs"; import { n as readStoredDeviceIdentity, r as readStoredDeviceIdentityReadOnly, t as insertStoredDeviceIdentityIfAbsent } from "./device-identity-store-BXZdlCZ2.mjs"; import crypto from "node:crypto"; //#region src/infra/device-identity.ts function toDeviceIdentity(e) { return { deviceId: e.deviceId, publicKeyPem: e.publicKeyPem, privateKeyPem: e.privateKeyPem }; } /** Load a valid canonical identity or atomically create its SQLite row. */ function loadOrCreateDeviceIdentity(e = {}) { const t = resolveDeviceIdentityStore(e); const n = { ...e, path: t.databasePath, identityKey: t.identityKey }; const r = pathMayExistSync(t.databasePath) ? readStoredDeviceIdentity(n) : null; if (r) return toDeviceIdentity(r); const i = generateStoredDeviceIdentity(); return toDeviceIdentity(insertStoredDeviceIdentityIfAbsent(i, n)); } /** Load a valid persisted identity without creating or mutating SQLite state. */ function loadDeviceIdentityIfPresent(e = {}) { const t = readStoredDeviceIdentityReadOnly(e); if (t) return toDeviceIdentity(t); return null; } /** Derive the stable device id from PEM or raw base64/base64url public key material. */ function deriveDeviceIdFromPublicKey(e) { try { const t = normalizeEd25519PublicKeyBase64Url(e); if (!t) return null; const n = Buffer.from(t, "base64url"); return crypto.createHash("sha256").update(n).digest("hex"); } catch { return null; } } /** Verify a UTF-8 payload signature against PEM or raw base64/base64url public key material. */ function verifyDeviceSignature(e, t, n) { return verifyEd25519Signature({ publicKey: e, payload: t, signatureBase64Url: n }); } //#endregion export { verifyDeviceSignature as i, loadDeviceIdentityIfPresent as n, loadOrCreateDeviceIdentity as r, deriveDeviceIdFromPublicKey as t };