@rookdaemon/agora 0.2.7 → 0.2.9
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 +33 -0
- package/dist/chunk-JUOGKXFN.js +1645 -0
- package/dist/chunk-JUOGKXFN.js.map +1 -0
- package/dist/cli.d.ts +0 -2
- package/dist/cli.js +1163 -1137
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +1613 -25
- package/dist/index.js +1135 -24
- package/dist/index.js.map +1 -1
- package/package.json +11 -2
- package/dist/cli.d.ts.map +0 -1
- package/dist/config.d.ts +0 -59
- package/dist/config.d.ts.map +0 -1
- package/dist/config.js +0 -115
- package/dist/config.js.map +0 -1
- package/dist/discovery/bootstrap.d.ts +0 -32
- package/dist/discovery/bootstrap.d.ts.map +0 -1
- package/dist/discovery/bootstrap.js +0 -36
- package/dist/discovery/bootstrap.js.map +0 -1
- package/dist/discovery/peer-discovery.d.ts +0 -59
- package/dist/discovery/peer-discovery.d.ts.map +0 -1
- package/dist/discovery/peer-discovery.js +0 -108
- package/dist/discovery/peer-discovery.js.map +0 -1
- package/dist/identity/keypair.d.ts +0 -42
- package/dist/identity/keypair.d.ts.map +0 -1
- package/dist/identity/keypair.js +0 -83
- package/dist/identity/keypair.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/message/envelope.d.ts +0 -59
- package/dist/message/envelope.d.ts.map +0 -1
- package/dist/message/envelope.js +0 -83
- package/dist/message/envelope.js.map +0 -1
- package/dist/message/types/paper-discovery.d.ts +0 -28
- package/dist/message/types/paper-discovery.d.ts.map +0 -1
- package/dist/message/types/paper-discovery.js +0 -2
- package/dist/message/types/paper-discovery.js.map +0 -1
- package/dist/message/types/peer-discovery.d.ts +0 -78
- package/dist/message/types/peer-discovery.d.ts.map +0 -1
- package/dist/message/types/peer-discovery.js +0 -90
- package/dist/message/types/peer-discovery.js.map +0 -1
- package/dist/peer/client.d.ts +0 -50
- package/dist/peer/client.d.ts.map +0 -1
- package/dist/peer/client.js +0 -138
- package/dist/peer/client.js.map +0 -1
- package/dist/peer/manager.d.ts +0 -65
- package/dist/peer/manager.d.ts.map +0 -1
- package/dist/peer/manager.js +0 -153
- package/dist/peer/manager.js.map +0 -1
- package/dist/peer/server.d.ts +0 -65
- package/dist/peer/server.d.ts.map +0 -1
- package/dist/peer/server.js +0 -154
- package/dist/peer/server.js.map +0 -1
- package/dist/registry/capability.d.ts +0 -44
- package/dist/registry/capability.d.ts.map +0 -1
- package/dist/registry/capability.js +0 -94
- package/dist/registry/capability.js.map +0 -1
- package/dist/registry/discovery-service.d.ts +0 -64
- package/dist/registry/discovery-service.d.ts.map +0 -1
- package/dist/registry/discovery-service.js +0 -129
- package/dist/registry/discovery-service.js.map +0 -1
- package/dist/registry/messages.d.ts +0 -105
- package/dist/registry/messages.d.ts.map +0 -1
- package/dist/registry/messages.js +0 -2
- package/dist/registry/messages.js.map +0 -1
- package/dist/registry/peer-store.d.ts +0 -57
- package/dist/registry/peer-store.d.ts.map +0 -1
- package/dist/registry/peer-store.js +0 -92
- package/dist/registry/peer-store.js.map +0 -1
- package/dist/registry/peer.d.ts +0 -20
- package/dist/registry/peer.d.ts.map +0 -1
- package/dist/registry/peer.js +0 -2
- package/dist/registry/peer.js.map +0 -1
- package/dist/relay/client.d.ts +0 -112
- package/dist/relay/client.d.ts.map +0 -1
- package/dist/relay/client.js +0 -281
- package/dist/relay/client.js.map +0 -1
- package/dist/relay/server.d.ts +0 -76
- package/dist/relay/server.d.ts.map +0 -1
- package/dist/relay/server.js +0 -338
- package/dist/relay/server.js.map +0 -1
- package/dist/relay/types.d.ts +0 -35
- package/dist/relay/types.d.ts.map +0 -1
- package/dist/relay/types.js +0 -2
- package/dist/relay/types.js.map +0 -1
- package/dist/reputation/commit-reveal.d.ts +0 -45
- package/dist/reputation/commit-reveal.d.ts.map +0 -1
- package/dist/reputation/commit-reveal.js +0 -125
- package/dist/reputation/commit-reveal.js.map +0 -1
- package/dist/reputation/scoring.d.ts +0 -31
- package/dist/reputation/scoring.d.ts.map +0 -1
- package/dist/reputation/scoring.js +0 -105
- package/dist/reputation/scoring.js.map +0 -1
- package/dist/reputation/store.d.ts +0 -83
- package/dist/reputation/store.d.ts.map +0 -1
- package/dist/reputation/store.js +0 -202
- package/dist/reputation/store.js.map +0 -1
- package/dist/reputation/types.d.ts +0 -150
- package/dist/reputation/types.d.ts.map +0 -1
- package/dist/reputation/types.js +0 -113
- package/dist/reputation/types.js.map +0 -1
- package/dist/reputation/verification.d.ts +0 -28
- package/dist/reputation/verification.d.ts.map +0 -1
- package/dist/reputation/verification.js +0 -91
- package/dist/reputation/verification.js.map +0 -1
- package/dist/service.d.ts +0 -90
- package/dist/service.d.ts.map +0 -1
- package/dist/service.js +0 -176
- package/dist/service.js.map +0 -1
- package/dist/transport/http.d.ts +0 -41
- package/dist/transport/http.d.ts.map +0 -1
- package/dist/transport/http.js +0 -103
- package/dist/transport/http.js.map +0 -1
- package/dist/transport/peer-config.d.ts +0 -38
- package/dist/transport/peer-config.d.ts.map +0 -1
- package/dist/transport/peer-config.js +0 -41
- package/dist/transport/peer-config.js.map +0 -1
- package/dist/transport/relay.d.ts +0 -30
- package/dist/transport/relay.d.ts.map +0 -1
- package/dist/transport/relay.js +0 -85
- package/dist/transport/relay.js.map +0 -1
- package/dist/utils.d.ts +0 -40
- package/dist/utils.d.ts.map +0 -1
- package/dist/utils.js +0 -59
- package/dist/utils.js.map +0 -1
package/dist/transport/http.js
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import { createEnvelope, verifyEnvelope } from '../message/envelope.js';
|
|
2
|
-
/**
|
|
3
|
-
* Send a signed envelope to a peer via HTTP webhook.
|
|
4
|
-
* Creates the envelope, signs it, and POSTs to the peer's /hooks/agent endpoint.
|
|
5
|
-
* Returns the HTTP status code.
|
|
6
|
-
*/
|
|
7
|
-
export async function sendToPeer(config, peerPublicKey, type, payload, inReplyTo) {
|
|
8
|
-
// Look up peer config
|
|
9
|
-
const peer = config.peers.get(peerPublicKey);
|
|
10
|
-
if (!peer) {
|
|
11
|
-
return { ok: false, status: 0, error: 'Unknown peer' };
|
|
12
|
-
}
|
|
13
|
-
// Relay-only peer — no webhook URL configured
|
|
14
|
-
if (!peer.url) {
|
|
15
|
-
return { ok: false, status: 0, error: 'No webhook URL configured' };
|
|
16
|
-
}
|
|
17
|
-
// Create and sign the envelope
|
|
18
|
-
const envelope = createEnvelope(type, config.identity.publicKey, config.identity.privateKey, payload, Date.now(), inReplyTo);
|
|
19
|
-
// Encode envelope as base64url
|
|
20
|
-
const envelopeJson = JSON.stringify(envelope);
|
|
21
|
-
const envelopeBase64 = Buffer.from(envelopeJson).toString('base64url');
|
|
22
|
-
// Construct webhook payload
|
|
23
|
-
const webhookPayload = {
|
|
24
|
-
message: `[AGORA_ENVELOPE]${envelopeBase64}`,
|
|
25
|
-
name: 'Agora',
|
|
26
|
-
sessionKey: `agora:${envelope.sender.substring(0, 16)}`,
|
|
27
|
-
deliver: false,
|
|
28
|
-
};
|
|
29
|
-
// Send HTTP POST
|
|
30
|
-
try {
|
|
31
|
-
const response = await fetch(`${peer.url}/agent`, {
|
|
32
|
-
method: 'POST',
|
|
33
|
-
headers: {
|
|
34
|
-
'Authorization': `Bearer ${peer.token}`,
|
|
35
|
-
'Content-Type': 'application/json',
|
|
36
|
-
},
|
|
37
|
-
body: JSON.stringify(webhookPayload),
|
|
38
|
-
});
|
|
39
|
-
return {
|
|
40
|
-
ok: response.ok,
|
|
41
|
-
status: response.status,
|
|
42
|
-
error: response.ok ? undefined : await response.text(),
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
catch (err) {
|
|
46
|
-
return {
|
|
47
|
-
ok: false,
|
|
48
|
-
status: 0,
|
|
49
|
-
error: err instanceof Error ? err.message : String(err),
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Decode and verify an inbound Agora envelope from a webhook message.
|
|
55
|
-
* Expects the message to start with [AGORA_ENVELOPE] followed by base64.
|
|
56
|
-
* Returns the verified envelope or an error.
|
|
57
|
-
*/
|
|
58
|
-
export function decodeInboundEnvelope(message, knownPeers) {
|
|
59
|
-
// Check for AGORA_ENVELOPE prefix
|
|
60
|
-
const prefix = '[AGORA_ENVELOPE]';
|
|
61
|
-
if (!message.startsWith(prefix)) {
|
|
62
|
-
return { ok: false, reason: 'not_agora_message' };
|
|
63
|
-
}
|
|
64
|
-
// Extract base64 payload
|
|
65
|
-
const base64Payload = message.substring(prefix.length);
|
|
66
|
-
// Check for empty payload
|
|
67
|
-
if (!base64Payload) {
|
|
68
|
-
return { ok: false, reason: 'invalid_base64' };
|
|
69
|
-
}
|
|
70
|
-
// Decode base64
|
|
71
|
-
let envelopeJson;
|
|
72
|
-
try {
|
|
73
|
-
const decoded = Buffer.from(base64Payload, 'base64url');
|
|
74
|
-
// Check if decoded buffer is empty or contains invalid data
|
|
75
|
-
if (decoded.length === 0) {
|
|
76
|
-
return { ok: false, reason: 'invalid_base64' };
|
|
77
|
-
}
|
|
78
|
-
envelopeJson = decoded.toString('utf-8');
|
|
79
|
-
}
|
|
80
|
-
catch {
|
|
81
|
-
return { ok: false, reason: 'invalid_base64' };
|
|
82
|
-
}
|
|
83
|
-
// Parse JSON
|
|
84
|
-
let envelope;
|
|
85
|
-
try {
|
|
86
|
-
envelope = JSON.parse(envelopeJson);
|
|
87
|
-
}
|
|
88
|
-
catch {
|
|
89
|
-
return { ok: false, reason: 'invalid_json' };
|
|
90
|
-
}
|
|
91
|
-
// Verify envelope integrity
|
|
92
|
-
const verification = verifyEnvelope(envelope);
|
|
93
|
-
if (!verification.valid) {
|
|
94
|
-
return { ok: false, reason: verification.reason || 'verification_failed' };
|
|
95
|
-
}
|
|
96
|
-
// Check if sender is a known peer
|
|
97
|
-
const senderKnown = knownPeers.has(envelope.sender);
|
|
98
|
-
if (!senderKnown) {
|
|
99
|
-
return { ok: false, reason: 'unknown_sender' };
|
|
100
|
-
}
|
|
101
|
-
return { ok: true, envelope };
|
|
102
|
-
}
|
|
103
|
-
//# sourceMappingURL=http.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/transport/http.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,cAAc,EAAmC,MAAM,wBAAwB,CAAC;AAkBzG;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,MAAuB,EACvB,aAAqB,EACrB,IAAiB,EACjB,OAAgB,EAChB,SAAkB;IAElB,sBAAsB;IACtB,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;IAC7C,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,EAAE,KAAK,EAAE,cAAc,EAAE,CAAC;IACzD,CAAC;IAED,8CAA8C;IAC9C,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;QACd,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,EAAE,KAAK,EAAE,2BAA2B,EAAE,CAAC;IACtE,CAAC;IAED,+BAA+B;IAC/B,MAAM,QAAQ,GAAG,cAAc,CAC7B,IAAI,EACJ,MAAM,CAAC,QAAQ,CAAC,SAAS,EACzB,MAAM,CAAC,QAAQ,CAAC,UAAU,EAC1B,OAAO,EACP,IAAI,CAAC,GAAG,EAAE,EACV,SAAS,CACV,CAAC;IAEF,+BAA+B;IAC/B,MAAM,YAAY,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;IAC9C,MAAM,cAAc,GAAG,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;IAEvE,4BAA4B;IAC5B,MAAM,cAAc,GAAG;QACrB,OAAO,EAAE,mBAAmB,cAAc,EAAE;QAC5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B,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,gBAAgB,EAAE,CAAC;IACjD,CAAC;IAED,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;AAChC,CAAC"}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
export interface PeerConfigFile {
|
|
2
|
-
identity: {
|
|
3
|
-
publicKey: string;
|
|
4
|
-
privateKey: string;
|
|
5
|
-
name?: string;
|
|
6
|
-
};
|
|
7
|
-
relay?: string | {
|
|
8
|
-
url: string;
|
|
9
|
-
name?: string;
|
|
10
|
-
};
|
|
11
|
-
peers: Record<string, {
|
|
12
|
-
url?: string;
|
|
13
|
-
token?: string;
|
|
14
|
-
publicKey: string;
|
|
15
|
-
name?: string;
|
|
16
|
-
}>;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Load peer configuration from a JSON file.
|
|
20
|
-
* @param path - Path to the config file
|
|
21
|
-
* @returns The parsed configuration
|
|
22
|
-
* @throws Error if file doesn't exist or contains invalid JSON
|
|
23
|
-
*/
|
|
24
|
-
export declare function loadPeerConfig(path: string): PeerConfigFile;
|
|
25
|
-
/**
|
|
26
|
-
* Save peer configuration to a JSON file.
|
|
27
|
-
* @param path - Path to the config file
|
|
28
|
-
* @param config - The configuration to save
|
|
29
|
-
*/
|
|
30
|
-
export declare function savePeerConfig(path: string, config: PeerConfigFile): void;
|
|
31
|
-
/**
|
|
32
|
-
* Initialize peer configuration, generating a new keypair if the file doesn't exist.
|
|
33
|
-
* If the file exists, loads and returns it.
|
|
34
|
-
* @param path - Path to the config file
|
|
35
|
-
* @returns The configuration (loaded or newly created)
|
|
36
|
-
*/
|
|
37
|
-
export declare function initPeerConfig(path: string): PeerConfigFile;
|
|
38
|
-
//# sourceMappingURL=peer-config.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"peer-config.d.ts","sourceRoot":"","sources":["../../src/transport/peer-config.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE;QACR,SAAS,EAAE,MAAM,CAAC;QAClB,UAAU,EAAE,MAAM,CAAC;QACnB,IAAI,CAAC,EAAE,MAAM,CAAC;KACf,CAAC;IACF,KAAK,CAAC,EAAE,MAAM,GAAG;QACf,GAAG,EAAE,MAAM,CAAC;QACZ,IAAI,CAAC,EAAE,MAAM,CAAC;KACf,CAAC;IACF,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE;QACpB,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,SAAS,EAAE,MAAM,CAAC;QAClB,IAAI,CAAC,EAAE,MAAM,CAAC;KACf,CAAC,CAAC;CACJ;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,CAG3D;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc,GAAG,IAAI,CAGzE;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,CAc3D"}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { readFileSync, writeFileSync, existsSync } from 'node:fs';
|
|
2
|
-
import { generateKeyPair } from '../identity/keypair.js';
|
|
3
|
-
/**
|
|
4
|
-
* Load peer configuration from a JSON file.
|
|
5
|
-
* @param path - Path to the config file
|
|
6
|
-
* @returns The parsed configuration
|
|
7
|
-
* @throws Error if file doesn't exist or contains invalid JSON
|
|
8
|
-
*/
|
|
9
|
-
export function loadPeerConfig(path) {
|
|
10
|
-
const content = readFileSync(path, 'utf-8');
|
|
11
|
-
return JSON.parse(content);
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Save peer configuration to a JSON file.
|
|
15
|
-
* @param path - Path to the config file
|
|
16
|
-
* @param config - The configuration to save
|
|
17
|
-
*/
|
|
18
|
-
export function savePeerConfig(path, config) {
|
|
19
|
-
const content = JSON.stringify(config, null, 2);
|
|
20
|
-
writeFileSync(path, content, 'utf-8');
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Initialize peer configuration, generating a new keypair if the file doesn't exist.
|
|
24
|
-
* If the file exists, loads and returns it.
|
|
25
|
-
* @param path - Path to the config file
|
|
26
|
-
* @returns The configuration (loaded or newly created)
|
|
27
|
-
*/
|
|
28
|
-
export function initPeerConfig(path) {
|
|
29
|
-
if (existsSync(path)) {
|
|
30
|
-
return loadPeerConfig(path);
|
|
31
|
-
}
|
|
32
|
-
// Generate new keypair and create initial config
|
|
33
|
-
const identity = generateKeyPair();
|
|
34
|
-
const config = {
|
|
35
|
-
identity,
|
|
36
|
-
peers: {},
|
|
37
|
-
};
|
|
38
|
-
savePeerConfig(path, config);
|
|
39
|
-
return config;
|
|
40
|
-
}
|
|
41
|
-
//# sourceMappingURL=peer-config.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"peer-config.js","sourceRoot":"","sources":["../../src/transport/peer-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAClE,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAoBzD;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,IAAY;IACzC,MAAM,OAAO,GAAG,YAAY,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC5C,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAmB,CAAC;AAC/C,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,IAAY,EAAE,MAAsB;IACjE,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IAChD,aAAa,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;AACxC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,IAAY;IACzC,IAAI,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QACrB,OAAO,cAAc,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC;IAED,iDAAiD;IACjD,MAAM,QAAQ,GAAG,eAAe,EAAE,CAAC;IACnC,MAAM,MAAM,GAAmB;QAC7B,QAAQ;QACR,KAAK,EAAE,EAAE;KACV,CAAC;IAEF,cAAc,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAC7B,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { type Envelope, type MessageType } from '../message/envelope.js';
|
|
2
|
-
/** Minimal interface for a connected relay client (avoids importing full RelayClient) */
|
|
3
|
-
export interface RelayClientSender {
|
|
4
|
-
connected(): boolean;
|
|
5
|
-
send(to: string, envelope: Envelope): Promise<{
|
|
6
|
-
ok: boolean;
|
|
7
|
-
error?: string;
|
|
8
|
-
}>;
|
|
9
|
-
}
|
|
10
|
-
export interface RelayTransportConfig {
|
|
11
|
-
/** This agent's keypair */
|
|
12
|
-
identity: {
|
|
13
|
-
publicKey: string;
|
|
14
|
-
privateKey: string;
|
|
15
|
-
};
|
|
16
|
-
/** Relay server WebSocket URL (e.g., wss://agora-relay.lbsa71.net) */
|
|
17
|
-
relayUrl: string;
|
|
18
|
-
/** Optional persistent relay client (if provided, will use it instead of connect-per-message) */
|
|
19
|
-
relayClient?: RelayClientSender;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Send a signed envelope to a peer via relay server.
|
|
23
|
-
* If a persistent relayClient is provided in the config, uses that.
|
|
24
|
-
* Otherwise, connects to relay, registers, sends message, and disconnects.
|
|
25
|
-
*/
|
|
26
|
-
export declare function sendViaRelay(config: RelayTransportConfig, peerPublicKey: string, type: MessageType, payload: unknown, inReplyTo?: string): Promise<{
|
|
27
|
-
ok: boolean;
|
|
28
|
-
error?: string;
|
|
29
|
-
}>;
|
|
30
|
-
//# sourceMappingURL=relay.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"relay.d.ts","sourceRoot":"","sources":["../../src/transport/relay.ts"],"names":[],"mappings":"AACA,OAAO,EAAkB,KAAK,QAAQ,EAAE,KAAK,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAEzF,yFAAyF;AACzF,MAAM,WAAW,iBAAiB;IAChC,SAAS,IAAI,OAAO,CAAC;IACrB,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC;QAAE,EAAE,EAAE,OAAO,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAChF;AAED,MAAM,WAAW,oBAAoB;IACnC,2BAA2B;IAC3B,QAAQ,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,CAAC;IACpD,sEAAsE;IACtE,QAAQ,EAAE,MAAM,CAAC;IACjB,iGAAiG;IACjG,WAAW,CAAC,EAAE,iBAAiB,CAAC;CACjC;AAED;;;;GAIG;AACH,wBAAsB,YAAY,CAChC,MAAM,EAAE,oBAAoB,EAC5B,aAAa,EAAE,MAAM,EACrB,IAAI,EAAE,WAAW,EACjB,OAAO,EAAE,OAAO,EAChB,SAAS,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC;IAAE,EAAE,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAmG1C"}
|
package/dist/transport/relay.js
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import WebSocket from 'ws';
|
|
2
|
-
import { createEnvelope } from '../message/envelope.js';
|
|
3
|
-
/**
|
|
4
|
-
* Send a signed envelope to a peer via relay server.
|
|
5
|
-
* If a persistent relayClient is provided in the config, uses that.
|
|
6
|
-
* Otherwise, connects to relay, registers, sends message, and disconnects.
|
|
7
|
-
*/
|
|
8
|
-
export async function sendViaRelay(config, peerPublicKey, type, payload, inReplyTo) {
|
|
9
|
-
// If a persistent relay client is available, use it
|
|
10
|
-
if (config.relayClient && config.relayClient.connected()) {
|
|
11
|
-
const envelope = createEnvelope(type, config.identity.publicKey, config.identity.privateKey, payload, Date.now(), inReplyTo);
|
|
12
|
-
return config.relayClient.send(peerPublicKey, envelope);
|
|
13
|
-
}
|
|
14
|
-
// Otherwise, fall back to connect-per-message
|
|
15
|
-
return new Promise((resolve) => {
|
|
16
|
-
const ws = new WebSocket(config.relayUrl);
|
|
17
|
-
let registered = false;
|
|
18
|
-
let messageSent = false;
|
|
19
|
-
let resolved = false;
|
|
20
|
-
// Helper to resolve once
|
|
21
|
-
const resolveOnce = (result) => {
|
|
22
|
-
if (!resolved) {
|
|
23
|
-
resolved = true;
|
|
24
|
-
clearTimeout(timeout);
|
|
25
|
-
resolve(result);
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
// Set timeout for the entire operation
|
|
29
|
-
const timeout = setTimeout(() => {
|
|
30
|
-
if (!messageSent) {
|
|
31
|
-
ws.close();
|
|
32
|
-
resolveOnce({ ok: false, error: 'Relay connection timeout' });
|
|
33
|
-
}
|
|
34
|
-
}, 10000); // 10 second timeout
|
|
35
|
-
ws.on('open', () => {
|
|
36
|
-
// Send register message
|
|
37
|
-
const registerMsg = {
|
|
38
|
-
type: 'register',
|
|
39
|
-
publicKey: config.identity.publicKey,
|
|
40
|
-
};
|
|
41
|
-
ws.send(JSON.stringify(registerMsg));
|
|
42
|
-
});
|
|
43
|
-
ws.on('message', (data) => {
|
|
44
|
-
try {
|
|
45
|
-
const msg = JSON.parse(data.toString());
|
|
46
|
-
if (msg.type === 'registered' && !registered) {
|
|
47
|
-
registered = true;
|
|
48
|
-
// Create and sign the envelope
|
|
49
|
-
const envelope = createEnvelope(type, config.identity.publicKey, config.identity.privateKey, payload, Date.now(), inReplyTo);
|
|
50
|
-
// Send message via relay
|
|
51
|
-
const relayMsg = {
|
|
52
|
-
type: 'message',
|
|
53
|
-
to: peerPublicKey,
|
|
54
|
-
envelope,
|
|
55
|
-
};
|
|
56
|
-
ws.send(JSON.stringify(relayMsg));
|
|
57
|
-
messageSent = true;
|
|
58
|
-
// Close connection after sending
|
|
59
|
-
setTimeout(() => {
|
|
60
|
-
ws.close();
|
|
61
|
-
resolveOnce({ ok: true });
|
|
62
|
-
}, 100); // Small delay to ensure message is sent
|
|
63
|
-
}
|
|
64
|
-
else if (msg.type === 'error') {
|
|
65
|
-
ws.close();
|
|
66
|
-
resolveOnce({ ok: false, error: msg.message || 'Relay server error' });
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
catch (err) {
|
|
70
|
-
ws.close();
|
|
71
|
-
resolveOnce({ ok: false, error: err instanceof Error ? err.message : String(err) });
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
ws.on('error', (err) => {
|
|
75
|
-
ws.close();
|
|
76
|
-
resolveOnce({ ok: false, error: err.message });
|
|
77
|
-
});
|
|
78
|
-
ws.on('close', () => {
|
|
79
|
-
if (!messageSent) {
|
|
80
|
-
resolveOnce({ ok: false, error: 'Connection closed before message sent' });
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
//# sourceMappingURL=relay.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"relay.js","sourceRoot":"","sources":["../../src/transport/relay.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,IAAI,CAAC;AAC3B,OAAO,EAAE,cAAc,EAAmC,MAAM,wBAAwB,CAAC;AAiBzF;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,MAA4B,EAC5B,aAAqB,EACrB,IAAiB,EACjB,OAAgB,EAChB,SAAkB;IAElB,oDAAoD;IACpD,IAAI,MAAM,CAAC,WAAW,IAAI,MAAM,CAAC,WAAW,CAAC,SAAS,EAAE,EAAE,CAAC;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YACH,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,EAAE,CAAC,KAAK,EAAE,CAAC;gBACX,WAAW,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;YACtF,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE;YACrB,EAAE,CAAC,KAAK,EAAE,CAAC;YACX,WAAW,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;QACjD,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE;YAClB,IAAI,CAAC,WAAW,EAAE,CAAC;gBACjB,WAAW,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,uCAAuC,EAAE,CAAC,CAAC;YAC7E,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/dist/utils.d.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Get a short display version of a public key using the last 8 characters.
|
|
3
|
-
* Ed25519 public keys all share the same OID prefix, so the last 8 characters
|
|
4
|
-
* are more distinguishable than the first 8.
|
|
5
|
-
*
|
|
6
|
-
* @param publicKey - The full public key hex string
|
|
7
|
-
* @returns "..." followed by the last 8 characters of the key
|
|
8
|
-
*/
|
|
9
|
-
export declare function shortKey(publicKey: string): string;
|
|
10
|
-
/**
|
|
11
|
-
* Resolves the name to broadcast when connecting to a relay.
|
|
12
|
-
* Priority order:
|
|
13
|
-
* 1. CLI --name flag
|
|
14
|
-
* 2. config.relay.name (if relay is an object with name property)
|
|
15
|
-
* 3. config.identity.name
|
|
16
|
-
* 4. undefined (no name broadcast)
|
|
17
|
-
*
|
|
18
|
-
* @param config - The Agora configuration (or compatible config with identity and optional relay)
|
|
19
|
-
* @param cliName - Optional name from CLI --name flag
|
|
20
|
-
* @returns The resolved name to broadcast, or undefined if none available
|
|
21
|
-
*/
|
|
22
|
-
export declare function resolveBroadcastName(config: {
|
|
23
|
-
identity: {
|
|
24
|
-
name?: string;
|
|
25
|
-
};
|
|
26
|
-
relay?: {
|
|
27
|
-
name?: string;
|
|
28
|
-
} | string;
|
|
29
|
-
}, cliName?: string): string | undefined;
|
|
30
|
-
/**
|
|
31
|
-
* Formats a display name with short ID postfix.
|
|
32
|
-
* If name exists: "name (...3f8c2247)"
|
|
33
|
-
* If no name: "...3f8c2247" (short ID only)
|
|
34
|
-
*
|
|
35
|
-
* @param name - Optional name to display (should not be a short ID)
|
|
36
|
-
* @param publicKey - The public key to use for short ID
|
|
37
|
-
* @returns Formatted display string
|
|
38
|
-
*/
|
|
39
|
-
export declare function formatDisplayName(name: string | undefined, publicKey: string): string;
|
|
40
|
-
//# sourceMappingURL=utils.d.ts.map
|
package/dist/utils.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAElD;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE;IAAE,QAAQ,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAAC,KAAK,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,MAAM,CAAA;CAAE,EAC3E,OAAO,CAAC,EAAE,MAAM,GACf,MAAM,GAAG,SAAS,CAoBpB;AAED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAOrF"}
|
package/dist/utils.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Get a short display version of a public key using the last 8 characters.
|
|
3
|
-
* Ed25519 public keys all share the same OID prefix, so the last 8 characters
|
|
4
|
-
* are more distinguishable than the first 8.
|
|
5
|
-
*
|
|
6
|
-
* @param publicKey - The full public key hex string
|
|
7
|
-
* @returns "..." followed by the last 8 characters of the key
|
|
8
|
-
*/
|
|
9
|
-
export function shortKey(publicKey) {
|
|
10
|
-
return "..." + publicKey.slice(-8);
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Resolves the name to broadcast when connecting to a relay.
|
|
14
|
-
* Priority order:
|
|
15
|
-
* 1. CLI --name flag
|
|
16
|
-
* 2. config.relay.name (if relay is an object with name property)
|
|
17
|
-
* 3. config.identity.name
|
|
18
|
-
* 4. undefined (no name broadcast)
|
|
19
|
-
*
|
|
20
|
-
* @param config - The Agora configuration (or compatible config with identity and optional relay)
|
|
21
|
-
* @param cliName - Optional name from CLI --name flag
|
|
22
|
-
* @returns The resolved name to broadcast, or undefined if none available
|
|
23
|
-
*/
|
|
24
|
-
export function resolveBroadcastName(config, cliName) {
|
|
25
|
-
// Priority 1: CLI --name flag
|
|
26
|
-
if (cliName) {
|
|
27
|
-
return cliName;
|
|
28
|
-
}
|
|
29
|
-
// Priority 2: config.relay.name (if relay is an object with name property)
|
|
30
|
-
if (config.relay) {
|
|
31
|
-
if (typeof config.relay === 'object' && config.relay.name) {
|
|
32
|
-
return config.relay.name;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
// Priority 3: config.identity.name
|
|
36
|
-
if (config.identity.name) {
|
|
37
|
-
return config.identity.name;
|
|
38
|
-
}
|
|
39
|
-
// Priority 4: No name available
|
|
40
|
-
return undefined;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Formats a display name with short ID postfix.
|
|
44
|
-
* If name exists: "name (...3f8c2247)"
|
|
45
|
-
* If no name: "...3f8c2247" (short ID only)
|
|
46
|
-
*
|
|
47
|
-
* @param name - Optional name to display (should not be a short ID)
|
|
48
|
-
* @param publicKey - The public key to use for short ID
|
|
49
|
-
* @returns Formatted display string
|
|
50
|
-
*/
|
|
51
|
-
export function formatDisplayName(name, publicKey) {
|
|
52
|
-
const shortId = shortKey(publicKey);
|
|
53
|
-
// If name is undefined, empty, or is already a short ID, return only short ID
|
|
54
|
-
if (!name || name.trim() === '' || name.startsWith('...')) {
|
|
55
|
-
return shortId;
|
|
56
|
-
}
|
|
57
|
-
return `${name} (${shortId})`;
|
|
58
|
-
}
|
|
59
|
-
//# sourceMappingURL=utils.js.map
|
package/dist/utils.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,UAAU,QAAQ,CAAC,SAAiB;IACxC,OAAO,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;AACrC,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,oBAAoB,CAClC,MAA2E,EAC3E,OAAgB;IAEhB,8BAA8B;IAC9B,IAAI,OAAO,EAAE,CAAC;QACZ,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,2EAA2E;IAC3E,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;QACjB,IAAI,OAAO,MAAM,CAAC,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;YAC1D,OAAO,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC;QAC3B,CAAC;IACH,CAAC;IAED,mCAAmC;IACnC,IAAI,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;QACzB,OAAO,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC;IAC9B,CAAC;IAED,gCAAgC;IAChC,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,iBAAiB,CAAC,IAAwB,EAAE,SAAiB;IAC3E,MAAM,OAAO,GAAG,QAAQ,CAAC,SAAS,CAAC,CAAC;IACpC,8EAA8E;IAC9E,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;QAC1D,OAAO,OAAO,CAAC;IACjB,CAAC;IACD,OAAO,GAAG,IAAI,KAAK,OAAO,GAAG,CAAC;AAChC,CAAC"}
|