@mysten/walrus 0.4.0 → 0.5.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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @mysten/walrus
2
2
 
3
+ ## 0.5.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 3fd7e41: Move delete, epochs and owner options from writeFilesFlow to flow.register
8
+
3
9
  ## 0.4.0
4
10
 
5
11
  ### Minor Changes
package/README.md CHANGED
@@ -60,10 +60,14 @@ any other desired behavior.
60
60
 
61
61
  ## SDK Overview
62
62
 
63
- The walrus SDK is designed primarily to be used to build aggregators and publishers, and may not be
64
- optimal when used directly in client side apps. Reading and writing directly from storage nodes
65
- requires a lot of requests (~2200 to write a blob, ~335 to read a blob). For most apps, using
66
- aggregators and publishers with optimized reads/writes will provide a better user experience.
63
+ The Walrus TS SDK is designed to work directly with walrus storage nodes, or with the walrus upload
64
+ relay. When using the walrus SDK without an upload relay, it is important to understand that reading
65
+ and writing walrus blobs requires a lot of requests (~2200 to write a blob, ~335 to read a blob).
66
+ The upload relay will reduce the number of requests needed to write a blob, but reads through the
67
+ walrus SDK will still require a lot of requests. For many applications, using publishers and
68
+ aggregators is recommended, but the TS SDK can be useful when building applications where the
69
+ application needs to directly interact with walrus or users need to pay for their own storage
70
+ directly.
67
71
 
68
72
  The `WalrusClient` exposes high level methods for reading and writing blobs, as well as lower level
69
73
  methods for the individual steps in the process that can be used to implement more complex flows
@@ -202,20 +206,21 @@ const flow = walrusClient.writeFilesFlow({
202
206
  identifier: 'my-file.txt',
203
207
  }),
204
208
  ],
205
- epochs: 3,
206
- owner: currentAccount.address,
207
- deletable: true,
208
209
  });
209
210
 
210
211
  await flow.encode();
211
212
 
212
213
  // Step 2: Register the blob (triggered by user clicking a register button after the encode step)
213
214
  async function handleRegister() {
214
- const registerTx = flow.register();
215
- await signAndExecuteTransaction({ transaction: registerTx });
215
+ const registerTx = flow.register({
216
+ epochs: 3,
217
+ owner: currentAccount.address,
218
+ deletable: true,
219
+ });
220
+ const { digest } = await signAndExecuteTransaction({ transaction: registerTx });
216
221
  // Step 3: Upload the data to storage nodes
217
222
  // This can be done immediately after the register step, or as a separate step the user initiates
218
- await flow.upload();
223
+ await flow.upload({ digest });
219
224
  }
220
225
 
221
226
  // Step 4: Certify the blob (triggered by user clicking a certify button after the blob is uploaded)
@@ -683,5 +683,5 @@ export declare class WalrusClient {
683
683
  deletable: boolean;
684
684
  };
685
685
  }[]>;
686
- writeFilesFlow({ files, epochs, deletable, owner, attributes, signal, }: WriteFilesFlowOptions): WriteFilesFlow;
686
+ writeFilesFlow({ files }: WriteFilesFlowOptions): WriteFilesFlow;
687
687
  }
@@ -1466,14 +1466,7 @@ const _WalrusClient = class _WalrusClient {
1466
1466
  blobObject
1467
1467
  }));
1468
1468
  }
