@tomo-inc/chains-service 0.0.2

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.
Files changed (52) hide show
  1. package/CHANGELOG.md +3 -0
  2. package/README.md +15 -0
  3. package/package.json +38 -0
  4. package/project.json +59 -0
  5. package/src/api/__tests__/config.ts +21 -0
  6. package/src/api/__tests__/token.test.ts +120 -0
  7. package/src/api/__tests__/transaction.test.ts +86 -0
  8. package/src/api/__tests__/user.test.ts +105 -0
  9. package/src/api/__tests__/wallet.test.ts +73 -0
  10. package/src/api/base.ts +52 -0
  11. package/src/api/index.ts +24 -0
  12. package/src/api/network-data.ts +572 -0
  13. package/src/api/network.ts +81 -0
  14. package/src/api/token.ts +182 -0
  15. package/src/api/transaction.ts +59 -0
  16. package/src/api/types/common.ts +35 -0
  17. package/src/api/types/index.ts +13 -0
  18. package/src/api/types/type.ts +283 -0
  19. package/src/api/user.ts +83 -0
  20. package/src/api/utils/index.ts +34 -0
  21. package/src/api/utils/signature.ts +60 -0
  22. package/src/api/wallet.ts +57 -0
  23. package/src/base/network.ts +55 -0
  24. package/src/base/service.ts +33 -0
  25. package/src/base/token.ts +43 -0
  26. package/src/base/transaction.ts +58 -0
  27. package/src/config.ts +21 -0
  28. package/src/dogecoin/base.ts +39 -0
  29. package/src/dogecoin/config.ts +43 -0
  30. package/src/dogecoin/rpc.ts +449 -0
  31. package/src/dogecoin/service.ts +451 -0
  32. package/src/dogecoin/type.ts +29 -0
  33. package/src/dogecoin/utils-doge.ts +105 -0
  34. package/src/dogecoin/utils.ts +601 -0
  35. package/src/evm/rpc.ts +68 -0
  36. package/src/evm/service.ts +403 -0
  37. package/src/evm/utils.ts +92 -0
  38. package/src/index.ts +28 -0
  39. package/src/solana/config.ts +5 -0
  40. package/src/solana/service.ts +312 -0
  41. package/src/solana/types.ts +91 -0
  42. package/src/solana/utils.ts +635 -0
  43. package/src/types/account.ts +58 -0
  44. package/src/types/dapp.ts +7 -0
  45. package/src/types/gas.ts +53 -0
  46. package/src/types/index.ts +81 -0
  47. package/src/types/network.ts +66 -0
  48. package/src/types/tx.ts +181 -0
  49. package/src/types/wallet.ts +49 -0
  50. package/src/wallet.ts +96 -0
  51. package/tsconfig.json +14 -0
  52. package/tsup.config.ts +18 -0
