@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.cjs +100 -101
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +31 -31
- package/dist/index.d.ts +31 -31
- package/dist/index.js +62 -63
- package/dist/index.js.map +1 -1
- package/package.json +10 -13
- package/src/backend/BackendImpl.ts +2 -2
- package/src/backend/interface.ts +2 -2
- package/src/core/AddressBookSDK.ts +1 -1
- package/src/core/CreateHelper.ts +3 -3
- package/src/core/InvitationSDK.ts +1 -1
- package/src/core/MSafeAccount.ts +25 -26
- package/src/core/MSafeClient.ts +1 -1
- package/src/core/PublicKeyHelper.ts +6 -6
- package/src/core/ReportSDK.ts +1 -1
- package/src/globals/MSafeGlobals.ts +6 -6
- package/src/globals/const.ts +9 -9
- package/src/simulate/simulator.ts +6 -6
- package/src/types/assets.ts +1 -1
- package/src/types/msafe.ts +4 -4
- package/src/types/wallet.ts +7 -7
- package/src/utils/coin.ts +5 -5
- package/src/utils/crypto.ts +3 -3
- package/src/utils/format.ts +4 -4
- package/src/utils/iter/object.ts +28 -28
- package/src/utils/sui.ts +10 -10
package/dist/index.cjs
CHANGED
|
@@ -62,7 +62,7 @@ __export(src_exports, {
|
|
|
62
62
|
module.exports = __toCommonJS(src_exports);
|
|
63
63
|
|
|
64
64
|
// src/core/CreateHelper.ts
|
|
65
|
-
var
|
|
65
|
+
var import_iota_utils = require("@msafe/iota-utils");
|
|
66
66
|
var CreateHelper = class {
|
|
67
67
|
constructor(globals, pkHelper) {
|
|
68
68
|
this.globals = globals;
|
|
@@ -73,7 +73,7 @@ var CreateHelper = class {
|
|
|
73
73
|
}
|
|
74
74
|
async calculateMSafeAddress(info) {
|
|
75
75
|
const msConfig = await this.reduceCreationInfoToRawConfig(info);
|
|
76
|
-
const ms = new
|
|
76
|
+
const ms = new import_iota_utils.MultiSigAccount(msConfig);
|
|
77
77
|
return ms.address;
|
|
78
78
|
}
|
|
79
79
|
// Validate the create info and return the msafe address.
|
|
@@ -89,15 +89,15 @@ var CreateHelper = class {
|
|
|
89
89
|
* @throws error if the public key does not match
|
|
90
90
|
*/
|
|
91
91
|
addPublicKey(address, pkEncoded) {
|
|
92
|
-
const pk =
|
|
93
|
-
if (!(0,
|
|
92
|
+
const pk = import_iota_utils.PublicKeySerde.de(pkEncoded);
|
|
93
|
+
if (!(0, import_iota_utils.isSameAddress)(address, pk.toIotaAddress())) {
|
|
94
94
|
throw new Error("Public key not match");
|
|
95
95
|
}
|
|
96
96
|
this.pkHelper.addPublicKey(address, pk);
|
|
97
97
|
}
|
|
98
98
|
async submitMSafeCreation(creationInfo) {
|
|
99
99
|
const msafeAddress = await this.validateCreateInfo(creationInfo);
|
|
100
|
-
const signingMessage =
|
|
100
|
+
const signingMessage = import_iota_utils.SigningMessageHelper.createMSafeMessage(msafeAddress);
|
|
101
101
|
const signature = await this.globals.wallet.signPersonalMessage({ messageStr: signingMessage });
|
|
102
102
|
await this.submitToBackend(creationInfo, signature.signature);
|
|
103
103
|
return msafeAddress;
|
|
@@ -125,7 +125,7 @@ var CreateHelper = class {
|
|
|
125
125
|
address: owner.address,
|
|
126
126
|
weight: owner.weight,
|
|
127
127
|
status: "",
|
|
128
|
-
...
|
|
128
|
+
...import_iota_utils.PublicKeySerde.ser(pks[i])
|
|
129
129
|
})),
|
|
130
130
|
threshold: createInfo.threshold,
|
|
131
131
|
name: createInfo.name,
|
|
@@ -139,10 +139,10 @@ var CreateHelper = class {
|
|
|
139
139
|
};
|
|
140
140
|
|
|
141
141
|
// src/core/MSafeClient.ts
|
|
142
|
-
var
|
|
142
|
+
var import_iota_utils7 = require("@msafe/iota-utils");
|
|
143
143
|
|
|
144
144
|
// src/core/AddressBookSDK.ts
|
|
145
|
-
var
|
|
145
|
+
var import_iota_utils2 = require("@msafe/iota-utils");
|
|
146
146
|
var AddressBookSDK = class {
|
|
147
147
|
constructor(globals) {
|
|
148
148
|
this.globals = globals;
|
|
@@ -151,7 +151,7 @@ var AddressBookSDK = class {
|
|
|
151
151
|
return this.globals.backend.getAddressBookEntries(pagination);
|
|
152
152
|
}
|
|
153
153
|
async update(updates) {
|
|
154
|
-
const messageStr =
|
|
154
|
+
const messageStr = import_iota_utils2.SigningMessageHelper.updateAddressBookMessage(updates);
|
|
155
155
|
const sig = await this.globals.wallet.signPersonalMessage({ messageStr });
|
|
156
156
|
return this.globals.backend.updateAddressBook({ updates, signature: sig.signature });
|
|
157
157
|
}
|
|
@@ -178,14 +178,13 @@ var InvitationSDK = class {
|
|
|
178
178
|
};
|
|
179
179
|
|
|
180
180
|
// src/core/MSafeAccount.ts
|
|
181
|
-
var
|
|
182
|
-
var
|
|
183
|
-
var import_transactions2 = require("@
|
|
184
|
-
var import_utils3 = require("@
|
|
185
|
-
var import_wallet_standard = require("@mysten/wallet-standard");
|
|
181
|
+
var import_iota_app_store = require("@msafe/iota-app-store");
|
|
182
|
+
var import_iota_utils4 = require("@msafe/iota-utils");
|
|
183
|
+
var import_transactions2 = require("@iota/iota-sdk/transactions");
|
|
184
|
+
var import_utils3 = require("@iota/iota-sdk/utils");
|
|
186
185
|
|
|
187
186
|
// src/simulate/simulator.ts
|
|
188
|
-
var import_transactions = require("@
|
|
187
|
+
var import_transactions = require("@iota/iota-sdk/transactions");
|
|
189
188
|
var GAS_SAFE_OVERHEAD = 1000n;
|
|
190
189
|
var DEF_GAS_PRICE_NUM = 120n;
|
|
191
190
|
var DEF_GAS_PRICE_DEN = 100n;
|
|
@@ -209,12 +208,12 @@ var Simulator = class {
|
|
|
209
208
|
}
|
|
210
209
|
async simulate(input, gasOption = DEF_GAS_PRICE_OPTION, budgetOption = DEF_GAS_BUDGET_OPTION) {
|
|
211
210
|
const tx = this.copyTransactionBlock(input.txb);
|
|
212
|
-
const {
|
|
211
|
+
const { client } = this.globals;
|
|
213
212
|
const gasPrice = await this.getGasPrice(gasOption);
|
|
214
213
|
tx.setGasPrice(gasPrice);
|
|
215
214
|
try {
|
|
216
|
-
const inspectResult = await
|
|
217
|
-
transactionBlock: await tx.build({ client
|
|
215
|
+
const inspectResult = await client.dryRunTransactionBlock({
|
|
216
|
+
transactionBlock: await tx.build({ client })
|
|
218
217
|
});
|
|
219
218
|
const { gasUsed } = inspectResult.effects;
|
|
220
219
|
const gasBudget = this.toGasBudget(gasUsed, gasPrice);
|
|
@@ -255,7 +254,7 @@ var Simulator = class {
|
|
|
255
254
|
if (this.isFixedValue(option)) {
|
|
256
255
|
return option.fixedVal;
|
|
257
256
|
}
|
|
258
|
-
const refGasPrice = await this.globals.
|
|
257
|
+
const refGasPrice = await this.globals.client.getReferenceGasPrice();
|
|
259
258
|
return this.applyGasOption(refGasPrice, option);
|
|
260
259
|
}
|
|
261
260
|
toGasBudget(gasUsed, gasPrice) {
|
|
@@ -309,13 +308,13 @@ function HexToUint8Array(hex) {
|
|
|
309
308
|
}
|
|
310
309
|
|
|
311
310
|
// src/utils/crypto.ts
|
|
312
|
-
var import_verify = require("@
|
|
311
|
+
var import_verify = require("@iota/iota-sdk/verify");
|
|
313
312
|
|
|
314
313
|
// src/utils/format.ts
|
|
315
|
-
var import_utils2 = require("@
|
|
314
|
+
var import_utils2 = require("@iota/iota-sdk/utils");
|
|
316
315
|
|
|
317
316
|
// src/utils/coin.ts
|
|
318
|
-
var import_utils = require("@
|
|
317
|
+
var import_utils = require("@iota/iota-sdk/utils");
|
|
319
318
|
var CoinHelper = class {
|
|
320
319
|
_client;
|
|
321
320
|
_coinMetaReg;
|
|
@@ -368,14 +367,14 @@ var Coin = class _Coin {
|
|
|
368
367
|
|
|
369
368
|
// src/utils/format.ts
|
|
370
369
|
var Formatter = class {
|
|
371
|
-
static
|
|
372
|
-
return (0, import_utils2.
|
|
370
|
+
static normalizeIotaAddress(addr) {
|
|
371
|
+
return (0, import_utils2.normalizeIotaAddress)(addr);
|
|
373
372
|
}
|
|
374
373
|
static normalizeStructTag(struct) {
|
|
375
374
|
return (0, import_utils2.normalizeStructTag)(struct);
|
|
376
375
|
}
|
|
377
376
|
static isSuiAddressEqual(addr1, addr2) {
|
|
378
|
-
return (0, import_utils2.
|
|
377
|
+
return (0, import_utils2.normalizeIotaAddress)(addr1) === (0, import_utils2.normalizeIotaAddress)(addr2);
|
|
379
378
|
}
|
|
380
379
|
static isSuiStructEqual(struct1, struct2) {
|
|
381
380
|
return (0, import_utils2.normalizeStructTag)(struct1) === (0, import_utils2.normalizeStructTag)(struct2);
|
|
@@ -409,7 +408,7 @@ var SignatureVerifier = class _SignatureVerifier {
|
|
|
409
408
|
}
|
|
410
409
|
static async verifySignature(input) {
|
|
411
410
|
const publicKey = await _SignatureVerifier.getPublicKeyFromSignature(input);
|
|
412
|
-
return Formatter.isSuiAddressEqual(publicKey.
|
|
411
|
+
return Formatter.isSuiAddressEqual(publicKey.toIotaAddress(), input.targetAddress);
|
|
413
412
|
}
|
|
414
413
|
static async verifyPersonalSignature(input) {
|
|
415
414
|
const message = stringToBuffer(input.messageStr);
|
|
@@ -431,14 +430,14 @@ var SignatureVerifier = class _SignatureVerifier {
|
|
|
431
430
|
};
|
|
432
431
|
|
|
433
432
|
// src/utils/sui.ts
|
|
434
|
-
var
|
|
435
|
-
var import_cryptography = require("@
|
|
436
|
-
var import_multisig = require("@
|
|
433
|
+
var import_iota_utils3 = require("@msafe/iota-utils");
|
|
434
|
+
var import_cryptography = require("@iota/iota-sdk/cryptography");
|
|
435
|
+
var import_multisig = require("@iota/iota-sdk/multisig");
|
|
437
436
|
var SUI_COIN = "0x2::sui::SUI";
|
|
438
|
-
async function getPublicKeyFromChain(
|
|
437
|
+
async function getPublicKeyFromChain(client, address) {
|
|
439
438
|
let txs;
|
|
440
439
|
try {
|
|
441
|
-
txs = await
|
|
440
|
+
txs = await client.queryTransactionBlocks({
|
|
442
441
|
// Disable naming rule since the variable is defined by Mysten
|
|
443
442
|
filter: { FromAddress: address },
|
|
444
443
|
options: { showInput: true },
|
|
@@ -466,7 +465,7 @@ function getAddressFromSignatures(serializedSig, targetAddress) {
|
|
|
466
465
|
const decoded = (0, import_cryptography.parseSerializedSignature)(serializedSig);
|
|
467
466
|
switch (decoded.signatureScheme) {
|
|
468
467
|
case "MultiSig": {
|
|
469
|
-
const multiSigAddress = new import_multisig.MultiSigPublicKey(decoded.multisig.multisig_pk).
|
|
468
|
+
const multiSigAddress = new import_multisig.MultiSigPublicKey(decoded.multisig.multisig_pk).toIotaAddress();
|
|
470
469
|
if (Formatter.isSuiAddressEqual(multiSigAddress, targetAddress)) {
|
|
471
470
|
throw new Error("multi-sig wallet cannot be owner");
|
|
472
471
|
}
|
|
@@ -481,8 +480,8 @@ function getAddressFromSignatures(serializedSig, targetAddress) {
|
|
|
481
480
|
case "ED25519":
|
|
482
481
|
case "Secp256k1":
|
|
483
482
|
case "Secp256r1": {
|
|
484
|
-
const pk =
|
|
485
|
-
if (Formatter.isSuiAddressEqual(pk.
|
|
483
|
+
const pk = import_iota_utils3.PublicKeySerde.de({ publicKeyEncoded: decoded.publicKey, schema: decoded.signatureScheme });
|
|
484
|
+
if (Formatter.isSuiAddressEqual(pk.toIotaAddress(), targetAddress)) {
|
|
486
485
|
return pk;
|
|
487
486
|
}
|
|
488
487
|
return void 0;
|
|
@@ -496,7 +495,7 @@ async function getAllCoins(input) {
|
|
|
496
495
|
let cursor;
|
|
497
496
|
const res = [];
|
|
498
497
|
while (hasNext) {
|
|
499
|
-
const currentPage = await input.
|
|
498
|
+
const currentPage = await input.client.getCoins({
|
|
500
499
|
owner: input.owner,
|
|
501
500
|
coinType: input.coinType,
|
|
502
501
|
cursor
|
|
@@ -640,12 +639,12 @@ var MSafeAccount = class _MSafeAccount {
|
|
|
640
639
|
constructor(globals, info) {
|
|
641
640
|
this.globals = globals;
|
|
642
641
|
this.info = info;
|
|
643
|
-
this.multiSig = new
|
|
642
|
+
this.multiSig = new import_iota_utils4.MultiSigAccount({
|
|
644
643
|
threshold: info.threshold,
|
|
645
644
|
ownersWithWeight: info.owners,
|
|
646
645
|
creationNonce: info.creationNonce
|
|
647
646
|
});
|
|
648
|
-
this.coinHelper = new CoinHelper(this.
|
|
647
|
+
this.coinHelper = new CoinHelper(this.client);
|
|
649
648
|
this.simulator = new Simulator(globals);
|
|
650
649
|
}
|
|
651
650
|
multiSig;
|
|
@@ -659,7 +658,7 @@ var MSafeAccount = class _MSafeAccount {
|
|
|
659
658
|
}
|
|
660
659
|
}
|
|
661
660
|
async ownedCoins() {
|
|
662
|
-
const balances = await this.
|
|
661
|
+
const balances = await this.client.getAllBalances({ owner: this.address });
|
|
663
662
|
return Promise.all(
|
|
664
663
|
balances.map(async (balance) => {
|
|
665
664
|
const meta = await this.coinHelper.getCoinMeta(balance.coinType);
|
|
@@ -677,7 +676,7 @@ var MSafeAccount = class _MSafeAccount {
|
|
|
677
676
|
filter: (objRes) => !objRes?.data?.type?.startsWith("0x2::coin::Coin"),
|
|
678
677
|
...options
|
|
679
678
|
};
|
|
680
|
-
return getAllOwnedObjects(this.
|
|
679
|
+
return getAllOwnedObjects(this.client, this.address, filterCoinObjectOptions);
|
|
681
680
|
}
|
|
682
681
|
async pendingTransaction() {
|
|
683
682
|
const res = await this.backend.getPendingTransactions({ msafeAddress: this.address });
|
|
@@ -721,7 +720,7 @@ var MSafeAccount = class _MSafeAccount {
|
|
|
721
720
|
return this.backend.getNextSequenceNumber(this.address);
|
|
722
721
|
}
|
|
723
722
|
async simulateIntention(request) {
|
|
724
|
-
const appHelper =
|
|
723
|
+
const appHelper = import_iota_app_store.appHelpers.getAppHelper(request.application);
|
|
725
724
|
if (!appHelper) {
|
|
726
725
|
throw new Error(`Can't find app helper for application ${request.application}`);
|
|
727
726
|
}
|
|
@@ -730,11 +729,11 @@ var MSafeAccount = class _MSafeAccount {
|
|
|
730
729
|
intentionData: request.intention,
|
|
731
730
|
txType: request.txType,
|
|
732
731
|
txSubType: request.txSubType,
|
|
733
|
-
|
|
732
|
+
client: this.globals.client,
|
|
734
733
|
account: {
|
|
735
734
|
address: this.address,
|
|
736
735
|
publicKey: (0, import_utils3.fromHEX)(this.address),
|
|
737
|
-
chains: [
|
|
736
|
+
chains: [],
|
|
738
737
|
features: []
|
|
739
738
|
}
|
|
740
739
|
});
|
|
@@ -742,7 +741,7 @@ var MSafeAccount = class _MSafeAccount {
|
|
|
742
741
|
return this.simulator.simulate({ txb, sender: this.address });
|
|
743
742
|
}
|
|
744
743
|
async proposeIntention(input) {
|
|
745
|
-
const message =
|
|
744
|
+
const message = import_iota_utils4.SigningMessageHelper.proposeIntentionMessage({
|
|
746
745
|
msafeAddress: this.address,
|
|
747
746
|
intention: input.intention,
|
|
748
747
|
sn: input.sequenceNumber
|
|
@@ -757,7 +756,7 @@ var MSafeAccount = class _MSafeAccount {
|
|
|
757
756
|
});
|
|
758
757
|
}
|
|
759
758
|
async proposeIntentionAndBuildVote(input) {
|
|
760
|
-
const appHelper =
|
|
759
|
+
const appHelper = import_iota_app_store.appHelpers.getAppHelper(input.application);
|
|
761
760
|
if (!appHelper) {
|
|
762
761
|
throw new Error(`Can't find app helper for application ${input.application}`);
|
|
763
762
|
}
|
|
@@ -766,19 +765,19 @@ var MSafeAccount = class _MSafeAccount {
|
|
|
766
765
|
intentionData: input.intention,
|
|
767
766
|
txType: input.txType,
|
|
768
767
|
txSubType: input.txSubType,
|
|
769
|
-
|
|
768
|
+
client: this.globals.client,
|
|
770
769
|
account: {
|
|
771
770
|
address: this.address,
|
|
772
771
|
publicKey: (0, import_utils3.fromHEX)(this.address),
|
|
773
|
-
chains: [
|
|
772
|
+
chains: [],
|
|
774
773
|
features: []
|
|
775
774
|
}
|
|
776
775
|
});
|
|
777
776
|
txb.setGasPrice(input.gasPrice);
|
|
778
777
|
txb.setGasBudget(input.gasBudget);
|
|
779
778
|
txb.setSender(this.address);
|
|
780
|
-
const payload = await txb.build({ client: this.globals.
|
|
781
|
-
const digest = await txb.getDigest({ client: this.globals.
|
|
779
|
+
const payload = await txb.build({ client: this.globals.client });
|
|
780
|
+
const digest = await txb.getDigest({ client: this.globals.client });
|
|
782
781
|
const signature = await this.wallet.signTransactionBlock({ transactionBlock: payload });
|
|
783
782
|
return this.backend.proposeIntentionAndBuildVote({
|
|
784
783
|
...input,
|
|
@@ -791,9 +790,9 @@ var MSafeAccount = class _MSafeAccount {
|
|
|
791
790
|
async simulateCoinTransferIntention(intention) {
|
|
792
791
|
const sn = await this.nextSequenceNumber();
|
|
793
792
|
return this.simulateIntention({
|
|
794
|
-
application:
|
|
795
|
-
txType:
|
|
796
|
-
txSubType:
|
|
793
|
+
application: import_iota_utils4.TransactionDefaultApplication,
|
|
794
|
+
txType: import_iota_utils4.TransactionType.Assets,
|
|
795
|
+
txSubType: import_iota_utils4.TransactionSubTypes.assets.coin.send,
|
|
797
796
|
sequenceNumber: sn,
|
|
798
797
|
intention
|
|
799
798
|
});
|
|
@@ -801,9 +800,9 @@ var MSafeAccount = class _MSafeAccount {
|
|
|
801
800
|
async proposeCoinTransferIntention(intention) {
|
|
802
801
|
const sn = await this.nextSequenceNumber();
|
|
803
802
|
return this.proposeIntention({
|
|
804
|
-
application:
|
|
805
|
-
txType:
|
|
806
|
-
txSubType:
|
|
803
|
+
application: import_iota_utils4.TransactionDefaultApplication,
|
|
804
|
+
txType: import_iota_utils4.TransactionType.Assets,
|
|
805
|
+
txSubType: import_iota_utils4.TransactionSubTypes.assets.coin.send,
|
|
807
806
|
sequenceNumber: sn,
|
|
808
807
|
intention
|
|
809
808
|
});
|
|
@@ -811,9 +810,9 @@ var MSafeAccount = class _MSafeAccount {
|
|
|
811
810
|
async simulateObjectTransferIntention(intention) {
|
|
812
811
|
const sn = await this.nextSequenceNumber();
|
|
813
812
|
return this.simulateIntention({
|
|
814
|
-
application:
|
|
815
|
-
txType:
|
|
816
|
-
txSubType:
|
|
813
|
+
application: import_iota_utils4.TransactionDefaultApplication,
|
|
814
|
+
txType: import_iota_utils4.TransactionType.Assets,
|
|
815
|
+
txSubType: import_iota_utils4.TransactionSubTypes.assets.object.send,
|
|
817
816
|
sequenceNumber: sn,
|
|
818
817
|
intention
|
|
819
818
|
});
|
|
@@ -821,9 +820,9 @@ var MSafeAccount = class _MSafeAccount {
|
|
|
821
820
|
async proposeObjectTransferIntention(intention) {
|
|
822
821
|
const sn = await this.nextSequenceNumber();
|
|
823
822
|
return this.proposeIntention({
|
|
824
|
-
application:
|
|
825
|
-
txType:
|
|
826
|
-
txSubType:
|
|
823
|
+
application: import_iota_utils4.TransactionDefaultApplication,
|
|
824
|
+
txType: import_iota_utils4.TransactionType.Assets,
|
|
825
|
+
txSubType: import_iota_utils4.TransactionSubTypes.assets.object.send,
|
|
827
826
|
sequenceNumber: sn,
|
|
828
827
|
intention
|
|
829
828
|
});
|
|
@@ -831,9 +830,9 @@ var MSafeAccount = class _MSafeAccount {
|
|
|
831
830
|
async simulatePlainPayloadIntention(intention) {
|
|
832
831
|
const sn = await this.nextSequenceNumber();
|
|
833
832
|
return this.simulateIntention({
|
|
834
|
-
application:
|
|
835
|
-
txType:
|
|
836
|
-
txSubType:
|
|
833
|
+
application: import_iota_utils4.TransactionDefaultApplication,
|
|
834
|
+
txType: import_iota_utils4.TransactionType.Other,
|
|
835
|
+
txSubType: import_iota_utils4.TransactionSubTypes.others.plain,
|
|
837
836
|
sequenceNumber: sn,
|
|
838
837
|
intention
|
|
839
838
|
});
|
|
@@ -841,13 +840,13 @@ var MSafeAccount = class _MSafeAccount {
|
|
|
841
840
|
async proposePlainPayloadIntention(intention) {
|
|
842
841
|
const sn = await this.nextSequenceNumber();
|
|
843
842
|
const tb = import_transactions2.TransactionBlock.from(intention.payload);
|
|
844
|
-
if (!tb.blockData.sender || !(0,
|
|
843
|
+
if (!tb.blockData.sender || !(0, import_iota_utils4.isSameAddress)(tb.blockData.sender, this.address)) {
|
|
845
844
|
throw new Error("Transaction sender is not same as the multisig address");
|
|
846
845
|
}
|
|
847
846
|
return this.proposeIntention({
|
|
848
|
-
application:
|
|
849
|
-
txType:
|
|
850
|
-
txSubType:
|
|
847
|
+
application: import_iota_utils4.TransactionDefaultApplication,
|
|
848
|
+
txType: import_iota_utils4.TransactionType.Other,
|
|
849
|
+
txSubType: import_iota_utils4.TransactionSubTypes.others.plain,
|
|
851
850
|
sequenceNumber: sn,
|
|
852
851
|
intention
|
|
853
852
|
});
|
|
@@ -866,7 +865,7 @@ var MSafeAccount = class _MSafeAccount {
|
|
|
866
865
|
if (!pendingTx || pendingTx.rejectDigest !== "") {
|
|
867
866
|
throw new Error("Already rejected");
|
|
868
867
|
}
|
|
869
|
-
const txb = (0,
|
|
868
|
+
const txb = (0, import_iota_utils4.buildRejectTxb)(this.address);
|
|
870
869
|
txb.setSender(this.address);
|
|
871
870
|
return this.simulator.simulate({ txb, sender: this.address });
|
|
872
871
|
}
|
|
@@ -875,9 +874,9 @@ var MSafeAccount = class _MSafeAccount {
|
|
|
875
874
|
if (!pendingTx || pendingTx.rejectDigest !== "") {
|
|
876
875
|
throw new Error("Already rejected");
|
|
877
876
|
}
|
|
878
|
-
const rejectTxb = (0,
|
|
879
|
-
const digest = await rejectTxb.getDigest({ client: this.
|
|
880
|
-
const payload = await rejectTxb.build({ client: this.
|
|
877
|
+
const rejectTxb = (0, import_iota_utils4.buildRejectTxb)(this.address);
|
|
878
|
+
const digest = await rejectTxb.getDigest({ client: this.client });
|
|
879
|
+
const payload = await rejectTxb.build({ client: this.client });
|
|
881
880
|
const signature = await this.wallet.signTransactionBlock({ transactionBlock: payload });
|
|
882
881
|
return this.backend.rejectCurrentTx({
|
|
883
882
|
msafeAddress: this.address,
|
|
@@ -888,7 +887,7 @@ var MSafeAccount = class _MSafeAccount {
|
|
|
888
887
|
}
|
|
889
888
|
async simulateBuildTransaction() {
|
|
890
889
|
const intention = await this.backend.getNextIntention({ msafeAddress: this.address });
|
|
891
|
-
const appHelper =
|
|
890
|
+
const appHelper = import_iota_app_store.appHelpers.getAppHelper(intention.application);
|
|
892
891
|
if (!appHelper) {
|
|
893
892
|
throw new Error(`Can't find app helper for application ${intention.application}`);
|
|
894
893
|
}
|
|
@@ -897,11 +896,11 @@ var MSafeAccount = class _MSafeAccount {
|
|
|
897
896
|
intentionData: intention.intention,
|
|
898
897
|
txType: intention.txType,
|
|
899
898
|
txSubType: intention.txSubType,
|
|
900
|
-
|
|
899
|
+
client: this.globals.client,
|
|
901
900
|
account: {
|
|
902
901
|
address: this.address,
|
|
903
902
|
publicKey: (0, import_utils3.fromHEX)(this.address),
|
|
904
|
-
chains: [
|
|
903
|
+
chains: [],
|
|
905
904
|
features: []
|
|
906
905
|
}
|
|
907
906
|
});
|
|
@@ -935,7 +934,7 @@ var MSafeAccount = class _MSafeAccount {
|
|
|
935
934
|
}
|
|
936
935
|
}
|
|
937
936
|
const multiSignature = this.multiSig.combinePartialSignatures(sortedSigs);
|
|
938
|
-
return this.
|
|
937
|
+
return this.client.executeTransactionBlock({
|
|
939
938
|
transactionBlock: HexToUint8Array(payload),
|
|
940
939
|
signature: multiSignature,
|
|
941
940
|
options: { showEffects: true, showEvents: true }
|
|
@@ -952,7 +951,7 @@ var MSafeAccount = class _MSafeAccount {
|
|
|
952
951
|
calculateWeight(addressList) {
|
|
953
952
|
let gotWeight = 0;
|
|
954
953
|
for (let i = 0; i < addressList.length; i++) {
|
|
955
|
-
const found = this.info.owners.find((owner) => (0,
|
|
954
|
+
const found = this.info.owners.find((owner) => (0, import_iota_utils4.isSameAddress)(owner.address, addressList[i]));
|
|
956
955
|
if (found) {
|
|
957
956
|
gotWeight += found.weight;
|
|
958
957
|
}
|
|
@@ -971,14 +970,14 @@ var MSafeAccount = class _MSafeAccount {
|
|
|
971
970
|
async userAddress() {
|
|
972
971
|
return this.globals.wallet.address();
|
|
973
972
|
}
|
|
974
|
-
get
|
|
975
|
-
return this.globals.
|
|
973
|
+
get client() {
|
|
974
|
+
return this.globals.client;
|
|
976
975
|
}
|
|
977
976
|
};
|
|
978
977
|
|
|
979
978
|
// src/core/PublicKeyHelper.ts
|
|
980
|
-
var
|
|
981
|
-
var import_utils5 = require("@
|
|
979
|
+
var import_iota_utils5 = require("@msafe/iota-utils");
|
|
980
|
+
var import_utils5 = require("@iota/iota-sdk/utils");
|
|
982
981
|
var PublicKeyHelper = class {
|
|
983
982
|
constructor(globals) {
|
|
984
983
|
this.globals = globals;
|
|
@@ -1024,10 +1023,10 @@ var PublicKeyHelper = class {
|
|
|
1024
1023
|
return results;
|
|
1025
1024
|
}
|
|
1026
1025
|
addPublicKey(address, publicKey) {
|
|
1027
|
-
if (!(0,
|
|
1026
|
+
if (!(0, import_iota_utils5.isSameAddress)(address, publicKey.toIotaAddress())) {
|
|
1028
1027
|
throw new Error("Invalid public key");
|
|
1029
1028
|
}
|
|
1030
|
-
this.knownPublicKeys.set((0, import_utils5.
|
|
1029
|
+
this.knownPublicKeys.set((0, import_utils5.normalizeIotaAddress)(address), publicKey);
|
|
1031
1030
|
}
|
|
1032
1031
|
async _getPublicKey(address) {
|
|
1033
1032
|
const pkBackend = await this.getPublicKeyFromBackend(address);
|
|
@@ -1049,7 +1048,7 @@ var PublicKeyHelper = class {
|
|
|
1049
1048
|
}
|
|
1050
1049
|
}
|
|
1051
1050
|
async getPublicKeyFromChain(address) {
|
|
1052
|
-
return getPublicKeyFromChain(this.globals.
|
|
1051
|
+
return getPublicKeyFromChain(this.globals.client, address);
|
|
1053
1052
|
}
|
|
1054
1053
|
};
|
|
1055
1054
|
|
|
@@ -1064,10 +1063,10 @@ var ReportSDK = class {
|
|
|
1064
1063
|
};
|
|
1065
1064
|
|
|
1066
1065
|
// src/globals/MSafeGlobals.ts
|
|
1067
|
-
var import_client = require("@
|
|
1066
|
+
var import_client = require("@iota/iota-sdk/client");
|
|
1068
1067
|
|
|
1069
1068
|
// src/backend/BackendImpl.ts
|
|
1070
|
-
var
|
|
1069
|
+
var import_iota_utils6 = require("@msafe/iota-utils");
|
|
1071
1070
|
var import_axios = __toESM(require("axios"), 1);
|
|
1072
1071
|
var BackendImpl = class _BackendImpl {
|
|
1073
1072
|
constructor(apiURL, mockAddress) {
|
|
@@ -1103,7 +1102,7 @@ var BackendImpl = class _BackendImpl {
|
|
|
1103
1102
|
headers: this.headers()
|
|
1104
1103
|
});
|
|
1105
1104
|
return res.data?.map(
|
|
1106
|
-
(publicKeyWithSchema) => publicKeyWithSchema ?
|
|
1105
|
+
(publicKeyWithSchema) => publicKeyWithSchema ? import_iota_utils6.PublicKeySerde.de(publicKeyWithSchema) : void 0
|
|
1107
1106
|
);
|
|
1108
1107
|
}
|
|
1109
1108
|
async getMSafeAccountInfo(msafeAddress) {
|
|
@@ -1124,7 +1123,7 @@ var BackendImpl = class _BackendImpl {
|
|
|
1124
1123
|
}
|
|
1125
1124
|
async getOwnedMSafeByStatus(input) {
|
|
1126
1125
|
const q = {
|
|
1127
|
-
status: input.status ??
|
|
1126
|
+
status: input.status ?? import_iota_utils6.UserMSafeStatus.active,
|
|
1128
1127
|
...input.pagination ? {
|
|
1129
1128
|
page: input.pagination.page.toString(),
|
|
1130
1129
|
limit: input.pagination.limit.toString()
|
|
@@ -1264,7 +1263,7 @@ var BackendImpl = class _BackendImpl {
|
|
|
1264
1263
|
owners: resp.owners.map((owner) => ({
|
|
1265
1264
|
address: owner.address,
|
|
1266
1265
|
weight: owner.weight,
|
|
1267
|
-
publicKey:
|
|
1266
|
+
publicKey: import_iota_utils6.PublicKeySerde.de({
|
|
1268
1267
|
publicKeyEncoded: owner.publicKeyEncoded,
|
|
1269
1268
|
schema: owner.schema
|
|
1270
1269
|
}),
|
|
@@ -1374,7 +1373,7 @@ var ENV_CONFIGS = /* @__PURE__ */ new Map([
|
|
|
1374
1373
|
[
|
|
1375
1374
|
"unit" /* unit */,
|
|
1376
1375
|
{
|
|
1377
|
-
|
|
1376
|
+
client: {
|
|
1378
1377
|
url: TESTNET_RPC_URL
|
|
1379
1378
|
},
|
|
1380
1379
|
backend: {
|
|
@@ -1387,7 +1386,7 @@ var ENV_CONFIGS = /* @__PURE__ */ new Map([
|
|
|
1387
1386
|
[
|
|
1388
1387
|
"local" /* local */,
|
|
1389
1388
|
{
|
|
1390
|
-
|
|
1389
|
+
client: {
|
|
1391
1390
|
url: TESTNET_RPC_URL
|
|
1392
1391
|
},
|
|
1393
1392
|
backend: {
|
|
@@ -1400,7 +1399,7 @@ var ENV_CONFIGS = /* @__PURE__ */ new Map([
|
|
|
1400
1399
|
[
|
|
1401
1400
|
"dev" /* dev */,
|
|
1402
1401
|
{
|
|
1403
|
-
|
|
1402
|
+
client: {
|
|
1404
1403
|
url: TESTNET_RPC_URL
|
|
1405
1404
|
},
|
|
1406
1405
|
backend: {
|
|
@@ -1413,7 +1412,7 @@ var ENV_CONFIGS = /* @__PURE__ */ new Map([
|
|
|
1413
1412
|
[
|
|
1414
1413
|
"prev" /* prev */,
|
|
1415
1414
|
{
|
|
1416
|
-
|
|
1415
|
+
client: {
|
|
1417
1416
|
url: MAINNET_RPC_URL
|
|
1418
1417
|
},
|
|
1419
1418
|
backend: {
|
|
@@ -1426,7 +1425,7 @@ var ENV_CONFIGS = /* @__PURE__ */ new Map([
|
|
|
1426
1425
|
[
|
|
1427
1426
|
"prod" /* prod */,
|
|
1428
1427
|
{
|
|
1429
|
-
|
|
1428
|
+
client: {
|
|
1430
1429
|
url: MAINNET_RPC_URL
|
|
1431
1430
|
},
|
|
1432
1431
|
backend: {
|
|
@@ -1442,8 +1441,8 @@ function getMSafeConfig(env, options) {
|
|
|
1442
1441
|
if (!config) {
|
|
1443
1442
|
throw new Error("Unknown environment");
|
|
1444
1443
|
}
|
|
1445
|
-
if (options?.
|
|
1446
|
-
config.
|
|
1444
|
+
if (options?.client?.url) {
|
|
1445
|
+
config.client.url = options.client.url;
|
|
1447
1446
|
}
|
|
1448
1447
|
if (options?.backend?.url) {
|
|
1449
1448
|
config.backend.url = options.backend.url;
|
|
@@ -1454,21 +1453,21 @@ function getMSafeConfig(env, options) {
|
|
|
1454
1453
|
// src/globals/MSafeGlobals.ts
|
|
1455
1454
|
var MSafeGlobals = class _MSafeGlobals {
|
|
1456
1455
|
backend;
|
|
1457
|
-
|
|
1456
|
+
client;
|
|
1458
1457
|
config;
|
|
1459
1458
|
_wallet;
|
|
1460
1459
|
constructor(input) {
|
|
1461
1460
|
this.backend = input.backend;
|
|
1462
|
-
this.
|
|
1461
|
+
this.client = input.client;
|
|
1463
1462
|
this.config = input.config;
|
|
1464
1463
|
}
|
|
1465
1464
|
static async New(env, options) {
|
|
1466
1465
|
const config = getMSafeConfig(env, options);
|
|
1467
|
-
const
|
|
1466
|
+
const client = new import_client.IotaClient(config.client);
|
|
1468
1467
|
const backend = new BackendImpl(config.backend.url, options?.mockAddress);
|
|
1469
1468
|
return new _MSafeGlobals({
|
|
1470
1469
|
backend,
|
|
1471
|
-
|
|
1470
|
+
client,
|
|
1472
1471
|
config
|
|
1473
1472
|
});
|
|
1474
1473
|
}
|
|
@@ -1512,7 +1511,7 @@ var MSafeClient = class _MSafeClient {
|
|
|
1512
1511
|
return jwt;
|
|
1513
1512
|
}
|
|
1514
1513
|
async authSign(wallet) {
|
|
1515
|
-
const messageStr =
|
|
1514
|
+
const messageStr = import_iota_utils7.SigningMessageHelper.loginMessageWithTimestamp((/* @__PURE__ */ new Date()).toUTCString());
|
|
1516
1515
|
const sig = await wallet.signPersonalMessage({
|
|
1517
1516
|
messageStr
|
|
1518
1517
|
});
|
|
@@ -1527,7 +1526,7 @@ var MSafeClient = class _MSafeClient {
|
|
|
1527
1526
|
return this.globals.backend.getUserInfo();
|
|
1528
1527
|
}
|
|
1529
1528
|
async ownedMSafe(pagination) {
|
|
1530
|
-
return this.globals.backend.getOwnedMSafeByStatus({ status:
|
|
1529
|
+
return this.globals.backend.getOwnedMSafeByStatus({ status: import_iota_utils7.UserMSafeStatus.active, pagination });
|
|
1531
1530
|
}
|
|
1532
1531
|
async createAccount(info) {
|
|
1533
1532
|
return this.creationHelper.submitMSafeCreation(info);
|