@dynamic-labs/ethereum 4.0.0-alpha.9 → 4.0.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 +483 -1
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +11 -9
- package/src/coinbase/coinbase.cjs +1 -3
- package/src/coinbase/coinbase.d.ts +2 -5
- package/src/coinbase/coinbase.js +2 -4
- package/src/coinbase/types.d.ts +2 -2
- package/src/ethProviderHelper.cjs +49 -43
- package/src/ethProviderHelper.d.ts +5 -7
- package/src/ethProviderHelper.js +50 -44
- package/src/index.cjs +14 -3
- package/src/index.d.ts +2 -1
- package/src/index.js +5 -4
- package/src/injected/ExodusEvm.cjs +3 -5
- package/src/injected/ExodusEvm.d.ts +1 -3
- package/src/injected/ExodusEvm.js +3 -5
- package/src/injected/FallbackEvmConnector.cjs +3 -5
- package/src/injected/FallbackEvmConnector.d.ts +1 -3
- package/src/injected/FallbackEvmConnector.js +3 -5
- package/src/injected/InjectedWalletBase.cjs +18 -31
- package/src/injected/InjectedWalletBase.d.ts +4 -10
- package/src/injected/InjectedWalletBase.js +17 -32
- package/src/injected/PhantomEvm.cjs +4 -6
- package/src/injected/PhantomEvm.d.ts +1 -3
- package/src/injected/PhantomEvm.js +4 -6
- package/src/injected/fetchInjectedWalletConnectors.cjs +48 -39
- package/src/injected/fetchInjectedWalletConnectors.js +49 -40
- package/src/injected/index.d.ts +1 -1
- package/src/metaMask/MetaMaskConnector.cjs +376 -0
- package/src/metaMask/MetaMaskConnector.d.ts +52 -0
- package/src/metaMask/MetaMaskConnector.js +372 -0
- package/src/metaMask/utils/createMetaMaskSDKDisplayUriState.cjs +58 -0
- package/src/metaMask/utils/createMetaMaskSDKDisplayUriState.d.ts +14 -0
- package/src/metaMask/utils/createMetaMaskSDKDisplayUriState.js +54 -0
- package/src/metaMask/utils/isPendingWalletRequestPermissionError.cjs +11 -0
- package/src/metaMask/utils/isPendingWalletRequestPermissionError.d.ts +1 -0
- package/src/metaMask/utils/isPendingWalletRequestPermissionError.js +7 -0
- package/src/metaMask/utils/waitForConnection.cjs +10 -0
- package/src/metaMask/utils/waitForConnection.d.ts +2 -0
- package/src/metaMask/utils/waitForConnection.js +6 -0
- package/src/utils/createInjectedConnector/createInjectedConnector.cjs +93 -0
- package/src/utils/createInjectedConnector/createInjectedConnector.d.ts +16 -0
- package/src/utils/createInjectedConnector/createInjectedConnector.js +89 -0
- package/src/utils/createInjectedConnector/index.d.ts +1 -0
- package/src/utils/getConnectorConstructorForEip6963Wallet/getConnectorConstructorForEip6963Wallet.cjs +30 -0
- package/src/utils/getConnectorConstructorForEip6963Wallet/getConnectorConstructorForEip6963Wallet.d.ts +3 -0
- package/src/utils/getConnectorConstructorForEip6963Wallet/getConnectorConstructorForEip6963Wallet.js +26 -0
- package/src/utils/getConnectorConstructorForEip6963Wallet/index.d.ts +1 -0
- package/src/utils/getConnectorConstructorInjectedWallet/getConnectorConstructorInjectedWallet.cjs +44 -0
- package/src/utils/getConnectorConstructorInjectedWallet/getConnectorConstructorInjectedWallet.d.ts +3 -0
- package/src/utils/getConnectorConstructorInjectedWallet/getConnectorConstructorInjectedWallet.js +40 -0
- package/src/utils/getConnectorConstructorInjectedWallet/index.d.ts +1 -0
- package/src/utils/logger.cjs +10 -0
- package/src/utils/logger.d.ts +2 -0
- package/src/utils/logger.js +6 -0
- package/src/utils/normalizeRpcError/index.d.ts +1 -0
- package/src/utils/normalizeRpcError/normalizeRpcError.cjs +51 -0
- package/src/utils/normalizeRpcError/normalizeRpcError.d.ts +5 -0
- package/src/utils/normalizeRpcError/normalizeRpcError.js +47 -0
- package/src/walletConnect/walletConnect.cjs +175 -204
- package/src/walletConnect/walletConnect.d.ts +7681 -27
- package/src/walletConnect/walletConnect.js +175 -204
- package/src/injected/UnknownInjected.cjs +0 -21
- package/src/injected/UnknownInjected.d.ts +0 -8
- package/src/injected/UnknownInjected.js +0 -17
- package/src/utils/isString.d.ts +0 -1
- package/src/utils/last.d.ts +0 -1
- package/src/utils/parseIntSafe.cjs +0 -23
- package/src/utils/parseIntSafe.d.ts +0 -1
- package/src/utils/parseIntSafe.js +0 -19
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { __awaiter } from '../../../_virtual/_tslib.js';
|
|
3
|
+
import '@dynamic-labs/utils';
|
|
4
|
+
import { InjectedWalletBase } from '../../injected/InjectedWalletBase.js';
|
|
5
|
+
import '@dynamic-labs/wallet-connector-core';
|
|
6
|
+
import '../logger.js';
|
|
7
|
+
|
|
8
|
+
const createInjectedConnector = (customConnectorFn) => (props) => {
|
|
9
|
+
const delegate = customConnectorFn(props);
|
|
10
|
+
return [
|
|
11
|
+
class extends InjectedWalletBase {
|
|
12
|
+
constructor(props) {
|
|
13
|
+
super(Object.assign(Object.assign({}, props), { metadata: delegate.metadata }));
|
|
14
|
+
this.name = delegate.metadata.name;
|
|
15
|
+
}
|
|
16
|
+
init() {
|
|
17
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
return delegate.init();
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
findProvider() {
|
|
22
|
+
return delegate.findProvider();
|
|
23
|
+
}
|
|
24
|
+
signMessage(messageToSign) {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
return delegate.signMessage(messageToSign);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
connect() {
|
|
30
|
+
const _super = Object.create(null, {
|
|
31
|
+
connect: { get: () => super.connect }
|
|
32
|
+
});
|
|
33
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
+
if (delegate.connect) {
|
|
35
|
+
return delegate.connect();
|
|
36
|
+
}
|
|
37
|
+
return _super.connect.call(this);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
endSession() {
|
|
41
|
+
const _super = Object.create(null, {
|
|
42
|
+
endSession: { get: () => super.endSession }
|
|
43
|
+
});
|
|
44
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
if (delegate.disconnect) {
|
|
46
|
+
yield delegate.disconnect();
|
|
47
|
+
}
|
|
48
|
+
return _super.endSession.call(this);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
getAddress() {
|
|
52
|
+
const _super = Object.create(null, {
|
|
53
|
+
getAddress: { get: () => super.getAddress }
|
|
54
|
+
});
|
|
55
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
56
|
+
if (delegate.getAddress) {
|
|
57
|
+
return delegate.getAddress();
|
|
58
|
+
}
|
|
59
|
+
return _super.getAddress.call(this);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
getConnectedAccounts() {
|
|
63
|
+
const _super = Object.create(null, {
|
|
64
|
+
getConnectedAccounts: { get: () => super.getConnectedAccounts }
|
|
65
|
+
});
|
|
66
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
+
if (delegate.getConnectedAccounts) {
|
|
68
|
+
return delegate.getConnectedAccounts();
|
|
69
|
+
}
|
|
70
|
+
return _super.getConnectedAccounts.call(this);
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
filter() {
|
|
74
|
+
if (delegate.filter) {
|
|
75
|
+
return delegate.filter();
|
|
76
|
+
}
|
|
77
|
+
return super.filter();
|
|
78
|
+
}
|
|
79
|
+
supportsNetworkSwitching() {
|
|
80
|
+
if (delegate.supportsNetworkSwitching) {
|
|
81
|
+
return delegate.supportsNetworkSwitching();
|
|
82
|
+
}
|
|
83
|
+
return super.supportsNetworkSwitching();
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
];
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export { createInjectedConnector };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './createInjectedConnector';
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var utils = require('@dynamic-labs/utils');
|
|
7
|
+
var InjectedWalletBase = require('../../injected/InjectedWalletBase.cjs');
|
|
8
|
+
|
|
9
|
+
const getConnectorConstructorForEip6963Wallet = (walletDetail) => {
|
|
10
|
+
const { info, provider } = walletDetail;
|
|
11
|
+
const sanitizedName = utils.sanitizeName(info.name);
|
|
12
|
+
return class extends InjectedWalletBase.InjectedWalletBase {
|
|
13
|
+
constructor(props) {
|
|
14
|
+
super(Object.assign(Object.assign({}, props), { metadata: {
|
|
15
|
+
groupKey: sanitizedName,
|
|
16
|
+
icon: info.icon,
|
|
17
|
+
id: info.uuid,
|
|
18
|
+
name: info.name,
|
|
19
|
+
rdns: info.rdns,
|
|
20
|
+
} }));
|
|
21
|
+
this.name = info.name;
|
|
22
|
+
this.overrideKey = `${sanitizedName}evm`;
|
|
23
|
+
}
|
|
24
|
+
findProvider() {
|
|
25
|
+
return provider;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
exports.getConnectorConstructorForEip6963Wallet = getConnectorConstructorForEip6963Wallet;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { Eip6963ProviderDetail } from '@dynamic-labs/utils';
|
|
2
|
+
import { WalletConnectorConstructor } from '@dynamic-labs/wallet-connector-core';
|
|
3
|
+
export declare const getConnectorConstructorForEip6963Wallet: (walletDetail: Eip6963ProviderDetail) => WalletConnectorConstructor;
|
package/src/utils/getConnectorConstructorForEip6963Wallet/getConnectorConstructorForEip6963Wallet.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { sanitizeName } from '@dynamic-labs/utils';
|
|
3
|
+
import { InjectedWalletBase } from '../../injected/InjectedWalletBase.js';
|
|
4
|
+
|
|
5
|
+
const getConnectorConstructorForEip6963Wallet = (walletDetail) => {
|
|
6
|
+
const { info, provider } = walletDetail;
|
|
7
|
+
const sanitizedName = sanitizeName(info.name);
|
|
8
|
+
return class extends InjectedWalletBase {
|
|
9
|
+
constructor(props) {
|
|
10
|
+
super(Object.assign(Object.assign({}, props), { metadata: {
|
|
11
|
+
groupKey: sanitizedName,
|
|
12
|
+
icon: info.icon,
|
|
13
|
+
id: info.uuid,
|
|
14
|
+
name: info.name,
|
|
15
|
+
rdns: info.rdns,
|
|
16
|
+
} }));
|
|
17
|
+
this.name = info.name;
|
|
18
|
+
this.overrideKey = `${sanitizedName}evm`;
|
|
19
|
+
}
|
|
20
|
+
findProvider() {
|
|
21
|
+
return provider;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export { getConnectorConstructorForEip6963Wallet };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { getConnectorConstructorForEip6963Wallet } from './getConnectorConstructorForEip6963Wallet';
|
package/src/utils/getConnectorConstructorInjectedWallet/getConnectorConstructorInjectedWallet.cjs
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var _tslib = require('../../../_virtual/_tslib.cjs');
|
|
7
|
+
var InjectedWalletBase = require('../../injected/InjectedWalletBase.cjs');
|
|
8
|
+
var logger = require('../logger.cjs');
|
|
9
|
+
|
|
10
|
+
const getConnectorConstructorInjectedWallet = (key, wallet) => {
|
|
11
|
+
const { shortName } = wallet;
|
|
12
|
+
const name = shortName || wallet.name;
|
|
13
|
+
const walletConnectorFallback = Boolean(wallet.walletConnect);
|
|
14
|
+
return class extends InjectedWalletBase.InjectedWalletBase {
|
|
15
|
+
constructor() {
|
|
16
|
+
super(...arguments);
|
|
17
|
+
this.name = name;
|
|
18
|
+
this.walletConnectorFallback = walletConnectorFallback;
|
|
19
|
+
// this is the key from the wallet book entry so that we don't purely rely on the normalized name
|
|
20
|
+
this.overrideKey = key;
|
|
21
|
+
}
|
|
22
|
+
getAddress() {
|
|
23
|
+
const _super = Object.create(null, {
|
|
24
|
+
getAddress: { get: () => super.getAddress }
|
|
25
|
+
});
|
|
26
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
var _a;
|
|
28
|
+
if (this.isInstalledOnBrowser()) {
|
|
29
|
+
return _super.getAddress.call(this);
|
|
30
|
+
}
|
|
31
|
+
const inAppBrowserBase = (_a = this.metadata) === null || _a === void 0 ? void 0 : _a.inAppBrowserUrl;
|
|
32
|
+
if (!inAppBrowserBase) {
|
|
33
|
+
const error = new Error(`No inAppBrowserBase found for ${this.name}.`);
|
|
34
|
+
logger.logger.error(error.message);
|
|
35
|
+
throw error;
|
|
36
|
+
}
|
|
37
|
+
window.location.href = `${inAppBrowserBase}/${window.location.href}`;
|
|
38
|
+
return undefined;
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
exports.getConnectorConstructorInjectedWallet = getConnectorConstructorInjectedWallet;
|
package/src/utils/getConnectorConstructorInjectedWallet/getConnectorConstructorInjectedWallet.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { __awaiter } from '../../../_virtual/_tslib.js';
|
|
3
|
+
import { InjectedWalletBase } from '../../injected/InjectedWalletBase.js';
|
|
4
|
+
import { logger } from '../logger.js';
|
|
5
|
+
|
|
6
|
+
const getConnectorConstructorInjectedWallet = (key, wallet) => {
|
|
7
|
+
const { shortName } = wallet;
|
|
8
|
+
const name = shortName || wallet.name;
|
|
9
|
+
const walletConnectorFallback = Boolean(wallet.walletConnect);
|
|
10
|
+
return class extends InjectedWalletBase {
|
|
11
|
+
constructor() {
|
|
12
|
+
super(...arguments);
|
|
13
|
+
this.name = name;
|
|
14
|
+
this.walletConnectorFallback = walletConnectorFallback;
|
|
15
|
+
// this is the key from the wallet book entry so that we don't purely rely on the normalized name
|
|
16
|
+
this.overrideKey = key;
|
|
17
|
+
}
|
|
18
|
+
getAddress() {
|
|
19
|
+
const _super = Object.create(null, {
|
|
20
|
+
getAddress: { get: () => super.getAddress }
|
|
21
|
+
});
|
|
22
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
var _a;
|
|
24
|
+
if (this.isInstalledOnBrowser()) {
|
|
25
|
+
return _super.getAddress.call(this);
|
|
26
|
+
}
|
|
27
|
+
const inAppBrowserBase = (_a = this.metadata) === null || _a === void 0 ? void 0 : _a.inAppBrowserUrl;
|
|
28
|
+
if (!inAppBrowserBase) {
|
|
29
|
+
const error = new Error(`No inAppBrowserBase found for ${this.name}.`);
|
|
30
|
+
logger.error(error.message);
|
|
31
|
+
throw error;
|
|
32
|
+
}
|
|
33
|
+
window.location.href = `${inAppBrowserBase}/${window.location.href}`;
|
|
34
|
+
return undefined;
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export { getConnectorConstructorInjectedWallet };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { getConnectorConstructorInjectedWallet } from './getConnectorConstructorInjectedWallet';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { normalizeRpcError } from './normalizeRpcError';
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var viem = require('viem');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Some wallets may not reject some operations following the EIP-1193 standard.
|
|
10
|
+
* This function normalizes the errors to follow the EIP-1193 standard.
|
|
11
|
+
*/
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
13
|
+
const normalizeRpcError = (err) => {
|
|
14
|
+
/**
|
|
15
|
+
* When the error already comply with the EIP-1193 standard, we don't need to normalize it
|
|
16
|
+
*/
|
|
17
|
+
if (err.code === 4001) {
|
|
18
|
+
throw err;
|
|
19
|
+
}
|
|
20
|
+
let mappedError = null;
|
|
21
|
+
try {
|
|
22
|
+
mappedError = mapRpcError(err);
|
|
23
|
+
}
|
|
24
|
+
catch (e) {
|
|
25
|
+
// ignore errors when mapping
|
|
26
|
+
}
|
|
27
|
+
if (mappedError) {
|
|
28
|
+
throw mappedError;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* If no error is mapped, we rethrow the original error
|
|
32
|
+
*/
|
|
33
|
+
throw err;
|
|
34
|
+
};
|
|
35
|
+
const mapRpcError = (err) => {
|
|
36
|
+
/**
|
|
37
|
+
* Checks for user rejection error message
|
|
38
|
+
* Rainbow Extension will return a message like "User rejected the request"
|
|
39
|
+
* BitGet will return a message like "user reject this request"
|
|
40
|
+
* Keplr will return a message that matches "Request rejected"
|
|
41
|
+
*/
|
|
42
|
+
if (typeof err.message === 'string' &&
|
|
43
|
+
(err.message.includes('User rejected the request') ||
|
|
44
|
+
err.message.includes('user reject this request') ||
|
|
45
|
+
err.message === 'Request rejected')) {
|
|
46
|
+
return new viem.UserRejectedRequestError(err);
|
|
47
|
+
}
|
|
48
|
+
return null;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
exports.normalizeRpcError = normalizeRpcError;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { UserRejectedRequestError } from 'viem';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Some wallets may not reject some operations following the EIP-1193 standard.
|
|
6
|
+
* This function normalizes the errors to follow the EIP-1193 standard.
|
|
7
|
+
*/
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
9
|
+
const normalizeRpcError = (err) => {
|
|
10
|
+
/**
|
|
11
|
+
* When the error already comply with the EIP-1193 standard, we don't need to normalize it
|
|
12
|
+
*/
|
|
13
|
+
if (err.code === 4001) {
|
|
14
|
+
throw err;
|
|
15
|
+
}
|
|
16
|
+
let mappedError = null;
|
|
17
|
+
try {
|
|
18
|
+
mappedError = mapRpcError(err);
|
|
19
|
+
}
|
|
20
|
+
catch (e) {
|
|
21
|
+
// ignore errors when mapping
|
|
22
|
+
}
|
|
23
|
+
if (mappedError) {
|
|
24
|
+
throw mappedError;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* If no error is mapped, we rethrow the original error
|
|
28
|
+
*/
|
|
29
|
+
throw err;
|
|
30
|
+
};
|
|
31
|
+
const mapRpcError = (err) => {
|
|
32
|
+
/**
|
|
33
|
+
* Checks for user rejection error message
|
|
34
|
+
* Rainbow Extension will return a message like "User rejected the request"
|
|
35
|
+
* BitGet will return a message like "user reject this request"
|
|
36
|
+
* Keplr will return a message that matches "Request rejected"
|
|
37
|
+
*/
|
|
38
|
+
if (typeof err.message === 'string' &&
|
|
39
|
+
(err.message.includes('User rejected the request') ||
|
|
40
|
+
err.message.includes('user reject this request') ||
|
|
41
|
+
err.message === 'Request rejected')) {
|
|
42
|
+
return new UserRejectedRequestError(err);
|
|
43
|
+
}
|
|
44
|
+
return null;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export { normalizeRpcError };
|