@msafe/sui3-sdk 0.0.65 → 0.0.67

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
@@ -4,7 +4,7 @@ import {
4
4
  MultiSigAccount,
5
5
  PublicKeySerde,
6
6
  SigningMessageHelper
7
- } from "@msafe/iota-utils";
7
+ } from "@msafe/sui3-utils";
8
8
  var CreateHelper = class {
9
9
  constructor(globals, pkHelper) {
10
10
  this.globals = globals;
@@ -32,7 +32,7 @@ var CreateHelper = class {
32
32
  */
33
33
  addPublicKey(address, pkEncoded) {
34
34
  const pk = PublicKeySerde.de(pkEncoded);
35
- if (!isSameAddress(address, pk.toIotaAddress())) {
35
+ if (!isSameAddress(address, pk.toSuiAddress())) {
36
36
  throw new Error("Public key not match");
37
37
  }
38
38
  this.pkHelper.addPublicKey(address, pk);
@@ -84,10 +84,10 @@ var CreateHelper = class {
84
84
  import {
85
85
  SigningMessageHelper as SigningMessageHelper4,
86
86
  UserMSafeStatus as UserMSafeStatus2
87
- } from "@msafe/iota-utils";
87
+ } from "@msafe/sui3-utils";
88
88
 
89
89
  // src/core/AddressBookSDK.ts
90
- import { SigningMessageHelper as SigningMessageHelper2 } from "@msafe/iota-utils";
90
+ import { SigningMessageHelper as SigningMessageHelper2 } from "@msafe/sui3-utils";
91
91
  var AddressBookSDK = class {
92
92
  constructor(globals) {
93
93
  this.globals = globals;
@@ -123,7 +123,7 @@ var InvitationSDK = class {
123
123
  };
124
124
 
125
125
  // src/core/MSafeAccount.ts
126
- import { appHelpers } from "@msafe/iota-app-store";
126
+ import { appHelpers } from "@msafe/sui-app-store";
127
127
  import {
128
128
  MultiSigAccount as MultiSigAccount2,
129
129
  SigningMessageHelper as SigningMessageHelper3,
@@ -132,12 +132,13 @@ import {
132
132
  TransactionType,
133
133
  buildRejectTxb,
134
134
  isSameAddress as isSameAddress2
135
- } from "@msafe/iota-utils";
136
- import { TransactionBlock as TransactionBlock2 } from "@iota/iota-sdk/transactions";
137
- import { fromHEX, normalizeStructTag as normalizeStructTag3, toHEX } from "@iota/iota-sdk/utils";
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";
138
+ import { SUI_MAINNET_CHAIN, SUI_TESTNET_CHAIN } from "@mysten/wallet-standard";
138
139
 
139
140
  // src/simulate/simulator.ts
140
- import { TransactionBlock } from "@iota/iota-sdk/transactions";
141
+ import { TransactionBlock } from "@mysten/sui.js/transactions";
141
142
  var GAS_SAFE_OVERHEAD = 1000n;
142
143
  var DEF_GAS_PRICE_NUM = 120n;
143
144
  var DEF_GAS_PRICE_DEN = 100n;
@@ -161,12 +162,12 @@ var Simulator = class {
161
162
  }
162
163
  async simulate(input, gasOption = DEF_GAS_PRICE_OPTION, budgetOption = DEF_GAS_BUDGET_OPTION) {
163
164
  const tx = this.copyTransactionBlock(input.txb);
164
- const { client } = this.globals;
165
+ const { suiClient } = this.globals;
165
166
  const gasPrice = await this.getGasPrice(gasOption);
166
167
  tx.setGasPrice(gasPrice);
167
168
  try {
168
- const inspectResult = await client.dryRunTransactionBlock({
169
- transactionBlock: await tx.build({ client })
169
+ const inspectResult = await suiClient.dryRunTransactionBlock({
170
+ transactionBlock: await tx.build({ client: suiClient })
170
171
  });
171
172
  const { gasUsed } = inspectResult.effects;
172
173
  const gasBudget = this.toGasBudget(gasUsed, gasPrice);
@@ -207,7 +208,7 @@ var Simulator = class {
207
208
  if (this.isFixedValue(option)) {
208
209
  return option.fixedVal;
209
210
  }
210
- const refGasPrice = await this.globals.client.getReferenceGasPrice();
211
+ const refGasPrice = await this.globals.suiClient.getReferenceGasPrice();
211
212
  return this.applyGasOption(refGasPrice, option);
212
213
  }
213
214
  toGasBudget(gasUsed, gasPrice) {
@@ -261,13 +262,13 @@ function HexToUint8Array(hex) {
261
262
  }
262
263
 
263
264
  // src/utils/crypto.ts
264
- import { verifyPersonalMessage, verifyTransactionBlock } from "@iota/iota-sdk/verify";
265
+ import { verifyPersonalMessage, verifyTransactionBlock } from "@mysten/sui.js/verify";
265
266
 
266
267
  // src/utils/format.ts
267
- import { normalizeIotaAddress, normalizeStructTag as normalizeStructTag2 } from "@iota/iota-sdk/utils";
268
+ import { normalizeSuiAddress, normalizeStructTag as normalizeStructTag2 } from "@mysten/sui.js/utils";
268
269
 
269
270
  // src/utils/coin.ts
270
- import { normalizeStructTag } from "@iota/iota-sdk/utils";
271
+ import { normalizeStructTag } from "@mysten/sui.js/utils";
271
272
  var CoinHelper = class {
272
273
  _client;
273
274
  _coinMetaReg;
@@ -320,14 +321,14 @@ var Coin = class _Coin {
320
321
 
321
322
  // src/utils/format.ts
322
323
  var Formatter = class {
323
- static normalizeIotaAddress(addr) {
324
- return normalizeIotaAddress(addr);
324
+ static normalizeSuiAddress(addr) {
325
+ return normalizeSuiAddress(addr);
325
326
  }
326
327
  static normalizeStructTag(struct) {
327
328
  return normalizeStructTag2(struct);
328
329
  }
329
330
  static isSuiAddressEqual(addr1, addr2) {
330
- return normalizeIotaAddress(addr1) === normalizeIotaAddress(addr2);
331
+ return normalizeSuiAddress(addr1) === normalizeSuiAddress(addr2);
331
332
  }
332
333
  static isSuiStructEqual(struct1, struct2) {
333
334
  return normalizeStructTag2(struct1) === normalizeStructTag2(struct2);
@@ -361,7 +362,7 @@ var SignatureVerifier = class _SignatureVerifier {
361
362
  }
362
363
  static async verifySignature(input) {
363
364
  const publicKey = await _SignatureVerifier.getPublicKeyFromSignature(input);
364
- return Formatter.isSuiAddressEqual(publicKey.toIotaAddress(), input.targetAddress);
365
+ return Formatter.isSuiAddressEqual(publicKey.toSuiAddress(), input.targetAddress);
365
366
  }
366
367
  static async verifyPersonalSignature(input) {
367
368
  const message = stringToBuffer(input.messageStr);
@@ -383,14 +384,14 @@ var SignatureVerifier = class _SignatureVerifier {
383
384
  };
384
385
 
385
386
  // src/utils/sui.ts
386
- import { PublicKeySerde as PublicKeySerde2 } from "@msafe/iota-utils";
387
- import { parseSerializedSignature } from "@iota/iota-sdk/cryptography";
388
- import { MultiSigPublicKey } from "@iota/iota-sdk/multisig";
387
+ import { PublicKeySerde as PublicKeySerde2 } from "@msafe/sui3-utils";
388
+ import { parseSerializedSignature } from "@mysten/sui.js/cryptography";
389
+ import { MultiSigPublicKey } from "@mysten/sui.js/multisig";
389
390
  var SUI_COIN = "0x2::sui::SUI";
390
- async function getPublicKeyFromChain(client, address) {
391
+ async function getPublicKeyFromChain(suiClient, address) {
391
392
  let txs;
392
393
  try {
393
- txs = await client.queryTransactionBlocks({
394
+ txs = await suiClient.queryTransactionBlocks({
394
395
  // Disable naming rule since the variable is defined by Mysten
395
396
  filter: { FromAddress: address },
396
397
  options: { showInput: true },
@@ -418,7 +419,7 @@ function getAddressFromSignatures(serializedSig, targetAddress) {
418
419
  const decoded = parseSerializedSignature(serializedSig);
419
420
  switch (decoded.signatureScheme) {
420
421
  case "MultiSig": {
421
- const multiSigAddress = new MultiSigPublicKey(decoded.multisig.multisig_pk).toIotaAddress();
422
+ const multiSigAddress = new MultiSigPublicKey(decoded.multisig.multisig_pk).toSuiAddress();
422
423
  if (Formatter.isSuiAddressEqual(multiSigAddress, targetAddress)) {
423
424
  throw new Error("multi-sig wallet cannot be owner");
424
425
  }
@@ -434,7 +435,7 @@ function getAddressFromSignatures(serializedSig, targetAddress) {
434
435
  case "Secp256k1":
435
436
  case "Secp256r1": {
436
437
  const pk = PublicKeySerde2.de({ publicKeyEncoded: decoded.publicKey, schema: decoded.signatureScheme });
437
- if (Formatter.isSuiAddressEqual(pk.toIotaAddress(), targetAddress)) {
438
+ if (Formatter.isSuiAddressEqual(pk.toSuiAddress(), targetAddress)) {
438
439
  return pk;
439
440
  }
440
441
  return void 0;
@@ -448,7 +449,7 @@ async function getAllCoins(input) {
448
449
  let cursor;
449
450
  const res = [];
450
451
  while (hasNext) {
451
- const currentPage = await input.client.getCoins({
452
+ const currentPage = await input.suiClient.getCoins({
452
453
  owner: input.owner,
453
454
  coinType: input.coinType,
454
455
  cursor
@@ -597,7 +598,7 @@ var MSafeAccount = class _MSafeAccount {
597
598
  ownersWithWeight: info.owners,
598
599
  creationNonce: info.creationNonce
599
600
  });
600
- this.coinHelper = new CoinHelper(this.client);
601
+ this.coinHelper = new CoinHelper(this.suiClient);
601
602
  this.simulator = new Simulator(globals);
602
603
  }
603
604
  multiSig;
@@ -611,7 +612,7 @@ var MSafeAccount = class _MSafeAccount {
611
612
  }
612
613
  }
613
614
  async ownedCoins() {
614
- const balances = await this.client.getAllBalances({ owner: this.address });
615
+ const balances = await this.suiClient.getAllBalances({ owner: this.address });
615
616
  return Promise.all(
616
617
  balances.map(async (balance) => {
617
618
  const meta = await this.coinHelper.getCoinMeta(balance.coinType);
@@ -629,7 +630,7 @@ var MSafeAccount = class _MSafeAccount {
629
630
  filter: (objRes) => !objRes?.data?.type?.startsWith("0x2::coin::Coin"),
630
631
  ...options
631
632
  };
632
- return getAllOwnedObjects(this.client, this.address, filterCoinObjectOptions);
633
+ return getAllOwnedObjects(this.suiClient, this.address, filterCoinObjectOptions);
633
634
  }
634
635
  async pendingTransaction() {
635
636
  const res = await this.backend.getPendingTransactions({ msafeAddress: this.address });
@@ -682,11 +683,11 @@ var MSafeAccount = class _MSafeAccount {
682
683
  intentionData: request.intention,
683
684
  txType: request.txType,
684
685
  txSubType: request.txSubType,
685
- client: this.globals.client,
686
+ clientUrl: this.globals.config.suiClient.url,
686
687
  account: {
687
688
  address: this.address,
688
689
  publicKey: fromHEX(this.address),
689
- chains: [],
690
+ chains: [SUI_MAINNET_CHAIN, SUI_TESTNET_CHAIN],
690
691
  features: []
691
692
  }
692
693
  });
@@ -718,19 +719,19 @@ var MSafeAccount = class _MSafeAccount {
718
719
  intentionData: input.intention,
719
720
  txType: input.txType,
720
721
  txSubType: input.txSubType,
721
- client: this.globals.client,
722
+ clientUrl: this.globals.config.suiClient.url,
722
723
  account: {
723
724
  address: this.address,
724
725
  publicKey: fromHEX(this.address),
725
- chains: [],
726
+ chains: [SUI_MAINNET_CHAIN, SUI_TESTNET_CHAIN],
726
727
  features: []
727
728
  }
728
729
  });
729
730
  txb.setGasPrice(input.gasPrice);
730
731
  txb.setGasBudget(input.gasBudget);
731
732
  txb.setSender(this.address);
732
- const payload = await txb.build({ client: this.globals.client });
733
- const digest = await txb.getDigest({ client: this.globals.client });
733
+ const payload = await txb.build({ client: this.globals.suiClient });
734
+ const digest = await txb.getDigest({ client: this.globals.suiClient });
734
735
  const signature = await this.wallet.signTransactionBlock({ transactionBlock: payload });
735
736
  return this.backend.proposeIntentionAndBuildVote({
736
737
  ...input,
@@ -828,8 +829,8 @@ var MSafeAccount = class _MSafeAccount {
828
829
  throw new Error("Already rejected");
829
830
  }
830
831
  const rejectTxb = buildRejectTxb(this.address);
831
- const digest = await rejectTxb.getDigest({ client: this.client });
832
- const payload = await rejectTxb.build({ client: this.client });
832
+ const digest = await rejectTxb.getDigest({ client: this.suiClient });
833
+ const payload = await rejectTxb.build({ client: this.suiClient });
833
834
  const signature = await this.wallet.signTransactionBlock({ transactionBlock: payload });
834
835
  return this.backend.rejectCurrentTx({
835
836
  msafeAddress: this.address,
@@ -849,11 +850,11 @@ var MSafeAccount = class _MSafeAccount {
849
850
  intentionData: intention.intention,
850
851
  txType: intention.txType,
851
852
  txSubType: intention.txSubType,
852
- client: this.globals.client,
853
+ clientUrl: this.globals.config.suiClient.url,
853
854
  account: {
854
855
  address: this.address,
855
856
  publicKey: fromHEX(this.address),
856
- chains: [],
857
+ chains: [SUI_MAINNET_CHAIN, SUI_TESTNET_CHAIN],
857
858
  features: []
858
859
  }
859
860
  });
@@ -887,7 +888,7 @@ var MSafeAccount = class _MSafeAccount {
887
888
  }
888
889
  }
889
890
  const multiSignature = this.multiSig.combinePartialSignatures(sortedSigs);
890
- return this.client.executeTransactionBlock({
891
+ return this.suiClient.executeTransactionBlock({
891
892
  transactionBlock: HexToUint8Array(payload),
892
893
  signature: multiSignature,
893
894
  options: { showEffects: true, showEvents: true }
@@ -923,14 +924,14 @@ var MSafeAccount = class _MSafeAccount {
923
924
  async userAddress() {
924
925
  return this.globals.wallet.address();
925
926
  }
926
- get client() {
927
- return this.globals.client;
927
+ get suiClient() {
928
+ return this.globals.suiClient;
928
929
  }
929
930
  };
930
931
 
931
932
  // src/core/PublicKeyHelper.ts
932
- import { isSameAddress as isSameAddress3 } from "@msafe/iota-utils";
933
- import { normalizeIotaAddress as normalizeIotaAddress2 } from "@iota/iota-sdk/utils";
933
+ import { isSameAddress as isSameAddress3 } from "@msafe/sui3-utils";
934
+ import { normalizeSuiAddress as normalizeSuiAddress2 } from "@mysten/sui.js/utils";
934
935
  var PublicKeyHelper = class {
935
936
  constructor(globals) {
936
937
  this.globals = globals;
@@ -976,10 +977,10 @@ var PublicKeyHelper = class {
976
977
  return results;
977
978
  }
978
979
  addPublicKey(address, publicKey) {
979
- if (!isSameAddress3(address, publicKey.toIotaAddress())) {
980
+ if (!isSameAddress3(address, publicKey.toSuiAddress())) {
980
981
  throw new Error("Invalid public key");
981
982
  }
982
- this.knownPublicKeys.set(normalizeIotaAddress2(address), publicKey);
983
+ this.knownPublicKeys.set(normalizeSuiAddress2(address), publicKey);
983
984
  }
984
985
  async _getPublicKey(address) {
985
986
  const pkBackend = await this.getPublicKeyFromBackend(address);
@@ -1001,7 +1002,7 @@ var PublicKeyHelper = class {
1001
1002
  }
1002
1003
  }
1003
1004
  async getPublicKeyFromChain(address) {
1004
- return getPublicKeyFromChain(this.globals.client, address);
1005
+ return getPublicKeyFromChain(this.globals.suiClient, address);
1005
1006
  }
1006
1007
  };
1007
1008
 
@@ -1016,13 +1017,13 @@ var ReportSDK = class {
1016
1017
  };
1017
1018
 
1018
1019
  // src/globals/MSafeGlobals.ts
1019
- import { IotaClient } from "@iota/iota-sdk/client";
1020
+ import { SuiClient } from "@mysten/sui.js/client";
1020
1021
 
1021
1022
  // src/backend/BackendImpl.ts
1022
1023
  import {
1023
1024
  PublicKeySerde as PublicKeySerde3,
1024
1025
  UserMSafeStatus
1025
- } from "@msafe/iota-utils";
1026
+ } from "@msafe/sui3-utils";
1026
1027
  import axios from "axios";
1027
1028
  var BackendImpl = class _BackendImpl {
1028
1029
  constructor(apiURL, mockAddress) {
@@ -1329,7 +1330,7 @@ var ENV_CONFIGS = /* @__PURE__ */ new Map([
1329
1330
  [
1330
1331
  "unit" /* unit */,
1331
1332
  {
1332
- client: {
1333
+ suiClient: {
1333
1334
  url: TESTNET_RPC_URL
1334
1335
  },
1335
1336
  backend: {
@@ -1342,7 +1343,7 @@ var ENV_CONFIGS = /* @__PURE__ */ new Map([
1342
1343
  [
1343
1344
  "local" /* local */,
1344
1345
  {
1345
- client: {
1346
+ suiClient: {
1346
1347
  url: TESTNET_RPC_URL
1347
1348
  },
1348
1349
  backend: {
@@ -1355,7 +1356,7 @@ var ENV_CONFIGS = /* @__PURE__ */ new Map([
1355
1356
  [
1356
1357
  "dev" /* dev */,
1357
1358
  {
1358
- client: {
1359
+ suiClient: {
1359
1360
  url: TESTNET_RPC_URL
1360
1361
  },
1361
1362
  backend: {
@@ -1368,7 +1369,7 @@ var ENV_CONFIGS = /* @__PURE__ */ new Map([
1368
1369
  [
1369
1370
  "prev" /* prev */,
1370
1371
  {
1371
- client: {
1372
+ suiClient: {
1372
1373
  url: MAINNET_RPC_URL
1373
1374
  },
1374
1375
  backend: {
@@ -1381,7 +1382,7 @@ var ENV_CONFIGS = /* @__PURE__ */ new Map([
1381
1382
  [
1382
1383
  "prod" /* prod */,
1383
1384
  {
1384
- client: {
1385
+ suiClient: {
1385
1386
  url: MAINNET_RPC_URL
1386
1387
  },
1387
1388
  backend: {
@@ -1397,8 +1398,8 @@ function getMSafeConfig(env, options) {
1397
1398
  if (!config) {
1398
1399
  throw new Error("Unknown environment");
1399
1400
  }
1400
- if (options?.client?.url) {
1401
- config.client.url = options.client.url;
1401
+ if (options?.suiClient?.url) {
1402
+ config.suiClient.url = options.suiClient.url;
1402
1403
  }
1403
1404
  if (options?.backend?.url) {
1404
1405
  config.backend.url = options.backend.url;
@@ -1409,21 +1410,21 @@ function getMSafeConfig(env, options) {
1409
1410
  // src/globals/MSafeGlobals.ts
1410
1411
  var MSafeGlobals = class _MSafeGlobals {
1411
1412
  backend;
1412
- client;
1413
+ suiClient;
1413
1414
  config;
1414
1415
  _wallet;
1415
1416
  constructor(input) {
1416
1417
  this.backend = input.backend;
1417
- this.client = input.client;
1418
+ this.suiClient = input.suiClient;
1418
1419
  this.config = input.config;
1419
1420
  }
1420
1421
  static async New(env, options) {
1421
1422
  const config = getMSafeConfig(env, options);
1422
- const client = new IotaClient(config.client);
1423
+ const suiClient = new SuiClient(config.suiClient);
1423
1424
  const backend = new BackendImpl(config.backend.url, options?.mockAddress);
1424
1425
  return new _MSafeGlobals({
1425
1426
  backend,
1426
- client,
1427
+ suiClient,
1427
1428
  config
1428
1429
  });
1429
1430
  }