@mysten/walrus 0.2.3 → 0.3.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.
Files changed (48) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +83 -0
  3. package/dist/cjs/client.d.ts +6 -6
  4. package/dist/cjs/client.js +29 -29
  5. package/dist/cjs/client.js.map +2 -2
  6. package/dist/{esm/read/quilt.d.ts → cjs/quilt/reader.d.ts} +7 -3
  7. package/dist/cjs/{read/quilt.js → quilt/reader.js} +32 -18
  8. package/dist/cjs/quilt/reader.js.map +7 -0
  9. package/dist/cjs/quilt/write.d.ts +21 -0
  10. package/dist/cjs/quilt/write.js +167 -0
  11. package/dist/cjs/quilt/write.js.map +7 -0
  12. package/dist/cjs/types.d.ts +7 -7
  13. package/dist/cjs/types.js.map +1 -1
  14. package/dist/cjs/{fan-out-proxy → upload-relay}/client.d.ts +7 -7
  15. package/dist/cjs/{fan-out-proxy → upload-relay}/client.js +9 -9
  16. package/dist/cjs/upload-relay/client.js.map +7 -0
  17. package/dist/cjs/utils/bcs.d.ts +11 -5
  18. package/dist/cjs/utils/bcs.js +10 -6
  19. package/dist/cjs/utils/bcs.js.map +2 -2
  20. package/dist/cjs/utils/quilts.d.ts +6 -1
  21. package/dist/cjs/utils/quilts.js +12 -2
  22. package/dist/cjs/utils/quilts.js.map +2 -2
  23. package/dist/esm/client.d.ts +6 -6
  24. package/dist/esm/client.js +29 -29
  25. package/dist/esm/client.js.map +2 -2
  26. package/dist/{cjs/read/quilt.d.ts → esm/quilt/reader.d.ts} +7 -3
  27. package/dist/esm/{read/quilt.js → quilt/reader.js} +31 -17
  28. package/dist/esm/quilt/reader.js.map +7 -0
  29. package/dist/esm/quilt/write.d.ts +21 -0
  30. package/dist/esm/quilt/write.js +156 -0
  31. package/dist/esm/quilt/write.js.map +7 -0
  32. package/dist/esm/types.d.ts +7 -7
  33. package/dist/esm/{fan-out-proxy → upload-relay}/client.d.ts +7 -7
  34. package/dist/esm/{fan-out-proxy → upload-relay}/client.js +9 -9
  35. package/dist/esm/upload-relay/client.js.map +7 -0
  36. package/dist/esm/utils/bcs.d.ts +11 -5
  37. package/dist/esm/utils/bcs.js +10 -6
  38. package/dist/esm/utils/bcs.js.map +2 -2
  39. package/dist/esm/utils/quilts.d.ts +6 -1
  40. package/dist/esm/utils/quilts.js +12 -2
  41. package/dist/esm/utils/quilts.js.map +2 -2
  42. package/dist/tsconfig.esm.tsbuildinfo +1 -1
  43. package/dist/tsconfig.tsbuildinfo +1 -1
  44. package/package.json +4 -4
  45. package/dist/cjs/fan-out-proxy/client.js.map +0 -7
  46. package/dist/cjs/read/quilt.js.map +0 -7
  47. package/dist/esm/fan-out-proxy/client.js.map +0 -7
  48. package/dist/esm/read/quilt.js.map +0 -7
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @mysten/walrus
2
2
 
3
+ ## 0.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 0d5cd85: rename fanout proxy to upload relay
8
+
3
9
  ## 0.2.3
4
10
 
5
11
  ### Patch Changes
package/README.md CHANGED
@@ -102,6 +102,89 @@ const { blobId } = await walrusClient.writeBlob({
102
102
  });
