@msafe/sui3-sdk 0.0.50 → 0.0.51-pre-35fa193.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@msafe/sui3-sdk",
3
- "version": "0.0.50",
3
+ "version": "0.0.51-pre-35fa193.0",
4
4
  "description": "SDK for MSafe SUI V3",
5
5
  "type": "module",
6
6
  "module": "./dist/index.js",
@@ -6,7 +6,10 @@ import {
6
6
  IAuthLoginResp,
7
7
  IBuildTransactionRequest,
8
8
  ICreateMSafeReq,
9
+ IGetAddressBookModeResult,
9
10
  IGetAddressBookResult,
11
+ IGetDashboardReq,
12
+ IGetDashboardResp,
10
13
  IGetHistoryTransactionsRequest,
11
14
  IGetIntentionsRequest,
12
15
  IGetMSafeQuery,
@@ -19,7 +22,10 @@ import {
19
22
  IMSafeInfoResp,
20
23
  IPageOptions,
21
24
  IPagedResult,
25
+ IProposeIntentionAndBuildAndVoteRequest,
22
26
  IProposeIntentionRequest,
27
+ IRejectTransactionRequest,
28
+ ISetAddressBookModeReq,
23
29
  ISkipIntentionRequest,
24
30
  IUpdateMSafeStatusReq,
25
31
  IUserInfoResp,
@@ -31,14 +37,8 @@ import {
31
37
  TxIntention,
32
38
  UpdateAddressBookEntry,
33
39
  UserMSafeStatus,
34
- IGetAddressBookModeResult,
35
- ISetAddressBookModeReq,
36
- IRejectTransactionRequest,
37
- IProposeIntentionAndBuildAndVoteRequest,
38
- IGetDashboardReq,
39
- IGetDashboardResp,
40
40
  } from '@msafe/sui3-utils';
41
- import { SerializedSignature, PublicKey } from '@mysten/sui.js/cryptography';
41
+ import { PublicKey, SerializedSignature } from '@mysten/sui.js/cryptography';
42
42
  import axios, { AxiosError, AxiosRequestConfig, AxiosRequestTransformer, AxiosResponse } from 'axios';
43
43
 
44
44
  import { IBackend } from '@/backend/interface';
@@ -47,7 +47,10 @@ import { addPrefix } from '@/utils';
47
47
  export class BackendImpl implements IBackend {
48
48
  private _token: JWTToken;
49
49
 
50
- constructor(private readonly apiURL: string) {}
50
+ constructor(
51
+ private readonly apiURL: string,
52
+ private readonly mockAddress?: string,
53
+ ) {}
51
54
 
52
55
  async authSign(input: IAuthLoginReq): Promise<JWTToken> {
53
56
  const res = await this.post<IAuthLoginResp>(`/auth/login`, input);
@@ -275,7 +278,7 @@ export class BackendImpl implements IBackend {
275
278
  }
276
279
 
277
280
  private headers(token?: string) {
278
- return { Authorization: `Bearer ${token || this._token}` };
281
+ return { Authorization: `Bearer ${token || this._token}`, 'sui-mock-user': this.mockAddress };
279
282
  }
280
283
 
281
284
  private static toMSafeConfig(resp: IMSafeInfoResp): IMSafeConfig {
@@ -30,7 +30,7 @@ export class MSafeClient {
30
30
  return new MSafeClient(globals);
31
31
  }
32
32
 
33
- async connectWallet(input: { wallet: IWallet; jwtToken?: JWTToken; mockAddress?: string }): Promise<JWTToken> {
33
+ async connectWallet(input: { wallet: IWallet; jwtToken?: JWTToken }): Promise<JWTToken> {
34
34
  if (input.jwtToken) {
35
35
  const verified = await this.backend.verifyToken(input.jwtToken);
36
36
  if (verified) {
@@ -39,13 +39,13 @@ export class MSafeClient {
39
39
  return input.jwtToken;
40
40
  }
41
41
  }
42
- const jwt = await this.authSign(input.wallet, input.mockAddress);
42
+ const jwt = await this.authSign(input.wallet);
43
43
  this.globals.wallet = input.wallet;
44
44
  this.backend.setJWTToken(jwt);
45
45
  return jwt;
46
46
  }
47
47
 
48
- private async authSign(wallet: IWallet, mockAddress?: string): Promise<JWTToken> {
48
+ private async authSign(wallet: IWallet): Promise<JWTToken> {
49
49
  const messageStr = SigningMessageHelper.loginMessageWithTimestamp(new Date().toUTCString());
50
50
  const sig = await wallet.signPersonalMessage({
51
51
  messageStr,
@@ -55,7 +55,6 @@ export class MSafeClient {
55
55
  message: messageStr,
56
56
  signature: sig.signature,
57
57
  walletType: wallet.walletType,
58
- mockAddress,
59
58
  });
60
59
  }
61
60
 
@@ -23,7 +23,7 @@ export class MSafeGlobals {
23
23
  static async New(env: MSafeEnv, options?: MSafeConfigOptions) {
24
24
  const config = getMSafeConfig(env, options);
25
25
  const suiClient = new SuiClient(config.suiClient);
26
- const backend = new BackendImpl(config.backend.url);
26
+ const backend = new BackendImpl(config.backend.url, options?.mockAddress);
27
27
  return new MSafeGlobals({
28
28
  backend,
29
29
  suiClient,
@@ -24,6 +24,7 @@ export interface MSafeConfigOptions {
24
24
  backend?: {
25
25
  url?: string;
26
26
  };
27
+ mockAddress?: string;
27
28
  }
28
29
 
29
30
  export const TESTNET_RPC_URL = 'https://fullnode.testnet.sui.io';