@tomo-inc/wallet-adaptor-base 0.0.19 → 0.0.21
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 +18 -22
- package/dist/index.d.cts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +18 -22
- package/package.json +7 -2
- package/project.json +1 -1
- package/src/__tests__/WalletConnectProvider.test.ts +535 -0
- package/src/__tests__/WalletConnectSolanaProvider.test.ts +537 -0
- package/src/__tests__/browsers.test.ts +263 -0
- package/src/__tests__/chainId.test.ts +66 -0
- package/src/__tests__/chains-utils.test.ts +49 -0
- package/src/__tests__/defaultConnectors.test.ts +8 -5
- package/src/__tests__/detector.test.ts +402 -0
- package/src/__tests__/index.test.ts +275 -0
- package/src/__tests__/isMobile.test.ts +187 -0
- package/src/__tests__/log.test.ts +40 -0
- package/src/__tests__/utils.test.ts +66 -0
- package/src/__tests__/wallet-api.test.ts +1755 -0
- package/src/__tests__/wallet-config.test.ts +75 -0
- package/src/__tests__/wallet-eip6963.test.ts +377 -0
- package/src/__tests__/wallet-standard.test.ts +41 -3
- package/src/__tests__/wallet-walletconnect.test.ts +370 -0
- package/src/__tests__/wallets/index.test.ts +42 -0
- package/src/type.ts +4 -0
- package/src/utils/chainId.ts +6 -5
- package/src/utils/wallet-config.ts +2 -9
- package/src/wallet-api/connect.ts +4 -2
- package/src/wallets/detector.ts +3 -4
- package/src/wallets/providers/WalletConnectProvider.ts +5 -4
- package/src/wallets/providers/WalletConnectSolanaProvider.ts +1 -1
- package/src/wallets/wallet-eip6963.ts +1 -1
- package/vitest.config.ts +20 -0
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach, afterEach } from "vitest";
|
|
2
|
+
import { isMobile, isAndroid, isSmallIOS, isLargeIOS, isIOS } from "../utils/isMobile";
|
|
3
|
+
|
|
4
|
+
describe("isMobile", () => {
|
|
5
|
+
let originalUserAgent: string;
|
|
6
|
+
let originalPlatform: string;
|
|
7
|
+
let originalMaxTouchPoints: number;
|
|
8
|
+
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
originalUserAgent = navigator.userAgent;
|
|
11
|
+
originalPlatform = navigator.platform;
|
|
12
|
+
originalMaxTouchPoints = navigator.maxTouchPoints;
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
afterEach(() => {
|
|
16
|
+
Object.defineProperty(navigator, "userAgent", {
|
|
17
|
+
value: originalUserAgent,
|
|
18
|
+
writable: true,
|
|
19
|
+
configurable: true,
|
|
20
|
+
});
|
|
21
|
+
Object.defineProperty(navigator, "platform", {
|
|
22
|
+
value: originalPlatform,
|
|
23
|
+
writable: true,
|
|
24
|
+
configurable: true,
|
|
25
|
+
});
|
|
26
|
+
Object.defineProperty(navigator, "maxTouchPoints", {
|
|
27
|
+
value: originalMaxTouchPoints,
|
|
28
|
+
writable: true,
|
|
29
|
+
configurable: true,
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
describe("isAndroid", () => {
|
|
34
|
+
it("should detect Android", () => {
|
|
35
|
+
Object.defineProperty(navigator, "userAgent", {
|
|
36
|
+
value: "Mozilla/5.0 (Linux; Android 10) Mobile",
|
|
37
|
+
writable: true,
|
|
38
|
+
configurable: true,
|
|
39
|
+
});
|
|
40
|
+
expect(isAndroid()).toBe(true);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("should return false for non-Android", () => {
|
|
44
|
+
Object.defineProperty(navigator, "userAgent", {
|
|
45
|
+
value: "Mozilla/5.0 (Windows NT 10.0; Win64; x64)",
|
|
46
|
+
writable: true,
|
|
47
|
+
configurable: true,
|
|
48
|
+
});
|
|
49
|
+
expect(isAndroid()).toBe(false);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
describe("isSmallIOS", () => {
|
|
54
|
+
it("should detect iPhone", () => {
|
|
55
|
+
Object.defineProperty(navigator, "userAgent", {
|
|
56
|
+
value: "Mozilla/5.0 (iPhone; CPU iPhone OS 14_0 like Mac OS X)",
|
|
57
|
+
writable: true,
|
|
58
|
+
configurable: true,
|
|
59
|
+
});
|
|
60
|
+
expect(isSmallIOS()).toBe(true);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("should detect iPod", () => {
|
|
64
|
+
Object.defineProperty(navigator, "userAgent", {
|
|
65
|
+
value: "Mozilla/5.0 (iPod; CPU iPhone OS 14_0 like Mac OS X)",
|
|
66
|
+
writable: true,
|
|
67
|
+
configurable: true,
|
|
68
|
+
});
|
|
69
|
+
expect(isSmallIOS()).toBe(true);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("should return false for non-iPhone/iPod", () => {
|
|
73
|
+
Object.defineProperty(navigator, "userAgent", {
|
|
74
|
+
value: "Mozilla/5.0 (Windows NT 10.0; Win64; x64)",
|
|
75
|
+
writable: true,
|
|
76
|
+
configurable: true,
|
|
77
|
+
});
|
|
78
|
+
expect(isSmallIOS()).toBe(false);
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
describe("isLargeIOS", () => {
|
|
83
|
+
it("should detect iPad", () => {
|
|
84
|
+
Object.defineProperty(navigator, "userAgent", {
|
|
85
|
+
value: "Mozilla/5.0 (iPad; CPU OS 14_0 like Mac OS X)",
|
|
86
|
+
writable: true,
|
|
87
|
+
configurable: true,
|
|
88
|
+
});
|
|
89
|
+
expect(isLargeIOS()).toBe(true);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("should detect iPad on MacIntel", () => {
|
|
93
|
+
Object.defineProperty(navigator, "userAgent", {
|
|
94
|
+
value: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)",
|
|
95
|
+
writable: true,
|
|
96
|
+
configurable: true,
|
|
97
|
+
});
|
|
98
|
+
Object.defineProperty(navigator, "platform", {
|
|
99
|
+
value: "MacIntel",
|
|
100
|
+
writable: true,
|
|
101
|
+
configurable: true,
|
|
102
|
+
});
|
|
103
|
+
Object.defineProperty(navigator, "maxTouchPoints", {
|
|
104
|
+
value: 5,
|
|
105
|
+
writable: true,
|
|
106
|
+
configurable: true,
|
|
107
|
+
});
|
|
108
|
+
expect(isLargeIOS()).toBe(true);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it("should return false for non-iPad", () => {
|
|
112
|
+
Object.defineProperty(navigator, "userAgent", {
|
|
113
|
+
value: "Mozilla/5.0 (Windows NT 10.0; Win64; x64)",
|
|
114
|
+
writable: true,
|
|
115
|
+
configurable: true,
|
|
116
|
+
});
|
|
117
|
+
expect(isLargeIOS()).toBe(false);
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
describe("isIOS", () => {
|
|
122
|
+
it("should return true for iPhone", () => {
|
|
123
|
+
Object.defineProperty(navigator, "userAgent", {
|
|
124
|
+
value: "Mozilla/5.0 (iPhone; CPU iPhone OS 14_0 like Mac OS X)",
|
|
125
|
+
writable: true,
|
|
126
|
+
configurable: true,
|
|
127
|
+
});
|
|
128
|
+
expect(isIOS()).toBe(true);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it("should return true for iPad", () => {
|
|
132
|
+
Object.defineProperty(navigator, "userAgent", {
|
|
133
|
+
value: "Mozilla/5.0 (iPad; CPU OS 14_0 like Mac OS X)",
|
|
134
|
+
writable: true,
|
|
135
|
+
configurable: true,
|
|
136
|
+
});
|
|
137
|
+
expect(isIOS()).toBe(true);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it("should return false for non-iOS", () => {
|
|
141
|
+
Object.defineProperty(navigator, "userAgent", {
|
|
142
|
+
value: "Mozilla/5.0 (Windows NT 10.0; Win64; x64)",
|
|
143
|
+
writable: true,
|
|
144
|
+
configurable: true,
|
|
145
|
+
});
|
|
146
|
+
expect(isIOS()).toBe(false);
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
describe("isMobile", () => {
|
|
151
|
+
it("should return true for Android", () => {
|
|
152
|
+
Object.defineProperty(navigator, "userAgent", {
|
|
153
|
+
value: "Mozilla/5.0 (Linux; Android 10) Mobile",
|
|
154
|
+
writable: true,
|
|
155
|
+
configurable: true,
|
|
156
|
+
});
|
|
157
|
+
expect(isMobile()).toBe(true);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it("should return true for iPhone", () => {
|
|
161
|
+
Object.defineProperty(navigator, "userAgent", {
|
|
162
|
+
value: "Mozilla/5.0 (iPhone; CPU iPhone OS 14_0 like Mac OS X)",
|
|
163
|
+
writable: true,
|
|
164
|
+
configurable: true,
|
|
165
|
+
});
|
|
166
|
+
expect(isMobile()).toBe(true);
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it("should return true for iPad", () => {
|
|
170
|
+
Object.defineProperty(navigator, "userAgent", {
|
|
171
|
+
value: "Mozilla/5.0 (iPad; CPU OS 14_0 like Mac OS X)",
|
|
172
|
+
writable: true,
|
|
173
|
+
configurable: true,
|
|
174
|
+
});
|
|
175
|
+
expect(isMobile()).toBe(true);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it("should return false for desktop", () => {
|
|
179
|
+
Object.defineProperty(navigator, "userAgent", {
|
|
180
|
+
value: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36",
|
|
181
|
+
writable: true,
|
|
182
|
+
configurable: true,
|
|
183
|
+
});
|
|
184
|
+
expect(isMobile()).toBe(false);
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
2
|
+
import { debugLog } from "../utils/log";
|
|
3
|
+
|
|
4
|
+
describe("log", () => {
|
|
5
|
+
let originalConsoleLog: typeof console.log;
|
|
6
|
+
let consoleLogSpy: ReturnType<typeof vi.spyOn>;
|
|
7
|
+
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
originalConsoleLog = console.log;
|
|
10
|
+
consoleLogSpy = vi.spyOn(console, "log").mockImplementation(() => {});
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
afterEach(() => {
|
|
14
|
+
console.log = originalConsoleLog;
|
|
15
|
+
vi.restoreAllMocks();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
describe("debugLog", () => {
|
|
19
|
+
it("should log when isDebug is true", () => {
|
|
20
|
+
debugLog("test message", 123, { key: "value" });
|
|
21
|
+
expect(consoleLogSpy).toHaveBeenCalledWith("test message", 123, { key: "value" });
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("should handle multiple arguments", () => {
|
|
25
|
+
debugLog("arg1", "arg2", "arg3");
|
|
26
|
+
expect(consoleLogSpy).toHaveBeenCalledWith("arg1", "arg2", "arg3");
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("should handle empty arguments", () => {
|
|
30
|
+
debugLog();
|
|
31
|
+
expect(consoleLogSpy).toHaveBeenCalledWith();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("should handle complex objects", () => {
|
|
35
|
+
const complexObj = { nested: { deep: { value: 42 } } };
|
|
36
|
+
debugLog(complexObj);
|
|
37
|
+
expect(consoleLogSpy).toHaveBeenCalledWith(complexObj);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { uniqueConnectors, uint8arrayToHex } from "../utils/utils";
|
|
3
|
+
import type { Connector } from "../type";
|
|
4
|
+
|
|
5
|
+
describe("utils", () => {
|
|
6
|
+
describe("uniqueConnectors", () => {
|
|
7
|
+
it("should remove duplicate connectors by rdns", () => {
|
|
8
|
+
const connectors: Connector[] = [
|
|
9
|
+
{
|
|
10
|
+
info: { name: "Wallet1", rdns: "com.wallet1" },
|
|
11
|
+
} as Connector,
|
|
12
|
+
{
|
|
13
|
+
info: { name: "Wallet1", rdns: "com.wallet1" },
|
|
14
|
+
} as Connector,
|
|
15
|
+
{
|
|
16
|
+
info: { name: "Wallet2", rdns: "com.wallet2" },
|
|
17
|
+
} as Connector,
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
const result = uniqueConnectors(connectors);
|
|
21
|
+
expect(result.length).toBe(2);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("should remove duplicate connectors by name if rdns is missing", () => {
|
|
25
|
+
const connectors: Connector[] = [
|
|
26
|
+
{
|
|
27
|
+
info: { name: "Wallet1" },
|
|
28
|
+
} as Connector,
|
|
29
|
+
{
|
|
30
|
+
info: { name: "Wallet1" },
|
|
31
|
+
} as Connector,
|
|
32
|
+
{
|
|
33
|
+
info: { name: "Wallet2" },
|
|
34
|
+
} as Connector,
|
|
35
|
+
];
|
|
36
|
+
|
|
37
|
+
const result = uniqueConnectors(connectors);
|
|
38
|
+
expect(result.length).toBe(2);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("should handle empty array", () => {
|
|
42
|
+
const result = uniqueConnectors([]);
|
|
43
|
+
expect(result).toEqual([]);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
describe("uint8arrayToHex", () => {
|
|
48
|
+
it("should convert Uint8Array to hex string", () => {
|
|
49
|
+
const arr = new Uint8Array([0, 255, 16, 15]);
|
|
50
|
+
const result = uint8arrayToHex(arr);
|
|
51
|
+
expect(result).toBe("00ff100f");
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("should handle empty array", () => {
|
|
55
|
+
const arr = new Uint8Array([]);
|
|
56
|
+
const result = uint8arrayToHex(arr);
|
|
57
|
+
expect(result).toBe("");
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("should pad single digit hex values", () => {
|
|
61
|
+
const arr = new Uint8Array([0, 1, 15, 255]);
|
|
62
|
+
const result = uint8arrayToHex(arr);
|
|
63
|
+
expect(result).toBe("00010fff");
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
});
|