mirror of
https://github.com/Portabase/portabase.git
synced 2026-07-14 11:16:13 +02:00
working on edge key with public server key.
This commit is contained in:
@@ -1,25 +1,20 @@
|
||||
"use client";
|
||||
import {generateEdgeKey} from "@/utils/edge_key";
|
||||
import {getServerUrl} from "@/utils/get-server-url";
|
||||
import {PasswordInput} from "@/components/wrappers/auth/password-input/password-input";
|
||||
import {useState} from "react";
|
||||
import {CopyButton} from "@/components/wrappers/common/button/copy-button";
|
||||
import {Agent} from "@/db/schema/08_agent";
|
||||
|
||||
export type AgentCardKeyProps = {
|
||||
agent: Agent;
|
||||
edgeKey: string;
|
||||
};
|
||||
|
||||
export const AgentCardKey = (props: AgentCardKeyProps) => {
|
||||
const edge_key = generateEdgeKey(getServerUrl(), props.agent.id);
|
||||
const [code, setCode] = useState<string>(`${edge_key}`);
|
||||
|
||||
export const AgentCardKey = ({edgeKey}: AgentCardKeyProps) => {
|
||||
const [code, setCode] = useState<string>(`${edgeKey}`);
|
||||
return (
|
||||
<>
|
||||
<PasswordInput
|
||||
value={code}
|
||||
onChange={() => {
|
||||
setCode(edge_key);
|
||||
setCode(edgeKey);
|
||||
}}
|
||||
/>
|
||||
<CopyButton className="mt-5" value={code}/>
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import fs from "node:fs";
|
||||
|
||||
|
||||
/**
|
||||
* Get Public server key content
|
||||
*/
|
||||
export function getPublicServerKeyContent() {
|
||||
try {
|
||||
return fs.readFileSync("private/keys/server_public.pem", "utf8");
|
||||
} catch (error: any) {
|
||||
console.error("Error :", error);
|
||||
return {
|
||||
success: false,
|
||||
message: `An error occurred while getting public server key`,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,17 @@
|
||||
"use server"
|
||||
import {getPublicServerKeyContent} from "@/features/keys/keys.action";
|
||||
|
||||
export function generateEdgeKey(serverUrl: string, agentId: string): string {
|
||||
export async function generateEdgeKey(serverUrl: string, agentId: string): Promise<string> {
|
||||
const publicKey = getPublicServerKeyContent()
|
||||
const edgeKeyData = {
|
||||
serverUrl,
|
||||
agentId,
|
||||
publicKey
|
||||
};
|
||||
console.log(edgeKeyData);
|
||||
const edgeKeyJson = JSON.stringify(edgeKeyData);
|
||||
const edgeKeyBuffer = Buffer.from(edgeKeyJson, 'utf-8');
|
||||
const edgeKeyBase64 = edgeKeyBuffer.toString('base64').replace(/=+$/, '').replace(/\+/g, '-').replace(/\//g, '_');
|
||||
return edgeKeyBase64;
|
||||
return edgeKeyBuffer.toString('base64').replace(/=+$/, '').replace(/\+/g, '-').replace(/\//g, '_');
|
||||
}
|
||||
|
||||
function decodeEdgeKey(edgeKey: string): object {
|
||||
|
||||
@@ -4,6 +4,7 @@ import {eq} from "drizzle-orm";
|
||||
import * as drizzleDb from "@/db";
|
||||
import {retentionJob} from "@/lib/tasks";
|
||||
import {generateRSAKeys} from "@/utils/rsa-keys";
|
||||
import {getPublicServerKeyContent} from "@/features/keys/keys.action";
|
||||
|
||||
|
||||
export async function init() {
|
||||
|
||||
Reference in New Issue
Block a user