103
103
  ```
104
104
 
105
+ ### Writing blobs with an upload relay
106
+
107
+ Writing blobs directly from a client requires a lot of requests to write data to all of the storage
108
+ nodes. An upload relay can be used to offload the work of these writes to a server, reducing
109
+ complexity for the client.
110
+
111
+ To use an upload relay, you can add the `uploadRelay` option when creating your `WalrusClient`:
112
+
113
+ ```ts
114
+ const client = new SuiClient({
115
+ url: getFullnodeUrl('testnet'),
116
+ network: 'testnet',
117
+ }).$extend(
118
+ WalrusClient.experimental_asClientExtension({
119
+ uploadRelay: {
120
+ host: 'https://upload-relay.testnet.walrus.space',
121
+ sendTip: {
122
+ max: 1_000,
123
+ },
124
+ },
125
+ }),
126
+ );
127
+ ```
128
+
129
+ The `host` option is required, and indicates the url for your upload relay. Upload relays may
130
+ require a tip to be included to cover the cost of writing the blob. You can configure a maximum tip
131
+ (paid in MIST) and the `WalrusClient` will automatically determine the required tip for your upload
132
+ relay, or you can manually configure the tip configuration as shown below.
133
+
134
+ The tip required by an upload relay can be found using the `tip-config` endpoint: (eg.
135
+ `https://upload-relay.testnet.walrus.space/v1/tip-config`) and may either be a `const` or a `linear`
136
+ tip.
137
+
138
+ ### `const` tip
139
+
140
+ A `const` will send a fixed amount for each blob written to the upload relay.
141
+
142
+ ```ts
143
+ const client = new SuiClient({
144
+ url: getFullnodeUrl('testnet'),
145
+ network: 'testnet',
146
+ }).$extend(
147
+ WalrusClient.experimental_asClientExtension({
148
+ uploadRelay: {
149
+ host: 'https://upload-relay.testnet.walrus.space',
150
+ sendTip: {
151
+ address: '0x123...',
152
+ kind: {
153
+ const: 105,
154
+ },
155
+ },
156
+ },
157
+ }),
158
+ );
159
+ ```
160
+
161
+ ### `linear` tip
162
+
163
+ A `linear` tip will send a fixed amount for each blob written to the fan out proxy, plus a
164
+ multiplier based on the size of the blob.
165
+
166
+ ```ts
167
+ const client = new SuiClient({
168
+ url: getFullnodeUrl('testnet'),
169
+ network: 'testnet',
170
+ }).$extend(
171
+ WalrusClient.experimental_asClientExtension({
172
+ uploadRelay: {
173
+ host: 'https://upload-relay.testnet.walrus.space',
174
+ sendTip: {
175
+ address: '0x123...',
176
+ kind: {
177
+ linear: {
178
+ base: 105,
179
+ multiplier: 10,
180
+ },
181
+ },
182
+ },
183
+ },
184
+ }),
185
+ );
186
+ ```
187
+
105
188
  ### Full API
106
189
 
107
190
  For a complete overview of the available methods on the `WalrusClient` you can reference type
@@ -5,7 +5,7 @@ import type { TransactionResult } from '@mysten/sui/transactions';
5
5
  import { Transaction } from '@mysten/sui/transactions';
6
6
  import { Blob } from './contracts/walrus/blob.js';
7
7
  import type { BlobStatus } from './storage-node/types.js';
8
- import type { CertifyBlobOptions, ComputeBlobMetadataOptions, DeleteBlobOptions, ExtendBlobOptions, GetBlobMetadataOptions, GetSecondarySliverOptions, GetSliversOptions, GetStorageConfirmationOptions, GetVerifiedBlobStatusOptions, ProtocolMessageCertificate, ReadBlobOptions, RegisterBlobOptions, SliversForNode, StorageWithSizeOptions, WalrusClientConfig, WalrusClientExtensionOptions, WriteBlobAttributesOptions, WriteBlobOptions, WriteBlobToFanOutProxyOptions, WriteEncodedBlobOptions, WriteEncodedBlobToNodesOptions, WriteMetadataOptions, WriteSliverOptions, WriteSliversToNodeOptions } from './types.js';
8
+ import type { CertifyBlobOptions, ComputeBlobMetadataOptions, DeleteBlobOptions, ExtendBlobOptions, GetBlobMetadataOptions, GetSecondarySliverOptions, GetSliversOptions, GetStorageConfirmationOptions, GetVerifiedBlobStatusOptions, ProtocolMessageCertificate, ReadBlobOptions, RegisterBlobOptions, SliversForNode, StorageWithSizeOptions, WalrusClientConfig, WalrusClientExtensionOptions, WriteBlobAttributesOptions, WriteBlobOptions, WriteBlobToUploadRelayOptions, WriteEncodedBlobOptions, WriteEncodedBlobToNodesOptions, WriteMetadataOptions, WriteSliverOptions, WriteSliversToNodeOptions } from './types.js';
9
9
  export declare class WalrusClient {
10
10
  #private;
11
11
  constructor(config: WalrusClientConfig);
@@ -269,10 +269,10 @@ export declare class WalrusClient {
269
269
  blobDigest: Uint8Array | (() => Promise<Uint8Array>);
270
270
  nonce: Uint8Array;
271
271
  }): (transaction: Transaction) => Promise<void>;
