@siafoundation/sia-storage 0.0.14 → 0.1.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.
@@ -1,5 +1,14 @@
1
1
  /* auto-generated by NAPI-RS */
2
2
  /* eslint-disable */
3
+
4
+ /**
5
+ * Which binding artifact the generated loader actually loaded: `'native'` for
6
+ * a native addon, otherwise the `platformArchABI` of the WASI flavor. Every
7
+ * flavor napi-rs can build is listed, because `NAPI_RS_NATIVE_LIBRARY_PATH`
8
+ * can point the loader at a WASI artifact this package does not build itself.
9
+ */
10
+ export declare const __napiBindingTarget: 'native' | 'wasm32-wasi' | 'wasm32-wasip1'
11
+
3
12
  /**
4
13
  * An AppKey is used to sign requests to the indexer.
5
14
  *
@@ -38,8 +47,49 @@ export declare class Builder {
38
47
  responseUrl(): string
39
48
  /** Waits for the connection request to be approved. */
40
49
  waitForApproval(): Promise<void>
41
- /** Registers the application with the indexer using the provided mnemonic. */
50
+ /**
51
+ * Returns whether the connect key the user approved with already has an
52
+ * account for this application. Only valid after `waitForApproval` has
53
+ * resolved.
54
+ *
55
+ * The connect key may have accounts under more than one recovery phrase.
56
+ * Use `matchesExistingAppKey` to check a particular phrase.
57
+ */
58
+ reconnecting(): boolean
59
+ /**
60
+ * Returns whether `mnemonic` derives an application key that is already
61
+ * registered with the indexer. Unlike `register`, the builder remains
62
+ * usable. Only valid after `waitForApproval` has resolved.
63
+ */
64
+ matchesExistingAppKey(mnemonic: string): Promise<boolean>
65
+ /**
66
+ * Registers the application with the indexer using the provided mnemonic.
67
+ *
68
+ * A different recovery phrase registers a new application key even when
69
+ * `reconnecting()` is true.
70
+ */
42
71
  register(mnemonic: string): Promise<Sdk>
72
+ /**
73
+ * Connects using a pre-authorized key, bypassing the interactive approval
74
+ * flow, and returns the SDK directly. `preAuthorizedKey` is the 32-byte
75
+ * pre-authorized private key seed; `mnemonic` derives the application key.
76
+ */
77
+ connectPreAuthorized(preAuthorizedKey: Buffer, mnemonic: string): Promise<Sdk>
78
+ }
79
+
80
+ /**
81
+ * The indexer's record for a sharing key, including how many objects it grants
82
+ * access to and how much space they use.
83
+ */
84
+ export declare class KeyRecord {
85
+ /** The key this record describes. */
86
+ get key(): SharingKey
87
+ get description(): string
88
+ /**
89
+ * A snapshot of how many objects the key grants access to and how much
90
+ * space they use.
91
+ */
92
+ get stats(): KeyStats
43
93
  }
44
94
 
45
95
  /** An object event from the indexer. */
