Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
elribonazo committed Apr 25, 2024
1 parent cae043b commit 56c87a8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion demos/next/src/reducers/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { v4 as uuidv4 } from "uuid";
import { DBPreload, Message } from "@/actions/types";
import { acceptCredentialOffer, acceptPresentationRequest, connectDatabase, initAgent, rejectCredentialOffer, startAgent, stopAgent } from "../actions";

const defaultMediatorDID = "did:peer:2.Ez6LSghwSE437wnDE1pt3X6hVDUQzSjsHzinpX3XFvMjRAm7y.Vz6Mkhh1e5CEYYq6JBUcTZ6Cp2ranCWRrv7Yax3Le4N59R6dd.SeyJ0IjoiZG0iLCJzIjp7InVyaSI6Imh0dHA6Ly9sb2NhbGhvc3Q6ODA4MCIsImEiOlsiZGlkY29tbS92MiJdfX0.SeyJ0IjoiZG0iLCJzIjp7InVyaSI6IndzOi8vbG9jYWxob3N0OjgwODAvd3MiLCJhIjpbImRpZGNvbW0vdjIiXX19";
const defaultMediatorDID = "did:peer:2.Ez6LSghwSE437wnDE1pt3X6hVDUQzSjsHzinpX3XFvMjRAm7y.Vz6Mkhh1e5CEYYq6JBUcTZ6Cp2ranCWRrv7Yax3Le4N59R6dd.SeyJ0IjoiZG0iLCJzIjp7InVyaSI6Imh0dHA6Ly8xOTIuMTY4LjEuNDQ6ODA4MCIsImEiOlsiZGlkY29tbS92MiJdfX0.SeyJ0IjoiZG0iLCJzIjp7InVyaSI6IndzOi8vMTkyLjE2OC4xLjQ0OjgwODAvd3MiLCJhIjpbImRpZGNvbW0vdjIiXX19";

class TraceableError extends Error {

Expand Down
5 changes: 4 additions & 1 deletion src/pluto/Pluto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,10 @@ export class Pluto implements Domain.Pluto {
/** LinkSecret **/

async storeLinkSecret(linkSecret: Domain.LinkSecret): Promise<void> {
await this.Repositories.LinkSecrets.save(linkSecret);
const existingLinkSecret = await this.Repositories.LinkSecrets.findOne({ rawHex: Buffer.from(linkSecret.secret).toString('hex') });
if (!existingLinkSecret) {
await this.Repositories.LinkSecrets.save(linkSecret);
}
}

async getLinkSecret(name: string = Domain.LinkSecret.defaultName): Promise<Domain.LinkSecret | null> {
Expand Down
12 changes: 10 additions & 2 deletions src/prism-agent/Agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,31 +265,39 @@ export default class Agent
}
this.state = AgentState.STARTING;
try {
debugger
await this.pluto.start();
debugger
await this.pollux.start();
debugger
await this.connectionManager.startMediator();
debugger
} catch (e) {
if (e instanceof Domain.AgentError.NoMediatorAvailableError) {
const hostDID = await this.createNewPeerDID([], false);
debugger
await this.connectionManager.registerMediator(hostDID);
debugger
} else throw e;
}

if (this.connectionManager.mediationHandler.mediator !== undefined) {
await this.connectionManager.startFetchingMessages(5);
this.state = AgentState.RUNNING;
debugger
} else {
throw new Domain.AgentError.MediationRequestFailedError("Mediation failed");
debugger
}

const storedLinkSecret = await this.pluto.getLinkSecret();
if (storedLinkSecret == null) {
const secret = this.pollux.anoncreds.createLinksecret();
const linkSecret = new Domain.LinkSecret(secret);

debugger
await this.pluto.storeLinkSecret(linkSecret);
}

debugger
return this.state;
}

Expand Down

0 comments on commit 56c87a8

Please sign in to comment.