@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.
@@ -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, _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;
9
+ 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;
10
10
  import { bcs } from "@mysten/bcs";
11
11
  import { SuiClient } from "@mysten/sui/client";
12
12
  import { coinWithBalance, Transaction } from "@mysten/sui/transactions";
@@ -17,7 +17,7 @@ import {
17
17
  TESTNET_WALRUS_PACKAGE_CONFIG
18
18
  } from "./constants.js";
19
19
  import { Blob, init as initBlobContract } from "./contracts/blob.js";
20
- import { init as initMetadataContract } from "./contracts/metadata.js";
20
+ import { init as initMetadataContract, Metadata } from "./contracts/metadata.js";
21
21
  import { StakingInnerV1 } from "./contracts/staking_inner.js";
22
22
  import { StakingPool } from "./contracts/staking_pool.js";
23
23
  import { Staking } from "./contracts/staking.js";
@@ -54,78 +54,22 @@ import {
54
54
  toShardIndex,
55
55
  toTypeString
56
56
  } from "./utils/index.js";
57
- import { MemoCache } from "./utils/memo.js";
58
57
  import { SuiObjectDataLoader } from "./utils/object-loader.js";
59
58
  import { shuffle, weightedShuffle } from "./utils/randomness.js";
60
- import {
61
- combineSignatures,
62
- computeMetadata,
63
- decodePrimarySlivers,
64
- encodeBlob,
65
- getVerifySignature
66
- } from "./wasm.js";
67
- class WalrusClient {
59
+ import { getWasmBindings } from "./wasm.js";
60
+ const _WalrusClient = class _WalrusClient {
68
61
  constructor(config) {
69
62
  __privateAdd(this, _WalrusClient_instances);
70
63
  __privateAdd(this, _storageNodeClient);
64
+ __privateAdd(this, _wasmUrl);
71
65
  __privateAdd(this, _packageConfig);
72
66
  __privateAdd(this, _suiClient);
73
67
  __privateAdd(this, _objectLoader);
74
68
  __privateAdd(this, _blobMetadataConcurrencyLimit, 10);
75
69
  __privateAdd(this, _readCommittee);
76
- __privateAdd(this, _memo, new MemoCache());
77
- /** The Move type for a WAL coin */
78
- __privateAdd(this, _walType, __privateGet(this, _memo).create("walType", async () => {
79
- const stakedWal = await __privateGet(this, _suiClient).getNormalizedMoveStruct({
80
- package: await __privateGet(this, _getPackageId).call(this),
81
- module: "staked_wal",
82
- struct: "StakedWal"
83
- });
84
- const balanceType = stakedWal.fields.find((field) => field.name === "principal")?.type;
85
- if (!balanceType) {
86
- throw new WalrusClientError("WAL type not found");
87
- }
88
- const parsed = parseStructTag(toTypeString(balanceType));
89
- const coinType = parsed.typeParams[0];
90
- if (!coinType) {
91
- throw new WalrusClientError("WAL type not found");
92
- }
93
- return normalizeStructTag(coinType);
94
- }));
95
- __privateAdd(this, _getPackageId, __privateGet(this, _memo).create("getPackageId", async () => {
96
- const system = await __privateGet(this, _objectLoader).load(__privateGet(this, _packageConfig).systemObjectId);
97
- return parseStructTag(system.type).address;
98
- }));
99
- /** The Move type for a Blob object */
100
- this.getBlobType = __privateGet(this, _memo).create("getBlobType", async () => {
101
- return `${await __privateGet(this, _getPackageId).call(this)}::blob::Blob`;
102
- });
103
- __privateAdd(this, _getSystemContract, __privateGet(this, _memo).create("getSystemContract", async () => {
104
- const { package_id } = await this.systemObject();
105
- return initSystemContract(package_id);
106
- }));
107
- __privateAdd(this, _getSubsidiesContract, __privateGet(this, _memo).create("getSubsidiesContract", async () => {
108
- if (!__privateGet(this, _packageConfig).subsidiesObjectId) {
109
- throw new WalrusClientError("Subsidies object ID not defined in package config");
110
- }
111
- const subsidiesObject = await __privateGet(this, _objectLoader).load(__privateGet(this, _packageConfig).subsidiesObjectId);
112
- const packageId = parseStructTag(subsidiesObject.type).address;
113
- return initSubsidiesContract(packageId);
114
- }));
115
- __privateAdd(this, _getBlobContract, __privateGet(this, _memo).create("getBlobContract", async () => {
116
- const { package_id } = await this.systemObject();
117
- return initBlobContract(package_id);
118
- }));
119
- __privateAdd(this, _getMetadataContract, __privateGet(this, _memo).create("getMetadataContract", async () => {
120
- const { package_id } = await this.systemObject();
121
- return initMetadataContract(package_id);
122
- }));
70
+ __privateAdd(this, _cache);
123
71
  /** Read a blob from the storage nodes */
124
72
  this.readBlob = __privateMethod(this, _WalrusClient_instances, retryOnPossibleEpochChange_fn).call(this, __privateMethod(this, _WalrusClient_instances, internalReadBlob_fn));
125
- __privateAdd(this, _getActiveCommittee, __privateGet(this, _memo).create("getActiveCommittee", async () => {
126
- const stakingState = await this.stakingState();
127
- return __privateMethod(this, _WalrusClient_instances, getCommittee_fn).call(this, stakingState.committee);
128
- }));
129
73
  if (config.network && !config.packageConfig) {
130
74
  const network = config.network;
131
75
  switch (network) {
@@ -141,11 +85,45 @@ class WalrusClient {
141
85
  } else {
142
86
  __privateSet(this, _packageConfig, config.packageConfig);
143
87
  }
88
+ __privateSet(this, _wasmUrl, config.wasmUrl);
144
89
  __privateSet(this, _suiClient, config.suiClient ?? new SuiClient({
145
90
  url: config.suiRpcUrl
146
91
  }));
147
92
  __privateSet(this, _storageNodeClient, new StorageNodeClient(config.storageNodeClientOptions));
148
93
  __privateSet(this, _objectLoader, new SuiObjectDataLoader(__privateGet(this, _suiClient)));
94
+ __privateSet(this, _cache, __privateGet(this, _suiClient).cache.scope("@mysten/walrus"));
95
+ }
96
+ static experimental_asClientExtension({
97
+ packageConfig,
98
+ network,
99
+ ...options
100
+ } = {}) {
101
+ return {
102
+ name: "walrus",
103
+ register: (client) => {
104
+ const walrusNetwork = network || client.network;
105
+ if (walrusNetwork !== "mainnet" && walrusNetwork !== "testnet") {
106
+ throw new WalrusClientError("Walrus client only supports mainnet and testnet");
107
+ }
108
+ return new _WalrusClient(
109
+ packageConfig ? {
110
+ packageConfig,
111
+ suiClient: client,
112
+ ...options
113
+ } : {
114
+ network: walrusNetwork,
115
+ suiClient: client,
116
+ ...options
117
+ }
118
+ );
119
+ }
120
+ };
121
+ }
122
+ /** The Move type for a Blob object */
123
+ getBlobType() {
124
+ return __privateGet(this, _cache).read(["getBlobType"], async () => {
125
+ return `${await __privateMethod(this, _WalrusClient_instances, getPackageId_fn).call(this)}::blob::Blob`;
126
+ });
149
127
  }
150
128
  /** The cached system object for the walrus package */
151
129
  systemObject() {
@@ -321,7 +299,7 @@ class WalrusClient {
321
299
  * Gets the blob status from multiple storage nodes and returns the latest status that can be verified.
322
300
  */
323
301
  async getVerifiedBlobStatus({ blobId, signal }) {
324
- const committee = await __privateGet(this, _getActiveCommittee).call(this);
302
+ const committee = await __privateMethod(this, _WalrusClient_instances, getActiveCommittee_fn).call(this);
325
303
  const stakingState = await this.stakingState();
326
304
  const numShards = stakingState.n_shards;
327
305
  const controller = new AbortController();
@@ -421,8 +399,8 @@ class WalrusClient {
421
399
  const systemState = await this.systemState();
422
400
  const encodedSize = encodedBlobLength(size, systemState.committee.n_shards);
423
401
  const { storageCost } = await this.storageCost(size, epochs);
424
- const systemContract = await __privateGet(this, _getSystemContract).call(this);
425
- const subsidiesContract = __privateGet(this, _packageConfig).subsidiesObjectId ? await __privateGet(this, _getSubsidiesContract).call(this) : null;
402
+ const systemContract = await __privateMethod(this, _WalrusClient_instances, getSystemContract_fn).call(this);
403
+ const subsidiesContract = __privateGet(this, _packageConfig).subsidiesObjectId ? await __privateMethod(this, _WalrusClient_instances, getSubsidiesContract_fn).call(this) : null;
426
404
  return __privateMethod(this, _WalrusClient_instances, withWal_fn).call(this, storageCost, owner, walCoin ?? null, subsidiesContract !== null, (coin, tx) => {
427
405
  return tx.add(
428
406
  subsidiesContract ? subsidiesContract.reserve_space({
@@ -474,21 +452,19 @@ class WalrusClient {
474
452
  });
475
453
  const blobType = await this.getBlobType();
476
454
  const { digest, effects } = await __privateMethod(this, _WalrusClient_instances, executeTransaction_fn).call(this, transaction, signer, "create storage");
477
- const createdObjectIds = effects?.created?.map((effect) => effect.reference.objectId) ?? [];
478
- const createdObjects = await __privateGet(this, _suiClient).multiGetObjects({
479
- ids: createdObjectIds,
480
- options: {
481
- showType: true,
482
- showBcs: true
483
- }
455
+ const createdObjectIds = effects?.changedObjects.filter((object) => object.idOperation === "Created").map((object) => object.id);
456
+ const createdObjects = await __privateGet(this, _suiClient).core.getObjects({
457
+ objectIds: createdObjectIds
484
458
  });
485
- const suiBlobObject = createdObjects.find((object) => object.data?.type === blobType);
486
- if (!suiBlobObject || suiBlobObject.data?.bcs?.dataType !== "moveObject") {
459
+ const suiBlobObject = createdObjects.objects.find(
460
+ (object) => !(object instanceof Error) && object.type === blobType
461
+ );
462
+ if (suiBlobObject instanceof Error || !suiBlobObject) {
487
463
  throw new WalrusClientError("Storage object not found in transaction effects");
488
464
  }
489
465
  return {
490
466
  digest,
491
- storage: Storage().fromBase64(suiBlobObject.data.bcs.bcsBytes)
467
+ storage: Storage().parse(suiBlobObject.content)
492
468
  };
493
469
  }
494
470
  /**
@@ -511,7 +487,7 @@ class WalrusClient {
511
487
  }) {
512
488
  const storage = await this.createStorage({ size, epochs, walCoin, owner });
513
489
  const { writeCost } = await this.storageCost(size, epochs);
514
- const systemContract = await __privateGet(this, _getSystemContract).call(this);
490
+ const systemContract = await __privateMethod(this, _WalrusClient_instances, getSystemContract_fn).call(this);
515
491
  const writeAttributes = attributes ? await __privateMethod(this, _WalrusClient_instances, writeBlobAttributesForRef_fn).call(this, {
516
492
  attributes,
517
493
  existingAttributes: null
@@ -571,21 +547,19 @@ class WalrusClient {
571
547
  });
572
548
  const blobType = await this.getBlobType();
573
549
  const { digest, effects } = await __privateMethod(this, _WalrusClient_instances, executeTransaction_fn).call(this, transaction, signer, "register blob");
574
- const createdObjectIds = effects?.created?.map((effect) => effect.reference.objectId) ?? [];
575
- const createdObjects = await __privateGet(this, _suiClient).multiGetObjects({
576
- ids: createdObjectIds,
577
- options: {
578
- showType: true,
579
- showBcs: true
580
- }
550
+ const createdObjectIds = effects?.changedObjects.filter((object) => object.idOperation === "Created").map((object) => object.id);
551
+ const createdObjects = await __privateGet(this, _suiClient).core.getObjects({
552
+ objectIds: createdObjectIds
581
553
  });
582
- const suiBlobObject = createdObjects.find((object) => object.data?.type === blobType);
583
- if (!suiBlobObject || suiBlobObject.data?.bcs?.dataType !== "moveObject") {
554
+ const suiBlobObject = createdObjects.objects.find(
555
+ (object) => !(object instanceof Error) && object.type === blobType
556
+ );
557
+ if (suiBlobObject instanceof Error || !suiBlobObject) {
584
558
  throw new WalrusClientError("Blob object not found in transaction effects");
585
559
  }
586
560
  return {
587
561
  digest,
588
- blob: Blob().fromBase64(suiBlobObject.data.bcs.bcsBytes)
562
+ blob: Blob().parse(suiBlobObject.content)
589
563
  };
590
564
  }
591
565
  /**
@@ -598,7 +572,7 @@ class WalrusClient {
598
572
  */
599
573
  async certifyBlob({ blobId, blobObjectId, confirmations, deletable }) {
600
574
  const systemState = await this.systemState();
601
- const committee = await __privateGet(this, _getActiveCommittee).call(this);
575
+ const committee = await __privateMethod(this, _WalrusClient_instances, getActiveCommittee_fn).call(this);
602
576
  if (confirmations.length !== systemState.committee.members.length) {
603
577
  throw new WalrusClientError(
604
578
  "Invalid number of confirmations. Confirmations array must contain an entry for each node"
@@ -618,7 +592,8 @@ class WalrusClient {
618
592
  }
619
593
  }
620
594
  }).toBase64();
621
- const verifySignature = await getVerifySignature();
595
+ const bindings = await __privateMethod(this, _WalrusClient_instances, wasmBindings_fn).call(this);
596
+ const verifySignature = bindings.getVerifySignature();
622
597
  const filteredConfirmations = confirmations.map((confirmation, index) => {
623
598
  const isValid = confirmation?.serializedMessage === confirmationMessage && verifySignature(
624
599
  confirmation,
@@ -634,11 +609,11 @@ class WalrusClient {
634
609
  `Too many invalid confirmations received for blob (${filteredConfirmations.length} of ${systemState.committee.members.length})`
635
610
  );
636
611
  }
637
- const combinedSignature = await combineSignatures(
612
+ const combinedSignature = bindings.combineSignatures(
638
613
  filteredConfirmations,
639
614
  filteredConfirmations.map(({ index }) => index)
640
615
  );
641
- const systemContract = await __privateGet(this, _getSystemContract).call(this);
616
+ const systemContract = await __privateMethod(this, _WalrusClient_instances, getSystemContract_fn).call(this);
642
617
  return (tx) => {
643
618
  tx.add(
644
619
  systemContract.certify_blob({
@@ -700,7 +675,7 @@ class WalrusClient {
700
675
  * ```
701
676
  */
702
677
  async deleteBlob({ blobObjectId }) {
703
- const systemContract = await __privateGet(this, _getSystemContract).call(this);
678
+ const systemContract = await __privateMethod(this, _WalrusClient_instances, getSystemContract_fn).call(this);
704
679
  return (tx) => {
705
680
  const storage = tx.add(
706
681
  systemContract.delete_blob({
@@ -763,8 +738,8 @@ class WalrusClient {
763
738
  };
764
739
  }
765
740
  const { storageCost } = await this.storageCost(Number(blob.storage.storage_size), numEpochs);
766
- const systemContract = await __privateGet(this, _getSystemContract).call(this);
767
- const subsidiesContract = __privateGet(this, _packageConfig).subsidiesObjectId ? await __privateGet(this, _getSubsidiesContract).call(this) : null;
741
+ const systemContract = await __privateMethod(this, _WalrusClient_instances, getSystemContract_fn).call(this);
742
+ const subsidiesContract = __privateGet(this, _packageConfig).subsidiesObjectId ? await __privateMethod(this, _WalrusClient_instances, getSubsidiesContract_fn).call(this) : null;
768
743
  return __privateMethod(this, _WalrusClient_instances, withWal_fn).call(this, storageCost, owner, walCoin ?? null, subsidiesContract !== null, (coin, tx) => {
769
744
  tx.add(
770
745
  subsidiesContract ? subsidiesContract.extend_blob({
@@ -814,23 +789,15 @@ class WalrusClient {
814
789
  async readBlobAttributes({
815
790
  blobObjectId
816
791
  }) {
817
- const response = await __privateGet(this, _suiClient).getDynamicFieldObject({
792
+ const response = await __privateGet(this, _suiClient).core.getDynamicField({
818
793
  parentId: blobObjectId,
819
794
  name: {
820
795
  type: "vector<u8>",
821
- value: [...new TextEncoder().encode("metadata")]
796
+ bcs: bcs.string().serialize("metadata").toBytes()
822
797
  }
823
798
  });
824
- if (response.error?.code === "dynamicFieldNotFound") {
825
- return null;
826
- }
827
- if (response.error || !response.data) {
828
- throw new WalrusClientError(
829
- `Failed to fetch metadata for object ${blobObjectId}: ${response.error}`
830
- );
831
- }
832
- const metadata = response.data.content.fields.value.fields.metadata.fields.contents;
833
- return Object.fromEntries(metadata.map(({ fields: { key, value } }) => [key, value]));
799
+ const metadata = Metadata().parse(response.dynamicField.value.bcs);
800
+ return Object.fromEntries(metadata.metadata.contents.map(({ key, value }) => [key, value]));
834
801
  }
835
802
  /**
836
803
  * Write attributes to a blob
@@ -900,7 +867,7 @@ class WalrusClient {
900
867
  */
901
868
  async writeSliver({ blobId, sliverPairIndex, sliverType, sliver, signal }) {
902
869
  const systemState = await this.systemState();
903
- const committee = await __privateGet(this, _getActiveCommittee).call(this);
870
+ const committee = await __privateMethod(this, _WalrusClient_instances, getActiveCommittee_fn).call(this);
904
871
  const shardIndex = toShardIndex(sliverPairIndex, blobId, systemState.committee.n_shards);
905
872
  const node = await __privateMethod(this, _WalrusClient_instances, getNodeByShardIndex_fn).call(this, committee, shardIndex);
906
873
  return await __privateGet(this, _storageNodeClient).storeSliver(
@@ -917,7 +884,7 @@ class WalrusClient {
917
884
  * ```
918
885
  */
919
886
  async writeMetadataToNode({ nodeIndex, blobId, metadata, signal }) {
920
- const committee = await __privateGet(this, _getActiveCommittee).call(this);
887
+ const committee = await __privateMethod(this, _WalrusClient_instances, getActiveCommittee_fn).call(this);
921
888
  const node = committee.nodes[nodeIndex];
922
889
  return await __privateGet(this, _storageNodeClient).storeBlobMetadata(
923
890
  { blobId, metadata },
@@ -939,7 +906,7 @@ class WalrusClient {
939
906
  objectId,
940
907
  signal
941
908
  }) {
942
- const committee = await __privateGet(this, _getActiveCommittee).call(this);
909
+ const committee = await __privateMethod(this, _WalrusClient_instances, getActiveCommittee_fn).call(this);
943
910
  const node = committee.nodes[nodeIndex];
944
911
  const result = deletable ? await __privateGet(this, _storageNodeClient).getDeletableBlobConfirmation(
945
912
  { blobId, objectId },
@@ -960,9 +927,10 @@ class WalrusClient {
960
927
  */
961
928
  async encodeBlob(blob) {
962
929
  const systemState = await this.systemState();
963
- const committee = await __privateGet(this, _getActiveCommittee).call(this);
930
+ const committee = await __privateMethod(this, _WalrusClient_instances, getActiveCommittee_fn).call(this);
964
931
  const numShards = systemState.committee.n_shards;
965
- const { blobId, metadata, sliverPairs, rootHash } = await encodeBlob(numShards, blob);
932
+ const bindings = await __privateMethod(this, _WalrusClient_instances, wasmBindings_fn).call(this);
933
+ const { blobId, metadata, sliverPairs, rootHash } = bindings.encodeBlob(numShards, blob);
966
934
  const sliversByNodeMap = /* @__PURE__ */ new Map();
967
935
  while (sliverPairs.length > 0) {
968
936
  const { primary, secondary } = sliverPairs.pop();
@@ -1041,7 +1009,7 @@ class WalrusClient {
1041
1009
  ...options
1042
1010
  }) {
1043
1011
  const systemState = await this.systemState();
1044
- const committee = await __privateGet(this, _getActiveCommittee).call(this);
1012
+ const committee = await __privateMethod(this, _WalrusClient_instances, getActiveCommittee_fn).call(this);
1045
1013
  const controller = new AbortController();
1046
1014
  let failures = 0;
1047
1015
  const confirmations = await Promise.all(
@@ -1155,36 +1123,93 @@ class WalrusClient {
1155
1123
  */
1156
1124
  reset() {
1157
1125
  __privateGet(this, _objectLoader).clearAll();
1158
- __privateSet(this, _readCommittee, null);
1159
- __privateGet(this, _memo).reset();
1126
+ __privateGet(this, _cache).clear();
1160
1127
  }
1161
- }
1128
+ };
1162
1129
  _storageNodeClient = new WeakMap();
1130
+ _wasmUrl = new WeakMap();
1163
1131
  _packageConfig = new WeakMap();
1164
1132
  _suiClient = new WeakMap();
1165
1133
  _objectLoader = new WeakMap();
1166
1134
  _blobMetadataConcurrencyLimit = new WeakMap();
1167
1135
  _readCommittee = new WeakMap();
1168
- _memo = new WeakMap();
1169
- _walType = new WeakMap();
1170
- _getPackageId = new WeakMap();
1171
- _getSystemContract = new WeakMap();
1172
- _getSubsidiesContract = new WeakMap();
1173
- _getBlobContract = new WeakMap();
1174
- _getMetadataContract = new WeakMap();
1136
+ _cache = new WeakMap();
1175
1137
  _WalrusClient_instances = new WeakSet();
1138
+ /** The Move type for a WAL coin */
1139
+ walType_fn = function() {
1140
+ return __privateGet(this, _cache).read(["walType"], async () => {
1141
+ const stakedWal = await __privateGet(this, _suiClient).jsonRpc.getNormalizedMoveStruct({
1142
+ package: await __privateMethod(this, _WalrusClient_instances, getPackageId_fn).call(this),
1143
+ module: "staked_wal",
1144
+ struct: "StakedWal"
1145
+ });
1146
+ const balanceType = stakedWal.fields.find((field) => field.name === "principal")?.type;
1147
+ if (!balanceType) {
1148
+ throw new WalrusClientError("WAL type not found");
1149
+ }
1150
+ const parsed = parseStructTag(toTypeString(balanceType));
1151
+ const coinType = parsed.typeParams[0];
1152
+ if (!coinType) {
1153
+ throw new WalrusClientError("WAL type not found");
1154
+ }
1155
+ return normalizeStructTag(coinType);
1156
+ });
1157
+ };
1158
+ getPackageId_fn = function() {
1159
+ return __privateGet(this, _cache).read(["getPackageId"], async () => {
1160
+ const system = await __privateGet(this, _objectLoader).load(__privateGet(this, _packageConfig).systemObjectId);
1161
+ return parseStructTag(system.type).address;
1162
+ });
1163
+ };
1164
+ getSystemContract_fn = function() {
1165
+ return __privateGet(this, _cache).read(["getSystemContract"], async () => {
1166
+ const { package_id } = await this.systemObject();
1167
+ return initSystemContract(package_id);
1168
+ });
1169
+ };
1170
+ getSubsidiesContract_fn = function() {
1171
+ return __privateGet(this, _cache).read(["getSubsidiesContract"], async () => {
1172
+ if (!__privateGet(this, _packageConfig).subsidiesObjectId) {
1173
+ throw new WalrusClientError("Subsidies object ID not defined in package config");
1174
+ }
1175
+ const subsidiesObject = await __privateGet(this, _objectLoader).load(__privateGet(this, _packageConfig).subsidiesObjectId);
1176
+ const packageId = parseStructTag(subsidiesObject.type).address;
1177
+ return initSubsidiesContract(packageId);
1178
+ });
1179
+ };
1180
+ getBlobContract_fn = function() {
1181
+ return __privateGet(this, _cache).read(["getBlobContract"], async () => {
1182
+ const { package_id } = await this.systemObject();
1183
+ return initBlobContract(package_id);
1184
+ });
1185
+ };
1186
+ getMetadataContract_fn = function() {
1187
+ return __privateGet(this, _cache).read(["getMetadataContract"], async () => {
1188
+ const { package_id } = await this.systemObject();
1189
+ return initMetadataContract(package_id);
1190
+ });
1191
+ };
1192
+ wasmBindings_fn = function() {
1193
+ return __privateGet(this, _cache).read(["wasmBindings"], async () => {
1194
+ return getWasmBindings(__privateGet(this, _wasmUrl));
1195
+ });
1196
+ };
1176
1197
  internalReadBlob_fn = async function({ blobId, signal }) {
1177
1198
  const systemState = await this.systemState();
1178
1199
  const numShards = systemState.committee.n_shards;
1179
1200
  const blobMetadata = await this.getBlobMetadata({ blobId, signal });
1180
1201
  const slivers = await this.getSlivers({ blobId, signal });
1181
- const blobBytes = decodePrimarySlivers(
1202
+ const bindings = await __privateMethod(this, _WalrusClient_instances, wasmBindings_fn).call(this);
1203
+ const blobBytes = bindings.decodePrimarySlivers(
1182
1204
  blobId,
1183
1205
  numShards,
1184
1206
  blobMetadata.metadata.V1.unencoded_length,
1185
1207
  slivers
1186
1208
  );
1187
- const reconstructedBlobMetadata = computeMetadata(systemState.committee.n_shards, blobBytes);
1209
+ const reconstructedBlobMetadata = bindings.computeMetadata(
1210
+ systemState.committee.n_shards,
1211
+ blobBytes
1212
+ );
1188
1213
  if (reconstructedBlobMetadata.blob_id !== blobId) {
1189
1214
  throw new InconsistentBlobError("The specified blob was encoded incorrectly.");
1190
1215
  }
@@ -1223,10 +1248,10 @@ forceGetReadCommittee_fn = async function({ blobId, signal }) {
1223
1248
  if (isTransitioning && certificationEpoch < stakingState.epoch) {
1224
1249
  return await __privateMethod(this, _WalrusClient_instances, getCommittee_fn).call(this, stakingState.previous_committee);
1225
1250
  }
1226
- return await __privateGet(this, _getActiveCommittee).call(this);
1251
+ return await __privateMethod(this, _WalrusClient_instances, getActiveCommittee_fn).call(this);
1227
1252
  };
1228
1253
  withWal_fn = async function(amount, owner, source, withSubsidies, fn) {
1229
- const walType = await __privateGet(this, _walType).call(this);
1254
+ const walType = await __privateMethod(this, _WalrusClient_instances, walType_fn).call(this);
1230
1255
  return (tx) => {
1231
1256
  const coin = source ? tx.splitCoins(source, [amount])[0] : tx.add(
1232
1257
  coinWithBalance({
@@ -1255,8 +1280,8 @@ writeBlobAttributesForRef_fn = async function({
1255
1280
  attributes,
1256
1281
  existingAttributes
1257
1282
  }) {
1258
- const blobContract = await __privateGet(this, _getBlobContract).call(this);
1259
- const metadataContract = await __privateGet(this, _getMetadataContract).call(this);
1283
+ const blobContract = await __privateMethod(this, _WalrusClient_instances, getBlobContract_fn).call(this);
1284
+ const metadataContract = await __privateMethod(this, _WalrusClient_instances, getMetadataContract_fn).call(this);
1260
1285
  return (tx, blob) => {
1261
1286
  if (!existingAttributes) {
1262
1287
  tx.add(
@@ -1291,17 +1316,19 @@ writeBlobAttributesForRef_fn = async function({
1291
1316
  };
1292
1317
  };
1293
1318
  executeTransaction_fn = async function(transaction, signer, action) {
1294
- const { digest, effects } = await __privateGet(this, _suiClient).signAndExecuteTransaction({
1295
- transaction,
1296
- signer,
1297
- options: {
1298
- showEffects: true
1299
- }
1319
+ transaction.setSenderIfNotSet(signer.toSuiAddress());
1320
+ const bytes = await transaction.build({ client: __privateGet(this, _suiClient).jsonRpc });
1321
+ const { signature } = await signer.signTransaction(bytes);
1322
+ const {
1323
+ transaction: { digest, effects }
1324
+ } = await __privateGet(this, _suiClient).core.executeTransaction({
1325
+ transaction: bytes,
1326
+ signatures: [signature]
1300
1327
  });
1301
- if (effects?.status.status !== "success") {
1328
+ if (effects?.status.error) {
1302
1329
  throw new WalrusClientError(`Failed to ${action}: ${effects?.status.error}`);
1303
1330
  }
1304
- await __privateGet(this, _suiClient).waitForTransaction({
1331
+ await __privateGet(this, _suiClient).core.waitForTransaction({
1305
1332
  digest
1306
1333
  });
1307
1334
  return { digest, effects };
@@ -1329,7 +1356,12 @@ getCommittee_fn = async function(committee) {
1329
1356
  nodes
1330
1357
  };
1331
1358
  };
1332
- _getActiveCommittee = new WeakMap();
1359
+ getActiveCommittee_fn = function() {
1360
+ return __privateGet(this, _cache).read(["getActiveCommittee"], async () => {
1361
+ const stakingState = await this.stakingState();
1362
+ return __privateMethod(this, _WalrusClient_instances, getCommittee_fn).call(this, stakingState.committee);
1363
+ });
1364
+ };
1333
1365
  stakingPool_fn = async function(committee) {
1334
1366
  const nodeIds = committee.pos0.contents.map((node) => node.key);
1335
1367
  return __privateGet(this, _objectLoader).loadManyOrThrow(nodeIds, StakingPool());
@@ -1354,6 +1386,7 @@ retryOnPossibleEpochChange_fn = function(fn) {
1354
1386
  }
1355
1387
  };
1356
1388
  };
1389
+ let WalrusClient = _WalrusClient;
1357
1390
  export {
1358
1391
  WalrusClient
1359
1392
  };