@metamask/providers
Advanced tools
Comparing version 12.0.0 to 13.0.0
@@ -9,2 +9,8 @@ # Changelog | ||
## [13.0.0] | ||
### Changed | ||
- **BREAKING**: Update `chainId`, `networkVersion`, and `selectedAddress` to be read-only ([#280](https://github.com/MetaMask/providers/pull/280)) | ||
- Log deprecation warning when accessing `chainId`, `networkVersion`, and `selectedAddress` ([#280](https://github.com/MetaMask/providers/pull/280)) | ||
- Remove `pump` ([#281](https://github.com/MetaMask/providers/pull/281)) | ||
## [12.0.0] | ||
@@ -242,3 +248,4 @@ ### Changed | ||
[Unreleased]: https://github.com/MetaMask/providers/compare/v12.0.0...HEAD | ||
[Unreleased]: https://github.com/MetaMask/providers/compare/v13.0.0...HEAD | ||
[13.0.0]: https://github.com/MetaMask/providers/compare/v12.0.0...v13.0.0 | ||
[12.0.0]: https://github.com/MetaMask/providers/compare/v11.1.2...v12.0.0 | ||
@@ -245,0 +252,0 @@ [11.1.2]: https://github.com/MetaMask/providers/compare/v11.1.1...v11.1.2 |
@@ -50,2 +50,3 @@ import { JsonRpcEngine, JsonRpcMiddleware } from '@metamask/json-rpc-engine'; | ||
export declare abstract class BaseProvider extends SafeEventEmitter { | ||
#private; | ||
protected readonly _log: ConsoleLike; | ||
@@ -56,13 +57,2 @@ protected _state: BaseProviderState; | ||
/** | ||
* The chain ID of the currently connected Ethereum chain. | ||
* See [chainId.network]{@link https://chainid.network} for more information. | ||
*/ | ||
chainId: string | null; | ||
/** | ||
* The user's currently selected Ethereum address. | ||
* If null, MetaMask is either locked or the user has not permitted any | ||
* addresses to be viewed. | ||
*/ | ||
selectedAddress: string | null; | ||
/** | ||
* Create a new instance of the provider. | ||
@@ -77,2 +67,4 @@ * | ||
constructor({ logger, maxEventListeners, rpcMiddleware, }?: BaseProviderOptions); | ||
get chainId(): string | null; | ||
get selectedAddress(): string | null; | ||
/** | ||
@@ -79,0 +71,0 @@ * Returns whether the provider can process RPC requests. |
"use strict"; | ||
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { | ||
if (kind === "m") throw new TypeError("Private method is not writable"); | ||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); | ||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); | ||
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; | ||
}; | ||
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { | ||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); | ||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); | ||
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
var _BaseProvider_chainId, _BaseProvider_selectedAddress; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -35,2 +47,13 @@ exports.BaseProvider = void 0; | ||
super(); | ||
/** | ||
* The chain ID of the currently connected Ethereum chain. | ||
* See [chainId.network]{@link https://chainid.network} for more information. | ||
*/ | ||
_BaseProvider_chainId.set(this, void 0); | ||
/** | ||
* The user's currently selected Ethereum address. | ||
* If null, MetaMask is either locked or the user has not permitted any | ||
* addresses to be viewed. | ||
*/ | ||
_BaseProvider_selectedAddress.set(this, void 0); | ||
this._log = logger; | ||
@@ -43,4 +66,4 @@ this.setMaxListeners(maxEventListeners); | ||
// Public state | ||
this.selectedAddress = null; | ||
this.chainId = null; | ||
__classPrivateFieldSet(this, _BaseProvider_selectedAddress, null, "f"); | ||
__classPrivateFieldSet(this, _BaseProvider_chainId, null, "f"); | ||
// Bind functions to prevent consumers from making unbound calls | ||
@@ -63,2 +86,11 @@ this._handleAccountsChanged = this._handleAccountsChanged.bind(this); | ||
//==================== | ||
// Public Properties | ||
//==================== | ||
get chainId() { | ||
return __classPrivateFieldGet(this, _BaseProvider_chainId, "f"); | ||
} | ||
get selectedAddress() { | ||
return __classPrivateFieldGet(this, _BaseProvider_selectedAddress, "f"); | ||
} | ||
//==================== | ||
// Public Methods | ||
@@ -212,5 +244,5 @@ //==================== | ||
this._log.error(error); | ||
this.chainId = null; | ||
__classPrivateFieldSet(this, _BaseProvider_chainId, null, "f"); | ||
this._state.accounts = null; | ||
this.selectedAddress = null; | ||
__classPrivateFieldSet(this, _BaseProvider_selectedAddress, null, "f"); | ||
this._state.isUnlocked = false; | ||
@@ -240,6 +272,6 @@ this._state.isPermanentlyDisconnected = true; | ||
this._handleConnect(chainId); | ||
if (chainId !== this.chainId) { | ||
this.chainId = chainId; | ||
if (chainId !== __classPrivateFieldGet(this, _BaseProvider_chainId, "f")) { | ||
__classPrivateFieldSet(this, _BaseProvider_chainId, chainId, "f"); | ||
if (this._state.initialized) { | ||
this.emit('chainChanged', this.chainId); | ||
this.emit('chainChanged', __classPrivateFieldGet(this, _BaseProvider_chainId, "f")); | ||
} | ||
@@ -279,4 +311,4 @@ } | ||
// handle selectedAddress | ||
if (this.selectedAddress !== _accounts[0]) { | ||
this.selectedAddress = _accounts[0] || null; | ||
if (__classPrivateFieldGet(this, _BaseProvider_selectedAddress, "f") !== _accounts[0]) { | ||
__classPrivateFieldSet(this, _BaseProvider_selectedAddress, _accounts[0] || null, "f"); | ||
} | ||
@@ -314,2 +346,3 @@ // finally, after all state has been updated, emit the event | ||
exports.BaseProvider = BaseProvider; | ||
_BaseProvider_chainId = new WeakMap(), _BaseProvider_selectedAddress = new WeakMap(); | ||
BaseProvider._defaultState = { | ||
@@ -316,0 +349,0 @@ accounts: null, |
@@ -29,2 +29,7 @@ "use strict"; | ||
deleteProperty: () => true, | ||
// fix issue with Proxy unable to access private variables from getters | ||
// https://stackoverflow.com/a/73051482 | ||
get(target, propName) { | ||
return target[propName]; | ||
}, | ||
}); | ||
@@ -31,0 +36,0 @@ if (shouldSetOnWindow) { |
@@ -19,2 +19,5 @@ declare const messages: { | ||
warnings: { | ||
chainIdDeprecation: string; | ||
networkVersionDeprecation: string; | ||
selectedAddressDeprecation: string; | ||
enableDeprecation: string; | ||
@@ -21,0 +24,0 @@ sendDeprecation: string; |
@@ -21,2 +21,6 @@ "use strict"; | ||
warnings: { | ||
// deprecated properties | ||
chainIdDeprecation: `MetaMask: 'ethereum.chainId' is deprecated and may be removed in the future. Please use the 'eth_chainId' RPC method instead.\nFor more information, see: https://github.com/MetaMask/metamask-improvement-proposals/discussions/23`, | ||
networkVersionDeprecation: `MetaMask: 'ethereum.networkVersion' is deprecated and may be removed in the future. Please use the 'net_version' RPC method instead.\nFor more information, see: https://github.com/MetaMask/metamask-improvement-proposals/discussions/23`, | ||
selectedAddressDeprecation: `MetaMask: 'ethereum.selectedAddress' is deprecated and may be removed in the future. Please use the 'eth_accounts' RPC method instead.\nFor more information, see: https://github.com/MetaMask/metamask-improvement-proposals/discussions/23`, | ||
// deprecated methods | ||
@@ -23,0 +27,0 @@ enableDeprecation: `MetaMask: 'ethereum.enable()' is deprecated and may be removed in the future. Please use the 'eth_requestAccounts' RPC method instead.\nFor more information, see: https://eips.ethereum.org/EIPS/eip-1102`, |
@@ -17,2 +17,5 @@ /// <reference types="node" /> | ||
declare type SentWarningsState = { | ||
chainId: boolean; | ||
networkVersion: boolean; | ||
selectedAddress: boolean; | ||
enable: boolean; | ||
@@ -33,2 +36,3 @@ experimentalMethods: boolean; | ||
export declare class MetaMaskInpageProvider extends AbstractStreamProvider { | ||
#private; | ||
protected _sentWarnings: SentWarningsState; | ||
@@ -39,3 +43,2 @@ /** | ||
readonly _metamask: ReturnType<MetaMaskInpageProvider['_getExperimentalApi']>; | ||
networkVersion: string | null; | ||
/** | ||
@@ -59,2 +62,5 @@ * Indicating that this provider is a MetaMask provider. | ||
constructor(connectionStream: Duplex, { jsonRpcStreamName, logger, maxEventListeners, shouldSendMetadata, }?: MetaMaskInpageProviderOptions); | ||
get chainId(): string | null; | ||
get networkVersion(): string | null; | ||
get selectedAddress(): string | null; | ||
/** | ||
@@ -61,0 +67,0 @@ * Submits an RPC request per the given JSON-RPC request object. |
"use strict"; | ||
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { | ||
if (kind === "m") throw new TypeError("Private method is not writable"); | ||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); | ||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); | ||
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; | ||
}; | ||
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { | ||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); | ||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); | ||
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
var _MetaMaskInpageProvider_networkVersion; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -38,2 +50,6 @@ exports.MetaMaskInpageProvider = exports.MetaMaskInpageProviderStreamName = void 0; | ||
this._sentWarnings = { | ||
// properties | ||
chainId: false, | ||
networkVersion: false, | ||
selectedAddress: false, | ||
// methods | ||
@@ -51,2 +67,3 @@ enable: false, | ||
}; | ||
_MetaMaskInpageProvider_networkVersion.set(this, void 0); | ||
// We shouldn't perform asynchronous work in the constructor, but at one | ||
@@ -57,3 +74,3 @@ // point we started doing so, and changing this class isn't worth it at | ||
this._initializeStateAsync(); | ||
this.networkVersion = null; | ||
__classPrivateFieldSet(this, _MetaMaskInpageProvider_networkVersion, null, "f"); | ||
this.isMetaMask = true; | ||
@@ -94,2 +111,26 @@ this._sendSync = this._sendSync.bind(this); | ||
//==================== | ||
// Deprecated Properties | ||
//==================== | ||
get chainId() { | ||
if (!this._sentWarnings.chainId) { | ||
this._log.warn(messages_1.default.warnings.chainIdDeprecation); | ||
this._sentWarnings.chainId = true; | ||
} | ||
return super.chainId; | ||
} | ||
get networkVersion() { | ||
if (!this._sentWarnings.networkVersion) { | ||
this._log.warn(messages_1.default.warnings.networkVersionDeprecation); | ||
this._sentWarnings.networkVersion = true; | ||
} | ||
return __classPrivateFieldGet(this, _MetaMaskInpageProvider_networkVersion, "f"); | ||
} | ||
get selectedAddress() { | ||
if (!this._sentWarnings.selectedAddress) { | ||
this._log.warn(messages_1.default.warnings.selectedAddressDeprecation); | ||
this._sentWarnings.selectedAddress = true; | ||
} | ||
return super.selectedAddress; | ||
} | ||
//==================== | ||
// Public Methods | ||
@@ -147,4 +188,4 @@ //==================== | ||
super._handleDisconnect(isRecoverable, errorMessage); | ||
if (this.networkVersion && !isRecoverable) { | ||
this.networkVersion = null; | ||
if (__classPrivateFieldGet(this, _MetaMaskInpageProvider_networkVersion, "f") && !isRecoverable) { | ||
__classPrivateFieldSet(this, _MetaMaskInpageProvider_networkVersion, null, "f"); | ||
} | ||
@@ -232,3 +273,3 @@ } | ||
case 'net_version': | ||
result = this.networkVersion ?? null; | ||
result = __classPrivateFieldGet(this, _MetaMaskInpageProvider_networkVersion, "f") ?? null; | ||
break; | ||
@@ -307,6 +348,6 @@ default: | ||
super._handleChainChanged({ chainId, networkVersion }); | ||
if (this._state.isConnected && networkVersion !== this.networkVersion) { | ||
this.networkVersion = networkVersion; | ||
if (this._state.isConnected && networkVersion !== __classPrivateFieldGet(this, _MetaMaskInpageProvider_networkVersion, "f")) { | ||
__classPrivateFieldSet(this, _MetaMaskInpageProvider_networkVersion, networkVersion, "f"); | ||
if (this._state.initialized) { | ||
this.emit('networkChanged', this.networkVersion); | ||
this.emit('networkChanged', __classPrivateFieldGet(this, _MetaMaskInpageProvider_networkVersion, "f")); | ||
} | ||
@@ -317,2 +358,3 @@ } | ||
exports.MetaMaskInpageProvider = MetaMaskInpageProvider; | ||
_MetaMaskInpageProvider_networkVersion = new WeakMap(); | ||
//# sourceMappingURL=MetaMaskInpageProvider.js.map |
@@ -10,3 +10,3 @@ "use strict"; | ||
const json_rpc_middleware_stream_1 = require("json-rpc-middleware-stream"); | ||
const pump_1 = __importDefault(require("pump")); | ||
const stream_1 = require("stream"); | ||
const BaseProvider_1 = require("./BaseProvider"); | ||
@@ -42,3 +42,3 @@ const messages_1 = __importDefault(require("./messages")); | ||
const mux = new object_multiplex_1.default(); | ||
(0, pump_1.default)(connectionStream, mux, connectionStream, this._handleStreamDisconnect.bind(this, 'MetaMask')); | ||
(0, stream_1.pipeline)(connectionStream, mux, connectionStream, this._handleStreamDisconnect.bind(this, 'MetaMask')); | ||
// Set up RPC connection | ||
@@ -50,3 +50,3 @@ // Typecast: The type of `Duplex` is incompatible with the type of | ||
}); | ||
(0, pump_1.default)(this._jsonRpcConnection.stream, mux.createStream(jsonRpcStreamName), this._jsonRpcConnection.stream, this._handleStreamDisconnect.bind(this, 'MetaMask RpcProvider')); | ||
(0, stream_1.pipeline)(this._jsonRpcConnection.stream, mux.createStream(jsonRpcStreamName), this._jsonRpcConnection.stream, this._handleStreamDisconnect.bind(this, 'MetaMask RpcProvider')); | ||
// Wire up the JsonRpcEngine to the JSON-RPC connection stream | ||
@@ -53,0 +53,0 @@ this._rpcEngine.push(this._jsonRpcConnection.middleware); |
{ | ||
"name": "@metamask/providers", | ||
"version": "12.0.0", | ||
"version": "13.0.0", | ||
"description": "A JavaScript Ethereum provider that connects to the wallet over a stream.", | ||
@@ -50,3 +50,2 @@ "keywords": [ | ||
"json-rpc-middleware-stream": "^4.2.1", | ||
"pump": "^3.0.0", | ||
"webextension-polyfill": "^0.10.0" | ||
@@ -64,3 +63,2 @@ }, | ||
"@types/node": "^17.0.23", | ||
"@types/pump": "^1.1.0", | ||
"@types/readable-stream": "^2.3.15", | ||
@@ -67,0 +65,0 @@ "@types/webextension-polyfill": "^0.10.0", |
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 not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
197129
11
32
1934
- Removedpump@^3.0.0
- Removedpump@3.0.2(transitive)