@msafe/sui3-sdk 0.0.12 → 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 +606 -741
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +94 -156
- package/dist/index.d.ts +94 -156
- package/dist/index.js +610 -740
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/backend/BackendImpl.ts +108 -134
- package/src/backend/interface.ts +26 -25
- 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 +37 -29
- 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 +12 -0
- 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.js
CHANGED
|
@@ -1,29 +1,107 @@
|
|
|
1
1
|
// src/core/CreateHelper.ts
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
import { MultiSigAccount, PublicKeySerde, SigningMessageHelper } from "@msafe/sui3-utils";
|
|
3
|
+
var CreateHelper = class {
|
|
4
|
+
constructor(globals, pkHelper) {
|
|
5
|
+
this.globals = globals;
|
|
6
|
+
this.pkHelper = pkHelper;
|
|
7
|
+
}
|
|
8
|
+
async getPublicKeyBatch(addresses) {
|
|
9
|
+
return this.pkHelper.getPublicKeyBatch(addresses);
|
|
10
|
+
}
|
|
11
|
+
async calculateMSafeAddress(info) {
|
|
12
|
+
const msConfig = await this.reduceCreationInfoToRawConfig(info);
|
|
13
|
+
const ms = new MultiSigAccount(msConfig);
|
|
14
|
+
return ms.address;
|
|
15
|
+
}
|
|
16
|
+
// Validate the create info and return the msafe address.
|
|
17
|
+
async validateCreateInfo(createInfo) {
|
|
18
|
+
return this.calculateMSafeAddress(createInfo);
|
|
19
|
+
}
|
|
20
|
+
async submitMSafeCreation(creationInfo) {
|
|
21
|
+
const msafeAddress = await this.validateCreateInfo(creationInfo);
|
|
22
|
+
const signingMessage = SigningMessageHelper.createMSafeMessage(msafeAddress);
|
|
23
|
+
const signature = await this.globals.wallet.signPersonalMessage({ messageStr: signingMessage });
|
|
24
|
+
await this.submitToBackend(creationInfo, signature.signature);
|
|
25
|
+
return msafeAddress;
|
|
26
|
+
}
|
|
27
|
+
async reduceCreationInfoToRawConfig(info) {
|
|
28
|
+
const publicKeys = await this.getPublicKeyBatch(info.owners.map((owner) => owner.address));
|
|
29
|
+
publicKeys.forEach((pk, i) => {
|
|
30
|
+
if (pk === void 0) {
|
|
31
|
+
throw new Error(`Unknown public key for address: ${info.owners[i].address}`);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
return {
|
|
35
|
+
threshold: info.threshold,
|
|
36
|
+
ownersWithWeight: info.owners.map((owner, i) => ({
|
|
37
|
+
publicKey: publicKeys[i],
|
|
38
|
+
weight: owner.weight
|
|
39
|
+
})),
|
|
40
|
+
creationNonce: info.creationNonce
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
async submitToBackend(createInfo, signature) {
|
|
44
|
+
const pks = await this.pkHelper.getPublicKeyBatch(createInfo.owners.map((owner) => owner.address));
|
|
45
|
+
await this.globals.backend.createMSafeAccount({
|
|
46
|
+
owners: createInfo.owners.map((owner, i) => ({
|
|
47
|
+
address: owner.address,
|
|
48
|
+
weight: owner.weight,
|
|
49
|
+
...PublicKeySerde.ser(pks[i])
|
|
50
|
+
})),
|
|
51
|
+
threshold: createInfo.threshold,
|
|
52
|
+
name: createInfo.name,
|
|
53
|
+
// name validation is deferred to backend
|
|
54
|
+
description: createInfo.description,
|
|
55
|
+
// description validation is deferred to backend
|
|
56
|
+
creationNonce: createInfo.creationNonce,
|
|
57
|
+
signature
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
};
|
|
7
61
|
|
|
8
|
-
// src/
|
|
62
|
+
// src/core/MSafeClient.ts
|
|
63
|
+
import { SigningMessageHelper as SigningMessageHelper4, UserMSafeStatus as UserMSafeStatus2 } from "@msafe/sui3-utils";
|
|
64
|
+
|
|
65
|
+
// src/core/AddressBookSDK.ts
|
|
66
|
+
import { SigningMessageHelper as SigningMessageHelper2 } from "@msafe/sui3-utils";
|
|
67
|
+
var AddressBookSDK = class {
|
|
68
|
+
constructor(globals) {
|
|
69
|
+
this.globals = globals;
|
|
70
|
+
}
|
|
71
|
+
async getEntries(pagination) {
|
|
72
|
+
return this.globals.backend.getAddressBookEntries(pagination);
|
|
73
|
+
}
|
|
74
|
+
async update(updates) {
|
|
75
|
+
const messageStr = SigningMessageHelper2.updateAddressBookMessage(updates);
|
|
76
|
+
const sig = await this.globals.wallet.signPersonalMessage({ messageStr });
|
|
77
|
+
return this.globals.backend.updateAddressBook({ updates, signature: sig.signature });
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
// src/core/InvitationSDK.ts
|
|
82
|
+
var InvitationSDK = class {
|
|
83
|
+
constructor(globals) {
|
|
84
|
+
this.globals = globals;
|
|
85
|
+
}
|
|
86
|
+
async getMSafeByStatus(status, pagination) {
|
|
87
|
+
return this.globals.backend.getOwnedMSafeByStatus({ status, pagination });
|
|
88
|
+
}
|
|
89
|
+
async updateMSafeStatus(msafeAddress, status) {
|
|
90
|
+
return this.globals.backend.updateMSafeStatus({ msafeAddress, status });
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
// src/core/MSafeAccount.ts
|
|
9
95
|
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
import {
|
|
96
|
+
buildIntentionTransaction,
|
|
97
|
+
MultiSigAccount as MultiSigAccount2,
|
|
98
|
+
PublicKeySerde as PublicKeySerde3,
|
|
99
|
+
SigningMessageHelper as SigningMessageHelper3
|
|
100
|
+
} from "@msafe/sui3-utils";
|
|
101
|
+
import { normalizeStructTag as normalizeStructTag3 } from "@mysten/sui.js/utils";
|
|
16
102
|
|
|
17
|
-
// src/
|
|
18
|
-
|
|
19
|
-
return Buffer.from(s, "utf-8");
|
|
20
|
-
}
|
|
21
|
-
function Uint8ArrayToHex(b) {
|
|
22
|
-
return `0x${Array.prototype.map.call(b, (x) => `0${x.toString(16)}`.slice(-2)).join("")}`;
|
|
23
|
-
}
|
|
24
|
-
function HexToUint8Array(hex) {
|
|
25
|
-
return Uint8Array.from(Buffer.from(hex.startsWith("0x") ? hex.slice(2) : hex, "hex"));
|
|
26
|
-
}
|
|
103
|
+
// src/transactions/coin-transfer.ts
|
|
104
|
+
import { TransactionBlock } from "@mysten/sui.js/transactions";
|
|
27
105
|
|
|
28
106
|
// src/utils/format.ts
|
|
29
107
|
import { normalizeSuiAddress, normalizeStructTag as normalizeStructTag2 } from "@mysten/sui.js/utils";
|
|
@@ -99,139 +177,8 @@ var Formatter = class {
|
|
|
99
177
|
}
|
|
100
178
|
};
|
|
101
179
|
|
|
102
|
-
// src/utils/crypto.ts
|
|
103
|
-
var SignatureVerifier = class _SignatureVerifier {
|
|
104
|
-
static async getPublicKeyFromSignature(input) {
|
|
105
|
-
if (input.messageType === "TransactionBlock") {
|
|
106
|
-
return verifyTransactionBlock(input.message, input.signature);
|
|
107
|
-
}
|
|
108
|
-
return verifyPersonalMessage(input.message, input.signature);
|
|
109
|
-
}
|
|
110
|
-
static async getPublicKeyFromPersonalSignature(input) {
|
|
111
|
-
const message = stringToBuffer(input.messageStr);
|
|
112
|
-
return this.getPublicKeyFromSignature({
|
|
113
|
-
message,
|
|
114
|
-
messageType: "Personal",
|
|
115
|
-
signature: input.signature
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
static async verifySignature(input) {
|
|
119
|
-
const publicKey = await _SignatureVerifier.getPublicKeyFromSignature(input);
|
|
120
|
-
return Formatter.isSuiAddressEqual(publicKey.toSuiAddress(), input.targetAddress);
|
|
121
|
-
}
|
|
122
|
-
static async verifyPersonalSignature(input) {
|
|
123
|
-
const message = stringToBuffer(input.messageStr);
|
|
124
|
-
return this.verifySignature({
|
|
125
|
-
message,
|
|
126
|
-
messageType: "Personal",
|
|
127
|
-
signature: input.signature,
|
|
128
|
-
targetAddress: input.targetAddress
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
static async verifyTransactionSignature(input) {
|
|
132
|
-
return this.verifySignature({
|
|
133
|
-
messageType: "TransactionBlock",
|
|
134
|
-
message: input.payload,
|
|
135
|
-
signature: input.signature,
|
|
136
|
-
targetAddress: input.targetAddress
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
};
|
|
140
|
-
var PublicKeySerde = class {
|
|
141
|
-
static ser(publicKey) {
|
|
142
|
-
return {
|
|
143
|
-
publicKey: publicKey.toBase64(),
|
|
144
|
-
scheme: SIGNATURE_FLAG_TO_SCHEME[publicKey.flag()]
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
static de(input) {
|
|
148
|
-
switch (input.scheme) {
|
|
149
|
-
case "ED25519":
|
|
150
|
-
return new Ed25519PublicKey(input.publicKey);
|
|
151
|
-
case "Secp256k1":
|
|
152
|
-
return new Secp256k1PublicKey(input.publicKey);
|
|
153
|
-
case "Secp256r1":
|
|
154
|
-
return new Secp256r1PublicKey(input.publicKey);
|
|
155
|
-
default:
|
|
156
|
-
throw new Error("Unsupported signature scheme: $input.scheme");
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
// src/core/CreateHelper.ts
|
|
162
|
-
var CreateHelper = class {
|
|
163
|
-
constructor(globals, pkHelper) {
|
|
164
|
-
this.globals = globals;
|
|
165
|
-
this.pkHelper = pkHelper;
|
|
166
|
-
}
|
|
167
|
-
async getPublicKeyBatch(addresses) {
|
|
168
|
-
return this.pkHelper.getPublicKeyBatch(addresses);
|
|
169
|
-
}
|
|
170
|
-
async calculateMSafeAddress(info) {
|
|
171
|
-
const msConfig = await this.reduceCreationInfoToRawConfig(info);
|
|
172
|
-
const ms = new MultisigAccountManager(msConfig);
|
|
173
|
-
return ms.address;
|
|
174
|
-
}
|
|
175
|
-
// Validate the create info and return the msafe address.
|
|
176
|
-
async validateCreateInfo(createInfo) {
|
|
177
|
-
const rawConfig = await this.reduceCreationInfoToRawConfig(createInfo);
|
|
178
|
-
validateCreateAccountRequest(rawConfig);
|
|
179
|
-
return this.calculateMSafeAddress(createInfo);
|
|
180
|
-
}
|
|
181
|
-
async submitMSafeCreation(creationInfo) {
|
|
182
|
-
const msafeAddress = await this.validateCreateInfo(creationInfo);
|
|
183
|
-
const signingMessage = createAccountCreationMessage(msafeAddress);
|
|
184
|
-
const signature = await this.globals.wallet.signPersonalMessage({ messageStr: signingMessage });
|
|
185
|
-
await this.submitToBackend(creationInfo, signature.signature);
|
|
186
|
-
return msafeAddress;
|
|
187
|
-
}
|
|
188
|
-
async reduceCreationInfoToRawConfig(info) {
|
|
189
|
-
const publicKeys = await this.getPublicKeyBatch(info.ownerWithWeight.map((oww) => oww.address));
|
|
190
|
-
publicKeys.forEach((pk, i) => {
|
|
191
|
-
if (pk === void 0) {
|
|
192
|
-
throw new Error(`Unknown public key for address: ${info.ownerWithWeight[i].address}`);
|
|
193
|
-
}
|
|
194
|
-
});
|
|
195
|
-
return {
|
|
196
|
-
threshold: info.threshold,
|
|
197
|
-
ownersWithWeight: info.ownerWithWeight.map((owner, i) => ({
|
|
198
|
-
publicKey: publicKeys[i],
|
|
199
|
-
weight: owner.weight
|
|
200
|
-
})),
|
|
201
|
-
creationNonce: info.creationNonce
|
|
202
|
-
};
|
|
203
|
-
}
|
|
204
|
-
async submitToBackend(createInfo, signature) {
|
|
205
|
-
const pks = await this.pkHelper.getPublicKeyBatch(createInfo.ownerWithWeight.map((owner) => owner.address));
|
|
206
|
-
await this.globals.backend.createMSafeAccount({
|
|
207
|
-
ownersWithWeightPKEncoded: createInfo.ownerWithWeight.map((owner, i) => {
|
|
208
|
-
const publicKeySer = PublicKeySerde.ser(pks[i]);
|
|
209
|
-
return {
|
|
210
|
-
address: owner.address,
|
|
211
|
-
weight: owner.weight,
|
|
212
|
-
publicKeyEncoded: publicKeySer.publicKey,
|
|
213
|
-
schema: publicKeySer.scheme
|
|
214
|
-
};
|
|
215
|
-
}),
|
|
216
|
-
threshold: createInfo.threshold,
|
|
217
|
-
name: createInfo.name,
|
|
218
|
-
// name validation is deferred to backend
|
|
219
|
-
description: createInfo.description,
|
|
220
|
-
// description validation is deferred to backend
|
|
221
|
-
creationNonce: createInfo.creationNonce,
|
|
222
|
-
signature
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
};
|
|
226
|
-
|
|
227
|
-
// src/core/MessageHelper.ts
|
|
228
|
-
import { normalizeSuiAddress as normalizeSuiAddress2 } from "@mysten/sui.js/utils";
|
|
229
|
-
import { MD5 } from "crypto-js";
|
|
230
|
-
|
|
231
|
-
// src/transactions/coin-transfer.ts
|
|
232
|
-
import { TransactionBlock } from "@mysten/sui.js/transactions";
|
|
233
|
-
|
|
234
180
|
// src/utils/sui.ts
|
|
181
|
+
import { PublicKeySerde as PublicKeySerde2 } from "@msafe/sui3-utils";
|
|
235
182
|
import { parseSerializedSignature } from "@mysten/sui.js/cryptography";
|
|
236
183
|
import { MultiSigPublicKey } from "@mysten/sui.js/multisig";
|
|
237
184
|
var SUI_COIN = "0x2::sui::SUI";
|
|
@@ -281,7 +228,7 @@ function getAddressFromSignatures(serializedSig, targetAddress) {
|
|
|
281
228
|
case "ED25519":
|
|
282
229
|
case "Secp256k1":
|
|
283
230
|
case "Secp256r1": {
|
|
284
|
-
const pk =
|
|
231
|
+
const pk = PublicKeySerde2.de({ publicKeyEncoded: decoded.publicKey, schema: decoded.signatureScheme });
|
|
285
232
|
if (Formatter.isSuiAddressEqual(pk.toSuiAddress(), targetAddress)) {
|
|
286
233
|
return pk;
|
|
287
234
|
}
|
|
@@ -394,6 +341,19 @@ function getAddressOwner(object) {
|
|
|
394
341
|
|
|
395
342
|
// src/transactions/reject.ts
|
|
396
343
|
import { TransactionBlock as TransactionBlock3 } from "@mysten/sui.js/transactions";
|
|
344
|
+
|
|
345
|
+
// src/utils/buffer.ts
|
|
346
|
+
function stringToBuffer(s) {
|
|
347
|
+
return Buffer.from(s, "utf-8");
|
|
348
|
+
}
|
|
349
|
+
function Uint8ArrayToHex(b) {
|
|
350
|
+
return `0x${Array.prototype.map.call(b, (x) => `0${x.toString(16)}`.slice(-2)).join("")}`;
|
|
351
|
+
}
|
|
352
|
+
function HexToUint8Array(hex) {
|
|
353
|
+
return Uint8Array.from(Buffer.from(hex.startsWith("0x") ? hex.slice(2) : hex, "hex"));
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
// src/transactions/reject.ts
|
|
397
357
|
async function buildRejectTxb(input) {
|
|
398
358
|
const approveTxb = TransactionBlock3.from(HexToUint8Array(input.payloadToReject));
|
|
399
359
|
const gasPayment = approveTxb.blockData.gasConfig.payment;
|
|
@@ -458,487 +418,43 @@ var IntentionHelper = class {
|
|
|
458
418
|
}
|
|
459
419
|
};
|
|
460
420
|
|
|
461
|
-
// src/
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
static
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
static deCreateMSafeMessage(msg) {
|
|
468
|
-
const regex = /Create MSafe Account: (.+)/;
|
|
469
|
-
const matches = msg.match(regex);
|
|
470
|
-
return matches ? matches[1] : void 0;
|
|
471
|
-
}
|
|
472
|
-
// Message to be used when user login. The timestamp string
|
|
473
|
-
// is used to for extra validation.
|
|
474
|
-
static welcomeMessage(timestamp) {
|
|
475
|
-
return `Welcome to MSafe. ${timestamp}`;
|
|
476
|
-
}
|
|
477
|
-
static deWelcomeMessage(msg) {
|
|
478
|
-
const regex = /Welcome to MSafe. (.+)/;
|
|
479
|
-
const matches = msg.match(regex);
|
|
480
|
-
return matches ? matches[1] : void 0;
|
|
481
|
-
}
|
|
482
|
-
static proposeIntentionMessage(data) {
|
|
483
|
-
const { msafeAddress, intention, sn } = data;
|
|
484
|
-
const intentionData = IntentionHelper.ser(intention);
|
|
485
|
-
const msg = {
|
|
486
|
-
intentionData,
|
|
487
|
-
sequenceNumber: sn,
|
|
488
|
-
msafeAddress
|
|
489
|
-
};
|
|
490
|
-
return JSON.stringify(msg);
|
|
491
|
-
}
|
|
492
|
-
static deProposeIntentionMessage(s) {
|
|
493
|
-
const de = JSON.parse(s);
|
|
494
|
-
if (!("intentionData" in de) || typeof de.intentionData !== "string" || !("sequenceNumber" in de) || typeof de.sequenceNumber !== "number") {
|
|
495
|
-
throw new Error("Invalid intention data");
|
|
421
|
+
// src/utils/crypto.ts
|
|
422
|
+
import { verifyPersonalMessage, verifyTransactionBlock } from "@mysten/sui.js/verify";
|
|
423
|
+
var SignatureVerifier = class _SignatureVerifier {
|
|
424
|
+
static async getPublicKeyFromSignature(input) {
|
|
425
|
+
if (input.messageType === "TransactionBlock") {
|
|
426
|
+
return verifyTransactionBlock(input.message, input.signature);
|
|
496
427
|
}
|
|
497
|
-
|
|
498
|
-
return {
|
|
499
|
-
msafeAddress,
|
|
500
|
-
sn: sequenceNumber,
|
|
501
|
-
intention: IntentionHelper.de(intentionData)
|
|
502
|
-
};
|
|
428
|
+
return verifyPersonalMessage(input.message, input.signature);
|
|
503
429
|
}
|
|
504
|
-
static
|
|
505
|
-
const
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
}
|
|
512
|
-
const sortedUpdates = normalized.map((update) => sortObjectKeys(update));
|
|
513
|
-
const raw = JSON.stringify(sortedUpdates, null, 2);
|
|
514
|
-
const encoded = stringToBuffer(raw);
|
|
515
|
-
if (encoded.length <= 1024) {
|
|
516
|
-
return raw;
|
|
517
|
-
}
|
|
518
|
-
const md5 = MD5(raw);
|
|
519
|
-
return `Bulk address book update: ${md5}`;
|
|
430
|
+
static async getPublicKeyFromPersonalSignature(input) {
|
|
431
|
+
const message = stringToBuffer(input.messageStr);
|
|
432
|
+
return this.getPublicKeyFromSignature({
|
|
433
|
+
message,
|
|
434
|
+
messageType: "Personal",
|
|
435
|
+
signature: input.signature
|
|
436
|
+
});
|
|
520
437
|
}
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
var AddressBookSDK = class {
|
|
525
|
-
constructor(globals) {
|
|
526
|
-
this.globals = globals;
|
|
438
|
+
static async verifySignature(input) {
|
|
439
|
+
const publicKey = await _SignatureVerifier.getPublicKeyFromSignature(input);
|
|
440
|
+
return Formatter.isSuiAddressEqual(publicKey.toSuiAddress(), input.targetAddress);
|
|
527
441
|
}
|
|
528
|
-
async
|
|
529
|
-
|
|
442
|
+
static async verifyPersonalSignature(input) {
|
|
443
|
+
const message = stringToBuffer(input.messageStr);
|
|
444
|
+
return this.verifySignature({
|
|
445
|
+
message,
|
|
446
|
+
messageType: "Personal",
|
|
447
|
+
signature: input.signature,
|
|
448
|
+
targetAddress: input.targetAddress
|
|
449
|
+
});
|
|
530
450
|
}
|
|
531
|
-
async
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
// src/core/MSafeAccount.ts
|
|
539
|
-
import {
|
|
540
|
-
buildIntentionTransaction,
|
|
541
|
-
getIntentionType,
|
|
542
|
-
MultisigAccountManager as MultisigAccountManager2
|
|
543
|
-
} from "@msafe/sui3-utils";
|
|
544
|
-
import { normalizeStructTag as normalizeStructTag3 } from "@mysten/sui.js/utils";
|
|
545
|
-
|
|
546
|
-
// src/globals/const.ts
|
|
547
|
-
var MSafeEnv = /* @__PURE__ */ ((MSafeEnv3) => {
|
|
548
|
-
MSafeEnv3["local"] = "local";
|
|
549
|
-
MSafeEnv3["unit"] = "unit";
|
|
550
|
-
MSafeEnv3["dev"] = "dev";
|
|
551
|
-
MSafeEnv3["prev"] = "prev";
|
|
552
|
-
MSafeEnv3["prod"] = "prod";
|
|
553
|
-
return MSafeEnv3;
|
|
554
|
-
})(MSafeEnv || {});
|
|
555
|
-
var UNIT_DATABASE_CONFIG = {
|
|
556
|
-
type: "sqlite",
|
|
557
|
-
database: ":memory:",
|
|
558
|
-
logging: false
|
|
559
|
-
};
|
|
560
|
-
var LOCAL_DATABASE_CONFIG = {
|
|
561
|
-
type: "mysql",
|
|
562
|
-
host: "127.0.0.1",
|
|
563
|
-
port: 3306,
|
|
564
|
-
username: "msafe",
|
|
565
|
-
password: "msafe",
|
|
566
|
-
database: "msafe_sui_local",
|
|
567
|
-
logging: false
|
|
568
|
-
};
|
|
569
|
-
var DEV_DATABASE_CONFIG = {
|
|
570
|
-
type: "mysql",
|
|
571
|
-
host: "msafe-dev-database.cluster-caos3ssocrx6.us-west-1.rds.amazonaws.com",
|
|
572
|
-
port: 3306,
|
|
573
|
-
username: "msafe",
|
|
574
|
-
password: "Momentum.Safe2022",
|
|
575
|
-
database: "msafe_sui_dev",
|
|
576
|
-
logging: false
|
|
577
|
-
};
|
|
578
|
-
var MSAFE_APPLICATION = "msafe";
|
|
579
|
-
var TESTNET_RPC_URL = "https://sui-testnet.blockvision.org/v1/2Sgk89ivT64MnKdcGzjmyjY2ndD";
|
|
580
|
-
var MAINNET_RPC_URL = "https://sui-mainnet.blockvision.org/v1/2Sgk7NPvqkd7mESYkxF01yX15l7";
|
|
581
|
-
var LOCAL_API_URL = "http://127.0.0.1:3000";
|
|
582
|
-
var LOCAL_SYNCING_URL = "http://127.0.0.1:3001";
|
|
583
|
-
var DEV_API_URL = "http://13.56.226.148";
|
|
584
|
-
var DEV_SYNCING_URL = "http://52.53.228.20";
|
|
585
|
-
var ENV_CONFIGS = /* @__PURE__ */ new Map([
|
|
586
|
-
[
|
|
587
|
-
"unit" /* unit */,
|
|
588
|
-
{
|
|
589
|
-
suiClient: {
|
|
590
|
-
url: TESTNET_RPC_URL
|
|
591
|
-
},
|
|
592
|
-
backend: LOCAL_DATABASE_CONFIG,
|
|
593
|
-
apiURL: LOCAL_API_URL,
|
|
594
|
-
syncingURL: LOCAL_SYNCING_URL
|
|
595
|
-
}
|
|
596
|
-
],
|
|
597
|
-
[
|
|
598
|
-
"local" /* local */,
|
|
599
|
-
{
|
|
600
|
-
suiClient: {
|
|
601
|
-
url: TESTNET_RPC_URL
|
|
602
|
-
},
|
|
603
|
-
backend: LOCAL_DATABASE_CONFIG,
|
|
604
|
-
apiURL: LOCAL_API_URL,
|
|
605
|
-
syncingURL: LOCAL_SYNCING_URL
|
|
606
|
-
}
|
|
607
|
-
],
|
|
608
|
-
[
|
|
609
|
-
"dev" /* dev */,
|
|
610
|
-
{
|
|
611
|
-
suiClient: {
|
|
612
|
-
url: TESTNET_RPC_URL
|
|
613
|
-
},
|
|
614
|
-
backend: DEV_DATABASE_CONFIG,
|
|
615
|
-
apiURL: DEV_API_URL,
|
|
616
|
-
syncingURL: DEV_SYNCING_URL
|
|
617
|
-
}
|
|
618
|
-
]
|
|
619
|
-
]);
|
|
620
|
-
function getMSafeConfig(env, options) {
|
|
621
|
-
const config = ENV_CONFIGS.get(env);
|
|
622
|
-
if (!config) {
|
|
623
|
-
throw new Error("Unknown environment");
|
|
624
|
-
}
|
|
625
|
-
if (options?.suiClient?.url) {
|
|
626
|
-
config.suiClient.url = options.suiClient.url;
|
|
627
|
-
}
|
|
628
|
-
if (options?.backend) {
|
|
629
|
-
config.backend = options.backend;
|
|
630
|
-
}
|
|
631
|
-
return config;
|
|
632
|
-
}
|
|
633
|
-
var AUTH_SIGN_MESSAGE = "Welcome to MSafe";
|
|
634
|
-
|
|
635
|
-
// src/globals/MSafeGlobals.ts
|
|
636
|
-
import { SuiClient } from "@mysten/sui.js/client";
|
|
637
|
-
|
|
638
|
-
// src/backend/BackendImpl.ts
|
|
639
|
-
import axios from "axios";
|
|
640
|
-
var BackendImpl = class {
|
|
641
|
-
constructor(apiURL) {
|
|
642
|
-
this.apiURL = apiURL;
|
|
643
|
-
}
|
|
644
|
-
_token;
|
|
645
|
-
async authSign(input) {
|
|
646
|
-
const res = await axios.post(`${this.apiURL}/auth/login`, input);
|
|
647
|
-
if (res.status !== 200 && res.status !== 201) {
|
|
648
|
-
throw new Error(`invalid authSign return: ${res}`);
|
|
649
|
-
}
|
|
650
|
-
this._token = res.data.accessToken;
|
|
651
|
-
return this._token;
|
|
652
|
-
}
|
|
653
|
-
async verifyToken(jwt) {
|
|
654
|
-
try {
|
|
655
|
-
const res = await axios.get(`${this.apiURL}/auth`, { headers: this.headers(jwt) });
|
|
656
|
-
return res.status === 200;
|
|
657
|
-
} catch (_) {
|
|
658
|
-
return false;
|
|
659
|
-
}
|
|
660
|
-
}
|
|
661
|
-
setJWTToken(token) {
|
|
662
|
-
this._token = token;
|
|
663
|
-
}
|
|
664
|
-
async getPublicKey(address) {
|
|
665
|
-
return (await this.getPublicKeyBatch([address]))[0];
|
|
666
|
-
}
|
|
667
|
-
async getPublicKeyBatch(addresses) {
|
|
668
|
-
const res = await axios.post(
|
|
669
|
-
`${this.apiURL}/account/getPublicKeyBatch`,
|
|
670
|
-
addresses,
|
|
671
|
-
{
|
|
672
|
-
headers: this.headers()
|
|
673
|
-
}
|
|
674
|
-
);
|
|
675
|
-
if (res.status !== 200 && res.status !== 201) {
|
|
676
|
-
throw new Error(`invalid getPublicKeyBatch return: ${res}`);
|
|
677
|
-
}
|
|
678
|
-
return res.data?.map(
|
|
679
|
-
(publicKeyWithSchema) => publicKeyWithSchema ? PublicKeySerde.de({ ...publicKeyWithSchema }) : void 0
|
|
680
|
-
);
|
|
681
|
-
}
|
|
682
|
-
async getMSafeAccountInfo(msafeAddress) {
|
|
683
|
-
const res = await axios.get(
|
|
684
|
-
`${this.apiURL}/account/getMSafeAccountInfo/${msafeAddress}`,
|
|
685
|
-
{
|
|
686
|
-
headers: this.headers()
|
|
687
|
-
}
|
|
688
|
-
);
|
|
689
|
-
if (res.status !== 200 && res.status !== 201) {
|
|
690
|
-
throw new Error(`invalid getPublicKeyBatch return: ${res}`);
|
|
691
|
-
}
|
|
692
|
-
const msafeResp = res.data;
|
|
693
|
-
return {
|
|
694
|
-
address: msafeResp.address,
|
|
695
|
-
ownersWithWeightPK: msafeResp.ownersWithWeightPKEncoded.map(
|
|
696
|
-
(owner) => ({
|
|
697
|
-
publicKey: PublicKeySerde.de({ publicKey: owner.publicKeyEncoded, scheme: owner.schema }),
|
|
698
|
-
address: owner.address,
|
|
699
|
-
weight: owner.weight
|
|
700
|
-
})
|
|
701
|
-
),
|
|
702
|
-
threshold: msafeResp.threshold,
|
|
703
|
-
name: msafeResp.name,
|
|
704
|
-
description: msafeResp.description,
|
|
705
|
-
creationNonce: msafeResp.creationNonce
|
|
706
|
-
};
|
|
707
|
-
}
|
|
708
|
-
async getUserInfo(userAddress) {
|
|
709
|
-
const res = await axios.get(`${this.apiURL}/account/user/${userAddress}`, {
|
|
710
|
-
headers: this.headers()
|
|
711
|
-
});
|
|
712
|
-
if (res.status !== 200 && res.status !== 201) {
|
|
713
|
-
throw new Error(`invalid getPublicKeyBatch return: ${res}`);
|
|
714
|
-
}
|
|
715
|
-
return {
|
|
716
|
-
address: res.data.address,
|
|
717
|
-
publicKey: res.data.publicKey,
|
|
718
|
-
schema: res.data.schema,
|
|
719
|
-
creationNonce: res.data.creationNonce,
|
|
720
|
-
ownedMSafe: res.data.ownedMSafe.map(
|
|
721
|
-
(msafe) => ({
|
|
722
|
-
address: msafe.address,
|
|
723
|
-
ownersWithWeightPK: msafe.ownersWithWeightPKEncoded.map(
|
|
724
|
-
(owner) => ({
|
|
725
|
-
publicKey: PublicKeySerde.de({ publicKey: owner.publicKeyEncoded, scheme: owner.schema }),
|
|
726
|
-
address: owner.address,
|
|
727
|
-
weight: owner.weight
|
|
728
|
-
})
|
|
729
|
-
),
|
|
730
|
-
threshold: msafe.threshold,
|
|
731
|
-
name: msafe.name,
|
|
732
|
-
description: msafe.description,
|
|
733
|
-
creationNonce: msafe.creationNonce
|
|
734
|
-
})
|
|
735
|
-
)
|
|
736
|
-
};
|
|
737
|
-
}
|
|
738
|
-
async getPendingTransactions(msafeAddress) {
|
|
739
|
-
const res = await axios.get(`${this.apiURL}/transaction/pending/${msafeAddress}`, {
|
|
740
|
-
headers: this.headers()
|
|
741
|
-
});
|
|
742
|
-
if (res.status !== 200 && res.status !== 201) {
|
|
743
|
-
throw new Error(`invalid getPublicKeyBatch return: ${res}`);
|
|
744
|
-
}
|
|
745
|
-
return res.data;
|
|
746
|
-
}
|
|
747
|
-
async getHistoryTransactions(msafeAddress, paginationOption) {
|
|
748
|
-
const res = await axios.get(
|
|
749
|
-
`${this.apiURL}/transaction/history?address=${msafeAddress}`,
|
|
750
|
-
{
|
|
751
|
-
params: {
|
|
752
|
-
page: paginationOption?.page,
|
|
753
|
-
limit: paginationOption?.limit
|
|
754
|
-
},
|
|
755
|
-
headers: this.headers()
|
|
756
|
-
}
|
|
757
|
-
);
|
|
758
|
-
if (res.status !== 200 && res.status !== 201) {
|
|
759
|
-
throw new Error(`invalid getCurrentSequenceNumber return: ${res}`);
|
|
760
|
-
}
|
|
761
|
-
return res.data;
|
|
762
|
-
}
|
|
763
|
-
async getFutureIntentions(msafeAddress, paginationOption) {
|
|
764
|
-
const res = await axios.get(`${this.apiURL}/transaction/intention/${msafeAddress}`, {
|
|
765
|
-
params: {
|
|
766
|
-
page: paginationOption?.page,
|
|
767
|
-
limit: paginationOption?.limit
|
|
768
|
-
},
|
|
769
|
-
headers: this.headers()
|
|
770
|
-
});
|
|
771
|
-
if (res.status !== 200 && res.status !== 201) {
|
|
772
|
-
throw new Error(`invalid getCurrentSequenceNumber return: ${res}`);
|
|
773
|
-
}
|
|
774
|
-
return res.data;
|
|
775
|
-
}
|
|
776
|
-
async getCurrentSequenceNumber(msafeAddress) {
|
|
777
|
-
const res = await axios.get(`${this.apiURL}/transaction/sn/current/${msafeAddress}`, {
|
|
778
|
-
headers: this.headers()
|
|
779
|
-
});
|
|
780
|
-
if (res.status !== 200 && res.status !== 201) {
|
|
781
|
-
throw new Error(`invalid getCurrentSequenceNumber return: ${res}`);
|
|
782
|
-
}
|
|
783
|
-
return res.data;
|
|
784
|
-
}
|
|
785
|
-
async getNextSequenceNumber(msafeAddress) {
|
|
786
|
-
const res = await axios.get(`${this.apiURL}/transaction/sn/next/${msafeAddress}`, {
|
|
787
|
-
headers: this.headers()
|
|
788
|
-
});
|
|
789
|
-
if (res.status !== 200 && res.status !== 201) {
|
|
790
|
-
throw new Error(`invalid getNextSequenceNumber return: ${res}`);
|
|
791
|
-
}
|
|
792
|
-
return res.data;
|
|
793
|
-
}
|
|
794
|
-
async createMSafeAccount(input) {
|
|
795
|
-
const res = await axios.post(`${this.apiURL}/account`, input, {
|
|
796
|
-
headers: this.headers()
|
|
797
|
-
});
|
|
798
|
-
if (res.status !== 200 && res.status !== 201) {
|
|
799
|
-
throw new Error(`invalid createMSafeAccount return: ${res}`);
|
|
800
|
-
}
|
|
801
|
-
}
|
|
802
|
-
async proposeIntention(input) {
|
|
803
|
-
try {
|
|
804
|
-
const res = await axios.post(
|
|
805
|
-
`${this.apiURL}/transaction/intention`,
|
|
806
|
-
{
|
|
807
|
-
intention: input.intention,
|
|
808
|
-
sequenceNumber: input.sequenceNumber,
|
|
809
|
-
address: input.msafeAddress,
|
|
810
|
-
signature: input.signature,
|
|
811
|
-
application: input.application,
|
|
812
|
-
txType: input.txType,
|
|
813
|
-
txSubType: input.txSubType
|
|
814
|
-
},
|
|
815
|
-
{ headers: this.headers() }
|
|
816
|
-
);
|
|
817
|
-
if (res.status !== 200 && res.status !== 201) {
|
|
818
|
-
throw new Error(`invalid proposeIntention return: ${res}`);
|
|
819
|
-
}
|
|
820
|
-
} catch (e) {
|
|
821
|
-
console.log(e);
|
|
822
|
-
}
|
|
823
|
-
}
|
|
824
|
-
// TODO later
|
|
825
|
-
async proposePendingTransaction(input) {
|
|
826
|
-
}
|
|
827
|
-
async rejectCurrentTx(input) {
|
|
828
|
-
try {
|
|
829
|
-
const res = await axios.post(
|
|
830
|
-
`${this.apiURL}/transaction/pending/reject`,
|
|
831
|
-
{
|
|
832
|
-
address: input.msafeAddress,
|
|
833
|
-
digest: input.digest,
|
|
834
|
-
signature: input.signature
|
|
835
|
-
},
|
|
836
|
-
{
|
|
837
|
-
headers: this.headers()
|
|
838
|
-
}
|
|
839
|
-
);
|
|
840
|
-
if (res.status !== 200 && res.status !== 201) {
|
|
841
|
-
throw new Error(`invalid voteForTransaction return: ${res}`);
|
|
842
|
-
}
|
|
843
|
-
} catch (e) {
|
|
844
|
-
console.log("e:", e);
|
|
845
|
-
}
|
|
846
|
-
}
|
|
847
|
-
async voteForTransaction(input) {
|
|
848
|
-
const res = await axios.post(
|
|
849
|
-
`${this.apiURL}/transaction/pending/vote`,
|
|
850
|
-
{
|
|
851
|
-
address: input.msafeAddress,
|
|
852
|
-
digest: input.txDigest,
|
|
853
|
-
signature: input.signature
|
|
854
|
-
},
|
|
855
|
-
{
|
|
856
|
-
headers: this.headers()
|
|
857
|
-
}
|
|
858
|
-
);
|
|
859
|
-
if (res.status !== 200 && res.status !== 201) {
|
|
860
|
-
throw new Error(`invalid voteForTransaction return: ${res}`);
|
|
861
|
-
}
|
|
862
|
-
}
|
|
863
|
-
async buildNextIntentionAndAddToPending(input) {
|
|
864
|
-
const res = await axios.post(
|
|
865
|
-
`${this.apiURL}/transaction/pending/build`,
|
|
866
|
-
{
|
|
867
|
-
address: input.msafeAddress
|
|
868
|
-
},
|
|
869
|
-
{ headers: this.headers() }
|
|
870
|
-
);
|
|
871
|
-
if (res.status !== 200 && res.status !== 201) {
|
|
872
|
-
throw new Error(`invalid buildNextIntentionAndAddToPending return: ${res}`);
|
|
873
|
-
}
|
|
874
|
-
}
|
|
875
|
-
async skipNextFailedIntention(input) {
|
|
876
|
-
const res = await axios.post(
|
|
877
|
-
`${this.apiURL}/transaction/pending/skip`,
|
|
878
|
-
{
|
|
879
|
-
msafeAddress: input.msafeAddress
|
|
880
|
-
},
|
|
881
|
-
{ headers: this.headers() }
|
|
882
|
-
);
|
|
883
|
-
if (res.status !== 200 && res.status !== 201) {
|
|
884
|
-
throw new Error(`invalid skipNextFailedIntention return: ${res}`);
|
|
885
|
-
}
|
|
886
|
-
}
|
|
887
|
-
async getAddressBookEntries(pagination) {
|
|
888
|
-
const res = await axios.get(`${this.apiURL}/address-book`, {
|
|
889
|
-
headers: this.headers(),
|
|
890
|
-
params: pagination
|
|
891
|
-
});
|
|
892
|
-
if (res.status !== 200) {
|
|
893
|
-
throw new Error(`Invalid address-book return: ${res}`);
|
|
894
|
-
}
|
|
895
|
-
return res.data;
|
|
896
|
-
}
|
|
897
|
-
async updateAddressBook(input) {
|
|
898
|
-
const res = await axios.post(`${this.apiURL}/address-book`, input, { headers: this.headers() });
|
|
899
|
-
if (res.status !== 200 && res.status !== 201) {
|
|
900
|
-
throw new Error(`invalid updateAddressBook return: ${res}`);
|
|
901
|
-
}
|
|
902
|
-
}
|
|
903
|
-
async processExecutedTransaction(digest) {
|
|
904
|
-
}
|
|
905
|
-
headers(token) {
|
|
906
|
-
return { Authorization: `Bearer ${token || this._token}` };
|
|
907
|
-
}
|
|
908
|
-
};
|
|
909
|
-
|
|
910
|
-
// src/globals/MSafeGlobals.ts
|
|
911
|
-
var MSafeGlobals = class _MSafeGlobals {
|
|
912
|
-
backend;
|
|
913
|
-
suiClient;
|
|
914
|
-
config;
|
|
915
|
-
_wallet;
|
|
916
|
-
constructor(input) {
|
|
917
|
-
this.backend = input.backend;
|
|
918
|
-
this.suiClient = input.suiClient;
|
|
919
|
-
this.config = input.config;
|
|
920
|
-
}
|
|
921
|
-
static async New(env, options) {
|
|
922
|
-
const config = getMSafeConfig(env, options);
|
|
923
|
-
const suiClient = new SuiClient(config.suiClient);
|
|
924
|
-
const backend = new BackendImpl(config.apiURL);
|
|
925
|
-
return new _MSafeGlobals({
|
|
926
|
-
backend,
|
|
927
|
-
suiClient,
|
|
928
|
-
config
|
|
929
|
-
});
|
|
930
|
-
}
|
|
931
|
-
connectWallet(wallet) {
|
|
932
|
-
this._wallet = wallet;
|
|
933
|
-
}
|
|
934
|
-
get wallet() {
|
|
935
|
-
if (!this._wallet) {
|
|
936
|
-
throw new Error("wallet not connected");
|
|
937
|
-
}
|
|
938
|
-
return this._wallet;
|
|
939
|
-
}
|
|
940
|
-
set wallet(val) {
|
|
941
|
-
this._wallet = val;
|
|
451
|
+
static async verifyTransactionSignature(input) {
|
|
452
|
+
return this.verifySignature({
|
|
453
|
+
messageType: "TransactionBlock",
|
|
454
|
+
message: input.payload,
|
|
455
|
+
signature: input.signature,
|
|
456
|
+
targetAddress: input.targetAddress
|
|
457
|
+
});
|
|
942
458
|
}
|
|
943
459
|
};
|
|
944
460
|
|
|
@@ -1070,21 +586,29 @@ var OwnedObjectRequester = class {
|
|
|
1070
586
|
};
|
|
1071
587
|
|
|
1072
588
|
// src/core/MSafeAccount.ts
|
|
1073
|
-
var MSafeAccount = class {
|
|
589
|
+
var MSafeAccount = class _MSafeAccount {
|
|
1074
590
|
constructor(globals, info) {
|
|
1075
591
|
this.globals = globals;
|
|
1076
592
|
this.info = info;
|
|
1077
|
-
this.
|
|
593
|
+
this.multiSig = new MultiSigAccount2({
|
|
1078
594
|
threshold: info.threshold,
|
|
1079
|
-
ownersWithWeight: info.
|
|
595
|
+
ownersWithWeight: info.owners.map((owner) => ({
|
|
596
|
+
address: owner.address,
|
|
597
|
+
weight: owner.weight,
|
|
598
|
+
publicKey: PublicKeySerde3.de({ publicKeyEncoded: owner.publicKeyEncoded, schema: owner.schema })
|
|
599
|
+
})),
|
|
1080
600
|
creationNonce: info.creationNonce
|
|
1081
601
|
});
|
|
1082
602
|
this.coinHelper = new CoinHelper(this.suiClient);
|
|
1083
603
|
}
|
|
1084
|
-
|
|
604
|
+
multiSig;
|
|
1085
605
|
coinHelper;
|
|
1086
|
-
static async
|
|
1087
|
-
|
|
606
|
+
static async New(globals, address) {
|
|
607
|
+
const info = await globals.backend.getMSafeAccountInfo(address);
|
|
608
|
+
const ms = new _MSafeAccount(globals, info);
|
|
609
|
+
if (ms.address !== address) {
|
|
610
|
+
throw new Error("Invalid msafe config with address");
|
|
611
|
+
}
|
|
1088
612
|
}
|
|
1089
613
|
async ownedCoins() {
|
|
1090
614
|
const balances = await this.suiClient.getAllBalances({ owner: this.address });
|
|
@@ -1137,25 +661,20 @@ var MSafeAccount = class {
|
|
|
1137
661
|
async nextSequenceNumber() {
|
|
1138
662
|
return this.backend.getNextSequenceNumber(this.address);
|
|
1139
663
|
}
|
|
1140
|
-
async proposeIntention(
|
|
1141
|
-
const message =
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
664
|
+
async proposeIntention(input) {
|
|
665
|
+
const message = SigningMessageHelper3.proposeIntentionMessage({
|
|
666
|
+
msafeAddress: this.address,
|
|
667
|
+
intention: input.intention,
|
|
668
|
+
sn: input.sequenceNumber
|
|
1145
669
|
});
|
|
1146
670
|
const signature = await this.wallet.signPersonalMessage({
|
|
1147
671
|
messageStr: message
|
|
1148
672
|
});
|
|
1149
|
-
const txType = getIntentionType(intention);
|
|
1150
673
|
await this.backend.proposeIntention({
|
|
1151
|
-
|
|
1152
|
-
sequenceNumber,
|
|
674
|
+
...input,
|
|
1153
675
|
msafeAddress: this.address,
|
|
1154
676
|
userAddress: await this.userAddress(),
|
|
1155
|
-
signature: signature.signature
|
|
1156
|
-
application: MSAFE_APPLICATION,
|
|
1157
|
-
txType: txType.txType,
|
|
1158
|
-
txSubType: txType.txSubType
|
|
677
|
+
signature: signature.signature
|
|
1159
678
|
});
|
|
1160
679
|
}
|
|
1161
680
|
async voteForTransaction(digest, payload) {
|
|
@@ -1253,101 +772,460 @@ var MSafeAccount = class {
|
|
|
1253
772
|
} else {
|
|
1254
773
|
throw new Error("Not enough signatures");
|
|
1255
774
|
}
|
|
1256
|
-
const sigs = [];
|
|
1257
|
-
for (let i = 0; i < this.info.
|
|
1258
|
-
const owner = this.info.
|
|
1259
|
-
const signature = gotSigs.get(owner.
|
|
1260
|
-
if (signature) {
|
|
1261
|
-
sigs.push(signature);
|
|
1262
|
-
}
|
|
775
|
+
const sigs = [];
|
|
776
|
+
for (let i = 0; i < this.info.owners.length; i++) {
|
|
777
|
+
const owner = this.info.owners[i];
|
|
778
|
+
const signature = gotSigs.get(owner.address);
|
|
779
|
+
if (signature) {
|
|
780
|
+
sigs.push(signature);
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
const multiSignature = this.multiSig.combinePartialSignatures(sigs);
|
|
784
|
+
return this.suiClient.executeTransactionBlock({
|
|
785
|
+
transactionBlock: HexToUint8Array(payload),
|
|
786
|
+
signature: multiSignature,
|
|
787
|
+
options: { showEffects: true }
|
|
788
|
+
});
|
|
789
|
+
}
|
|
790
|
+
get address() {
|
|
791
|
+
return this.multiSig.address;
|
|
792
|
+
}
|
|
793
|
+
get backend() {
|
|
794
|
+
return this.globals.backend;
|
|
795
|
+
}
|
|
796
|
+
get wallet() {
|
|
797
|
+
return this.globals.wallet;
|
|
798
|
+
}
|
|
799
|
+
async userAddress() {
|
|
800
|
+
return this.globals.wallet.address();
|
|
801
|
+
}
|
|
802
|
+
get suiClient() {
|
|
803
|
+
return this.globals.suiClient;
|
|
804
|
+
}
|
|
805
|
+
};
|
|
806
|
+
|
|
807
|
+
// src/core/PublicKeyHelper.ts
|
|
808
|
+
var PublicKeyHelper = class {
|
|
809
|
+
constructor(globals) {
|
|
810
|
+
this.globals = globals;
|
|
811
|
+
this.knownPublicKeys = /* @__PURE__ */ new Map();
|
|
812
|
+
}
|
|
813
|
+
knownPublicKeys;
|
|
814
|
+
async getPublicKey(address) {
|
|
815
|
+
const cached = this.knownPublicKeys.get(address);
|
|
816
|
+
if (cached) {
|
|
817
|
+
return cached;
|
|
818
|
+
}
|
|
819
|
+
const pk = await this._getPublicKey(address);
|
|
820
|
+
if (pk) {
|
|
821
|
+
this.knownPublicKeys.set(address, pk);
|
|
822
|
+
}
|
|
823
|
+
return pk;
|
|
824
|
+
}
|
|
825
|
+
async getPublicKeyBatch(addresses) {
|
|
826
|
+
const results = new Array(addresses.length).fill(void 0);
|
|
827
|
+
for (let i = 0; i < addresses.length; i++) {
|
|
828
|
+
const address = addresses[i];
|
|
829
|
+
results[i] = this.knownPublicKeys.get(address);
|
|
830
|
+
}
|
|
831
|
+
const emptyIndexes = results.map((elem, index) => elem === void 0 ? index : -1).filter((index) => index !== -1);
|
|
832
|
+
if (emptyIndexes.length === 0) {
|
|
833
|
+
return results;
|
|
834
|
+
}
|
|
835
|
+
const backendResult = await this.globals.backend.getPublicKeyBatch(emptyIndexes.map((index) => addresses[index]));
|
|
836
|
+
for (let i = 0; i < emptyIndexes.length; i++) {
|
|
837
|
+
const index = emptyIndexes[i];
|
|
838
|
+
results[index] = backendResult[i];
|
|
839
|
+
}
|
|
840
|
+
for (let i = 0; i < results.length; i++) {
|
|
841
|
+
if (results[i] === void 0) {
|
|
842
|
+
results[i] = await this.getPublicKeyFromChain(addresses[i]);
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
for (let i = 0; i < addresses.length; i++) {
|
|
846
|
+
if (results[i]) {
|
|
847
|
+
this.knownPublicKeys.set(addresses[i], results[i]);
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
return results;
|
|
851
|
+
}
|
|
852
|
+
async _getPublicKey(address) {
|
|
853
|
+
const pkBackend = await this.getPublicKeyFromBackend(address);
|
|
854
|
+
if (pkBackend) {
|
|
855
|
+
return pkBackend;
|
|
856
|
+
}
|
|
857
|
+
const pkChain = await this.getPublicKeyFromChain(address);
|
|
858
|
+
if (pkChain) {
|
|
859
|
+
return pkChain;
|
|
860
|
+
}
|
|
861
|
+
return void 0;
|
|
862
|
+
}
|
|
863
|
+
async getPublicKeyFromBackend(address) {
|
|
864
|
+
try {
|
|
865
|
+
const pk = await this.globals.backend.getPublicKey(address);
|
|
866
|
+
return pk;
|
|
867
|
+
} catch (_) {
|
|
868
|
+
return void 0;
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
async getPublicKeyFromChain(address) {
|
|
872
|
+
return getPublicKeyFromChain(this.globals.suiClient, address);
|
|
873
|
+
}
|
|
874
|
+
};
|
|
875
|
+
|
|
876
|
+
// src/globals/MSafeGlobals.ts
|
|
877
|
+
import { SuiClient } from "@mysten/sui.js/client";
|
|
878
|
+
|
|
879
|
+
// src/backend/BackendImpl.ts
|
|
880
|
+
import {
|
|
881
|
+
PublicKeySerde as PublicKeySerde4,
|
|
882
|
+
UserMSafeStatus
|
|
883
|
+
} from "@msafe/sui3-utils";
|
|
884
|
+
import axios from "axios";
|
|
885
|
+
var BackendImpl = class {
|
|
886
|
+
constructor(apiURL) {
|
|
887
|
+
this.apiURL = apiURL;
|
|
888
|
+
}
|
|
889
|
+
_token;
|
|
890
|
+
async authSign(input) {
|
|
891
|
+
const res = await axios.post(`${this.apiURL}/auth/login`, input);
|
|
892
|
+
if (res.status !== 200 && res.status !== 201) {
|
|
893
|
+
throw new Error(`invalid authSign return: ${res}`);
|
|
894
|
+
}
|
|
895
|
+
this._token = res.data.accessToken;
|
|
896
|
+
return this._token;
|
|
897
|
+
}
|
|
898
|
+
async verifyToken(jwt) {
|
|
899
|
+
try {
|
|
900
|
+
const res = await axios.get(`${this.apiURL}/auth`, { headers: this.headers(jwt) });
|
|
901
|
+
return res.status === 200;
|
|
902
|
+
} catch (_) {
|
|
903
|
+
return false;
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
setJWTToken(token) {
|
|
907
|
+
this._token = token;
|
|
908
|
+
}
|
|
909
|
+
async getPublicKey(address) {
|
|
910
|
+
return (await this.getPublicKeyBatch([address]))[0];
|
|
911
|
+
}
|
|
912
|
+
async getPublicKeyBatch(addresses) {
|
|
913
|
+
const query = {
|
|
914
|
+
userAddressList: addresses
|
|
915
|
+
};
|
|
916
|
+
const res = await axios.get(`${this.apiURL}/user/public-keys`, {
|
|
917
|
+
params: query,
|
|
918
|
+
headers: this.headers()
|
|
919
|
+
});
|
|
920
|
+
if (res.status !== 200 && res.status !== 201) {
|
|
921
|
+
throw new Error(`invalid getPublicKeyBatch return: ${res}`);
|
|
922
|
+
}
|
|
923
|
+
return res.data?.map(
|
|
924
|
+
(publicKeyWithSchema) => publicKeyWithSchema ? PublicKeySerde4.de(publicKeyWithSchema) : void 0
|
|
925
|
+
);
|
|
926
|
+
}
|
|
927
|
+
async getMSafeAccountInfo(msafeAddress) {
|
|
928
|
+
const q = {
|
|
929
|
+
msafeAddress
|
|
930
|
+
};
|
|
931
|
+
const res = await axios.get(`${this.apiURL}/msafe`, {
|
|
932
|
+
params: q,
|
|
933
|
+
headers: this.headers()
|
|
934
|
+
});
|
|
935
|
+
if (res.status !== 200 && res.status !== 201) {
|
|
936
|
+
throw new Error(`invalid getPublicKeyBatch return: ${res}`);
|
|
937
|
+
}
|
|
938
|
+
return res.data;
|
|
939
|
+
}
|
|
940
|
+
async getUserInfo() {
|
|
941
|
+
const userRes = await axios.get(`${this.apiURL}/user`, {
|
|
942
|
+
headers: this.headers()
|
|
943
|
+
});
|
|
944
|
+
if (userRes.status !== 200 && userRes.status !== 201) {
|
|
945
|
+
throw new Error(`invalid getPublicKeyBatch return: ${userRes}`);
|
|
946
|
+
}
|
|
947
|
+
return userRes.data;
|
|
948
|
+
}
|
|
949
|
+
async getOwnedMSafeByStatus(input) {
|
|
950
|
+
const q = {
|
|
951
|
+
status: input.status ?? UserMSafeStatus.active,
|
|
952
|
+
...input.pagination ? {
|
|
953
|
+
page: input.pagination.page.toString(),
|
|
954
|
+
limit: input.pagination.limit.toString()
|
|
955
|
+
} : {}
|
|
956
|
+
};
|
|
957
|
+
const res = await axios.get(`${this.apiURL}/msafe/owned`, {
|
|
958
|
+
params: q,
|
|
959
|
+
headers: this.headers()
|
|
960
|
+
});
|
|
961
|
+
if (res.status !== 200 && res.status !== 201) {
|
|
962
|
+
throw new Error(`invalid getOwnedMSafeByStatus return: ${res}`);
|
|
963
|
+
}
|
|
964
|
+
return res.data;
|
|
965
|
+
}
|
|
966
|
+
async updateMSafeStatus(input) {
|
|
967
|
+
const p = input;
|
|
968
|
+
const res = await axios.post(`${this.apiURL}/msafe/status`, p, { headers: this.headers() });
|
|
969
|
+
if (res.status !== 200 && res.status !== 201) {
|
|
970
|
+
throw new Error(`Invalid updateMSafeStatus return: ${res}`);
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
async getPendingTransactions(msafeAddress) {
|
|
974
|
+
const res = await axios.get(`${this.apiURL}/transaction/pending/${msafeAddress}`, {
|
|
975
|
+
headers: this.headers()
|
|
976
|
+
});
|
|
977
|
+
if (res.status !== 200 && res.status !== 201) {
|
|
978
|
+
throw new Error(`invalid getPublicKeyBatch return: ${res}`);
|
|
979
|
+
}
|
|
980
|
+
return res.data;
|
|
981
|
+
}
|
|
982
|
+
async getHistoryTransactions(msafeAddress, paginationOption) {
|
|
983
|
+
const res = await axios.get(
|
|
984
|
+
`${this.apiURL}/transaction/history?address=${msafeAddress}`,
|
|
985
|
+
{
|
|
986
|
+
params: {
|
|
987
|
+
page: paginationOption?.page,
|
|
988
|
+
limit: paginationOption?.limit
|
|
989
|
+
},
|
|
990
|
+
headers: this.headers()
|
|
991
|
+
}
|
|
992
|
+
);
|
|
993
|
+
if (res.status !== 200 && res.status !== 201) {
|
|
994
|
+
throw new Error(`invalid getCurrentSequenceNumber return: ${res}`);
|
|
995
|
+
}
|
|
996
|
+
return res.data;
|
|
997
|
+
}
|
|
998
|
+
async getFutureIntentions(msafeAddress, paginationOption) {
|
|
999
|
+
const res = await axios.get(`${this.apiURL}/transaction/intention/${msafeAddress}`, {
|
|
1000
|
+
params: {
|
|
1001
|
+
page: paginationOption?.page,
|
|
1002
|
+
limit: paginationOption?.limit
|
|
1003
|
+
},
|
|
1004
|
+
headers: this.headers()
|
|
1005
|
+
});
|
|
1006
|
+
if (res.status !== 200 && res.status !== 201) {
|
|
1007
|
+
throw new Error(`invalid getCurrentSequenceNumber return: ${res}`);
|
|
1008
|
+
}
|
|
1009
|
+
return res.data;
|
|
1010
|
+
}
|
|
1011
|
+
async getCurrentSequenceNumber(msafeAddress) {
|
|
1012
|
+
const res = await axios.get(`${this.apiURL}/transaction/sn/current/${msafeAddress}`, {
|
|
1013
|
+
headers: this.headers()
|
|
1014
|
+
});
|
|
1015
|
+
if (res.status !== 200 && res.status !== 201) {
|
|
1016
|
+
throw new Error(`invalid getCurrentSequenceNumber return: ${res}`);
|
|
1263
1017
|
}
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1018
|
+
return res.data;
|
|
1019
|
+
}
|
|
1020
|
+
async getNextSequenceNumber(msafeAddress) {
|
|
1021
|
+
const res = await axios.get(`${this.apiURL}/transaction/sn/next/${msafeAddress}`, {
|
|
1022
|
+
headers: this.headers()
|
|
1269
1023
|
});
|
|
1024
|
+
if (res.status !== 200 && res.status !== 201) {
|
|
1025
|
+
throw new Error(`invalid getNextSequenceNumber return: ${res}`);
|
|
1026
|
+
}
|
|
1027
|
+
return res.data;
|
|
1270
1028
|
}
|
|
1271
|
-
|
|
1272
|
-
|
|
1029
|
+
async createMSafeAccount(input) {
|
|
1030
|
+
const res = await axios.post(`${this.apiURL}/msafe/create`, input, {
|
|
1031
|
+
headers: this.headers()
|
|
1032
|
+
});
|
|
1033
|
+
if (res.status !== 200 && res.status !== 201) {
|
|
1034
|
+
throw new Error(`invalid createMSafeAccount return: ${res}`);
|
|
1035
|
+
}
|
|
1273
1036
|
}
|
|
1274
|
-
|
|
1275
|
-
|
|
1037
|
+
async proposeIntention(input) {
|
|
1038
|
+
const res = await axios.post(`${this.apiURL}/transaction/intention`, input, { headers: this.headers() });
|
|
1039
|
+
if (res.status !== 200 && res.status !== 201) {
|
|
1040
|
+
throw new Error(`invalid proposeIntention return: ${res}`);
|
|
1041
|
+
}
|
|
1276
1042
|
}
|
|
1277
|
-
|
|
1278
|
-
|
|
1043
|
+
// TODO later
|
|
1044
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
1045
|
+
async proposePendingTransaction(_input) {
|
|
1046
|
+
return void 0;
|
|
1279
1047
|
}
|
|
1280
|
-
async
|
|
1281
|
-
|
|
1048
|
+
async rejectCurrentTx(input) {
|
|
1049
|
+
const res = await axios.post(
|
|
1050
|
+
`${this.apiURL}/transaction/pending/reject`,
|
|
1051
|
+
{
|
|
1052
|
+
address: input.msafeAddress,
|
|
1053
|
+
digest: input.digest,
|
|
1054
|
+
signature: input.signature
|
|
1055
|
+
},
|
|
1056
|
+
{
|
|
1057
|
+
headers: this.headers()
|
|
1058
|
+
}
|
|
1059
|
+
);
|
|
1060
|
+
if (res.status !== 200 && res.status !== 201) {
|
|
1061
|
+
throw new Error(`invalid voteForTransaction return: ${res}`);
|
|
1062
|
+
}
|
|
1282
1063
|
}
|
|
1283
|
-
|
|
1284
|
-
|
|
1064
|
+
async voteForTransaction(input) {
|
|
1065
|
+
const res = await axios.post(
|
|
1066
|
+
`${this.apiURL}/transaction/pending/vote`,
|
|
1067
|
+
{
|
|
1068
|
+
address: input.msafeAddress,
|
|
1069
|
+
digest: input.txDigest,
|
|
1070
|
+
signature: input.signature
|
|
1071
|
+
},
|
|
1072
|
+
{
|
|
1073
|
+
headers: this.headers()
|
|
1074
|
+
}
|
|
1075
|
+
);
|
|
1076
|
+
if (res.status !== 200 && res.status !== 201) {
|
|
1077
|
+
throw new Error(`invalid voteForTransaction return: ${res}`);
|
|
1078
|
+
}
|
|
1285
1079
|
}
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1080
|
+
async buildNextIntentionAndAddToPending(input) {
|
|
1081
|
+
const res = await axios.post(
|
|
1082
|
+
`${this.apiURL}/transaction/pending/build`,
|
|
1083
|
+
{
|
|
1084
|
+
address: input.msafeAddress
|
|
1085
|
+
},
|
|
1086
|
+
{ headers: this.headers() }
|
|
1087
|
+
);
|
|
1088
|
+
if (res.status !== 200 && res.status !== 201) {
|
|
1089
|
+
throw new Error(`invalid buildNextIntentionAndAddToPending return: ${res}`);
|
|
1090
|
+
}
|
|
1293
1091
|
}
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1092
|
+
async skipNextFailedIntention(input) {
|
|
1093
|
+
const res = await axios.post(
|
|
1094
|
+
`${this.apiURL}/transaction/pending/skip`,
|
|
1095
|
+
{
|
|
1096
|
+
msafeAddress: input.msafeAddress
|
|
1097
|
+
},
|
|
1098
|
+
{ headers: this.headers() }
|
|
1099
|
+
);
|
|
1100
|
+
if (res.status !== 200 && res.status !== 201) {
|
|
1101
|
+
throw new Error(`invalid skipNextFailedIntention return: ${res}`);
|
|
1299
1102
|
}
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1103
|
+
}
|
|
1104
|
+
async getAddressBookEntries(pagination) {
|
|
1105
|
+
const res = await axios.get(`${this.apiURL}/address-book`, {
|
|
1106
|
+
headers: this.headers(),
|
|
1107
|
+
params: pagination
|
|
1108
|
+
});
|
|
1109
|
+
if (res.status !== 200) {
|
|
1110
|
+
throw new Error(`Invalid address-book return: ${res}`);
|
|
1303
1111
|
}
|
|
1304
|
-
return
|
|
1112
|
+
return res.data;
|
|
1305
1113
|
}
|
|
1306
|
-
async
|
|
1307
|
-
const
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
results[i] = this.knownPublicKeys.get(address);
|
|
1114
|
+
async updateAddressBook(input) {
|
|
1115
|
+
const res = await axios.post(`${this.apiURL}/address-book`, input, { headers: this.headers() });
|
|
1116
|
+
if (res.status !== 200 && res.status !== 201) {
|
|
1117
|
+
throw new Error(`invalid updateAddressBook return: ${res}`);
|
|
1311
1118
|
}
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1119
|
+
}
|
|
1120
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
1121
|
+
async processExecutedTransaction(_digest) {
|
|
1122
|
+
return void 0;
|
|
1123
|
+
}
|
|
1124
|
+
headers(token) {
|
|
1125
|
+
return { Authorization: `Bearer ${token || this._token}` };
|
|
1126
|
+
}
|
|
1127
|
+
};
|
|
1128
|
+
|
|
1129
|
+
// src/globals/const.ts
|
|
1130
|
+
var MSafeEnv = /* @__PURE__ */ ((MSafeEnv3) => {
|
|
1131
|
+
MSafeEnv3["local"] = "local";
|
|
1132
|
+
MSafeEnv3["unit"] = "unit";
|
|
1133
|
+
MSafeEnv3["dev"] = "dev";
|
|
1134
|
+
MSafeEnv3["prev"] = "prev";
|
|
1135
|
+
MSafeEnv3["prod"] = "prod";
|
|
1136
|
+
return MSafeEnv3;
|
|
1137
|
+
})(MSafeEnv || {});
|
|
1138
|
+
var MSAFE_APPLICATION = "msafe";
|
|
1139
|
+
var TESTNET_RPC_URL = "https://sui-testnet.blockvision.org/v1/2Sgk89ivT64MnKdcGzjmyjY2ndD";
|
|
1140
|
+
var MAINNET_RPC_URL = "https://sui-mainnet.blockvision.org/v1/2Sgk7NPvqkd7mESYkxF01yX15l7";
|
|
1141
|
+
var LOCAL_API_URL = "http://127.0.0.1:3000";
|
|
1142
|
+
var LOCAL_SYNCING_URL = "http://127.0.0.1:3001";
|
|
1143
|
+
var DEV_API_URL = "http://13.56.226.148";
|
|
1144
|
+
var DEV_SYNCING_URL = "http://52.53.228.20";
|
|
1145
|
+
var ENV_CONFIGS = /* @__PURE__ */ new Map([
|
|
1146
|
+
[
|
|
1147
|
+
"unit" /* unit */,
|
|
1148
|
+
{
|
|
1149
|
+
suiClient: {
|
|
1150
|
+
url: TESTNET_RPC_URL
|
|
1151
|
+
},
|
|
1152
|
+
backend: {
|
|
1153
|
+
url: LOCAL_API_URL
|
|
1154
|
+
},
|
|
1155
|
+
syncingURL: LOCAL_SYNCING_URL
|
|
1317
1156
|
}
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1157
|
+
],
|
|
1158
|
+
[
|
|
1159
|
+
"local" /* local */,
|
|
1160
|
+
{
|
|
1161
|
+
suiClient: {
|
|
1162
|
+
url: TESTNET_RPC_URL
|
|
1163
|
+
},
|
|
1164
|
+
backend: {
|
|
1165
|
+
url: LOCAL_API_URL
|
|
1166
|
+
},
|
|
1167
|
+
syncingURL: LOCAL_SYNCING_URL
|
|
1322
1168
|
}
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1169
|
+
],
|
|
1170
|
+
[
|
|
1171
|
+
"dev" /* dev */,
|
|
1172
|
+
{
|
|
1173
|
+
suiClient: {
|
|
1174
|
+
url: TESTNET_RPC_URL
|
|
1175
|
+
},
|
|
1176
|
+
backend: {
|
|
1177
|
+
url: DEV_API_URL
|
|
1178
|
+
},
|
|
1179
|
+
syncingURL: DEV_SYNCING_URL
|
|
1327
1180
|
}
|
|
1328
|
-
|
|
1181
|
+
]
|
|
1182
|
+
]);
|
|
1183
|
+
function getMSafeConfig(env, options) {
|
|
1184
|
+
const config = ENV_CONFIGS.get(env);
|
|
1185
|
+
if (!config) {
|
|
1186
|
+
throw new Error("Unknown environment");
|
|
1329
1187
|
}
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
if (pkBackend) {
|
|
1333
|
-
return pkBackend;
|
|
1334
|
-
}
|
|
1335
|
-
const pkChain = await this.getPublicKeyFromChain(address);
|
|
1336
|
-
if (pkChain) {
|
|
1337
|
-
return pkChain;
|
|
1338
|
-
}
|
|
1339
|
-
return void 0;
|
|
1188
|
+
if (options?.suiClient?.url) {
|
|
1189
|
+
config.suiClient.url = options.suiClient.url;
|
|
1340
1190
|
}
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1191
|
+
if (options?.backend?.url) {
|
|
1192
|
+
config.backend.url = options.backend.url;
|
|
1193
|
+
}
|
|
1194
|
+
return config;
|
|
1195
|
+
}
|
|
1196
|
+
|
|
1197
|
+
// src/globals/MSafeGlobals.ts
|
|
1198
|
+
var MSafeGlobals = class _MSafeGlobals {
|
|
1199
|
+
backend;
|
|
1200
|
+
suiClient;
|
|
1201
|
+
config;
|
|
1202
|
+
_wallet;
|
|
1203
|
+
constructor(input) {
|
|
1204
|
+
this.backend = input.backend;
|
|
1205
|
+
this.suiClient = input.suiClient;
|
|
1206
|
+
this.config = input.config;
|
|
1207
|
+
}
|
|
1208
|
+
static async New(env, options) {
|
|
1209
|
+
const config = getMSafeConfig(env, options);
|
|
1210
|
+
const suiClient = new SuiClient(config.suiClient);
|
|
1211
|
+
const backend = new BackendImpl(config.backend.url);
|
|
1212
|
+
return new _MSafeGlobals({
|
|
1213
|
+
backend,
|
|
1214
|
+
suiClient,
|
|
1215
|
+
config
|
|
1216
|
+
});
|
|
1217
|
+
}
|
|
1218
|
+
connectWallet(wallet) {
|
|
1219
|
+
this._wallet = wallet;
|
|
1220
|
+
}
|
|
1221
|
+
get wallet() {
|
|
1222
|
+
if (!this._wallet) {
|
|
1223
|
+
throw new Error("wallet not connected");
|
|
1347
1224
|
}
|
|
1225
|
+
return this._wallet;
|
|
1348
1226
|
}
|
|
1349
|
-
|
|
1350
|
-
|
|
1227
|
+
set wallet(val) {
|
|
1228
|
+
this._wallet = val;
|
|
1351
1229
|
}
|
|
1352
1230
|
};
|
|
1353
1231
|
|
|
@@ -1377,7 +1255,7 @@ var MSafeClient = class _MSafeClient {
|
|
|
1377
1255
|
return jwt;
|
|
1378
1256
|
}
|
|
1379
1257
|
async authSign(wallet) {
|
|
1380
|
-
const messageStr =
|
|
1258
|
+
const messageStr = SigningMessageHelper4.loginMessageWithTimestamp((/* @__PURE__ */ new Date()).toUTCString());
|
|
1381
1259
|
const sig = await wallet.signPersonalMessage({
|
|
1382
1260
|
messageStr
|
|
1383
1261
|
});
|
|
@@ -1389,7 +1267,10 @@ var MSafeClient = class _MSafeClient {
|
|
|
1389
1267
|
});
|
|
1390
1268
|
}
|
|
1391
1269
|
async userInfo() {
|
|
1392
|
-
return this.globals.backend.getUserInfo(
|
|
1270
|
+
return this.globals.backend.getUserInfo();
|
|
1271
|
+
}
|
|
1272
|
+
async ownedMSafe(pagination) {
|
|
1273
|
+
return this.globals.backend.getOwnedMSafeByStatus({ status: UserMSafeStatus2.active, pagination });
|
|
1393
1274
|
}
|
|
1394
1275
|
async createAccount(info) {
|
|
1395
1276
|
return this.creationHelper.submitMSafeCreation(info);
|
|
@@ -1427,33 +1308,26 @@ var MSafeClient = class _MSafeClient {
|
|
|
1427
1308
|
get AddressBook() {
|
|
1428
1309
|
return new AddressBookSDK(this.globals);
|
|
1429
1310
|
}
|
|
1311
|
+
get Invitation() {
|
|
1312
|
+
return new InvitationSDK(this.globals);
|
|
1313
|
+
}
|
|
1430
1314
|
async walletAddress() {
|
|
1431
1315
|
return this.wallet.address();
|
|
1432
1316
|
}
|
|
1433
1317
|
};
|
|
1434
|
-
|
|
1435
|
-
// src/types/address-book.ts
|
|
1436
|
-
var OpAddressBookType = /* @__PURE__ */ ((OpAddressBookType2) => {
|
|
1437
|
-
OpAddressBookType2["Delete"] = "delete";
|
|
1438
|
-
OpAddressBookType2["Upsert"] = "upsert";
|
|
1439
|
-
return OpAddressBookType2;
|
|
1440
|
-
})(OpAddressBookType || {});
|
|
1441
1318
|
export {
|
|
1442
|
-
AUTH_SIGN_MESSAGE,
|
|
1443
1319
|
AddressBookSDK,
|
|
1444
1320
|
COIN_TYPE_ARG_REGEX,
|
|
1445
1321
|
Coin,
|
|
1446
1322
|
CoinHelper,
|
|
1447
1323
|
CreateHelper,
|
|
1448
1324
|
DEV_API_URL,
|
|
1449
|
-
DEV_DATABASE_CONFIG,
|
|
1450
1325
|
DEV_SYNCING_URL,
|
|
1451
1326
|
ENV_CONFIGS,
|
|
1452
1327
|
Formatter,
|
|
1453
1328
|
HexToUint8Array,
|
|
1454
1329
|
IntentionHelper,
|
|
1455
1330
|
LOCAL_API_URL,
|
|
1456
|
-
LOCAL_DATABASE_CONFIG,
|
|
1457
1331
|
LOCAL_SYNCING_URL,
|
|
1458
1332
|
MAINNET_RPC_URL,
|
|
1459
1333
|
MSAFE_APPLICATION,
|
|
@@ -1461,13 +1335,9 @@ export {
|
|
|
1461
1335
|
MSafeClient,
|
|
1462
1336
|
MSafeEnv,
|
|
1463
1337
|
MSafeGlobals,
|
|
1464
|
-
MessageHelper,
|
|
1465
|
-
OpAddressBookType,
|
|
1466
|
-
PublicKeySerde,
|
|
1467
1338
|
SUI_COIN,
|
|
1468
1339
|
SignatureVerifier,
|
|
1469
1340
|
TESTNET_RPC_URL,
|
|
1470
|
-
UNIT_DATABASE_CONFIG,
|
|
1471
1341
|
Uint8ArrayToHex,
|
|
1472
1342
|
getAllCoins,
|
|
1473
1343
|
getMSafeConfig,
|