@msafe/sui3-sdk 0.0.89 → 1.0.4
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 +377 -149
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +35 -29
- package/dist/index.d.ts +35 -29
- package/dist/index.js +386 -175
- package/dist/index.js.map +1 -1
- package/package.json +34 -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.js
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
1
4
|
// src/core/CreateHelper.ts
|
|
2
|
-
import {
|
|
3
|
-
isSameAddress,
|
|
4
|
-
MultiSigAccount,
|
|
5
|
-
PublicKeySerde,
|
|
6
|
-
SigningMessageHelper
|
|
7
|
-
} from "@msafe/sui3-utils";
|
|
5
|
+
import { isSameAddress, MultiSigAccount, PublicKeySerde, SigningMessageHelper } from "@msafe/sui3-utils";
|
|
8
6
|
var CreateHelper = class {
|
|
7
|
+
static {
|
|
8
|
+
__name(this, "CreateHelper");
|
|
9
|
+
}
|
|
10
|
+
globals;
|
|
11
|
+
pkHelper;
|
|
9
12
|
constructor(globals, pkHelper) {
|
|
10
13
|
this.globals = globals;
|
|
11
14
|
this.pkHelper = pkHelper;
|
|
@@ -23,13 +26,13 @@ var CreateHelper = class {
|
|
|
23
26
|
return this.calculateMSafeAddress(createInfo);
|
|
24
27
|
}
|
|
25
28
|
/**
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
* Add user manually added public key for an address. If user input the public key with
|
|
30
|
+
* extra signature scheme flag, the scheme value will be automatically fixed.
|
|
31
|
+
*
|
|
32
|
+
* @param address
|
|
33
|
+
* @param pkEncoded
|
|
34
|
+
* @throws error if the public key does not match
|
|
35
|
+
*/
|
|
33
36
|
addPublicKey(address, pkEncoded) {
|
|
34
37
|
const pk = PublicKeySerde.de(pkEncoded);
|
|
35
38
|
if (!isSameAddress(address, pk.toSuiAddress())) {
|
|
@@ -40,7 +43,9 @@ var CreateHelper = class {
|
|
|
40
43
|
async submitMSafeCreation(creationInfo) {
|
|
41
44
|
const msafeAddress = await this.validateCreateInfo(creationInfo);
|
|
42
45
|
const signingMessage = SigningMessageHelper.createMSafeMessage(msafeAddress);
|
|
43
|
-
const signature = await this.globals.wallet.signPersonalMessage({
|
|
46
|
+
const signature = await this.globals.wallet.signPersonalMessage({
|
|
47
|
+
messageStr: signingMessage
|
|
48
|
+
});
|
|
44
49
|
await this.submitToBackend(creationInfo, signature.signature);
|
|
45
50
|
return msafeAddress;
|
|
46
51
|
}
|
|
@@ -71,9 +76,7 @@ var CreateHelper = class {
|
|
|
71
76
|
})),
|
|
72
77
|
threshold: createInfo.threshold,
|
|
73
78
|
name: createInfo.name,
|
|
74
|
-
// name validation is deferred to backend
|
|
75
79
|
description: createInfo.description,
|
|
76
|
-
// description validation is deferred to backend
|
|
77
80
|
creationNonce: createInfo.creationNonce,
|
|
78
81
|
signature
|
|
79
82
|
});
|
|
@@ -81,14 +84,15 @@ var CreateHelper = class {
|
|
|
81
84
|
};
|
|
82
85
|
|
|
83
86
|
// src/core/MSafeClient.ts
|
|
84
|
-
import {
|
|
85
|
-
SigningMessageHelper as SigningMessageHelper4,
|
|
86
|
-
UserMSafeStatus as UserMSafeStatus2
|
|
87
|
-
} from "@msafe/sui3-utils";
|
|
87
|
+
import { SigningMessageHelper as SigningMessageHelper4, UserMSafeStatus as UserMSafeStatus2 } from "@msafe/sui3-utils";
|
|
88
88
|
|
|
89
89
|
// src/core/AddressBookSDK.ts
|
|
90
90
|
import { SigningMessageHelper as SigningMessageHelper2 } from "@msafe/sui3-utils";
|
|
91
91
|
var AddressBookSDK = class {
|
|
92
|
+
static {
|
|
93
|
+
__name(this, "AddressBookSDK");
|
|
94
|
+
}
|
|
95
|
+
globals;
|
|
92
96
|
constructor(globals) {
|
|
93
97
|
this.globals = globals;
|
|
94
98
|
}
|
|
@@ -97,60 +101,75 @@ var AddressBookSDK = class {
|
|
|
97
101
|
}
|
|
98
102
|
async update(updates) {
|
|
99
103
|
const messageStr = SigningMessageHelper2.updateAddressBookMessage(updates);
|
|
100
|
-
const sig = await this.globals.wallet.signPersonalMessage({
|
|
101
|
-
|
|
104
|
+
const sig = await this.globals.wallet.signPersonalMessage({
|
|
105
|
+
messageStr
|
|
106
|
+
});
|
|
107
|
+
return this.globals.backend.updateAddressBook({
|
|
108
|
+
updates,
|
|
109
|
+
signature: sig.signature
|
|
110
|
+
});
|
|
102
111
|
}
|
|
103
112
|
async getMode() {
|
|
104
113
|
const res = await this.globals.backend.getAddressBookMode();
|
|
105
114
|
return res.mode;
|
|
106
115
|
}
|
|
107
116
|
async setMode(mode) {
|
|
108
|
-
return this.globals.backend.setAddressBookMode({
|
|
117
|
+
return this.globals.backend.setAddressBookMode({
|
|
118
|
+
mode
|
|
119
|
+
});
|
|
109
120
|
}
|
|
110
121
|
};
|
|
111
122
|
|
|
112
123
|
// src/core/InvitationSDK.ts
|
|
113
124
|
var InvitationSDK = class {
|
|
125
|
+
static {
|
|
126
|
+
__name(this, "InvitationSDK");
|
|
127
|
+
}
|
|
128
|
+
globals;
|
|
114
129
|
constructor(globals) {
|
|
115
130
|
this.globals = globals;
|
|
116
131
|
}
|
|
117
132
|
async getMSafeByStatus(status, pagination) {
|
|
118
|
-
return this.globals.backend.getOwnedMSafeByStatus({
|
|
133
|
+
return this.globals.backend.getOwnedMSafeByStatus({
|
|
134
|
+
status,
|
|
135
|
+
pagination
|
|
136
|
+
});
|
|
119
137
|
}
|
|
120
138
|
async updateMSafeStatus(msafeAddress, status) {
|
|
121
|
-
return this.globals.backend.updateMSafeStatus({
|
|
139
|
+
return this.globals.backend.updateMSafeStatus({
|
|
140
|
+
msafeAddress,
|
|
141
|
+
status
|
|
142
|
+
});
|
|
122
143
|
}
|
|
123
144
|
};
|
|
124
145
|
|
|
125
146
|
// src/core/MSafeAccount.ts
|
|
126
147
|
import { appHelpers } from "@msafe/sui-app-store";
|
|
127
|
-
import {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
TransactionDefaultApplication,
|
|
131
|
-
TransactionSubTypes,
|
|
132
|
-
TransactionType,
|
|
133
|
-
buildRejectTxb,
|
|
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";
|
|
148
|
+
import { MultiSigAccount as MultiSigAccount2, SigningMessageHelper as SigningMessageHelper3, TransactionDefaultApplication, TransactionSubTypes, TransactionType, buildRejectTxb, isSameAddress as isSameAddress2 } from "@msafe/sui3-utils";
|
|
149
|
+
import { Transaction as Transaction3 } from "@mysten/sui/transactions";
|
|
150
|
+
import { fromHex, normalizeStructTag as normalizeStructTag3, toHex } from "@mysten/sui/utils";
|
|
138
151
|
import { SUI_MAINNET_CHAIN, SUI_TESTNET_CHAIN } from "@mysten/wallet-standard";
|
|
139
152
|
|
|
140
153
|
// src/simulate/simulator.ts
|
|
141
|
-
import {
|
|
154
|
+
import { Transaction } from "@mysten/sui/transactions";
|
|
142
155
|
var GAS_SAFE_OVERHEAD = 1000n;
|
|
143
156
|
var Simulator = class {
|
|
157
|
+
static {
|
|
158
|
+
__name(this, "Simulator");
|
|
159
|
+
}
|
|
160
|
+
globals;
|
|
144
161
|
constructor(globals) {
|
|
145
162
|
this.globals = globals;
|
|
146
163
|
}
|
|
147
164
|
async simulate(input) {
|
|
148
|
-
const tx = this.
|
|
165
|
+
const tx = this.copyTransaction(input.txb);
|
|
149
166
|
const { suiClient } = this.globals;
|
|
150
167
|
const gasPrice = await this.getGasPrice();
|
|
151
168
|
tx.setGasPrice(gasPrice);
|
|
152
169
|
const inspectResult = await suiClient.dryRunTransactionBlock({
|
|
153
|
-
transactionBlock: await tx.build({
|
|
170
|
+
transactionBlock: await tx.build({
|
|
171
|
+
client: suiClient
|
|
172
|
+
})
|
|
154
173
|
});
|
|
155
174
|
const success = inspectResult.effects.status.status === "success";
|
|
156
175
|
if (!success) {
|
|
@@ -181,32 +200,38 @@ var Simulator = class {
|
|
|
181
200
|
const gasBudget = baseComputationCostWithOverhead + BigInt(storageCost) - BigInt(storageRebate);
|
|
182
201
|
return gasBudget > baseComputationCostWithOverhead ? gasBudget : baseComputationCostWithOverhead;
|
|
183
202
|
}
|
|
184
|
-
|
|
185
|
-
return
|
|
203
|
+
copyTransaction(tx) {
|
|
204
|
+
return Transaction.from(tx.serialize());
|
|
186
205
|
}
|
|
187
206
|
};
|
|
188
207
|
|
|
189
208
|
// src/utils/buffer.ts
|
|
190
|
-
import { Buffer } from "buffer";
|
|
209
|
+
import { Buffer as Buffer2 } from "buffer";
|
|
191
210
|
function stringToBuffer(s) {
|
|
192
|
-
return
|
|
211
|
+
return Buffer2.from(s, "utf-8");
|
|
193
212
|
}
|
|
213
|
+
__name(stringToBuffer, "stringToBuffer");
|
|
194
214
|
function Uint8ArrayToHex(b) {
|
|
195
215
|
return `0x${Array.prototype.map.call(b, (x) => `0${x.toString(16)}`.slice(-2)).join("")}`;
|
|
196
216
|
}
|
|
217
|
+
__name(Uint8ArrayToHex, "Uint8ArrayToHex");
|
|
197
218
|
function HexToUint8Array(hex) {
|
|
198
|
-
return Uint8Array.from(
|
|
219
|
+
return Uint8Array.from(Buffer2.from(hex.startsWith("0x") ? hex.slice(2) : hex, "hex"));
|
|
199
220
|
}
|
|
221
|
+
__name(HexToUint8Array, "HexToUint8Array");
|
|
200
222
|
|
|
201
223
|
// src/utils/crypto.ts
|
|
202
|
-
import {
|
|
224
|
+
import { verifyPersonalMessageSignature, verifyTransactionSignature } from "@mysten/sui/verify";
|
|
203
225
|
|
|
204
226
|
// src/utils/format.ts
|
|
205
|
-
import { normalizeSuiAddress, normalizeStructTag as normalizeStructTag2 } from "@mysten/sui
|
|
227
|
+
import { normalizeSuiAddress, normalizeStructTag as normalizeStructTag2 } from "@mysten/sui/utils";
|
|
206
228
|
|
|
207
229
|
// src/utils/coin.ts
|
|
208
|
-
import { normalizeStructTag } from "@mysten/sui
|
|
230
|
+
import { normalizeStructTag } from "@mysten/sui/utils";
|
|
209
231
|
var CoinHelper = class {
|
|
232
|
+
static {
|
|
233
|
+
__name(this, "CoinHelper");
|
|
234
|
+
}
|
|
210
235
|
_client;
|
|
211
236
|
_coinMetaReg;
|
|
212
237
|
constructor(client) {
|
|
@@ -225,12 +250,17 @@ var CoinHelper = class {
|
|
|
225
250
|
return meta;
|
|
226
251
|
}
|
|
227
252
|
async queryCoinMeta(coinType) {
|
|
228
|
-
const res = await this._client.getCoinMetadata({
|
|
253
|
+
const res = await this._client.getCoinMetadata({
|
|
254
|
+
coinType
|
|
255
|
+
});
|
|
229
256
|
return res || void 0;
|
|
230
257
|
}
|
|
231
258
|
};
|
|
232
259
|
var COIN_TYPE_ARG_REGEX = /^0x0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<(.+)>$/;
|
|
233
260
|
var Coin = class _Coin {
|
|
261
|
+
static {
|
|
262
|
+
__name(this, "Coin");
|
|
263
|
+
}
|
|
234
264
|
static isCoin(type) {
|
|
235
265
|
if (!type) {
|
|
236
266
|
return false;
|
|
@@ -258,6 +288,9 @@ var Coin = class _Coin {
|
|
|
258
288
|
|
|
259
289
|
// src/utils/format.ts
|
|
260
290
|
var Formatter = class {
|
|
291
|
+
static {
|
|
292
|
+
__name(this, "Formatter");
|
|
293
|
+
}
|
|
261
294
|
static normalizeSuiAddress(addr) {
|
|
262
295
|
return normalizeSuiAddress(addr);
|
|
263
296
|
}
|
|
@@ -280,14 +313,18 @@ function addPrefix(s, prefix) {
|
|
|
280
313
|
}
|
|
281
314
|
return prefix + s;
|
|
282
315
|
}
|
|
316
|
+
__name(addPrefix, "addPrefix");
|
|
283
317
|
|
|
284
318
|
// src/utils/crypto.ts
|
|
285
319
|
var SignatureVerifier = class _SignatureVerifier {
|
|
320
|
+
static {
|
|
321
|
+
__name(this, "SignatureVerifier");
|
|
322
|
+
}
|
|
286
323
|
static async getPublicKeyFromSignature(input) {
|
|
287
324
|
if (input.messageType === "TransactionBlock") {
|
|
288
|
-
return
|
|
325
|
+
return verifyTransactionSignature(input.message, input.signature);
|
|
289
326
|
}
|
|
290
|
-
return
|
|
327
|
+
return verifyPersonalMessageSignature(input.message, input.signature);
|
|
291
328
|
}
|
|
292
329
|
static async getPublicKeyFromPersonalSignature(input) {
|
|
293
330
|
const message = stringToBuffer(input.messageStr);
|
|
@@ -322,16 +359,20 @@ var SignatureVerifier = class _SignatureVerifier {
|
|
|
322
359
|
|
|
323
360
|
// src/utils/sui.ts
|
|
324
361
|
import { PublicKeySerde as PublicKeySerde2 } from "@msafe/sui3-utils";
|
|
325
|
-
import { parseSerializedSignature } from "@mysten/sui
|
|
326
|
-
import { MultiSigPublicKey } from "@mysten/sui
|
|
362
|
+
import { parseSerializedSignature } from "@mysten/sui/cryptography";
|
|
363
|
+
import { MultiSigPublicKey } from "@mysten/sui/multisig";
|
|
327
364
|
var SUI_COIN = "0x2::sui::SUI";
|
|
328
365
|
async function getPublicKeyFromChain(suiClient, address) {
|
|
329
366
|
let txs;
|
|
330
367
|
try {
|
|
331
368
|
txs = await suiClient.queryTransactionBlocks({
|
|
332
369
|
// Disable naming rule since the variable is defined by Mysten
|
|
333
|
-
filter: {
|
|
334
|
-
|
|
370
|
+
filter: {
|
|
371
|
+
FromAddress: address
|
|
372
|
+
},
|
|
373
|
+
options: {
|
|
374
|
+
showInput: true
|
|
375
|
+
},
|
|
335
376
|
limit: 2
|
|
336
377
|
});
|
|
337
378
|
} catch (e) {
|
|
@@ -352,6 +393,7 @@ async function getPublicKeyFromChain(suiClient, address) {
|
|
|
352
393
|
}
|
|
353
394
|
return void 0;
|
|
354
395
|
}
|
|
396
|
+
__name(getPublicKeyFromChain, "getPublicKeyFromChain");
|
|
355
397
|
function getAddressFromSignatures(serializedSig, targetAddress) {
|
|
356
398
|
const decoded = parseSerializedSignature(serializedSig);
|
|
357
399
|
switch (decoded.signatureScheme) {
|
|
@@ -366,7 +408,10 @@ function getAddressFromSignatures(serializedSig, targetAddress) {
|
|
|
366
408
|
case "ED25519":
|
|
367
409
|
case "Secp256k1":
|
|
368
410
|
case "Secp256r1": {
|
|
369
|
-
const pk = PublicKeySerde2.de({
|
|
411
|
+
const pk = PublicKeySerde2.de({
|
|
412
|
+
publicKeyEncoded: decoded.publicKey,
|
|
413
|
+
schema: decoded.signatureScheme
|
|
414
|
+
});
|
|
370
415
|
if (Formatter.isSuiAddressEqual(pk.toSuiAddress(), targetAddress)) {
|
|
371
416
|
return pk;
|
|
372
417
|
}
|
|
@@ -376,6 +421,7 @@ function getAddressFromSignatures(serializedSig, targetAddress) {
|
|
|
376
421
|
throw new Error("Unknown schema");
|
|
377
422
|
}
|
|
378
423
|
}
|
|
424
|
+
__name(getAddressFromSignatures, "getAddressFromSignatures");
|
|
379
425
|
async function getAllCoins(input) {
|
|
380
426
|
let hasNext = true;
|
|
381
427
|
let cursor;
|
|
@@ -392,6 +438,18 @@ async function getAllCoins(input) {
|
|
|
392
438
|
}
|
|
393
439
|
return res;
|
|
394
440
|
}
|
|
441
|
+
__name(getAllCoins, "getAllCoins");
|
|
442
|
+
|
|
443
|
+
// src/utils/transaction.ts
|
|
444
|
+
import { Transaction as Transaction2, isTransaction } from "@mysten/sui/transactions";
|
|
445
|
+
function toSuiTransaction(txb) {
|
|
446
|
+
if (isTransaction(txb)) {
|
|
447
|
+
return txb;
|
|
448
|
+
}
|
|
449
|
+
const legacy = txb;
|
|
450
|
+
return Transaction2.from(legacy.serialize());
|
|
451
|
+
}
|
|
452
|
+
__name(toSuiTransaction, "toSuiTransaction");
|
|
395
453
|
|
|
396
454
|
// src/utils/iter/iterator.ts
|
|
397
455
|
var REQUEST_PAGE_SIZE = 25;
|
|
@@ -406,14 +464,19 @@ async function getAllFromIterator(it) {
|
|
|
406
464
|
}
|
|
407
465
|
return res;
|
|
408
466
|
}
|
|
467
|
+
__name(getAllFromIterator, "getAllFromIterator");
|
|
409
468
|
var PagedIterator = class {
|
|
469
|
+
static {
|
|
470
|
+
__name(this, "PagedIterator");
|
|
471
|
+
}
|
|
472
|
+
requester;
|
|
473
|
+
curPage;
|
|
474
|
+
init;
|
|
410
475
|
constructor(requester) {
|
|
411
476
|
this.requester = requester;
|
|
412
477
|
this.curPage = void 0;
|
|
413
478
|
this.init = true;
|
|
414
479
|
}
|
|
415
|
-
curPage;
|
|
416
|
-
init;
|
|
417
480
|
async hasNext() {
|
|
418
481
|
if (this.init) {
|
|
419
482
|
if (!this.curPage) {
|
|
@@ -439,15 +502,19 @@ var PagedIterator = class {
|
|
|
439
502
|
}
|
|
440
503
|
};
|
|
441
504
|
var EntryIterator = class {
|
|
505
|
+
static {
|
|
506
|
+
__name(this, "EntryIterator");
|
|
507
|
+
}
|
|
508
|
+
requester;
|
|
509
|
+
cursor;
|
|
510
|
+
pager;
|
|
511
|
+
curData;
|
|
442
512
|
constructor(requester) {
|
|
443
513
|
this.requester = requester;
|
|
444
514
|
this.pager = new PagedIterator(requester);
|
|
445
515
|
this.curData = [];
|
|
446
516
|
this.cursor = 0;
|
|
447
517
|
}
|
|
448
|
-
cursor;
|
|
449
|
-
pager;
|
|
450
|
-
curData;
|
|
451
518
|
async hasNext() {
|
|
452
519
|
if (this.cursor < this.curData.length - 1) {
|
|
453
520
|
return true;
|
|
@@ -473,7 +540,14 @@ async function getAllOwnedObjects(provider, owner, options) {
|
|
|
473
540
|
const iter = new OwnedObjectIterator(provider, owner, options);
|
|
474
541
|
return await getAllFromIterator(iter);
|
|
475
542
|
}
|
|
543
|
+
__name(getAllOwnedObjects, "getAllOwnedObjects");
|
|
476
544
|
var OwnedObjectIterator = class extends EntryIterator {
|
|
545
|
+
static {
|
|
546
|
+
__name(this, "OwnedObjectIterator");
|
|
547
|
+
}
|
|
548
|
+
provider;
|
|
549
|
+
owner;
|
|
550
|
+
options;
|
|
477
551
|
constructor(provider, owner, options) {
|
|
478
552
|
super(new OwnedObjectRequester(provider, owner, options));
|
|
479
553
|
this.provider = provider;
|
|
@@ -482,6 +556,16 @@ var OwnedObjectIterator = class extends EntryIterator {
|
|
|
482
556
|
}
|
|
483
557
|
};
|
|
484
558
|
var OwnedObjectRequester = class {
|
|
559
|
+
static {
|
|
560
|
+
__name(this, "OwnedObjectRequester");
|
|
561
|
+
}
|
|
562
|
+
provider;
|
|
563
|
+
owner;
|
|
564
|
+
options;
|
|
565
|
+
nextCursor;
|
|
566
|
+
filter;
|
|
567
|
+
pageSize;
|
|
568
|
+
objectOptions;
|
|
485
569
|
constructor(provider, owner, options) {
|
|
486
570
|
this.provider = provider;
|
|
487
571
|
this.owner = owner;
|
|
@@ -494,10 +578,6 @@ var OwnedObjectRequester = class {
|
|
|
494
578
|
showContent: true
|
|
495
579
|
};
|
|
496
580
|
}
|
|
497
|
-
nextCursor;
|
|
498
|
-
filter;
|
|
499
|
-
pageSize;
|
|
500
|
-
objectOptions;
|
|
501
581
|
async doNextRequest() {
|
|
502
582
|
const res = await this.provider.getOwnedObjects({
|
|
503
583
|
owner: this.owner,
|
|
@@ -522,6 +602,14 @@ var OwnedObjectRequester = class {
|
|
|
522
602
|
|
|
523
603
|
// src/core/MSafeAccount.ts
|
|
524
604
|
var MSafeAccount = class _MSafeAccount {
|
|
605
|
+
static {
|
|
606
|
+
__name(this, "MSafeAccount");
|
|
607
|
+
}
|
|
608
|
+
globals;
|
|
609
|
+
info;
|
|
610
|
+
multiSig;
|
|
611
|
+
simulator;
|
|
612
|
+
coinHelper;
|
|
525
613
|
constructor(globals, info) {
|
|
526
614
|
this.globals = globals;
|
|
527
615
|
this.info = info;
|
|
@@ -533,9 +621,6 @@ var MSafeAccount = class _MSafeAccount {
|
|
|
533
621
|
this.coinHelper = new CoinHelper(this.suiClient);
|
|
534
622
|
this.simulator = new Simulator(globals);
|
|
535
623
|
}
|
|
536
|
-
multiSig;
|
|
537
|
-
simulator;
|
|
538
|
-
coinHelper;
|
|
539
624
|
static async New(globals, address) {
|
|
540
625
|
const info = await globals.backend.getMSafeAccountInfo(address);
|
|
541
626
|
const ms = new _MSafeAccount(globals, info);
|
|
@@ -544,18 +629,19 @@ var MSafeAccount = class _MSafeAccount {
|
|
|
544
629
|
}
|
|
545
630
|
}
|
|
546
631
|
async ownedCoins() {
|
|
547
|
-
const balances = await this.suiClient.getAllBalances({
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
632
|
+
const balances = await this.suiClient.getAllBalances({
|
|
633
|
+
owner: this.address
|
|
634
|
+
});
|
|
635
|
+
return Promise.all(balances.map(async (balance) => {
|
|
636
|
+
const meta = await this.coinHelper.getCoinMeta(balance.coinType);
|
|
637
|
+
const lockedEntry = balance.lockedBalance && typeof balance.lockedBalance === "object" && "number" in balance.lockedBalance && balance.lockedBalance.number ? BigInt(balance.lockedBalance.number) : 0n;
|
|
638
|
+
const unlockedBalance = lockedEntry ? BigInt(balance.totalBalance) - lockedEntry : BigInt(balance.totalBalance);
|
|
639
|
+
return {
|
|
640
|
+
type: normalizeStructTag3(balance.coinType),
|
|
641
|
+
balance: unlockedBalance,
|
|
642
|
+
metadata: meta
|
|
643
|
+
};
|
|
644
|
+
}));
|
|
559
645
|
}
|
|
560
646
|
async ownedObjects(options) {
|
|
561
647
|
const filterCoinObjectOptions = {
|
|
@@ -565,7 +651,9 @@ var MSafeAccount = class _MSafeAccount {
|
|
|
565
651
|
return getAllOwnedObjects(this.suiClient, this.address, filterCoinObjectOptions);
|
|
566
652
|
}
|
|
567
653
|
async pendingTransaction() {
|
|
568
|
-
const res = await this.backend.getPendingTransactions({
|
|
654
|
+
const res = await this.backend.getPendingTransactions({
|
|
655
|
+
msafeAddress: this.address
|
|
656
|
+
});
|
|
569
657
|
if (!res?.pending) {
|
|
570
658
|
return void 0;
|
|
571
659
|
}
|
|
@@ -597,7 +685,10 @@ var MSafeAccount = class _MSafeAccount {
|
|
|
597
685
|
});
|
|
598
686
|
}
|
|
599
687
|
async futureIntentions(pagination) {
|
|
600
|
-
return this.backend.getFutureIntentions({
|
|
688
|
+
return this.backend.getFutureIntentions({
|
|
689
|
+
msafeAddress: this.address,
|
|
690
|
+
...pagination
|
|
691
|
+
});
|
|
601
692
|
}
|
|
602
693
|
async currentSequenceNumber() {
|
|
603
694
|
return this.backend.getCurrentSequenceNumber(this.address);
|
|
@@ -614,7 +705,7 @@ var MSafeAccount = class _MSafeAccount {
|
|
|
614
705
|
if (!appHelper) {
|
|
615
706
|
throw new Error(`Can't find app helper for application ${request.application}`);
|
|
616
707
|
}
|
|
617
|
-
txb = await appHelper.build({
|
|
708
|
+
txb = toSuiTransaction(await appHelper.build({
|
|
618
709
|
network: this.globals.config.network,
|
|
619
710
|
intentionData: request.intention,
|
|
620
711
|
txType: request.txType,
|
|
@@ -622,14 +713,20 @@ var MSafeAccount = class _MSafeAccount {
|
|
|
622
713
|
clientUrl: this.globals.config.suiClient.url,
|
|
623
714
|
account: {
|
|
624
715
|
address: this.address,
|
|
625
|
-
publicKey:
|
|
626
|
-
chains: [
|
|
716
|
+
publicKey: fromHex(this.address),
|
|
717
|
+
chains: [
|
|
718
|
+
SUI_MAINNET_CHAIN,
|
|
719
|
+
SUI_TESTNET_CHAIN
|
|
720
|
+
],
|
|
627
721
|
features: []
|
|
628
722
|
}
|
|
629
|
-
});
|
|
723
|
+
}));
|
|
630
724
|
}
|
|
631
725
|
txb.setSender(this.address);
|
|
632
|
-
return this.simulator.simulate({
|
|
726
|
+
return this.simulator.simulate({
|
|
727
|
+
txb,
|
|
728
|
+
sender: this.address
|
|
729
|
+
});
|
|
633
730
|
}
|
|
634
731
|
async proposeIntention(input) {
|
|
635
732
|
const message = SigningMessageHelper3.proposeIntentionMessage({
|
|
@@ -655,7 +752,7 @@ var MSafeAccount = class _MSafeAccount {
|
|
|
655
752
|
if (!appHelper) {
|
|
656
753
|
throw new Error(`Can't find app helper for application ${input.application}`);
|
|
657
754
|
}
|
|
658
|
-
txb = await appHelper.build({
|
|
755
|
+
txb = toSuiTransaction(await appHelper.build({
|
|
659
756
|
network: this.globals.config.network,
|
|
660
757
|
intentionData: input.intention,
|
|
661
758
|
txType: input.txType,
|
|
@@ -663,21 +760,30 @@ var MSafeAccount = class _MSafeAccount {
|
|
|
663
760
|
clientUrl: this.globals.config.suiClient.url,
|
|
664
761
|
account: {
|
|
665
762
|
address: this.address,
|
|
666
|
-
publicKey:
|
|
667
|
-
chains: [
|
|
763
|
+
publicKey: fromHex(this.address),
|
|
764
|
+
chains: [
|
|
765
|
+
SUI_MAINNET_CHAIN,
|
|
766
|
+
SUI_TESTNET_CHAIN
|
|
767
|
+
],
|
|
668
768
|
features: []
|
|
669
769
|
}
|
|
670
|
-
});
|
|
770
|
+
}));
|
|
671
771
|
}
|
|
672
772
|
txb.setGasPrice(input.gasPrice);
|
|
673
773
|
txb.setGasBudget(input.gasBudget);
|
|
674
774
|
txb.setSender(this.address);
|
|
675
|
-
const payload = await txb.build({
|
|
676
|
-
|
|
677
|
-
|
|
775
|
+
const payload = await txb.build({
|
|
776
|
+
client: this.globals.suiClient
|
|
777
|
+
});
|
|
778
|
+
const digest = await txb.getDigest({
|
|
779
|
+
client: this.globals.suiClient
|
|
780
|
+
});
|
|
781
|
+
const signature = await this.wallet.signTransactionBlock({
|
|
782
|
+
transactionBlock: payload
|
|
783
|
+
});
|
|
678
784
|
return this.backend.proposeIntentionAndBuildVote({
|
|
679
785
|
...input,
|
|
680
|
-
payload:
|
|
786
|
+
payload: toHex(payload),
|
|
681
787
|
digest,
|
|
682
788
|
msafeAddress: this.address,
|
|
683
789
|
signature: signature.signature
|
|
@@ -735,8 +841,9 @@ var MSafeAccount = class _MSafeAccount {
|
|
|
735
841
|
}
|
|
736
842
|
async proposePlainPayloadIntention(intention) {
|
|
737
843
|
const sn = await this.nextSequenceNumber();
|
|
738
|
-
const tb =
|
|
739
|
-
|
|
844
|
+
const tb = Transaction3.from(intention.payload);
|
|
845
|
+
const data = tb.getData();
|
|
846
|
+
if (!data.sender || !isSameAddress2(data.sender, this.address)) {
|
|
740
847
|
throw new Error("Transaction sender is not same as the multisig address");
|
|
741
848
|
}
|
|
742
849
|
return this.proposeIntention({
|
|
@@ -749,7 +856,9 @@ var MSafeAccount = class _MSafeAccount {
|
|
|
749
856
|
}
|
|
750
857
|
async voteForTransaction(digest, payload) {
|
|
751
858
|
const payloadBytes = HexToUint8Array(payload);
|
|
752
|
-
const signature = await this.wallet.signTransactionBlock({
|
|
859
|
+
const signature = await this.wallet.signTransactionBlock({
|
|
860
|
+
transactionBlock: payloadBytes
|
|
861
|
+
});
|
|
753
862
|
return this.backend.voteForTransaction({
|
|
754
863
|
msafeAddress: this.address,
|
|
755
864
|
digest,
|
|
@@ -761,19 +870,28 @@ var MSafeAccount = class _MSafeAccount {
|
|
|
761
870
|
if (!pendingTx || pendingTx.rejectDigest !== "") {
|
|
762
871
|
throw new Error("Already rejected");
|
|
763
872
|
}
|
|
764
|
-
const txb = buildRejectTxb(this.address);
|
|
873
|
+
const txb = toSuiTransaction(buildRejectTxb(this.address));
|
|
765
874
|
txb.setSender(this.address);
|
|
766
|
-
return this.simulator.simulate({
|
|
875
|
+
return this.simulator.simulate({
|
|
876
|
+
txb,
|
|
877
|
+
sender: this.address
|
|
878
|
+
});
|
|
767
879
|
}
|
|
768
880
|
async rejectCurrentTx(input) {
|
|
769
881
|
const pendingTx = await this.pendingTransaction();
|
|
770
882
|
if (!pendingTx || pendingTx.rejectDigest !== "") {
|
|
771
883
|
throw new Error("Already rejected");
|
|
772
884
|
}
|
|
773
|
-
const rejectTxb = buildRejectTxb(this.address);
|
|
774
|
-
const digest = await rejectTxb.getDigest({
|
|
775
|
-
|
|
776
|
-
|
|
885
|
+
const rejectTxb = toSuiTransaction(buildRejectTxb(this.address));
|
|
886
|
+
const digest = await rejectTxb.getDigest({
|
|
887
|
+
client: this.suiClient
|
|
888
|
+
});
|
|
889
|
+
const payload = await rejectTxb.build({
|
|
890
|
+
client: this.suiClient
|
|
891
|
+
});
|
|
892
|
+
const signature = await this.wallet.signTransactionBlock({
|
|
893
|
+
transactionBlock: payload
|
|
894
|
+
});
|
|
777
895
|
return this.backend.rejectCurrentTx({
|
|
778
896
|
msafeAddress: this.address,
|
|
779
897
|
digest,
|
|
@@ -782,12 +900,14 @@ var MSafeAccount = class _MSafeAccount {
|
|
|
782
900
|
});
|
|
783
901
|
}
|
|
784
902
|
async simulateBuildTransaction() {
|
|
785
|
-
const intention = await this.backend.getNextIntention({
|
|
903
|
+
const intention = await this.backend.getNextIntention({
|
|
904
|
+
msafeAddress: this.address
|
|
905
|
+
});
|
|
786
906
|
const appHelper = appHelpers.getAppHelper(intention.application);
|
|
787
907
|
if (!appHelper) {
|
|
788
908
|
throw new Error(`Can't find app helper for application ${intention.application}`);
|
|
789
909
|
}
|
|
790
|
-
const txb = await appHelper.build({
|
|
910
|
+
const txb = toSuiTransaction(await appHelper.build({
|
|
791
911
|
network: this.globals.config.network,
|
|
792
912
|
intentionData: intention.intention,
|
|
793
913
|
txType: intention.txType,
|
|
@@ -795,13 +915,19 @@ var MSafeAccount = class _MSafeAccount {
|
|
|
795
915
|
clientUrl: this.globals.config.suiClient.url,
|
|
796
916
|
account: {
|
|
797
917
|
address: this.address,
|
|
798
|
-
publicKey:
|
|
799
|
-
chains: [
|
|
918
|
+
publicKey: fromHex(this.address),
|
|
919
|
+
chains: [
|
|
920
|
+
SUI_MAINNET_CHAIN,
|
|
921
|
+
SUI_TESTNET_CHAIN
|
|
922
|
+
],
|
|
800
923
|
features: []
|
|
801
924
|
}
|
|
802
|
-
});
|
|
925
|
+
}));
|
|
803
926
|
txb.setSender(this.address);
|
|
804
|
-
return this.simulator.simulate({
|
|
927
|
+
return this.simulator.simulate({
|
|
928
|
+
txb,
|
|
929
|
+
sender: this.address
|
|
930
|
+
});
|
|
805
931
|
}
|
|
806
932
|
async buildNextIntentionAndAddToPending(gasOption) {
|
|
807
933
|
return this.backend.buildNextIntentionAndAddToPending({
|
|
@@ -812,10 +938,14 @@ var MSafeAccount = class _MSafeAccount {
|
|
|
812
938
|
});
|
|
813
939
|
}
|
|
814
940
|
async skipNextFailedIntention() {
|
|
815
|
-
return this.backend.skipNextFailedIntention({
|
|
941
|
+
return this.backend.skipNextFailedIntention({
|
|
942
|
+
msafeAddress: this.address
|
|
943
|
+
});
|
|
816
944
|
}
|
|
817
945
|
async fetchTransaction() {
|
|
818
|
-
return this.backend.fetchTransaction({
|
|
946
|
+
return this.backend.fetchTransaction({
|
|
947
|
+
msafeAddress: this.address
|
|
948
|
+
});
|
|
819
949
|
}
|
|
820
950
|
async executePendingTx(pending, isRejectTx = false) {
|
|
821
951
|
const votes = isRejectTx ? pending.rejectVotes : pending.votes;
|
|
@@ -824,7 +954,10 @@ var MSafeAccount = class _MSafeAccount {
|
|
|
824
954
|
throw new Error("Not enough signature");
|
|
825
955
|
}
|
|
826
956
|
const sortedSigs = [];
|
|
827
|
-
const gotSigs = new Map(votes.map((vote) => [
|
|
957
|
+
const gotSigs = new Map(votes.map((vote) => [
|
|
958
|
+
vote.userAddress,
|
|
959
|
+
vote.signature
|
|
960
|
+
]));
|
|
828
961
|
for (let i = 0; i < this.info.owners.length; i++) {
|
|
829
962
|
const owner = this.info.owners[i];
|
|
830
963
|
const signature = gotSigs.get(owner.address);
|
|
@@ -836,7 +969,10 @@ var MSafeAccount = class _MSafeAccount {
|
|
|
836
969
|
return this.suiClient.executeTransactionBlock({
|
|
837
970
|
transactionBlock: HexToUint8Array(payload),
|
|
838
971
|
signature: multiSignature,
|
|
839
|
-
options: {
|
|
972
|
+
options: {
|
|
973
|
+
showEffects: true,
|
|
974
|
+
showEvents: true
|
|
975
|
+
}
|
|
840
976
|
});
|
|
841
977
|
}
|
|
842
978
|
async dashboard() {
|
|
@@ -876,13 +1012,17 @@ var MSafeAccount = class _MSafeAccount {
|
|
|
876
1012
|
|
|
877
1013
|
// src/core/PublicKeyHelper.ts
|
|
878
1014
|
import { isSameAddress as isSameAddress3 } from "@msafe/sui3-utils";
|
|
879
|
-
import { normalizeSuiAddress as normalizeSuiAddress2 } from "@mysten/sui
|
|
1015
|
+
import { normalizeSuiAddress as normalizeSuiAddress2 } from "@mysten/sui/utils";
|
|
880
1016
|
var PublicKeyHelper = class {
|
|
1017
|
+
static {
|
|
1018
|
+
__name(this, "PublicKeyHelper");
|
|
1019
|
+
}
|
|
1020
|
+
globals;
|
|
1021
|
+
knownPublicKeys;
|
|
881
1022
|
constructor(globals) {
|
|
882
1023
|
this.globals = globals;
|
|
883
1024
|
this.knownPublicKeys = /* @__PURE__ */ new Map();
|
|
884
1025
|
}
|
|
885
|
-
knownPublicKeys;
|
|
886
1026
|
async getPublicKey(address) {
|
|
887
1027
|
const cached = this.knownPublicKeys.get(address);
|
|
888
1028
|
if (cached) {
|
|
@@ -953,6 +1093,10 @@ var PublicKeyHelper = class {
|
|
|
953
1093
|
|
|
954
1094
|
// src/core/ReportSDK.ts
|
|
955
1095
|
var ReportSDK = class {
|
|
1096
|
+
static {
|
|
1097
|
+
__name(this, "ReportSDK");
|
|
1098
|
+
}
|
|
1099
|
+
globals;
|
|
956
1100
|
constructor(globals) {
|
|
957
1101
|
this.globals = globals;
|
|
958
1102
|
}
|
|
@@ -962,20 +1106,22 @@ var ReportSDK = class {
|
|
|
962
1106
|
};
|
|
963
1107
|
|
|
964
1108
|
// src/globals/MSafeGlobals.ts
|
|
965
|
-
import {
|
|
1109
|
+
import { SuiJsonRpcClient } from "@mysten/sui/jsonRpc";
|
|
966
1110
|
|
|
967
1111
|
// src/backend/BackendImpl.ts
|
|
968
|
-
import {
|
|
969
|
-
PublicKeySerde as PublicKeySerde3,
|
|
970
|
-
UserMSafeStatus
|
|
971
|
-
} from "@msafe/sui3-utils";
|
|
1112
|
+
import { PublicKeySerde as PublicKeySerde3, UserMSafeStatus } from "@msafe/sui3-utils";
|
|
972
1113
|
import axios from "axios";
|
|
973
1114
|
var BackendImpl = class _BackendImpl {
|
|
1115
|
+
static {
|
|
1116
|
+
__name(this, "BackendImpl");
|
|
1117
|
+
}
|
|
1118
|
+
apiURL;
|
|
1119
|
+
mockAddress;
|
|
1120
|
+
_token;
|
|
974
1121
|
constructor(apiURL, mockAddress) {
|
|
975
1122
|
this.apiURL = apiURL;
|
|
976
1123
|
this.mockAddress = mockAddress;
|
|
977
1124
|
}
|
|
978
|
-
_token;
|
|
979
1125
|
getNotificationInfo() {
|
|
980
1126
|
return this.get(`/notification`, {
|
|
981
1127
|
headers: this.headers()
|
|
@@ -998,7 +1144,9 @@ var BackendImpl = class _BackendImpl {
|
|
|
998
1144
|
}
|
|
999
1145
|
async verifyToken(jwt) {
|
|
1000
1146
|
try {
|
|
1001
|
-
const res = await this.get(`/auth`, {
|
|
1147
|
+
const res = await this.get(`/auth`, {
|
|
1148
|
+
headers: this.headers(jwt)
|
|
1149
|
+
});
|
|
1002
1150
|
return res.status === 200;
|
|
1003
1151
|
} catch (_) {
|
|
1004
1152
|
return false;
|
|
@@ -1008,7 +1156,9 @@ var BackendImpl = class _BackendImpl {
|
|
|
1008
1156
|
this._token = token;
|
|
1009
1157
|
}
|
|
1010
1158
|
async getPublicKey(address) {
|
|
1011
|
-
return (await this.getPublicKeyBatch([
|
|
1159
|
+
return (await this.getPublicKeyBatch([
|
|
1160
|
+
address
|
|
1161
|
+
]))[0];
|
|
1012
1162
|
}
|
|
1013
1163
|
async getPublicKeyBatch(addresses) {
|
|
1014
1164
|
const query = {
|
|
@@ -1018,9 +1168,7 @@ var BackendImpl = class _BackendImpl {
|
|
|
1018
1168
|
params: query,
|
|
1019
1169
|
headers: this.headers()
|
|
1020
1170
|
});
|
|
1021
|
-
return res.data?.map(
|
|
1022
|
-
(publicKeyWithSchema) => publicKeyWithSchema ? PublicKeySerde3.de(publicKeyWithSchema) : void 0
|
|
1023
|
-
);
|
|
1171
|
+
return res.data?.map((publicKeyWithSchema) => publicKeyWithSchema ? PublicKeySerde3.de(publicKeyWithSchema) : void 0);
|
|
1024
1172
|
}
|
|
1025
1173
|
async getMSafeAccountInfo(msafeAddress) {
|
|
1026
1174
|
const q = {
|
|
@@ -1057,7 +1205,9 @@ var BackendImpl = class _BackendImpl {
|
|
|
1057
1205
|
}
|
|
1058
1206
|
async updateMSafeStatus(input) {
|
|
1059
1207
|
const p = input;
|
|
1060
|
-
await this.post(`/msafe/status`, p, {
|
|
1208
|
+
await this.post(`/msafe/status`, p, {
|
|
1209
|
+
headers: this.headers()
|
|
1210
|
+
});
|
|
1061
1211
|
}
|
|
1062
1212
|
async getPendingTransactions(input) {
|
|
1063
1213
|
const res = await this.get(`/transaction/pending`, {
|
|
@@ -1111,16 +1261,18 @@ var BackendImpl = class _BackendImpl {
|
|
|
1111
1261
|
});
|
|
1112
1262
|
}
|
|
1113
1263
|
async proposeIntention(input) {
|
|
1114
|
-
await this.post(`/transaction/intention`, input, {
|
|
1264
|
+
await this.post(`/transaction/intention`, input, {
|
|
1265
|
+
headers: this.headers()
|
|
1266
|
+
});
|
|
1115
1267
|
}
|
|
1116
1268
|
async rejectCurrentTx(input) {
|
|
1117
|
-
await this.post(
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
);
|
|
1269
|
+
await this.post(`/transaction/pending/reject`, {
|
|
1270
|
+
...input,
|
|
1271
|
+
gasPrice: input.gasPrice.toString(),
|
|
1272
|
+
gasBudget: input.gasBudget.toString()
|
|
1273
|
+
}, {
|
|
1274
|
+
headers: this.headers()
|
|
1275
|
+
});
|
|
1124
1276
|
}
|
|
1125
1277
|
async voteForTransaction(input) {
|
|
1126
1278
|
await this.post(`/transaction/pending/vote`, input, {
|
|
@@ -1128,24 +1280,32 @@ var BackendImpl = class _BackendImpl {
|
|
|
1128
1280
|
});
|
|
1129
1281
|
}
|
|
1130
1282
|
async buildNextIntentionAndAddToPending(input) {
|
|
1131
|
-
await this.post(
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1283
|
+
await this.post(`/transaction/pending/build`, {
|
|
1284
|
+
...input,
|
|
1285
|
+
gasPrice: input.gasPrice.toString(),
|
|
1286
|
+
gasBudget: input.gasBudget.toString()
|
|
1287
|
+
}, {
|
|
1288
|
+
headers: this.headers()
|
|
1289
|
+
});
|
|
1136
1290
|
}
|
|
1137
1291
|
async proposeIntentionAndBuildVote(input) {
|
|
1138
|
-
await this.post(
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1292
|
+
await this.post(`/transaction/intention/build`, {
|
|
1293
|
+
...input,
|
|
1294
|
+
gasPrice: input.gasPrice.toString(),
|
|
1295
|
+
gasBudget: input.gasBudget.toString()
|
|
1296
|
+
}, {
|
|
1297
|
+
headers: this.headers()
|
|
1298
|
+
});
|
|
1143
1299
|
}
|
|
1144
1300
|
async skipNextFailedIntention(input) {
|
|
1145
|
-
await this.post(`/transaction/pending/skip`, input, {
|
|
1301
|
+
await this.post(`/transaction/pending/skip`, input, {
|
|
1302
|
+
headers: this.headers()
|
|
1303
|
+
});
|
|
1146
1304
|
}
|
|
1147
1305
|
async fetchTransaction(input) {
|
|
1148
|
-
const res = await this.post(`/transaction/fetch`, input, {
|
|
1306
|
+
const res = await this.post(`/transaction/fetch`, input, {
|
|
1307
|
+
headers: this.headers()
|
|
1308
|
+
});
|
|
1149
1309
|
return res.data;
|
|
1150
1310
|
}
|
|
1151
1311
|
async getAddressBookEntries(pagination) {
|
|
@@ -1156,14 +1316,22 @@ var BackendImpl = class _BackendImpl {
|
|
|
1156
1316
|
return res.data;
|
|
1157
1317
|
}
|
|
1158
1318
|
async updateAddressBook(input) {
|
|
1159
|
-
await this.post(`/address-book`, input, {
|
|
1319
|
+
await this.post(`/address-book`, input, {
|
|
1320
|
+
headers: this.headers()
|
|
1321
|
+
});
|
|
1160
1322
|
}
|
|
1161
1323
|
async getAddressBookMode() {
|
|
1162
|
-
const res = await this.get("/address-book/mode", {
|
|
1324
|
+
const res = await this.get("/address-book/mode", {
|
|
1325
|
+
headers: this.headers()
|
|
1326
|
+
});
|
|
1163
1327
|
return res.data;
|
|
1164
1328
|
}
|
|
1165
1329
|
async setAddressBookMode(input) {
|
|
1166
|
-
await this.post("/address-book/mode", {
|
|
1330
|
+
await this.post("/address-book/mode", {
|
|
1331
|
+
mode: input.mode
|
|
1332
|
+
}, {
|
|
1333
|
+
headers: this.headers()
|
|
1334
|
+
});
|
|
1167
1335
|
}
|
|
1168
1336
|
async submitReport(report) {
|
|
1169
1337
|
await this.post("/report", report);
|
|
@@ -1176,7 +1344,10 @@ var BackendImpl = class _BackendImpl {
|
|
|
1176
1344
|
return res.data;
|
|
1177
1345
|
}
|
|
1178
1346
|
headers(token) {
|
|
1179
|
-
return {
|
|
1347
|
+
return {
|
|
1348
|
+
Authorization: `Bearer ${token || this._token}`,
|
|
1349
|
+
"sui-mock-user": this.mockAddress
|
|
1350
|
+
};
|
|
1180
1351
|
}
|
|
1181
1352
|
static toMSafeConfig(resp) {
|
|
1182
1353
|
return {
|
|
@@ -1232,7 +1403,9 @@ var BackendImpl = class _BackendImpl {
|
|
|
1232
1403
|
} else if (transformRequest instanceof Array) {
|
|
1233
1404
|
transformRequests = transformRequest;
|
|
1234
1405
|
} else {
|
|
1235
|
-
transformRequests = [
|
|
1406
|
+
transformRequests = [
|
|
1407
|
+
transformRequest
|
|
1408
|
+
];
|
|
1236
1409
|
}
|
|
1237
1410
|
return [
|
|
1238
1411
|
(d) => JSON.parse(JSON.stringify(d, (_, value) => typeof value === "bigint" ? `${value.toString()}n` : value)),
|
|
@@ -1241,6 +1414,10 @@ var BackendImpl = class _BackendImpl {
|
|
|
1241
1414
|
}
|
|
1242
1415
|
};
|
|
1243
1416
|
var BackendError = class _BackendError extends Error {
|
|
1417
|
+
static {
|
|
1418
|
+
__name(this, "BackendError");
|
|
1419
|
+
}
|
|
1420
|
+
e;
|
|
1244
1421
|
constructor(e) {
|
|
1245
1422
|
super();
|
|
1246
1423
|
this.e = e;
|
|
@@ -1274,14 +1451,18 @@ var BackendError = class _BackendError extends Error {
|
|
|
1274
1451
|
};
|
|
1275
1452
|
|
|
1276
1453
|
// src/globals/const.ts
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1454
|
+
function msafeChainToSuiNetwork(chain) {
|
|
1455
|
+
return chain === "sui:mainnet" ? "mainnet" : "testnet";
|
|
1456
|
+
}
|
|
1457
|
+
__name(msafeChainToSuiNetwork, "msafeChainToSuiNetwork");
|
|
1458
|
+
var MSafeEnv;
|
|
1459
|
+
(function(MSafeEnv2) {
|
|
1460
|
+
MSafeEnv2["local"] = "local";
|
|
1461
|
+
MSafeEnv2["unit"] = "unit";
|
|
1462
|
+
MSafeEnv2["dev"] = "dev";
|
|
1463
|
+
MSafeEnv2["prev"] = "prev";
|
|
1464
|
+
MSafeEnv2["prod"] = "prod";
|
|
1465
|
+
})(MSafeEnv || (MSafeEnv = {}));
|
|
1285
1466
|
var TESTNET_RPC_URL = "https://fullnode.testnet.sui.io";
|
|
1286
1467
|
var MAINNET_RPC_URL = "https://fullnode.mainnet.sui.io";
|
|
1287
1468
|
var LOCAL_API_URL = "http://127.0.0.1:3000";
|
|
@@ -1292,7 +1473,7 @@ var PREV_API_URL = "https://sui-preview.m-safe.link";
|
|
|
1292
1473
|
var PROD_API_URL = "https://sui.m-safe.link";
|
|
1293
1474
|
var ENV_CONFIGS = /* @__PURE__ */ new Map([
|
|
1294
1475
|
[
|
|
1295
|
-
"unit"
|
|
1476
|
+
"unit",
|
|
1296
1477
|
{
|
|
1297
1478
|
suiClient: {
|
|
1298
1479
|
url: TESTNET_RPC_URL
|
|
@@ -1305,7 +1486,7 @@ var ENV_CONFIGS = /* @__PURE__ */ new Map([
|
|
|
1305
1486
|
}
|
|
1306
1487
|
],
|
|
1307
1488
|
[
|
|
1308
|
-
"local"
|
|
1489
|
+
"local",
|
|
1309
1490
|
{
|
|
1310
1491
|
suiClient: {
|
|
1311
1492
|
url: TESTNET_RPC_URL
|
|
@@ -1318,7 +1499,7 @@ var ENV_CONFIGS = /* @__PURE__ */ new Map([
|
|
|
1318
1499
|
}
|
|
1319
1500
|
],
|
|
1320
1501
|
[
|
|
1321
|
-
"dev"
|
|
1502
|
+
"dev",
|
|
1322
1503
|
{
|
|
1323
1504
|
suiClient: {
|
|
1324
1505
|
url: TESTNET_RPC_URL
|
|
@@ -1331,7 +1512,7 @@ var ENV_CONFIGS = /* @__PURE__ */ new Map([
|
|
|
1331
1512
|
}
|
|
1332
1513
|
],
|
|
1333
1514
|
[
|
|
1334
|
-
"prev"
|
|
1515
|
+
"prev",
|
|
1335
1516
|
{
|
|
1336
1517
|
suiClient: {
|
|
1337
1518
|
url: MAINNET_RPC_URL
|
|
@@ -1344,7 +1525,7 @@ var ENV_CONFIGS = /* @__PURE__ */ new Map([
|
|
|
1344
1525
|
}
|
|
1345
1526
|
],
|
|
1346
1527
|
[
|
|
1347
|
-
"prod"
|
|
1528
|
+
"prod",
|
|
1348
1529
|
{
|
|
1349
1530
|
suiClient: {
|
|
1350
1531
|
url: MAINNET_RPC_URL
|
|
@@ -1373,9 +1554,13 @@ function getMSafeConfig(env, options) {
|
|
|
1373
1554
|
}
|
|
1374
1555
|
return config;
|
|
1375
1556
|
}
|
|
1557
|
+
__name(getMSafeConfig, "getMSafeConfig");
|
|
1376
1558
|
|
|
1377
1559
|
// src/globals/MSafeGlobals.ts
|
|
1378
1560
|
var MSafeGlobals = class _MSafeGlobals {
|
|
1561
|
+
static {
|
|
1562
|
+
__name(this, "MSafeGlobals");
|
|
1563
|
+
}
|
|
1379
1564
|
backend;
|
|
1380
1565
|
suiClient;
|
|
1381
1566
|
config;
|
|
@@ -1387,9 +1572,14 @@ var MSafeGlobals = class _MSafeGlobals {
|
|
|
1387
1572
|
}
|
|
1388
1573
|
static async New(env, options) {
|
|
1389
1574
|
const config = getMSafeConfig(env, options);
|
|
1390
|
-
const suiClient = new
|
|
1391
|
-
config.suiClient.transport ? {
|
|
1392
|
-
|
|
1575
|
+
const suiClient = new SuiJsonRpcClient({
|
|
1576
|
+
...config.suiClient.transport ? {
|
|
1577
|
+
transport: config.suiClient.transport
|
|
1578
|
+
} : {
|
|
1579
|
+
url: config.suiClient.url
|
|
1580
|
+
},
|
|
1581
|
+
network: msafeChainToSuiNetwork(config.network)
|
|
1582
|
+
});
|
|
1393
1583
|
const backend = new BackendImpl(config.backend.url, options?.mockAddress);
|
|
1394
1584
|
return new _MSafeGlobals({
|
|
1395
1585
|
backend,
|
|
@@ -1413,11 +1603,15 @@ var MSafeGlobals = class _MSafeGlobals {
|
|
|
1413
1603
|
|
|
1414
1604
|
// src/core/MSafeClient.ts
|
|
1415
1605
|
var MSafeClient = class _MSafeClient {
|
|
1416
|
-
|
|
1417
|
-
this
|
|
1606
|
+
static {
|
|
1607
|
+
__name(this, "MSafeClient");
|
|
1418
1608
|
}
|
|
1609
|
+
globals;
|
|
1419
1610
|
_creationHelper;
|
|
1420
1611
|
_publicKeyHelper;
|
|
1612
|
+
constructor(globals) {
|
|
1613
|
+
this.globals = globals;
|
|
1614
|
+
}
|
|
1421
1615
|
static async New(env, options) {
|
|
1422
1616
|
const globals = await MSafeGlobals.New(env, options);
|
|
1423
1617
|
return new _MSafeClient(globals);
|
|
@@ -1452,7 +1646,10 @@ var MSafeClient = class _MSafeClient {
|
|
|
1452
1646
|
return this.globals.backend.getUserInfo();
|
|
1453
1647
|
}
|
|
1454
1648
|
async ownedMSafe(pagination) {
|
|
1455
|
-
return this.globals.backend.getOwnedMSafeByStatus({
|
|
1649
|
+
return this.globals.backend.getOwnedMSafeByStatus({
|
|
1650
|
+
status: UserMSafeStatus2.active,
|
|
1651
|
+
pagination
|
|
1652
|
+
});
|
|
1456
1653
|
}
|
|
1457
1654
|
async createAccount(info) {
|
|
1458
1655
|
return this.creationHelper.submitMSafeCreation(info);
|
|
@@ -1502,26 +1699,38 @@ var MSafeClient = class _MSafeClient {
|
|
|
1502
1699
|
};
|
|
1503
1700
|
|
|
1504
1701
|
// src/backend/types/notification.ts
|
|
1505
|
-
var InfoTypeKey
|
|
1702
|
+
var InfoTypeKey;
|
|
1703
|
+
(function(InfoTypeKey2) {
|
|
1506
1704
|
InfoTypeKey2["receive"] = "info_type_receive";
|
|
1507
1705
|
InfoTypeKey2["send"] = "info_type_send";
|
|
1508
1706
|
InfoTypeKey2["invitation"] = "info_type_invitation";
|
|
1509
1707
|
InfoTypeKey2["awaitApproval"] = "info_type_await_approval";
|
|
1510
|
-
|
|
1511
|
-
})(InfoTypeKey || {});
|
|
1708
|
+
})(InfoTypeKey || (InfoTypeKey = {}));
|
|
1512
1709
|
var NotificationSubscribeDto = class {
|
|
1710
|
+
static {
|
|
1711
|
+
__name(this, "NotificationSubscribeDto");
|
|
1712
|
+
}
|
|
1513
1713
|
email;
|
|
1514
1714
|
};
|
|
1515
1715
|
var NotificationUpdateDto = class {
|
|
1716
|
+
static {
|
|
1717
|
+
__name(this, "NotificationUpdateDto");
|
|
1718
|
+
}
|
|
1516
1719
|
email;
|
|
1517
1720
|
infoTypes;
|
|
1518
1721
|
msafeEnabled;
|
|
1519
1722
|
};
|
|
1520
1723
|
var InfoTypeEnabledDto = class {
|
|
1724
|
+
static {
|
|
1725
|
+
__name(this, "InfoTypeEnabledDto");
|
|
1726
|
+
}
|
|
1521
1727
|
infoType;
|
|
1522
1728
|
enabled;
|
|
1523
1729
|
};
|
|
1524
1730
|
var MSafeEnabledDto = class {
|
|
1731
|
+
static {
|
|
1732
|
+
__name(this, "MSafeEnabledDto");
|
|
1733
|
+
}
|
|
1525
1734
|
msafeAddress;
|
|
1526
1735
|
enabled;
|
|
1527
1736
|
};
|
|
@@ -1558,6 +1767,8 @@ export {
|
|
|
1558
1767
|
getAllCoins,
|
|
1559
1768
|
getMSafeConfig,
|
|
1560
1769
|
getPublicKeyFromChain,
|
|
1561
|
-
|
|
1770
|
+
msafeChainToSuiNetwork,
|
|
1771
|
+
stringToBuffer,
|
|
1772
|
+
toSuiTransaction
|
|
1562
1773
|
};
|
|
1563
1774
|
//# sourceMappingURL=index.js.map
|