@msafe/sui3-sdk 1.0.20 → 1.0.21
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 +80 -73
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -1
- package/dist/index.d.ts +14 -1
- package/dist/index.js +76 -69
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/core/MSafeAccount.ts +59 -68
- package/src/utils/transaction.ts +32 -0
package/dist/index.cjs
CHANGED
|
@@ -65,6 +65,7 @@ __export(src_exports, {
|
|
|
65
65
|
createCoinReservationRef: () => createCoinReservationRef,
|
|
66
66
|
estimateGasBudget: () => estimateGasBudget,
|
|
67
67
|
getAllCoins: () => getAllCoins,
|
|
68
|
+
getIntentionContent: () => getIntentionContent,
|
|
68
69
|
getMSafeConfig: () => getMSafeConfig,
|
|
69
70
|
getPublicKeyFromChain: () => getPublicKeyFromChain,
|
|
70
71
|
httpUrlToGrpcBaseUrl: () => httpUrlToGrpcBaseUrl,
|
|
@@ -74,7 +75,8 @@ __export(src_exports, {
|
|
|
74
75
|
prepareGasFunding: () => prepareGasFunding,
|
|
75
76
|
selectGasFunding: () => selectGasFunding,
|
|
76
77
|
stringToBuffer: () => stringToBuffer,
|
|
77
|
-
toSuiTransaction: () => toSuiTransaction
|
|
78
|
+
toSuiTransaction: () => toSuiTransaction,
|
|
79
|
+
transactionFromContent: () => transactionFromContent
|
|
78
80
|
});
|
|
79
81
|
module.exports = __toCommonJS(src_exports);
|
|
80
82
|
|
|
@@ -198,7 +200,7 @@ var InvitationSDK = class {
|
|
|
198
200
|
var import_sui_app_store = require("@msafe/sui-app-store");
|
|
199
201
|
var import_sui3_utils4 = require("@msafe/sui3-utils");
|
|
200
202
|
var import_transactions4 = require("@mysten/sui/transactions");
|
|
201
|
-
var
|
|
203
|
+
var import_utils6 = require("@mysten/sui/utils");
|
|
202
204
|
var import_wallet_standard = require("@mysten/wallet-standard");
|
|
203
205
|
|
|
204
206
|
// src/simulate/simulator.ts
|
|
@@ -866,6 +868,7 @@ var SignatureVerifier = class _SignatureVerifier {
|
|
|
866
868
|
|
|
867
869
|
// src/utils/transaction.ts
|
|
868
870
|
var import_transactions3 = require("@mysten/sui/transactions");
|
|
871
|
+
var import_utils5 = require("@mysten/sui/utils");
|
|
869
872
|
function toSuiTransaction(txb) {
|
|
870
873
|
if ((0, import_transactions3.isTransaction)(txb)) {
|
|
871
874
|
return txb;
|
|
@@ -879,6 +882,30 @@ function toSuiTransaction(txb) {
|
|
|
879
882
|
}
|
|
880
883
|
throw new Error("Unsupported transaction value for toSuiTransaction");
|
|
881
884
|
}
|
|
885
|
+
function isHex(str) {
|
|
886
|
+
return /^[0-9a-fA-F]+$/.test(str);
|
|
887
|
+
}
|
|
888
|
+
function getIntentionContent(intention) {
|
|
889
|
+
if (intention && typeof intention === "object" && "content" in intention) {
|
|
890
|
+
return intention.content;
|
|
891
|
+
}
|
|
892
|
+
return void 0;
|
|
893
|
+
}
|
|
894
|
+
function transactionFromContent(content) {
|
|
895
|
+
if (content instanceof Uint8Array) {
|
|
896
|
+
return import_transactions3.Transaction.from(content);
|
|
897
|
+
}
|
|
898
|
+
if (typeof content === "string") {
|
|
899
|
+
if (isHex(content)) {
|
|
900
|
+
return import_transactions3.Transaction.from((0, import_utils5.fromHex)(content));
|
|
901
|
+
}
|
|
902
|
+
return import_transactions3.Transaction.from(content);
|
|
903
|
+
}
|
|
904
|
+
if (content && typeof content === "object") {
|
|
905
|
+
return import_transactions3.Transaction.from(JSON.stringify(content));
|
|
906
|
+
}
|
|
907
|
+
throw new Error("Invalid transaction content");
|
|
908
|
+
}
|
|
882
909
|
|
|
883
910
|
// src/utils/iter/iterator.ts
|
|
884
911
|
var REQUEST_PAGE_SIZE = 25;
|
|
@@ -1045,7 +1072,7 @@ var MSafeAccount = class _MSafeAccount {
|
|
|
1045
1072
|
balances.map(async (balance) => {
|
|
1046
1073
|
const meta = await this.coinHelper.getCoinMeta(balance.coinType);
|
|
1047
1074
|
return {
|
|
1048
|
-
type: (0,
|
|
1075
|
+
type: (0, import_utils6.normalizeStructTag)(balance.coinType),
|
|
1049
1076
|
balance: BigInt(balance.addressBalance),
|
|
1050
1077
|
metadata: meta
|
|
1051
1078
|
};
|
|
@@ -1101,30 +1128,7 @@ var MSafeAccount = class _MSafeAccount {
|
|
|
1101
1128
|
return this.backend.getNextSequenceNumber(this.address);
|
|
1102
1129
|
}
|
|
1103
1130
|
async simulateIntention(request) {
|
|
1104
|
-
|
|
1105
|
-
if (request.txb) {
|
|
1106
|
-
txb = request.txb;
|
|
1107
|
-
} else {
|
|
1108
|
-
const appHelper = import_sui_app_store.appHelpers.getAppHelper(request.application);
|
|
1109
|
-
if (!appHelper) {
|
|
1110
|
-
throw new Error(`Can't find app helper for application ${request.application}`);
|
|
1111
|
-
}
|
|
1112
|
-
txb = toSuiTransaction(
|
|
1113
|
-
await appHelper.build({
|
|
1114
|
-
network: this.globals.config.network,
|
|
1115
|
-
intentionData: request.intention,
|
|
1116
|
-
txType: request.txType,
|
|
1117
|
-
txSubType: request.txSubType,
|
|
1118
|
-
clientUrl: this.globals.config.suiClient.url,
|
|
1119
|
-
account: {
|
|
1120
|
-
address: this.address,
|
|
1121
|
-
publicKey: (0, import_utils5.fromHex)(this.address),
|
|
1122
|
-
chains: [import_wallet_standard.SUI_MAINNET_CHAIN, import_wallet_standard.SUI_TESTNET_CHAIN],
|
|
1123
|
-
features: []
|
|
1124
|
-
}
|
|
1125
|
-
})
|
|
1126
|
-
);
|
|
1127
|
-
}
|
|
1131
|
+
const txb = await this.buildTxFromIntention(request);
|
|
1128
1132
|
txb.setSender(this.address);
|
|
1129
1133
|
return this.simulator.simulate({ txb, sender: this.address });
|
|
1130
1134
|
}
|
|
@@ -1144,30 +1148,7 @@ var MSafeAccount = class _MSafeAccount {
|
|
|
1144
1148
|
});
|
|
1145
1149
|
}
|
|
1146
1150
|
async proposeIntentionAndBuildVote(input) {
|
|
1147
|
-
|
|
1148
|
-
if (input.txb) {
|
|
1149
|
-
txb = input.txb;
|
|
1150
|
-
} else {
|
|
1151
|
-
const appHelper = import_sui_app_store.appHelpers.getAppHelper(input.application);
|
|
1152
|
-
if (!appHelper) {
|
|
1153
|
-
throw new Error(`Can't find app helper for application ${input.application}`);
|
|
1154
|
-
}
|
|
1155
|
-
txb = toSuiTransaction(
|
|
1156
|
-
await appHelper.build({
|
|
1157
|
-
network: this.globals.config.network,
|
|
1158
|
-
intentionData: input.intention,
|
|
1159
|
-
txType: input.txType,
|
|
1160
|
-
txSubType: input.txSubType,
|
|
1161
|
-
clientUrl: this.globals.config.suiClient.url,
|
|
1162
|
-
account: {
|
|
1163
|
-
address: this.address,
|
|
1164
|
-
publicKey: (0, import_utils5.fromHex)(this.address),
|
|
1165
|
-
chains: [import_wallet_standard.SUI_MAINNET_CHAIN, import_wallet_standard.SUI_TESTNET_CHAIN],
|
|
1166
|
-
features: []
|
|
1167
|
-
}
|
|
1168
|
-
})
|
|
1169
|
-
);
|
|
1170
|
-
}
|
|
1151
|
+
const txb = await this.buildTxFromIntention(input);
|
|
1171
1152
|
txb.setGasPrice(input.gasPrice);
|
|
1172
1153
|
txb.setSender(this.address);
|
|
1173
1154
|
await prepareGasFunding({
|
|
@@ -1182,7 +1163,7 @@ var MSafeAccount = class _MSafeAccount {
|
|
|
1182
1163
|
const signature = await this.wallet.signTransactionBlock({ transactionBlock: payload });
|
|
1183
1164
|
return this.backend.proposeIntentionAndBuildVote({
|
|
1184
1165
|
...input,
|
|
1185
|
-
payload: (0,
|
|
1166
|
+
payload: (0, import_utils6.toHex)(payload),
|
|
1186
1167
|
digest,
|
|
1187
1168
|
msafeAddress: this.address,
|
|
1188
1169
|
signature: signature.signature
|
|
@@ -1289,25 +1270,12 @@ var MSafeAccount = class _MSafeAccount {
|
|
|
1289
1270
|
}
|
|
1290
1271
|
async simulateBuildTransaction() {
|
|
1291
1272
|
const intention = await this.backend.getNextIntention({ msafeAddress: this.address });
|
|
1292
|
-
const
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
network: this.globals.config.network,
|
|
1299
|
-
intentionData: intention.intention,
|
|
1300
|
-
txType: intention.txType,
|
|
1301
|
-
txSubType: intention.txSubType,
|
|
1302
|
-
clientUrl: this.globals.config.suiClient.url,
|
|
1303
|
-
account: {
|
|
1304
|
-
address: this.address,
|
|
1305
|
-
publicKey: (0, import_utils5.fromHex)(this.address),
|
|
1306
|
-
chains: [import_wallet_standard.SUI_MAINNET_CHAIN, import_wallet_standard.SUI_TESTNET_CHAIN],
|
|
1307
|
-
features: []
|
|
1308
|
-
}
|
|
1309
|
-
})
|
|
1310
|
-
);
|
|
1273
|
+
const txb = await this.buildTxFromIntention({
|
|
1274
|
+
application: intention.application,
|
|
1275
|
+
intention: intention.intention,
|
|
1276
|
+
txType: intention.txType,
|
|
1277
|
+
txSubType: intention.txSubType
|
|
1278
|
+
});
|
|
1311
1279
|
txb.setSender(this.address);
|
|
1312
1280
|
return this.simulator.simulate({ txb, sender: this.address });
|
|
1313
1281
|
}
|
|
@@ -1352,6 +1320,45 @@ var MSafeAccount = class _MSafeAccount {
|
|
|
1352
1320
|
msafeAddress: this.address
|
|
1353
1321
|
});
|
|
1354
1322
|
}
|
|
1323
|
+
/**
|
|
1324
|
+
* Resolve a Transaction from propose/simulate input.
|
|
1325
|
+
* 1. Caller-supplied `txb` (generic store path — do not rebuild).
|
|
1326
|
+
* 2. Registered app helper `build`.
|
|
1327
|
+
* 3. Unregistered app: restore from `intention.content` (JSON or hex).
|
|
1328
|
+
*/
|
|
1329
|
+
async buildTxFromIntention(input) {
|
|
1330
|
+
if (input.txb) {
|
|
1331
|
+
return input.txb;
|
|
1332
|
+
}
|
|
1333
|
+
let appHelper;
|
|
1334
|
+
try {
|
|
1335
|
+
appHelper = import_sui_app_store.appHelpers.getAppHelper(input.application);
|
|
1336
|
+
} catch {
|
|
1337
|
+
appHelper = void 0;
|
|
1338
|
+
}
|
|
1339
|
+
if (appHelper) {
|
|
1340
|
+
return toSuiTransaction(
|
|
1341
|
+
await appHelper.build({
|
|
1342
|
+
network: this.globals.config.network,
|
|
1343
|
+
intentionData: input.intention,
|
|
1344
|
+
txType: input.txType,
|
|
1345
|
+
txSubType: input.txSubType,
|
|
1346
|
+
clientUrl: this.globals.config.suiClient.url,
|
|
1347
|
+
account: {
|
|
1348
|
+
address: this.address,
|
|
1349
|
+
publicKey: (0, import_utils6.fromHex)(this.address),
|
|
1350
|
+
chains: [import_wallet_standard.SUI_MAINNET_CHAIN, import_wallet_standard.SUI_TESTNET_CHAIN],
|
|
1351
|
+
features: []
|
|
1352
|
+
}
|
|
1353
|
+
})
|
|
1354
|
+
);
|
|
1355
|
+
}
|
|
1356
|
+
const content = getIntentionContent(input.intention);
|
|
1357
|
+
if (content != null) {
|
|
1358
|
+
return transactionFromContent(content);
|
|
1359
|
+
}
|
|
1360
|
+
throw new Error(`Can't find app helper for application ${input.application}`);
|
|
1361
|
+
}
|
|
1355
1362
|
calculateWeightFromVotes(votes) {
|
|
1356
1363
|
return this.calculateWeight(votes.map((vote) => vote.userAddress));
|
|
1357
1364
|
}
|
|
@@ -1384,7 +1391,7 @@ var MSafeAccount = class _MSafeAccount {
|
|
|
1384
1391
|
|
|
1385
1392
|
// src/core/PublicKeyHelper.ts
|
|
1386
1393
|
var import_sui3_utils5 = require("@msafe/sui3-utils");
|
|
1387
|
-
var
|
|
1394
|
+
var import_utils8 = require("@mysten/sui/utils");
|
|
1388
1395
|
var PublicKeyHelper = class {
|
|
1389
1396
|
constructor(globals) {
|
|
1390
1397
|
this.globals = globals;
|
|
@@ -1433,7 +1440,7 @@ var PublicKeyHelper = class {
|
|
|
1433
1440
|
if (!(0, import_sui3_utils5.isSameAddress)(address, publicKey.toSuiAddress())) {
|
|
1434
1441
|
throw new Error("Invalid public key");
|
|
1435
1442
|
}
|
|
1436
|
-
this.knownPublicKeys.set((0,
|
|
1443
|
+
this.knownPublicKeys.set((0, import_utils8.normalizeSuiAddress)(address), publicKey);
|
|
1437
1444
|
}
|
|
1438
1445
|
async _getPublicKey(address) {
|
|
1439
1446
|
const pkBackend = await this.getPublicKeyFromBackend(address);
|