@msafe/sui3-sdk 0.0.13 → 0.0.15-pre-3144325.0
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 +267 -373
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +76 -145
- package/dist/index.d.ts +76 -145
- package/dist/index.js +271 -366
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/backend/BackendImpl.ts +123 -110
- package/src/backend/interface.ts +24 -14
- package/src/core/AddressBookSDK.ts +4 -5
- package/src/core/CreateHelper.ts +18 -32
- package/src/core/InvitationSDK.ts +15 -0
- package/src/core/MSafeAccount.ts +25 -17
- package/src/core/MSafeClient.ts +22 -8
- package/src/core/PublicKeyHelper.ts +3 -0
- package/src/core/index.ts +0 -1
- package/src/globals/MSafeGlobals.ts +1 -1
- package/src/globals/const.ts +17 -45
- package/src/types/create.ts +11 -0
- package/src/types/index.ts +1 -4
- package/src/types/msafe.ts +2 -2
- package/src/utils/crypto.ts +1 -32
- package/src/utils/sui.ts +2 -2
- package/src/backend/CoreDatabase.ts +0 -55
- package/src/backend/PseudoBackend.ts +0 -936
- package/src/core/MessageHelper.ts +0 -95
- package/src/types/address-book.ts +0 -32
- package/src/types/backend.ts +0 -19
- package/src/types/creation.ts +0 -19
- package/src/types/pagination.ts +0 -15
package/dist/index.cjs
CHANGED
|
@@ -30,21 +30,18 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var src_exports = {};
|
|
32
32
|
__export(src_exports, {
|
|
33
|
-
AUTH_SIGN_MESSAGE: () => AUTH_SIGN_MESSAGE,
|
|
34
33
|
AddressBookSDK: () => AddressBookSDK,
|
|
35
34
|
COIN_TYPE_ARG_REGEX: () => COIN_TYPE_ARG_REGEX,
|
|
36
35
|
Coin: () => Coin,
|
|
37
36
|
CoinHelper: () => CoinHelper,
|
|
38
37
|
CreateHelper: () => CreateHelper,
|
|
39
38
|
DEV_API_URL: () => DEV_API_URL,
|
|
40
|
-
DEV_DATABASE_CONFIG: () => DEV_DATABASE_CONFIG,
|
|
41
39
|
DEV_SYNCING_URL: () => DEV_SYNCING_URL,
|
|
42
40
|
ENV_CONFIGS: () => ENV_CONFIGS,
|
|
43
41
|
Formatter: () => Formatter,
|
|
44
42
|
HexToUint8Array: () => HexToUint8Array,
|
|
45
43
|
IntentionHelper: () => IntentionHelper,
|
|
46
44
|
LOCAL_API_URL: () => LOCAL_API_URL,
|
|
47
|
-
LOCAL_DATABASE_CONFIG: () => LOCAL_DATABASE_CONFIG,
|
|
48
45
|
LOCAL_SYNCING_URL: () => LOCAL_SYNCING_URL,
|
|
49
46
|
MAINNET_RPC_URL: () => MAINNET_RPC_URL,
|
|
50
47
|
MSAFE_APPLICATION: () => MSAFE_APPLICATION,
|
|
@@ -52,13 +49,9 @@ __export(src_exports, {
|
|
|
52
49
|
MSafeClient: () => MSafeClient,
|
|
53
50
|
MSafeEnv: () => MSafeEnv,
|
|
54
51
|
MSafeGlobals: () => MSafeGlobals,
|
|
55
|
-
MessageHelper: () => MessageHelper,
|
|
56
|
-
OpAddressBookType: () => OpAddressBookType,
|
|
57
|
-
PublicKeySerde: () => PublicKeySerde,
|
|
58
52
|
SUI_COIN: () => SUI_COIN,
|
|
59
53
|
SignatureVerifier: () => SignatureVerifier,
|
|
60
54
|
TESTNET_RPC_URL: () => TESTNET_RPC_URL,
|
|
61
|
-
UNIT_DATABASE_CONFIG: () => UNIT_DATABASE_CONFIG,
|
|
62
55
|
Uint8ArrayToHex: () => Uint8ArrayToHex,
|
|
63
56
|
getAllCoins: () => getAllCoins,
|
|
64
57
|
getMSafeConfig: () => getMSafeConfig,
|
|
@@ -69,24 +62,103 @@ module.exports = __toCommonJS(src_exports);
|
|
|
69
62
|
|
|
70
63
|
// src/core/CreateHelper.ts
|
|
71
64
|
var import_sui3_utils = require("@msafe/sui3-utils");
|
|
65
|
+
var CreateHelper = class {
|
|
66
|
+
constructor(globals, pkHelper) {
|
|
67
|
+
this.globals = globals;
|
|
68
|
+
this.pkHelper = pkHelper;
|
|
69
|
+
}
|
|
70
|
+
async getPublicKeyBatch(addresses) {
|
|
71
|
+
return this.pkHelper.getPublicKeyBatch(addresses);
|
|
72
|
+
}
|
|
73
|
+
async calculateMSafeAddress(info) {
|
|
74
|
+
const msConfig = await this.reduceCreationInfoToRawConfig(info);
|
|
75
|
+
const ms = new import_sui3_utils.MultiSigAccount(msConfig);
|
|
76
|
+
return ms.address;
|
|
77
|
+
}
|
|
78
|
+
// Validate the create info and return the msafe address.
|
|
79
|
+
async validateCreateInfo(createInfo) {
|
|
80
|
+
return this.calculateMSafeAddress(createInfo);
|
|
81
|
+
}
|
|
82
|
+
async submitMSafeCreation(creationInfo) {
|
|
83
|
+
const msafeAddress = await this.validateCreateInfo(creationInfo);
|
|
84
|
+
const signingMessage = import_sui3_utils.SigningMessageHelper.createMSafeMessage(msafeAddress);
|
|
85
|
+
const signature = await this.globals.wallet.signPersonalMessage({ messageStr: signingMessage });
|
|
86
|
+
await this.submitToBackend(creationInfo, signature.signature);
|
|
87
|
+
return msafeAddress;
|
|
88
|
+
}
|
|
89
|
+
async reduceCreationInfoToRawConfig(info) {
|
|
90
|
+
const publicKeys = await this.getPublicKeyBatch(info.owners.map((owner) => owner.address));
|
|
91
|
+
publicKeys.forEach((pk, i) => {
|
|
92
|
+
if (pk === void 0) {
|
|
93
|
+
throw new Error(`Unknown public key for address: ${info.owners[i].address}`);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
return {
|
|
97
|
+
threshold: info.threshold,
|
|
98
|
+
ownersWithWeight: info.owners.map((owner, i) => ({
|
|
99
|
+
publicKey: publicKeys[i],
|
|
100
|
+
weight: owner.weight
|
|
101
|
+
})),
|
|
102
|
+
creationNonce: info.creationNonce
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
async submitToBackend(createInfo, signature) {
|
|
106
|
+
const pks = await this.pkHelper.getPublicKeyBatch(createInfo.owners.map((owner) => owner.address));
|
|
107
|
+
await this.globals.backend.createMSafeAccount({
|
|
108
|
+
owners: createInfo.owners.map((owner, i) => ({
|
|
109
|
+
address: owner.address,
|
|
110
|
+
weight: owner.weight,
|
|
111
|
+
...import_sui3_utils.PublicKeySerde.ser(pks[i])
|
|
112
|
+
})),
|
|
113
|
+
threshold: createInfo.threshold,
|
|
114
|
+
name: createInfo.name,
|
|
115
|
+
// name validation is deferred to backend
|
|
116
|
+
description: createInfo.description,
|
|
117
|
+
// description validation is deferred to backend
|
|
118
|
+
creationNonce: createInfo.creationNonce,
|
|
119
|
+
signature
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
};
|
|
72
123
|
|
|
73
|
-
// src/
|
|
74
|
-
var
|
|
75
|
-
var import_ed25519 = require("@mysten/sui.js/keypairs/ed25519");
|
|
76
|
-
var import_secp256k1 = require("@mysten/sui.js/keypairs/secp256k1");
|
|
77
|
-
var import_secp256r1 = require("@mysten/sui.js/keypairs/secp256r1");
|
|
78
|
-
var import_verify = require("@mysten/sui.js/verify");
|
|
124
|
+
// src/core/MSafeClient.ts
|
|
125
|
+
var import_sui3_utils6 = require("@msafe/sui3-utils");
|
|
79
126
|
|
|
80
|
-
// src/
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
127
|
+
// src/core/AddressBookSDK.ts
|
|
128
|
+
var import_sui3_utils2 = require("@msafe/sui3-utils");
|
|
129
|
+
var AddressBookSDK = class {
|
|
130
|
+
constructor(globals) {
|
|
131
|
+
this.globals = globals;
|
|
132
|
+
}
|
|
133
|
+
async getEntries(pagination) {
|
|
134
|
+
return this.globals.backend.getAddressBookEntries(pagination);
|
|
135
|
+
}
|
|
136
|
+
async update(updates) {
|
|
137
|
+
const messageStr = import_sui3_utils2.SigningMessageHelper.updateAddressBookMessage(updates);
|
|
138
|
+
const sig = await this.globals.wallet.signPersonalMessage({ messageStr });
|
|
139
|
+
return this.globals.backend.updateAddressBook({ updates, signature: sig.signature });
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
// src/core/InvitationSDK.ts
|
|
144
|
+
var InvitationSDK = class {
|
|
145
|
+
constructor(globals) {
|
|
146
|
+
this.globals = globals;
|
|
147
|
+
}
|
|
148
|
+
async getMSafeByStatus(status, pagination) {
|
|
149
|
+
return this.globals.backend.getOwnedMSafeByStatus({ status, pagination });
|
|
150
|
+
}
|
|
151
|
+
async updateMSafeStatus(msafeAddress, status) {
|
|
152
|
+
return this.globals.backend.updateMSafeStatus({ msafeAddress, status });
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
// src/core/MSafeAccount.ts
|
|
157
|
+
var import_sui3_utils4 = require("@msafe/sui3-utils");
|
|
158
|
+
var import_utils3 = require("@mysten/sui.js/utils");
|
|
159
|
+
|
|
160
|
+
// src/transactions/coin-transfer.ts
|
|
161
|
+
var import_transactions = require("@mysten/sui.js/transactions");
|
|
90
162
|
|
|
91
163
|
// src/utils/format.ts
|
|
92
164
|
var import_utils2 = require("@mysten/sui.js/utils");
|
|
@@ -162,140 +234,9 @@ var Formatter = class {
|
|
|
162
234
|
}
|
|
163
235
|
};
|
|
164
236
|
|
|
165
|
-
// src/utils/crypto.ts
|
|
166
|
-
var SignatureVerifier = class _SignatureVerifier {
|
|
167
|
-
static async getPublicKeyFromSignature(input) {
|
|
168
|
-
if (input.messageType === "TransactionBlock") {
|
|
169
|
-
return (0, import_verify.verifyTransactionBlock)(input.message, input.signature);
|
|
170
|
-
}
|
|
171
|
-
return (0, import_verify.verifyPersonalMessage)(input.message, input.signature);
|
|
172
|
-
}
|
|
173
|
-
static async getPublicKeyFromPersonalSignature(input) {
|
|
174
|
-
const message = stringToBuffer(input.messageStr);
|
|
175
|
-
return this.getPublicKeyFromSignature({
|
|
176
|
-
message,
|
|
177
|
-
messageType: "Personal",
|
|
178
|
-
signature: input.signature
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
static async verifySignature(input) {
|
|
182
|
-
const publicKey = await _SignatureVerifier.getPublicKeyFromSignature(input);
|
|
183
|
-
return Formatter.isSuiAddressEqual(publicKey.toSuiAddress(), input.targetAddress);
|
|
184
|
-
}
|
|
185
|
-
static async verifyPersonalSignature(input) {
|
|
186
|
-
const message = stringToBuffer(input.messageStr);
|
|
187
|
-
return this.verifySignature({
|
|
188
|
-
message,
|
|
189
|
-
messageType: "Personal",
|
|
190
|
-
signature: input.signature,
|
|
191
|
-
targetAddress: input.targetAddress
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
static async verifyTransactionSignature(input) {
|
|
195
|
-
return this.verifySignature({
|
|
196
|
-
messageType: "TransactionBlock",
|
|
197
|
-
message: input.payload,
|
|
198
|
-
signature: input.signature,
|
|
199
|
-
targetAddress: input.targetAddress
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
};
|
|
203
|
-
var PublicKeySerde = class {
|
|
204
|
-
static ser(publicKey) {
|
|
205
|
-
return {
|
|
206
|
-
publicKey: publicKey.toBase64(),
|
|
207
|
-
scheme: import_cryptography.SIGNATURE_FLAG_TO_SCHEME[publicKey.flag()]
|
|
208
|
-
};
|
|
209
|
-
}
|
|
210
|
-
static de(input) {
|
|
211
|
-
switch (input.scheme) {
|
|
212
|
-
case "ED25519":
|
|
213
|
-
return new import_ed25519.Ed25519PublicKey(input.publicKey);
|
|
214
|
-
case "Secp256k1":
|
|
215
|
-
return new import_secp256k1.Secp256k1PublicKey(input.publicKey);
|
|
216
|
-
case "Secp256r1":
|
|
217
|
-
return new import_secp256r1.Secp256r1PublicKey(input.publicKey);
|
|
218
|
-
default:
|
|
219
|
-
throw new Error("Unsupported signature scheme: $input.scheme");
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
};
|
|
223
|
-
|
|
224
|
-
// src/core/CreateHelper.ts
|
|
225
|
-
var CreateHelper = class {
|
|
226
|
-
constructor(globals, pkHelper) {
|
|
227
|
-
this.globals = globals;
|
|
228
|
-
this.pkHelper = pkHelper;
|
|
229
|
-
}
|
|
230
|
-
async getPublicKeyBatch(addresses) {
|
|
231
|
-
return this.pkHelper.getPublicKeyBatch(addresses);
|
|
232
|
-
}
|
|
233
|
-
async calculateMSafeAddress(info) {
|
|
234
|
-
const msConfig = await this.reduceCreationInfoToRawConfig(info);
|
|
235
|
-
const ms = new import_sui3_utils.MultisigAccountManager(msConfig);
|
|
236
|
-
return ms.address;
|
|
237
|
-
}
|
|
238
|
-
// Validate the create info and return the msafe address.
|
|
239
|
-
async validateCreateInfo(createInfo) {
|
|
240
|
-
const rawConfig = await this.reduceCreationInfoToRawConfig(createInfo);
|
|
241
|
-
(0, import_sui3_utils.validateCreateAccountRequest)(rawConfig);
|
|
242
|
-
return this.calculateMSafeAddress(createInfo);
|
|
243
|
-
}
|
|
244
|
-
async submitMSafeCreation(creationInfo) {
|
|
245
|
-
const msafeAddress = await this.validateCreateInfo(creationInfo);
|
|
246
|
-
const signingMessage = (0, import_sui3_utils.createAccountCreationMessage)(msafeAddress);
|
|
247
|
-
const signature = await this.globals.wallet.signPersonalMessage({ messageStr: signingMessage });
|
|
248
|
-
await this.submitToBackend(creationInfo, signature.signature);
|
|
249
|
-
return msafeAddress;
|
|
250
|
-
}
|
|
251
|
-
async reduceCreationInfoToRawConfig(info) {
|
|
252
|
-
const publicKeys = await this.getPublicKeyBatch(info.ownerWithWeight.map((oww) => oww.address));
|
|
253
|
-
publicKeys.forEach((pk, i) => {
|
|
254
|
-
if (pk === void 0) {
|
|
255
|
-
throw new Error(`Unknown public key for address: ${info.ownerWithWeight[i].address}`);
|
|
256
|
-
}
|
|
257
|
-
});
|
|
258
|
-
return {
|
|
259
|
-
threshold: info.threshold,
|
|
260
|
-
ownersWithWeight: info.ownerWithWeight.map((owner, i) => ({
|
|
261
|
-
publicKey: publicKeys[i],
|
|
262
|
-
weight: owner.weight
|
|
263
|
-
})),
|
|
264
|
-
creationNonce: info.creationNonce
|
|
265
|
-
};
|
|
266
|
-
}
|
|
267
|
-
async submitToBackend(createInfo, signature) {
|
|
268
|
-
const pks = await this.pkHelper.getPublicKeyBatch(createInfo.ownerWithWeight.map((owner) => owner.address));
|
|
269
|
-
await this.globals.backend.createMSafeAccount({
|
|
270
|
-
ownersWithWeightPKEncoded: createInfo.ownerWithWeight.map((owner, i) => {
|
|
271
|
-
const publicKeySer = PublicKeySerde.ser(pks[i]);
|
|
272
|
-
return {
|
|
273
|
-
address: owner.address,
|
|
274
|
-
weight: owner.weight,
|
|
275
|
-
publicKeyEncoded: publicKeySer.publicKey,
|
|
276
|
-
schema: publicKeySer.scheme
|
|
277
|
-
};
|
|
278
|
-
}),
|
|
279
|
-
threshold: createInfo.threshold,
|
|
280
|
-
name: createInfo.name,
|
|
281
|
-
// name validation is deferred to backend
|
|
282
|
-
description: createInfo.description,
|
|
283
|
-
// description validation is deferred to backend
|
|
284
|
-
creationNonce: createInfo.creationNonce,
|
|
285
|
-
signature
|
|
286
|
-
});
|
|
287
|
-
}
|
|
288
|
-
};
|
|
289
|
-
|
|
290
|
-
// src/core/MessageHelper.ts
|
|
291
|
-
var import_utils3 = require("@mysten/sui.js/utils");
|
|
292
|
-
var import_crypto_js = require("crypto-js");
|
|
293
|
-
|
|
294
|
-
// src/transactions/coin-transfer.ts
|
|
295
|
-
var import_transactions = require("@mysten/sui.js/transactions");
|
|
296
|
-
|
|
297
237
|
// src/utils/sui.ts
|
|
298
|
-
var
|
|
238
|
+
var import_sui3_utils3 = require("@msafe/sui3-utils");
|
|
239
|
+
var import_cryptography = require("@mysten/sui.js/cryptography");
|
|
299
240
|
var import_multisig = require("@mysten/sui.js/multisig");
|
|
300
241
|
var SUI_COIN = "0x2::sui::SUI";
|
|
301
242
|
async function getPublicKeyFromChain(suiClient, address) {
|
|
@@ -326,7 +267,7 @@ async function getPublicKeyFromChain(suiClient, address) {
|
|
|
326
267
|
return void 0;
|
|
327
268
|
}
|
|
328
269
|
function getAddressFromSignatures(serializedSig, targetAddress) {
|
|
329
|
-
const decoded = (0,
|
|
270
|
+
const decoded = (0, import_cryptography.parseSerializedSignature)(serializedSig);
|
|
330
271
|
switch (decoded.signatureScheme) {
|
|
331
272
|
case "MultiSig": {
|
|
332
273
|
const multiSigAddress = new import_multisig.MultiSigPublicKey(decoded.multisig.multisig_pk).toSuiAddress();
|
|
@@ -344,7 +285,7 @@ function getAddressFromSignatures(serializedSig, targetAddress) {
|
|
|
344
285
|
case "ED25519":
|
|
345
286
|
case "Secp256k1":
|
|
346
287
|
case "Secp256r1": {
|
|
347
|
-
const pk = PublicKeySerde.de({
|
|
288
|
+
const pk = import_sui3_utils3.PublicKeySerde.de({ publicKeyEncoded: decoded.publicKey, schema: decoded.signatureScheme });
|
|
348
289
|
if (Formatter.isSuiAddressEqual(pk.toSuiAddress(), targetAddress)) {
|
|
349
290
|
return pk;
|
|
350
291
|
}
|
|
@@ -457,6 +398,19 @@ function getAddressOwner(object) {
|
|
|
457
398
|
|
|
458
399
|
// src/transactions/reject.ts
|
|
459
400
|
var import_transactions3 = require("@mysten/sui.js/transactions");
|
|
401
|
+
|
|
402
|
+
// src/utils/buffer.ts
|
|
403
|
+
function stringToBuffer(s) {
|
|
404
|
+
return Buffer.from(s, "utf-8");
|
|
405
|
+
}
|
|
406
|
+
function Uint8ArrayToHex(b) {
|
|
407
|
+
return `0x${Array.prototype.map.call(b, (x) => `0${x.toString(16)}`.slice(-2)).join("")}`;
|
|
408
|
+
}
|
|
409
|
+
function HexToUint8Array(hex) {
|
|
410
|
+
return Uint8Array.from(Buffer.from(hex.startsWith("0x") ? hex.slice(2) : hex, "hex"));
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
// src/transactions/reject.ts
|
|
460
414
|
async function buildRejectTxb(input) {
|
|
461
415
|
const approveTxb = import_transactions3.TransactionBlock.from(HexToUint8Array(input.payloadToReject));
|
|
462
416
|
const gasPayment = approveTxb.blockData.gasConfig.payment;
|
|
@@ -521,87 +475,46 @@ var IntentionHelper = class {
|
|
|
521
475
|
}
|
|
522
476
|
};
|
|
523
477
|
|
|
524
|
-
// src/
|
|
525
|
-
var
|
|
526
|
-
|
|
527
|
-
static
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
static deCreateMSafeMessage(msg) {
|
|
531
|
-
const regex = /Create MSafe Account: (.+)/;
|
|
532
|
-
const matches = msg.match(regex);
|
|
533
|
-
return matches ? matches[1] : void 0;
|
|
534
|
-
}
|
|
535
|
-
// Message to be used when user login. The timestamp string
|
|
536
|
-
// is used to for extra validation.
|
|
537
|
-
static welcomeMessage(timestamp) {
|
|
538
|
-
return `Welcome to MSafe. ${timestamp}`;
|
|
539
|
-
}
|
|
540
|
-
static deWelcomeMessage(msg) {
|
|
541
|
-
const regex = /Welcome to MSafe. (.+)/;
|
|
542
|
-
const matches = msg.match(regex);
|
|
543
|
-
return matches ? matches[1] : void 0;
|
|
544
|
-
}
|
|
545
|
-
static proposeIntentionMessage(data) {
|
|
546
|
-
const { msafeAddress, intention, sn } = data;
|
|
547
|
-
const intentionData = IntentionHelper.ser(intention);
|
|
548
|
-
const msg = {
|
|
549
|
-
intentionData,
|
|
550
|
-
sequenceNumber: sn,
|
|
551
|
-
msafeAddress
|
|
552
|
-
};
|
|
553
|
-
return JSON.stringify(msg);
|
|
554
|
-
}
|
|
555
|
-
static deProposeIntentionMessage(s) {
|
|
556
|
-
const de = JSON.parse(s);
|
|
557
|
-
if (!("intentionData" in de) || typeof de.intentionData !== "string" || !("sequenceNumber" in de) || typeof de.sequenceNumber !== "number") {
|
|
558
|
-
throw new Error("Invalid intention data");
|
|
478
|
+
// src/utils/crypto.ts
|
|
479
|
+
var import_verify = require("@mysten/sui.js/verify");
|
|
480
|
+
var SignatureVerifier = class _SignatureVerifier {
|
|
481
|
+
static async getPublicKeyFromSignature(input) {
|
|
482
|
+
if (input.messageType === "TransactionBlock") {
|
|
483
|
+
return (0, import_verify.verifyTransactionBlock)(input.message, input.signature);
|
|
559
484
|
}
|
|
560
|
-
|
|
561
|
-
return {
|
|
562
|
-
msafeAddress,
|
|
563
|
-
sn: sequenceNumber,
|
|
564
|
-
intention: IntentionHelper.de(intentionData)
|
|
565
|
-
};
|
|
485
|
+
return (0, import_verify.verifyPersonalMessage)(input.message, input.signature);
|
|
566
486
|
}
|
|
567
|
-
static
|
|
568
|
-
const
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
}
|
|
575
|
-
const sortedUpdates = normalized.map((update) => sortObjectKeys(update));
|
|
576
|
-
const raw = JSON.stringify(sortedUpdates, null, 2);
|
|
577
|
-
const encoded = stringToBuffer(raw);
|
|
578
|
-
if (encoded.length <= 1024) {
|
|
579
|
-
return raw;
|
|
580
|
-
}
|
|
581
|
-
const md5 = (0, import_crypto_js.MD5)(raw);
|
|
582
|
-
return `Bulk address book update: ${md5}`;
|
|
487
|
+
static async getPublicKeyFromPersonalSignature(input) {
|
|
488
|
+
const message = stringToBuffer(input.messageStr);
|
|
489
|
+
return this.getPublicKeyFromSignature({
|
|
490
|
+
message,
|
|
491
|
+
messageType: "Personal",
|
|
492
|
+
signature: input.signature
|
|
493
|
+
});
|
|
583
494
|
}
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
var AddressBookSDK = class {
|
|
588
|
-
constructor(globals) {
|
|
589
|
-
this.globals = globals;
|
|
495
|
+
static async verifySignature(input) {
|
|
496
|
+
const publicKey = await _SignatureVerifier.getPublicKeyFromSignature(input);
|
|
497
|
+
return Formatter.isSuiAddressEqual(publicKey.toSuiAddress(), input.targetAddress);
|
|
590
498
|
}
|
|
591
|
-
async
|
|
592
|
-
|
|
499
|
+
static async verifyPersonalSignature(input) {
|
|
500
|
+
const message = stringToBuffer(input.messageStr);
|
|
501
|
+
return this.verifySignature({
|
|
502
|
+
message,
|
|
503
|
+
messageType: "Personal",
|
|
504
|
+
signature: input.signature,
|
|
505
|
+
targetAddress: input.targetAddress
|
|
506
|
+
});
|
|
593
507
|
}
|
|
594
|
-
async
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
508
|
+
static async verifyTransactionSignature(input) {
|
|
509
|
+
return this.verifySignature({
|
|
510
|
+
messageType: "TransactionBlock",
|
|
511
|
+
message: input.payload,
|
|
512
|
+
signature: input.signature,
|
|
513
|
+
targetAddress: input.targetAddress
|
|
514
|
+
});
|
|
598
515
|
}
|
|
599
516
|
};
|
|
600
517
|
|
|
601
|
-
// src/core/MSafeAccount.ts
|
|
602
|
-
var import_sui3_utils2 = require("@msafe/sui3-utils");
|
|
603
|
-
var import_utils5 = require("@mysten/sui.js/utils");
|
|
604
|
-
|
|
605
518
|
// src/utils/iter/iterator.ts
|
|
606
519
|
var REQUEST_PAGE_SIZE = 25;
|
|
607
520
|
async function getAllFromIterator(it) {
|
|
@@ -730,21 +643,25 @@ var OwnedObjectRequester = class {
|
|
|
730
643
|
};
|
|
731
644
|
|
|
732
645
|
// src/core/MSafeAccount.ts
|
|
733
|
-
var MSafeAccount = class {
|
|
646
|
+
var MSafeAccount = class _MSafeAccount {
|
|
734
647
|
constructor(globals, info) {
|
|
735
648
|
this.globals = globals;
|
|
736
649
|
this.info = info;
|
|
737
|
-
this.
|
|
650
|
+
this.multiSig = new import_sui3_utils4.MultiSigAccount({
|
|
738
651
|
threshold: info.threshold,
|
|
739
|
-
ownersWithWeight: info.
|
|
652
|
+
ownersWithWeight: info.owners,
|
|
740
653
|
creationNonce: info.creationNonce
|
|
741
654
|
});
|
|
742
655
|
this.coinHelper = new CoinHelper(this.suiClient);
|
|
743
656
|
}
|
|
744
|
-
|
|
657
|
+
multiSig;
|
|
745
658
|
coinHelper;
|
|
746
|
-
static async
|
|
747
|
-
|
|
659
|
+
static async New(globals, address) {
|
|
660
|
+
const info = await globals.backend.getMSafeAccountInfo(address);
|
|
661
|
+
const ms = new _MSafeAccount(globals, info);
|
|
662
|
+
if (ms.address !== address) {
|
|
663
|
+
throw new Error("Invalid msafe config with address");
|
|
664
|
+
}
|
|
748
665
|
}
|
|
749
666
|
async ownedCoins() {
|
|
750
667
|
const balances = await this.suiClient.getAllBalances({ owner: this.address });
|
|
@@ -753,7 +670,7 @@ var MSafeAccount = class {
|
|
|
753
670
|
const meta = await this.coinHelper.getCoinMeta(balance.coinType);
|
|
754
671
|
const unlockedBalance = balance.lockedBalance.number ? BigInt(balance.totalBalance) - BigInt(balance.lockedBalance.number) : BigInt(balance.totalBalance);
|
|
755
672
|
return {
|
|
756
|
-
type: (0,
|
|
673
|
+
type: (0, import_utils3.normalizeStructTag)(balance.coinType),
|
|
757
674
|
balance: BigInt(unlockedBalance),
|
|
758
675
|
metadata: meta
|
|
759
676
|
};
|
|
@@ -798,7 +715,7 @@ var MSafeAccount = class {
|
|
|
798
715
|
return this.backend.getNextSequenceNumber(this.address);
|
|
799
716
|
}
|
|
800
717
|
async proposeIntention(input) {
|
|
801
|
-
const message =
|
|
718
|
+
const message = import_sui3_utils4.SigningMessageHelper.proposeIntentionMessage({
|
|
802
719
|
msafeAddress: this.address,
|
|
803
720
|
intention: input.intention,
|
|
804
721
|
sn: input.sequenceNumber
|
|
@@ -877,7 +794,7 @@ var MSafeAccount = class {
|
|
|
877
794
|
return this.backend.skipNextFailedIntention({ msafeAddress: this.address, userAddress: await this.userAddress() });
|
|
878
795
|
}
|
|
879
796
|
async simulateIntention(intention) {
|
|
880
|
-
const txb = await (0,
|
|
797
|
+
const txb = await (0, import_sui3_utils4.buildIntentionTransaction)(this.suiClient, intention, this.address);
|
|
881
798
|
if (!txb.blockData.gasConfig.price) {
|
|
882
799
|
const refGas = await this.suiClient.getReferenceGasPrice();
|
|
883
800
|
txb.setGasPrice(refGas);
|
|
@@ -909,14 +826,14 @@ var MSafeAccount = class {
|
|
|
909
826
|
throw new Error("Not enough signatures");
|
|
910
827
|
}
|
|
911
828
|
const sigs = [];
|
|
912
|
-
for (let i = 0; i < this.info.
|
|
913
|
-
const owner = this.info.
|
|
914
|
-
const signature = gotSigs.get(owner.
|
|
829
|
+
for (let i = 0; i < this.info.owners.length; i++) {
|
|
830
|
+
const owner = this.info.owners[i];
|
|
831
|
+
const signature = gotSigs.get(owner.address);
|
|
915
832
|
if (signature) {
|
|
916
833
|
sigs.push(signature);
|
|
917
834
|
}
|
|
918
835
|
}
|
|
919
|
-
const multiSignature = this.
|
|
836
|
+
const multiSignature = this.multiSig.combinePartialSignatures(sigs);
|
|
920
837
|
return this.suiClient.executeTransactionBlock({
|
|
921
838
|
transactionBlock: HexToUint8Array(payload),
|
|
922
839
|
signature: multiSignature,
|
|
@@ -924,7 +841,7 @@ var MSafeAccount = class {
|
|
|
924
841
|
});
|
|
925
842
|
}
|
|
926
843
|
get address() {
|
|
927
|
-
return this.
|
|
844
|
+
return this.multiSig.address;
|
|
928
845
|
}
|
|
929
846
|
get backend() {
|
|
930
847
|
return this.globals.backend;
|
|
@@ -965,6 +882,9 @@ var PublicKeyHelper = class {
|
|
|
965
882
|
results[i] = this.knownPublicKeys.get(address);
|
|
966
883
|
}
|
|
967
884
|
const emptyIndexes = results.map((elem, index) => elem === void 0 ? index : -1).filter((index) => index !== -1);
|
|
885
|
+
if (emptyIndexes.length === 0) {
|
|
886
|
+
return results;
|
|
887
|
+
}
|
|
968
888
|
const backendResult = await this.globals.backend.getPublicKeyBatch(emptyIndexes.map((index) => addresses[index]));
|
|
969
889
|
for (let i = 0; i < emptyIndexes.length; i++) {
|
|
970
890
|
const index = emptyIndexes[i];
|
|
@@ -1010,8 +930,9 @@ var PublicKeyHelper = class {
|
|
|
1010
930
|
var import_client = require("@mysten/sui.js/client");
|
|
1011
931
|
|
|
1012
932
|
// src/backend/BackendImpl.ts
|
|
933
|
+
var import_sui3_utils5 = require("@msafe/sui3-utils");
|
|
1013
934
|
var import_axios = __toESM(require("axios"), 1);
|
|
1014
|
-
var BackendImpl = class {
|
|
935
|
+
var BackendImpl = class _BackendImpl {
|
|
1015
936
|
constructor(apiURL) {
|
|
1016
937
|
this.apiURL = apiURL;
|
|
1017
938
|
}
|
|
@@ -1039,76 +960,69 @@ var BackendImpl = class {
|
|
|
1039
960
|
return (await this.getPublicKeyBatch([address]))[0];
|
|
1040
961
|
}
|
|
1041
962
|
async getPublicKeyBatch(addresses) {
|
|
1042
|
-
const
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
);
|
|
963
|
+
const query = {
|
|
964
|
+
userAddressList: addresses
|
|
965
|
+
};
|
|
966
|
+
const res = await import_axios.default.get(`${this.apiURL}/user/public-keys`, {
|
|
967
|
+
params: query,
|
|
968
|
+
headers: this.headers()
|
|
969
|
+
});
|
|
1049
970
|
if (res.status !== 200 && res.status !== 201) {
|
|
1050
971
|
throw new Error(`invalid getPublicKeyBatch return: ${res}`);
|
|
1051
972
|
}
|
|
1052
973
|
return res.data?.map(
|
|
1053
|
-
(publicKeyWithSchema) => publicKeyWithSchema ? PublicKeySerde.de(
|
|
974
|
+
(publicKeyWithSchema) => publicKeyWithSchema ? import_sui3_utils5.PublicKeySerde.de(publicKeyWithSchema) : void 0
|
|
1054
975
|
);
|
|
1055
976
|
}
|
|
1056
977
|
async getMSafeAccountInfo(msafeAddress) {
|
|
1057
|
-
const
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
978
|
+
const q = {
|
|
979
|
+
msafeAddress
|
|
980
|
+
};
|
|
981
|
+
const res = await import_axios.default.get(`${this.apiURL}/msafe`, {
|
|
982
|
+
params: q,
|
|
983
|
+
headers: this.headers()
|
|
984
|
+
});
|
|
1063
985
|
if (res.status !== 200 && res.status !== 201) {
|
|
1064
986
|
throw new Error(`invalid getPublicKeyBatch return: ${res}`);
|
|
1065
987
|
}
|
|
1066
|
-
|
|
1067
|
-
return {
|
|
1068
|
-
address: msafeResp.address,
|
|
1069
|
-
ownersWithWeightPK: msafeResp.ownersWithWeightPKEncoded.map(
|
|
1070
|
-
(owner) => ({
|
|
1071
|
-
publicKey: PublicKeySerde.de({ publicKey: owner.publicKeyEncoded, scheme: owner.schema }),
|
|
1072
|
-
address: owner.address,
|
|
1073
|
-
weight: owner.weight
|
|
1074
|
-
})
|
|
1075
|
-
),
|
|
1076
|
-
threshold: msafeResp.threshold,
|
|
1077
|
-
name: msafeResp.name,
|
|
1078
|
-
description: msafeResp.description,
|
|
1079
|
-
creationNonce: msafeResp.creationNonce
|
|
1080
|
-
};
|
|
988
|
+
return _BackendImpl.toMSafeConfig(res.data);
|
|
1081
989
|
}
|
|
1082
|
-
async getUserInfo(
|
|
1083
|
-
const
|
|
990
|
+
async getUserInfo() {
|
|
991
|
+
const userRes = await import_axios.default.get(`${this.apiURL}/user`, {
|
|
992
|
+
headers: this.headers()
|
|
993
|
+
});
|
|
994
|
+
if (userRes.status !== 200 && userRes.status !== 201) {
|
|
995
|
+
throw new Error(`invalid getPublicKeyBatch return: ${userRes}`);
|
|
996
|
+
}
|
|
997
|
+
return userRes.data;
|
|
998
|
+
}
|
|
999
|
+
async getOwnedMSafeByStatus(input) {
|
|
1000
|
+
const q = {
|
|
1001
|
+
status: input.status ?? import_sui3_utils5.UserMSafeStatus.active,
|
|
1002
|
+
...input.pagination ? {
|
|
1003
|
+
page: input.pagination.page.toString(),
|
|
1004
|
+
limit: input.pagination.limit.toString()
|
|
1005
|
+
} : {}
|
|
1006
|
+
};
|
|
1007
|
+
const res = await import_axios.default.get(`${this.apiURL}/msafe/owned`, {
|
|
1008
|
+
params: q,
|
|
1084
1009
|
headers: this.headers()
|
|
1085
1010
|
});
|
|
1086
1011
|
if (res.status !== 200 && res.status !== 201) {
|
|
1087
|
-
throw new Error(`invalid
|
|
1012
|
+
throw new Error(`invalid getOwnedMSafeByStatus return: ${res}`);
|
|
1088
1013
|
}
|
|
1089
1014
|
return {
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
schema: res.data.schema,
|
|
1093
|
-
creationNonce: res.data.creationNonce,
|
|
1094
|
-
ownedMSafe: res.data.ownedMSafe.map(
|
|
1095
|
-
(msafe) => ({
|
|
1096
|
-
address: msafe.address,
|
|
1097
|
-
ownersWithWeightPK: msafe.ownersWithWeightPKEncoded.map(
|
|
1098
|
-
(owner) => ({
|
|
1099
|
-
publicKey: PublicKeySerde.de({ publicKey: owner.publicKeyEncoded, scheme: owner.schema }),
|
|
1100
|
-
address: owner.address,
|
|
1101
|
-
weight: owner.weight
|
|
1102
|
-
})
|
|
1103
|
-
),
|
|
1104
|
-
threshold: msafe.threshold,
|
|
1105
|
-
name: msafe.name,
|
|
1106
|
-
description: msafe.description,
|
|
1107
|
-
creationNonce: msafe.creationNonce
|
|
1108
|
-
})
|
|
1109
|
-
)
|
|
1015
|
+
data: res.data.data.map(_BackendImpl.toMSafeConfig),
|
|
1016
|
+
meta: res.data.meta
|
|
1110
1017
|
};
|
|
1111
1018
|
}
|
|
1019
|
+
async updateMSafeStatus(input) {
|
|
1020
|
+
const p = input;
|
|
1021
|
+
const res = await import_axios.default.post(`${this.apiURL}/msafe/status`, p, { headers: this.headers() });
|
|
1022
|
+
if (res.status !== 200 && res.status !== 201) {
|
|
1023
|
+
throw new Error(`Invalid updateMSafeStatus return: ${res}`);
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1112
1026
|
async getPendingTransactions(msafeAddress) {
|
|
1113
1027
|
const res = await import_axios.default.get(`${this.apiURL}/transaction/pending/${msafeAddress}`, {
|
|
1114
1028
|
headers: this.headers()
|
|
@@ -1166,7 +1080,7 @@ var BackendImpl = class {
|
|
|
1166
1080
|
return res.data;
|
|
1167
1081
|
}
|
|
1168
1082
|
async createMSafeAccount(input) {
|
|
1169
|
-
const res = await import_axios.default.post(`${this.apiURL}/
|
|
1083
|
+
const res = await import_axios.default.post(`${this.apiURL}/msafe/create`, input, {
|
|
1170
1084
|
headers: this.headers()
|
|
1171
1085
|
});
|
|
1172
1086
|
if (res.status !== 200 && res.status !== 201) {
|
|
@@ -1174,36 +1088,30 @@ var BackendImpl = class {
|
|
|
1174
1088
|
}
|
|
1175
1089
|
}
|
|
1176
1090
|
async proposeIntention(input) {
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
throw new Error(`invalid proposeIntention return: ${res}`);
|
|
1181
|
-
}
|
|
1182
|
-
} catch (e) {
|
|
1183
|
-
console.log(e);
|
|
1091
|
+
const res = await import_axios.default.post(`${this.apiURL}/transaction/intention`, input, { headers: this.headers() });
|
|
1092
|
+
if (res.status !== 200 && res.status !== 201) {
|
|
1093
|
+
throw new Error(`invalid proposeIntention return: ${res}`);
|
|
1184
1094
|
}
|
|
1185
1095
|
}
|
|
1186
1096
|
// TODO later
|
|
1187
|
-
|
|
1097
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
1098
|
+
async proposePendingTransaction(_input) {
|
|
1099
|
+
return void 0;
|
|
1188
1100
|
}
|
|
1189
1101
|
async rejectCurrentTx(input) {
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
headers: this.headers()
|
|
1200
|
-
}
|
|
1201
|
-
);
|
|
1202
|
-
if (res.status !== 200 && res.status !== 201) {
|
|
1203
|
-
throw new Error(`invalid voteForTransaction return: ${res}`);
|
|
1102
|
+
const res = await import_axios.default.post(
|
|
1103
|
+
`${this.apiURL}/transaction/pending/reject`,
|
|
1104
|
+
{
|
|
1105
|
+
address: input.msafeAddress,
|
|
1106
|
+
digest: input.digest,
|
|
1107
|
+
signature: input.signature
|
|
1108
|
+
},
|
|
1109
|
+
{
|
|
1110
|
+
headers: this.headers()
|
|
1204
1111
|
}
|
|
1205
|
-
|
|
1206
|
-
|
|
1112
|
+
);
|
|
1113
|
+
if (res.status !== 200 && res.status !== 201) {
|
|
1114
|
+
throw new Error(`invalid voteForTransaction return: ${res}`);
|
|
1207
1115
|
}
|
|
1208
1116
|
}
|
|
1209
1117
|
async voteForTransaction(input) {
|
|
@@ -1262,11 +1170,26 @@ var BackendImpl = class {
|
|
|
1262
1170
|
throw new Error(`invalid updateAddressBook return: ${res}`);
|
|
1263
1171
|
}
|
|
1264
1172
|
}
|
|
1265
|
-
|
|
1173
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
1174
|
+
async processExecutedTransaction(_digest) {
|
|
1175
|
+
return void 0;
|
|
1266
1176
|
}
|
|
1267
1177
|
headers(token) {
|
|
1268
1178
|
return { Authorization: `Bearer ${token || this._token}` };
|
|
1269
1179
|
}
|
|
1180
|
+
static toMSafeConfig(resp) {
|
|
1181
|
+
return {
|
|
1182
|
+
...resp,
|
|
1183
|
+
owners: resp.owners.map((owner) => ({
|
|
1184
|
+
address: owner.address,
|
|
1185
|
+
weight: owner.weight,
|
|
1186
|
+
publicKey: import_sui3_utils5.PublicKeySerde.de({
|
|
1187
|
+
publicKeyEncoded: owner.publicKeyEncoded,
|
|
1188
|
+
schema: owner.schema
|
|
1189
|
+
})
|
|
1190
|
+
}))
|
|
1191
|
+
};
|
|
1192
|
+
}
|
|
1270
1193
|
};
|
|
1271
1194
|
|
|
1272
1195
|
// src/globals/const.ts
|
|
@@ -1278,29 +1201,6 @@ var MSafeEnv = /* @__PURE__ */ ((MSafeEnv3) => {
|
|
|
1278
1201
|
MSafeEnv3["prod"] = "prod";
|
|
1279
1202
|
return MSafeEnv3;
|
|
1280
1203
|
})(MSafeEnv || {});
|
|
1281
|
-
var UNIT_DATABASE_CONFIG = {
|
|
1282
|
-
type: "sqlite",
|
|
1283
|
-
database: ":memory:",
|
|
1284
|
-
logging: false
|
|
1285
|
-
};
|
|
1286
|
-
var LOCAL_DATABASE_CONFIG = {
|
|
1287
|
-
type: "mysql",
|
|
1288
|
-
host: "127.0.0.1",
|
|
1289
|
-
port: 3306,
|
|
1290
|
-
username: "msafe",
|
|
1291
|
-
password: "msafe",
|
|
1292
|
-
database: "msafe_sui_local",
|
|
1293
|
-
logging: false
|
|
1294
|
-
};
|
|
1295
|
-
var DEV_DATABASE_CONFIG = {
|
|
1296
|
-
type: "mysql",
|
|
1297
|
-
host: "msafe-dev-database.cluster-caos3ssocrx6.us-west-1.rds.amazonaws.com",
|
|
1298
|
-
port: 3306,
|
|
1299
|
-
username: "msafe",
|
|
1300
|
-
password: "Momentum.Safe2022",
|
|
1301
|
-
database: "msafe_sui_dev",
|
|
1302
|
-
logging: false
|
|
1303
|
-
};
|
|
1304
1204
|
var MSAFE_APPLICATION = "msafe";
|
|
1305
1205
|
var TESTNET_RPC_URL = "https://sui-testnet.blockvision.org/v1/2Sgk89ivT64MnKdcGzjmyjY2ndD";
|
|
1306
1206
|
var MAINNET_RPC_URL = "https://sui-mainnet.blockvision.org/v1/2Sgk7NPvqkd7mESYkxF01yX15l7";
|
|
@@ -1315,8 +1215,9 @@ var ENV_CONFIGS = /* @__PURE__ */ new Map([
|
|
|
1315
1215
|
suiClient: {
|
|
1316
1216
|
url: TESTNET_RPC_URL
|
|
1317
1217
|
},
|
|
1318
|
-
backend:
|
|
1319
|
-
|
|
1218
|
+
backend: {
|
|
1219
|
+
url: LOCAL_API_URL
|
|
1220
|
+
},
|
|
1320
1221
|
syncingURL: LOCAL_SYNCING_URL
|
|
1321
1222
|
}
|
|
1322
1223
|
],
|
|
@@ -1326,8 +1227,9 @@ var ENV_CONFIGS = /* @__PURE__ */ new Map([
|
|
|
1326
1227
|
suiClient: {
|
|
1327
1228
|
url: TESTNET_RPC_URL
|
|
1328
1229
|
},
|
|
1329
|
-
backend:
|
|
1330
|
-
|
|
1230
|
+
backend: {
|
|
1231
|
+
url: LOCAL_API_URL
|
|
1232
|
+
},
|
|
1331
1233
|
syncingURL: LOCAL_SYNCING_URL
|
|
1332
1234
|
}
|
|
1333
1235
|
],
|
|
@@ -1337,8 +1239,9 @@ var ENV_CONFIGS = /* @__PURE__ */ new Map([
|
|
|
1337
1239
|
suiClient: {
|
|
1338
1240
|
url: TESTNET_RPC_URL
|
|
1339
1241
|
},
|
|
1340
|
-
backend:
|
|
1341
|
-
|
|
1242
|
+
backend: {
|
|
1243
|
+
url: DEV_API_URL
|
|
1244
|
+
},
|
|
1342
1245
|
syncingURL: DEV_SYNCING_URL
|
|
1343
1246
|
}
|
|
1344
1247
|
]
|
|
@@ -1351,12 +1254,11 @@ function getMSafeConfig(env, options) {
|
|
|
1351
1254
|
if (options?.suiClient?.url) {
|
|
1352
1255
|
config.suiClient.url = options.suiClient.url;
|
|
1353
1256
|
}
|
|
1354
|
-
if (options?.backend) {
|
|
1355
|
-
config.backend = options.backend;
|
|
1257
|
+
if (options?.backend?.url) {
|
|
1258
|
+
config.backend.url = options.backend.url;
|
|
1356
1259
|
}
|
|
1357
1260
|
return config;
|
|
1358
1261
|
}
|
|
1359
|
-
var AUTH_SIGN_MESSAGE = "Welcome to MSafe";
|
|
1360
1262
|
|
|
1361
1263
|
// src/globals/MSafeGlobals.ts
|
|
1362
1264
|
var MSafeGlobals = class _MSafeGlobals {
|
|
@@ -1372,7 +1274,7 @@ var MSafeGlobals = class _MSafeGlobals {
|
|
|
1372
1274
|
static async New(env, options) {
|
|
1373
1275
|
const config = getMSafeConfig(env, options);
|
|
1374
1276
|
const suiClient = new import_client.SuiClient(config.suiClient);
|
|
1375
|
-
const backend = new BackendImpl(config.
|
|
1277
|
+
const backend = new BackendImpl(config.backend.url);
|
|
1376
1278
|
return new _MSafeGlobals({
|
|
1377
1279
|
backend,
|
|
1378
1280
|
suiClient,
|
|
@@ -1419,7 +1321,7 @@ var MSafeClient = class _MSafeClient {
|
|
|
1419
1321
|
return jwt;
|
|
1420
1322
|
}
|
|
1421
1323
|
async authSign(wallet) {
|
|
1422
|
-
const messageStr =
|
|
1324
|
+
const messageStr = import_sui3_utils6.SigningMessageHelper.loginMessageWithTimestamp((/* @__PURE__ */ new Date()).toUTCString());
|
|
1423
1325
|
const sig = await wallet.signPersonalMessage({
|
|
1424
1326
|
messageStr
|
|
1425
1327
|
});
|
|
@@ -1431,7 +1333,10 @@ var MSafeClient = class _MSafeClient {
|
|
|
1431
1333
|
});
|
|
1432
1334
|
}
|
|
1433
1335
|
async userInfo() {
|
|
1434
|
-
return this.globals.backend.getUserInfo(
|
|
1336
|
+
return this.globals.backend.getUserInfo();
|
|
1337
|
+
}
|
|
1338
|
+
async ownedMSafe(pagination) {
|
|
1339
|
+
return this.globals.backend.getOwnedMSafeByStatus({ status: import_sui3_utils6.UserMSafeStatus.active, pagination });
|
|
1435
1340
|
}
|
|
1436
1341
|
async createAccount(info) {
|
|
1437
1342
|
return this.creationHelper.submitMSafeCreation(info);
|
|
@@ -1469,34 +1374,27 @@ var MSafeClient = class _MSafeClient {
|
|
|
1469
1374
|
get AddressBook() {
|
|
1470
1375
|
return new AddressBookSDK(this.globals);
|
|
1471
1376
|
}
|
|
1377
|
+
get Invitation() {
|
|
1378
|
+
return new InvitationSDK(this.globals);
|
|
1379
|
+
}
|
|
1472
1380
|
async walletAddress() {
|
|
1473
1381
|
return this.wallet.address();
|
|
1474
1382
|
}
|
|
1475
1383
|
};
|
|
1476
|
-
|
|
1477
|
-
// src/types/address-book.ts
|
|
1478
|
-
var OpAddressBookType = /* @__PURE__ */ ((OpAddressBookType2) => {
|
|
1479
|
-
OpAddressBookType2["Delete"] = "delete";
|
|
1480
|
-
OpAddressBookType2["Upsert"] = "upsert";
|
|
1481
|
-
return OpAddressBookType2;
|
|
1482
|
-
})(OpAddressBookType || {});
|
|
1483
1384
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1484
1385
|
0 && (module.exports = {
|
|
1485
|
-
AUTH_SIGN_MESSAGE,
|
|
1486
1386
|
AddressBookSDK,
|
|
1487
1387
|
COIN_TYPE_ARG_REGEX,
|
|
1488
1388
|
Coin,
|
|
1489
1389
|
CoinHelper,
|
|
1490
1390
|
CreateHelper,
|
|
1491
1391
|
DEV_API_URL,
|
|
1492
|
-
DEV_DATABASE_CONFIG,
|
|
1493
1392
|
DEV_SYNCING_URL,
|
|
1494
1393
|
ENV_CONFIGS,
|
|
1495
1394
|
Formatter,
|
|
1496
1395
|
HexToUint8Array,
|
|
1497
1396
|
IntentionHelper,
|
|
1498
1397
|
LOCAL_API_URL,
|
|
1499
|
-
LOCAL_DATABASE_CONFIG,
|
|
1500
1398
|
LOCAL_SYNCING_URL,
|
|
1501
1399
|
MAINNET_RPC_URL,
|
|
1502
1400
|
MSAFE_APPLICATION,
|
|
@@ -1504,13 +1402,9 @@ var OpAddressBookType = /* @__PURE__ */ ((OpAddressBookType2) => {
|
|
|
1504
1402
|
MSafeClient,
|
|
1505
1403
|
MSafeEnv,
|
|
1506
1404
|
MSafeGlobals,
|
|
1507
|
-
MessageHelper,
|
|
1508
|
-
OpAddressBookType,
|
|
1509
|
-
PublicKeySerde,
|
|
1510
1405
|
SUI_COIN,
|
|
1511
1406
|
SignatureVerifier,
|
|
1512
1407
|
TESTNET_RPC_URL,
|
|
1513
|
-
UNIT_DATABASE_CONFIG,
|
|
1514
1408
|
Uint8ArrayToHex,
|
|
1515
1409
|
getAllCoins,
|
|
1516
1410
|
getMSafeConfig,
|