@meshline/sdk 0.0.0-stage → 0.1.0-alpha.1
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/LICENSE +21 -0
- package/README.md +43 -2
- package/dist/channels/repository.d.ts +73 -0
- package/dist/channels/repository.d.ts.map +1 -0
- package/dist/channels/repository.js +367 -0
- package/dist/channels/repository.js.map +1 -0
- package/dist/client/account-operations.d.ts +41 -0
- package/dist/client/account-operations.d.ts.map +1 -0
- package/dist/client/account-operations.js +304 -0
- package/dist/client/account-operations.js.map +1 -0
- package/dist/client/conversations.d.ts +36 -0
- package/dist/client/conversations.d.ts.map +1 -0
- package/dist/client/conversations.js +144 -0
- package/dist/client/conversations.js.map +1 -0
- package/dist/client.d.ts +53 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +162 -0
- package/dist/client.js.map +1 -0
- package/dist/components/account.d.ts +38 -0
- package/dist/components/account.d.ts.map +1 -0
- package/dist/components/account.js +243 -0
- package/dist/components/account.js.map +1 -0
- package/dist/components/channel.d.ts +78 -0
- package/dist/components/channel.d.ts.map +1 -0
- package/dist/components/channel.js +475 -0
- package/dist/components/channel.js.map +1 -0
- package/dist/components/component.d.ts +49 -0
- package/dist/components/component.d.ts.map +1 -0
- package/dist/components/component.js +194 -0
- package/dist/components/component.js.map +1 -0
- package/dist/components/device.d.ts +60 -0
- package/dist/components/device.d.ts.map +1 -0
- package/dist/components/device.js +648 -0
- package/dist/components/device.js.map +1 -0
- package/dist/components/group.d.ts +141 -0
- package/dist/components/group.d.ts.map +1 -0
- package/dist/components/group.js +933 -0
- package/dist/components/group.js.map +1 -0
- package/dist/components/message.d.ts +63 -0
- package/dist/components/message.d.ts.map +1 -0
- package/dist/components/message.js +439 -0
- package/dist/components/message.js.map +1 -0
- package/dist/components/profile.d.ts +37 -0
- package/dist/components/profile.d.ts.map +1 -0
- package/dist/components/profile.js +232 -0
- package/dist/components/profile.js.map +1 -0
- package/dist/crypto/groups.d.ts +56 -0
- package/dist/crypto/groups.d.ts.map +1 -0
- package/dist/crypto/groups.js +163 -0
- package/dist/crypto/groups.js.map +1 -0
- package/dist/crypto/messages.d.ts +52 -0
- package/dist/crypto/messages.d.ts.map +1 -0
- package/dist/crypto/messages.js +180 -0
- package/dist/crypto/messages.js.map +1 -0
- package/dist/crypto/primitives.d.ts +30 -0
- package/dist/crypto/primitives.d.ts.map +1 -0
- package/dist/crypto/primitives.js +102 -0
- package/dist/crypto/primitives.js.map +1 -0
- package/dist/errors.d.ts +11 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +14 -0
- package/dist/errors.js.map +1 -0
- package/dist/groups/account-sync.d.ts +28 -0
- package/dist/groups/account-sync.d.ts.map +1 -0
- package/dist/groups/account-sync.js +235 -0
- package/dist/groups/account-sync.js.map +1 -0
- package/dist/groups/messages.d.ts +39 -0
- package/dist/groups/messages.d.ts.map +1 -0
- package/dist/groups/messages.js +141 -0
- package/dist/groups/messages.js.map +1 -0
- package/dist/groups/operations.d.ts +57 -0
- package/dist/groups/operations.d.ts.map +1 -0
- package/dist/groups/operations.js +225 -0
- package/dist/groups/operations.js.map +1 -0
- package/dist/groups/repository.d.ts +56 -0
- package/dist/groups/repository.d.ts.map +1 -0
- package/dist/groups/repository.js +254 -0
- package/dist/groups/repository.js.map +1 -0
- package/dist/groups/secrets.d.ts +67 -0
- package/dist/groups/secrets.d.ts.map +1 -0
- package/dist/groups/secrets.js +452 -0
- package/dist/groups/secrets.js.map +1 -0
- package/dist/groups/state.d.ts +39 -0
- package/dist/groups/state.d.ts.map +1 -0
- package/dist/groups/state.js +201 -0
- package/dist/groups/state.js.map +1 -0
- package/dist/identity/identifiers.d.ts +9 -0
- package/dist/identity/identifiers.d.ts.map +1 -0
- package/dist/identity/identifiers.js +37 -0
- package/dist/identity/identifiers.js.map +1 -0
- package/dist/identity/neo.d.ts +11 -0
- package/dist/identity/neo.d.ts.map +1 -0
- package/dist/identity/neo.js +77 -0
- package/dist/identity/neo.js.map +1 -0
- package/dist/index.d.ts +53 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +46 -0
- package/dist/index.js.map +1 -0
- package/dist/interactions.d.ts +31 -0
- package/dist/interactions.d.ts.map +1 -0
- package/dist/interactions.js +2 -0
- package/dist/interactions.js.map +1 -0
- package/dist/messages/account-sender.d.ts +9 -0
- package/dist/messages/account-sender.d.ts.map +1 -0
- package/dist/messages/account-sender.js +46 -0
- package/dist/messages/account-sender.js.map +1 -0
- package/dist/messages/contacts.d.ts +103 -0
- package/dist/messages/contacts.d.ts.map +1 -0
- package/dist/messages/contacts.js +525 -0
- package/dist/messages/contacts.js.map +1 -0
- package/dist/messages/outbox.d.ts +66 -0
- package/dist/messages/outbox.d.ts.map +1 -0
- package/dist/messages/outbox.js +167 -0
- package/dist/messages/outbox.js.map +1 -0
- package/dist/messages/receiver.d.ts +35 -0
- package/dist/messages/receiver.d.ts.map +1 -0
- package/dist/messages/receiver.js +113 -0
- package/dist/messages/receiver.js.map +1 -0
- package/dist/messages/repository.d.ts +89 -0
- package/dist/messages/repository.d.ts.map +1 -0
- package/dist/messages/repository.js +295 -0
- package/dist/messages/repository.js.map +1 -0
- package/dist/models/authentication.d.ts +37 -0
- package/dist/models/authentication.d.ts.map +1 -0
- package/dist/models/authentication.js +53 -0
- package/dist/models/authentication.js.map +1 -0
- package/dist/models/channels.d.ts +141 -0
- package/dist/models/channels.d.ts.map +1 -0
- package/dist/models/channels.js +258 -0
- package/dist/models/channels.js.map +1 -0
- package/dist/models/contacts.d.ts +68 -0
- package/dist/models/contacts.d.ts.map +1 -0
- package/dist/models/contacts.js +186 -0
- package/dist/models/contacts.js.map +1 -0
- package/dist/models/content.d.ts +37 -0
- package/dist/models/content.d.ts.map +1 -0
- package/dist/models/content.js +137 -0
- package/dist/models/content.js.map +1 -0
- package/dist/models/device-state.d.ts +8 -0
- package/dist/models/device-state.d.ts.map +1 -0
- package/dist/models/device-state.js +22 -0
- package/dist/models/device-state.js.map +1 -0
- package/dist/models/group-admission.d.ts +111 -0
- package/dist/models/group-admission.d.ts.map +1 -0
- package/dist/models/group-admission.js +153 -0
- package/dist/models/group-admission.js.map +1 -0
- package/dist/models/group-keys.d.ts +30 -0
- package/dist/models/group-keys.d.ts.map +1 -0
- package/dist/models/group-keys.js +52 -0
- package/dist/models/group-keys.js.map +1 -0
- package/dist/models/group-management.d.ts +190 -0
- package/dist/models/group-management.d.ts.map +1 -0
- package/dist/models/group-management.js +263 -0
- package/dist/models/group-management.js.map +1 -0
- package/dist/models/groups.d.ts +81 -0
- package/dist/models/groups.d.ts.map +1 -0
- package/dist/models/groups.js +127 -0
- package/dist/models/groups.js.map +1 -0
- package/dist/models/identity.d.ts +47 -0
- package/dist/models/identity.d.ts.map +1 -0
- package/dist/models/identity.js +136 -0
- package/dist/models/identity.js.map +1 -0
- package/dist/models/messages.d.ts +104 -0
- package/dist/models/messages.d.ts.map +1 -0
- package/dist/models/messages.js +168 -0
- package/dist/models/messages.js.map +1 -0
- package/dist/models/profile.d.ts +24 -0
- package/dist/models/profile.d.ts.map +1 -0
- package/dist/models/profile.js +47 -0
- package/dist/models/profile.js.map +1 -0
- package/dist/models/relay.d.ts +39 -0
- package/dist/models/relay.d.ts.map +1 -0
- package/dist/models/relay.js +160 -0
- package/dist/models/relay.js.map +1 -0
- package/dist/protocol/codec.d.ts +36 -0
- package/dist/protocol/codec.d.ts.map +1 -0
- package/dist/protocol/codec.js +144 -0
- package/dist/protocol/codec.js.map +1 -0
- package/dist/protocol/context.d.ts +14 -0
- package/dist/protocol/context.d.ts.map +1 -0
- package/dist/protocol/context.js +43 -0
- package/dist/protocol/context.js.map +1 -0
- package/dist/protocol/encoding.d.ts +15 -0
- package/dist/protocol/encoding.d.ts.map +1 -0
- package/dist/protocol/encoding.js +133 -0
- package/dist/protocol/encoding.js.map +1 -0
- package/dist/protocol/json.d.ts +16 -0
- package/dist/protocol/json.d.ts.map +1 -0
- package/dist/protocol/json.js +172 -0
- package/dist/protocol/json.js.map +1 -0
- package/dist/protocol/validation.d.ts +4 -0
- package/dist/protocol/validation.d.ts.map +1 -0
- package/dist/protocol/validation.js +18 -0
- package/dist/protocol/validation.js.map +1 -0
- package/dist/runtime/abort.d.ts +6 -0
- package/dist/runtime/abort.d.ts.map +1 -0
- package/dist/runtime/abort.js +32 -0
- package/dist/runtime/abort.js.map +1 -0
- package/dist/runtime/async-gate.d.ts +6 -0
- package/dist/runtime/async-gate.d.ts.map +1 -0
- package/dist/runtime/async-gate.js +15 -0
- package/dist/runtime/async-gate.js.map +1 -0
- package/dist/runtime/async-pulse.d.ts +7 -0
- package/dist/runtime/async-pulse.d.ts.map +1 -0
- package/dist/runtime/async-pulse.js +23 -0
- package/dist/runtime/async-pulse.js.map +1 -0
- package/dist/runtime/clock.d.ts +16 -0
- package/dist/runtime/clock.d.ts.map +1 -0
- package/dist/runtime/clock.js +62 -0
- package/dist/runtime/clock.js.map +1 -0
- package/dist/runtime/events.d.ts +11 -0
- package/dist/runtime/events.d.ts.map +1 -0
- package/dist/runtime/events.js +45 -0
- package/dist/runtime/events.js.map +1 -0
- package/dist/runtime/url.d.ts +3 -0
- package/dist/runtime/url.d.ts.map +1 -0
- package/dist/runtime/url.js +23 -0
- package/dist/runtime/url.js.map +1 -0
- package/dist/storage/signed-request.d.ts +14 -0
- package/dist/storage/signed-request.d.ts.map +1 -0
- package/dist/storage/signed-request.js +26 -0
- package/dist/storage/signed-request.js.map +1 -0
- package/dist/storage/store.d.ts +58 -0
- package/dist/storage/store.d.ts.map +1 -0
- package/dist/storage/store.js +52 -0
- package/dist/storage/store.js.map +1 -0
- package/dist/storage/transaction.d.ts +7 -0
- package/dist/storage/transaction.d.ts.map +1 -0
- package/dist/storage/transaction.js +22 -0
- package/dist/storage/transaction.js.map +1 -0
- package/dist/transport/client.d.ts +61 -0
- package/dist/transport/client.d.ts.map +1 -0
- package/dist/transport/client.js +392 -0
- package/dist/transport/client.js.map +1 -0
- package/dist/transport/discovery.d.ts +19 -0
- package/dist/transport/discovery.d.ts.map +1 -0
- package/dist/transport/discovery.js +75 -0
- package/dist/transport/discovery.js.map +1 -0
- package/dist/transport/endpoint.d.ts +6 -0
- package/dist/transport/endpoint.d.ts.map +1 -0
- package/dist/transport/endpoint.js +35 -0
- package/dist/transport/endpoint.js.map +1 -0
- package/dist/transport/http.d.ts +52 -0
- package/dist/transport/http.d.ts.map +1 -0
- package/dist/transport/http.js +128 -0
- package/dist/transport/http.js.map +1 -0
- package/dist/transport/pool.d.ts +31 -0
- package/dist/transport/pool.d.ts.map +1 -0
- package/dist/transport/pool.js +137 -0
- package/dist/transport/pool.js.map +1 -0
- package/dist/transport/relay-error.d.ts +23 -0
- package/dist/transport/relay-error.d.ts.map +1 -0
- package/dist/transport/relay-error.js +47 -0
- package/dist/transport/relay-error.js.map +1 -0
- package/dist/transport/rpc.d.ts +31 -0
- package/dist/transport/rpc.d.ts.map +1 -0
- package/dist/transport/rpc.js +56 -0
- package/dist/transport/rpc.js.map +1 -0
- package/dist/transport/session.d.ts +49 -0
- package/dist/transport/session.d.ts.map +1 -0
- package/dist/transport/session.js +169 -0
- package/dist/transport/session.js.map +1 -0
- package/dist/transport/socket.d.ts +55 -0
- package/dist/transport/socket.d.ts.map +1 -0
- package/dist/transport/socket.js +266 -0
- package/dist/transport/socket.js.map +1 -0
- package/dist/transport/subscription.d.ts +36 -0
- package/dist/transport/subscription.d.ts.map +1 -0
- package/dist/transport/subscription.js +169 -0
- package/dist/transport/subscription.js.map +1 -0
- package/package.json +35 -4
- package/src/channels/repository.ts +244 -0
- package/src/client/account-operations.ts +183 -0
- package/src/client/conversations.ts +95 -0
- package/src/client.ts +108 -0
- package/src/components/account.ts +206 -0
- package/src/components/channel.ts +253 -0
- package/src/components/component.ts +151 -0
- package/src/components/device.ts +455 -0
- package/src/components/group.ts +546 -0
- package/src/components/message.ts +253 -0
- package/src/components/profile.ts +179 -0
- package/src/crypto/groups.ts +107 -0
- package/src/crypto/messages.ts +129 -0
- package/src/crypto/primitives.ts +103 -0
- package/src/errors.ts +13 -0
- package/src/groups/account-sync.ts +144 -0
- package/src/groups/messages.ts +89 -0
- package/src/groups/operations.ts +145 -0
- package/src/groups/repository.ts +161 -0
- package/src/groups/secrets.ts +256 -0
- package/src/groups/state.ts +138 -0
- package/src/identity/identifiers.ts +41 -0
- package/src/identity/neo.ts +72 -0
- package/src/index.ts +52 -0
- package/src/interactions.ts +35 -0
- package/src/messages/account-sender.ts +33 -0
- package/src/messages/contacts.ts +379 -0
- package/src/messages/outbox.ts +152 -0
- package/src/messages/receiver.ts +86 -0
- package/src/messages/repository.ts +230 -0
- package/src/models/authentication.ts +63 -0
- package/src/models/channels.ts +155 -0
- package/src/models/contacts.ts +141 -0
- package/src/models/content.ts +105 -0
- package/src/models/device-state.ts +18 -0
- package/src/models/group-admission.ts +110 -0
- package/src/models/group-keys.ts +34 -0
- package/src/models/group-management.ts +182 -0
- package/src/models/groups.ts +100 -0
- package/src/models/identity.ts +164 -0
- package/src/models/messages.ts +139 -0
- package/src/models/profile.ts +46 -0
- package/src/models/relay.ts +151 -0
- package/src/protocol/codec.ts +144 -0
- package/src/protocol/context.ts +39 -0
- package/src/protocol/encoding.ts +106 -0
- package/src/protocol/json.ts +140 -0
- package/src/protocol/validation.ts +13 -0
- package/src/runtime/abort.ts +27 -0
- package/src/runtime/async-gate.ts +16 -0
- package/src/runtime/async-pulse.ts +20 -0
- package/src/runtime/clock.ts +63 -0
- package/src/runtime/events.ts +31 -0
- package/src/runtime/url.ts +17 -0
- package/src/storage/signed-request.ts +26 -0
- package/src/storage/store.ts +90 -0
- package/src/storage/transaction.ts +17 -0
- package/src/transport/client.ts +328 -0
- package/src/transport/discovery.ts +64 -0
- package/src/transport/endpoint.ts +32 -0
- package/src/transport/http.ts +129 -0
- package/src/transport/pool.ts +115 -0
- package/src/transport/relay-error.ts +46 -0
- package/src/transport/rpc.ts +56 -0
- package/src/transport/session.ts +154 -0
- package/src/transport/socket.ts +248 -0
- package/src/transport/subscription.ts +117 -0
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
import { createAbortController } from '../runtime/abort.js';
|
|
2
|
+
import { systemRandom } from '../crypto/primitives.js';
|
|
3
|
+
import { ProtocolError } from '../errors.js';
|
|
4
|
+
import { abortScope, awaitWithSignal, systemClock, throwIfAborted } from '../runtime/clock.js';
|
|
5
|
+
import { EventHub } from '../runtime/events.js';
|
|
6
|
+
import { RelayDiscovery } from './discovery.js';
|
|
7
|
+
import { HttpRelayTransport, RelayBackoff } from './http.js';
|
|
8
|
+
import { RelayError } from './relay-error.js';
|
|
9
|
+
import { HttpRelaySessions, RelayAuthenticator } from './session.js';
|
|
10
|
+
import { RpcConnection } from './socket.js';
|
|
11
|
+
import { RelaySubscription } from './subscription.js';
|
|
12
|
+
function readiness() {
|
|
13
|
+
let settled = false;
|
|
14
|
+
let resolve, reject;
|
|
15
|
+
const promise = new Promise((yes, no) => { resolve = yes; reject = no; });
|
|
16
|
+
// A notification-only client may have no readiness waiter; retain errors for later callers.
|
|
17
|
+
promise.then(() => undefined, () => undefined);
|
|
18
|
+
return { promise, get settled() { return settled; }, resolve(slot) { settled = true; resolve(slot); }, reject(error) { settled = true; reject(error); } };
|
|
19
|
+
}
|
|
20
|
+
function retryable(error) {
|
|
21
|
+
if (error instanceof RelayError)
|
|
22
|
+
return ['unauthorized', 'temporarily_unavailable', 'bad_gateway', 'rate_limited'].includes(error.code);
|
|
23
|
+
if (error instanceof ProtocolError)
|
|
24
|
+
return ['socket_closed', 'socket_error', 'notification_overflow'].includes(error.code);
|
|
25
|
+
if (error instanceof Error && error.name === 'TimeoutError')
|
|
26
|
+
return true;
|
|
27
|
+
// Fetch uses TypeError for connection failure; Node HTTPS preserves its system error code.
|
|
28
|
+
return error instanceof TypeError || error instanceof Error && 'code' in error
|
|
29
|
+
&& ['ECONNRESET', 'ECONNREFUSED', 'ENOTFOUND', 'EAI_AGAIN', 'ETIMEDOUT', 'EPIPE'].includes(String(error.code));
|
|
30
|
+
}
|
|
31
|
+
/** Pool-owned transport for one relay and one immutable session identity. No constructor I/O. */
|
|
32
|
+
export class RelayClient {
|
|
33
|
+
relayId;
|
|
34
|
+
#events = new EventHub();
|
|
35
|
+
#lifetime = createAbortController();
|
|
36
|
+
#clock;
|
|
37
|
+
#random;
|
|
38
|
+
#options;
|
|
39
|
+
#http;
|
|
40
|
+
#discovery;
|
|
41
|
+
#sessions;
|
|
42
|
+
#authenticator;
|
|
43
|
+
#backoff;
|
|
44
|
+
#httpSession;
|
|
45
|
+
#socket;
|
|
46
|
+
#opening;
|
|
47
|
+
#notifications;
|
|
48
|
+
#ready = readiness();
|
|
49
|
+
#generation = 0;
|
|
50
|
+
#connection = 'disconnected';
|
|
51
|
+
#authenticating = false;
|
|
52
|
+
#authenticationRejected = false;
|
|
53
|
+
#lastError;
|
|
54
|
+
#terminal;
|
|
55
|
+
#disposal;
|
|
56
|
+
#subscriptions = new Map();
|
|
57
|
+
constructor(relayId, registry, options = {}, authenticator) {
|
|
58
|
+
this.relayId = relayId;
|
|
59
|
+
this.#options = { ...options };
|
|
60
|
+
this.#clock = options.clock ?? systemClock;
|
|
61
|
+
this.#random = options.random ?? systemRandom;
|
|
62
|
+
this.#backoff = new RelayBackoff(this.#clock);
|
|
63
|
+
this.#http = new HttpRelayTransport({ ...options, backoff: this.#backoff });
|
|
64
|
+
this.#discovery = new RelayDiscovery(relayId, registry, this.#http, this.#clock);
|
|
65
|
+
if (authenticator && (authenticator.relayId !== relayId || authenticator.context.toString() !== registry.context.toString()))
|
|
66
|
+
throw new ProtocolError('invalid_identity', 'Authenticator does not match this relay and network.');
|
|
67
|
+
this.#authenticator = authenticator;
|
|
68
|
+
if (authenticator)
|
|
69
|
+
this.#sessions = new HttpRelaySessions(authenticator, this.#http);
|
|
70
|
+
}
|
|
71
|
+
get sessionMode() { return this.#authenticator?.mode; }
|
|
72
|
+
get isDisposed() { return this.#lifetime.signal.aborted; }
|
|
73
|
+
#hasValidSession() { return (this.#httpSession?.remainingSeconds ?? 0) > 0 || this.#socket !== undefined && !this.#socket.connection.failure && this.#socket.session.remainingSeconds > 0; }
|
|
74
|
+
get state() {
|
|
75
|
+
const valid = this.#hasValidSession();
|
|
76
|
+
return Object.freeze({ connection: this.#connection,
|
|
77
|
+
authentication: this.isDisposed ? 'none' : this.#authenticationRejected ? 'rejected' : valid ? this.sessionMode : this.#authenticating ? 'authenticating' : this.#httpSession || this.#socket ? 'expired' : 'none',
|
|
78
|
+
sessionMode: this.sessionMode, lastError: this.#lastError });
|
|
79
|
+
}
|
|
80
|
+
on(event, listener) { return this.#events.on(event, listener); }
|
|
81
|
+
#check(signal) { throwIfAborted(signal); throwIfAborted(this.#lifetime.signal); if (this.#terminal !== undefined)
|
|
82
|
+
throw this.#terminal; }
|
|
83
|
+
#notify(event, value) {
|
|
84
|
+
this.#events.notify(event, value, error => this.#publishError(this.#lastError === undefined ? error
|
|
85
|
+
: new AggregateError([this.#lastError, error], 'Relay operation and observer failed.')));
|
|
86
|
+
}
|
|
87
|
+
#stateChanged() { this.#notify('stateChanged', this.state); }
|
|
88
|
+
#publishError(error) {
|
|
89
|
+
this.#lastError = error;
|
|
90
|
+
// Do not publish another state event for observer failures: a failing state
|
|
91
|
+
// subscriber must not recursively trigger itself through error reporting.
|
|
92
|
+
this.#events.notify('errorOccurred', error, observerError => {
|
|
93
|
+
this.#lastError = new AggregateError([error, observerError], 'Relay operation and error observer failed.');
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
#report(error) {
|
|
97
|
+
if (error instanceof RelayError && ['unauthorized', 'device_unknown', 'invalid_signature'].includes(error.code))
|
|
98
|
+
this.#authenticationRejected = true;
|
|
99
|
+
this.#publishError(error);
|
|
100
|
+
this.#stateChanged();
|
|
101
|
+
}
|
|
102
|
+
#acceptHttpSession(session) {
|
|
103
|
+
// A public response or a cached token is not evidence that a rejected
|
|
104
|
+
// identity has authenticated again. Only a newly issued session clears it.
|
|
105
|
+
if (session !== this.#httpSession)
|
|
106
|
+
this.#authenticationRejected = false;
|
|
107
|
+
this.#httpSession = session;
|
|
108
|
+
}
|
|
109
|
+
getDescriptor(signal) { this.#check(signal); return this.#discovery.getDescriptor(signal); }
|
|
110
|
+
getInfo(signal) { this.#check(signal); return this.#discovery.getInfo(signal); }
|
|
111
|
+
async authenticate(signal) {
|
|
112
|
+
this.#check(signal);
|
|
113
|
+
if (!this.#sessions)
|
|
114
|
+
throw new ProtocolError('authentication_required', 'This relay client has no authentication identity.');
|
|
115
|
+
if (!this.#hasValidSession())
|
|
116
|
+
this.#authenticationRejected = false;
|
|
117
|
+
this.#authenticating = true;
|
|
118
|
+
this.#connection = 'connecting';
|
|
119
|
+
try {
|
|
120
|
+
this.#stateChanged();
|
|
121
|
+
const descriptor = await this.getDescriptor(signal);
|
|
122
|
+
this.#acceptHttpSession(await this.#sessions.get(descriptor.endpoints.find(value => value.startsWith('https://')), signal));
|
|
123
|
+
this.#check(signal);
|
|
124
|
+
this.#connection = 'connected';
|
|
125
|
+
this.#lastError = undefined;
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
if (!signal?.aborted && !this.isDisposed)
|
|
129
|
+
this.#report(error);
|
|
130
|
+
throw error;
|
|
131
|
+
}
|
|
132
|
+
finally {
|
|
133
|
+
this.#authenticating = false;
|
|
134
|
+
this.#stateChanged();
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
async requestHttp(method, name, parameters, options = {}) {
|
|
138
|
+
this.#check(options.signal);
|
|
139
|
+
const scope = abortScope([options.signal, this.#lifetime.signal]);
|
|
140
|
+
let session;
|
|
141
|
+
try {
|
|
142
|
+
const descriptor = await this.getDescriptor(scope.signal);
|
|
143
|
+
const endpoint = descriptor.endpoints.find(value => value.startsWith('https://'));
|
|
144
|
+
if (options.authenticated !== false) {
|
|
145
|
+
if (!this.#sessions)
|
|
146
|
+
throw new ProtocolError('authentication_required', 'Establish a relay session before an authenticated request.');
|
|
147
|
+
session = await this.#sessions.get(endpoint, scope.signal);
|
|
148
|
+
this.#acceptHttpSession(session);
|
|
149
|
+
}
|
|
150
|
+
const result = await this.#http.request(endpoint, method, name, parameters, session?.getToken(endpoint), scope.signal);
|
|
151
|
+
this.#connection = 'connected';
|
|
152
|
+
this.#lastError = undefined;
|
|
153
|
+
this.#stateChanged();
|
|
154
|
+
return result;
|
|
155
|
+
}
|
|
156
|
+
catch (error) {
|
|
157
|
+
if (error instanceof RelayError && error.code === 'unauthorized' && session) {
|
|
158
|
+
this.#sessions.invalidate(session);
|
|
159
|
+
if (this.#httpSession === session)
|
|
160
|
+
this.#httpSession = undefined;
|
|
161
|
+
}
|
|
162
|
+
if (!scope.signal.aborted)
|
|
163
|
+
this.#report(error);
|
|
164
|
+
throw error;
|
|
165
|
+
}
|
|
166
|
+
finally {
|
|
167
|
+
scope.dispose();
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
async #getSocket(signal) {
|
|
171
|
+
this.#check(signal);
|
|
172
|
+
if (!this.#authenticator)
|
|
173
|
+
throw new ProtocolError('authentication_required', 'WebSocket connections require an authentication identity.');
|
|
174
|
+
if (!this.#opening) {
|
|
175
|
+
const opening = this.#openSocket();
|
|
176
|
+
this.#opening = opening;
|
|
177
|
+
opening.then(() => { if (this.#opening === opening)
|
|
178
|
+
this.#opening = undefined; }, () => { if (this.#opening === opening)
|
|
179
|
+
this.#opening = undefined; });
|
|
180
|
+
}
|
|
181
|
+
return awaitWithSignal(this.#opening, signal);
|
|
182
|
+
}
|
|
183
|
+
async #openSocket() {
|
|
184
|
+
const descriptor = await this.getDescriptor(this.#lifetime.signal);
|
|
185
|
+
const endpoint = descriptor.endpoints.find(value => value.startsWith('wss://'));
|
|
186
|
+
if (!endpoint)
|
|
187
|
+
throw new ProtocolError('socket_unavailable', 'The relay does not advertise WebSocket support.');
|
|
188
|
+
const existing = this.#socket;
|
|
189
|
+
if (existing && existing.connection.endpoint === endpoint && !existing.connection.failure && existing.session.remainingSeconds > 0)
|
|
190
|
+
return existing;
|
|
191
|
+
if (existing) {
|
|
192
|
+
existing.controller.abort();
|
|
193
|
+
existing.connection.dispose();
|
|
194
|
+
await existing.renewal;
|
|
195
|
+
this.#socket = undefined;
|
|
196
|
+
}
|
|
197
|
+
const connection = new RpcConnection(endpoint, { ...this.#options, clock: this.#clock, random: this.#random, backoff: this.#backoff });
|
|
198
|
+
const timeout = abortScope([this.#lifetime.signal], this.#options.requestTimeoutMilliseconds ?? 60000);
|
|
199
|
+
this.#connection = 'connecting';
|
|
200
|
+
this.#stateChanged();
|
|
201
|
+
try {
|
|
202
|
+
const session = await this.#authenticator.authenticate(endpoint, (name, params, signal) => connection.request(name, params, signal), timeout.signal);
|
|
203
|
+
this.#check(timeout.signal);
|
|
204
|
+
const slot = { connection, session, controller: createAbortController(), renewal: Promise.resolve(), generation: ++this.#generation };
|
|
205
|
+
this.#socket = slot;
|
|
206
|
+
this.#authenticationRejected = false;
|
|
207
|
+
slot.renewal = this.#renew(slot);
|
|
208
|
+
this.#connection = 'connected';
|
|
209
|
+
this.#lastError = undefined;
|
|
210
|
+
this.#stateChanged();
|
|
211
|
+
return slot;
|
|
212
|
+
}
|
|
213
|
+
catch (error) {
|
|
214
|
+
connection.dispose();
|
|
215
|
+
if (this.#socket?.connection === connection) {
|
|
216
|
+
const failed = this.#socket;
|
|
217
|
+
this.#socket = undefined;
|
|
218
|
+
failed.controller.abort(error);
|
|
219
|
+
await failed.renewal;
|
|
220
|
+
}
|
|
221
|
+
throw error;
|
|
222
|
+
}
|
|
223
|
+
finally {
|
|
224
|
+
timeout.dispose();
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
async #renew(slot) {
|
|
228
|
+
const scope = abortScope([this.#lifetime.signal, slot.controller.signal]);
|
|
229
|
+
try {
|
|
230
|
+
while (!scope.signal.aborted) {
|
|
231
|
+
const previous = slot.session;
|
|
232
|
+
const remaining = previous.remainingSeconds;
|
|
233
|
+
if (remaining <= 0)
|
|
234
|
+
throw new ProtocolError('expired_session', 'The WebSocket session expired.');
|
|
235
|
+
const due = this.#clock.monotonicMilliseconds() + Math.max(remaining * 0.8, remaining - 30) * 1000;
|
|
236
|
+
while (due > this.#clock.monotonicMilliseconds())
|
|
237
|
+
await this.#clock.delay(Math.min(60000, due - this.#clock.monotonicMilliseconds()), scope.signal);
|
|
238
|
+
const deadline = abortScope([scope.signal], Math.max(1, Math.min(60000, Math.floor(previous.remainingSeconds * 1000))));
|
|
239
|
+
try {
|
|
240
|
+
const renewed = await this.#authenticator.authenticate(slot.connection.endpoint, (name, params, signal) => slot.connection.request(name, params, signal), deadline.signal);
|
|
241
|
+
if (previous.remainingSeconds <= 0)
|
|
242
|
+
throw new ProtocolError('expired_session', 'Previous socket session expired before renewal completed.');
|
|
243
|
+
slot.session = renewed;
|
|
244
|
+
this.#authenticationRejected = false;
|
|
245
|
+
this.#stateChanged();
|
|
246
|
+
}
|
|
247
|
+
catch (error) {
|
|
248
|
+
if (error instanceof RelayError && error.code !== 'unauthorized' && previous.remainingSeconds > 0) {
|
|
249
|
+
this.#report(error);
|
|
250
|
+
// A rejected renewal other than unauthorized leaves the
|
|
251
|
+
// already accepted socket session usable until expiry.
|
|
252
|
+
this.#authenticationRejected = false;
|
|
253
|
+
this.#stateChanged();
|
|
254
|
+
await this.#clock.delay(Math.min(5000, previous.remainingSeconds * 1000), scope.signal);
|
|
255
|
+
}
|
|
256
|
+
else
|
|
257
|
+
throw error;
|
|
258
|
+
}
|
|
259
|
+
finally {
|
|
260
|
+
deadline.dispose();
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
catch (error) {
|
|
265
|
+
if (!scope.signal.aborted) {
|
|
266
|
+
this.#report(error);
|
|
267
|
+
slot.connection.fail(error);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
finally {
|
|
271
|
+
scope.dispose();
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
/** Device notification reconnection restores transport only; callers synchronize after socketConnected. */
|
|
275
|
+
startNotifications() {
|
|
276
|
+
this.#check();
|
|
277
|
+
if (this.sessionMode !== 'device')
|
|
278
|
+
throw new ProtocolError('device_session_required', 'Notifications require a device session.');
|
|
279
|
+
this.#notifications ??= this.#dispatchNotifications();
|
|
280
|
+
}
|
|
281
|
+
async #dispatchNotifications() {
|
|
282
|
+
let failures = 0;
|
|
283
|
+
try {
|
|
284
|
+
while (!this.isDisposed) {
|
|
285
|
+
try {
|
|
286
|
+
const slot = await this.#getSocket(this.#lifetime.signal);
|
|
287
|
+
this.#ready.resolve(slot);
|
|
288
|
+
this.#notify('socketConnected', { generation: slot.generation });
|
|
289
|
+
failures = 0;
|
|
290
|
+
for (;;) {
|
|
291
|
+
const notification = await slot.connection.nextNotification(this.#lifetime.signal);
|
|
292
|
+
if (slot.session.remainingSeconds <= 0)
|
|
293
|
+
throw new ProtocolError('expired_session', 'A notification arrived after socket session expiry.');
|
|
294
|
+
this.#notify('notificationReceived', notification);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
catch (error) {
|
|
298
|
+
if (this.isDisposed)
|
|
299
|
+
break;
|
|
300
|
+
this.#connection = 'disconnected';
|
|
301
|
+
if (this.#ready.settled)
|
|
302
|
+
this.#ready = readiness();
|
|
303
|
+
this.#report(error);
|
|
304
|
+
if (!retryable(error)) {
|
|
305
|
+
this.#terminal = error;
|
|
306
|
+
this.#ready.reject(error);
|
|
307
|
+
this.#socket?.controller.abort(error);
|
|
308
|
+
this.#socket?.connection.fail(error);
|
|
309
|
+
this.#notify('faulted', error);
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
const jitter = this.#random.bytes(2);
|
|
313
|
+
const fraction = ((jitter[0] << 8) | jitter[1]) / 65536;
|
|
314
|
+
await this.#clock.delay((Math.min(30, 2 ** Math.min(failures++, 5)) + fraction) * 1000, this.#lifetime.signal);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
catch (error) {
|
|
319
|
+
if (!this.isDisposed) {
|
|
320
|
+
this.#terminal = error;
|
|
321
|
+
this.#ready.reject(error);
|
|
322
|
+
this.#report(error);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
async requestWebSocket(method, parameters, signal) {
|
|
327
|
+
this.#check(signal);
|
|
328
|
+
const deadline = abortScope([signal, this.#lifetime.signal], this.#options.requestTimeoutMilliseconds ?? 60000);
|
|
329
|
+
try {
|
|
330
|
+
let slot;
|
|
331
|
+
if (this.sessionMode === 'device') {
|
|
332
|
+
this.startNotifications();
|
|
333
|
+
slot = await awaitWithSignal(this.#ready.promise, deadline.signal);
|
|
334
|
+
}
|
|
335
|
+
else
|
|
336
|
+
slot = await this.#getSocket(deadline.signal);
|
|
337
|
+
const result = await slot.connection.request(method, parameters, deadline.signal);
|
|
338
|
+
this.#connection = 'connected';
|
|
339
|
+
this.#lastError = undefined;
|
|
340
|
+
this.#stateChanged();
|
|
341
|
+
return result;
|
|
342
|
+
}
|
|
343
|
+
catch (error) {
|
|
344
|
+
if (!deadline.signal.aborted)
|
|
345
|
+
this.#report(error);
|
|
346
|
+
throw error;
|
|
347
|
+
}
|
|
348
|
+
finally {
|
|
349
|
+
deadline.dispose();
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
/** Owns the complete replacement stream for this method; dispose it after stopping its update producers. */
|
|
353
|
+
createSubscription(method, empty, options = {}) {
|
|
354
|
+
this.#check(options.signal);
|
|
355
|
+
if (this.sessionMode !== 'device')
|
|
356
|
+
throw new ProtocolError('device_session_required', 'Subscriptions require a device session.');
|
|
357
|
+
if (method !== 'channel.subscribe' && method !== 'group.subscribe')
|
|
358
|
+
throw new TypeError('Unknown subscription method.');
|
|
359
|
+
if (this.#subscriptions.has(method))
|
|
360
|
+
throw new ProtocolError('subscription_in_use', 'This client already has an owner for the subscription method.');
|
|
361
|
+
const subscription = new RelaySubscription(method, empty, { ...options }, {
|
|
362
|
+
clock: this.#clock, lifetime: this.#lifetime.signal, onConnected: listener => this.on('socketConnected', listener),
|
|
363
|
+
ready: async (signal) => {
|
|
364
|
+
this.startNotifications();
|
|
365
|
+
const slot = await awaitWithSignal(this.#ready.promise, signal);
|
|
366
|
+
return { generation: slot.generation, get failure() { return slot.connection.failure; },
|
|
367
|
+
request: (name, params, token) => slot.connection.request(name, params, token), retire: error => slot.connection.fail(error) };
|
|
368
|
+
},
|
|
369
|
+
closed: () => { if (this.#subscriptions.get(method) === subscription)
|
|
370
|
+
this.#subscriptions.delete(method); },
|
|
371
|
+
});
|
|
372
|
+
this.#subscriptions.set(method, subscription);
|
|
373
|
+
return subscription;
|
|
374
|
+
}
|
|
375
|
+
dispose() {
|
|
376
|
+
return this.#disposal ??= (async () => {
|
|
377
|
+
const reason = new DOMException('Relay client was disposed.', 'AbortError');
|
|
378
|
+
this.#lifetime.abort(reason);
|
|
379
|
+
this.#ready.reject(reason);
|
|
380
|
+
this.#sessions?.dispose();
|
|
381
|
+
this.#discovery.dispose();
|
|
382
|
+
this.#http.dispose();
|
|
383
|
+
this.#socket?.controller.abort(reason);
|
|
384
|
+
this.#socket?.connection.dispose();
|
|
385
|
+
await Promise.allSettled([this.#opening, this.#notifications, this.#socket?.renewal, ...[...this.#subscriptions.values()].map(value => value.dispose())]);
|
|
386
|
+
this.#connection = 'disconnected';
|
|
387
|
+
this.#stateChanged();
|
|
388
|
+
this.#events.clear();
|
|
389
|
+
})();
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/transport/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAqB,MAAM,yBAAyB,CAAC;AAC1E,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAK7C,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,WAAW,EAAE,cAAc,EAA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ClC,IAAI,CAAC,aAAa,EAAE,CAAC;YAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QAC/C,CAAC,CAAC,EAAE,CAAC;IACT,CAAC;CACJ"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { RelayRegistry } from '../interactions.js';
|
|
2
|
+
import { type RelayDescriptor, type RelayInfo } from '../models/relay.js';
|
|
3
|
+
import { NetworkContext } from '../protocol/context.js';
|
|
4
|
+
import { type RuntimeClock } from '../runtime/clock.js';
|
|
5
|
+
import type { HttpRelayTransport } from './http.js';
|
|
6
|
+
/** Resolves one trusted relay identity; descriptors, never old URLs, authorize endpoint selection. */
|
|
7
|
+
export declare class RelayDiscovery {
|
|
8
|
+
#private;
|
|
9
|
+
readonly relayId: string;
|
|
10
|
+
readonly registry: RelayRegistry;
|
|
11
|
+
readonly transport: HttpRelayTransport;
|
|
12
|
+
readonly clock: RuntimeClock;
|
|
13
|
+
constructor(relayId: string, registry: RelayRegistry, transport: HttpRelayTransport, clock?: RuntimeClock);
|
|
14
|
+
get context(): NetworkContext;
|
|
15
|
+
getDescriptor(signal?: AbortSignal): Promise<RelayDescriptor>;
|
|
16
|
+
getInfo(signal?: AbortSignal): Promise<RelayInfo>;
|
|
17
|
+
dispose(): void;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=discovery.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discovery.d.ts","sourceRoot":"","sources":["../../src/transport/discovery.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAoF,KAAK,eAAe,EAAE,KAAK,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC5J,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAgD,KAAK,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEtG,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAEpD,sGAAsG;AACtG,qBAAa,cAAc;;IAKX,QAAQ,CAAC,OAAO,EAAE,MAAM;IAAE,QAAQ,CAAC,QAAQ,EAAE,aAAa;IAAE,QAAQ,CAAC,SAAS,EAAE,kBAAkB;IAAE,QAAQ,CAAC,KAAK,EAAE,YAAY;IAA5I,YAAqB,OAAO,EAAE,MAAM,EAAW,QAAQ,EAAE,aAAa,EAAW,SAAS,EAAE,kBAAkB,EAAW,KAAK,GAAE,YAA0B,EAGzJ;IACD,IAAI,OAAO,IAAI,cAAc,CAA0B;IAEjD,aAAa,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,eAAe,CAAC,CAWlE;IAkBK,OAAO,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,SAAS,CAAC,CAQtD;IAGD,OAAO,IAAI,IAAI,CAAqH;CACvI"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { createAbortController } from '../runtime/abort.js';
|
|
2
|
+
import { ProtocolError } from '../errors.js';
|
|
3
|
+
import { validateRelayId } from '../identity/neo.js';
|
|
4
|
+
import { relayDescriptorCodec, relayInfoCodec, validateRelayDescriptor, validateRelayInfo } from '../models/relay.js';
|
|
5
|
+
import { NetworkContext } from '../protocol/context.js';
|
|
6
|
+
import { awaitWithSignal, systemClock, throwIfAborted } from '../runtime/clock.js';
|
|
7
|
+
import { webEndpoint } from './endpoint.js';
|
|
8
|
+
/** Resolves one trusted relay identity; descriptors, never old URLs, authorize endpoint selection. */
|
|
9
|
+
export class RelayDiscovery {
|
|
10
|
+
relayId;
|
|
11
|
+
registry;
|
|
12
|
+
transport;
|
|
13
|
+
clock;
|
|
14
|
+
#lifetime = createAbortController();
|
|
15
|
+
#context;
|
|
16
|
+
#cached;
|
|
17
|
+
#pending;
|
|
18
|
+
constructor(relayId, registry, transport, clock = systemClock) {
|
|
19
|
+
this.relayId = relayId;
|
|
20
|
+
this.registry = registry;
|
|
21
|
+
this.transport = transport;
|
|
22
|
+
this.clock = clock;
|
|
23
|
+
validateRelayId(relayId);
|
|
24
|
+
this.#context = NetworkContext.parse(registry.context.toString());
|
|
25
|
+
}
|
|
26
|
+
get context() { return this.#context; }
|
|
27
|
+
async getDescriptor(signal) {
|
|
28
|
+
throwIfAborted(signal);
|
|
29
|
+
throwIfAborted(this.#lifetime.signal);
|
|
30
|
+
if (this.registry.context.toString() !== this.#context.toString())
|
|
31
|
+
throw new ProtocolError('context_changed', 'The relay registry network context has changed.');
|
|
32
|
+
if (this.#cached && this.#cached.expiresAt > this.clock.nowSeconds())
|
|
33
|
+
return this.#copy(this.#cached);
|
|
34
|
+
if (!this.#pending) {
|
|
35
|
+
const pending = this.#discover();
|
|
36
|
+
this.#pending = pending;
|
|
37
|
+
pending.then(value => { this.#cached = value; if (this.#pending === pending)
|
|
38
|
+
this.#pending = undefined; }, () => { if (this.#pending === pending)
|
|
39
|
+
this.#pending = undefined; });
|
|
40
|
+
}
|
|
41
|
+
return this.#copy(await awaitWithSignal(this.#pending, signal));
|
|
42
|
+
}
|
|
43
|
+
async #discover() {
|
|
44
|
+
const signal = this.#lifetime.signal;
|
|
45
|
+
const entry = await this.registry.getRelay(this.relayId, signal);
|
|
46
|
+
throwIfAborted(signal);
|
|
47
|
+
if (this.registry.context.toString() !== this.#context.toString())
|
|
48
|
+
throw new ProtocolError('context_changed', 'The registry network context changed during discovery.');
|
|
49
|
+
if (!entry || entry.relayId !== this.relayId || entry.status !== 'active')
|
|
50
|
+
throw new ProtocolError('inactive_relay', 'The registry does not identify an active relay with the requested ID.');
|
|
51
|
+
webEndpoint(entry.endpoint, 'https:');
|
|
52
|
+
const wire = await this.transport.request(entry.endpoint, 'GET', 'relay.descriptor', undefined, undefined, signal);
|
|
53
|
+
if (wire === undefined)
|
|
54
|
+
throw new ProtocolError('missing_result', 'Relay discovery returned no descriptor.');
|
|
55
|
+
const descriptor = relayDescriptorCodec.decode(wire);
|
|
56
|
+
validateRelayDescriptor(descriptor, this.#context, this.clock.nowSeconds());
|
|
57
|
+
if (descriptor.relayId !== this.relayId)
|
|
58
|
+
throw new ProtocolError('invalid_identity', 'The descriptor does not identify the registered relay.');
|
|
59
|
+
throwIfAborted(signal);
|
|
60
|
+
return descriptor;
|
|
61
|
+
}
|
|
62
|
+
async getInfo(signal) {
|
|
63
|
+
const descriptor = await this.getDescriptor(signal);
|
|
64
|
+
const endpoint = descriptor.endpoints.find(endpoint => endpoint.startsWith('https://'));
|
|
65
|
+
const wire = await this.transport.request(endpoint, 'GET', 'relay.info', undefined, undefined, signal);
|
|
66
|
+
if (wire === undefined)
|
|
67
|
+
throw new ProtocolError('missing_result', 'Relay info returned no result.');
|
|
68
|
+
const info = relayInfoCodec.decode(wire);
|
|
69
|
+
validateRelayInfo(info, descriptor);
|
|
70
|
+
return info;
|
|
71
|
+
}
|
|
72
|
+
#copy(value) { return relayDescriptorCodec.decode(relayDescriptorCodec.encode(value)); }
|
|
73
|
+
dispose() { this.#cached = undefined; this.#lifetime.abort(new DOMException('Relay discovery was disposed.', 'AbortError')); }
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=discovery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discovery.js","sourceRoot":"","sources":["../../src/transport/discovery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD,OAAO,EAAE,oBAAoB,EAAE,cAAc,EAAE,uBAAuB,EAAE,iBAAiB,EAAwC,MAAM,oBAAoB,CAAC;AAC5J,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,cAAc,EAAqB,MAAM,qBAAqB,CAAC;AACtG,OAAO,EAAE,WAAW,EAAE,M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C,OAAO,GAAG,SAAS,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,YAAY,CAAC,+BAA+B,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;CACvI"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Validates before URL parsing so a parser cannot silently repair unsafe input. */
|
|
2
|
+
export declare function webEndpoint(endpoint: string, protocol?: 'https:' | 'wss:'): URL;
|
|
3
|
+
/** Authentication maps WSS to HTTPS and excludes the endpoint path. */
|
|
4
|
+
export declare function relayOrigin(endpoint: string): string;
|
|
5
|
+
export declare function validateMethodName(name: string): void;
|
|
6
|
+
//# sourceMappingURL=endpoint.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"endpoint.d.ts","sourceRoot":"","sources":["../../src/transport/endpoint.ts"],"names":[],"mappings":"AAIA,oFAAoF;AACpF,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,QAAQ,GAAG,MAAM,GAAG,GAAG,CAe/E;AAED,uEAAuE;AACvE,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAGpD;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAGrD"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ProtocolError } from '../errors.js';
|
|
2
|
+
import { encodeUtf8 } from '../protocol/encoding.js';
|
|
3
|
+
import { parseAbsoluteUrl } from '../runtime/url.js';
|
|
4
|
+
/** Validates before URL parsing so a parser cannot silently repair unsafe input. */
|
|
5
|
+
export function webEndpoint(endpoint, protocol) {
|
|
6
|
+
if (typeof endpoint !== 'string' || !/^(https|wss):\/\//.test(endpoint) || encodeUtf8(endpoint).length > 512
|
|
7
|
+
|| /[\s\p{Cc}?#\\]/u.test(endpoint))
|
|
8
|
+
throw new ProtocolError('invalid_endpoint', 'Expected an HTTPS or WSS relay endpoint without whitespace, query, fragment or backslash.');
|
|
9
|
+
const authority = endpoint.slice(endpoint.indexOf('://') + 3).split('/')[0];
|
|
10
|
+
if (authority.length === 0 || authority.includes('@') || authority.includes('%'))
|
|
11
|
+
throw new ProtocolError('invalid_endpoint', 'Relay endpoints must have a host and cannot contain user information or an escaped authority.');
|
|
12
|
+
// URL accepts malformed percent escapes in paths; the protocol does not.
|
|
13
|
+
if (/%(?![0-9a-fA-F]{2})/.test(endpoint))
|
|
14
|
+
throw new ProtocolError('invalid_endpoint', 'Malformed endpoint escape.');
|
|
15
|
+
let url;
|
|
16
|
+
try {
|
|
17
|
+
url = parseAbsoluteUrl(endpoint);
|
|
18
|
+
}
|
|
19
|
+
catch (cause) {
|
|
20
|
+
throw new ProtocolError('invalid_endpoint', 'Invalid relay endpoint.', { cause });
|
|
21
|
+
}
|
|
22
|
+
if (!url.hostname || (protocol !== undefined && url.protocol !== protocol))
|
|
23
|
+
throw new ProtocolError('invalid_endpoint', 'Unexpected relay endpoint protocol or host.');
|
|
24
|
+
return url;
|
|
25
|
+
}
|
|
26
|
+
/** Authentication maps WSS to HTTPS and excludes the endpoint path. */
|
|
27
|
+
export function relayOrigin(endpoint) {
|
|
28
|
+
const url = webEndpoint(endpoint);
|
|
29
|
+
return `https://${url.hostname.toLowerCase()}${url.port === '' || url.port === '443' ? '' : `:${url.port}`}`;
|
|
30
|
+
}
|
|
31
|
+
export function validateMethodName(name) {
|
|
32
|
+
if (!/^[a-z][a-z0-9_]*(?:\.[a-z][a-z0-9_]*)*$/.test(name) || /\s/.test(name))
|
|
33
|
+
throw new ProtocolError('invalid_method', 'Invalid relay method name.');
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=endpoint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"endpoint.js","sourceRoot":"","sources":["../../src/transport/endpoint.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,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KAAK,QAAQ,CAAC;QACtE,MAAM,IAAI,aAAa,CAAC,kBAAkB,EAAE,6CAA6C,CAAC,CAAC;IAC/F,OAAO,GAAG,CAAC;AACf,CAAC;AAED,uEAAuE;AACvE,MAAM,UAAU,WAAW,CAAC,QAAgB;IACxC,MAAM,GAAG,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAC;IAClC,OAAO,WAAW,GAAG,CAAC,QAAQ,CAAC,WAAW,EAAE,GAAG,GAAG,CAAC,IAAI,KAAK,EAAE,IAAI,GAAG,CAAC,IAAI,KAAK,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC;AACjH,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,IAAY;IAC3C,IAAI,CAAC,yCAAyC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;QACxE,MAAM,IAAI,aAAa,CAAC,gBAAgB,EAAE,4BAA4B,CAAC,CAAC;AAChF,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { type JsonObject, type JsonValue } from '../protocol/json.js';
|
|
2
|
+
import { type RuntimeClock } from '../runtime/clock.js';
|
|
3
|
+
import { type RelayFailure } from './relay-error.js';
|
|
4
|
+
export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
5
|
+
export interface RelayFetchInit {
|
|
6
|
+
readonly method: HttpMethod;
|
|
7
|
+
readonly headers: Readonly<Record<string, string>>;
|
|
8
|
+
readonly body?: string;
|
|
9
|
+
readonly signal: AbortSignal;
|
|
10
|
+
readonly redirect: 'error';
|
|
11
|
+
readonly credentials: 'omit';
|
|
12
|
+
readonly cache: 'no-store';
|
|
13
|
+
readonly referrerPolicy: 'no-referrer';
|
|
14
|
+
}
|
|
15
|
+
export interface RelayFetchResponse {
|
|
16
|
+
readonly status: number;
|
|
17
|
+
readonly redirected?: boolean;
|
|
18
|
+
readonly type?: string;
|
|
19
|
+
readonly headers: {
|
|
20
|
+
get(name: string): string | null;
|
|
21
|
+
};
|
|
22
|
+
readonly body?: {
|
|
23
|
+
cancel(): Promise<void>;
|
|
24
|
+
} | null;
|
|
25
|
+
arrayBuffer(): Promise<ArrayBuffer>;
|
|
26
|
+
}
|
|
27
|
+
/** An injected fetch must honor redirect:error and credentials:omit and must never replay a business request. */
|
|
28
|
+
export type RelayFetch = (url: string, init: RelayFetchInit) => Promise<RelayFetchResponse>;
|
|
29
|
+
/** Share between HTTP and WebSocket for one relay. A rejected request is never automatically retried. */
|
|
30
|
+
export declare class RelayBackoff {
|
|
31
|
+
#private;
|
|
32
|
+
readonly clock: RuntimeClock;
|
|
33
|
+
constructor(clock?: RuntimeClock);
|
|
34
|
+
apply(failure: RelayFailure): void;
|
|
35
|
+
wait(signal?: AbortSignal): Promise<void>;
|
|
36
|
+
}
|
|
37
|
+
/** Strict media-type parsing avoids accepting a second hidden non-UTF8 charset. */
|
|
38
|
+
export declare function validateJsonContentType(value: string | null): void;
|
|
39
|
+
export interface HttpRelayTransportOptions {
|
|
40
|
+
readonly fetch?: RelayFetch;
|
|
41
|
+
readonly backoff?: RelayBackoff;
|
|
42
|
+
readonly requestTimeoutMilliseconds?: number;
|
|
43
|
+
}
|
|
44
|
+
export declare class HttpRelayTransport {
|
|
45
|
+
#private;
|
|
46
|
+
readonly backoff: RelayBackoff;
|
|
47
|
+
constructor(options?: HttpRelayTransportOptions);
|
|
48
|
+
request(endpoint: string, method: HttpMethod, name: string, parameters?: JsonObject, token?: string, signal?: AbortSignal): Promise<JsonValue | undefined>;
|
|
49
|
+
/** Cancels active requests and makes later requests fail. */
|
|
50
|
+
dispose(): void;
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=http.d.ts.map
|