@mysten/walrus 0.8.5 → 0.9.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,25 @@
1
1
  # @mysten/walrus
2
2
 
3
+ ## 0.9.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 412ceb9: Upgrade wasm module to use pre-allocated array buffers and avoid decoding SliverData
8
+
9
+ ### Patch Changes
10
+
11
+ - 06d915f: Fix extending blobs
12
+ - 06d915f: Fix bug that could lead to infinite loop when encoding quilts
13
+ - Updated dependencies [412ceb9]
14
+ - @mysten/walrus-wasm@0.2.0
15
+
16
+ ## 0.8.6
17
+
18
+ ### Patch Changes
19
+
20
+ - Updated dependencies [29e8b92]
21
+ - @mysten/sui@1.45.2
22
+
3
23
  ## 0.8.5
4
24
 
5
25
  ### Patch Changes
@@ -3,8 +3,8 @@ import type { ClientWithCoreApi } from '@mysten/sui/experimental';
3
3
  import type { TransactionResult } from '@mysten/sui/transactions';
4
4
  import { Transaction } from '@mysten/sui/transactions';
5
5
  import { Blob } from './contracts/walrus/blob.js';
6
- import type { BlobStatus } from './storage-node/types.js';
7
- import type { CertifyBlobOptions, ComputeBlobMetadataOptions, DeleteBlobOptions, ExtendBlobOptions, GetBlobMetadataOptions, GetSecondarySliverOptions, GetSliversOptions, GetStorageConfirmationOptions, GetVerifiedBlobStatusOptions, ProtocolMessageCertificate, ReadBlobOptions, RegisterBlobOptions, SliversForNode, StorageWithSizeOptions, WalrusClientConfig, WalrusClientExtensionOptions, WriteBlobAttributesOptions, WriteBlobOptions, WriteBlobToUploadRelayOptions, WriteEncodedBlobOptions, WriteEncodedBlobToNodesOptions, WriteMetadataOptions, WriteQuiltOptions, WriteSliverOptions, WriteSliversToNodeOptions, WriteFilesOptions, WriteFilesFlowOptions, WriteFilesFlow, WriteBlobFlow, WriteBlobFlowOptions, WalrusOptions } from './types.js';
6
+ import type { BlobStatus, GetSliverResponse } from './storage-node/types.js';
7
+ import type { CertifyBlobOptions, ComputeBlobMetadataOptions, DeleteBlobOptions, EncodingType, ExtendBlobOptions, GetBlobMetadataOptions, GetSecondarySliverOptions, GetSliversOptions, GetStorageConfirmationOptions, GetVerifiedBlobStatusOptions, ProtocolMessageCertificate, ReadBlobOptions, RegisterBlobOptions, SliversForNode, StorageWithSizeOptions, WalrusClientConfig, WalrusClientExtensionOptions, WriteBlobAttributesOptions, WriteBlobOptions, WriteBlobToUploadRelayOptions, WriteEncodedBlobOptions, WriteEncodedBlobToNodesOptions, WriteMetadataOptions, WriteQuiltOptions, WriteSliverOptions, WriteSliversToNodeOptions, WriteFilesOptions, WriteFilesFlowOptions, WriteFilesFlow, WriteBlobFlow, WriteBlobFlowOptions, WalrusOptions } from './types.js';
8
8
  import { WalrusBlob } from './files/blob.js';
9
9
  import { WalrusFile } from './files/file.js';
