@keplr-wallet/background 0.10.23 → 0.10.24

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 (49) hide show
  1. package/build/index.d.ts +1 -0
  2. package/build/index.js +9 -0
  3. package/build/index.js.map +1 -1
  4. package/build/phishing-list/constants.d.ts +1 -0
  5. package/build/phishing-list/constants.js +5 -0
  6. package/build/phishing-list/constants.js.map +1 -0
  7. package/build/phishing-list/handler.d.ts +3 -0
  8. package/build/phishing-list/handler.js +19 -0
  9. package/build/phishing-list/handler.js.map +1 -0
  10. package/build/phishing-list/index.d.ts +2 -0
  11. package/build/phishing-list/index.js +15 -0
  12. package/build/phishing-list/index.js.map +1 -0
  13. package/build/phishing-list/init.d.ts +3 -0
  14. package/build/phishing-list/init.js +12 -0
  15. package/build/phishing-list/init.js.map +1 -0
  16. package/build/phishing-list/internal.d.ts +2 -0
  17. package/build/phishing-list/internal.js +15 -0
  18. package/build/phishing-list/internal.js.map +1 -0
  19. package/build/phishing-list/messages.d.ts +9 -0
  20. package/build/phishing-list/messages.js +30 -0
  21. package/build/phishing-list/messages.js.map +1 -0
  22. package/build/phishing-list/messages.spec.d.ts +1 -0
  23. package/build/phishing-list/messages.spec.js +102 -0
  24. package/build/phishing-list/messages.spec.js.map +1 -0
  25. package/build/phishing-list/service.d.ts +22 -0
  26. package/build/phishing-list/service.js +86 -0
  27. package/build/phishing-list/service.js.map +1 -0
  28. package/build/phishing-list/service.spec.d.ts +1 -0
  29. package/build/phishing-list/service.spec.js +302 -0
  30. package/build/phishing-list/service.spec.js.map +1 -0
  31. package/build/phishing-list/utils.d.ts +1 -0
  32. package/build/phishing-list/utils.js +27 -0
  33. package/build/phishing-list/utils.js.map +1 -0
  34. package/build/phishing-list/utils.spec.d.ts +1 -0
  35. package/build/phishing-list/utils.spec.js +142 -0
  36. package/build/phishing-list/utils.spec.js.map +1 -0
  37. package/package.json +11 -11
  38. package/src/index.ts +11 -0
  39. package/src/phishing-list/constants.ts +1 -0
  40. package/src/phishing-list/handler.ts +27 -0
  41. package/src/phishing-list/index.ts +2 -0
  42. package/src/phishing-list/init.ts +11 -0
  43. package/src/phishing-list/internal.ts +2 -0
  44. package/src/phishing-list/messages.spec.ts +104 -0
  45. package/src/phishing-list/messages.ts +32 -0
  46. package/src/phishing-list/service.spec.ts +367 -0
  47. package/src/phishing-list/service.ts +88 -0
  48. package/src/phishing-list/utils.spec.ts +144 -0
  49. package/src/phishing-list/utils.ts +27 -0
