You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+218
Original file line number
Diff line number
Diff line change
@@ -76,3 +76,221 @@ This section has moved here: [https://facebook.github.io/create-react-app/docs/d
76
76
### `npm run build` fails to minify
77
77
78
78
This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
79
+
# Welcome to your organization's demo respository
80
+
This code repository (or "repo") is designed to demonstrate the best GitHub has to offer with the least amount of noise.
81
+
82
+
The repo includes an `index.html` file (so it can render a web page), two GitHub Actions workflows, and a CSS stylesheet dependency.
83
+
# This workflow uses actions that are not certified by GitHub.
84
+
# They are provided by a third-party and are governed by
85
+
# separate terms of service, privacy policy, and support
86
+
# documentation.
87
+
88
+
# This workflow lets you generate SLSA provenance file for your project.
89
+
# The generation satisfies level 3 for the provenance requirements - see https://slsa.dev/spec/v0.1/requirements
90
+
# The project is an initiative of the OpenSSF (openssf.org) and is developed at
upload-assets: true # Optional: Upload to a new release
149
+
150
+
# polkadot{.js} extension
151
+
152
+
A very simple scaffolding browser extension that injects a [@polkadot/api](https://github.com/polkadot-js/api) Signer into a page, along with any associated accounts, allowing for use by any dapp. This is an extensible POC implementation of a Polkadot/Substrate browser signer.
153
+
154
+
As it stands, it does one thing: it _only_ manages accounts and allows the signing of transactions with those accounts. It does not inject providers for use by dapps at this early point, nor does it perform wallet functions where it constructs and submits txs to the network.
155
+
156
+
## Installation
157
+
158
+
- On Chrome, install via [Chrome web store](https://chrome.google.com/webstore/detail/polkadot%7Bjs%7D-extension/mopnmbcafieddcagagdcbnhejhlodfdd)
159
+
- On Firefox, install via [Firefox add-ons](https://addons.mozilla.org/en-US/firefox/addon/polkadot-js-extension/)
Find out more about how to use the extension as a Dapp developper, cookbook, as well as answers to most frequent questions in the [Polkadot-js extension documentation](https://polkadot.js.org/docs/extension/)
165
+
166
+
## Development version
167
+
168
+
Steps to build the extension and view your changes in a browser:
169
+
170
+
1. Build via `yarn build`
171
+
2. Install the extension
172
+
- Chrome:
173
+
- go to `chrome://extensions/`
174
+
- ensure you have the Development flag set
175
+
- "Load unpacked" and point to `packages/extension/build`
176
+
- if developing, after making changes - refresh the extension
177
+
- Firefox:
178
+
- go to `about:debugging#addons`
179
+
- check "Enable add-on debugging"
180
+
- click on "Load Temporary Add-on" and point to `packages/extension/build/manifest.json`
181
+
- if developing, after making changes - reload the extension
182
+
3. When visiting `https://polkadot.js.org/apps/` it will inject the extension
183
+
184
+
Once added, you can create an account (via a generated seed) or import via an existing seed. The [apps UI](https://github.com/polkadot-js/apps/), when loaded, will show these accounts as ` (extension)`
185
+
186
+
## Development
187
+
188
+
The repo is split into a number of packages -
189
+
190
+
-[extension](packages/extension/) - All the injection and background processing logic (the main entry)
191
+
-[extension-ui](packages/extension-ui/) - The UI components for the extension, to build up the popup
192
+
-[extension-dapp](packages/extension-dapp/) - A convenience wrapper to work with the injected objects, simplifying data extraction for any dapp that wishes to integrate the extension (or any extension that supports the interface)
193
+
-[extension-inject](packages/extension-inject/) - A convenience wrapper that allows extension developers to inject their extension for use by any dapp
194
+
195
+
## Dapp developers
196
+
197
+
The actual in-depth technical breakdown is given in the next section for any dapp developer wishing to work with the raw objects injected into the window. However, convenience wrappers are provided that allows for any dapp to use this extension (or any other extension that conforms to the interface) without having to manage any additional info.
198
+
199
+
The documentation for Dapp development is available [in the polkadot-js doc](https://polkadot.js.org/docs/extension).
200
+
201
+
This approach is used to support multiple external signers in for instance [apps](https://github.com/polkadot-js/apps/). You can read more about the convenience wrapper [@polkadot/extension-dapp](packages/extension-dapp/) along with usage samples.
202
+
203
+
## API interface
204
+
205
+
The extension injection interfaces are generic, i.e. it is designed to allow any extension developer to easily inject extensions (that conforms to a specific interface) and at the same time, it allows for any dapp developer to easily enable the interfaces from multiple extensions at the same time. It is not an all-or-nothing approach, but rather it is an ecosystem where the user can choose which extensions fit their style best.
206
+
207
+
From a dapp developer perspective, the only work needed is to include the [@polkadot/extension-dapp](packages/extension-dapp/) package and call the appropriate enabling function to retrieve all the extensions and their associated interfaces.
208
+
209
+
From an extension developer perspective, the only work required is to enable the extension via the razor-thin [@polkadot/extension-inject](packages/extension-inject/) wrapper. Any dapp using the above interfaces will have access to the extension via this interface.
210
+
211
+
When there is more than one extension, each will populate an entry via the injection interface and each will be made available to the dapp. The `Injected` interface, as returned via `enable`, contains the following information for any compliant extension -
212
+
213
+
```js
214
+
interface Injected {
215
+
// the interface for Accounts, as detailed below
216
+
readonly accounts: Accounts;
217
+
// the standard Signer interface for the API, as detailed below
218
+
readonly signer: Signer;
219
+
// not injected as of yet, subscribable provider for polkadot-js API injection,
220
+
// this can be passed to the API itself upon construction in the dapp
221
+
// readonly provider?: Provider
222
+
}
223
+
224
+
interface Account = {
225
+
// ss-58 encoded address
226
+
readonly address: string;
227
+
// the genesisHash for this account (empty if applicable to all)
228
+
readonly genesisHash?: string;
229
+
// (optional) name for display
230
+
readonly name?: string;
231
+
};
232
+
233
+
// exposes accounts
234
+
interface Accounts {
235
+
// retrieves the list of accounts for right now
236
+
get: () => Promise;
237
+
// (optional) subscribe to all accounts, updating as they change
// a signer that communicates with the extension via sendMessage
242
+
interface Signer extends SignerInterface {
243
+
// no specific signer extensions, exposes the `sign` interface for use by
244
+
// the polkadot-js API, confirming the Signer interface for this API
245
+
}
246
+
```
247
+
248
+
## Injection information
249
+
250
+
The information contained in this section may change and evolve. It is therefore recommended that all access is done via the [@polkadot/extension-dapp](packages/extension-dapp/) (for dapps) and [extension-inject](packages/extension-inject/) (for extensions) packages, which removes the need to work with the lower-level targets.
251
+
252
+
The extension injects `injectedWeb3` into the global `window` object, exposing the following: (This is meant to be generic across extensions, allowing any dapp to utilize multiple signers, and pull accounts from multiples, as they are available.)
253
+
254
+
```js
255
+
window.injectedWeb3= {
256
+
// this is the name for this extension, there could be multiples injected,
257
+
// each with their own keys, here `polkadot-js` is for this extension
258
+
'polkadot-js': {
259
+
// semver for the package
260
+
version:'0.1.0',
261
+
262
+
// this is called to enable the injection, and returns an injected
263
+
// object containing the accounts, signer and provider interfaces
264
+
// (or it will reject if not authorized)
265
+
enable (originName: string):Promise
266
+
}
267
+
}
268
+
```
269
+
270
+
## Mnemonics, Passwords, and Imports/Exports
271
+
272
+
### Using the mnemonic and password from the extension
273
+
274
+
When you create a keypair via the extension, it supplies a 12-word mnemonic seed and asks you to create a password. This password only encrypts the private key on disk so that the password is required to spend funds in `polkadot-js/apps` or to import the account from backup. The password does not protect the mnemonic phrase. That is, if an attacker were to acquire the mnemonic phrase, they would be able to use it to spend funds without the password.
275
+
276
+
### Importing mnemonics from other key generation utilities
277
+
278
+
Some key-generation tools, e.g. [Subkey](https://www.substrate.io/kb/integrate/subkey), support hard and soft key derivation as well as passwords that encrypt the mnemonic phrase such that the mnemonic phrase itself is insufficient to spend funds.
279
+
280
+
The extension supports these advanced features. When you import an account from a seed, you can add these derivation paths or password to the end of the mnemonic in the following format:
281
+
282
+
```
283
+
//////
284
+
```
285
+
286
+
That is, hard-derivation paths are prefixed with `//`, soft paths with `/`, and the password with `///`.
287
+
288
+
The extension will still ask you to enter a password for this account. As before, this password only encrypts the private key on disk. It is not required to be the same password as the one that encrypts the mnemonic phrase.
289
+
290
+
Accounts can also be derived from existing accounts – `Derive New Account` option in account's dropdown menu should be selected. After providing the password of the parent account, along with name and password of the derived account, enter derivation path in the following format:
291
+
292
+
```
293
+
///
294
+
```
295
+
296
+
The path will be added to the mnemonic phrase of the parent account.
0 commit comments