@msafe/sui3-sdk 0.0.13 → 0.0.15-pre-3144325.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,29 +1,109 @@
1
1
  // src/core/CreateHelper.ts
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
+ };
61
+
62
+ // src/core/MSafeClient.ts
2
63
  import {
3
- createAccountCreationMessage,
4
- MultisigAccountManager,
5
- validateCreateAccountRequest
64
+ SigningMessageHelper as SigningMessageHelper4,
65
+ UserMSafeStatus as UserMSafeStatus2
6
66
  } from "@msafe/sui3-utils";
7
67
 
8
- // src/utils/crypto.ts
68
+ // src/core/AddressBookSDK.ts
69
+ import { SigningMessageHelper as SigningMessageHelper2 } from "@msafe/sui3-utils";
70
+ var AddressBookSDK = class {
71
+ constructor(globals) {
72
+ this.globals = globals;
73
+ }
74
+ async getEntries(pagination) {
75
+ return this.globals.backend.getAddressBookEntries(pagination);
76
+ }
77
+ async update(updates) {
78
+ const messageStr = SigningMessageHelper2.updateAddressBookMessage(updates);
79
+ const sig = await this.globals.wallet.signPersonalMessage({ messageStr });
80
+ return this.globals.backend.updateAddressBook({ updates, signature: sig.signature });
81
+ }
82
+ };
83
+
84
+ // src/core/InvitationSDK.ts
85
+ var InvitationSDK = class {
86
+ constructor(globals) {
87
+ this.globals = globals;
88
+ }
89
+ async getMSafeByStatus(status, pagination) {
90
+ return this.globals.backend.getOwnedMSafeByStatus({ status, pagination });
91
+ }
92
+ async updateMSafeStatus(msafeAddress, status) {
93
+ return this.globals.backend.updateMSafeStatus({ msafeAddress, status });
94
+ }
95
+ };
96
+
97
+ // src/core/MSafeAccount.ts
9
98
  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";
99
+ buildIntentionTransaction,
100
+ MultiSigAccount as MultiSigAccount2,
101
+ SigningMessageHelper as SigningMessageHelper3
102
+ } from "@msafe/sui3-utils";
103
+ import { normalizeStructTag as normalizeStructTag3 } from "@mysten/sui.js/utils";
16
104
 
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
- }
105
+ // src/transactions/coin-transfer.ts
106
+ import { TransactionBlock } from "@mysten/sui.js/transactions";
27
107
 
28
108
  // src/utils/format.ts
29
109
  import { normalizeSuiAddress, normalizeStructTag as normalizeStructTag2 } from "@mysten/sui.js/utils";
@@ -99,139 +179,8 @@ var Formatter = class {
99
179
  }
100
180
  };
101
181
 
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
182
  // src/utils/sui.ts
183
+ import { PublicKeySerde as PublicKeySerde2 } from "@msafe/sui3-utils";
235
184
  import { parseSerializedSignature } from "@mysten/sui.js/cryptography";
236
185
  import { MultiSigPublicKey } from "@mysten/sui.js/multisig";
237
186
  var SUI_COIN = "0x2::sui::SUI";
