@automerge/subduction 0.10.0 → 0.10.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/node.cjs +5 -0
- package/dist/cjs/slim.cjs +1 -0
- package/dist/cjs/wasm-base64.cjs +1 -0
- package/dist/cjs/web-bindings.cjs +4768 -0
- package/dist/cjs/web.cjs +4719 -0
- package/dist/esm/bundler.js +7 -0
- package/dist/esm/node.js +7 -0
- package/dist/esm/slim.js +2 -0
- package/dist/esm/wasm-base64.js +1 -0
- package/dist/esm/web.js +5 -0
- package/dist/esm/workerd.js +5 -0
- package/dist/iife/index.js +4677 -0
- package/dist/index.d.ts +1706 -0
- package/dist/subduction.wasm +0 -0
- package/dist/wasm_bindgen/bundler/snippets/sedimentree_wasm-75027ecce41278de/inline0.js +2 -0
- package/dist/wasm_bindgen/bundler/snippets/sedimentree_wasm-75027ecce41278de/inline1.js +2 -0
- package/dist/wasm_bindgen/bundler/snippets/sedimentree_wasm-75027ecce41278de/inline2.js +2 -0
- package/dist/wasm_bindgen/bundler/snippets/subduction_wasm-ec51bcf335db35bd/inline0.js +8 -0
- package/dist/wasm_bindgen/bundler/snippets/subduction_wasm-ec51bcf335db35bd/inline1.js +9 -0
- package/dist/wasm_bindgen/bundler/subduction_wasm.d.ts +1706 -0
- package/dist/wasm_bindgen/bundler/subduction_wasm.js +9 -0
- package/dist/wasm_bindgen/bundler/subduction_wasm_bg.js +4774 -0
- package/dist/wasm_bindgen/bundler/subduction_wasm_bg.wasm +0 -0
- package/dist/wasm_bindgen/bundler/subduction_wasm_bg.wasm.d.ts +246 -0
- package/dist/wasm_bindgen/nodejs/snippets/sedimentree_wasm-75027ecce41278de/inline0.js +2 -0
- package/dist/wasm_bindgen/nodejs/snippets/sedimentree_wasm-75027ecce41278de/inline1.js +2 -0
- package/dist/wasm_bindgen/nodejs/snippets/sedimentree_wasm-75027ecce41278de/inline2.js +2 -0
- package/dist/wasm_bindgen/nodejs/snippets/subduction_wasm-ec51bcf335db35bd/inline0.js +8 -0
- package/dist/wasm_bindgen/nodejs/snippets/subduction_wasm-ec51bcf335db35bd/inline1.js +9 -0
- package/dist/wasm_bindgen/nodejs/subduction_wasm.cjs +4821 -0
- package/dist/wasm_bindgen/nodejs/subduction_wasm.d.ts +1706 -0
- package/dist/wasm_bindgen/nodejs/subduction_wasm_bg.wasm +0 -0
- package/dist/wasm_bindgen/nodejs/subduction_wasm_bg.wasm.d.ts +246 -0
- package/dist/wasm_bindgen/web/snippets/sedimentree_wasm-75027ecce41278de/inline0.js +2 -0
- package/dist/wasm_bindgen/web/snippets/sedimentree_wasm-75027ecce41278de/inline1.js +2 -0
- package/dist/wasm_bindgen/web/snippets/sedimentree_wasm-75027ecce41278de/inline2.js +2 -0
- package/dist/wasm_bindgen/web/snippets/subduction_wasm-ec51bcf335db35bd/inline0.js +8 -0
- package/dist/wasm_bindgen/web/snippets/subduction_wasm-ec51bcf335db35bd/inline1.js +9 -0
- package/dist/wasm_bindgen/web/subduction_wasm.d.ts +1977 -0
- package/dist/wasm_bindgen/web/subduction_wasm.js +4879 -0
- package/dist/wasm_bindgen/web/subduction_wasm_bg.wasm +0 -0
- package/dist/wasm_bindgen/web/subduction_wasm_bg.wasm.d.ts +246 -0
- package/package.json +1 -1
|
@@ -0,0 +1,1706 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Connection and storage authorization policy.
|
|
6
|
+
*
|
|
7
|
+
* Throwing (or returning a rejected promise) denies the operation.
|
|
8
|
+
* Resolving allows it.
|
|
9
|
+
*/
|
|
10
|
+
export interface Policy {
|
|
11
|
+
authorizeConnect(peerId: PeerId): Promise<void>;
|
|
12
|
+
authorizeFetch(peerId: PeerId, sedimentreeId: SedimentreeId): Promise<void>;
|
|
13
|
+
authorizePut(requestor: PeerId, author: PeerId, sedimentreeId: SedimentreeId): Promise<void>;
|
|
14
|
+
filterAuthorizedFetch(peerId: PeerId, ids: SedimentreeId[]): Promise<SedimentreeId[]>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Ephemeral message authorization policy.
|
|
21
|
+
*
|
|
22
|
+
* Throwing (or returning a rejected promise) denies the operation.
|
|
23
|
+
* Resolving allows it.
|
|
24
|
+
*/
|
|
25
|
+
export interface EphemeralPolicy {
|
|
26
|
+
authorizeSubscribe(peerId: PeerId, topic: Topic): Promise<void>;
|
|
27
|
+
authorizePublish(peerId: PeerId, topic: Topic): Promise<void>;
|
|
28
|
+
filterAuthorizedSubscribers(topic: Topic, peers: PeerId[]): Promise<PeerId[]>;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
export interface SedimentreeStorage {
|
|
34
|
+
saveSedimentreeId(sedimentreeId: SedimentreeId): Promise<void>;
|
|
35
|
+
deleteSedimentreeId(sedimentreeId: SedimentreeId): Promise<void>;
|
|
36
|
+
loadAllSedimentreeIds(): Promise<SedimentreeId[]>;
|
|
37
|
+
|
|
38
|
+
// Compound storage for commits (signed data + blob stored together)
|
|
39
|
+
saveCommit(sedimentreeId: SedimentreeId, digest: Digest, signedCommit: SignedLooseCommit, blob: Uint8Array): Promise<void>;
|
|
40
|
+
loadCommit(sedimentreeId: SedimentreeId, digest: Digest): Promise<CommitWithBlob | null>;
|
|
41
|
+
listCommitDigests(sedimentreeId: SedimentreeId): Promise<Digest[]>;
|
|
42
|
+
loadAllCommits(sedimentreeId: SedimentreeId): Promise<CommitWithBlob[]>;
|
|
43
|
+
deleteCommit(sedimentreeId: SedimentreeId, digest: Digest): Promise<void>;
|
|
44
|
+
deleteAllCommits(sedimentreeId: SedimentreeId): Promise<void>;
|
|
45
|
+
|
|
46
|
+
// Compound storage for fragments (signed data + blob stored together)
|
|
47
|
+
saveFragment(sedimentreeId: SedimentreeId, digest: Digest, signedFragment: SignedFragment, blob: Uint8Array): Promise<void>;
|
|
48
|
+
loadFragment(sedimentreeId: SedimentreeId, digest: Digest): Promise<FragmentWithBlob | null>;
|
|
49
|
+
listFragmentDigests(sedimentreeId: SedimentreeId): Promise<Digest[]>;
|
|
50
|
+
loadAllFragments(sedimentreeId: SedimentreeId): Promise<FragmentWithBlob[]>;
|
|
51
|
+
deleteFragment(sedimentreeId: SedimentreeId, digest: Digest): Promise<void>;
|
|
52
|
+
deleteAllFragments(sedimentreeId: SedimentreeId): Promise<void>;
|
|
53
|
+
|
|
54
|
+
// Batch save: write all commits + fragments in a single storage transaction.
|
|
55
|
+
saveBatchAll(sedimentreeId: SedimentreeId, commits: Array<{digest: Digest, signedCommit: SignedLooseCommit, blob: Uint8Array}>, fragments: Array<{digest: Digest, signedFragment: SignedFragment, blob: Uint8Array}>): Promise<number>;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
export interface Transport {
|
|
61
|
+
sendBytes(bytes: Uint8Array): Promise<void>;
|
|
62
|
+
recvBytes(): Promise<Uint8Array>;
|
|
63
|
+
disconnect(): Promise<void>;
|
|
64
|
+
onDisconnect(callback: () => void): void;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* An authenticated HTTP long-poll transport.
|
|
71
|
+
*
|
|
72
|
+
* This wrapper proves that the transport has completed the Subduction handshake
|
|
73
|
+
* and the peer identity has been cryptographically verified.
|
|
74
|
+
*
|
|
75
|
+
* Obtain via [`SubductionLongPoll::tryConnect`] or [`SubductionLongPoll::tryDiscover`].
|
|
76
|
+
*/
|
|
77
|
+
export class AuthenticatedLongPoll {
|
|
78
|
+
private constructor();
|
|
79
|
+
free(): void;
|
|
80
|
+
[Symbol.dispose](): void;
|
|
81
|
+
/**
|
|
82
|
+
* Convert to a transport-erased [`AuthenticatedTransport`](super::WasmAuthenticatedTransport).
|
|
83
|
+
*/
|
|
84
|
+
toTransport(): AuthenticatedTransport;
|
|
85
|
+
/**
|
|
86
|
+
* The verified peer identity.
|
|
87
|
+
*/
|
|
88
|
+
readonly peerId: PeerId;
|
|
89
|
+
/**
|
|
90
|
+
* The session ID assigned by the server.
|
|
91
|
+
*/
|
|
92
|
+
readonly sessionId: string;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* A transport-erased authenticated transport.
|
|
97
|
+
*
|
|
98
|
+
* Wraps an [`Authenticated<MessageTransport<JsTransport>>`] and is the common type
|
|
99
|
+
* accepted by [`addConnection`](crate::subduction::WasmSubduction::add_connection).
|
|
100
|
+
*
|
|
101
|
+
* # Construction
|
|
102
|
+
*
|
|
103
|
+
* There are three ways to obtain an `AuthenticatedTransport`:
|
|
104
|
+
*
|
|
105
|
+
* 1. **Custom transport** — implement the `Transport` interface
|
|
106
|
+
* (`sendBytes`/`recvBytes`/`disconnect`/`onDisconnect`) and call
|
|
107
|
+
* [`setup`](Self::setup):
|
|
108
|
+
*
|
|
109
|
+
* ```js
|
|
110
|
+
* const auth = await AuthenticatedTransport.setup(myTransport, signer, peerId, (peerId) => {
|
|
111
|
+
* console.log(`${peerId} disconnected`);
|
|
112
|
+
* });
|
|
113
|
+
* ```
|
|
114
|
+
*
|
|
115
|
+
* 2. **From WebSocket** — authenticate via [`SubductionWebSocket`] then convert:
|
|
116
|
+
*
|
|
117
|
+
* ```js
|
|
118
|
+
* const wsAuth = await SubductionWebSocket.tryConnect(url, signer, peerId, (peerId) => {
|
|
119
|
+
* console.log(`${peerId} disconnected`);
|
|
120
|
+
* });
|
|
121
|
+
* const auth = wsAuth.toTransport();
|
|
122
|
+
* ```
|
|
123
|
+
*
|
|
124
|
+
* 3. **From HTTP long-poll** — same pattern via [`SubductionLongPoll`]:
|
|
125
|
+
*
|
|
126
|
+
* ```js
|
|
127
|
+
* const lpAuth = await SubductionLongPoll.tryConnect(url, signer, peerId, (peerId) => {
|
|
128
|
+
* console.log(`${peerId} disconnected`);
|
|
129
|
+
* });
|
|
130
|
+
* const auth = lpAuth.toTransport();
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
export class AuthenticatedTransport {
|
|
134
|
+
private constructor();
|
|
135
|
+
free(): void;
|
|
136
|
+
[Symbol.dispose](): void;
|
|
137
|
+
/**
|
|
138
|
+
* Accept an incoming handshake over a custom transport (responder side).
|
|
139
|
+
*
|
|
140
|
+
* This is the counterpart to [`setup`](Self::setup). The initiator calls
|
|
141
|
+
* `setup`, and the responder calls `accept` over the same underlying channel.
|
|
142
|
+
*
|
|
143
|
+
* # Arguments
|
|
144
|
+
*
|
|
145
|
+
* * `transport` - A `Transport` implementing `sendBytes`/`recvBytes`/`disconnect`/`onDisconnect`
|
|
146
|
+
* * `signer` - The responder's signer for authentication
|
|
147
|
+
* * `max_drift_seconds` - Maximum acceptable clock drift in seconds (default: 600)
|
|
148
|
+
*
|
|
149
|
+
* # Errors
|
|
150
|
+
*
|
|
151
|
+
* Returns a [`HandshakeError`](WasmHandshakeError) if the handshake fails.
|
|
152
|
+
*/
|
|
153
|
+
static accept(transport: Transport, signer: any, max_drift_seconds?: number | null, on_disconnect?: Function | null): Promise<AuthenticatedTransport>;
|
|
154
|
+
/**
|
|
155
|
+
* Run the Subduction handshake over a custom transport, producing an
|
|
156
|
+
* authenticated transport.
|
|
157
|
+
*
|
|
158
|
+
* The `transport` object must implement the `Transport` interface
|
|
159
|
+
* (`sendBytes`/`recvBytes`/`disconnect`/`onDisconnect`).
|
|
160
|
+
* The same object is used for both the handshake phase and post-handshake
|
|
161
|
+
* communication.
|
|
162
|
+
*
|
|
163
|
+
* # Arguments
|
|
164
|
+
*
|
|
165
|
+
* * `transport` - A `Transport` implementing `sendBytes`/`recvBytes`/`disconnect`/`onDisconnect`
|
|
166
|
+
* * `signer` - The client's signer for authentication
|
|
167
|
+
* * `expected_peer_id` - The expected server peer ID (verified during handshake)
|
|
168
|
+
*
|
|
169
|
+
* # Errors
|
|
170
|
+
*
|
|
171
|
+
* Returns a [`HandshakeError`](WasmHandshakeError) if the handshake fails.
|
|
172
|
+
*/
|
|
173
|
+
static setup(transport: Transport, signer: any, expected_peer_id: PeerId, on_disconnect?: Function | null): Promise<AuthenticatedTransport>;
|
|
174
|
+
/**
|
|
175
|
+
* Run the Subduction handshake over a custom transport using discovery
|
|
176
|
+
* mode, producing an authenticated transport.
|
|
177
|
+
*
|
|
178
|
+
* Unlike [`setup`](Self::setup) which requires a known peer ID,
|
|
179
|
+
* this method discovers the peer's identity during the handshake
|
|
180
|
+
* using a shared service name.
|
|
181
|
+
*
|
|
182
|
+
* # Arguments
|
|
183
|
+
*
|
|
184
|
+
* * `transport` - A `Transport` implementing `sendBytes`/`recvBytes`/`disconnect`/`onDisconnect`
|
|
185
|
+
* * `signer` - The client's signer for authentication
|
|
186
|
+
* * `service_name` - Shared service name for discovery.
|
|
187
|
+
* Defaults to [`DEFAULT_LOCAL_SERVICE_NAME`] (`"subduction:local"`) if omitted.
|
|
188
|
+
*
|
|
189
|
+
* # Errors
|
|
190
|
+
*
|
|
191
|
+
* Returns a [`HandshakeError`](WasmHandshakeError) if the handshake fails.
|
|
192
|
+
*/
|
|
193
|
+
static setupDiscover(transport: Transport, signer: any, service_name?: string | null, on_disconnect?: Function | null): Promise<AuthenticatedTransport>;
|
|
194
|
+
/**
|
|
195
|
+
* The verified peer identity.
|
|
196
|
+
*/
|
|
197
|
+
readonly peerId: PeerId;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* An authenticated WebSocket transport.
|
|
202
|
+
*
|
|
203
|
+
* This wrapper proves that the connection has completed the Subduction handshake
|
|
204
|
+
* and the peer identity has been cryptographically verified.
|
|
205
|
+
*
|
|
206
|
+
* Obtain via [`SubductionWebSocket::setup`], [`SubductionWebSocket::tryConnect`],
|
|
207
|
+
* or [`SubductionWebSocket::tryDiscover`].
|
|
208
|
+
*/
|
|
209
|
+
export class AuthenticatedWebSocket {
|
|
210
|
+
private constructor();
|
|
211
|
+
free(): void;
|
|
212
|
+
[Symbol.dispose](): void;
|
|
213
|
+
/**
|
|
214
|
+
* Convert to a transport-erased [`AuthenticatedTransport`](super::WasmAuthenticatedTransport).
|
|
215
|
+
*/
|
|
216
|
+
toTransport(): AuthenticatedTransport;
|
|
217
|
+
/**
|
|
218
|
+
* The verified peer identity.
|
|
219
|
+
*/
|
|
220
|
+
readonly peerId: PeerId;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Wasm wrapper for [`BatchSyncRequest`].
|
|
225
|
+
*/
|
|
226
|
+
export class BatchSyncRequest {
|
|
227
|
+
private constructor();
|
|
228
|
+
free(): void;
|
|
229
|
+
[Symbol.dispose](): void;
|
|
230
|
+
/**
|
|
231
|
+
* The sedimentree ID this request corresponds to.
|
|
232
|
+
*/
|
|
233
|
+
id(): SedimentreeId;
|
|
234
|
+
/**
|
|
235
|
+
* The request ID for this request.
|
|
236
|
+
*/
|
|
237
|
+
request_id(): RequestId;
|
|
238
|
+
/**
|
|
239
|
+
* Whether this request subscribes to future updates.
|
|
240
|
+
*/
|
|
241
|
+
subscribe(): boolean;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Wasm wrapper for [`BatchSyncResponse`].
|
|
246
|
+
*/
|
|
247
|
+
export class BatchSyncResponse {
|
|
248
|
+
private constructor();
|
|
249
|
+
free(): void;
|
|
250
|
+
[Symbol.dispose](): void;
|
|
251
|
+
/**
|
|
252
|
+
* Upcasts; to the JS-import type for [`WasmBatchSyncResponse`].
|
|
253
|
+
*/
|
|
254
|
+
__wasm_refgen_toWasmBatchSyncResponse(): BatchSyncResponse;
|
|
255
|
+
/**
|
|
256
|
+
* The sedimentree ID this response corresponds to.
|
|
257
|
+
*/
|
|
258
|
+
id(): SedimentreeId;
|
|
259
|
+
/**
|
|
260
|
+
* The request ID this response corresponds to.
|
|
261
|
+
*/
|
|
262
|
+
request_id(): RequestId;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* A Wasm wrapper around the [`BlobMeta`] type.
|
|
267
|
+
*/
|
|
268
|
+
export class BlobMeta {
|
|
269
|
+
free(): void;
|
|
270
|
+
[Symbol.dispose](): void;
|
|
271
|
+
/**
|
|
272
|
+
* Get the digest of the blob.
|
|
273
|
+
*/
|
|
274
|
+
digest(): Digest;
|
|
275
|
+
/**
|
|
276
|
+
* Create a `BlobMeta` from a digest and size.
|
|
277
|
+
*
|
|
278
|
+
* This is useful for deserialization when the original blob is not available.
|
|
279
|
+
* Since this is manual, the caller must ensure the digest and size are correct.
|
|
280
|
+
*/
|
|
281
|
+
static fromDigestSize(digest: Digest, size_bytes: bigint): BlobMeta;
|
|
282
|
+
/**
|
|
283
|
+
* Create a new `BlobMeta` from the given blob contents.
|
|
284
|
+
*/
|
|
285
|
+
constructor(blob: Uint8Array);
|
|
286
|
+
/**
|
|
287
|
+
* Get the size of the blob in bytes.
|
|
288
|
+
*/
|
|
289
|
+
readonly sizeBytes: bigint;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Wasm wrapper for call errors.
|
|
294
|
+
*/
|
|
295
|
+
export class CallError {
|
|
296
|
+
private constructor();
|
|
297
|
+
free(): void;
|
|
298
|
+
[Symbol.dispose](): void;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* A commit stored with its associated blob.
|
|
303
|
+
*/
|
|
304
|
+
export class CommitWithBlob {
|
|
305
|
+
free(): void;
|
|
306
|
+
[Symbol.dispose](): void;
|
|
307
|
+
/**
|
|
308
|
+
* Upcasts; to the JS-import type for [`WasmCommitWithBlob`].
|
|
309
|
+
*/
|
|
310
|
+
__wasm_refgen_toWasmCommitWithBlob(): CommitWithBlob;
|
|
311
|
+
/**
|
|
312
|
+
* Create a new commit with blob.
|
|
313
|
+
*/
|
|
314
|
+
constructor(signed: SignedLooseCommit, blob: Uint8Array);
|
|
315
|
+
/**
|
|
316
|
+
* Get the blob.
|
|
317
|
+
*/
|
|
318
|
+
readonly blob: Uint8Array;
|
|
319
|
+
/**
|
|
320
|
+
* Get the signed commit.
|
|
321
|
+
*/
|
|
322
|
+
readonly signed: SignedLooseCommit;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* A JavaScript wrapper around `Depth`.
|
|
327
|
+
*/
|
|
328
|
+
export class Depth {
|
|
329
|
+
free(): void;
|
|
330
|
+
[Symbol.dispose](): void;
|
|
331
|
+
/**
|
|
332
|
+
* Internal method for a hack crossing the JS boundary.
|
|
333
|
+
*/
|
|
334
|
+
__subduction_castToDepth(): Depth;
|
|
335
|
+
/**
|
|
336
|
+
* Upcasts; to the JS-import type for [`WasmDepth`].
|
|
337
|
+
*/
|
|
338
|
+
__wasm_refgen_toWasmDepth(): Depth;
|
|
339
|
+
/**
|
|
340
|
+
* Creates a new `WasmDepth` from a JavaScript value.
|
|
341
|
+
*
|
|
342
|
+
* # Errors
|
|
343
|
+
*
|
|
344
|
+
* Returns a `NotU32Error` if the JS value is not safely coercible to `u32`.
|
|
345
|
+
*/
|
|
346
|
+
constructor(js_value: any);
|
|
347
|
+
/**
|
|
348
|
+
* The depth value as an integer.
|
|
349
|
+
*/
|
|
350
|
+
readonly value: number;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* A wrapper around digest bytes for use in JavaScript via wasm-bindgen.
|
|
355
|
+
*
|
|
356
|
+
* Since JavaScript doesn't have Rust's type system, this stores raw bytes
|
|
357
|
+
* and converts to/from typed `Digest<T>` at the Rust boundary.
|
|
358
|
+
*/
|
|
359
|
+
export class Digest {
|
|
360
|
+
free(): void;
|
|
361
|
+
[Symbol.dispose](): void;
|
|
362
|
+
/**
|
|
363
|
+
* Upcasts; to the JS-import type for [`WasmDigest`].
|
|
364
|
+
*/
|
|
365
|
+
__wasm_refgen_toWasmDigest(): Digest;
|
|
366
|
+
/**
|
|
367
|
+
* Creates a new digest from its Base58 string representation.
|
|
368
|
+
*
|
|
369
|
+
* # Errors
|
|
370
|
+
*
|
|
371
|
+
* Returns a `WasmInvalidDigest` error if the string cannot be decoded or is not a valid digest.
|
|
372
|
+
*/
|
|
373
|
+
static fromBase58(s: string): Digest;
|
|
374
|
+
/**
|
|
375
|
+
* Creates a new digest from its byte representation.
|
|
376
|
+
*
|
|
377
|
+
* # Errors
|
|
378
|
+
*
|
|
379
|
+
* Returns a `WasmValue` error if the byte slice is not a valid digest.
|
|
380
|
+
*/
|
|
381
|
+
static fromBytes(bytes: Uint8Array): Digest;
|
|
382
|
+
/**
|
|
383
|
+
* Creates a new digest from its hexadecimal string representation.
|
|
384
|
+
*
|
|
385
|
+
* # Errors
|
|
386
|
+
*
|
|
387
|
+
* Returns a [`WasmInvalidDigest`] if the string is not a valid digest.
|
|
388
|
+
*/
|
|
389
|
+
static fromHexString(s: string): Digest;
|
|
390
|
+
/**
|
|
391
|
+
* Creates a new digest from its byte representation.
|
|
392
|
+
*
|
|
393
|
+
* # Errors
|
|
394
|
+
*
|
|
395
|
+
* Returns a `WasmValue` error if the byte slice is not a valid digest.
|
|
396
|
+
*/
|
|
397
|
+
constructor(bytes: Uint8Array);
|
|
398
|
+
/**
|
|
399
|
+
* Returns the byte representation of the digest.
|
|
400
|
+
*/
|
|
401
|
+
toBytes(): Uint8Array;
|
|
402
|
+
/**
|
|
403
|
+
* Returns the hexadecimal string representation of the digest.
|
|
404
|
+
*/
|
|
405
|
+
toHexString(): string;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* A data fragment used in the Sedimentree system.
|
|
410
|
+
*/
|
|
411
|
+
export class Fragment {
|
|
412
|
+
free(): void;
|
|
413
|
+
[Symbol.dispose](): void;
|
|
414
|
+
/**
|
|
415
|
+
* Upcasts; to the JS-import type for [`WasmFragment`].
|
|
416
|
+
*/
|
|
417
|
+
__wasm_refgen_toWasmFragment(): Fragment;
|
|
418
|
+
/**
|
|
419
|
+
* Create a new fragment from the given sedimentree ID, head, boundary, checkpoints, and blob metadata.
|
|
420
|
+
*/
|
|
421
|
+
constructor(sedimentree_id: SedimentreeId, head: Digest, boundary: Digest[], checkpoints: Digest[], blob_meta: BlobMeta);
|
|
422
|
+
/**
|
|
423
|
+
* Get the blob metadata of the fragment.
|
|
424
|
+
*/
|
|
425
|
+
readonly blobMeta: BlobMeta;
|
|
426
|
+
/**
|
|
427
|
+
* Get the boundary digests of the fragment.
|
|
428
|
+
*/
|
|
429
|
+
readonly boundary: Digest[];
|
|
430
|
+
/**
|
|
431
|
+
* Get the head digest of the fragment.
|
|
432
|
+
*/
|
|
433
|
+
readonly head: Digest;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
* A request for a specific fragment in the Sedimentree system.
|
|
438
|
+
*/
|
|
439
|
+
export class FragmentRequested {
|
|
440
|
+
free(): void;
|
|
441
|
+
[Symbol.dispose](): void;
|
|
442
|
+
/**
|
|
443
|
+
* Create a new fragment request from the given digest.
|
|
444
|
+
*/
|
|
445
|
+
constructor(digest: Digest, depth: Depth);
|
|
446
|
+
/**
|
|
447
|
+
* Get the depth of the requested fragment.
|
|
448
|
+
*/
|
|
449
|
+
readonly depth: Depth;
|
|
450
|
+
/**
|
|
451
|
+
* Get the digest of the requested fragment.
|
|
452
|
+
*/
|
|
453
|
+
readonly head: Digest;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
/**
|
|
457
|
+
* A fragment stored with its associated blob.
|
|
458
|
+
*/
|
|
459
|
+
export class FragmentWithBlob {
|
|
460
|
+
free(): void;
|
|
461
|
+
[Symbol.dispose](): void;
|
|
462
|
+
/**
|
|
463
|
+
* Upcasts; to the JS-import type for [`WasmFragmentWithBlob`].
|
|
464
|
+
*/
|
|
465
|
+
__wasm_refgen_toWasmFragmentWithBlob(): FragmentWithBlob;
|
|
466
|
+
/**
|
|
467
|
+
* Create a new fragment with blob.
|
|
468
|
+
*/
|
|
469
|
+
constructor(signed: SignedFragment, blob: Uint8Array);
|
|
470
|
+
/**
|
|
471
|
+
* Get the blob.
|
|
472
|
+
*/
|
|
473
|
+
readonly blob: Uint8Array;
|
|
474
|
+
/**
|
|
475
|
+
* Get the signed fragment.
|
|
476
|
+
*/
|
|
477
|
+
readonly signed: SignedFragment;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
export class FragmentsArray {
|
|
481
|
+
private constructor();
|
|
482
|
+
free(): void;
|
|
483
|
+
[Symbol.dispose](): void;
|
|
484
|
+
/**
|
|
485
|
+
* Upcasts; to the JS-import type for [`WasmFragmentsArray`].
|
|
486
|
+
*/
|
|
487
|
+
__wasm_refgen_toWasmFragmentsArray(): FragmentsArray;
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
/**
|
|
491
|
+
* An overridable hash metric.
|
|
492
|
+
*/
|
|
493
|
+
export class HashMetric {
|
|
494
|
+
free(): void;
|
|
495
|
+
[Symbol.dispose](): void;
|
|
496
|
+
/**
|
|
497
|
+
* Create a new `WasmHashMetric` with an optional JavaScript function.
|
|
498
|
+
*
|
|
499
|
+
* Defaults to counting leading zero bytes if no function is provided.
|
|
500
|
+
*/
|
|
501
|
+
constructor(func?: Function | null);
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
/**
|
|
505
|
+
* A Wasm wrapper around the [`LooseCommit`] type.
|
|
506
|
+
*/
|
|
507
|
+
export class LooseCommit {
|
|
508
|
+
free(): void;
|
|
509
|
+
[Symbol.dispose](): void;
|
|
510
|
+
/**
|
|
511
|
+
* Upcasts; to the JS-import type for [`WasmLooseCommit`].
|
|
512
|
+
*/
|
|
513
|
+
__wasm_refgen_toWasmLooseCommit(): LooseCommit;
|
|
514
|
+
/**
|
|
515
|
+
* Create a new `LooseCommit` from the given sedimentree ID, parents, and blob metadata.
|
|
516
|
+
*/
|
|
517
|
+
constructor(sedimentree_id: SedimentreeId, parents: Digest[], blob_meta: BlobMeta);
|
|
518
|
+
/**
|
|
519
|
+
* Get the blob metadata of the commit.
|
|
520
|
+
*/
|
|
521
|
+
readonly blobMeta: BlobMeta;
|
|
522
|
+
/**
|
|
523
|
+
* Get the digest of the commit.
|
|
524
|
+
*/
|
|
525
|
+
readonly digest: Digest;
|
|
526
|
+
/**
|
|
527
|
+
* Get the parent digests of the commit.
|
|
528
|
+
*/
|
|
529
|
+
readonly parents: Digest[];
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
/**
|
|
533
|
+
* An in-memory Ed25519 signer exposed to JavaScript.
|
|
534
|
+
*
|
|
535
|
+
* Implements the `Signer` interface (`sign` / `verifyingKey`) so it can be
|
|
536
|
+
* passed anywhere a [`JsSigner`](crate::signer::JsSigner) is expected.
|
|
537
|
+
*
|
|
538
|
+
* # Example
|
|
539
|
+
*
|
|
540
|
+
* ```javascript
|
|
541
|
+
* import { MemorySigner } from "@automerge/subduction";
|
|
542
|
+
*
|
|
543
|
+
* const signer = MemorySigner.generate();
|
|
544
|
+
* console.log("Peer ID:", signer.peerId().toString());
|
|
545
|
+
* ```
|
|
546
|
+
*/
|
|
547
|
+
export class MemorySigner {
|
|
548
|
+
free(): void;
|
|
549
|
+
[Symbol.dispose](): void;
|
|
550
|
+
/**
|
|
551
|
+
* Create a signer from raw 32-byte Ed25519 secret key bytes.
|
|
552
|
+
*
|
|
553
|
+
* # Errors
|
|
554
|
+
*
|
|
555
|
+
* Returns an error if `bytes` is not exactly 32 bytes.
|
|
556
|
+
*/
|
|
557
|
+
static fromBytes(bytes: Uint8Array): MemorySigner;
|
|
558
|
+
/**
|
|
559
|
+
* Create a new signer with a randomly generated Ed25519 key.
|
|
560
|
+
*
|
|
561
|
+
* # Panics
|
|
562
|
+
*
|
|
563
|
+
* Panics if the system random number generator fails.
|
|
564
|
+
*/
|
|
565
|
+
static generate(): MemorySigner;
|
|
566
|
+
/**
|
|
567
|
+
* Create a new signer with a randomly generated Ed25519 key.
|
|
568
|
+
*
|
|
569
|
+
* This is the JS constructor (`new MemorySigner()`), equivalent to
|
|
570
|
+
* [`generate`](Self::generate).
|
|
571
|
+
*
|
|
572
|
+
* # Panics
|
|
573
|
+
*
|
|
574
|
+
* Panics if the system random number generator fails.
|
|
575
|
+
*/
|
|
576
|
+
constructor();
|
|
577
|
+
/**
|
|
578
|
+
* Get the peer ID derived from this signer's verifying key.
|
|
579
|
+
*/
|
|
580
|
+
peerId(): PeerId;
|
|
581
|
+
/**
|
|
582
|
+
* Sign a message and return the 64-byte Ed25519 signature as a `Uint8Array`.
|
|
583
|
+
*
|
|
584
|
+
* This fulfils the `Signer.sign(message)` interface contract.
|
|
585
|
+
* Returns a `Promise<Uint8Array>` for consistency with the async signer interface.
|
|
586
|
+
*/
|
|
587
|
+
sign(message: Uint8Array): Promise<Uint8Array>;
|
|
588
|
+
/**
|
|
589
|
+
* Get the 32-byte Ed25519 verifying (public) key as a `Uint8Array`.
|
|
590
|
+
*
|
|
591
|
+
* This fulfils the `Signer.verifyingKey()` interface contract.
|
|
592
|
+
*/
|
|
593
|
+
verifyingKey(): Uint8Array;
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
/**
|
|
597
|
+
* An in-memory storage implementation for use in tests and development.
|
|
598
|
+
*
|
|
599
|
+
* This wraps the core `MemoryStorage` and exposes it via the `SedimentreeStorage` interface.
|
|
600
|
+
*/
|
|
601
|
+
export class MemoryStorage {
|
|
602
|
+
free(): void;
|
|
603
|
+
[Symbol.dispose](): void;
|
|
604
|
+
/**
|
|
605
|
+
* Delete all commits for a sedimentree.
|
|
606
|
+
*/
|
|
607
|
+
deleteAllCommits(sedimentree_id: SedimentreeId): Promise<any>;
|
|
608
|
+
/**
|
|
609
|
+
* Delete all fragments for a sedimentree.
|
|
610
|
+
*/
|
|
611
|
+
deleteAllFragments(sedimentree_id: SedimentreeId): Promise<any>;
|
|
612
|
+
/**
|
|
613
|
+
* Delete a commit by digest.
|
|
614
|
+
*/
|
|
615
|
+
deleteCommit(sedimentree_id: SedimentreeId, digest: Digest): Promise<any>;
|
|
616
|
+
/**
|
|
617
|
+
* Delete a fragment by digest.
|
|
618
|
+
*/
|
|
619
|
+
deleteFragment(sedimentree_id: SedimentreeId, digest: Digest): Promise<any>;
|
|
620
|
+
/**
|
|
621
|
+
* Delete a sedimentree ID.
|
|
622
|
+
*/
|
|
623
|
+
deleteSedimentreeId(sedimentree_id: SedimentreeId): Promise<any>;
|
|
624
|
+
/**
|
|
625
|
+
* List all commit digests for a sedimentree.
|
|
626
|
+
*/
|
|
627
|
+
listCommitDigests(sedimentree_id: SedimentreeId): Promise<any>;
|
|
628
|
+
/**
|
|
629
|
+
* List all fragment digests for a sedimentree.
|
|
630
|
+
*/
|
|
631
|
+
listFragmentDigests(sedimentree_id: SedimentreeId): Promise<any>;
|
|
632
|
+
/**
|
|
633
|
+
* Load all commits for a sedimentree, returning `CommitWithBlob[]`.
|
|
634
|
+
*/
|
|
635
|
+
loadAllCommits(sedimentree_id: SedimentreeId): Promise<any>;
|
|
636
|
+
/**
|
|
637
|
+
* Load all fragments for a sedimentree, returning `FragmentWithBlob[]`.
|
|
638
|
+
*/
|
|
639
|
+
loadAllFragments(sedimentree_id: SedimentreeId): Promise<any>;
|
|
640
|
+
/**
|
|
641
|
+
* Load all sedimentree IDs.
|
|
642
|
+
*/
|
|
643
|
+
loadAllSedimentreeIds(): Promise<any>;
|
|
644
|
+
/**
|
|
645
|
+
* Load a commit by digest, returning `CommitWithBlob` or null.
|
|
646
|
+
*/
|
|
647
|
+
loadCommit(sedimentree_id: SedimentreeId, digest: Digest): Promise<any>;
|
|
648
|
+
/**
|
|
649
|
+
* Load a fragment by digest, returning `FragmentWithBlob` or null.
|
|
650
|
+
*/
|
|
651
|
+
loadFragment(sedimentree_id: SedimentreeId, digest: Digest): Promise<any>;
|
|
652
|
+
/**
|
|
653
|
+
* Create a new in-memory storage instance.
|
|
654
|
+
*/
|
|
655
|
+
constructor();
|
|
656
|
+
/**
|
|
657
|
+
* Save a commit with its blob.
|
|
658
|
+
*/
|
|
659
|
+
saveCommit(sedimentree_id: SedimentreeId, _digest: Digest, signed_commit: SignedLooseCommit, blob: Uint8Array): Promise<any>;
|
|
660
|
+
/**
|
|
661
|
+
* Save a fragment with its blob.
|
|
662
|
+
*/
|
|
663
|
+
saveFragment(sedimentree_id: SedimentreeId, _digest: Digest, signed_fragment: SignedFragment, blob: Uint8Array): Promise<any>;
|
|
664
|
+
/**
|
|
665
|
+
* Save a sedimentree ID.
|
|
666
|
+
*/
|
|
667
|
+
saveSedimentreeId(sedimentree_id: SedimentreeId): Promise<any>;
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
/**
|
|
671
|
+
* A `Transport` backed by a `MessagePort` (or any object with
|
|
672
|
+
* `postMessage` / `onmessage` / `close`).
|
|
673
|
+
*
|
|
674
|
+
* Implements the byte-oriented `Transport` interface (`sendBytes`,
|
|
675
|
+
* `recvBytes`, `disconnect`) using the port as the underlying channel.
|
|
676
|
+
* After the handshake, the [`Authenticated`] wrapper provides the sync API.
|
|
677
|
+
*/
|
|
678
|
+
export class MessagePortTransport {
|
|
679
|
+
free(): void;
|
|
680
|
+
[Symbol.dispose](): void;
|
|
681
|
+
/**
|
|
682
|
+
* Disconnect (close the port) and fire the `onDisconnect` callback if registered.
|
|
683
|
+
*/
|
|
684
|
+
disconnect(): Promise<any>;
|
|
685
|
+
/**
|
|
686
|
+
* Create a new connection wrapping the given `MessagePort`.
|
|
687
|
+
*/
|
|
688
|
+
constructor(port: any);
|
|
689
|
+
/**
|
|
690
|
+
* Register a callback to be invoked when the transport disconnects.
|
|
691
|
+
*
|
|
692
|
+
* Part of the [`Transport`](super::JsTransport) interface contract.
|
|
693
|
+
* Typically called by internal wiring rather than directly by user code.
|
|
694
|
+
*/
|
|
695
|
+
onDisconnect(callback: Function): void;
|
|
696
|
+
/**
|
|
697
|
+
* Receive raw bytes (for the handshake phase).
|
|
698
|
+
*/
|
|
699
|
+
recvBytes(): Promise<any>;
|
|
700
|
+
/**
|
|
701
|
+
* Send raw bytes (for the handshake phase).
|
|
702
|
+
*/
|
|
703
|
+
sendBytes(bytes: Uint8Array): Promise<any>;
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
/**
|
|
707
|
+
* A 64-bit nonce represented as big-endian bytes.
|
|
708
|
+
*/
|
|
709
|
+
export class Nonce {
|
|
710
|
+
free(): void;
|
|
711
|
+
[Symbol.dispose](): void;
|
|
712
|
+
/**
|
|
713
|
+
* Create a new [`WasmNonce`] from exactly 8 big-endian bytes.
|
|
714
|
+
*
|
|
715
|
+
* # Errors
|
|
716
|
+
*
|
|
717
|
+
* Returns [`WasmNonceError`] if the input is not exactly 8 bytes.
|
|
718
|
+
*/
|
|
719
|
+
constructor(bytes: Uint8Array);
|
|
720
|
+
/**
|
|
721
|
+
* Generate a random nonce.
|
|
722
|
+
*
|
|
723
|
+
* # Panics
|
|
724
|
+
*
|
|
725
|
+
* Panics if the system random number generator fails.
|
|
726
|
+
*/
|
|
727
|
+
static random(): Nonce;
|
|
728
|
+
/**
|
|
729
|
+
* Get the nonce as big-endian bytes.
|
|
730
|
+
*/
|
|
731
|
+
readonly bytes: Uint8Array;
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
/**
|
|
735
|
+
* Result of a peer batch sync request.
|
|
736
|
+
*/
|
|
737
|
+
export class PeerBatchSyncResult {
|
|
738
|
+
private constructor();
|
|
739
|
+
free(): void;
|
|
740
|
+
[Symbol.dispose](): void;
|
|
741
|
+
/**
|
|
742
|
+
* Statistics about the sync operation.
|
|
743
|
+
*/
|
|
744
|
+
readonly stats: SyncStats;
|
|
745
|
+
/**
|
|
746
|
+
* Whether the batch sync was successful with at least one connection.
|
|
747
|
+
*/
|
|
748
|
+
readonly success: boolean;
|
|
749
|
+
/**
|
|
750
|
+
* Errors that occurred during the batch sync.
|
|
751
|
+
*/
|
|
752
|
+
readonly transportErrors: Error[];
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
/**
|
|
756
|
+
* A JavaScript-compatible wrapper around the Rust `PeerId` type.
|
|
757
|
+
*/
|
|
758
|
+
export class PeerId {
|
|
759
|
+
free(): void;
|
|
760
|
+
[Symbol.dispose](): void;
|
|
761
|
+
/**
|
|
762
|
+
* Creates a new `WasmPeerId` from a `PeerId`.
|
|
763
|
+
*
|
|
764
|
+
* # Errors
|
|
765
|
+
*
|
|
766
|
+
* Returns a `WasmInvalidPeerId` if the provided byte slice is not exactly 32 bytes long.
|
|
767
|
+
*/
|
|
768
|
+
constructor(bytes: Uint8Array);
|
|
769
|
+
/**
|
|
770
|
+
* Returns the byte representation of the `PeerId`.
|
|
771
|
+
*/
|
|
772
|
+
toBytes(): Uint8Array;
|
|
773
|
+
/**
|
|
774
|
+
* Returns the string representation of the `PeerId`.
|
|
775
|
+
*/
|
|
776
|
+
toString(): string;
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
/**
|
|
780
|
+
* Map of peer IDs to their batch sync results.
|
|
781
|
+
*/
|
|
782
|
+
export class PeerResultMap {
|
|
783
|
+
private constructor();
|
|
784
|
+
free(): void;
|
|
785
|
+
[Symbol.dispose](): void;
|
|
786
|
+
/**
|
|
787
|
+
* Get all entries in the peer result map.
|
|
788
|
+
*/
|
|
789
|
+
entries(): PeerBatchSyncResult[];
|
|
790
|
+
/**
|
|
791
|
+
* Get the result for a specific peer ID.
|
|
792
|
+
*/
|
|
793
|
+
getResult(peer_id: PeerId): PeerBatchSyncResult | undefined;
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
/**
|
|
797
|
+
* Wasm wrapper for [`RequestId`].
|
|
798
|
+
*/
|
|
799
|
+
export class RequestId {
|
|
800
|
+
free(): void;
|
|
801
|
+
[Symbol.dispose](): void;
|
|
802
|
+
/**
|
|
803
|
+
* Upcasts; to the JS-import type for [`WasmRequestId`].
|
|
804
|
+
*/
|
|
805
|
+
__wasm_refgen_toWasmRequestId(): RequestId;
|
|
806
|
+
/**
|
|
807
|
+
* Create a new [`RequestId`] from a requestor peer ID and nonce.
|
|
808
|
+
*/
|
|
809
|
+
constructor(requestor: PeerId, nonce: Nonce);
|
|
810
|
+
/**
|
|
811
|
+
* The request nonce.
|
|
812
|
+
*/
|
|
813
|
+
readonly nonce: Nonce;
|
|
814
|
+
/**
|
|
815
|
+
* The peer ID of the requestor.
|
|
816
|
+
*/
|
|
817
|
+
readonly requestor: PeerId;
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
/**
|
|
821
|
+
* The main Sedimentree data structure.
|
|
822
|
+
*/
|
|
823
|
+
export class Sedimentree {
|
|
824
|
+
free(): void;
|
|
825
|
+
[Symbol.dispose](): void;
|
|
826
|
+
/**
|
|
827
|
+
* Create an empty Sedimentree.
|
|
828
|
+
*/
|
|
829
|
+
static empty(): Sedimentree;
|
|
830
|
+
/**
|
|
831
|
+
* Create a new Sedimentree from fragments and loose commits.
|
|
832
|
+
*/
|
|
833
|
+
constructor(fragments: Fragment[], commits: LooseCommit[]);
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
/**
|
|
837
|
+
* A Wasm wrapper around the [`SedimentreeId`] type.
|
|
838
|
+
*/
|
|
839
|
+
export class SedimentreeId {
|
|
840
|
+
private constructor();
|
|
841
|
+
free(): void;
|
|
842
|
+
[Symbol.dispose](): void;
|
|
843
|
+
/**
|
|
844
|
+
* Upcasts; to the JS-import type for [`WasmSedimentreeId`].
|
|
845
|
+
*/
|
|
846
|
+
__wasm_refgen_toWasmSedimentreeId(): SedimentreeId;
|
|
847
|
+
/**
|
|
848
|
+
* Create an ID from a byte array.
|
|
849
|
+
*
|
|
850
|
+
* # Errors
|
|
851
|
+
*
|
|
852
|
+
* Returns `Not32Bytes` if the provided byte array is not exactly 32 bytes long.
|
|
853
|
+
*/
|
|
854
|
+
static fromBytes(bytes: Uint8Array): SedimentreeId;
|
|
855
|
+
/**
|
|
856
|
+
* Returns the raw bytes of this ID.
|
|
857
|
+
*/
|
|
858
|
+
toBytes(): Uint8Array;
|
|
859
|
+
/**
|
|
860
|
+
* Returns the string representation of the ID.
|
|
861
|
+
*/
|
|
862
|
+
toString(): string;
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
export class SedimentreeIdsArray {
|
|
866
|
+
private constructor();
|
|
867
|
+
free(): void;
|
|
868
|
+
[Symbol.dispose](): void;
|
|
869
|
+
/**
|
|
870
|
+
* Upcasts; to the JS-import type for [`WasmSedimentreeIdsArray`].
|
|
871
|
+
*/
|
|
872
|
+
__wasm_refgen_toWasmSedimentreeIdsArray(): SedimentreeIdsArray;
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
/**
|
|
876
|
+
* A Wasm wrapper around `Signed<Fragment>`.
|
|
877
|
+
*/
|
|
878
|
+
export class SignedFragment {
|
|
879
|
+
private constructor();
|
|
880
|
+
free(): void;
|
|
881
|
+
[Symbol.dispose](): void;
|
|
882
|
+
/**
|
|
883
|
+
* Upcasts; to the JS-import type for [`WasmSignedFragment`].
|
|
884
|
+
*/
|
|
885
|
+
__wasm_refgen_toWasmSignedFragment(): SignedFragment;
|
|
886
|
+
/**
|
|
887
|
+
* Encode this signed fragment to raw bytes.
|
|
888
|
+
*/
|
|
889
|
+
encode(): Uint8Array;
|
|
890
|
+
/**
|
|
891
|
+
* Decode a `SignedFragment` from raw bytes.
|
|
892
|
+
*
|
|
893
|
+
* # Errors
|
|
894
|
+
*
|
|
895
|
+
* Returns an error if the bytes are not a valid signed fragment.
|
|
896
|
+
*/
|
|
897
|
+
static tryDecode(bytes: Uint8Array): SignedFragment;
|
|
898
|
+
/**
|
|
899
|
+
* Get the unsigned payload without re-verifying the signature.
|
|
900
|
+
*
|
|
901
|
+
* # Errors
|
|
902
|
+
*
|
|
903
|
+
* Returns an error if the payload cannot be decoded.
|
|
904
|
+
*/
|
|
905
|
+
readonly payload: Fragment;
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
/**
|
|
909
|
+
* A Wasm wrapper around `Signed<LooseCommit>`.
|
|
910
|
+
*/
|
|
911
|
+
export class SignedLooseCommit {
|
|
912
|
+
private constructor();
|
|
913
|
+
free(): void;
|
|
914
|
+
[Symbol.dispose](): void;
|
|
915
|
+
/**
|
|
916
|
+
* Upcasts; to the JS-import type for [`WasmSignedLooseCommit`].
|
|
917
|
+
*/
|
|
918
|
+
__wasm_refgen_toWasmSignedLooseCommit(): SignedLooseCommit;
|
|
919
|
+
/**
|
|
920
|
+
* Encode this signed loose commit to raw bytes.
|
|
921
|
+
*/
|
|
922
|
+
encode(): Uint8Array;
|
|
923
|
+
/**
|
|
924
|
+
* Decode a `SignedLooseCommit` from raw bytes.
|
|
925
|
+
*
|
|
926
|
+
* # Errors
|
|
927
|
+
*
|
|
928
|
+
* Returns an error if the bytes are not a valid signed loose commit.
|
|
929
|
+
*/
|
|
930
|
+
static tryDecode(bytes: Uint8Array): SignedLooseCommit;
|
|
931
|
+
/**
|
|
932
|
+
* Get the unsigned payload without re-verifying the signature.
|
|
933
|
+
*
|
|
934
|
+
* # Errors
|
|
935
|
+
*
|
|
936
|
+
* Returns an error if the payload cannot be decoded.
|
|
937
|
+
*/
|
|
938
|
+
readonly payload: LooseCommit;
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
/**
|
|
942
|
+
* Wasm bindings for [`Subduction`](subduction_core::Subduction)
|
|
943
|
+
*/
|
|
944
|
+
export class Subduction {
|
|
945
|
+
free(): void;
|
|
946
|
+
[Symbol.dispose](): void;
|
|
947
|
+
/**
|
|
948
|
+
* Accept a connection from a peer over any [`Transport`](JsTransport).
|
|
949
|
+
*
|
|
950
|
+
* Performs the responder side of the handshake, then adds the authenticated
|
|
951
|
+
* connection. This is the counterpart to [`connectTransport`](Self::connect_transport).
|
|
952
|
+
*
|
|
953
|
+
* # Arguments
|
|
954
|
+
*
|
|
955
|
+
* * `transport` - Any JS object with `sendBytes`/`recvBytes`/`disconnect`
|
|
956
|
+
* * `service_name` - Shared service name for discovery
|
|
957
|
+
*
|
|
958
|
+
* # Errors
|
|
959
|
+
*
|
|
960
|
+
* Returns an error if the handshake or connection fails.
|
|
961
|
+
*/
|
|
962
|
+
acceptTransport(transport: Transport, service_name: string): Promise<PeerId>;
|
|
963
|
+
/**
|
|
964
|
+
* Add a commit with its associated blob to the storage.
|
|
965
|
+
*
|
|
966
|
+
* The commit metadata (including `BlobMeta`) is computed internally from
|
|
967
|
+
* the provided blob, ensuring consistency by construction.
|
|
968
|
+
*
|
|
969
|
+
* # Errors
|
|
970
|
+
*
|
|
971
|
+
* Returns a [`WasmWriteError`] if storage, networking, or policy fail.
|
|
972
|
+
*/
|
|
973
|
+
addCommit(id: SedimentreeId, parents: Digest[], blob: Uint8Array): Promise<FragmentRequested | undefined>;
|
|
974
|
+
/**
|
|
975
|
+
* Onboard an authenticated transport: add it and sync all sedimentrees.
|
|
976
|
+
*
|
|
977
|
+
* Accepts an [`AuthenticatedTransport`](WasmAuthenticatedTransport),
|
|
978
|
+
* obtained via [`AuthenticatedTransport.setup`](WasmAuthenticatedTransport::setup),
|
|
979
|
+
* [`AuthenticatedWebSocket.toTransport`], or [`AuthenticatedLongPoll.toTransport`].
|
|
980
|
+
*
|
|
981
|
+
* Returns `true` if this is a new peer, `false` if already connected.
|
|
982
|
+
*
|
|
983
|
+
* Add an authenticated transport to tracking.
|
|
984
|
+
*
|
|
985
|
+
* This does not perform any synchronization. To sync after adding,
|
|
986
|
+
* call [`fullSyncWithPeer`](Self::full_sync_with_peer).
|
|
987
|
+
*
|
|
988
|
+
* Returns `true` if this is a new peer, `false` if already connected.
|
|
989
|
+
*
|
|
990
|
+
* # Errors
|
|
991
|
+
*
|
|
992
|
+
* Returns an error if the connection is rejected by the policy.
|
|
993
|
+
*/
|
|
994
|
+
addConnection(transport: AuthenticatedTransport): Promise<boolean>;
|
|
995
|
+
/**
|
|
996
|
+
* Add a fragment with its associated blob to the storage.
|
|
997
|
+
*
|
|
998
|
+
* The fragment metadata (including `BlobMeta`) is computed internally from
|
|
999
|
+
* the provided blob, ensuring consistency by construction.
|
|
1000
|
+
*
|
|
1001
|
+
* # Errors
|
|
1002
|
+
*
|
|
1003
|
+
* Returns a [`WasmWriteError`] if storage, networking, or policy fail.
|
|
1004
|
+
*/
|
|
1005
|
+
addFragment(id: SedimentreeId, head: Digest, boundary: Digest[], checkpoints: Digest[], blob: Uint8Array): Promise<void>;
|
|
1006
|
+
/**
|
|
1007
|
+
* Add a Sedimentree.
|
|
1008
|
+
*
|
|
1009
|
+
* # Errors
|
|
1010
|
+
*
|
|
1011
|
+
* Returns [`WasmWriteError`] if there is a problem with storage, networking, or policy.
|
|
1012
|
+
*/
|
|
1013
|
+
addSedimentree(id: SedimentreeId, sedimentree: Sedimentree, blobs: Uint8Array[]): Promise<void>;
|
|
1014
|
+
/**
|
|
1015
|
+
* Connect to a peer via WebSocket and add the connection.
|
|
1016
|
+
*
|
|
1017
|
+
* This performs the cryptographic handshake, verifies the server's identity,
|
|
1018
|
+
* and adds the authenticated connection for syncing.
|
|
1019
|
+
*
|
|
1020
|
+
* Returns the verified peer ID on success.
|
|
1021
|
+
*
|
|
1022
|
+
* # Arguments
|
|
1023
|
+
*
|
|
1024
|
+
* * `address` - The WebSocket URL to connect to
|
|
1025
|
+
* * `expected_peer_id` - The expected server peer ID (verified during handshake)
|
|
1026
|
+
*
|
|
1027
|
+
* # Errors
|
|
1028
|
+
*
|
|
1029
|
+
* Returns an error if connection, handshake, or adding the connection fails.
|
|
1030
|
+
*/
|
|
1031
|
+
connect(address: URL, expected_peer_id: PeerId): Promise<PeerId>;
|
|
1032
|
+
/**
|
|
1033
|
+
* Connect to a peer via WebSocket using discovery mode and add the connection.
|
|
1034
|
+
*
|
|
1035
|
+
* Returns the discovered and verified peer ID on success.
|
|
1036
|
+
*
|
|
1037
|
+
* # Arguments
|
|
1038
|
+
*
|
|
1039
|
+
* * `address` - The WebSocket URL to connect to
|
|
1040
|
+
* * `timeout_milliseconds` - Request timeout in milliseconds (defaults to 30000)
|
|
1041
|
+
* * `service_name` - The service name for discovery (defaults to URL host)
|
|
1042
|
+
*
|
|
1043
|
+
* # Errors
|
|
1044
|
+
*
|
|
1045
|
+
* Returns an error if connection, handshake, or adding the connection fails.
|
|
1046
|
+
*/
|
|
1047
|
+
connectDiscover(address: URL, service_name?: string | null): Promise<PeerId>;
|
|
1048
|
+
/**
|
|
1049
|
+
* Connect to a peer via HTTP long-poll using discovery mode.
|
|
1050
|
+
*
|
|
1051
|
+
* Returns the discovered and verified peer ID on success.
|
|
1052
|
+
*
|
|
1053
|
+
* # Arguments
|
|
1054
|
+
*
|
|
1055
|
+
* * `base_url` - The server's HTTP base URL (e.g., `http://localhost:8080`)
|
|
1056
|
+
* * `timeout_milliseconds` - Request timeout in milliseconds (default: 30000)
|
|
1057
|
+
* * `service_name` - The service name for discovery (defaults to `base_url`)
|
|
1058
|
+
*
|
|
1059
|
+
* # Errors
|
|
1060
|
+
*
|
|
1061
|
+
* Returns an error if connection, handshake, or adding the connection fails.
|
|
1062
|
+
*/
|
|
1063
|
+
connectDiscoverLongPoll(base_url: string, service_name?: string | null): Promise<PeerId>;
|
|
1064
|
+
/**
|
|
1065
|
+
* Connect to a peer via HTTP long-poll and add the connection.
|
|
1066
|
+
*
|
|
1067
|
+
* Returns the verified peer ID on success.
|
|
1068
|
+
*
|
|
1069
|
+
* # Arguments
|
|
1070
|
+
*
|
|
1071
|
+
* * `base_url` - The server's HTTP base URL (e.g., `http://localhost:8080`)
|
|
1072
|
+
* * `expected_peer_id` - The expected server peer ID (verified during handshake)
|
|
1073
|
+
* * `timeout_milliseconds` - Request timeout in milliseconds (default: 30000)
|
|
1074
|
+
*
|
|
1075
|
+
* # Errors
|
|
1076
|
+
*
|
|
1077
|
+
* Returns an error if connection, handshake, or adding the connection fails.
|
|
1078
|
+
*/
|
|
1079
|
+
connectLongPoll(base_url: string, expected_peer_id: PeerId): Promise<PeerId>;
|
|
1080
|
+
/**
|
|
1081
|
+
* Connect to a peer over any [`Transport`](JsTransport) using discovery mode.
|
|
1082
|
+
*
|
|
1083
|
+
* Performs a discovery handshake, then adds the authenticated connection.
|
|
1084
|
+
* The peer's identity is discovered during the handshake.
|
|
1085
|
+
*
|
|
1086
|
+
* # Arguments
|
|
1087
|
+
*
|
|
1088
|
+
* * `transport` - Any JS object with `sendBytes`/`recvBytes`/`disconnect`
|
|
1089
|
+
* * `service_name` - Shared service name for discovery
|
|
1090
|
+
*
|
|
1091
|
+
* # Errors
|
|
1092
|
+
*
|
|
1093
|
+
* Returns an error if the handshake or connection fails.
|
|
1094
|
+
*/
|
|
1095
|
+
connectTransport(transport: Transport, service_name: string): Promise<PeerId>;
|
|
1096
|
+
/**
|
|
1097
|
+
* Disconnect from all peers.
|
|
1098
|
+
*
|
|
1099
|
+
* # Errors
|
|
1100
|
+
*
|
|
1101
|
+
* Returns a [`WasmDisconnectionError`] if disconnection was not graceful.
|
|
1102
|
+
*/
|
|
1103
|
+
disconnectAll(): Promise<void>;
|
|
1104
|
+
/**
|
|
1105
|
+
* Disconnect from a peer by its ID.
|
|
1106
|
+
*
|
|
1107
|
+
* # Errors
|
|
1108
|
+
*
|
|
1109
|
+
* Returns a `WasmDisconnectionError` if disconnection fails.
|
|
1110
|
+
*/
|
|
1111
|
+
disconnectFromPeer(peer_id: PeerId): Promise<boolean>;
|
|
1112
|
+
/**
|
|
1113
|
+
* Fetch blobs by their digests, with an optional timeout in milliseconds.
|
|
1114
|
+
*
|
|
1115
|
+
* # Errors
|
|
1116
|
+
*
|
|
1117
|
+
* Returns a [`WasmIoError`] if storage or networking fail.
|
|
1118
|
+
*/
|
|
1119
|
+
fetchBlobs(id: SedimentreeId, timeout_milliseconds?: bigint | null): Promise<Uint8Array[] | undefined>;
|
|
1120
|
+
/**
|
|
1121
|
+
* Sync all known Sedimentree IDs with all connected peers.
|
|
1122
|
+
*/
|
|
1123
|
+
fullSyncWithAllPeers(timeout_milliseconds?: bigint | null): Promise<PeerBatchSyncResult>;
|
|
1124
|
+
/**
|
|
1125
|
+
* Sync all known Sedimentree IDs with a single peer.
|
|
1126
|
+
*
|
|
1127
|
+
* # Arguments
|
|
1128
|
+
*
|
|
1129
|
+
* * `peer_id` - The peer to sync with
|
|
1130
|
+
* * `subscribe` - Whether to subscribe to future updates (default: `true`)
|
|
1131
|
+
* * `timeout_milliseconds` - Per-call timeout in milliseconds
|
|
1132
|
+
*/
|
|
1133
|
+
fullSyncWithPeer(peer_id: PeerId, subscribe?: boolean | null, timeout_milliseconds?: bigint | null): Promise<PeerBatchSyncResult>;
|
|
1134
|
+
/**
|
|
1135
|
+
* Get a local blob by its digest.
|
|
1136
|
+
*
|
|
1137
|
+
* # Errors
|
|
1138
|
+
*
|
|
1139
|
+
* Returns a [`JsStorageError`] if JS storage fails.
|
|
1140
|
+
*/
|
|
1141
|
+
getBlob(id: SedimentreeId, digest: Digest): Promise<Uint8Array | undefined>;
|
|
1142
|
+
/**
|
|
1143
|
+
* Get all local blobs for a given Sedimentree ID.
|
|
1144
|
+
*
|
|
1145
|
+
* # Errors
|
|
1146
|
+
*
|
|
1147
|
+
* Returns a [`JsStorageError`] if JS storage fails.
|
|
1148
|
+
*/
|
|
1149
|
+
getBlobs(id: SedimentreeId): Promise<Uint8Array[]>;
|
|
1150
|
+
/**
|
|
1151
|
+
* Get all commits for a given Sedimentree ID
|
|
1152
|
+
*/
|
|
1153
|
+
getCommits(id: SedimentreeId): Promise<LooseCommit[] | undefined>;
|
|
1154
|
+
/**
|
|
1155
|
+
* Get the peer IDs of all connected peers.
|
|
1156
|
+
*/
|
|
1157
|
+
getConnectedPeerIds(): Promise<PeerId[]>;
|
|
1158
|
+
/**
|
|
1159
|
+
* Get all fragments for a given Sedimentree ID
|
|
1160
|
+
*/
|
|
1161
|
+
getFragments(id: SedimentreeId): Promise<Fragment[] | undefined>;
|
|
1162
|
+
/**
|
|
1163
|
+
* Hydrate a [`Subduction`] instance from external storage.
|
|
1164
|
+
*
|
|
1165
|
+
* Loads all sedimentree data from storage and reconstructs the in-memory
|
|
1166
|
+
* state before initializing the sync engine.
|
|
1167
|
+
*
|
|
1168
|
+
* # Arguments
|
|
1169
|
+
*
|
|
1170
|
+
* * `signer` - The cryptographic signer for this node's identity
|
|
1171
|
+
* * `storage` - Storage backend for persisting data
|
|
1172
|
+
* * `service_name` - Optional service identifier for discovery mode (e.g., `sync.example.com`).
|
|
1173
|
+
* When set, clients can connect without knowing the server's peer ID.
|
|
1174
|
+
* * `hash_metric_override` - Optional custom depth metric function
|
|
1175
|
+
* * `max_pending_blob_requests` - Optional maximum number of pending blob requests (default: 10,000)
|
|
1176
|
+
* * `policy` - Optional connection/storage authorization policy.
|
|
1177
|
+
* Defaults to allow-all.
|
|
1178
|
+
* * `ephemeral_policy` - Optional ephemeral message authorization policy.
|
|
1179
|
+
* Defaults to allow-all.
|
|
1180
|
+
*
|
|
1181
|
+
* # Panics
|
|
1182
|
+
*
|
|
1183
|
+
* Panics if `hash_metric_override` is `Some` but the underlying JS value
|
|
1184
|
+
* cannot be cast to a `Function`.
|
|
1185
|
+
*
|
|
1186
|
+
* # Errors
|
|
1187
|
+
*
|
|
1188
|
+
* Returns [`WasmHydrationError`] if hydration fails.
|
|
1189
|
+
*/
|
|
1190
|
+
static hydrate(signer: any, storage: SedimentreeStorage, service_name?: string | null, hash_metric_override?: (digest: Digest) => Depth | null, max_pending_blob_requests?: number | null, policy?: Policy | null, ephemeral_policy?: EphemeralPolicy | null, on_remote_heads?: Function | null, on_ephemeral?: Function | null): Promise<Subduction>;
|
|
1191
|
+
/**
|
|
1192
|
+
* Link two local [`Subduction`](WasmSubduction) instances over a
|
|
1193
|
+
* [`MessageChannel`](web_sys::MessageChannel).
|
|
1194
|
+
*
|
|
1195
|
+
* Creates a `MessageChannel`, performs a discovery handshake between
|
|
1196
|
+
* the two instances, and adds the connections to both. This is the
|
|
1197
|
+
* simplest way to sync two local instances.
|
|
1198
|
+
*
|
|
1199
|
+
* # Errors
|
|
1200
|
+
*
|
|
1201
|
+
* Returns an error if the handshake or connection fails.
|
|
1202
|
+
*/
|
|
1203
|
+
static link(a: Subduction, b: Subduction): Promise<void>;
|
|
1204
|
+
/**
|
|
1205
|
+
* Create a new [`Subduction`] instance.
|
|
1206
|
+
*
|
|
1207
|
+
* # Arguments
|
|
1208
|
+
*
|
|
1209
|
+
* * `signer` - The cryptographic signer for this node's identity
|
|
1210
|
+
* * `storage` - Storage backend for persisting data
|
|
1211
|
+
* * `service_name` - Optional service identifier for discovery mode (e.g., `sync.example.com`).
|
|
1212
|
+
* When set, clients can connect without knowing the server's peer ID.
|
|
1213
|
+
* * `hash_metric_override` - Optional custom depth metric function
|
|
1214
|
+
* * `max_pending_blob_requests` - Optional maximum number of pending blob requests (default: 10,000)
|
|
1215
|
+
* * `policy` - Optional connection/storage authorization policy.
|
|
1216
|
+
* Defaults to allow-all.
|
|
1217
|
+
* * `ephemeral_policy` - Optional ephemeral message authorization policy.
|
|
1218
|
+
* Defaults to allow-all.
|
|
1219
|
+
*
|
|
1220
|
+
* # Panics
|
|
1221
|
+
*
|
|
1222
|
+
* Panics if `hash_metric_override` is `Some` but the underlying JS value
|
|
1223
|
+
* cannot be cast to a `Function`.
|
|
1224
|
+
*/
|
|
1225
|
+
constructor(signer: any, storage: SedimentreeStorage, service_name?: string | null, hash_metric_override?: (digest: Digest) => Depth | null, max_pending_blob_requests?: number | null, policy?: Policy | null, ephemeral_policy?: EphemeralPolicy | null, on_remote_heads?: Function | null, on_ephemeral?: Function | null);
|
|
1226
|
+
/**
|
|
1227
|
+
* Publish an ephemeral message to all subscribers of a topic.
|
|
1228
|
+
*
|
|
1229
|
+
* The payload is opaque bytes — encoding is the caller's responsibility.
|
|
1230
|
+
* Messages are fire-and-forget; delivery is best-effort.
|
|
1231
|
+
*
|
|
1232
|
+
* # Panics
|
|
1233
|
+
*
|
|
1234
|
+
* Panics if the platform's random number generator fails.
|
|
1235
|
+
*/
|
|
1236
|
+
publishEphemeral(topic: Topic, payload: Uint8Array): Promise<void>;
|
|
1237
|
+
/**
|
|
1238
|
+
* Remove a Sedimentree and all associated data.
|
|
1239
|
+
*
|
|
1240
|
+
* # Errors
|
|
1241
|
+
*
|
|
1242
|
+
* Returns a [`WasmIoError`] if storage or networking fail.
|
|
1243
|
+
*/
|
|
1244
|
+
removeSedimentree(id: SedimentreeId): Promise<void>;
|
|
1245
|
+
/**
|
|
1246
|
+
* Request blobs by their digests from connected peers for a specific sedimentree.
|
|
1247
|
+
*/
|
|
1248
|
+
requestBlobs(id: SedimentreeId, digests: Digest[]): Promise<void>;
|
|
1249
|
+
/**
|
|
1250
|
+
* Get all known Sedimentree IDs
|
|
1251
|
+
*/
|
|
1252
|
+
sedimentreeIds(): Promise<SedimentreeId[]>;
|
|
1253
|
+
/**
|
|
1254
|
+
* Subscribe to ephemeral messages for the given topics
|
|
1255
|
+
* from all connected peers.
|
|
1256
|
+
*/
|
|
1257
|
+
subscribeEphemeral(topics: Topic[]): Promise<void>;
|
|
1258
|
+
/**
|
|
1259
|
+
* Request batch sync for a given Sedimentree ID from all connected peers.
|
|
1260
|
+
*
|
|
1261
|
+
* # Arguments
|
|
1262
|
+
*
|
|
1263
|
+
* * `id` - The sedimentree ID to sync
|
|
1264
|
+
* * `subscribe` - Whether to subscribe for incremental updates
|
|
1265
|
+
* * `timeout_milliseconds` - Optional timeout in milliseconds
|
|
1266
|
+
*
|
|
1267
|
+
* # Errors
|
|
1268
|
+
*
|
|
1269
|
+
* Returns a [`WasmIoError`] if storage or networking fail.
|
|
1270
|
+
*/
|
|
1271
|
+
syncWithAllPeers(id: SedimentreeId, subscribe: boolean, timeout_milliseconds?: bigint | null): Promise<PeerResultMap>;
|
|
1272
|
+
/**
|
|
1273
|
+
* Request batch sync for a given Sedimentree ID from a specific peer.
|
|
1274
|
+
*
|
|
1275
|
+
* # Arguments
|
|
1276
|
+
*
|
|
1277
|
+
* * `to_ask` - The peer ID to sync with
|
|
1278
|
+
* * `id` - The sedimentree ID to sync
|
|
1279
|
+
* * `subscribe` - Whether to subscribe for incremental updates
|
|
1280
|
+
* * `timeout_milliseconds` - Optional timeout in milliseconds
|
|
1281
|
+
*
|
|
1282
|
+
* # Errors
|
|
1283
|
+
*
|
|
1284
|
+
* Returns a [`WasmIoError`] if storage or networking fail.
|
|
1285
|
+
*/
|
|
1286
|
+
syncWithPeer(to_ask: PeerId, id: SedimentreeId, subscribe: boolean, timeout_milliseconds?: bigint | null): Promise<PeerBatchSyncResult>;
|
|
1287
|
+
/**
|
|
1288
|
+
* Unsubscribe from ephemeral messages for the given topics
|
|
1289
|
+
* from all connected peers.
|
|
1290
|
+
*/
|
|
1291
|
+
unsubscribeEphemeral(topics: Topic[]): Promise<void>;
|
|
1292
|
+
/**
|
|
1293
|
+
* Get the backing storage.
|
|
1294
|
+
*/
|
|
1295
|
+
readonly storage: any;
|
|
1296
|
+
}
|
|
1297
|
+
|
|
1298
|
+
/**
|
|
1299
|
+
* JS-facing wrapper around [`HttpLongPollTransport`] that exposes the
|
|
1300
|
+
* byte-oriented [`Transport`](super::JsTransport) interface
|
|
1301
|
+
* (`sendBytes`/`recvBytes`/`disconnect`/`onDisconnect`) so it can be used as a
|
|
1302
|
+
* duck-typed `JsTransport` from JavaScript.
|
|
1303
|
+
*/
|
|
1304
|
+
export class SubductionHttpLongPoll {
|
|
1305
|
+
private constructor();
|
|
1306
|
+
free(): void;
|
|
1307
|
+
[Symbol.dispose](): void;
|
|
1308
|
+
/**
|
|
1309
|
+
* Disconnect from the peer gracefully.
|
|
1310
|
+
*
|
|
1311
|
+
* Fires the `onDisconnect` callback if one is registered.
|
|
1312
|
+
*
|
|
1313
|
+
* # Errors
|
|
1314
|
+
*
|
|
1315
|
+
* Returns an error if the disconnect fails.
|
|
1316
|
+
*/
|
|
1317
|
+
disconnect(): Promise<void>;
|
|
1318
|
+
/**
|
|
1319
|
+
* Register a callback to be invoked when the transport disconnects.
|
|
1320
|
+
*
|
|
1321
|
+
* Part of the [`Transport`](super::JsTransport) interface contract.
|
|
1322
|
+
* Typically called by internal wiring rather than directly by user code.
|
|
1323
|
+
*/
|
|
1324
|
+
onDisconnect(callback: Function): void;
|
|
1325
|
+
/**
|
|
1326
|
+
* Receive the next message frame as raw bytes.
|
|
1327
|
+
*
|
|
1328
|
+
* # Errors
|
|
1329
|
+
*
|
|
1330
|
+
* Returns an error if the inbound channel is closed.
|
|
1331
|
+
*/
|
|
1332
|
+
recvBytes(): Promise<Uint8Array>;
|
|
1333
|
+
/**
|
|
1334
|
+
* Send raw bytes over the transport.
|
|
1335
|
+
*
|
|
1336
|
+
* # Errors
|
|
1337
|
+
*
|
|
1338
|
+
* Returns an error if the outbound channel is closed.
|
|
1339
|
+
*/
|
|
1340
|
+
sendBytes(bytes: Uint8Array): Promise<void>;
|
|
1341
|
+
}
|
|
1342
|
+
|
|
1343
|
+
/**
|
|
1344
|
+
* HTTP long-poll transport factory for browser/worker environments.
|
|
1345
|
+
*
|
|
1346
|
+
* Analogous to [`SubductionWebSocket`] but uses HTTP long-poll instead of WebSocket.
|
|
1347
|
+
*/
|
|
1348
|
+
export class SubductionLongPoll {
|
|
1349
|
+
private constructor();
|
|
1350
|
+
free(): void;
|
|
1351
|
+
[Symbol.dispose](): void;
|
|
1352
|
+
/**
|
|
1353
|
+
* Connect to a server with a known peer ID.
|
|
1354
|
+
*
|
|
1355
|
+
* # Arguments
|
|
1356
|
+
*
|
|
1357
|
+
* * `base_url` - The server's HTTP base URL (e.g., `http://localhost:8080`)
|
|
1358
|
+
* * `signer` - The client's signer for authentication
|
|
1359
|
+
* * `expected_peer_id` - The expected server peer ID (verified during handshake)
|
|
1360
|
+
* * `on_disconnect` - Optional callback invoked with the peer's [`PeerId`] when the connection closes
|
|
1361
|
+
*
|
|
1362
|
+
* # Errors
|
|
1363
|
+
*
|
|
1364
|
+
* Returns [`LongPollTransportError`] if connection or handshake fails.
|
|
1365
|
+
*/
|
|
1366
|
+
static tryConnect(base_url: string, signer: any, expected_peer_id: PeerId, on_disconnect?: Function | null): Promise<AuthenticatedLongPoll>;
|
|
1367
|
+
/**
|
|
1368
|
+
* Connect to a server using discovery mode.
|
|
1369
|
+
*
|
|
1370
|
+
* # Arguments
|
|
1371
|
+
*
|
|
1372
|
+
* * `base_url` - The server's HTTP base URL (e.g., `http://localhost:8080`)
|
|
1373
|
+
* * `signer` - The client's signer for authentication
|
|
1374
|
+
* * `service_name` - The service name for discovery. If omitted, the base URL is used.
|
|
1375
|
+
*
|
|
1376
|
+
* # Errors
|
|
1377
|
+
*
|
|
1378
|
+
* Returns [`LongPollTransportError`] if connection or handshake fails.
|
|
1379
|
+
*/
|
|
1380
|
+
static tryDiscover(base_url: string, signer: any, service_name?: string | null, on_disconnect?: Function | null): Promise<AuthenticatedLongPoll>;
|
|
1381
|
+
}
|
|
1382
|
+
|
|
1383
|
+
/**
|
|
1384
|
+
* A WebSocket transport exposing the byte-oriented `Transport` interface.
|
|
1385
|
+
*
|
|
1386
|
+
* Raw bytes from the WebSocket's `onmessage` handler are buffered in an
|
|
1387
|
+
* `async_channel` and returned via `recvBytes`. No message decoding or
|
|
1388
|
+
* request-response routing happens here — that's handled by
|
|
1389
|
+
* [`MessageTransport`](subduction_core::transport::message::MessageTransport).
|
|
1390
|
+
*/
|
|
1391
|
+
export class SubductionWebSocket {
|
|
1392
|
+
private constructor();
|
|
1393
|
+
free(): void;
|
|
1394
|
+
[Symbol.dispose](): void;
|
|
1395
|
+
/**
|
|
1396
|
+
* Disconnect from the peer gracefully.
|
|
1397
|
+
*/
|
|
1398
|
+
disconnect(): Promise<void>;
|
|
1399
|
+
/**
|
|
1400
|
+
* Register a callback to be invoked when the WebSocket closes.
|
|
1401
|
+
*
|
|
1402
|
+
* Part of the [`Transport`](super::JsTransport) interface contract.
|
|
1403
|
+
* Typically called by internal wiring (factory methods like `tryConnect`
|
|
1404
|
+
* and `tryDiscover`) rather than directly by user code.
|
|
1405
|
+
*
|
|
1406
|
+
* The callback is fired from the browser WebSocket's `onclose` handler.
|
|
1407
|
+
*/
|
|
1408
|
+
onDisconnect(callback: Function): void;
|
|
1409
|
+
/**
|
|
1410
|
+
* Receive the next message frame as raw bytes.
|
|
1411
|
+
*
|
|
1412
|
+
* # Errors
|
|
1413
|
+
*
|
|
1414
|
+
* Returns [`ReadFromClosedChannel`] if the channel has been closed.
|
|
1415
|
+
*/
|
|
1416
|
+
recvBytes(): Promise<Uint8Array>;
|
|
1417
|
+
/**
|
|
1418
|
+
* Send raw bytes over the WebSocket.
|
|
1419
|
+
*
|
|
1420
|
+
* # Errors
|
|
1421
|
+
*
|
|
1422
|
+
* Returns [`WasmSendError`] if the bytes could not be sent.
|
|
1423
|
+
*/
|
|
1424
|
+
sendBytes(bytes: Uint8Array): Promise<void>;
|
|
1425
|
+
/**
|
|
1426
|
+
* Authenticate an existing WebSocket via handshake.
|
|
1427
|
+
*
|
|
1428
|
+
* This performs the Subduction handshake protocol over the provided WebSocket
|
|
1429
|
+
* to establish mutual identity. The WebSocket can be in CONNECTING or OPEN state.
|
|
1430
|
+
*
|
|
1431
|
+
* # Arguments
|
|
1432
|
+
*
|
|
1433
|
+
* * `ws` - An existing WebSocket (CONNECTING or OPEN)
|
|
1434
|
+
* * `signer` - The client's signer for authentication
|
|
1435
|
+
* * `expected_peer_id` - The expected server peer ID (verified during handshake)
|
|
1436
|
+
* * `on_disconnect` - Optional callback invoked with the peer's [`PeerId`] when the connection closes
|
|
1437
|
+
*
|
|
1438
|
+
* # Errors
|
|
1439
|
+
*
|
|
1440
|
+
* Returns an error if the handshake fails (signature invalid, wrong peer, etc.)
|
|
1441
|
+
*/
|
|
1442
|
+
static setup(ws: WebSocket, signer: any, expected_peer_id: PeerId, on_disconnect?: Function | null): Promise<AuthenticatedWebSocket>;
|
|
1443
|
+
/**
|
|
1444
|
+
* Connect to a WebSocket server with mutual authentication via handshake.
|
|
1445
|
+
*
|
|
1446
|
+
* # Arguments
|
|
1447
|
+
*
|
|
1448
|
+
* * `address` - The WebSocket URL to connect to
|
|
1449
|
+
* * `signer` - The client's signer for authentication
|
|
1450
|
+
* * `expected_peer_id` - The expected server peer ID (verified during handshake)
|
|
1451
|
+
* * `on_disconnect` - Optional callback invoked with the peer's [`PeerId`] when the connection closes
|
|
1452
|
+
*
|
|
1453
|
+
* # Errors
|
|
1454
|
+
*
|
|
1455
|
+
* Returns an error if:
|
|
1456
|
+
* - The WebSocket connection could not be established
|
|
1457
|
+
* - The handshake fails (signature invalid, wrong server, clock drift, etc.)
|
|
1458
|
+
*/
|
|
1459
|
+
static tryConnect(address: URL, signer: any, expected_peer_id: PeerId, on_disconnect?: Function | null): Promise<AuthenticatedWebSocket>;
|
|
1460
|
+
/**
|
|
1461
|
+
* Connect to a WebSocket server using discovery mode.
|
|
1462
|
+
*
|
|
1463
|
+
* This method performs a cryptographic handshake using a service name
|
|
1464
|
+
* instead of a known peer ID. The server's peer ID is discovered during
|
|
1465
|
+
* the handshake and returned.
|
|
1466
|
+
*
|
|
1467
|
+
* # Arguments
|
|
1468
|
+
*
|
|
1469
|
+
* * `address` - The WebSocket URL to connect to
|
|
1470
|
+
* * `signer` - The client's signer for authentication
|
|
1471
|
+
* * `service_name` - The service name for discovery (e.g., `localhost:8080`).
|
|
1472
|
+
* If omitted, the host is extracted from the URL.
|
|
1473
|
+
* * `on_disconnect` - Optional callback invoked with the peer's [`PeerId`] when the connection closes
|
|
1474
|
+
*
|
|
1475
|
+
* # Errors
|
|
1476
|
+
*
|
|
1477
|
+
* Returns an error if:
|
|
1478
|
+
* - The WebSocket connection could not be established
|
|
1479
|
+
* - The handshake fails (signature invalid, clock drift, etc.)
|
|
1480
|
+
*/
|
|
1481
|
+
static tryDiscover(address: URL, signer: any, service_name?: string | null, on_disconnect?: Function | null): Promise<AuthenticatedWebSocket>;
|
|
1482
|
+
}
|
|
1483
|
+
|
|
1484
|
+
/**
|
|
1485
|
+
* Wasm wrapper for [`SyncMessage`].
|
|
1486
|
+
*/
|
|
1487
|
+
export class SyncMessage {
|
|
1488
|
+
private constructor();
|
|
1489
|
+
free(): void;
|
|
1490
|
+
[Symbol.dispose](): void;
|
|
1491
|
+
/**
|
|
1492
|
+
* Upcasts; to the JS-import type for [`WasmMessage`].
|
|
1493
|
+
*/
|
|
1494
|
+
__wasm_refgen_toWasmMessage(): SyncMessage;
|
|
1495
|
+
/**
|
|
1496
|
+
* Create a [`SyncMessage::BatchSyncRequest`] message.
|
|
1497
|
+
*/
|
|
1498
|
+
static batchSyncRequest(request: BatchSyncRequest): SyncMessage;
|
|
1499
|
+
/**
|
|
1500
|
+
* Create a [`SyncMessage::BatchSyncResponse`] message.
|
|
1501
|
+
*/
|
|
1502
|
+
static batchSyncResponse(response: BatchSyncResponse): SyncMessage;
|
|
1503
|
+
/**
|
|
1504
|
+
* Create a [`SyncMessage::BlobsRequest`] message.
|
|
1505
|
+
*/
|
|
1506
|
+
static blobsRequest(id: SedimentreeId, digests: Digest[]): SyncMessage;
|
|
1507
|
+
/**
|
|
1508
|
+
* Create a [`SyncMessage::BlobsResponse`] message.
|
|
1509
|
+
*/
|
|
1510
|
+
static blobsResponse(id: SedimentreeId, blobs: Uint8Array[]): SyncMessage;
|
|
1511
|
+
/**
|
|
1512
|
+
* Deserialize a message from bytes.
|
|
1513
|
+
*
|
|
1514
|
+
* # Errors
|
|
1515
|
+
*
|
|
1516
|
+
* Returns a [`JsMessageDeserializationError`] if deserialization fails.
|
|
1517
|
+
*/
|
|
1518
|
+
static fromBytes(bytes: Uint8Array): SyncMessage;
|
|
1519
|
+
/**
|
|
1520
|
+
* Serialize the message to bytes.
|
|
1521
|
+
*/
|
|
1522
|
+
toBytes(): Uint8Array;
|
|
1523
|
+
/**
|
|
1524
|
+
* The [`Blob`] for commit or fragment messages, if applicable.
|
|
1525
|
+
*/
|
|
1526
|
+
readonly blob: Uint8Array | undefined;
|
|
1527
|
+
/**
|
|
1528
|
+
* The [`Blob`]s for a [`SyncMessage::BlobsResponse`], if applicable.
|
|
1529
|
+
*/
|
|
1530
|
+
readonly blobs: Uint8Array[] | undefined;
|
|
1531
|
+
/**
|
|
1532
|
+
* The [`LooseCommit`] for a [`SyncMessage::LooseCommit`], if applicable.
|
|
1533
|
+
*
|
|
1534
|
+
* Decodes the signed payload to extract the underlying commit.
|
|
1535
|
+
*/
|
|
1536
|
+
readonly commit: LooseCommit | undefined;
|
|
1537
|
+
/**
|
|
1538
|
+
* The requested [`Digest`]s for a [`SyncMessage::BlobsRequest`], if applicable.
|
|
1539
|
+
*/
|
|
1540
|
+
readonly digests: Digest[] | undefined;
|
|
1541
|
+
/**
|
|
1542
|
+
* The [`Fragment`] for a [`SyncMessage::Fragment`], if applicable.
|
|
1543
|
+
*
|
|
1544
|
+
* Decodes the signed payload to extract the underlying fragment.
|
|
1545
|
+
*/
|
|
1546
|
+
readonly fragment: Fragment | undefined;
|
|
1547
|
+
/**
|
|
1548
|
+
* The [`BatchSyncRequest`] for a [`SyncMessage::BatchSyncRequest`], if applicable.
|
|
1549
|
+
*/
|
|
1550
|
+
readonly request: BatchSyncRequest | undefined;
|
|
1551
|
+
/**
|
|
1552
|
+
* The [`BatchSyncResponse`] for a [`SyncMessage::BatchSyncResponse`], if applicable.
|
|
1553
|
+
*/
|
|
1554
|
+
readonly response: BatchSyncResponse | undefined;
|
|
1555
|
+
/**
|
|
1556
|
+
* The [`SedimentreeId`] associated with this message, if any.
|
|
1557
|
+
*/
|
|
1558
|
+
readonly sedimentreeId: SedimentreeId | undefined;
|
|
1559
|
+
/**
|
|
1560
|
+
* The message variant name.
|
|
1561
|
+
*/
|
|
1562
|
+
readonly type: string;
|
|
1563
|
+
}
|
|
1564
|
+
|
|
1565
|
+
/**
|
|
1566
|
+
* Statistics from a sync operation.
|
|
1567
|
+
*
|
|
1568
|
+
* The "sent" counts reflect items that were _successfully_ sent over the wire,
|
|
1569
|
+
* not just items that were requested.
|
|
1570
|
+
*/
|
|
1571
|
+
export class SyncStats {
|
|
1572
|
+
private constructor();
|
|
1573
|
+
free(): void;
|
|
1574
|
+
[Symbol.dispose](): void;
|
|
1575
|
+
/**
|
|
1576
|
+
* Number of commits received from the peer.
|
|
1577
|
+
*/
|
|
1578
|
+
readonly commitsReceived: number;
|
|
1579
|
+
/**
|
|
1580
|
+
* Number of commits successfully sent to the peer.
|
|
1581
|
+
*/
|
|
1582
|
+
readonly commitsSent: number;
|
|
1583
|
+
/**
|
|
1584
|
+
* Number of fragments received from the peer.
|
|
1585
|
+
*/
|
|
1586
|
+
readonly fragmentsReceived: number;
|
|
1587
|
+
/**
|
|
1588
|
+
* Number of fragments successfully sent to the peer.
|
|
1589
|
+
*/
|
|
1590
|
+
readonly fragmentsSent: number;
|
|
1591
|
+
/**
|
|
1592
|
+
* Returns true if no commits or fragments were transferred.
|
|
1593
|
+
*
|
|
1594
|
+
* Note: `remoteHeads` may still be non-empty (heads metadata is not
|
|
1595
|
+
* considered "data" for this check).
|
|
1596
|
+
*/
|
|
1597
|
+
readonly isEmpty: boolean;
|
|
1598
|
+
/**
|
|
1599
|
+
* The remote peer's heads for this sedimentree.
|
|
1600
|
+
*/
|
|
1601
|
+
readonly remoteHeads: Digest[];
|
|
1602
|
+
/**
|
|
1603
|
+
* Total items received (commits + fragments).
|
|
1604
|
+
*/
|
|
1605
|
+
readonly totalReceived: number;
|
|
1606
|
+
/**
|
|
1607
|
+
* Total items sent (commits + fragments).
|
|
1608
|
+
*/
|
|
1609
|
+
readonly totalSent: number;
|
|
1610
|
+
}
|
|
1611
|
+
|
|
1612
|
+
/**
|
|
1613
|
+
* A Wasm wrapper around the ephemeral [`Topic`] type.
|
|
1614
|
+
*
|
|
1615
|
+
* Topics are opaque 32-byte identifiers for ephemeral pubsub channels.
|
|
1616
|
+
* A [`SedimentreeId`] can be used as a topic, but topics are not
|
|
1617
|
+
* limited to sedimentrees.
|
|
1618
|
+
*
|
|
1619
|
+
* [`SedimentreeId`]: sedimentree_core::id::SedimentreeId
|
|
1620
|
+
*/
|
|
1621
|
+
export class Topic {
|
|
1622
|
+
private constructor();
|
|
1623
|
+
free(): void;
|
|
1624
|
+
[Symbol.dispose](): void;
|
|
1625
|
+
/**
|
|
1626
|
+
* Create a topic from a 32-byte array.
|
|
1627
|
+
*
|
|
1628
|
+
* # Errors
|
|
1629
|
+
*
|
|
1630
|
+
* Returns an error if the provided byte array is not exactly 32 bytes.
|
|
1631
|
+
*/
|
|
1632
|
+
static fromBytes(bytes: Uint8Array): Topic;
|
|
1633
|
+
/**
|
|
1634
|
+
* Returns the raw 32 bytes of this topic.
|
|
1635
|
+
*/
|
|
1636
|
+
toBytes(): Uint8Array;
|
|
1637
|
+
/**
|
|
1638
|
+
* Returns a shortened hex prefix representation (first 4 bytes + `…`).
|
|
1639
|
+
*/
|
|
1640
|
+
toString(): string;
|
|
1641
|
+
}
|
|
1642
|
+
|
|
1643
|
+
/**
|
|
1644
|
+
* An Ed25519 signer using the browser's `WebCrypto` API.
|
|
1645
|
+
*
|
|
1646
|
+
* This signer generates and stores Ed25519 keys using `crypto.subtle`,
|
|
1647
|
+
* providing secure key generation and signing operations. The key is
|
|
1648
|
+
* persisted to `IndexedDB` so it survives page reloads.
|
|
1649
|
+
*
|
|
1650
|
+
* # Example
|
|
1651
|
+
*
|
|
1652
|
+
* ```javascript
|
|
1653
|
+
* import { WebCryptoSigner } from "@anthropic/subduction";
|
|
1654
|
+
*
|
|
1655
|
+
* const signer = await WebCryptoSigner.setup();
|
|
1656
|
+
* console.log("Peer ID:", signer.peerId().toString());
|
|
1657
|
+
* ```
|
|
1658
|
+
*/
|
|
1659
|
+
export class WebCryptoSigner {
|
|
1660
|
+
private constructor();
|
|
1661
|
+
free(): void;
|
|
1662
|
+
[Symbol.dispose](): void;
|
|
1663
|
+
/**
|
|
1664
|
+
* Get the peer ID derived from this signer's verifying key.
|
|
1665
|
+
*
|
|
1666
|
+
* # Panics
|
|
1667
|
+
*
|
|
1668
|
+
* Panics if the stored public key bytes are invalid (should never happen).
|
|
1669
|
+
*/
|
|
1670
|
+
peerId(): PeerId;
|
|
1671
|
+
/**
|
|
1672
|
+
* Set up the signer, loading an existing key from `IndexedDB` or generating a new one.
|
|
1673
|
+
*
|
|
1674
|
+
* # Errors
|
|
1675
|
+
*
|
|
1676
|
+
* Returns an error if `WebCrypto` or `IndexedDB` operations fail.
|
|
1677
|
+
*/
|
|
1678
|
+
static setup(): Promise<WebCryptoSigner>;
|
|
1679
|
+
/**
|
|
1680
|
+
* Sign a message and return the 64-byte Ed25519 signature.
|
|
1681
|
+
*
|
|
1682
|
+
* # Errors
|
|
1683
|
+
*
|
|
1684
|
+
* Returns an error if `WebCrypto` signing fails.
|
|
1685
|
+
*/
|
|
1686
|
+
sign(message: Uint8Array): Promise<Uint8Array>;
|
|
1687
|
+
/**
|
|
1688
|
+
* Get the 32-byte Ed25519 verifying (public) key.
|
|
1689
|
+
*/
|
|
1690
|
+
verifyingKey(): Uint8Array;
|
|
1691
|
+
}
|
|
1692
|
+
|
|
1693
|
+
/**
|
|
1694
|
+
* Convenience factory — equivalent to `new MessagePortTransport(port)`.
|
|
1695
|
+
*/
|
|
1696
|
+
export function makeMessagePortTransport(port: any): MessagePortTransport;
|
|
1697
|
+
|
|
1698
|
+
/**
|
|
1699
|
+
* Entry point called when the Wasm module is instantiated.
|
|
1700
|
+
*
|
|
1701
|
+
* Only compiled when the `standalone` feature is active. Downstream cdylib
|
|
1702
|
+
* crates that define their own `#[wasm_bindgen(start)]` should depend on
|
|
1703
|
+
* `subduction_wasm` with `default-features = false` and call
|
|
1704
|
+
* [`set_panic_hook`] from their own start function.
|
|
1705
|
+
*/
|
|
1706
|
+
export function start(): void;
|