UNPKG

@keypo/typescript-sdk-server

Version:

Server-side SDK for Keypo with custom decrypt and proxy execute implementations

48 lines 2.16 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.proxyExecuteServer = proxyExecuteServer; const authenticateLitSessionServer_1 = require("./utils/authenticateLitSessionServer"); const ensureServerEnvironment_1 = require("./utils/ensureServerEnvironment"); async function proxyExecuteServer(dataIdentifier, wallet, request, config, debug) { // Ensure server environment is properly configured await (0, ensureServerEnvironment_1.ensureServerEnvironment)(); if (debug) { console.log("dataIdentifier", dataIdentifier); console.log("wallet", wallet); console.log("request", request); console.log("config", config); } try { // authenticate lit session using server-side approach const { sessionSigs, authSig, litNodeClient, dataMetadata } = await (0, authenticateLitSessionServer_1.authenticateLitSessionServer)(wallet, config.chain, config.expiration, config.permissionsRegistryContractAddress, dataIdentifier, config.apiUrl, debug); if (debug) { console.log("sessionSigs", sessionSigs); console.log("authSig", authSig); console.log("litNodeClient", litNodeClient); console.log("dataMetadata", dataMetadata); console.log("request", request); } // prepare the request, which should include sessionSigs, authsig, evmConditions, dataMetadata, and the request body const preparedRequest = { sessionSigs, authSig, dataMetadata: JSON.stringify(dataMetadata), request: JSON.stringify(request), }; // make the request to the proxy const response = await fetch(`${config.apiUrl}/proxy`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify(preparedRequest), }); const data = await response.json(); return data.Response; } catch (error) { console.error("Error in proxyExecuteServer:", error); throw error; } } //# sourceMappingURL=proxyExecuteServer.js.map