@mysten/walrus 0.0.13 → 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,14 @@
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
+
3
12
  ## 0.0.13
4
13
 
5
14
  ### Patch Changes
@@ -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,12 +48,11 @@ 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, _wasmUrl, _packageConfig, _suiClient, _objectLoader, _blobMetadataConcurrencyLimit, _readCommittee, _memo, _walType, _getPackageId, _getSystemContract, _getSubsidiesContract, _getBlobContract, _getMetadataContract, _wasmBindings, _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);
@@ -63,62 +62,9 @@ class WalrusClient {
63
62
  __privateAdd(this, _objectLoader);
64
63
  __privateAdd(this, _blobMetadataConcurrencyLimit, 10);
65
64
  __privateAdd(this, _readCommittee);
66
- __privateAdd(this, _memo, new import_memo.MemoCache());
67
- /** The Move type for a WAL coin */
68
- __privateAdd(this, _walType, __privateGet(this, _memo).create("walType", async () => {
69
- const stakedWal = await __privateGet(this, _suiClient).getNormalizedMoveStruct({
70
- package: await __privateGet(this, _getPackageId).call(this),
71
- module: "staked_wal",
72
- struct: "StakedWal"
73
- });
74
- const balanceType = stakedWal.fields.find((field) => field.name === "principal")?.type;
75
- if (!balanceType) {
76
- throw new import_error.WalrusClientError("WAL type not found");
77
- }
78
- const parsed = (0, import_utils.parseStructTag)((0, import_utils2.toTypeString)(balanceType));
79
- const coinType = parsed.typeParams[0];
80
- if (!coinType) {
81
- throw new import_error.WalrusClientError("WAL type not found");
82
- }
83
- return (0, import_utils.normalizeStructTag)(coinType);
84
- }));
85
- __privateAdd(this, _getPackageId, __privateGet(this, _memo).create("getPackageId", async () => {
86
- const system = await __privateGet(this, _objectLoader).load(__privateGet(this, _packageConfig).systemObjectId);
87
- return (0, import_utils.parseStructTag)(system.type).address;
88
- }));
89
- /** The Move type for a Blob object */
90
- this.getBlobType = __privateGet(this, _memo).create("getBlobType", async () => {
91
- return `${await __privateGet(this, _getPackageId).call(this)}::blob::Blob`;
92
- });
93
- __privateAdd(this, _getSystemContract, __privateGet(this, _memo).create("getSystemContract", async () => {
94
- const { package_id } = await this.systemObject();
95
- return (0, import_system.init)(package_id);
96
- }));
97
- __privateAdd(this, _getSubsidiesContract, __privateGet(this, _memo).create("getSubsidiesContract", async () => {
98
- if (!__privateGet(this, _packageConfig).subsidiesObjectId) {
99
- throw new import_error.WalrusClientError("Subsidies object ID not defined in package config");
100
- }
101
- const subsidiesObject = await __privateGet(this, _objectLoader).load(__privateGet(this, _packageConfig).subsidiesObjectId);
102
- const packageId = (0, import_utils.parseStructTag)(subsidiesObject.type).address;
103
- return (0, import_subsidies.init)(packageId);
104
- }));
105
- __privateAdd(this, _getBlobContract, __privateGet(this, _memo).create("getBlobContract", async () => {
106
- const { package_id } = await this.systemObject();
107
- return (0, import_blob.init)(package_id);
108
- }));
109
- __privateAdd(this, _getMetadataContract, __privateGet(this, _memo).create("getMetadataContract", async () => {
110
- const { package_id } = await this.systemObject();
111
- return (0, import_metadata.init)(package_id);
112
- }));
113
- __privateAdd(this, _wasmBindings, __privateGet(this, _memo).create("wasmBindings", async () => {
114
- return (0, import_wasm.getWasmBindings)(__privateGet(this, _wasmUrl));
115
- }));
65
+ __privateAdd(this, _cache);
116
66
  /** Read a blob from the storage nodes */
117
67
  this.readBlob = __privateMethod(this, _WalrusClient_instances, retryOnPossibleEpochChange_fn).call(this, __privateMethod(this, _WalrusClient_instances, internalReadBlob_fn));
118
- __privateAdd(this, _getActiveCommittee, __privateGet(this, _memo).create("getActiveCommittee", async () => {
119
- const stakingState = await this.stakingState();
120
- return __privateMethod(this, _WalrusClient_instances, getCommittee_fn).call(this, stakingState.committee);
121
- }));
122
68
  if (config.network && !config.packageConfig) {
123
69
  const network = config.network;
124
70
  switch (network) {
@@ -140,6 +86,39 @@ class WalrusClient {
140
86
  }));
141
87
  __privateSet(this, _storageNodeClient, new import_client2.StorageNodeClient(config.storageNodeClientOptions));
142
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
+ });
143
122
  }
