@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.cjs +240 -105
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +76 -41
- package/dist/index.d.ts +76 -41
- package/dist/index.js +240 -105
- package/dist/index.js.map +1 -1
- package/package.json +33 -19
- package/src/backend/BackendImpl.ts +3 -3
- package/src/backend/interface.ts +2 -2
- package/src/core/CreateHelper.ts +6 -6
- package/src/core/MSafeAccount.ts +76 -66
- package/src/core/PublicKeyHelper.ts +2 -2
- package/src/globals/MSafeGlobals.ts +20 -7
- package/src/globals/const.ts +21 -5
- package/src/simulate/simulator.ts +60 -17
- package/src/types/assets.ts +3 -1
- package/src/types/msafe.ts +15 -7
- package/src/types/wallet.ts +7 -12
- package/src/utils/coin.ts +20 -7
- package/src/utils/crypto.ts +8 -13
- package/src/utils/format.ts +1 -1
- package/src/utils/index.ts +1 -0
- package/src/utils/iter/object.ts +56 -43
- package/src/utils/sui.ts +71 -21
- package/src/utils/transaction.ts +12 -0
- package/tsconfig.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -62,7 +62,10 @@ __export(src_exports, {
|
|
|
62
62
|
getAllCoins: () => getAllCoins,
|
|
63
63
|
getMSafeConfig: () => getMSafeConfig,
|
|
64
64
|
getPublicKeyFromChain: () => getPublicKeyFromChain,
|
|
65
|
-
|
|
65
|
+
httpUrlToGrpcBaseUrl: () => httpUrlToGrpcBaseUrl,
|
|
66
|
+
msafeChainToSuiNetwork: () => msafeChainToSuiNetwork,
|
|
67
|
+
stringToBuffer: () => stringToBuffer,
|
|
68
|
+
toSuiTransaction: () => toSuiTransaction
|
|
66
69
|
});
|
|
67
70
|
module.exports = __toCommonJS(src_exports);
|
|
68
71
|
|
|
@@ -185,46 +188,86 @@ var InvitationSDK = class {
|
|
|
185
188
|
// src/core/MSafeAccount.ts
|
|
186
189
|
var import_sui_app_store = require("@msafe/sui-app-store");
|
|
187
190
|
var import_sui3_utils4 = require("@msafe/sui3-utils");
|
|
188
|
-
var
|
|
189
|
-
var import_utils3 = require("@mysten/sui
|
|
191
|
+
var import_transactions3 = require("@mysten/sui/transactions");
|
|
192
|
+
var import_utils3 = require("@mysten/sui/utils");
|
|
190
193
|
var import_wallet_standard = require("@mysten/wallet-standard");
|
|
191
194
|
|
|
192
195
|
// src/simulate/simulator.ts
|
|
193
|
-
var import_transactions = require("@mysten/sui
|
|
196
|
+
var import_transactions = require("@mysten/sui/transactions");
|
|
194
197
|
var GAS_SAFE_OVERHEAD = 1000n;
|
|
198
|
+
function formatExecutionError(error) {
|
|
199
|
+
return error.message;
|
|
200
|
+
}
|
|
201
|
+
function gasObjectToReference(gas) {
|
|
202
|
+
if (!gas?.objectId) {
|
|
203
|
+
throw new Error("Gas object missing from simulation effects");
|
|
204
|
+
}
|
|
205
|
+
const version = gas.outputVersion ?? gas.inputVersion ?? "0";
|
|
206
|
+
const digest = gas.outputDigest ?? gas.inputDigest ?? "";
|
|
207
|
+
return { objectId: gas.objectId, version, digest };
|
|
208
|
+
}
|
|
195
209
|
var Simulator = class {
|
|
196
210
|
constructor(globals) {
|
|
197
211
|
this.globals = globals;
|
|
198
212
|
}
|
|
199
213
|
async simulate(input) {
|
|
200
|
-
const tx = this.
|
|
214
|
+
const tx = this.copyTransaction(input.txb);
|
|
201
215
|
const { suiClient } = this.globals;
|
|
202
216
|
const gasPrice = await this.getGasPrice();
|
|
203
217
|
tx.setGasPrice(gasPrice);
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
218
|
+
let built;
|
|
219
|
+
try {
|
|
220
|
+
built = await tx.build({ client: suiClient });
|
|
221
|
+
} catch (e) {
|
|
222
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
223
|
+
return {
|
|
224
|
+
success: false,
|
|
225
|
+
gasPrice,
|
|
226
|
+
simulationError: message
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
let inspectResult;
|
|
230
|
+
try {
|
|
231
|
+
inspectResult = await suiClient.simulateTransaction({
|
|
232
|
+
transaction: built,
|
|
233
|
+
include: { effects: true }
|
|
234
|
+
});
|
|
235
|
+
} catch (e) {
|
|
236
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
237
|
+
return {
|
|
238
|
+
success: false,
|
|
239
|
+
gasPrice,
|
|
240
|
+
simulationError: message
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
const txRow = inspectResult.Transaction ?? inspectResult.FailedTransaction;
|
|
244
|
+
const { effects } = txRow;
|
|
245
|
+
if (!effects) {
|
|
246
|
+
throw new Error("simulateTransaction did not return effects");
|
|
247
|
+
}
|
|
248
|
+
const success = effects.status.success === true;
|
|
208
249
|
if (!success) {
|
|
250
|
+
const err = effects.status.success === false ? effects.status.error : null;
|
|
209
251
|
return {
|
|
210
252
|
success,
|
|
211
253
|
gasPrice,
|
|
212
254
|
response: inspectResult,
|
|
213
|
-
simulationError:
|
|
255
|
+
simulationError: err ? formatExecutionError(err) : "Simulation failed"
|
|
214
256
|
};
|
|
215
257
|
}
|
|
216
|
-
const gasBudget = this.toGasBudget(
|
|
258
|
+
const gasBudget = this.toGasBudget(effects.gasUsed, gasPrice);
|
|
217
259
|
return {
|
|
218
260
|
success,
|
|
219
261
|
gasPrice,
|
|
220
|
-
gasObject:
|
|
221
|
-
gasUsed:
|
|
262
|
+
gasObject: gasObjectToReference(effects.gasObject),
|
|
263
|
+
gasUsed: effects.gasUsed,
|
|
222
264
|
gasBudget,
|
|
223
265
|
response: inspectResult
|
|
224
266
|
};
|
|
225
267
|
}
|
|
226
268
|
async getGasPrice() {
|
|
227
|
-
|
|
269
|
+
const { referenceGasPrice } = await this.globals.suiClient.getReferenceGasPrice();
|
|
270
|
+
return BigInt(referenceGasPrice);
|
|
228
271
|
}
|
|
229
272
|
toGasBudget(gasUsed, gasPrice) {
|
|
230
273
|
const { computationCost, storageCost, storageRebate } = gasUsed;
|
|
@@ -233,8 +276,8 @@ var Simulator = class {
|
|
|
233
276
|
const gasBudget = baseComputationCostWithOverhead + BigInt(storageCost) - BigInt(storageRebate);
|
|
234
277
|
return gasBudget > baseComputationCostWithOverhead ? gasBudget : baseComputationCostWithOverhead;
|
|
235
278
|
}
|
|
236
|
-
|
|
237
|
-
return import_transactions.
|
|
279
|
+
copyTransaction(tx) {
|
|
280
|
+
return import_transactions.Transaction.from(tx.serialize());
|
|
238
281
|
}
|
|
239
282
|
};
|
|
240
283
|
|
|
@@ -251,13 +294,13 @@ function HexToUint8Array(hex) {
|
|
|
251
294
|
}
|
|
252
295
|
|
|
253
296
|
// src/utils/crypto.ts
|
|
254
|
-
var import_verify = require("@mysten/sui
|
|
297
|
+
var import_verify = require("@mysten/sui/verify");
|
|
255
298
|
|
|
256
299
|
// src/utils/format.ts
|
|
257
|
-
var import_utils2 = require("@mysten/sui
|
|
300
|
+
var import_utils2 = require("@mysten/sui/utils");
|
|
258
301
|
|
|
259
302
|
// src/utils/coin.ts
|
|
260
|
-
var import_utils = require("@mysten/sui
|
|
303
|
+
var import_utils = require("@mysten/sui/utils");
|
|
261
304
|
var CoinHelper = class {
|
|
262
305
|
_client;
|
|
263
306
|
_coinMetaReg;
|
|
@@ -278,7 +321,7 @@ var CoinHelper = class {
|
|
|
278
321
|
}
|
|
279
322
|
async queryCoinMeta(coinType) {
|
|
280
323
|
const res = await this._client.getCoinMetadata({ coinType });
|
|
281
|
-
return res
|
|
324
|
+
return res.coinMetadata ?? void 0;
|
|
282
325
|
}
|
|
283
326
|
};
|
|
284
327
|
var COIN_TYPE_ARG_REGEX = /^0x0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<(.+)>$/;
|
|
@@ -297,6 +340,13 @@ var Coin = class _Coin {
|
|
|
297
340
|
if (!_Coin.isCoin(data.type)) {
|
|
298
341
|
return void 0;
|
|
299
342
|
}
|
|
343
|
+
if (data.json && typeof data.json === "object" && "balance" in data.json) {
|
|
344
|
+
const { balance: balance2 } = data.json;
|
|
345
|
+
if (balance2 === void 0) {
|
|
346
|
+
return void 0;
|
|
347
|
+
}
|
|
348
|
+
return BigInt(balance2);
|
|
349
|
+
}
|
|
300
350
|
if (data.content?.dataType !== "moveObject") {
|
|
301
351
|
return void 0;
|
|
302
352
|
}
|
|
@@ -337,9 +387,9 @@ function addPrefix(s, prefix) {
|
|
|
337
387
|
var SignatureVerifier = class _SignatureVerifier {
|
|
338
388
|
static async getPublicKeyFromSignature(input) {
|
|
339
389
|
if (input.messageType === "TransactionBlock") {
|
|
340
|
-
return (0, import_verify.
|
|
390
|
+
return (0, import_verify.verifyTransactionSignature)(input.message, input.signature);
|
|
341
391
|
}
|
|
342
|
-
return (0, import_verify.
|
|
392
|
+
return (0, import_verify.verifyPersonalMessageSignature)(input.message, input.signature);
|
|
343
393
|
}
|
|
344
394
|
static async getPublicKeyFromPersonalSignature(input) {
|
|
345
395
|
const message = stringToBuffer(input.messageStr);
|
|
@@ -374,26 +424,69 @@ var SignatureVerifier = class _SignatureVerifier {
|
|
|
374
424
|
|
|
375
425
|
// src/utils/sui.ts
|
|
376
426
|
var import_sui3_utils3 = require("@msafe/sui3-utils");
|
|
377
|
-
var import_cryptography = require("@mysten/sui
|
|
378
|
-
var
|
|
427
|
+
var import_cryptography = require("@mysten/sui/cryptography");
|
|
428
|
+
var import_graphql = require("@mysten/sui/graphql");
|
|
429
|
+
var import_multisig = require("@mysten/sui/multisig");
|
|
379
430
|
var SUI_COIN = "0x2::sui::SUI";
|
|
431
|
+
var GRAPHQL_URL_BY_NETWORK = {
|
|
432
|
+
mainnet: "https://sui-mainnet.mystenlabs.com/graphql",
|
|
433
|
+
testnet: "https://sui-testnet.mystenlabs.com/graphql",
|
|
434
|
+
devnet: "https://sui-devnet.mystenlabs.com/graphql"
|
|
435
|
+
};
|
|
436
|
+
function graphqlClientForGrpc(suiClient) {
|
|
437
|
+
const url = GRAPHQL_URL_BY_NETWORK[suiClient.network] ?? GRAPHQL_URL_BY_NETWORK.testnet;
|
|
438
|
+
return new import_graphql.SuiGraphQLClient({ url, network: suiClient.network });
|
|
439
|
+
}
|
|
440
|
+
function collectSignatureStrings(value) {
|
|
441
|
+
if (typeof value === "string") {
|
|
442
|
+
return [value];
|
|
443
|
+
}
|
|
444
|
+
if (!value || typeof value !== "object") {
|
|
445
|
+
return [];
|
|
446
|
+
}
|
|
447
|
+
if ("base64" in value && typeof value.base64 === "string") {
|
|
448
|
+
return [value.base64];
|
|
449
|
+
}
|
|
450
|
+
if ("scheme" in value && "base64" in value) {
|
|
451
|
+
const b64 = value.base64;
|
|
452
|
+
return typeof b64 === "string" ? [b64] : [];
|
|
453
|
+
}
|
|
454
|
+
return [];
|
|
455
|
+
}
|
|
456
|
+
var TX_SIG_QUERY = `
|
|
457
|
+
query PublicKeyTxSigs($sender: SuiAddress!, $first: Int!) {
|
|
458
|
+
transactions(first: $first, filter: { sentAddress: $sender }) {
|
|
459
|
+
nodes {
|
|
460
|
+
signatures
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
`;
|
|
380
465
|
async function getPublicKeyFromChain(suiClient, address) {
|
|
466
|
+
const graphql = graphqlClientForGrpc(suiClient);
|
|
381
467
|
let txs;
|
|
382
468
|
try {
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
options: { showInput: true },
|
|
387
|
-
limit: 2
|
|
469
|
+
const res = await graphql.query({
|
|
470
|
+
query: TX_SIG_QUERY,
|
|
471
|
+
variables: { sender: address, first: 2 }
|
|
388
472
|
});
|
|
473
|
+
if (res.errors?.length) {
|
|
474
|
+
return void 0;
|
|
475
|
+
}
|
|
476
|
+
txs = res.data ?? {};
|
|
389
477
|
} catch (e) {
|
|
390
478
|
return void 0;
|
|
391
479
|
}
|
|
392
|
-
|
|
480
|
+
const nodes = txs.transactions?.nodes ?? [];
|
|
481
|
+
if (nodes.length === 0) {
|
|
482
|
+
return void 0;
|
|
483
|
+
}
|
|
484
|
+
const first = nodes[0];
|
|
485
|
+
const rawSigs = first.signatures;
|
|
486
|
+
const signatures = Array.isArray(rawSigs) ? rawSigs.flatMap((item) => collectSignatureStrings(item)) : [];
|
|
487
|
+
if (signatures.length === 0) {
|
|
393
488
|
return void 0;
|
|
394
489
|
}
|
|
395
|
-
const tx = txs.data[0];
|
|
396
|
-
const signatures = tx.transaction?.txSignatures;
|
|
397
490
|
for (let i = 0; i !== signatures.length; i++) {
|
|
398
491
|
const serializedSig = signatures[i];
|
|
399
492
|
const pk = getAddressFromSignatures(serializedSig, address);
|
|
@@ -433,18 +526,28 @@ async function getAllCoins(input) {
|
|
|
433
526
|
let cursor;
|
|
434
527
|
const res = [];
|
|
435
528
|
while (hasNext) {
|
|
436
|
-
const currentPage = await input.suiClient.
|
|
529
|
+
const currentPage = await input.suiClient.listCoins({
|
|
437
530
|
owner: input.owner,
|
|
438
531
|
coinType: input.coinType,
|
|
439
532
|
cursor
|
|
440
533
|
});
|
|
441
|
-
res.push(...currentPage.
|
|
534
|
+
res.push(...currentPage.objects);
|
|
442
535
|
hasNext = currentPage.hasNextPage;
|
|
443
|
-
cursor = currentPage.
|
|
536
|
+
cursor = currentPage.cursor;
|
|
444
537
|
}
|
|
445
538
|
return res;
|
|
446
539
|
}
|
|
447
540
|
|
|
541
|
+
// src/utils/transaction.ts
|
|
542
|
+
var import_transactions2 = require("@mysten/sui/transactions");
|
|
543
|
+
function toSuiTransaction(txb) {
|
|
544
|
+
if ((0, import_transactions2.isTransaction)(txb)) {
|
|
545
|
+
return txb;
|
|
546
|
+
}
|
|
547
|
+
const legacy = txb;
|
|
548
|
+
return import_transactions2.Transaction.from(legacy.serialize());
|
|
549
|
+
}
|
|
550
|
+
|
|
448
551
|
// src/utils/iter/iterator.ts
|
|
449
552
|
var REQUEST_PAGE_SIZE = 25;
|
|
450
553
|
async function getAllFromIterator(it) {
|
|
@@ -521,6 +624,10 @@ var EntryIterator = class {
|
|
|
521
624
|
};
|
|
522
625
|
|
|
523
626
|
// src/utils/iter/object.ts
|
|
627
|
+
var defaultObjectInclude = { json: true };
|
|
628
|
+
function mergeInclude(options) {
|
|
629
|
+
return { ...defaultObjectInclude, ...options?.objectInclude };
|
|
630
|
+
}
|
|
524
631
|
async function getAllOwnedObjects(provider, owner, options) {
|
|
525
632
|
const iter = new OwnedObjectIterator(provider, owner, options);
|
|
526
633
|
return await getAllFromIterator(iter);
|
|
@@ -541,32 +648,29 @@ var OwnedObjectRequester = class {
|
|
|
541
648
|
this.nextCursor = null;
|
|
542
649
|
this.filter = options?.filter;
|
|
543
650
|
this.pageSize = options?.pageSize || REQUEST_PAGE_SIZE;
|
|
544
|
-
this.
|
|
545
|
-
showType: true,
|
|
546
|
-
showContent: true
|
|
547
|
-
};
|
|
651
|
+
this.objectInclude = mergeInclude(options);
|
|
548
652
|
}
|
|
549
653
|
nextCursor;
|
|
550
654
|
filter;
|
|
551
655
|
pageSize;
|
|
552
|
-
|
|
656
|
+
objectInclude;
|
|
553
657
|
async doNextRequest() {
|
|
554
|
-
const res = await this.provider.
|
|
658
|
+
const res = await this.provider.listOwnedObjects({
|
|
555
659
|
owner: this.owner,
|
|
556
|
-
|
|
660
|
+
include: this.objectInclude,
|
|
557
661
|
cursor: this.nextCursor,
|
|
558
662
|
limit: this.pageSize
|
|
559
663
|
});
|
|
560
|
-
this.nextCursor = res.
|
|
664
|
+
this.nextCursor = res.cursor;
|
|
561
665
|
let filtered;
|
|
562
666
|
if (this.filter) {
|
|
563
667
|
const { filter } = this;
|
|
564
|
-
filtered = res.
|
|
668
|
+
filtered = res.objects.filter((obj) => filter(obj));
|
|
565
669
|
} else {
|
|
566
|
-
filtered = res.
|
|
670
|
+
filtered = res.objects;
|
|
567
671
|
}
|
|
568
672
|
return {
|
|
569
|
-
data: filtered
|
|
673
|
+
data: filtered,
|
|
570
674
|
hasNext: res.hasNextPage
|
|
571
675
|
};
|
|
572
676
|
}
|
|
@@ -596,14 +700,21 @@ var MSafeAccount = class _MSafeAccount {
|
|
|
596
700
|
}
|
|
597
701
|
}
|
|
598
702
|
async ownedCoins() {
|
|
599
|
-
const balances =
|
|
703
|
+
const balances = [];
|
|
704
|
+
let cursor = null;
|
|
705
|
+
let hasNext = true;
|
|
706
|
+
while (hasNext) {
|
|
707
|
+
const page = await this.suiClient.listBalances({ owner: this.address, cursor, limit: 50 });
|
|
708
|
+
balances.push(...page.balances);
|
|
709
|
+
hasNext = page.hasNextPage;
|
|
710
|
+
cursor = page.cursor;
|
|
711
|
+
}
|
|
600
712
|
return Promise.all(
|
|
601
713
|
balances.map(async (balance) => {
|
|
602
714
|
const meta = await this.coinHelper.getCoinMeta(balance.coinType);
|
|
603
|
-
const unlockedBalance = balance.lockedBalance.number ? BigInt(balance.totalBalance) - BigInt(balance.lockedBalance.number) : BigInt(balance.totalBalance);
|
|
604
715
|
return {
|
|
605
716
|
type: (0, import_utils3.normalizeStructTag)(balance.coinType),
|
|
606
|
-
balance: BigInt(
|
|
717
|
+
balance: BigInt(balance.addressBalance),
|
|
607
718
|
metadata: meta
|
|
608
719
|
};
|
|
609
720
|
})
|
|
@@ -611,7 +722,7 @@ var MSafeAccount = class _MSafeAccount {
|
|
|
611
722
|
}
|
|
612
723
|
async ownedObjects(options) {
|
|
613
724
|
const filterCoinObjectOptions = {
|
|
614
|
-
filter: (
|
|
725
|
+
filter: (obj) => !obj?.type?.startsWith("0x2::coin::Coin"),
|
|
615
726
|
...options
|
|
616
727
|
};
|
|
617
728
|
return getAllOwnedObjects(this.suiClient, this.address, filterCoinObjectOptions);
|
|
@@ -666,19 +777,21 @@ var MSafeAccount = class _MSafeAccount {
|
|
|
666
777
|
if (!appHelper) {
|
|
667
778
|
throw new Error(`Can't find app helper for application ${request.application}`);
|
|
668
779
|
}
|
|
669
|
-
txb =
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
780
|
+
txb = toSuiTransaction(
|
|
781
|
+
await appHelper.build({
|
|
782
|
+
network: this.globals.config.network,
|
|
783
|
+
intentionData: request.intention,
|
|
784
|
+
txType: request.txType,
|
|
785
|
+
txSubType: request.txSubType,
|
|
786
|
+
clientUrl: this.globals.config.suiClient.url,
|
|
787
|
+
account: {
|
|
788
|
+
address: this.address,
|
|
789
|
+
publicKey: (0, import_utils3.fromHex)(this.address),
|
|
790
|
+
chains: [import_wallet_standard.SUI_MAINNET_CHAIN, import_wallet_standard.SUI_TESTNET_CHAIN],
|
|
791
|
+
features: []
|
|
792
|
+
}
|
|
793
|
+
})
|
|
794
|
+
);
|
|
682
795
|
}
|
|
683
796
|
txb.setSender(this.address);
|
|
684
797
|
return this.simulator.simulate({ txb, sender: this.address });
|
|
@@ -707,19 +820,21 @@ var MSafeAccount = class _MSafeAccount {
|
|
|
707
820
|
if (!appHelper) {
|
|
708
821
|
throw new Error(`Can't find app helper for application ${input.application}`);
|
|
709
822
|
}
|
|
710
|
-
txb =
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
823
|
+
txb = toSuiTransaction(
|
|
824
|
+
await appHelper.build({
|
|
825
|
+
network: this.globals.config.network,
|
|
826
|
+
intentionData: input.intention,
|
|
827
|
+
txType: input.txType,
|
|
828
|
+
txSubType: input.txSubType,
|
|
829
|
+
clientUrl: this.globals.config.suiClient.url,
|
|
830
|
+
account: {
|
|
831
|
+
address: this.address,
|
|
832
|
+
publicKey: (0, import_utils3.fromHex)(this.address),
|
|
833
|
+
chains: [import_wallet_standard.SUI_MAINNET_CHAIN, import_wallet_standard.SUI_TESTNET_CHAIN],
|
|
834
|
+
features: []
|
|
835
|
+
}
|
|
836
|
+
})
|
|
837
|
+
);
|
|
723
838
|
}
|
|
724
839
|
txb.setGasPrice(input.gasPrice);
|
|
725
840
|
txb.setGasBudget(input.gasBudget);
|
|
@@ -729,7 +844,7 @@ var MSafeAccount = class _MSafeAccount {
|
|
|
729
844
|
const signature = await this.wallet.signTransactionBlock({ transactionBlock: payload });
|
|
730
845
|
return this.backend.proposeIntentionAndBuildVote({
|
|
731
846
|
...input,
|
|
732
|
-
payload: (0, import_utils3.
|
|
847
|
+
payload: (0, import_utils3.toHex)(payload),
|
|
733
848
|
digest,
|
|
734
849
|
msafeAddress: this.address,
|
|
735
850
|
signature: signature.signature
|
|
@@ -787,8 +902,9 @@ var MSafeAccount = class _MSafeAccount {
|
|
|
787
902
|
}
|
|
788
903
|
async proposePlainPayloadIntention(intention) {
|
|
789
904
|
const sn = await this.nextSequenceNumber();
|
|
790
|
-
const tb =
|
|
791
|
-
|
|
905
|
+
const tb = import_transactions3.Transaction.from(intention.payload);
|
|
906
|
+
const data = tb.getData();
|
|
907
|
+
if (!data.sender || !(0, import_sui3_utils4.isSameAddress)(data.sender, this.address)) {
|
|
792
908
|
throw new Error("Transaction sender is not same as the multisig address");
|
|
793
909
|
}
|
|
794
910
|
return this.proposeIntention({
|
|
@@ -813,7 +929,7 @@ var MSafeAccount = class _MSafeAccount {
|
|
|
813
929
|
if (!pendingTx || pendingTx.rejectDigest !== "") {
|
|
814
930
|
throw new Error("Already rejected");
|
|
815
931
|
}
|
|
816
|
-
const txb = (0, import_sui3_utils4.buildRejectTxb)(this.address);
|
|
932
|
+
const txb = toSuiTransaction((0, import_sui3_utils4.buildRejectTxb)(this.address));
|
|
817
933
|
txb.setSender(this.address);
|
|
818
934
|
return this.simulator.simulate({ txb, sender: this.address });
|
|
819
935
|
}
|
|
@@ -822,7 +938,7 @@ var MSafeAccount = class _MSafeAccount {
|
|
|
822
938
|
if (!pendingTx || pendingTx.rejectDigest !== "") {
|
|
823
939
|
throw new Error("Already rejected");
|
|
824
940
|
}
|
|
825
|
-
const rejectTxb = (0, import_sui3_utils4.buildRejectTxb)(this.address);
|
|
941
|
+
const rejectTxb = toSuiTransaction((0, import_sui3_utils4.buildRejectTxb)(this.address));
|
|
826
942
|
const digest = await rejectTxb.getDigest({ client: this.suiClient });
|
|
827
943
|
const payload = await rejectTxb.build({ client: this.suiClient });
|
|
828
944
|
const signature = await this.wallet.signTransactionBlock({ transactionBlock: payload });
|
|
@@ -839,19 +955,21 @@ var MSafeAccount = class _MSafeAccount {
|
|
|
839
955
|
if (!appHelper) {
|
|
840
956
|
throw new Error(`Can't find app helper for application ${intention.application}`);
|
|
841
957
|
}
|
|
842
|
-
const txb =
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
958
|
+
const txb = toSuiTransaction(
|
|
959
|
+
await appHelper.build({
|
|
960
|
+
network: this.globals.config.network,
|
|
961
|
+
intentionData: intention.intention,
|
|
962
|
+
txType: intention.txType,
|
|
963
|
+
txSubType: intention.txSubType,
|
|
964
|
+
clientUrl: this.globals.config.suiClient.url,
|
|
965
|
+
account: {
|
|
966
|
+
address: this.address,
|
|
967
|
+
publicKey: (0, import_utils3.fromHex)(this.address),
|
|
968
|
+
chains: [import_wallet_standard.SUI_MAINNET_CHAIN, import_wallet_standard.SUI_TESTNET_CHAIN],
|
|
969
|
+
features: []
|
|
970
|
+
}
|
|
971
|
+
})
|
|
972
|
+
);
|
|
855
973
|
txb.setSender(this.address);
|
|
856
974
|
return this.simulator.simulate({ txb, sender: this.address });
|
|
857
975
|
}
|
|
@@ -885,10 +1003,10 @@ var MSafeAccount = class _MSafeAccount {
|
|
|
885
1003
|
}
|
|
886
1004
|
}
|
|
887
1005
|
const multiSignature = this.multiSig.combinePartialSignatures(sortedSigs);
|
|
888
|
-
return this.suiClient.
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
1006
|
+
return this.suiClient.executeTransaction({
|
|
1007
|
+
transaction: HexToUint8Array(payload),
|
|
1008
|
+
signatures: [multiSignature],
|
|
1009
|
+
include: { effects: true, events: true }
|
|
892
1010
|
});
|
|
893
1011
|
}
|
|
894
1012
|
async dashboard() {
|
|
@@ -928,7 +1046,7 @@ var MSafeAccount = class _MSafeAccount {
|
|
|
928
1046
|
|
|
929
1047
|
// src/core/PublicKeyHelper.ts
|
|
930
1048
|
var import_sui3_utils5 = require("@msafe/sui3-utils");
|
|
931
|
-
var import_utils5 = require("@mysten/sui
|
|
1049
|
+
var import_utils5 = require("@mysten/sui/utils");
|
|
932
1050
|
var PublicKeyHelper = class {
|
|
933
1051
|
constructor(globals) {
|
|
934
1052
|
this.globals = globals;
|
|
@@ -1014,7 +1132,7 @@ var ReportSDK = class {
|
|
|
1014
1132
|
};
|
|
1015
1133
|
|
|
1016
1134
|
// src/globals/MSafeGlobals.ts
|
|
1017
|
-
var
|
|
1135
|
+
var import_grpc = require("@mysten/sui/grpc");
|
|
1018
1136
|
|
|
1019
1137
|
// src/backend/BackendImpl.ts
|
|
1020
1138
|
var import_sui3_utils6 = require("@msafe/sui3-utils");
|
|
@@ -1323,6 +1441,9 @@ var BackendError = class _BackendError extends Error {
|
|
|
1323
1441
|
};
|
|
1324
1442
|
|
|
1325
1443
|
// src/globals/const.ts
|
|
1444
|
+
function msafeChainToSuiNetwork(chain) {
|
|
1445
|
+
return chain === "sui:mainnet" ? "mainnet" : "testnet";
|
|
1446
|
+
}
|
|
1326
1447
|
var MSafeEnv = /* @__PURE__ */ ((MSafeEnv3) => {
|
|
1327
1448
|
MSafeEnv3["local"] = "local";
|
|
1328
1449
|
MSafeEnv3["unit"] = "unit";
|
|
@@ -1331,6 +1452,16 @@ var MSafeEnv = /* @__PURE__ */ ((MSafeEnv3) => {
|
|
|
1331
1452
|
MSafeEnv3["prod"] = "prod";
|
|
1332
1453
|
return MSafeEnv3;
|
|
1333
1454
|
})(MSafeEnv || {});
|
|
1455
|
+
function httpUrlToGrpcBaseUrl(url) {
|
|
1456
|
+
const parsed = new URL(url);
|
|
1457
|
+
if (parsed.protocol === "https:" && parsed.port === "") {
|
|
1458
|
+
return `https://${parsed.hostname}:443${parsed.pathname}${parsed.search}`;
|
|
1459
|
+
}
|
|
1460
|
+
if (parsed.protocol === "http:" && parsed.port === "") {
|
|
1461
|
+
return `http://${parsed.hostname}:80${parsed.pathname}${parsed.search}`;
|
|
1462
|
+
}
|
|
1463
|
+
return `${parsed.origin}${parsed.pathname}${parsed.search}`;
|
|
1464
|
+
}
|
|
1334
1465
|
var TESTNET_RPC_URL = "https://fullnode.testnet.sui.io";
|
|
1335
1466
|
var MAINNET_RPC_URL = "https://fullnode.mainnet.sui.io";
|
|
1336
1467
|
var LOCAL_API_URL = "http://127.0.0.1:3000";
|
|
@@ -1347,9 +1478,9 @@ var ENV_CONFIGS = /* @__PURE__ */ new Map([
|
|
|
1347
1478
|
url: TESTNET_RPC_URL
|
|
1348
1479
|
},
|
|
1349
1480
|
backend: {
|
|
1350
|
-
url:
|
|
1481
|
+
url: DEV_API_URL
|
|
1351
1482
|
},
|
|
1352
|
-
syncingURL:
|
|
1483
|
+
syncingURL: DEV_SYNCING_URL,
|
|
1353
1484
|
network: "sui:testnet"
|
|
1354
1485
|
}
|
|
1355
1486
|
],
|
|
@@ -1436,9 +1567,13 @@ var MSafeGlobals = class _MSafeGlobals {
|
|
|
1436
1567
|
}
|
|
1437
1568
|
static async New(env, options) {
|
|
1438
1569
|
const config = getMSafeConfig(env, options);
|
|
1439
|
-
const suiClient = new
|
|
1440
|
-
|
|
1441
|
-
|
|
1570
|
+
const suiClient = config.suiClient.transport ? new import_grpc.SuiGrpcClient({
|
|
1571
|
+
transport: config.suiClient.transport,
|
|
1572
|
+
network: msafeChainToSuiNetwork(config.network)
|
|
1573
|
+
}) : new import_grpc.SuiGrpcClient({
|
|
1574
|
+
baseUrl: httpUrlToGrpcBaseUrl(config.suiClient.url),
|
|
1575
|
+
network: msafeChainToSuiNetwork(config.network)
|
|
1576
|
+
});
|
|
1442
1577
|
const backend = new BackendImpl(config.backend.url, options?.mockAddress);
|
|
1443
1578
|
return new _MSafeGlobals({
|
|
1444
1579
|
backend,
|