@@ -281,7 +230,7 @@ function getAddressFromSignatures(serializedSig, targetAddress) {
281
230
  case "ED25519":
282
231
  case "Secp256k1":
283
232
  case "Secp256r1": {
284
- const pk = PublicKeySerde.de({ publicKey: decoded.publicKey, scheme: decoded.signatureScheme });
233
+ const pk = PublicKeySerde2.de({ publicKeyEncoded: decoded.publicKey, schema: decoded.signatureScheme });
285
234
  if (Formatter.isSuiAddressEqual(pk.toSuiAddress(), targetAddress)) {
286
235
  return pk;
287
236
  }
@@ -394,6 +343,19 @@ function getAddressOwner(object) {
394
343
 
395
344
  // src/transactions/reject.ts
396
345
  import { TransactionBlock as TransactionBlock3 } from "@mysten/sui.js/transactions";
346
+
347
+ // src/utils/buffer.ts
348
+ function stringToBuffer(s) {
349
+ return Buffer.from(s, "utf-8");
350
+ }
351
+ function Uint8ArrayToHex(b) {
352
+ return `0x${Array.prototype.map.call(b, (x) => `0${x.toString(16)}`.slice(-2)).join("")}`;
353
+ }
354
+ function HexToUint8Array(hex) {
355
+ return Uint8Array.from(Buffer.from(hex.startsWith("0x") ? hex.slice(2) : hex, "hex"));
356
+ }
357
+
358
+ // src/transactions/reject.ts
397
359
  async function buildRejectTxb(input) {
398
360
  const approveTxb = TransactionBlock3.from(HexToUint8Array(input.payloadToReject));
399
361
  const gasPayment = approveTxb.blockData.gasConfig.payment;
@@ -458,87 +420,46 @@ var IntentionHelper = class {
458
420
  }
459
421
  };
460
422
 
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");
423
+ // src/utils/crypto.ts
424
+ import { verifyPersonalMessage, verifyTransactionBlock } from "@mysten/sui.js/verify";
425
+ var SignatureVerifier = class _SignatureVerifier {
426
+ static async getPublicKeyFromSignature(input) {
427
+ if (input.messageType === "TransactionBlock") {
428
+ return verifyTransactionBlock(input.message, input.signature);
496
429
  }
497
- const { msafeAddress, sequenceNumber, intentionData } = de;
498
- return {
499
- msafeAddress,
500
- sn: sequenceNumber,
501
- intention: IntentionHelper.de(intentionData)
502
- };
430
+ return verifyPersonalMessage(input.message, input.signature);
503
431
  }
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}`;
432
+ static async getPublicKeyFromPersonalSignature(input) {
433
+ const message = stringToBuffer(input.messageStr);
434
+ return this.getPublicKeyFromSignature({
435
+ message,
436
+ messageType: "Personal",
437
+ signature: input.signature
438
+ });
520
439
  }
521
- };
522
-
523
- // src/core/AddressBookSDK.ts
524
- var AddressBookSDK = class {
525
- constructor(globals) {
526
- this.globals = globals;
440
+ static async verifySignature(input) {
441
+ const publicKey = await _SignatureVerifier.getPublicKeyFromSignature(input);
442
+ return Formatter.isSuiAddressEqual(publicKey.toSuiAddress(), input.targetAddress);
527
443
  }
528
- async getEntries(pagination) {
529
- return this.globals.backend.getAddressBookEntries(pagination);
444
+ static async verifyPersonalSignature(input) {
445
+ const message = stringToBuffer(input.messageStr);
446
+ return this.verifySignature({
447
+ message,
448
+ messageType: "Personal",
449
+ signature: input.signature,
450
+ targetAddress: input.targetAddress
451
+ });
530
452
  }
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 });
453
+ static async verifyTransactionSignature(input) {
454
+ return this.verifySignature({
455
+ messageType: "TransactionBlock",
456
+ message: input.payload,
457
+ signature: input.signature,
458
+ targetAddress: input.targetAddress
459
+ });
535
460
  }
536
461
  };
537
462
 
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
463
  // src/utils/iter/iterator.ts
543
464
  var REQUEST_PAGE_SIZE = 25;
544
465
  async function getAllFromIterator(it) {
@@ -667,21 +588,25 @@ var OwnedObjectRequester = class {
667
588
  };
668
589
 
669
590
  // src/core/MSafeAccount.ts
670
- var MSafeAccount = class {
591
+ var MSafeAccount = class _MSafeAccount {
671
592
  constructor(globals, info) {
672
593
  this.globals = globals;
673
594
  this.info = info;
674
- this.multisigManager = new MultisigAccountManager2({
595
+ this.multiSig = new MultiSigAccount2({
675
596
  threshold: info.threshold,
676
- ownersWithWeight: info.ownersWithWeightPK,
597
+ ownersWithWeight: info.owners,
677
598
  creationNonce: info.creationNonce
678
599
  });
679
600
  this.coinHelper = new CoinHelper(this.suiClient);
680
601
  }
681
- multisigManager;
602
+ multiSig;
682
603
  coinHelper;
683
- static async new(globals, address) {
684
- return globals.backend.getMSafeAccountInfo(address);
604
+ static async New(globals, address) {
605
+ const info = await globals.backend.getMSafeAccountInfo(address);
606
+ const ms = new _MSafeAccount(globals, info);
607
+ if (ms.address !== address) {
608
+ throw new Error("Invalid msafe config with address");
609
+ }
685
610
  }
686
611
  async ownedCoins() {
687
612
  const balances = await this.suiClient.getAllBalances({ owner: this.address });
@@ -735,7 +660,7 @@ var MSafeAccount = class {
735
660
  return this.backend.getNextSequenceNumber(this.address);
736
661
  }
737
662
  async proposeIntention(input) {
738
- const message = MessageHelper.proposeIntentionMessage({
663
+ const message = SigningMessageHelper3.proposeIntentionMessage({
739
664
  msafeAddress: this.address,
740
665
  intention: input.intention,
741
666
  sn: input.sequenceNumber
@@ -846,14 +771,14 @@ var MSafeAccount = class {
846
771
  throw new Error("Not enough signatures");
847
772
  }
848
773
  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());
774
+ for (let i = 0; i < this.info.owners.length; i++) {
775
+ const owner = this.info.owners[i];
776
+ const signature = gotSigs.get(owner.address);
852
777
  if (signature) {
853
778
  sigs.push(signature);
854
779
  }
855
780
  }
856
- const multiSignature = this.multisigManager.combinePartialSignatures(sigs);
781
+ const multiSignature = this.multiSig.combinePartialSignatures(sigs);
857
782
  return this.suiClient.executeTransactionBlock({
858
783
  transactionBlock: HexToUint8Array(payload),
859
784
  signature: multiSignature,
@@ -861,7 +786,7 @@ var MSafeAccount = class {
861
786
  });
862
787
  }
863
788
  get address() {
864
- return this.info.address;
789
+ return this.multiSig.address;
865
790
  }
866
791
  get backend() {
867
792
  return this.globals.backend;
@@ -902,6 +827,9 @@ var PublicKeyHelper = class {
902
827
  results[i] = this.knownPublicKeys.get(address);
903
828
  }
904
829
  const emptyIndexes = results.map((elem, index) => elem === void 0 ? index : -1).filter((index) => index !== -1);
830
+ if (emptyIndexes.length === 0) {
831
+ return results;
832
+ }
905
833
  const backendResult = await this.globals.backend.getPublicKeyBatch(emptyIndexes.map((index) => addresses[index]));
906
834
  for (let i = 0; i < emptyIndexes.length; i++) {
907
835
  const index = emptyIndexes[i];
@@ -947,8 +875,12 @@ var PublicKeyHelper = class {
947
875
  import { SuiClient } from "@mysten/sui.js/client";
948
876
 
949
877
  // src/backend/BackendImpl.ts
878
+ import {
879
+ PublicKeySerde as PublicKeySerde3,
880
+ UserMSafeStatus
881
+ } from "@msafe/sui3-utils";
950
882
  import axios from "axios";
951
- var BackendImpl = class {
883
+ var BackendImpl = class _BackendImpl {
952
884
  constructor(apiURL) {
953
885
  this.apiURL = apiURL;
954
886
  }
@@ -976,76 +908,69 @@ var BackendImpl = class {
976
908
  return (await this.getPublicKeyBatch([address]))[0];
977
909
  }
978
910
  async getPublicKeyBatch(addresses) {
979
- const res = await axios.post(
980
- `${this.apiURL}/account/getPublicKeyBatch`,
981
- addresses,
982
- {
983
- headers: this.headers()
984
- }
985
- );
911
+ const query = {
912
+ userAddressList: addresses
913
+ };
914
+ const res = await axios.get(`${this.apiURL}/user/public-keys`, {
915
+ params: query,
916
+ headers: this.headers()
917
+ });
986
918
  if (res.status !== 200 && res.status !== 201) {
987
919
  throw new Error(`invalid getPublicKeyBatch return: ${res}`);
988
920
  }
989
921
  return res.data?.map(
990
- (publicKeyWithSchema) => publicKeyWithSchema ? PublicKeySerde.de({ ...publicKeyWithSchema }) : void 0
922
+ (publicKeyWithSchema) => publicKeyWithSchema ? PublicKeySerde3.de(publicKeyWithSchema) : void 0
991
923
  );
992
924
  }
993
925
  async getMSafeAccountInfo(msafeAddress) {
994
- const res = await axios.get(
995
- `${this.apiURL}/account/getMSafeAccountInfo/${msafeAddress}`,
996
- {
997
- headers: this.headers()
998
- }
999
- );
926
+ const q = {
927
+ msafeAddress
928
+ };
929
+ const res = await axios.get(`${this.apiURL}/msafe`, {
930
+ params: q,
931
+ headers: this.headers()
932
+ });
1000
933
  if (res.status !== 200 && res.status !== 201) {
1001
934
  throw new Error(`invalid getPublicKeyBatch return: ${res}`);
1002
935
  }
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
- };
936
+ return _BackendImpl.toMSafeConfig(res.data);
1018
937
  }
1019
- async getUserInfo(userAddress) {
1020
- const res = await axios.get(`${this.apiURL}/account/user/${userAddress}`, {
938
+ async getUserInfo() {
939
+ const userRes = await axios.get(`${this.apiURL}/user`, {
940
+ headers: this.headers()
941
+ });
942
+ if (userRes.status !== 200 && userRes.status !== 201) {
943
+ throw new Error(`invalid getPublicKeyBatch return: ${userRes}`);
944
+ }
945
+ return userRes.data;
946
+ }
947
+ async getOwnedMSafeByStatus(input) {
948
+ const q = {
949
+ status: input.status ?? UserMSafeStatus.active,
950
+ ...input.pagination ? {
951
+ page: input.pagination.page.toString(),
952
+ limit: input.pagination.limit.toString()
953
+ } : {}
954
+ };
955
+ const res = await axios.get(`${this.apiURL}/msafe/owned`, {
956
+ params: q,
1021
957
  headers: this.headers()
1022
958
  });
1023
959
  if (res.status !== 200 && res.status !== 201) {
1024
- throw new Error(`invalid getPublicKeyBatch return: ${res}`);
960
+ throw new Error(`invalid getOwnedMSafeByStatus return: ${res}`);
1025
961
  }
1026
962
  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
- )
963
+ data: res.data.data.map(_BackendImpl.toMSafeConfig),
964
+ meta: res.data.meta
1047
965
  };
1048
966
  }
967
+ async updateMSafeStatus(input) {
968
+ const p = input;
969
+ const res = await axios.post(`${this.apiURL}/msafe/status`, p, { headers: this.headers() });
970
+ if (res.status !== 200 && res.status !== 201) {
971
+ throw new Error(`Invalid updateMSafeStatus return: ${res}`);
972
+ }
973
+ }
1049
974
  async getPendingTransactions(msafeAddress) {
1050
975
  const res = await axios.get(`${this.apiURL}/transaction/pending/${msafeAddress}`, {
1051
976
  headers: this.headers()
@@ -1103,7 +1028,7 @@ var BackendImpl = class {
1103
1028
  return res.data;
1104
1029
  }
1105
1030
  async createMSafeAccount(input) {
1106
- const res = await axios.post(`${this.apiURL}/account`, input, {
1031
+ const res = await axios.post(`${this.apiURL}/msafe/create`, input, {
1107
1032
  headers: this.headers()
1108
1033
  });
1109
1034
  if (res.status !== 200 && res.status !== 201) {
@@ -1111,36 +1036,30 @@ var BackendImpl = class {
1111
1036
  }
1112
1037
  }
1113
1038
  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);
1039
+ const res = await axios.post(`${this.apiURL}/transaction/intention`, input, { headers: this.headers() });
1040
+ if (res.status !== 200 && res.status !== 201) {
1041
+ throw new Error(`invalid proposeIntention return: ${res}`);
1121
1042
  }
1122
1043
  }
1123
1044
  // TODO later
1124
- async proposePendingTransaction(input) {
1045
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1046
+ async proposePendingTransaction(_input) {
1047
+ return void 0;
1125
1048
  }
1126
1049
  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}`);
1050
+ const res = await axios.post(
1051
+ `${this.apiURL}/transaction/pending/reject`,
1052
+ {
1053
+ address: input.msafeAddress,
1054
+ digest: input.digest,
1055
+ signature: input.signature
1056
+ },
1057
+ {
1058
+ headers: this.headers()
1141
1059
  }
1142
- } catch (e) {
1143
- console.log("e:", e);
1060
+ );
1061
+ if (res.status !== 200 && res.status !== 201) {
1062
+ throw new Error(`invalid voteForTransaction return: ${res}`);
1144
1063
  }
1145
1064
  }
1146
1065
  async voteForTransaction(input) {
@@ -1199,11 +1118,26 @@ var BackendImpl = class {
1199
1118
  throw new Error(`invalid updateAddressBook return: ${res}`);
1200
1119
  }
1201
1120
  }
1202
- async processExecutedTransaction(digest) {
1121
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1122
+ async processExecutedTransaction(_digest) {
1123
+ return void 0;
1203
1124
  }
1204
1125
  headers(token) {
1205
1126
  return { Authorization: `Bearer ${token || this._token}` };
1206
1127
  }
1128
+ static toMSafeConfig(resp) {
1129
+ return {
1130
+ ...resp,
1131
+ owners: resp.owners.map((owner) => ({
1132
+ address: owner.address,
1133
+ weight: owner.weight,
1134
+ publicKey: PublicKeySerde3.de({
1135
+ publicKeyEncoded: owner.publicKeyEncoded,
1136
+ schema: owner.schema
1137
+ })
1138
+ }))
1139
+ };
1140
+ }
1207
1141
  };
1208
1142
 
1209
1143
  // src/globals/const.ts
@@ -1215,29 +1149,6 @@ var MSafeEnv = /* @__PURE__ */ ((MSafeEnv3) => {
1215
1149
  MSafeEnv3["prod"] = "prod";
1216
1150
  return MSafeEnv3;
1217
1151
  })(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
1152
  var MSAFE_APPLICATION = "msafe";
1242
1153
  var TESTNET_RPC_URL = "https://sui-testnet.blockvision.org/v1/2Sgk89ivT64MnKdcGzjmyjY2ndD";
1243
1154
  var MAINNET_RPC_URL = "https://sui-mainnet.blockvision.org/v1/2Sgk7NPvqkd7mESYkxF01yX15l7";
@@ -1252,8 +1163,9 @@ var ENV_CONFIGS = /* @__PURE__ */ new Map([
1252
1163
  suiClient: {
1253
1164
  url: TESTNET_RPC_URL
1254
1165
  },
1255
- backend: LOCAL_DATABASE_CONFIG,
1256
- apiURL: LOCAL_API_URL,
1166
+ backend: {
1167
+ url: LOCAL_API_URL
1168
+ },
1257
1169
  syncingURL: LOCAL_SYNCING_URL
1258
1170
  }
1259
1171
  ],
@@ -1263,8 +1175,9 @@ var ENV_CONFIGS = /* @__PURE__ */ new Map([
1263
1175
  suiClient: {
1264
1176
  url: TESTNET_RPC_URL
1265
1177
  },
1266
- backend: LOCAL_DATABASE_CONFIG,
1267
- apiURL: LOCAL_API_URL,
1178
+ backend: {
1179
+ url: LOCAL_API_URL
1180
+ },
1268
1181
  syncingURL: LOCAL_SYNCING_URL
1269
1182
  }
1270
1183
  ],
@@ -1274,8 +1187,9 @@ var ENV_CONFIGS = /* @__PURE__ */ new Map([
1274
1187
  suiClient: {
1275
1188
  url: TESTNET_RPC_URL
1276
1189
  },
1277
- backend: DEV_DATABASE_CONFIG,
1278
- apiURL: DEV_API_URL,
1190
+ backend: {
1191
+ url: DEV_API_URL
1192
+ },
1279
1193
  syncingURL: DEV_SYNCING_URL
1280
1194
  }
1281
1195
  ]
@@ -1288,12 +1202,11 @@ function getMSafeConfig(env, options) {
1288
1202
  if (options?.suiClient?.url) {
1289
1203
  config.suiClient.url = options.suiClient.url;
1290
1204
  }
1291
- if (options?.backend) {
1292
- config.backend = options.backend;
1205
+ if (options?.backend?.url) {
1206
+ config.backend.url = options.backend.url;
1293
1207
  }
1294
1208
  return config;
1295
1209
  }
1296
- var AUTH_SIGN_MESSAGE = "Welcome to MSafe";
1297
1210
 
1298
1211
  // src/globals/MSafeGlobals.ts
1299
1212
  var MSafeGlobals = class _MSafeGlobals {
@@ -1309,7 +1222,7 @@ var MSafeGlobals = class _MSafeGlobals {
1309
1222
  static async New(env, options) {
1310
1223
  const config = getMSafeConfig(env, options);
1311
1224
  const suiClient = new SuiClient(config.suiClient);
1312
- const backend = new BackendImpl(config.apiURL);
1225
+ const backend = new BackendImpl(config.backend.url);
1313
1226
  return new _MSafeGlobals({
1314
1227
  backend,
1315
1228
  suiClient,
@@ -1356,7 +1269,7 @@ var MSafeClient = class _MSafeClient {
1356
1269
  return jwt;
1357
1270
  }
1358
1271
  async authSign(wallet) {
1359
- const messageStr = MessageHelper.welcomeMessage((/* @__PURE__ */ new Date()).toUTCString());
1272
+ const messageStr = SigningMessageHelper4.loginMessageWithTimestamp((/* @__PURE__ */ new Date()).toUTCString());
1360
1273
  const sig = await wallet.signPersonalMessage({
1361
1274
  messageStr
1362
1275
  });
@@ -1368,7 +1281,10 @@ var MSafeClient = class _MSafeClient {
1368
1281
  });
1369
1282
  }
1370
1283
  async userInfo() {
1371
- return this.globals.backend.getUserInfo(await this.walletAddress());
1284
+ return this.globals.backend.getUserInfo();
1285
+ }
1286
+ async ownedMSafe(pagination) {
1287
+ return this.globals.backend.getOwnedMSafeByStatus({ status: UserMSafeStatus2.active, pagination });
1372
1288
  }
1373
1289
  async createAccount(info) {
1374
1290
  return this.creationHelper.submitMSafeCreation(info);
@@ -1406,33 +1322,26 @@ var MSafeClient = class _MSafeClient {
1406
1322
  get AddressBook() {
1407
1323
  return new AddressBookSDK(this.globals);
1408
1324
  }
1325
+ get Invitation() {
1326
+ return new InvitationSDK(this.globals);
1327
+ }
1409
1328
  async walletAddress() {
1410
1329
  return this.wallet.address();
1411
1330
  }
1412
1331
  };
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
1332
  export {
1421
- AUTH_SIGN_MESSAGE,
1422
1333
  AddressBookSDK,
1423
1334
  COIN_TYPE_ARG_REGEX,
1424
1335
  Coin,
1425
1336
  CoinHelper,
1426
1337
  CreateHelper,
1427
1338
  DEV_API_URL,
1428
- DEV_DATABASE_CONFIG,
1429
1339
  DEV_SYNCING_URL,
1430
1340
  ENV_CONFIGS,
1431
1341
  Formatter,
1432
1342
  HexToUint8Array,
1433
1343
  IntentionHelper,
1434
1344
  LOCAL_API_URL,
1435
- LOCAL_DATABASE_CONFIG,
1436
1345
  LOCAL_SYNCING_URL,
1437
1346
  MAINNET_RPC_URL,
1438
1347
  MSAFE_APPLICATION,
@@ -1440,13 +1349,9 @@ export {
1440
1349
  MSafeClient,
1441
1350
  MSafeEnv,
1442
1351
  MSafeGlobals,
1443
- MessageHelper,
1444
- OpAddressBookType,
1445
- PublicKeySerde,
1446
1352
  SUI_COIN,
1447
1353
  SignatureVerifier,
1448
1354
  TESTNET_RPC_URL,
1449
- UNIT_DATABASE_CONFIG,
1450
1355
  Uint8ArrayToHex,
1451
1356
  getAllCoins,
1452
1357
  getMSafeConfig,