@mysten/walrus 0.0.12 → 0.0.14

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,22 @@
1
1
  # @mysten/walrus
2
2
 
3
+ ## 0.0.14
4
+
5
+ ### Patch Changes
6
+
7
+ - 4d13ef8: Implement experimental client extension support
8
+ - Updated dependencies [4d13ef8]
9
+ - Updated dependencies [4d13ef8]
10
+ - @mysten/sui@1.27.0
11
+
12
+ ## 0.0.13
13
+
14
+ ### Patch Changes
15
+
16
+ - 4389b36: Add support for customizing wasm url
17
+ - Updated dependencies [4389b36]
18
+ - @mysten/walrus-wasm@0.0.5
19
+
3
20
  ## 0.0.12
4
21
 
5
22
  ### Patch Changes
package/README.md CHANGED
@@ -180,6 +180,37 @@ const walrusClient = new WalrusClient({
180
180
  });
181
181
  ```
182
182
 
183
+ ### Loading the wasm module in vite or client side apps
184
+
185
+ The walrus SDK requires wasm bindings to encode and decode blobs. When running in node or bun and
186
+ some bundlers this will work without any additional configuration.
187
+
188
+ In some cases you may need to manually specify where the SDK loads the wasm bindings from.
189
+
190
+ In vite you can get the url for the wasm bindings by importing the wasm file with a `?url` suffix,
191
+ and then passed into the walrus client:
192
+
193
+ ```ts
194
+ import walrusWasmUrl from '@mysten/walrus-wasm/web/walrus_wasm_bg.wasm?url';
195
+
196
+ const walrusClient = new WalrusClient({
197
+ network: 'testnet',
198
+ suiClient,
199
+ wasmUrl: walrusWasmUrl,
200
+ });
201
+ ```
202
+
203
+ If you are unable to get a url for the wasm file in your bundler or build system, you can self host
204
+ the wasm bindings, or load them from a CDN:
205
+
206
+ ```ts
207
+ const walrusClient = new WalrusClient({
208
+ network: 'testnet',
209
+ suiClient,
210
+ wasmUrl: 'https://unpkg.com/@mysten/walrus-wasm@latest/web/walrus_wasm_bg.wasm',
211
+ });
212
+ ```
213
+
183
214
  ### Known fetch limitations you might run into
184
215
 
185
216
  - Some nodes can be slow to respond. When running in node, the default connectTimeout is 10 seconds
@@ -1,13 +1,21 @@
1
+ import { SuiClient } from '@mysten/sui/client';
1
2
  import type { Signer } from '@mysten/sui/cryptography';
3
+ import type { ClientWithExtensions } from '@mysten/sui/experimental';
2
4
  import { Transaction } from '@mysten/sui/transactions';
3
5
  import { Blob } from './contracts/blob.js';
4
6
  import type { BlobStatus } from './storage-node/types.js';
5
- import type { CertifyBlobOptions, DeleteBlobOptions, ExtendBlobOptions, GetBlobMetadataOptions, GetSliversOptions, GetStorageConfirmationOptions, GetVerifiedBlobStatusOptions, ReadBlobOptions, RegisterBlobOptions, SliversForNode, StorageWithSizeOptions, WalrusClientConfig, WriteBlobAttributesOptions, WriteBlobOptions, WriteEncodedBlobOptions, WriteEncodedBlobToNodesOptions, WriteMetadataOptions, WriteSliverOptions, WriteSliversToNodeOptions } from './types.js';
7
+ import type { CertifyBlobOptions, DeleteBlobOptions, ExtendBlobOptions, GetBlobMetadataOptions, GetSliversOptions, GetStorageConfirmationOptions, GetVerifiedBlobStatusOptions, ReadBlobOptions, RegisterBlobOptions, SliversForNode, StorageWithSizeOptions, WalrusClientConfig, WalrusClientExtensionOptions, WriteBlobAttributesOptions, WriteBlobOptions, WriteEncodedBlobOptions, WriteEncodedBlobToNodesOptions, WriteMetadataOptions, WriteSliverOptions, WriteSliversToNodeOptions } from './types.js';
6
8
  export declare class WalrusClient {
7
9
  #private;
8
10
  constructor(config: WalrusClientConfig);
11
+ static experimental_asClientExtension({ packageConfig, network, ...options }?: WalrusClientExtensionOptions): {
12
+ name: "walrus";
13
+ register: (client: ClientWithExtensions<{
14
+ jsonRpc: SuiClient;
15
+ }>) => WalrusClient;
16
+ };
9
17
  /** The Move type for a Blob object */
10
- getBlobType: () => string | Promise<string>;
18
+ getBlobType(): string | Promise<string>;
11
19
  /** The cached system object for the walrus package */
12
20
  systemObject(): Promise<{
13
21
  id: {
@@ -48,73 +48,23 @@ var import_client2 = require("./storage-node/client.js");
48
48
  var import_error2 = require("./storage-node/error.js");
49
49
  var import_bcs2 = require("./utils/bcs.js");
50
50
  var import_utils2 = require("./utils/index.js");
51
- var import_memo = require("./utils/memo.js");
52
51
  var import_object_loader = require("./utils/object-loader.js");
53
52
  var import_randomness = require("./utils/randomness.js");
54
53
  var import_wasm = require("./wasm.js");
55
- var _storageNodeClient, _packageConfig, _suiClient, _objectLoader, _blobMetadataConcurrencyLimit, _readCommittee, _memo, _walType, _getPackageId, _getSystemContract, _getSubsidiesContract, _getBlobContract, _getMetadataContract, _WalrusClient_instances, internalReadBlob_fn, getCertificationEpoch_fn, getReadCommittee_fn, forceGetReadCommittee_fn, withWal_fn, writeBlobAttributesForRef_fn, executeTransaction_fn, getCommittee_fn, _getActiveCommittee, stakingPool_fn, getNodeByShardIndex_fn, retryOnPossibleEpochChange_fn;
56
- class WalrusClient {
54
+ var _storageNodeClient, _wasmUrl, _packageConfig, _suiClient, _objectLoader, _blobMetadataConcurrencyLimit, _readCommittee, _cache, _WalrusClient_instances, walType_fn, getPackageId_fn, getSystemContract_fn, getSubsidiesContract_fn, getBlobContract_fn, getMetadataContract_fn, wasmBindings_fn, internalReadBlob_fn, getCertificationEpoch_fn, getReadCommittee_fn, forceGetReadCommittee_fn, withWal_fn, writeBlobAttributesForRef_fn, executeTransaction_fn, getCommittee_fn, getActiveCommittee_fn, stakingPool_fn, getNodeByShardIndex_fn, retryOnPossibleEpochChange_fn;
55
+ const _WalrusClient = class _WalrusClient {
57
56
  constructor(config) {
58
57
  __privateAdd(this, _WalrusClient_instances);
59
58
  __privateAdd(this, _storageNodeClient);
59
+ __privateAdd(this, _wasmUrl);
60
60
  __privateAdd(this, _packageConfig);
61
61
  __privateAdd(this, _suiClient);
62
62
  __privateAdd(this, _objectLoader);
63
63
  __privateAdd(this, _blobMetadataConcurrencyLimit, 10);
64
64
  __privateAdd(this, _readCommittee);
65
- __privateAdd(this, _memo, new import_memo.MemoCache());
66
- /** The Move type for a WAL coin */
67
- __privateAdd(this, _walType, __privateGet(this, _memo).create("walType", async () => {
68
- const stakedWal = await __privateGet(this, _suiClient).getNormalizedMoveStruct({
69
- package: await __privateGet(this, _getPackageId).call(this),
70
- module: "staked_wal",
71
- struct: "StakedWal"
72
- });
73
- const balanceType = stakedWal.fields.find((field) => field.name === "principal")?.type;
74
- if (!balanceType) {
75
- throw new import_error.WalrusClientError("WAL type not found");
76
- }
77
- const parsed = (0, import_utils.parseStructTag)((0, import_utils2.toTypeString)(balanceType));
78
- const coinType = parsed.typeParams[0];
79
- if (!coinType) {
80
- throw new import_error.WalrusClientError("WAL type not found");
81
- }
82
- return (0, import_utils.normalizeStructTag)(coinType);
83
- }));
84
- __privateAdd(this, _getPackageId, __privateGet(this, _memo).create("getPackageId", async () => {
85
- const system = await __privateGet(this, _objectLoader).load(__privateGet(this, _packageConfig).systemObjectId);
86
- return (0, import_utils.parseStructTag)(system.type).address;
87
- }));
88
- /** The Move type for a Blob object */
89
- this.getBlobType = __privateGet(this, _memo).create("getBlobType", async () => {
90
- return `${await __privateGet(this, _getPackageId).call(this)}::blob::Blob`;
91
- });
92
- __privateAdd(this, _getSystemContract, __privateGet(this, _memo).create("getSystemContract", async () => {
93
- const { package_id } = await this.systemObject();
94
- return (0, import_system.init)(package_id);
95
- }));
96
- __privateAdd(this, _getSubsidiesContract, __privateGet(this, _memo).create("getSubsidiesContract", async () => {
97
- if (!__privateGet(this, _packageConfig).subsidiesObjectId) {
98
- throw new import_error.WalrusClientError("Subsidies object ID not defined in package config");
99
- }
100
- const subsidiesObject = await __privateGet(this, _objectLoader).load(__privateGet(this, _packageConfig).subsidiesObjectId);
101
- const packageId = (0, import_utils.parseStructTag)(subsidiesObject.type).address;
102
- return (0, import_subsidies.init)(packageId);
103
- }));
104
- __privateAdd(this, _getBlobContract, __privateGet(this, _memo).create("getBlobContract", async () => {
105
- const { package_id } = await this.systemObject();
106
- return (0, import_blob.init)(package_id);
107
- }));
108
- __privateAdd(this, _getMetadataContract, __privateGet(this, _memo).create("getMetadataContract", async () => {
109
- const { package_id } = await this.systemObject();
110
- return (0, import_metadata.init)(package_id);
111
- }));
65
+ __privateAdd(this, _cache);
112
66
  /** Read a blob from the storage nodes */
113
67
  this.readBlob = __privateMethod(this, _WalrusClient_instances, retryOnPossibleEpochChange_fn).call(this, __privateMethod(this, _WalrusClient_instances, internalReadBlob_fn));
114
- __privateAdd(this, _getActiveCommittee, __privateGet(this, _memo).create("getActiveCommittee", async () => {
115
- const stakingState = await this.stakingState();
116
- return __privateMethod(this, _WalrusClient_instances, getCommittee_fn).call(this, stakingState.committee);
117
- }));
118
68
  if (config.network && !config.packageConfig) {
119
69
  const network = config.network;
120
70
  switch (network) {
@@ -130,11 +80,45 @@ class WalrusClient {
130
80
  } else {
131
81
  __privateSet(this, _packageConfig, config.packageConfig);
132
82
  }
83
+ __privateSet(this, _wasmUrl, config.wasmUrl);
133
84
  __privateSet(this, _suiClient, config.suiClient ?? new import_client.SuiClient({
134
85
  url: config.suiRpcUrl
135
86
  }));
136
87
  __privateSet(this, _storageNodeClient, new import_client2.StorageNodeClient(config.storageNodeClientOptions));
137
88
  __privateSet(this, _objectLoader, new import_object_loader.SuiObjectDataLoader(__privateGet(this, _suiClient)));
89
+ __privateSet(this, _cache, __privateGet(this, _suiClient).cache.scope("@mysten/walrus"));
90
+ }
91
+ static experimental_asClientExtension({
92
+ packageConfig,
93
+ network,
94
+ ...options
95
+ } = {}) {
96
+ return {
97
+ name: "walrus",
98
+ register: (client) => {
99
+ const walrusNetwork = network || client.network;
100
+ if (walrusNetwork !== "mainnet" && walrusNetwork !== "testnet") {
101
+ throw new import_error.WalrusClientError("Walrus client only supports mainnet and testnet");
102
+ }
103
+ return new _WalrusClient(
104
+ packageConfig ? {
105
+ packageConfig,
106
+ suiClient: client,
107
+ ...options
108
+ } : {
109
+ network: walrusNetwork,
110
+ suiClient: client,
111
+ ...options
112
+ }
113
+ );
114
+ }
115
+ };
116
+ }
117
+ /** The Move type for a Blob object */
118
+ getBlobType() {
119
+ return __privateGet(this, _cache).read(["getBlobType"], async () => {
120
+ return `${await __privateMethod(this, _WalrusClient_instances, getPackageId_fn).call(this)}::blob::Blob`;
121
+ });
138
122
  }
139
123
  /** The cached system object for the walrus package */
140
124
  systemObject() {
@@ -310,7 +294,7 @@ class WalrusClient {
310
294
  * Gets the blob status from multiple storage nodes and returns the latest status that can be verified.
311
295
  */
312
296
  async getVerifiedBlobStatus({ blobId, signal }) {
313
- const committee = await __privateGet(this, _getActiveCommittee).call(this);
297
+ const committee = await __privateMethod(this, _WalrusClient_instances, getActiveCommittee_fn).call(this);
314
298
  const stakingState = await this.stakingState();
315
299
  const numShards = stakingState.n_shards;
316
300
  const controller = new AbortController();
@@ -410,8 +394,8 @@ class WalrusClient {
410
394
  const systemState = await this.systemState();
411
395
  const encodedSize = (0, import_utils2.encodedBlobLength)(size, systemState.committee.n_shards);
412
396
  const { storageCost } = await this.storageCost(size, epochs);
413
- const systemContract = await __privateGet(this, _getSystemContract).call(this);
414
- const subsidiesContract = __privateGet(this, _packageConfig).subsidiesObjectId ? await __privateGet(this, _getSubsidiesContract).call(this) : null;
397
+ const systemContract = await __privateMethod(this, _WalrusClient_instances, getSystemContract_fn).call(this);
398
+ const subsidiesContract = __privateGet(this, _packageConfig).subsidiesObjectId ? await __privateMethod(this, _WalrusClient_instances, getSubsidiesContract_fn).call(this) : null;
415
399
  return __privateMethod(this, _WalrusClient_instances, withWal_fn).call(this, storageCost, owner, walCoin ?? null, subsidiesContract !== null, (coin, tx) => {
416
400
  return tx.add(
417
401
  subsidiesContract ? subsidiesContract.reserve_space({
@@ -463,21 +447,19 @@ class WalrusClient {
463
447
  });
464
448
  const blobType = await this.getBlobType();
465
449
  const { digest, effects } = await __privateMethod(this, _WalrusClient_instances, executeTransaction_fn).call(this, transaction, signer, "create storage");
466
- const createdObjectIds = effects?.created?.map((effect) => effect.reference.objectId) ?? [];
467
- const createdObjects = await __privateGet(this, _suiClient).multiGetObjects({
468
- ids: createdObjectIds,
469
- options: {
470
- showType: true,
471
- showBcs: true
472
- }
450
+ const createdObjectIds = effects?.changedObjects.filter((object) => object.idOperation === "Created").map((object) => object.id);
451
+ const createdObjects = await __privateGet(this, _suiClient).core.getObjects({
452
+ objectIds: createdObjectIds
473
453
  });
474
- const suiBlobObject = createdObjects.find((object) => object.data?.type === blobType);
475
- if (!suiBlobObject || suiBlobObject.data?.bcs?.dataType !== "moveObject") {
454
+ const suiBlobObject = createdObjects.objects.find(
455
+ (object) => !(object instanceof Error) && object.type === blobType
456
+ );
457
+ if (suiBlobObject instanceof Error || !suiBlobObject) {
476
458
  throw new import_error.WalrusClientError("Storage object not found in transaction effects");
477
459
  }
478
460
  return {
479
461
  digest,
480
- storage: (0, import_storage_resource.Storage)().fromBase64(suiBlobObject.data.bcs.bcsBytes)
462
+ storage: (0, import_storage_resource.Storage)().parse(suiBlobObject.content)
481
463
  };
482
464
  }
483
465
  /**
@@ -500,7 +482,7 @@ class WalrusClient {
500
482
  }) {
501
483
  const storage = await this.createStorage({ size, epochs, walCoin, owner });
502
484
  const { writeCost } = await this.storageCost(size, epochs);
503
- const systemContract = await __privateGet(this, _getSystemContract).call(this);
485
+ const systemContract = await __privateMethod(this, _WalrusClient_instances, getSystemContract_fn).call(this);
504
486
  const writeAttributes = attributes ? await __privateMethod(this, _WalrusClient_instances, writeBlobAttributesForRef_fn).call(this, {
505
487
  attributes,
506
488
  existingAttributes: null
@@ -560,21 +542,19 @@ class WalrusClient {
560
542
  });
561
543
  const blobType = await this.getBlobType();
562
544
  const { digest, effects } = await __privateMethod(this, _WalrusClient_instances, executeTransaction_fn).call(this, transaction, signer, "register blob");
563
- const createdObjectIds = effects?.created?.map((effect) => effect.reference.objectId) ?? [];
564
- const createdObjects = await __privateGet(this, _suiClient).multiGetObjects({
565
- ids: createdObjectIds,
566
- options: {
567
- showType: true,
568
- showBcs: true
569
- }
545
+ const createdObjectIds = effects?.changedObjects.filter((object) => object.idOperation === "Created").map((object) => object.id);
546
+ const createdObjects = await __privateGet(this, _suiClient).core.getObjects({
547
+ objectIds: createdObjectIds
570
548
  });
571
- const suiBlobObject = createdObjects.find((object) => object.data?.type === blobType);
572
- if (!suiBlobObject || suiBlobObject.data?.bcs?.dataType !== "moveObject") {
549
+ const suiBlobObject = createdObjects.objects.find(
550
+ (object) => !(object instanceof Error) && object.type === blobType
551
+ );
552
+ if (suiBlobObject instanceof Error || !suiBlobObject) {
573
553
  throw new import_error.WalrusClientError("Blob object not found in transaction effects");
574
554
  }
575
555
  return {
576
556
  digest,
577
- blob: (0, import_blob.Blob)().fromBase64(suiBlobObject.data.bcs.bcsBytes)
557
+ blob: (0, import_blob.Blob)().parse(suiBlobObject.content)
578
558
  };
579
559
  }
580
560
  /**
@@ -587,7 +567,7 @@ class WalrusClient {
587
567
  */
588
568
  async certifyBlob({ blobId, blobObjectId, confirmations, deletable }) {
589
569
  const systemState = await this.systemState();
590
- const committee = await __privateGet(this, _getActiveCommittee).call(this);
570
+ const committee = await __privateMethod(this, _WalrusClient_instances, getActiveCommittee_fn).call(this);
591
571
  if (confirmations.length !== systemState.committee.members.length) {
592
572
  throw new import_error.WalrusClientError(
593
573
  "Invalid number of confirmations. Confirmations array must contain an entry for each node"
@@ -607,7 +587,8 @@ class WalrusClient {
607
587
  }
608
588
  }
609
589
  }).toBase64();
610
- const verifySignature = await (0, import_wasm.getVerifySignature)();
590
+ const bindings = await __privateMethod(this, _WalrusClient_instances, wasmBindings_fn).call(this);
591
+ const verifySignature = bindings.getVerifySignature();
611
592
  const filteredConfirmations = confirmations.map((confirmation, index) => {
612
593
  const isValid = confirmation?.serializedMessage === confirmationMessage && verifySignature(
613
594
  confirmation,
@@ -623,11 +604,11 @@ class WalrusClient {
623
604
  `Too many invalid confirmations received for blob (${filteredConfirmations.length} of ${systemState.committee.members.length})`
624
605
  );
625
606
  }
626
- const combinedSignature = await (0, import_wasm.combineSignatures)(
607
+ const combinedSignature = bindings.combineSignatures(
627
608
  filteredConfirmations,
628
609
  filteredConfirmations.map(({ index }) => index)
629
610
  );
630
- const systemContract = await __privateGet(this, _getSystemContract).call(this);
611
+ const systemContract = await __privateMethod(this, _WalrusClient_instances, getSystemContract_fn).call(this);
631
612
  return (tx) => {
632
613
  tx.add(
633
614
  systemContract.certify_blob({
@@ -689,7 +670,7 @@ class WalrusClient {
689
670
  * ```
