@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.js CHANGED
@@ -1,29 +1,107 @@
1
1
  // src/core/CreateHelper.ts
2
- import {
3
- createAccountCreationMessage,
4
- MultisigAccountManager,
5
- validateCreateAccountRequest
6
- } from "@msafe/sui3-utils";
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/utils/crypto.ts
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
- SIGNATURE_FLAG_TO_SCHEME
11
- } from "@mysten/sui.js/cryptography";
12
- import { Ed25519PublicKey } from "@mysten/sui.js/keypairs/ed25519";
13
- import { Secp256k1PublicKey } from "@mysten/sui.js/keypairs/secp256k1";
14
- import { Secp256r1PublicKey } from "@mysten/sui.js/keypairs/secp256r1";
15
- import { verifyPersonalMessage, verifyTransactionBlock } from "@mysten/sui.js/verify";
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/utils/buffer.ts
18
- function stringToBuffer(s) {
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 = PublicKeySerde.de({ publicKey: decoded.publicKey, scheme: decoded.signatureScheme });
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,87 +418,46 @@ var IntentionHelper = class {
458
418
  }
459
419
  };
460
420
 
461
- // src/core/MessageHelper.ts
462
- var MessageHelper = class {
463
- // Message used for MSafe creation
464
- static createMSafeMessage(msafeAddress) {
465
- return `Create MSafe Account: ${msafeAddress}`;
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
- const { msafeAddress, sequenceNumber, intentionData } = de;
498
- return {
499
- msafeAddress,
500
- sn: sequenceNumber,
501
- intention: IntentionHelper.de(intentionData)
502
- };
428
+ return verifyPersonalMessage(input.message, input.signature);
503
429
  }
504
- static updateAddressBookMessage(updates) {
505
- const normalized = updates.map((update) => ({
506
- ...update,
507
- address: normalizeSuiAddress2(update.address)
508
- }));
509
- function sortObjectKeys(obj) {
510
- return Object.keys(obj).sort().reduce((result, key) => ({ ...result, [key]: obj[key] }), {});
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
- // src/core/AddressBookSDK.ts
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 getEntries(pagination) {
529
- return this.globals.backend.getAddressBookEntries(pagination);
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 update(updates) {
532
- const messageStr = MessageHelper.updateAddressBookMessage(updates);
533
- const sig = await this.globals.wallet.signPersonalMessage({ messageStr });
534
- return this.globals.backend.updateAddressBook({ updates, signature: sig.signature });
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
+ });
535
458
  }
536
459
  };
537
460
 
538
- // src/core/MSafeAccount.ts
539
- import { buildIntentionTransaction, MultisigAccountManager as MultisigAccountManager2 } from "@msafe/sui3-utils";
540
- import { normalizeStructTag as normalizeStructTag3 } from "@mysten/sui.js/utils";
541
-
542
461
  // src/utils/iter/iterator.ts
543
462
  var REQUEST_PAGE_SIZE = 25;
544
463
  async function getAllFromIterator(it) {
@@ -667,21 +586,29 @@ var OwnedObjectRequester = class {
667
586
  };
668
587
 
669
588
  // src/core/MSafeAccount.ts
670
- var MSafeAccount = class {
589
+ var MSafeAccount = class _MSafeAccount {
671
590
  constructor(globals, info) {
672
591
  this.globals = globals;
673
592
  this.info = info;
674
- this.multisigManager = new MultisigAccountManager2({
593
+ this.multiSig = new MultiSigAccount2({
675
594
  threshold: info.threshold,
676
- ownersWithWeight: info.ownersWithWeightPK,
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
+ })),
677
600
  creationNonce: info.creationNonce
678
601
  });
679
602
  this.coinHelper = new CoinHelper(this.suiClient);
680
603
  }
681
- multisigManager;
604
+ multiSig;
682
605
  coinHelper;
683
- static async new(globals, address) {
684
- return globals.backend.getMSafeAccountInfo(address);
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
+ }
685
612
  }
686
613
  async ownedCoins() {
687
614
  const balances = await this.suiClient.getAllBalances({ owner: this.address });
@@ -735,7 +662,7 @@ var MSafeAccount = class {
735
662
  return this.backend.getNextSequenceNumber(this.address);
736
663
  }
737
664
  async proposeIntention(input) {
738
- const message = MessageHelper.proposeIntentionMessage({
665
+ const message = SigningMessageHelper3.proposeIntentionMessage({
739
666
  msafeAddress: this.address,
740
667
  intention: input.intention,
741
668
  sn: input.sequenceNumber
@@ -846,14 +773,14 @@ var MSafeAccount = class {
846
773
  throw new Error("Not enough signatures");
847
774
  }
848
775
  const sigs = [];
849
- for (let i = 0; i < this.info.ownersWithWeightPK.length; i++) {
850
- const owner = this.info.ownersWithWeightPK[i];
851
- const signature = gotSigs.get(owner.publicKey.toSuiAddress());
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);
852
779
  if (signature) {
853
780
  sigs.push(signature);
854
781
  }
855
782
  }
856
- const multiSignature = this.multisigManager.combinePartialSignatures(sigs);
783
+ const multiSignature = this.multiSig.combinePartialSignatures(sigs);
857
784
  return this.suiClient.executeTransactionBlock({
858
785
  transactionBlock: HexToUint8Array(payload),
859
786
  signature: multiSignature,
@@ -861,7 +788,7 @@ var MSafeAccount = class {
861
788
  });
862
789
  }
863
790
  get address() {
864
- return this.info.address;
791
+ return this.multiSig.address;
865
792
  }
866
793
  get backend() {
867
794
  return this.globals.backend;
@@ -902,6 +829,9 @@ var PublicKeyHelper = class {
902
829
  results[i] = this.knownPublicKeys.get(address);
903
830
  }
904
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
+ }
905
835
  const backendResult = await this.globals.backend.getPublicKeyBatch(emptyIndexes.map((index) => addresses[index]));
906
836
  for (let i = 0; i < emptyIndexes.length; i++) {
907
837
  const index = emptyIndexes[i];
@@ -947,6 +877,10 @@ var PublicKeyHelper = class {
947
877
  import { SuiClient } from "@mysten/sui.js/client";
948
878
 
949
879
  // src/backend/BackendImpl.ts
880
+ import {
881
+ PublicKeySerde as PublicKeySerde4,
882
+ UserMSafeStatus
883
+ } from "@msafe/sui3-utils";
950
884
  import axios from "axios";
951
885
  var BackendImpl = class {
952
886
  constructor(apiURL) {
@@ -976,75 +910,65 @@ var BackendImpl = class {
976
910
  return (await this.getPublicKeyBatch([address]))[0];
977
911
  }
978
912
  async getPublicKeyBatch(addresses) {
979
- const res = await axios.post(
980
- `${this.apiURL}/account/getPublicKeyBatch`,
981
- addresses,
982
- {
983
- headers: this.headers()
984
- }
985
- );
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
+ });
986
920
  if (res.status !== 200 && res.status !== 201) {
987
921
  throw new Error(`invalid getPublicKeyBatch return: ${res}`);
988
922
  }
989
923
  return res.data?.map(
990
- (publicKeyWithSchema) => publicKeyWithSchema ? PublicKeySerde.de({ ...publicKeyWithSchema }) : void 0
924
+ (publicKeyWithSchema) => publicKeyWithSchema ? PublicKeySerde4.de(publicKeyWithSchema) : void 0
991
925
  );
992
926
  }
993
927
  async getMSafeAccountInfo(msafeAddress) {
994
- const res = await axios.get(
995
- `${this.apiURL}/account/getMSafeAccountInfo/${msafeAddress}`,
996
- {
997
- headers: this.headers()
998
- }
999
- );
928
+ const q = {
929
+ msafeAddress
930
+ };
931
+ const res = await axios.get(`${this.apiURL}/msafe`, {
932
+ params: q,
933
+ headers: this.headers()
934
+ });
1000
935
  if (res.status !== 200 && res.status !== 201) {
1001
936
  throw new Error(`invalid getPublicKeyBatch return: ${res}`);
1002
937
  }
1003
- const msafeResp = res.data;
1004
- return {
1005
- address: msafeResp.address,
1006
- ownersWithWeightPK: msafeResp.ownersWithWeightPKEncoded.map(
1007
- (owner) => ({
1008
- publicKey: PublicKeySerde.de({ publicKey: owner.publicKeyEncoded, scheme: owner.schema }),
1009
- address: owner.address,
1010
- weight: owner.weight
1011
- })
1012
- ),
1013
- threshold: msafeResp.threshold,
1014
- name: msafeResp.name,
1015
- description: msafeResp.description,
1016
- creationNonce: msafeResp.creationNonce
1017
- };
938
+ return res.data;
1018
939
  }
1019
- async getUserInfo(userAddress) {
1020
- const res = await axios.get(`${this.apiURL}/account/user/${userAddress}`, {
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,
1021
959
  headers: this.headers()
1022
960
  });
1023
961
  if (res.status !== 200 && res.status !== 201) {
1024
- throw new Error(`invalid getPublicKeyBatch return: ${res}`);
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}`);
1025
971
  }
1026
- return {
1027
- address: res.data.address,
1028
- publicKey: res.data.publicKey,
1029
- schema: res.data.schema,
1030
- creationNonce: res.data.creationNonce,
1031
- ownedMSafe: res.data.ownedMSafe.map(
1032
- (msafe) => ({
1033
- address: msafe.address,
1034
- ownersWithWeightPK: msafe.ownersWithWeightPKEncoded.map(
1035
- (owner) => ({
1036
- publicKey: PublicKeySerde.de({ publicKey: owner.publicKeyEncoded, scheme: owner.schema }),
1037
- address: owner.address,
1038
- weight: owner.weight
1039
- })
1040
- ),
1041
- threshold: msafe.threshold,
1042
- name: msafe.name,
1043
- description: msafe.description,
1044
- creationNonce: msafe.creationNonce
1045
- })
1046
- )
1047
- };
1048
972
  }
1049
973
  async getPendingTransactions(msafeAddress) {
1050
974
  const res = await axios.get(`${this.apiURL}/transaction/pending/${msafeAddress}`, {
@@ -1103,7 +1027,7 @@ var BackendImpl = class {
1103
1027
  return res.data;
1104
1028
  }
1105
1029
  async createMSafeAccount(input) {
1106
- const res = await axios.post(`${this.apiURL}/account`, input, {
1030
+ const res = await axios.post(`${this.apiURL}/msafe/create`, input, {
1107
1031
  headers: this.headers()
1108
1032
  });
1109
1033
  if (res.status !== 200 && res.status !== 201) {
@@ -1111,36 +1035,30 @@ var BackendImpl = class {
1111
1035
  }
1112
1036
  }
1113
1037
  async proposeIntention(input) {
1114
- try {
1115
- const res = await axios.post(`${this.apiURL}/transaction/intention`, input, { headers: this.headers() });
1116
- if (res.status !== 200 && res.status !== 201) {
1117
- throw new Error(`invalid proposeIntention return: ${res}`);
1118
- }
1119
- } catch (e) {
1120
- console.log(e);
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}`);
1121
1041
  }
1122
1042
  }
1123
1043
  // TODO later
1124
- async proposePendingTransaction(input) {
1044
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1045
+ async proposePendingTransaction(_input) {
1046
+ return void 0;
1125
1047
  }
1126
1048
  async rejectCurrentTx(input) {
1127
- try {
1128
- const res = await axios.post(
1129
- `${this.apiURL}/transaction/pending/reject`,
1130
- {
1131
- address: input.msafeAddress,
1132
- digest: input.digest,
1133
- signature: input.signature
1134
- },
1135
- {
1136
- headers: this.headers()
1137
- }
1138
- );
1139
- if (res.status !== 200 && res.status !== 201) {
1140
- throw new Error(`invalid voteForTransaction return: ${res}`);
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()
1141
1058
  }
1142
- } catch (e) {
1143
- console.log("e:", e);
1059
+ );
1060
+ if (res.status !== 200 && res.status !== 201) {
1061
+ throw new Error(`invalid voteForTransaction return: ${res}`);
1144
1062
  }
1145
1063
  }
1146
1064
  async voteForTransaction(input) {
@@ -1199,7 +1117,9 @@ var BackendImpl = class {
1199
1117
  throw new Error(`invalid updateAddressBook return: ${res}`);
1200
1118
  }
1201
1119
  }
1202
- async processExecutedTransaction(digest) {
1120
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1121
+ async processExecutedTransaction(_digest) {
1122
+ return void 0;
1203
1123
  }
1204
1124
  headers(token) {
1205
1125
  return { Authorization: `Bearer ${token || this._token}` };
@@ -1215,29 +1135,6 @@ var MSafeEnv = /* @__PURE__ */ ((MSafeEnv3) => {
1215
1135
  MSafeEnv3["prod"] = "prod";
1216
1136
  return MSafeEnv3;
1217
1137
  })(MSafeEnv || {});
1218
- var UNIT_DATABASE_CONFIG = {
1219
- type: "sqlite",
1220
- database: ":memory:",
1221
- logging: false
1222
- };
1223
- var LOCAL_DATABASE_CONFIG = {
1224
- type: "mysql",
1225
- host: "127.0.0.1",
1226
- port: 3306,
1227
- username: "msafe",
1228
- password: "msafe",
1229
- database: "msafe_sui_local",
1230
- logging: false
1231
- };
1232
- var DEV_DATABASE_CONFIG = {
1233
- type: "mysql",
1234
- host: "msafe-dev-database.cluster-caos3ssocrx6.us-west-1.rds.amazonaws.com",
1235
- port: 3306,
1236
- username: "msafe",
1237
- password: "Momentum.Safe2022",
1238
- database: "msafe_sui_dev",
1239
- logging: false
1240
- };
1241
1138
  var MSAFE_APPLICATION = "msafe";
1242
1139
  var TESTNET_RPC_URL = "https://sui-testnet.blockvision.org/v1/2Sgk89ivT64MnKdcGzjmyjY2ndD";
1243
1140
  var MAINNET_RPC_URL = "https://sui-mainnet.blockvision.org/v1/2Sgk7NPvqkd7mESYkxF01yX15l7";
@@ -1252,8 +1149,9 @@ var ENV_CONFIGS = /* @__PURE__ */ new Map([
1252
1149
  suiClient: {
1253
1150
  url: TESTNET_RPC_URL
1254
1151
  },
1255
- backend: LOCAL_DATABASE_CONFIG,
1256
- apiURL: LOCAL_API_URL,
1152
+ backend: {
1153
+ url: LOCAL_API_URL
1154
+ },
1257
1155
  syncingURL: LOCAL_SYNCING_URL
1258
1156
  }
1259
1157
  ],
@@ -1263,8 +1161,9 @@ var ENV_CONFIGS = /* @__PURE__ */ new Map([
1263
1161
  suiClient: {
1264
1162
  url: TESTNET_RPC_URL
1265
1163
  },
1266
- backend: LOCAL_DATABASE_CONFIG,
1267
- apiURL: LOCAL_API_URL,
1164
+ backend: {
1165
+ url: LOCAL_API_URL
1166
+ },
1268
1167
  syncingURL: LOCAL_SYNCING_URL
1269
1168
  }
1270
1169
  ],
@@ -1274,8 +1173,9 @@ var ENV_CONFIGS = /* @__PURE__ */ new Map([
1274
1173
  suiClient: {
1275
1174
  url: TESTNET_RPC_URL
1276
1175
  },
1277
- backend: DEV_DATABASE_CONFIG,
1278
- apiURL: DEV_API_URL,
1176
+ backend: {
1177
+ url: DEV_API_URL
1178
+ },
1279
1179
  syncingURL: DEV_SYNCING_URL
1280
1180
  }
1281
1181
  ]
@@ -1288,12 +1188,11 @@ function getMSafeConfig(env, options) {
1288
1188
  if (options?.suiClient?.url) {
1289
1189
  config.suiClient.url = options.suiClient.url;
1290
1190
  }
1291
- if (options?.backend) {
1292
- config.backend = options.backend;
1191
+ if (options?.backend?.url) {
1192
+ config.backend.url = options.backend.url;
1293
1193
  }
1294
1194
  return config;
1295
1195
  }
1296
- var AUTH_SIGN_MESSAGE = "Welcome to MSafe";
1297
1196
 
1298
1197
  // src/globals/MSafeGlobals.ts
1299
1198
  var MSafeGlobals = class _MSafeGlobals {
@@ -1309,7 +1208,7 @@ var MSafeGlobals = class _MSafeGlobals {
1309
1208
  static async New(env, options) {
1310
1209
  const config = getMSafeConfig(env, options);
1311
1210
  const suiClient = new SuiClient(config.suiClient);
1312
- const backend = new BackendImpl(config.apiURL);
1211
+ const backend = new BackendImpl(config.backend.url);
1313
1212
  return new _MSafeGlobals({
1314
1213
  backend,
1315
1214
  suiClient,
@@ -1356,7 +1255,7 @@ var MSafeClient = class _MSafeClient {
1356
1255
  return jwt;
1357
1256
  }
1358
1257
  async authSign(wallet) {
1359
- const messageStr = MessageHelper.welcomeMessage((/* @__PURE__ */ new Date()).toUTCString());
1258
+ const messageStr = SigningMessageHelper4.loginMessageWithTimestamp((/* @__PURE__ */ new Date()).toUTCString());
1360
1259
  const sig = await wallet.signPersonalMessage({
1361
1260
  messageStr
1362
1261
  });
@@ -1368,7 +1267,10 @@ var MSafeClient = class _MSafeClient {
1368
1267
  });
1369
1268
  }
1370
1269
  async userInfo() {
1371
- return this.globals.backend.getUserInfo(await this.walletAddress());
1270
+ return this.globals.backend.getUserInfo();
1271
+ }
1272
+ async ownedMSafe(pagination) {
1273
+ return this.globals.backend.getOwnedMSafeByStatus({ status: UserMSafeStatus2.active, pagination });
1372
1274
  }
1373
1275
  async createAccount(info) {
1374
1276
  return this.creationHelper.submitMSafeCreation(info);
@@ -1406,33 +1308,26 @@ var MSafeClient = class _MSafeClient {
1406
1308
  get AddressBook() {
1407
1309
  return new AddressBookSDK(this.globals);
1408
1310
  }
1311
+ get Invitation() {
1312
+ return new InvitationSDK(this.globals);
1313
+ }
1409
1314
  async walletAddress() {
1410
1315
  return this.wallet.address();
1411
1316
  }
1412
1317
  };
1413
-
1414
- // src/types/address-book.ts
1415
- var OpAddressBookType = /* @__PURE__ */ ((OpAddressBookType2) => {
1416
- OpAddressBookType2["Delete"] = "delete";
1417
- OpAddressBookType2["Upsert"] = "upsert";
1418
- return OpAddressBookType2;
1419
- })(OpAddressBookType || {});
1420
1318
  export {
1421
- AUTH_SIGN_MESSAGE,
1422
1319
  AddressBookSDK,
1423
1320
  COIN_TYPE_ARG_REGEX,
1424
1321
  Coin,
1425
1322
  CoinHelper,
1426
1323
  CreateHelper,
1427
1324
  DEV_API_URL,
1428
- DEV_DATABASE_CONFIG,
1429
1325
  DEV_SYNCING_URL,
1430
1326
  ENV_CONFIGS,
1431
1327
  Formatter,
1432
1328
  HexToUint8Array,
1433
1329
  IntentionHelper,
1434
1330
  LOCAL_API_URL,
1435
- LOCAL_DATABASE_CONFIG,
1436
1331
  LOCAL_SYNCING_URL,
1437
1332
  MAINNET_RPC_URL,
1438
1333
  MSAFE_APPLICATION,
@@ -1440,13 +1335,9 @@ export {
1440
1335
  MSafeClient,
1441
1336
  MSafeEnv,
1442
1337
  MSafeGlobals,
1443
- MessageHelper,
1444
- OpAddressBookType,
1445
- PublicKeySerde,
1446
1338
  SUI_COIN,
1447
1339
  SignatureVerifier,
1448
1340
  TESTNET_RPC_URL,
1449
- UNIT_DATABASE_CONFIG,
1450
1341
  Uint8ArrayToHex,
1451
1342
  getAllCoins,
1452
1343
  getMSafeConfig,