diff --git a/api/lit_action.js b/api/lit_action.js index 03441110..4f1389e7 100644 --- a/api/lit_action.js +++ b/api/lit_action.js @@ -59,7 +59,7 @@ const context = { isPermittedAddress: false, isCreator: false, siweMessage: false }; const pkpTokenId = Lit.Actions.pubkeyToTokenId({ publicKey }); const pkpAddress = ethers.utils.computeAddress(publicKey).toLowerCase(); - const isPermittedAddress = await Lit.Actions.isPermittedAddress({ tokenId: pkpTokenId, address: Lit.Auth.authSigAddress }); + const isPermittedAddress = await Lit.Actions.isPermittedAddress({ tokenId: pkpTokenId, address: authSig.address }); context.isPermittedAddress = isPermittedAddress; const conditions = getCreatorConditions(); let isCreator = false; @@ -88,6 +88,7 @@ publicKey, sigName }); + context.litAuth = Lit.Auth; context.siweMessage = siweMessage; LitActions.setResponse({ response: JSON.stringify({ diff --git a/api/src/clients/lit.js b/api/src/clients/lit.js new file mode 100644 index 00000000..6ef27c9f --- /dev/null +++ b/api/src/clients/lit.js @@ -0,0 +1,38 @@ +import * as LitJsSdk from "@lit-protocol/lit-node-client-nodejs"; + + +class LitNodeClientSingleton { + constructor() { + if (!LitNodeClientSingleton.instance) { + // Inline configuration + const config = { + litNetwork: 'habanero', + debug: true, + }; + + this.client = new LitJsSdk.LitNodeClientNodeJs(config); + this.connect(); + LitNodeClientSingleton.instance = this; + } + return LitNodeClientSingleton.instance.client; + } + + async connect() { + try { + await this.client.connect(); + console.log('LitNodeClient connected successfully.'); + } catch (error) { + console.error('Failed to connect LitNodeClient:', error); + } + } +} + +// Ensuring the object is a singleton +LitNodeClientSingleton.instance = null; + +export function getLitNodeClient() { + if (!LitNodeClientSingleton.instance) { + return new LitNodeClientSingleton(); + } + return LitNodeClientSingleton.instance.client; +} diff --git a/api/src/libs/lit/index.js b/api/src/libs/lit/index.js index a53edc07..be7424d7 100644 --- a/api/src/libs/lit/index.js +++ b/api/src/libs/lit/index.js @@ -8,7 +8,7 @@ const ec = new elliptic.ec("secp256k1"); import RedisClient from '../../clients/redis.js'; import {DIDService} from "../../services/did.js"; import { definition } from "../../types/merged-runtime.js"; - +import { getLitNodeClient } from "../../clients/lit.js" import { DID } from "dids"; import * as LitJsSdk from "@lit-protocol/lit-node-client-nodejs"; @@ -29,6 +29,8 @@ const config = { domain: "index.network", }; +const litNodeClient = getLitNodeClient(); + const litContracts = new LitContracts({ network: config.litNetwork }); @@ -221,7 +223,7 @@ export const getPKPSession = async (session, index) => { sig: signature.replace('0x', ''), derivedVia: 'web3.eth.personal.sign', signedMessage: messageToSign, - address: userAuthSig.address, + address: dappOwnerWallet.address, }; return authSig; @@ -236,12 +238,6 @@ export const getPKPSession = async (session, index) => { try { - const litNodeClient = new LitJsSdk.LitNodeClientNodeJs({ - litNetwork: config.litNetwork, - debug: false, - }); - await litNodeClient.connect(); - const { capacityDelegationAuthSig } = await litNodeClient.createCapacityDelegationAuthSig({ diff --git a/web-app/src/config/index.ts b/web-app/src/config/index.ts index cbaaf6f2..7c4c63b2 100644 --- a/web-app/src/config/index.ts +++ b/web-app/src/config/index.ts @@ -3,7 +3,7 @@ export const appConfig = { apiUrl: "https://dev.index.network/api", // TODO: handle better ipfsProxy: "https://indexas.infura-ipfs.io/ipfs", ipfsInfura: "http://localhost:3001/avatar", - defaultCID: "QmPAoTyDyaFJJdKK6FQd9pWivAhiNLYxTUpan5zVxbbMUZ", // Empty. + defaultCID: "QmUGZYw7xY3VHYnagmaVsmgP2AnuGrqwVryNSgKgcNX9AD", // Empty. litNetwork: "habanero" as "cayenne" | "custom" | "localhost" | "manzano" | "habanero", testNetwork: { chainId: "0x2ac49",