272
- calculateFanOutTip(options: {
272
+ calculateUploadRelayTip(options: {
273
273
  size: number;
274
274
  }): Promise<number | bigint>;
275
- sendFanOutTip({ size, blobDigest, nonce, }: {
275
+ sendUploadRelayTip({ size, blobDigest, nonce, }: {
276
276
  size: number;
277
277
  blobDigest: Uint8Array | (() => Promise<Uint8Array>);
278
278
  nonce: Uint8Array;
@@ -537,14 +537,14 @@ export declare class WalrusClient {
537
537
  */
538
538
  writeEncodedBlobToNodes({ blobId, metadata, sliversByNode, signal, ...options }: WriteEncodedBlobToNodesOptions): Promise<(import("./storage-node/types.js").StorageConfirmation | null)[]>;
539
539
  /**
540
- * Writes a blob to to a fan out proxy
540
+ * Writes a blob to to an upload relay
541
541
  *
542
542
  * @usage
543
543
  * ```ts
544
- * await client.writeBlobToFanOutProxy({ blob, deletable, epochs, signer });
544
+ * await client.writeBlobToUploadRelay({ blob, deletable, epochs, signer });
545
545
  * ```
546
546
  */
547
- writeBlobToFanOutProxy(options: WriteBlobToFanOutProxyOptions): Promise<{
547
+ writeBlobToUploadRelay(options: WriteBlobToUploadRelayOptions): Promise<{
548
548
  blobId: string;
549
549
  certificate: ProtocolMessageCertificate;
550
550
  }>;
@@ -62,8 +62,8 @@ var import_object_loader = require("./utils/object-loader.js");
62
62
  var import_randomness = require("./utils/randomness.js");
63
63
  var import_wasm = require("./wasm.js");
64
64
  var import_utils3 = require("@mysten/utils");
65
- var import_client3 = require("./fan-out-proxy/client.js");
66
- var _storageNodeClient, _wasmUrl, _packageConfig, _suiClient, _objectLoader, _blobMetadataConcurrencyLimit, _readCommittee, _cache, _fanOutConfig, _fanOutClient, _WalrusClient_instances, walType_fn, getPackageId_fn, getWalrusPackageId_fn, getSubsidiesPackageId_fn, wasmBindings_fn, internalReadBlob_fn, getCertificationEpoch_fn, getReadCommittee_fn, forceGetReadCommittee_fn, withWal_fn, loadTipConfig_fn, writeBlobAttributesForRef_fn, executeTransaction_fn, getCommittee_fn, getActiveCommittee_fn, stakingPool_fn, getNodeByShardIndex_fn, retryOnPossibleEpochChange_fn;
65
+ var import_client3 = require("./upload-relay/client.js");
66
+ var _storageNodeClient, _wasmUrl, _packageConfig, _suiClient, _objectLoader, _blobMetadataConcurrencyLimit, _readCommittee, _cache, _uploadRelayConfig, _uploadRelayClient, _WalrusClient_instances, walType_fn, getPackageId_fn, getWalrusPackageId_fn, getSubsidiesPackageId_fn, wasmBindings_fn, internalReadBlob_fn, getCertificationEpoch_fn, getReadCommittee_fn, forceGetReadCommittee_fn, withWal_fn, loadTipConfig_fn, writeBlobAttributesForRef_fn, executeTransaction_fn, getCommittee_fn, getActiveCommittee_fn, stakingPool_fn, getNodeByShardIndex_fn, retryOnPossibleEpochChange_fn;
67
67
  const _WalrusClient = class _WalrusClient {
68
68
  constructor(config) {
69
69
  __privateAdd(this, _WalrusClient_instances);
@@ -75,8 +75,8 @@ const _WalrusClient = class _WalrusClient {
75
75
  __privateAdd(this, _blobMetadataConcurrencyLimit, 10);
76
76
  __privateAdd(this, _readCommittee);
77
77
  __privateAdd(this, _cache);
78
- __privateAdd(this, _fanOutConfig, null);
79
- __privateAdd(this, _fanOutClient, null);
78
+ __privateAdd(this, _uploadRelayConfig, null);
79
+ __privateAdd(this, _uploadRelayClient, null);
80
80
  /** Read a blob from the storage nodes */
81
81
  this.readBlob = __privateMethod(this, _WalrusClient_instances, retryOnPossibleEpochChange_fn).call(this, __privateMethod(this, _WalrusClient_instances, internalReadBlob_fn));
82
82
  if (config.network && !config.packageConfig) {
@@ -95,9 +95,9 @@ const _WalrusClient = class _WalrusClient {
95
95
  __privateSet(this, _packageConfig, config.packageConfig);
96
96
  }
97
97
  __privateSet(this, _wasmUrl, config.wasmUrl);
98
- __privateSet(this, _fanOutConfig, config.fanOut ?? null);
99
- if (__privateGet(this, _fanOutConfig)) {
100
- __privateSet(this, _fanOutClient, new import_client3.FanOutProxyClient(__privateGet(this, _fanOutConfig)));
98
+ __privateSet(this, _uploadRelayConfig, config.uploadRelay ?? null);
99
+ if (__privateGet(this, _uploadRelayConfig)) {
100
+ __privateSet(this, _uploadRelayClient, new import_client3.UploadRelayClient(__privateGet(this, _uploadRelayConfig)));
101
101
  }
102
102
  __privateSet(this, _suiClient, config.suiClient ?? new import_client.SuiClient({
103
103
  url: config.suiRpcUrl
@@ -611,7 +611,7 @@ const _WalrusClient = class _WalrusClient {
611
611
  transaction.pure(authPayload);
612
612
  };
613
613
  }
614
- async calculateFanOutTip(options) {
614
+ async calculateUploadRelayTip(options) {
615
615
  const systemState = await this.systemState();
616
616
  const encodedSize = (0, import_utils2.encodedBlobLength)(options.size, systemState.committee.n_shards);
617
617
  const tipConfig = await __privateMethod(this, _WalrusClient_instances, loadTipConfig_fn).call(this);
@@ -619,7 +619,7 @@ const _WalrusClient = class _WalrusClient {
619
619
  return 0n;
620
620
  }
621
621
  const { max, kind } = tipConfig;
622
- const amount = "const" in kind ? kind.const : BigInt(kind.linear.base) + BigInt(kind.linear.perEncodedKb) * (BigInt(encodedSize) / 1024n);
622
+ const amount = "const" in kind ? kind.const : BigInt(kind.linear.base) + BigInt(kind.linear.perEncodedKib) * ((BigInt(encodedSize) + 1023n) / 1024n);
623
623
  if (max != null && amount > max) {
624
624
  throw new import_error.WalrusClientError(
625
625
  `Tip amount (${amount}) exceeds the maximum allowed tip (${max})`
@@ -627,7 +627,7 @@ const _WalrusClient = class _WalrusClient {
627
627
  }
628
628
  return amount;
629
629
  }
630
- sendFanOutTip({
630
+ sendUploadRelayTip({
631
631
  size,
632
632
  blobDigest,
633
633
  nonce
@@ -636,7 +636,7 @@ const _WalrusClient = class _WalrusClient {
636
636
  const tipConfig = await __privateMethod(this, _WalrusClient_instances, loadTipConfig_fn).call(this);
637
637
  if (tipConfig) {
638
638
  transaction.add(this.addAuthPayload({ size, blobDigest, nonce }));
639
- const amount = await this.calculateFanOutTip({ size });
639
+ const amount = await this.calculateUploadRelayTip({ size });
640
640
  const { address } = tipConfig;
641
641
  transaction.transferObjects(
642
642
  [
@@ -1196,20 +1196,20 @@ const _WalrusClient = class _WalrusClient {
1196
1196
  return confirmations;
1197
1197
  }
1198
1198
  /**
1199
- * Writes a blob to to a fan out proxy
1199
+ * Writes a blob to to an upload relay
1200
1200
  *
1201
1201
  * @usage
1202
1202
  * ```ts
1203
- * await client.writeBlobToFanOutProxy({ blob, deletable, epochs, signer });
1203
+ * await client.writeBlobToUploadRelay({ blob, deletable, epochs, signer });
1204
1204
  * ```
1205
1205
  */
1206
- async writeBlobToFanOutProxy(options) {
1207
- if (!__privateGet(this, _fanOutClient)) {
1208
- throw new import_error.WalrusClientError("Fan out proxy not configured");
1206
+ async writeBlobToUploadRelay(options) {
1207
+ if (!__privateGet(this, _uploadRelayClient)) {
1208
+ throw new import_error.WalrusClientError("Upload relay not configured");
1209
1209
  }
1210
- return __privateGet(this, _fanOutClient).writeBlob({
1210
+ return __privateGet(this, _uploadRelayClient).writeBlob({
1211
1211
  ...options,
1212
- requiresTip: !!__privateGet(this, _fanOutConfig)?.sendTip
1212
+ requiresTip: !!__privateGet(this, _uploadRelayConfig)?.sendTip
1213
1213
  });
1214
1214
  }
1215
1215
  /**
@@ -1258,7 +1258,7 @@ const _WalrusClient = class _WalrusClient {
1258
1258
  owner,
1259
1259
  attributes
1260
1260
  }) {
1261
- if (!__privateGet(this, _fanOutConfig)) {
1261
+ if (!__privateGet(this, _uploadRelayConfig)) {
1262
1262
  const encoded = await this.encodeBlob(blob);
1263
1263
  const blobId = encoded.blobId;
1264
1264
  const { sliversByNode, metadata: metadata2, rootHash } = encoded;
@@ -1299,7 +1299,7 @@ const _WalrusClient = class _WalrusClient {
1299
1299
  const blobId = metadata2.blobId;
1300
1300
  const transaction = new import_transactions.Transaction();
1301
1301
  transaction.add(
1302
- this.sendFanOutTip({
1302
+ this.sendUploadRelayTip({
1303
1303
  size: blob.length,
1304
1304
  blobDigest: metadata2.blobDigest,
1305
1305
  nonce: metadata2.nonce
@@ -1319,7 +1319,7 @@ const _WalrusClient = class _WalrusClient {
1319
1319
  await __privateGet(this, _suiClient).core.waitForTransaction({
1320
1320
  digest: registerResult.digest
1321
1321
  });
1322
- const result = await this.writeBlobToFanOutProxy({
1322
+ const result = await this.writeBlobToUploadRelay({
1323
1323
  blobId,
1324
1324
  blob,
1325
1325
  nonce: metadata2.nonce,
@@ -1365,8 +1365,8 @@ _objectLoader = new WeakMap();
1365
1365
  _blobMetadataConcurrencyLimit = new WeakMap();
1366
1366
  _readCommittee = new WeakMap();
1367
1367
  _cache = new WeakMap();
1368
- _fanOutConfig = new WeakMap();
1369
- _fanOutClient = new WeakMap();
1368
+ _uploadRelayConfig = new WeakMap();
1369
+ _uploadRelayClient = new WeakMap();
1370
1370
  _WalrusClient_instances = new WeakSet();
1371
1371
  /** The Move type for a WAL coin */
1372
1372
  walType_fn = function() {
@@ -1500,17 +1500,17 @@ withWal_fn = function(amount, owner, source, withSubsidies, fn) {
1500
1500
  };
1501
1501
  };
1502
1502
  loadTipConfig_fn = function() {
1503
- return __privateGet(this, _cache).read(["fanout-tip-config"], async () => {
1504
- if (!__privateGet(this, _fanOutConfig)?.sendTip || !__privateGet(this, _fanOutClient)) {
1503
+ return __privateGet(this, _cache).read(["upload-relay-tip-config"], async () => {
1504
+ if (!__privateGet(this, _uploadRelayConfig)?.sendTip || !__privateGet(this, _uploadRelayClient)) {
1505
1505
  return null;
1506
1506
  }
1507
- if ("kind" in __privateGet(this, _fanOutConfig).sendTip) {
1508
- return __privateGet(this, _fanOutConfig).sendTip;
1507
+ if ("kind" in __privateGet(this, _uploadRelayConfig).sendTip) {
1508
+ return __privateGet(this, _uploadRelayConfig).sendTip;
1509
1509
  }
1510
- const tipConfig = await __privateGet(this, _fanOutClient).tipConfig();
1510
+ const tipConfig = await __privateGet(this, _uploadRelayClient).tipConfig();
1511
1511
  return {
1512
1512
  ...tipConfig,
1513
- max: __privateGet(this, _fanOutConfig).sendTip.max
1513
+ max: __privateGet(this, _uploadRelayConfig).sendTip.max
1514
1514
  };
1515
1515
  });
1516
1516
  };