@shelby-protocol/sdk 0.3.1 → 0.4.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.
Files changed (66) hide show
  1. package/dist/browser/index.d.ts +9 -9
  2. package/dist/browser/index.mjs +1068 -589
  3. package/dist/core/clients/ShelbyBlobClient.d.ts +155 -40
  4. package/dist/core/clients/ShelbyBlobClient.mjs +314 -112
  5. package/dist/core/clients/ShelbyClient.d.ts +27 -4
  6. package/dist/core/clients/ShelbyClient.mjs +869 -551
  7. package/dist/core/clients/ShelbyClientConfig.d.ts +9 -1
  8. package/dist/core/clients/ShelbyMetadataClient.d.ts +38 -6
  9. package/dist/core/clients/ShelbyMetadataClient.mjs +95 -13
  10. package/dist/core/clients/ShelbyMicropaymentChannelClient.d.ts +42 -0
  11. package/dist/core/clients/ShelbyMicropaymentChannelClient.mjs +62 -7
  12. package/dist/core/clients/ShelbyPlacementGroupClient.mjs +10 -7
  13. package/dist/core/clients/ShelbyRPCClient.d.ts +55 -66
  14. package/dist/core/clients/ShelbyRPCClient.mjs +344 -360
  15. package/dist/core/clients/index.d.ts +3 -2
  16. package/dist/core/clients/index.mjs +933 -551
  17. package/dist/core/clients/utils.mjs +1 -1
  18. package/dist/core/commitments.d.ts +12 -1
  19. package/dist/core/commitments.mjs +7 -0
  20. package/dist/core/constants.d.ts +1 -1
  21. package/dist/core/constants.mjs +1 -1
  22. package/dist/core/erasure/constants.d.ts +16 -1
  23. package/dist/core/erasure/constants.mjs +15 -1
  24. package/dist/core/erasure/index.d.ts +1 -1
  25. package/dist/core/erasure/index.mjs +15 -1
  26. package/dist/core/errors.d.ts +20 -1
  27. package/dist/core/errors.mjs +29 -0
  28. package/dist/core/index.d.ts +9 -9
  29. package/dist/core/index.mjs +1068 -589
  30. package/dist/core/operations/generated/sdk.d.ts +798 -42
  31. package/dist/core/operations/generated/sdk.mjs +93 -9
  32. package/dist/core/operations/index.d.ts +1 -1
  33. package/dist/core/operations/index.mjs +94 -10
  34. package/dist/core/rpc-responses.d.ts +1 -57
  35. package/dist/core/rpc-responses.mjs +1 -21
  36. package/dist/core/sp/chunk_proof.d.ts +23 -0
  37. package/dist/core/sp/chunk_proof.mjs +113 -0
  38. package/dist/core/sp/index.d.ts +3 -0
  39. package/dist/core/sp/index.mjs +402 -0
  40. package/dist/core/sp/sp_write_client.d.ts +53 -0
  41. package/dist/core/sp/sp_write_client.mjs +302 -0
  42. package/dist/core/types/blobs.d.ts +24 -5
  43. package/dist/core/types/blobs.mjs +24 -0
  44. package/dist/core/types/index.d.ts +2 -2
  45. package/dist/core/types/index.mjs +46 -2
  46. package/dist/core/types/payments.mjs +1 -1
  47. package/dist/core/types/storage_providers.d.ts +32 -6
  48. package/dist/core/types/storage_providers.mjs +22 -0
  49. package/dist/gen/rpc_server_pb.d.ts +295 -0
  50. package/dist/gen/rpc_server_pb.mjs +28 -0
  51. package/dist/node/clients/ShelbyNodeClient.d.ts +1 -0
  52. package/dist/node/clients/ShelbyNodeClient.mjs +869 -551
  53. package/dist/node/clients/index.d.ts +1 -0
  54. package/dist/node/clients/index.mjs +867 -551
  55. package/dist/node/index.d.ts +9 -9
  56. package/dist/node/index.mjs +1068 -589
  57. package/dist/node/parallel/commitment_worker.mjs +36 -249
  58. package/dist/node/parallel/commitment_worker_pool.mjs +56 -3
  59. package/dist/node/parallel/coverage_flush.d.ts +16 -0
  60. package/dist/node/parallel/coverage_flush.mjs +43 -0
  61. package/dist/node/parallel/default_commitment_worker_pool.mjs +56 -3
  62. package/dist/node/parallel/index.d.ts +1 -0
  63. package/dist/node/parallel/index.mjs +72 -4
  64. package/dist/node/parallel/parallel_commitments.mjs +56 -3
  65. package/dist/node/parallel/worker_pool.mjs +56 -3
  66. package/package.json +10 -3
