@web3auth/no-modal 11.0.0-beta.1 → 11.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/dist/lib.cjs/account-linking/errors.js +111 -0
- package/dist/lib.cjs/account-linking/index.js +4 -0
- package/dist/lib.cjs/account-linking/rest.js +6 -6
- package/dist/lib.cjs/account-linking/vue.js +0 -1
- package/dist/lib.cjs/base/connector/constants.js +2 -0
- package/dist/lib.cjs/base/errors/index.js +21 -50
- package/dist/lib.cjs/base/utils.js +1 -1
- package/dist/lib.cjs/connectors/auth-connector/authConnector.js +125 -58
- package/dist/lib.cjs/connectors/metamask-connector/metamaskConnector.js +40 -31
- package/dist/lib.cjs/index.js +24 -19
- package/dist/lib.cjs/noModal.js +60 -26
- package/dist/lib.cjs/providers/account-abstraction-provider/providers/AccountAbstractionProvider.js +8 -4
- package/dist/lib.cjs/providers/account-abstraction-provider/providers/utils.js +0 -17
- package/dist/lib.cjs/providers/account-abstraction-provider/rpc/ethRpcMiddlewares.js +15 -0
- package/dist/lib.cjs/react/context/useWeb3AuthInnerContextValue.js +18 -2
- package/dist/lib.cjs/react/solana/provider.js +6 -2
- package/dist/lib.cjs/react/wagmi/index.js +6 -0
- package/dist/lib.cjs/react/wagmi/provider.js +74 -23
- package/dist/lib.cjs/types/account-linking/errors.d.ts +17 -0
- package/dist/lib.cjs/types/account-linking/index.d.ts +1 -0
- package/dist/lib.cjs/types/base/connector/constants.d.ts +1 -0
- package/dist/lib.cjs/types/base/connector/interfaces.d.ts +1 -1
- package/dist/lib.cjs/types/base/errors/index.d.ts +2 -13
- package/dist/lib.cjs/types/connectors/auth-connector/authConnector.d.ts +8 -2
- package/dist/lib.cjs/types/connectors/auth-connector/interface.d.ts +1 -1
- package/dist/lib.cjs/types/noModal.d.ts +1 -1
- package/dist/lib.cjs/types/providers/account-abstraction-provider/rpc/ethRpcMiddlewares.d.ts +1 -0
- package/dist/lib.cjs/types/react/wagmi/constants.d.ts +2 -0
- package/dist/lib.cjs/types/react/wagmi/provider.d.ts +7 -0
- package/dist/lib.cjs/types/vue/wagmi/constants.d.ts +2 -0
- package/dist/lib.cjs/types/vue/wagmi/provider.d.ts +7 -1
- package/dist/lib.cjs/vue/solana/provider.js +50 -26
- package/dist/lib.cjs/vue/useWeb3AuthInnerContextValue.js +13 -6
- package/dist/lib.cjs/vue/wagmi/index.js +6 -0
- package/dist/lib.cjs/vue/wagmi/provider.js +78 -35
- package/dist/lib.esm/account-linking/errors.js +92 -0
- package/dist/lib.esm/account-linking/index.js +1 -0
- package/dist/lib.esm/account-linking/rest.js +3 -3
- package/dist/lib.esm/account-linking/vue.js +0 -1
- package/dist/lib.esm/base/connector/constants.js +2 -1
- package/dist/lib.esm/base/errors/index.js +21 -50
- package/dist/lib.esm/base/utils.js +1 -1
- package/dist/lib.esm/connectors/auth-connector/authConnector.js +109 -41
- package/dist/lib.esm/connectors/base-solana-connector/baseSolanaConnector.js +1 -1
- package/dist/lib.esm/connectors/metamask-connector/metamaskConnector.js +42 -33
- package/dist/lib.esm/index.js +3 -2
- package/dist/lib.esm/noModal.js +56 -20
- package/dist/lib.esm/providers/account-abstraction-provider/providers/AccountAbstractionProvider.js +10 -5
- package/dist/lib.esm/providers/account-abstraction-provider/providers/utils.js +0 -3
- package/dist/lib.esm/providers/account-abstraction-provider/rpc/ethRpcMiddlewares.js +17 -3
- package/dist/lib.esm/react/context/useWeb3AuthInnerContextValue.js +18 -2
- package/dist/lib.esm/react/solana/provider.js +6 -2
- package/dist/lib.esm/react/wagmi/index.js +1 -1
- package/dist/lib.esm/react/wagmi/provider.js +74 -25
- package/dist/lib.esm/vue/solana/provider.js +51 -28
- package/dist/lib.esm/vue/useWeb3AuthInnerContextValue.js +11 -4
- package/dist/lib.esm/vue/wagmi/index.js +1 -1
- package/dist/lib.esm/vue/wagmi/provider.js +73 -34
- package/package.json +20 -20
package/dist/lib.cjs/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var rest = require('./account-linking/rest.js');
|
|
4
3
|
var analytics = require('./base/analytics.js');
|
|
5
4
|
var IChainInterface = require('./base/chain/IChainInterface.js');
|
|
6
5
|
var index$2 = require('./base/composables/index.js');
|
|
@@ -11,13 +10,13 @@ var auth = require('@web3auth/auth');
|
|
|
11
10
|
var utils$1 = require('./base/connector/utils.js');
|
|
12
11
|
var constants$1 = require('./base/constants.js');
|
|
13
12
|
var cookie = require('./base/cookie.js');
|
|
14
|
-
var index = require('./base/errors/index.js');
|
|
13
|
+
var index$1 = require('./base/errors/index.js');
|
|
15
14
|
var loglevel = require('./base/loglevel.js');
|
|
16
|
-
var errors = require('./base/plugin/errors.js');
|
|
15
|
+
var errors$1 = require('./base/plugin/errors.js');
|
|
17
16
|
var IPlugin = require('./base/plugin/IPlugin.js');
|
|
18
17
|
var IProvider = require('./base/provider/IProvider.js');
|
|
19
18
|
var utils$2 = require('./base/utils.js');
|
|
20
|
-
var index
|
|
19
|
+
var index = require('./base/wallet/index.js');
|
|
21
20
|
var authConnector = require('./connectors/auth-connector/authConnector.js');
|
|
22
21
|
var baseEvmConnector = require('./connectors/base-evm-connector/baseEvmConnector.js');
|
|
23
22
|
var baseSolanaConnector = require('./connectors/base-solana-connector/baseSolanaConnector.js');
|
|
@@ -39,16 +38,16 @@ var utils = require('./providers/base-provider/utils.js');
|
|
|
39
38
|
var ethRpcMiddlewares = require('./providers/ethereum-provider/rpc/ethRpcMiddlewares.js');
|
|
40
39
|
var jrpcClient = require('./providers/ethereum-provider/rpc/jrpcClient.js');
|
|
41
40
|
var walletMiddleware = require('./providers/ethereum-provider/rpc/walletMiddleware.js');
|
|
41
|
+
var errors = require('./account-linking/errors.js');
|
|
42
42
|
var wsEmbed = require('@web3auth/ws-embed');
|
|
43
43
|
var baseControllers = require('@toruslabs/base-controllers');
|
|
44
44
|
var app = require('@wallet-standard/app');
|
|
45
45
|
var solana = require('./base/wallet/solana.js');
|
|
46
|
+
var rest = require('./account-linking/rest.js');
|
|
46
47
|
var walletStandardConnector = require('./connectors/injected-solana-connector/walletStandardConnector.js');
|
|
47
48
|
|
|
48
49
|
|
|
49
50
|
|
|
50
|
-
exports.makeAccountLinkingRequest = rest.makeAccountLinkingRequest;
|
|
51
|
-
exports.makeAccountUnlinkingRequest = rest.makeAccountUnlinkingRequest;
|
|
52
51
|
exports.ANALYTICS_EVENTS = analytics.ANALYTICS_EVENTS;
|
|
53
52
|
exports.ANALYTICS_INTEGRATION_TYPE = analytics.ANALYTICS_INTEGRATION_TYPE;
|
|
54
53
|
exports.ANALYTICS_SDK_TYPE = analytics.ANALYTICS_SDK_TYPE;
|
|
@@ -63,6 +62,7 @@ exports.CONNECTOR_CATEGORY = constants.CONNECTOR_CATEGORY;
|
|
|
63
62
|
exports.CONNECTOR_EVENTS = constants.CONNECTOR_EVENTS;
|
|
64
63
|
exports.CONNECTOR_INITIAL_AUTHENTICATION_MODE = constants.CONNECTOR_INITIAL_AUTHENTICATION_MODE;
|
|
65
64
|
exports.CONNECTOR_STATUS = constants.CONNECTOR_STATUS;
|
|
65
|
+
exports.WEB3AUTH_CONNECTOR_ID = constants.WEB3AUTH_CONNECTOR_ID;
|
|
66
66
|
Object.defineProperty(exports, "AUTH_CONNECTION", {
|
|
67
67
|
enumerable: true,
|
|
68
68
|
get: function () { return auth.AUTH_CONNECTION; }
|
|
@@ -98,14 +98,14 @@ exports.WALLET_REGISTRY_URL = constants$1.WALLET_REGISTRY_URL;
|
|
|
98
98
|
exports.WEB3AUTH_STATE_STORAGE_KEY = constants$1.WEB3AUTH_STATE_STORAGE_KEY;
|
|
99
99
|
exports.WIDGET_TYPE = constants$1.WIDGET_TYPE;
|
|
100
100
|
exports.cookieToWeb3AuthState = cookie.cookieToWeb3AuthState;
|
|
101
|
-
exports.
|
|
102
|
-
exports.
|
|
103
|
-
exports.
|
|
104
|
-
exports.
|
|
105
|
-
exports.
|
|
106
|
-
exports.
|
|
101
|
+
exports.WalletInitializationError = index$1.WalletInitializationError;
|
|
102
|
+
exports.WalletLoginError = index$1.WalletLoginError;
|
|
103
|
+
exports.WalletOperationsError = index$1.WalletOperationsError;
|
|
104
|
+
exports.WalletProviderError = index$1.WalletProviderError;
|
|
105
|
+
exports.Web3AuthError = index$1.Web3AuthError;
|
|
106
|
+
exports.isUserRejectedError = index$1.isUserRejectedError;
|
|
107
107
|
exports.log = loglevel.log;
|
|
108
|
-
exports.WalletServicesPluginError = errors.WalletServicesPluginError;
|
|
108
|
+
exports.WalletServicesPluginError = errors$1.WalletServicesPluginError;
|
|
109
109
|
exports.EVM_PLUGINS = IPlugin.EVM_PLUGINS;
|
|
110
110
|
exports.PLUGIN_EVENTS = IPlugin.PLUGIN_EVENTS;
|
|
111
111
|
exports.PLUGIN_NAMESPACES = IPlugin.PLUGIN_NAMESPACES;
|
|
@@ -131,12 +131,12 @@ exports.normalizeWalletName = utils$2.normalizeWalletName;
|
|
|
131
131
|
exports.parseChainNamespaceFromCitadelResponse = utils$2.parseChainNamespaceFromCitadelResponse;
|
|
132
132
|
exports.sdkVersion = utils$2.sdkVersion;
|
|
133
133
|
exports.withAbort = utils$2.withAbort;
|
|
134
|
-
exports.CONNECTOR_NAMES = index
|
|
135
|
-
exports.EVM_CONNECTORS = index
|
|
136
|
-
exports.MULTI_CHAIN_CONNECTORS = index
|
|
137
|
-
exports.SOLANA_CONNECTORS = index
|
|
138
|
-
exports.WALLET_CONNECTORS = index
|
|
139
|
-
exports.WEB3AUTH_ICON = index
|
|
134
|
+
exports.CONNECTOR_NAMES = index.CONNECTOR_NAMES;
|
|
135
|
+
exports.EVM_CONNECTORS = index.EVM_CONNECTORS;
|
|
136
|
+
exports.MULTI_CHAIN_CONNECTORS = index.MULTI_CHAIN_CONNECTORS;
|
|
137
|
+
exports.SOLANA_CONNECTORS = index.SOLANA_CONNECTORS;
|
|
138
|
+
exports.WALLET_CONNECTORS = index.WALLET_CONNECTORS;
|
|
139
|
+
exports.WEB3AUTH_ICON = index.WEB3AUTH_ICON;
|
|
140
140
|
exports.assertAuthConnector = authConnector.assertAuthConnector;
|
|
141
141
|
exports.authConnector = authConnector.authConnector;
|
|
142
142
|
exports.isAuthConnector = authConnector.isAuthConnector;
|
|
@@ -215,6 +215,9 @@ exports.createEthChainSwitchMiddleware = ethRpcMiddlewares.createEthChainSwitchM
|
|
|
215
215
|
exports.createEthMiddleware = ethRpcMiddlewares.createEthMiddleware;
|
|
216
216
|
exports.createEthJsonRpcClient = jrpcClient.createEthJsonRpcClient;
|
|
217
217
|
exports.createWalletMiddlewareV2 = walletMiddleware.createWalletMiddlewareV2;
|
|
218
|
+
exports.AccountLinkingError = errors.AccountLinkingError;
|
|
219
|
+
exports.formatAccountLinkingErrorMessage = errors.formatAccountLinkingErrorMessage;
|
|
220
|
+
exports.getAccountLinkingRequestError = errors.getAccountLinkingRequestError;
|
|
218
221
|
Object.defineProperty(exports, "BUTTON_POSITION", {
|
|
219
222
|
enumerable: true,
|
|
220
223
|
get: function () { return wsEmbed.BUTTON_POSITION; }
|
|
@@ -239,4 +242,6 @@ exports.getSolanaChainByChainConfig = solana.getSolanaChainByChainConfig;
|
|
|
239
242
|
exports.walletSignAndSendTransaction = solana.walletSignAndSendTransaction;
|
|
240
243
|
exports.walletSignMessage = solana.walletSignMessage;
|
|
241
244
|
exports.walletSignTransaction = solana.walletSignTransaction;
|
|
245
|
+
exports.makeAccountLinkingRequest = rest.makeAccountLinkingRequest;
|
|
246
|
+
exports.makeAccountUnlinkingRequest = rest.makeAccountUnlinkingRequest;
|
|
242
247
|
exports.walletStandardConnector = walletStandardConnector.walletStandardConnector;
|
package/dist/lib.cjs/noModal.js
CHANGED
|
@@ -27,6 +27,7 @@ var plugin = require('./plugins/wallet-services-plugin/plugin.js');
|
|
|
27
27
|
require('./providers/base-provider/utils.js');
|
|
28
28
|
var CommonJRPCProvider = require('./providers/base-provider/CommonJRPCProvider.js');
|
|
29
29
|
require('./providers/base-provider/commonPrivateKeyProvider.js');
|
|
30
|
+
var errors = require('./account-linking/errors.js');
|
|
30
31
|
|
|
31
32
|
const _excluded = ["walletScope", "eipStandard"];
|
|
32
33
|
const PRIMARY_CONNECTED_WALLET_KEY = "__primary__";
|
|
@@ -60,7 +61,9 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
|
|
|
60
61
|
if (!options.clientId) throw index.WalletInitializationError.invalidParams("Please provide a valid clientId in constructor");
|
|
61
62
|
if (options.enableLogging) loglevel.log.enableAll();else loglevel.log.setLevel("error");
|
|
62
63
|
if (!options.initialAuthenticationMode) options.initialAuthenticationMode = constants.CONNECTOR_INITIAL_AUTHENTICATION_MODE.CONNECT_AND_SIGN;
|
|
63
|
-
this.coreOptions = options
|
|
64
|
+
this.coreOptions = _objectSpread(_objectSpread({}, options), {}, {
|
|
65
|
+
authBuildEnv: options.authBuildEnv || auth.BUILD_ENV.PRODUCTION
|
|
66
|
+
});
|
|
64
67
|
this.storage = this.getStorageMethod();
|
|
65
68
|
this.analytics = new analytics.Analytics();
|
|
66
69
|
if (options.disableAnalytics) {
|
|
@@ -526,13 +529,13 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
|
|
|
526
529
|
const linkedAccounts = (_await$authConnector$ = (await authConnector.getUserInfo()).linkedAccounts) !== null && _await$authConnector$ !== void 0 ? _await$authConnector$ : [];
|
|
527
530
|
const targetAccount = this.findLinkedAccountByAddress(linkedAccounts, address);
|
|
528
531
|
if (!targetAccount) {
|
|
529
|
-
throw
|
|
532
|
+
throw errors.AccountLinkingError.accountNotLinked(`Account with address "${address}" is not linked`);
|
|
530
533
|
}
|
|
531
534
|
if (targetAccount.connector === index$1.WALLET_CONNECTORS.AUTH || targetAccount.isPrimary) {
|
|
532
|
-
throw
|
|
535
|
+
throw errors.AccountLinkingError.cannotUnlinkPrimaryAccount();
|
|
533
536
|
}
|
|
534
537
|
if (((_this$state$activeAcc = this.state.activeAccount) === null || _this$state$activeAcc === void 0 ? void 0 : _this$state$activeAcc.id) === targetAccount.id) {
|
|
535
|
-
throw
|
|
538
|
+
throw errors.AccountLinkingError.cannotUnlinkActiveAccount();
|
|
536
539
|
}
|
|
537
540
|
const result = await authConnector.unlinkAccount({
|
|
538
541
|
address,
|
|
@@ -908,7 +911,6 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
|
|
|
908
911
|
}));
|
|
909
912
|
this.setActiveWalletConnectorKey();
|
|
910
913
|
this.connectionReconnected = data.reconnected;
|
|
911
|
-
const connectedChainId = ethereumProvider === null || ethereumProvider === void 0 ? void 0 : ethereumProvider.chainId;
|
|
912
914
|
// when ssr is enabled, we need to get the idToken from the connector.
|
|
913
915
|
if (this.coreOptions.ssr) {
|
|
914
916
|
try {
|
|
@@ -931,14 +933,16 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
|
|
|
931
933
|
}
|
|
932
934
|
// The following block only hits during rehydration
|
|
933
935
|
const {
|
|
934
|
-
activeAccount
|
|
936
|
+
activeAccount,
|
|
937
|
+
currentChainId
|
|
935
938
|
} = this.state;
|
|
936
|
-
|
|
939
|
+
let rehydrateWithLinkedAccount = false;
|
|
940
|
+
// for rehydration, if the active account is not the primary account, i.e. not `null`, create an isolated connector and connect to the chain
|
|
937
941
|
if (activeAccount && !activeAccount.isPrimary && activeAccount.connector !== index$1.WALLET_CONNECTORS.AUTH) {
|
|
938
942
|
var _ref3, _walletConnector$prov, _linkedAccountConnect, _ref4, _walletConnector$sola, _linkedAccountConnect2;
|
|
939
943
|
const accountLinkingConnector = authConnector.isAuthConnector(connector) ? connector : this.getConnector(index$1.WALLET_CONNECTORS.AUTH);
|
|
940
944
|
authConnector.assertAuthConnector(accountLinkingConnector, "Account switching requires the AUTH connector to be available.");
|
|
941
|
-
const targetChainId = accountLinkingConnector.getChainIdForLinkedAccount(activeAccount,
|
|
945
|
+
const targetChainId = accountLinkingConnector.getChainIdForLinkedAccount(activeAccount, currentChainId);
|
|
942
946
|
const walletConnector = await this.createIsolatedWalletConnector(activeAccount.connector, targetChainId);
|
|
943
947
|
let linkedAccountConnection = null;
|
|
944
948
|
if (!this.hasUsableConnectedSwitchConnector(walletConnector)) {
|
|
@@ -946,7 +950,7 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
|
|
|
946
950
|
chainId: targetChainId
|
|
947
951
|
});
|
|
948
952
|
if (!linkedAccountConnection) {
|
|
949
|
-
throw
|
|
953
|
+
throw errors.AccountLinkingError.requestFailed(`Failed to connect isolated connector "${activeAccount.connector}" for account switch.`);
|
|
950
954
|
}
|
|
951
955
|
}
|
|
952
956
|
const connectedWalletState = await this.resolveConnectedWalletConnectorState({
|
|
@@ -958,6 +962,7 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
|
|
|
958
962
|
});
|
|
959
963
|
this.setConnectedWalletConnectorState(connectedWalletState, activeAccount);
|
|
960
964
|
this.setActiveWalletConnectorKey(activeAccount);
|
|
965
|
+
rehydrateWithLinkedAccount = true;
|
|
961
966
|
}
|
|
962
967
|
if (ethereumProvider) {
|
|
963
968
|
await this.bindPrimaryEthereumSigningProxy(ethereumProvider, data.connectorName);
|
|
@@ -970,24 +975,42 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
|
|
|
970
975
|
});
|
|
971
976
|
this.setConnectedWalletConnectorState(primaryConnectedWalletState);
|
|
972
977
|
await this.setState({
|
|
973
|
-
primaryConnectorName: data.connectorName
|
|
974
|
-
currentChainId: connectedChainId
|
|
978
|
+
primaryConnectorName: data.connectorName
|
|
975
979
|
});
|
|
976
980
|
this.cacheWallet(data.connectorName);
|
|
977
981
|
const isConnectAndSign = this.coreOptions.initialAuthenticationMode === constants.CONNECTOR_INITIAL_AUTHENTICATION_MODE.CONNECT_AND_SIGN;
|
|
978
|
-
|
|
982
|
+
const pendingUserConsent = this.consentRequired && !this.state.hasUserConsent;
|
|
983
|
+
if (pendingUserConsent && !isConnectAndSign) {
|
|
979
984
|
this.status = constants.CONNECTOR_STATUS.CONSENT_REQUIRING;
|
|
980
985
|
this.emit(constants.CONNECTOR_EVENTS.CONSENT_REQUIRING);
|
|
981
986
|
loglevel.log.debug("consent_requiring", this.status, this.primaryConnectorName);
|
|
982
987
|
} else {
|
|
983
|
-
this
|
|
988
|
+
// In CONNECT_AND_SIGN mode the AUTHORIZED handler can run before this point (e.g. when `ssr=true`
|
|
989
|
+
// this handler `await`s `connector.getAuthTokenInfo()` which fires AUTHORIZED mid-execution).
|
|
990
|
+
// Don't downgrade an already-advanced status (CONSENT_REQUIRING or AUTHORIZED) back to CONNECTED;
|
|
991
|
+
// otherwise `acceptConsent` would throw "Cannot accept consent: not in consent_requiring state".
|
|
992
|
+
if (this.status !== constants.CONNECTOR_STATUS.CONSENT_REQUIRING && this.status !== constants.CONNECTOR_STATUS.AUTHORIZED) {
|
|
993
|
+
this.status = constants.CONNECTOR_STATUS.CONNECTED;
|
|
994
|
+
}
|
|
984
995
|
loglevel.log.debug("connected", this.status, this.primaryConnectorName);
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
996
|
+
// Defer plugin connection until consent is accepted; otherwise plugins would start before the consent step completes.
|
|
997
|
+
// `completeConsentAcceptance` connects the plugins once the user accepts the consent.
|
|
998
|
+
if (!pendingUserConsent) {
|
|
999
|
+
this.connectToPlugins(_objectSpread(_objectSpread({}, data), {}, {
|
|
1000
|
+
connector: data.connectorName
|
|
1001
|
+
}));
|
|
1002
|
+
}
|
|
1003
|
+
// `pendingUserConsent` signals listeners (LoginModal, React/Vue contexts) to skip processing this CONNECTED event,
|
|
1004
|
+
// so the upcoming AUTHORIZED -> CONSENT_REQUIRING transition is not overridden by a late CONNECTED handler in CONNECT_AND_SIGN mode.
|
|
988
1005
|
this.emit(constants.CONNECTOR_EVENTS.CONNECTED, _objectSpread(_objectSpread({}, data), {}, {
|
|
989
|
-
loginMode: this.loginMode
|
|
1006
|
+
loginMode: this.loginMode,
|
|
1007
|
+
pendingUserConsent
|
|
990
1008
|
}));
|
|
1009
|
+
// if we're rehydrating with a linked account, we need to emit a CONNECTION_UPDATED event
|
|
1010
|
+
// so that upstream listeners and context are updated with the linked connection.
|
|
1011
|
+
if (rehydrateWithLinkedAccount) {
|
|
1012
|
+
this.emit(constants.CONNECTOR_EVENTS.CONNECTION_UPDATED, this.connection);
|
|
1013
|
+
}
|
|
991
1014
|
}
|
|
992
1015
|
});
|
|
993
1016
|
connector.on(constants.CONNECTOR_EVENTS.DISCONNECTED, async data => {
|
|
@@ -1181,7 +1204,7 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
|
|
|
1181
1204
|
resolveLinkAccountChainId(chainId) {
|
|
1182
1205
|
const finalChainId = chainId || this.state.currentChainId;
|
|
1183
1206
|
if (!finalChainId) {
|
|
1184
|
-
throw
|
|
1207
|
+
throw errors.AccountLinkingError.walletProofFailed("No chainId is available. Please specify chainId in LinkAccountParams or ensure the SDK has an active chain.");
|
|
1185
1208
|
}
|
|
1186
1209
|
return finalChainId;
|
|
1187
1210
|
}
|
|
@@ -1202,7 +1225,15 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
|
|
|
1202
1225
|
return activeChainId;
|
|
1203
1226
|
}
|
|
1204
1227
|
async createLinkingWalletConnector(connectorName, chainId, config) {
|
|
1205
|
-
|
|
1228
|
+
try {
|
|
1229
|
+
const linkingConnector = await this.createIsolatedWalletConnector(connectorName, chainId, config);
|
|
1230
|
+
return linkingConnector;
|
|
1231
|
+
} catch (error) {
|
|
1232
|
+
if (error instanceof errors.AccountLinkingError && error.code === 5405) {
|
|
1233
|
+
throw error;
|
|
1234
|
+
}
|
|
1235
|
+
throw errors.AccountLinkingError.walletProofFailed(error instanceof Error ? error.message : String(error), error);
|
|
1236
|
+
}
|
|
1206
1237
|
}
|
|
1207
1238
|
async createSwitchingWalletConnector(connectorName, chainId, config) {
|
|
1208
1239
|
return this.createIsolatedWalletConnector(connectorName, chainId, config);
|
|
@@ -1357,12 +1388,12 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
|
|
|
1357
1388
|
account
|
|
1358
1389
|
});
|
|
1359
1390
|
}
|
|
1360
|
-
async linkAccountWithConnector(connectorName, chainId,
|
|
1391
|
+
async linkAccountWithConnector(connectorName, chainId, connectorToLink) {
|
|
1361
1392
|
const authConnector = this.getMainAuthConnector();
|
|
1362
1393
|
const result = await authConnector.linkAccount({
|
|
1363
1394
|
connectorName,
|
|
1364
1395
|
chainId,
|
|
1365
|
-
|
|
1396
|
+
connectorToLink,
|
|
1366
1397
|
authSessionTokens: {
|
|
1367
1398
|
accessToken: this.accessToken,
|
|
1368
1399
|
idToken: this.idToken
|
|
@@ -1371,7 +1402,7 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
|
|
|
1371
1402
|
await this.setState({
|
|
1372
1403
|
idToken: result.idToken
|
|
1373
1404
|
});
|
|
1374
|
-
await this.cacheConnectedLinkedWalletConnector(authConnector,
|
|
1405
|
+
await this.cacheConnectedLinkedWalletConnector(authConnector, connectorToLink);
|
|
1375
1406
|
return result;
|
|
1376
1407
|
}
|
|
1377
1408
|
getMainAuthConnector() {
|
|
@@ -1430,7 +1461,7 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
|
|
|
1430
1461
|
caipAccountIds: [caipAccountId]
|
|
1431
1462
|
});
|
|
1432
1463
|
if (!linkedAccountConnection) {
|
|
1433
|
-
throw
|
|
1464
|
+
throw errors.AccountLinkingError.requestFailed(`Failed to connect isolated connector "${switchResult.targetAccount.connector}" for account switch.`);
|
|
1434
1465
|
}
|
|
1435
1466
|
}
|
|
1436
1467
|
await authConnector.assertSwitchAccountConnectorMatchesTarget(walletConnector, switchResult.targetAccount);
|
|
@@ -1550,7 +1581,10 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
|
|
|
1550
1581
|
});
|
|
1551
1582
|
}
|
|
1552
1583
|
async setCurrentChain(chainId) {
|
|
1553
|
-
|
|
1584
|
+
const {
|
|
1585
|
+
currentChainId
|
|
1586
|
+
} = this.state;
|
|
1587
|
+
if (chainId === currentChainId) return;
|
|
1554
1588
|
const newChain = this.coreOptions.chains.find(chain => chain.chainId === chainId);
|
|
1555
1589
|
if (!newChain) throw index.WalletInitializationError.invalidParams(`Invalid chainId: ${chainId}`);
|
|
1556
1590
|
await this.setState({
|
|
@@ -1676,7 +1710,7 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
|
|
|
1676
1710
|
} = await Promise.resolve().then(function () { return require('./connectors/wallet-connect-v2-connector/index.js'); });
|
|
1677
1711
|
return walletConnectV2Connector()(config);
|
|
1678
1712
|
}
|
|
1679
|
-
throw
|
|
1713
|
+
throw errors.AccountLinkingError.unsupportedConnector(`Connector "${connectorName}" does not support automatic wallet linking. ` + `Use ${index$1.WALLET_CONNECTORS.METAMASK}, ${index$1.WALLET_CONNECTORS.WALLET_CONNECT_V2}, or an installed compatible wallet.`);
|
|
1680
1714
|
}
|
|
1681
1715
|
/**
|
|
1682
1716
|
* Create a new connector instance that is NOT registered in this.connectors and NOT
|
|
@@ -1705,7 +1739,7 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
|
|
|
1705
1739
|
break;
|
|
1706
1740
|
}
|
|
1707
1741
|
case index$1.WALLET_CONNECTORS.AUTH:
|
|
1708
|
-
throw
|
|
1742
|
+
throw errors.AccountLinkingError.unsupportedConnector(`Connector "${connectorName}" does not support automatic wallet linking.`);
|
|
1709
1743
|
default:
|
|
1710
1744
|
{
|
|
1711
1745
|
connector = await this.resolveDiscoveredWalletConnector(connectorName, chainId, config, effectiveProjectConfig);
|
package/dist/lib.cjs/providers/account-abstraction-provider/providers/AccountAbstractionProvider.js
CHANGED
|
@@ -71,9 +71,10 @@ class AccountAbstractionProvider extends baseProvider.BaseProvider {
|
|
|
71
71
|
}
|
|
72
72
|
async setupProvider(eoaProvider) {
|
|
73
73
|
var _bundlerConfig$transp;
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
|
|
74
|
+
const currentChain = this.currentChain;
|
|
75
|
+
if (!currentChain) {
|
|
76
|
+
throw index.WalletInitializationError.invalidProviderConfigError(`AA chain config not found for chain ${this.chainId}`);
|
|
77
|
+
}
|
|
77
78
|
const {
|
|
78
79
|
chainNamespace
|
|
79
80
|
} = currentChain;
|
|
@@ -148,9 +149,12 @@ class AccountAbstractionProvider extends baseProvider.BaseProvider {
|
|
|
148
149
|
eoaProvider,
|
|
149
150
|
handlers: providerHandlers
|
|
150
151
|
});
|
|
152
|
+
// middleware to handle EIP-7702 and EIP-5792 methods,
|
|
153
|
+
// currently, we do not support EIP-7702 and EIP-5792 methods for account abstraction provider
|
|
154
|
+
const eip7702And5792Middleware = await ethRpcMiddlewares.createEip7702And5792MiddlewareForAaProvider();
|
|
151
155
|
const eoaMiddleware = ethRpcMiddlewares.providerAsMiddleware(eoaProvider);
|
|
152
156
|
const engine = auth.JRPCEngineV2.create({
|
|
153
|
-
middleware: [aaMiddleware, eoaMiddleware]
|
|
157
|
+
middleware: [aaMiddleware, eip7702And5792Middleware, eoaMiddleware]
|
|
154
158
|
});
|
|
155
159
|
const provider = auth.providerFromEngineV2(engine);
|
|
156
160
|
this.updateProviderEngineProxy(provider);
|
|
@@ -4,21 +4,6 @@ var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
|
|
|
4
4
|
var metadataHelpers = require('@toruslabs/metadata-helpers');
|
|
5
5
|
var auth = require('@web3auth/auth');
|
|
6
6
|
var viem = require('viem');
|
|
7
|
-
require('@babel/runtime/helpers/defineProperty');
|
|
8
|
-
require('@segment/analytics-next');
|
|
9
|
-
var loglevel = require('../../../base/loglevel.js');
|
|
10
|
-
require('@toruslabs/base-controllers');
|
|
11
|
-
require('@toruslabs/session-manager');
|
|
12
|
-
require('../../../base/errors/index.js');
|
|
13
|
-
require('@toruslabs/constants');
|
|
14
|
-
require('@toruslabs/http-helpers');
|
|
15
|
-
require('../../../base/constants.js');
|
|
16
|
-
require('../../../base/wallet/index.js');
|
|
17
|
-
require('../../../base/connector/connectorStatus.js');
|
|
18
|
-
require('../../../base/connector/constants.js');
|
|
19
|
-
require('jwt-decode');
|
|
20
|
-
require('../../../base/plugin/errors.js');
|
|
21
|
-
require('../../../base/plugin/IPlugin.js');
|
|
22
7
|
|
|
23
8
|
function getProviderHandlers({
|
|
24
9
|
bundlerClient,
|
|
@@ -36,8 +21,6 @@ function getProviderHandlers({
|
|
|
36
21
|
const [smartAccounts, eoaAccounts] = await Promise.all([smartAccount.getAddress(), eoaProvider.request({
|
|
37
22
|
method: "eth_accounts"
|
|
38
23
|
})]);
|
|
39
|
-
loglevel.log.info("smartAccounts", smartAccounts);
|
|
40
|
-
loglevel.log.info("eoaAccounts", eoaAccounts);
|
|
41
24
|
return [smartAccounts, ...eoaAccounts];
|
|
42
25
|
},
|
|
43
26
|
getPrivateKey: async _ => {
|
|
@@ -181,6 +181,20 @@ async function createEoaMiddleware({
|
|
|
181
181
|
eth_requestAccounts: requestAccounts
|
|
182
182
|
});
|
|
183
183
|
}
|
|
184
|
+
async function createEip7702And5792MiddlewareForAaProvider() {
|
|
185
|
+
const eip5792Methods = Object.values(ethereumControllers.EIP_5792_METHODS);
|
|
186
|
+
const eip7702Methods = Object.values(ethereumControllers.EIP_7702_METHODS);
|
|
187
|
+
const eip7702And5792Methods = [...eip5792Methods, ...eip7702Methods];
|
|
188
|
+
return async ({
|
|
189
|
+
request,
|
|
190
|
+
next
|
|
191
|
+
}) => {
|
|
192
|
+
if (eip7702And5792Methods.includes(request.method)) {
|
|
193
|
+
throw auth.providerErrors.unsupportedMethod(`${request.method} is not supported for account abstraction provider`);
|
|
194
|
+
}
|
|
195
|
+
return next(request);
|
|
196
|
+
};
|
|
197
|
+
}
|
|
184
198
|
function providerAsMiddleware(provider) {
|
|
185
199
|
return async ({
|
|
186
200
|
request
|
|
@@ -193,5 +207,6 @@ function providerAsMiddleware(provider) {
|
|
|
193
207
|
}
|
|
194
208
|
|
|
195
209
|
exports.createAaMiddleware = createAaMiddleware;
|
|
210
|
+
exports.createEip7702And5792MiddlewareForAaProvider = createEip7702And5792MiddlewareForAaProvider;
|
|
196
211
|
exports.createEoaMiddleware = createEoaMiddleware;
|
|
197
212
|
exports.providerAsMiddleware = providerAsMiddleware;
|
|
@@ -140,19 +140,26 @@ function useWeb3AuthInnerContextValue({
|
|
|
140
140
|
const authorizedListener = () => {
|
|
141
141
|
setStatus(web3Auth.status);
|
|
142
142
|
if (web3Auth.status === constants.CONNECTOR_STATUS.AUTHORIZED) {
|
|
143
|
+
var _web3Auth$currentChai7, _web3Auth$currentChai8;
|
|
144
|
+
setIsInitialized(true);
|
|
143
145
|
setIsConnected(true);
|
|
146
|
+
// on rehydration, `AUTHORIZED` event can be fired first in `CONNECT_AND_SIGN` mode, before `CONNECTED` event.
|
|
147
|
+
// Update the connection state here, so that clients can use the connection state immediately.
|
|
148
|
+
setConnection(web3Auth.connection);
|
|
149
|
+
setChainId(web3Auth.currentChainId);
|
|
150
|
+
setChainNamespace((_web3Auth$currentChai7 = (_web3Auth$currentChai8 = web3Auth.currentChain) === null || _web3Auth$currentChai8 === void 0 ? void 0 : _web3Auth$currentChai8.chainNamespace) !== null && _web3Auth$currentChai7 !== void 0 ? _web3Auth$currentChai7 : null);
|
|
144
151
|
setIsAuthorized(true);
|
|
145
152
|
}
|
|
146
153
|
};
|
|
147
154
|
const consentAcceptedListener = () => {
|
|
148
155
|
setStatus(web3Auth.status);
|
|
149
156
|
if (web3Auth.status === constants.CONNECTOR_STATUS.CONNECTED || web3Auth.status === constants.CONNECTOR_STATUS.AUTHORIZED) {
|
|
150
|
-
var _web3Auth$
|
|
157
|
+
var _web3Auth$currentChai9, _web3Auth$currentChai0;
|
|
151
158
|
setIsInitialized(true);
|
|
152
159
|
setIsConnected(true);
|
|
153
160
|
setConnection(web3Auth.connection);
|
|
154
161
|
setChainId(web3Auth.currentChainId);
|
|
155
|
-
setChainNamespace((_web3Auth$
|
|
162
|
+
setChainNamespace((_web3Auth$currentChai9 = (_web3Auth$currentChai0 = web3Auth.currentChain) === null || _web3Auth$currentChai0 === void 0 ? void 0 : _web3Auth$currentChai0.chainNamespace) !== null && _web3Auth$currentChai9 !== void 0 ? _web3Auth$currentChai9 : null);
|
|
156
163
|
if (web3Auth.status === constants.CONNECTOR_STATUS.AUTHORIZED) {
|
|
157
164
|
setIsAuthorized(true);
|
|
158
165
|
}
|
|
@@ -161,6 +168,13 @@ function useWeb3AuthInnerContextValue({
|
|
|
161
168
|
const mfaEnabledListener = nextIsMFAEnabled => {
|
|
162
169
|
if (typeof nextIsMFAEnabled === "boolean") setIsMFAEnabled(nextIsMFAEnabled);
|
|
163
170
|
};
|
|
171
|
+
const connectionUpdatedListener = () => {
|
|
172
|
+
var _web3Auth$currentChai1, _web3Auth$currentChai10;
|
|
173
|
+
setStatus(web3Auth.status);
|
|
174
|
+
setConnection(web3Auth.connection);
|
|
175
|
+
setChainId(web3Auth.currentChainId);
|
|
176
|
+
setChainNamespace((_web3Auth$currentChai1 = (_web3Auth$currentChai10 = web3Auth.currentChain) === null || _web3Auth$currentChai10 === void 0 ? void 0 : _web3Auth$currentChai10.chainNamespace) !== null && _web3Auth$currentChai1 !== void 0 ? _web3Auth$currentChai1 : null);
|
|
177
|
+
};
|
|
164
178
|
if (web3Auth) {
|
|
165
179
|
web3Auth.on(constants.CONNECTOR_EVENTS.NOT_READY, notReadyListener);
|
|
166
180
|
web3Auth.on(constants.CONNECTOR_EVENTS.READY, readyListener);
|
|
@@ -171,6 +185,7 @@ function useWeb3AuthInnerContextValue({
|
|
|
171
185
|
web3Auth.on(constants.CONNECTOR_EVENTS.ERRORED, errorListener);
|
|
172
186
|
web3Auth.on(constants.CONNECTOR_EVENTS.REHYDRATION_ERROR, rehydrationErrorListener);
|
|
173
187
|
web3Auth.on(constants.CONNECTOR_EVENTS.MFA_ENABLED, mfaEnabledListener);
|
|
188
|
+
web3Auth.on(constants.CONNECTOR_EVENTS.CONNECTION_UPDATED, connectionUpdatedListener);
|
|
174
189
|
if (web3Auth.loginMode === constants$1.LOGIN_MODE.MODAL) {
|
|
175
190
|
web3Auth.on(constants.CONNECTOR_EVENTS.CONSENT_ACCEPTED, consentAcceptedListener);
|
|
176
191
|
}
|
|
@@ -186,6 +201,7 @@ function useWeb3AuthInnerContextValue({
|
|
|
186
201
|
web3Auth.removeListener(constants.CONNECTOR_EVENTS.REHYDRATION_ERROR, rehydrationErrorListener);
|
|
187
202
|
web3Auth.removeListener(constants.CONNECTOR_EVENTS.MFA_ENABLED, mfaEnabledListener);
|
|
188
203
|
web3Auth.removeListener(constants.CONNECTOR_EVENTS.AUTHORIZED, authorizedListener);
|
|
204
|
+
web3Auth.removeListener(constants.CONNECTOR_EVENTS.CONNECTION_UPDATED, connectionUpdatedListener);
|
|
189
205
|
if (web3Auth.loginMode === constants$1.LOGIN_MODE.MODAL) {
|
|
190
206
|
web3Auth.removeListener(constants.CONNECTOR_EVENTS.CONSENT_ACCEPTED, consentAcceptedListener);
|
|
191
207
|
}
|
|
@@ -69,6 +69,7 @@ function useFrameworkKitSolanaClient() {
|
|
|
69
69
|
isInitialized
|
|
70
70
|
} = useWeb3Auth.useWeb3Auth();
|
|
71
71
|
const {
|
|
72
|
+
chainId,
|
|
72
73
|
chainNamespace
|
|
73
74
|
} = useChain.useChain();
|
|
74
75
|
const ref = react.useRef(null);
|
|
@@ -118,7 +119,10 @@ function useFrameworkKitSolanaClient() {
|
|
|
118
119
|
return;
|
|
119
120
|
}
|
|
120
121
|
// only reconnect for the primary connector
|
|
121
|
-
if (conn.connectorName !== (web3Auth === null || web3Auth === void 0 ? void 0 : web3Auth.primaryConnectorName))
|
|
122
|
+
if (conn.connectorName !== (web3Auth === null || web3Auth === void 0 ? void 0 : web3Auth.primaryConnectorName)) {
|
|
123
|
+
adopt(makePlaceholder(rpc));
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
122
126
|
try {
|
|
123
127
|
const solanaWalletId = "wallet-standard:" + conn.connectorName;
|
|
124
128
|
const connector = client.createWalletStandardConnector(solanaWallet, {
|
|
@@ -150,7 +154,7 @@ function useFrameworkKitSolanaClient() {
|
|
|
150
154
|
return () => {
|
|
151
155
|
stale = true;
|
|
152
156
|
};
|
|
153
|
-
}, [isConnected, connection === null || connection === void 0 ? void 0 : connection.solanaWallet, chainNamespace, web3Auth, isInitialized, connection === null || connection === void 0 ? void 0 : connection.connectorName]);
|
|
157
|
+
}, [isConnected, connection === null || connection === void 0 ? void 0 : connection.solanaWallet, chainId, chainNamespace, web3Auth, isInitialized, connection === null || connection === void 0 ? void 0 : connection.connectorName]);
|
|
154
158
|
return client$1;
|
|
155
159
|
}
|
|
156
160
|
function SolanaProvider(_ref) {
|
|
@@ -5,3 +5,9 @@ var provider = require('./provider.js');
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
exports.WagmiProvider = provider.WagmiProvider;
|
|
8
|
+
exports.connectWeb3AuthWithWagmi = provider.connectWeb3AuthWithWagmi;
|
|
9
|
+
exports.createWeb3AuthConnectorForWagmi = provider.createWeb3AuthConnectorForWagmi;
|
|
10
|
+
exports.disconnectWeb3AuthFromWagmi = provider.disconnectWeb3AuthFromWagmi;
|
|
11
|
+
exports.getWeb3authConnector = provider.getWeb3authConnector;
|
|
12
|
+
exports.resetConnectorState = provider.resetConnectorState;
|
|
13
|
+
exports.setupConnector = provider.setupConnector;
|