Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@web3auth/metamask-adapter

Package Overview
Dependencies
Maintainers
2
Versions
113
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@web3auth/metamask-adapter - npm Package Compare versions

Comparing version 3.3.0 to 4.0.0-alpha.0

106

dist/metamaskAdapter.cjs.js

@@ -113,6 +113,9 @@ /******/ (() => { // webpackBootstrap

var _super = _createSuper(MetamaskAdapter);
function MetamaskAdapter(adapterOptions) {
function MetamaskAdapter() {
var _this;
classCallCheck_default()(this, MetamaskAdapter);
_this = _super.call(this, adapterOptions);
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _super.call.apply(_super, [this].concat(args));
defineProperty_default()(assertThisInitialized_default()(_this), "adapterNamespace", base_namespaceObject.ADAPTER_NAMESPACES.EIP155);

@@ -123,6 +126,3 @@ defineProperty_default()(assertThisInitialized_default()(_this), "currentChainNamespace", base_namespaceObject.CHAIN_NAMESPACES.EIP155);

defineProperty_default()(assertThisInitialized_default()(_this), "status", base_namespaceObject.ADAPTER_STATUS.NOT_READY);
defineProperty_default()(assertThisInitialized_default()(_this), "rehydrated", false);
defineProperty_default()(assertThisInitialized_default()(_this), "metamaskProvider", null);
_this.chainConfig = (adapterOptions === null || adapterOptions === void 0 ? void 0 : adapterOptions.chainConfig) || null;
_this.sessionTime = (adapterOptions === null || adapterOptions === void 0 ? void 0 : adapterOptions.sessionTime) || 86400;
return _this;

@@ -149,34 +149,37 @@ }

case 0:
_context.next = 2;
return get_default()(getPrototypeOf_default()(MetamaskAdapter.prototype), "init", this).call(this, options);
case 2:
get_default()(getPrototypeOf_default()(MetamaskAdapter.prototype), "checkInitializationRequirements", this).call(this);
_context.next = 3;
_context.next = 5;
return detect_provider_default()({
mustBeMetaMask: true
});
case 3:
case 5:
this.metamaskProvider = _context.sent;
if (this.metamaskProvider) {
_context.next = 6;
_context.next = 8;
break;
}
throw base_namespaceObject.WalletInitializationError.notInstalled("Metamask extension is not installed");
case 6:
case 8:
this.status = base_namespaceObject.ADAPTER_STATUS.READY;
this.emit(base_namespaceObject.ADAPTER_EVENTS.READY, base_namespaceObject.WALLET_ADAPTERS.METAMASK);
_context.prev = 8;
_context.prev = 10;
base_namespaceObject.log.debug("initializing metamask adapter");
if (!options.autoConnect) {
_context.next = 14;
_context.next = 16;
break;
}
this.rehydrated = true;
_context.next = 14;
_context.next = 16;
return this.connect();
case 14:
_context.next = 19;
case 16:
_context.next = 21;
break;
case 16:
_context.prev = 16;
_context.t0 = _context["catch"](8);
case 18:
_context.prev = 18;
_context.t0 = _context["catch"](10);
this.emit(base_namespaceObject.ADAPTER_EVENTS.ERRORED, _context.t0);
case 19:
case 21:
case "end":

@@ -186,3 +189,3 @@ return _context.stop();

}
}, _callee, this, [[8, 16]]);
}, _callee, this, [[10, 18]]);
}));