@@ -0,0 +1,144 @@
1
+ import { parseDomainUntilSecondLevel } from "./utils";
2
+
3
+ describe("Test phishing list service utils", () => {
4
+ test("Test parseDomainUntilSecondLevel", () => {
5
+ const tests: ({
6
+ url: string;
7
+ } & ({ expect: string } | { invalid: true }))[] = [
8
+ {
9
+ url: "",
10
+ invalid: true,
11
+ },
12
+ {
13
+ url: ".",
14
+ invalid: true,
15
+ },
16
+ {
17
+ url: "..",
18
+ invalid: true,
19
+ },
20
+ {
21
+ url: ".test.",
22
+ invalid: true,
23
+ },
24
+ {
25
+ url: "..test",
26
+ invalid: true,
27
+ },
28
+ {
29
+ url: "test.com.",
30
+ expect: "test.com",
31
+ },
32
+ {
33
+ url: "test.com..",
34
+ expect: "test.com",
35
+ },
36
+ {
37
+ url: ".test.com.",
38
+ expect: "test.com",
39
+ },
40
+ {
41
+ url: "..test.com..",
42
+ expect: "test.com",
43
+ },
44
+ {
45
+ url: "test..com",
46
+ expect: "test.com",
47
+ },
48
+ {
49
+ url: "..test..com..",
50
+ expect: "test.com",
51
+ },
52
+ {
53
+ url: "asd.test.com.",
54
+ expect: "test.com",
55
+ },
56
+ {
57
+ url: "asd..test.com.",
58
+ expect: "test.com",
59
+ },
60
+ {
61
+ url: "http://",
62
+ invalid: true,
63
+ },
64
+ {
65
+ url: "https://.",
66
+ invalid: true,
67
+ },
68
+ {
69
+ url: "https://..",
70
+ invalid: true,
71
+ },
72
+ {
73
+ url: "https://.test.",
74
+ invalid: true,
75
+ },
76
+ {
77
+ url: "https://..test",
78
+ invalid: true,
79
+ },
80
+ {
81
+ url: "https://test.com.",
82
+ expect: "test.com",
83
+ },
84
+ {
85
+ url: "https://test.com..",
86
+ expect: "test.com",
87
+ },
88
+ {
89
+ url: "https://.test.com.",
90
+ expect: "test.com",
91
+ },
92
+ {
93
+ url: "https://..test.com..",
94
+ expect: "test.com",
95
+ },
96
+ {
97
+ url: "https://test..com",
98
+ expect: "test.com",
99
+ },
100
+ {
101
+ url: "https://..test..com..",
102
+ expect: "test.com",
103
+ },
104
+ {
105
+ url: "https://asd.test.com.",
106
+ expect: "test.com",
107
+ },
108
+ {
109
+ url: "https://asd..test.com.",
110
+ expect: "test.com",
111
+ },
112
+ {
113
+ url:
114
+ "chrome-extension://hajcclbibbmagnhankhjinooiploogfm/_generated_background_page.html",
115
+ invalid: true,
116
+ },
117
+ {
118
+ url: "chrome-extension://hajcclbibbmagnhankhjinooiploogfm.test/",
119
+ expect: "hajcclbibbmagnhankhjinooiploogfm.test",
120
+ },
121
+ {
122
+ url: "chrome-extension://hajcclbibbmagnhankhjinooiploogfm.test/?test=1",
123
+ expect: "hajcclbibbmagnhankhjinooiploogfm.test",
124
+ },
125
+ {
126
+ url: "chrome-extension://hajcclbibbmagnhankhjinooiploogfm.test?test=1",
127
+ expect: "hajcclbibbmagnhankhjinooiploogfm.test",
128
+ },
129
+ {
130
+ url:
131
+ "chrome-extension://hajcclbibbmagnhankhjinooiploogfm.test/_generated_background_page.html",
132
+ expect: "hajcclbibbmagnhankhjinooiploogfm.test",
133
+ },
134
+ ];
135
+
136
+ for (const test of tests) {
137
+ if ("invalid" in test) {
138
+ expect(() => parseDomainUntilSecondLevel(test.url)).toThrow();
139
+ } else {
140
+ expect(parseDomainUntilSecondLevel(test.url)).toBe(test.expect);
141
+ }
142
+ }
143
+ });
144
+ });
@@ -0,0 +1,27 @@
1
+ export function parseDomainUntilSecondLevel(param: string): string {
2
+ let domain = param;
3
+
4
+ if (domain.match(/^[a-zA-Z0-9-]+:\/\/.+$/)) {
5
+ domain = domain.replace(/^[a-zA-Z0-9-]+:\/\//, "");
6
+ }
7
+
8
+ const slash = domain.indexOf("/");
9
+ if (slash >= 0) {
10
+ domain = domain.slice(0, slash);
11
+ }
12
+ const qMark = domain.indexOf("?");
13
+ if (qMark >= 0) {
14
+ domain = domain.slice(0, qMark);
15
+ }
16
+
17
+ const split = domain
18
+ .split(".")
19
+ .map((str) => str.trim())
20
+ .filter((str) => str.length > 0);
21
+
22
+ if (split.length < 2) {
23
+ throw new Error(`Invalid domain: ${param}`);
24
+ }
25
+
26
+ return split[split.length - 2] + "." + split[split.length - 1];
27
+ }