@msafe/sui3-sdk 0.0.13 → 0.0.14
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 +256 -374
- 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 +260 -369
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/backend/BackendImpl.ts +106 -111
- 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 +30 -17
- package/src/core/MSafeClient.ts +15 -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,29 @@ 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.map((owner) => ({
|
|
653
|
+
address: owner.address,
|
|
654
|
+
weight: owner.weight,
|
|
655
|
+
publicKey: import_sui3_utils4.PublicKeySerde.de({ publicKeyEncoded: owner.publicKeyEncoded, schema: owner.schema })
|
|
656
|
+
})),
|
|
740
657
|
creationNonce: info.creationNonce
|
|
741
658
|
});
|
|
742
659
|
this.coinHelper = new CoinHelper(this.suiClient);
|
|
743
660
|
}
|
|
744
|
-
|
|
661
|
+
multiSig;
|
|
745
662
|
coinHelper;
|
|
746
|
-
static async
|
|
747
|
-
|
|
663
|
+
static async New(globals, address) {
|
|
664
|
+
const info = await globals.backend.getMSafeAccountInfo(address);
|
|
665
|
+
const ms = new _MSafeAccount(globals, info);
|
|
666
|
+
if (ms.address !== address) {
|
|
667
|
+
throw new Error("Invalid msafe config with address");
|
|
668
|
+
}
|
|
748
669
|
}
|
|
749
670
|
async ownedCoins() {
|
|
750
671
|
const balances = await this.suiClient.getAllBalances({ owner: this.address });
|
|
@@ -753,7 +674,7 @@ var MSafeAccount = class {
|
|
|
753
674
|
const meta = await this.coinHelper.getCoinMeta(balance.coinType);
|
|
754
675
|
const unlockedBalance = balance.lockedBalance.number ? BigInt(balance.totalBalance) - BigInt(balance.lockedBalance.number) : BigInt(balance.totalBalance);
|
|
755
676
|
return {
|
|
756
|
-
type: (0,
|
|
677
|
+
type: (0, import_utils3.normalizeStructTag)(balance.coinType),
|
|
757
678
|
balance: BigInt(unlockedBalance),
|
|
758
679
|
metadata: meta
|
|
759
680
|
};
|
|
@@ -798,7 +719,7 @@ var MSafeAccount = class {
|
|
|
798
719
|
return this.backend.getNextSequenceNumber(this.address);
|
|
799
720
|
}
|
|
800
721
|
async proposeIntention(input) {
|
|
801
|
-
const message =
|
|
722
|
+
const message = import_sui3_utils4.SigningMessageHelper.proposeIntentionMessage({
|
|
802
723
|
msafeAddress: this.address,
|
|
803
724
|
intention: input.intention,
|
|
804
725
|
sn: input.sequenceNumber
|
|
@@ -877,7 +798,7 @@ var MSafeAccount = class {
|
|
|
877
798
|
return this.backend.skipNextFailedIntention({ msafeAddress: this.address, userAddress: await this.userAddress() });
|
|
878
799
|
}
|
|
879
800
|
async simulateIntention(intention) {
|
|
880
|
-
const txb = await (0,
|
|
801
|
+
const txb = await (0, import_sui3_utils4.buildIntentionTransaction)(this.suiClient, intention, this.address);
|
|
881
802
|
if (!txb.blockData.gasConfig.price) {
|
|
882
803
|
const refGas = await this.suiClient.getReferenceGasPrice();
|
|
883
804
|
txb.setGasPrice(refGas);
|
|
@@ -909,14 +830,14 @@ var MSafeAccount = class {
|
|
|
909
830
|
throw new Error("Not enough signatures");
|
|
910
831
|
}
|
|
911
832
|
const sigs = [];
|
|
912
|
-
for (let i = 0; i < this.info.
|
|
913
|
-
const owner = this.info.
|
|
914
|
-
const signature = gotSigs.get(owner.
|
|
833
|
+
for (let i = 0; i < this.info.owners.length; i++) {
|
|
834
|
+
const owner = this.info.owners[i];
|
|
835
|
+
const signature = gotSigs.get(owner.address);
|
|
915
836
|
if (signature) {
|
|
916
837
|
sigs.push(signature);
|
|
917
838
|
}
|
|
918
839
|
}
|
|
919
|
-
const multiSignature = this.
|
|
840
|
+
const multiSignature = this.multiSig.combinePartialSignatures(sigs);
|
|
920
841
|
return this.suiClient.executeTransactionBlock({
|
|
921
842
|
transactionBlock: HexToUint8Array(payload),
|
|
922
843
|
signature: multiSignature,
|
|
@@ -924,7 +845,7 @@ var MSafeAccount = class {
|
|
|
924
845
|
});
|
|
925
846
|
}
|
|
926
847
|
get address() {
|
|
927
|
-
return this.
|
|
848
|
+
return this.multiSig.address;
|
|
928
849
|
}
|
|
929
850
|
get backend() {
|
|
930
851
|
return this.globals.backend;
|
|
@@ -965,6 +886,9 @@ var PublicKeyHelper = class {
|
|
|
965
886
|
results[i] = this.knownPublicKeys.get(address);
|
|
966
887
|
}
|
|
967
888
|
const emptyIndexes = results.map((elem, index) => elem === void 0 ? index : -1).filter((index) => index !== -1);
|
|
889
|
+
if (emptyIndexes.length === 0) {
|
|
890
|
+
return results;
|
|
891
|
+
}
|
|
968
892
|
const backendResult = await this.globals.backend.getPublicKeyBatch(emptyIndexes.map((index) => addresses[index]));
|
|
969
893
|
for (let i = 0; i < emptyIndexes.length; i++) {
|
|
970
894
|
const index = emptyIndexes[i];
|
|
@@ -1010,6 +934,7 @@ var PublicKeyHelper = class {
|
|
|
1010
934
|
var import_client = require("@mysten/sui.js/client");
|
|
1011
935
|
|
|
1012
936
|
// src/backend/BackendImpl.ts
|
|
937
|
+
var import_sui3_utils5 = require("@msafe/sui3-utils");
|
|
1013
938
|
var import_axios = __toESM(require("axios"), 1);
|
|
1014
939
|
var BackendImpl = class {
|
|
1015
940
|
constructor(apiURL) {
|
|
@@ -1039,75 +964,65 @@ var BackendImpl = class {
|
|
|
1039
964
|
return (await this.getPublicKeyBatch([address]))[0];
|
|
1040
965
|
}
|
|
1041
966
|
async getPublicKeyBatch(addresses) {
|
|
1042
|
-
const
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
);
|
|
967
|
+
const query = {
|
|
968
|
+
userAddressList: addresses
|
|
969
|
+
};
|
|
970
|
+
const res = await import_axios.default.get(`${this.apiURL}/user/public-keys`, {
|
|
971
|
+
params: query,
|
|
972
|
+
headers: this.headers()
|
|
973
|
+
});
|
|
1049
974
|
if (res.status !== 200 && res.status !== 201) {
|
|
1050
975
|
throw new Error(`invalid getPublicKeyBatch return: ${res}`);
|
|
1051
976
|
}
|
|
1052
977
|
return res.data?.map(
|
|
1053
|
-
(publicKeyWithSchema) => publicKeyWithSchema ? PublicKeySerde.de(
|
|
978
|
+
(publicKeyWithSchema) => publicKeyWithSchema ? import_sui3_utils5.PublicKeySerde.de(publicKeyWithSchema) : void 0
|
|
1054
979
|
);
|
|
1055
980
|
}
|
|
1056
981
|
async getMSafeAccountInfo(msafeAddress) {
|
|
1057
|
-
const
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
982
|
+
const q = {
|
|
983
|
+
msafeAddress
|
|
984
|
+
};
|
|
985
|
+
const res = await import_axios.default.get(`${this.apiURL}/msafe`, {
|
|
986
|
+
params: q,
|
|
987
|
+
headers: this.headers()
|
|
988
|
+
});
|
|
1063
989
|
if (res.status !== 200 && res.status !== 201) {
|
|
1064
990
|
throw new Error(`invalid getPublicKeyBatch return: ${res}`);
|
|
1065
991
|
}
|
|
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
|
-
};
|
|
992
|
+
return res.data;
|
|
1081
993
|
}
|
|
1082
|
-
async getUserInfo(
|
|
1083
|
-
const
|
|
994
|
+
async getUserInfo() {
|
|
995
|
+
const userRes = await import_axios.default.get(`${this.apiURL}/user`, {
|
|
996
|
+
headers: this.headers()
|
|
997
|
+
});
|
|
998
|
+
if (userRes.status !== 200 && userRes.status !== 201) {
|
|
999
|
+
throw new Error(`invalid getPublicKeyBatch return: ${userRes}`);
|
|
1000
|
+
}
|
|
1001
|
+
return userRes.data;
|
|
1002
|
+
}
|
|
1003
|
+
async getOwnedMSafeByStatus(input) {
|
|
1004
|
+
const q = {
|
|
1005
|
+
status: input.status ?? import_sui3_utils5.UserMSafeStatus.active,
|
|
1006
|
+
...input.pagination ? {
|
|
1007
|
+
page: input.pagination.page.toString(),
|
|
1008
|
+
limit: input.pagination.limit.toString()
|
|
1009
|
+
} : {}
|
|
1010
|
+
};
|
|
1011
|
+
const res = await import_axios.default.get(`${this.apiURL}/msafe/owned`, {
|
|
1012
|
+
params: q,
|
|
1084
1013
|
headers: this.headers()
|
|
1085
1014
|
});
|
|
1086
1015
|
if (res.status !== 200 && res.status !== 201) {
|
|
1087
|
-
throw new Error(`invalid
|
|
1016
|
+
throw new Error(`invalid getOwnedMSafeByStatus return: ${res}`);
|
|
1017
|
+
}
|
|
1018
|
+
return res.data;
|
|
1019
|
+
}
|
|
1020
|
+
async updateMSafeStatus(input) {
|
|
1021
|
+
const p = input;
|
|
1022
|
+
const res = await import_axios.default.post(`${this.apiURL}/msafe/status`, p, { headers: this.headers() });
|
|
1023
|
+
if (res.status !== 200 && res.status !== 201) {
|
|
1024
|
+
throw new Error(`Invalid updateMSafeStatus return: ${res}`);
|
|
1088
1025
|
}
|
|
1089
|
-
return {
|
|
1090
|
-
address: res.data.address,
|
|
1091
|
-
publicKey: res.data.publicKey,
|
|
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
|
-
)
|
|
1110
|
-
};
|
|
1111
1026
|
}
|
|
1112
1027
|
async getPendingTransactions(msafeAddress) {
|
|
1113
1028
|
const res = await import_axios.default.get(`${this.apiURL}/transaction/pending/${msafeAddress}`, {
|
|
@@ -1166,7 +1081,7 @@ var BackendImpl = class {
|
|
|
1166
1081
|
return res.data;
|
|
1167
1082
|
}
|
|
1168
1083
|
async createMSafeAccount(input) {
|
|
1169
|
-
const res = await import_axios.default.post(`${this.apiURL}/
|
|
1084
|
+
const res = await import_axios.default.post(`${this.apiURL}/msafe/create`, input, {
|
|
1170
1085
|
headers: this.headers()
|
|
1171
1086
|
});
|
|
1172
1087
|
if (res.status !== 200 && res.status !== 201) {
|
|
@@ -1174,36 +1089,30 @@ var BackendImpl = class {
|
|
|
1174
1089
|
}
|
|
1175
1090
|
}
|
|
1176
1091
|
async proposeIntention(input) {
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
throw new Error(`invalid proposeIntention return: ${res}`);
|
|
1181
|
-
}
|
|
1182
|
-
} catch (e) {
|
|
1183
|
-
console.log(e);
|
|
1092
|
+
const res = await import_axios.default.post(`${this.apiURL}/transaction/intention`, input, { headers: this.headers() });
|
|
1093
|
+
if (res.status !== 200 && res.status !== 201) {
|
|
1094
|
+
throw new Error(`invalid proposeIntention return: ${res}`);
|
|
1184
1095
|
}
|
|
1185
1096
|
}
|
|
1186
1097
|
// TODO later
|
|
1187
|
-
|
|
1098
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
1099
|
+
async proposePendingTransaction(_input) {
|
|
1100
|
+
return void 0;
|
|
1188
1101
|
}
|
|
1189
1102
|
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}`);
|
|
1103
|
+
const res = await import_axios.default.post(
|
|
1104
|
+
`${this.apiURL}/transaction/pending/reject`,
|
|
1105
|
+
{
|
|
1106
|
+
address: input.msafeAddress,
|
|
1107
|
+
digest: input.digest,
|
|
1108
|
+
signature: input.signature
|
|
1109
|
+
},
|
|
1110
|
+
{
|
|
1111
|
+
headers: this.headers()
|
|
1204
1112
|
}
|
|
1205
|
-
|
|
1206
|
-
|
|
1113
|
+
);
|
|
1114
|
+
if (res.status !== 200 && res.status !== 201) {
|
|
1115
|
+
throw new Error(`invalid voteForTransaction return: ${res}`);
|
|
1207
1116
|
}
|
|
1208
1117
|
}
|
|
1209
1118
|
async voteForTransaction(input) {
|
|
@@ -1262,7 +1171,9 @@ var BackendImpl = class {
|
|
|
1262
1171
|
throw new Error(`invalid updateAddressBook return: ${res}`);
|
|
1263
1172
|
}
|
|
1264
1173
|
}
|
|
1265
|
-
|
|
1174
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
1175
|
+
async processExecutedTransaction(_digest) {
|
|
1176
|
+
return void 0;
|
|
1266
1177
|
}
|
|
1267
1178
|
headers(token) {
|
|
1268
1179
|
return { Authorization: `Bearer ${token || this._token}` };
|
|
@@ -1278,29 +1189,6 @@ var MSafeEnv = /* @__PURE__ */ ((MSafeEnv3) => {
|
|
|
1278
1189
|
MSafeEnv3["prod"] = "prod";
|
|
1279
1190
|
return MSafeEnv3;
|
|
1280
1191
|
})(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
1192
|
var MSAFE_APPLICATION = "msafe";
|
|
1305
1193
|
var TESTNET_RPC_URL = "https://sui-testnet.blockvision.org/v1/2Sgk89ivT64MnKdcGzjmyjY2ndD";
|
|
1306
1194
|
var MAINNET_RPC_URL = "https://sui-mainnet.blockvision.org/v1/2Sgk7NPvqkd7mESYkxF01yX15l7";
|
|
@@ -1315,8 +1203,9 @@ var ENV_CONFIGS = /* @__PURE__ */ new Map([
|
|
|
1315
1203
|
suiClient: {
|
|
1316
1204
|
url: TESTNET_RPC_URL
|
|
1317
1205
|
},
|
|
1318
|
-
backend:
|
|
1319
|
-
|
|
1206
|
+
backend: {
|
|
1207
|
+
url: LOCAL_API_URL
|
|
1208
|
+
},
|
|
1320
1209
|
syncingURL: LOCAL_SYNCING_URL
|
|
1321
1210
|
}
|
|
1322
1211
|
],
|
|
@@ -1326,8 +1215,9 @@ var ENV_CONFIGS = /* @__PURE__ */ new Map([
|
|
|
1326
1215
|
suiClient: {
|
|
1327
1216
|
url: TESTNET_RPC_URL
|
|
1328
1217
|
},
|
|
1329
|
-
backend:
|
|
1330
|
-
|
|
1218
|
+
backend: {
|
|
1219
|
+
url: LOCAL_API_URL
|
|
1220
|
+
},
|
|
1331
1221
|
syncingURL: LOCAL_SYNCING_URL
|
|
1332
1222
|
}
|
|
1333
1223
|
],
|
|
@@ -1337,8 +1227,9 @@ var ENV_CONFIGS = /* @__PURE__ */ new Map([
|
|
|
1337
1227
|
suiClient: {
|
|
1338
1228
|
url: TESTNET_RPC_URL
|
|
1339
1229
|
},
|
|
1340
|
-
backend:
|
|
1341
|
-
|
|
1230
|
+
backend: {
|
|
1231
|
+
url: DEV_API_URL
|
|
1232
|
+
},
|
|
1342
1233
|
syncingURL: DEV_SYNCING_URL
|
|
1343
1234
|
}
|
|
1344
1235
|
]
|
|
@@ -1351,12 +1242,11 @@ function getMSafeConfig(env, options) {
|
|
|
1351
1242
|
if (options?.suiClient?.url) {
|
|
1352
1243
|
config.suiClient.url = options.suiClient.url;
|
|
1353
1244
|
}
|
|
1354
|
-
if (options?.backend) {
|
|
1355
|
-
config.backend = options.backend;
|
|
1245
|
+
if (options?.backend?.url) {
|
|
1246
|
+
config.backend.url = options.backend.url;
|
|
1356
1247
|
}
|
|
1357
1248
|
return config;
|
|
1358
1249
|
}
|
|
1359
|
-
var AUTH_SIGN_MESSAGE = "Welcome to MSafe";
|
|
1360
1250
|
|
|
1361
1251
|
// src/globals/MSafeGlobals.ts
|
|
1362
1252
|
var MSafeGlobals = class _MSafeGlobals {
|
|
@@ -1372,7 +1262,7 @@ var MSafeGlobals = class _MSafeGlobals {
|
|
|
1372
1262
|
static async New(env, options) {
|
|
1373
1263
|
const config = getMSafeConfig(env, options);
|
|
1374
1264
|
const suiClient = new import_client.SuiClient(config.suiClient);
|
|
1375
|
-
const backend = new BackendImpl(config.
|
|
1265
|
+
const backend = new BackendImpl(config.backend.url);
|
|
1376
1266
|
return new _MSafeGlobals({
|
|
1377
1267
|
backend,
|
|
1378
1268
|
suiClient,
|
|
@@ -1419,7 +1309,7 @@ var MSafeClient = class _MSafeClient {
|
|
|
1419
1309
|
return jwt;
|
|
1420
1310
|
}
|
|
1421
1311
|
async authSign(wallet) {
|
|
1422
|
-
const messageStr =
|
|
1312
|
+
const messageStr = import_sui3_utils6.SigningMessageHelper.loginMessageWithTimestamp((/* @__PURE__ */ new Date()).toUTCString());
|
|
1423
1313
|
const sig = await wallet.signPersonalMessage({
|
|
1424
1314
|
messageStr
|
|
1425
1315
|
});
|
|
@@ -1431,7 +1321,10 @@ var MSafeClient = class _MSafeClient {
|
|
|
1431
1321
|
});
|
|
1432
1322
|
}
|
|
1433
1323
|
async userInfo() {
|
|
1434
|
-
return this.globals.backend.getUserInfo(
|
|
1324
|
+
return this.globals.backend.getUserInfo();
|
|
1325
|
+
}
|
|
1326
|
+
async ownedMSafe(pagination) {
|
|
1327
|
+
return this.globals.backend.getOwnedMSafeByStatus({ status: import_sui3_utils6.UserMSafeStatus.active, pagination });
|
|
1435
1328
|
}
|
|
1436
1329
|
async createAccount(info) {
|
|
1437
1330
|
return this.creationHelper.submitMSafeCreation(info);
|
|
@@ -1469,34 +1362,27 @@ var MSafeClient = class _MSafeClient {
|
|
|
1469
1362
|
get AddressBook() {
|
|
1470
1363
|
return new AddressBookSDK(this.globals);
|
|
1471
1364
|
}
|
|
1365
|
+
get Invitation() {
|
|
1366
|
+
return new InvitationSDK(this.globals);
|
|
1367
|
+
}
|
|
1472
1368
|
async walletAddress() {
|
|
1473
1369
|
return this.wallet.address();
|
|
1474
1370
|
}
|
|
1475
1371
|
};
|
|
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
1372
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1484
1373
|
0 && (module.exports = {
|
|
1485
|
-
AUTH_SIGN_MESSAGE,
|
|
1486
1374
|
AddressBookSDK,
|
|
1487
1375
|
COIN_TYPE_ARG_REGEX,
|
|
1488
1376
|
Coin,
|
|
1489
1377
|
CoinHelper,
|
|
1490
1378
|
CreateHelper,
|
|
1491
1379
|
DEV_API_URL,
|
|
1492
|
-
DEV_DATABASE_CONFIG,
|
|
1493
1380
|
DEV_SYNCING_URL,
|
|
1494
1381
|
ENV_CONFIGS,
|
|
1495
1382
|
Formatter,
|
|
1496
1383
|
HexToUint8Array,
|
|
1497
1384
|
IntentionHelper,
|
|
1498
1385
|
LOCAL_API_URL,
|
|
1499
|
-
LOCAL_DATABASE_CONFIG,
|
|
1500
1386
|
LOCAL_SYNCING_URL,
|
|
1501
1387
|
MAINNET_RPC_URL,
|
|
1502
1388
|
MSAFE_APPLICATION,
|
|
@@ -1504,13 +1390,9 @@ var OpAddressBookType = /* @__PURE__ */ ((OpAddressBookType2) => {
|
|
|
1504
1390
|
MSafeClient,
|
|
1505
1391
|
MSafeEnv,
|
|
1506
1392
|
MSafeGlobals,
|
|
1507
|
-
MessageHelper,
|
|
1508
|
-
OpAddressBookType,
|
|
1509
|
-
PublicKeySerde,
|
|
1510
1393
|
SUI_COIN,
|
|
1511
1394
|
SignatureVerifier,
|
|
1512
1395
|
TESTNET_RPC_URL,
|
|
1513
|
-
UNIT_DATABASE_CONFIG,
|
|
1514
1396
|
Uint8ArrayToHex,
|
|
1515
1397
|
getAllCoins,
|
|
1516
1398
|
getMSafeConfig,
|