@enbox/dwn-clients 0.0.2
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/README.md +73 -0
- package/dist/esm/dwn-registrar.js +119 -0
- package/dist/esm/dwn-registrar.js.map +1 -0
- package/dist/esm/dwn-rpc-types.js +2 -0
- package/dist/esm/dwn-rpc-types.js.map +1 -0
- package/dist/esm/dwn-server-info-cache-memory.js +74 -0
- package/dist/esm/dwn-server-info-cache-memory.js.map +1 -0
- package/dist/esm/http-dwn-rpc-client.js +115 -0
- package/dist/esm/http-dwn-rpc-client.js.map +1 -0
- package/dist/esm/index.js +12 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/json-rpc-socket.js +175 -0
- package/dist/esm/json-rpc-socket.js.map +1 -0
- package/dist/esm/json-rpc.js +77 -0
- package/dist/esm/json-rpc.js.map +1 -0
- package/dist/esm/registration-types.js +2 -0
- package/dist/esm/registration-types.js.map +1 -0
- package/dist/esm/rpc-client.js +123 -0
- package/dist/esm/rpc-client.js.map +1 -0
- package/dist/esm/server-info-types.js +2 -0
- package/dist/esm/server-info-types.js.map +1 -0
- package/dist/esm/utils.js +13 -0
- package/dist/esm/utils.js.map +1 -0
- package/dist/esm/web-socket-clients.js +90 -0
- package/dist/esm/web-socket-clients.js.map +1 -0
- package/dist/types/dwn-registrar.d.ts +28 -0
- package/dist/types/dwn-registrar.d.ts.map +1 -0
- package/dist/types/dwn-rpc-types.d.ts +45 -0
- package/dist/types/dwn-rpc-types.d.ts.map +1 -0
- package/dist/types/dwn-server-info-cache-memory.d.ts +57 -0
- package/dist/types/dwn-server-info-cache-memory.d.ts.map +1 -0
- package/dist/types/http-dwn-rpc-client.d.ts +13 -0
- package/dist/types/http-dwn-rpc-client.d.ts.map +1 -0
- package/dist/types/index.d.ts +12 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/json-rpc-socket.d.ts +40 -0
- package/dist/types/json-rpc-socket.d.ts.map +1 -0
- package/dist/types/json-rpc.d.ts +64 -0
- package/dist/types/json-rpc.d.ts.map +1 -0
- package/dist/types/registration-types.d.ts +25 -0
- package/dist/types/registration-types.d.ts.map +1 -0
- package/dist/types/rpc-client.d.ts +51 -0
- package/dist/types/rpc-client.d.ts.map +1 -0
- package/dist/types/server-info-types.d.ts +28 -0
- package/dist/types/server-info-types.d.ts.map +1 -0
- package/dist/types/utils.d.ts +3 -0
- package/dist/types/utils.d.ts.map +1 -0
- package/dist/types/web-socket-clients.d.ts +10 -0
- package/dist/types/web-socket-clients.d.ts.map +1 -0
- package/package.json +66 -0
- package/src/dwn-registrar.ts +129 -0
- package/src/dwn-rpc-types.ts +55 -0
- package/src/dwn-server-info-cache-memory.ts +80 -0
- package/src/http-dwn-rpc-client.ts +122 -0
- package/src/index.ts +11 -0
- package/src/json-rpc-socket.ts +198 -0
- package/src/json-rpc.ts +142 -0
- package/src/registration-types.ts +26 -0
- package/src/rpc-client.ts +160 -0
- package/src/server-info-types.ts +29 -0
- package/src/utils.ts +14 -0
- package/src/web-socket-clients.ts +107 -0
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
export var JsonRpcErrorCodes;
|
|
2
|
+
(function (JsonRpcErrorCodes) {
|
|
3
|
+
// JSON-RPC 2.0 pre-defined errors
|
|
4
|
+
JsonRpcErrorCodes[JsonRpcErrorCodes["InvalidRequest"] = -32600] = "InvalidRequest";
|
|
5
|
+
JsonRpcErrorCodes[JsonRpcErrorCodes["MethodNotFound"] = -32601] = "MethodNotFound";
|
|
6
|
+
JsonRpcErrorCodes[JsonRpcErrorCodes["InvalidParams"] = -32602] = "InvalidParams";
|
|
7
|
+
JsonRpcErrorCodes[JsonRpcErrorCodes["InternalError"] = -32603] = "InternalError";
|
|
8
|
+
JsonRpcErrorCodes[JsonRpcErrorCodes["ParseError"] = -32700] = "ParseError";
|
|
9
|
+
JsonRpcErrorCodes[JsonRpcErrorCodes["TransportError"] = -32300] = "TransportError";
|
|
10
|
+
// App defined errors
|
|
11
|
+
JsonRpcErrorCodes[JsonRpcErrorCodes["BadRequest"] = -50400] = "BadRequest";
|
|
12
|
+
JsonRpcErrorCodes[JsonRpcErrorCodes["Unauthorized"] = -50401] = "Unauthorized";
|
|
13
|
+
JsonRpcErrorCodes[JsonRpcErrorCodes["Forbidden"] = -50403] = "Forbidden";
|
|
14
|
+
JsonRpcErrorCodes[JsonRpcErrorCodes["Conflict"] = -50409] = "Conflict";
|
|
15
|
+
})(JsonRpcErrorCodes || (JsonRpcErrorCodes = {}));
|
|
16
|
+
export const createJsonRpcErrorResponse = (id, code, message, data) => {
|
|
17
|
+
const error = { code, message };
|
|
18
|
+
if (data != undefined) {
|
|
19
|
+
error.data = data;
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
jsonrpc: '2.0',
|
|
23
|
+
id,
|
|
24
|
+
error,
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
export const createJsonRpcNotification = (method, params) => {
|
|
28
|
+
return {
|
|
29
|
+
jsonrpc: '2.0',
|
|
30
|
+
method,
|
|
31
|
+
params,
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
export const createJsonRpcRequest = (id, method, params) => {
|
|
35
|
+
return {
|
|
36
|
+
jsonrpc: '2.0',
|
|
37
|
+
id,
|
|
38
|
+
method,
|
|
39
|
+
params,
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Creates a JSON-RPC subscription request.
|
|
44
|
+
*
|
|
45
|
+
* The caller is responsible for providing the full method name including
|
|
46
|
+
* any `rpc.subscribe.` prefix.
|
|
47
|
+
*/
|
|
48
|
+
export const createJsonRpcSubscriptionRequest = (id, method, params, subscriptionId) => {
|
|
49
|
+
return {
|
|
50
|
+
jsonrpc: '2.0',
|
|
51
|
+
id,
|
|
52
|
+
method,
|
|
53
|
+
params,
|
|
54
|
+
subscription: {
|
|
55
|
+
id: subscriptionId !== null && subscriptionId !== void 0 ? subscriptionId : null,
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
export const createJsonRpcSuccessResponse = (id, result) => {
|
|
60
|
+
return {
|
|
61
|
+
jsonrpc: '2.0',
|
|
62
|
+
id,
|
|
63
|
+
result: result !== null && result !== void 0 ? result : null,
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Safely parses a JSON string, returning `null` on failure instead of throwing.
|
|
68
|
+
*/
|
|
69
|
+
export function parseJson(text) {
|
|
70
|
+
try {
|
|
71
|
+
return JSON.parse(text);
|
|
72
|
+
}
|
|
73
|
+
catch (_a) {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=json-rpc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-rpc.js","sourceRoot":"","sources":["../../src/json-rpc.ts"],"names":[],"mappings":"AAyBA,MAAM,CAAN,IAAY,iBAcX;AAdD,WAAY,iBAAiB;IAC3B,kCAAkC;IAClC,kFAAuB,CAAA;IACvB,kFAAuB,CAAA;IACvB,gFAAsB,CAAA;IACtB,gFAAsB,CAAA;IACtB,0EAAmB,CAAA;IACnB,kFAAuB,CAAA;IAEvB,qBAAqB;IACrB,0EAAmB,CAAA;IACnB,8EAAqB,CAAA;IACrB,wEAAkB,CAAA;IAClB,sEAAiB,CAAA;AACnB,CAAC,EAdW,iBAAiB,KAAjB,iBAAiB,QAc5B;AAkBD,MAAM,CAAC,MAAM,0BAA0B,GAAG,CACxC,EAAa,EACb,IAAuB,EACvB,OAAe,EACf,IAAU,EACY,EAAE;IACxB,MAAM,KAAK,GAAiB,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;IAC9C,IAAI,IAAI,IAAI,SAAS,EAAE,CAAC;QACtB,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC;IACpB,CAAC;IACD,OAAO;QACL,OAAO,EAAE,KAAK;QACd,EAAE;QACF,KAAK;KACN,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,yBAAyB,GAAG,CACvC,MAAc,EACd,MAAY,EACI,EAAE;IAClB,OAAO;QACL,OAAO,EAAE,KAAK;QACd,MAAM;QACN,MAAM;KACP,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAClC,EAAa,EACb,MAAc,EACd,MAAsB,EACN,EAAE;IAClB,OAAO;QACL,OAAO,EAAE,KAAK;QACd,EAAE;QACF,MAAM;QACN,MAAM;KACP,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gCAAgC,GAAG,CAC9C,EAAa,EACb,MAAc,EACd,MAAY,EACZ,cAA0B,EACV,EAAE;IAClB,OAAO;QACL,OAAO,EAAQ,KAAK;QACpB,EAAE;QACF,MAAM;QACN,MAAM;QACN,YAAY,EAAG;YACb,EAAE,EAAE,cAAc,aAAd,cAAc,cAAd,cAAc,GAAI,IAAI;SAC3B;KACF,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAC1C,EAAa,EACb,MAAY,EACY,EAAE;IAC1B,OAAO;QACL,OAAO,EAAG,KAAK;QACf,EAAE;QACF,MAAM,EAAI,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,IAAI;KACzB,CAAC;AACJ,CAAC,CAAC;AAEF;;GAEG;AACH,MAAM,UAAU,SAAS,CAAC,IAAY;IACpC,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;IAAC,WAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registration-types.js","sourceRoot":"","sources":["../../src/registration-types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { createJsonRpcRequest } from './json-rpc.js';
|
|
11
|
+
import { CryptoUtils } from '@enbox/crypto';
|
|
12
|
+
import { HttpDwnRpcClient } from './http-dwn-rpc-client.js';
|
|
13
|
+
import { WebSocketDwnRpcClient } from './web-socket-clients.js';
|
|
14
|
+
export var DidRpcMethod;
|
|
15
|
+
(function (DidRpcMethod) {
|
|
16
|
+
DidRpcMethod["Create"] = "did.create";
|
|
17
|
+
DidRpcMethod["Resolve"] = "did.resolve";
|
|
18
|
+
})(DidRpcMethod || (DidRpcMethod = {}));
|
|
19
|
+
/**
|
|
20
|
+
* Client used to communicate with Dwn Servers
|
|
21
|
+
*/
|
|
22
|
+
export class Web5RpcClient {
|
|
23
|
+
constructor(clients = []) {
|
|
24
|
+
this.transportClients = new Map();
|
|
25
|
+
// include http and socket clients as default.
|
|
26
|
+
// can be overwritten for 'http:', 'https:', 'ws: or ':wss' if instantiated with other clients.
|
|
27
|
+
clients = [new HttpWeb5RpcClient(), new WebSocketWeb5RpcClient(), ...clients];
|
|
28
|
+
for (const client of clients) {
|
|
29
|
+
for (const transportScheme of client.transportProtocols) {
|
|
30
|
+
this.transportClients.set(transportScheme, client);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
get transportProtocols() {
|
|
35
|
+
return Array.from(this.transportClients.keys());
|
|
36
|
+
}
|
|
37
|
+
sendDidRequest(request) {
|
|
38
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
// URL() will throw if provided `url` is invalid.
|
|
40
|
+
const url = new URL(request.url);
|
|
41
|
+
const transportClient = this.transportClients.get(url.protocol);
|
|
42
|
+
if (!transportClient) {
|
|
43
|
+
const error = new Error(`no ${url.protocol} transport client available`);
|
|
44
|
+
error.name = 'NO_TRANSPORT_CLIENT';
|
|
45
|
+
throw error;
|
|
46
|
+
}
|
|
47
|
+
return transportClient.sendDidRequest(request);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
sendDwnRequest(request) {
|
|
51
|
+
// will throw if url is invalid
|
|
52
|
+
const url = new URL(request.dwnUrl);
|
|
53
|
+
const transportClient = this.transportClients.get(url.protocol);
|
|
54
|
+
if (!transportClient) {
|
|
55
|
+
const error = new Error(`no ${url.protocol} transport client available`);
|
|
56
|
+
error.name = 'NO_TRANSPORT_CLIENT';
|
|
57
|
+
throw error;
|
|
58
|
+
}
|
|
59
|
+
return transportClient.sendDwnRequest(request);
|
|
60
|
+
}
|
|
61
|
+
getServerInfo(dwnUrl) {
|
|
62
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
63
|
+
// will throw if url is invalid
|
|
64
|
+
const url = new URL(dwnUrl);
|
|
65
|
+
const transportClient = this.transportClients.get(url.protocol);
|
|
66
|
+
if (!transportClient) {
|
|
67
|
+
const error = new Error(`no ${url.protocol} transport client available`);
|
|
68
|
+
error.name = 'NO_TRANSPORT_CLIENT';
|
|
69
|
+
throw error;
|
|
70
|
+
}
|
|
71
|
+
return transportClient.getServerInfo(dwnUrl);
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
export class HttpWeb5RpcClient extends HttpDwnRpcClient {
|
|
76
|
+
sendDidRequest(request) {
|
|
77
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
78
|
+
const requestId = CryptoUtils.randomUuid();
|
|
79
|
+
const jsonRpcRequest = createJsonRpcRequest(requestId, request.method, {
|
|
80
|
+
data: request.data
|
|
81
|
+
});
|
|
82
|
+
const httpRequest = new Request(request.url, {
|
|
83
|
+
method: 'POST',
|
|
84
|
+
headers: {
|
|
85
|
+
'Content-Type': 'application/json',
|
|
86
|
+
},
|
|
87
|
+
body: JSON.stringify(jsonRpcRequest),
|
|
88
|
+
});
|
|
89
|
+
let jsonRpcResponse;
|
|
90
|
+
try {
|
|
91
|
+
const response = yield fetch(httpRequest);
|
|
92
|
+
if (response.ok) {
|
|
93
|
+
jsonRpcResponse = yield response.json();
|
|
94
|
+
// If the response is an error, throw an error.
|
|
95
|
+
if (jsonRpcResponse.error) {
|
|
96
|
+
const { code, message } = jsonRpcResponse.error;
|
|
97
|
+
throw new Error(`JSON RPC (${code}) - ${message}`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
throw new Error(`HTTP (${response.status}) - ${response.statusText}`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
throw new Error(`Error encountered while processing response from ${request.url}: ${error.message}`);
|
|
106
|
+
}
|
|
107
|
+
return jsonRpcResponse.result;
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
export class WebSocketWeb5RpcClient extends WebSocketDwnRpcClient {
|
|
112
|
+
sendDidRequest(_request) {
|
|
113
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
114
|
+
throw new Error(`not implemented for transports [${this.transportProtocols.join(', ')}]`);
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
getServerInfo(_dwnUrl) {
|
|
118
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
119
|
+
throw new Error(`not implemented for transports [${this.transportProtocols.join(', ')}]`);
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
//# sourceMappingURL=rpc-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rpc-client.js","sourceRoot":"","sources":["../../src/rpc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AqB;IACzD,cAAc,CAAC,QAAuB;;YAC1C,MAAM,IAAI,KAAK,CAAC,mCAAmC,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC5F,CAAC;KAAA;IAEK,aAAa,CAAC,OAAe;;YACjC,MAAM,IAAI,KAAK,CAAC,mCAAmC,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC5F,CAAC;KAAA;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-info-types.js","sourceRoot":"","sources":["../../src/server-info-types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Concatenates a base URL and a path ensuring that there is exactly one slash between them. */
|
|
2
|
+
export function concatenateUrl(baseUrl, path) {
|
|
3
|
+
// Remove trailing slash from baseUrl if it exists
|
|
4
|
+
if (baseUrl.endsWith('/')) {
|
|
5
|
+
baseUrl = baseUrl.slice(0, -1);
|
|
6
|
+
}
|
|
7
|
+
// Remove leading slash from path if it exists
|
|
8
|
+
if (path.startsWith('/')) {
|
|
9
|
+
path = path.slice(1);
|
|
10
|
+
}
|
|
11
|
+
return `${baseUrl}/${path}`;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,gGAAgG;AAChG,MAAM,UAAU,cAAc,CAAC,OAAe,EAAE,IAAY;IAC1D,kDAAkD;IAClD,IAAI,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QAC1B,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IACjC,CAAC;IAED,8CAA8C;IAC9C,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QACzB,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACvB,CAAC;IAED,OAAO,GAAG,OAAO,IAAI,IAAI,EAAE,CAAC;AAC9B,CAAC"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { CryptoUtils } from '@enbox/crypto';
|
|
11
|
+
import { JsonRpcSocket } from './json-rpc-socket.js';
|
|
12
|
+
import { createJsonRpcRequest, createJsonRpcSubscriptionRequest } from './json-rpc.js';
|
|
13
|
+
export class WebSocketDwnRpcClient {
|
|
14
|
+
get transportProtocols() { return ['ws:', 'wss:']; }
|
|
15
|
+
sendDwnRequest(request, jsonRpcSocketOptions) {
|
|
16
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
// validate that the dwn URL provided is a valid WebSocket URL
|
|
18
|
+
const url = new URL(request.dwnUrl);
|
|
19
|
+
if (url.protocol !== 'ws:' && url.protocol !== 'wss:') {
|
|
20
|
+
throw new Error(`Invalid websocket protocol ${url.protocol}`);
|
|
21
|
+
}
|
|
22
|
+
// check if there is already a connection to this host, if it does not exist, initiate a new connection
|
|
23
|
+
const hasConnection = WebSocketDwnRpcClient.connections.has(url.host);
|
|
24
|
+
if (!hasConnection) {
|
|
25
|
+
try {
|
|
26
|
+
const socket = yield JsonRpcSocket.connect(url.toString(), jsonRpcSocketOptions);
|
|
27
|
+
const subscriptions = new Map();
|
|
28
|
+
WebSocketDwnRpcClient.connections.set(url.host, { socket, subscriptions });
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
throw new Error(`Error connecting to ${url.host}: ${error.message}`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
const connection = WebSocketDwnRpcClient.connections.get(url.host);
|
|
35
|
+
const { targetDid, message, subscriptionHandler } = request;
|
|
36
|
+
if (subscriptionHandler) {
|
|
37
|
+
return WebSocketDwnRpcClient.subscriptionRequest(connection, targetDid, message, subscriptionHandler);
|
|
38
|
+
}
|
|
39
|
+
return WebSocketDwnRpcClient.processMessage(connection, targetDid, message);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
static processMessage(connection, target, message) {
|
|
43
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
const requestId = CryptoUtils.randomUuid();
|
|
45
|
+
const request = createJsonRpcRequest(requestId, 'dwn.processMessage', { target, message });
|
|
46
|
+
const { socket } = connection;
|
|
47
|
+
const response = yield socket.request(request);
|
|
48
|
+
const { error, result } = response;
|
|
49
|
+
if (error !== undefined) {
|
|
50
|
+
throw new Error(`error sending DWN request: ${error.message}`);
|
|
51
|
+
}
|
|
52
|
+
return result.reply;
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
static subscriptionRequest(connection, target, message, messageHandler) {
|
|
56
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
57
|
+
const requestId = CryptoUtils.randomUuid();
|
|
58
|
+
const subscriptionId = CryptoUtils.randomUuid();
|
|
59
|
+
const request = createJsonRpcSubscriptionRequest(requestId, 'rpc.subscribe.dwn.processMessage', { target, message }, subscriptionId);
|
|
60
|
+
const { socket, subscriptions } = connection;
|
|
61
|
+
const { response, close } = yield socket.subscribe(request, (response) => {
|
|
62
|
+
const { result, error } = response;
|
|
63
|
+
if (error) {
|
|
64
|
+
// if there is an error, close the subscription and delete it from the connection
|
|
65
|
+
const subscription = subscriptions.get(subscriptionId);
|
|
66
|
+
if (subscription) {
|
|
67
|
+
subscription.close();
|
|
68
|
+
}
|
|
69
|
+
subscriptions.delete(subscriptionId);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const { event } = result;
|
|
73
|
+
messageHandler(event);
|
|
74
|
+
});
|
|
75
|
+
const { error, result } = response;
|
|
76
|
+
if (error) {
|
|
77
|
+
throw new Error(`could not subscribe via jsonrpc socket: ${error.message}`);
|
|
78
|
+
}
|
|
79
|
+
const { reply } = result;
|
|
80
|
+
if (reply.subscription && close) {
|
|
81
|
+
subscriptions.set(subscriptionId, Object.assign(Object.assign({}, reply.subscription), { close }));
|
|
82
|
+
reply.subscription.close = close;
|
|
83
|
+
}
|
|
84
|
+
return reply;
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
// a map of dwn host to WebSocket connection
|
|
89
|
+
WebSocketDwnRpcClient.connections = new Map();
|
|
90
|
+
//# sourceMappingURL=web-socket-clients.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web-socket-clients.js","sourceRoot":"","sources":["../../src/web-socket-clients.ts"],"names":[],"mappings":";;;;;;;;;AAIA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,oBAAoB,EAAE,gCAAgC,EAAE,MAAM,eAAe,CAAC;AAOvF,MAAM,OAAO,qBAAqB;IAChC,IAAW,kBAAkB,KAAe,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;IAI/D,cAAc,CAAC,OAAsB,EAAE,oBAA2C;;YAEtF,8DAA8D;YAC9D,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;YACpC,IAAI,GAAG,CAAC,QAAQ,KAAK,KAAK,IAAI,GAAG,CAA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B,CAAC;oBAED,aAAa,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;oBACrC,OAAO;gBACT,CAAC;gBAED,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,CAAC;gBACzB,cAAc,CAAC,KAAK,CAAC,CAAC;YACxB,CAAC,CAAC,CAAC;YAEH,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,QAAQ,CAAC;YACnC,IAAI,KAAK,EAAE,CAAC;gBACV,MAAM,IAAI,KAAK,CAAC,2CAA2C,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;YAC9E,CAAC;YAED,MAAM,EAAE,KAAK,EAAE,GAAG,MAAsC,CAAC;YACzD,IAAI,KAAK,CAAC,YAAY,IAAI,KAAK,EAAE,CAAC;gBAChC,aAAa,CAAC,GAAG,CAAC,cAAc,kCAAO,KAAK,CAAC,YAAY,KAAE,KAAK,IAAG,CAAC;gBACpE,KAAK,CAAC,YAAY,CAAC,KAAK,GAAG,KAAK,CAAC;YACnC,CAAC;YAED,OAAO,KAAK,CAAC;QACf,CAAC;KAAA;;AA1FD,4CAA4C;AAC7B,iCAAW,GAAG,IAAI,GAAG,EAA4B,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A client for registering tenants with a DWN.
|
|
3
|
+
*/
|
|
4
|
+
export declare class DwnRegistrar {
|
|
5
|
+
/**
|
|
6
|
+
* Registers a new tenant with the given DWN.
|
|
7
|
+
* NOTE: Assumes the user has already accepted the terms of service.
|
|
8
|
+
* NOTE: Currently the DWN Server from `dwn-server` does not require user signature.
|
|
9
|
+
*/
|
|
10
|
+
static registerTenant(dwnEndpoint: string, did: string): Promise<void>;
|
|
11
|
+
/**
|
|
12
|
+
* Computes the SHA-256 hash of the given array of strings.
|
|
13
|
+
*/
|
|
14
|
+
static hashAsHexString(input: string): Promise<string>;
|
|
15
|
+
/**
|
|
16
|
+
* Finds a response nonce that qualifies the difficulty requirement for the given proof-of-work challenge and request data.
|
|
17
|
+
*/
|
|
18
|
+
static findQualifiedResponseNonce(input: {
|
|
19
|
+
maximumAllowedHashValue: string;
|
|
20
|
+
challengeNonce: string;
|
|
21
|
+
requestData: string;
|
|
22
|
+
}): Promise<string>;
|
|
23
|
+
/**
|
|
24
|
+
* Generates 32 random bytes expressed as a HEX string.
|
|
25
|
+
*/
|
|
26
|
+
static generateNonce(): Promise<string>;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=dwn-registrar.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dwn-registrar.d.ts","sourceRoot":"","sources":["../../src/dwn-registrar.ts"],"names":[],"mappings":"AAMA;;GAEG;AACH,qBAAa,YAAY;IACvB;;;;OAIG;WACiB,cAAc,CAAC,WAAW,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IA8DnF;;OAEG;WACiB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAMnE;;OAEG;WACiB,0BAA0B,CAAC,KAAK,EAAE;QACpD,uBAAuB,EAAE,MAAM,CAAC;QAChC,cAAc,EAAE,MAAM,CAAC;QACvB,WAAW,EAAE,MAAM,CAAC;KACrB,GAAG,OAAO,CAAC,MAAM,CAAC;IA2BnB;;OAEG;WACiB,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;CAKrD"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { MessageSubscriptionHandler, RecordsReadReply, RecordSubscriptionHandler, UnionMessageReply } from '@enbox/dwn-sdk-js';
|
|
2
|
+
export interface SerializableDwnMessage {
|
|
3
|
+
toJSON(): string;
|
|
4
|
+
}
|
|
5
|
+
export type DwnSubscriptionHandler = MessageSubscriptionHandler | RecordSubscriptionHandler;
|
|
6
|
+
/**
|
|
7
|
+
* Interface for communicating with {@link https://github.com/enboxorg/enbox | DWN Servers}
|
|
8
|
+
* via JSON-RPC, supporting operations like sending DWN requests.
|
|
9
|
+
*/
|
|
10
|
+
export interface DwnRpc {
|
|
11
|
+
/**
|
|
12
|
+
* Lists the transport protocols supported by the DWN RPC client, such as HTTP or HTTPS.
|
|
13
|
+
* @returns An array of strings representing the supported transport protocols.
|
|
14
|
+
*/
|
|
15
|
+
get transportProtocols(): string[];
|
|
16
|
+
/**
|
|
17
|
+
* Sends a request to a DWN Server using the specified DWN RPC request parameters.
|
|
18
|
+
*
|
|
19
|
+
* @param request - The DWN RPC request containing the URL, target DID, message, and optional data.
|
|
20
|
+
* @returns A promise that resolves to the response from the DWN server.
|
|
21
|
+
*/
|
|
22
|
+
sendDwnRequest(request: DwnRpcRequest): Promise<DwnRpcResponse>;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Represents a JSON RPC request to a DWN server, including the URL, target DID, the message to be
|
|
26
|
+
* processed, and optional data.
|
|
27
|
+
*/
|
|
28
|
+
export type DwnRpcRequest = {
|
|
29
|
+
/** Optional data to be sent with the request. */
|
|
30
|
+
data?: any;
|
|
31
|
+
/** The URL of the DWN server to which the request is sent. */
|
|
32
|
+
dwnUrl: string;
|
|
33
|
+
/** The message to be processed by the DWN server, which can be a serializable DWN message. */
|
|
34
|
+
message: SerializableDwnMessage | any;
|
|
35
|
+
/** The DID of the target to which the message is addressed. */
|
|
36
|
+
targetDid: string;
|
|
37
|
+
/** Optional subscription handler for DWN message events. */
|
|
38
|
+
subscriptionHandler?: DwnSubscriptionHandler;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Represents the JSON RPC response from a DWN server to a request, combining the results of various
|
|
42
|
+
* DWN operations.
|
|
43
|
+
*/
|
|
44
|
+
export type DwnRpcResponse = UnionMessageReply & RecordsReadReply;
|
|
45
|
+
//# sourceMappingURL=dwn-rpc-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dwn-rpc-types.d.ts","sourceRoot":"","sources":["../../src/dwn-rpc-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,gBAAgB,EAAE,yBAAyB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAEpI,MAAM,WAAW,sBAAsB;IACrC,MAAM,IAAI,MAAM,CAAC;CAClB;AAED,MAAM,MAAM,sBAAsB,GAAG,0BAA0B,GAAG,yBAAyB,CAAC;AAE5F;;;GAGG;AACH,MAAM,WAAW,MAAM;IACrB;;;OAGG;IACH,IAAI,kBAAkB,IAAI,MAAM,EAAE,CAAA;IAElC;;;;;OAKG;IACH,cAAc,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,cAAc,CAAC,CAAA;CAChE;AAGD;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B,iDAAiD;IACjD,IAAI,CAAC,EAAE,GAAG,CAAC;IAEX,8DAA8D;IAC9D,MAAM,EAAE,MAAM,CAAC;IAEf,8FAA8F;IAC9F,OAAO,EAAE,sBAAsB,GAAG,GAAG,CAAC;IAEtC,+DAA+D;IAC/D,SAAS,EAAE,MAAM,CAAC;IAElB,4DAA4D;IAC5D,mBAAmB,CAAC,EAAE,sBAAsB,CAAC;CAC9C,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG,iBAAiB,GAAG,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { DwnServerInfoCache, ServerInfo } from './server-info-types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Configuration parameters for creating an in-memory cache for DWN ServerInfo entries.
|
|
4
|
+
*
|
|
5
|
+
* Allows customization of the cache time-to-live (TTL) setting.
|
|
6
|
+
*/
|
|
7
|
+
export type DwnServerInfoCacheMemoryParams = {
|
|
8
|
+
/**
|
|
9
|
+
* Optional. The time-to-live for cache entries, expressed as a string (e.g., '1h', '15m').
|
|
10
|
+
* Determines how long a cache entry should remain valid before being considered expired.
|
|
11
|
+
*
|
|
12
|
+
* Defaults to '15m' if not specified.
|
|
13
|
+
*/
|
|
14
|
+
ttl?: string;
|
|
15
|
+
};
|
|
16
|
+
export declare class DwnServerInfoCacheMemory implements DwnServerInfoCache {
|
|
17
|
+
private cache;
|
|
18
|
+
constructor({ ttl }?: DwnServerInfoCacheMemoryParams);
|
|
19
|
+
/**
|
|
20
|
+
* Retrieves a DWN ServerInfo entry from the cache.
|
|
21
|
+
*
|
|
22
|
+
* If the cached item has exceeded its TTL, it's scheduled for deletion and undefined is returned.
|
|
23
|
+
*
|
|
24
|
+
* @param dwnUrl - The DWN URL endpoint string used as the key for getting the entry.
|
|
25
|
+
* @returns The cached DWN ServerInfo entry or undefined if not found or expired.
|
|
26
|
+
*/
|
|
27
|
+
get(dwnUrl: string): Promise<ServerInfo | undefined>;
|
|
28
|
+
/**
|
|
29
|
+
* Stores a DWN ServerInfo entry in the cache with a TTL.
|
|
30
|
+
*
|
|
31
|
+
* @param dwnUrl - The DWN URL endpoint string used as the key for storing the entry.
|
|
32
|
+
* @param value - The DWN ServerInfo entry to be cached.
|
|
33
|
+
* @returns A promise that resolves when the operation is complete.
|
|
34
|
+
*/
|
|
35
|
+
set(dwnUrl: string, value: ServerInfo): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Deletes a DWN ServerInfo entry from the cache.
|
|
38
|
+
*
|
|
39
|
+
* @param dwnUrl - The DWN URL endpoint string used as the key for deletion.
|
|
40
|
+
* @returns A promise that resolves when the operation is complete.
|
|
41
|
+
*/
|
|
42
|
+
delete(dwnUrl: string): Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* Clears all entries from the cache.
|
|
45
|
+
*
|
|
46
|
+
* @returns A promise that resolves when the operation is complete.
|
|
47
|
+
*/
|
|
48
|
+
clear(): Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* This method is a no-op but exists to be consistent with other DWN ServerInfo Cache
|
|
51
|
+
* implementations.
|
|
52
|
+
*
|
|
53
|
+
* @returns A promise that resolves immediately.
|
|
54
|
+
*/
|
|
55
|
+
close(): Promise<void>;
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=dwn-server-info-cache-memory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dwn-server-info-cache-memory.d.ts","sourceRoot":"","sources":["../../src/dwn-server-info-cache-memory.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAE7E;;;;GAIG;AACH,MAAM,MAAM,8BAA8B,GAAG;IAC3C;;;;;OAKG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,qBAAa,wBAAyB,YAAW,kBAAkB;IACjE,OAAO,CAAC,KAAK,CAA+B;gBAEhC,EAAE,GAAW,EAAE,GAAE,8BAAkC;IAI/D;;;;;;;OAOG;IACU,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAE,SAAS,CAAC;IAIhE;;;;;;OAMG;IACU,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAIlE;;;;;OAKG;IACU,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIlD;;;;OAIG;IACU,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAInC;;;;;OAKG;IACU,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAGpC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { DwnRpc, DwnRpcRequest, DwnRpcResponse } from './dwn-rpc-types.js';
|
|
2
|
+
import type { DwnServerInfoCache, ServerInfo } from './server-info-types.js';
|
|
3
|
+
/**
|
|
4
|
+
* HTTP client that can be used to communicate with Dwn Servers
|
|
5
|
+
*/
|
|
6
|
+
export declare class HttpDwnRpcClient implements DwnRpc {
|
|
7
|
+
private serverInfoCache;
|
|
8
|
+
constructor(serverInfoCache?: DwnServerInfoCache);
|
|
9
|
+
get transportProtocols(): string[];
|
|
10
|
+
sendDwnRequest(request: DwnRpcRequest): Promise<DwnRpcResponse>;
|
|
11
|
+
getServerInfo(dwnUrl: string): Promise<ServerInfo>;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=http-dwn-rpc-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-dwn-rpc-client.d.ts","sourceRoot":"","sources":["../../src/http-dwn-rpc-client.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAChF,OAAO,KAAK,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAO7E;;GAEG;AACH,qBAAa,gBAAiB,YAAW,MAAM;IAC7C,OAAO,CAAC,eAAe,CAAqB;gBAChC,eAAe,CAAC,EAAE,kBAAkB;IAIhD,IAAI,kBAAkB,IAAI,MAAM,EAAE,CAAgC;IAE5D,cAAc,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,cAAc,CAAC;IAkE/D,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;CAmCzD"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from './dwn-registrar.js';
|
|
2
|
+
export * from './dwn-rpc-types.js';
|
|
3
|
+
export * from './dwn-server-info-cache-memory.js';
|
|
4
|
+
export * from './http-dwn-rpc-client.js';
|
|
5
|
+
export * from './json-rpc.js';
|
|
6
|
+
export * from './json-rpc-socket.js';
|
|
7
|
+
export * from './registration-types.js';
|
|
8
|
+
export * from './rpc-client.js';
|
|
9
|
+
export * from './server-info-types.js';
|
|
10
|
+
export * from './utils.js';
|
|
11
|
+
export * from './web-socket-clients.js';
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mCAAmC,CAAC;AAClD,cAAc,0BAA0B,CAAC;AACzC,cAAc,eAAe,CAAC;AAC9B,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC;AACxC,cAAc,iBAAiB,CAAC;AAChC,cAAc,wBAAwB,CAAC;AACvC,cAAc,YAAY,CAAC;AAC3B,cAAc,yBAAyB,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { JsonRpcRequest, JsonRpcResponse } from './json-rpc.js';
|
|
2
|
+
export interface JsonRpcSocketOptions {
|
|
3
|
+
/** socket connection timeout in milliseconds */
|
|
4
|
+
connectTimeout?: number;
|
|
5
|
+
/** response timeout for rpc requests in milliseconds */
|
|
6
|
+
responseTimeout?: number;
|
|
7
|
+
/** optional connection close handler */
|
|
8
|
+
onclose?: () => void;
|
|
9
|
+
/** optional socket error handler */
|
|
10
|
+
onerror?: (error?: any) => void;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* JSON RPC Socket Client for WebSocket request/response and long-running subscriptions.
|
|
14
|
+
*/
|
|
15
|
+
export declare class JsonRpcSocket {
|
|
16
|
+
private socket;
|
|
17
|
+
private responseTimeout;
|
|
18
|
+
private messageHandlers;
|
|
19
|
+
private constructor();
|
|
20
|
+
static connect(url: string, options?: JsonRpcSocketOptions): Promise<JsonRpcSocket>;
|
|
21
|
+
close(): void;
|
|
22
|
+
/**
|
|
23
|
+
* Sends a JSON-RPC request through the socket and waits for a single response.
|
|
24
|
+
*/
|
|
25
|
+
request(request: JsonRpcRequest): Promise<JsonRpcResponse>;
|
|
26
|
+
/**
|
|
27
|
+
* Sends a JSON-RPC request through the socket and keeps a listener open to read associated responses as they arrive.
|
|
28
|
+
* Returns a close method to clean up the listener.
|
|
29
|
+
*/
|
|
30
|
+
subscribe(request: JsonRpcRequest, listener: (response: JsonRpcResponse) => void): Promise<{
|
|
31
|
+
response: JsonRpcResponse;
|
|
32
|
+
close?: () => Promise<void>;
|
|
33
|
+
}>;
|
|
34
|
+
private closeSubscription;
|
|
35
|
+
/**
|
|
36
|
+
* Sends a JSON-RPC request through the socket. You must subscribe to a message listener separately to capture the response.
|
|
37
|
+
*/
|
|
38
|
+
send(request: JsonRpcRequest): void;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=json-rpc-socket.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-rpc-socket.d.ts","sourceRoot":"","sources":["../../src/json-rpc-socket.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAa,cAAc,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AA4BhF,MAAM,WAAW,oBAAoB;IACnC,gDAAgD;IAChD,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,wDAAwD;IACxD,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,wCAAwC;IACxC,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,oCAAoC;IACpC,OAAO,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,GAAG,KAAK,IAAI,CAAC;CACjC;AAED;;GAEG;AACH,qBAAa,aAAa;IAGJ,OAAO,CAAC,MAAM;IAAa,OAAO,CAAC,eAAe;IAFtE,OAAO,CAAC,eAAe,CAA6D;IAEpF,OAAO;WAEa,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,oBAAyB,GAAG,OAAO,CAAC,aAAa,CAAC;IA4C7F,KAAK,IAAI,IAAI;IAIpB;;OAEG;IACU,OAAO,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,eAAe,CAAC;IAyBvE;;;OAGG;IACU,SAAS,CAAC,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,CAAC,QAAQ,EAAE,eAAe,KAAK,IAAI,GAAG,OAAO,CAAC;QACtG,QAAQ,EAAE,eAAe,CAAC;QAC1B,KAAK,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;KAC5B,CAAC;IAuDH,OAAO,CAAC,iBAAiB;IAMzB;;OAEG;IACI,IAAI,CAAC,OAAO,EAAE,cAAc,GAAE,IAAI;CAG1C"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
export type JsonRpcId = string | number | null;
|
|
2
|
+
export type JsonRpcParams = any;
|
|
3
|
+
export type JsonRpcVersion = '2.0';
|
|
4
|
+
export interface JsonRpcRequest {
|
|
5
|
+
jsonrpc: JsonRpcVersion;
|
|
6
|
+
id?: JsonRpcId;
|
|
7
|
+
method: string;
|
|
8
|
+
params?: any;
|
|
9
|
+
/** JSON RPC Subscription Extension Parameters */
|
|
10
|
+
subscription?: {
|
|
11
|
+
id: JsonRpcId;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export interface JsonRpcError {
|
|
15
|
+
code: JsonRpcErrorCodes;
|
|
16
|
+
message: string;
|
|
17
|
+
data?: any;
|
|
18
|
+
}
|
|
19
|
+
export interface JsonRpcSubscription {
|
|
20
|
+
/** JSON RPC Id of the Subscription Request */
|
|
21
|
+
id: JsonRpcId;
|
|
22
|
+
close: () => Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
export declare enum JsonRpcErrorCodes {
|
|
25
|
+
InvalidRequest = -32600,
|
|
26
|
+
MethodNotFound = -32601,
|
|
27
|
+
InvalidParams = -32602,
|
|
28
|
+
InternalError = -32603,
|
|
29
|
+
ParseError = -32700,
|
|
30
|
+
TransportError = -32300,
|
|
31
|
+
BadRequest = -50400,// equivalent to HTTP Status 400
|
|
32
|
+
Unauthorized = -50401,// equivalent to HTTP Status 401
|
|
33
|
+
Forbidden = -50403,// equivalent to HTTP Status 403
|
|
34
|
+
Conflict = -50409
|
|
35
|
+
}
|
|
36
|
+
export type JsonRpcResponse = JsonRpcSuccessResponse | JsonRpcErrorResponse;
|
|
37
|
+
export interface JsonRpcSuccessResponse {
|
|
38
|
+
jsonrpc: JsonRpcVersion;
|
|
39
|
+
id: JsonRpcId;
|
|
40
|
+
result: any;
|
|
41
|
+
error?: never;
|
|
42
|
+
}
|
|
43
|
+
export interface JsonRpcErrorResponse {
|
|
44
|
+
jsonrpc: JsonRpcVersion;
|
|
45
|
+
id: JsonRpcId;
|
|
46
|
+
result?: never;
|
|
47
|
+
error: JsonRpcError;
|
|
48
|
+
}
|
|
49
|
+
export declare const createJsonRpcErrorResponse: (id: JsonRpcId, code: JsonRpcErrorCodes, message: string, data?: any) => JsonRpcErrorResponse;
|
|
50
|
+
export declare const createJsonRpcNotification: (method: string, params?: any) => JsonRpcRequest;
|
|
51
|
+
export declare const createJsonRpcRequest: (id: JsonRpcId, method: string, params?: JsonRpcParams) => JsonRpcRequest;
|
|
52
|
+
/**
|
|
53
|
+
* Creates a JSON-RPC subscription request.
|
|
54
|
+
*
|
|
55
|
+
* The caller is responsible for providing the full method name including
|
|
56
|
+
* any `rpc.subscribe.` prefix.
|
|
57
|
+
*/
|
|
58
|
+
export declare const createJsonRpcSubscriptionRequest: (id: JsonRpcId, method: string, params?: any, subscriptionId?: JsonRpcId) => JsonRpcRequest;
|
|
59
|
+
export declare const createJsonRpcSuccessResponse: (id: JsonRpcId, result?: any) => JsonRpcSuccessResponse;
|
|
60
|
+
/**
|
|
61
|
+
* Safely parses a JSON string, returning `null` on failure instead of throwing.
|
|
62
|
+
*/
|
|
63
|
+
export declare function parseJson(text: string): object | null;
|
|
64
|
+
//# sourceMappingURL=json-rpc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-rpc.d.ts","sourceRoot":"","sources":["../../src/json-rpc.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;AAC/C,MAAM,MAAM,aAAa,GAAG,GAAG,CAAC;AAChC,MAAM,MAAM,cAAc,GAAG,KAAK,CAAC;AAEnC,MAAM,WAAW,cAAc;IAC7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