@onsignet/daemon 0.1.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/agent-process.d.ts +19 -0
- package/dist/agent-process.d.ts.map +1 -0
- package/dist/agent-process.js +102 -0
- package/dist/agent-process.js.map +1 -0
- package/dist/audit-log.d.ts +23 -0
- package/dist/audit-log.d.ts.map +1 -0
- package/dist/audit-log.js +75 -0
- package/dist/audit-log.js.map +1 -0
- package/dist/config.d.ts +30 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +104 -0
- package/dist/config.js.map +1 -0
- package/dist/errors.d.ts +23 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +24 -0
- package/dist/errors.js.map +1 -0
- package/dist/identity.d.ts +39 -0
- package/dist/identity.d.ts.map +1 -0
- package/dist/identity.js +107 -0
- package/dist/identity.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +524 -0
- package/dist/index.js.map +1 -0
- package/dist/policies.d.ts +11 -0
- package/dist/policies.d.ts.map +1 -0
- package/dist/policies.js +58 -0
- package/dist/policies.js.map +1 -0
- package/dist/relay-client.d.ts +34 -0
- package/dist/relay-client.d.ts.map +1 -0
- package/dist/relay-client.js +170 -0
- package/dist/relay-client.js.map +1 -0
- package/dist/server.d.ts +93 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +460 -0
- package/dist/server.js.map +1 -0
- package/package.json +35 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"relay-client.d.ts","sourceRoot":"","sources":["../src/relay-client.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAIL,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACnB,KAAK,aAAa,EACnB,MAAM,gBAAgB,CAAC;AAMxB,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,EAAE,MAAM,CAAC;IACzB,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,EAAE,cAAc,CAAC;IAC/B,SAAS,EAAE,CAAC,KAAK,EAAE,kBAAkB,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/D,kBAAkB,CAAC,EAAE,CAAC,UAAU,EAAE,OAAO,KAAK,IAAI,CAAC;IACnD,gBAAgB,CAAC,EAAE,CAAC,QAAQ,EAAE,gBAAgB,KAAK,IAAI,CAAC;IACxD,eAAe,CAAC,EAAE,CAAC,WAAW,EAAE,aAAa,KAAK,IAAI,CAAC;CACxD;AAED,qBAAa,WAAW;IACtB,OAAO,CAAC,OAAO,CAAqB;IACpC,OAAO,CAAC,EAAE,CAA0B;IACpC,OAAO,CAAC,OAAO,CAAsB;IACrC,OAAO,CAAC,cAAc,CAA8C;IACpE,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,iBAAiB,CAAS;gBAEtB,OAAO,EAAE,kBAAkB;IAIvC,OAAO,IAAI,IAAI;IA4Gf,OAAO,CAAC,iBAAiB;IASzB,IAAI,CAAC,IAAI,EAAE,kBAAkB,GAAG,OAAO;IAUvC,OAAO,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO;IAUlC,UAAU,IAAI,IAAI;IAclB,WAAW,IAAI,OAAO;CAGvB"}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* WebSocket client to relay: signed challenge auth, send envelopes, reconnect with backoff.
|
|
4
|
+
*/
|
|
5
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
6
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.RelayClient = void 0;
|
|
10
|
+
const ws_1 = __importDefault(require("ws"));
|
|
11
|
+
const core_1 = require("@onsignet/core");
|
|
12
|
+
const INITIAL_BACKOFF_MS = 500;
|
|
13
|
+
const MAX_BACKOFF_MS = 30_000;
|
|
14
|
+
const VERSION = process.env.SIGNET_VERSION ?? "0.1.0";
|
|
15
|
+
class RelayClient {
|
|
16
|
+
options;
|
|
17
|
+
ws = null;
|
|
18
|
+
backoff = INITIAL_BACKOFF_MS;
|
|
19
|
+
reconnectTimer = null;
|
|
20
|
+
registered = false;
|
|
21
|
+
awaitingChallenge = false;
|
|
22
|
+
constructor(options) {
|
|
23
|
+
this.options = options;
|
|
24
|
+
}
|
|
25
|
+
connect() {
|
|
26
|
+
if (this.ws && this.ws.readyState === ws_1.default.OPEN)
|
|
27
|
+
return;
|
|
28
|
+
const ws = new ws_1.default(this.options.relayUrl);
|
|
29
|
+
this.ws = ws;
|
|
30
|
+
this.awaitingChallenge = true;
|
|
31
|
+
ws.on("open", () => {
|
|
32
|
+
// Wait for challenge from relay before sending handshake
|
|
33
|
+
});
|
|
34
|
+
ws.on("message", (data) => {
|
|
35
|
+
const raw = typeof data === "string" ? data : String(data);
|
|
36
|
+
// Phase 1: waiting for challenge from relay
|
|
37
|
+
if (this.awaitingChallenge) {
|
|
38
|
+
try {
|
|
39
|
+
const msg = JSON.parse(raw);
|
|
40
|
+
if (msg.type === "challenge" && typeof msg.challenge === "string") {
|
|
41
|
+
const challengeBytes = (0, core_1.decodeBase64)(msg.challenge);
|
|
42
|
+
const signature = (0, core_1.sign)(challengeBytes, this.options.ed25519KeyPair.secretKey);
|
|
43
|
+
ws.send(JSON.stringify({
|
|
44
|
+
nodeId: this.options.nodeId,
|
|
45
|
+
signature: (0, core_1.encodeBase64)(signature),
|
|
46
|
+
version: VERSION,
|
|
47
|
+
}));
|
|
48
|
+
this.awaitingChallenge = false;
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
// Backward compat: if relay doesn't send challenge, send plain handshake
|
|
52
|
+
ws.send(JSON.stringify({ nodeId: this.options.nodeId, version: VERSION }));
|
|
53
|
+
this.awaitingChallenge = false;
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
// ignore
|
|
57
|
+
}
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
// Phase 2: waiting for registration confirmation
|
|
61
|
+
if (!this.registered) {
|
|
62
|
+
try {
|
|
63
|
+
const msg = JSON.parse(raw);
|
|
64
|
+
if (msg.type === "registered") {
|
|
65
|
+
this.registered = true;
|
|
66
|
+
this.backoff = INITIAL_BACKOFF_MS;
|
|
67
|
+
if (msg.warning)
|
|
68
|
+
console.warn(`[relay] ${msg.warning}`);
|
|
69
|
+
this.options.onConnectionChange?.(true);
|
|
70
|
+
}
|
|
71
|
+
else if (msg.type === "error") {
|
|
72
|
+
console.error("[relay] Auth rejected:", raw);
|
|
73
|
+
ws.close();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
// ignore
|
|
78
|
+
}
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
// Phase 3: normal operation
|
|
82
|
+
try {
|
|
83
|
+
const parsed = JSON.parse(raw);
|
|
84
|
+
if (parsed.type === "signet_web_chat" && typeof parsed.sessionId === "string") {
|
|
85
|
+
this.options.onWebChatMessage?.({
|
|
86
|
+
sessionId: parsed.sessionId,
|
|
87
|
+
visitorAuthLevel: typeof parsed.visitorAuthLevel === "string" ? parsed.visitorAuthLevel : "anonymous",
|
|
88
|
+
content: parsed.content,
|
|
89
|
+
});
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
if (parsed.type === "key_revocation" && parsed.revocation) {
|
|
93
|
+
this.options.onKeyRevocation?.(parsed.revocation);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
if (parsed.type === "error" && parsed.code === "E_KEY_REVOKED") {
|
|
97
|
+
console.error("[relay] This node's key has been revoked!");
|
|
98
|
+
this.options.onConnectionChange?.(false);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
const envelope = parsed;
|
|
102
|
+
if (envelope.protocol && envelope.to !== undefined) {
|
|
103
|
+
void this.options.onMessage(envelope);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
// ignore non-envelope messages
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
ws.on("close", () => {
|
|
111
|
+
this.ws = null;
|
|
112
|
+
this.registered = false;
|
|
113
|
+
this.awaitingChallenge = false;
|
|
114
|
+
this.options.onConnectionChange?.(false);
|
|
115
|
+
this.scheduleReconnect();
|
|
116
|
+
});
|
|
117
|
+
ws.on("error", () => {
|
|
118
|
+
this.options.onConnectionChange?.(false);
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
scheduleReconnect() {
|
|
122
|
+
if (this.reconnectTimer)
|
|
123
|
+
return;
|
|
124
|
+
this.reconnectTimer = setTimeout(() => {
|
|
125
|
+
this.reconnectTimer = null;
|
|
126
|
+
this.connect();
|
|
127
|
+
this.backoff = Math.min(this.backoff * 2, MAX_BACKOFF_MS);
|
|
128
|
+
}, this.backoff);
|
|
129
|
+
}
|
|
130
|
+
send(wire) {
|
|
131
|
+
if (!this.ws || this.ws.readyState !== ws_1.default.OPEN || !this.registered)
|
|
132
|
+
return false;
|
|
133
|
+
try {
|
|
134
|
+
this.ws.send(JSON.stringify(wire));
|
|
135
|
+
return true;
|
|
136
|
+
}
|
|
137
|
+
catch {
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
sendRaw(payload) {
|
|
142
|
+
if (!this.ws || this.ws.readyState !== ws_1.default.OPEN || !this.registered)
|
|
143
|
+
return false;
|
|
144
|
+
try {
|
|
145
|
+
this.ws.send(JSON.stringify(payload));
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
catch {
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
disconnect() {
|
|
153
|
+
if (this.reconnectTimer) {
|
|
154
|
+
clearTimeout(this.reconnectTimer);
|
|
155
|
+
this.reconnectTimer = null;
|
|
156
|
+
}
|
|
157
|
+
if (this.ws) {
|
|
158
|
+
this.ws.close();
|
|
159
|
+
this.ws = null;
|
|
160
|
+
}
|
|
161
|
+
this.registered = false;
|
|
162
|
+
this.awaitingChallenge = false;
|
|
163
|
+
this.options.onConnectionChange?.(false);
|
|
164
|
+
}
|
|
165
|
+
isConnected() {
|
|
166
|
+
return this.ws?.readyState === ws_1.default.OPEN && this.registered;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
exports.RelayClient = RelayClient;
|
|
170
|
+
//# sourceMappingURL=relay-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"relay-client.js","sourceRoot":"","sources":["../src/relay-client.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;AAEH,4CAA2B;AAC3B,yCAOwB;AAExB,MAAM,kBAAkB,GAAG,GAAG,CAAC;AAC/B,MAAM,cAAc,GAAG,MAAM,CAAC;AAC9B,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,cAAc,IAAI,OAAO,CAAC;AAkBtD,MAAa,WAAW;IACd,OAAO,CAAqB;IAC5B,EAAE,GAAqB,IAAI,CAAC;IAC5B,OAAO,GAAG,kBAAkB,CAAC;IAC7B,cAAc,GAAyC,IAAI,CAAC;IAC5D,UAAU,GAAG,KAAK,CAAC;IACnB,iBAAiB,GAAG,KAAK,CAAC;IAElC,YAAY,OAA2B;QACrC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED,OAAO;QACL,IAAI,IAAI,CAAC,EAAE,IAAI,IAAI,CAAC,EAAE,CAAC,UAAU,KAAK,YAAS,CAAC,IAAI;YAAE,OAAO;QAC7D,MAAM,EAAE,GAAG,IAAI,YAAS,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QAChD,IAAI,CAAC,EAAE,GAAG,EAAE,CA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CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;YAClC,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC;QAC7B,CAAC;QACD,IAAI,IAAI,CAAC,EAAE,EAAE,CAAC;YACZ,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC;YAChB,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC;QACjB,CAAC;QACD,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;QACxB,IAAI,CAAC,iBAAiB,GAAG,KAAK,CAAC;QAC/B,IAAI,CAAC,OAAO,CAAC,kBAAkB,EAAE,CAAC,KAAK,CAAC,CAAC;IAC3C,CAAC;IAED,WAAW;QACT,OAAO,IAAI,CAAC,EAAE,EAAE,UAAU,KAAK,YAAS,CAAC,IAAI,IAAI,IAAI,CAAC,UAAU,CAAC;IACnE,CAAC;CACF;AAtKD,kCAsKC"}
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local HTTP API: POST /send, GET /messages, GET /status, GET /discover,
|
|
3
|
+
* GET /pending, POST /approve, POST /deny, GET /policies, PUT /policies, GET /activity.
|
|
4
|
+
* Optionally serves oversight UI static files from uiPath.
|
|
5
|
+
*/
|
|
6
|
+
import express from "express";
|
|
7
|
+
import { type SignetEnvelope, type SignetEnvelopeWire } from "@onsignet/core";
|
|
8
|
+
import type { PolicyRule } from "./policies.js";
|
|
9
|
+
export interface PendingMessage {
|
|
10
|
+
messageId: string;
|
|
11
|
+
from: string;
|
|
12
|
+
to: string;
|
|
13
|
+
timestamp: string;
|
|
14
|
+
payload: {
|
|
15
|
+
type: string;
|
|
16
|
+
content: Record<string, unknown>;
|
|
17
|
+
};
|
|
18
|
+
capabilityScope?: string;
|
|
19
|
+
}
|
|
20
|
+
export interface HttpServerDeps {
|
|
21
|
+
nodeId: string;
|
|
22
|
+
relayUrl: string;
|
|
23
|
+
/** Base64 X25519 public key for recipients to use when sending to this daemon. */
|
|
24
|
+
x25519PublicKeyBase64: string;
|
|
25
|
+
ownerAttestation?: boolean;
|
|
26
|
+
isConnected: () => boolean;
|
|
27
|
+
/** to, payload, and recipient X25519 public key (base64) for encryption. */
|
|
28
|
+
buildAndSend: (_to: string, _payload: {
|
|
29
|
+
type: string;
|
|
30
|
+
content: Record<string, unknown>;
|
|
31
|
+
}, _recipientX25519PublicKeyBase64: string) => SignetEnvelopeWire | null;
|
|
32
|
+
getMessages: (_limit?: number) => SignetEnvelope[];
|
|
33
|
+
discoverAgents: () => Promise<Array<{
|
|
34
|
+
nodeId: string;
|
|
35
|
+
x25519PublicKey?: string;
|
|
36
|
+
}>>;
|
|
37
|
+
getPending: () => PendingMessage[];
|
|
38
|
+
approve: (_messageId: string) => boolean;
|
|
39
|
+
deny: (_messageId: string, _reason?: string) => boolean;
|
|
40
|
+
getPolicies: () => PolicyRule[];
|
|
41
|
+
setPolicies: (_rules: PolicyRule[]) => void;
|
|
42
|
+
getActivity: (_limit: number) => {
|
|
43
|
+
entries: unknown[];
|
|
44
|
+
lastHash: string;
|
|
45
|
+
chainValid: boolean;
|
|
46
|
+
};
|
|
47
|
+
/** Optional: get conversation history with a contact (from audit log). */
|
|
48
|
+
getConversationHistory?: (_withNodeId: string, _limit?: number) => Array<{
|
|
49
|
+
timestamp: string;
|
|
50
|
+
event: string;
|
|
51
|
+
messageId?: string;
|
|
52
|
+
from?: string;
|
|
53
|
+
to?: string;
|
|
54
|
+
}>;
|
|
55
|
+
/** Optional: send web chat reply back through relay to browser session. */
|
|
56
|
+
sendWebChatReply?: (_sessionId: string, _content: {
|
|
57
|
+
text: string;
|
|
58
|
+
}) => boolean;
|
|
59
|
+
/** Optional: get pending web chat messages (for dashboard). */
|
|
60
|
+
getWebChatIncoming?: () => Array<{
|
|
61
|
+
sessionId: string;
|
|
62
|
+
visitorAuthLevel: string;
|
|
63
|
+
content: unknown;
|
|
64
|
+
receivedAt: string;
|
|
65
|
+
}>;
|
|
66
|
+
/** Optional path to oversight UI static files (e.g. public folder). */
|
|
67
|
+
uiPath?: string;
|
|
68
|
+
/** Optional marketplace API base URL (legacy). */
|
|
69
|
+
marketplaceApiUrl?: string;
|
|
70
|
+
/** Optional directory API base URL. When set, /directory/* and /contacts/* proxy to directory API with X-AgentMesh-Node-Id. */
|
|
71
|
+
directoryApiUrl?: string;
|
|
72
|
+
/** Optional agent process status (Addendum A1 managed mode). */
|
|
73
|
+
getAgentStatus?: () => {
|
|
74
|
+
status: string;
|
|
75
|
+
pid: number | null;
|
|
76
|
+
restartCount: number;
|
|
77
|
+
lastExitCode: number | null;
|
|
78
|
+
lastExitSignal: string | null;
|
|
79
|
+
};
|
|
80
|
+
/** Revoke this daemon's key. Returns true if broadcast was sent. */
|
|
81
|
+
revokeKey?: (_reason: "compromise" | "rotation" | "decommission", _replacementNodeId?: string) => boolean;
|
|
82
|
+
/** Get list of revoked nodeIds known to this daemon. */
|
|
83
|
+
getRevokedKeys?: () => string[];
|
|
84
|
+
/** Rotate agent identity keys. Returns new nodeId or null on failure. */
|
|
85
|
+
rotateKey?: () => {
|
|
86
|
+
oldNodeId: string;
|
|
87
|
+
newNodeId: string;
|
|
88
|
+
} | null;
|
|
89
|
+
/** Halt the daemon gracefully. */
|
|
90
|
+
halt?: () => void;
|
|
91
|
+
}
|
|
92
|
+
export declare function createHttpServer(deps: HttpServerDeps): express.Application;
|
|
93
|
+
//# sourceMappingURL=server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,OAAwC,MAAM,SAAS,CAAC;AAG/D,OAAO,EAAgB,KAAK,cAAc,EAAE,KAAK,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAC5F,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAehD,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,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