Skip to content

Commit

Permalink
iterate
Browse files Browse the repository at this point in the history
  • Loading branch information
serefyarar committed Feb 18, 2024
1 parent f5628c8 commit 02fa95c
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 10 deletions.
3 changes: 2 additions & 1 deletion api/lit_action.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -88,6 +88,7 @@
publicKey,
sigName
});
context.litAuth = Lit.Auth;
context.siweMessage = siweMessage;
LitActions.setResponse({
response: JSON.stringify({
Expand Down
38 changes: 38 additions & 0 deletions api/src/clients/lit.js
Original file line number Diff line number Diff line change
@@ -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;
}
12 changes: 4 additions & 8 deletions api/src/libs/lit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -29,6 +29,8 @@ const config = {
domain: "index.network",
};

const litNodeClient = getLitNodeClient();

const litContracts = new LitContracts({
network: config.litNetwork
});
Expand Down Expand Up @@ -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;
Expand All @@ -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({
Expand Down
2 changes: 1 addition & 1 deletion web-app/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 02fa95c

Please sign in to comment.