@@ -1,6 +1,6 @@
1
1
  import { InputGenerateTransactionOptions, Aptos, AccountAddress, InputTransactionPluginData, AccountAddressInput, Account, PendingTransactionResponse, InputGenerateTransactionPayloadData } from '@aptos-labs/ts-sdk';
2
2
  import { BlobName } from '../layout.js';
3
- import { BlobMetadata, BlobActivity, StorageProviderAck } from '../types/blobs.js';
3
+ import { FullObjectMetadata, BlobActivity, BlobEncryption, StorageProviderAck } from '../types/blobs.js';
4
4
  import { E as ErasureCodingConfig } from '../../clay-codes-DdXABBDx.js';
5
5
  import { ShelbyIndexerClient } from '../operations/index.js';
6
6
  import { Blobs_Order_By, Blobs_Bool_Exp, Blob_Activities_Bool_Exp, Blob_Activities_Order_By } from '../operations/generated/sdk.js';
@@ -19,6 +19,22 @@ import '../networks.js';
19
19
  declare class MissingTransactionSubmitterError extends Error {
20
20
  constructor();
21
21
  }
22
+ /**
23
+ * Why `commit_object` rejected a write, mirroring the contract's
24
+ * `CommitRejectionReason` variants (blob_metadata.move).
25
+ */
26
+ type CommitRejectionReason = "AlreadyExists" | "NoPriorVersion" | "EtagMismatch";
27
+ /**
28
+ * Thrown when `commit_object` rejected a write instead of applying it. The
29
+ * transaction itself succeeded; the contract tore down the pending blob and
30
+ * emitted `ObjectCommitRejectedEvent` rather than aborting.
31
+ */
32
+ declare class ObjectCommitRejectedError extends Error {
33
+ readonly blobName: BlobName;
34
+ readonly uid: bigint;
35
+ readonly reason: CommitRejectionReason;
36
+ constructor(blobName: BlobName, uid: bigint, reason: CommitRejectionReason);
37
+ }
22
38
  interface BuildOptions {
23
39
  options?: InputGenerateTransactionOptions;
24
40
  withFeePayer?: boolean;
@@ -51,6 +67,18 @@ interface WriteBlobCommitmentsOptions {
51
67
  */
52
68
  usdSponsor?: UsdSponsorOptions;
53
69
  chunksetSizeBytes?: number;
70
+ /**
71
+ * The location (region) to write the blob to. Authoritative: the write lands there
72
+ * or aborts on chain (e.g. if the account's location preference is locked to a
73
+ * different location).
74
+ */
75
+ selectedLocation?: string;
76
+ /**
77
+ * Best-effort location hint, typically derived from where the client runs. Honored
78
+ * only for accounts in the default `FollowHint` preference mode, and overridden by
79
+ * `selectedLocation`. Defaults to `ShelbyClientConfig.locationHint`.
80
+ */
81
+ locationHint?: string;
54
82
  }
55
83
  interface AckTransactionOptions {
56
84
  build?: BuildOptions;
@@ -128,16 +156,33 @@ declare class ShelbyBlobClient {
128
156
  *
129
157
  * @example
130
158
  * ```typescript
131
- * const metadata = await client.getBlobMetadata({
159
+ * const metadata = await client.getFullObjectMetadata({
132
160
  * account: AccountAddress.fromString("0x1"),
133
161
  * name: "foo/bar.txt",
134
162
  * });
135
163
  * ```
136
164
  */
137
- getBlobMetadata(params: {
165
+ getFullObjectMetadata(params: {
138
166
  account: AccountAddressInput;
139
167
  name: BlobName;
140
- }): Promise<BlobMetadata | undefined>;
168
+ }): Promise<FullObjectMetadata | undefined>;
169
+ /**
170
+ * Retrieves blob metadata directly by its on-chain UID, including blobs in
171
+ * the pending (registered-but-not-yet-committed) state that
172
+ * {@link getFullObjectMetadata} cannot resolve by object name. Returns `undefined`
173
+ * if no blob has that UID.
174
+ *
175
+ * The returned `name`/`blobNameSuffix` are empty: the blob layer is keyed by
176
+ * UID and carries no object name (a name binding is established only at
177
+ * commit). `isWritten` reflects whether the blob has been committed.
178
+ */
179
+ getFullObjectMetadataByUid(uid: bigint): Promise<FullObjectMetadata | undefined>;
180
+ /**
181
+ * Parse the on-chain `BlobMetadata::V1` view shape into the SDK
182
+ * {@link FullObjectMetadata}. `uid` / `name` / `isWritten` are supplied by the
183
+ * caller since they depend on the lookup path (by object name vs by UID).
184
+ */
185
+ private parseBlobMetadata;
141
186
  /**
142
187
  * Retrieves all the blobs and their metadata for an account from the
143
188
  * blockchain.
@@ -149,7 +194,7 @@ declare class ShelbyBlobClient {
149
194
  *
150
195
  * @example
151
196
  * ```typescript
152
- * // BlobMetadata[]
197
+ * // FullObjectMetadata[]
153
198
  * const blobs = await client.getAccountBlobs({
154
199
  * account: AccountAddress.fromString("0x1"),
155
200
  * });
@@ -163,7 +208,19 @@ declare class ShelbyBlobClient {
163
208
  };
164
209
  orderBy?: Blobs_Order_By;
165
210
  where?: Omit<Blobs_Bool_Exp, "owner">;
166
- }): Promise<BlobMetadata[]>;
211
+ }): Promise<FullObjectMetadata[]>;
212
+ /**
213
+ * Object-facing default filter: only committed, non-deleted, unexpired rows.
214
+ * The blobs table is UID-keyed, so during an atomic overwrite a single
215
+ * object_name transiently has two non-deleted rows — the currently committed
216
+ * blob and the new pending (is_committed = "0") blob. Filtering on
217
+ * is_committed keeps name lookups/listings pinned to the committed object and
218
+ * avoids returning or duplicating the in-flight pending row. Applied to
219
+ * getBlobs *and* the getBlobsCount / getTotalBlobsSize aggregates so counts
220
+ * and sizes agree with the listing mid-overwrite. Callers can override any
221
+ * key (e.g. is_committed) via their own `where`.
222
+ */
223
+ private activeBlobsWhere;
167
224
  /**
168
225
  * Retrieves blobs and their metadata from the blockchain.
169
226
  *
@@ -174,7 +231,7 @@ declare class ShelbyBlobClient {
174
231
  *
175
232
  * @example
176
233
  * ```typescript
177
- * // BlobMetadata[]
234
+ * // FullObjectMetadata[]
178
235
  * const blobs = await client.getBlobs({
179
236
  * where: { owner: { _eq: AccountAddress.fromString("0x1").toString() } },
180
237
  * });
@@ -187,7 +244,7 @@ declare class ShelbyBlobClient {
187
244
  offset?: number;
188
245
  };
189
246
  orderBy?: Blobs_Order_By;
190
- }): Promise<BlobMetadata[]>;
247
+ }): Promise<FullObjectMetadata[]>;
191
248
  getBlobActivities(params: {
192
249
  where?: Blob_Activities_Bool_Exp;
193
250
  pagination?: {
@@ -207,7 +264,7 @@ declare class ShelbyBlobClient {
207
264
  * const count = await client.getBlobsCount();
208
265
  * ```
209
266
  */
210
- getBlobsCount(params: {
267
+ getBlobsCount(params?: {
211
268
  where?: Blobs_Bool_Exp;
212
269
  }): Promise<number>;
213
270
  /**
@@ -272,6 +329,7 @@ declare class ShelbyBlobClient {
272
329
  blobMerkleRoot: string;
273
330
  size: number;
274
331
  expirationMicros: number;
332
+ encryption?: BlobEncryption;
275
333
  config?: ErasureCodingConfig;
276
334
  options?: WriteBlobCommitmentsOptions;
277
335
  }): Promise<{
@@ -289,13 +347,13 @@ declare class ShelbyBlobClient {
289
347
  * @example
290
348
  * ```typescript
291
349
  *
292
- * const { transaction } = await client.deleteBlob({
350
+ * const { transaction } = await client.deleteObject({
293
351
  * account: signer,
294
352
  * blobName: "foo/bar.txt",
295
353
  * });
296
354
  * ```
297
355
  */
298
- deleteBlob(params: {
356
+ deleteObject(params: {
299
357
  account: Account;
300
358
  blobName: BlobName;
301
359
  options?: InputGenerateTransactionOptions;
@@ -305,10 +363,6 @@ declare class ShelbyBlobClient {
305
363
  /**
306
364
  * Deletes multiple blobs on the blockchain in a single atomic transaction.
307
365
  *
308
- * **Note:** This function requires the `delete_multiple_blobs` entry function
309
- * which will be deployed to the smart contract on 2026-02-04. Using this
310
- * function before that date will result in a transaction failure.
311
- *
312
366
  * This operation is atomic: if any blob deletion fails (e.g., blob not found),
313
367
  * the entire transaction fails and no blobs are deleted.
314
368
  *
@@ -323,13 +377,13 @@ declare class ShelbyBlobClient {
323
377
  * @example
324
378
  * ```typescript
325
379
  *
326
- * const { transaction } = await client.deleteMultipleBlobs({
380
+ * const { transaction } = await client.deleteMultipleObjects({
327
381
  * account: signer,
328
382
  * blobNames: ["foo/bar.txt", "baz.txt"],
329
383
  * });
330
384
  * ```
331
385
  */
332
- deleteMultipleBlobs(params: {
386
+ deleteMultipleObjects(params: {
333
387
  account: Account;
334
388
  blobNames: BlobName[];
335
389
  options?: InputGenerateTransactionOptions;
@@ -377,11 +431,49 @@ declare class ShelbyBlobClient {
377
431
  blobSize: number;
378
432
  blobMerkleRoot: string;
379
433
  }[];
434
+ encryption?: BlobEncryption;
380
435
  config?: ErasureCodingConfig;
381
436
  options?: WriteBlobCommitmentsOptions;
382
437
  }): Promise<{
383
438
  transaction: PendingTransactionResponse;
384
439
  }>;
440
+ /**
441
+ * Extracts the on-chain UIDs assigned at registration from a committed
442
+ * register transaction's events.
443
+ *
444
+ * `register_blob` / `register_multiple_blobs` create *pending* blobs and emit
445
+ * one `BlobRegisteredEvent` per blob. The UID is published only on this event
446
+ * (the blob is not yet in the `objects` map, so it cannot be read back by
447
+ * name), so callers must parse it here before uploading bytes or committing.
448
+ *
449
+ * @param events - The committed transaction's events (from `waitForTransaction`).
450
+ * @param deployer - The contract deployer address.
451
+ * @returns One entry per registered blob, keyed by its full object name
452
+ * (`@<owner>/<suffix>`, matching {@link createBlobKey}).
453
+ */
454
+ static registeredBlobUids(events: ReadonlyArray<{
455
+ type: string;
456
+ data: unknown;
457
+ }>, deployer: AccountAddress): {
458
+ objectName: string;
459
+ uid: bigint;
460
+ }[];
461
+ /**
462
+ * Detects whether `commit_object` rejected the write for `uid` rather than
463
+ * applying it. A rejected commit is still a *successful* transaction — the
464
+ * contract tears down the pending blob and emits `ObjectCommitRejectedEvent`
465
+ * instead of aborting — so callers must inspect the finalized transaction's
466
+ * events to tell a durable write apart from a silent no-op.
467
+ *
468
+ * @param events - The committed transaction's events (from `waitForTransaction`).
469
+ * @param deployer - The contract deployer address.
470
+ * @param uid - The UID passed to `commit_object`.
471
+ * @returns The rejection reason, or `undefined` if the commit was applied.
472
+ */
473
+ static findObjectCommitRejection(events: ReadonlyArray<{
474
+ type: string;
475
+ data: unknown;
476
+ }>, deployer: AccountAddress, uid: bigint): CommitRejectionReason | undefined;
385
477
  /**
386
478
  * Creates a transaction payload to register a blob on the blockchain.
387
479
  * This is a static helper method for constructing the Move function call payload.
@@ -395,19 +487,25 @@ declare class ShelbyBlobClient {
395
487
  * @param params.numChunksets - The total number of chunksets in the blob.
396
488
  *
397
489
  * @returns An Aptos transaction payload data object for the register_blob Move function.
398
- *
399
- * @see https://github.com/shelby/shelby/blob/e08e84742cf2b80ad8bb7227deb3013398076d53/move/shelby_contract/sources/global_metadata.move#L357
400
490
  */
401
491
  static createRegisterBlobPayload(params: {
402
492
  deployer?: AccountAddress;
403
493
  account: AccountAddress;
404
494
  blobName: BlobName;
495
+ selectedLocation?: string;
496
+ locationHint?: string;
405
497
  blobSize: number;
406
498
  blobMerkleRoot: string;
407
499
  expirationMicros: number;
408
500
  numChunksets: number;
409
501
  useSponsoredUsdVariant?: boolean;
410
502
  encoding: number;
503
+ encryption?: BlobEncryption;
504
+ /**
505
+ * TEMP (#1739): drop the trailing encryption arg to match contracts that
506
+ * predate the encryption upgrade (e.g. shelbynet). Defaults to false.
507
+ */
508
+ omitEncryptionArg?: boolean;
411
509
  }): InputGenerateTransactionPayloadData;
412
510
  /**
413
511
  * Creates a transaction payload to register multiple blobs on the blockchain.
@@ -423,12 +521,12 @@ declare class ShelbyBlobClient {
423
521
  * @param params.blobs.numChunksets - The total number of chunksets in the blob.
424
522
  *
425
523
  * @returns An Aptos transaction payload data object for the register_multiple_blobs Move function.
426
- *
427
- * @see https://github.com/shelby/shelby/blob/e08e84742cf2b80ad8bb7227deb3013398076d53/move/shelby_contract/sources/global_metadata.move#L357
428
524
  */
429
525
  static createBatchRegisterBlobsPayload(params: {
430
526
  deployer?: AccountAddress;
431
527
  account: AccountAddress;
528
+ selectedLocation?: string;
529
+ locationHint?: string;
432
530
  expirationMicros: number;
433
531
  blobs: {
434
532
  blobName: BlobName;
@@ -438,6 +536,12 @@ declare class ShelbyBlobClient {
438
536
  }[];
439
537
  useSponsoredUsdVariant?: boolean;
440
538
  encoding: number;
539
+ encryption?: BlobEncryption;
540
+ /**
541
+ * TEMP (#1739): drop the trailing encryption arg to match contracts that
542
+ * predate the encryption upgrade (e.g. shelbynet). Defaults to false.
543
+ */
544
+ omitEncryptionArg?: boolean;
441
545
  }): InputGenerateTransactionPayloadData;
442
546
  /**
443
547
  * Creates a transaction payload to delete a blob on the blockchain.
@@ -446,11 +550,9 @@ declare class ShelbyBlobClient {
446
550
  * @param params.deployer - Optional deployer account address. Defaults to SHELBY_DEPLOYER.
447
551
  * @param params.blobName - The blob name (e.g. "bar.txt", without the account address prefix).
448
552
  *
449
- * @returns An Aptos transaction payload data object for the delete_blob Move function.
450
- *
451
- * @see https://github.com/shelby/shelby/blob/64e9d7b4f0005e586faeb1e4085c79159234b6b6/move/shelby_contract/sources/global_metadata.move#L616
553
+ * @returns An Aptos transaction payload data object for the delete_object Move function.
452
554
  */
453
- static createDeleteBlobPayload(params: {
555
+ static createDeleteObjectPayload(params: {
454
556
  deployer?: AccountAddress;
455
557
  blobName: string;
456
558
  }): InputGenerateTransactionPayloadData;
@@ -458,10 +560,6 @@ declare class ShelbyBlobClient {
458
560
  * Creates a transaction payload to delete multiple blobs on the blockchain.
459
561
  * This is a static helper method for constructing the Move function call payload.
460
562
  *
461
- * **Note:** This function requires the `delete_multiple_blobs` entry function
462
- * which will be deployed to the smart contract on 2026-02-04. Using this
463
- * function before that date will result in a transaction failure.
464
- *
465
563
  * This operation is atomic: if any blob deletion fails (e.g., blob not found),
466
564
  * the entire transaction fails and no blobs are deleted.
467
565
  *
@@ -470,25 +568,42 @@ declare class ShelbyBlobClient {
470
568
  * (e.g. ["foo/bar.txt", "baz.txt"], NOT ["0x1/foo/bar.txt"]). The account address
471
569
  * prefix is automatically derived from the transaction sender.
472
570
  *
473
- * @returns An Aptos transaction payload data object for the delete_multiple_blobs Move function.
474
- *
475
- * @see https://github.com/shelby/shelby/blob/main/move/shelby_contract/sources/blob_metadata.move
571
+ * @returns An Aptos transaction payload data object for the delete_multiple_objects Move function.
476
572
  */
477
- static createDeleteMultipleBlobsPayload(params: {
573
+ static createDeleteMultipleObjectsPayload(params: {
478
574
  deployer?: AccountAddress;
479
575
  blobNames: string[];
480
576
  }): InputGenerateTransactionPayloadData;
481
- static createBlobAcknowledgementsPayload(params: {
482
- blobOwner: AccountAddress;
577
+ /**
578
+ * Sort acks by slot and reduce to the `(ack_bits, signatures)` pair the
579
+ * contract expects: it walks the set bits low-to-high and consumes the
580
+ * signatures in that same order.
581
+ */
582
+ private static encodeAcks;
583
+ /**
584
+ * Payload for `commit_object(uid, object_name_suffix, overwrite, if_match_etag,
585
+ * ack_bits, signatures)` — binds a written pending blob under its object name,
586
+ * finalizing the upload. SP acks may be batched in here (the contract applies
587
+ * them before the `is_written` check), so register → upload → commit needs
588
+ * only a single finalize transaction.
589
+ *
590
+ * @param params.uid - The blob UID returned at registration.
591
+ * @param params.blobName - The object name suffix the blob was registered under.
592
+ * @param params.overwrite - Allow replacing an existing binding under this name.
593
+ * @param params.storageProviderAcks - Acks applied atomically with the commit.
594
+ */
595
+ static createCommitObjectPayload(params: {
596
+ deployer?: AccountAddress;
597
+ uid: bigint;
483
598
  blobName: BlobName;
484
- creationMicros: number;
599
+ overwrite: boolean;
485
600
  storageProviderAcks: StorageProviderAck[];
486
601
  }): InputGenerateTransactionPayloadData;
487
- addBlobAcknowledgements(params: {
602
+ commitObject(params: {
488
603
  account: Account;
489
- blobOwner: AccountAddress;
604
+ uid: bigint;
490
605
  blobName: BlobName;
491
- creationMicros: number;
606
+ overwrite: boolean;
492
607
  storageProviderAcks: StorageProviderAck[];
493
608
  options?: AckTransactionOptions;
494
609
  }): Promise<{
@@ -496,4 +611,4 @@ declare class ShelbyBlobClient {
496
611
  }>;
497
612
  }
498
613
 
499
- export { type AckTransactionOptions, type BuildOptions, MissingTransactionSubmitterError, ShelbyBlobClient, type UsdSponsorOptions, type WriteBlobCommitmentsOptions };
614
+ export { type AckTransactionOptions, type BuildOptions, type CommitRejectionReason, MissingTransactionSubmitterError, ObjectCommitRejectedError, ShelbyBlobClient, type UsdSponsorOptions, type WriteBlobCommitmentsOptions };