@aroha-sdk/core 1.0.0 → 1.2.0
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/dist/crypto/encryption.d.ts +39 -0
- package/dist/crypto/encryption.d.ts.map +1 -0
- package/dist/crypto/encryption.js +88 -0
- package/dist/crypto/encryption.js.map +1 -0
- package/dist/crypto/index.d.ts +3 -0
- package/dist/crypto/index.d.ts.map +1 -0
- package/dist/crypto/index.js +3 -0
- package/dist/crypto/index.js.map +1 -0
- package/dist/crypto/signing.d.ts +43 -0
- package/dist/crypto/signing.d.ts.map +1 -0
- package/dist/crypto/signing.js +80 -0
- package/dist/crypto/signing.js.map +1 -0
- package/dist/identity/credentials.d.ts +81 -0
- package/dist/identity/credentials.d.ts.map +1 -0
- package/dist/identity/credentials.js +82 -0
- package/dist/identity/credentials.js.map +1 -0
- package/dist/identity/did-cache.d.ts +46 -0
- package/dist/identity/did-cache.d.ts.map +1 -0
- package/dist/identity/did-cache.js +90 -0
- package/dist/identity/did-cache.js.map +1 -0
- package/dist/identity/did.d.ts +139 -0
- package/dist/identity/did.d.ts.map +1 -0
- package/dist/identity/did.js +291 -0
- package/dist/identity/did.js.map +1 -0
- package/dist/identity/index.d.ts +5 -0
- package/dist/identity/index.d.ts.map +1 -0
- package/dist/identity/index.js +5 -0
- package/dist/identity/index.js.map +1 -0
- package/dist/identity/web-did.d.ts +131 -0
- package/dist/identity/web-did.d.ts.map +1 -0
- package/dist/identity/web-did.js +338 -0
- package/dist/identity/web-did.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/messages/envelope.d.ts +102 -0
- package/dist/messages/envelope.d.ts.map +1 -0
- package/dist/messages/envelope.js +106 -0
- package/dist/messages/envelope.js.map +1 -0
- package/dist/messages/idempotency.d.ts +61 -0
- package/dist/messages/idempotency.d.ts.map +1 -0
- package/dist/messages/idempotency.js +93 -0
- package/dist/messages/idempotency.js.map +1 -0
- package/dist/messages/index.d.ts +5 -0
- package/dist/messages/index.d.ts.map +1 -0
- package/dist/messages/index.js +5 -0
- package/dist/messages/index.js.map +1 -0
- package/dist/messages/nonce.d.ts +60 -0
- package/dist/messages/nonce.d.ts.map +1 -0
- package/dist/messages/nonce.js +94 -0
- package/dist/messages/nonce.js.map +1 -0
- package/dist/messages/types.d.ts +302 -0
- package/dist/messages/types.d.ts.map +1 -0
- package/dist/messages/types.js +38 -0
- package/dist/messages/types.js.map +1 -0
- package/dist/transport/client.d.ts +79 -0
- package/dist/transport/client.d.ts.map +1 -0
- package/dist/transport/client.js +182 -0
- package/dist/transport/client.js.map +1 -0
- package/dist/transport/http-utils.d.ts +3 -0
- package/dist/transport/http-utils.d.ts.map +1 -0
- package/dist/transport/http-utils.js +27 -0
- package/dist/transport/http-utils.js.map +1 -0
- package/dist/transport/index.d.ts +4 -0
- package/dist/transport/index.d.ts.map +1 -0
- package/dist/transport/index.js +4 -0
- package/dist/transport/index.js.map +1 -0
- package/dist/transport/server.d.ts +123 -0
- package/dist/transport/server.d.ts.map +1 -0
- package/dist/transport/server.js +251 -0
- package/dist/transport/server.js.map +1 -0
- package/package.json +5 -1
- package/tsconfig.json +0 -10
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Aroha Protocol — Layer 3 Message Type Definitions
|
|
3
|
+
*
|
|
4
|
+
* All message types defined by the Aroha spec (aroha/1.0).
|
|
5
|
+
* These are the ONLY valid values for the "type" field in a Aroha envelope.
|
|
6
|
+
*
|
|
7
|
+
* Applications may not invent new top-level message types — they extend
|
|
8
|
+
* behavior through the "body" field only.
|
|
9
|
+
*/
|
|
10
|
+
// ─── Error Codes ──────────────────────────────────────────────────────────────
|
|
11
|
+
export var ArohaErrorCode;
|
|
12
|
+
(function (ArohaErrorCode) {
|
|
13
|
+
// Auth / access errors
|
|
14
|
+
ArohaErrorCode["Unauthorized"] = "Aroha_UNAUTHORIZED";
|
|
15
|
+
ArohaErrorCode["Forbidden"] = "Aroha_FORBIDDEN";
|
|
16
|
+
// Protocol errors
|
|
17
|
+
ArohaErrorCode["InvalidSignature"] = "Aroha_INVALID_SIGNATURE";
|
|
18
|
+
ArohaErrorCode["ExpiredMessage"] = "Aroha_EXPIRED_MESSAGE";
|
|
19
|
+
ArohaErrorCode["ReplayDetected"] = "Aroha_REPLAY_DETECTED";
|
|
20
|
+
ArohaErrorCode["UnknownCapability"] = "Aroha_UNKNOWN_CAPABILITY";
|
|
21
|
+
ArohaErrorCode["TrustLevelInsufficient"] = "Aroha_TRUST_LEVEL_INSUFFICIENT";
|
|
22
|
+
// Saga errors
|
|
23
|
+
ArohaErrorCode["ReservationFailed"] = "Aroha_RESERVATION_FAILED";
|
|
24
|
+
ArohaErrorCode["ReservationExpired"] = "Aroha_RESERVATION_EXPIRED";
|
|
25
|
+
ArohaErrorCode["CommitFailed"] = "Aroha_COMMIT_FAILED";
|
|
26
|
+
ArohaErrorCode["CancelFailed"] = "Aroha_CANCEL_FAILED";
|
|
27
|
+
ArohaErrorCode["InvalidToken"] = "Aroha_INVALID_TOKEN";
|
|
28
|
+
// Availability errors
|
|
29
|
+
ArohaErrorCode["NoInventory"] = "Aroha_NO_INVENTORY";
|
|
30
|
+
ArohaErrorCode["CapacityExceeded"] = "Aroha_CAPACITY_EXCEEDED";
|
|
31
|
+
ArohaErrorCode["ServiceUnavailable"] = "Aroha_SERVICE_UNAVAILABLE";
|
|
32
|
+
// Generic
|
|
33
|
+
ArohaErrorCode["InternalError"] = "Aroha_INTERNAL_ERROR";
|
|
34
|
+
ArohaErrorCode["InvalidParams"] = "Aroha_INVALID_PARAMS";
|
|
35
|
+
// CSN errors
|
|
36
|
+
ArohaErrorCode["CSN_NO_STRUCTURAL_MATCH"] = "CSN_NO_STRUCTURAL_MATCH";
|
|
37
|
+
})(ArohaErrorCode || (ArohaErrorCode = {}));
|
|
38
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/messages/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAqRH,iFAAiF;AAEjF,MAAM,CAAN,IAAY,cA8BX;AA9BD,WAAY,cAAc;IACxB,uBAAuB;IACvB,qDAA4C,CAAA;IAC5C,+CAAyC,CAAA;IAEzC,kBAAkB;IAClB,8DAAiD,CAAA;IACjD,0DAA+C,CAAA;IAC/C,0DAA+C,CAAA;IAC/C,gEAAkD,CAAA;IAClD,2EAAyD,CAAA;IAEzD,cAAc;IACd,gEAAkD,CAAA;IAClD,kEAAmD,CAAA;IACnD,sDAA6C,CAAA;IAC7C,sDAA6C,CAAA;IAC7C,sDAA6C,CAAA;IAE7C,sBAAsB;IACtB,oDAA4C,CAAA;IAC5C,8DAAiD,CAAA;IACjD,kEAAmD,CAAA;IAEnD,UAAU;IACV,wDAA8C,CAAA;IAC9C,wDAA8C,CAAA;IAE9C,aAAa;IACb,qEAAmD,CAAA;AACrD,CAAC,EA9BW,cAAc,KAAd,cAAc,QA8BzB"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Aroha Protocol — Layer 0 Transport Client
|
|
3
|
+
*
|
|
4
|
+
* Sends Aroha messages to remote agents over HTTPS.
|
|
5
|
+
* Handles streaming responses via WebSocket.
|
|
6
|
+
*
|
|
7
|
+
* This is protocol infrastructure. It does not know what the messages
|
|
8
|
+
* mean or what to do with responses — that is the orchestrator's job.
|
|
9
|
+
*/
|
|
10
|
+
import { type ArohaEnvelope } from "../messages/envelope.js";
|
|
11
|
+
export interface ConnectionPoolConfig {
|
|
12
|
+
/**
|
|
13
|
+
* Maximum number of concurrent connections per origin (scheme+host+port).
|
|
14
|
+
* Default: 10
|
|
15
|
+
*/
|
|
16
|
+
connections?: number;
|
|
17
|
+
/**
|
|
18
|
+
* How long an idle connection is kept alive in ms.
|
|
19
|
+
* Default: 60_000 (60 seconds)
|
|
20
|
+
*/
|
|
21
|
+
keepAliveTimeoutMs?: number;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* AgentConnectionPool — maintains persistent HTTP connections per origin.
|
|
25
|
+
*
|
|
26
|
+
* Uses undici (built into Node.js 22+) to pool connections, eliminating
|
|
27
|
+
* the TCP+TLS handshake overhead on every ArohaClient.send() call.
|
|
28
|
+
*
|
|
29
|
+
* For an orchestrator talking to 20 agents at 100 msg/s, this removes
|
|
30
|
+
* ~2,000 TLS handshakes per second (~400ms each = 800s of saved latency/s).
|
|
31
|
+
*
|
|
32
|
+
* Usage:
|
|
33
|
+
* const pool = new AgentConnectionPool();
|
|
34
|
+
* const client = new ArohaClient({ pool });
|
|
35
|
+
*/
|
|
36
|
+
export declare class AgentConnectionPool {
|
|
37
|
+
private readonly connections;
|
|
38
|
+
private readonly keepAliveTimeoutMs;
|
|
39
|
+
private readonly pools;
|
|
40
|
+
constructor(config?: ConnectionPoolConfig);
|
|
41
|
+
fetch(url: string, init: RequestInit): Promise<Response>;
|
|
42
|
+
destroy(): Promise<void>;
|
|
43
|
+
get poolCount(): number;
|
|
44
|
+
}
|
|
45
|
+
export interface SendOptions {
|
|
46
|
+
timeoutMs?: number;
|
|
47
|
+
}
|
|
48
|
+
export interface ArohaClientOptions {
|
|
49
|
+
/** Optional connection pool for persistent keep-alive connections. */
|
|
50
|
+
pool?: AgentConnectionPool;
|
|
51
|
+
}
|
|
52
|
+
export declare class ArohaClient {
|
|
53
|
+
private readonly pool?;
|
|
54
|
+
constructor(opts?: ArohaClientOptions);
|
|
55
|
+
/**
|
|
56
|
+
* Send an Aroha message and await a synchronous response.
|
|
57
|
+
* Returns the response ArohaEnvelope, or null when the provider responds
|
|
58
|
+
* with 202 Accepted (async / streaming — use stream() for WebSocket events).
|
|
59
|
+
*/
|
|
60
|
+
send(endpoint: string, envelope: ArohaEnvelope, opts?: SendOptions): Promise<ArohaEnvelope | null>;
|
|
61
|
+
/**
|
|
62
|
+
* Open a WebSocket stream to receive ArohaStream events for a given saga.
|
|
63
|
+
*
|
|
64
|
+
* @param wsEndpoint WebSocket URL (wss://<host>/aroha/stream)
|
|
65
|
+
* @param correlationId The saga correlationId to subscribe to
|
|
66
|
+
* @param streamToken One-time token from the 202 response (recommended)
|
|
67
|
+
*/
|
|
68
|
+
stream(wsEndpoint: string, correlationId: string, streamToken?: string): AsyncIterable<ArohaEnvelope>;
|
|
69
|
+
/**
|
|
70
|
+
* Fetch the DID Document from an agent's well-known endpoint.
|
|
71
|
+
*/
|
|
72
|
+
fetchDIDDocument(agentBaseUrl: string): Promise<Record<string, unknown>>;
|
|
73
|
+
}
|
|
74
|
+
export declare class ArohaTransportError extends Error {
|
|
75
|
+
readonly statusCode: number;
|
|
76
|
+
readonly body: string;
|
|
77
|
+
constructor(statusCode: number, body: string);
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/transport/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAI7D,MAAM,WAAW,oBAAoB;IACnC;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED;;;;;;;;;;;;GAYG;AACH,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAS;IAE5C,OAAO,CAAC,QAAQ,CAAC,KAAK,CAA4C;gBAEtD,MAAM,GAAE,oBAAyB;IAKvC,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC;IAkBxD,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAK9B,IAAI,SAAS,IAAI,MAAM,CAEtB;CACF;AAID,MAAM,WAAW,WAAW;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,kBAAkB;IACjC,sEAAsE;IACtE,IAAI,CAAC,EAAE,mBAAmB,CAAC;CAC5B;AAID,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAsB;gBAEhC,IAAI,GAAE,kBAAuB;IAIzC;;;;OAIG;IACG,IAAI,CACR,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,aAAa,EACvB,IAAI,GAAE,WAAgB,GACrB,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC;IAiChC;;;;;;OAMG;IACH,MAAM,CACJ,UAAU,EAAE,MAAM,EAClB,aAAa,EAAE,MAAM,EACrB,WAAW,CAAC,EAAE,MAAM,GACnB,aAAa,CAAC,aAAa,CAAC;IA8D/B;;OAEG;IACG,gBAAgB,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAK/E;AAID,qBAAa,mBAAoB,SAAQ,KAAK;aAE1B,UAAU,EAAE,MAAM;aAClB,IAAI,EAAE,MAAM;gBADZ,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,MAAM;CAK/B"}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Aroha Protocol — Layer 0 Transport Client
|
|
3
|
+
*
|
|
4
|
+
* Sends Aroha messages to remote agents over HTTPS.
|
|
5
|
+
* Handles streaming responses via WebSocket.
|
|
6
|
+
*
|
|
7
|
+
* This is protocol infrastructure. It does not know what the messages
|
|
8
|
+
* mean or what to do with responses — that is the orchestrator's job.
|
|
9
|
+
*/
|
|
10
|
+
import { WebSocket } from "ws";
|
|
11
|
+
/**
|
|
12
|
+
* AgentConnectionPool — maintains persistent HTTP connections per origin.
|
|
13
|
+
*
|
|
14
|
+
* Uses undici (built into Node.js 22+) to pool connections, eliminating
|
|
15
|
+
* the TCP+TLS handshake overhead on every ArohaClient.send() call.
|
|
16
|
+
*
|
|
17
|
+
* For an orchestrator talking to 20 agents at 100 msg/s, this removes
|
|
18
|
+
* ~2,000 TLS handshakes per second (~400ms each = 800s of saved latency/s).
|
|
19
|
+
*
|
|
20
|
+
* Usage:
|
|
21
|
+
* const pool = new AgentConnectionPool();
|
|
22
|
+
* const client = new ArohaClient({ pool });
|
|
23
|
+
*/
|
|
24
|
+
export class AgentConnectionPool {
|
|
25
|
+
connections;
|
|
26
|
+
keepAliveTimeoutMs;
|
|
27
|
+
// Map from origin → undici Pool instance (lazy-created)
|
|
28
|
+
pools = new Map();
|
|
29
|
+
constructor(config = {}) {
|
|
30
|
+
this.connections = config.connections ?? 10;
|
|
31
|
+
this.keepAliveTimeoutMs = config.keepAliveTimeoutMs ?? 60_000;
|
|
32
|
+
}
|
|
33
|
+
async fetch(url, init) {
|
|
34
|
+
const origin = new URL(url).origin;
|
|
35
|
+
let pool = this.pools.get(origin);
|
|
36
|
+
if (!pool) {
|
|
37
|
+
const { Pool } = await import("undici");
|
|
38
|
+
pool = new Pool(origin, {
|
|
39
|
+
connections: this.connections,
|
|
40
|
+
keepAliveTimeout: this.keepAliveTimeoutMs / 1000,
|
|
41
|
+
keepAliveMaxTimeout: this.keepAliveTimeoutMs / 1000,
|
|
42
|
+
});
|
|
43
|
+
this.pools.set(origin, pool);
|
|
44
|
+
}
|
|
45
|
+
const { fetch: undiciFetch } = await import("undici");
|
|
46
|
+
return undiciFetch(url, { ...init, dispatcher: pool });
|
|
47
|
+
}
|
|
48
|
+
async destroy() {
|
|
49
|
+
await Promise.all([...this.pools.values()].map((p) => p.destroy()));
|
|
50
|
+
this.pools.clear();
|
|
51
|
+
}
|
|
52
|
+
get poolCount() {
|
|
53
|
+
return this.pools.size;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
// ─── Client ───────────────────────────────────────────────────────────────────
|
|
57
|
+
export class ArohaClient {
|
|
58
|
+
pool;
|
|
59
|
+
constructor(opts = {}) {
|
|
60
|
+
this.pool = opts.pool;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Send an Aroha message and await a synchronous response.
|
|
64
|
+
* Returns the response ArohaEnvelope, or null when the provider responds
|
|
65
|
+
* with 202 Accepted (async / streaming — use stream() for WebSocket events).
|
|
66
|
+
*/
|
|
67
|
+
async send(endpoint, envelope, opts = {}) {
|
|
68
|
+
const { timeoutMs = 30_000 } = opts;
|
|
69
|
+
const controller = new AbortController();
|
|
70
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
71
|
+
const fetchFn = this.pool
|
|
72
|
+
? (url, init) => this.pool.fetch(url, init)
|
|
73
|
+
: fetch;
|
|
74
|
+
let response;
|
|
75
|
+
try {
|
|
76
|
+
response = await fetchFn(endpoint, {
|
|
77
|
+
method: "POST",
|
|
78
|
+
headers: { "Content-Type": "application/json" },
|
|
79
|
+
body: JSON.stringify(envelope),
|
|
80
|
+
signal: controller.signal,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
finally {
|
|
84
|
+
clearTimeout(timer);
|
|
85
|
+
}
|
|
86
|
+
if (response.status === 202) {
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
if (!response.ok) {
|
|
90
|
+
const error = await response.text();
|
|
91
|
+
throw new ArohaTransportError(response.status, error);
|
|
92
|
+
}
|
|
93
|
+
return response.json();
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Open a WebSocket stream to receive ArohaStream events for a given saga.
|
|
97
|
+
*
|
|
98
|
+
* @param wsEndpoint WebSocket URL (wss://<host>/aroha/stream)
|
|
99
|
+
* @param correlationId The saga correlationId to subscribe to
|
|
100
|
+
* @param streamToken One-time token from the 202 response (recommended)
|
|
101
|
+
*/
|
|
102
|
+
stream(wsEndpoint, correlationId, streamToken) {
|
|
103
|
+
const u = new URL(wsEndpoint);
|
|
104
|
+
u.searchParams.set("cid", correlationId);
|
|
105
|
+
if (streamToken)
|
|
106
|
+
u.searchParams.set("tok", streamToken);
|
|
107
|
+
const ws = new WebSocket(u.toString());
|
|
108
|
+
return {
|
|
109
|
+
[Symbol.asyncIterator]() {
|
|
110
|
+
const queue = [];
|
|
111
|
+
let resolve = null;
|
|
112
|
+
let done = false;
|
|
113
|
+
let error = null;
|
|
114
|
+
ws.on("message", (data) => {
|
|
115
|
+
const envelope = JSON.parse(data.toString());
|
|
116
|
+
if (resolve) {
|
|
117
|
+
const r = resolve;
|
|
118
|
+
resolve = null;
|
|
119
|
+
r({ value: envelope, done: false });
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
queue.push(envelope);
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
ws.on("close", () => {
|
|
126
|
+
done = true;
|
|
127
|
+
if (resolve) {
|
|
128
|
+
const r = resolve;
|
|
129
|
+
resolve = null;
|
|
130
|
+
r({ value: undefined, done: true });
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
ws.on("error", (err) => {
|
|
134
|
+
error = err;
|
|
135
|
+
if (resolve) {
|
|
136
|
+
const r = resolve;
|
|
137
|
+
resolve = null;
|
|
138
|
+
r({ value: undefined, done: true });
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
return {
|
|
142
|
+
next() {
|
|
143
|
+
if (error)
|
|
144
|
+
return Promise.reject(error);
|
|
145
|
+
if (queue.length > 0) {
|
|
146
|
+
return Promise.resolve({ value: queue.shift(), done: false });
|
|
147
|
+
}
|
|
148
|
+
if (done) {
|
|
149
|
+
return Promise.resolve({ value: undefined, done: true });
|
|
150
|
+
}
|
|
151
|
+
return new Promise((r) => { resolve = r; });
|
|
152
|
+
},
|
|
153
|
+
return() {
|
|
154
|
+
ws.close();
|
|
155
|
+
return Promise.resolve({ value: undefined, done: true });
|
|
156
|
+
},
|
|
157
|
+
};
|
|
158
|
+
},
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Fetch the DID Document from an agent's well-known endpoint.
|
|
163
|
+
*/
|
|
164
|
+
async fetchDIDDocument(agentBaseUrl) {
|
|
165
|
+
const response = await fetch(`${agentBaseUrl}/.well-known/aroha-agent.json`);
|
|
166
|
+
if (!response.ok)
|
|
167
|
+
throw new Error(`Failed to fetch DID Document from ${agentBaseUrl}`);
|
|
168
|
+
return response.json();
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
// ─── Errors ───────────────────────────────────────────────────────────────────
|
|
172
|
+
export class ArohaTransportError extends Error {
|
|
173
|
+
statusCode;
|
|
174
|
+
body;
|
|
175
|
+
constructor(statusCode, body) {
|
|
176
|
+
super(`Aroha transport error ${statusCode}: ${body}`);
|
|
177
|
+
this.statusCode = statusCode;
|
|
178
|
+
this.body = body;
|
|
179
|
+
this.name = "ArohaTransportError";
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/transport/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAkB/B;;;;;;;;;;;;GAYG;AACH,MAAM,OAAO,mBAAmB;IACb,WAAW,CAAS;IACpB,kBAAkB,CAAS;IAC5C,wDAAwD;IACvC,KAAK,GAAG,IAAI,GAAG,EAAiC,CAAC;IAElE,YAAY,SAA+B,EAAE;QAC3C,IAAI,CAAC,WAAW,GAAS,MAAM,CAAC,WAAW,IAAU,EAAE,CAAC;QACxD,IAAI,CAAC,kBAAkB,GAAG,MAAM,CAAC,kBAAkB,IAAI,MAAM,CAAC;IAChE,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,GAAW,EAAE,IAAiB;QACxC,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC;QACnC,IAAI,IAAI,GAAG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AAE;YAAE,MAAM,IAAI,KAAK,CAAC,qCAAqC,YAAY,EAAE,CAAC,CAAC;QACvF,OAAO,QAAQ,CAAC,IAAI,EAAsC,CAAC;IAC7D,CAAC;CACF;AAED,iFAAiF;AAEjF,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IAE1B;IACA;IAFlB,YACkB,UAAkB,EAClB,IAAY;QAE5B,KAAK,CAAC,yBAAyB,UAAU,KAAK,IAAI,EAAE,CAAC,CAAC;QAHtC,eAAU,GAAV,UAAU,CAAQ;QAClB,SAAI,GAAJ,IAAI,CAAQ;QAG5B,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACpC,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-utils.d.ts","sourceRoot":"","sources":["../../src/transport/http-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,MAAM,CAAC;AAE5C,wBAAgB,QAAQ,CAAC,GAAG,EAAE,eAAe,EAAE,QAAQ,SAAY,GAAG,OAAO,CAAC,MAAM,CAAC,CA2BpF"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export function readBody(req, maxBytes = 1_048_576) {
|
|
2
|
+
return new Promise((resolve, reject) => {
|
|
3
|
+
const chunks = [];
|
|
4
|
+
let totalBytes = 0;
|
|
5
|
+
let settled = false;
|
|
6
|
+
const done = (fn) => {
|
|
7
|
+
if (settled)
|
|
8
|
+
return;
|
|
9
|
+
settled = true;
|
|
10
|
+
fn();
|
|
11
|
+
};
|
|
12
|
+
req.on("data", (chunk) => {
|
|
13
|
+
totalBytes += chunk.length;
|
|
14
|
+
if (totalBytes > maxBytes) {
|
|
15
|
+
const err = new Error("PAYLOAD_TOO_LARGE");
|
|
16
|
+
err.code = "PAYLOAD_TOO_LARGE";
|
|
17
|
+
done(() => reject(err));
|
|
18
|
+
req.destroy();
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
chunks.push(chunk);
|
|
22
|
+
});
|
|
23
|
+
req.on("end", () => done(() => resolve(Buffer.concat(chunks).toString("utf8"))));
|
|
24
|
+
req.on("error", (err) => done(() => reject(err)));
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=http-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-utils.js","sourceRoot":"","sources":["../../src/transport/http-utils.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,QAAQ,CAAC,GAAoB,EAAE,QAAQ,GAAG,SAAS;IACjE,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,MAAM,MAAM,GAAa,EAAE,CAAC;QAC5B,IAAI,UAAU,GAAG,CAAC,CAAC;QACnB,IAAI,OAAO,GAAG,KAAK,CAAC;QAEpB,MAAM,IAAI,GAAG,CAAC,EAAc,EAAE,EAAE;YAC9B,IAAI,OAAO;gBAAE,OAAO;YACpB,OAAO,GAAG,IAAI,CAAC;YACf,EAAE,EAAE,CAAC;QACP,CAAC,CAAC;QAEF,GAAG,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,KAAa,EAAE,EAAE;YAC/B,UAAU,IAAI,KAAK,CAAC,MAAM,CAAC;YAC3B,IAAI,UAAU,GAAG,QAAQ,EAAE,CAAC;gBAC1B,MAAM,GAAG,GAAG,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;gBAC1C,GAA6B,CAAC,IAAI,GAAG,mBAAmB,CAAC;gBAC1D,IAAI,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;gBACxB,GAAG,CAAC,OAAO,EAAE,CAAC;gBACd,OAAO;YACT,CAAC;YACD,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACrB,CAAC,CAAC,CAAC;QAEH,GAAG,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;QACjF,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACpD,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/transport/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/transport/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Aroha Protocol — Layer 0 Transport Server (core)
|
|
3
|
+
*
|
|
4
|
+
* Responsibilities (protocol only):
|
|
5
|
+
* - Serve /.well-known/aroha-agent.json
|
|
6
|
+
* - Accept POST /aroha/v1, validate envelope (sig + nonce + expiry + recipient)
|
|
7
|
+
* - Run optional middleware chain before dispatch
|
|
8
|
+
* - Dispatch valid envelopes to the application handler
|
|
9
|
+
* - Handle WebSocket streams
|
|
10
|
+
* - Delegate unknown HTTP routes to optional httpRoutes handlers
|
|
11
|
+
*
|
|
12
|
+
* What this server deliberately does NOT do:
|
|
13
|
+
* - RBAC / credential verification → @aroha-sdk/credentials createRbacMiddleware()
|
|
14
|
+
* - Credential registry endpoints → @aroha-sdk/credentials credentialRegistryRoutes()
|
|
15
|
+
* - Settlement → @aroha-sdk/settlement
|
|
16
|
+
*/
|
|
17
|
+
import { type IncomingMessage, type ServerResponse } from "http";
|
|
18
|
+
import { type ArohaEnvelope } from "../messages/envelope.js";
|
|
19
|
+
import { type NonceStore } from "../messages/nonce.js";
|
|
20
|
+
import { type DIDDocument } from "../identity/did.js";
|
|
21
|
+
/**
|
|
22
|
+
* A ArohaMiddleware runs after envelope validation and before dispatch.
|
|
23
|
+
* Call reject() to short-circuit with an HTTP error. Return without calling
|
|
24
|
+
* reject to pass the envelope to the next middleware or the handler.
|
|
25
|
+
*/
|
|
26
|
+
export type ArohaMiddleware = (envelope: ArohaEnvelope, reject: (status: number, errorCode: string, reason: string) => void) => Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* An additional HTTP route registered on ArohaServer.
|
|
29
|
+
* Use credentialRegistryRoutes() from @aroha-sdk/credentials to mount the
|
|
30
|
+
* credential registry without coupling aroha-core to auth logic.
|
|
31
|
+
*/
|
|
32
|
+
export interface ArohaHttpRoute {
|
|
33
|
+
method: string;
|
|
34
|
+
test: (url: string) => boolean;
|
|
35
|
+
handle: (req: IncomingMessage, res: ServerResponse) => Promise<void>;
|
|
36
|
+
}
|
|
37
|
+
export type MessageHandler = (envelope: ArohaEnvelope, respond: (reply: ArohaEnvelope) => void, stream: (event: ArohaEnvelope) => void) => Promise<void>;
|
|
38
|
+
import type { PublicKeyResolver } from "../identity/did-cache.js";
|
|
39
|
+
export type { PublicKeyResolver };
|
|
40
|
+
export interface ArohaServerOptions {
|
|
41
|
+
agentDID: string;
|
|
42
|
+
didDocument: DIDDocument;
|
|
43
|
+
port: number;
|
|
44
|
+
onMessage: MessageHandler;
|
|
45
|
+
resolvePublicKey: PublicKeyResolver;
|
|
46
|
+
/**
|
|
47
|
+
* Optional did:aroha-web: document to serve at the well-known path.
|
|
48
|
+
* When set, the server serves GET /.well-known/aroha/agents/{path}/did.json
|
|
49
|
+
* in addition to the standard /.well-known/aroha-agent.json endpoint.
|
|
50
|
+
*/
|
|
51
|
+
webDIDDocument?: import("../identity/web-did.js").WebDIDDocument;
|
|
52
|
+
/**
|
|
53
|
+
* Middleware chain — runs in order after envelope validation.
|
|
54
|
+
* Any middleware may call reject() to abort processing.
|
|
55
|
+
* Mount RBAC here via createRbacMiddleware() from @aroha-sdk/credentials.
|
|
56
|
+
*/
|
|
57
|
+
middleware?: ArohaMiddleware[];
|
|
58
|
+
/**
|
|
59
|
+
* Additional HTTP route handlers mounted alongside /aroha/v1.
|
|
60
|
+
* Checked in order after built-in routes. First match wins.
|
|
61
|
+
* Mount credential registry here via credentialRegistryRoutes() from @aroha-sdk/credentials.
|
|
62
|
+
*/
|
|
63
|
+
httpRoutes?: ArohaHttpRoute[];
|
|
64
|
+
/**
|
|
65
|
+
* Trusted mesh / VPC mode: skip Ed25519 signature verification for senders
|
|
66
|
+
* whose DID matches this predicate. Use within private networks protected by
|
|
67
|
+
* mTLS or a VPC where network-level trust replaces cryptographic identity.
|
|
68
|
+
* Configure via @aroha-sdk/trusted-mesh createTrustedMeshOptions().
|
|
69
|
+
*/
|
|
70
|
+
bypassSignatureFor?: (senderDID: string) => boolean;
|
|
71
|
+
/**
|
|
72
|
+
* Development mode — skips ALL cryptographic validation (signatures, nonce
|
|
73
|
+
* replay, expiry) so you can spin up agents with zero ceremony on localhost.
|
|
74
|
+
*
|
|
75
|
+
* Set devMode: false (or omit) before deploying to production. The flip
|
|
76
|
+
* requires no other code changes — your capability handlers are identical.
|
|
77
|
+
*
|
|
78
|
+
* @aroha-sdk/micro sets this automatically when devMode: true is passed there.
|
|
79
|
+
*/
|
|
80
|
+
devMode?: boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Minimum client protocol version accepted.
|
|
83
|
+
* Requests with X-Aroha-Client-Version below this are rejected with 400.
|
|
84
|
+
* Default: "1.0".
|
|
85
|
+
*/
|
|
86
|
+
minClientVersion?: string;
|
|
87
|
+
/**
|
|
88
|
+
* Custom nonce store for distributed deployments.
|
|
89
|
+
* Defaults to in-process MapNonceStore (breaks in multi-instance deployments).
|
|
90
|
+
* In production, inject a Redis-backed NonceStore to share nonce state
|
|
91
|
+
* across all instances and prevent cross-instance replay attacks.
|
|
92
|
+
*/
|
|
93
|
+
nonceStore?: NonceStore;
|
|
94
|
+
/**
|
|
95
|
+
* Clock skew tolerance applied to envelope expiry checks, in milliseconds.
|
|
96
|
+
* Recommended value for cross-region deployments: 5000.
|
|
97
|
+
* Default: 0 (strict — rejects messages expired by even 1ms).
|
|
98
|
+
*/
|
|
99
|
+
clockToleranceMs?: number;
|
|
100
|
+
/**
|
|
101
|
+
* Maximum allowed request body size in bytes.
|
|
102
|
+
* Requests exceeding this limit are rejected with HTTP 413.
|
|
103
|
+
* Default: 1_048_576 (1 MiB).
|
|
104
|
+
*/
|
|
105
|
+
maxBodyBytes?: number;
|
|
106
|
+
}
|
|
107
|
+
export declare class ArohaServer {
|
|
108
|
+
private readonly opts;
|
|
109
|
+
private readonly nonceRegistry;
|
|
110
|
+
private readonly wsClients;
|
|
111
|
+
private readonly streamTokens;
|
|
112
|
+
private server;
|
|
113
|
+
private wss;
|
|
114
|
+
constructor(opts: ArohaServerOptions);
|
|
115
|
+
start(): Promise<void>;
|
|
116
|
+
stop(): Promise<void>;
|
|
117
|
+
private versionLessThan;
|
|
118
|
+
private writeJson;
|
|
119
|
+
private handleHttp;
|
|
120
|
+
private handleInbound;
|
|
121
|
+
private handleWsConnection;
|
|
122
|
+
}
|
|
123
|
+
//# sourceMappingURL=server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/transport/server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAgB,KAAK,eAAe,EAAE,KAAK,cAAc,EAAE,MAAM,MAAM,CAAC;AAI/E,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAE7D,OAAO,EAAiB,KAAK,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACtE,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM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