@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.
- package/CHANGELOG.md +3 -0
- package/README.md +15 -0
- package/package.json +38 -0
- package/project.json +59 -0
- package/src/api/__tests__/config.ts +21 -0
- package/src/api/__tests__/token.test.ts +120 -0
- package/src/api/__tests__/transaction.test.ts +86 -0
- package/src/api/__tests__/user.test.ts +105 -0
- package/src/api/__tests__/wallet.test.ts +73 -0
- package/src/api/base.ts +52 -0
- package/src/api/index.ts +24 -0
- package/src/api/network-data.ts +572 -0
- package/src/api/network.ts +81 -0
- package/src/api/token.ts +182 -0
- package/src/api/transaction.ts +59 -0
- package/src/api/types/common.ts +35 -0
- package/src/api/types/index.ts +13 -0
- package/src/api/types/type.ts +283 -0
- package/src/api/user.ts +83 -0
- package/src/api/utils/index.ts +34 -0
- package/src/api/utils/signature.ts +60 -0
- package/src/api/wallet.ts +57 -0
- package/src/base/network.ts +55 -0
- package/src/base/service.ts +33 -0
- package/src/base/token.ts +43 -0
- package/src/base/transaction.ts +58 -0
- package/src/config.ts +21 -0
- package/src/dogecoin/base.ts +39 -0
- package/src/dogecoin/config.ts +43 -0
- package/src/dogecoin/rpc.ts +449 -0
- package/src/dogecoin/service.ts +451 -0
- package/src/dogecoin/type.ts +29 -0
- package/src/dogecoin/utils-doge.ts +105 -0
- package/src/dogecoin/utils.ts +601 -0
- package/src/evm/rpc.ts +68 -0
- package/src/evm/service.ts +403 -0
- package/src/evm/utils.ts +92 -0
- package/src/index.ts +28 -0
- package/src/solana/config.ts +5 -0
- package/src/solana/service.ts +312 -0
- package/src/solana/types.ts +91 -0
- package/src/solana/utils.ts +635 -0
- package/src/types/account.ts +58 -0
- package/src/types/dapp.ts +7 -0
- package/src/types/gas.ts +53 -0
- package/src/types/index.ts +81 -0
- package/src/types/network.ts +66 -0
- package/src/types/tx.ts +181 -0
- package/src/types/wallet.ts +49 -0
- package/src/wallet.ts +96 -0
- package/tsconfig.json +14 -0
- package/tsup.config.ts +18 -0
package/CHANGELOG.md
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# @tomo-inc/chains-service
|
|
2
|
+
|
|
3
|
+
## support
|
|
4
|
+
|
|
5
|
+
1. rpc APIs: balance, gas, transaction detail,
|
|
6
|
+
2. chainType.EVM
|
|
7
|
+
3. wallet APIs: chains、transaction history
|
|
8
|
+
|
|
9
|
+
## how to use
|
|
10
|
+
|
|
11
|
+
demo: packages/social-account-sdk/src/cube-account.ts
|
|
12
|
+
|
|
13
|
+
## todo
|
|
14
|
+
|
|
15
|
+
1. support more chainType: SOL、DOGE、TRON、BTC....
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tomo-inc/chains-service",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"author": "tomo.inc",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"private": false,
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "./dist/index.cjs",
|
|
9
|
+
"module": "./dist/index.js",
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/index.js",
|
|
15
|
+
"require": "./dist/index.cjs"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@solana/spl-token": "^0.4.8",
|
|
20
|
+
"@solana/web3.js": "^1.98.0",
|
|
21
|
+
"axios": "^1.11.0",
|
|
22
|
+
"bignumber.js": "^9.1.2",
|
|
23
|
+
"bitcoinjs-lib": "^7.0.0",
|
|
24
|
+
"crypto-js": "4.2.0",
|
|
25
|
+
"viem": "2.21.54",
|
|
26
|
+
"@tomo-inc/wallet-utils": "0.0.2"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@types/supertest": "^2.0.12",
|
|
30
|
+
"@vitest/browser": "^3.2.4",
|
|
31
|
+
"playwright": "^1.44.1",
|
|
32
|
+
"supertest": "^6.3.0",
|
|
33
|
+
"tsup": "^8.0.0",
|
|
34
|
+
"tsx": "^4.19.2",
|
|
35
|
+
"typescript": "^5.0.0",
|
|
36
|
+
"vitest": "^3.2.4"
|
|
37
|
+
}
|
|
38
|
+
}
|
package/project.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "chains-service",
|
|
3
|
+
"sourceRoot": "packages/chains-service/src",
|
|
4
|
+
"projectType": "library",
|
|
5
|
+
"targets": {
|
|
6
|
+
"build": {
|
|
7
|
+
"executor": "nx:run-commands",
|
|
8
|
+
"outputs": ["{projectRoot}/dist"],
|
|
9
|
+
"options": {
|
|
10
|
+
"command": "tsup src/index.ts --format esm,cjs --dts --treeshake",
|
|
11
|
+
"cwd": "packages/chains-service"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"dev": {
|
|
15
|
+
"executor": "nx:run-commands",
|
|
16
|
+
"options": {
|
|
17
|
+
"command": "tsup src/index.ts --format esm,cjs --watch --dts",
|
|
18
|
+
"cwd": "packages/chains-service"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"lint": {
|
|
22
|
+
"executor": "nx:run-commands",
|
|
23
|
+
"options": {
|
|
24
|
+
"command": "eslint src/**/*.ts",
|
|
25
|
+
"cwd": "packages/chains-service"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"lint:fix": {
|
|
29
|
+
"executor": "nx:run-commands",
|
|
30
|
+
"options": {
|
|
31
|
+
"command": "eslint src/**/*.ts --fix",
|
|
32
|
+
"cwd": "packages/chains-service"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"format": {
|
|
36
|
+
"executor": "nx:run-commands",
|
|
37
|
+
"options": {
|
|
38
|
+
"command": "prettier --write \"src/**/*.{ts,tsx}\"",
|
|
39
|
+
"cwd": "packages/chains-service"
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
"test": {
|
|
43
|
+
"executor": "nx:run-commands",
|
|
44
|
+
"outputs": ["{projectRoot}/coverage"],
|
|
45
|
+
"options": {
|
|
46
|
+
"command": "vitest run",
|
|
47
|
+
"cwd": "packages/chains-service"
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
"test:watch": {
|
|
51
|
+
"executor": "nx:run-commands",
|
|
52
|
+
"options": {
|
|
53
|
+
"command": "vitest",
|
|
54
|
+
"cwd": "packages/chains-service"
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
"tags": ["npm:private", "scope:chains-service", "type:library"]
|
|
59
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { TomoApiDomains } from "@tomo-inc/wallet-utils";
|
|
2
|
+
const domain = TomoApiDomains["dev"];
|
|
3
|
+
|
|
4
|
+
export const CONFIG = {
|
|
5
|
+
rpcBaseUrl: domain,
|
|
6
|
+
walletBaseUrl: `${domain}/wallet`,
|
|
7
|
+
txBaseUrl: `${domain}/quote`,
|
|
8
|
+
tokenBaseUrl: `${domain}/token`,
|
|
9
|
+
userBaseUrl: `${domain}/user/api`,
|
|
10
|
+
clientId: "tvmff3fh5I0raW9xMN9zW8wW8WX4uUE9hmYnmwVuzh8rJ7vkglUzsQnzOqeSC8vC39vhPTPUIJFK5DwyHBkRIk4M",
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const SIGN_CONFIG = {
|
|
14
|
+
apiKey: "*****",
|
|
15
|
+
apiSecret: "*****",
|
|
16
|
+
salt: "*****",
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export const jwtToken = "";
|
|
20
|
+
|
|
21
|
+
export const salt = "";
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { CONFIG, SIGN_CONFIG } from "../__tests__/config";
|
|
2
|
+
import { TokenAPIs } from "../token";
|
|
3
|
+
import { beforeEach, describe, it, expect, vi, afterEach } from "vitest";
|
|
4
|
+
|
|
5
|
+
describe("api", () => {
|
|
6
|
+
let service: TokenAPIs;
|
|
7
|
+
const params = {
|
|
8
|
+
chainIndex: 50100,
|
|
9
|
+
chainId: "501",
|
|
10
|
+
name: "tokenTestName",
|
|
11
|
+
symbol: "tokenTestSymbol",
|
|
12
|
+
decimals: 6,
|
|
13
|
+
logo: "https://assets.tomo.org/token/50100/2NxhyCKNRp7qwhJj9rWHvqZqk6oA9aehDm8XWprDpump.png",
|
|
14
|
+
address: "2NxhyCKNRp7qwhJj9rWHvqZqk6oA9aehDm8XWprDpump",
|
|
15
|
+
tokenAddress: "2NxhyCKNRp7qwhJj9rWHvqZqk6oA9aehDm8XWprDpump",
|
|
16
|
+
walletId: "d1e88058-e979-5637-9daa-7f8cf4b454cb",
|
|
17
|
+
keyword: "5LThamuNW11L4Zf7mfMY8UKWf3ZByDwHq4CLTkc4bonk",
|
|
18
|
+
chains: "1,56",
|
|
19
|
+
assetsType: "multi",
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
beforeEach(() => {
|
|
23
|
+
service = TokenAPIs.getInstance(CONFIG, SIGN_CONFIG);
|
|
24
|
+
vi.clearAllMocks();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
afterEach(() => {
|
|
28
|
+
vi.restoreAllMocks();
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
describe("token", () => {
|
|
32
|
+
it("getTokenInfo", async () => {
|
|
33
|
+
const result = await service.getTokenInfo(params);
|
|
34
|
+
console.log("getTokenInfo", result);
|
|
35
|
+
|
|
36
|
+
expect(result?.data?.address).toBe(params.address);
|
|
37
|
+
// expect(result).toEqual(result.success === true);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("getTokenRisk", async () => {
|
|
41
|
+
const result = await service.getTokenRisk(params);
|
|
42
|
+
console.log("getTokenRisk", result);
|
|
43
|
+
|
|
44
|
+
expect(result?.data?.chainIndex).toBe(params.chainIndex);
|
|
45
|
+
expect(result?.data?.tokenAddress).toBe(params.tokenAddress);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("deleteCustomToken", async () => {
|
|
49
|
+
const result = await service.deleteCustomToken(params);
|
|
50
|
+
console.log("deleteCustomToken", result);
|
|
51
|
+
|
|
52
|
+
expect(typeof result.success).toBe("boolean");
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("addCustomToken", async () => {
|
|
56
|
+
const result = await service.addCustomToken(params);
|
|
57
|
+
console.log("addCustomToken", result);
|
|
58
|
+
|
|
59
|
+
expect(typeof result.success).toBe("boolean");
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("addMultiToken", async () => {
|
|
63
|
+
const result = await service.addMultiToken(params);
|
|
64
|
+
|
|
65
|
+
console.log("addMultiToken", result);
|
|
66
|
+
|
|
67
|
+
expect(typeof result.success).toBe("boolean");
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("removeMultiToken", async () => {
|
|
71
|
+
const result = await service.removeMultiToken(params);
|
|
72
|
+
console.log("removeMultiToken", result);
|
|
73
|
+
|
|
74
|
+
expect(typeof result.success).toBe("boolean");
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("syncCustomToken", async () => {
|
|
78
|
+
const result = await service.syncCustomToken({
|
|
79
|
+
walletId: params.walletId,
|
|
80
|
+
chainId: params.chainId,
|
|
81
|
+
address: params.address,
|
|
82
|
+
name: params.name,
|
|
83
|
+
symbol: params.symbol,
|
|
84
|
+
decimals: params.decimals,
|
|
85
|
+
logo: params.logo,
|
|
86
|
+
});
|
|
87
|
+
console.log("syncCustomToken", result);
|
|
88
|
+
|
|
89
|
+
expect(typeof result.success).toBe("boolean");
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("getTokenBalance", async () => {
|
|
93
|
+
const result = await service.getTokenBalance({
|
|
94
|
+
walletId: params.walletId,
|
|
95
|
+
assetsType: "multi",
|
|
96
|
+
});
|
|
97
|
+
console.log("getTokenBalance", result);
|
|
98
|
+
|
|
99
|
+
expect(typeof result.success).toBe("boolean");
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it("getTokenDetail", async () => {
|
|
103
|
+
const result = await service.getTokenDetail(params);
|
|
104
|
+
console.log("getTokenDetail", result);
|
|
105
|
+
|
|
106
|
+
expect(typeof result.success).toBe("boolean");
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it("queryRemoteTokens", async () => {
|
|
110
|
+
const params = {
|
|
111
|
+
keyword: "2NxhyCKNRp7qwhJj9rWHvqZqk6oA9aehDm8XWprDpump",
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const result = await service.queryRemoteTokens(params);
|
|
115
|
+
console.log("queryRemoteTokens", result);
|
|
116
|
+
|
|
117
|
+
expect(typeof result.success).toBe("boolean");
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
});
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { CONFIG, SIGN_CONFIG } from "./config";
|
|
2
|
+
import { TransactionAPIs } from "../transaction";
|
|
3
|
+
import { beforeEach, describe, it, expect, vi, afterEach } from "vitest";
|
|
4
|
+
|
|
5
|
+
describe("api", () => {
|
|
6
|
+
let service: TransactionAPIs;
|
|
7
|
+
|
|
8
|
+
const params = {
|
|
9
|
+
walletId: "d1e88058-e979-5637-9daa-7f8cf4b454cb",
|
|
10
|
+
chainIndex: 50100,
|
|
11
|
+
address: "2NxhyCKNRp7qwhJj9rWHvqZqk6oA9aehDm8XWprDpump",
|
|
12
|
+
orderId: "order123",
|
|
13
|
+
chainType: "DOGE",
|
|
14
|
+
txHash: "txHash123",
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
beforeEach(() => {
|
|
18
|
+
service = TransactionAPIs.getInstance(CONFIG, SIGN_CONFIG);
|
|
19
|
+
vi.clearAllMocks();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
afterEach(() => {
|
|
23
|
+
vi.restoreAllMocks();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
describe("transaction", () => {
|
|
27
|
+
it("getTransactions", async () => {
|
|
28
|
+
const result = await service.getTransactions(params);
|
|
29
|
+
console.log("getTransactions", result);
|
|
30
|
+
|
|
31
|
+
expect(typeof result.success).toBe("boolean");
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("getTransaction", async () => {
|
|
35
|
+
const result = await service.getTransaction(params);
|
|
36
|
+
console.log("getTransaction", result);
|
|
37
|
+
|
|
38
|
+
expect(typeof result.success).toBe("boolean");
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("queryGasInfo", async () => {
|
|
42
|
+
const gasParams = {
|
|
43
|
+
chainType: params.chainType,
|
|
44
|
+
from: params.address,
|
|
45
|
+
chainIndex: params.chainIndex,
|
|
46
|
+
to: "2NxhyCKNRp7qwhJj9rWHvqZqk6oA9aehDm8XWprDpump",
|
|
47
|
+
callData: "0x",
|
|
48
|
+
gasLimitParam: {
|
|
49
|
+
from: params.address,
|
|
50
|
+
to: "2NxhyCKNRp7qwhJj9rWHvqZqk6oA9aehDm8XWprDpump",
|
|
51
|
+
value: "1000000",
|
|
52
|
+
},
|
|
53
|
+
value: "1000000",
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const result = await service.queryGasInfo(params.chainType, gasParams);
|
|
57
|
+
console.log("queryGasInfo", result);
|
|
58
|
+
|
|
59
|
+
expect(typeof result.success).toBe("boolean");
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("sendTransaction", async () => {
|
|
63
|
+
const sendParams = {
|
|
64
|
+
walletId: params.walletId,
|
|
65
|
+
chainIndex: params.chainIndex,
|
|
66
|
+
from: params.address,
|
|
67
|
+
to: "2NxhyCKNRp7qwhJj9rWHvqZqk6oA9aehDm8XWprDpump",
|
|
68
|
+
value: "1000000",
|
|
69
|
+
gasPrice: "1000000000",
|
|
70
|
+
gasLimit: "21000",
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const result = await service.sendTransaction(sendParams);
|
|
74
|
+
console.log("sendTransaction", result);
|
|
75
|
+
|
|
76
|
+
expect(typeof result.success).toBe("boolean");
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("getOrderStatus", async () => {
|
|
80
|
+
const result = await service.getOrderStatus({ orderId: params.orderId });
|
|
81
|
+
console.log("getOrderStatus", result);
|
|
82
|
+
|
|
83
|
+
expect(typeof result.success).toBe("boolean");
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
});
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { CONFIG, jwtToken } from "./config";
|
|
2
|
+
import { UserAPIs } from "../user";
|
|
3
|
+
import { beforeEach, describe, it, expect, vi, afterEach } from "vitest";
|
|
4
|
+
|
|
5
|
+
describe("api", () => {
|
|
6
|
+
let service: UserAPIs;
|
|
7
|
+
const params = {
|
|
8
|
+
nickname: "Test User",
|
|
9
|
+
username: "testuser",
|
|
10
|
+
email: "test@example.com",
|
|
11
|
+
exportTime: 1759630767526,
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
service = UserAPIs.getInstance(CONFIG, jwtToken);
|
|
16
|
+
vi.clearAllMocks();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
afterEach(() => {
|
|
20
|
+
vi.restoreAllMocks();
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
describe("user", () => {
|
|
24
|
+
it("getUserInfo", async () => {
|
|
25
|
+
const result = await service.getUserInfo();
|
|
26
|
+
console.log("getUserInfo", result);
|
|
27
|
+
|
|
28
|
+
expect(typeof result.success).toBe("boolean");
|
|
29
|
+
expect(typeof result.data).toBe("object");
|
|
30
|
+
expect(typeof result.data?.userID).toBe("string");
|
|
31
|
+
expect(typeof result.data?.nickname).toBe("string");
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("updateUserInfo", async () => {
|
|
35
|
+
const r = Date.now() % 10;
|
|
36
|
+
const userInfo = {
|
|
37
|
+
nickname: `${params.nickname}_${r}`,
|
|
38
|
+
username: `${params.username}_${r}`,
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const result = await service.updateUserInfo(userInfo);
|
|
42
|
+
console.log("updateUserInfo", result);
|
|
43
|
+
|
|
44
|
+
expect(typeof result.success).toBe("boolean");
|
|
45
|
+
expect(typeof result.data).toBe("object");
|
|
46
|
+
expect(typeof result.data?.userID).toBe("string");
|
|
47
|
+
expect(result.data?.nickname).toBe(userInfo.nickname);
|
|
48
|
+
expect(result.data?.username).toBe(userInfo.username);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
// it("addUserToCube", async () => {
|
|
52
|
+
// const cubistIdentity = {
|
|
53
|
+
// id: "Proof#DNrsd2A5k=",
|
|
54
|
+
// preferred_username: "nuise",
|
|
55
|
+
// aud: "Vk13WDUDA6MTpjaQ",
|
|
56
|
+
// email: null,
|
|
57
|
+
// identity: {
|
|
58
|
+
// iss: "https://shim.oauth2.cubist.dev/twitter",
|
|
59
|
+
// sub: "18712172",
|
|
60
|
+
// },
|
|
61
|
+
// user_info: {
|
|
62
|
+
// user_id: "User#58cd7c7e-80e7-4887-b735-e47c3a06e0f2",
|
|
63
|
+
// initialized: true,
|
|
64
|
+
// },
|
|
65
|
+
// exp_epoch: 1754910294,
|
|
66
|
+
// };
|
|
67
|
+
|
|
68
|
+
// const iss = cubistIdentity?.identity?.iss;
|
|
69
|
+
// const sub = cubistIdentity?.identity?.sub;
|
|
70
|
+
|
|
71
|
+
// const req = {
|
|
72
|
+
// cubistUserID: cubistIdentity?.user_info?.user_id,
|
|
73
|
+
// aud: cubistIdentity?.aud,
|
|
74
|
+
// email: cubistIdentity?.email || null,
|
|
75
|
+
// iss,
|
|
76
|
+
// sub,
|
|
77
|
+
// initialized: cubistIdentity?.user_info?.initialized,
|
|
78
|
+
// };
|
|
79
|
+
|
|
80
|
+
// const result = await service.addUserToCube(req);
|
|
81
|
+
// console.log("addUserToCube", result);
|
|
82
|
+
|
|
83
|
+
// expect(typeof result).toBe("object");
|
|
84
|
+
// });
|
|
85
|
+
|
|
86
|
+
it("getUserWallet", async () => {
|
|
87
|
+
const result = await service.getUserWallet();
|
|
88
|
+
console.log("getUserWallet", result);
|
|
89
|
+
|
|
90
|
+
expect(typeof result.success).toBe("boolean");
|
|
91
|
+
expect(typeof result.data).toBe("object");
|
|
92
|
+
expect(typeof result.data?.id).toBe("string");
|
|
93
|
+
expect(typeof result.data?.bitcoinP2shPubKeyMain).toBe("string");
|
|
94
|
+
expect(typeof result.data?.deleted).toBe("boolean");
|
|
95
|
+
expect(typeof result.data?.solanaAddress).toBe("string");
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it("isExistEmail", async () => {
|
|
99
|
+
const result = await service.isExistEmail(params.email);
|
|
100
|
+
console.log("isExistEmail", result);
|
|
101
|
+
|
|
102
|
+
expect(typeof result).toBe("object");
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
});
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { CONFIG, SIGN_CONFIG } from "./config";
|
|
2
|
+
import { WalletAPIs } from "../wallet";
|
|
3
|
+
import { beforeEach, describe, it, expect, vi, afterEach } from "vitest";
|
|
4
|
+
|
|
5
|
+
describe("api", () => {
|
|
6
|
+
let service: WalletAPIs;
|
|
7
|
+
const params = {
|
|
8
|
+
walletId: "d1e88058-e979-5637-9daa-7f8cf4b454cb",
|
|
9
|
+
chainIndex: 50100,
|
|
10
|
+
address: "2NxhyCKNRp7qwhJj9rWHvqZqk6oA9aehDm8XWprDpump",
|
|
11
|
+
publicKey: "publicKey123",
|
|
12
|
+
path: "m/44'/3'/0'/0/0",
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
service = WalletAPIs.getInstance(CONFIG, SIGN_CONFIG);
|
|
17
|
+
vi.clearAllMocks();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
afterEach(() => {
|
|
21
|
+
vi.restoreAllMocks();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
describe("wallet", () => {
|
|
25
|
+
it("createWallet", async () => {
|
|
26
|
+
const createParams = {
|
|
27
|
+
walletId: params.walletId,
|
|
28
|
+
chainIndex: params.chainIndex,
|
|
29
|
+
address: params.address,
|
|
30
|
+
publicKey: params.publicKey,
|
|
31
|
+
path: params.path,
|
|
32
|
+
userId: "5001704",
|
|
33
|
+
source: 2,
|
|
34
|
+
type: 2 as const,
|
|
35
|
+
clientType: 4 as const,
|
|
36
|
+
addressList: [],
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const result = await service.createWallet(createParams);
|
|
40
|
+
console.log("createWallet", result);
|
|
41
|
+
|
|
42
|
+
expect(result).toEqual(typeof result.data === "object");
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("syncWallet", async () => {
|
|
46
|
+
const syncParams = {
|
|
47
|
+
walletId: params.walletId,
|
|
48
|
+
chainIndex: params.chainIndex,
|
|
49
|
+
address: params.address,
|
|
50
|
+
publicKey: params.publicKey,
|
|
51
|
+
path: params.path,
|
|
52
|
+
addressList: [],
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const result = await service.syncWallet(syncParams);
|
|
56
|
+
console.log("syncWallet", result);
|
|
57
|
+
|
|
58
|
+
expect(result).toEqual(typeof result.data === "object");
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it("deleteWallet", async () => {
|
|
62
|
+
const deleteParams = {
|
|
63
|
+
walletId: params.walletId,
|
|
64
|
+
chainIndex: params.chainIndex,
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const result = await service.deleteWallet(deleteParams);
|
|
68
|
+
console.log("deleteWallet", result);
|
|
69
|
+
|
|
70
|
+
expect(result).toEqual(typeof result.data === "object");
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
});
|
package/src/api/base.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import axios, { AxiosInstance } from "axios";
|
|
2
|
+
import { signRequest } from "./utils";
|
|
3
|
+
import { IPrivateApiBaseConfig, IPublicApiBaseConfig } from "./types";
|
|
4
|
+
import { TomoAppInfo } from "../types";
|
|
5
|
+
|
|
6
|
+
export class BasePublicService {
|
|
7
|
+
public tokenApi: AxiosInstance = axios.create();
|
|
8
|
+
public txApi: AxiosInstance = axios.create();
|
|
9
|
+
public walletApi: AxiosInstance = axios.create();
|
|
10
|
+
private apiBase: IPublicApiBaseConfig;
|
|
11
|
+
private tomoAppInfo: TomoAppInfo;
|
|
12
|
+
|
|
13
|
+
public constructor(publicApiBase: IPublicApiBaseConfig, tomoAppInfo: TomoAppInfo) {
|
|
14
|
+
this.apiBase = publicApiBase;
|
|
15
|
+
this.tomoAppInfo = tomoAppInfo;
|
|
16
|
+
|
|
17
|
+
[this.tokenApi, this.txApi, this.walletApi].map((api, i) =>
|
|
18
|
+
api.interceptors.request.use((params: any) => {
|
|
19
|
+
const { tokenBaseUrl, txBaseUrl, walletBaseUrl } = publicApiBase;
|
|
20
|
+
params.baseURL = [tokenBaseUrl, txBaseUrl, walletBaseUrl][i] as string;
|
|
21
|
+
return signRequest(params, tomoAppInfo.tomoClientId, tomoAppInfo);
|
|
22
|
+
}),
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
private getSignConfig() {
|
|
27
|
+
return this.tomoAppInfo;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export class BasePrivateService {
|
|
32
|
+
public userApi: AxiosInstance = axios.create();
|
|
33
|
+
private apiBase: IPrivateApiBaseConfig;
|
|
34
|
+
private jwtToken: string;
|
|
35
|
+
|
|
36
|
+
public constructor(privateApiBase: IPrivateApiBaseConfig, tomoAppInfo: TomoAppInfo) {
|
|
37
|
+
this.jwtToken = tomoAppInfo.jwtToken || "";
|
|
38
|
+
this.apiBase = privateApiBase;
|
|
39
|
+
|
|
40
|
+
[this.userApi].map((api, i) =>
|
|
41
|
+
api.interceptors.request.use((params: any) => {
|
|
42
|
+
const { userBaseUrl } = privateApiBase;
|
|
43
|
+
params.baseURL = [userBaseUrl][i] as string;
|
|
44
|
+
return signRequest(params, tomoAppInfo.tomoClientId, this.jwtToken);
|
|
45
|
+
}),
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
public getJwtToken() {
|
|
50
|
+
return this.jwtToken;
|
|
51
|
+
}
|
|
52
|
+
}
|
package/src/api/index.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { IPrivateApiBaseConfig, IPublicApiBaseConfig } from "./types";
|
|
2
|
+
import { TomoAppInfo } from "../types";
|
|
3
|
+
import { UserAPIs } from "./user";
|
|
4
|
+
import { TokenAPIs } from "./token";
|
|
5
|
+
import { TransactionAPIs } from "./transaction";
|
|
6
|
+
import { WalletAPIs } from "./wallet";
|
|
7
|
+
import { signature } from "./utils";
|
|
8
|
+
import { NetworkAPIs } from "./network";
|
|
9
|
+
export const utils = { signature };
|
|
10
|
+
|
|
11
|
+
export function tomoPublicApiService(publicApiBase: IPublicApiBaseConfig, tomoAppInfo: TomoAppInfo) {
|
|
12
|
+
return {
|
|
13
|
+
tokenAPIs: TokenAPIs.getInstance(publicApiBase, tomoAppInfo),
|
|
14
|
+
transactionAPIs: TransactionAPIs.getInstance(publicApiBase, tomoAppInfo),
|
|
15
|
+
networkAPIs: NetworkAPIs.getInstance(publicApiBase, tomoAppInfo),
|
|
16
|
+
walletAPIs: WalletAPIs.getInstance(publicApiBase, tomoAppInfo),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function tomoPrivateApiService(privateApiBase: IPrivateApiBaseConfig, tomoAppInfo: TomoAppInfo) {
|
|
21
|
+
return {
|
|
22
|
+
userAPIs: UserAPIs.getInstance(privateApiBase, tomoAppInfo),
|
|
23
|
+
};
|
|
24
|
+
}
|