@tomo-inc/wallet-utils 0.0.4 → 0.0.5
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 +349 -0
- package/dist/index.d.cts +78 -0
- package/dist/index.d.ts +78 -0
- package/dist/index.js +332 -0
- package/package.json +1 -1
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __export = (target, all) => {
|
|
5
|
+
for (var name in all)
|
|
6
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
// src/cache.ts
|
|
10
|
+
var cache_exports = {};
|
|
11
|
+
__export(cache_exports, {
|
|
12
|
+
clear: () => clear,
|
|
13
|
+
get: () => get,
|
|
14
|
+
remove: () => remove,
|
|
15
|
+
set: () => set,
|
|
16
|
+
setKeyNS: () => setKeyNS
|
|
17
|
+
});
|
|
18
|
+
var keyNS = "tomo-";
|
|
19
|
+
function get(key) {
|
|
20
|
+
if (typeof window === "undefined") {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
const tempKey = keyNS + key;
|
|
24
|
+
if (!isKeyExist(tempKey)) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
let val = null;
|
|
28
|
+
try {
|
|
29
|
+
const data = window.localStorage.getItem(tempKey) || window.sessionStorage.getItem(tempKey);
|
|
30
|
+
val = JSON.parse(data);
|
|
31
|
+
} catch (err) {
|
|
32
|
+
console.error(err);
|
|
33
|
+
}
|
|
34
|
+
if (val !== null && Object.prototype.hasOwnProperty.call(val, "type") && Object.prototype.hasOwnProperty.call(val, "data")) {
|
|
35
|
+
return val["data"];
|
|
36
|
+
}
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
function set(key, val, isTemp) {
|
|
40
|
+
if (typeof window === "undefined") {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
let store;
|
|
44
|
+
if (isTemp) {
|
|
45
|
+
store = window.sessionStorage;
|
|
46
|
+
} else {
|
|
47
|
+
store = window.localStorage;
|
|
48
|
+
}
|
|
49
|
+
const data = JSON.stringify({
|
|
50
|
+
data: val,
|
|
51
|
+
time: (/* @__PURE__ */ new Date()).getTime(),
|
|
52
|
+
//for manage by time limit
|
|
53
|
+
type: typeof val
|
|
54
|
+
});
|
|
55
|
+
try {
|
|
56
|
+
store.setItem(keyNS + key, data);
|
|
57
|
+
return true;
|
|
58
|
+
} catch (err) {
|
|
59
|
+
if (err?.name?.toUpperCase().indexOf("QUOTA") >= 0) {
|
|
60
|
+
window.localStorage.clear();
|
|
61
|
+
store.setItem(keyNS + key, data);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
function remove(key) {
|
|
67
|
+
if (typeof window === "undefined") {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const tempKey = keyNS + key;
|
|
71
|
+
window.localStorage.removeItem(tempKey);
|
|
72
|
+
window.sessionStorage.removeItem(tempKey);
|
|
73
|
+
}
|
|
74
|
+
function clear() {
|
|
75
|
+
if (typeof window === "undefined") {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
window?.localStorage?.clear();
|
|
79
|
+
window?.sessionStorage?.clear();
|
|
80
|
+
}
|
|
81
|
+
function isKeyExist(key) {
|
|
82
|
+
if (typeof window === "undefined") {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
return Object.prototype.hasOwnProperty.call(window.localStorage, key) || Object.prototype.hasOwnProperty.call(window.sessionStorage, key);
|
|
86
|
+
}
|
|
87
|
+
function setKeyNS(NS) {
|
|
88
|
+
const isString = typeof NS === "string";
|
|
89
|
+
if (isString && NS !== "") {
|
|
90
|
+
keyNS = NS;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// src/broswer.ts
|
|
95
|
+
var getBrowserName = () => {
|
|
96
|
+
if (typeof window === "undefined") {
|
|
97
|
+
return "";
|
|
98
|
+
}
|
|
99
|
+
const userAgent = window.navigator.userAgent;
|
|
100
|
+
if (userAgent.includes("Safari/") && !userAgent.includes("Chrome/")) {
|
|
101
|
+
return "Safari";
|
|
102
|
+
}
|
|
103
|
+
if (userAgent.includes("Edg/")) {
|
|
104
|
+
return "Edge";
|
|
105
|
+
}
|
|
106
|
+
if (userAgent.includes("Firefox/")) {
|
|
107
|
+
return "Firefox";
|
|
108
|
+
}
|
|
109
|
+
if (userAgent.includes("Chrome/")) {
|
|
110
|
+
return "Chrome";
|
|
111
|
+
}
|
|
112
|
+
const brave = window.navigator?.brave;
|
|
113
|
+
if (brave?.isBrave?.()) {
|
|
114
|
+
return "Brave";
|
|
115
|
+
}
|
|
116
|
+
if (userAgent.includes("Opera/") || userAgent.includes("OPR/")) {
|
|
117
|
+
return "Opera";
|
|
118
|
+
}
|
|
119
|
+
return "";
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
// src/email.ts
|
|
123
|
+
var maskEmail = (email) => {
|
|
124
|
+
if (!email) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
const parts = email.split("@");
|
|
128
|
+
if (parts.length === 2) {
|
|
129
|
+
let username = parts[0];
|
|
130
|
+
const domain = parts[1];
|
|
131
|
+
if (username.length >= 4) {
|
|
132
|
+
username = username.slice(0, -3) + "***";
|
|
133
|
+
} else {
|
|
134
|
+
username = username + "*".repeat(4 - username.length);
|
|
135
|
+
}
|
|
136
|
+
const maskedEmail = `${username}@${domain}`;
|
|
137
|
+
return maskedEmail;
|
|
138
|
+
} else {
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
var isEmail = (email) => {
|
|
143
|
+
return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
// src/global-config.ts
|
|
147
|
+
var ChainTypes = /* @__PURE__ */ ((ChainTypes2) => {
|
|
148
|
+
ChainTypes2["BTC"] = "btc";
|
|
149
|
+
ChainTypes2["DOGE"] = "doge";
|
|
150
|
+
ChainTypes2["EVM"] = "evm";
|
|
151
|
+
ChainTypes2["SOL"] = "sol";
|
|
152
|
+
ChainTypes2["SUI"] = "sui";
|
|
153
|
+
ChainTypes2["TON"] = "ton";
|
|
154
|
+
ChainTypes2["TRON"] = "tron";
|
|
155
|
+
ChainTypes2["COSMOS"] = "cosmos";
|
|
156
|
+
ChainTypes2["APTOS"] = "aptos";
|
|
157
|
+
return ChainTypes2;
|
|
158
|
+
})(ChainTypes || {});
|
|
159
|
+
var SupportedChainTypes = {
|
|
160
|
+
["doge" /* DOGE */]: {
|
|
161
|
+
chainId: "3",
|
|
162
|
+
chainIndex: 300,
|
|
163
|
+
support: true,
|
|
164
|
+
gasFee: 0.5,
|
|
165
|
+
dust: 1e-4
|
|
166
|
+
},
|
|
167
|
+
["evm" /* EVM */]: {
|
|
168
|
+
chainId: "1",
|
|
169
|
+
chainIndex: 100,
|
|
170
|
+
support: true,
|
|
171
|
+
gasFee: 1e-5,
|
|
172
|
+
dust: 0
|
|
173
|
+
},
|
|
174
|
+
["sol" /* SOL */]: {
|
|
175
|
+
chainId: "501",
|
|
176
|
+
chainIndex: 50100,
|
|
177
|
+
support: true,
|
|
178
|
+
gasFee: 1e-4,
|
|
179
|
+
dust: 0,
|
|
180
|
+
reserve: 9e-4
|
|
181
|
+
// Available balance = Total balance - Reserve balance (for rent exemption)
|
|
182
|
+
},
|
|
183
|
+
["tron" /* TRON */]: {
|
|
184
|
+
chainId: "19484",
|
|
185
|
+
chainIndex: 1948400,
|
|
186
|
+
support: true,
|
|
187
|
+
gasFee: 0.5,
|
|
188
|
+
dust: 0
|
|
189
|
+
},
|
|
190
|
+
["btc" /* BTC */]: {
|
|
191
|
+
chainId: "0",
|
|
192
|
+
//livenet
|
|
193
|
+
chainIndex: 0,
|
|
194
|
+
support: false,
|
|
195
|
+
gasFee: 1e-5,
|
|
196
|
+
dust: 1e-4
|
|
197
|
+
},
|
|
198
|
+
["sui" /* SUI */]: {
|
|
199
|
+
support: false,
|
|
200
|
+
gasFee: 0,
|
|
201
|
+
dust: 0
|
|
202
|
+
},
|
|
203
|
+
["ton" /* TON */]: {
|
|
204
|
+
support: false,
|
|
205
|
+
gasFee: 0,
|
|
206
|
+
dust: 0
|
|
207
|
+
},
|
|
208
|
+
["cosmos" /* COSMOS */]: {
|
|
209
|
+
support: false,
|
|
210
|
+
gasFee: 0,
|
|
211
|
+
dust: 0
|
|
212
|
+
},
|
|
213
|
+
["aptos" /* APTOS */]: {
|
|
214
|
+
support: false,
|
|
215
|
+
gasFee: 0,
|
|
216
|
+
dust: 0
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
// src/password.ts
|
|
221
|
+
var validatePassword = (password) => {
|
|
222
|
+
const lengthValid = password.length >= 8 && password.length <= 32;
|
|
223
|
+
const hasLetter = /[a-zA-Z]/.test(password);
|
|
224
|
+
const hasNumber = /[0-9]/.test(password);
|
|
225
|
+
return lengthValid && hasLetter && hasNumber;
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
// src/string.ts
|
|
229
|
+
function stripHexPrefix(str) {
|
|
230
|
+
if (typeof str !== "string") {
|
|
231
|
+
return str;
|
|
232
|
+
}
|
|
233
|
+
return str.startsWith("0x") ? str.slice(2) : str;
|
|
234
|
+
}
|
|
235
|
+
function compareString(a, b) {
|
|
236
|
+
return a.toLowerCase() === b.toLowerCase();
|
|
237
|
+
}
|
|
238
|
+
function subs(temp, data, regexp) {
|
|
239
|
+
if (!(Object.prototype.toString.call(data) === "[object Array]")) data = [data];
|
|
240
|
+
const ret = [];
|
|
241
|
+
for (let i = 0, j = data.length; i < j; i++) {
|
|
242
|
+
ret.push(replaceAction(data[i]));
|
|
243
|
+
}
|
|
244
|
+
return ret.join("");
|
|
245
|
+
function replaceAction(object) {
|
|
246
|
+
return temp.replace(regexp || /\\?\{([^}]+)\}/g, function(match, name) {
|
|
247
|
+
if (match.charAt(0) == "\\") return match.slice(1);
|
|
248
|
+
return object[name] != void 0 ? object[name] : "";
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
function getExplorerUrl(chainIndex, data) {
|
|
253
|
+
const linkTpls = {
|
|
254
|
+
"0": "",
|
|
255
|
+
"100": "https://etherscan.io/tx/{txId}",
|
|
256
|
+
"300": "https://dogechain.info/tx/{txId}",
|
|
257
|
+
"400": "",
|
|
258
|
+
"1000": "https://optimistic.etherscan.io/tx/{txId}",
|
|
259
|
+
"5600": "https://bscscan.com/tx/{txId}",
|
|
260
|
+
"12600": "https://explorer.movementnetwork.xyz/txn/{txId}?network=mainnet",
|
|
261
|
+
"13700": "https://polygonscan.com/tx/{txId}",
|
|
262
|
+
"20400": "https://opbnb.bscscan.com/tx/{txId}",
|
|
263
|
+
"22300": "https://explorer.bsquared.network/tx/{txId}",
|
|
264
|
+
"22700": "https://promscan.io/tx/{txId}",
|
|
265
|
+
"32400": "https://mainnet.era.zksync.io/tx/{txId}",
|
|
266
|
+
"48000": "https://worldchain-mainnet.explorer.alchemy.com/tx/{txId}",
|
|
267
|
+
"50100": "https://solscan.io/tx/{txId}",
|
|
268
|
+
"78400": "",
|
|
269
|
+
"110000": "",
|
|
270
|
+
"132900": "https://seitrace.com/tx/{txId}",
|
|
271
|
+
"151400": "https://mainnet.storyscan.xyz/tx/{txId}",
|
|
272
|
+
"162500": "https://explorer.gravity.xyz/tx/{txId}",
|
|
273
|
+
"264900": "https://mainnet-explorer.ailayer.xyz/tx/{txId}",
|
|
274
|
+
"420000": "https://scan.merlinchain.io/tx/{txId}",
|
|
275
|
+
"554500": "https://scan.duckchain.io/tx/{txId}",
|
|
276
|
+
"833300": "https://mainnet-rpc.b3.fun/http/tx/{txId}",
|
|
277
|
+
"845300": "https://base.blockscout.com/tx/{txId}",
|
|
278
|
+
"1948400": "https://tronscan.org/#/transaction/{txId}",
|
|
279
|
+
"4216100": "https://arbiscan.io/tx/{txId}",
|
|
280
|
+
"4311400": "https://snowtrace.io/tx/{txId}",
|
|
281
|
+
"4776300": "https://neotube.io/transaction/{txId}",
|
|
282
|
+
"5914400": "https://lineascan.build/tx/{txId}",
|
|
283
|
+
"6080800": "https://rpc.gobob.xyz/tx/{txId}",
|
|
284
|
+
"8009400": "https://berascan.com/tx/{txId}",
|
|
285
|
+
"8145700": "https://blastscan.io/tx/{txId}",
|
|
286
|
+
"20090100": "https://rpc.bitlayer.org/tx/{txId}",
|
|
287
|
+
"53435200": "https://scrollscan.com/tx/{txId}",
|
|
288
|
+
"221122420": "https://blockscout.devnet.doge.xyz/tx/{txId}",
|
|
289
|
+
"2100000000": "https://maizenet-explorer.usecorn.com/tx/{txId}"
|
|
290
|
+
};
|
|
291
|
+
const key = chainIndex.toString();
|
|
292
|
+
const linkTpl = linkTpls[key] || "";
|
|
293
|
+
if (linkTpl === "") {
|
|
294
|
+
throw new Error(`chainIndex ${chainIndex} tpl not found`);
|
|
295
|
+
}
|
|
296
|
+
return subs(linkTpl, data);
|
|
297
|
+
}
|
|
298
|
+
function calcCtrLength(str) {
|
|
299
|
+
let length = 0;
|
|
300
|
+
str = str.trim();
|
|
301
|
+
for (let i = 0; i < str.length; i++) {
|
|
302
|
+
const code = str.charCodeAt(i);
|
|
303
|
+
if (code >= 19968 && code <= 40869) {
|
|
304
|
+
length += 2;
|
|
305
|
+
} else {
|
|
306
|
+
length += 1;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
return { len: length, originLen: str.length };
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// src/index.ts
|
|
313
|
+
var CubeStages = {
|
|
314
|
+
prod: "prod",
|
|
315
|
+
pre: "prod",
|
|
316
|
+
dev: "gamma"
|
|
317
|
+
};
|
|
318
|
+
var CubeOrgIds = {
|
|
319
|
+
prod: "Org#49944bce-9daf-423f-a982-269f6d0d301b",
|
|
320
|
+
pre: "Org#71c13f6d-b992-4660-874d-2ae0fadc789f",
|
|
321
|
+
dev: "Org#3d07a75a-1188-4bd0-acfa-671a198b83eb"
|
|
322
|
+
};
|
|
323
|
+
var RelayOrigins = {
|
|
324
|
+
prod: "https://social-relay.tomo.inc",
|
|
325
|
+
pre: "https://social-relay.tomo.inc",
|
|
326
|
+
dev: "https://social-relay-dev.tomo.inc"
|
|
327
|
+
};
|
|
328
|
+
var TomoApiDomains = {
|
|
329
|
+
prod: "https://wallet-pro.tomo.inc",
|
|
330
|
+
pre: "https://wallet-pre-wlfi.tomo.inc",
|
|
331
|
+
dev: "https://wallet-test.tomo.inc"
|
|
332
|
+
};
|
|
333
|
+
|
|
334
|
+
exports.ChainTypes = ChainTypes;
|
|
335
|
+
exports.CubeOrgIds = CubeOrgIds;
|
|
336
|
+
exports.CubeStages = CubeStages;
|
|
337
|
+
exports.RelayOrigins = RelayOrigins;
|
|
338
|
+
exports.SupportedChainTypes = SupportedChainTypes;
|
|
339
|
+
exports.TomoApiDomains = TomoApiDomains;
|
|
340
|
+
exports.cache = cache_exports;
|
|
341
|
+
exports.calcCtrLength = calcCtrLength;
|
|
342
|
+
exports.compareString = compareString;
|
|
343
|
+
exports.getBrowserName = getBrowserName;
|
|
344
|
+
exports.getExplorerUrl = getExplorerUrl;
|
|
345
|
+
exports.isEmail = isEmail;
|
|
346
|
+
exports.maskEmail = maskEmail;
|
|
347
|
+
exports.stripHexPrefix = stripHexPrefix;
|
|
348
|
+
exports.subs = subs;
|
|
349
|
+
exports.validatePassword = validatePassword;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
declare function get(key: string): any;
|
|
2
|
+
declare function set(key: string, val: any, isTemp: boolean): boolean;
|
|
3
|
+
declare function remove(key: string): void;
|
|
4
|
+
declare function clear(): void;
|
|
5
|
+
declare function setKeyNS(NS: string): void;
|
|
6
|
+
|
|
7
|
+
declare const cache_clear: typeof clear;
|
|
8
|
+
declare const cache_get: typeof get;
|
|
9
|
+
declare const cache_remove: typeof remove;
|
|
10
|
+
declare const cache_set: typeof set;
|
|
11
|
+
declare const cache_setKeyNS: typeof setKeyNS;
|
|
12
|
+
declare namespace cache {
|
|
13
|
+
export { cache_clear as clear, cache_get as get, cache_remove as remove, cache_set as set, cache_setKeyNS as setKeyNS };
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
declare const getBrowserName: () => string;
|
|
17
|
+
|
|
18
|
+
declare const maskEmail: (email: string) => string | null | undefined;
|
|
19
|
+
declare const isEmail: (email: string) => boolean;
|
|
20
|
+
|
|
21
|
+
declare enum ChainTypes {
|
|
22
|
+
BTC = "btc",
|
|
23
|
+
DOGE = "doge",
|
|
24
|
+
EVM = "evm",
|
|
25
|
+
SOL = "sol",
|
|
26
|
+
SUI = "sui",
|
|
27
|
+
TON = "ton",
|
|
28
|
+
TRON = "tron",
|
|
29
|
+
COSMOS = "cosmos",
|
|
30
|
+
APTOS = "aptos"
|
|
31
|
+
}
|
|
32
|
+
interface ChainTypeConfig {
|
|
33
|
+
chainId?: string;
|
|
34
|
+
chainIndex?: number;
|
|
35
|
+
support: boolean;
|
|
36
|
+
gasFee: number;
|
|
37
|
+
dust: number;
|
|
38
|
+
reserve?: number;
|
|
39
|
+
}
|
|
40
|
+
declare const SupportedChainTypes: Record<ChainTypes, ChainTypeConfig>;
|
|
41
|
+
|
|
42
|
+
declare const validatePassword: (password: string) => boolean;
|
|
43
|
+
|
|
44
|
+
declare function stripHexPrefix(str: string): string;
|
|
45
|
+
declare function compareString(a: string, b: string): boolean;
|
|
46
|
+
declare function subs(temp: string, data: any, regexp?: RegExp): string;
|
|
47
|
+
declare function getExplorerUrl(chainIndex: number, data: {
|
|
48
|
+
txId: string;
|
|
49
|
+
}): string;
|
|
50
|
+
declare function calcCtrLength(str: string): {
|
|
51
|
+
len: number;
|
|
52
|
+
originLen: number;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
type TomoStage = "prod" | "pre" | "dev";
|
|
56
|
+
type CubeStage = "gamma" | "prod";
|
|
57
|
+
declare const CubeStages: {
|
|
58
|
+
prod: string;
|
|
59
|
+
pre: string;
|
|
60
|
+
dev: string;
|
|
61
|
+
};
|
|
62
|
+
declare const CubeOrgIds: {
|
|
63
|
+
prod: string;
|
|
64
|
+
pre: string;
|
|
65
|
+
dev: string;
|
|
66
|
+
};
|
|
67
|
+
declare const RelayOrigins: {
|
|
68
|
+
prod: string;
|
|
69
|
+
pre: string;
|
|
70
|
+
dev: string;
|
|
71
|
+
};
|
|
72
|
+
declare const TomoApiDomains: {
|
|
73
|
+
prod: string;
|
|
74
|
+
pre: string;
|
|
75
|
+
dev: string;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export { ChainTypes, CubeOrgIds, type CubeStage, CubeStages, RelayOrigins, SupportedChainTypes, TomoApiDomains, type TomoStage, cache, calcCtrLength, compareString, getBrowserName, getExplorerUrl, isEmail, maskEmail, stripHexPrefix, subs, validatePassword };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
declare function get(key: string): any;
|
|
2
|
+
declare function set(key: string, val: any, isTemp: boolean): boolean;
|
|
3
|
+
declare function remove(key: string): void;
|
|
4
|
+
declare function clear(): void;
|
|
5
|
+
declare function setKeyNS(NS: string): void;
|
|
6
|
+
|
|
7
|
+
declare const cache_clear: typeof clear;
|
|
8
|
+
declare const cache_get: typeof get;
|
|
9
|
+
declare const cache_remove: typeof remove;
|
|
10
|
+
declare const cache_set: typeof set;
|
|
11
|
+
declare const cache_setKeyNS: typeof setKeyNS;
|
|
12
|
+
declare namespace cache {
|
|
13
|
+
export { cache_clear as clear, cache_get as get, cache_remove as remove, cache_set as set, cache_setKeyNS as setKeyNS };
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
declare const getBrowserName: () => string;
|
|
17
|
+
|
|
18
|
+
declare const maskEmail: (email: string) => string | null | undefined;
|
|
19
|
+
declare const isEmail: (email: string) => boolean;
|
|
20
|
+
|
|
21
|
+
declare enum ChainTypes {
|
|
22
|
+
BTC = "btc",
|
|
23
|
+
DOGE = "doge",
|
|
24
|
+
EVM = "evm",
|
|
25
|
+
SOL = "sol",
|
|
26
|
+
SUI = "sui",
|
|
27
|
+
TON = "ton",
|
|
28
|
+
TRON = "tron",
|
|
29
|
+
COSMOS = "cosmos",
|
|
30
|
+
APTOS = "aptos"
|
|
31
|
+
}
|
|
32
|
+
interface ChainTypeConfig {
|
|
33
|
+
chainId?: string;
|
|
34
|
+
chainIndex?: number;
|
|
35
|
+
support: boolean;
|
|
36
|
+
gasFee: number;
|
|
37
|
+
dust: number;
|
|
38
|
+
reserve?: number;
|
|
39
|
+
}
|
|
40
|
+
declare const SupportedChainTypes: Record<ChainTypes, ChainTypeConfig>;
|
|
41
|
+
|
|
42
|
+
declare const validatePassword: (password: string) => boolean;
|
|
43
|
+
|
|
44
|
+
declare function stripHexPrefix(str: string): string;
|
|
45
|
+
declare function compareString(a: string, b: string): boolean;
|
|
46
|
+
declare function subs(temp: string, data: any, regexp?: RegExp): string;
|
|
47
|
+
declare function getExplorerUrl(chainIndex: number, data: {
|
|
48
|
+
txId: string;
|
|
49
|
+
}): string;
|
|
50
|
+
declare function calcCtrLength(str: string): {
|
|
51
|
+
len: number;
|
|
52
|
+
originLen: number;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
type TomoStage = "prod" | "pre" | "dev";
|
|
56
|
+
type CubeStage = "gamma" | "prod";
|
|
57
|
+
declare const CubeStages: {
|
|
58
|
+
prod: string;
|
|
59
|
+
pre: string;
|
|
60
|
+
dev: string;
|
|
61
|
+
};
|
|
62
|
+
declare const CubeOrgIds: {
|
|
63
|
+
prod: string;
|
|
64
|
+
pre: string;
|
|
65
|
+
dev: string;
|
|
66
|
+
};
|
|
67
|
+
declare const RelayOrigins: {
|
|
68
|
+
prod: string;
|
|
69
|
+
pre: string;
|
|
70
|
+
dev: string;
|
|
71
|
+
};
|
|
72
|
+
declare const TomoApiDomains: {
|
|
73
|
+
prod: string;
|
|
74
|
+
pre: string;
|
|
75
|
+
dev: string;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export { ChainTypes, CubeOrgIds, type CubeStage, CubeStages, RelayOrigins, SupportedChainTypes, TomoApiDomains, type TomoStage, cache, calcCtrLength, compareString, getBrowserName, getExplorerUrl, isEmail, maskEmail, stripHexPrefix, subs, validatePassword };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __export = (target, all) => {
|
|
3
|
+
for (var name in all)
|
|
4
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
// src/cache.ts
|
|
8
|
+
var cache_exports = {};
|
|
9
|
+
__export(cache_exports, {
|
|
10
|
+
clear: () => clear,
|
|
11
|
+
get: () => get,
|
|
12
|
+
remove: () => remove,
|
|
13
|
+
set: () => set,
|
|
14
|
+
setKeyNS: () => setKeyNS
|
|
15
|
+
});
|
|
16
|
+
var keyNS = "tomo-";
|
|
17
|
+
function get(key) {
|
|
18
|
+
if (typeof window === "undefined") {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
const tempKey = keyNS + key;
|
|
22
|
+
if (!isKeyExist(tempKey)) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
let val = null;
|
|
26
|
+
try {
|
|
27
|
+
const data = window.localStorage.getItem(tempKey) || window.sessionStorage.getItem(tempKey);
|
|
28
|
+
val = JSON.parse(data);
|
|
29
|
+
} catch (err) {
|
|
30
|
+
console.error(err);
|
|
31
|
+
}
|
|
32
|
+
if (val !== null && Object.prototype.hasOwnProperty.call(val, "type") && Object.prototype.hasOwnProperty.call(val, "data")) {
|
|
33
|
+
return val["data"];
|
|
34
|
+
}
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
function set(key, val, isTemp) {
|
|
38
|
+
if (typeof window === "undefined") {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
let store;
|
|
42
|
+
if (isTemp) {
|
|
43
|
+
store = window.sessionStorage;
|
|
44
|
+
} else {
|
|
45
|
+
store = window.localStorage;
|
|
46
|
+
}
|
|
47
|
+
const data = JSON.stringify({
|
|
48
|
+
data: val,
|
|
49
|
+
time: (/* @__PURE__ */ new Date()).getTime(),
|
|
50
|
+
//for manage by time limit
|
|
51
|
+
type: typeof val
|
|
52
|
+
});
|
|
53
|
+
try {
|
|
54
|
+
store.setItem(keyNS + key, data);
|
|
55
|
+
return true;
|
|
56
|
+
} catch (err) {
|
|
57
|
+
if (err?.name?.toUpperCase().indexOf("QUOTA") >= 0) {
|
|
58
|
+
window.localStorage.clear();
|
|
59
|
+
store.setItem(keyNS + key, data);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
function remove(key) {
|
|
65
|
+
if (typeof window === "undefined") {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const tempKey = keyNS + key;
|
|
69
|
+
window.localStorage.removeItem(tempKey);
|
|
70
|
+
window.sessionStorage.removeItem(tempKey);
|
|
71
|
+
}
|
|
72
|
+
function clear() {
|
|
73
|
+
if (typeof window === "undefined") {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
window?.localStorage?.clear();
|
|
77
|
+
window?.sessionStorage?.clear();
|
|
78
|
+
}
|
|
79
|
+
function isKeyExist(key) {
|
|
80
|
+
if (typeof window === "undefined") {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
return Object.prototype.hasOwnProperty.call(window.localStorage, key) || Object.prototype.hasOwnProperty.call(window.sessionStorage, key);
|
|
84
|
+
}
|
|
85
|
+
function setKeyNS(NS) {
|
|
86
|
+
const isString = typeof NS === "string";
|
|
87
|
+
if (isString && NS !== "") {
|
|
88
|
+
keyNS = NS;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// src/broswer.ts
|
|
93
|
+
var getBrowserName = () => {
|
|
94
|
+
if (typeof window === "undefined") {
|
|
95
|
+
return "";
|
|
96
|
+
}
|
|
97
|
+
const userAgent = window.navigator.userAgent;
|
|
98
|
+
if (userAgent.includes("Safari/") && !userAgent.includes("Chrome/")) {
|
|
99
|
+
return "Safari";
|
|
100
|
+
}
|
|
101
|
+
if (userAgent.includes("Edg/")) {
|
|
102
|
+
return "Edge";
|
|
103
|
+
}
|
|
104
|
+
if (userAgent.includes("Firefox/")) {
|
|
105
|
+
return "Firefox";
|
|
106
|
+
}
|
|
107
|
+
if (userAgent.includes("Chrome/")) {
|
|
108
|
+
return "Chrome";
|
|
109
|
+
}
|
|
110
|
+
const brave = window.navigator?.brave;
|
|
111
|
+
if (brave?.isBrave?.()) {
|
|
112
|
+
return "Brave";
|
|
113
|
+
}
|
|
114
|
+
if (userAgent.includes("Opera/") || userAgent.includes("OPR/")) {
|
|
115
|
+
return "Opera";
|
|
116
|
+
}
|
|
117
|
+
return "";
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
// src/email.ts
|
|
121
|
+
var maskEmail = (email) => {
|
|
122
|
+
if (!email) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
const parts = email.split("@");
|
|
126
|
+
if (parts.length === 2) {
|
|
127
|
+
let username = parts[0];
|
|
128
|
+
const domain = parts[1];
|
|
129
|
+
if (username.length >= 4) {
|
|
130
|
+
username = username.slice(0, -3) + "***";
|
|
131
|
+
} else {
|
|
132
|
+
username = username + "*".repeat(4 - username.length);
|
|
133
|
+
}
|
|
134
|
+
const maskedEmail = `${username}@${domain}`;
|
|
135
|
+
return maskedEmail;
|
|
136
|
+
} else {
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
var isEmail = (email) => {
|
|
141
|
+
return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
// src/global-config.ts
|
|
145
|
+
var ChainTypes = /* @__PURE__ */ ((ChainTypes2) => {
|
|
146
|
+
ChainTypes2["BTC"] = "btc";
|
|
147
|
+
ChainTypes2["DOGE"] = "doge";
|
|
148
|
+
ChainTypes2["EVM"] = "evm";
|
|
149
|
+
ChainTypes2["SOL"] = "sol";
|
|
150
|
+
ChainTypes2["SUI"] = "sui";
|
|
151
|
+
ChainTypes2["TON"] = "ton";
|
|
152
|
+
ChainTypes2["TRON"] = "tron";
|
|
153
|
+
ChainTypes2["COSMOS"] = "cosmos";
|
|
154
|
+
ChainTypes2["APTOS"] = "aptos";
|
|
155
|
+
return ChainTypes2;
|
|
156
|
+
})(ChainTypes || {});
|
|
157
|
+
var SupportedChainTypes = {
|
|
158
|
+
["doge" /* DOGE */]: {
|
|
159
|
+
chainId: "3",
|
|
160
|
+
chainIndex: 300,
|
|
161
|
+
support: true,
|
|
162
|
+
gasFee: 0.5,
|
|
163
|
+
dust: 1e-4
|
|
164
|
+
},
|
|
165
|
+
["evm" /* EVM */]: {
|
|
166
|
+
chainId: "1",
|
|
167
|
+
chainIndex: 100,
|
|
168
|
+
support: true,
|
|
169
|
+
gasFee: 1e-5,
|
|
170
|
+
dust: 0
|
|
171
|
+
},
|
|
172
|
+
["sol" /* SOL */]: {
|
|
173
|
+
chainId: "501",
|
|
174
|
+
chainIndex: 50100,
|
|
175
|
+
support: true,
|
|
176
|
+
gasFee: 1e-4,
|
|
177
|
+
dust: 0,
|
|
178
|
+
reserve: 9e-4
|
|
179
|
+
// Available balance = Total balance - Reserve balance (for rent exemption)
|
|
180
|
+
},
|
|
181
|
+
["tron" /* TRON */]: {
|
|
182
|
+
chainId: "19484",
|
|
183
|
+
chainIndex: 1948400,
|
|
184
|
+
support: true,
|
|
185
|
+
gasFee: 0.5,
|
|
186
|
+
dust: 0
|
|
187
|
+
},
|
|
188
|
+
["btc" /* BTC */]: {
|
|
189
|
+
chainId: "0",
|
|
190
|
+
//livenet
|
|
191
|
+
chainIndex: 0,
|
|
192
|
+
support: false,
|
|
193
|
+
gasFee: 1e-5,
|
|
194
|
+
dust: 1e-4
|
|
195
|
+
},
|
|
196
|
+
["sui" /* SUI */]: {
|
|
197
|
+
support: false,
|
|
198
|
+
gasFee: 0,
|
|
199
|
+
dust: 0
|
|
200
|
+
},
|
|
201
|
+
["ton" /* TON */]: {
|
|
202
|
+
support: false,
|
|
203
|
+
gasFee: 0,
|
|
204
|
+
dust: 0
|
|
205
|
+
},
|
|
206
|
+
["cosmos" /* COSMOS */]: {
|
|
207
|
+
support: false,
|
|
208
|
+
gasFee: 0,
|
|
209
|
+
dust: 0
|
|
210
|
+
},
|
|
211
|
+
["aptos" /* APTOS */]: {
|
|
212
|
+
support: false,
|
|
213
|
+
gasFee: 0,
|
|
214
|
+
dust: 0
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
// src/password.ts
|
|
219
|
+
var validatePassword = (password) => {
|
|
220
|
+
const lengthValid = password.length >= 8 && password.length <= 32;
|
|
221
|
+
const hasLetter = /[a-zA-Z]/.test(password);
|
|
222
|
+
const hasNumber = /[0-9]/.test(password);
|
|
223
|
+
return lengthValid && hasLetter && hasNumber;
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
// src/string.ts
|
|
227
|
+
function stripHexPrefix(str) {
|
|
228
|
+
if (typeof str !== "string") {
|
|
229
|
+
return str;
|
|
230
|
+
}
|
|
231
|
+
return str.startsWith("0x") ? str.slice(2) : str;
|
|
232
|
+
}
|
|
233
|
+
function compareString(a, b) {
|
|
234
|
+
return a.toLowerCase() === b.toLowerCase();
|
|
235
|
+
}
|
|
236
|
+
function subs(temp, data, regexp) {
|
|
237
|
+
if (!(Object.prototype.toString.call(data) === "[object Array]")) data = [data];
|
|
238
|
+
const ret = [];
|
|
239
|
+
for (let i = 0, j = data.length; i < j; i++) {
|
|
240
|
+
ret.push(replaceAction(data[i]));
|
|
241
|
+
}
|
|
242
|
+
return ret.join("");
|
|
243
|
+
function replaceAction(object) {
|
|
244
|
+
return temp.replace(regexp || /\\?\{([^}]+)\}/g, function(match, name) {
|
|
245
|
+
if (match.charAt(0) == "\\") return match.slice(1);
|
|
246
|
+
return object[name] != void 0 ? object[name] : "";
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
function getExplorerUrl(chainIndex, data) {
|
|
251
|
+
const linkTpls = {
|
|
252
|
+
"0": "",
|
|
253
|
+
"100": "https://etherscan.io/tx/{txId}",
|
|
254
|
+
"300": "https://dogechain.info/tx/{txId}",
|
|
255
|
+
"400": "",
|
|
256
|
+
"1000": "https://optimistic.etherscan.io/tx/{txId}",
|
|
257
|
+
"5600": "https://bscscan.com/tx/{txId}",
|
|
258
|
+
"12600": "https://explorer.movementnetwork.xyz/txn/{txId}?network=mainnet",
|
|
259
|
+
"13700": "https://polygonscan.com/tx/{txId}",
|
|
260
|
+
"20400": "https://opbnb.bscscan.com/tx/{txId}",
|
|
261
|
+
"22300": "https://explorer.bsquared.network/tx/{txId}",
|
|
262
|
+
"22700": "https://promscan.io/tx/{txId}",
|
|
263
|
+
"32400": "https://mainnet.era.zksync.io/tx/{txId}",
|
|
264
|
+
"48000": "https://worldchain-mainnet.explorer.alchemy.com/tx/{txId}",
|
|
265
|
+
"50100": "https://solscan.io/tx/{txId}",
|
|
266
|
+
"78400": "",
|
|
267
|
+
"110000": "",
|
|
268
|
+
"132900": "https://seitrace.com/tx/{txId}",
|
|
269
|
+
"151400": "https://mainnet.storyscan.xyz/tx/{txId}",
|
|
270
|
+
"162500": "https://explorer.gravity.xyz/tx/{txId}",
|
|
271
|
+
"264900": "https://mainnet-explorer.ailayer.xyz/tx/{txId}",
|
|
272
|
+
"420000": "https://scan.merlinchain.io/tx/{txId}",
|
|
273
|
+
"554500": "https://scan.duckchain.io/tx/{txId}",
|
|
274
|
+
"833300": "https://mainnet-rpc.b3.fun/http/tx/{txId}",
|
|
275
|
+
"845300": "https://base.blockscout.com/tx/{txId}",
|
|
276
|
+
"1948400": "https://tronscan.org/#/transaction/{txId}",
|
|
277
|
+
"4216100": "https://arbiscan.io/tx/{txId}",
|
|
278
|
+
"4311400": "https://snowtrace.io/tx/{txId}",
|
|
279
|
+
"4776300": "https://neotube.io/transaction/{txId}",
|
|
280
|
+
"5914400": "https://lineascan.build/tx/{txId}",
|
|
281
|
+
"6080800": "https://rpc.gobob.xyz/tx/{txId}",
|
|
282
|
+
"8009400": "https://berascan.com/tx/{txId}",
|
|
283
|
+
"8145700": "https://blastscan.io/tx/{txId}",
|
|
284
|
+
"20090100": "https://rpc.bitlayer.org/tx/{txId}",
|
|
285
|
+
"53435200": "https://scrollscan.com/tx/{txId}",
|
|
286
|
+
"221122420": "https://blockscout.devnet.doge.xyz/tx/{txId}",
|
|
287
|
+
"2100000000": "https://maizenet-explorer.usecorn.com/tx/{txId}"
|
|
288
|
+
};
|
|
289
|
+
const key = chainIndex.toString();
|
|
290
|
+
const linkTpl = linkTpls[key] || "";
|
|
291
|
+
if (linkTpl === "") {
|
|
292
|
+
throw new Error(`chainIndex ${chainIndex} tpl not found`);
|
|
293
|
+
}
|
|
294
|
+
return subs(linkTpl, data);
|
|
295
|
+
}
|
|
296
|
+
function calcCtrLength(str) {
|
|
297
|
+
let length = 0;
|
|
298
|
+
str = str.trim();
|
|
299
|
+
for (let i = 0; i < str.length; i++) {
|
|
300
|
+
const code = str.charCodeAt(i);
|
|
301
|
+
if (code >= 19968 && code <= 40869) {
|
|
302
|
+
length += 2;
|
|
303
|
+
} else {
|
|
304
|
+
length += 1;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
return { len: length, originLen: str.length };
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
// src/index.ts
|
|
311
|
+
var CubeStages = {
|
|
312
|
+
prod: "prod",
|
|
313
|
+
pre: "prod",
|
|
314
|
+
dev: "gamma"
|
|
315
|
+
};
|
|
316
|
+
var CubeOrgIds = {
|
|
317
|
+
prod: "Org#49944bce-9daf-423f-a982-269f6d0d301b",
|
|
318
|
+
pre: "Org#71c13f6d-b992-4660-874d-2ae0fadc789f",
|
|
319
|
+
dev: "Org#3d07a75a-1188-4bd0-acfa-671a198b83eb"
|
|
320
|
+
};
|
|
321
|
+
var RelayOrigins = {
|
|
322
|
+
prod: "https://social-relay.tomo.inc",
|
|
323
|
+
pre: "https://social-relay.tomo.inc",
|
|
324
|
+
dev: "https://social-relay-dev.tomo.inc"
|
|
325
|
+
};
|
|
326
|
+
var TomoApiDomains = {
|
|
327
|
+
prod: "https://wallet-pro.tomo.inc",
|
|
328
|
+
pre: "https://wallet-pre-wlfi.tomo.inc",
|
|
329
|
+
dev: "https://wallet-test.tomo.inc"
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
export { ChainTypes, CubeOrgIds, CubeStages, RelayOrigins, SupportedChainTypes, TomoApiDomains, cache_exports as cache, calcCtrLength, compareString, getBrowserName, getExplorerUrl, isEmail, maskEmail, stripHexPrefix, subs, validatePassword };
|