@msafe/sui3-sdk 0.0.49 → 0.0.51-pre-331bbea.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.cjs +15 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +15 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/backend/BackendImpl.ts +20 -9
- package/src/core/MSafeClient.ts +2 -3
- package/src/globals/MSafeGlobals.ts +1 -1
- package/src/globals/const.ts +1 -0
package/package.json
CHANGED
|
@@ -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 {
|
|
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(
|
|
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);
|
|
@@ -295,7 +298,12 @@ export class BackendImpl implements IBackend {
|
|
|
295
298
|
private async get<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R> {
|
|
296
299
|
const fullUrl = this.getFullUrl(url);
|
|
297
300
|
try {
|
|
298
|
-
return await axios.get<T, R, D>(fullUrl,
|
|
301
|
+
return await axios.get<T, R, D>(fullUrl, {
|
|
302
|
+
...config,
|
|
303
|
+
headers: {
|
|
304
|
+
'sui-mock-user': this.mockAddress,
|
|
305
|
+
},
|
|
306
|
+
});
|
|
299
307
|
} catch (e) {
|
|
300
308
|
throw BackendError.fromError(e) ?? e;
|
|
301
309
|
}
|
|
@@ -311,6 +319,9 @@ export class BackendImpl implements IBackend {
|
|
|
311
319
|
return await axios.post<T, R, D>(fullUrl, data, {
|
|
312
320
|
...config,
|
|
313
321
|
transformRequest: this.getTransformRequest(),
|
|
322
|
+
headers: {
|
|
323
|
+
'sui-mock-user': this.mockAddress,
|
|
324
|
+
},
|
|
314
325
|
});
|
|
315
326
|
} catch (e) {
|
|
316
327
|
throw BackendError.fromError(e) ?? e;
|
package/src/core/MSafeClient.ts
CHANGED
|
@@ -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
|
|
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) {
|
|
@@ -45,7 +45,7 @@ export class MSafeClient {
|
|
|
45
45
|
return jwt;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
private async authSign(wallet: IWallet
|
|
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,
|