690
671
  */
691
672
  async deleteBlob({ blobObjectId }) {
692
- const systemContract = await __privateGet(this, _getSystemContract).call(this);
673
+ const systemContract = await __privateMethod(this, _WalrusClient_instances, getSystemContract_fn).call(this);
693
674
  return (tx) => {
694
675
  const storage = tx.add(
695
676
  systemContract.delete_blob({
@@ -752,8 +733,8 @@ class WalrusClient {
752
733
  };
753
734
  }
754
735
  const { storageCost } = await this.storageCost(Number(blob.storage.storage_size), numEpochs);
755
- const systemContract = await __privateGet(this, _getSystemContract).call(this);
756
- const subsidiesContract = __privateGet(this, _packageConfig).subsidiesObjectId ? await __privateGet(this, _getSubsidiesContract).call(this) : null;
736
+ const systemContract = await __privateMethod(this, _WalrusClient_instances, getSystemContract_fn).call(this);
737
+ const subsidiesContract = __privateGet(this, _packageConfig).subsidiesObjectId ? await __privateMethod(this, _WalrusClient_instances, getSubsidiesContract_fn).call(this) : null;
757
738
  return __privateMethod(this, _WalrusClient_instances, withWal_fn).call(this, storageCost, owner, walCoin ?? null, subsidiesContract !== null, (coin, tx) => {
758
739
  tx.add(
759
740
  subsidiesContract ? subsidiesContract.extend_blob({
@@ -803,23 +784,15 @@ class WalrusClient {
803
784
  async readBlobAttributes({
804
785
  blobObjectId
805
786
  }) {
806
- const response = await __privateGet(this, _suiClient).getDynamicFieldObject({
787
+ const response = await __privateGet(this, _suiClient).core.getDynamicField({
807
788
  parentId: blobObjectId,
808
789
  name: {
809
790
  type: "vector<u8>",
810
- value: [...new TextEncoder().encode("metadata")]
791
+ bcs: import_bcs.bcs.string().serialize("metadata").toBytes()
811
792
  }
812
793
  });
813
- if (response.error?.code === "dynamicFieldNotFound") {
814
- return null;
815
- }
816
- if (response.error || !response.data) {
817
- throw new import_error.WalrusClientError(
818
- `Failed to fetch metadata for object ${blobObjectId}: ${response.error}`
819
- );
820
- }
821
- const metadata = response.data.content.fields.value.fields.metadata.fields.contents;
822
- return Object.fromEntries(metadata.map(({ fields: { key, value } }) => [key, value]));
794
+ const metadata = (0, import_metadata.Metadata)().parse(response.dynamicField.value.bcs);
795
+ return Object.fromEntries(metadata.metadata.contents.map(({ key, value }) => [key, value]));
823
796
  }
824
797
  /**
825
798
  * Write attributes to a blob
@@ -889,7 +862,7 @@ class WalrusClient {
889
862
  */
890
863
  async writeSliver({ blobId, sliverPairIndex, sliverType, sliver, signal }) {
891
864
  const systemState = await this.systemState();
892
- const committee = await __privateGet(this, _getActiveCommittee).call(this);
865
+ const committee = await __privateMethod(this, _WalrusClient_instances, getActiveCommittee_fn).call(this);
893
866
  const shardIndex = (0, import_utils2.toShardIndex)(sliverPairIndex, blobId, systemState.committee.n_shards);
894
867
  const node = await __privateMethod(this, _WalrusClient_instances, getNodeByShardIndex_fn).call(this, committee, shardIndex);
895
868
  return await __privateGet(this, _storageNodeClient).storeSliver(
@@ -906,7 +879,7 @@ class WalrusClient {
906
879
  * ```
907
880
  */
908
881
  async writeMetadataToNode({ nodeIndex, blobId, metadata, signal }) {
909
- const committee = await __privateGet(this, _getActiveCommittee).call(this);
882
+ const committee = await __privateMethod(this, _WalrusClient_instances, getActiveCommittee_fn).call(this);
910
883
  const node = committee.nodes[nodeIndex];
911
884
  return await __privateGet(this, _storageNodeClient).storeBlobMetadata(
912
885
  { blobId, metadata },
@@ -928,7 +901,7 @@ class WalrusClient {
928
901
  objectId,
929
902
  signal
930
903
  }) {
931
- const committee = await __privateGet(this, _getActiveCommittee).call(this);
904
+ const committee = await __privateMethod(this, _WalrusClient_instances, getActiveCommittee_fn).call(this);
932
905
  const node = committee.nodes[nodeIndex];
933
906
  const result = deletable ? await __privateGet(this, _storageNodeClient).getDeletableBlobConfirmation(
934
907
  { blobId, objectId },
@@ -949,9 +922,10 @@ class WalrusClient {
949
922
  */
950
923
  async encodeBlob(blob) {
951
924
  const systemState = await this.systemState();
952
- const committee = await __privateGet(this, _getActiveCommittee).call(this);
925
+ const committee = await __privateMethod(this, _WalrusClient_instances, getActiveCommittee_fn).call(this);
953
926
  const numShards = systemState.committee.n_shards;
954
- const { blobId, metadata, sliverPairs, rootHash } = await (0, import_wasm.encodeBlob)(numShards, blob);
927
+ const bindings = await __privateMethod(this, _WalrusClient_instances, wasmBindings_fn).call(this);
928
+ const { blobId, metadata, sliverPairs, rootHash } = bindings.encodeBlob(numShards, blob);
955
929
  const sliversByNodeMap = /* @__PURE__ */ new Map();
956
930
  while (sliverPairs.length > 0) {
957
931
  const { primary, secondary } = sliverPairs.pop();
@@ -1030,7 +1004,7 @@ class WalrusClient {
1030
1004
  ...options
1031
1005
  }) {
1032
1006
  const systemState = await this.systemState();
1033
- const committee = await __privateGet(this, _getActiveCommittee).call(this);
1007
+ const committee = await __privateMethod(this, _WalrusClient_instances, getActiveCommittee_fn).call(this);
1034
1008
  const controller = new AbortController();
1035
1009
  let failures = 0;
1036
1010
  const confirmations = await Promise.all(
@@ -1144,36 +1118,93 @@ class WalrusClient {
1144
1118
  */
1145
1119
  reset() {
1146
1120
  __privateGet(this, _objectLoader).clearAll();
1147
- __privateSet(this, _readCommittee, null);
1148
- __privateGet(this, _memo).reset();
1121
+ __privateGet(this, _cache).clear();
1149
1122
  }
1150
- }
1123
+ };
1151
1124
  _storageNodeClient = new WeakMap();
1125
+ _wasmUrl = new WeakMap();
1152
1126
  _packageConfig = new WeakMap();
1153
1127
  _suiClient = new WeakMap();
1154
1128
  _objectLoader = new WeakMap();
1155
1129
  _blobMetadataConcurrencyLimit = new WeakMap();
1156
1130
  _readCommittee = new WeakMap();
1157
- _memo = new WeakMap();
1158
- _walType = new WeakMap();
1159
- _getPackageId = new WeakMap();
1160
- _getSystemContract = new WeakMap();
1161
- _getSubsidiesContract = new WeakMap();
1162
- _getBlobContract = new WeakMap();
1163
- _getMetadataContract = new WeakMap();
1131
+ _cache = new WeakMap();
1164
1132
  _WalrusClient_instances = new WeakSet();
1133
+ /** The Move type for a WAL coin */
1134
+ walType_fn = function() {
1135
+ return __privateGet(this, _cache).read(["walType"], async () => {
1136
+ const stakedWal = await __privateGet(this, _suiClient).jsonRpc.getNormalizedMoveStruct({
1137
+ package: await __privateMethod(this, _WalrusClient_instances, getPackageId_fn).call(this),
1138
+ module: "staked_wal",
1139
+ struct: "StakedWal"
1140
+ });
1141
+ const balanceType = stakedWal.fields.find((field) => field.name === "principal")?.type;
1142
+ if (!balanceType) {
1143
+ throw new import_error.WalrusClientError("WAL type not found");
1144
+ }
1145
+ const parsed = (0, import_utils.parseStructTag)((0, import_utils2.toTypeString)(balanceType));
1146
+ const coinType = parsed.typeParams[0];
1147
+ if (!coinType) {
1148
+ throw new import_error.WalrusClientError("WAL type not found");
1149
+ }
1150
+ return (0, import_utils.normalizeStructTag)(coinType);
1151
+ });
1152
+ };
1153
+ getPackageId_fn = function() {
1154
+ return __privateGet(this, _cache).read(["getPackageId"], async () => {
1155
+ const system = await __privateGet(this, _objectLoader).load(__privateGet(this, _packageConfig).systemObjectId);
1156
+ return (0, import_utils.parseStructTag)(system.type).address;
1157
+ });
1158
+ };
1159
+ getSystemContract_fn = function() {
1160
+ return __privateGet(this, _cache).read(["getSystemContract"], async () => {
1161
+ const { package_id } = await this.systemObject();
1162
+ return (0, import_system.init)(package_id);
1163
+ });
1164
+ };
1165
+ getSubsidiesContract_fn = function() {
1166
+ return __privateGet(this, _cache).read(["getSubsidiesContract"], async () => {
1167
+ if (!__privateGet(this, _packageConfig).subsidiesObjectId) {
1168
+ throw new import_error.WalrusClientError("Subsidies object ID not defined in package config");
1169
+ }
1170
+ const subsidiesObject = await __privateGet(this, _objectLoader).load(__privateGet(this, _packageConfig).subsidiesObjectId);
1171
+ const packageId = (0, import_utils.parseStructTag)(subsidiesObject.type).address;
1172
+ return (0, import_subsidies.init)(packageId);
1173
+ });
1174
+ };
1175
+ getBlobContract_fn = function() {
1176
+ return __privateGet(this, _cache).read(["getBlobContract"], async () => {
1177
+ const { package_id } = await this.systemObject();
1178
+ return (0, import_blob.init)(package_id);
1179
+ });
1180
+ };
1181
+ getMetadataContract_fn = function() {
1182
+ return __privateGet(this, _cache).read(["getMetadataContract"], async () => {
1183
+ const { package_id } = await this.systemObject();
1184
+ return (0, import_metadata.init)(package_id);
1185
+ });
1186
+ };
1187
+ wasmBindings_fn = function() {
1188
+ return __privateGet(this, _cache).read(["wasmBindings"], async () => {
1189
+ return (0, import_wasm.getWasmBindings)(__privateGet(this, _wasmUrl));
1190
+ });
1191
+ };
1165
1192
  internalReadBlob_fn = async function({ blobId, signal }) {
1166
1193
  const systemState = await this.systemState();
1167
1194
  const numShards = systemState.committee.n_shards;
1168
1195
  const blobMetadata = await this.getBlobMetadata({ blobId, signal });
1169
1196
  const slivers = await this.getSlivers({ blobId, signal });
1170
- const blobBytes = (0, import_wasm.decodePrimarySlivers)(
1197
+ const bindings = await __privateMethod(this, _WalrusClient_instances, wasmBindings_fn).call(this);
1198
+ const blobBytes = bindings.decodePrimarySlivers(
1171
1199
  blobId,
1172
1200
  numShards,
1173
1201
  blobMetadata.metadata.V1.unencoded_length,
1174
1202
  slivers
1175
1203
  );
1176
- const reconstructedBlobMetadata = (0, import_wasm.computeMetadata)(systemState.committee.n_shards, blobBytes);
1204
+ const reconstructedBlobMetadata = bindings.computeMetadata(
1205
+ systemState.committee.n_shards,
1206
+ blobBytes
1207
+ );
1177
1208
  if (reconstructedBlobMetadata.blob_id !== blobId) {
1178
1209
  throw new import_error.InconsistentBlobError("The specified blob was encoded incorrectly.");
1179
1210
  }
@@ -1212,10 +1243,10 @@ forceGetReadCommittee_fn = async function({ blobId, signal }) {
1212
1243
  if (isTransitioning && certificationEpoch < stakingState.epoch) {
1213
1244
  return await __privateMethod(this, _WalrusClient_instances, getCommittee_fn).call(this, stakingState.previous_committee);
1214
1245
  }
1215
- return await __privateGet(this, _getActiveCommittee).call(this);
1246
+ return await __privateMethod(this, _WalrusClient_instances, getActiveCommittee_fn).call(this);
1216
1247
  };
1217
1248
  withWal_fn = async function(amount, owner, source, withSubsidies, fn) {
1218
- const walType = await __privateGet(this, _walType).call(this);
1249
+ const walType = await __privateMethod(this, _WalrusClient_instances, walType_fn).call(this);
1219
1250
  return (tx) => {
1220
1251
  const coin = source ? tx.splitCoins(source, [amount])[0] : tx.add(
1221
1252
  (0, import_transactions.coinWithBalance)({
@@ -1244,8 +1275,8 @@ writeBlobAttributesForRef_fn = async function({
1244
1275
  attributes,
1245
1276
  existingAttributes
1246
1277
  }) {
1247
- const blobContract = await __privateGet(this, _getBlobContract).call(this);
1248
- const metadataContract = await __privateGet(this, _getMetadataContract).call(this);
1278
+ const blobContract = await __privateMethod(this, _WalrusClient_instances, getBlobContract_fn).call(this);
1279
+ const metadataContract = await __privateMethod(this, _WalrusClient_instances, getMetadataContract_fn).call(this);
1249
1280
  return (tx, blob) => {
1250
1281
  if (!existingAttributes) {
1251
1282
  tx.add(
@@ -1280,17 +1311,19 @@ writeBlobAttributesForRef_fn = async function({
1280
1311
  };
1281
1312
  };
1282
1313
  executeTransaction_fn = async function(transaction, signer, action) {
1283
- const { digest, effects } = await __privateGet(this, _suiClient).signAndExecuteTransaction({
1284
- transaction,
1285
- signer,
1286
- options: {
1287
- showEffects: true
1288
- }
1314
+ transaction.setSenderIfNotSet(signer.toSuiAddress());
1315
+ const bytes = await transaction.build({ client: __privateGet(this, _suiClient).jsonRpc });
1316
+ const { signature } = await signer.signTransaction(bytes);
1317
+ const {
1318
+ transaction: { digest, effects }
1319
+ } = await __privateGet(this, _suiClient).core.executeTransaction({
1320
+ transaction: bytes,
1321
+ signatures: [signature]
1289
1322
  });
1290
- if (effects?.status.status !== "success") {
1323
+ if (effects?.status.error) {
1291
1324
  throw new import_error.WalrusClientError(`Failed to ${action}: ${effects?.status.error}`);
1292
1325
  }
1293
- await __privateGet(this, _suiClient).waitForTransaction({
1326
+ await __privateGet(this, _suiClient).core.waitForTransaction({
1294
1327
  digest
1295
1328
  });
1296
1329
  return { digest, effects };
@@ -1318,7 +1351,12 @@ getCommittee_fn = async function(committee) {
1318
1351
  nodes
1319
1352
  };
1320
1353
  };
1321
- _getActiveCommittee = new WeakMap();
1354
+ getActiveCommittee_fn = function() {
1355
+ return __privateGet(this, _cache).read(["getActiveCommittee"], async () => {
1356
+ const stakingState = await this.stakingState();
1357
+ return __privateMethod(this, _WalrusClient_instances, getCommittee_fn).call(this, stakingState.committee);
1358
+ });
1359
+ };
1322
1360
  stakingPool_fn = async function(committee) {
1323
1361
  const nodeIds = committee.pos0.contents.map((node) => node.key);
1324
1362
  return __privateGet(this, _objectLoader).loadManyOrThrow(nodeIds, (0, import_staking_pool.StakingPool)());
@@ -1343,4 +1381,5 @@ retryOnPossibleEpochChange_fn = function(fn) {
1343
1381
  }
1344
1382
  };
1345
1383
  };
1384
+ let WalrusClient = _WalrusClient;
1346
1385
  //# sourceMappingURL=client.js.map