const DEFAULT_SOURCE_CONTEXT = "web:dashboard";
export function peerRuntimeContextKey(peer, sourceContextKey) {
    const source = sourceContextKey?.trim() || DEFAULT_SOURCE_CONTEXT;
    return `peer:${encodeContextPart(peer.id || peer.nodeId)}:${encodeContextPart(source)}`;
}
export function parsePeerRuntimeContextKey(key) {
    const match = /^peer:([^:]+):(.+)$/.exec(key);
    if (!match?.[1] || !match[2]) {
        return null;
    }
    return {
        peerId: decodeContextPart(match[1]),
        sourceContextKey: decodeContextPart(match[2]),
    };
}
function encodeContextPart(value) {
    return Buffer.from(value, "utf8").toString("base64url");
}
function decodeContextPart(value) {
    return Buffer.from(value, "base64url").toString("utf8");
}
