From 80324667015eb1cbd7535426cc4a821334cf3886 Mon Sep 17 00:00:00 2001 From: Paul Bouchon Date: Tue, 3 Jul 2018 17:42:37 -0400 Subject: [PATCH] Automatically merged updates to draft EIP(s) 1102 Hi, I'm a bot! This change was automatically merged because: - It only modifies existing Draft or Last Call EIP(s) - The PR was approved or written by at least one author of each modified EIP - The build is passing --- EIPS/eip-1102.md | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/EIPS/eip-1102.md b/EIPS/eip-1102.md index e8d4b564..41732c37 100644 --- a/EIPS/eip-1102.md +++ b/EIPS/eip-1102.md @@ -2,7 +2,7 @@ eip: 1102 title: Opt-in provider access author: Paul Bouchon -discussions-to: https://ethereum-magicians.org/t/opt-in-web3-access/414 +discussions-to: https://ethereum-magicians.org/t/eip-1102-opt-in-provider-access/414 status: Draft type: Standards Track category: Interface @@ -37,22 +37,27 @@ IF web3 is undefined START dapp REQUEST[1] Ethereum provider IF user approves - NOTIFY[2] dapp + INJECT[2] provider API + NOTIFY[3] dapp CONTINUE dapp IF user rejects IF non-Ethereum environment - NOOP[3] + NOOP[4] ``` #### `[1] REQUEST` -Dapps MUST request an Ethereum provider API by sending a message using the [`window.postMessage`](https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage) API. This message MUST be sent with a payload object containing a `type` property with a value of `ETHEREUM_PROVIDER_REQUEST`. +Dapps MUST request an Ethereum provider API by sending a message using the [`window.postMessage`](https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage) API. This message MUST be sent with a payload object containing a `type` property with a value of ETHEREUM_PROVIDER_REQUEST and an optional `id` property corresponding to an identifier of a specific wallet provider, such as "METAMASK". -#### `[2] NOTIFY` +#### `[2] INJECT` -Ethereum-enabled DOM environments MUST notify dapps of successful provider API exposure by sending a message using the [`window.postMessage`](https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage) API. This message MUST be sent with a payload object containing a `type` property with a value of `ETHEREUM_PROVIDER_SUCCESS` and an `ethereum` property containing an Ethereum provider object that conforms to [ethereum/interfaces#16](https://github.com/ethereum/interfaces/issues/16). +Ethereum-enabled DOM environments MUST expose an Ethereum provider API as a global `ETHEREUM_PROVIDER` variable on the `window` object. -#### `[3] NOOP` +#### `[3] NOTIFY` + +Ethereum-enabled DOM environments MUST notify dapps of successful provider API exposure by sending a message using the [`window.postMessage`](https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage) API. This message MUST be sent with a payload object containing a `type` property with a value of ETHEREUM_PROVIDER_SUCCESS" and an optional `id` property corresponding to an identifier of a specific wallet provider, such as "METAMASK" + +#### `[4] NOOP` If a user rejects access to the Ethereum provider API on an untrusted site, the site itself MUST NOT be notified in any way; notification of a rejection would allow third-party tools to still identify that a client is Ethereum-enabled despite not being granted access to any provider API. @@ -61,12 +66,12 @@ If a user rejects access to the Ethereum provider API on an untrusted site, the The following example demonstrates one possible implementation of this strategy in a browser-based DOM environment. Note that Ethereum-enabled environments on other platforms would most likely use platform-specific native messaging protocols, not `postMessage`. ```js -// Listen for provider API +// Listen for provider API exposure window.addEventListener('message', function (event) { if (!event.data || !event.data.type) { return; } if (event.data.type === 'ETHEREUM_PROVIDER_SUCCESS') { // Provider API exposed, continue - const networkVersion = await event.data.ethereum.send('net_version', []); + const networkVersion = await ETHEREUM_PROVIDER.send('net_version', []); console.log(networkVersion); } });