@credo-ts/node 0.6.0-alpha-20251204143549 → 0.6.0-alpha-20260304224601
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/build/NodeFileSystem.d.ts +28 -0
- package/build/NodeFileSystem.js +117 -0
- package/build/NodeFileSystem.js.map +1 -0
- package/build/index.d.ts +5 -0
- package/build/index.js +18 -0
- package/build/index.js.map +1 -0
- package/build/transport/HttpInboundTransport.d.ts +28 -0
- package/build/transport/HttpInboundTransport.js +129 -0
- package/build/transport/HttpInboundTransport.js.map +1 -0
- package/build/transport/WsInboundTransport.d.ts +26 -0
- package/build/transport/WsInboundTransport.js +121 -0
- package/build/transport/WsInboundTransport.js.map +1 -0
- package/package.json +18 -22
- package/build/NodeFileSystem.mjs +0 -86
- package/build/NodeFileSystem.mjs.map +0 -1
- package/build/_virtual/_@oxc-project_runtime@0.99.0/helpers/assertClassBrand.mjs +0 -8
- package/build/_virtual/_@oxc-project_runtime@0.99.0/helpers/checkPrivateRedeclaration.mjs +0 -7
- package/build/_virtual/_@oxc-project_runtime@0.99.0/helpers/classPrivateFieldGet2.mjs +0 -9
- package/build/_virtual/_@oxc-project_runtime@0.99.0/helpers/classPrivateFieldInitSpec.mjs +0 -9
- package/build/_virtual/_@oxc-project_runtime@0.99.0/helpers/classPrivateFieldSet2.mjs +0 -9
- package/build/index.d.mts +0 -12
- package/build/index.d.mts.map +0 -1
- package/build/index.mjs +0 -19
- package/build/index.mjs.map +0 -1
- package/build/kms/NodeInMemoryKeyManagementStorage.d.mts +0 -81
- package/build/kms/NodeInMemoryKeyManagementStorage.d.mts.map +0 -1
- package/build/kms/NodeInMemoryKeyManagementStorage.mjs +0 -34
- package/build/kms/NodeInMemoryKeyManagementStorage.mjs.map +0 -1
- package/build/kms/NodeKeyManagementService.d.mts +0 -24
- package/build/kms/NodeKeyManagementService.d.mts.map +0 -1
- package/build/kms/NodeKeyManagementService.mjs +0 -279
- package/build/kms/NodeKeyManagementService.mjs.map +0 -1
- package/build/kms/NodeKeyManagementStorage.d.mts +0 -15
- package/build/kms/NodeKeyManagementStorage.d.mts.map +0 -1
- package/build/kms/crypto/createKey.mjs +0 -59
- package/build/kms/crypto/createKey.mjs.map +0 -1
- package/build/kms/crypto/decrypt.mjs +0 -68
- package/build/kms/crypto/decrypt.mjs.map +0 -1
- package/build/kms/crypto/deriveKey.mjs +0 -159
- package/build/kms/crypto/deriveKey.mjs.map +0 -1
- package/build/kms/crypto/encrypt.mjs +0 -98
- package/build/kms/crypto/encrypt.mjs.map +0 -1
- package/build/kms/crypto/sign.mjs +0 -65
- package/build/kms/crypto/sign.mjs.map +0 -1
- package/build/kms/crypto/verify.mjs +0 -30
- package/build/kms/crypto/verify.mjs.map +0 -1
- package/build/transport/DidCommHttpInboundTransport.d.mts +0 -31
- package/build/transport/DidCommHttpInboundTransport.d.mts.map +0 -1
- package/build/transport/DidCommHttpInboundTransport.mjs +0 -83
- package/build/transport/DidCommHttpInboundTransport.mjs.map +0 -1
- package/build/transport/DidCommWsInboundTransport.d.mts +0 -26
- package/build/transport/DidCommWsInboundTransport.d.mts.map +0 -1
- package/build/transport/DidCommWsInboundTransport.mjs +0 -82
- package/build/transport/DidCommWsInboundTransport.mjs.map +0 -1
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { DownloadToFileOptions, FileSystem } from '@credo-ts/core';
|
|
2
|
+
export declare class NodeFileSystem implements FileSystem {
|
|
3
|
+
readonly dataPath: string;
|
|
4
|
+
readonly cachePath: string;
|
|
5
|
+
readonly tempPath: string;
|
|
6
|
+
/**
|
|
7
|
+
* Create new NodeFileSystem class instance.
|
|
8
|
+
*
|
|
9
|
+
* @param baseDataPath The base path to use for reading and writing data files used within the framework.
|
|
10
|
+
* Files will be created under baseDataPath/.afj directory. If not specified, it will be set to homedir()
|
|
11
|
+
* @param baseCachePath The base path to use for reading and writing cache files used within the framework.
|
|
12
|
+
* Files will be created under baseCachePath/.afj directory. If not specified, it will be set to homedir()
|
|
13
|
+
* @param baseTempPath The base path to use for reading and writing temporary files within the framework.
|
|
14
|
+
* Files will be created under baseTempPath/.afj directory. If not specified, it will be set to tmpdir()
|
|
15
|
+
*/
|
|
16
|
+
constructor(options?: {
|
|
17
|
+
baseDataPath?: string;
|
|
18
|
+
baseCachePath?: string;
|
|
19
|
+
baseTempPath?: string;
|
|
20
|
+
});
|
|
21
|
+
exists(path: string): Promise<boolean>;
|
|
22
|
+
createDirectory(path: string): Promise<void>;
|
|
23
|
+
copyFile(sourcePath: string, destinationPath: string): Promise<void>;
|
|
24
|
+
write(path: string, data: string): Promise<void>;
|
|
25
|
+
read(path: string): Promise<string>;
|
|
26
|
+
delete(path: string): Promise<void>;
|
|
27
|
+
downloadToFile(url: string, path: string, options: DownloadToFileOptions): Promise<void>;
|
|
28
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
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 (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.NodeFileSystem = void 0;
|
|
30
|
+
const core_1 = require("@credo-ts/core");
|
|
31
|
+
const crypto_1 = require("crypto");
|
|
32
|
+
const fs_1 = __importStar(require("fs"));
|
|
33
|
+
const http_1 = __importDefault(require("http"));
|
|
34
|
+
const https_1 = __importDefault(require("https"));
|
|
35
|
+
const os_1 = require("os");
|
|
36
|
+
const path_1 = require("path");
|
|
37
|
+
const { access, readFile, writeFile, mkdir, rm, unlink, copyFile } = fs_1.promises;
|
|
38
|
+
class NodeFileSystem {
|
|
39
|
+
/**
|
|
40
|
+
* Create new NodeFileSystem class instance.
|
|
41
|
+
*
|
|
42
|
+
* @param baseDataPath The base path to use for reading and writing data files used within the framework.
|
|
43
|
+
* Files will be created under baseDataPath/.afj directory. If not specified, it will be set to homedir()
|
|
44
|
+
* @param baseCachePath The base path to use for reading and writing cache files used within the framework.
|
|
45
|
+
* Files will be created under baseCachePath/.afj directory. If not specified, it will be set to homedir()
|
|
46
|
+
* @param baseTempPath The base path to use for reading and writing temporary files within the framework.
|
|
47
|
+
* Files will be created under baseTempPath/.afj directory. If not specified, it will be set to tmpdir()
|
|
48
|
+
*/
|
|
49
|
+
constructor(options) {
|
|
50
|
+
this.dataPath = options?.baseDataPath ? `${options?.baseDataPath}/.afj` : `${(0, os_1.homedir)()}/.afj/data`;
|
|
51
|
+
this.cachePath = options?.baseCachePath ? `${options?.baseCachePath}/.afj` : `${(0, os_1.homedir)()}/.afj/cache`;
|
|
52
|
+
this.tempPath = `${options?.baseTempPath ?? (0, os_1.tmpdir)()}/.afj`;
|
|
53
|
+
}
|
|
54
|
+
async exists(path) {
|
|
55
|
+
try {
|
|
56
|
+
await access(path);
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
async createDirectory(path) {
|
|
64
|
+
await mkdir((0, path_1.dirname)(path), { recursive: true });
|
|
65
|
+
}
|
|
66
|
+
async copyFile(sourcePath, destinationPath) {
|
|
67
|
+
await copyFile(sourcePath, destinationPath);
|
|
68
|
+
}
|
|
69
|
+
async write(path, data) {
|
|
70
|
+
// Make sure parent directories exist
|
|
71
|
+
await mkdir((0, path_1.dirname)(path), { recursive: true });
|
|
72
|
+
return writeFile(path, data, { encoding: 'utf-8' });
|
|
73
|
+
}
|
|
74
|
+
async read(path) {
|
|
75
|
+
return readFile(path, { encoding: 'utf-8' });
|
|
76
|
+
}
|
|
77
|
+
async delete(path) {
|
|
78
|
+
await rm(path, { recursive: true, force: true });
|
|
79
|
+
}
|
|
80
|
+
async downloadToFile(url, path, options) {
|
|
81
|
+
const httpMethod = url.startsWith('https') ? https_1.default : http_1.default;
|
|
82
|
+
// Make sure parent directories exist
|
|
83
|
+
await mkdir((0, path_1.dirname)(path), { recursive: true });
|
|
84
|
+
const file = fs_1.default.createWriteStream(path);
|
|
85
|
+
const hash = options.verifyHash ? (0, crypto_1.createHash)('sha256') : undefined;
|
|
86
|
+
return new Promise((resolve, reject) => {
|
|
87
|
+
httpMethod
|
|
88
|
+
.get(url, (response) => {
|
|
89
|
+
// check if response is success
|
|
90
|
+
if (response.statusCode !== 200) {
|
|
91
|
+
reject(`Unable to download file from url: ${url}. Response status was ${response.statusCode}`);
|
|
92
|
+
}
|
|
93
|
+
hash && response.pipe(hash);
|
|
94
|
+
response.pipe(file);
|
|
95
|
+
file.on('finish', async () => {
|
|
96
|
+
file.close();
|
|
97
|
+
if (hash && options.verifyHash?.hash) {
|
|
98
|
+
hash.end();
|
|
99
|
+
const digest = hash.digest();
|
|
100
|
+
if (digest.compare(options.verifyHash.hash) !== 0) {
|
|
101
|
+
await fs_1.default.promises.unlink(path);
|
|
102
|
+
reject(new core_1.CredoError(`Hash of downloaded file does not match expected hash. Expected: ${options.verifyHash.hash}, Actual: ${core_1.TypedArrayEncoder.toUtf8String(digest)})}`));
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
resolve();
|
|
106
|
+
});
|
|
107
|
+
})
|
|
108
|
+
.on('error', async (error) => {
|
|
109
|
+
// Handle errors
|
|
110
|
+
await unlink(path); // Delete the file async. (But we don't check the result)
|
|
111
|
+
reject(`Unable to download file from url: ${url}. ${error.message}`);
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
exports.NodeFileSystem = NodeFileSystem;
|
|
117
|
+
//# sourceMappingURL=NodeFileSystem.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NodeFileSystem.js","sourceRoot":"","sources":["../src/NodeFileSystem.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,yCAA8D;AAC9D,mCAAmC;AACnC,yCAAiC;AACjC,gDAAuB;AACvB,kDAAyB;AACzB,2BAAoC;AACpC,+BAA8B;AAE9B,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,aAAQ,CAAA;AAE7E,MAAa,cAAc;IAKzB;;;;;;;;;OASG;IACH,YAAmB,OAAkF;QACnG,IAAI,CAAC,QAAQ,GAAG,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,OAAO,EAAE,YAAY,OAAO,CAAC,CAAC,CAAC,GAAG,IAAA,YAAO,GAAE,YAAY,CAAA;QAClG,IAAI,CAAC,SAAS,GAAG,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,OAAO,EAAE,aAA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,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;4BAE9B,MAAM,CACJ,IAAI,iBAAU,CACZ,mEACE,OAAO,CAAC,UAAU,CAAC,IACrB,aAAa,wBAAiB,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,CACxD,CACF,CAAA;wBACH,CAAC;oBACH,CAAC;oBACD,OAAO,EAAE,CAAA;gBACX,CAAC,CAAC,CAAA;YACJ,CAAC,CAAC;iBACD,EAAE,CAAC,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE;gBAC3B,gBAAgB;gBAChB,MAAM,MAAM,CAAC,IAAI,CAAC,CAAA,CAAC,yDAAyD;gBAC5E,MAAM,CAAC,qCAAqC,GAAG,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC,CAAA;YACtE,CAAC,CAAC,CAAA;QACN,CAAC,CAAC,CAAA;IACJ,CAAC;CACF;AApGD,wCAoGC"}
|
package/build/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { AgentDependencies } from '@credo-ts/core';
|
|
2
|
+
import { HttpInboundTransport } from './transport/HttpInboundTransport';
|
|
3
|
+
import { WsInboundTransport } from './transport/WsInboundTransport';
|
|
4
|
+
declare const agentDependencies: AgentDependencies;
|
|
5
|
+
export { agentDependencies, HttpInboundTransport, WsInboundTransport };
|
package/build/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WsInboundTransport = exports.HttpInboundTransport = exports.agentDependencies = void 0;
|
|
4
|
+
const events_1 = require("events");
|
|
5
|
+
const ws_1 = require("ws");
|
|
6
|
+
const NodeFileSystem_1 = require("./NodeFileSystem");
|
|
7
|
+
const HttpInboundTransport_1 = require("./transport/HttpInboundTransport");
|
|
8
|
+
Object.defineProperty(exports, "HttpInboundTransport", { enumerable: true, get: function () { return HttpInboundTransport_1.HttpInboundTransport; } });
|
|
9
|
+
const WsInboundTransport_1 = require("./transport/WsInboundTransport");
|
|
10
|
+
Object.defineProperty(exports, "WsInboundTransport", { enumerable: true, get: function () { return WsInboundTransport_1.WsInboundTransport; } });
|
|
11
|
+
const agentDependencies = {
|
|
12
|
+
FileSystem: NodeFileSystem_1.NodeFileSystem,
|
|
13
|
+
fetch,
|
|
14
|
+
EventEmitterClass: events_1.EventEmitter,
|
|
15
|
+
WebSocketClass: ws_1.WebSocket,
|
|
16
|
+
};
|
|
17
|
+
exports.agentDependencies = agentDependencies;
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAEA,mCAAqC;AACrC,2BAA8B;AAE9B,qDAAiD;AACjD,2EAAuE;AAU3C,qGAVnB,2CAAoB,OAUmB;AAThD,uEAAmE;AASjB,mGATzC,uCAAkB,OASyC;AAPpE,MAAM,iBAAiB,GAAsB;IAC3C,UAAU,EAAE,+BAAc;IAC1B,KAAK;IACL,iBAAiB,EAAE,qBAAY;IAC/B,cAAc,EAAE,cAAS;CAC1B,CAAA;AAEQ,8CAAiB"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { InboundTransport, Agent, TransportSession, EncryptedMessage, AgentContext } from '@credo-ts/core';
|
|
2
|
+
import type { Express, Request, Response } from 'express';
|
|
3
|
+
import type { Server } from 'http';
|
|
4
|
+
export declare class HttpInboundTransport implements InboundTransport {
|
|
5
|
+
readonly app: Express;
|
|
6
|
+
private port;
|
|
7
|
+
private path;
|
|
8
|
+
private _server?;
|
|
9
|
+
private processedMessageListenerTimeoutMs;
|
|
10
|
+
get server(): Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse> | undefined;
|
|
11
|
+
constructor({ app, path, port, processedMessageListenerTimeoutMs, }: {
|
|
12
|
+
app?: Express;
|
|
13
|
+
path?: string;
|
|
14
|
+
port: number;
|
|
15
|
+
processedMessageListenerTimeoutMs?: number;
|
|
16
|
+
});
|
|
17
|
+
start(agent: Agent): Promise<void>;
|
|
18
|
+
stop(): Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
export declare class HttpTransportSession implements TransportSession {
|
|
21
|
+
id: string;
|
|
22
|
+
readonly type = "http";
|
|
23
|
+
req: Request;
|
|
24
|
+
res: Response;
|
|
25
|
+
constructor(id: string, req: Request, res: Response);
|
|
26
|
+
close(): Promise<void>;
|
|
27
|
+
send(agentContext: AgentContext, encryptedMessage: EncryptedMessage): Promise<void>;
|
|
28
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
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 (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.HttpTransportSession = exports.HttpInboundTransport = void 0;
|
|
27
|
+
const core_1 = require("@credo-ts/core");
|
|
28
|
+
const express_1 = __importStar(require("express"));
|
|
29
|
+
const rxjs_1 = require("rxjs");
|
|
30
|
+
const supportedContentTypes = [core_1.DidCommMimeType.V0, core_1.DidCommMimeType.V1];
|
|
31
|
+
class HttpInboundTransport {
|
|
32
|
+
get server() {
|
|
33
|
+
return this._server;
|
|
34
|
+
}
|
|
35
|
+
constructor({ app, path, port, processedMessageListenerTimeoutMs, }) {
|
|
36
|
+
this.port = port;
|
|
37
|
+
this.processedMessageListenerTimeoutMs = processedMessageListenerTimeoutMs ?? 10000; // timeout after 10 seconds
|
|
38
|
+
// Create Express App
|
|
39
|
+
this.app = app ?? (0, express_1.default)();
|
|
40
|
+
this.path = path ?? '/';
|
|
41
|
+
this.app.use((0, express_1.text)({ type: supportedContentTypes, limit: '5mb' }));
|
|
42
|
+
}
|
|
43
|
+
async start(agent) {
|
|
44
|
+
const transportService = agent.dependencyManager.resolve(core_1.TransportService);
|
|
45
|
+
agent.config.logger.debug(`Starting HTTP inbound transport`, {
|
|
46
|
+
port: this.port,
|
|
47
|
+
});
|
|
48
|
+
this.app.post(this.path, async (req, res) => {
|
|
49
|
+
const contentType = req.headers['content-type'];
|
|
50
|
+
if (!contentType || !supportedContentTypes.includes(contentType)) {
|
|
51
|
+
return res
|
|
52
|
+
.status(415)
|
|
53
|
+
.send('Unsupported content-type. Supported content-types are: ' + supportedContentTypes.join(', '));
|
|
54
|
+
}
|
|
55
|
+
const session = new HttpTransportSession(core_1.utils.uuid(), req, res);
|
|
56
|
+
// We want to make sure the session is removed if the connection is closed, as it
|
|
57
|
+
// can't be used anymore then. This could happen if the client abruptly closes the connection.
|
|
58
|
+
req.once('close', () => transportService.removeSession(session));
|
|
59
|
+
try {
|
|
60
|
+
const message = req.body;
|
|
61
|
+
const encryptedMessage = JSON.parse(message);
|
|
62
|
+
const observable = agent.events.observable(core_1.AgentEventTypes.AgentMessageProcessed);
|
|
63
|
+
const subject = new rxjs_1.ReplaySubject(1);
|
|
64
|
+
observable
|
|
65
|
+
.pipe((0, rxjs_1.filter)((e) => e.type === core_1.AgentEventTypes.AgentMessageProcessed), (0, rxjs_1.filter)((e) => e.payload.encryptedMessage === encryptedMessage), (0, rxjs_1.timeout)({
|
|
66
|
+
first: this.processedMessageListenerTimeoutMs,
|
|
67
|
+
meta: 'HttpInboundTransport.start',
|
|
68
|
+
}), (0, rxjs_1.take)(1))
|
|
69
|
+
.subscribe(subject);
|
|
70
|
+
agent.events.emit(agent.context, {
|
|
71
|
+
type: core_1.AgentEventTypes.AgentMessageReceived,
|
|
72
|
+
payload: {
|
|
73
|
+
message: encryptedMessage,
|
|
74
|
+
session: session,
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
// Wait for message to be processed
|
|
78
|
+
await (0, rxjs_1.firstValueFrom)(subject);
|
|
79
|
+
// If agent did not use session when processing message we need to send response here.
|
|
80
|
+
if (!res.headersSent) {
|
|
81
|
+
res.status(200).end();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
agent.config.logger.error(`Error processing inbound message: ${error.message}`, error);
|
|
86
|
+
if (!res.headersSent) {
|
|
87
|
+
res.status(500).send('Error processing message');
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
finally {
|
|
91
|
+
transportService.removeSession(session);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
this._server = this.app.listen(this.port);
|
|
95
|
+
}
|
|
96
|
+
async stop() {
|
|
97
|
+
return new Promise((resolve, reject) => this._server?.close((err) => (err ? reject(err) : resolve())));
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
exports.HttpInboundTransport = HttpInboundTransport;
|
|
101
|
+
class HttpTransportSession {
|
|
102
|
+
constructor(id, req, res) {
|
|
103
|
+
this.type = 'http';
|
|
104
|
+
this.id = id;
|
|
105
|
+
this.req = req;
|
|
106
|
+
this.res = res;
|
|
107
|
+
}
|
|
108
|
+
async close() {
|
|
109
|
+
if (!this.res.headersSent) {
|
|
110
|
+
this.res.status(200).end();
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
async send(agentContext, encryptedMessage) {
|
|
114
|
+
if (this.res.headersSent) {
|
|
115
|
+
throw new core_1.CredoError(`${this.type} transport session has been closed.`);
|
|
116
|
+
}
|
|
117
|
+
// By default we take the agent config's default DIDComm content-type
|
|
118
|
+
let responseMimeType = agentContext.config.didCommMimeType;
|
|
119
|
+
// However, if the request mime-type is a mime-type that is supported by us, we use that
|
|
120
|
+
// to minimize the chance of interoperability issues
|
|
121
|
+
const requestMimeType = this.req.headers['content-type'];
|
|
122
|
+
if (requestMimeType && supportedContentTypes.includes(requestMimeType)) {
|
|
123
|
+
responseMimeType = requestMimeType;
|
|
124
|
+
}
|
|
125
|
+
this.res.status(200).contentType(responseMimeType).json(encryptedMessage).end();
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
exports.HttpTransportSession = HttpTransportSession;
|
|
129
|
+
//# sourceMappingURL=HttpInboundTransport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HttpInboundTransport.js","sourceRoot":"","sources":["../../src/transport/HttpInboundTransport.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAYA,yCAAsG;AACtG,mDAAuC;AACvC,+BAA2E;AAE3E,MAAM,qBAAqB,GAAa,CAAC,sBAAe,CAAC,EAAE,EAAE,sBAAe,CAAC,EAAE,CAAC,CAAA;AAEhF,MAAa,oBAAoB;IAO/B,IAAW,MAAM;QACf,OAAO,IAAI,CAAC,OAAO,CAAA;IACrB,CAAC;IAED,YAAmB,EACjB,GAAG,EACH,IAAI,EACJ,IAAI,EACJ,iCAAiC,GAMlC;QACC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,iCAAiC,GAAG,iCAAiC,IAA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AE,CAAC;YACzB,MAAM,IAAI,iBAAU,CAAC,GAAG,IAAI,CAAC,IAAI,qCAAqC,CAAC,CAAA;QACzE,CAAC;QAED,qEAAqE;QACrE,IAAI,gBAAgB,GAAG,YAAY,CAAC,MAAM,CAAC,eAAyB,CAAA;QAEpE,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,26 @@
|
|
|
1
|
+
import type { Agent, InboundTransport, Logger, TransportSession, EncryptedMessage, AgentContext } from '@credo-ts/core';
|
|
2
|
+
import WebSocket, { Server } from 'ws';
|
|
3
|
+
export declare class WsInboundTransport implements InboundTransport {
|
|
4
|
+
private socketServer;
|
|
5
|
+
private logger;
|
|
6
|
+
private socketIds;
|
|
7
|
+
constructor({ server, port }: {
|
|
8
|
+
server: Server;
|
|
9
|
+
port?: undefined;
|
|
10
|
+
} | {
|
|
11
|
+
server?: undefined;
|
|
12
|
+
port: number;
|
|
13
|
+
});
|
|
14
|
+
start(agent: Agent): Promise<void>;
|
|
15
|
+
stop(): Promise<void>;
|
|
16
|
+
private listenOnWebSocketMessages;
|
|
17
|
+
}
|
|
18
|
+
export declare class WebSocketTransportSession implements TransportSession {
|
|
19
|
+
id: string;
|
|
20
|
+
readonly type = "WebSocket";
|
|
21
|
+
socket: WebSocket;
|
|
22
|
+
private logger;
|
|
23
|
+
constructor(id: string, socket: WebSocket, logger: Logger);
|
|
24
|
+
send(agentContext: AgentContext, encryptedMessage: EncryptedMessage): Promise<void>;
|
|
25
|
+
close(): Promise<void>;
|
|
26
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
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 (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.WebSocketTransportSession = exports.WsInboundTransport = void 0;
|
|
27
|
+
const core_1 = require("@credo-ts/core");
|
|
28
|
+
// eslint-disable-next-line import/no-named-as-default
|
|
29
|
+
const ws_1 = __importStar(require("ws"));
|
|
30
|
+
class WsInboundTransport {
|
|
31
|
+
constructor({ server, port }) {
|
|
32
|
+
// We're using a `socketId` just for the prevention of calling the connection handler twice.
|
|
33
|
+
this.socketIds = {};
|
|
34
|
+
this.socketServer = server ?? new ws_1.Server({ port });
|
|
35
|
+
}
|
|
36
|
+
async start(agent) {
|
|
37
|
+
const transportService = agent.dependencyManager.resolve(core_1.TransportService);
|
|
38
|
+
this.logger = agent.config.logger;
|
|
39
|
+
const wsEndpoint = agent.config.endpoints.find((e) => e.startsWith('ws'));
|
|
40
|
+
this.logger.debug(`Starting WS inbound transport`, {
|
|
41
|
+
endpoint: wsEndpoint,
|
|
42
|
+
});
|
|
43
|
+
this.socketServer.on('connection', (socket) => {
|
|
44
|
+
const socketId = core_1.utils.uuid();
|
|
45
|
+
this.logger.debug('Socket connected.');
|
|
46
|
+
if (!this.socketIds[socketId]) {
|
|
47
|
+
this.logger.debug(`Saving new socket with id ${socketId}.`);
|
|
48
|
+
this.socketIds[socketId] = socket;
|
|
49
|
+
const session = new WebSocketTransportSession(socketId, socket, this.logger);
|
|
50
|
+
this.listenOnWebSocketMessages(agent, socket, session);
|
|
51
|
+
socket.on('close', () => {
|
|
52
|
+
this.logger.debug('Socket closed.');
|
|
53
|
+
transportService.removeSession(session);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
this.logger.debug(`Socket with id ${socketId} already exists.`);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
async stop() {
|
|
62
|
+
this.logger.debug('Closing WebSocket Server');
|
|
63
|
+
return new Promise((resolve, reject) => {
|
|
64
|
+
this.socketServer.close((error) => {
|
|
65
|
+
if (error) {
|
|
66
|
+
reject(error);
|
|
67
|
+
}
|
|
68
|
+
resolve();
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
listenOnWebSocketMessages(agent, socket, session) {
|
|
73
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
74
|
+
socket.addEventListener('message', async (event) => {
|
|
75
|
+
this.logger.debug('WebSocket message event received.', { url: event.target.url });
|
|
76
|
+
try {
|
|
77
|
+
const encryptedMessage = JSON.parse(event.data);
|
|
78
|
+
agent.events.emit(agent.context, {
|
|
79
|
+
type: core_1.AgentEventTypes.AgentMessageReceived,
|
|
80
|
+
payload: {
|
|
81
|
+
message: encryptedMessage,
|
|
82
|
+
session: session,
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
this.logger.error(`Error processing message: ${error}`);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
exports.WsInboundTransport = WsInboundTransport;
|
|
93
|
+
class WebSocketTransportSession {
|
|
94
|
+
constructor(id, socket, logger) {
|
|
95
|
+
this.type = 'WebSocket';
|
|
96
|
+
this.id = id;
|
|
97
|
+
this.socket = socket;
|
|
98
|
+
this.logger = logger;
|
|
99
|
+
}
|
|
100
|
+
async send(agentContext, encryptedMessage) {
|
|
101
|
+
if (this.socket.readyState !== ws_1.default.OPEN) {
|
|
102
|
+
throw new core_1.CredoError(`${this.type} transport session has been closed.`);
|
|
103
|
+
}
|
|
104
|
+
this.socket.send(JSON.stringify(encryptedMessage), (error) => {
|
|
105
|
+
if (error != undefined) {
|
|
106
|
+
this.logger.debug(`Error sending message: ${error}`);
|
|
107
|
+
throw new core_1.CredoError(`${this.type} send message failed.`, { cause: error });
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
this.logger.debug(`${this.type} sent message successfully.`);
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
async close() {
|
|
115
|
+
if (this.socket.readyState === ws_1.default.OPEN) {
|
|
116
|
+
this.socket.close();
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
exports.WebSocketTransportSession = WebSocketTransportSession;
|
|
121
|
+
//# sourceMappingURL=WsInboundTransport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WsInboundTransport.js","sourceRoot":"","sources":["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AC,KAAK,CAAC,GAAG,IAAI,CAAC,IAAI,6BAA6B,CAAC,CAAA;YAC9D,CAAC;QACH,CAAC,CAAC,CAAA;IACJ,CAAC;IAEM,KAAK,CAAC,KAAK;QAChB,IAAI,IAAI,CAAC,MAAM,CAAC,UAAU,KAAK,YAAS,CAAC,IAAI,EAAE,CAAC;YAC9C,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAA;QACrB,CAAC;IACH,CAAC;CACF;AA/BD,8DA+BC"}
|
package/package.json
CHANGED
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@credo-ts/node",
|
|
3
|
-
"
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
},
|
|
7
|
-
"version": "0.6.0-alpha-20251204143549",
|
|
3
|
+
"main": "build/index",
|
|
4
|
+
"types": "build/index",
|
|
5
|
+
"version": "0.6.0-alpha-20260304224601",
|
|
8
6
|
"files": [
|
|
9
7
|
"build"
|
|
10
8
|
],
|
|
11
9
|
"license": "Apache-2.0",
|
|
12
|
-
"engines": {
|
|
13
|
-
"node": ">=20.19"
|
|
14
|
-
},
|
|
15
10
|
"publishConfig": {
|
|
16
11
|
"access": "public"
|
|
17
12
|
},
|
|
@@ -24,22 +19,23 @@
|
|
|
24
19
|
"dependencies": {
|
|
25
20
|
"@2060.io/ffi-napi": "^4.0.9",
|
|
26
21
|
"@2060.io/ref-napi": "^3.0.6",
|
|
27
|
-
"@types/express": "^
|
|
28
|
-
"express": "^
|
|
29
|
-
"rxjs": "^7.8.
|
|
30
|
-
"ws": "^8.
|
|
31
|
-
"@credo-ts/core": "0.6.0-alpha-
|
|
32
|
-
"@credo-ts/didcomm": "0.6.0-alpha-20251204143549"
|
|
22
|
+
"@types/express": "^4.17.15",
|
|
23
|
+
"express": "^4.17.1",
|
|
24
|
+
"rxjs": "^7.8.0",
|
|
25
|
+
"ws": "^8.13.0",
|
|
26
|
+
"@credo-ts/core": "0.6.0-alpha-20260304224601"
|
|
33
27
|
},
|
|
34
28
|
"devDependencies": {
|
|
35
|
-
"@types/node": "^
|
|
36
|
-
"@types/ws": "^8.
|
|
37
|
-
"nock": "^
|
|
38
|
-
"
|
|
29
|
+
"@types/node": "^18.18.8",
|
|
30
|
+
"@types/ws": "^8.5.4",
|
|
31
|
+
"nock": "^13.3.0",
|
|
32
|
+
"rimraf": "^4.4.0",
|
|
33
|
+
"typescript": "~5.5.2"
|
|
39
34
|
},
|
|
40
35
|
"scripts": {
|
|
41
|
-
"build": "
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
36
|
+
"build": "pnpm run clean && pnpm run compile",
|
|
37
|
+
"clean": "rimraf ./build",
|
|
38
|
+
"compile": "tsc -p tsconfig.build.json",
|
|
39
|
+
"test": "jest"
|
|
40
|
+
}
|
|
45
41
|
}
|
package/build/NodeFileSystem.mjs
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { CredoError, TypedArrayEncoder } from "@credo-ts/core";
|
|
2
|
-
import { createHash } from "crypto";
|
|
3
|
-
import fs, { promises } from "fs";
|
|
4
|
-
import http from "http";
|
|
5
|
-
import https from "https";
|
|
6
|
-
import { homedir, tmpdir } from "os";
|
|
7
|
-
import { dirname } from "path";
|
|
8
|
-
|
|
9
|
-
//#region src/NodeFileSystem.ts
|
|
10
|
-
const { access, readFile, writeFile, mkdir, rm, unlink, copyFile } = promises;
|
|
11
|
-
var NodeFileSystem = class {
|
|
12
|
-
/**
|
|
13
|
-
* Create new NodeFileSystem class instance.
|
|
14
|
-
*
|
|
15
|
-
* @param baseDataPath The base path to use for reading and writing data files used within the framework.
|
|
16
|
-
* Files will be created under baseDataPath/.afj directory. If not specified, it will be set to homedir()
|
|
17
|
-
* @param baseCachePath The base path to use for reading and writing cache files used within the framework.
|
|
18
|
-
* Files will be created under baseCachePath/.afj directory. If not specified, it will be set to homedir()
|
|
19
|
-
* @param baseTempPath The base path to use for reading and writing temporary files within the framework.
|
|
20
|
-
* Files will be created under baseTempPath/.afj directory. If not specified, it will be set to tmpdir()
|
|
21
|
-
*/
|
|
22
|
-
constructor(options) {
|
|
23
|
-
this.dataPath = options?.baseDataPath ? `${options?.baseDataPath}/.afj` : `${homedir()}/.afj/data`;
|
|
24
|
-
this.cachePath = options?.baseCachePath ? `${options?.baseCachePath}/.afj` : `${homedir()}/.afj/cache`;
|
|
25
|
-
this.tempPath = `${options?.baseTempPath ?? tmpdir()}/.afj`;
|
|
26
|
-
}
|
|
27
|
-
async exists(path) {
|
|
28
|
-
try {
|
|
29
|
-
await access(path);
|
|
30
|
-
return true;
|
|
31
|
-
} catch {
|
|
32
|
-
return false;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
async createDirectory(path) {
|
|
36
|
-
await mkdir(dirname(path), { recursive: true });
|
|
37
|
-
}
|
|
38
|
-
async copyFile(sourcePath, destinationPath) {
|
|
39
|
-
await copyFile(sourcePath, destinationPath);
|
|
40
|
-
}
|
|
41
|
-
async write(path, data) {
|
|
42
|
-
await mkdir(dirname(path), { recursive: true });
|
|
43
|
-
return writeFile(path, data, { encoding: "utf-8" });
|
|
44
|
-
}
|
|
45
|
-
async read(path) {
|
|
46
|
-
return readFile(path, { encoding: "utf-8" });
|
|
47
|
-
}
|
|
48
|
-
async delete(path) {
|
|
49
|
-
await rm(path, {
|
|
50
|
-
recursive: true,
|
|
51
|
-
force: true
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
async downloadToFile(url, path, options) {
|
|
55
|
-
const httpMethod = url.startsWith("https") ? https : http;
|
|
56
|
-
await mkdir(dirname(path), { recursive: true });
|
|
57
|
-
const file = fs.createWriteStream(path);
|
|
58
|
-
const hash = options.verifyHash ? createHash("sha256") : void 0;
|
|
59
|
-
return new Promise((resolve, reject) => {
|
|
60
|
-
httpMethod.get(url, (response) => {
|
|
61
|
-
if (response.statusCode !== 200) reject(`Unable to download file from url: ${url}. Response status was ${response.statusCode}`);
|
|
62
|
-
hash && response.pipe(hash);
|
|
63
|
-
response.pipe(file);
|
|
64
|
-
file.on("finish", async () => {
|
|
65
|
-
file.close();
|
|
66
|
-
if (hash && options.verifyHash?.hash) {
|
|
67
|
-
hash.end();
|
|
68
|
-
const digest = hash.digest();
|
|
69
|
-
if (digest.compare(options.verifyHash.hash) !== 0) {
|
|
70
|
-
await fs.promises.unlink(path);
|
|
71
|
-
reject(new CredoError(`Hash of downloaded file does not match expected hash. Expected: ${options.verifyHash.hash}, Actual: ${TypedArrayEncoder.toUtf8String(digest)})}`));
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
resolve();
|
|
75
|
-
});
|
|
76
|
-
}).on("error", async (error) => {
|
|
77
|
-
await unlink(path);
|
|
78
|
-
reject(`Unable to download file from url: ${url}. ${error.message}`);
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
//#endregion
|
|
85
|
-
export { NodeFileSystem };
|
|
86
|
-
//# sourceMappingURL=NodeFileSystem.mjs.map
|