Skip to content
Snippets Groups Projects
Commit 5ee43e86 authored by Zdravko Iliev's avatar Zdravko Iliev
Browse files

feat: implement url shortener for invitation urls

parent 816f63aa
No related branches found
No related tags found
1 merge request!41feat: implement url shortener for invitation urls
Pipeline #65897 waiting for manual action with stages
in 20 minutes and 37 seconds
# OCM ENGINE - AGENT
# OCM ENGINE - AGENT
Agent service is a wrapper around @ocm-engine/askar library.
......
# OCM ENGINE - Gateway
# OCM ENGINE - Gateway
External service.
......
......@@ -134,9 +134,9 @@ export class ConnectionController {
},
})
@ApiOperation({
summary: "Accept invitation for connection",
summary: "Accept invitation long and short urls for connection",
description:
"Method will accept the invitation and will return connection thought the websocket. The id of the response will be matched when you receive event from the websocket",
"Method will accept long and short invitation urls and will return connection thought the websocket. The id of the response will be matched when you receive event from the websocket",
tags: ["Connections"],
})
async acceptInvitation(
......
......@@ -22,6 +22,7 @@ import {
V2ProofProtocol,
WalletError,
WalletKeyExistsError,
OutOfBandState,
} from "@aries-framework/core";
import {
AnonCredsCredentialFormatService,
......@@ -62,6 +63,7 @@ export type SubjectMessage = {
message: EncryptedMessage;
replySubject?: Subject<SubjectMessage>;
};
import { Request, Response, Express } from "express";
export const importDidsToWallet = async (
agent: Agent,
......@@ -385,3 +387,34 @@ export const waitForProofExchangeRecordSubject = (
),
);
};
export const attachShortUrlHandler = (server: Express, agent: Agent): void => {
server.get(
"/invitations/:invitationId",
async (req: Request, res: Response) => {
try {
const { invitationId } = req.params;
const outOfBandRecord = await agent.oob.findByCreatedInvitationId(
invitationId,
);
if (
!outOfBandRecord ||
outOfBandRecord.state !== OutOfBandState.AwaitResponse
) {
return res.status(404).send("Not found");
}
const invitationJson = outOfBandRecord.outOfBandInvitation.toJSON();
return res
.header("Content-Type", "application/json")
.send(invitationJson);
} catch (error) {
console.error(error);
return res.status(500).send("Internal Server Error");
}
},
);
};
......@@ -42,6 +42,7 @@ export class AgentService {
domain: this.askar.agentConfig.agentPeerAddress,
});
i.shortInvitationUrl = `${this.askar.agentConfig.agentPeerAddress}/invitations/${outOfBoundRecord.outOfBandInvitation.id}`;
return i;
};
......
......@@ -24,11 +24,13 @@ import {
generateKey,
getAskarAnonCredsIndyModules,
importDidsToWallet,
attachShortUrlHandler,
setupEventReplaySubjects,
setupSubjectTransports,
} from "../agent.utils";
import { IConfAgent } from "@ocm-engine/config";
import { ReplaySubject } from "rxjs";
import express from "express";
@Injectable()
export class AskarService implements OnModuleInit, OnModuleDestroy {
......@@ -36,13 +38,14 @@ export class AskarService implements OnModuleInit, OnModuleDestroy {
public agentR: ReplaySubject<BaseEvent>;
public agentConfig: IConfAgent;
private readonly logger: Logger = new Logger(AskarService.name);
private readonly server = express();
constructor(
private readonly configService: ConfigService,
private readonly ledgersSerivce: LedgersService,
) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
this.agentConfig = configService.get<IConfAgent>("agent")!;
this.agentConfig = this.configService.get<IConfAgent>("agent")!;
const config = {
label: this.agentConfig.agentName,
......@@ -72,8 +75,14 @@ export class AskarService implements OnModuleInit, OnModuleDestroy {
),
});
//handler for short url invitations, look at agent service createInvitation
attachShortUrlHandler(this.server, this.agent);
this.agent.registerInboundTransport(
new HttpInboundTransport({ port: this.agentConfig.agentPeerPort }),
new HttpInboundTransport({
app: this.server,
port: this.agentConfig.agentPeerPort,
}),
);
this.agent.registerOutboundTransport(new WsOutboundTransport());
......
export class CreateInvitationResponseDto {
/**
* A list of user's roles
* Example of long invitation url
* @example "http://0.0.0.0:8001?oob=eyJAdHlwZSI6Imh0dHBzOi8vZGlkY29tbS5vcmcvb3V0LW9mLWJhbmQvMS4xL2ludml0YXRpb24iLCJAaWQiOiIzYWExNGIzNC04YTk5LTQxY2UtYTY3NC1jODUxYmVhMTIxMWEiLCJsYWJlbCI6IkRFeGNWYXNkX0FHRU5UXzQ1IiwiYWNjZXB0IjpbImRpZGNvbW0vYWlwMSIsImRpZGNvbW0vYWlwMjtlbnY9cmZjMTkiXSwiaGFuZHNoYWtlX3Byb3RvY29scyI6WyJodHRwczovL2RpZGNvbW0ub3JnL2RpZGV4Y2hhbmdlLzEuMCIsImh0dHBzOi8vZGlkY29tbS5vcmcvY29ubmVjdGlvbnMvMS4wIl0sInNlcnZpY2VzIjpbeyJpZCI6IiNpbmxpbmUtMCIsInNlcnZpY2VFbmRwb2ludCI6Imh0dHA6Ly8wLjAuMC4wOjgwMDEiLCJ0eXBlIjoiZGlkLWNvbW11bmljYXRpb24iLCJyZWNpcGllbnRLZXlzIjpbImRpZDprZXk6ejZNa3VFcHllc1pNa3k0a1BpQzhEOEplZERlcm55YTFuaTREMUF3ZmdnWWt6YmR4Il0sInJvdXRpbmdLZXlzIjpbXX1dfQ"
*/
public invitationUrl: string;
/**
*
* @example "http://0.0.0.0:8001/invitations/85a7c179-122b-4d2d-9a86-d92ad31cef2b"
*/
public shortInvitationUrl: string;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment