@siafoundation/sia-storage 0.0.8

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.
@@ -0,0 +1,592 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ /**
4
+ * The `ReadableStreamType` enum.
5
+ *
6
+ * *This API requires the following crate features to be activated: `ReadableStreamType`*
7
+ */
8
+
9
+ type ReadableStreamType = "bytes";
10
+
11
+ export interface DownloadOptions {
12
+ maxInflight?: number;
13
+ offset?: number;
14
+ length?: number;
15
+ onShardDownloaded?: (progress: ShardProgress) => void;
16
+ }
17
+
18
+
19
+
20
+ export interface SealedObject {
21
+ encryptedDataKey: string;
22
+ slabs: Slab[];
23
+ dataSignature: string;
24
+ encryptedMetadataKey?: string;
25
+ encryptedMetadata?: string;
26
+ metadataSignature: string;
27
+ createdAt: string;
28
+ updatedAt: string;
29
+ }
30
+
31
+
32
+
33
+ export interface Sector {
34
+ root: string;
35
+ hostKey: string;
36
+ }
37
+
38
+ export interface Slab {
39
+ encryptionKey: string;
40
+ minShards: number;
41
+ offset: number;
42
+ length: number;
43
+ sectors: Sector[];
44
+ }
45
+
46
+ export interface PinnedSlab {
47
+ id: string;
48
+ encryptionKey: string;
49
+ minShards: number;
50
+ sectors: Sector[];
51
+ }
52
+
53
+ export interface Host {
54
+ publicKey: string;
55
+ addresses: { protocol: string; address: string }[];
56
+ countryCode: string;
57
+ latitude: number;
58
+ longitude: number;
59
+ goodForUpload: boolean;
60
+ }
61
+
62
+
63
+
64
+ export interface UploadOptions {
65
+ dataShards?: number;
66
+ parityShards?: number;
67
+ maxInflight?: number;
68
+ onShardUploaded?: (progress: ShardProgress) => void;
69
+ }
70
+
71
+
72
+
73
+ interface Sdk {
74
+ download(object: PinnedObject, options?: DownloadOptions): ReadableStream;
75
+ upload(object: PinnedObject, source: ReadableStream, options?: UploadOptions): Promise<PinnedObject>;
76
+ uploadPacked(options?: UploadOptions): PackedUpload;
77
+ }
78
+
79
+
80
+ export interface Account {
81
+ accountKey: string;
82
+ maxPinnedData: number;
83
+ remainingStorage: number;
84
+ pinnedData: number;
85
+ pinnedSize: number;
86
+ ready: boolean;
87
+ app: App;
88
+ lastUsed: Date;
89
+ }
90
+
91
+ export interface App {
92
+ id: string;
93
+ name: string;
94
+ description: string;
95
+ logoUrl: string | undefined;
96
+ serviceUrl: string | undefined;
97
+ }
98
+
99
+ export interface AppMetadata {
100
+ appId: string;
101
+ name: string;
102
+ description: string;
103
+ serviceUrl: string;
104
+ logoUrl: string | undefined;
105
+ callbackUrl: string | undefined;
106
+ }
107
+
108
+ export interface HostQuery {
109
+ country: string | undefined;
110
+ limit: number | undefined;
111
+ offset: number | undefined;
112
+ }
113
+
114
+ export interface ObjectsCursor {
115
+ id: string;
116
+ after: Date;
117
+ }
118
+
119
+ export interface ShardProgress {
120
+ hostKey: string;
121
+ shardSize: number;
122
+ shardIndex: number;
123
+ slabIndex: number;
124
+ elapsedMs: number;
125
+ }
126
+
127
+ export type SealedObject = SealedObject;
128
+
129
+
130
+ /**
131
+ * An application key used for authentication with the indexer.
132
+ *
133
+ * AppKeys are derived from a BIP-39 recovery phrase during registration.
134
+ * They can be exported as a 32-byte seed and re-imported for future
135
+ * connections. The key must be stored securely — anyone with access
136
+ * can authenticate as the user.
137
+ */
138
+ export class AppKey {
139
+ free(): void;
140
+ [Symbol.dispose](): void;
141
+ /**
142
+ * Exports the AppKey as a 32-byte seed (Uint8Array).
143
+ */
144
+ export(): Uint8Array;
145
+ /**
146
+ * Imports an AppKey from a 32-byte seed (Uint8Array).
147
+ */
148
+ constructor(seed: Uint8Array);
149
+ /**
150
+ * Returns the ed25519 public key as a string (e.g. "ed25519:abc123...").
151
+ */
152
+ publicKey(): string;
153
+ /**
154
+ * Signs a message and returns the 64-byte ed25519 signature (Uint8Array).
155
+ */
156
+ sign(message: Uint8Array): Uint8Array;
157
+ /**
158
+ * Verifies a signature for a given message.
159
+ * Returns true if the signature is valid.
160
+ */
161
+ verifySignature(message: Uint8Array, signature: Uint8Array): boolean;
162
+ }
163
+
164
+ /**
165
+ * SDK Builder — handles the connection and registration flow with an indexer.
166
+ */
167
+ export class Builder {
168
+ free(): void;
169
+ [Symbol.dispose](): void;
170
+ /**
171
+ * Attempts to connect using an existing AppKey.
172
+ * Returns a Sdk if the key is valid, or undefined if not registered.
173
+ */
174
+ connected(app_key: AppKey): Promise<Sdk | undefined>;
175
+ constructor(indexer_url: string, app: AppMetadata);
176
+ /**
177
+ * Completes registration and returns a Sdk instance.
178
+ */
179
+ register(mnemonic: string): Promise<Sdk>;
180
+ /**
181
+ * Requests connection approval from the indexer.
182
+ */
183
+ requestConnection(): Promise<void>;
184
+ /**
185
+ * Returns the approval URL the user must visit.
186
+ */
187
+ responseUrl(): string;
188
+ /**
189
+ * Waits for the user to approve the connection request.
190
+ */
191
+ waitForApproval(): Promise<void>;
192
+ }
193
+
194
+ export class IntoUnderlyingByteSource {
195
+ private constructor();
196
+ free(): void;
197
+ [Symbol.dispose](): void;
198
+ cancel(): void;
199
+ pull(controller: ReadableByteStreamController): Promise<any>;
200
+ start(controller: ReadableByteStreamController): void;
201
+ readonly autoAllocateChunkSize: number;
202
+ readonly type: ReadableStreamType;
203
+ }
204
+
205
+ export class IntoUnderlyingSink {
206
+ private constructor();
207
+ free(): void;
208
+ [Symbol.dispose](): void;
209
+ abort(reason: any): Promise<any>;
210
+ close(): Promise<any>;
211
+ write(chunk: any): Promise<any>;
212
+ }
213
+
214
+ export class IntoUnderlyingSource {
215
+ private constructor();
216
+ free(): void;
217
+ [Symbol.dispose](): void;
218
+ cancel(): void;
219
+ pull(controller: ReadableStreamDefaultController): Promise<any>;
220
+ }
221
+
222
+ /**
223
+ * An object event from the indexer.
224
+ */
225
+ export class ObjectEvent {
226
+ private constructor();
227
+ free(): void;
228
+ [Symbol.dispose](): void;
229
+ readonly deleted: boolean;
230
+ readonly id: string;
231
+ /**
232
+ * Returns the object associated with this event, if it exists.
233
+ */
234
+ readonly object: PinnedObject | undefined;
235
+ /**
236
+ * Returns the time the event occurred.
237
+ */
238
+ readonly updatedAt: Date;
239
+ }
240
+
241
+ /**
242
+ * A packed upload handle for efficiently uploading multiple objects
243
+ * together. Objects are packed into shared slabs to avoid wasting storage.
244
+ *
245
+ * ```js
246
+ * const packed = sdk.uploadPacked();
247
+ * await packed.add(file1.stream());
248
+ * await packed.add(file2.stream());
249
+ * const objects = await packed.finalize();
250
+ * for (const obj of objects) await sdk.pinObject(obj);
251
+ * ```
252
+ */
253
+ export class PackedUpload {
254
+ private constructor();
255
+ free(): void;
256
+ [Symbol.dispose](): void;
257
+ /**
258
+ * Adds an object to the packed upload. Returns the number of bytes written.
259
+ *
260
+ * ```js
261
+ * const packed = sdk.uploadPacked();
262
+ * await packed.add(file.stream());
263
+ * await packed.add(blob.stream());
264
+ * ```
265
+ */
266
+ add(stream: ReadableStream): Promise<number>;
267
+ /**
268
+ * Cancels the packed upload. Immediately interrupts any in-flight `add`
269
+ * and aborts all pending slab uploads.
270
+ */
271
+ cancel(): void;
272
+ /**
273
+ * Finalizes the packed upload and returns the resulting objects.
274
+ * Each object must be pinned separately with `sdk.pinObject()`.
275
+ */
276
+ finalize(): Promise<PinnedObject[]>;
277
+ /**
278
+ * Total bytes added so far across all objects.
279
+ */
280
+ length(): number;
281
+ /**
282
+ * Bytes remaining until the current slab is full. Adding objects that
283
+ * fit within this size avoids starting a new slab and minimizes padding.
284
+ */
285
+ remaining(): number;
286
+ /**
287
+ * Optimal size of each slab in bytes.
288
+ */
289
+ slabSize(): number;
290
+ /**
291
+ * Number of slabs in the upload.
292
+ */
293
+ slabs(): number;
294
+ }
295
+
296
+ /**
297
+ * An object stored on the Sia network. JS holds this as an opaque handle
298
+ * and passes it back to Rust for operations like pin, download, share, and
299
+ * metadata updates. The internal state (encryption keys, slab data) cannot
300
+ * be serialized to JS.
301
+ */
302
+ export class PinnedObject {
303
+ free(): void;
304
+ [Symbol.dispose](): void;
305
+ /**
306
+ * Returns the creation time.
307
+ */
308
+ createdAt(): Date;
309
+ /**
310
+ * Returns the encoded (on-network) size after erasure coding.
311
+ */
312
+ encodedSize(): number;
313
+ /**
314
+ * Returns the object's ID as a hex string.
315
+ */
316
+ id(): string;
317
+ /**
318
+ * Returns the object's metadata as raw bytes.
319
+ */
320
+ metadata(): Uint8Array;
321
+ /**
322
+ * Creates a new empty object.
323
+ */
324
+ constructor();
325
+ /**
326
+ * Opens a previously sealed object.
327
+ */
328
+ static open(app_key: AppKey, sealed_obj: SealedObject): PinnedObject;
329
+ /**
330
+ * Seals the object for offline storage.
331
+ */
332
+ seal(app_key: AppKey): SealedObject;
333
+ /**
334
+ * Returns the total size of the object in bytes.
335
+ */
336
+ size(): number;
337
+ /**
338
+ * Returns the slabs that make up the object.
339
+ */
340
+ slabs(): Slab[];
341
+ /**
342
+ * Updates the object's metadata.
343
+ */
344
+ updateMetadata(metadata: Uint8Array): void;
345
+ /**
346
+ * Returns the last updated time.
347
+ */
348
+ updatedAt(): Date;
349
+ }
350
+
351
+ /**
352
+ * The main Sia storage SDK. Provides methods for uploading, downloading,
353
+ * and managing objects on the Sia storage network via an indexer.
354
+ */
355
+ export class Sdk {
356
+ private constructor();
357
+ free(): void;
358
+ [Symbol.dispose](): void;
359
+ /**
360
+ * Returns account information from the indexer.
361
+ */
362
+ account(): Promise<Account>;
363
+ /**
364
+ * Returns the AppKey used by this SDK instance.
365
+ */
366
+ appKey(): AppKey;
367
+ /**
368
+ * Deletes an object from the indexer by its hex ID.
369
+ */
370
+ deleteObject(key_hex: string): Promise<void>;
371
+ /**
372
+ * Downloads an object and returns a `ReadableStream` of `Uint8Array` chunks.
373
+ *
374
+ * ```js
375
+ * // as a blob
376
+ * const stream = sdk.download(obj);
377
+ * const blob = await new Response(stream).blob();
378
+ *
379
+ * // as a stream
380
+ * for await (const chunk of sdk.download(obj)) {
381
+ * console.log('got', chunk.length, 'bytes');
382
+ * }
383
+ * ```
384
+ */
385
+ download(object: PinnedObject, options?: any | null): ReadableStream;
386
+ /**
387
+ * Returns a list of usable hosts, optionally filtered by a HostQuery.
388
+ */
389
+ hosts(query?: HostQuery | null): Promise<Host[]>;
390
+ /**
391
+ * Retrieves an object from the indexer by its hex ID.
392
+ * Returns a `PinnedObject` handle for use with download, share, seal, etc.
393
+ */
394
+ object(key_hex: string): Promise<PinnedObject>;
395
+ /**
396
+ * Returns object events for syncing local state with the indexer.
397
+ */
398
+ objectEvents(cursor: ObjectsCursor | null | undefined, limit: number): Promise<ObjectEvent[]>;
399
+ /**
400
+ * Pins an object to the indexer so it persists beyond temporary storage.
401
+ */
402
+ pinObject(object: PinnedObject): Promise<void>;
403
+ /**
404
+ * Prunes unused slabs from the indexer.
405
+ */
406
+ pruneSlabs(): Promise<void>;
407
+ /**
408
+ * Generates a signed share URL for an object. Anyone with the URL can
409
+ * download and decrypt the object until `validUntil`.
410
+ */
411
+ shareObject(object: PinnedObject, valid_until: Date): string;
412
+ /**
413
+ * Resolves a share URL (sia://...) and returns the shared object.
414
+ * The encryption key is extracted from the URL fragment (never sent
415
+ * to the indexer).
416
+ */
417
+ sharedObject(share_url: string): Promise<PinnedObject>;
418
+ /**
419
+ * Retrieves a pinned slab from the indexer by its hex ID.
420
+ */
421
+ slab(slab_id: string): Promise<PinnedSlab>;
422
+ /**
423
+ * Updates an object's metadata on the indexer.
424
+ */
425
+ updateObjectMetadata(object: PinnedObject): Promise<void>;
426
+ /**
427
+ * Uploads data from a `ReadableStream` to the Sia network.
428
+ *
429
+ * Pass an existing `PinnedObject` to append new slabs to it, or `null`
430
+ * for a new upload. Appending changes the object's ID — the caller must
431
+ * re-pin and update any references to the old ID.
432
+ *
433
+ * ```js
434
+ * const obj = await sdk.upload(new PinnedObject(), file.stream());
435
+ * await sdk.pinObject(obj);
436
+ * ```
437
+ */
438
+ upload(object: PinnedObject, source: ReadableStream, options?: any | null): Promise<PinnedObject>;
439
+ /**
440
+ * Starts a packed upload for efficiently uploading multiple small objects.
441
+ * Objects smaller than the slab size (~40 MiB) are packed into shared slabs
442
+ * to avoid wasting storage. Call `add(data)` for each object, then
443
+ * `finalize()` to get the resulting `PinnedObject` handles.
444
+ */
445
+ uploadPacked(options?: any | null): PackedUpload;
446
+ }
447
+
448
+ /**
449
+ * Calculates the encoded size of data after erasure coding.
450
+ */
451
+ export function encodedSize(data_size: number, data_shards: number, parity_shards: number): number;
452
+
453
+ /**
454
+ * Generates a new BIP-39 12-word recovery phrase.
455
+ */
456
+ export function generateRecoveryPhrase(): string;
457
+
458
+ /**
459
+ * Set up panic hook and tokio runtime for browser use.
460
+ *
461
+ * Call `setLogger` to receive log messages.
462
+ */
463
+ export function init(): void;
464
+
465
+ /**
466
+ * Sets a logging callback to receive log messages from the SDK.
467
+ *
468
+ * The callback receives formatted log messages as strings.
469
+ * `level` should be one of: "off", "error", "warn", "info", "debug", "trace".
470
+ */
471
+ export function setLogger(callback: (message: string) => void, level: "off" | "error" | "warn" | "info" | "debug" | "trace"): void;
472
+
473
+ /**
474
+ * Validates a BIP-39 recovery phrase.
475
+ */
476
+ export function validateRecoveryPhrase(phrase: string): void;
477
+
478
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
479
+
480
+ export interface InitOutput {
481
+ readonly memory: WebAssembly.Memory;
482
+ readonly __wbg_packedupload_free: (a: number, b: number) => void;
483
+ readonly encodedSize: (a: number, b: number, c: number) => number;
484
+ readonly generateRecoveryPhrase: () => [number, number];
485
+ readonly init: () => void;
486
+ readonly packedupload_add: (a: number, b: any) => any;
487
+ readonly packedupload_cancel: (a: number) => void;
488
+ readonly packedupload_finalize: (a: number) => any;
489
+ readonly packedupload_length: (a: number) => number;
490
+ readonly packedupload_remaining: (a: number) => number;
491
+ readonly packedupload_slabSize: (a: number) => number;
492
+ readonly packedupload_slabs: (a: number) => number;
493
+ readonly validateRecoveryPhrase: (a: number, b: number) => [number, number];
494
+ readonly __wbg_appkey_free: (a: number, b: number) => void;
495
+ readonly __wbg_builder_free: (a: number, b: number) => void;
496
+ readonly __wbg_objectevent_free: (a: number, b: number) => void;
497
+ readonly __wbg_pinnedobject_free: (a: number, b: number) => void;
498
+ readonly __wbg_sdk_free: (a: number, b: number) => void;
499
+ readonly appkey_export: (a: number) => [number, number];
500
+ readonly appkey_new: (a: number, b: number) => [number, number, number];
501
+ readonly appkey_publicKey: (a: number) => [number, number];
502
+ readonly appkey_sign: (a: number, b: number, c: number) => [number, number];
503
+ readonly appkey_verifySignature: (a: number, b: number, c: number, d: number, e: number) => [number, number, number];
504
+ readonly builder_connected: (a: number, b: number) => any;
505
+ readonly builder_new: (a: number, b: number, c: any) => [number, number, number];
506
+ readonly builder_register: (a: number, b: number, c: number) => any;
507
+ readonly builder_requestConnection: (a: number) => any;
508
+ readonly builder_responseUrl: (a: number) => [number, number, number, number];
509
+ readonly builder_waitForApproval: (a: number) => any;
510
+ readonly objectevent_deleted: (a: number) => number;
511
+ readonly objectevent_id: (a: number) => [number, number];
512
+ readonly objectevent_object: (a: number) => number;
513
+ readonly objectevent_updatedAt: (a: number) => any;
514
+ readonly pinnedobject_createdAt: (a: number) => any;
515
+ readonly pinnedobject_encodedSize: (a: number) => number;
516
+ readonly pinnedobject_id: (a: number) => [number, number];
517
+ readonly pinnedobject_metadata: (a: number) => [number, number];
518
+ readonly pinnedobject_new: () => number;
519
+ readonly pinnedobject_open: (a: number, b: any) => [number, number, number];
520
+ readonly pinnedobject_seal: (a: number, b: number) => any;
521
+ readonly pinnedobject_size: (a: number) => number;
522
+ readonly pinnedobject_slabs: (a: number) => [number, number, number];
523
+ readonly pinnedobject_updateMetadata: (a: number, b: number, c: number) => void;
524
+ readonly pinnedobject_updatedAt: (a: number) => any;
525
+ readonly sdk_account: (a: number) => any;
526
+ readonly sdk_appKey: (a: number) => number;
527
+ readonly sdk_deleteObject: (a: number, b: number, c: number) => any;
528
+ readonly sdk_download: (a: number, b: number, c: number) => [number, number, number];
529
+ readonly sdk_hosts: (a: number, b: number) => any;
530
+ readonly sdk_object: (a: number, b: number, c: number) => any;
531
+ readonly sdk_objectEvents: (a: number, b: number, c: number) => any;
532
+ readonly sdk_pinObject: (a: number, b: number) => any;
533
+ readonly sdk_pruneSlabs: (a: number) => any;
534
+ readonly sdk_shareObject: (a: number, b: number, c: any) => [number, number, number, number];
535
+ readonly sdk_sharedObject: (a: number, b: number, c: number) => any;
536
+ readonly sdk_slab: (a: number, b: number, c: number) => any;
537
+ readonly sdk_updateObjectMetadata: (a: number, b: number) => any;
538
+ readonly sdk_upload: (a: number, b: number, c: any, d: number) => any;
539
+ readonly sdk_uploadPacked: (a: number, b: number) => [number, number, number];
540
+ readonly setLogger: (a: any, b: any) => void;
541
+ readonly __wbg_intounderlyingbytesource_free: (a: number, b: number) => void;
542
+ readonly intounderlyingbytesource_autoAllocateChunkSize: (a: number) => number;
543
+ readonly intounderlyingbytesource_cancel: (a: number) => void;
544
+ readonly intounderlyingbytesource_pull: (a: number, b: any) => any;
545
+ readonly intounderlyingbytesource_start: (a: number, b: any) => void;
546
+ readonly intounderlyingbytesource_type: (a: number) => number;
547
+ readonly __wbg_intounderlyingsink_free: (a: number, b: number) => void;
548
+ readonly intounderlyingsink_abort: (a: number, b: any) => any;
549
+ readonly intounderlyingsink_close: (a: number) => any;
550
+ readonly intounderlyingsink_write: (a: number, b: any) => any;
551
+ readonly __wbg_intounderlyingsource_free: (a: number, b: number) => void;
552
+ readonly intounderlyingsource_cancel: (a: number) => void;
553
+ readonly intounderlyingsource_pull: (a: number, b: any) => any;
554
+ readonly wasm_bindgen__convert__closures_____invoke__h0c753f5de41a6544: (a: number, b: number, c: any) => [number, number];
555
+ readonly wasm_bindgen__convert__closures_____invoke__h461ed1cf4779c6f2: (a: number, b: number, c: any) => [number, number];
556
+ readonly wasm_bindgen__convert__closures_____invoke__h461ed1cf4779c6f2_3: (a: number, b: number, c: any) => [number, number];
557
+ readonly wasm_bindgen__convert__closures_____invoke__h29f5bd75867abdc1: (a: number, b: number, c: any, d: any) => void;
558
+ readonly wasm_bindgen__convert__closures_____invoke__h3bdeb7de158ed318: (a: number, b: number, c: any) => void;
559
+ readonly wasm_bindgen__convert__closures_____invoke__hed868b385381c6ed: (a: number, b: number) => void;
560
+ readonly __wbindgen_malloc: (a: number, b: number) => number;
561
+ readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
562
+ readonly __wbindgen_exn_store: (a: number) => void;
563
+ readonly __externref_table_alloc: () => number;
564
+ readonly __wbindgen_externrefs: WebAssembly.Table;
565
+ readonly __wbindgen_free: (a: number, b: number, c: number) => void;
566
+ readonly __wbindgen_destroy_closure: (a: number, b: number) => void;
567
+ readonly __externref_drop_slice: (a: number, b: number) => void;
568
+ readonly __externref_table_dealloc: (a: number) => void;
569
+ readonly __wbindgen_start: () => void;
570
+ }
571
+
572
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
573
+
574
+ /**
575
+ * Instantiates the given `module`, which can either be bytes or
576
+ * a precompiled `WebAssembly.Module`.
577
+ *
578
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
579
+ *
580
+ * @returns {InitOutput}
581
+ */
582
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
583
+
584
+ /**
585
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
586
+ * for everything else, calls `WebAssembly.instantiate` directly.
587
+ *
588
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
589
+ *
590
+ * @returns {Promise<InitOutput>}
591
+ */
592
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;