1469
- writeFilesFlow({
1470
- files,
1471
- epochs,
1472
- deletable,
1473
- owner,
1474
- attributes,
1475
- signal
1476
- }) {
1469
+ writeFilesFlow({ files }) {
1477
1470
  const encode = async () => {
1478
1471
  const { quilt, index } = await this.encodeQuilt({
1479
1472
  blobs: await Promise.all(
@@ -1487,13 +1480,21 @@ const _WalrusClient = class _WalrusClient {
1487
1480
  const metadata2 = __privateGet(this, _uploadRelayClient) ? await this.computeBlobMetadata({
1488
1481
  bytes: quilt
1489
1482
  }) : await this.encodeBlob(quilt);
1483
+ return {
1484
+ metadata: metadata2,
1485
+ size: quilt.length,
1486
+ data: __privateGet(this, _uploadRelayClient) ? quilt : void 0,
1487
+ index
1488
+ };
1489
+ };
1490
+ const register = ({ data, metadata: metadata2, index, size }, { epochs, deletable, owner, attributes }) => {
1490
1491
  const transaction = new import_transactions.Transaction();
1491
1492
  transaction.setSenderIfNotSet(owner);
1492
1493
  if (__privateGet(this, _uploadRelayClient)) {
1493
1494
  const meta = metadata2;
1494
1495
  transaction.add(
1495
1496
  this.sendUploadRelayTip({
1496
- size: quilt.length,
1497
+ size,
1497
1498
  blobDigest: meta.blobDigest,
1498
1499
  nonce: meta.nonce
1499
1500
  })
@@ -1502,7 +1503,7 @@ const _WalrusClient = class _WalrusClient {
1502
1503
  transaction.transferObjects(
1503
1504
  [
1504
1505
  this.registerBlob({
1505
- size: quilt.length,
1506
+ size,
1506
1507
  epochs,
1507
1508
  blobId: metadata2.blobId,
1508
1509
  rootHash: metadata2.rootHash,
@@ -1513,38 +1514,28 @@ const _WalrusClient = class _WalrusClient {
1513
1514
  ],
1514
1515
  owner
1515
1516
  );
1516
- const digest = await transaction.getDigest({
1517
- client: __privateGet(this, _suiClient)
1518
- });
1519
1517
  return {
1520
1518
  registerTransaction: transaction,
1519
+ index,
1520
+ data,
1521
1521
  metadata: metadata2,
1522
- registerDigest: digest,
1523
- data: __privateGet(this, _uploadRelayClient) ? quilt : void 0,
1524
- index
1522
+ deletable
1525
1523
  };
1526
1524
  };
1527
- const register = (result) => {
1528
- return result;
1529
- };
1530
- const upload = async ({
1531
- index,
1532
- data,
1533
- registerDigest,
1534
- metadata: metadata2
1535
- }) => {
1536
- const blobObject = await __privateMethod(this, _WalrusClient_instances, getCreatedBlob_fn).call(this, registerDigest);
1525
+ const upload = async ({ index, data, metadata: metadata2, deletable }, { digest }) => {
1526
+ const blobObject = await __privateMethod(this, _WalrusClient_instances, getCreatedBlob_fn).call(this, digest);
1537
1527
  if (__privateGet(this, _uploadRelayClient)) {
1538
1528
  const meta2 = metadata2;
1539
1529
  return {
1540
1530
  index,
1541
1531
  blobObject,
1542
1532
  metadata: metadata2,
1533
+ deletable,
1543
1534
  certificate: (await this.writeBlobToUploadRelay({
1544
1535
  blobId: metadata2.blobId,
1545
1536
  blob: data,
1546
1537
  nonce: meta2.nonce,
1547
- txDigest: registerDigest,
1538
+ txDigest: digest,
1548
1539
  blobObjectId: blobObject.id.id,
1549
1540
  deletable,
1550
1541
  encodingType: meta2.metadata.encodingType
@@ -1556,13 +1547,13 @@ const _WalrusClient = class _WalrusClient {
1556
1547
  index,
1557
1548
  blobObject,
1558
1549
  metadata: metadata2,
1550
+ deletable,
1559
1551
  confirmations: await this.writeEncodedBlobToNodes({
1560
1552
  blobId: metadata2.blobId,
1561
1553
  objectId: blobObject.id.id,
1562
1554
  metadata: meta.metadata,
1563
1555
  sliversByNode: meta.sliversByNode,
1564
- deletable,
1565
- signal
1556
+ deletable
1566
1557
  })
1567
1558
  };
1568
1559
  };
@@ -1571,7 +1562,8 @@ const _WalrusClient = class _WalrusClient {
1571
1562
  metadata: metadata2,
1572
1563
  confirmations,
1573
1564
  certificate,
1574
- blobObject
1565
+ blobObject,
1566
+ deletable
1575
1567
  }) => {
1576
1568
  return {
1577
1569
  index,
@@ -1581,12 +1573,12 @@ const _WalrusClient = class _WalrusClient {
1581
1573
  blobId: metadata2.blobId,
1582
1574
  blobObjectId: blobObject.id.id,
1583
1575
  confirmations,
1584
- deletable: true
1576
+ deletable
1585
1577
  }) : this.certifyBlobTransaction({
1586
1578
  certificate,
1587
1579
  blobId: metadata2.blobId,
1588
1580
  blobObjectId: blobObject.id.id,
1589
- deletable: true
1581
+ deletable
1590
1582
  })
1591
1583
  };
1592
1584
  };
@@ -1617,12 +1609,12 @@ const _WalrusClient = class _WalrusClient {
1617
1609
  stepResults.encode = await encode();
1618
1610
  }
1619
1611
  },
1620
- register: () => {
1621
- stepResults.register = register(getResults("encode", "register"));
1612
+ register: (options) => {
1613
+ stepResults.register = register(getResults("encode", "register"), options);
1622
1614
  return stepResults.register.registerTransaction;
1623
1615
  },
1624
- upload: async () => {
1625
- stepResults.upload = await upload(getResults("register", "upload"));
1616
+ upload: async (options) => {
1617
+ stepResults.upload = await upload(getResults("register", "upload"), options);
1626
1618
  },
1627
1619
  certify: () => {
1628
1620
  stepResults.certify = certify(getResults("upload", "certify"));