@@ -0,0 +1,182 @@
1
+ import {
2
+ GetTokenInfoParams,
3
+ RemoteResponse,
4
+ RemoteTokenInfo,
5
+ AddCustomTokenParams,
6
+ DeleteCustomTokenParams,
7
+ SyncCustomTokenParams,
8
+ GetTokenBalanceParams,
9
+ GetTokenBalanceResponse,
10
+ IPublicApiBaseConfig,
11
+ } from "./types";
12
+ import { BasePublicService } from "./base";
13
+ import { TomoAppInfo } from "../types";
14
+
15
+ export class TokenAPIs extends BasePublicService {
16
+ private static instance: TokenAPIs;
17
+
18
+ private constructor(apiBase: IPublicApiBaseConfig, tomoAppInfo: TomoAppInfo) {
19
+ super(apiBase, tomoAppInfo);
20
+ }
21
+
22
+ public static getInstance(apiBase: IPublicApiBaseConfig, tomoAppInfo: TomoAppInfo) {
23
+ if (!this.instance) {
24
+ this.instance = new TokenAPIs(apiBase, tomoAppInfo);
25
+ }
26
+ return this.instance;
27
+ }
28
+
29
+ // --------------- token api ---------------
30
+ async getTokenInfo(params: GetTokenInfoParams): Promise<RemoteResponse<RemoteTokenInfo>> {
31
+ try {
32
+ const res = await this.walletApi.get("/v1/balance/getTokenInfo", {
33
+ params,
34
+ });
35
+ return {
36
+ success: res?.data?.code === "00000",
37
+ message: res?.data?.msg,
38
+ data: res?.data?.data,
39
+ };
40
+ } catch (error) {
41
+ console.error("Failed to get token info:", error);
42
+ throw error;
43
+ }
44
+ }
45
+
46
+ async getTokenRisk(params: { chainIndex: number; tokenAddress: string }): Promise<RemoteResponse<any>> {
47
+ if (typeof params.chainIndex !== "number" || !params.tokenAddress) {
48
+ throw new Error("chainName or tokenAddress is required");
49
+ }
50
+ const res = await this.tokenApi.post("/v1/market/risk/details", [params]);
51
+ return {
52
+ success: res?.data?.code === "0",
53
+ message: res?.data?.msg,
54
+ data: res?.data?.data?.[0] || null,
55
+ };
56
+ }
57
+
58
+ async addCustomToken(params: AddCustomTokenParams): Promise<RemoteResponse<any>> {
59
+ try {
60
+ const res = await this.walletApi.post("/v1/customTokens/addCustomToken", params, {});
61
+ return {
62
+ success: res?.data?.code === "00000",
63
+ message: res?.data?.msg,
64
+ data: res?.data?.data,
65
+ };
66
+ } catch (error) {
67
+ console.error("Failed to add custom token:", error);
68
+ throw error;
69
+ }
70
+ }
71
+
72
+ async deleteCustomToken(params: DeleteCustomTokenParams): Promise<RemoteResponse<any>> {
73
+ try {
74
+ const res = await this.walletApi.get("/v1/customTokens/delete", {
75
+ params,
76
+ });
77
+ return {
78
+ success: res?.data?.code === "00000",
79
+ message: res?.data?.msg,
80
+ data: res?.data?.data,
81
+ };
82
+ } catch (error) {
83
+ console.error("Failed to delete custom token:", error);
84
+ throw error;
85
+ }
86
+ }
87
+
88
+ async addMultiToken(params: AddCustomTokenParams): Promise<RemoteResponse<any>> {
89
+ try {
90
+ const res = await this.walletApi.post("/v1/customTokens/addTokenWithMulti", params, {});
91
+ return {
92
+ success: res?.data?.code === "00000",
93
+ message: res?.data?.msg,
94
+ data: res?.data?.data,
95
+ };
96
+ } catch (error) {
97
+ console.error("Failed to add multi token:", error);
98
+ throw error;
99
+ }
100
+ }
101
+
102
+ async removeMultiToken(params: DeleteCustomTokenParams): Promise<RemoteResponse<any>> {
103
+ try {
104
+ const res = await this.walletApi.get("/v1/customTokens/hideTokenWithMulti", {
105
+ params,
106
+ });
107
+ return {
108
+ success: res?.data?.code === "00000",
109
+ message: res?.data?.msg,
110
+ data: res?.data?.data,
111
+ };
112
+ } catch (error) {
113
+ console.error("Failed to delete multi token:", error);
114
+ throw error;
115
+ }
116
+ }
117
+
118
+ async syncCustomToken(params: SyncCustomTokenParams): Promise<RemoteResponse<any>> {
119
+ try {
120
+ const res = await this.walletApi.post("/v1/customTokens/sync", params, {});
121
+ return res?.data || {};
122
+ } catch (error) {
123
+ console.error("Failed to sync custom token:", error);
124
+ throw error;
125
+ }
126
+ }
127
+
128
+ async getTokenBalance(params: GetTokenBalanceParams): Promise<RemoteResponse<GetTokenBalanceResponse>> {
129
+ try {
130
+ const res = await this.walletApi.get("/v1/balance/getTokenBalanceWithDetail", {
131
+ params,
132
+ });
133
+
134
+ return {
135
+ success: res?.data?.code === "00000",
136
+ message: res?.data?.msg,
137
+ data: res?.data?.data || null,
138
+ };
139
+ } catch (error) {
140
+ console.error("Failed to get token balance:", error);
141
+ throw error;
142
+ }
143
+ }
144
+
145
+ async getTokenDetail(params: { chainIndex: number; tokenAddress: string }): Promise<RemoteResponse<any>> {
146
+ //bad design, should: chainId + tokenAddress
147
+ const { chainIndex, tokenAddress } = params;
148
+
149
+ const res = await this.tokenApi.get(`/v1/market/token/detail`, {
150
+ params: {
151
+ tokenAddress,
152
+ chainIndex,
153
+ },
154
+ });
155
+
156
+ return {
157
+ success: res?.data?.code === "0",
158
+ message: res?.data?.msg,
159
+ data: res?.data?.data || null,
160
+ };
161
+ }
162
+
163
+ async queryRemoteTokens(params: { keyword: string; chainIndex?: number }): Promise<RemoteResponse<any[]>> {
164
+ const { keyword = "", chainIndex } = params || {};
165
+ if (!keyword) {
166
+ throw new Error("Params is required");
167
+ }
168
+
169
+ const res = await this.tokenApi.get(`/v1/market/token/search`, {
170
+ params: {
171
+ content: keyword,
172
+ chainIndex,
173
+ },
174
+ });
175
+
176
+ return {
177
+ success: res?.data?.code === "0",
178
+ message: res?.data?.msg,
179
+ data: res?.data?.data || [],
180
+ };
181
+ }
182
+ }
@@ -0,0 +1,59 @@
1
+ import {
2
+ GetGasInfoParams,
3
+ GetGasInfoResponse,
4
+ GetTransactionParams,
5
+ GetTransactionsParams,
6
+ IPublicApiBaseConfig,
7
+ RemoteResponse,
8
+ } from "./types";
9
+ import { BasePublicService } from "./base";
10
+ import { TomoAppInfo } from "../types";
11
+
12
+ export class TransactionAPIs extends BasePublicService {
13
+ private static instance: TransactionAPIs;
14
+
15
+ private constructor(apiBase: IPublicApiBaseConfig, tomoAppInfo: TomoAppInfo) {
16
+ super(apiBase, tomoAppInfo);
17
+ }
18
+
19
+ public static getInstance(apiBase: IPublicApiBaseConfig, tomoAppInfo: TomoAppInfo) {
20
+ if (!this.instance) {
21
+ this.instance = new TransactionAPIs(apiBase, tomoAppInfo);
22
+ }
23
+ return this.instance;
24
+ }
25
+
26
+ async queryGasInfo(chainType: any, params: GetGasInfoParams): Promise<RemoteResponse<GetGasInfoResponse>> {
27
+ try {
28
+ const res = await this.txApi.post("/api/v1/quote/queryGasInfo", params);
29
+ return res?.data || {};
30
+ } catch (error) {
31
+ console.error("Failed to get gas info:", error);
32
+ throw error;
33
+ }
34
+ }
35
+
36
+ async getTransactions(params: GetTransactionsParams): Promise<RemoteResponse<any>> {
37
+ try {
38
+ const res = await this.walletApi.get("/v1/transaction/list", {
39
+ params,
40
+ });
41
+ return res?.data?.data || {};
42
+ } catch (error) {
43
+ console.error("Failed to get transactions:", error);
44
+ throw error;
45
+ }
46
+ }
47
+
48
+ async getTransaction(params: GetTransactionParams): Promise<RemoteResponse<any>> {
49
+ try {
50
+ const res = await this.walletApi.get("/v1/transaction/detail", {
51
+ params,
52
+ });
53
+ return res?.data?.data || {};
54
+ } catch (error) {
55
+ console.error("Failed to get transaction:", error);
56
+ throw error;
57
+ }
58
+ }
59
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Common types for API responses and requests
3
+ */
4
+
5
+ export interface ApiResponse<T> {
6
+ code: number;
7
+ message: string;
8
+ data: T;
9
+ }
10
+
11
+ export interface PaginationParams {
12
+ page: number;
13
+ pageSize: number;
14
+ }
15
+
16
+ export interface PaginatedResponse<T> {
17
+ items: T[];
18
+ total: number;
19
+ page: number;
20
+ pageSize: number;
21
+ }
22
+
23
+ export interface ApiConfig {
24
+ baseURL: string;
25
+ timeout?: number;
26
+ headers?: Record<string, string>;
27
+ }
28
+
29
+ export interface RequestOptions {
30
+ method: "GET" | "POST" | "PUT" | "DELETE";
31
+ path: string;
32
+ params?: Record<string, any>;
33
+ data?: any;
34
+ headers?: Record<string, string>;
35
+ }
@@ -0,0 +1,13 @@
1
+ export * from "./common";
2
+ export * from "./type";
3
+
4
+ export interface IPublicApiBaseConfig {
5
+ rpcBaseUrl: string;
6
+ walletBaseUrl: string;
7
+ txBaseUrl: string;
8
+ tokenBaseUrl: string;
9
+ }
10
+
11
+ export interface IPrivateApiBaseConfig {
12
+ userBaseUrl: string;
13
+ }
@@ -0,0 +1,283 @@
1
+ export interface ISocialBaseService {
2
+ setJwtToken(jwtToken: string): void;
3
+ }
4
+
5
+ export type TomoUserWallet = {
6
+ createdTime: string;
7
+ updatedTime: string;
8
+ id: string;
9
+ userId: string;
10
+ ethereumAddress: string;
11
+ solanaAddress: string;
12
+ bitcoinP2pkhAddress: string;
13
+ bitcoinP2trAddress: string;
14
+ bitcoinP2shAddress: string;
15
+ bitcoinP2wpkhAddress: string;
16
+ tonAddress: string;
17
+ tonAddressTest: string;
18
+ tonPublicKey: string;
19
+ tronAddress: string;
20
+ suiAddress: string;
21
+ cosmosAddress: string;
22
+ dogeAddress: string;
23
+ bitcoinP2pkhAddressTest: string;
24
+ bitcoinP2pkhPubKeyTest: string;
25
+ bitcoinP2pkhAddressMain: string;
26
+ bitcoinP2pkhPubKeyMain: string;
27
+ bitcoinP2trAddressTest: string;
28
+ bitcoinP2trPubKeyTest: string;
29
+ bitcoinP2trAddressMain: string;
30
+ bitcoinP2trPubKeyMain: string;
31
+ bitcoinP2shAddressTest: string;
32
+ bitcoinP2shPubKeyTest: string;
33
+ bitcoinP2shAddressMain: string;
34
+ bitcoinP2shPubKeyMain: string;
35
+ bitcoinP2wpkhAddressTest: string;
36
+ bitcoinP2wpkhPubKeyTest: string;
37
+ bitcoinP2wpkhAddressMain: string;
38
+ bitcoinP2wpkhPubKeyMain: string;
39
+ };
40
+
41
+ export type TomoUserBaseInfo = {
42
+ avatar: string;
43
+ nickname: string;
44
+ bio: string;
45
+ };
46
+
47
+ export type TomoUserInfo = TomoUserBaseInfo & {
48
+ userID: string;
49
+ accountID: string;
50
+ tenantID: string;
51
+ username: string;
52
+ nickname: string;
53
+ avatar: string;
54
+ freePasswordAuth: string;
55
+ forbidden: boolean;
56
+ deleted: boolean;
57
+ updatedTime: string;
58
+ };
59
+
60
+ export type TokenAssets = {
61
+ tokenAssets?: AssetInfo[];
62
+ };
63
+
64
+ export type AssetInfo = {
65
+ chainIndex: string;
66
+ tokenAddress: string;
67
+ symbol: string;
68
+ balance: string;
69
+ tokenPrice: string;
70
+ tokenType: string;
71
+ isRiskToken: boolean;
72
+ riskLevel: number;
73
+ transferAmount: string;
74
+ availableAmount: string;
75
+ rawBalance: string;
76
+ address: string;
77
+ };
78
+
79
+ export type RemoteChainInfo = {
80
+ chainName: string;
81
+ chainId: number;
82
+ chainIndex: number;
83
+ support: boolean;
84
+ orderStatusSupport: boolean;
85
+ supportBalance: boolean;
86
+ supportBroadcast: boolean;
87
+ type: number;
88
+ };
89
+
90
+ export interface RemoteChainInfo2 {
91
+ chainId: number;
92
+ chainIndex: number;
93
+ name: string;
94
+ chainName: string;
95
+ nativeCurrencyName: string;
96
+ nativeCurrencySymbol: string;
97
+ nativeCurrencyDecimals: number;
98
+ rpcUrls?: string[];
99
+ blockExplorerUrl?: string;
100
+ platformType: string;
101
+ isTestnet: boolean;
102
+ icon: string;
103
+ supportSwap: boolean;
104
+ supportGift: boolean;
105
+ supportHistory: boolean;
106
+ }
107
+
108
+ export type RemoteTokenInfo = {
109
+ chainIndex: number;
110
+ address: string;
111
+ isNative: boolean;
112
+ name: string;
113
+ displayName: string | null;
114
+ symbol: string;
115
+ logo: string;
116
+ decimals: number;
117
+ };
118
+
119
+ export type RemoteResponse<TData> = {
120
+ success: boolean;
121
+ message?: string;
122
+ data?: TData;
123
+ };
124
+
125
+ export type CreateWalletParams = {
126
+ walletId: string;
127
+ userId: string | number;
128
+ source: number; //fixed 2. 1:Create, 2:import mnemonic,3:import private key
129
+ type: 2; //fixed 2. 11:tomo,12:bot,2:WEB3
130
+ clientType: 4; // fixed 4. (1:telegram,2:ios,3:Android,4:plugin)
131
+ addressList: AddressListEntity[] | any;
132
+ };
133
+
134
+ export interface AddressListEntity {
135
+ chainIndex: number;
136
+ address: string;
137
+ }
138
+
139
+ export type SyncWalletParams = {
140
+ walletId: string;
141
+ addressList: (AddressListEntity & { operationType: 1 | 2 })[];
142
+ };
143
+
144
+ export type DeleteWalletParams = {
145
+ walletId: string;
146
+ };
147
+
148
+ export type GetTokenInfoParams = {
149
+ chainIndex: number;
150
+ address: string;
151
+ };
152
+
153
+ export type AddCustomTokenParams = {
154
+ walletId: string;
155
+ chainIndex: number;
156
+ address: string;
157
+ };
158
+
159
+ export type DeleteCustomTokenParams = {
160
+ walletId: string;
161
+ chainIndex: number;
162
+ address: string;
163
+ };
164
+
165
+ export type SyncCustomTokenParams = {
166
+ walletId: string;
167
+ chainId: string;
168
+ address: string;
169
+ name: string;
170
+ symbol: string;
171
+ decimals: number;
172
+ logo: string;
173
+ };
174
+
175
+ export type GetTokenBalanceParams = {
176
+ walletId: string;
177
+ chains?: string; // chainIndex1,chainIndex2
178
+ assetsType: "single" | "multi"; // is token merge by chainIndex or not
179
+ };
180
+
181
+ export type GetTransactionsParams = {
182
+ walletId: string;
183
+ chainIndex: number;
184
+ tokenAddress?: string;
185
+ typeList?: number;
186
+ cursor?: string;
187
+ pageLimit?: number; // default 10, max 20.
188
+ };
189
+
190
+ export type GetTransactionParams = {
191
+ walletId: string;
192
+ chainIndex: number;
193
+ txHash: string;
194
+ };
195
+
196
+ export type InitAccountData = any;
197
+
198
+ export type TokenBalance = {
199
+ chainIndex: string;
200
+ tokenAddress: string;
201
+ symbol: string;
202
+ balance: string;
203
+ isRiskToken: boolean;
204
+ riskLevel?: number;
205
+ address: string;
206
+ tokenPrice: string;
207
+ priceChangeH24: string;
208
+ imgUrl: string;
209
+ decimals: number;
210
+ name: string;
211
+ isHidden?: boolean;
212
+ isMultiChain?: boolean;
213
+ chainDetails?: [];
214
+ fourMemeToken?: any;
215
+ };
216
+ export type GetTokenBalanceResponse = {
217
+ total: string;
218
+ balance: TokenBalance[];
219
+ };
220
+
221
+ export type SignEthTypedData = {
222
+ primaryType: string;
223
+ types: {
224
+ additionalProp1: any;
225
+ additionalProp2: any;
226
+ additionalProp3: any;
227
+ };
228
+ domain: {
229
+ additionalProp1: any;
230
+ additionalProp2: any;
231
+ additionalProp3: any;
232
+ };
233
+ message: {
234
+ additionalProp1: any;
235
+ additionalProp2: any;
236
+ additionalProp3: any;
237
+ };
238
+ };
239
+
240
+ export type ETHTransactionParams = {
241
+ transaction: {
242
+ to: string;
243
+ from: string;
244
+ value: string;
245
+ data: string;
246
+ nonce: number;
247
+ gas: string;
248
+ gasPrice?: string;
249
+ maxFeePerGas: string;
250
+ maxPriorityFeePerGas: string;
251
+ minReceiveAmount?: string;
252
+ };
253
+ chainId: number;
254
+ };
255
+
256
+ export type DOGETransactionParams = {
257
+ rpcUrl: "string";
258
+ from: "string";
259
+ to: "string";
260
+ fee: "string";
261
+ amount: 0;
262
+ };
263
+ export type SignTransactionParams = ETHTransactionParams | DOGETransactionParams;
264
+
265
+ export type GasLimitParams = {
266
+ from: string;
267
+ to: string;
268
+ value: string;
269
+ };
270
+
271
+ export type GetGasInfoParams = {
272
+ chainIndex: number;
273
+ callData: string;
274
+ gasLimitParam: GasLimitParams;
275
+ addressList?: string[];
276
+ };
277
+ export type GetGasInfoResponse = {
278
+ gasLimit: string;
279
+ baseFee: string;
280
+ priorityFeeLow: string;
281
+ priorityFeeMedium: string;
282
+ priorityFeeHigh: string;
283
+ };
@@ -0,0 +1,83 @@
1
+ import { IPrivateApiBaseConfig, RemoteResponse, TomoUserInfo, TomoUserWallet } from "./types";
2
+ import { BasePrivateService } from "./base";
3
+ import { signature as signUtils } from "./utils";
4
+ import { TomoAppInfo } from "../types";
5
+
6
+ export class UserAPIs extends BasePrivateService {
7
+ private static instance: UserAPIs;
8
+
9
+ private constructor(apiBase: IPrivateApiBaseConfig, tomoAppInfo: TomoAppInfo) {
10
+ super(apiBase, tomoAppInfo);
11
+ }
12
+
13
+ public static getInstance(apiBase: IPrivateApiBaseConfig, tomoAppInfo: TomoAppInfo) {
14
+ if (!this.instance) {
15
+ this.instance = new UserAPIs(apiBase, tomoAppInfo);
16
+ }
17
+ return this.instance;
18
+ }
19
+
20
+ async getUserInfo(): Promise<RemoteResponse<{ user: TomoUserInfo; accountBaseInfo: any }>> {
21
+ const res = await this.userApi.post("/api/user/getUserInfo");
22
+
23
+ return {
24
+ success: res?.data?.code.toString() === "10000",
25
+ message: res?.data?.message,
26
+ data: res?.data?.data,
27
+ };
28
+ }
29
+
30
+ async updateUserInfo(userInfo: TomoUserInfo): Promise<RemoteResponse<TomoUserInfo>> {
31
+ if (!userInfo) throw new Error("User info is required");
32
+
33
+ // const { data: userInfoBefore } = await this.getUserInfo();
34
+ // userInfo = { ...userInfoBefore, ...userInfo };
35
+
36
+ const res = await this.userApi.post("/api/setting/updateUserInfo", userInfo);
37
+ return {
38
+ success: res?.data?.code.toString() === "10000",
39
+ message: res?.data?.message,
40
+ data: res?.data?.data,
41
+ };
42
+ }
43
+
44
+ async getUserWallet(): Promise<RemoteResponse<TomoUserWallet>> {
45
+ const res = await this.userApi.post("/api/account/getAccountInfo");
46
+ return {
47
+ success: res?.data?.success,
48
+ message: res?.data?.message,
49
+ data: res?.data?.data,
50
+ };
51
+ }
52
+
53
+ async addUserToCube(req: any, salt: string): Promise<RemoteResponse<any>> {
54
+ // sign for api
55
+ const { iss, sub } = req;
56
+ const { timestamp, signature } = await signUtils.generateCubeSignature({ iss, sub }, salt);
57
+ const signedReq = { ...req, timestamp, signature };
58
+
59
+ // send signatrue
60
+ const res = await this.userApi.post("/api/login/loginByCubistV2", signedReq);
61
+ return res?.data;
62
+ }
63
+
64
+ async isExistEmail(email: string): Promise<RemoteResponse<any>> {
65
+ const res = await this.userApi.post(`/api/login/isExistEmail?email=${email}`, { email });
66
+ return res?.data;
67
+ }
68
+
69
+ async sendExportSeedPhraseEmail(exportTime: number): Promise<RemoteResponse<any>> {
70
+ const res = await this.userApi.post(`/api/setting/exportSeedSendEmail?exportTime=${exportTime}`, {});
71
+ return res.data;
72
+ }
73
+
74
+ async sendCancelExportSeedPhraseEmail(): Promise<RemoteResponse<any>> {
75
+ const res = await this.userApi.post(`/api/setting/cancelExportSeedSendEmail`, {});
76
+ return res.data;
77
+ }
78
+
79
+ async sendChangeDeviceEmail(exportTime: number): Promise<RemoteResponse<any>> {
80
+ const res = await this.userApi.post(`/api/setting/changeDeviceSendEmail?exportTime=${exportTime}`, {});
81
+ return res.data;
82
+ }
83
+ }
@@ -0,0 +1,34 @@
1
+ import { ISignConfig } from "../types";
2
+ import * as signUtils from "./signature";
3
+ export { signUtils as signature };
4
+ export const formatJwtToken = (jwtToken: string) => `Bearer ${jwtToken}`;
5
+
6
+ export function signRequest(params: any, clientId: string, signParams: ISignConfig | string): any {
7
+ if (typeof signParams === "string") {
8
+ const jwtToken = signParams;
9
+ Object.assign(params.headers ?? {}, {
10
+ "client-id": clientId,
11
+ Authorization: formatJwtToken(jwtToken),
12
+ });
13
+ return params;
14
+ }
15
+
16
+ const { apiKey, apiSecret, salt } = signParams;
17
+ const { signature, timestamp } = signUtils.generateSignature({
18
+ method: params.method,
19
+ url: params.url,
20
+ data: params.data,
21
+ apiKey: apiKey,
22
+ apiSecret: apiSecret,
23
+ salt: salt,
24
+ });
25
+
26
+ Object.assign(params.headers ?? {}, {
27
+ "X-APP-Key": apiKey,
28
+ "X-Signature": signature,
29
+ "X-Timestamp": timestamp,
30
+ "client-id": clientId,
31
+ });
32
+
33
+ return params;
34
+ }