@@ -195,13 +198,2 @@ function init(_x) {

}, {
key: "setAdapterSettings",
value: function setAdapterSettings(options) {
if (this.status === base_namespaceObject.ADAPTER_STATUS.READY) return;
if (options !== null && options !== void 0 && options.sessionTime) {
this.sessionTime = options.sessionTime;
}
if (options !== null && options !== void 0 && options.clientId) {
this.clientId = options.clientId;
}
}
}, {
key: "connect",

@@ -217,4 +209,8 @@ value: function () {

get_default()(getPrototypeOf_default()(MetamaskAdapter.prototype), "checkConnectionRequirements", this).call(this);
// set default to mainnet
if (!this.chainConfig) this.chainConfig = (0,base_namespaceObject.getChainConfig)(base_namespaceObject.CHAIN_NAMESPACES.EIP155, 1);
if (this.metamaskProvider) {
_context2.next = 3;
break;
}
throw base_namespaceObject.WalletLoginError.notConnectedError("Not able to connect with metamask");
case 3:
this.status = base_namespaceObject.ADAPTER_STATUS.CONNECTING;

@@ -224,29 +220,23 @@ this.emit(base_namespaceObject.ADAPTER_EVENTS.CONNECTING, {

});
if (this.metamaskProvider) {
_context2.next = 6;
break;
}
throw base_namespaceObject.WalletLoginError.notConnectedError("Not able to connect with metamask");
case 6:
_context2.prev = 6;
_context2.next = 9;
_context2.prev = 5;
_context2.next = 8;
return this.metamaskProvider.request({
method: "eth_requestAccounts"
});
case 9:
case 8:
chainId = this.metamaskProvider.chainId;
if (!(chainId !== this.chainConfig.chainId)) {
_context2.next = 13;
_context2.next = 12;
break;
}
_context2.next = 13;
_context2.next = 12;
return this.switchChain(this.chainConfig);
case 13:
case 12:
this.status = base_namespaceObject.ADAPTER_STATUS.CONNECTED;
if (this.provider) {
_context2.next = 16;
_context2.next = 15;
break;
}
throw base_namespaceObject.WalletLoginError.notConnectedError("Failed to connect with provider");
case 16:
case 15:
this.provider.once("disconnect", function () {

@@ -261,5 +251,5 @@ // ready to be connected again

return _context2.abrupt("return", this.provider);
case 21:
_context2.prev = 21;
_context2.t0 = _context2["catch"](6);
case 20:
_context2.prev = 20;
_context2.t0 = _context2["catch"](5);
// ready again to be connected

@@ -270,3 +260,3 @@ this.status = base_namespaceObject.ADAPTER_STATUS.READY;

throw base_namespaceObject.WalletLoginError.connectionError("Failed to login with metamask wallet");
case 27:
case 26:
case "end":

@@ -276,3 +266,3 @@ return _context2.stop();

}
}, _callee2, this, [[6, 21]]);
}, _callee2, this, [[5, 20]]);
}));

@@ -299,3 +289,3 @@ function connect() {

_context3.next = 3;
return get_default()(getPrototypeOf_default()(MetamaskAdapter.prototype), "disconnect", this).call(this);
return get_default()(getPrototypeOf_default()(MetamaskAdapter.prototype), "disconnectSession", this).call(this);
case 3:

@@ -310,4 +300,4 @@ (_this$provider = this.provider) === null || _this$provider === void 0 ? void 0 : _this$provider.removeAllListeners();

}
this.rehydrated = false;
this.emit(base_namespaceObject.ADAPTER_EVENTS.DISCONNECTED);
_context3.next = 7;
return get_default()(getPrototypeOf_default()(MetamaskAdapter.prototype), "disconnect", this).call(this);
case 7:

@@ -390,3 +380,9 @@ case "end":

chainName: chainConfig.displayName,
rpcUrls: [chainConfig.rpcTarget]
rpcUrls: [chainConfig.rpcTarget],
blockExplorerUrls: [chainConfig.blockExplorer],
nativeCurrency: {
name: chainConfig.tickerName,
symbol: chainConfig.ticker,
decimals: chainConfig.decimals || 18
}
}]

@@ -393,0 +389,0 @@ });

@@ -12,3 +12,3 @@ import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';

import detectEthereumProvider from '@metamask/detect-provider';
import { ADAPTER_NAMESPACES, CHAIN_NAMESPACES, ADAPTER_CATEGORY, WALLET_ADAPTERS, ADAPTER_STATUS, ADAPTER_EVENTS, log, WalletInitializationError, WalletLoginError, getChainConfig } from '@web3auth/base';
import { ADAPTER_NAMESPACES, CHAIN_NAMESPACES, ADAPTER_CATEGORY, WALLET_ADAPTERS, ADAPTER_STATUS, ADAPTER_EVENTS, log, WalletInitializationError, WalletLoginError } from '@web3auth/base';
import { BaseEvmAdapter } from '@web3auth/base-evm-adapter';

