@msafe/sui3-sdk 0.0.63 → 0.0.65

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