@tomo-inc/wallet-adaptor-base 0.0.20 → 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
package/dist/index.cjs
CHANGED
|
@@ -76,15 +76,9 @@ function uint8arrayToHex(uint8array) {
|
|
|
76
76
|
|
|
77
77
|
// src/utils/wallet-config.ts
|
|
78
78
|
function hasWalletConfigProperties(config) {
|
|
79
|
-
if (!config || typeof config !== "object") {
|
|
80
|
-
return false;
|
|
81
|
-
}
|
|
82
79
|
return typeof config.id === "string" && typeof config.name === "string" && typeof config.icon === "string" && typeof config.iconBackground === "string";
|
|
83
80
|
}
|
|
84
81
|
function hasWagmiConnectorProperties(config) {
|
|
85
|
-
if (!config || typeof config !== "object") {
|
|
86
|
-
return false;
|
|
87
|
-
}
|
|
88
82
|
if (typeof config.createConnector === "function") {
|
|
89
83
|
return true;
|
|
90
84
|
}
|
|
@@ -284,7 +278,7 @@ function tomoConnectorDector(wallet) {
|
|
|
284
278
|
rdns: wallet == null ? void 0 : wallet.rdns,
|
|
285
279
|
deeplink: wallet == null ? void 0 : wallet.deeplink,
|
|
286
280
|
mobile: wallet == null ? void 0 : wallet.mobile,
|
|
287
|
-
links: {
|
|
281
|
+
links: (wallet == null ? void 0 : wallet.links) || {
|
|
288
282
|
homepage: ((_d = wallet == null ? void 0 : wallet.downloadUrls) == null ? void 0 : _d.qrCode) || "",
|
|
289
283
|
ios_install: ((_e = wallet == null ? void 0 : wallet.downloadUrls) == null ? void 0 : _e.ios) || "",
|
|
290
284
|
android_install: ((_f = wallet == null ? void 0 : wallet.downloadUrls) == null ? void 0 : _f.android) || "",
|
|
@@ -354,7 +348,7 @@ async function eip6963Wallets() {
|
|
|
354
348
|
function handleProviderAnnouncement(event) {
|
|
355
349
|
try {
|
|
356
350
|
const { info: wallet, provider } = event.detail;
|
|
357
|
-
const isInfoValid = typeof (wallet == null ? void 0 : wallet.uuid) === "string" && typeof (wallet == null ? void 0 : wallet.name) === "string" && typeof (wallet == null ? void 0 : wallet.icon) === "string" && typeof (wallet == null ? void 0 : wallet.rdns) === "string";
|
|
351
|
+
const isInfoValid = typeof (wallet == null ? void 0 : wallet.uuid) === "string" && typeof (wallet == null ? void 0 : wallet.name) === "string" && typeof (wallet == null ? void 0 : wallet.icon) === "string" && ((wallet == null ? void 0 : wallet.rdns) === void 0 || typeof (wallet == null ? void 0 : wallet.rdns) === "string");
|
|
358
352
|
if (wallet && provider && isInfoValid && typeof provider.request === "function") {
|
|
359
353
|
const existingWallet = evmWallets.find((w) => w.info.uuid === wallet.uuid);
|
|
360
354
|
if (!existingWallet) {
|
|
@@ -690,12 +684,12 @@ var WalletConnectProvider = class {
|
|
|
690
684
|
}
|
|
691
685
|
return this.connect();
|
|
692
686
|
}
|
|
693
|
-
if (!this.session) {
|
|
694
|
-
throw new Error("Not connected. Please call connect() first.");
|
|
695
|
-
}
|
|
696
687
|
if (args.method === "eth_chainId") {
|
|
697
688
|
return this.chainId || "0x1";
|
|
698
689
|
}
|
|
690
|
+
if (!this.session) {
|
|
691
|
+
throw new Error("Not connected. Please call connect() first.");
|
|
692
|
+
}
|
|
699
693
|
try {
|
|
700
694
|
const result = await this.client.sendRequest({
|
|
701
695
|
topic: this.session.topic,
|
|
@@ -966,7 +960,7 @@ var WalletConnectSolanaProvider = class {
|
|
|
966
960
|
async request(args) {
|
|
967
961
|
if (args.method === "solana_requestAccounts") {
|
|
968
962
|
if (this.accounts.length > 0) {
|
|
969
|
-
return
|
|
963
|
+
return this.accounts[0];
|
|
970
964
|
}
|
|
971
965
|
const accounts = await this.connect();
|
|
972
966
|
return accounts;
|
|
@@ -1322,6 +1316,7 @@ var connect = async (connectParams, walletOptions) => {
|
|
|
1322
1316
|
address = ((_e = (_d = res == null ? void 0 : res.accounts) == null ? void 0 : _d[0]) == null ? void 0 : _e.address) || "";
|
|
1323
1317
|
}
|
|
1324
1318
|
network = "mainnet-beta";
|
|
1319
|
+
chainId = `solana:${network}`;
|
|
1325
1320
|
}
|
|
1326
1321
|
if (chainType === "aptos") {
|
|
1327
1322
|
if (provider == null ? void 0 : provider.connect) {
|
|
@@ -1401,7 +1396,7 @@ var connectMobile = async ({
|
|
|
1401
1396
|
connectParams,
|
|
1402
1397
|
walletOptions
|
|
1403
1398
|
}) => {
|
|
1404
|
-
var _a, _b, _c;
|
|
1399
|
+
var _a, _b, _c, _d;
|
|
1405
1400
|
const { useWalletConnect, dappLink } = connectParams;
|
|
1406
1401
|
const { mobile, links } = walletOptions.walletInfo;
|
|
1407
1402
|
const connectWithWalletConnect = () => {
|
|
@@ -1433,8 +1428,8 @@ var connectMobile = async ({
|
|
|
1433
1428
|
};
|
|
1434
1429
|
if (useWalletConnect) {
|
|
1435
1430
|
return connectWithWalletConnect();
|
|
1436
|
-
} else if (mobile == null ? void 0 : mobile.
|
|
1437
|
-
const deeplink =
|
|
1431
|
+
} else if ((_a = mobile == null ? void 0 : mobile.deeplinkTemplate) == null ? void 0 : _a.deeplink) {
|
|
1432
|
+
const deeplink = (_b = mobile == null ? void 0 : mobile.deeplinkTemplate) == null ? void 0 : _b.deeplink.replace("{dappUrl}", encodeURIComponent(dappLink));
|
|
1438
1433
|
if (deeplink) {
|
|
1439
1434
|
openUri(deeplink);
|
|
1440
1435
|
}
|
|
@@ -1448,9 +1443,9 @@ var connectMobile = async ({
|
|
|
1448
1443
|
} else {
|
|
1449
1444
|
openUri(links.homepage || "");
|
|
1450
1445
|
}
|
|
1451
|
-
throw new Error(`${(_b = walletOptions.walletInfo) == null ? void 0 : _b.name} not supported`);
|
|
1452
|
-
} else {
|
|
1453
1446
|
throw new Error(`${(_c = walletOptions.walletInfo) == null ? void 0 : _c.name} not supported`);
|
|
1447
|
+
} else {
|
|
1448
|
+
throw new Error(`${(_d = walletOptions.walletInfo) == null ? void 0 : _d.name} not supported`);
|
|
1454
1449
|
}
|
|
1455
1450
|
return new Promise(() => {
|
|
1456
1451
|
});
|
|
@@ -1675,18 +1670,19 @@ Resources:`;
|
|
|
1675
1670
|
var getAllTypeChainIds = ({ chainId, chainType }) => {
|
|
1676
1671
|
if (viem.isHex(chainId)) {
|
|
1677
1672
|
const chainIdHex2 = chainId;
|
|
1678
|
-
|
|
1673
|
+
const chainIdStr2 = viem.fromHex(chainId, "number").toString();
|
|
1679
1674
|
return {
|
|
1680
|
-
chainId,
|
|
1675
|
+
chainId: chainIdStr2,
|
|
1681
1676
|
chainIdHex: chainIdHex2,
|
|
1682
|
-
chainUid: `${chainType}:${
|
|
1677
|
+
chainUid: `${chainType}:${chainIdStr2}`
|
|
1683
1678
|
};
|
|
1684
1679
|
}
|
|
1680
|
+
const chainIdStr = String(chainId);
|
|
1685
1681
|
const chainIdHex = viem.toHex(Number(chainId));
|
|
1686
1682
|
return {
|
|
1687
|
-
chainId,
|
|
1683
|
+
chainId: chainIdStr,
|
|
1688
1684
|
chainIdHex,
|
|
1689
|
-
chainUid: `${chainType}:${
|
|
1685
|
+
chainUid: `${chainType}:${chainIdStr}`
|
|
1690
1686
|
};
|
|
1691
1687
|
};
|
|
1692
1688
|
|
package/dist/index.d.cts
CHANGED
|
@@ -16,6 +16,9 @@ interface WalletInfo {
|
|
|
16
16
|
mobile?: {
|
|
17
17
|
getUri?: (uri: string) => string;
|
|
18
18
|
getDeeplink?: (dappUrl?: string, chainId?: number) => string | Promise<string>;
|
|
19
|
+
deeplinkTemplate?: {
|
|
20
|
+
deeplink?: string;
|
|
21
|
+
};
|
|
19
22
|
};
|
|
20
23
|
links: {
|
|
21
24
|
homepage?: string;
|
|
@@ -41,6 +44,7 @@ interface ConnectorProvider {
|
|
|
41
44
|
}
|
|
42
45
|
type ConnectorProviders = Partial<Record<ChainTypeEnum, ConnectorProvider | null>>;
|
|
43
46
|
interface Connector {
|
|
47
|
+
providers?: any;
|
|
44
48
|
info: WalletInfo;
|
|
45
49
|
isInstalled?: boolean;
|
|
46
50
|
recommoned?: boolean;
|
package/dist/index.d.ts
CHANGED
|
@@ -16,6 +16,9 @@ interface WalletInfo {
|
|
|
16
16
|
mobile?: {
|
|
17
17
|
getUri?: (uri: string) => string;
|
|
18
18
|
getDeeplink?: (dappUrl?: string, chainId?: number) => string | Promise<string>;
|
|
19
|
+
deeplinkTemplate?: {
|
|
20
|
+
deeplink?: string;
|
|
21
|
+
};
|
|
19
22
|
};
|
|
20
23
|
links: {
|
|
21
24
|
homepage?: string;
|
|
@@ -41,6 +44,7 @@ interface ConnectorProvider {
|
|
|
41
44
|
}
|
|
42
45
|
type ConnectorProviders = Partial<Record<ChainTypeEnum, ConnectorProvider | null>>;
|
|
43
46
|
interface Connector {
|
|
47
|
+
providers?: any;
|
|
44
48
|
info: WalletInfo;
|
|
45
49
|
isInstalled?: boolean;
|
|
46
50
|
recommoned?: boolean;
|
package/dist/index.js
CHANGED
|
@@ -74,15 +74,9 @@ function uint8arrayToHex(uint8array) {
|
|
|
74
74
|
|
|
75
75
|
// src/utils/wallet-config.ts
|
|
76
76
|
function hasWalletConfigProperties(config) {
|
|
77
|
-
if (!config || typeof config !== "object") {
|
|
78
|
-
return false;
|
|
79
|
-
}
|
|
80
77
|
return typeof config.id === "string" && typeof config.name === "string" && typeof config.icon === "string" && typeof config.iconBackground === "string";
|
|
81
78
|
}
|
|
82
79
|
function hasWagmiConnectorProperties(config) {
|
|
83
|
-
if (!config || typeof config !== "object") {
|
|
84
|
-
return false;
|
|
85
|
-
}
|
|
86
80
|
if (typeof config.createConnector === "function") {
|
|
87
81
|
return true;
|
|
88
82
|
}
|
|
@@ -282,7 +276,7 @@ function tomoConnectorDector(wallet) {
|
|
|
282
276
|
rdns: wallet == null ? void 0 : wallet.rdns,
|
|
283
277
|
deeplink: wallet == null ? void 0 : wallet.deeplink,
|
|
284
278
|
mobile: wallet == null ? void 0 : wallet.mobile,
|
|
285
|
-
links: {
|
|
279
|
+
links: (wallet == null ? void 0 : wallet.links) || {
|
|
286
280
|
homepage: ((_d = wallet == null ? void 0 : wallet.downloadUrls) == null ? void 0 : _d.qrCode) || "",
|
|
287
281
|
ios_install: ((_e = wallet == null ? void 0 : wallet.downloadUrls) == null ? void 0 : _e.ios) || "",
|
|
288
282
|
android_install: ((_f = wallet == null ? void 0 : wallet.downloadUrls) == null ? void 0 : _f.android) || "",
|
|
@@ -352,7 +346,7 @@ async function eip6963Wallets() {
|
|
|
352
346
|
function handleProviderAnnouncement(event) {
|
|
353
347
|
try {
|
|
354
348
|
const { info: wallet, provider } = event.detail;
|
|
355
|
-
const isInfoValid = typeof (wallet == null ? void 0 : wallet.uuid) === "string" && typeof (wallet == null ? void 0 : wallet.name) === "string" && typeof (wallet == null ? void 0 : wallet.icon) === "string" && typeof (wallet == null ? void 0 : wallet.rdns) === "string";
|
|
349
|
+
const isInfoValid = typeof (wallet == null ? void 0 : wallet.uuid) === "string" && typeof (wallet == null ? void 0 : wallet.name) === "string" && typeof (wallet == null ? void 0 : wallet.icon) === "string" && ((wallet == null ? void 0 : wallet.rdns) === void 0 || typeof (wallet == null ? void 0 : wallet.rdns) === "string");
|
|
356
350
|
if (wallet && provider && isInfoValid && typeof provider.request === "function") {
|
|
357
351
|
const existingWallet = evmWallets.find((w) => w.info.uuid === wallet.uuid);
|
|
358
352
|
if (!existingWallet) {
|
|
@@ -688,12 +682,12 @@ var WalletConnectProvider = class {
|
|
|
688
682
|
}
|
|
689
683
|
return this.connect();
|
|
690
684
|
}
|
|
691
|
-
if (!this.session) {
|
|
692
|
-
throw new Error("Not connected. Please call connect() first.");
|
|
693
|
-
}
|
|
694
685
|
if (args.method === "eth_chainId") {
|
|
695
686
|
return this.chainId || "0x1";
|
|
696
687
|
}
|
|
688
|
+
if (!this.session) {
|
|
689
|
+
throw new Error("Not connected. Please call connect() first.");
|
|
690
|
+
}
|
|
697
691
|
try {
|
|
698
692
|
const result = await this.client.sendRequest({
|
|
699
693
|
topic: this.session.topic,
|
|
@@ -964,7 +958,7 @@ var WalletConnectSolanaProvider = class {
|
|
|
964
958
|
async request(args) {
|
|
965
959
|
if (args.method === "solana_requestAccounts") {
|
|
966
960
|
if (this.accounts.length > 0) {
|
|
967
|
-
return
|
|
961
|
+
return this.accounts[0];
|
|
968
962
|
}
|
|
969
963
|
const accounts = await this.connect();
|
|
970
964
|
return accounts;
|
|
@@ -1320,6 +1314,7 @@ var connect = async (connectParams, walletOptions) => {
|
|
|
1320
1314
|
address = ((_e = (_d = res == null ? void 0 : res.accounts) == null ? void 0 : _d[0]) == null ? void 0 : _e.address) || "";
|
|
1321
1315
|
}
|
|
1322
1316
|
network = "mainnet-beta";
|
|
1317
|
+
chainId = `solana:${network}`;
|
|
1323
1318
|
}
|
|
1324
1319
|
if (chainType === "aptos") {
|
|
1325
1320
|
if (provider == null ? void 0 : provider.connect) {
|
|
@@ -1399,7 +1394,7 @@ var connectMobile = async ({
|
|
|
1399
1394
|
connectParams,
|
|
1400
1395
|
walletOptions
|
|
1401
1396
|
}) => {
|
|
1402
|
-
var _a, _b, _c;
|
|
1397
|
+
var _a, _b, _c, _d;
|
|
1403
1398
|
const { useWalletConnect, dappLink } = connectParams;
|
|
1404
1399
|
const { mobile, links } = walletOptions.walletInfo;
|
|
1405
1400
|
const connectWithWalletConnect = () => {
|
|
@@ -1431,8 +1426,8 @@ var connectMobile = async ({
|
|
|
1431
1426
|
};
|
|
1432
1427
|
if (useWalletConnect) {
|
|
1433
1428
|
return connectWithWalletConnect();
|
|
1434
|
-
} else if (mobile == null ? void 0 : mobile.
|
|
1435
|
-
const deeplink =
|
|
1429
|
+
} else if ((_a = mobile == null ? void 0 : mobile.deeplinkTemplate) == null ? void 0 : _a.deeplink) {
|
|
1430
|
+
const deeplink = (_b = mobile == null ? void 0 : mobile.deeplinkTemplate) == null ? void 0 : _b.deeplink.replace("{dappUrl}", encodeURIComponent(dappLink));
|
|
1436
1431
|
if (deeplink) {
|
|
1437
1432
|
openUri(deeplink);
|
|
1438
1433
|
}
|
|
@@ -1446,9 +1441,9 @@ var connectMobile = async ({
|
|
|
1446
1441
|
} else {
|
|
1447
1442
|
openUri(links.homepage || "");
|
|
1448
1443
|
}
|
|
1449
|
-
throw new Error(`${(_b = walletOptions.walletInfo) == null ? void 0 : _b.name} not supported`);
|
|
1450
|
-
} else {
|
|
1451
1444
|
throw new Error(`${(_c = walletOptions.walletInfo) == null ? void 0 : _c.name} not supported`);
|
|
1445
|
+
} else {
|
|
1446
|
+
throw new Error(`${(_d = walletOptions.walletInfo) == null ? void 0 : _d.name} not supported`);
|
|
1452
1447
|
}
|
|
1453
1448
|
return new Promise(() => {
|
|
1454
1449
|
});
|
|
@@ -1673,18 +1668,19 @@ Resources:`;
|
|
|
1673
1668
|
var getAllTypeChainIds = ({ chainId, chainType }) => {
|
|
1674
1669
|
if (isHex(chainId)) {
|
|
1675
1670
|
const chainIdHex2 = chainId;
|
|
1676
|
-
|
|
1671
|
+
const chainIdStr2 = fromHex(chainId, "number").toString();
|
|
1677
1672
|
return {
|
|
1678
|
-
chainId,
|
|
1673
|
+
chainId: chainIdStr2,
|
|
1679
1674
|
chainIdHex: chainIdHex2,
|
|
1680
|
-
chainUid: `${chainType}:${
|
|
1675
|
+
chainUid: `${chainType}:${chainIdStr2}`
|
|
1681
1676
|
};
|
|
1682
1677
|
}
|
|
1678
|
+
const chainIdStr = String(chainId);
|
|
1683
1679
|
const chainIdHex = toHex(Number(chainId));
|
|
1684
1680
|
return {
|
|
1685
|
-
chainId,
|
|
1681
|
+
chainId: chainIdStr,
|
|
1686
1682
|
chainIdHex,
|
|
1687
|
-
chainUid: `${chainType}:${
|
|
1683
|
+
chainUid: `${chainType}:${chainIdStr}`
|
|
1688
1684
|
};
|
|
1689
1685
|
};
|
|
1690
1686
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tomo-inc/wallet-adaptor-base",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.21",
|
|
4
4
|
"author": "tomo.inc",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"private": false,
|
|
@@ -22,13 +22,18 @@
|
|
|
22
22
|
"@solana/web3.js": "^1.98.0",
|
|
23
23
|
"@wallet-standard/core": "^1.1.0",
|
|
24
24
|
"viem": "2.21.54",
|
|
25
|
-
"@tomo-inc/wallet-utils": "0.0.
|
|
25
|
+
"@tomo-inc/wallet-utils": "0.0.19",
|
|
26
26
|
"@tomo-inc/wallet-connect-protocol": "0.0.17"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@types/node": "^20.0.0",
|
|
30
30
|
"tsup": "^8.0.0",
|
|
31
31
|
"typescript": "^5.0.0",
|
|
32
|
+
"@vitest/coverage-v8": "^3.2.4",
|
|
32
33
|
"vitest": "^3.2.4"
|
|
34
|
+
},
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "tsup",
|
|
37
|
+
"test": "vitest run"
|
|
33
38
|
}
|
|
34
39
|
}
|