144
123
  /** The cached system object for the walrus package */
145
124
  systemObject() {
@@ -315,7 +294,7 @@ class WalrusClient {
315
294
  * Gets the blob status from multiple storage nodes and returns the latest status that can be verified.
316
295
  */
317
296
  async getVerifiedBlobStatus({ blobId, signal }) {
318
- const committee = await __privateGet(this, _getActiveCommittee).call(this);
297
+ const committee = await __privateMethod(this, _WalrusClient_instances, getActiveCommittee_fn).call(this);
319
298
  const stakingState = await this.stakingState();
320
299
  const numShards = stakingState.n_shards;
321
300
  const controller = new AbortController();
@@ -415,8 +394,8 @@ class WalrusClient {
415
394
  const systemState = await this.systemState();
416
395
  const encodedSize = (0, import_utils2.encodedBlobLength)(size, systemState.committee.n_shards);
417
396
  const { storageCost } = await this.storageCost(size, epochs);
418
- const systemContract = await __privateGet(this, _getSystemContract).call(this);
419
- 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;
420
399
  return __privateMethod(this, _WalrusClient_instances, withWal_fn).call(this, storageCost, owner, walCoin ?? null, subsidiesContract !== null, (coin, tx) => {
421
400
  return tx.add(
422
401
  subsidiesContract ? subsidiesContract.reserve_space({
@@ -468,21 +447,19 @@ class WalrusClient {
468
447
  });
469
448
  const blobType = await this.getBlobType();
470
449
  const { digest, effects } = await __privateMethod(this, _WalrusClient_instances, executeTransaction_fn).call(this, transaction, signer, "create storage");
471
- const createdObjectIds = effects?.created?.map((effect) => effect.reference.objectId) ?? [];
472
- const createdObjects = await __privateGet(this, _suiClient).multiGetObjects({
473
- ids: createdObjectIds,
474
- options: {
475
- showType: true,
476
- showBcs: true
477
- }
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
478
453
  });
479
- const suiBlobObject = createdObjects.find((object) => object.data?.type === blobType);
480
- 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) {
481
458
  throw new import_error.WalrusClientError("Storage object not found in transaction effects");
482
459
  }
483
460
  return {
484
461
  digest,
485
- storage: (0, import_storage_resource.Storage)().fromBase64(suiBlobObject.data.bcs.bcsBytes)
462
+ storage: (0, import_storage_resource.Storage)().parse(suiBlobObject.content)
486
463
  };
487
464
  }
488
465
  /**
@@ -505,7 +482,7 @@ class WalrusClient {
505
482
  }) {
506
483
  const storage = await this.createStorage({ size, epochs, walCoin, owner });
507
484
  const { writeCost } = await this.storageCost(size, epochs);
508
- const systemContract = await __privateGet(this, _getSystemContract).call(this);
485
+ const systemContract = await __privateMethod(this, _WalrusClient_instances, getSystemContract_fn).call(this);
509
486
  const writeAttributes = attributes ? await __privateMethod(this, _WalrusClient_instances, writeBlobAttributesForRef_fn).call(this, {
510
487
  attributes,
511
488
  existingAttributes: null
@@ -565,21 +542,19 @@ class WalrusClient {
565
542
  });
566
543
  const blobType = await this.getBlobType();
567
544
  const { digest, effects } = await __privateMethod(this, _WalrusClient_instances, executeTransaction_fn).call(this, transaction, signer, "register blob");
568
- const createdObjectIds = effects?.created?.map((effect) => effect.reference.objectId) ?? [];
569
- const createdObjects = await __privateGet(this, _suiClient).multiGetObjects({
570
- ids: createdObjectIds,
571
- options: {
572
- showType: true,
573
- showBcs: true
574
- }
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
575
548
  });
576
- const suiBlobObject = createdObjects.find((object) => object.data?.type === blobType);
577
- 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) {
578
553
  throw new import_error.WalrusClientError("Blob object not found in transaction effects");
579
554
  }
580
555
  return {
581
556
  digest,
582
- blob: (0, import_blob.Blob)().fromBase64(suiBlobObject.data.bcs.bcsBytes)
557
+ blob: (0, import_blob.Blob)().parse(suiBlobObject.content)
583
558
  };
584
559
  }
585
560
  /**
@@ -592,7 +567,7 @@ class WalrusClient {
592
567
  */
593
568
  async certifyBlob({ blobId, blobObjectId, confirmations, deletable }) {
594
569
  const systemState = await this.systemState();
595
- const committee = await __privateGet(this, _getActiveCommittee).call(this);
570
+ const committee = await __privateMethod(this, _WalrusClient_instances, getActiveCommittee_fn).call(this);
596
571
  if (confirmations.length !== systemState.committee.members.length) {
597
572
  throw new import_error.WalrusClientError(
598
573
  "Invalid number of confirmations. Confirmations array must contain an entry for each node"
@@ -612,7 +587,7 @@ class WalrusClient {
612
587
  }
613
588
  }
614
589
  }).toBase64();
615
- const bindings = await __privateGet(this, _wasmBindings).call(this);
590
+ const bindings = await __privateMethod(this, _WalrusClient_instances, wasmBindings_fn).call(this);
616
591
  const verifySignature = bindings.getVerifySignature();
617
592
  const filteredConfirmations = confirmations.map((confirmation, index) => {
618
593
  const isValid = confirmation?.serializedMessage === confirmationMessage && verifySignature(
@@ -633,7 +608,7 @@ class WalrusClient {
633
608
  filteredConfirmations,
634
609
  filteredConfirmations.map(({ index }) => index)
635
610
  );
636
- const systemContract = await __privateGet(this, _getSystemContract).call(this);
611
+ const systemContract = await __privateMethod(this, _WalrusClient_instances, getSystemContract_fn).call(this);
637
612
  return (tx) => {
638
613
  tx.add(
639
614
  systemContract.certify_blob({
@@ -695,7 +670,7 @@ class WalrusClient {
695
670
  * ```
696
671
  */
697
672
  async deleteBlob({ blobObjectId }) {
698
- const systemContract = await __privateGet(this, _getSystemContract).call(this);
673
+ const systemContract = await __privateMethod(this, _WalrusClient_instances, getSystemContract_fn).call(this);
699
674
  return (tx) => {
700
675
  const storage = tx.add(
701
676
  systemContract.delete_blob({
@@ -758,8 +733,8 @@ class WalrusClient {
758
733
  };
759
734
  }
760
735
  const { storageCost } = await this.storageCost(Number(blob.storage.storage_size), numEpochs);
761
- const systemContract = await __privateGet(this, _getSystemContract).call(this);
762
- 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;
763
738
  return __privateMethod(this, _WalrusClient_instances, withWal_fn).call(this, storageCost, owner, walCoin ?? null, subsidiesContract !== null, (coin, tx) => {
764
739
  tx.add(
765
740
  subsidiesContract ? subsidiesContract.extend_blob({
@@ -809,23 +784,15 @@ class WalrusClient {
809
784
  async readBlobAttributes({
810
785
  blobObjectId
811
786
  }) {
812
- const response = await __privateGet(this, _suiClient).getDynamicFieldObject({
787
+ const response = await __privateGet(this, _suiClient).core.getDynamicField({
813
788
  parentId: blobObjectId,
814
789
  name: {
815
790
  type: "vector<u8>",
816
- value: [...new TextEncoder().encode("metadata")]
791
+ bcs: import_bcs.bcs.string().serialize("metadata").toBytes()
817
792
  }
818
793
  });
819
- if (response.error?.code === "dynamicFieldNotFound") {
820
- return null;
821
- }
822
- if (response.error || !response.data) {
823
- throw new import_error.WalrusClientError(
824
- `Failed to fetch metadata for object ${blobObjectId}: ${response.error}`
825
- );
826
- }
827
- const metadata = response.data.content.fields.value.fields.metadata.fields.contents;
828
- 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]));
829
796
  }
830
797
  /**
831
798
  * Write attributes to a blob
@@ -895,7 +862,7 @@ class WalrusClient {
895
862
  */
896
863
  async writeSliver({ blobId, sliverPairIndex, sliverType, sliver, signal }) {
897
864
  const systemState = await this.systemState();
898
- const committee = await __privateGet(this, _getActiveCommittee).call(this);
865
+ const committee = await __privateMethod(this, _WalrusClient_instances, getActiveCommittee_fn).call(this);
899
866
  const shardIndex = (0, import_utils2.toShardIndex)(sliverPairIndex, blobId, systemState.committee.n_shards);
900
867
  const node = await __privateMethod(this, _WalrusClient_instances, getNodeByShardIndex_fn).call(this, committee, shardIndex);
901
868
  return await __privateGet(this, _storageNodeClient).storeSliver(
@@ -912,7 +879,7 @@ class WalrusClient {
912
879
  * ```
913
880
  */
914
881
  async writeMetadataToNode({ nodeIndex, blobId, metadata, signal }) {
915
- const committee = await __privateGet(this, _getActiveCommittee).call(this);
882
+ const committee = await __privateMethod(this, _WalrusClient_instances, getActiveCommittee_fn).call(this);
916
883
  const node = committee.nodes[nodeIndex];
917
884
  return await __privateGet(this, _storageNodeClient).storeBlobMetadata(
918
885
  { blobId, metadata },
@@ -934,7 +901,7 @@ class WalrusClient {
934
901
  objectId,
935
902
  signal
936
903
  }) {
937
- const committee = await __privateGet(this, _getActiveCommittee).call(this);
904
+ const committee = await __privateMethod(this, _WalrusClient_instances, getActiveCommittee_fn).call(this);
938
905
  const node = committee.nodes[nodeIndex];
939
906
  const result = deletable ? await __privateGet(this, _storageNodeClient).getDeletableBlobConfirmation(
940
907
  { blobId, objectId },
@@ -955,9 +922,9 @@ class WalrusClient {
955
922
  */
956
923
  async encodeBlob(blob) {
957
924
  const systemState = await this.systemState();
958
- const committee = await __privateGet(this, _getActiveCommittee).call(this);
925
+ const committee = await __privateMethod(this, _WalrusClient_instances, getActiveCommittee_fn).call(this);
959
926
  const numShards = systemState.committee.n_shards;
960
- const bindings = await __privateGet(this, _wasmBindings).call(this);
927
+ const bindings = await __privateMethod(this, _WalrusClient_instances, wasmBindings_fn).call(this);
961
928
  const { blobId, metadata, sliverPairs, rootHash } = bindings.encodeBlob(numShards, blob);
962
929
  const sliversByNodeMap = /* @__PURE__ */ new Map();
963
930
  while (sliverPairs.length > 0) {
@@ -1037,7 +1004,7 @@ class WalrusClient {
1037
1004
  ...options
1038
1005
  }) {
1039
1006
  const systemState = await this.systemState();
1040
- const committee = await __privateGet(this, _getActiveCommittee).call(this);
1007
+ const committee = await __privateMethod(this, _WalrusClient_instances, getActiveCommittee_fn).call(this);
1041
1008
  const controller = new AbortController();
1042
1009
  let failures = 0;
1043
1010
  const confirmations = await Promise.all(
@@ -1151,10 +1118,9 @@ class WalrusClient {
1151
1118
  */
1152
1119
  reset() {
1153
1120
  __privateGet(this, _objectLoader).clearAll();
1154
- __privateSet(this, _readCommittee, null);
1155
- __privateGet(this, _memo).reset();
1121
+ __privateGet(this, _cache).clear();
1156
1122
  }
1157
- }
1123
+ };
1158
1124
  _storageNodeClient = new WeakMap();
1159
1125
  _wasmUrl = new WeakMap();
1160
1126
  _packageConfig = new WeakMap();
@@ -1162,21 +1128,73 @@ _suiClient = new WeakMap();
1162
1128
  _objectLoader = new WeakMap();
1163
1129
  _blobMetadataConcurrencyLimit = new WeakMap();
1164
1130
  _readCommittee = new WeakMap();
1165
- _memo = new WeakMap();
1166
- _walType = new WeakMap();
1167
- _getPackageId = new WeakMap();
1168
- _getSystemContract = new WeakMap();
1169
- _getSubsidiesContract = new WeakMap();
1170
- _getBlobContract = new WeakMap();
1171
- _getMetadataContract = new WeakMap();
1172
- _wasmBindings = new WeakMap();
1131
+ _cache = new WeakMap();
1173
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
+ };
1174
1192
  internalReadBlob_fn = async function({ blobId, signal }) {
1175
1193
  const systemState = await this.systemState();
1176
1194
  const numShards = systemState.committee.n_shards;
1177
1195
  const blobMetadata = await this.getBlobMetadata({ blobId, signal });
1178
1196
  const slivers = await this.getSlivers({ blobId, signal });
1179
- const bindings = await __privateGet(this, _wasmBindings).call(this);
1197
+ const bindings = await __privateMethod(this, _WalrusClient_instances, wasmBindings_fn).call(this);
1180
1198
  const blobBytes = bindings.decodePrimarySlivers(
1181
1199
  blobId,
1182
1200
  numShards,
@@ -1225,10 +1243,10 @@ forceGetReadCommittee_fn = async function({ blobId, signal }) {
1225
1243
  if (isTransitioning && certificationEpoch < stakingState.epoch) {
1226
1244
  return await __privateMethod(this, _WalrusClient_instances, getCommittee_fn).call(this, stakingState.previous_committee);
1227
1245
  }
1228
- return await __privateGet(this, _getActiveCommittee).call(this);
1246
+ return await __privateMethod(this, _WalrusClient_instances, getActiveCommittee_fn).call(this);
1229
1247
  };
1230
1248
  withWal_fn = async function(amount, owner, source, withSubsidies, fn) {
1231
- const walType = await __privateGet(this, _walType).call(this);
1249
+ const walType = await __privateMethod(this, _WalrusClient_instances, walType_fn).call(this);
1232
1250
  return (tx) => {
1233
1251
  const coin = source ? tx.splitCoins(source, [amount])[0] : tx.add(
1234
1252
  (0, import_transactions.coinWithBalance)({
@@ -1257,8 +1275,8 @@ writeBlobAttributesForRef_fn = async function({
1257
1275
  attributes,
1258
1276
  existingAttributes
1259
1277
  }) {
1260
- const blobContract = await __privateGet(this, _getBlobContract).call(this);
1261
- 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);
1262
1280
  return (tx, blob) => {
1263
1281
  if (!existingAttributes) {
1264
1282
  tx.add(
@@ -1293,17 +1311,19 @@ writeBlobAttributesForRef_fn = async function({
1293
1311
  };
1294
1312
  };
1295
1313
  executeTransaction_fn = async function(transaction, signer, action) {
1296
- const { digest, effects } = await __privateGet(this, _suiClient).signAndExecuteTransaction({
1297
- transaction,
1298
- signer,
1299
- options: {
1300
- showEffects: true
1301
- }
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]
1302
1322
  });
1303
- if (effects?.status.status !== "success") {
1323
+ if (effects?.status.error) {
1304
1324
  throw new import_error.WalrusClientError(`Failed to ${action}: ${effects?.status.error}`);
1305
1325
  }
1306
- await __privateGet(this, _suiClient).waitForTransaction({
1326
+ await __privateGet(this, _suiClient).core.waitForTransaction({
1307
1327
  digest
1308
1328
  });
1309
1329
  return { digest, effects };
@@ -1331,7 +1351,12 @@ getCommittee_fn = async function(committee) {
1331
1351
  nodes
1332
1352
  };
1333
1353
  };
1334
- _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
+ };
1335
1360
  stakingPool_fn = async function(committee) {
1336
1361
  const nodeIds = committee.pos0.contents.map((node) => node.key);
1337
1362
  return __privateGet(this, _objectLoader).loadManyOrThrow(nodeIds, (0, import_staking_pool.StakingPool)());
@@ -1356,4 +1381,5 @@ retryOnPossibleEpochChange_fn = function(fn) {
1356
1381
  }
1357
1382
  };
1358
1383
  };
1384
+ let WalrusClient = _WalrusClient;
1359
1385
  //# sourceMappingURL=client.js.map