10
10
  export declare function walrus<const Name = 'walrus'>({ packageConfig, network, name, ...options }?: WalrusOptions<Name>): {
@@ -148,22 +148,8 @@ export declare class WalrusClient {
148
148
  rootHash: Uint8Array<ArrayBufferLike>;
149
149
  blobId: string;
150
150
  metadata: {
151
- encodingType: "RedStuff" | "RS2" | {
152
- RedStuff: boolean | object | null;
153
- } | {
154
- RS2: boolean | object | null;
155
- };
156
- hashes: {
157
- primaryHash: import("@mysten/bcs").EnumInputShape<{
158
- Empty: boolean | object | null;
159
- Digest: Iterable<number>;
160
- }>;
161
- secondaryHash: import("@mysten/bcs").EnumInputShape<{
162
- Empty: boolean | object | null;
163
- Digest: Iterable<number>;
164
- }>;
165
- }[];
166
- unencodedLength: string | number | bigint;
151
+ encodingType: EncodingType;
152
+ unencodedLength: bigint;
167
153
  };
168
154
  nonce: Uint8Array<ArrayBuffer>;
169
155
  blobDigest: () => Promise<Uint8Array<ArrayBufferLike>>;
@@ -191,27 +177,9 @@ export declare class WalrusClient {
191
177
  $kind: "V1";
192
178
  };
193
179
  }>;
194
- getSecondarySliver: ({ blobId, index, signal }: GetSecondarySliverOptions) => Promise<{
195
- symbols: {
196
- data: Uint8Array<ArrayBufferLike>;
197
- symbol_size: number;
198
- };
199
- index: number;
200
- }>;
201
- internalGetSecondarySliver({ blobId, index, signal }: GetSecondarySliverOptions): Promise<{
202
- symbols: {
203
- data: Uint8Array<ArrayBufferLike>;
204
- symbol_size: number;
205
- };
206
- index: number;
207
- }>;
208
- getSlivers({ blobId, signal }: GetSliversOptions): Promise<{
209
- symbols: {
210
- data: Uint8Array<ArrayBufferLike>;
211
- symbol_size: number;
212
- };
213
- index: number;
214
- }[]>;
180
+ getSecondarySliver: ({ blobId, index, signal }: GetSecondarySliverOptions) => Promise<GetSliverResponse>;
181
+ internalGetSecondarySliver({ blobId, index, signal }: GetSecondarySliverOptions): Promise<GetSliverResponse>;
182
+ getSlivers({ blobId, signal }: GetSliversOptions): Promise<GetSliverResponse[]>;
215
183
  /**
216
184
  * Gets the blob status from multiple storage nodes and returns the latest status that can be verified.
217
185
  */
@@ -70,7 +70,7 @@ var import_file = require("./files/file.js");
70
70
  var import_quilt_file = require("./files/readers/quilt-file.js");
71
71
  var import_quilt = require("./files/readers/quilt.js");
72
72
  var import_retry = require("./utils/retry.js");
73
- var _storageNodeClient, _wasmUrl, _packageConfig, _suiClient, _objectLoader, _blobMetadataConcurrencyLimit, _readCommittee, _cache, _uploadRelayConfig, _uploadRelayClient, _WalrusClient_instances, walType_fn, getPackageId_fn, getWalrusPackageId_fn, wasmBindings_fn, internalReadBlob_fn, getCertificationEpoch_fn, getReadCommittee_fn, forceGetReadCommittee_fn, withWal_fn, loadTipConfig_fn, getCreatedBlob_fn, writeBlobAttributesForRef_fn, executeTransaction_fn, getCommittee_fn, getActiveCommittee_fn, stakingPool_fn, getNodeByShardIndex_fn, retryOnPossibleEpochChange_fn;
73
+ var _storageNodeClient, _wasmUrl, _packageConfig, _suiClient, _objectLoader, _blobMetadataConcurrencyLimit, _readCommittee, _cache, _uploadRelayConfig, _uploadRelayClient, _WalrusClient_instances, walType_fn, getPackageId_fn, getWalrusPackageId_fn, wasmBindings_fn, internalReadBlob_fn, getCertificationEpoch_fn, getReadCommittee_fn, forceGetReadCommittee_fn, storageCostFromEncodedSize_fn, withWal_fn, loadTipConfig_fn, getCreatedBlob_fn, writeBlobAttributesForRef_fn, executeTransaction_fn, getCommittee_fn, getActiveCommittee_fn, stakingPool_fn, getNodeByShardIndex_fn, retryOnPossibleEpochChange_fn;
74
74
  function walrus({
75
75
  packageConfig,
76
76
  network,
@@ -211,19 +211,18 @@ const _WalrusClient = class _WalrusClient {
211
211
  shardCount = systemState.committee.n_shards;
212
212
  }
213
213
  const bindings = await __privateMethod(this, _WalrusClient_instances, wasmBindings_fn).call(this);
214
- const { blobId, metadata: metadata2, rootHash } = bindings.computeMetadata(shardCount, bytes);
214
+ const { blobId, rootHash, unencodedLength, encodingType } = bindings.computeMetadata(
215
+ shardCount,
216
+ bytes
217
+ );
215
218
  let sha256Hash;
216
219
  const nonce = crypto.getRandomValues(new Uint8Array(32));
217
220
  return {
218
221
  rootHash,
219
222
  blobId,
220
223
  metadata: {
221
- encodingType: metadata2.V1.encoding_type,
222
- hashes: Array.from(metadata2.V1.hashes).map((hashes) => ({
223
- primaryHash: hashes.primary_hash,
224
- secondaryHash: hashes.secondary_hash
225
- })),
226
- unencodedLength: metadata2.V1.unencoded_length
224
+ encodingType,
225
+ unencodedLength
227
226
  },
228
227
  nonce,
229
228
  blobDigest: () => {
@@ -480,11 +479,7 @@ const _WalrusClient = class _WalrusClient {
480
479
  async storageCost(size, epochs) {
481
480
  const systemState = await this.systemState();
482
481
  const encodedSize = (0, import_utils2.encodedBlobLength)(size, systemState.committee.n_shards);
483
- const storageUnits = (0, import_utils2.storageUnitsFromSize)(encodedSize);
484
- const storageCost = BigInt(storageUnits) * BigInt(systemState.storage_price_per_unit_size) * BigInt(epochs);
485
- BigInt(epochs);
486
- const writeCost = BigInt(storageUnits) * BigInt(systemState.write_price_per_unit_size);
487
- return { storageCost, writeCost, totalCost: storageCost + writeCost };
482
+ return __privateMethod(this, _WalrusClient_instances, storageCostFromEncodedSize_fn).call(this, encodedSize, epochs);
488
483
  }
489
484
  /**
490
485
  * A utility for creating a storage object in a transaction.
@@ -921,7 +916,7 @@ const _WalrusClient = class _WalrusClient {
921
916
  if (numEpochs <= 0) {
922
917
  return;
923
918
  }
924
- const { storageCost } = await this.storageCost(Number(blob.storage.storage_size), numEpochs);
919
+ const { storageCost } = await __privateMethod(this, _WalrusClient_instances, storageCostFromEncodedSize_fn).call(this, Number(blob.storage.storage_size), numEpochs);
925
920
  const walrusPackageId = await __privateMethod(this, _WalrusClient_instances, getWalrusPackageId_fn).call(this);
926
921
  return tx.add(
927
922
  __privateMethod(this, _WalrusClient_instances, withWal_fn).call(this, storageCost, walCoin ?? null, async (coin, tx2) => {
@@ -1125,27 +1120,30 @@ const _WalrusClient = class _WalrusClient {
1125
1120
  const committee = await __privateMethod(this, _WalrusClient_instances, getActiveCommittee_fn).call(this);
1126
1121
  const numShards = systemState.committee.n_shards;
1127
1122
  const bindings = await __privateMethod(this, _WalrusClient_instances, wasmBindings_fn).call(this);
1128
- const { blobId, metadata: metadata2, sliverPairs, rootHash } = bindings.encodeBlob(numShards, blob);
1123
+ const { blobId, metadata: metadata2, primarySlivers, secondarySlivers, rootHash } = bindings.encodeBlob(
1124
+ numShards,
1125
+ blob
1126
+ );
1129
1127
  const sliversByNodeMap = /* @__PURE__ */ new Map();
1130
- while (sliverPairs.length > 0) {
1131
- const { primary, secondary } = sliverPairs.pop();
1132
- const sliverPairIndex = primary.index;
1128
+ for (let sliverPairIndex = 0; sliverPairIndex < primarySlivers.length; sliverPairIndex++) {
1129
+ const primarySliver = primarySlivers[sliverPairIndex];
1130
+ const secondarySliver = secondarySlivers[sliverPairIndex];
1133
1131
  const shardIndex = (0, import_utils2.toShardIndex)(sliverPairIndex, blobId, numShards);
1134
1132
  const node = await __privateMethod(this, _WalrusClient_instances, getNodeByShardIndex_fn).call(this, committee, shardIndex);
1135
1133
  if (!sliversByNodeMap.has(node.nodeIndex)) {
1136
1134
  sliversByNodeMap.set(node.nodeIndex, { primary: [], secondary: [] });
1137
1135
  }
1138
1136
  sliversByNodeMap.get(node.nodeIndex).primary.push({
1139
- sliverIndex: primary.index,
1137
+ sliverIndex: sliverPairIndex,
1140
1138
  sliverPairIndex,
1141
1139
  shardIndex,
1142
- sliver: import_bcs2.SliverData.serialize(primary).toBytes()
1140
+ sliver: primarySliver
1143
1141
  });
1144
1142
  sliversByNodeMap.get(node.nodeIndex).secondary.push({
1145
- sliverIndex: secondary.index,
1143
+ sliverIndex: sliverPairIndex,
1146
1144
  sliverPairIndex,
1147
1145
  shardIndex,
1148
- sliver: import_bcs2.SliverData.serialize(secondary).toBytes()
1146
+ sliver: secondarySliver
1149
1147
  });
1150
1148
  }
1151
1149
  const sliversByNode = new Array();
@@ -1897,6 +1895,13 @@ forceGetReadCommittee_fn = async function({ blobId, signal }) {
1897
1895
  }
1898
1896
  return await __privateMethod(this, _WalrusClient_instances, getActiveCommittee_fn).call(this);
1899
1897
  };
1898
+ storageCostFromEncodedSize_fn = async function(encodedSize, epochs) {
1899
+ const systemState = await this.systemState();
1900
+ const storageUnits = (0, import_utils2.storageUnitsFromSize)(encodedSize);
1901
+ const storageCost = BigInt(storageUnits) * BigInt(systemState.storage_price_per_unit_size) * BigInt(epochs);
1902
+ const writeCost = BigInt(storageUnits) * BigInt(systemState.write_price_per_unit_size);
1903
+ return { storageCost, writeCost, totalCost: storageCost + writeCost };
1904
+ };
1900
1905
  withWal_fn = function(amount, source, fn) {
1901
1906
  return async (tx) => {
1902
1907
  const walType = await __privateMethod(this, _WalrusClient_instances, walType_fn).call(this);