@dynamic-labs/ethereum 0.0.0-exp20240808.0
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 +3746 -0
- package/LICENSE +21 -0
- package/README.md +0 -0
- package/_virtual/_tslib.cjs +49 -0
- package/_virtual/_tslib.js +44 -0
- package/package.json +46 -0
- package/src/EthWalletConnector.cjs +234 -0
- package/src/EthWalletConnector.d.ts +3088 -0
- package/src/EthWalletConnector.js +230 -0
- package/src/coinbase/coinbase.cjs +98 -0
- package/src/coinbase/coinbase.d.ts +22 -0
- package/src/coinbase/coinbase.js +94 -0
- package/src/coinbase/helpers.cjs +38 -0
- package/src/coinbase/helpers.d.ts +3 -0
- package/src/coinbase/helpers.js +34 -0
- package/src/coinbase/index.d.ts +3 -0
- package/src/coinbase/types.d.ts +18 -0
- package/src/constants.cjs +8 -0
- package/src/constants.d.ts +1 -0
- package/src/constants.js +4 -0
- package/src/ethProviderHelper.cjs +163 -0
- package/src/ethProviderHelper.d.ts +43 -0
- package/src/ethProviderHelper.js +159 -0
- package/src/index.cjs +49 -0
- package/src/index.d.ts +11 -0
- package/src/index.js +35 -0
- package/src/injected/ExodusEvm.cjs +20 -0
- package/src/injected/ExodusEvm.d.ts +8 -0
- package/src/injected/ExodusEvm.js +16 -0
- package/src/injected/FallbackEvmConnector.cjs +22 -0
- package/src/injected/FallbackEvmConnector.d.ts +9 -0
- package/src/injected/FallbackEvmConnector.js +18 -0
- package/src/injected/InjectedWalletBase.cjs +110 -0
- package/src/injected/InjectedWalletBase.d.ts +29 -0
- package/src/injected/InjectedWalletBase.js +108 -0
- package/src/injected/PhantomEvm.cjs +37 -0
- package/src/injected/PhantomEvm.d.ts +8 -0
- package/src/injected/PhantomEvm.js +33 -0
- package/src/injected/UnknownInjected.cjs +21 -0
- package/src/injected/UnknownInjected.d.ts +8 -0
- package/src/injected/UnknownInjected.js +17 -0
- package/src/injected/fetchInjectedWalletConnectors.cjs +67 -0
- package/src/injected/fetchInjectedWalletConnectors.d.ts +6 -0
- package/src/injected/fetchInjectedWalletConnectors.js +62 -0
- package/src/injected/index.d.ts +5 -0
- package/src/polyfills.cjs +17 -0
- package/src/polyfills.d.ts +1 -0
- package/src/polyfills.js +15 -0
- package/src/types.d.ts +33 -0
- package/src/utils/findEvmNetwork.cjs +21 -0
- package/src/utils/findEvmNetwork.d.ts +6 -0
- package/src/utils/findEvmNetwork.js +17 -0
- package/src/utils/getNameservice.cjs +46 -0
- package/src/utils/getNameservice.d.ts +6 -0
- package/src/utils/getNameservice.js +42 -0
- package/src/utils/index.d.ts +2 -0
- package/src/utils/isEthWalletConnector/index.d.ts +1 -0
- package/src/utils/isEthWalletConnector/isEthWalletConnector.cjs +8 -0
- package/src/utils/isEthWalletConnector/isEthWalletConnector.d.ts +3 -0
- package/src/utils/isEthWalletConnector/isEthWalletConnector.js +4 -0
- package/src/utils/isString.d.ts +1 -0
- package/src/utils/isUnsupportedProviderError/index.d.ts +1 -0
- package/src/utils/isUnsupportedProviderError/isUnsupportedProviderError.d.ts +6 -0
- package/src/utils/last.d.ts +1 -0
- package/src/utils/parseIntSafe.cjs +23 -0
- package/src/utils/parseIntSafe.d.ts +1 -0
- package/src/utils/parseIntSafe.js +19 -0
- package/src/wallet/EthereumWallet.cjs +65 -0
- package/src/wallet/EthereumWallet.d.ts +17 -0
- package/src/wallet/EthereumWallet.js +61 -0
- package/src/wallet/index.d.ts +2 -0
- package/src/wallet/isEthereumWallet.cjs +8 -0
- package/src/wallet/isEthereumWallet.d.ts +3 -0
- package/src/wallet/isEthereumWallet.js +4 -0
- package/src/walletConnect/fetchWalletConnectWallets.cjs +30 -0
- package/src/walletConnect/fetchWalletConnectWallets.d.ts +6 -0
- package/src/walletConnect/fetchWalletConnectWallets.js +25 -0
- package/src/walletConnect/index.d.ts +2 -0
- package/src/walletConnect/walletConnect.cjs +531 -0
- package/src/walletConnect/walletConnect.d.ts +78 -0
- package/src/walletConnect/walletConnect.js +522 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { WalletClient, Transport, Account, Chain as ViemChain } from 'viem';
|
|
2
|
+
import { Chain } from '@dynamic-labs/wallet-connector-core';
|
|
3
|
+
import { EvmNetwork } from '@dynamic-labs/types';
|
|
4
|
+
import { WalletSchema } from '@dynamic-labs/wallet-book';
|
|
5
|
+
import { EthProviderHelper } from '../ethProviderHelper';
|
|
6
|
+
import { EthWalletConnector } from '../EthWalletConnector';
|
|
7
|
+
declare abstract class InjectedWalletBase extends EthWalletConnector {
|
|
8
|
+
supportedChains: Chain[];
|
|
9
|
+
connectedChain: Chain;
|
|
10
|
+
publicAddress: string | undefined;
|
|
11
|
+
walletConnectorFallback: boolean;
|
|
12
|
+
ethProviderHelper: EthProviderHelper | undefined;
|
|
13
|
+
wallet: WalletSchema | undefined;
|
|
14
|
+
getEthProviderHelper(): EthProviderHelper | undefined;
|
|
15
|
+
getMobileOrInstalledWallet(): InjectedWalletBase;
|
|
16
|
+
setupEventListeners(): void;
|
|
17
|
+
getWalletClient(chainId?: string): WalletClient<Transport, ViemChain, Account> | undefined;
|
|
18
|
+
isInstalledOnBrowser(): boolean;
|
|
19
|
+
getAddress(): Promise<string | undefined>;
|
|
20
|
+
connect(): Promise<void>;
|
|
21
|
+
signMessage(messageToSign: string): Promise<string | undefined>;
|
|
22
|
+
proveOwnership(messageToSign: string): Promise<string | undefined>;
|
|
23
|
+
endSession(): Promise<void>;
|
|
24
|
+
providerSwitchNetwork({ network, provider, }: {
|
|
25
|
+
network: EvmNetwork;
|
|
26
|
+
provider: WalletClient;
|
|
27
|
+
}): Promise<void>;
|
|
28
|
+
}
|
|
29
|
+
export default InjectedWalletBase;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { __awaiter } from '../../_virtual/_tslib.js';
|
|
3
|
+
import { findWalletBookWallet } from '@dynamic-labs/wallet-book';
|
|
4
|
+
import { isMobile } from '@dynamic-labs/utils';
|
|
5
|
+
import { EthProviderHelper } from '../ethProviderHelper.js';
|
|
6
|
+
import { EthWalletConnector } from '../EthWalletConnector.js';
|
|
7
|
+
import { WalletConnect } from '../walletConnect/walletConnect.js';
|
|
8
|
+
|
|
9
|
+
class InjectedWalletBase extends EthWalletConnector {
|
|
10
|
+
constructor() {
|
|
11
|
+
super(...arguments);
|
|
12
|
+
this.supportedChains = ['ETH', 'EVM'];
|
|
13
|
+
this.connectedChain = 'EVM';
|
|
14
|
+
this.walletConnectorFallback = false;
|
|
15
|
+
}
|
|
16
|
+
getEthProviderHelper() {
|
|
17
|
+
if (!this.wallet) {
|
|
18
|
+
// changing this to findWalletBookWallet so it returns undefined if not found which
|
|
19
|
+
// allows the getEthProviderHelper to return undefined if the wallet is not installed
|
|
20
|
+
this.wallet = findWalletBookWallet(this.walletBook, this.key);
|
|
21
|
+
}
|
|
22
|
+
if (this.wallet && !this.ethProviderHelper) {
|
|
23
|
+
this.ethProviderHelper = new EthProviderHelper(this.wallet, this);
|
|
24
|
+
}
|
|
25
|
+
// this.ethProviderHelper is undefined if the wallet is not installed or found in walletbook
|
|
26
|
+
return this.ethProviderHelper;
|
|
27
|
+
}
|
|
28
|
+
getMobileOrInstalledWallet() {
|
|
29
|
+
var _a, _b;
|
|
30
|
+
if (!this.wallet) {
|
|
31
|
+
this.wallet = findWalletBookWallet(this.walletBook, this.key);
|
|
32
|
+
}
|
|
33
|
+
if (this.isInstalledOnBrowser()) {
|
|
34
|
+
return this;
|
|
35
|
+
}
|
|
36
|
+
// this is to handle the case where the user is in a webview.
|
|
37
|
+
// when the user is in a webview, customers should set the deepLinkPreference prop to universal,
|
|
38
|
+
// in which case this condition will be false, and the SDK will use WalletConnect (if available)
|
|
39
|
+
if (((_b = (_a = this.wallet) === null || _a === void 0 ? void 0 : _a.mobile) === null || _b === void 0 ? void 0 : _b.inAppBrowser) &&
|
|
40
|
+
this.mobileExperience === 'in-app-browser' &&
|
|
41
|
+
isMobile()) {
|
|
42
|
+
return this;
|
|
43
|
+
}
|
|
44
|
+
// this is the case where the wallet is not installed on the browser and
|
|
45
|
+
// it does not support WalletConnect. in this case, the SDK will instruct
|
|
46
|
+
// the user to download the wallet extension
|
|
47
|
+
if (!this.walletConnectorFallback) {
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
return new WalletConnect(Object.assign(Object.assign({}, this.constructorProps), { walletName: this.name }));
|
|
51
|
+
}
|
|
52
|
+
setupEventListeners() {
|
|
53
|
+
const provider = this.getWalletClient();
|
|
54
|
+
if (!provider)
|
|
55
|
+
return;
|
|
56
|
+
const ethProviderHelper = this.getEthProviderHelper();
|
|
57
|
+
if (!ethProviderHelper)
|
|
58
|
+
return;
|
|
59
|
+
const { tearDownEventListeners } = ethProviderHelper._setupEventListeners(this);
|
|
60
|
+
this.teardownEventListeners = tearDownEventListeners;
|
|
61
|
+
}
|
|
62
|
+
getWalletClient(chainId) {
|
|
63
|
+
var _a;
|
|
64
|
+
return (_a = this.getEthProviderHelper()) === null || _a === void 0 ? void 0 : _a.findWalletClient(chainId);
|
|
65
|
+
}
|
|
66
|
+
isInstalledOnBrowser() {
|
|
67
|
+
var _a;
|
|
68
|
+
return ((_a = this.getEthProviderHelper()) === null || _a === void 0 ? void 0 : _a.findProvider()) !== undefined;
|
|
69
|
+
}
|
|
70
|
+
getAddress() {
|
|
71
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
72
|
+
var _a;
|
|
73
|
+
return (_a = this.getEthProviderHelper()) === null || _a === void 0 ? void 0 : _a.getAddress();
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
connect() {
|
|
77
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
78
|
+
yield this.getAddress();
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
signMessage(messageToSign) {
|
|
82
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
83
|
+
var _a;
|
|
84
|
+
return (_a = this.getEthProviderHelper()) === null || _a === void 0 ? void 0 : _a.signMessage(messageToSign);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
proveOwnership(messageToSign) {
|
|
88
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
89
|
+
return this.signMessage(messageToSign);
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
endSession() {
|
|
93
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
94
|
+
// nothing to do on browser-based metamask
|
|
95
|
+
return;
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
providerSwitchNetwork(_a) {
|
|
99
|
+
const _super = Object.create(null, {
|
|
100
|
+
providerSwitchNetwork: { get: () => super.providerSwitchNetwork }
|
|
101
|
+
});
|
|
102
|
+
return __awaiter(this, arguments, void 0, function* ({ network, provider, }) {
|
|
103
|
+
return _super.providerSwitchNetwork.call(this, { network, provider });
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export { InjectedWalletBase as default };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var _tslib = require('../../_virtual/_tslib.cjs');
|
|
7
|
+
var utils = require('@dynamic-labs/utils');
|
|
8
|
+
var walletBook = require('@dynamic-labs/wallet-book');
|
|
9
|
+
var InjectedWalletBase = require('./InjectedWalletBase.cjs');
|
|
10
|
+
|
|
11
|
+
class PhantomEvm extends InjectedWalletBase {
|
|
12
|
+
constructor(props) {
|
|
13
|
+
super(props);
|
|
14
|
+
this.name = 'Phantom';
|
|
15
|
+
this.overrideKey = 'phantomevm';
|
|
16
|
+
this.wallet = walletBook.findWalletBookWallet(this.walletBook, this.key);
|
|
17
|
+
}
|
|
18
|
+
getAddress() {
|
|
19
|
+
const _super = Object.create(null, {
|
|
20
|
+
getAddress: { get: () => super.getAddress }
|
|
21
|
+
});
|
|
22
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
if (this.isInstalledOnBrowser()) {
|
|
24
|
+
return _super.getAddress.call(this);
|
|
25
|
+
}
|
|
26
|
+
if (utils.isMobile()) {
|
|
27
|
+
utils.handleMobileWalletRedirect({
|
|
28
|
+
nativeLink: 'phantom://browse',
|
|
29
|
+
universalLink: 'https://phantom.app/ul/browse',
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
return undefined;
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
exports.PhantomEvm = PhantomEvm;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { EthWalletConnectorOpts } from '..';
|
|
2
|
+
import InjectedWalletBase from './InjectedWalletBase';
|
|
3
|
+
export declare class PhantomEvm extends InjectedWalletBase {
|
|
4
|
+
name: string;
|
|
5
|
+
overrideKey: string;
|
|
6
|
+
constructor(props: EthWalletConnectorOpts);
|
|
7
|
+
getAddress(): Promise<string | undefined>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { __awaiter } from '../../_virtual/_tslib.js';
|
|
3
|
+
import { isMobile, handleMobileWalletRedirect } from '@dynamic-labs/utils';
|
|
4
|
+
import { findWalletBookWallet } from '@dynamic-labs/wallet-book';
|
|
5
|
+
import InjectedWalletBase from './InjectedWalletBase.js';
|
|
6
|
+
|
|
7
|
+
class PhantomEvm extends InjectedWalletBase {
|
|
8
|
+
constructor(props) {
|
|
9
|
+
super(props);
|
|
10
|
+
this.name = 'Phantom';
|
|
11
|
+
this.overrideKey = 'phantomevm';
|
|
12
|
+
this.wallet = findWalletBookWallet(this.walletBook, this.key);
|
|
13
|
+
}
|
|
14
|
+
getAddress() {
|
|
15
|
+
const _super = Object.create(null, {
|
|
16
|
+
getAddress: { get: () => super.getAddress }
|
|
17
|
+
});
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
if (this.isInstalledOnBrowser()) {
|
|
20
|
+
return _super.getAddress.call(this);
|
|
21
|
+
}
|
|
22
|
+
if (isMobile()) {
|
|
23
|
+
handleMobileWalletRedirect({
|
|
24
|
+
nativeLink: 'phantom://browse',
|
|
25
|
+
universalLink: 'https://phantom.app/ul/browse',
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
return undefined;
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export { PhantomEvm };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var walletBook = require('@dynamic-labs/wallet-book');
|
|
7
|
+
var InjectedWalletBase = require('./InjectedWalletBase.cjs');
|
|
8
|
+
|
|
9
|
+
class UnknownInjected extends InjectedWalletBase {
|
|
10
|
+
constructor(props) {
|
|
11
|
+
super(props);
|
|
12
|
+
this.name = 'Unknown';
|
|
13
|
+
this.overrideKey = 'unknown';
|
|
14
|
+
this.wallet = walletBook.findWalletBookWallet(this.walletBook, this.key);
|
|
15
|
+
}
|
|
16
|
+
isInstalledOnBrowser() {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
exports.UnknownInjected = UnknownInjected;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { EthWalletConnectorOpts } from '..';
|
|
2
|
+
import InjectedWalletBase from './InjectedWalletBase';
|
|
3
|
+
export declare class UnknownInjected extends InjectedWalletBase {
|
|
4
|
+
name: string;
|
|
5
|
+
overrideKey: string;
|
|
6
|
+
constructor(props: EthWalletConnectorOpts);
|
|
7
|
+
isInstalledOnBrowser(): boolean;
|
|
8
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { findWalletBookWallet } from '@dynamic-labs/wallet-book';
|
|
3
|
+
import InjectedWalletBase from './InjectedWalletBase.js';
|
|
4
|
+
|
|
5
|
+
class UnknownInjected extends InjectedWalletBase {
|
|
6
|
+
constructor(props) {
|
|
7
|
+
super(props);
|
|
8
|
+
this.name = 'Unknown';
|
|
9
|
+
this.overrideKey = 'unknown';
|
|
10
|
+
this.wallet = findWalletBookWallet(this.walletBook, this.key);
|
|
11
|
+
}
|
|
12
|
+
isInstalledOnBrowser() {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { UnknownInjected };
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var _tslib = require('../../_virtual/_tslib.cjs');
|
|
7
|
+
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
8
|
+
var InjectedWalletBase = require('./InjectedWalletBase.cjs');
|
|
9
|
+
var PhantomEvm = require('./PhantomEvm.cjs');
|
|
10
|
+
var ExodusEvm = require('./ExodusEvm.cjs');
|
|
11
|
+
|
|
12
|
+
const injectedWalletOverrides = [
|
|
13
|
+
PhantomEvm.PhantomEvm,
|
|
14
|
+
ExodusEvm.ExodusEvm,
|
|
15
|
+
];
|
|
16
|
+
const filteredInjectedWalletKeysOverrides = [
|
|
17
|
+
'phantomevm',
|
|
18
|
+
'coinbase',
|
|
19
|
+
'exodusevm',
|
|
20
|
+
];
|
|
21
|
+
const fetchInjectedWalletConnector = ({ walletBook, }) => {
|
|
22
|
+
var _a;
|
|
23
|
+
return Object.entries((_a = walletBook === null || walletBook === void 0 ? void 0 : walletBook.wallets) !== null && _a !== void 0 ? _a : {})
|
|
24
|
+
.filter(([key, wallet]) => {
|
|
25
|
+
var _a;
|
|
26
|
+
return ((_a = wallet.injectedConfig) === null || _a === void 0 ? void 0 : _a.find((config) => config.chain === 'evm')) &&
|
|
27
|
+
!filteredInjectedWalletKeysOverrides.includes(key);
|
|
28
|
+
})
|
|
29
|
+
.map(([key, wallet]) => {
|
|
30
|
+
const { shortName } = wallet;
|
|
31
|
+
const name = shortName || wallet.name;
|
|
32
|
+
const walletConnectorFallback = Boolean(wallet.walletConnect);
|
|
33
|
+
return class extends InjectedWalletBase {
|
|
34
|
+
constructor(props) {
|
|
35
|
+
super(Object.assign({}, props));
|
|
36
|
+
this.name = name;
|
|
37
|
+
this.wallet = wallet;
|
|
38
|
+
this.walletConnectorFallback = walletConnectorFallback;
|
|
39
|
+
// this is the key from the wallet book entry so that we don't purely rely on the normalized name
|
|
40
|
+
this.overrideKey = key;
|
|
41
|
+
}
|
|
42
|
+
getAddress() {
|
|
43
|
+
const _super = Object.create(null, {
|
|
44
|
+
getAddress: { get: () => super.getAddress }
|
|
45
|
+
});
|
|
46
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
47
|
+
var _a;
|
|
48
|
+
if (this.isInstalledOnBrowser()) {
|
|
49
|
+
return _super.getAddress.call(this);
|
|
50
|
+
}
|
|
51
|
+
const inAppBrowserBase = (_a = this.wallet.mobile) === null || _a === void 0 ? void 0 : _a.inAppBrowser;
|
|
52
|
+
if (!inAppBrowserBase) {
|
|
53
|
+
const error = new Error(`No inAppBrowserBase found for ${this.name}.`);
|
|
54
|
+
walletConnectorCore.logger.error(error.message);
|
|
55
|
+
throw error;
|
|
56
|
+
}
|
|
57
|
+
const cleanedTargetUrl = window.location.href.replace('https://', '');
|
|
58
|
+
window.location.href = `${inAppBrowserBase}/${cleanedTargetUrl}`;
|
|
59
|
+
return undefined;
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
exports.fetchInjectedWalletConnector = fetchInjectedWalletConnector;
|
|
67
|
+
exports.injectedWalletOverrides = injectedWalletOverrides;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { WalletConnectorConstructor } from '@dynamic-labs/wallet-connector-core';
|
|
2
|
+
import { WalletBookSchema } from '@dynamic-labs/wallet-book';
|
|
3
|
+
export declare const injectedWalletOverrides: WalletConnectorConstructor[];
|
|
4
|
+
export declare const fetchInjectedWalletConnector: ({ walletBook, }: {
|
|
5
|
+
walletBook: WalletBookSchema;
|
|
6
|
+
}) => WalletConnectorConstructor[];
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { __awaiter } from '../../_virtual/_tslib.js';
|
|
3
|
+
import { logger } from '@dynamic-labs/wallet-connector-core';
|
|
4
|
+
import InjectedWalletBase from './InjectedWalletBase.js';
|
|
5
|
+
import { PhantomEvm } from './PhantomEvm.js';
|
|
6
|
+
import { ExodusEvm } from './ExodusEvm.js';
|
|
7
|
+
|
|
8
|
+
const injectedWalletOverrides = [
|
|
9
|
+
PhantomEvm,
|
|
10
|
+
ExodusEvm,
|
|
11
|
+
];
|
|
12
|
+
const filteredInjectedWalletKeysOverrides = [
|
|
13
|
+
'phantomevm',
|
|
14
|
+
'coinbase',
|
|
15
|
+
'exodusevm',
|
|
16
|
+
];
|
|
17
|
+
const fetchInjectedWalletConnector = ({ walletBook, }) => {
|
|
18
|
+
var _a;
|
|
19
|
+
return Object.entries((_a = walletBook === null || walletBook === void 0 ? void 0 : walletBook.wallets) !== null && _a !== void 0 ? _a : {})
|
|
20
|
+
.filter(([key, wallet]) => {
|
|
21
|
+
var _a;
|
|
22
|
+
return ((_a = wallet.injectedConfig) === null || _a === void 0 ? void 0 : _a.find((config) => config.chain === 'evm')) &&
|
|
23
|
+
!filteredInjectedWalletKeysOverrides.includes(key);
|
|
24
|
+
})
|
|
25
|
+
.map(([key, wallet]) => {
|
|
26
|
+
const { shortName } = wallet;
|
|
27
|
+
const name = shortName || wallet.name;
|
|
28
|
+
const walletConnectorFallback = Boolean(wallet.walletConnect);
|
|
29
|
+
return class extends InjectedWalletBase {
|
|
30
|
+
constructor(props) {
|
|
31
|
+
super(Object.assign({}, props));
|
|
32
|
+
this.name = name;
|
|
33
|
+
this.wallet = wallet;
|
|
34
|
+
this.walletConnectorFallback = walletConnectorFallback;
|
|
35
|
+
// this is the key from the wallet book entry so that we don't purely rely on the normalized name
|
|
36
|
+
this.overrideKey = key;
|
|
37
|
+
}
|
|
38
|
+
getAddress() {
|
|
39
|
+
const _super = Object.create(null, {
|
|
40
|
+
getAddress: { get: () => super.getAddress }
|
|
41
|
+
});
|
|
42
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
var _a;
|
|
44
|
+
if (this.isInstalledOnBrowser()) {
|
|
45
|
+
return _super.getAddress.call(this);
|
|
46
|
+
}
|
|
47
|
+
const inAppBrowserBase = (_a = this.wallet.mobile) === null || _a === void 0 ? void 0 : _a.inAppBrowser;
|
|
48
|
+
if (!inAppBrowserBase) {
|
|
49
|
+
const error = new Error(`No inAppBrowserBase found for ${this.name}.`);
|
|
50
|
+
logger.error(error.message);
|
|
51
|
+
throw error;
|
|
52
|
+
}
|
|
53
|
+
const cleanedTargetUrl = window.location.href.replace('https://', '');
|
|
54
|
+
window.location.href = `${inAppBrowserBase}/${cleanedTargetUrl}`;
|
|
55
|
+
return undefined;
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export { fetchInjectedWalletConnector, injectedWalletOverrides };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var _ = require('buffer/');
|
|
5
|
+
|
|
6
|
+
/* eslint-disable */
|
|
7
|
+
/**
|
|
8
|
+
* @walletconnect/client and @walletconnect/qrcode-modal use `global` and `Buffer`, respectively.
|
|
9
|
+
* This issue is captured here: https://github.com/WalletConnect/walletconnect-monorepo/issues/341
|
|
10
|
+
* Here are some GH issues of others facing the same problem:
|
|
11
|
+
* * https://github.com/WalletConnect/walletconnect-monorepo/issues/734
|
|
12
|
+
* * https://github.com/WalletConnect/walletconnect-monorepo/issues/748
|
|
13
|
+
*/
|
|
14
|
+
if (typeof window !== 'undefined') {
|
|
15
|
+
window.global = globalThis;
|
|
16
|
+
Object.assign(window, { Buffer: _.Buffer });
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/src/polyfills.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { Buffer } from 'buffer/index.js';
|
|
3
|
+
|
|
4
|
+
/* eslint-disable */
|
|
5
|
+
/**
|
|
6
|
+
* @walletconnect/client and @walletconnect/qrcode-modal use `global` and `Buffer`, respectively.
|
|
7
|
+
* This issue is captured here: https://github.com/WalletConnect/walletconnect-monorepo/issues/341
|
|
8
|
+
* Here are some GH issues of others facing the same problem:
|
|
9
|
+
* * https://github.com/WalletConnect/walletconnect-monorepo/issues/734
|
|
10
|
+
* * https://github.com/WalletConnect/walletconnect-monorepo/issues/748
|
|
11
|
+
*/
|
|
12
|
+
if (typeof window !== 'undefined') {
|
|
13
|
+
window.global = globalThis;
|
|
14
|
+
Object.assign(window, { Buffer });
|
|
15
|
+
}
|
package/src/types.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import { EventEmitter } from 'stream';
|
|
4
|
+
import { PublicClient } from 'viem';
|
|
5
|
+
import { ProviderCondition } from '@dynamic-labs/wallet-connector-core';
|
|
6
|
+
declare global {
|
|
7
|
+
interface IWindowPhantom {
|
|
8
|
+
ethereum: IEthereum;
|
|
9
|
+
}
|
|
10
|
+
interface Window {
|
|
11
|
+
ethereum?: IEthereum;
|
|
12
|
+
phantom?: IWindowPhantom;
|
|
13
|
+
zerionWallet?: IEthereum;
|
|
14
|
+
coinbaseWalletExtension?: IEthereum;
|
|
15
|
+
superb?: IEthereum;
|
|
16
|
+
okxwallet?: IEthereum;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export type IEthereum = {
|
|
20
|
+
[key in ExtensionLocator]: boolean;
|
|
21
|
+
} & {
|
|
22
|
+
providers?: object[];
|
|
23
|
+
request: <T extends string>(params: {
|
|
24
|
+
method: T;
|
|
25
|
+
} | object) => Promise<T extends 'eth_requestAccounts' ? [string] : object>;
|
|
26
|
+
} & EventEmitter;
|
|
27
|
+
export type ExtensionLocator = 'isDawn' | 'isBraveWallet' | 'isCoinbaseWallet' | 'isFrame' | 'isGamestop' | 'isMetaMask' | 'isExodus' | 'isOpera' | 'isBlocto' | 'isTrustWallet' | 'isZerion' | 'isPhantom' | 'isSuperb' | 'isRabby' | 'isOkxWallet';
|
|
28
|
+
export type EthProviderCondition = ProviderCondition<ExtensionLocator>;
|
|
29
|
+
export type Provider = () => PublicClient | undefined;
|
|
30
|
+
export type ExternalProviderEventEmitter = PublicClient & {
|
|
31
|
+
on: (event: string, listener: (...args: Array<any>) => unknown) => void;
|
|
32
|
+
removeListener: (event: string, listener: (...args: Array<any>) => unknown) => void;
|
|
33
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
const findEvmNetwork = ({ chainId, name, networks, }) => {
|
|
7
|
+
if (!chainId && !name) {
|
|
8
|
+
return undefined;
|
|
9
|
+
}
|
|
10
|
+
if (chainId && name) {
|
|
11
|
+
return networks.find((network) => network.chainId === chainId && network.name === name);
|
|
12
|
+
}
|
|
13
|
+
else if (chainId) {
|
|
14
|
+
return networks.find((network) => network.chainId === chainId);
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
return networks.find((network) => network.name === name);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
exports.findEvmNetwork = findEvmNetwork;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
const findEvmNetwork = ({ chainId, name, networks, }) => {
|
|
3
|
+
if (!chainId && !name) {
|
|
4
|
+
return undefined;
|
|
5
|
+
}
|
|
6
|
+
if (chainId && name) {
|
|
7
|
+
return networks.find((network) => network.chainId === chainId && network.name === name);
|
|
8
|
+
}
|
|
9
|
+
else if (chainId) {
|
|
10
|
+
return networks.find((network) => network.chainId === chainId);
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
return networks.find((network) => network.name === name);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export { findEvmNetwork };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var _tslib = require('../../_virtual/_tslib.cjs');
|
|
7
|
+
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
8
|
+
|
|
9
|
+
const getNameservice = (_a) => _tslib.__awaiter(void 0, [_a], void 0, function* ({ rpcProvider, address, }) {
|
|
10
|
+
var _b;
|
|
11
|
+
const nsData = {
|
|
12
|
+
avatar: undefined,
|
|
13
|
+
name: undefined,
|
|
14
|
+
};
|
|
15
|
+
const network = yield rpcProvider.getChainId();
|
|
16
|
+
if (!network) {
|
|
17
|
+
return nsData;
|
|
18
|
+
}
|
|
19
|
+
// Handle Base name service requests
|
|
20
|
+
if (network === 8453) {
|
|
21
|
+
try {
|
|
22
|
+
const response = yield fetch(`https://resolver-api.basename.app/v1/addresses/${address}`);
|
|
23
|
+
if (response.ok) {
|
|
24
|
+
const data = yield response.json();
|
|
25
|
+
nsData.name = (_b = data.name) !== null && _b !== void 0 ? _b : undefined;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
catch (e) {
|
|
29
|
+
walletConnectorCore.logger.debug('Failed to fetch ens data', e);
|
|
30
|
+
}
|
|
31
|
+
return nsData;
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
nsData.name = (yield rpcProvider.getEnsName({
|
|
35
|
+
address: address,
|
|
36
|
+
}));
|
|
37
|
+
nsData.avatar = nsData.name
|
|
38
|
+
? (yield rpcProvider.getEnsAvatar({
|
|
39
|
+
name: nsData.name,
|
|
40
|
+
}))
|
|
41
|
+
: undefined;
|
|
42
|
+
}
|
|
43
|
+
return nsData;
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
exports.getNameservice = getNameservice;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { __awaiter } from '../../_virtual/_tslib.js';
|
|
3
|
+
import { logger } from '@dynamic-labs/wallet-connector-core';
|
|
4
|
+
|
|
5
|
+
const getNameservice = (_a) => __awaiter(void 0, [_a], void 0, function* ({ rpcProvider, address, }) {
|
|
6
|
+
var _b;
|
|
7
|
+
const nsData = {
|
|
8
|
+
avatar: undefined,
|
|
9
|
+
name: undefined,
|
|
10
|
+
};
|
|
11
|
+
const network = yield rpcProvider.getChainId();
|
|
12
|
+
if (!network) {
|
|
13
|
+
return nsData;
|
|
14
|
+
}
|
|
15
|
+
// Handle Base name service requests
|
|
16
|
+
if (network === 8453) {
|
|
17
|
+
try {
|
|
18
|
+
const response = yield fetch(`https://resolver-api.basename.app/v1/addresses/${address}`);
|
|
19
|
+
if (response.ok) {
|
|
20
|
+
const data = yield response.json();
|
|
21
|
+
nsData.name = (_b = data.name) !== null && _b !== void 0 ? _b : undefined;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
catch (e) {
|
|
25
|
+
logger.debug('Failed to fetch ens data', e);
|
|
26
|
+
}
|
|
27
|
+
return nsData;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
nsData.name = (yield rpcProvider.getEnsName({
|
|
31
|
+
address: address,
|
|
32
|
+
}));
|
|
33
|
+
nsData.avatar = nsData.name
|
|
34
|
+
? (yield rpcProvider.getEnsAvatar({
|
|
35
|
+
name: nsData.name,
|
|
36
|
+
}))
|
|
37
|
+
: undefined;
|
|
38
|
+
}
|
|
39
|
+
return nsData;
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
export { getNameservice };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { isEthWalletConnector } from './isEthWalletConnector';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
const isEthWalletConnector = (connector) => Boolean(connector === null || connector === void 0 ? void 0 : connector.getActiveAccount);
|
|
7
|
+
|
|
8
|
+
exports.isEthWalletConnector = isEthWalletConnector;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const isString: (value: unknown) => value is string;
|