@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.
- package/README.md +39 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/dist/index.node.cjs +9 -0
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.d.ts +169 -6
- package/package.json +8 -7
- package/wasm/sia_storage_wasm.d.ts +239 -36
- package/wasm/sia_storage_wasm.js +602 -237
- package/wasm/sia_storage_wasm_bg.wasm +0 -0
- package/wasm/sia_storage_wasm_bg.wasm.d.ts +36 -10
package/README.md
CHANGED
|
@@ -113,6 +113,9 @@ Near-identical surfaces. Real differences:
|
|
|
113
113
|
|
|
114
114
|
- App identifier: `appMeta.appId: string (hex)` on browser, `appMeta.id: Buffer(32)` on Node.
|
|
115
115
|
- Numeric sizes are `number` on browser, `bigint` on Node. Byte arrays are `Uint8Array` on browser, `Buffer` on Node (`Buffer` is a `Uint8Array` subclass; both accept either as input).
|
|
116
|
+
- Sharing key seeds are hex `string` on browser, `Buffer` on Node. This covers `SharingKey.seed()`, `SharingKey.fromSeed(seed)`, and `SharedSdk.connect(indexerUrl, seed)`.
|
|
117
|
+
- `sdk.unshareObject(key, object)` takes a `PinnedObject` on browser and an object id `string` on Node.
|
|
118
|
+
- `sdk.hosts(query?)` and `sharedSdk.hosts(query?)` accept a `HostQuery` on browser; on Node they take no arguments.
|
|
116
119
|
|
|
117
120
|
## API
|
|
118
121
|
|
|
@@ -128,7 +131,7 @@ Near-identical surfaces. Real differences:
|
|
|
128
131
|
|
|
129
132
|
### `Sdk`
|
|
130
133
|
|
|
131
|
-
Returned from `Builder.register()` or `Builder.
|
|
134
|
+
Returned from `Builder.register()`, `Builder.connected()`, or `Builder.connectPreAuthorized()`.
|
|
132
135
|
|
|
133
136
|
| | |
|
|
134
137
|
|---|---|
|
|
@@ -138,9 +141,14 @@ Returned from `Builder.register()` or `Builder.connected()`.
|
|
|
138
141
|
| `uploadPacked(options?)` | `PackedUpload` for batching small files into shared slabs. |
|
|
139
142
|
| `object(key)` / `deleteObject(key)` / `pinObject(object)` | Object CRUD. |
|
|
140
143
|
| `updateObjectMetadata(object)` | Push local metadata changes to the indexer. |
|
|
141
|
-
| `
|
|
144
|
+
| `objectShareUrl(object, validUntil)` / `objectFromShareUrl(url)` | Create / consume share URLs. |
|
|
142
145
|
| `objectEvents(cursor?, limit)` | Paginated change feed. |
|
|
143
|
-
| `hosts()` / `slab(id)` / `account()` / `pruneSlabs()` | Indexer reads. |
|
|
146
|
+
| `hosts(query?)` / `slab(id)` / `account()` / `pruneSlabs()` | Indexer reads. |
|
|
147
|
+
| `createSharingKey(description, expiresAt?)` | Create a `SharingKey` for read-only sharing. |
|
|
148
|
+
| `sharingKeys(offset, limit)` / `sharingKey(key)` | List keys / fetch one key's `KeyRecord`. |
|
|
149
|
+
| `shareObject(key, object)` / `unshareObject(key, object)` | Attach / detach an object on a sharing key. |
|
|
150
|
+
| `sharedObjects(key, offset, limit)` | Objects attached to a sharing key. |
|
|
151
|
+
| `revokeSharingKey(key)` | Delete the key and detach all of its objects. |
|
|
144
152
|
|
|
145
153
|
### `Builder`
|
|
146
154
|
|
|
@@ -153,6 +161,9 @@ Returned from `Builder.register()` or `Builder.connected()`.
|
|
|
153
161
|
| `waitForApproval()` | Resolves once the user approves. |
|
|
154
162
|
| `register(phrase)` | Finish onboarding with a new recovery phrase → `Sdk`. |
|
|
155
163
|
| `connected(appKey)` | Reconnect with a saved `AppKey` → `Sdk \| null`. |
|
|
164
|
+
| `reconnecting()` | Whether the approved connect key already has an account. |
|
|
165
|
+
| `matchesExistingAppKey(phrase)` | Whether a phrase derives an already-registered app key. |
|
|
166
|
+
| `connectPreAuthorized(seed, phrase)` | Skip the approval flow with a pre-authorized key's 32-byte seed → `Sdk`. |
|
|
156
167
|
|
|
157
168
|
### `AppKey`
|
|
158
169
|
|
|
@@ -164,7 +175,7 @@ Returned from `Builder.register()` or `Builder.connected()`.
|
|
|
164
175
|
|
|
165
176
|
`new PinnedObject()` for new uploads, or `sdk.object(key)`.
|
|
166
177
|
|
|
167
|
-
`id()` · `size()` · `encodedSize()` · `slabs()` · `metadata()` · `updateMetadata(bytes)` · `createdAt()` · `updatedAt()` · `seal(appKey)` · `PinnedObject.open(appKey, sealed)`
|
|
178
|
+
`id()` · `size()` · `encodedSize()` · `slabs()` · `metadata()` · `updateMetadata(bytes)` · `truncate(length: bigint)` · `createdAt()` · `updatedAt()` · `seal(appKey)` · `PinnedObject.open(appKey, sealed)`
|
|
168
179
|
|
|
169
180
|
### `PackedUpload`
|
|
170
181
|
|
|
@@ -172,6 +183,30 @@ From `sdk.uploadPacked()`.
|
|
|
172
183
|
|
|
173
184
|
`add(stream)` · `finalize()` · `cancel()` · `remaining()` · `length()` · `slabs()`
|
|
174
185
|
|
|
186
|
+
### `SharingKey`
|
|
187
|
+
|
|
188
|
+
From `sdk.createSharingKey()`, or `SharingKey.fromSeed(seed)` to import one.
|
|
189
|
+
|
|
190
|
+
`publicKey` · `seed()` · `SharingKey.fromSeed(seed)`
|
|
191
|
+
|
|
192
|
+
### `KeyRecord`
|
|
193
|
+
|
|
194
|
+
The indexer's record for a sharing key, from `sdk.sharingKey()` or `sdk.sharingKeys()`.
|
|
195
|
+
|
|
196
|
+
`key` · `description` · `stats`
|
|
197
|
+
|
|
198
|
+
### `SharedSdk`
|
|
199
|
+
|
|
200
|
+
`SharedSdk.connect(indexerUrl, seed)` — read-only access for a recipient holding a
|
|
201
|
+
sharing key's seed. Downloads are paid for by the key's owner.
|
|
202
|
+
|
|
203
|
+
| | |
|
|
204
|
+
|---|---|
|
|
205
|
+
| `stats()` | The key's `KeyStats` snapshot. |
|
|
206
|
+
| `object(id)` / `objects(offset, limit)` | Read the objects the key grants access to. |
|
|
207
|
+
| `download(object, options?)` | Returns a `ReadableStream`. |
|
|
208
|
+
| `hosts(query?)` | Hosts serving this key's objects. |
|
|
209
|
+
|
|
175
210
|
## License
|
|
176
211
|
|
|
177
212
|
MIT
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { Account, AppKey, AppMetadata, Builder, DownloadOptions, Host, HostQuery, ObjectEvent, PackedUpload, PinnedObject, PinnedSlab, Sdk, SealedObject, Sector, ShardProgress, Slab, UploadOptions, encodedSize, generateRecoveryPhrase, setLogger, validateRecoveryPhrase } from '../wasm/sia_storage_wasm.js';
|
|
1
|
+
export { Account, AppKey, AppMetadata, Builder, DownloadOptions, Host, HostQuery, KeyRecord, KeyStats, ObjectEvent, PackedUpload, PinnedObject, PinnedSlab, Sdk, SealedObject, Sector, ShardProgress, SharedSdk, SharingKey, Slab, UploadOptions, encodedSize, generateRecoveryPhrase, setLogger, validateRecoveryPhrase } from '../wasm/sia_storage_wasm.js';
|
|
2
2
|
|
|
3
3
|
/** Initialize the WASM module. Safe to call multiple times. */
|
|
4
4
|
declare function initSia(): Promise<void>;
|
package/dist/index.js
CHANGED
|
@@ -3,10 +3,13 @@ import wasmInit from "../wasm/sia_storage_wasm.js";
|
|
|
3
3
|
import {
|
|
4
4
|
AppKey,
|
|
5
5
|
Builder,
|
|
6
|
+
KeyRecord,
|
|
6
7
|
ObjectEvent,
|
|
7
8
|
PackedUpload,
|
|
8
9
|
PinnedObject,
|
|
9
10
|
Sdk,
|
|
11
|
+
SharedSdk,
|
|
12
|
+
SharingKey,
|
|
10
13
|
encodedSize,
|
|
11
14
|
generateRecoveryPhrase,
|
|
12
15
|
setLogger,
|
|
@@ -20,10 +23,13 @@ async function initSia() {
|
|
|
20
23
|
export {
|
|
21
24
|
AppKey,
|
|
22
25
|
Builder,
|
|
26
|
+
KeyRecord,
|
|
23
27
|
ObjectEvent,
|
|
24
28
|
PackedUpload,
|
|
25
29
|
PinnedObject,
|
|
26
30
|
Sdk,
|
|
31
|
+
SharedSdk,
|
|
32
|
+
SharingKey,
|
|
27
33
|
encodedSize,
|
|
28
34
|
generateRecoveryPhrase,
|
|
29
35
|
initSia,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["// Browser entry; lazily initializes WASM on first use.\n\nimport wasmInit from '../wasm/sia_storage_wasm.js'\n\nlet initPromise: Promise<unknown> | null = null\n\n/** Initialize the WASM module. Safe to call multiple times. */\nexport async function initSia(): Promise<void> {\n if (!initPromise) initPromise = wasmInit()\n await initPromise\n}\n\nexport {\n AppKey,\n Builder,\n ObjectEvent,\n PackedUpload,\n PinnedObject,\n Sdk,\n encodedSize,\n generateRecoveryPhrase,\n setLogger,\n validateRecoveryPhrase,\n} from '../wasm/sia_storage_wasm.js'\nexport type {\n Account,\n AppMetadata,\n DownloadOptions,\n Host,\n HostQuery,\n PinnedSlab,\n Sector,\n SealedObject,\n ShardProgress,\n Slab,\n UploadOptions,\n} from '../wasm/sia_storage_wasm.js'\n"],"mappings":";AAEA,OAAO,cAAc;AAUrB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["// Browser entry; lazily initializes WASM on first use.\n\nimport wasmInit from '../wasm/sia_storage_wasm.js'\n\nlet initPromise: Promise<unknown> | null = null\n\n/** Initialize the WASM module. Safe to call multiple times. */\nexport async function initSia(): Promise<void> {\n if (!initPromise) initPromise = wasmInit()\n await initPromise\n}\n\nexport {\n AppKey,\n Builder,\n KeyRecord,\n ObjectEvent,\n PackedUpload,\n PinnedObject,\n Sdk,\n SharedSdk,\n SharingKey,\n encodedSize,\n generateRecoveryPhrase,\n setLogger,\n validateRecoveryPhrase,\n} from '../wasm/sia_storage_wasm.js'\nexport type {\n Account,\n AppMetadata,\n DownloadOptions,\n Host,\n HostQuery,\n KeyStats,\n PinnedSlab,\n Sector,\n SealedObject,\n ShardProgress,\n Slab,\n UploadOptions,\n} from '../wasm/sia_storage_wasm.js'\n"],"mappings":";AAEA,OAAO,cAAc;AAUrB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAtBP,IAAI,cAAuC;AAG3C,eAAsB,UAAyB;AAC7C,MAAI,CAAC,YAAa,eAAc,SAAS;AACzC,QAAM;AACR;","names":[]}
|
package/dist/index.node.cjs
CHANGED
|
@@ -22,10 +22,13 @@ var index_node_exports = {};
|
|
|
22
22
|
__export(index_node_exports, {
|
|
23
23
|
AppKey: () => AppKey,
|
|
24
24
|
Builder: () => Builder,
|
|
25
|
+
KeyRecord: () => KeyRecord,
|
|
25
26
|
ObjectEvent: () => ObjectEvent,
|
|
26
27
|
PackedUpload: () => PackedUpload,
|
|
27
28
|
PinnedObject: () => PinnedObject,
|
|
28
29
|
Sdk: () => Sdk,
|
|
30
|
+
SharedSdk: () => SharedSdk,
|
|
31
|
+
SharingKey: () => SharingKey,
|
|
29
32
|
encodedSize: () => encodedSize,
|
|
30
33
|
generateRecoveryPhrase: () => generateRecoveryPhrase,
|
|
31
34
|
initSia: () => initSia,
|
|
@@ -71,6 +74,9 @@ var {
|
|
|
71
74
|
PinnedObject,
|
|
72
75
|
PackedUpload,
|
|
73
76
|
ObjectEvent,
|
|
77
|
+
SharingKey,
|
|
78
|
+
KeyRecord,
|
|
79
|
+
SharedSdk,
|
|
74
80
|
generateRecoveryPhrase,
|
|
75
81
|
validateRecoveryPhrase,
|
|
76
82
|
setLogger,
|
|
@@ -83,10 +89,13 @@ async function initSia() {
|
|
|
83
89
|
0 && (module.exports = {
|
|
84
90
|
AppKey,
|
|
85
91
|
Builder,
|
|
92
|
+
KeyRecord,
|
|
86
93
|
ObjectEvent,
|
|
87
94
|
PackedUpload,
|
|
88
95
|
PinnedObject,
|
|
89
96
|
Sdk,
|
|
97
|
+
SharedSdk,
|
|
98
|
+
SharingKey,
|
|
90
99
|
encodedSize,
|
|
91
100
|
generateRecoveryPhrase,
|
|
92
101
|
initSia,
|
package/dist/index.node.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.node.ts","../src/node/load.ts","../src/node/napi.ts"],"sourcesContent":["export * from './node/napi'\nexport type * from './node/napi'\n","import type * as Addon from './napi.generated'\n\nlet addon: typeof Addon | null = null\n\nexport function loadNativeAddon(): typeof Addon {\n if (addon) return addon\n\n const platform = process.platform\n const arch = process.arch\n\n try {\n if (platform === 'darwin' && arch === 'arm64') {\n addon = require('@siafoundation/sia-storage-darwin-arm64')\n } else if (platform === 'darwin' && arch === 'x64') {\n addon = require('@siafoundation/sia-storage-darwin-x64')\n } else if (platform === 'linux' && arch === 'x64') {\n addon = require('@siafoundation/sia-storage-linux-x64-gnu')\n } else if (platform === 'linux' && arch === 'arm64') {\n addon = require('@siafoundation/sia-storage-linux-arm64-gnu')\n } else if (platform === 'win32' && arch === 'x64') {\n addon = require('@siafoundation/sia-storage-win32-x64-msvc')\n }\n } catch {}\n\n if (!addon) {\n throw new Error(\n `@siafoundation/sia-storage: Native addon not found for ${platform}-${arch}. ` +\n `Install @siafoundation/sia-storage-${platform}-${arch} or use the browser/WASM build.`,\n )\n }\n\n return addon\n}\n","import { loadNativeAddon } from './load'\n\nconst addon = loadNativeAddon()\n\nexport const {\n AppKey,\n Builder,\n Sdk,\n PinnedObject,\n PackedUpload,\n ObjectEvent,\n generateRecoveryPhrase,\n validateRecoveryPhrase,\n setLogger,\n encodedSize,\n} = addon\n\nexport type * from './napi.generated'\n\n/** Force-load the native addon to surface missing-binary errors at startup. */\nexport async function initSia(): Promise<void> {\n loadNativeAddon()\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEA,IAAI,QAA6B;AAE1B,SAAS,kBAAgC;AAC9C,MAAI,MAAO,QAAO;AAElB,QAAM,WAAW,QAAQ;AACzB,QAAM,OAAO,QAAQ;AAErB,MAAI;AACF,QAAI,aAAa,YAAY,SAAS,SAAS;AAC7C,cAAQ,QAAQ,yCAAyC;AAAA,IAC3D,WAAW,aAAa,YAAY,SAAS,OAAO;AAClD,cAAQ,QAAQ,uCAAuC;AAAA,IACzD,WAAW,aAAa,WAAW,SAAS,OAAO;AACjD,cAAQ,QAAQ,0CAA0C;AAAA,IAC5D,WAAW,aAAa,WAAW,SAAS,SAAS;AACnD,cAAQ,QAAQ,4CAA4C;AAAA,IAC9D,WAAW,aAAa,WAAW,SAAS,OAAO;AACjD,cAAQ,QAAQ,2CAA2C;AAAA,IAC7D;AAAA,EACF,QAAQ;AAAA,EAAC;AAET,MAAI,CAAC,OAAO;AACV,UAAM,IAAI;AAAA,MACR,0DAA0D,QAAQ,IAAI,IAAI,wCAClC,QAAQ,IAAI,IAAI;AAAA,IAC1D;AAAA,EACF;AAEA,SAAO;AACT;;;AC9BA,IAAMA,SAAQ,gBAAgB;AAEvB,IAAM;AAAA,EACX;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,IAAIA;AAKJ,eAAsB,UAAyB;AAC7C,kBAAgB;AAClB;","names":["addon"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.node.ts","../src/node/load.ts","../src/node/napi.ts"],"sourcesContent":["export * from './node/napi'\nexport type * from './node/napi'\n","import type * as Addon from './napi.generated'\n\nlet addon: typeof Addon | null = null\n\nexport function loadNativeAddon(): typeof Addon {\n if (addon) return addon\n\n const platform = process.platform\n const arch = process.arch\n\n try {\n if (platform === 'darwin' && arch === 'arm64') {\n addon = require('@siafoundation/sia-storage-darwin-arm64')\n } else if (platform === 'darwin' && arch === 'x64') {\n addon = require('@siafoundation/sia-storage-darwin-x64')\n } else if (platform === 'linux' && arch === 'x64') {\n addon = require('@siafoundation/sia-storage-linux-x64-gnu')\n } else if (platform === 'linux' && arch === 'arm64') {\n addon = require('@siafoundation/sia-storage-linux-arm64-gnu')\n } else if (platform === 'win32' && arch === 'x64') {\n addon = require('@siafoundation/sia-storage-win32-x64-msvc')\n }\n } catch {}\n\n if (!addon) {\n throw new Error(\n `@siafoundation/sia-storage: Native addon not found for ${platform}-${arch}. ` +\n `Install @siafoundation/sia-storage-${platform}-${arch} or use the browser/WASM build.`,\n )\n }\n\n return addon\n}\n","import { loadNativeAddon } from './load'\n\nconst addon = loadNativeAddon()\n\nexport const {\n AppKey,\n Builder,\n Sdk,\n PinnedObject,\n PackedUpload,\n ObjectEvent,\n SharingKey,\n KeyRecord,\n SharedSdk,\n generateRecoveryPhrase,\n validateRecoveryPhrase,\n setLogger,\n encodedSize,\n} = addon\n\nexport type * from './napi.generated'\n\n/** Force-load the native addon to surface missing-binary errors at startup. */\nexport async function initSia(): Promise<void> {\n loadNativeAddon()\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEA,IAAI,QAA6B;AAE1B,SAAS,kBAAgC;AAC9C,MAAI,MAAO,QAAO;AAElB,QAAM,WAAW,QAAQ;AACzB,QAAM,OAAO,QAAQ;AAErB,MAAI;AACF,QAAI,aAAa,YAAY,SAAS,SAAS;AAC7C,cAAQ,QAAQ,yCAAyC;AAAA,IAC3D,WAAW,aAAa,YAAY,SAAS,OAAO;AAClD,cAAQ,QAAQ,uCAAuC;AAAA,IACzD,WAAW,aAAa,WAAW,SAAS,OAAO;AACjD,cAAQ,QAAQ,0CAA0C;AAAA,IAC5D,WAAW,aAAa,WAAW,SAAS,SAAS;AACnD,cAAQ,QAAQ,4CAA4C;AAAA,IAC9D,WAAW,aAAa,WAAW,SAAS,OAAO;AACjD,cAAQ,QAAQ,2CAA2C;AAAA,IAC7D;AAAA,EACF,QAAQ;AAAA,EAAC;AAET,MAAI,CAAC,OAAO;AACV,UAAM,IAAI;AAAA,MACR,0DAA0D,QAAQ,IAAI,IAAI,wCAClC,QAAQ,IAAI,IAAI;AAAA,IAC1D;AAAA,EACF;AAEA,SAAO;AACT;;;AC9BA,IAAMA,SAAQ,gBAAgB;AAEvB,IAAM;AAAA,EACX;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,IAAIA;AAKJ,eAAsB,UAAyB;AAC7C,kBAAgB;AAClB;","names":["addon"]}
|
package/dist/index.node.d.ts
CHANGED
|
@@ -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
|
-
/**
|
|
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. */
|
|
@@ -73,7 +123,9 @@ export declare class PackedUpload {
|
|
|
73
123
|
*
|
|
74
124
|
* If the reader errors part-way, it's safe to continue calling
|
|
75
125
|
* [add](Self::add); no object is registered for the failed call. Or call
|
|
76
|
-
* [finalize](Self::finalize) to collect the objects added so far.
|
|
126
|
+
* [finalize](Self::finalize) to collect the objects added so far. Bytes
|
|
127
|
+
* read before the error remain in the current slab as padding and stay
|
|
128
|
+
* counted in [length](Self::length) and [remaining](Self::remaining).
|
|
77
129
|
*
|
|
78
130
|
* ```js
|
|
79
131
|
* const packed = sdk.uploadPacked();
|
|
@@ -83,6 +135,20 @@ export declare class PackedUpload {
|
|
|
83
135
|
* ```
|
|
84
136
|
*/
|
|
85
137
|
add(stream: ReadableStream): Promise<bigint>
|
|
138
|
+
/**
|
|
139
|
+
* Adds a new object to the upload by opening the file at `path`. Behaves
|
|
140
|
+
* like [add](Self::add) otherwise.
|
|
141
|
+
*
|
|
142
|
+
* Prefer this to [add](Self::add) for files on disk: the read stays in
|
|
143
|
+
* Rust instead of streaming each chunk through JS.
|
|
144
|
+
*
|
|
145
|
+
* ```js
|
|
146
|
+
* const packed = sdk.uploadPacked();
|
|
147
|
+
* await packed.addPath("/tmp/photo.jpg");
|
|
148
|
+
* const objects = await packed.finalize();
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
addPath(path: string): Promise<bigint>
|
|
86
152
|
/** Cancels the upload. */
|
|
87
153
|
cancel(): void
|
|
88
154
|
/**
|
|
@@ -104,6 +170,8 @@ export declare class PinnedObject {
|
|
|
104
170
|
id(): string
|
|
105
171
|
/** Returns the total size of the object. */
|
|
106
172
|
size(): bigint
|
|
173
|
+
/** Returns a new object truncated to the requested length. */
|
|
174
|
+
truncate(length: bigint): PinnedObject
|
|
107
175
|
/** Returns the total encoded size after erasure coding. */
|
|
108
176
|
encodedSize(): bigint
|
|
109
177
|
/** Returns the slabs that make up the object. */
|
|
@@ -119,13 +187,30 @@ export declare class PinnedObject {
|
|
|
119
187
|
}
|
|
120
188
|
|
|
121
189
|
export declare class Sdk {
|
|
190
|
+
/** Creates a sharing key. Attach objects to it with `Sdk.shareObject`. */
|
|
191
|
+
createSharingKey(description: string, expiresAt?: Date | undefined | null): Promise<SharingKey>
|
|
192
|
+
/** Lists the account's sharing keys, most recently created first. */
|
|
193
|
+
sharingKeys(offset: number, limit: number): Promise<Array<KeyRecord>>
|
|
194
|
+
/** Fetches the indexer's record for a key, including its counts. */
|
|
195
|
+
sharingKey(key: SharingKey): Promise<KeyRecord>
|
|
196
|
+
/**
|
|
197
|
+
* Attaches an object to a sharing key, re-sealing its encryption keys under
|
|
198
|
+
* the key so recipients can decrypt it.
|
|
199
|
+
*/
|
|
200
|
+
shareObject(key: SharingKey, object: PinnedObject): Promise<void>
|
|
201
|
+
/** Lists and decrypts the objects attached to a sharing key. */
|
|
202
|
+
sharedObjects(key: SharingKey, offset: number, limit: number): Promise<Array<PinnedObject>>
|
|
203
|
+
/** Detaches an object from a sharing key. */
|
|
204
|
+
unshareObject(key: SharingKey, id: string): Promise<void>
|
|
205
|
+
/** Revokes a sharing key, deleting it and detaching all of its objects. */
|
|
206
|
+
revokeSharingKey(key: SharingKey): Promise<void>
|
|
122
207
|
/** Returns the application key used by the SDK. */
|
|
123
208
|
appKey(): AppKey
|
|
124
209
|
/**
|
|
125
210
|
* Creates a new packed upload for efficiently uploading multiple small
|
|
126
211
|
* objects together. Returns a `PackedUpload` handle.
|
|
127
212
|
*/
|
|
128
|
-
uploadPacked(options?:
|
|
213
|
+
uploadPacked(options?: PackedUploadOptions): PackedUpload
|
|
129
214
|
/**
|
|
130
215
|
* Uploads data to the Sia network.
|
|
131
216
|
*
|
|
@@ -135,6 +220,14 @@ export declare class Sdk {
|
|
|
135
220
|
* the previous ID must be updated.
|
|
136
221
|
*/
|
|
137
222
|
upload(object: PinnedObject, stream: ReadableStream, options?: UploadOptions): Promise<PinnedObject>
|
|
223
|
+
/**
|
|
224
|
+
* Uploads the file at `path`. Behaves like [upload](Self::upload)
|
|
225
|
+
* otherwise.
|
|
226
|
+
*
|
|
227
|
+
* Prefer this to [upload](Self::upload) for files on disk: the read stays
|
|
228
|
+
* in Rust instead of streaming each chunk through JS.
|
|
229
|
+
*/
|
|
230
|
+
uploadPath(object: PinnedObject, path: string, options?: UploadOptions): Promise<PinnedObject>
|
|
138
231
|
/**
|
|
139
232
|
* Downloads an object from the Sia network, returning a `ReadableStream`
|
|
140
233
|
* of the object's data.
|
|
@@ -157,13 +250,58 @@ export declare class Sdk {
|
|
|
157
250
|
/** Returns the current account. */
|
|
158
251
|
account(): Promise<Account>
|
|
159
252
|
/** Creates a signed URL for sharing an object. */
|
|
160
|
-
|
|
253
|
+
objectShareUrl(object: PinnedObject, validUntil: Date): string
|
|
161
254
|
/** Retrieves a shared object from a signed URL. */
|
|
162
|
-
|
|
255
|
+
objectFromShareUrl(sharedUrl: string): Promise<PinnedObject>
|
|
163
256
|
/** Pins an object to the indexer. */
|
|
164
257
|
pinObject(object: PinnedObject): Promise<void>
|
|
165
258
|
}
|
|
166
259
|
|
|
260
|
+
/**
|
|
261
|
+
* A read-only SDK for the objects a sharing key grants access to.
|
|
262
|
+
*
|
|
263
|
+
* Unlike `Sdk`, it authenticates with a sharing key rather than an app key and
|
|
264
|
+
* cannot upload, pin, or delete. Downloads are paid for by the key's owner.
|
|
265
|
+
*/
|
|
266
|
+
export declare class SharedSdk {
|
|
267
|
+
/**
|
|
268
|
+
* Connects to `indexer_url` as the recipient of the sharing key derived
|
|
269
|
+
* from `seed`, the 32-byte seed the key's owner handed out.
|
|
270
|
+
*/
|
|
271
|
+
static connect(indexerUrl: string, seed: Buffer): Promise<SharedSdk>
|
|
272
|
+
/** Fetches the sharing key's stats from the indexer. */
|
|
273
|
+
stats(): Promise<KeyStats>
|
|
274
|
+
/** Fetches and decrypts one object the key grants access to. */
|
|
275
|
+
object(id: string): Promise<PinnedObject>
|
|
276
|
+
/** Lists and decrypts a page of the objects the key grants access to. */
|
|
277
|
+
objects(offset: number, limit: number): Promise<Array<PinnedObject>>
|
|
278
|
+
/**
|
|
279
|
+
* Returns the hosts serving this key's objects. Mirrors `Sdk.hosts()` but
|
|
280
|
+
* is scoped to the sharing key, so the set is already limited to hosts
|
|
281
|
+
* holding its objects.
|
|
282
|
+
*/
|
|
283
|
+
hosts(): Promise<Array<Host>>
|
|
284
|
+
/** Streams a shared object's data, paying hosts with the owner's tokens. */
|
|
285
|
+
download(object: PinnedObject, options?: DownloadOptions | undefined | null): ReadableStream
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* A sharing key, granting read-only access to the objects attached to it.
|
|
290
|
+
*
|
|
291
|
+
* It is just the credential; the operations that use it live on `Sdk`.
|
|
292
|
+
*/
|
|
293
|
+
export declare class SharingKey {
|
|
294
|
+
/** The key's public half, which identifies it on the indexer. */
|
|
295
|
+
get publicKey(): string
|
|
296
|
+
/**
|
|
297
|
+
* The 32-byte seed a recipient needs to read the key's objects. Pair it
|
|
298
|
+
* with the indexer url in `SharedSdk.connect`.
|
|
299
|
+
*/
|
|
300
|
+
seed(): Buffer
|
|
301
|
+
/** Imports a sharing key from the 32-byte seed its owner handed out. */
|
|
302
|
+
static fromSeed(seed: Buffer): SharingKey
|
|
303
|
+
}
|
|
304
|
+
|
|
167
305
|
/** An account registered on the indexer. */
|
|
168
306
|
export interface Account {
|
|
169
307
|
accountKey: string
|
|
@@ -179,7 +317,7 @@ export interface Account {
|
|
|
179
317
|
/** The protocol used in a network address. */
|
|
180
318
|
export declare const enum AddressProtocol {
|
|
181
319
|
SiaMux = 'SiaMux',
|
|
182
|
-
Quic = 'Quic'
|
|
320
|
+
Quic = 'Quic',
|
|
183
321
|
}
|
|
184
322
|
|
|
185
323
|
/** Application info. */
|
|
@@ -225,6 +363,20 @@ export interface Host {
|
|
|
225
363
|
goodForUpload: boolean
|
|
226
364
|
}
|
|
227
365
|
|
|
366
|
+
/**
|
|
367
|
+
* A snapshot of what a sharing key grants access to. The counts reflect the
|
|
368
|
+
* moment the record was fetched, not a live view.
|
|
369
|
+
*/
|
|
370
|
+
export interface KeyStats {
|
|
371
|
+
objectCount: bigint
|
|
372
|
+
objectSize: bigint
|
|
373
|
+
pinnedData: bigint
|
|
374
|
+
pinnedSize: bigint
|
|
375
|
+
expiresAt?: Date
|
|
376
|
+
createdAt: Date
|
|
377
|
+
updatedAt: Date
|
|
378
|
+
}
|
|
379
|
+
|
|
228
380
|
/** A network address of a storage provider on the Sia network. */
|
|
229
381
|
export interface NetAddress {
|
|
230
382
|
protocol: AddressProtocol
|
|
@@ -237,6 +389,14 @@ export interface ObjectsCursor {
|
|
|
237
389
|
after: Date
|
|
238
390
|
}
|
|
239
391
|
|
|
392
|
+
/** Packed upload options. */
|
|
393
|
+
export interface PackedUploadOptions {
|
|
394
|
+
maxBufferedSlabs?: number
|
|
395
|
+
dataShards?: number
|
|
396
|
+
parityShards?: number
|
|
397
|
+
onShardUploaded?: (progress: ShardProgress) => void
|
|
398
|
+
}
|
|
399
|
+
|
|
240
400
|
/** A sector stored on a specific host. */
|
|
241
401
|
export interface PinnedSector {
|
|
242
402
|
root: string
|
|
@@ -245,6 +405,7 @@ export interface PinnedSector {
|
|
|
245
405
|
|
|
246
406
|
/** A pinned slab from the indexer. */
|
|
247
407
|
export interface PinnedSlab {
|
|
408
|
+
version: number
|
|
248
409
|
id: string
|
|
249
410
|
encryptionKey: Buffer
|
|
250
411
|
minShards: number
|
|
@@ -283,6 +444,7 @@ export interface ShardProgress {
|
|
|
283
444
|
|
|
284
445
|
/** A slab representing a contiguous erasure-coded segment of a file. */
|
|
285
446
|
export interface Slab {
|
|
447
|
+
version: number
|
|
286
448
|
encryptionKey: Buffer
|
|
287
449
|
minShards: number
|
|
288
450
|
sectors: Array<PinnedSector>
|
|
@@ -295,6 +457,7 @@ export interface UploadOptions {
|
|
|
295
457
|
maxBufferedSlabs?: number
|
|
296
458
|
dataShards?: number
|
|
297
459
|
parityShards?: number
|
|
460
|
+
startOffset?: bigint
|
|
298
461
|
onShardUploaded?: (progress: ShardProgress) => void
|
|
299
462
|
}
|
|
300
463
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@siafoundation/sia-storage",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
"build-wasm": "bun run scripts/build-wasm.ts",
|
|
41
41
|
"setup": "bun run scripts/setup-rust.ts",
|
|
42
42
|
"setup-napi-test": "bun run scripts/setup-napi-test.ts",
|
|
43
|
+
"typecheck": "tsc --noEmit",
|
|
43
44
|
"test": "bun test src/tests/install-integration.test.ts",
|
|
44
45
|
"test:browser": "bun test src/tests/vite-integration.test.ts src/tests/esbuild-integration.test.ts src/tests/webpack-integration.test.ts src/tests/rollup-integration.test.ts src/tests/nextjs-integration.test.ts",
|
|
45
46
|
"test:all": "bun test",
|
|
@@ -47,17 +48,17 @@
|
|
|
47
48
|
"publish-npm": "bun run scripts/publish.ts"
|
|
48
49
|
},
|
|
49
50
|
"optionalDependencies": {
|
|
50
|
-
"@siafoundation/sia-storage-darwin-arm64": "0.0
|
|
51
|
-
"@siafoundation/sia-storage-darwin-x64": "0.0
|
|
52
|
-
"@siafoundation/sia-storage-linux-x64-gnu": "0.0
|
|
53
|
-
"@siafoundation/sia-storage-linux-arm64-gnu": "0.0
|
|
54
|
-
"@siafoundation/sia-storage-win32-x64-msvc": "0.0
|
|
51
|
+
"@siafoundation/sia-storage-darwin-arm64": "0.1.0",
|
|
52
|
+
"@siafoundation/sia-storage-darwin-x64": "0.1.0",
|
|
53
|
+
"@siafoundation/sia-storage-linux-x64-gnu": "0.1.0",
|
|
54
|
+
"@siafoundation/sia-storage-linux-arm64-gnu": "0.1.0",
|
|
55
|
+
"@siafoundation/sia-storage-win32-x64-msvc": "0.1.0"
|
|
55
56
|
},
|
|
56
57
|
"devDependencies": {
|
|
57
58
|
"@types/bun": "^1.3.12",
|
|
58
59
|
"@types/node": "^24.13.2",
|
|
59
60
|
"playwright": "^1.60.0",
|
|
60
61
|
"tsup": "^8.4.0",
|
|
61
|
-
"typescript": "
|
|
62
|
+
"typescript": "5.9.3"
|
|
62
63
|
}
|
|
63
64
|
}
|