@@ -65,6 +115,8 @@ export declare class PackedUpload {
65
115
  length(): bigint
66
116
  /** Returns the number of slabs in the upload. */
67
117
  slabs(): bigint
118
+ /** Returns the optimal size of each slab in bytes. */
119
+ optimalDataSize(): bigint
68
120
  /**
69
121
  * Adds a new object to the upload. The data is read until EOF and packed into
70
122
  * the current slab. Returns the number of bytes consumed; call
@@ -120,6 +172,8 @@ export declare class PinnedObject {
120
172
  id(): string
121
173
  /** Returns the total size of the object. */
122
174
  size(): bigint
175
+ /** Returns a new object truncated to the requested length. */
176
+ truncate(length: bigint): PinnedObject
123
177
  /** Returns the total encoded size after erasure coding. */
124
178
  encodedSize(): bigint
125
179
  /** Returns the slabs that make up the object. */
@@ -135,6 +189,23 @@ export declare class PinnedObject {
135
189
  }
136
190
 
137
191
  export declare class Sdk {
192
+ /** Creates a sharing key. Attach objects to it with `Sdk.shareObject`. */
193
+ createSharingKey(description: string, expiresAt?: Date | undefined | null): Promise<SharingKey>
194
+ /** Lists the account's sharing keys, most recently created first. */
195
+ sharingKeys(offset: number, limit: number): Promise<Array<KeyRecord>>
196
+ /** Fetches the indexer's record for a key, including its counts. */
197
+ sharingKey(key: SharingKey): Promise<KeyRecord>
198
+ /**
199
+ * Attaches an object to a sharing key, re-sealing its encryption keys under
200
+ * the key so recipients can decrypt it.
201
+ */
202
+ shareObject(key: SharingKey, object: PinnedObject): Promise<void>
203
+ /** Lists and decrypts the objects attached to a sharing key. */
204
+ sharedObjects(key: SharingKey, offset: number, limit: number): Promise<Array<PinnedObject>>
205
+ /** Detaches an object from a sharing key. */
206
+ unshareObject(key: SharingKey, id: string): Promise<void>
207
+ /** Revokes a sharing key, deleting it and detaching all of its objects. */
208
+ revokeSharingKey(key: SharingKey): Promise<void>
138
209
  /** Returns the application key used by the SDK. */
139
210
  appKey(): AppKey
140
211
  /**
@@ -164,8 +235,8 @@ export declare class Sdk {
164
235
  * of the object's data.
165
236
  */
166
237
  download(object: PinnedObject, options?: DownloadOptions | undefined | null): ReadableStream
167
- /** Returns a list of all usable hosts. */
168
- hosts(): Promise<Array<Host>>
238
+ /** Returns a list of usable hosts, optionally filtered by a query. */
239
+ hosts(query?: HostQuery | undefined | null): Promise<Array<Host>>
169
240
  /** Returns object events from the indexer for syncing. */
170
241
  objectEvents(cursor: ObjectsCursor | undefined | null, limit: number): Promise<Array<ObjectEvent>>
171
242
  /** Updates the metadata of an object stored in the indexer. */
@@ -181,13 +252,58 @@ export declare class Sdk {
181
252
  /** Returns the current account. */
182
253
  account(): Promise<Account>
183
254
  /** Creates a signed URL for sharing an object. */
184
- shareObject(object: PinnedObject, validUntil: Date): string
255
+ objectShareUrl(object: PinnedObject, validUntil: Date): string
185
256
  /** Retrieves a shared object from a signed URL. */
186
- sharedObject(sharedUrl: string): Promise<PinnedObject>
257
+ objectFromShareUrl(sharedUrl: string): Promise<PinnedObject>
187
258
  /** Pins an object to the indexer. */
188
259
  pinObject(object: PinnedObject): Promise<void>
189
260
  }
190
261
 
262
+ /**
263
+ * A read-only SDK for the objects a sharing key grants access to.
264
+ *
265
+ * Unlike `Sdk`, it authenticates with a sharing key rather than an app key and
266
+ * cannot upload, pin, or delete. Downloads are paid for by the key's owner.
267
+ */
268
+ export declare class SharedSdk {
269
+ /**
270
+ * Connects to `indexer_url` as the recipient of the sharing key derived
271
+ * from `seed`, the 32-byte seed the key's owner handed out.
272
+ */
273
+ static connect(indexerUrl: string, seed: Buffer): Promise<SharedSdk>
274
+ /** Fetches the sharing key's stats from the indexer. */
275
+ stats(): Promise<KeyStats>
276
+ /** Fetches and decrypts one object the key grants access to. */
277
+ object(id: string): Promise<PinnedObject>
278
+ /** Lists and decrypts a page of the objects the key grants access to. */
279
+ objects(offset: number, limit: number): Promise<Array<PinnedObject>>
280
+ /**
281
+ * Returns the hosts serving this key's objects, optionally filtered by a
282
+ * query. Mirrors `Sdk.hosts()` but is scoped to the sharing key, so the
283
+ * set is already limited to hosts holding its objects.
284
+ */
285
+ hosts(query?: HostQuery | undefined | null): Promise<Array<Host>>
286
+ /** Streams a shared object's data, paying hosts with the owner's tokens. */
287
+ download(object: PinnedObject, options?: DownloadOptions | undefined | null): ReadableStream
288
+ }
289
+
290
+ /**
291
+ * A sharing key, granting read-only access to the objects attached to it.
292
+ *
293
+ * It is just the credential; the operations that use it live on `Sdk`.
294
+ */
295
+ export declare class SharingKey {
296
+ /** The key's public half, which identifies it on the indexer. */
297
+ get publicKey(): string
298
+ /**
299
+ * The 32-byte seed a recipient needs to read the key's objects. Pair it
300
+ * with the indexer url in `SharedSdk.connect`.
301
+ */
302
+ seed(): Buffer
303
+ /** Imports a sharing key from the 32-byte seed its owner handed out. */
304
+ static fromSeed(seed: Buffer): SharingKey
305
+ }
306
+
191
307
  /** An account registered on the indexer. */
192
308
  export interface Account {
193
309
  accountKey: string
@@ -203,7 +319,7 @@ export interface Account {
203
319
  /** The protocol used in a network address. */
204
320
  export declare const enum AddressProtocol {
205
321
  SiaMux = 'SiaMux',
206
- Quic = 'Quic'
322
+ Quic = 'Quic',
207
323
  }
208
324
 
209
325
  /** Application info. */
@@ -239,6 +355,12 @@ export declare function encodedSize(size: bigint, dataShards: number, parityShar
239
355
  /** Generates a new BIP-39 12-word recovery phrase. */
240
356
  export declare function generateRecoveryPhrase(): string
241
357
 
358
+ /** Geographic coordinates used to sort hosts by proximity. */
359
+ export interface GeoLocation {
360
+ latitude: number
361
+ longitude: number
362
+ }
363
+
242
364
  /** Information about a storage provider on the Sia network. */
243
365
  export interface Host {
244
366
  publicKey: string
@@ -249,6 +371,29 @@ export interface Host {
249
371
  goodForUpload: boolean
250
372
  }
251
373
 
374
+ /** Query parameters for filtering hosts. */
375
+ export interface HostQuery {
376
+ location?: GeoLocation
377
+ protocol?: AddressProtocol
378
+ country?: string
379
+ limit?: number
380
+ offset?: number
381
+ }
382
+
383
+ /**
384
+ * A snapshot of what a sharing key grants access to. The counts reflect the
385
+ * moment the record was fetched, not a live view.
386
+ */
387
+ export interface KeyStats {
388
+ objectCount: bigint
389
+ objectSize: bigint
390
+ pinnedData: bigint
391
+ pinnedSize: bigint
392
+ expiresAt?: Date
393
+ createdAt: Date
394
+ updatedAt: Date
395
+ }
396
+
252
397
  /** A network address of a storage provider on the Sia network. */
253
398
  export interface NetAddress {
254
399
  protocol: AddressProtocol
@@ -337,3 +482,12 @@ export interface UploadOptions {
337
482
  export declare function validateRecoveryPhrase(phrase: string): void
338
483
 
339
484
  export declare function initSia(): Promise<void>
485
+ export declare function detectPrivateRelay(): Promise<boolean>
486
+ /** Always false. Service worker streaming is for browser pages. */
487
+ export declare function enableStreaming(options?: { workerUrl?: string; scope?: string; type?: 'classic' | 'module' }): Promise<boolean>
488
+ /** For browser pages. In Node, `url` and `download` reject, and `sdk.download()` streams objects directly. */
489
+ export declare function openStreams(sdk: object, credentials: { indexerUrl: string; appMeta: AppMetadata } | { indexerUrl: string; seed: string }): {
490
+ url(object: PinnedObject, options: { name: string; type?: string }): Promise<never>
491
+ download(object: PinnedObject, options: { name: string; type?: string }): Promise<never>
492
+ close(): void
493
+ }
package/dist/next.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ declare function GET(): Response;
2
+
3
+ export { GET };