@@ -21,6 +21,9 @@

var _super = _createSuper(MetamaskAdapter);
function MetamaskAdapter(adapterOptions) {
function MetamaskAdapter() {
var _this;
_classCallCheck(this, MetamaskAdapter);
_this = _super.call(this, adapterOptions);
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _super.call.apply(_super, [this].concat(args));
_defineProperty(_assertThisInitialized(_this), "adapterNamespace", ADAPTER_NAMESPACES.EIP155);

@@ -31,6 +34,3 @@ _defineProperty(_assertThisInitialized(_this), "currentChainNamespace", CHAIN_NAMESPACES.EIP155);

_defineProperty(_assertThisInitialized(_this), "status", ADAPTER_STATUS.NOT_READY);
_defineProperty(_assertThisInitialized(_this), "rehydrated", false);
_defineProperty(_assertThisInitialized(_this), "metamaskProvider", null);
_this.chainConfig = (adapterOptions === null || adapterOptions === void 0 ? void 0 : adapterOptions.chainConfig) || null;
_this.sessionTime = (adapterOptions === null || adapterOptions === void 0 ? void 0 : adapterOptions.sessionTime) || 86400;
return _this;

@@ -57,34 +57,37 @@ }

case 0:
_context.next = 2;
return _get(_getPrototypeOf(MetamaskAdapter.prototype), "init", this).call(this, options);
case 2:
_get(_getPrototypeOf(MetamaskAdapter.prototype), "checkInitializationRequirements", this).call(this);
_context.next = 3;
_context.next = 5;
return detectEthereumProvider({
mustBeMetaMask: true
});
case 3:
case 5:
this.metamaskProvider = _context.sent;
if (this.metamaskProvider) {
_context.next = 6;
_context.next = 8;
break;
}
throw WalletInitializationError.notInstalled("Metamask extension is not installed");
case 6:
case 8:
this.status = ADAPTER_STATUS.READY;
this.emit(ADAPTER_EVENTS.READY, WALLET_ADAPTERS.METAMASK);
_context.prev = 8;
_context.prev = 10;
log.debug("initializing metamask adapter");
if (!options.autoConnect) {
_context.next = 14;
_context.next = 16;
break;
}
this.rehydrated = true;
_context.next = 14;
_context.next = 16;
return this.connect();
case 14:
_context.next = 19;
case 16:
_context.next = 21;
break;
case 16:
_context.prev = 16;
_context.t0 = _context["catch"](8);
case 18:
_context.prev = 18;
_context.t0 = _context["catch"](10);
this.emit(ADAPTER_EVENTS.ERRORED, _context.t0);
case 19:
case 21:
case "end":

@@ -94,3 +97,3 @@ return _context.stop();

}
}, _callee, this, [[8, 16]]);
}, _callee, this, [[10, 18]]);
}));

@@ -103,13 +106,2 @@ function init(_x) {

}, {
key: "setAdapterSettings",
value: function setAdapterSettings(options) {
if (this.status === ADAPTER_STATUS.READY) return;
if (options !== null && options !== void 0 && options.sessionTime) {
this.sessionTime = options.sessionTime;
}
if (options !== null && options !== void 0 && options.clientId) {
this.clientId = options.clientId;
}
}
}, {
key: "connect",

@@ -125,4 +117,8 @@ value: function () {

_get(_getPrototypeOf(MetamaskAdapter.prototype), "checkConnectionRequirements", this).call(this);
// set default to mainnet
if (!this.chainConfig) this.chainConfig = getChainConfig(CHAIN_NAMESPACES.EIP155, 1);
if (this.metamaskProvider) {
_context2.next = 3;
break;
}
throw WalletLoginError.notConnectedError("Not able to connect with metamask");
case 3:
this.status = ADAPTER_STATUS.CONNECTING;

@@ -132,29 +128,23 @@ this.emit(ADAPTER_EVENTS.CONNECTING, {

});
if (this.metamaskProvider) {
_context2.next = 6;
break;
}
throw WalletLoginError.notConnectedError("Not able to connect with metamask");
case 6:
_context2.prev = 6;
_context2.next = 9;
_context2.prev = 5;
_context2.next = 8;
return this.metamaskProvider.request({
method: "eth_requestAccounts"
});
case 9:
case 8:
chainId = this.metamaskProvider.chainId;
if (!(chainId !== this.chainConfig.chainId)) {
_context2.next = 13;
_context2.next = 12;
break;
}
_context2.next = 13;
_context2.next = 12;
return this.switchChain(this.chainConfig);
case 13:
case 12:
this.status = ADAPTER_STATUS.CONNECTED;
if (this.provider) {
_context2.next = 16;
_context2.next = 15;
break;
}
throw WalletLoginError.notConnectedError("Failed to connect with provider");
case 16:
case 15:
this.provider.once("disconnect", function () {

@@ -169,5 +159,5 @@ // ready to be connected again

return _context2.abrupt("return", this.provider);
case 21:
_context2.prev = 21;
_context2.t0 = _context2["catch"](6);
case 20:
_context2.prev = 20;
_context2.t0 = _context2["catch"](5);
// ready again to be connected

@@ -178,3 +168,3 @@ this.status = ADAPTER_STATUS.READY;

throw WalletLoginError.connectionError("Failed to login with metamask wallet");
case 27:
case 26:
case "end":

@@ -184,3 +174,3 @@ return _context2.stop();

}
}, _callee2, this, [[6, 21]]);
}, _callee2, this, [[5, 20]]);
}));

