@msafe/sui3-sdk 0.0.8 → 0.0.10

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.d.cts CHANGED
@@ -10,23 +10,6 @@ import { SignatureWithBytes } from '@mysten/sui.js/src/cryptography/keypair';
10
10
  import { TransactionBlock } from '@mysten/sui.js/transactions';
11
11
  import * as _mysten_sui_js_dist_cjs_client from '@mysten/sui.js/dist/cjs/client';
12
12
 
13
- type JWTToken = string;
14
- interface PaginationOption {
15
- page?: number;
16
- pageSize: number;
17
- }
18
- interface PaginationResponse<T> {
19
- items: T[];
20
- meta: PaginationMeta;
21
- }
22
- interface PaginationMeta {
23
- totalItems: number;
24
- itemCount: number;
25
- itemsPerPage: number;
26
- totalPages: number;
27
- currentPage: number;
28
- }
29
-
30
13
  interface IntentionCoinTransfer {
31
14
  txType: 'CoinTransfer';
32
15
  recipient: string;
@@ -60,6 +43,25 @@ declare class IntentionHelper {
60
43
  }): Promise<_mysten_sui_js_dist_cjs_builder.TransactionBlock>;
61
44
  }
62
45
 
46
+ interface CreateMSafeAccountInfo {
47
+ ownerWithWeight: {
48
+ address: string;
49
+ weight: number;
50
+ }[];
51
+ threshold: number;
52
+ name: string;
53
+ description?: string;
54
+ creationNonce: number;
55
+ }
56
+ interface CreatePermissionInfo {
57
+ ownerWithWeight: {
58
+ address: string;
59
+ weight: number;
60
+ }[];
61
+ threshold: number;
62
+ creationNonce: number;
63
+ }
64
+
63
65
  interface PendingTx {
64
66
  digest: string;
65
67
  payload: string;
@@ -112,8 +114,76 @@ interface FutureIntention {
112
114
  createdAt: Date;
113
115
  }
114
116
 
117
+ interface IWallet {
118
+ walletType: string;
119
+ address(): Promise<string>;
120
+ signPersonalMessage(input: {
121
+ messageStr: string;
122
+ }): Promise<SignatureWithBytes>;
123
+ signTransactionBlock(input: {
124
+ transactionBlock: TransactionBlock | Uint8Array;
125
+ }): Promise<SignatureWithBytes>;
126
+ signAndExecuteTransactionBlock(input: {
127
+ transactionBlock: TransactionBlock;
128
+ requestType?: ExecuteTransactionRequestType;
129
+ options?: SuiTransactionBlockResponseOptions;
130
+ }): Promise<SuiTransactionBlockResponse>;
131
+ }
132
+
133
+ interface PagedResult<T> {
134
+ data: T[];
135
+ meta: PagedMeta;
136
+ }
137
+ interface PagedMeta {
138
+ page: number;
139
+ limit: number;
140
+ total: number;
141
+ hasNext: boolean;
142
+ }
143
+
144
+ declare enum OpAddressBookType {
145
+ Delete = "delete",
146
+ Upsert = "upsert"
147
+ }
148
+ type UpdateAddressBookEntry = DeleteAddressBookEntry | UpsertAddressBookEntry;
149
+ interface DeleteAddressBookEntry {
150
+ opType: OpAddressBookType.Delete;
151
+ address: string;
152
+ }
153
+ interface UpsertAddressBookEntry {
154
+ opType: OpAddressBookType.Upsert;
155
+ address: string;
156
+ addressName: string;
157
+ remark?: string;
158
+ }
159
+ type GetAddressBookResult = PagedResult<GetAddressBookResultEntry>;
160
+ interface GetAddressBookResultEntry {
161
+ address: string;
162
+ addressName: string;
163
+ remark?: string;
164
+ updatedAt: Date;
165
+ }
166
+
167
+ type JWTToken = string;
168
+ interface PaginationOption {
169
+ page?: number;
170
+ limit?: number;
171
+ }
172
+ interface PaginationResponse<T> {
173
+ items: T[];
174
+ meta: PaginationMeta;
175
+ }
176
+ interface PaginationMeta {
177
+ totalItems: number;
178
+ itemCount: number;
179
+ itemsPerPage: number;
180
+ totalPages: number;
181
+ currentPage: number;
182
+ }
183
+
115
184
  interface IBackend {
116
185
  authSign(input: AuthLoginRequest): Promise<JWTToken>;
186
+ verifyToken(jwt?: JWTToken): Promise<boolean>;
117
187
  setJWTToken(token: JWTToken): void;
118
188
  getPublicKey(address: string): Promise<PublicKey | undefined>;
119
189
  getPublicKeyBatch(addresses: string[]): Promise<(PublicKey | undefined)[]>;
@@ -159,6 +229,11 @@ interface IBackend {
159
229
  userAddress: string;
160
230
  }): Promise<void>;
161
231
  processExecutedTransaction(digest: string): Promise<void>;
232
+ getAddressBookEntries(pagination?: PaginationOption): Promise<GetAddressBookResult>;
233
+ updateAddressBook(input: {
234
+ updates: UpdateAddressBookEntry[];
235
+ signature: SerializedSignature;
236
+ }): Promise<void>;
162
237
  }
163
238
 
164
239
  declare enum MSafeEnv {
@@ -196,22 +271,6 @@ declare const ENV_CONFIGS: Map<MSafeEnv, MSafeConfig>;
196
271
  declare function getMSafeConfig(env: MSafeEnv, options?: MSafeConfigOptions): MSafeConfig;
197
272
  declare const AUTH_SIGN_MESSAGE = "Welcome to MSafe";
198
273
 
199
- interface IWallet {
200
- walletType: string;
201
- address(): Promise<string>;
202
- signPersonalMessage(input: {
203
- messageStr: string;
204
- }): Promise<SignatureWithBytes>;
205
- signTransactionBlock(input: {
206
- transactionBlock: TransactionBlock | Uint8Array;
207
- }): Promise<SignatureWithBytes>;
208
- signAndExecuteTransactionBlock(input: {
209
- transactionBlock: TransactionBlock;
210
- requestType?: ExecuteTransactionRequestType;
211
- options?: SuiTransactionBlockResponseOptions;
212
- }): Promise<SuiTransactionBlockResponse>;
213
- }
214
-
215
274
  declare class MSafeGlobals {
216
275
  readonly backend: IBackend;
217
276
  readonly suiClient: SuiClient;
@@ -243,25 +302,6 @@ declare class PublicKeyHelper {
243
302
  private getPublicKeyFromChain;
244
303
  }
245
304
 
246
- interface CreateMSafeAccountInfo {
247
- ownerWithWeight: {
248
- address: string;
249
- weight: number;
250
- }[];
251
- threshold: number;
252
- name: string;
253
- description?: string;
254
- creationNonce: number;
255
- }
256
- interface CreatePermissionInfo {
257
- ownerWithWeight: {
258
- address: string;
259
- weight: number;
260
- }[];
261
- threshold: number;
262
- creationNonce: number;
263
- }
264
-
265
305
  declare class CreateHelper {
266
306
  readonly globals: MSafeGlobals;
267
307
  readonly pkHelper: PublicKeyHelper;
@@ -281,12 +321,20 @@ declare class MessageHelper {
281
321
  static deWelcomeMessage(msg: string): string | undefined;
282
322
  static proposeIntentionMessage(data: ProposeIntentionData): string;
283
323
  static deProposeIntentionMessage(s: string): ProposeIntentionData;
324
+ static updateAddressBookMessage(updates: UpdateAddressBookEntry[]): string;
284
325
  }
285
326
  interface ProposeIntentionData {
286
327
  intention: TxIntention;
287
328
  sn: number;
288
329
  }
289
330
 
331
+ declare class AddressBookSDK {
332
+ readonly globals: MSafeGlobals;
333
+ constructor(globals: MSafeGlobals);
334
+ getEntries(pagination?: PaginationOption): Promise<GetAddressBookResult>;
335
+ update(updates: UpdateAddressBookEntry[]): Promise<void>;
336
+ }
337
+
290
338
  declare class MSafeAccount {
291
339
  readonly globals: MSafeGlobals;
292
340
  readonly info: MSafeAccountInfo;
@@ -322,10 +370,7 @@ declare class MSafeClient {
322
370
  wallet: IWallet;
323
371
  jwtToken?: JWTToken;
324
372
  }): Promise<JWTToken>;
325
- setWallet(input: {
326
- wallet: IWallet;
327
- jwtToken: JWTToken;
328
- }): Promise<void>;
373
+ private authSign;
329
374
  userInfo(): Promise<_msafe_sui3_utils.UserWithOwnedMSafe>;
330
375
  createAccount(info: CreateMSafeAccountInfo): Promise<string>;
331
376
  getMSafeAccount(info: MSafeAccountInfo): MSafeAccount;
@@ -335,6 +380,7 @@ declare class MSafeClient {
335
380
  get config(): MSafeConfig;
336
381
  get backend(): IBackend;
337
382
  get wallet(): IWallet;
383
+ get AddressBook(): AddressBookSDK;
338
384
  private walletAddress;
339
385
  }
340
386
 
@@ -410,4 +456,4 @@ declare class Coin {
410
456
  static getBalance(data: SuiObjectData): bigint | undefined;
411
457
  }
412
458
 
413
- export { AUTH_SIGN_MESSAGE, COIN_TYPE_ARG_REGEX, Coin, CoinHelper, CreateHelper, type CreateMSafeAccountInfo, type CreatePermissionInfo, type DBConfig, DEV_API_URL, DEV_DATABASE_CONFIG, DEV_SYNCING_URL, ENV_CONFIGS, Formatter, type FutureIntention, HexToUint8Array, type HistorySendTx, type HistoryVote, type IWallet, type IntentionCoinTransfer, IntentionHelper, type IntentionObjectTransfer, LOCAL_API_URL, LOCAL_DATABASE_CONFIG, LOCAL_SYNCING_URL, MAINNET_RPC_URL, MSafeAccount, MSafeClient, type MSafeConfig, type MSafeConfigOptions, MSafeEnv, MSafeGlobals, MessageHelper, type PendingTx, type PendingVote, PublicKeySerde, type ReceiveTransaction, SUI_COIN, SignatureVerifier, TESTNET_RPC_URL, type TxIntention, UNIT_DATABASE_CONFIG, Uint8ArrayToHex, getAllCoins, getMSafeConfig, getPublicKeyFromChain, stringToBuffer };
459
+ export { AUTH_SIGN_MESSAGE, AddressBookSDK, COIN_TYPE_ARG_REGEX, Coin, CoinHelper, CreateHelper, type CreateMSafeAccountInfo, type CreatePermissionInfo, type DBConfig, DEV_API_URL, DEV_DATABASE_CONFIG, DEV_SYNCING_URL, type DeleteAddressBookEntry, ENV_CONFIGS, Formatter, type FutureIntention, type GetAddressBookResult, type GetAddressBookResultEntry, HexToUint8Array, type HistorySendTx, type HistoryVote, type IWallet, type IntentionCoinTransfer, IntentionHelper, type IntentionObjectTransfer, type JWTToken, LOCAL_API_URL, LOCAL_DATABASE_CONFIG, LOCAL_SYNCING_URL, MAINNET_RPC_URL, MSafeAccount, MSafeClient, type MSafeConfig, type MSafeConfigOptions, MSafeEnv, MSafeGlobals, MessageHelper, OpAddressBookType, type PagedMeta, type PagedResult, type PaginationMeta, type PaginationOption, type PaginationResponse, type PendingTx, type PendingVote, PublicKeySerde, type ReceiveTransaction, SUI_COIN, SignatureVerifier, TESTNET_RPC_URL, type TxIntention, UNIT_DATABASE_CONFIG, Uint8ArrayToHex, type UpdateAddressBookEntry, type UpsertAddressBookEntry, getAllCoins, getMSafeConfig, getPublicKeyFromChain, stringToBuffer };
package/dist/index.d.ts CHANGED
@@ -10,23 +10,6 @@ import { SignatureWithBytes } from '@mysten/sui.js/src/cryptography/keypair';
10
10
  import { TransactionBlock } from '@mysten/sui.js/transactions';
11
11
  import * as _mysten_sui_js_dist_cjs_client from '@mysten/sui.js/dist/cjs/client';
12
12
 
13
- type JWTToken = string;
14
- interface PaginationOption {
15
- page?: number;
16
- pageSize: number;
17
- }
18
- interface PaginationResponse<T> {
19
- items: T[];
20
- meta: PaginationMeta;
21
- }
22
- interface PaginationMeta {
23
- totalItems: number;
24
- itemCount: number;
25
- itemsPerPage: number;
26
- totalPages: number;
27
- currentPage: number;
28
- }
29
-
30
13
  interface IntentionCoinTransfer {
31
14
  txType: 'CoinTransfer';
32
15
  recipient: string;
@@ -60,6 +43,25 @@ declare class IntentionHelper {
60
43
  }): Promise<_mysten_sui_js_dist_cjs_builder.TransactionBlock>;
61
44
  }
62
45
 
46
+ interface CreateMSafeAccountInfo {
47
+ ownerWithWeight: {
48
+ address: string;
49
+ weight: number;
50
+ }[];
51
+ threshold: number;
52
+ name: string;
53
+ description?: string;
54
+ creationNonce: number;
55
+ }
56
+ interface CreatePermissionInfo {
57
+ ownerWithWeight: {
58
+ address: string;
59
+ weight: number;
60
+ }[];
61
+ threshold: number;
62
+ creationNonce: number;
63
+ }
64
+
63
65
  interface PendingTx {
64
66
  digest: string;
65
67
  payload: string;
@@ -112,8 +114,76 @@ interface FutureIntention {
112
114
  createdAt: Date;
113
115
  }
114
116
 
117
+ interface IWallet {
118
+ walletType: string;
119
+ address(): Promise<string>;
120
+ signPersonalMessage(input: {
121
+ messageStr: string;
122
+ }): Promise<SignatureWithBytes>;
123
+ signTransactionBlock(input: {
124
+ transactionBlock: TransactionBlock | Uint8Array;
125
+ }): Promise<SignatureWithBytes>;
126
+ signAndExecuteTransactionBlock(input: {
127
+ transactionBlock: TransactionBlock;
128
+ requestType?: ExecuteTransactionRequestType;
129
+ options?: SuiTransactionBlockResponseOptions;
130
+ }): Promise<SuiTransactionBlockResponse>;
131
+ }
132
+
133
+ interface PagedResult<T> {
134
+ data: T[];
135
+ meta: PagedMeta;
136
+ }
137
+ interface PagedMeta {
138
+ page: number;
139
+ limit: number;
140
+ total: number;
141
+ hasNext: boolean;
142
+ }
143
+
144
+ declare enum OpAddressBookType {
145
+ Delete = "delete",
146
+ Upsert = "upsert"
147
+ }
148
+ type UpdateAddressBookEntry = DeleteAddressBookEntry | UpsertAddressBookEntry;
149
+ interface DeleteAddressBookEntry {
150
+ opType: OpAddressBookType.Delete;
151
+ address: string;
152
+ }
153
+ interface UpsertAddressBookEntry {
154
+ opType: OpAddressBookType.Upsert;
155
+ address: string;
156
+ addressName: string;
157
+ remark?: string;
158
+ }
159
+ type GetAddressBookResult = PagedResult<GetAddressBookResultEntry>;
160
+ interface GetAddressBookResultEntry {
161
+ address: string;
162
+ addressName: string;
163
+ remark?: string;
164
+ updatedAt: Date;
165
+ }
166
+
167
+ type JWTToken = string;
168
+ interface PaginationOption {
169
+ page?: number;
170
+ limit?: number;
171
+ }
172
+ interface PaginationResponse<T> {
173
+ items: T[];
174
+ meta: PaginationMeta;
175
+ }
176
+ interface PaginationMeta {
177
+ totalItems: number;
178
+ itemCount: number;
179
+ itemsPerPage: number;
180
+ totalPages: number;
181
+ currentPage: number;
182
+ }
183
+
115
184
  interface IBackend {
116
185
  authSign(input: AuthLoginRequest): Promise<JWTToken>;
186
+ verifyToken(jwt?: JWTToken): Promise<boolean>;
117
187
  setJWTToken(token: JWTToken): void;
118
188
  getPublicKey(address: string): Promise<PublicKey | undefined>;
119
189
  getPublicKeyBatch(addresses: string[]): Promise<(PublicKey | undefined)[]>;
@@ -159,6 +229,11 @@ interface IBackend {
159
229
  userAddress: string;
160
230
  }): Promise<void>;
161
231
  processExecutedTransaction(digest: string): Promise<void>;
232
+ getAddressBookEntries(pagination?: PaginationOption): Promise<GetAddressBookResult>;
233
+ updateAddressBook(input: {
234
+ updates: UpdateAddressBookEntry[];
235
+ signature: SerializedSignature;
236
+ }): Promise<void>;
162
237
  }
163
238
 
164
239
  declare enum MSafeEnv {
@@ -196,22 +271,6 @@ declare const ENV_CONFIGS: Map<MSafeEnv, MSafeConfig>;
196
271
  declare function getMSafeConfig(env: MSafeEnv, options?: MSafeConfigOptions): MSafeConfig;
197
272
  declare const AUTH_SIGN_MESSAGE = "Welcome to MSafe";
198
273
 
199
- interface IWallet {
200
- walletType: string;
201
- address(): Promise<string>;
202
- signPersonalMessage(input: {
203
- messageStr: string;
204
- }): Promise<SignatureWithBytes>;
205
- signTransactionBlock(input: {
206
- transactionBlock: TransactionBlock | Uint8Array;
207
- }): Promise<SignatureWithBytes>;
208
- signAndExecuteTransactionBlock(input: {
209
- transactionBlock: TransactionBlock;
210
- requestType?: ExecuteTransactionRequestType;
211
- options?: SuiTransactionBlockResponseOptions;
212
- }): Promise<SuiTransactionBlockResponse>;
213
- }
214
-
215
274
  declare class MSafeGlobals {
216
275
  readonly backend: IBackend;
217
276
  readonly suiClient: SuiClient;
@@ -243,25 +302,6 @@ declare class PublicKeyHelper {
243
302
  private getPublicKeyFromChain;
244
303
  }
245
304
 
246
- interface CreateMSafeAccountInfo {
247
- ownerWithWeight: {
248
- address: string;
249
- weight: number;
250
- }[];
251
- threshold: number;
252
- name: string;
253
- description?: string;
254
- creationNonce: number;
255
- }
256
- interface CreatePermissionInfo {
257
- ownerWithWeight: {
258
- address: string;
259
- weight: number;
260
- }[];
261
- threshold: number;
262
- creationNonce: number;
263
- }
264
-
265
305
  declare class CreateHelper {
266
306
  readonly globals: MSafeGlobals;
267
307
  readonly pkHelper: PublicKeyHelper;
@@ -281,12 +321,20 @@ declare class MessageHelper {
281
321
  static deWelcomeMessage(msg: string): string | undefined;
282
322
  static proposeIntentionMessage(data: ProposeIntentionData): string;
283
323
  static deProposeIntentionMessage(s: string): ProposeIntentionData;
324
+ static updateAddressBookMessage(updates: UpdateAddressBookEntry[]): string;
284
325
  }
285
326
  interface ProposeIntentionData {
286
327
  intention: TxIntention;
287
328
  sn: number;
288
329
  }
289
330
 
331
+ declare class AddressBookSDK {
332
+ readonly globals: MSafeGlobals;
333
+ constructor(globals: MSafeGlobals);
334
+ getEntries(pagination?: PaginationOption): Promise<GetAddressBookResult>;
335
+ update(updates: UpdateAddressBookEntry[]): Promise<void>;
336
+ }
337
+
290
338
  declare class MSafeAccount {
291
339
  readonly globals: MSafeGlobals;
292
340
  readonly info: MSafeAccountInfo;
@@ -322,10 +370,7 @@ declare class MSafeClient {
322
370
  wallet: IWallet;
323
371
  jwtToken?: JWTToken;
324
372
  }): Promise<JWTToken>;
325
- setWallet(input: {
326
- wallet: IWallet;
327
- jwtToken: JWTToken;
328
- }): Promise<void>;
373
+ private authSign;
329
374
  userInfo(): Promise<_msafe_sui3_utils.UserWithOwnedMSafe>;
330
375
  createAccount(info: CreateMSafeAccountInfo): Promise<string>;
331
376
  getMSafeAccount(info: MSafeAccountInfo): MSafeAccount;
@@ -335,6 +380,7 @@ declare class MSafeClient {
335
380
  get config(): MSafeConfig;
336
381
  get backend(): IBackend;
337
382
  get wallet(): IWallet;
383
+ get AddressBook(): AddressBookSDK;
338
384
  private walletAddress;
339
385
  }
340
386
 
@@ -410,4 +456,4 @@ declare class Coin {
410
456
  static getBalance(data: SuiObjectData): bigint | undefined;
411
457
  }
412
458
 
413
- export { AUTH_SIGN_MESSAGE, COIN_TYPE_ARG_REGEX, Coin, CoinHelper, CreateHelper, type CreateMSafeAccountInfo, type CreatePermissionInfo, type DBConfig, DEV_API_URL, DEV_DATABASE_CONFIG, DEV_SYNCING_URL, ENV_CONFIGS, Formatter, type FutureIntention, HexToUint8Array, type HistorySendTx, type HistoryVote, type IWallet, type IntentionCoinTransfer, IntentionHelper, type IntentionObjectTransfer, LOCAL_API_URL, LOCAL_DATABASE_CONFIG, LOCAL_SYNCING_URL, MAINNET_RPC_URL, MSafeAccount, MSafeClient, type MSafeConfig, type MSafeConfigOptions, MSafeEnv, MSafeGlobals, MessageHelper, type PendingTx, type PendingVote, PublicKeySerde, type ReceiveTransaction, SUI_COIN, SignatureVerifier, TESTNET_RPC_URL, type TxIntention, UNIT_DATABASE_CONFIG, Uint8ArrayToHex, getAllCoins, getMSafeConfig, getPublicKeyFromChain, stringToBuffer };
459
+ export { AUTH_SIGN_MESSAGE, AddressBookSDK, COIN_TYPE_ARG_REGEX, Coin, CoinHelper, CreateHelper, type CreateMSafeAccountInfo, type CreatePermissionInfo, type DBConfig, DEV_API_URL, DEV_DATABASE_CONFIG, DEV_SYNCING_URL, type DeleteAddressBookEntry, ENV_CONFIGS, Formatter, type FutureIntention, type GetAddressBookResult, type GetAddressBookResultEntry, HexToUint8Array, type HistorySendTx, type HistoryVote, type IWallet, type IntentionCoinTransfer, IntentionHelper, type IntentionObjectTransfer, type JWTToken, LOCAL_API_URL, LOCAL_DATABASE_CONFIG, LOCAL_SYNCING_URL, MAINNET_RPC_URL, MSafeAccount, MSafeClient, type MSafeConfig, type MSafeConfigOptions, MSafeEnv, MSafeGlobals, MessageHelper, OpAddressBookType, type PagedMeta, type PagedResult, type PaginationMeta, type PaginationOption, type PaginationResponse, type PendingTx, type PendingVote, PublicKeySerde, type ReceiveTransaction, SUI_COIN, SignatureVerifier, TESTNET_RPC_URL, type TxIntention, UNIT_DATABASE_CONFIG, Uint8ArrayToHex, type UpdateAddressBookEntry, type UpsertAddressBookEntry, getAllCoins, getMSafeConfig, getPublicKeyFromChain, stringToBuffer };
package/dist/index.js CHANGED
@@ -224,6 +224,10 @@ var CreateHelper = class {
224
224
  }
225
225
  };
226
226
 
227
+ // src/core/MessageHelper.ts
228
+ import { normalizeSuiAddress as normalizeSuiAddress2 } from "@mysten/sui.js/utils";
229
+ import { MD5 } from "crypto-js";
230
+
227
231
  // src/transactions/coin-transfer.ts
228
232
  import { TransactionBlock } from "@mysten/sui.js/transactions";
229
233
 
@@ -495,6 +499,38 @@ var MessageHelper = class {
495
499
  intention: IntentionHelper.de(intentionData)
496
500
  };
497
501
  }
502
+ static updateAddressBookMessage(updates) {
503
+ const normalized = updates.map((update) => ({
504
+ ...update,
505
+ address: normalizeSuiAddress2(update.address)
506
+ }));
507
+ function sortObjectKeys(obj) {
508
+ return Object.keys(obj).sort().reduce((result, key) => ({ ...result, [key]: obj[key] }), {});
509
+ }
510
+ const sortedUpdates = normalized.map((update) => sortObjectKeys(update));
511
+ const raw = JSON.stringify(sortedUpdates, null, 2);
512
+ const encoded = stringToBuffer(raw);
513
+ if (encoded.length <= 1024) {
514
+ return raw;
515
+ }
516
+ const md5 = MD5(raw);
517
+ return `Bulk address book update: ${md5}`;
518
+ }
519
+ };
520
+
521
+ // src/core/AddressBookSDK.ts
522
+ var AddressBookSDK = class {
523
+ constructor(globals) {
524
+ this.globals = globals;
525
+ }
526
+ async getEntries(pagination) {
527
+ return this.globals.backend.getAddressBookEntries(pagination);
528
+ }
529
+ async update(updates) {
530
+ const messageStr = MessageHelper.updateAddressBookMessage(updates);
531
+ const sig = await this.globals.wallet.signPersonalMessage({ messageStr });
532
+ return this.globals.backend.updateAddressBook({ updates, signature: sig.signature });
533
+ }
498
534
  };
499
535
 
500
536
  // src/core/MSafeAccount.ts
@@ -816,6 +852,14 @@ var BackendImpl = class {
816
852
  this._token = res.data.accessToken;
817
853
  return this._token;
818
854
  }
855
+ async verifyToken(jwt) {
856
+ try {
857
+ const res = await axios.get(`${this.apiURL}/auth`, { headers: this.headers(jwt) });
858
+ return res.status === 200;
859
+ } catch (_) {
860
+ return false;
861
+ }
862
+ }
819
863
  setJWTToken(token) {
820
864
  this._token = token;
821
865
  }
@@ -908,7 +952,7 @@ var BackendImpl = class {
908
952
  {
909
953
  params: {
910
954
  page: paginationOption?.page,
911
- limit: paginationOption?.pageSize
955
+ limit: paginationOption?.limit
912
956
  },
913
957
  headers: this.headers()
914
958
  }
@@ -924,7 +968,7 @@ var BackendImpl = class {
924
968
  {
925
969
  params: {
926
970
  page: paginationOption?.page,
927
- limit: paginationOption?.pageSize
971
+ limit: paginationOption?.limit
928
972
  },
929
973
  headers: this.headers()
930
974
  }
@@ -1042,10 +1086,26 @@ var BackendImpl = class {
1042
1086
  throw new Error(`invalid skipNextFailedIntention return: ${res}`);
1043
1087
  }
1044
1088
  }
1089
+ async getAddressBookEntries(pagination) {
1090
+ const res = await axios.get(`${this.apiURL}/address-book`, {
1091
+ headers: this.headers(),
1092
+ params: pagination
1093
+ });
1094
+ if (res.status !== 200) {
1095
+ throw new Error(`Invalid address-book return: ${res}`);
1096
+ }
1097
+ return res.data;
1098
+ }
1099
+ async updateAddressBook(input) {
1100
+ const res = await axios.post(`${this.apiURL}/address-book`, input, { headers: this.headers() });
1101
+ if (res.status !== 200 && res.status !== 201) {
1102
+ throw new Error(`invalid updateAddressBook return: ${res}`);
1103
+ }
1104
+ }
1045
1105
  async processExecutedTransaction(digest) {
1046
1106
  }
1047
- headers() {
1048
- return { Authorization: `Bearer ${this._token}` };
1107
+ headers(token) {
1108
+ return { Authorization: `Bearer ${token || this._token}` };
1049
1109
  }
1050
1110
  };
1051
1111
 
@@ -1096,22 +1156,31 @@ var MSafeClient = class _MSafeClient {
1096
1156
  return new _MSafeClient(globals);
1097
1157
  }
1098
1158
  async connectWallet(input) {
1159
+ if (input.jwtToken) {
1160
+ const verified = await this.backend.verifyToken(input.jwtToken);
1161
+ if (verified) {
1162
+ this.globals.wallet = input.wallet;
1163
+ this.backend.setJWTToken(input.jwtToken);
1164
+ return input.jwtToken;
1165
+ }
1166
+ }
1167
+ const jwt = await this.authSign(input.wallet);
1099
1168
  this.globals.wallet = input.wallet;
1169
+ this.backend.setJWTToken(jwt);
1170
+ return jwt;
1171
+ }
1172
+ async authSign(wallet) {
1100
1173
  const messageStr = MessageHelper.welcomeMessage((/* @__PURE__ */ new Date()).toUTCString());
1101
- const sig = await input.wallet.signPersonalMessage({
1174
+ const sig = await wallet.signPersonalMessage({
1102
1175
  messageStr
1103
1176
  });
1104
1177
  return this.backend.authSign({
1105
- address: await input.wallet.address(),
1178
+ address: await wallet.address(),
1106
1179
  message: messageStr,
1107
1180
  signature: sig.signature,
1108
- walletType: input.wallet.walletType
1181
+ walletType: wallet.walletType
1109
1182
  });
1110
1183
  }
1111
- async setWallet(input) {
1112
- this.globals.wallet = input.wallet;
1113
- this.backend.setJWTToken(input.jwtToken);
1114
- }
1115
1184
  async userInfo() {
1116
1185
  return this.globals.backend.getUserInfo(await this.walletAddress());
1117
1186
  }
@@ -1148,12 +1217,23 @@ var MSafeClient = class _MSafeClient {
1148
1217
  get wallet() {
1149
1218
  return this.globals.wallet;
1150
1219
  }
1220
+ get AddressBook() {
1221
+ return new AddressBookSDK(this.globals);
1222
+ }
1151
1223
  async walletAddress() {
1152
1224
  return this.wallet.address();
1153
1225
  }
1154
1226
  };
1227
+
1228
+ // src/types/address-book.ts
1229
+ var OpAddressBookType = /* @__PURE__ */ ((OpAddressBookType2) => {
1230
+ OpAddressBookType2["Delete"] = "delete";
1231
+ OpAddressBookType2["Upsert"] = "upsert";
1232
+ return OpAddressBookType2;
1233
+ })(OpAddressBookType || {});
1155
1234
  export {
1156
1235
  AUTH_SIGN_MESSAGE,
1236
+ AddressBookSDK,
1157
1237
  COIN_TYPE_ARG_REGEX,
1158
1238
  Coin,
1159
1239
  CoinHelper,
@@ -1174,6 +1254,7 @@ export {
1174
1254
  MSafeEnv,
1175
1255
  MSafeGlobals,
1176
1256
  MessageHelper,
1257
+ OpAddressBookType,
1177
1258
  PublicKeySerde,
1178
1259
  SUI_COIN,
1179
1260
  SignatureVerifier,