@siafoundation/sia-storage 0.0.13 → 0.1.0

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.
@@ -17,25 +17,13 @@ export interface DownloadOptions {
17
17
 
18
18
 
19
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
20
  export interface Sector {
34
21
  root: string;
35
22
  hostKey: string;
36
23
  }
37
24
 
38
25
  export interface Slab {
26
+ version: number;
39
27
  encryptionKey: string;
40
28
  minShards: number;
41
29
  offset: number;
@@ -44,6 +32,7 @@ export interface Slab {
44
32
  }
45
33
 
46
34
  export interface PinnedSlab {
35
+ version: number;
47
36
  id: string;
48
37
  encryptionKey: string;
49
38
  minShards: number;
@@ -62,6 +51,14 @@ export interface Host {
62
51
 
63
52
 
64
53
  export interface UploadOptions {
54
+ dataShards?: number;
55
+ parityShards?: number;
56
+ maxBufferedSlabs?: number;
57
+ startOffset?: bigint;
58
+ onShardUploaded?: (progress: ShardProgress) => void;
59
+ }
60
+
61
+ export interface PackedUploadOptions {
65
62
  dataShards?: number;
66
63
  parityShards?: number;
67
64
  maxBufferedSlabs?: number;
@@ -73,7 +70,13 @@ export interface UploadOptions {
73
70
  interface Sdk {
74
71
  download(object: PinnedObject, options?: DownloadOptions): ReadableStream;
75
72
  upload(object: PinnedObject, source: ReadableStream, options?: UploadOptions): Promise<PinnedObject>;
76
- uploadPacked(options?: UploadOptions): PackedUpload;
73
+ uploadPacked(options?: PackedUploadOptions): PackedUpload;
74
+ }
75
+
76
+
77
+
78
+ interface SharedSdk {
79
+ download(object: PinnedObject, options?: DownloadOptions): ReadableStream;
77
80
  }
78
81
 
79
82
 
@@ -89,7 +92,7 @@ export interface App {
89
92
  }
90
93
 
91
94
  /**
92
- * Information about the user\'s account on the indexer.
95
+ * Information about the user's account on the indexer.
93
96
  */
94
97
  export interface Account {
95
98
  accountKey: string;
@@ -126,7 +129,7 @@ export interface HostQuery {
126
129
  }
127
130
 
128
131
  /**
129
- * TS interface for `Builder::new`\'s `app` parameter. Field names must
132
+ * TS interface for `Builder::new`'s `app` parameter. Field names must
130
133
  * match the Reflect reads in `helpers::make_app_metadata`.
131
134
  */
132
135
  export interface AppMetadata {
@@ -139,7 +142,7 @@ export interface AppMetadata {
139
142
  }
140
143
 
141
144
  /**
142
- * TS interface for `Sdk::objectEvents`\'s `cursor` parameter. Field
145
+ * TS interface for `Sdk::objectEvents`'s `cursor` parameter. Field
143
146
  * names must match the Reflect reads in `sdk.rs`.
144
147
  */
145
148
  export interface ObjectsCursor {
@@ -147,7 +150,30 @@ export interface ObjectsCursor {
147
150
  after: Date;
148
151
  }
149
152
 
150
- export type SealedObject = SealedObject;
153
+ /**
154
+ * What a recipient can see about the sharing key they hold. The counts are a
155
+ * snapshot, not a live view.
156
+ */
157
+ export interface KeyStats {
158
+ objectCount: number;
159
+ objectSize: number;
160
+ pinnedData: number;
161
+ pinnedSize: number;
162
+ expiresAt: Date | undefined;
163
+ createdAt: Date;
164
+ updatedAt: Date;
165
+ }
166
+
167
+ export type SealedObject = {
168
+ encryptedDataKey: string;
169
+ slabs: Slab[];
170
+ dataSignature: string;
171
+ encryptedMetadataKey?: string;
172
+ encryptedMetadata?: string;
173
+ metadataSignature: string;
174
+ createdAt: string;
175
+ updatedAt: string;
176
+ };
151
177
 
152
178
 
153
179
  /**
@@ -190,14 +216,38 @@ export class AppKey {
190
216
  export class Builder {
191
217
  free(): void;
192
218
  [Symbol.dispose](): void;
219
+ /**
220
+ * Connects using a pre-authorized key, bypassing the interactive approval
221
+ * flow, and returns a Sdk. `preAuthorizedKeySeed` is the 32-byte
222
+ * pre-authorized private key (Uint8Array); `mnemonic` derives the app key.
223
+ */
224
+ connectPreAuthorized(pre_authorized_key_seed: Uint8Array, mnemonic: string): Promise<Sdk>;
193
225
  /**
194
226
  * Attempts to connect using an existing AppKey.
195
227
  * Returns a Sdk if the key is valid, or undefined if not registered.
196
228
  */
197
229
  connected(app_key: AppKey): Promise<Sdk | undefined>;
230
+ /**
231
+ * Returns whether `mnemonic` derives an application key that is already
232
+ * registered with the indexer. Unlike `register`, the builder remains
233
+ * usable. Only valid after `waitForApproval` has resolved.
234
+ */
235
+ matchesExistingAppKey(mnemonic: string): Promise<boolean>;
198
236
  constructor(indexer_url: string, app: AppMetadata);
237
+ /**
238
+ * Returns whether the connect key the user approved with already has an
239
+ * account for this application. Only valid after `waitForApproval` has
240
+ * resolved.
241
+ *
242
+ * The connect key may have accounts under more than one recovery phrase.
243
+ * Use `matchesExistingAppKey` to check a particular phrase.
244
+ */
245
+ reconnecting(): boolean;
199
246
  /**
200
247
  * Completes registration and returns a Sdk instance.
248
+ *
249
+ * A different recovery phrase registers a new application key even when
250
+ * `reconnecting()` is true.
201
251
  */
202
252
  register(mnemonic: string): Promise<Sdk>;
203
253
  /**
@@ -242,6 +292,27 @@ export class IntoUnderlyingSource {
242
292
  pull(controller: ReadableStreamDefaultController): Promise<any>;
243
293
  }
244
294
 
295
+ /**
296
+ * The indexer's record for a sharing key, including how many objects it grants
297
+ * access to and how much space they use. The counts are a snapshot, not a live
298
+ * view.
299
+ */
300
+ export class KeyRecord {
301
+ private constructor();
302
+ free(): void;
303
+ [Symbol.dispose](): void;
304
+ readonly description: string;
305
+ /**
306
+ * The key this record describes.
307
+ */
308
+ readonly key: SharingKey;
309
+ /**
310
+ * A snapshot of how many objects the key grants access to and how much
311
+ * space they use.
312
+ */
313
+ readonly stats: KeyStats;
314
+ }
315
+
245
316
  /**
246
317
  * An object event from the indexer.
247
318
  */
@@ -285,7 +356,9 @@ export class PackedUpload {
285
356
  *
286
357
  * If the reader errors part-way, it's safe to continue calling
287
358
  * [add](Self::add); no object is registered for the failed call. Or call
288
- * [finalize](Self::finalize) to collect the objects added so far.
359
+ * [finalize](Self::finalize) to collect the objects added so far. Bytes
360
+ * read before the error remain in the current slab as padding and stay
361
+ * counted in [length](Self::length) and [remaining](Self::remaining).
289
362
  *
290
363
  * ```js
291
364
  * const packed = sdk.uploadPacked();
@@ -369,6 +442,10 @@ export class PinnedObject {
369
442
  * Returns the slabs that make up the object.
370
443
  */
371
444
  slabs(): Slab[];
445
+ /**
446
+ * Returns a new object truncated to the requested length.
447
+ */
448
+ truncate(length: bigint): PinnedObject;
372
449
  /**
373
450
  * Updates the object's metadata.
374
451
  */
@@ -395,6 +472,10 @@ export class Sdk {
395
472
  * Returns the AppKey used by this SDK instance.
396
473
  */
397
474
  appKey(): AppKey;
475
+ /**
476
+ * Creates a sharing key. Attach objects to it with `Sdk.shareObject`.
477
+ */
478
+ createSharingKey(description: string, expires_at?: Date | null): Promise<SharingKey>;
398
479
  /**
399
480
  * Deletes an object from the indexer by its hex ID.
400
481
  */
@@ -427,6 +508,17 @@ export class Sdk {
427
508
  * Returns object events for syncing local state with the indexer.
428
509
  */
429
510
  objectEvents(cursor: ObjectsCursor | null | undefined, limit: number): Promise<ObjectEvent[]>;
511
+ /**
512
+ * Resolves a share URL (sia://...) and returns the shared object.
513
+ * The encryption key is extracted from the URL fragment (never sent
514
+ * to the indexer).
515
+ */
516
+ objectFromShareUrl(share_url: string): Promise<PinnedObject>;
517
+ /**
518
+ * Generates a signed share URL for an object. Anyone with the URL can
519
+ * download and decrypt the object until `validUntil`.
520
+ */
521
+ objectShareUrl(object: PinnedObject, valid_until: Date): string;
430
522
  /**
431
523
  * Pins an object to the indexer so it persists beyond temporary storage.
432
524
  */
@@ -436,20 +528,38 @@ export class Sdk {
436
528
  */
437
529
  pruneSlabs(): Promise<void>;
438
530
  /**
439
- * Generates a signed share URL for an object. Anyone with the URL can
440
- * download and decrypt the object until `validUntil`.
531
+ * Deletes a sharing key along with all of its attachments, revoking
532
+ * recipients' access. Account tokens already issued stay valid until they
533
+ * expire, so a download in flight can keep reading for up to five minutes.
441
534
  */
442
- shareObject(object: PinnedObject, valid_until: Date): string;
535
+ revokeSharingKey(key: SharingKey): Promise<void>;
443
536
  /**
444
- * Resolves a share URL (sia://...) and returns the shared object.
445
- * The encryption key is extracted from the URL fragment (never sent
446
- * to the indexer).
537
+ * Attaches an object to a sharing key, re-sealing its encryption keys under
538
+ * the key so recipients can decrypt it. Attaching an already-attached
539
+ * object replaces its re-sealed keys, so a failed call can be retried.
540
+ */
541
+ shareObject(key: SharingKey, object: PinnedObject): Promise<void>;
542
+ /**
543
+ * Lists and decrypts a page of the objects a sharing key grants access to.
544
+ */
545
+ sharedObjects(key: SharingKey, offset: number, limit: number): Promise<PinnedObject[]>;
546
+ /**
547
+ * Fetches the indexer's record for a key, including its counts.
548
+ */
549
+ sharingKey(key: SharingKey): Promise<KeyRecord>;
550
+ /**
551
+ * Lists the account's sharing keys, most recently created first.
447
552
  */
448
- sharedObject(share_url: string): Promise<PinnedObject>;
553
+ sharingKeys(offset: number, limit: number): Promise<KeyRecord[]>;
449
554
  /**
450
555
  * Retrieves a pinned slab from the indexer by its hex ID.
451
556
  */
452
557
  slab(slab_id: string): Promise<PinnedSlab>;
558
+ /**
559
+ * Detaches an object from a sharing key, leaving the key and its other
560
+ * attachments in place.
561
+ */
562
+ unshareObject(key: SharingKey, object: PinnedObject): Promise<void>;
453
563
  /**
454
564
  * Updates an object's metadata on the indexer.
455
565
  */
@@ -476,6 +586,73 @@ export class Sdk {
476
586
  uploadPacked(options?: any | null): PackedUpload;
477
587
  }
478
588
 
589
+ /**
590
+ * A read-only SDK for the objects a sharing key grants access to.
591
+ *
592
+ * Unlike `Sdk`, it authenticates with a sharing key rather than an app key and
593
+ * cannot upload, pin, or delete. Downloads are paid for by the key's owner.
594
+ */
595
+ export class SharedSdk {
596
+ private constructor();
597
+ free(): void;
598
+ [Symbol.dispose](): void;
599
+ /**
600
+ * Connects to `indexerUrl` as the recipient of the sharing key derived
601
+ * from `seed`, which is the hex string the key's owner handed out.
602
+ */
603
+ static connect(indexer_url: string, seed: string): Promise<SharedSdk>;
604
+ /**
605
+ * Streams a shared object's data.
606
+ */
607
+ download(object: PinnedObject, options?: any | null): ReadableStream;
608
+ /**
609
+ * Returns the hosts serving this key's objects, optionally filtered by a
610
+ * HostQuery. Mirrors `Sdk.hosts()` but is scoped to the sharing key, so the
611
+ * set is already limited to hosts holding its objects.
612
+ */
613
+ hosts(query?: HostQuery | null): Promise<Host[]>;
614
+ /**
615
+ * Fetches and decrypts one object the key grants access to.
616
+ */
617
+ object(id: string): Promise<PinnedObject>;
618
+ /**
619
+ * Lists and decrypts a page of the objects the key grants access to.
620
+ */
621
+ objects(offset: number, limit: number): Promise<PinnedObject[]>;
622
+ /**
623
+ * Fetches the sharing key's stats from the indexer.
624
+ */
625
+ stats(): Promise<KeyStats>;
626
+ }
627
+
628
+ /**
629
+ * A sharing key, granting read-only access to the objects attached to it.
630
+ *
631
+ * It is just the credential; the operations that use it live on `Sdk`.
632
+ */
633
+ export class SharingKey {
634
+ private constructor();
635
+ free(): void;
636
+ [Symbol.dispose](): void;
637
+ /**
638
+ * Imports a sharing key from the hex seed its owner handed out.
639
+ *
640
+ * Pass the string returned by [seed](Self::seed).
641
+ */
642
+ static fromSeed(seed: string): SharingKey;
643
+ /**
644
+ * Returns the seed a recipient needs to read the key's objects, as hex.
645
+ *
646
+ * It is the whole credential. Pair it with the indexer's url in
647
+ * `SharedSdk.connect`.
648
+ */
649
+ seed(): string;
650
+ /**
651
+ * The key's public half, which identifies it.
652
+ */
653
+ readonly publicKey: string;
654
+ }
655
+
479
656
  /**
480
657
  * Calculates the encoded size of data after erasure coding.
481
658
  */
@@ -512,17 +689,22 @@ export interface InitOutput {
512
689
  readonly memory: WebAssembly.Memory;
513
690
  readonly __wbg_appkey_free: (a: number, b: number) => void;
514
691
  readonly __wbg_builder_free: (a: number, b: number) => void;
692
+ readonly __wbg_keyrecord_free: (a: number, b: number) => void;
515
693
  readonly __wbg_objectevent_free: (a: number, b: number) => void;
516
694
  readonly __wbg_packedupload_free: (a: number, b: number) => void;
517
695
  readonly __wbg_pinnedobject_free: (a: number, b: number) => void;
518
696
  readonly __wbg_sdk_free: (a: number, b: number) => void;
697
+ readonly __wbg_sharedsdk_free: (a: number, b: number) => void;
519
698
  readonly appkey_export: (a: number) => [number, number];
520
699
  readonly appkey_new: (a: number, b: number) => [number, number, number];
521
700
  readonly appkey_publicKey: (a: number) => [number, number];
522
701
  readonly appkey_sign: (a: number, b: number, c: number) => [number, number];
523
702
  readonly appkey_verifySignature: (a: number, b: number, c: number, d: number, e: number) => [number, number, number];
703
+ readonly builder_connectPreAuthorized: (a: number, b: number, c: number, d: number, e: number) => any;
524
704
  readonly builder_connected: (a: number, b: number) => any;
705
+ readonly builder_matchesExistingAppKey: (a: number, b: number, c: number) => any;
525
706
  readonly builder_new: (a: number, b: number, c: any) => [number, number, number];
707
+ readonly builder_reconnecting: (a: number) => [number, number, number];
526
708
  readonly builder_register: (a: number, b: number, c: number) => any;
527
709
  readonly builder_requestConnection: (a: number) => any;
528
710
  readonly builder_responseUrl: (a: number) => [number, number, number, number];
@@ -530,6 +712,9 @@ export interface InitOutput {
530
712
  readonly encodedSize: (a: number, b: number, c: number) => number;
531
713
  readonly generateRecoveryPhrase: () => [number, number];
532
714
  readonly init: () => void;
715
+ readonly keyrecord_description: (a: number) => [number, number];
716
+ readonly keyrecord_key: (a: number) => number;
717
+ readonly keyrecord_stats: (a: number) => [number, number, number];
533
718
  readonly objectevent_deleted: (a: number) => number;
534
719
  readonly objectevent_id: (a: number) => [number, number];
535
720
  readonly objectevent_object: (a: number) => number;
@@ -547,28 +732,46 @@ export interface InitOutput {
547
732
  readonly pinnedobject_metadata: (a: number) => [number, number];
548
733
  readonly pinnedobject_new: () => number;
549
734
  readonly pinnedobject_open: (a: number, b: any) => [number, number, number];
550
- readonly pinnedobject_seal: (a: number, b: number) => any;
735
+ readonly pinnedobject_seal: (a: number, b: number) => [number, number, number];
551
736
  readonly pinnedobject_size: (a: number) => number;
552
737
  readonly pinnedobject_slabs: (a: number) => [number, number, number];
738
+ readonly pinnedobject_truncate: (a: number, b: bigint) => number;
553
739
  readonly pinnedobject_updateMetadata: (a: number, b: number, c: number) => void;
554
740
  readonly pinnedobject_updatedAt: (a: number) => any;
555
741
  readonly sdk_account: (a: number) => any;
556
742
  readonly sdk_appKey: (a: number) => number;
743
+ readonly sdk_createSharingKey: (a: number, b: number, c: number, d: number) => any;
557
744
  readonly sdk_deleteObject: (a: number, b: number, c: number) => any;
558
745
  readonly sdk_download: (a: number, b: number, c: number) => [number, number, number];
559
746
  readonly sdk_hosts: (a: number, b: number) => any;
560
747
  readonly sdk_object: (a: number, b: number, c: number) => any;
561
748
  readonly sdk_objectEvents: (a: number, b: any, c: number) => any;
749
+ readonly sdk_objectFromShareUrl: (a: number, b: number, c: number) => any;
750
+ readonly sdk_objectShareUrl: (a: number, b: number, c: any) => [number, number, number, number];
562
751
  readonly sdk_pinObject: (a: number, b: number) => any;
563
752
  readonly sdk_pruneSlabs: (a: number) => any;
564
- readonly sdk_shareObject: (a: number, b: number, c: any) => [number, number, number, number];
565
- readonly sdk_sharedObject: (a: number, b: number, c: number) => any;
753
+ readonly sdk_revokeSharingKey: (a: number, b: number) => any;
754
+ readonly sdk_shareObject: (a: number, b: number, c: number) => any;
755
+ readonly sdk_sharedObjects: (a: number, b: number, c: number, d: number) => any;
756
+ readonly sdk_sharingKey: (a: number, b: number) => any;
757
+ readonly sdk_sharingKeys: (a: number, b: number, c: number) => any;
566
758
  readonly sdk_slab: (a: number, b: number, c: number) => any;
759
+ readonly sdk_unshareObject: (a: number, b: number, c: number) => any;
567
760
  readonly sdk_updateObjectMetadata: (a: number, b: number) => any;
568
761
  readonly sdk_upload: (a: number, b: number, c: any, d: number) => any;
569
762
  readonly sdk_uploadPacked: (a: number, b: number) => [number, number, number];
570
763
  readonly setLogger: (a: any, b: any) => void;
764
+ readonly sharedsdk_connect: (a: number, b: number, c: number, d: number) => any;
765
+ readonly sharedsdk_download: (a: number, b: number, c: number) => [number, number, number];
766
+ readonly sharedsdk_hosts: (a: number, b: number) => any;
767
+ readonly sharedsdk_object: (a: number, b: number, c: number) => any;
768
+ readonly sharedsdk_objects: (a: number, b: number, c: number) => any;
769
+ readonly sharedsdk_stats: (a: number) => any;
770
+ readonly sharingkey_fromSeed: (a: number, b: number) => [number, number, number];
771
+ readonly sharingkey_publicKey: (a: number) => [number, number];
772
+ readonly sharingkey_seed: (a: number) => [number, number];
571
773
  readonly validateRecoveryPhrase: (a: number, b: number) => [number, number];
774
+ readonly __wbg_sharingkey_free: (a: number, b: number) => void;
572
775
  readonly __wbg_intounderlyingbytesource_free: (a: number, b: number) => void;
573
776
  readonly __wbg_intounderlyingsink_free: (a: number, b: number) => void;
574
777
  readonly __wbg_intounderlyingsource_free: (a: number, b: number) => void;
@@ -582,13 +785,13 @@ export interface InitOutput {
582
785
  readonly intounderlyingsink_write: (a: number, b: any) => any;
583
786
  readonly intounderlyingsource_cancel: (a: number) => void;
584
787
  readonly intounderlyingsource_pull: (a: number, b: any) => any;
585
- readonly wasm_bindgen__convert__closures_____invoke__h466a94b78425b78b: (a: number, b: number, c: any) => [number, number];
586
- readonly wasm_bindgen__convert__closures_____invoke__hbf67b82a37e25b93: (a: number, b: number, c: any) => [number, number];
587
- readonly wasm_bindgen__convert__closures_____invoke__h466a94b78425b78b_3: (a: number, b: number, c: any) => [number, number];
588
- readonly wasm_bindgen__convert__closures_____invoke__h466a94b78425b78b_4: (a: number, b: number, c: any) => [number, number];
589
- readonly wasm_bindgen__convert__closures_____invoke__h4815d933c518c891: (a: number, b: number, c: any, d: any) => void;
590
- readonly wasm_bindgen__convert__closures_____invoke__h2aaa2940e06cecaf: (a: number, b: number, c: any) => void;
591
- readonly wasm_bindgen__convert__closures_____invoke__hfcaa223eea581645: (a: number, b: number) => void;
788
+ readonly wasm_bindgen_baa1b51bcdcd1a91___convert__closures_____invoke___wasm_bindgen_baa1b51bcdcd1a91___JsValue__core_ed718c3d60ebd546___result__Result_____wasm_bindgen_baa1b51bcdcd1a91___JsError___true_: (a: number, b: number, c: any) => [number, number];
789
+ readonly wasm_bindgen_baa1b51bcdcd1a91___convert__closures_____invoke___wasm_bindgen_baa1b51bcdcd1a91___sys__Undefined__core_ed718c3d60ebd546___result__Result_____wasm_bindgen_baa1b51bcdcd1a91___JsError___true_: (a: number, b: number, c: any) => [number, number];
790
+ readonly wasm_bindgen_baa1b51bcdcd1a91___convert__closures_____invoke___wasm_bindgen_baa1b51bcdcd1a91___sys__Undefined__core_ed718c3d60ebd546___result__Result_____wasm_bindgen_baa1b51bcdcd1a91___JsError___true__3: (a: number, b: number, c: any) => [number, number];
791
+ readonly wasm_bindgen_baa1b51bcdcd1a91___convert__closures_____invoke___wasm_bindgen_baa1b51bcdcd1a91___sys__Undefined__core_ed718c3d60ebd546___result__Result_____wasm_bindgen_baa1b51bcdcd1a91___JsError___true__4: (a: number, b: number, c: any) => [number, number];
792
+ readonly wasm_bindgen_baa1b51bcdcd1a91___convert__closures_____invoke___js_sys_bdd470c3fe1f6d69___Function_fn_wasm_bindgen_baa1b51bcdcd1a91___JsValue_____wasm_bindgen_baa1b51bcdcd1a91___sys__Undefined___js_sys_bdd470c3fe1f6d69___Function_fn_wasm_bindgen_baa1b51bcdcd1a91___JsValue_____wasm_bindgen_baa1b51bcdcd1a91___sys__Undefined_______true_: (a: number, b: number, c: any, d: any) => void;
793
+ readonly wasm_bindgen_baa1b51bcdcd1a91___convert__closures_____invoke___wasm_bindgen_baa1b51bcdcd1a91___JsValue______true_: (a: number, b: number, c: any) => void;
794
+ readonly wasm_bindgen_baa1b51bcdcd1a91___convert__closures_____invoke_______true_: (a: number, b: number) => void;
592
795
  readonly __wbindgen_malloc: (a: number, b: number) => number;
593
796
  readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
594
797
  readonly __wbindgen_exn_store: (a: number) => void;