@@ -207,3 +197,3 @@ function connect() {

_context3.next = 3;
return _get(_getPrototypeOf(MetamaskAdapter.prototype), "disconnect", this).call(this);
return _get(_getPrototypeOf(MetamaskAdapter.prototype), "disconnectSession", this).call(this);
case 3:

@@ -218,4 +208,4 @@ (_this$provider = this.provider) === null || _this$provider === void 0 ? void 0 : _this$provider.removeAllListeners();

}
this.rehydrated = false;
this.emit(ADAPTER_EVENTS.DISCONNECTED);
_context3.next = 7;
return _get(_getPrototypeOf(MetamaskAdapter.prototype), "disconnect", this).call(this);
case 7:

@@ -298,3 +288,9 @@ case "end":

chainName: chainConfig.displayName,
rpcUrls: [chainConfig.rpcTarget]
rpcUrls: [chainConfig.rpcTarget],
blockExplorerUrls: [chainConfig.blockExplorer],
nativeCurrency: {
name: chainConfig.tickerName,
symbol: chainConfig.ticker,
decimals: chainConfig.decimals || 18
}
}]

@@ -301,0 +297,0 @@ });

@@ -1,8 +0,4 @@

import { ADAPTER_CATEGORY_TYPE, ADAPTER_STATUS_TYPE, AdapterInitOptions, AdapterNamespaceType, ChainNamespaceType, CustomChainConfig, SafeEventEmitterProvider, UserInfo } from "@web3auth/base";
import { ADAPTER_CATEGORY_TYPE, ADAPTER_STATUS_TYPE, AdapterInitOptions, AdapterNamespaceType, BaseAdapterSettings, ChainNamespaceType, SafeEventEmitterProvider, UserInfo } from "@web3auth/base";
import { BaseEvmAdapter } from "@web3auth/base-evm-adapter";
export interface MetamaskAdapterOptions {
chainConfig?: CustomChainConfig;
sessionTime?: number;
clientId?: string;
}
export type MetamaskAdapterOptions = BaseAdapterSettings;
declare class MetamaskAdapter extends BaseEvmAdapter<void> {

@@ -14,12 +10,6 @@ readonly adapterNamespace: AdapterNamespaceType;

status: ADAPTER_STATUS_TYPE;
private rehydrated;
private metamaskProvider;
constructor(adapterOptions: MetamaskAdapterOptions);
get provider(): SafeEventEmitterProvider | null;
set provider(_: SafeEventEmitterProvider | null);
init(options: AdapterInitOptions): Promise<void>;
setAdapterSettings(options: {
sessionTime?: number;
clientId?: string;
}): void;
connect(): Promise<SafeEventEmitterProvider | null>;

@@ -26,0 +16,0 @@ disconnect(options?: {

{
"name": "@web3auth/metamask-adapter",
"version": "3.3.0",
"version": "4.0.0-alpha.0",
"description": "metamask wallet adapter for web3auth",

@@ -39,4 +39,4 @@ "keywords": [

"@metamask/detect-provider": "^2.0.0",
"@web3auth/base": "^3.3.0",
"@web3auth/base-evm-adapter": "^3.3.0"
"@web3auth/base": "^4.0.0-alpha.0",
"@web3auth/base-evm-adapter": "^4.0.0-alpha.0"
},

@@ -59,3 +59,3 @@ "lint-staged": {

},
"gitHead": "6e76c018f9e240a6ed4dcbfc5b87bed52a58b338"
"gitHead": "e53943258fb8082258c6bf382a350574637439f7"
}

@@ -11,2 +11,3 @@ import detectEthereumProvider from "@metamask/detect-provider";

AdapterNamespaceType,
BaseAdapterSettings,
CHAIN_NAMESPACES,

@@ -16,3 +17,2 @@ ChainNamespaceType,

CustomChainConfig,
getChainConfig,
log,

@@ -32,7 +32,3 @@ SafeEventEmitterProvider,

}
export interface MetamaskAdapterOptions {
chainConfig?: CustomChainConfig;
sessionTime?: number;
clientId?: string;
}
export type MetamaskAdapterOptions = BaseAdapterSettings;

@@ -50,12 +46,4 @@ class MetamaskAdapter extends BaseEvmAdapter<void> {

private rehydrated = false;
private metamaskProvider: EthereumProvider | null = null;
constructor(adapterOptions: MetamaskAdapterOptions) {
super(adapterOptions);
this.chainConfig = adapterOptions?.chainConfig || null;
this.sessionTime = adapterOptions?.sessionTime || 86400;
}
get provider(): SafeEventEmitterProvider | null {

@@ -73,2 +61,3 @@ if (this.status === ADAPTER_STATUS.CONNECTED && this.metamaskProvider) {

async init(options: AdapterInitOptions): Promise<void> {
await super.init(options);
super.checkInitializationRequirements();

@@ -90,20 +79,8 @@ this.metamaskProvider = (await detectEthereumProvider({ mustBeMetaMask: true })) as EthereumProvider;

setAdapterSettings(options: { sessionTime?: number; clientId?: string }): void {
if (this.status === ADAPTER_STATUS.READY) return;
if (options?.sessionTime) {
this.sessionTime = options.sessionTime;
}
if (options?.clientId) {
this.clientId = options.clientId;
}
}
async connect(): Promise<SafeEventEmitterProvider | null> {
super.checkConnectionRequirements();
// set default to mainnet
if (!this.chainConfig) this.chainConfig = getChainConfig(CHAIN_NAMESPACES.EIP155, 1);
if (!this.metamaskProvider) throw WalletLoginError.notConnectedError("Not able to connect with metamask");
this.status = ADAPTER_STATUS.CONNECTING;
this.emit(ADAPTER_EVENTS.CONNECTING, { adapter: WALLET_ADAPTERS.METAMASK });
if (!this.metamaskProvider) throw WalletLoginError.notConnectedError("Not able to connect with metamask");
try {

@@ -133,3 +110,3 @@ await this.metamaskProvider.request({ method: "eth_requestAccounts" });

async disconnect(options: { cleanup: boolean } = { cleanup: false }): Promise<void> {
await super.disconnect();
await super.disconnectSession();
this.provider?.removeAllListeners();

@@ -143,5 +120,3 @@ if (options.cleanup) {

}
this.rehydrated = false;
this.emit(ADAPTER_EVENTS.DISCONNECTED);
await super.disconnect();
}

@@ -166,3 +141,15 @@

method: "wallet_addEthereumChain",
params: [{ chainId: chainConfig.chainId, chainName: chainConfig.displayName, rpcUrls: [chainConfig.rpcTarget] }],
params: [
{
chainId: chainConfig.chainId,
chainName: chainConfig.displayName,
rpcUrls: [chainConfig.rpcTarget],
blockExplorerUrls: [chainConfig.blockExplorer],
nativeCurrency: {
name: chainConfig.tickerName,
symbol: chainConfig.ticker,
decimals: chainConfig.decimals || 18,
},
},
],
});

@@ -169,0 +156,0 @@ } else {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc