@verana-labs/vs-agent-sdk 1.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/build/agent/VsAgent.d.ts +66 -0
- package/build/agent/VsAgent.js +276 -0
- package/build/agent/VsAgent.js.map +1 -0
- package/build/agent/createVsAgent.d.ts +50 -0
- package/build/agent/createVsAgent.js +43 -0
- package/build/agent/createVsAgent.js.map +1 -0
- package/build/credentials/FullTailsFileService.d.ts +17 -0
- package/build/credentials/FullTailsFileService.js +76 -0
- package/build/credentials/FullTailsFileService.js.map +1 -0
- package/build/did/CachedDocumentLoader.d.ts +35 -0
- package/build/did/CachedDocumentLoader.js +139 -0
- package/build/did/CachedDocumentLoader.js.map +1 -0
- package/build/did/CachedWebDidResolver.d.ts +9 -0
- package/build/did/CachedWebDidResolver.js +44 -0
- package/build/did/CachedWebDidResolver.js.map +1 -0
- package/build/did/WebDidRegistrar.d.ts +34 -0
- package/build/did/WebDidRegistrar.js +110 -0
- package/build/did/WebDidRegistrar.js.map +1 -0
- package/build/did/legacyDidWeb.d.ts +10 -0
- package/build/did/legacyDidWeb.js +41 -0
- package/build/did/legacyDidWeb.js.map +1 -0
- package/build/index.d.ts +24 -0
- package/build/index.js +68 -0
- package/build/index.js.map +1 -0
- package/build/plugins/setupBaseDidComm.d.ts +15 -0
- package/build/plugins/setupBaseDidComm.js +82 -0
- package/build/plugins/setupBaseDidComm.js.map +1 -0
- package/build/transports/HttpInboundTransport.d.ts +28 -0
- package/build/transports/HttpInboundTransport.js +132 -0
- package/build/transports/HttpInboundTransport.js.map +1 -0
- package/build/transports/VsAgentWsInboundTransport.d.ts +30 -0
- package/build/transports/VsAgentWsInboundTransport.js +143 -0
- package/build/transports/VsAgentWsInboundTransport.js.map +1 -0
- package/build/transports/VsAgentWsOutboundTransport.d.ts +20 -0
- package/build/transports/VsAgentWsOutboundTransport.js +129 -0
- package/build/transports/VsAgentWsOutboundTransport.js.map +1 -0
- package/build/types.d.ts +30 -0
- package/build/types.js +5 -0
- package/build/types.js.map +1 -0
- package/build/utils/agent.d.ts +20 -0
- package/build/utils/agent.js +49 -0
- package/build/utils/agent.js.map +1 -0
- package/build/utils/data.d.ts +1 -0
- package/build/utils/data.js +255 -0
- package/build/utils/data.js.map +1 -0
- package/build/utils/parsers.d.ts +11 -0
- package/build/utils/parsers.js +36 -0
- package/build/utils/parsers.js.map +1 -0
- package/build/utils/util.d.ts +3 -0
- package/build/utils/util.js +151 -0
- package/build/utils/util.js.map +1 -0
- package/build/utils/webhook.d.ts +13 -0
- package/build/utils/webhook.js +56 -0
- package/build/utils/webhook.js.map +1 -0
- package/build/utils/webhookEvent.d.ts +5 -0
- package/build/utils/webhookEvent.js +26 -0
- package/build/utils/webhookEvent.js.map +1 -0
- package/package.json +53 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.HttpTransportSession = exports.HttpInboundTransport = void 0;
|
|
37
|
+
const core_1 = require("@credo-ts/core");
|
|
38
|
+
const didcomm_1 = require("@credo-ts/didcomm");
|
|
39
|
+
const express_1 = __importStar(require("express"));
|
|
40
|
+
const supportedContentTypes = [didcomm_1.DidCommMimeType.V0, didcomm_1.DidCommMimeType.V1];
|
|
41
|
+
class HttpInboundTransport {
|
|
42
|
+
get server() {
|
|
43
|
+
return this._server;
|
|
44
|
+
}
|
|
45
|
+
constructor({ path, port }) {
|
|
46
|
+
this.port = port;
|
|
47
|
+
this.path = path !== null && path !== void 0 ? path : '/';
|
|
48
|
+
}
|
|
49
|
+
setApp(app) {
|
|
50
|
+
this.app = app;
|
|
51
|
+
this.setupMiddleware();
|
|
52
|
+
}
|
|
53
|
+
setupMiddleware() {
|
|
54
|
+
var _a;
|
|
55
|
+
(_a = this.app) === null || _a === void 0 ? void 0 : _a.use((0, express_1.text)({ type: supportedContentTypes, limit: '5mb' }));
|
|
56
|
+
}
|
|
57
|
+
async start(agentContext, app) {
|
|
58
|
+
if (!this.app) {
|
|
59
|
+
this.app = app !== null && app !== void 0 ? app : (0, express_1.default)();
|
|
60
|
+
this.setupMiddleware();
|
|
61
|
+
}
|
|
62
|
+
const transportService = agentContext.dependencyManager.resolve(didcomm_1.DidCommTransportService);
|
|
63
|
+
const messageReceiver = agentContext.dependencyManager.resolve(didcomm_1.DidCommMessageReceiver);
|
|
64
|
+
agentContext.config.logger.debug(`Starting HTTP inbound transport`, {
|
|
65
|
+
port: this.port,
|
|
66
|
+
});
|
|
67
|
+
this.app.post(this.path, async (req, res) => {
|
|
68
|
+
const contentType = req.headers['content-type'];
|
|
69
|
+
if (!contentType || !supportedContentTypes.includes(contentType)) {
|
|
70
|
+
return res
|
|
71
|
+
.status(415)
|
|
72
|
+
.send('Unsupported content-type. Supported content-types are: ' + supportedContentTypes.join(', '));
|
|
73
|
+
}
|
|
74
|
+
const session = new HttpTransportSession(core_1.utils.uuid(), req, res);
|
|
75
|
+
try {
|
|
76
|
+
const message = req.body;
|
|
77
|
+
const encryptedMessage = JSON.parse(message);
|
|
78
|
+
await messageReceiver.receiveMessage(encryptedMessage, {
|
|
79
|
+
session,
|
|
80
|
+
});
|
|
81
|
+
// If agent did not use session when processing message we need to send response here.
|
|
82
|
+
if (!res.headersSent) {
|
|
83
|
+
res.status(200).end();
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
agentContext.config.logger.error(`Error processing inbound message: ${error.message}`, error);
|
|
88
|
+
if (!res.headersSent) {
|
|
89
|
+
res.status(500).send('Error processing message');
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
finally {
|
|
93
|
+
transportService.removeSession(session);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
this._server = this.app.listen(this.port);
|
|
97
|
+
}
|
|
98
|
+
async stop() {
|
|
99
|
+
var _a;
|
|
100
|
+
(_a = this._server) === null || _a === void 0 ? void 0 : _a.close();
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
exports.HttpInboundTransport = HttpInboundTransport;
|
|
104
|
+
class HttpTransportSession {
|
|
105
|
+
constructor(id, req, res) {
|
|
106
|
+
this.type = 'http';
|
|
107
|
+
this.id = id;
|
|
108
|
+
this.req = req;
|
|
109
|
+
this.res = res;
|
|
110
|
+
}
|
|
111
|
+
async close() {
|
|
112
|
+
if (!this.res.headersSent) {
|
|
113
|
+
this.res.status(200).end();
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
async send(agentContext, encryptedMessage) {
|
|
117
|
+
if (this.res.headersSent) {
|
|
118
|
+
throw new core_1.CredoError(`${this.type} transport session has been closed.`);
|
|
119
|
+
}
|
|
120
|
+
// By default we take the agent config's default DIDComm content-type
|
|
121
|
+
let responseMimeType = agentContext.dependencyManager.resolve(didcomm_1.DidCommModuleConfig).didCommMimeType;
|
|
122
|
+
// However, if the request mime-type is a mime-type that is supported by us, we use that
|
|
123
|
+
// to minimize the chance of interoperability issues
|
|
124
|
+
const requestMimeType = this.req.headers['content-type'];
|
|
125
|
+
if (requestMimeType && supportedContentTypes.includes(requestMimeType)) {
|
|
126
|
+
responseMimeType = requestMimeType;
|
|
127
|
+
}
|
|
128
|
+
this.res.status(200).contentType(responseMimeType).json(encryptedMessage).end();
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
exports.HttpTransportSession = HttpTransportSession;
|
|
132
|
+
//# sourceMappingURL=HttpInboundTransport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HttpInboundTransport.js","sourceRoot":"","sources":["../../src/transports/HttpInboundTransport.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,yCAAkD;AAClD,+CAQ0B;AAC1B,mDAAuC;AAEvC,MAAM,qBAAqB,GAAa,CAAC,yBAAe,CAAC,EAAE,EAAE,yBAAe,CAAC,EAAE,CAAC,CAAA;AAEhF,MAAa,oBAAoB;IAM/B,IAAW,MAAM;QACf,OAAO,IAAI,CAAC,OAAO,CAAA;IACrB,CAAC;IAED,YAAmB,EAAE,IAAI,EAAE,IAAI,EAAmC;QAChE,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB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Aa;QAJ1C,SAAI,GAAG,MAAM,CAAA;QAK3B,IAAI,CAAC,EAAE,GAAG,EAAE,CAAA;QACZ,IAAI,CAAC,GAAG,GAAG,GAAG,CAAA;QACd,IAAI,CAAC,GAAG,GAAG,GAAG,CAAA;IAChB,CAAC;IAEM,KAAK,CAAC,KAAK;QAChB,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC;YAC1B,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,CAAA;QAC5B,CAAC;IACH,CAAC;IAEM,KAAK,CAAC,IAAI,CAAC,YAA0B,EAAE,gBAAyC;QACrF,IAAI,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC;YACzB,MAAM,IAAI,iBAAU,CAAC,GAAG,IAAI,CAAC,IAAI,qCAAqC,CAAC,CAAA;QACzE,CAAC;QAED,qEAAqE;QACrE,IAAI,gBAAgB,GAAG,YAAY,CAAC,iBAAiB,CAAC,OAAO,CAAC,6BAAmB,CAAC,CAAC,eAAe,CAAA;QAElG,wFAAwF;QACxF,oDAAoD;QACpD,MAAM,eAAe,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,cAAc,CAAC,CAAA;QACxD,IAAI,eAAe,IAAI,qBAAqB,CAAC,QAAQ,CAAC,eAAe,CAAC,EAAE,CAAC;YACvE,gBAAgB,GAAG,eAAe,CAAA;QACpC,CAAC;QAED,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,WAAW,CAAC,gBAAgB,CAAC,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC,GAAG,EAAE,CAAA;IACjF,CAAC;CACF;AAnCD,oDAmCC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Logger, AgentContext } from '@credo-ts/core';
|
|
2
|
+
import { DidCommConnectionRecord, DidCommEncryptedMessage, DidCommInboundTransport, DidCommTransportSession } from '@credo-ts/didcomm';
|
|
3
|
+
import WebSocket, { Server } from 'ws';
|
|
4
|
+
export declare class VsAgentWsInboundTransport implements DidCommInboundTransport {
|
|
5
|
+
private socketServer;
|
|
6
|
+
private logger;
|
|
7
|
+
private socketIds;
|
|
8
|
+
constructor({ server, port, }: {
|
|
9
|
+
server: Server;
|
|
10
|
+
port?: undefined;
|
|
11
|
+
} | {
|
|
12
|
+
server?: undefined;
|
|
13
|
+
port: number;
|
|
14
|
+
});
|
|
15
|
+
start(agentContext: AgentContext): Promise<void>;
|
|
16
|
+
stop(): Promise<void>;
|
|
17
|
+
getServer(): WebSocket.Server<typeof WebSocket, typeof import("http").IncomingMessage>;
|
|
18
|
+
private startIdleSocketTimer;
|
|
19
|
+
private listenOnWebSocketMessages;
|
|
20
|
+
}
|
|
21
|
+
export declare class WebSocketTransportSession implements DidCommTransportSession {
|
|
22
|
+
id: string;
|
|
23
|
+
readonly type = "WebSocket";
|
|
24
|
+
socket: WebSocket;
|
|
25
|
+
connection?: DidCommConnectionRecord;
|
|
26
|
+
logger: Logger;
|
|
27
|
+
constructor(id: string, socket: WebSocket, logger: Logger);
|
|
28
|
+
send(agentContext: AgentContext, encryptedMessage: DidCommEncryptedMessage): Promise<void>;
|
|
29
|
+
close(): Promise<void>;
|
|
30
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.WebSocketTransportSession = exports.VsAgentWsInboundTransport = void 0;
|
|
37
|
+
const core_1 = require("@credo-ts/core");
|
|
38
|
+
const didcomm_1 = require("@credo-ts/didcomm");
|
|
39
|
+
const ws_1 = __importStar(require("ws"));
|
|
40
|
+
class VsAgentWsInboundTransport {
|
|
41
|
+
constructor({ server, port, }) {
|
|
42
|
+
// We're using a `socketId` just for the prevention of calling the connection handler twice.
|
|
43
|
+
this.socketIds = {};
|
|
44
|
+
this.socketServer = server !== null && server !== void 0 ? server : new ws_1.Server({ port });
|
|
45
|
+
}
|
|
46
|
+
async start(agentContext) {
|
|
47
|
+
const transportService = agentContext.dependencyManager.resolve(didcomm_1.DidCommTransportService);
|
|
48
|
+
const didcomm = agentContext.dependencyManager.resolve(didcomm_1.DidCommApi);
|
|
49
|
+
this.logger = agentContext.config.logger;
|
|
50
|
+
this.logger.debug('VS Agent Ws Inbound transport start');
|
|
51
|
+
const wsEndpoint = didcomm.config.endpoints.find(e => e.startsWith('ws'));
|
|
52
|
+
this.logger.debug(`Starting WS inbound transport`, {
|
|
53
|
+
endpoint: wsEndpoint,
|
|
54
|
+
});
|
|
55
|
+
this.socketServer.on('connection', (socket) => {
|
|
56
|
+
const socketId = core_1.utils.uuid();
|
|
57
|
+
this.logger.debug('Socket connected.');
|
|
58
|
+
socket.isAlive = true;
|
|
59
|
+
socket.lastActivity = new Date();
|
|
60
|
+
if (!this.socketIds[socketId]) {
|
|
61
|
+
this.logger.debug(`Saving new socket with id ${socketId}.`);
|
|
62
|
+
this.socketIds[socketId] = socket;
|
|
63
|
+
const session = new WebSocketTransportSession(socketId, socket, this.logger);
|
|
64
|
+
this.listenOnWebSocketMessages(agentContext, socket, session);
|
|
65
|
+
socket.on('close', () => {
|
|
66
|
+
this.logger.debug('Socket closed.');
|
|
67
|
+
transportService.removeSession(session);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
this.logger.debug(`Socket with id ${socketId} already exists.`);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
this.startIdleSocketTimer(60000);
|
|
75
|
+
}
|
|
76
|
+
async stop() {
|
|
77
|
+
this.logger.debug('Closing WebSocket Server');
|
|
78
|
+
return new Promise((resolve, reject) => {
|
|
79
|
+
this.socketServer.close(error => {
|
|
80
|
+
if (error) {
|
|
81
|
+
reject(error);
|
|
82
|
+
}
|
|
83
|
+
resolve();
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
getServer() {
|
|
88
|
+
this.logger.debug('Get WebSocket Server');
|
|
89
|
+
return this.socketServer;
|
|
90
|
+
}
|
|
91
|
+
startIdleSocketTimer(interval) {
|
|
92
|
+
setInterval(() => {
|
|
93
|
+
const currentDate = new Date();
|
|
94
|
+
this.socketServer.clients.forEach(item => {
|
|
95
|
+
if (currentDate.valueOf() - item.lastActivity.valueOf() > interval) {
|
|
96
|
+
this.logger.debug('Client session closed by inactivity');
|
|
97
|
+
item.close();
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}, interval);
|
|
101
|
+
}
|
|
102
|
+
listenOnWebSocketMessages(agentContext, socket, session) {
|
|
103
|
+
socket.on('pong', () => {
|
|
104
|
+
this.logger.debug('Pong received');
|
|
105
|
+
socket.isAlive = true;
|
|
106
|
+
});
|
|
107
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
108
|
+
socket.addEventListener('message', async (event) => {
|
|
109
|
+
this.logger.debug('WebSocket message event received.', { url: event.target.url, data: event.data });
|
|
110
|
+
socket.lastActivity = new Date();
|
|
111
|
+
try {
|
|
112
|
+
const messageReceiver = agentContext.dependencyManager.resolve(didcomm_1.DidCommMessageReceiver);
|
|
113
|
+
await messageReceiver.receiveMessage(JSON.parse(event.data), session);
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
this.logger.error('Error processing message');
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
exports.VsAgentWsInboundTransport = VsAgentWsInboundTransport;
|
|
122
|
+
class WebSocketTransportSession {
|
|
123
|
+
constructor(id, socket, logger) {
|
|
124
|
+
this.type = 'WebSocket';
|
|
125
|
+
this.id = id;
|
|
126
|
+
this.socket = socket;
|
|
127
|
+
this.logger = logger;
|
|
128
|
+
}
|
|
129
|
+
async send(agentContext, encryptedMessage) {
|
|
130
|
+
if (this.socket.readyState !== ws_1.default.OPEN) {
|
|
131
|
+
throw new core_1.CredoError(`${this.type} transport session has been closed.`);
|
|
132
|
+
}
|
|
133
|
+
this.socket.send(JSON.stringify(encryptedMessage));
|
|
134
|
+
this.socket.lastActivity = new Date();
|
|
135
|
+
}
|
|
136
|
+
async close() {
|
|
137
|
+
var _a;
|
|
138
|
+
this.logger.debug(`Web Socket Transport Session close requested. Connection Id: ${(_a = this.connection) === null || _a === void 0 ? void 0 : _a.id}`);
|
|
139
|
+
// Do not actually close socket. Leave heartbeat to do its job
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
exports.WebSocketTransportSession = WebSocketTransportSession;
|
|
143
|
+
//# sourceMappingURL=VsAgentWsInboundTransport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VsAgentWsInboundTransport.js","sourceRoot":"","sources":["../../src/transports/VsAgentWsInboundTransport.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yCAAwE;AACxE,+CAQ0B;AAC1B,yCAAsC;AAQtC,MAAa,yBAAyB;IAOpC,YAAmB,EACjB,MAAM,EACN,IAAI,GACwE;QAN9E,4FAA4F;QACpF,cAAS,GAA4B,EAAE,CAAA;QAM7C,IAAI,CAAC,YAAY,GAAG,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,IAAI,WAAM,CAAC,EAAE,IAAI,EAAE,CAAC,CAAA;IACpD,CAAC;IAEM,KAAK,CAAC,KAAK,CAAC,YAA0B;QAC3C,MAAM,gBAAgB,GAAG,YAAY,CAAC,iBAAiB,CAAC,OAAO,CAAC,iCAAuB,CAAC,CAAA;QACxF,MAAM,OAAO,GAAG,YAAY,CAAC,iBAAiB,CAAC,OAAO,CAAC,oBAAU,CAAC,CAAA;QAElE,IAAI,CAAC,MAAM,GAAG,YAAY,CAAC,MAAM,CAAC,MAAM,CAAA;QACxC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,qCAAqC,CAAC,CAAA;QAExD,MAAM,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAA;QACzE,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,+BAA+B,EAAE;YACjD,QAAQ,EAAE,UAAU;SACrB,CAAC,CAAA;QAEF,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AAU,0CAAE,EAAE,EAAE,CAAC,CAAA;QACxG,8DAA8D;IAChE,CAAC;CACF;AA1BD,8DA0BC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { AgentContext } from '@credo-ts/core';
|
|
2
|
+
import { DidCommOutboundPackage, DidCommOutboundTransport } from '@credo-ts/didcomm';
|
|
3
|
+
export declare function getProtocolScheme(url: string): string;
|
|
4
|
+
export declare class VsAgentWsOutboundTransport implements DidCommOutboundTransport {
|
|
5
|
+
private transportTable;
|
|
6
|
+
private agentContext;
|
|
7
|
+
private logger;
|
|
8
|
+
private eventEmitter;
|
|
9
|
+
private WebSocketClass;
|
|
10
|
+
supportedSchemes: string[];
|
|
11
|
+
constructor();
|
|
12
|
+
private startIdleSocketTimer;
|
|
13
|
+
start(agentContext: AgentContext): Promise<void>;
|
|
14
|
+
stop(): Promise<void>;
|
|
15
|
+
sendMessage(outboundPackage: DidCommOutboundPackage): Promise<void>;
|
|
16
|
+
private resolveSocket;
|
|
17
|
+
private handleMessageEvent;
|
|
18
|
+
private listenOnWebSocketMessages;
|
|
19
|
+
private createSocketConnection;
|
|
20
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VsAgentWsOutboundTransport = void 0;
|
|
4
|
+
exports.getProtocolScheme = getProtocolScheme;
|
|
5
|
+
const core_1 = require("@credo-ts/core");
|
|
6
|
+
const didcomm_1 = require("@credo-ts/didcomm");
|
|
7
|
+
function getProtocolScheme(url) {
|
|
8
|
+
const [protocolScheme] = url.split(':');
|
|
9
|
+
return protocolScheme;
|
|
10
|
+
}
|
|
11
|
+
class VsAgentWsOutboundTransport {
|
|
12
|
+
constructor() {
|
|
13
|
+
this.transportTable = new Map();
|
|
14
|
+
this.supportedSchemes = ['ws', 'wss'];
|
|
15
|
+
// NOTE: Because this method is passed to the event handler this must be a lambda method
|
|
16
|
+
// so 'this' is scoped to the 'WsOutboundTransport' class instance
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
18
|
+
this.handleMessageEvent = (event) => {
|
|
19
|
+
this.logger.trace('WebSocket message event received.', { url: event.target.url, data: event.data });
|
|
20
|
+
event.target.lastActivity = new Date();
|
|
21
|
+
const payload = core_1.JsonEncoder.fromUint8Array(event.data);
|
|
22
|
+
if (!(0, didcomm_1.isValidJweStructure)(payload)) {
|
|
23
|
+
throw new Error(`Received a response from the other agent but the structure of the
|
|
24
|
+
incoming message is not a DIDComm message: ${payload}`);
|
|
25
|
+
}
|
|
26
|
+
this.logger.debug('Payload received from mediator');
|
|
27
|
+
this.eventEmitter.emit(this.agentContext, {
|
|
28
|
+
type: didcomm_1.DidCommEventTypes.DidCommMessageReceived,
|
|
29
|
+
payload: {
|
|
30
|
+
message: payload,
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
this.startIdleSocketTimer(60000);
|
|
35
|
+
}
|
|
36
|
+
startIdleSocketTimer(interval) {
|
|
37
|
+
setInterval(() => {
|
|
38
|
+
const currentDate = new Date();
|
|
39
|
+
this.transportTable.forEach(item => {
|
|
40
|
+
if (currentDate.valueOf() - item.lastActivity.valueOf() > interval) {
|
|
41
|
+
item.removeEventListener('message', this.handleMessageEvent);
|
|
42
|
+
item.close();
|
|
43
|
+
this.logger.debug('Socket closed by inactivity');
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}, interval);
|
|
47
|
+
}
|
|
48
|
+
async start(agentContext) {
|
|
49
|
+
this.agentContext = agentContext;
|
|
50
|
+
const agentConfig = this.agentContext.dependencyManager.resolve(core_1.AgentConfig);
|
|
51
|
+
this.logger = agentConfig.logger;
|
|
52
|
+
this.eventEmitter = this.agentContext.dependencyManager.resolve(core_1.EventEmitter);
|
|
53
|
+
this.logger.debug('Starting WS outbound transport');
|
|
54
|
+
this.WebSocketClass = agentConfig.agentDependencies.WebSocketClass;
|
|
55
|
+
}
|
|
56
|
+
async stop() {
|
|
57
|
+
this.logger.debug('Stopping WS outbound transport');
|
|
58
|
+
this.transportTable.forEach(socket => {
|
|
59
|
+
socket.removeEventListener('message', this.handleMessageEvent);
|
|
60
|
+
socket.close();
|
|
61
|
+
this.logger.debug('Socket closed!');
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
async sendMessage(outboundPackage) {
|
|
65
|
+
const { payload, endpoint, connectionId } = outboundPackage;
|
|
66
|
+
this.logger.debug(`Sending outbound message to endpoint '${endpoint}' over WebSocket transport.`, {
|
|
67
|
+
payload,
|
|
68
|
+
});
|
|
69
|
+
if (!endpoint) {
|
|
70
|
+
throw new core_1.CredoError("Missing connection or endpoint. I don't know how and where to send the message.");
|
|
71
|
+
}
|
|
72
|
+
const socket = await this.resolveSocket({ socketId: endpoint, endpoint, connectionId });
|
|
73
|
+
socket.send(Buffer.from(JSON.stringify(payload)));
|
|
74
|
+
socket.lastActivity = new Date();
|
|
75
|
+
}
|
|
76
|
+
async resolveSocket({ socketId, endpoint, connectionId, }) {
|
|
77
|
+
// If we already have a socket connection use it
|
|
78
|
+
let socket = this.transportTable.get(socketId);
|
|
79
|
+
if (!socket) {
|
|
80
|
+
if (!endpoint) {
|
|
81
|
+
throw new core_1.CredoError("Missing endpoint. I don't know how and where to send the message.");
|
|
82
|
+
}
|
|
83
|
+
socket = await this.createSocketConnection({
|
|
84
|
+
endpoint,
|
|
85
|
+
socketId,
|
|
86
|
+
connectionId,
|
|
87
|
+
});
|
|
88
|
+
this.transportTable.set(socketId, socket);
|
|
89
|
+
this.listenOnWebSocketMessages(socket);
|
|
90
|
+
}
|
|
91
|
+
if (socket.readyState !== this.WebSocketClass.OPEN) {
|
|
92
|
+
throw new core_1.CredoError('Socket is not open.');
|
|
93
|
+
}
|
|
94
|
+
return socket;
|
|
95
|
+
}
|
|
96
|
+
listenOnWebSocketMessages(socket) {
|
|
97
|
+
socket.addEventListener('message', this.handleMessageEvent);
|
|
98
|
+
}
|
|
99
|
+
createSocketConnection({ socketId, endpoint, connectionId, }) {
|
|
100
|
+
return new Promise((resolve, reject) => {
|
|
101
|
+
this.logger.debug(`Connecting to WebSocket ${endpoint}`);
|
|
102
|
+
const socket = new this.WebSocketClass(endpoint);
|
|
103
|
+
socket.onopen = () => {
|
|
104
|
+
this.logger.debug(`Successfully connected to WebSocket ${endpoint}`);
|
|
105
|
+
resolve(socket);
|
|
106
|
+
};
|
|
107
|
+
socket.onerror = error => {
|
|
108
|
+
this.logger.debug(`Error while connecting to WebSocket ${endpoint}`, {
|
|
109
|
+
error,
|
|
110
|
+
});
|
|
111
|
+
reject(error);
|
|
112
|
+
};
|
|
113
|
+
socket.onclose = async () => {
|
|
114
|
+
this.logger.debug(`WebSocket closing to ${endpoint}`);
|
|
115
|
+
socket.removeEventListener('message', this.handleMessageEvent);
|
|
116
|
+
this.transportTable.delete(socketId);
|
|
117
|
+
this.eventEmitter.emit(this.agentContext, {
|
|
118
|
+
type: didcomm_1.DidCommTransportEventTypes.DidCommOutboundWebSocketClosedEvent,
|
|
119
|
+
payload: {
|
|
120
|
+
socketId,
|
|
121
|
+
connectionId: connectionId,
|
|
122
|
+
},
|
|
123
|
+
});
|
|
124
|
+
};
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
exports.VsAgentWsOutboundTransport = VsAgentWsOutboundTransport;
|
|
129
|
+
//# sourceMappingURL=VsAgentWsOutboundTransport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VsAgentWsOutboundTransport.js","sourceRoot":"","sources":["../../src/transports/VsAgentWsOutboundTransport.ts"],"names":[],"mappings":";;;AAaA,8CAGC;AAdD,yCAAyG;AACzG,+CAQ0B;AAE1B,SAAgB,iBAAiB,CAAC,GAAW;IAC3C,MAAM,CAAC,cAAc,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IACvC,OAAO,cAAc,CAAA;AACvB,CAAC;AAMD,MAAa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CAAA;QACH,CAAC,CAAC,CAAA;IACJ,CAAC;CACF;AA5JD,gEA4JC"}
|
package/build/types.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { IBaseMessage, MessageType } from '@verana-labs/vs-agent-model';
|
|
2
|
+
import { BaseLogger } from '@credo-ts/core';
|
|
3
|
+
import { DidCommConnectionRecord } from '@credo-ts/didcomm';
|
|
4
|
+
import { BaseAgentModules, VsAgent } from './agent/VsAgent';
|
|
5
|
+
export declare const MESSAGE_HANDLERS = "MESSAGE_HANDLERS";
|
|
6
|
+
export interface VsAgentPluginConfig {
|
|
7
|
+
logger: BaseLogger;
|
|
8
|
+
webhookUrl?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface MessageHandler {
|
|
11
|
+
readonly supportedTypes: MessageType[];
|
|
12
|
+
readonly openApiExamples: Record<string, {
|
|
13
|
+
summary: string;
|
|
14
|
+
description: string;
|
|
15
|
+
value: object;
|
|
16
|
+
}>;
|
|
17
|
+
handle(agent: VsAgent<any>, message: IBaseMessage, connection: DidCommConnectionRecord): Promise<string | undefined>;
|
|
18
|
+
}
|
|
19
|
+
export type Plugin = {
|
|
20
|
+
modules: Record<string, unknown>;
|
|
21
|
+
};
|
|
22
|
+
export interface VsAgentNestPlugin {
|
|
23
|
+
name: string;
|
|
24
|
+
credoPlugin?: Plugin;
|
|
25
|
+
controllers?: (new (...args: any[]) => any)[];
|
|
26
|
+
providers?: any[];
|
|
27
|
+
messageHandlers?: (new (...args: any[]) => MessageHandler)[];
|
|
28
|
+
imports?: any[];
|
|
29
|
+
registerEvents?: (agent: VsAgent<BaseAgentModules>, config: VsAgentPluginConfig) => void;
|
|
30
|
+
}
|
package/build/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAOa,QAAA,gBAAgB,GAAG,kBAAkB,CAAA"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { DidCommMessage } from '@credo-ts/didcomm';
|
|
2
|
+
import { VsAgent } from '../agent/VsAgent';
|
|
3
|
+
/**
|
|
4
|
+
* Creates an out of band invitation that will equal to the public DID in case the agent has one defined,
|
|
5
|
+
* and a new one every time in case the agent does not have any public DID.
|
|
6
|
+
*
|
|
7
|
+
* @param agent
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
export declare function createInvitation(options: {
|
|
11
|
+
agent: VsAgent;
|
|
12
|
+
messages?: DidCommMessage[];
|
|
13
|
+
useLegacyDid?: boolean;
|
|
14
|
+
invitationBaseUrl: string;
|
|
15
|
+
imageUrl?: string;
|
|
16
|
+
}): Promise<{
|
|
17
|
+
url: string;
|
|
18
|
+
}>;
|
|
19
|
+
export declare function getRecordId(agent: VsAgent, id: string): Promise<string>;
|
|
20
|
+
export declare function getWebDid(agent: VsAgent): Promise<string | undefined>;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createInvitation = createInvitation;
|
|
4
|
+
exports.getRecordId = getRecordId;
|
|
5
|
+
exports.getWebDid = getWebDid;
|
|
6
|
+
const core_1 = require("@credo-ts/core");
|
|
7
|
+
const didcomm_1 = require("@credo-ts/didcomm");
|
|
8
|
+
/**
|
|
9
|
+
* Creates an out of band invitation that will equal to the public DID in case the agent has one defined,
|
|
10
|
+
* and a new one every time in case the agent does not have any public DID.
|
|
11
|
+
*
|
|
12
|
+
* @param agent
|
|
13
|
+
* @returns
|
|
14
|
+
*/
|
|
15
|
+
async function createInvitation(options) {
|
|
16
|
+
const { agent, messages, useLegacyDid, invitationBaseUrl, imageUrl } = options;
|
|
17
|
+
// Use legacy did:web in case agent's did is webvh and using legacy did
|
|
18
|
+
const invitationDid = agent.did && (0, core_1.parseDid)(agent.did).method === 'webvh' && useLegacyDid
|
|
19
|
+
? `did:web:${(0, core_1.parseDid)(agent.did).id.split(':')[1]}`
|
|
20
|
+
: agent.did;
|
|
21
|
+
const outOfBandInvitation = (await agent.didcomm.oob.createInvitation({
|
|
22
|
+
label: agent.label,
|
|
23
|
+
handshakeProtocols: [didcomm_1.DidCommHandshakeProtocol.DidExchange, didcomm_1.DidCommHandshakeProtocol.Connections],
|
|
24
|
+
invitationDid,
|
|
25
|
+
multiUseInvitation: !messages,
|
|
26
|
+
imageUrl,
|
|
27
|
+
messages,
|
|
28
|
+
})).outOfBandInvitation;
|
|
29
|
+
return {
|
|
30
|
+
url: outOfBandInvitation.toUrl({
|
|
31
|
+
domain: invitationBaseUrl,
|
|
32
|
+
}),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
async function getRecordId(agent, id) {
|
|
36
|
+
var _a;
|
|
37
|
+
const record = await agent.genericRecords.findById(id);
|
|
38
|
+
return (_a = record === null || record === void 0 ? void 0 : record.getTag('messageId')) !== null && _a !== void 0 ? _a : id;
|
|
39
|
+
}
|
|
40
|
+
async function getWebDid(agent) {
|
|
41
|
+
if (agent.did) {
|
|
42
|
+
const parsedDid = (0, core_1.parseDid)(agent.did);
|
|
43
|
+
if (parsedDid.method === 'web')
|
|
44
|
+
return agent.did;
|
|
45
|
+
if (parsedDid.method === 'webvh')
|
|
46
|
+
return `did:web:${parsedDid.id.split(':')[1]}`;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=agent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent.js","sourceRoot":"","sources":["../../src/utils/agent.ts"],"names":[],"mappings":";;AAYA,4CA8BC;AAED,kCAGC;AAED,8BAOC;AAxDD,yCAAyC;AACzC,+CAA4E;AAI5E;;;;;;GAMG;AACI,KAAK,UAAU,gBAAgB,CAAC,OAMtC;IACC,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,iBAAiB,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAA;IAE9E,uEAAuE;IACvE,MAAM,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