@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.
@@ -6,7 +6,7 @@ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read fr
6
6
  var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
7
7
  var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
8
8
  var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
9
- 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;
9
+ 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;
10
10
  import { bcs } from "@mysten/bcs";
11
11
  import { SuiClient } from "@mysten/sui/client";
12
12
  import { coinWithBalance, Transaction } from "@mysten/sui/transactions";
@@ -56,7 +56,7 @@ import {
56
56
  NotFoundError,
57
57
  UserAbortError
58
58
  } from "./storage-node/error.js";
59
- import { blobIdToInt, IntentType, SliverData, StorageConfirmation } from "./utils/bcs.js";
59
+ import { blobIdToInt, IntentType, StorageConfirmation } from "./utils/bcs.js";
60
60
  import {
61
61
  encodedBlobLength,
62
62
  getShardIndicesByNodeId,
@@ -221,19 +221,18 @@ const _WalrusClient = class _WalrusClient {
221
221
  shardCount = systemState.committee.n_shards;
222
222
  }
223
223
  const bindings = await __privateMethod(this, _WalrusClient_instances, wasmBindings_fn).call(this);
224
- const { blobId, metadata: metadata2, rootHash } = bindings.computeMetadata(shardCount, bytes);
224
+ const { blobId, rootHash, unencodedLength, encodingType } = bindings.computeMetadata(
225
+ shardCount,
226
+ bytes
227
+ );
225
228
  let sha256Hash;
226
229
  const nonce = crypto.getRandomValues(new Uint8Array(32));
227
230
  return {
228
231
  rootHash,
229
232
  blobId,
230
233
  metadata: {
231
- encodingType: metadata2.V1.encoding_type,
232
- hashes: Array.from(metadata2.V1.hashes).map((hashes) => ({
233
- primaryHash: hashes.primary_hash,
234
- secondaryHash: hashes.secondary_hash
235
- })),
236
- unencodedLength: metadata2.V1.unencoded_length
234
+ encodingType,
235
+ unencodedLength
237
236
  },
238
237
  nonce,
239
238
  blobDigest: () => {
@@ -490,11 +489,7 @@ const _WalrusClient = class _WalrusClient {
490
489
  async storageCost(size, epochs) {
491
490
  const systemState = await this.systemState();
492
491
  const encodedSize = encodedBlobLength(size, systemState.committee.n_shards);
493
- const storageUnits = storageUnitsFromSize(encodedSize);
494
- const storageCost = BigInt(storageUnits) * BigInt(systemState.storage_price_per_unit_size) * BigInt(epochs);
495
- BigInt(epochs);
496
- const writeCost = BigInt(storageUnits) * BigInt(systemState.write_price_per_unit_size);
497
- return { storageCost, writeCost, totalCost: storageCost + writeCost };
492
+ return __privateMethod(this, _WalrusClient_instances, storageCostFromEncodedSize_fn).call(this, encodedSize, epochs);
498
493
  }
499
494
  /**
500
495
  * A utility for creating a storage object in a transaction.
@@ -931,7 +926,7 @@ const _WalrusClient = class _WalrusClient {
931
926
  if (numEpochs <= 0) {
932
927
  return;
933
928
  }
934
- const { storageCost } = await this.storageCost(Number(blob.storage.storage_size), numEpochs);
929
+ const { storageCost } = await __privateMethod(this, _WalrusClient_instances, storageCostFromEncodedSize_fn).call(this, Number(blob.storage.storage_size), numEpochs);
935
930
  const walrusPackageId = await __privateMethod(this, _WalrusClient_instances, getWalrusPackageId_fn).call(this);
936
931
  return tx.add(
937
932
  __privateMethod(this, _WalrusClient_instances, withWal_fn).call(this, storageCost, walCoin ?? null, async (coin, tx2) => {
@@ -1135,27 +1130,30 @@ const _WalrusClient = class _WalrusClient {
1135
1130
  const committee = await __privateMethod(this, _WalrusClient_instances, getActiveCommittee_fn).call(this);
1136
1131
  const numShards = systemState.committee.n_shards;
1137
1132
  const bindings = await __privateMethod(this, _WalrusClient_instances, wasmBindings_fn).call(this);
1138
- const { blobId, metadata: metadata2, sliverPairs, rootHash } = bindings.encodeBlob(numShards, blob);
1133
+ const { blobId, metadata: metadata2, primarySlivers, secondarySlivers, rootHash } = bindings.encodeBlob(
1134
+ numShards,
1135
+ blob
1136
+ );
1139
1137
  const sliversByNodeMap = /* @__PURE__ */ new Map();
1140
- while (sliverPairs.length > 0) {
1141
- const { primary, secondary } = sliverPairs.pop();
1142
- const sliverPairIndex = primary.index;
1138
+ for (let sliverPairIndex = 0; sliverPairIndex < primarySlivers.length; sliverPairIndex++) {
1139
+ const primarySliver = primarySlivers[sliverPairIndex];
1140
+ const secondarySliver = secondarySlivers[sliverPairIndex];
1143
1141
  const shardIndex = toShardIndex(sliverPairIndex, blobId, numShards);
1144
1142
  const node = await __privateMethod(this, _WalrusClient_instances, getNodeByShardIndex_fn).call(this, committee, shardIndex);
1145
1143
  if (!sliversByNodeMap.has(node.nodeIndex)) {
1146
1144
  sliversByNodeMap.set(node.nodeIndex, { primary: [], secondary: [] });
1147
1145
  }
1148
1146
  sliversByNodeMap.get(node.nodeIndex).primary.push({
1149
- sliverIndex: primary.index,
1147
+ sliverIndex: sliverPairIndex,
1150
1148
  sliverPairIndex,
1151
1149
  shardIndex,
1152
- sliver: SliverData.serialize(primary).toBytes()
1150
+ sliver: primarySliver
1153
1151
  });
1154
1152
  sliversByNodeMap.get(node.nodeIndex).secondary.push({
1155
- sliverIndex: secondary.index,
1153
+ sliverIndex: sliverPairIndex,
1156
1154
  sliverPairIndex,
1157
1155
  shardIndex,
1158
- sliver: SliverData.serialize(secondary).toBytes()
1156
+ sliver: secondarySliver
1159
1157
  });
1160
1158
  }
1161
1159
  const sliversByNode = new Array();
@@ -1907,6 +1905,13 @@ forceGetReadCommittee_fn = async function({ blobId, signal }) {
1907
1905
  }
1908
1906
  return await __privateMethod(this, _WalrusClient_instances, getActiveCommittee_fn).call(this);
1909
1907
  };
1908
+ storageCostFromEncodedSize_fn = async function(encodedSize, epochs) {
1909
+ const systemState = await this.systemState();
1910
+ const storageUnits = storageUnitsFromSize(encodedSize);
1911
+ const storageCost = BigInt(storageUnits) * BigInt(systemState.storage_price_per_unit_size) * BigInt(epochs);
1912
+ const writeCost = BigInt(storageUnits) * BigInt(systemState.write_price_per_unit_size);
1913
+ return { storageCost, writeCost, totalCost: storageCost + writeCost };
1914
+ };
1910
1915
  withWal_fn = function(amount, source, fn) {
1911
1916
  return async (tx) => {
1912
1917
  const walType = await __privateMethod(this, _WalrusClient_instances, walType_fn).call(this);