Skip to content

Commit

Permalink
Merge pull request #23 from indexnetwork/indexer-authenticate
Browse files Browse the repository at this point in the history
iterate
  • Loading branch information
serefyarar authored Feb 7, 2024
2 parents 0535afb + fc690ee commit ebba487
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
6 changes: 3 additions & 3 deletions api/src/libs/kafka-indexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import dotenv from 'dotenv'
import axios from 'axios'
import { ItemService } from "../services/item.js";
import { EmbeddingService } from "../services/embedding.js";
import { getPKPSession } from "../libs/lit/index.js";
import { getPKPSession, getPKPSessionForIndexer } from "../libs/lit/index.js";

if(process.env.NODE_ENV !== 'production'){
dotenv.config()
Expand All @@ -12,11 +12,11 @@ export const createIndexItemEvent = async (id) => {
console.log("createIndexItemEvent", id)

const itemService = new ItemService()
const indexItem = await itemService.getIndexItemById(id);
const indexItem = await itemService.getIndexItemById(id, false);

try {

const indexSession = await getPKPSession(indexItem.index);
const indexSession = await getPKPSessionForIndexer(indexItem.index);
await indexSession.did.authenticate();

const embeddingResponse = await axios.post(`${process.env.LLM_INDEXER_HOST}/embeddings`, {
Expand Down
8 changes: 8 additions & 0 deletions api/src/libs/lit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ export const decodeDIDWithLit = (encodedDID) => {

export const walletToDID = (chain, wallet) => `did:pkh:eip155:${parseInt(chain).toString()}:${wallet}`


export const getPKPSessionForIndexer = async(index) => {
const session = await DIDSession.fromSession(process.env.INDEXER_DID_SESSION);
await session.did.authenticate()

const pkpSession = await getPKPSession(session, index);
return pkpSession;
}
export const getPKPSession = async (session, index) => {

if(!session.did.authenticated){
Expand Down
4 changes: 2 additions & 2 deletions api/src/services/item.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export class ItemService {
}
}
// Todo make it multimodel later.
async getIndexItemById(indexItemId) {
async getIndexItemById(indexItemId, transformation=true) {

try {
const {data, errors} = await this.client.executeQuery(`
Expand All @@ -127,7 +127,7 @@ export class ItemService {
throw new Error('Invalid response data');
}

return transformIndexItem(data.node);
return transformation ?transformIndexItem(data.node) : data.node;

} catch (error) {
// Log the error and rethrow it for external handling
Expand Down

0 comments on commit ebba487

Please sign in to comment.