@automerge/subduction 0.7.0-alpha.1 → 0.8.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/dist/cjs/wasm-base64.cjs +1 -1
- package/dist/cjs/web-bindings.cjs +584 -701
- package/dist/cjs/web.cjs +585 -702
- package/dist/esm/wasm-base64.js +1 -1
- package/dist/iife/index.js +580 -695
- package/dist/index.d.ts +269 -283
- package/dist/subduction.wasm +0 -0
- package/dist/wasm_bindgen/bundler/subduction_wasm.d.ts +269 -283
- package/dist/wasm_bindgen/bundler/subduction_wasm.js +1 -1
- package/dist/wasm_bindgen/bundler/subduction_wasm_bg.js +689 -809
- package/dist/wasm_bindgen/bundler/subduction_wasm_bg.wasm +0 -0
- package/dist/wasm_bindgen/bundler/subduction_wasm_bg.wasm.d.ts +83 -93
- package/dist/wasm_bindgen/nodejs/subduction_wasm.cjs +689 -811
- package/dist/wasm_bindgen/nodejs/subduction_wasm.d.ts +269 -283
- package/dist/wasm_bindgen/nodejs/subduction_wasm_bg.wasm +0 -0
- package/dist/wasm_bindgen/nodejs/subduction_wasm_bg.wasm.d.ts +83 -93
- package/dist/wasm_bindgen/web/subduction_wasm.d.ts +352 -376
- package/dist/wasm_bindgen/web/subduction_wasm.js +689 -809
- package/dist/wasm_bindgen/web/subduction_wasm_bg.wasm +0 -0
- package/dist/wasm_bindgen/web/subduction_wasm_bg.wasm.d.ts +83 -93
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,23 +1,6 @@
|
|
|
1
1
|
/* tslint:disable */
|
|
2
2
|
/* eslint-disable */
|
|
3
3
|
|
|
4
|
-
export interface Connection {
|
|
5
|
-
disconnect(): Promise<void>;
|
|
6
|
-
send(message: Message): Promise<void>;
|
|
7
|
-
recv(): Promise<Message>;
|
|
8
|
-
nextRequestId(): Promise<RequestId>;
|
|
9
|
-
call(request: BatchSyncRequest, timeoutMs: number | null): Promise<BatchSyncResponse>;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
export interface HandshakeConnection extends Connection {
|
|
15
|
-
sendBytes(bytes: Uint8Array): Promise<void>;
|
|
16
|
-
recvBytes(): Promise<Uint8Array>;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
4
|
export interface SedimentreeStorage {
|
|
22
5
|
saveSedimentreeId(sedimentreeId: SedimentreeId): Promise<void>;
|
|
23
6
|
deleteSedimentreeId(sedimentreeId: SedimentreeId): Promise<void>;
|
|
@@ -42,38 +25,72 @@ export interface SedimentreeStorage {
|
|
|
42
25
|
|
|
43
26
|
|
|
44
27
|
|
|
28
|
+
export interface Transport {
|
|
29
|
+
sendBytes(bytes: Uint8Array): Promise<void>;
|
|
30
|
+
recvBytes(): Promise<Uint8Array>;
|
|
31
|
+
disconnect(): Promise<void>;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* An authenticated HTTP long-poll transport.
|
|
38
|
+
*
|
|
39
|
+
* This wrapper proves that the transport has completed the Subduction handshake
|
|
40
|
+
* and the peer identity has been cryptographically verified.
|
|
41
|
+
*
|
|
42
|
+
* Obtain via [`SubductionLongPoll::tryConnect`] or [`SubductionLongPoll::tryDiscover`].
|
|
43
|
+
*/
|
|
44
|
+
export class AuthenticatedLongPoll {
|
|
45
|
+
private constructor();
|
|
46
|
+
free(): void;
|
|
47
|
+
[Symbol.dispose](): void;
|
|
48
|
+
/**
|
|
49
|
+
* Convert to a transport-erased [`AuthenticatedTransport`](super::WasmAuthenticatedTransport).
|
|
50
|
+
*/
|
|
51
|
+
toTransport(): AuthenticatedTransport;
|
|
52
|
+
/**
|
|
53
|
+
* The verified peer identity.
|
|
54
|
+
*/
|
|
55
|
+
readonly peerId: PeerId;
|
|
56
|
+
/**
|
|
57
|
+
* The session ID assigned by the server.
|
|
58
|
+
*/
|
|
59
|
+
readonly sessionId: string;
|
|
60
|
+
}
|
|
61
|
+
|
|
45
62
|
/**
|
|
46
|
-
* A transport-erased authenticated
|
|
63
|
+
* A transport-erased authenticated transport.
|
|
47
64
|
*
|
|
48
|
-
* Wraps an [`Authenticated<
|
|
65
|
+
* Wraps an [`Authenticated<MessageTransport<JsTransport>>`] and is the common type
|
|
49
66
|
* accepted by [`addConnection`](crate::subduction::WasmSubduction::add_connection).
|
|
50
67
|
*
|
|
51
68
|
* # Construction
|
|
52
69
|
*
|
|
53
|
-
* There are three ways to obtain an `
|
|
70
|
+
* There are three ways to obtain an `AuthenticatedTransport`:
|
|
54
71
|
*
|
|
55
|
-
* 1. **Custom transport** — implement
|
|
56
|
-
* (
|
|
72
|
+
* 1. **Custom transport** — implement the `Transport` interface
|
|
73
|
+
* (`sendBytes`/`recvBytes`/`disconnect`) and call [`setup`](Self::setup):
|
|
57
74
|
*
|
|
58
75
|
* ```js
|
|
59
|
-
* const auth = await
|
|
76
|
+
* const auth = await AuthenticatedTransport.setup(myTransport, signer, peerId);
|
|
60
77
|
* ```
|
|
61
78
|
*
|
|
62
79
|
* 2. **From WebSocket** — authenticate via [`SubductionWebSocket`] then convert:
|
|
63
80
|
*
|
|
64
81
|
* ```js
|
|
65
82
|
* const wsAuth = await SubductionWebSocket.tryConnect(url, signer, peerId, timeout);
|
|
66
|
-
* const auth = wsAuth.
|
|
83
|
+
* const auth = wsAuth.toTransport();
|
|
67
84
|
* ```
|
|
68
85
|
*
|
|
69
86
|
* 3. **From HTTP long-poll** — same pattern via [`SubductionLongPoll`]:
|
|
70
87
|
*
|
|
71
88
|
* ```js
|
|
72
89
|
* const lpAuth = await SubductionLongPoll.tryConnect(url, signer, peerId, timeout);
|
|
73
|
-
* const auth = lpAuth.
|
|
90
|
+
* const auth = lpAuth.toTransport();
|
|
74
91
|
* ```
|
|
75
92
|
*/
|
|
76
|
-
export class
|
|
93
|
+
export class AuthenticatedTransport {
|
|
77
94
|
private constructor();
|
|
78
95
|
free(): void;
|
|
79
96
|
[Symbol.dispose](): void;
|
|
@@ -85,7 +102,7 @@ export class AuthenticatedConnection {
|
|
|
85
102
|
*
|
|
86
103
|
* # Arguments
|
|
87
104
|
*
|
|
88
|
-
* * `
|
|
105
|
+
* * `transport` - A `Transport` implementing `sendBytes`/`recvBytes`/`disconnect`
|
|
89
106
|
* * `signer` - The responder's signer for authentication
|
|
90
107
|
* * `max_drift_seconds` - Maximum acceptable clock drift in seconds (default: 600)
|
|
91
108
|
*
|
|
@@ -93,18 +110,19 @@ export class AuthenticatedConnection {
|
|
|
93
110
|
*
|
|
94
111
|
* Returns a [`HandshakeError`](WasmHandshakeError) if the handshake fails.
|
|
95
112
|
*/
|
|
96
|
-
static accept(
|
|
113
|
+
static accept(transport: Transport, signer: any, max_drift_seconds?: number | null): Promise<AuthenticatedTransport>;
|
|
97
114
|
/**
|
|
98
115
|
* Run the Subduction handshake over a custom transport, producing an
|
|
99
|
-
* authenticated
|
|
116
|
+
* authenticated transport.
|
|
100
117
|
*
|
|
101
|
-
* The `
|
|
102
|
-
* (
|
|
103
|
-
*
|
|
118
|
+
* The `transport` object must implement the `Transport` interface
|
|
119
|
+
* (`sendBytes`/`recvBytes`/`disconnect`).
|
|
120
|
+
* The same object is used for both the handshake phase and post-handshake
|
|
121
|
+
* communication.
|
|
104
122
|
*
|
|
105
123
|
* # Arguments
|
|
106
124
|
*
|
|
107
|
-
* * `
|
|
125
|
+
* * `transport` - A `Transport` implementing `sendBytes`/`recvBytes`/`disconnect`
|
|
108
126
|
* * `signer` - The client's signer for authentication
|
|
109
127
|
* * `expected_peer_id` - The expected server peer ID (verified during handshake)
|
|
110
128
|
*
|
|
@@ -112,41 +130,35 @@ export class AuthenticatedConnection {
|
|
|
112
130
|
*
|
|
113
131
|
* Returns a [`HandshakeError`](WasmHandshakeError) if the handshake fails.
|
|
114
132
|
*/
|
|
115
|
-
static setup(
|
|
133
|
+
static setup(transport: Transport, signer: any, expected_peer_id: PeerId): Promise<AuthenticatedTransport>;
|
|
116
134
|
/**
|
|
117
|
-
*
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* Convert to a transport-erased [`AuthenticatedConnection`](super::WasmAuthenticatedConnection).
|
|
135
|
+
* Run the Subduction handshake over a custom transport using discovery
|
|
136
|
+
* mode, producing an authenticated transport.
|
|
137
|
+
*
|
|
138
|
+
* Unlike [`setup`](Self::setup) which requires a known peer ID,
|
|
139
|
+
* this method discovers the peer's identity during the handshake
|
|
140
|
+
* using a shared service name.
|
|
141
|
+
*
|
|
142
|
+
* # Arguments
|
|
143
|
+
*
|
|
144
|
+
* * `transport` - A `Transport` implementing `sendBytes`/`recvBytes`/`disconnect`
|
|
145
|
+
* * `signer` - The client's signer for authentication
|
|
146
|
+
* * `service_name` - Shared service name for discovery.
|
|
147
|
+
* Defaults to [`DEFAULT_LOCAL_SERVICE_NAME`] (`"subduction:local"`) if omitted.
|
|
148
|
+
*
|
|
149
|
+
* # Errors
|
|
150
|
+
*
|
|
151
|
+
* Returns a [`HandshakeError`](WasmHandshakeError) if the handshake fails.
|
|
136
152
|
*/
|
|
137
|
-
|
|
153
|
+
static setupDiscover(transport: Transport, signer: any, service_name?: string | null): Promise<AuthenticatedTransport>;
|
|
138
154
|
/**
|
|
139
155
|
* The verified peer identity.
|
|
140
156
|
*/
|
|
141
157
|
readonly peerId: PeerId;
|
|
142
|
-
/**
|
|
143
|
-
* The session ID assigned by the server.
|
|
144
|
-
*/
|
|
145
|
-
readonly sessionId: string;
|
|
146
158
|
}
|
|
147
159
|
|
|
148
160
|
/**
|
|
149
|
-
* An authenticated WebSocket
|
|
161
|
+
* An authenticated WebSocket transport.
|
|
150
162
|
*
|
|
151
163
|
* This wrapper proves that the connection has completed the Subduction handshake
|
|
152
164
|
* and the peer identity has been cryptographically verified.
|
|
@@ -159,9 +171,9 @@ export class AuthenticatedWebSocket {
|
|
|
159
171
|
free(): void;
|
|
160
172
|
[Symbol.dispose](): void;
|
|
161
173
|
/**
|
|
162
|
-
* Convert to a transport-erased [`
|
|
174
|
+
* Convert to a transport-erased [`AuthenticatedTransport`](super::WasmAuthenticatedTransport).
|
|
163
175
|
*/
|
|
164
|
-
|
|
176
|
+
toTransport(): AuthenticatedTransport;
|
|
165
177
|
/**
|
|
166
178
|
* The verified peer identity.
|
|
167
179
|
*/
|
|
@@ -270,32 +282,6 @@ export class CommitWithBlob {
|
|
|
270
282
|
readonly signed: SignedLooseCommit;
|
|
271
283
|
}
|
|
272
284
|
|
|
273
|
-
/**
|
|
274
|
-
* A pair of a connection and an error that occurred during a call.
|
|
275
|
-
*/
|
|
276
|
-
export class ConnErrorPair {
|
|
277
|
-
private constructor();
|
|
278
|
-
free(): void;
|
|
279
|
-
[Symbol.dispose](): void;
|
|
280
|
-
/**
|
|
281
|
-
* The connection that encountered the error.
|
|
282
|
-
*/
|
|
283
|
-
readonly conn: Connection;
|
|
284
|
-
/**
|
|
285
|
-
* The error that occurred during the call.
|
|
286
|
-
*/
|
|
287
|
-
readonly err: Error;
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
/**
|
|
291
|
-
* A Wasm wrapper around the Rust `ConnectionId` type.
|
|
292
|
-
*/
|
|
293
|
-
export class ConnectionId {
|
|
294
|
-
private constructor();
|
|
295
|
-
free(): void;
|
|
296
|
-
[Symbol.dispose](): void;
|
|
297
|
-
}
|
|
298
|
-
|
|
299
285
|
/**
|
|
300
286
|
* A JavaScript wrapper around `Depth`.
|
|
301
287
|
*/
|
|
@@ -642,104 +628,16 @@ export class MemoryStorage {
|
|
|
642
628
|
}
|
|
643
629
|
|
|
644
630
|
/**
|
|
645
|
-
*
|
|
646
|
-
*/
|
|
647
|
-
export class Message {
|
|
648
|
-
private constructor();
|
|
649
|
-
free(): void;
|
|
650
|
-
[Symbol.dispose](): void;
|
|
651
|
-
/**
|
|
652
|
-
* Upcasts; to the JS-import type for [`WasmMessage`].
|
|
653
|
-
*/
|
|
654
|
-
__wasm_refgen_toWasmMessage(): Message;
|
|
655
|
-
/**
|
|
656
|
-
* Create a [`Message::BatchSyncRequest`] message.
|
|
657
|
-
*/
|
|
658
|
-
static batchSyncRequest(request: BatchSyncRequest): Message;
|
|
659
|
-
/**
|
|
660
|
-
* Create a [`Message::BatchSyncResponse`] message.
|
|
661
|
-
*/
|
|
662
|
-
static batchSyncResponse(response: BatchSyncResponse): Message;
|
|
663
|
-
/**
|
|
664
|
-
* Create a [`Message::BlobsRequest`] message.
|
|
665
|
-
*/
|
|
666
|
-
static blobsRequest(id: SedimentreeId, digests: Digest[]): Message;
|
|
667
|
-
/**
|
|
668
|
-
* Create a [`Message::BlobsResponse`] message.
|
|
669
|
-
*/
|
|
670
|
-
static blobsResponse(id: SedimentreeId, blobs: Uint8Array[]): Message;
|
|
671
|
-
/**
|
|
672
|
-
* Deserialize a message from bytes.
|
|
673
|
-
*
|
|
674
|
-
* # Errors
|
|
675
|
-
*
|
|
676
|
-
* Returns a [`JsMessageDeserializationError`] if deserialization fails.
|
|
677
|
-
*/
|
|
678
|
-
static fromBytes(bytes: Uint8Array): Message;
|
|
679
|
-
/**
|
|
680
|
-
* Serialize the message to bytes.
|
|
681
|
-
*/
|
|
682
|
-
toBytes(): Uint8Array;
|
|
683
|
-
/**
|
|
684
|
-
* The [`Blob`] for commit or fragment messages, if applicable.
|
|
685
|
-
*/
|
|
686
|
-
readonly blob: Uint8Array | undefined;
|
|
687
|
-
/**
|
|
688
|
-
* The [`Blob`]s for a [`Message::BlobsResponse`], if applicable.
|
|
689
|
-
*/
|
|
690
|
-
readonly blobs: Uint8Array[] | undefined;
|
|
691
|
-
/**
|
|
692
|
-
* The [`LooseCommit`] for a [`Message::LooseCommit`], if applicable.
|
|
693
|
-
*
|
|
694
|
-
* Decodes the signed payload to extract the underlying commit.
|
|
695
|
-
*/
|
|
696
|
-
readonly commit: LooseCommit | undefined;
|
|
697
|
-
/**
|
|
698
|
-
* The requested [`Digest`]s for a [`Message::BlobsRequest`], if applicable.
|
|
699
|
-
*/
|
|
700
|
-
readonly digests: Digest[] | undefined;
|
|
701
|
-
/**
|
|
702
|
-
* The [`Fragment`] for a [`Message::Fragment`], if applicable.
|
|
703
|
-
*
|
|
704
|
-
* Decodes the signed payload to extract the underlying fragment.
|
|
705
|
-
*/
|
|
706
|
-
readonly fragment: Fragment | undefined;
|
|
707
|
-
/**
|
|
708
|
-
* The [`BatchSyncRequest`] for a [`Message::BatchSyncRequest`], if applicable.
|
|
709
|
-
*/
|
|
710
|
-
readonly request: BatchSyncRequest | undefined;
|
|
711
|
-
/**
|
|
712
|
-
* The [`BatchSyncResponse`] for a [`Message::BatchSyncResponse`], if applicable.
|
|
713
|
-
*/
|
|
714
|
-
readonly response: BatchSyncResponse | undefined;
|
|
715
|
-
/**
|
|
716
|
-
* The [`SedimentreeId`] associated with this message, if any.
|
|
717
|
-
*/
|
|
718
|
-
readonly sedimentreeId: SedimentreeId | undefined;
|
|
719
|
-
/**
|
|
720
|
-
* The message variant name.
|
|
721
|
-
*/
|
|
722
|
-
readonly type: string;
|
|
723
|
-
}
|
|
724
|
-
|
|
725
|
-
/**
|
|
726
|
-
* A [`HandshakeConnection`] backed by a `MessagePort` (or any object with
|
|
631
|
+
* A `Transport` backed by a `MessagePort` (or any object with
|
|
727
632
|
* `postMessage` / `onmessage` / `close`).
|
|
728
633
|
*
|
|
729
|
-
* Implements the
|
|
730
|
-
* `recvBytes`, `
|
|
731
|
-
*
|
|
732
|
-
* `nextRequestId` and `call` return rejected promises — `MessagePort`
|
|
733
|
-
* connections are used for peer-to-peer handshakes, not RPC-style sync.
|
|
634
|
+
* Implements the byte-oriented `Transport` interface (`sendBytes`,
|
|
635
|
+
* `recvBytes`, `disconnect`) using the port as the underlying channel.
|
|
734
636
|
* After the handshake, the [`Authenticated`] wrapper provides the sync API.
|
|
735
637
|
*/
|
|
736
|
-
export class
|
|
638
|
+
export class MessagePortTransport {
|
|
737
639
|
free(): void;
|
|
738
640
|
[Symbol.dispose](): void;
|
|
739
|
-
/**
|
|
740
|
-
* Not supported on `MessagePort` connections.
|
|
741
|
-
*/
|
|
742
|
-
call(_request: any, _timeout_ms?: number | null): Promise<any>;
|
|
743
641
|
/**
|
|
744
642
|
* Disconnect (close the port).
|
|
745
643
|
*/
|
|
@@ -748,22 +646,10 @@ export class MessagePortConnection {
|
|
|
748
646
|
* Create a new connection wrapping the given `MessagePort`.
|
|
749
647
|
*/
|
|
750
648
|
constructor(port: any);
|
|
751
|
-
/**
|
|
752
|
-
* Not supported on `MessagePort` connections.
|
|
753
|
-
*/
|
|
754
|
-
nextRequestId(): Promise<any>;
|
|
755
|
-
/**
|
|
756
|
-
* Receive the next message.
|
|
757
|
-
*/
|
|
758
|
-
recv(): Promise<any>;
|
|
759
649
|
/**
|
|
760
650
|
* Receive raw bytes (for the handshake phase).
|
|
761
651
|
*/
|
|
762
652
|
recvBytes(): Promise<any>;
|
|
763
|
-
/**
|
|
764
|
-
* Send a structured message (post-handshake).
|
|
765
|
-
*/
|
|
766
|
-
send(message: any): Promise<any>;
|
|
767
653
|
/**
|
|
768
654
|
* Send raw bytes (for the handshake phase).
|
|
769
655
|
*/
|
|
@@ -805,10 +691,6 @@ export class PeerBatchSyncResult {
|
|
|
805
691
|
private constructor();
|
|
806
692
|
free(): void;
|
|
807
693
|
[Symbol.dispose](): void;
|
|
808
|
-
/**
|
|
809
|
-
* List of connection errors that occurred during the batch sync.
|
|
810
|
-
*/
|
|
811
|
-
readonly connErrors: ConnErrorPair[];
|
|
812
694
|
/**
|
|
813
695
|
* Statistics about the sync operation.
|
|
814
696
|
*/
|
|
@@ -817,6 +699,10 @@ export class PeerBatchSyncResult {
|
|
|
817
699
|
* Whether the batch sync was successful with at least one connection.
|
|
818
700
|
*/
|
|
819
701
|
readonly success: boolean;
|
|
702
|
+
/**
|
|
703
|
+
* Errors that occurred during the batch sync.
|
|
704
|
+
*/
|
|
705
|
+
readonly transportErrors: Error[];
|
|
820
706
|
}
|
|
821
707
|
|
|
822
708
|
/**
|
|
@@ -1011,6 +897,22 @@ export class SignedLooseCommit {
|
|
|
1011
897
|
export class Subduction {
|
|
1012
898
|
free(): void;
|
|
1013
899
|
[Symbol.dispose](): void;
|
|
900
|
+
/**
|
|
901
|
+
* Accept a connection from a peer over any [`Transport`](JsTransport).
|
|
902
|
+
*
|
|
903
|
+
* Performs the responder side of the handshake, then adds the authenticated
|
|
904
|
+
* connection. This is the counterpart to [`connectTransport`](Self::connect_transport).
|
|
905
|
+
*
|
|
906
|
+
* # Arguments
|
|
907
|
+
*
|
|
908
|
+
* * `transport` - Any JS object with `sendBytes`/`recvBytes`/`disconnect`
|
|
909
|
+
* * `service_name` - Shared service name for discovery
|
|
910
|
+
*
|
|
911
|
+
* # Errors
|
|
912
|
+
*
|
|
913
|
+
* Returns an error if the handshake or connection fails.
|
|
914
|
+
*/
|
|
915
|
+
acceptTransport(transport: Transport, service_name: string): Promise<PeerId>;
|
|
1014
916
|
/**
|
|
1015
917
|
* Add a commit with its associated blob to the storage.
|
|
1016
918
|
*
|
|
@@ -1023,15 +925,15 @@ export class Subduction {
|
|
|
1023
925
|
*/
|
|
1024
926
|
addCommit(id: SedimentreeId, parents: Digest[], blob: Uint8Array): Promise<FragmentRequested | undefined>;
|
|
1025
927
|
/**
|
|
1026
|
-
* Onboard an authenticated
|
|
928
|
+
* Onboard an authenticated transport: add it and sync all sedimentrees.
|
|
1027
929
|
*
|
|
1028
|
-
* Accepts an [`
|
|
1029
|
-
* obtained via [`
|
|
1030
|
-
* [`AuthenticatedWebSocket.
|
|
930
|
+
* Accepts an [`AuthenticatedTransport`](WasmAuthenticatedTransport),
|
|
931
|
+
* obtained via [`AuthenticatedTransport.setup`](WasmAuthenticatedTransport::setup),
|
|
932
|
+
* [`AuthenticatedWebSocket.toTransport`], or [`AuthenticatedLongPoll.toTransport`].
|
|
1031
933
|
*
|
|
1032
934
|
* Returns `true` if this is a new peer, `false` if already connected.
|
|
1033
935
|
*
|
|
1034
|
-
* Add an authenticated
|
|
936
|
+
* Add an authenticated transport to tracking.
|
|
1035
937
|
*
|
|
1036
938
|
* This does not perform any synchronization. To sync after adding,
|
|
1037
939
|
* call [`fullSyncWithPeer`](Self::full_sync_with_peer).
|
|
@@ -1042,7 +944,7 @@ export class Subduction {
|
|
|
1042
944
|
*
|
|
1043
945
|
* Returns an error if the connection is rejected by the policy.
|
|
1044
946
|
*/
|
|
1045
|
-
addConnection(
|
|
947
|
+
addConnection(transport: AuthenticatedTransport): Promise<boolean>;
|
|
1046
948
|
/**
|
|
1047
949
|
* Add a fragment with its associated blob to the storage.
|
|
1048
950
|
*
|
|
@@ -1074,13 +976,12 @@ export class Subduction {
|
|
|
1074
976
|
*
|
|
1075
977
|
* * `address` - The WebSocket URL to connect to
|
|
1076
978
|
* * `expected_peer_id` - The expected server peer ID (verified during handshake)
|
|
1077
|
-
* * `timeout_milliseconds` - Request timeout in milliseconds
|
|
1078
979
|
*
|
|
1079
980
|
* # Errors
|
|
1080
981
|
*
|
|
1081
982
|
* Returns an error if connection, handshake, or adding the connection fails.
|
|
1082
983
|
*/
|
|
1083
|
-
connect(address: URL, expected_peer_id: PeerId
|
|
984
|
+
connect(address: URL, expected_peer_id: PeerId): Promise<PeerId>;
|
|
1084
985
|
/**
|
|
1085
986
|
* Connect to a peer via WebSocket using discovery mode and add the connection.
|
|
1086
987
|
*
|
|
@@ -1096,7 +997,7 @@ export class Subduction {
|
|
|
1096
997
|
*
|
|
1097
998
|
* Returns an error if connection, handshake, or adding the connection fails.
|
|
1098
999
|
*/
|
|
1099
|
-
connectDiscover(address: URL,
|
|
1000
|
+
connectDiscover(address: URL, service_name?: string | null): Promise<PeerId>;
|
|
1100
1001
|
/**
|
|
1101
1002
|
* Connect to a peer via HTTP long-poll using discovery mode.
|
|
1102
1003
|
*
|
|
@@ -1112,7 +1013,7 @@ export class Subduction {
|
|
|
1112
1013
|
*
|
|
1113
1014
|
* Returns an error if connection, handshake, or adding the connection fails.
|
|
1114
1015
|
*/
|
|
1115
|
-
connectDiscoverLongPoll(base_url: string,
|
|
1016
|
+
connectDiscoverLongPoll(base_url: string, service_name?: string | null): Promise<PeerId>;
|
|
1116
1017
|
/**
|
|
1117
1018
|
* Connect to a peer via HTTP long-poll and add the connection.
|
|
1118
1019
|
*
|
|
@@ -1128,7 +1029,23 @@ export class Subduction {
|
|
|
1128
1029
|
*
|
|
1129
1030
|
* Returns an error if connection, handshake, or adding the connection fails.
|
|
1130
1031
|
*/
|
|
1131
|
-
connectLongPoll(base_url: string, expected_peer_id: PeerId
|
|
1032
|
+
connectLongPoll(base_url: string, expected_peer_id: PeerId): Promise<PeerId>;
|
|
1033
|
+
/**
|
|
1034
|
+
* Connect to a peer over any [`Transport`](JsTransport) using discovery mode.
|
|
1035
|
+
*
|
|
1036
|
+
* Performs a discovery handshake, then adds the authenticated connection.
|
|
1037
|
+
* The peer's identity is discovered during the handshake.
|
|
1038
|
+
*
|
|
1039
|
+
* # Arguments
|
|
1040
|
+
*
|
|
1041
|
+
* * `transport` - Any JS object with `sendBytes`/`recvBytes`/`disconnect`
|
|
1042
|
+
* * `service_name` - Shared service name for discovery
|
|
1043
|
+
*
|
|
1044
|
+
* # Errors
|
|
1045
|
+
*
|
|
1046
|
+
* Returns an error if the handshake or connection fails.
|
|
1047
|
+
*/
|
|
1048
|
+
connectTransport(transport: Transport, service_name: string): Promise<PeerId>;
|
|
1132
1049
|
/**
|
|
1133
1050
|
* Disconnect from all peers.
|
|
1134
1051
|
*
|
|
@@ -1220,6 +1137,19 @@ export class Subduction {
|
|
|
1220
1137
|
* Returns [`WasmHydrationError`] if hydration fails.
|
|
1221
1138
|
*/
|
|
1222
1139
|
static hydrate(signer: any, storage: SedimentreeStorage, service_name?: string | null, hash_metric_override?: (digest: Digest) => Depth | null, max_pending_blob_requests?: number | null): Promise<Subduction>;
|
|
1140
|
+
/**
|
|
1141
|
+
* Link two local [`Subduction`](WasmSubduction) instances over a
|
|
1142
|
+
* [`MessageChannel`](web_sys::MessageChannel).
|
|
1143
|
+
*
|
|
1144
|
+
* Creates a `MessageChannel`, performs a discovery handshake between
|
|
1145
|
+
* the two instances, and adds the connections to both. This is the
|
|
1146
|
+
* simplest way to sync two local instances.
|
|
1147
|
+
*
|
|
1148
|
+
* # Errors
|
|
1149
|
+
*
|
|
1150
|
+
* Returns an error if the handshake or connection fails.
|
|
1151
|
+
*/
|
|
1152
|
+
static link(a: Subduction, b: Subduction): Promise<void>;
|
|
1223
1153
|
/**
|
|
1224
1154
|
* Create a new [`Subduction`] instance.
|
|
1225
1155
|
*
|
|
@@ -1290,136 +1220,113 @@ export class Subduction {
|
|
|
1290
1220
|
}
|
|
1291
1221
|
|
|
1292
1222
|
/**
|
|
1293
|
-
*
|
|
1294
|
-
*
|
|
1295
|
-
*
|
|
1223
|
+
* JS-facing wrapper around [`HttpLongPollTransport`] that exposes the
|
|
1224
|
+
* byte-oriented [`Transport`](super::JsTransport) interface
|
|
1225
|
+
* (`sendBytes`/`recvBytes`/`disconnect`) so it can be used as a
|
|
1226
|
+
* duck-typed `JsTransport` from JavaScript.
|
|
1296
1227
|
*/
|
|
1297
|
-
export class
|
|
1228
|
+
export class SubductionHttpLongPoll {
|
|
1298
1229
|
private constructor();
|
|
1299
1230
|
free(): void;
|
|
1300
1231
|
[Symbol.dispose](): void;
|
|
1301
1232
|
/**
|
|
1302
|
-
*
|
|
1303
|
-
*
|
|
1304
|
-
* # Arguments
|
|
1305
|
-
*
|
|
1306
|
-
* * `base_url` - The server's HTTP base URL (e.g., `http://localhost:8080`)
|
|
1307
|
-
* * `signer` - The client's signer for authentication
|
|
1308
|
-
* * `expected_peer_id` - The expected server peer ID (verified during handshake)
|
|
1309
|
-
* * `timeout_milliseconds` - Request timeout in milliseconds (default: 30000)
|
|
1233
|
+
* Disconnect from the peer gracefully.
|
|
1310
1234
|
*
|
|
1311
1235
|
* # Errors
|
|
1312
1236
|
*
|
|
1313
|
-
* Returns
|
|
1237
|
+
* Returns an error if the disconnect fails.
|
|
1314
1238
|
*/
|
|
1315
|
-
|
|
1239
|
+
disconnect(): Promise<void>;
|
|
1316
1240
|
/**
|
|
1317
|
-
*
|
|
1241
|
+
* Receive the next message frame as raw bytes.
|
|
1318
1242
|
*
|
|
1319
|
-
* #
|
|
1243
|
+
* # Errors
|
|
1320
1244
|
*
|
|
1321
|
-
*
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1245
|
+
* Returns an error if the inbound channel is closed.
|
|
1246
|
+
*/
|
|
1247
|
+
recvBytes(): Promise<Uint8Array>;
|
|
1248
|
+
/**
|
|
1249
|
+
* Send raw bytes over the transport.
|
|
1325
1250
|
*
|
|
1326
1251
|
* # Errors
|
|
1327
1252
|
*
|
|
1328
|
-
* Returns
|
|
1253
|
+
* Returns an error if the outbound channel is closed.
|
|
1329
1254
|
*/
|
|
1330
|
-
|
|
1255
|
+
sendBytes(bytes: Uint8Array): Promise<void>;
|
|
1331
1256
|
}
|
|
1332
1257
|
|
|
1333
1258
|
/**
|
|
1334
|
-
*
|
|
1335
|
-
*
|
|
1336
|
-
*
|
|
1259
|
+
* HTTP long-poll transport factory for browser/worker environments.
|
|
1260
|
+
*
|
|
1261
|
+
* Analogous to [`SubductionWebSocket`] but uses HTTP long-poll instead of WebSocket.
|
|
1337
1262
|
*/
|
|
1338
|
-
export class
|
|
1263
|
+
export class SubductionLongPoll {
|
|
1339
1264
|
private constructor();
|
|
1340
1265
|
free(): void;
|
|
1341
1266
|
[Symbol.dispose](): void;
|
|
1342
1267
|
/**
|
|
1343
|
-
*
|
|
1268
|
+
* Connect to a server with a known peer ID.
|
|
1344
1269
|
*
|
|
1345
|
-
* #
|
|
1270
|
+
* # Arguments
|
|
1346
1271
|
*
|
|
1347
|
-
*
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
* Disconnect from the peer gracefully.
|
|
1272
|
+
* * `base_url` - The server's HTTP base URL (e.g., `http://localhost:8080`)
|
|
1273
|
+
* * `signer` - The client's signer for authentication
|
|
1274
|
+
* * `expected_peer_id` - The expected server peer ID (verified during handshake)
|
|
1275
|
+
* * `timeout_milliseconds` - Request timeout in milliseconds (default: 30000)
|
|
1352
1276
|
*
|
|
1353
1277
|
* # Errors
|
|
1354
1278
|
*
|
|
1355
|
-
* Returns [`
|
|
1356
|
-
*/
|
|
1357
|
-
disconnect(): Promise<void>;
|
|
1358
|
-
/**
|
|
1359
|
-
* Get the next request ID.
|
|
1279
|
+
* Returns [`LongPollTransportError`] if connection or handshake fails.
|
|
1360
1280
|
*/
|
|
1361
|
-
|
|
1281
|
+
static tryConnect(base_url: string, signer: any, expected_peer_id: PeerId): Promise<AuthenticatedLongPoll>;
|
|
1362
1282
|
/**
|
|
1363
|
-
*
|
|
1283
|
+
* Connect to a server using discovery mode.
|
|
1364
1284
|
*
|
|
1365
|
-
* #
|
|
1285
|
+
* # Arguments
|
|
1366
1286
|
*
|
|
1367
|
-
*
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
/**
|
|
1371
|
-
* Send a message.
|
|
1287
|
+
* * `base_url` - The server's HTTP base URL (e.g., `http://localhost:8080`)
|
|
1288
|
+
* * `signer` - The client's signer for authentication
|
|
1289
|
+
* * `service_name` - The service name for discovery. If omitted, the base URL is used.
|
|
1372
1290
|
*
|
|
1373
1291
|
* # Errors
|
|
1374
1292
|
*
|
|
1375
|
-
* Returns
|
|
1293
|
+
* Returns [`LongPollTransportError`] if connection or handshake fails.
|
|
1376
1294
|
*/
|
|
1377
|
-
|
|
1295
|
+
static tryDiscover(base_url: string, signer: any, service_name?: string | null): Promise<AuthenticatedLongPoll>;
|
|
1378
1296
|
}
|
|
1379
1297
|
|
|
1380
1298
|
/**
|
|
1381
|
-
* A WebSocket
|
|
1299
|
+
* A WebSocket transport exposing the byte-oriented `Transport` interface.
|
|
1300
|
+
*
|
|
1301
|
+
* Raw bytes from the WebSocket's `onmessage` handler are buffered in an
|
|
1302
|
+
* `async_channel` and returned via `recvBytes`. No message decoding or
|
|
1303
|
+
* request-response routing happens here — that's handled by
|
|
1304
|
+
* [`MessageTransport`](subduction_core::transport::message::MessageTransport).
|
|
1382
1305
|
*/
|
|
1383
1306
|
export class SubductionWebSocket {
|
|
1384
1307
|
private constructor();
|
|
1385
1308
|
free(): void;
|
|
1386
1309
|
[Symbol.dispose](): void;
|
|
1387
|
-
/**
|
|
1388
|
-
* Make a synchronous call to the peer.
|
|
1389
|
-
*
|
|
1390
|
-
* # Errors
|
|
1391
|
-
*
|
|
1392
|
-
* Returns [`WasmCallError`] if the call fails or times out.
|
|
1393
|
-
*/
|
|
1394
|
-
call(request: BatchSyncRequest, timeout_ms?: number | null): Promise<BatchSyncResponse>;
|
|
1395
1310
|
/**
|
|
1396
1311
|
* Disconnect from the peer gracefully.
|
|
1397
1312
|
*/
|
|
1398
1313
|
disconnect(): Promise<void>;
|
|
1399
1314
|
/**
|
|
1400
|
-
*
|
|
1401
|
-
*/
|
|
1402
|
-
nextRequestId(): Promise<RequestId>;
|
|
1403
|
-
/**
|
|
1404
|
-
* Get the peer ID of the remote peer.
|
|
1405
|
-
*/
|
|
1406
|
-
peerId(): PeerId;
|
|
1407
|
-
/**
|
|
1408
|
-
* Receive a message.
|
|
1315
|
+
* Receive the next message frame as raw bytes.
|
|
1409
1316
|
*
|
|
1410
1317
|
* # Errors
|
|
1411
1318
|
*
|
|
1412
1319
|
* Returns [`ReadFromClosedChannel`] if the channel has been closed.
|
|
1413
1320
|
*/
|
|
1414
|
-
|
|
1321
|
+
recvBytes(): Promise<Uint8Array>;
|
|
1415
1322
|
/**
|
|
1416
|
-
* Send
|
|
1323
|
+
* Send raw bytes over the WebSocket.
|
|
1417
1324
|
*
|
|
1418
1325
|
* # Errors
|
|
1419
1326
|
*
|
|
1420
|
-
* Returns [`WasmSendError`] if the
|
|
1327
|
+
* Returns [`WasmSendError`] if the bytes could not be sent.
|
|
1421
1328
|
*/
|
|
1422
|
-
|
|
1329
|
+
sendBytes(bytes: Uint8Array): Promise<void>;
|
|
1423
1330
|
/**
|
|
1424
1331
|
* Authenticate an existing WebSocket via handshake.
|
|
1425
1332
|
*
|
|
@@ -1437,7 +1344,7 @@ export class SubductionWebSocket {
|
|
|
1437
1344
|
*
|
|
1438
1345
|
* Returns an error if the handshake fails (signature invalid, wrong peer, etc.)
|
|
1439
1346
|
*/
|
|
1440
|
-
static setup(ws: WebSocket, signer: any, expected_peer_id: PeerId
|
|
1347
|
+
static setup(ws: WebSocket, signer: any, expected_peer_id: PeerId): Promise<AuthenticatedWebSocket>;
|
|
1441
1348
|
/**
|
|
1442
1349
|
* Connect to a WebSocket server with mutual authentication via handshake.
|
|
1443
1350
|
*
|
|
@@ -1446,15 +1353,13 @@ export class SubductionWebSocket {
|
|
|
1446
1353
|
* * `address` - The WebSocket URL to connect to
|
|
1447
1354
|
* * `signer` - The client's signer for authentication
|
|
1448
1355
|
* * `expected_peer_id` - The expected server peer ID (verified during handshake)
|
|
1449
|
-
* * `timeout_milliseconds` - Request timeout in milliseconds
|
|
1450
|
-
*
|
|
1451
1356
|
* # Errors
|
|
1452
1357
|
*
|
|
1453
1358
|
* Returns an error if:
|
|
1454
1359
|
* - The WebSocket connection could not be established
|
|
1455
1360
|
* - The handshake fails (signature invalid, wrong server, clock drift, etc.)
|
|
1456
1361
|
*/
|
|
1457
|
-
static tryConnect(address: URL, signer: any, expected_peer_id: PeerId
|
|
1362
|
+
static tryConnect(address: URL, signer: any, expected_peer_id: PeerId): Promise<AuthenticatedWebSocket>;
|
|
1458
1363
|
/**
|
|
1459
1364
|
* Connect to a WebSocket server using discovery mode.
|
|
1460
1365
|
*
|
|
@@ -1476,7 +1381,88 @@ export class SubductionWebSocket {
|
|
|
1476
1381
|
* - The WebSocket connection could not be established
|
|
1477
1382
|
* - The handshake fails (signature invalid, clock drift, etc.)
|
|
1478
1383
|
*/
|
|
1479
|
-
static tryDiscover(address: URL, signer: any,
|
|
1384
|
+
static tryDiscover(address: URL, signer: any, service_name?: string | null): Promise<AuthenticatedWebSocket>;
|
|
1385
|
+
}
|
|
1386
|
+
|
|
1387
|
+
/**
|
|
1388
|
+
* Wasm wrapper for [`SyncMessage`].
|
|
1389
|
+
*/
|
|
1390
|
+
export class SyncMessage {
|
|
1391
|
+
private constructor();
|
|
1392
|
+
free(): void;
|
|
1393
|
+
[Symbol.dispose](): void;
|
|
1394
|
+
/**
|
|
1395
|
+
* Upcasts; to the JS-import type for [`WasmMessage`].
|
|
1396
|
+
*/
|
|
1397
|
+
__wasm_refgen_toWasmMessage(): SyncMessage;
|
|
1398
|
+
/**
|
|
1399
|
+
* Create a [`SyncMessage::BatchSyncRequest`] message.
|
|
1400
|
+
*/
|
|
1401
|
+
static batchSyncRequest(request: BatchSyncRequest): SyncMessage;
|
|
1402
|
+
/**
|
|
1403
|
+
* Create a [`SyncMessage::BatchSyncResponse`] message.
|
|
1404
|
+
*/
|
|
1405
|
+
static batchSyncResponse(response: BatchSyncResponse): SyncMessage;
|
|
1406
|
+
/**
|
|
1407
|
+
* Create a [`SyncMessage::BlobsRequest`] message.
|
|
1408
|
+
*/
|
|
1409
|
+
static blobsRequest(id: SedimentreeId, digests: Digest[]): SyncMessage;
|
|
1410
|
+
/**
|
|
1411
|
+
* Create a [`SyncMessage::BlobsResponse`] message.
|
|
1412
|
+
*/
|
|
1413
|
+
static blobsResponse(id: SedimentreeId, blobs: Uint8Array[]): SyncMessage;
|
|
1414
|
+
/**
|
|
1415
|
+
* Deserialize a message from bytes.
|
|
1416
|
+
*
|
|
1417
|
+
* # Errors
|
|
1418
|
+
*
|
|
1419
|
+
* Returns a [`JsMessageDeserializationError`] if deserialization fails.
|
|
1420
|
+
*/
|
|
1421
|
+
static fromBytes(bytes: Uint8Array): SyncMessage;
|
|
1422
|
+
/**
|
|
1423
|
+
* Serialize the message to bytes.
|
|
1424
|
+
*/
|
|
1425
|
+
toBytes(): Uint8Array;
|
|
1426
|
+
/**
|
|
1427
|
+
* The [`Blob`] for commit or fragment messages, if applicable.
|
|
1428
|
+
*/
|
|
1429
|
+
readonly blob: Uint8Array | undefined;
|
|
1430
|
+
/**
|
|
1431
|
+
* The [`Blob`]s for a [`SyncMessage::BlobsResponse`], if applicable.
|
|
1432
|
+
*/
|
|
1433
|
+
readonly blobs: Uint8Array[] | undefined;
|
|
1434
|
+
/**
|
|
1435
|
+
* The [`LooseCommit`] for a [`SyncMessage::LooseCommit`], if applicable.
|
|
1436
|
+
*
|
|
1437
|
+
* Decodes the signed payload to extract the underlying commit.
|
|
1438
|
+
*/
|
|
1439
|
+
readonly commit: LooseCommit | undefined;
|
|
1440
|
+
/**
|
|
1441
|
+
* The requested [`Digest`]s for a [`SyncMessage::BlobsRequest`], if applicable.
|
|
1442
|
+
*/
|
|
1443
|
+
readonly digests: Digest[] | undefined;
|
|
1444
|
+
/**
|
|
1445
|
+
* The [`Fragment`] for a [`SyncMessage::Fragment`], if applicable.
|
|
1446
|
+
*
|
|
1447
|
+
* Decodes the signed payload to extract the underlying fragment.
|
|
1448
|
+
*/
|
|
1449
|
+
readonly fragment: Fragment | undefined;
|
|
1450
|
+
/**
|
|
1451
|
+
* The [`BatchSyncRequest`] for a [`SyncMessage::BatchSyncRequest`], if applicable.
|
|
1452
|
+
*/
|
|
1453
|
+
readonly request: BatchSyncRequest | undefined;
|
|
1454
|
+
/**
|
|
1455
|
+
* The [`BatchSyncResponse`] for a [`SyncMessage::BatchSyncResponse`], if applicable.
|
|
1456
|
+
*/
|
|
1457
|
+
readonly response: BatchSyncResponse | undefined;
|
|
1458
|
+
/**
|
|
1459
|
+
* The [`SedimentreeId`] associated with this message, if any.
|
|
1460
|
+
*/
|
|
1461
|
+
readonly sedimentreeId: SedimentreeId | undefined;
|
|
1462
|
+
/**
|
|
1463
|
+
* The message variant name.
|
|
1464
|
+
*/
|
|
1465
|
+
readonly type: string;
|
|
1480
1466
|
}
|
|
1481
1467
|
|
|
1482
1468
|
/**
|
|
@@ -1570,9 +1556,9 @@ export class WebCryptoSigner {
|
|
|
1570
1556
|
}
|
|
1571
1557
|
|
|
1572
1558
|
/**
|
|
1573
|
-
* Convenience factory — equivalent to `new
|
|
1559
|
+
* Convenience factory — equivalent to `new MessagePortTransport(port)`.
|
|
1574
1560
|
*/
|
|
1575
|
-
export function
|
|
1561
|
+
export function makeMessagePortTransport(port: any): MessagePortTransport;
|
|
1576
1562
|
|
|
1577
1563
|
/**
|
|
1578
1564
|
* Entry point called when the Wasm module is instantiated.
|