@msafe/sui3-sdk 0.0.90 → 1.0.6

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/dist/index.js CHANGED
@@ -133,46 +133,86 @@ import {
133
133
  buildRejectTxb,
134
134
  isSameAddress as isSameAddress2
135
135
  } from "@msafe/sui3-utils";
136
- import { TransactionBlock as TransactionBlock2 } from "@mysten/sui.js/transactions";
137
- import { fromHEX, normalizeStructTag as normalizeStructTag3, toHEX } from "@mysten/sui.js/utils";
136
+ import { Transaction as Transaction3 } from "@mysten/sui/transactions";
137
+ import { fromHex, normalizeStructTag as normalizeStructTag3, toHex } from "@mysten/sui/utils";
138
138
  import { SUI_MAINNET_CHAIN, SUI_TESTNET_CHAIN } from "@mysten/wallet-standard";
139
139
 
140
140
  // src/simulate/simulator.ts
141
- import { TransactionBlock } from "@mysten/sui.js/transactions";
141
+ import { Transaction } from "@mysten/sui/transactions";
142
142
  var GAS_SAFE_OVERHEAD = 1000n;
143
+ function formatExecutionError(error) {
144
+ return error.message;
145
+ }
146
+ function gasObjectToReference(gas) {
147
+ if (!gas?.objectId) {
148
+ throw new Error("Gas object missing from simulation effects");
149
+ }
150
+ const version = gas.outputVersion ?? gas.inputVersion ?? "0";
151
+ const digest = gas.outputDigest ?? gas.inputDigest ?? "";
152
+ return { objectId: gas.objectId, version, digest };
153
+ }
143
154
  var Simulator = class {
144
155
  constructor(globals) {
145
156
  this.globals = globals;
146
157
  }
147
158
  async simulate(input) {
148
- const tx = this.copyTransactionBlock(input.txb);
159
+ const tx = this.copyTransaction(input.txb);
149
160
  const { suiClient } = this.globals;
150
161
  const gasPrice = await this.getGasPrice();
151
162
  tx.setGasPrice(gasPrice);
152
- const inspectResult = await suiClient.dryRunTransactionBlock({
153
- transactionBlock: await tx.build({ client: suiClient })
154
- });
155
- const success = inspectResult.effects.status.status === "success";
163
+ let built;
164
+ try {
165
+ built = await tx.build({ client: suiClient });
166
+ } catch (e) {
167
+ const message = e instanceof Error ? e.message : String(e);
168
+ return {
169
+ success: false,
170
+ gasPrice,
171
+ simulationError: message
172
+ };
173
+ }
174
+ let inspectResult;
175
+ try {
176
+ inspectResult = await suiClient.simulateTransaction({
177
+ transaction: built,
178
+ include: { effects: true }
179
+ });
180
+ } catch (e) {
181
+ const message = e instanceof Error ? e.message : String(e);
182
+ return {
183
+ success: false,
184
+ gasPrice,
185
+ simulationError: message
186
+ };
187
+ }
188
+ const txRow = inspectResult.Transaction ?? inspectResult.FailedTransaction;
189
+ const { effects } = txRow;
190
+ if (!effects) {
191
+ throw new Error("simulateTransaction did not return effects");
192
+ }
193
+ const success = effects.status.success === true;
156
194
  if (!success) {
195
+ const err = effects.status.success === false ? effects.status.error : null;
157
196
  return {
158
197
  success,
159
198
  gasPrice,
160
199
  response: inspectResult,
161
- simulationError: inspectResult.effects.status.error
200
+ simulationError: err ? formatExecutionError(err) : "Simulation failed"
162
201
  };
163
202
  }
164
- const gasBudget = this.toGasBudget(inspectResult.effects.gasUsed, gasPrice);
203
+ const gasBudget = this.toGasBudget(effects.gasUsed, gasPrice);
165
204
  return {
166
205
  success,
167
206
  gasPrice,
168
- gasObject: inspectResult.effects.gasObject.reference,
169
- gasUsed: inspectResult.effects.gasUsed,
207
+ gasObject: gasObjectToReference(effects.gasObject),
208
+ gasUsed: effects.gasUsed,
170
209
  gasBudget,
171
210
  response: inspectResult
172
211
  };
173
212
  }
174
213
  async getGasPrice() {
175
- return this.globals.suiClient.getReferenceGasPrice();
214
+ const { referenceGasPrice } = await this.globals.suiClient.getReferenceGasPrice();
215
+ return BigInt(referenceGasPrice);
176
216
  }
177
217
  toGasBudget(gasUsed, gasPrice) {
178
218
  const { computationCost, storageCost, storageRebate } = gasUsed;
@@ -181,8 +221,8 @@ var Simulator = class {
181
221
  const gasBudget = baseComputationCostWithOverhead + BigInt(storageCost) - BigInt(storageRebate);
182
222
  return gasBudget > baseComputationCostWithOverhead ? gasBudget : baseComputationCostWithOverhead;
183
223
  }
184
- copyTransactionBlock(tx) {
185
- return TransactionBlock.from(tx.serialize());
224
+ copyTransaction(tx) {
225
+ return Transaction.from(tx.serialize());
186
226
  }
187
227
  };
188
228
 
@@ -199,13 +239,13 @@ function HexToUint8Array(hex) {
199
239
  }
200
240
 
201
241
  // src/utils/crypto.ts
202
- import { verifyPersonalMessage, verifyTransactionBlock } from "@mysten/sui.js/verify";
242
+ import { verifyPersonalMessageSignature, verifyTransactionSignature } from "@mysten/sui/verify";
203
243
 
204
244
  // src/utils/format.ts
205
- import { normalizeSuiAddress, normalizeStructTag as normalizeStructTag2 } from "@mysten/sui.js/utils";
245
+ import { normalizeSuiAddress, normalizeStructTag as normalizeStructTag2 } from "@mysten/sui/utils";
206
246
 
207
247
  // src/utils/coin.ts
208
- import { normalizeStructTag } from "@mysten/sui.js/utils";
248
+ import { normalizeStructTag } from "@mysten/sui/utils";
209
249
  var CoinHelper = class {
210
250
  _client;
211
251
  _coinMetaReg;
@@ -226,7 +266,7 @@ var CoinHelper = class {
226
266
  }
227
267
  async queryCoinMeta(coinType) {
228
268
  const res = await this._client.getCoinMetadata({ coinType });
229
- return res || void 0;
269
+ return res.coinMetadata ?? void 0;
230
270
  }
231
271
  };
232
272
  var COIN_TYPE_ARG_REGEX = /^0x0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<(.+)>$/;
@@ -245,6 +285,13 @@ var Coin = class _Coin {
245
285
  if (!_Coin.isCoin(data.type)) {
246
286
  return void 0;
247
287
  }
288
+ if (data.json && typeof data.json === "object" && "balance" in data.json) {
289
+ const { balance: balance2 } = data.json;
290
+ if (balance2 === void 0) {
291
+ return void 0;
292
+ }
293
+ return BigInt(balance2);
294
+ }
248
295
  if (data.content?.dataType !== "moveObject") {
249
296
  return void 0;
250
297
  }
@@ -285,9 +332,9 @@ function addPrefix(s, prefix) {
285
332
  var SignatureVerifier = class _SignatureVerifier {
286
333
  static async getPublicKeyFromSignature(input) {
287
334
  if (input.messageType === "TransactionBlock") {
288
- return verifyTransactionBlock(input.message, input.signature);
335
+ return verifyTransactionSignature(input.message, input.signature);
289
336
  }
290
- return verifyPersonalMessage(input.message, input.signature);
337
+ return verifyPersonalMessageSignature(input.message, input.signature);
291
338
  }
292
339
  static async getPublicKeyFromPersonalSignature(input) {
293
340
  const message = stringToBuffer(input.messageStr);
@@ -322,26 +369,69 @@ var SignatureVerifier = class _SignatureVerifier {
322
369
 
323
370
  // src/utils/sui.ts
324
371
  import { PublicKeySerde as PublicKeySerde2 } from "@msafe/sui3-utils";
325
- import { parseSerializedSignature } from "@mysten/sui.js/cryptography";
326
- import { MultiSigPublicKey } from "@mysten/sui.js/multisig";
372
+ import { parseSerializedSignature } from "@mysten/sui/cryptography";
373
+ import { SuiGraphQLClient } from "@mysten/sui/graphql";
374
+ import { MultiSigPublicKey } from "@mysten/sui/multisig";
327
375
  var SUI_COIN = "0x2::sui::SUI";
376
+ var GRAPHQL_URL_BY_NETWORK = {
377
+ mainnet: "https://sui-mainnet.mystenlabs.com/graphql",
378
+ testnet: "https://sui-testnet.mystenlabs.com/graphql",
379
+ devnet: "https://sui-devnet.mystenlabs.com/graphql"
380
+ };
381
+ function graphqlClientForGrpc(suiClient) {
382
+ const url = GRAPHQL_URL_BY_NETWORK[suiClient.network] ?? GRAPHQL_URL_BY_NETWORK.testnet;
383
+ return new SuiGraphQLClient({ url, network: suiClient.network });
384
+ }
385
+ function collectSignatureStrings(value) {
386
+ if (typeof value === "string") {
387
+ return [value];
388
+ }
389
+ if (!value || typeof value !== "object") {
390
+ return [];
391
+ }
392
+ if ("base64" in value && typeof value.base64 === "string") {
393
+ return [value.base64];
394
+ }
395
+ if ("scheme" in value && "base64" in value) {
396
+ const b64 = value.base64;
397
+ return typeof b64 === "string" ? [b64] : [];
398
+ }
399
+ return [];
400
+ }
401
+ var TX_SIG_QUERY = `
402
+ query PublicKeyTxSigs($sender: SuiAddress!, $first: Int!) {
403
+ transactions(first: $first, filter: { sentAddress: $sender }) {
404
+ nodes {
405
+ signatures
406
+ }
407
+ }
408
+ }
409
+ `;
328
410
  async function getPublicKeyFromChain(suiClient, address) {
411
+ const graphql = graphqlClientForGrpc(suiClient);
329
412
  let txs;
330
413
  try {
331
- txs = await suiClient.queryTransactionBlocks({
332
- // Disable naming rule since the variable is defined by Mysten
333
- filter: { FromAddress: address },
334
- options: { showInput: true },
335
- limit: 2
414
+ const res = await graphql.query({
415
+ query: TX_SIG_QUERY,
416
+ variables: { sender: address, first: 2 }
336
417
  });
418
+ if (res.errors?.length) {
419
+ return void 0;
420
+ }
421
+ txs = res.data ?? {};
337
422
  } catch (e) {
338
423
  return void 0;
339
424
  }
340
- if (txs.data.length === 0 || !txs.data[0].transaction?.txSignatures) {
425
+ const nodes = txs.transactions?.nodes ?? [];
426
+ if (nodes.length === 0) {
427
+ return void 0;
428
+ }
429
+ const first = nodes[0];
430
+ const rawSigs = first.signatures;
431
+ const signatures = Array.isArray(rawSigs) ? rawSigs.flatMap((item) => collectSignatureStrings(item)) : [];
432
+ if (signatures.length === 0) {
341
433
  return void 0;
342
434
  }
343
- const tx = txs.data[0];
344
- const signatures = tx.transaction?.txSignatures;
345
435
  for (let i = 0; i !== signatures.length; i++) {
346
436
  const serializedSig = signatures[i];
347
437
  const pk = getAddressFromSignatures(serializedSig, address);
@@ -381,18 +471,28 @@ async function getAllCoins(input) {
381
471
  let cursor;
382
472
  const res = [];
383
473
  while (hasNext) {
384
- const currentPage = await input.suiClient.getCoins({
474
+ const currentPage = await input.suiClient.listCoins({
385
475
  owner: input.owner,
386
476
  coinType: input.coinType,
387
477
  cursor
388
478
  });
389
- res.push(...currentPage.data);
479
+ res.push(...currentPage.objects);
390
480
  hasNext = currentPage.hasNextPage;
391
- cursor = currentPage.nextCursor;
481
+ cursor = currentPage.cursor;
392
482
  }
393
483
  return res;
394
484
  }
395
485
 
486
+ // src/utils/transaction.ts
487
+ import { Transaction as Transaction2, isTransaction } from "@mysten/sui/transactions";
488
+ function toSuiTransaction(txb) {
489
+ if (isTransaction(txb)) {
490
+ return txb;
491
+ }
492
+ const legacy = txb;
493
+ return Transaction2.from(legacy.serialize());
494
+ }
495
+
396
496
  // src/utils/iter/iterator.ts
397
497
  var REQUEST_PAGE_SIZE = 25;
398
498
  async function getAllFromIterator(it) {
@@ -469,6 +569,10 @@ var EntryIterator = class {
469
569
  };
470
570
 
471
571
  // src/utils/iter/object.ts
572
+ var defaultObjectInclude = { json: true };
573
+ function mergeInclude(options) {
574
+ return { ...defaultObjectInclude, ...options?.objectInclude };
575
+ }
472
576
  async function getAllOwnedObjects(provider, owner, options) {
473
577
  const iter = new OwnedObjectIterator(provider, owner, options);
474
578
  return await getAllFromIterator(iter);
@@ -489,32 +593,29 @@ var OwnedObjectRequester = class {
489
593
  this.nextCursor = null;
490
594
  this.filter = options?.filter;
491
595
  this.pageSize = options?.pageSize || REQUEST_PAGE_SIZE;
492
- this.objectOptions = options?.objectOptions || {
493
- showType: true,
494
- showContent: true
495
- };
596
+ this.objectInclude = mergeInclude(options);
496
597
  }
497
598
  nextCursor;
498
599
  filter;
499
600
  pageSize;
500
- objectOptions;
601
+ objectInclude;
501
602
  async doNextRequest() {
502
- const res = await this.provider.getOwnedObjects({
603
+ const res = await this.provider.listOwnedObjects({
503
604
  owner: this.owner,
504
- options: this.objectOptions,
605
+ include: this.objectInclude,
505
606
  cursor: this.nextCursor,
506
607
  limit: this.pageSize
507
608
  });
508
- this.nextCursor = res.nextCursor;
609
+ this.nextCursor = res.cursor;
509
610
  let filtered;
510
611
  if (this.filter) {
511
612
  const { filter } = this;
512
- filtered = res.data.filter((obj) => filter?.(obj));
613
+ filtered = res.objects.filter((obj) => filter(obj));
513
614
  } else {
514
- filtered = res.data;
615
+ filtered = res.objects;
515
616
  }
516
617
  return {
517
- data: filtered.map((r) => r.data).filter((data) => data),
618
+ data: filtered,
518
619
  hasNext: res.hasNextPage
519
620
  };
520
621
  }
@@ -544,14 +645,21 @@ var MSafeAccount = class _MSafeAccount {
544
645
  }
545
646
  }
546
647
  async ownedCoins() {
547
- const balances = await this.suiClient.getAllBalances({ owner: this.address });
648
+ const balances = [];
649
+ let cursor = null;
650
+ let hasNext = true;
651
+ while (hasNext) {
652
+ const page = await this.suiClient.listBalances({ owner: this.address, cursor, limit: 50 });
653
+ balances.push(...page.balances);
654
+ hasNext = page.hasNextPage;
655
+ cursor = page.cursor;
656
+ }
548
657
  return Promise.all(
549
658
  balances.map(async (balance) => {
550
659
  const meta = await this.coinHelper.getCoinMeta(balance.coinType);
551
- const unlockedBalance = balance.lockedBalance.number ? BigInt(balance.totalBalance) - BigInt(balance.lockedBalance.number) : BigInt(balance.totalBalance);
552
660
  return {
553
661
  type: normalizeStructTag3(balance.coinType),
554
- balance: BigInt(unlockedBalance),
662
+ balance: BigInt(balance.addressBalance),
555
663
  metadata: meta
556
664
  };
557
665
  })
@@ -559,7 +667,7 @@ var MSafeAccount = class _MSafeAccount {
559
667
  }
560
668
  async ownedObjects(options) {
561
669
  const filterCoinObjectOptions = {
562
- filter: (objRes) => !objRes?.data?.type?.startsWith("0x2::coin::Coin"),
670
+ filter: (obj) => !obj?.type?.startsWith("0x2::coin::Coin"),
563
671
  ...options
564
672
  };
565
673
  return getAllOwnedObjects(this.suiClient, this.address, filterCoinObjectOptions);
@@ -614,19 +722,21 @@ var MSafeAccount = class _MSafeAccount {
614
722
  if (!appHelper) {
615
723
  throw new Error(`Can't find app helper for application ${request.application}`);
616
724
  }
617
- txb = await appHelper.build({
618
- network: this.globals.config.network,
619
- intentionData: request.intention,
620
- txType: request.txType,
621
- txSubType: request.txSubType,
622
- clientUrl: this.globals.config.suiClient.url,
623
- account: {
624
- address: this.address,
625
- publicKey: fromHEX(this.address),
626
- chains: [SUI_MAINNET_CHAIN, SUI_TESTNET_CHAIN],
627
- features: []
628
- }
629
- });
725
+ txb = toSuiTransaction(
726
+ await appHelper.build({
727
+ network: this.globals.config.network,
728
+ intentionData: request.intention,
729
+ txType: request.txType,
730
+ txSubType: request.txSubType,
731
+ clientUrl: this.globals.config.suiClient.url,
732
+ account: {
733
+ address: this.address,
734
+ publicKey: fromHex(this.address),
735
+ chains: [SUI_MAINNET_CHAIN, SUI_TESTNET_CHAIN],
736
+ features: []
737
+ }
738
+ })
739
+ );
630
740
  }
631
741
  txb.setSender(this.address);
632
742
  return this.simulator.simulate({ txb, sender: this.address });
@@ -655,19 +765,21 @@ var MSafeAccount = class _MSafeAccount {
655
765
  if (!appHelper) {
656
766
  throw new Error(`Can't find app helper for application ${input.application}`);
657
767
  }
658
- txb = await appHelper.build({
659
- network: this.globals.config.network,
660
- intentionData: input.intention,
661
- txType: input.txType,
662
- txSubType: input.txSubType,
663
- clientUrl: this.globals.config.suiClient.url,
664
- account: {
665
- address: this.address,
666
- publicKey: fromHEX(this.address),
667
- chains: [SUI_MAINNET_CHAIN, SUI_TESTNET_CHAIN],
668
- features: []
669
- }
670
- });
768
+ txb = toSuiTransaction(
769
+ await appHelper.build({
770
+ network: this.globals.config.network,
771
+ intentionData: input.intention,
772
+ txType: input.txType,
773
+ txSubType: input.txSubType,
774
+ clientUrl: this.globals.config.suiClient.url,
775
+ account: {
776
+ address: this.address,
777
+ publicKey: fromHex(this.address),
778
+ chains: [SUI_MAINNET_CHAIN, SUI_TESTNET_CHAIN],
779
+ features: []
780
+ }
781
+ })
782
+ );
671
783
  }
672
784
  txb.setGasPrice(input.gasPrice);
673
785
  txb.setGasBudget(input.gasBudget);
@@ -677,7 +789,7 @@ var MSafeAccount = class _MSafeAccount {
677
789
  const signature = await this.wallet.signTransactionBlock({ transactionBlock: payload });
678
790
  return this.backend.proposeIntentionAndBuildVote({
679
791
  ...input,
680
- payload: toHEX(payload),
792
+ payload: toHex(payload),
681
793
  digest,
682
794
  msafeAddress: this.address,
683
795
  signature: signature.signature
@@ -735,8 +847,9 @@ var MSafeAccount = class _MSafeAccount {
735
847
  }
736
848
  async proposePlainPayloadIntention(intention) {
737
849
  const sn = await this.nextSequenceNumber();
738
- const tb = TransactionBlock2.from(intention.payload);
739
- if (!tb.blockData.sender || !isSameAddress2(tb.blockData.sender, this.address)) {
850
+ const tb = Transaction3.from(intention.payload);
851
+ const data = tb.getData();
852
+ if (!data.sender || !isSameAddress2(data.sender, this.address)) {
740
853
  throw new Error("Transaction sender is not same as the multisig address");
741
854
  }
742
855
  return this.proposeIntention({
@@ -761,7 +874,7 @@ var MSafeAccount = class _MSafeAccount {
761
874
  if (!pendingTx || pendingTx.rejectDigest !== "") {
762
875
  throw new Error("Already rejected");
763
876
  }
764
- const txb = buildRejectTxb(this.address);
877
+ const txb = toSuiTransaction(buildRejectTxb(this.address));
765
878
  txb.setSender(this.address);
766
879
  return this.simulator.simulate({ txb, sender: this.address });
767
880
  }
@@ -770,7 +883,7 @@ var MSafeAccount = class _MSafeAccount {
770
883
  if (!pendingTx || pendingTx.rejectDigest !== "") {
771
884
  throw new Error("Already rejected");
772
885
  }
773
- const rejectTxb = buildRejectTxb(this.address);
886
+ const rejectTxb = toSuiTransaction(buildRejectTxb(this.address));
774
887
  const digest = await rejectTxb.getDigest({ client: this.suiClient });
775
888
  const payload = await rejectTxb.build({ client: this.suiClient });
776
889
  const signature = await this.wallet.signTransactionBlock({ transactionBlock: payload });
@@ -787,19 +900,21 @@ var MSafeAccount = class _MSafeAccount {
787
900
  if (!appHelper) {
788
901
  throw new Error(`Can't find app helper for application ${intention.application}`);
789
902
  }
790
- const txb = await appHelper.build({
791
- network: this.globals.config.network,
792
- intentionData: intention.intention,
793
- txType: intention.txType,
794
- txSubType: intention.txSubType,
795
- clientUrl: this.globals.config.suiClient.url,
796
- account: {
797
- address: this.address,
798
- publicKey: fromHEX(this.address),
799
- chains: [SUI_MAINNET_CHAIN, SUI_TESTNET_CHAIN],
800
- features: []
801
- }
802
- });
903
+ const txb = toSuiTransaction(
904
+ await appHelper.build({
905
+ network: this.globals.config.network,
906
+ intentionData: intention.intention,
907
+ txType: intention.txType,
908
+ txSubType: intention.txSubType,
909
+ clientUrl: this.globals.config.suiClient.url,
910
+ account: {
911
+ address: this.address,
912
+ publicKey: fromHex(this.address),
913
+ chains: [SUI_MAINNET_CHAIN, SUI_TESTNET_CHAIN],
914
+ features: []
915
+ }
916
+ })
917
+ );
803
918
  txb.setSender(this.address);
804
919
  return this.simulator.simulate({ txb, sender: this.address });
805
920
  }
@@ -833,10 +948,10 @@ var MSafeAccount = class _MSafeAccount {
833
948
  }
834
949
  }
835
950
  const multiSignature = this.multiSig.combinePartialSignatures(sortedSigs);
836
- return this.suiClient.executeTransactionBlock({
837
- transactionBlock: HexToUint8Array(payload),
838
- signature: multiSignature,
839
- options: { showEffects: true, showEvents: true }
951
+ return this.suiClient.executeTransaction({
952
+ transaction: HexToUint8Array(payload),
953
+ signatures: [multiSignature],
954
+ include: { effects: true, events: true }
840
955
  });
841
956
  }
842
957
  async dashboard() {
@@ -876,7 +991,7 @@ var MSafeAccount = class _MSafeAccount {
876
991
 
877
992
  // src/core/PublicKeyHelper.ts
878
993
  import { isSameAddress as isSameAddress3 } from "@msafe/sui3-utils";
879
- import { normalizeSuiAddress as normalizeSuiAddress2 } from "@mysten/sui.js/utils";
994
+ import { normalizeSuiAddress as normalizeSuiAddress2 } from "@mysten/sui/utils";
880
995
  var PublicKeyHelper = class {
881
996
  constructor(globals) {
882
997
  this.globals = globals;
@@ -962,7 +1077,7 @@ var ReportSDK = class {
962
1077
  };
963
1078
 
964
1079
  // src/globals/MSafeGlobals.ts
965
- import { SuiClient } from "@mysten/sui.js/client";
1080
+ import { SuiGrpcClient } from "@mysten/sui/grpc";
966
1081
 
967
1082
  // src/backend/BackendImpl.ts
968
1083
  import {
@@ -1274,6 +1389,9 @@ var BackendError = class _BackendError extends Error {
1274
1389
  };
1275
1390
 
1276
1391
  // src/globals/const.ts
1392
+ function msafeChainToSuiNetwork(chain) {
1393
+ return chain === "sui:mainnet" ? "mainnet" : "testnet";
1394
+ }
1277
1395
  var MSafeEnv = /* @__PURE__ */ ((MSafeEnv3) => {
1278
1396
  MSafeEnv3["local"] = "local";
1279
1397
  MSafeEnv3["unit"] = "unit";
@@ -1282,6 +1400,16 @@ var MSafeEnv = /* @__PURE__ */ ((MSafeEnv3) => {
1282
1400
  MSafeEnv3["prod"] = "prod";
1283
1401
  return MSafeEnv3;
1284
1402
  })(MSafeEnv || {});
1403
+ function httpUrlToGrpcBaseUrl(url) {
1404
+ const parsed = new URL(url);
1405
+ if (parsed.protocol === "https:" && parsed.port === "") {
1406
+ return `https://${parsed.hostname}:443${parsed.pathname}${parsed.search}`;
1407
+ }
1408
+ if (parsed.protocol === "http:" && parsed.port === "") {
1409
+ return `http://${parsed.hostname}:80${parsed.pathname}${parsed.search}`;
1410
+ }
1411
+ return `${parsed.origin}${parsed.pathname}${parsed.search}`;
1412
+ }
1285
1413
  var TESTNET_RPC_URL = "https://fullnode.testnet.sui.io";
1286
1414
  var MAINNET_RPC_URL = "https://fullnode.mainnet.sui.io";
1287
1415
  var LOCAL_API_URL = "http://127.0.0.1:3000";
@@ -1298,9 +1426,9 @@ var ENV_CONFIGS = /* @__PURE__ */ new Map([
1298
1426
  url: TESTNET_RPC_URL
1299
1427
  },
1300
1428
  backend: {
1301
- url: LOCAL_API_URL
1429
+ url: DEV_API_URL
1302
1430
  },
1303
- syncingURL: LOCAL_SYNCING_URL,
1431
+ syncingURL: DEV_SYNCING_URL,
1304
1432
  network: "sui:testnet"
1305
1433
  }
1306
1434
  ],
@@ -1387,9 +1515,13 @@ var MSafeGlobals = class _MSafeGlobals {
1387
1515
  }
1388
1516
  static async New(env, options) {
1389
1517
  const config = getMSafeConfig(env, options);
1390
- const suiClient = new SuiClient(
1391
- config.suiClient.transport ? { transport: config.suiClient.transport } : { url: config.suiClient.url }
1392
- );
1518
+ const suiClient = config.suiClient.transport ? new SuiGrpcClient({
1519
+ transport: config.suiClient.transport,
1520
+ network: msafeChainToSuiNetwork(config.network)
1521
+ }) : new SuiGrpcClient({
1522
+ baseUrl: httpUrlToGrpcBaseUrl(config.suiClient.url),
1523
+ network: msafeChainToSuiNetwork(config.network)
1524
+ });
1393
1525
  const backend = new BackendImpl(config.backend.url, options?.mockAddress);
1394
1526
  return new _MSafeGlobals({
1395
1527
  backend,
@@ -1558,6 +1690,9 @@ export {
1558
1690
  getAllCoins,
1559
1691
  getMSafeConfig,
1560
1692
  getPublicKeyFromChain,
1561
- stringToBuffer
1693
+ httpUrlToGrpcBaseUrl,
1694
+ msafeChainToSuiNetwork,
1695
+ stringToBuffer,
1696
+ toSuiTransaction
1562
1697
  };
1563
1698
  //# sourceMappingURL=index.js.map