@pezkuwi/extension-dapp 0.62.6

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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # @polkadot/extension-dapp
2
+
3
+ Documentation available [in the pezkuwi doc](https://polkadot.js.org/docs/extension).
@@ -0,0 +1,205 @@
1
+ (function (global, factory) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@polkadot/util'), require('@polkadot/util-crypto')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', '@polkadot/util', '@polkadot/util-crypto'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.polkadotExtensionDapp = {}, global.polkadotUtil, global.polkadotUtilCrypto));
5
+ })(this, (function (exports, util, utilCrypto) { 'use strict';
6
+
7
+ const global = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : window;
8
+
9
+ var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
10
+ function documentReadyPromise(creator) {
11
+ return new Promise((resolve) => {
12
+ if (document.readyState === 'complete') {
13
+ resolve(creator());
14
+ }
15
+ else {
16
+ window.addEventListener('load', () => resolve(creator()));
17
+ }
18
+ });
19
+ }
20
+
21
+ const packageInfo = { name: '@polkadot/extension-dapp', path: (({ url: (typeof document === 'undefined' && typeof location === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : typeof document === 'undefined' ? location.href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('bundle-polkadot-extension-dapp.js', document.baseURI).href)) }) && (typeof document === 'undefined' && typeof location === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : typeof document === 'undefined' ? location.href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('bundle-polkadot-extension-dapp.js', document.baseURI).href))) ? new URL((typeof document === 'undefined' && typeof location === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : typeof document === 'undefined' ? location.href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('bundle-polkadot-extension-dapp.js', document.baseURI).href))).pathname.substring(0, new URL((typeof document === 'undefined' && typeof location === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : typeof document === 'undefined' ? location.href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('bundle-polkadot-extension-dapp.js', document.baseURI).href))).pathname.lastIndexOf('/') + 1) : 'auto', type: 'esm', version: '0.62.6' };
22
+
23
+ const unwrapBytes = util.u8aUnwrapBytes;
24
+ const wrapBytes = util.u8aWrapBytes;
25
+
26
+ const win = window;
27
+ win.injectedWeb3 = win.injectedWeb3 || {};
28
+ exports.isWeb3Injected = web3IsInjected();
29
+ exports.web3EnablePromise = null;
30
+ function web3IsInjected() {
31
+ return Object
32
+ .values(win.injectedWeb3)
33
+ .filter(({ connect, enable }) => !!(connect || enable))
34
+ .length !== 0;
35
+ }
36
+ function throwError(method) {
37
+ throw new Error(`${method}: web3Enable(originName) needs to be called before ${method}`);
38
+ }
39
+ function mapAccounts(source, list, ss58Format) {
40
+ return list.map(({ address, genesisHash, name, type }) => ({
41
+ address: address.length === 42
42
+ ? address
43
+ : utilCrypto.encodeAddress(utilCrypto.decodeAddress(address), ss58Format),
44
+ meta: { genesisHash, name, source },
45
+ type
46
+ }));
47
+ }
48
+ function filterAccounts(list, genesisHash, type) {
49
+ return list.filter((a) => (!a.type || !type || type.includes(a.type)) &&
50
+ (!a.genesisHash || !genesisHash || a.genesisHash === genesisHash));
51
+ }
52
+ function getWindowExtensions(originName) {
53
+ return Promise
54
+ .all(Object
55
+ .entries(win.injectedWeb3)
56
+ .map(([nameOrHash, { connect, enable, version }]) => Promise
57
+ .resolve()
58
+ .then(() => connect
59
+ ? connect(originName)
60
+ : enable
61
+ ? enable(originName).then((e) => util.objectSpread({ name: nameOrHash, version: version || 'unknown' }, e))
62
+ : Promise.reject(new Error('No connect(..) or enable(...) hook found')))
63
+ .catch(({ message }) => {
64
+ console.error(`Error initializing ${nameOrHash}: ${message}`);
65
+ })))
66
+ .then((exts) => exts.filter((e) => !!e));
67
+ }
68
+ async function filterEnable(caller, extensions) {
69
+ if (!exports.web3EnablePromise) {
70
+ return throwError(caller);
71
+ }
72
+ const sources = await exports.web3EnablePromise;
73
+ return sources.filter(({ name }) => !extensions ||
74
+ extensions.includes(name));
75
+ }
76
+ function web3Enable(originName, compatInits = []) {
77
+ if (!originName) {
78
+ throw new Error('You must pass a name for your app to the web3Enable function');
79
+ }
80
+ const initCompat = compatInits.length
81
+ ? Promise.all(compatInits.map((c) => c().catch(() => false)))
82
+ : Promise.resolve([true]);
83
+ exports.web3EnablePromise = documentReadyPromise(() => initCompat.then(() => getWindowExtensions(originName)
84
+ .then((values) => values.map((e) => {
85
+ if (!e.accounts.subscribe) {
86
+ e.accounts.subscribe = (cb) => {
87
+ e.accounts
88
+ .get()
89
+ .then(cb)
90
+ .catch(console.error);
91
+ return () => {
92
+ };
93
+ };
94
+ }
95
+ return e;
96
+ }))
97
+ .catch(() => [])
98
+ .then((values) => {
99
+ const names = values.map(({ name, version }) => `${name}/${version}`);
100
+ exports.isWeb3Injected = web3IsInjected();
101
+ console.info(`web3Enable: Enabled ${values.length} extension${values.length !== 1 ? 's' : ''}: ${names.join(', ')}`);
102
+ return values;
103
+ })));
104
+ return exports.web3EnablePromise;
105
+ }
106
+ async function web3Accounts({ accountType, extensions, genesisHash, ss58Format } = {}) {
107
+ const accounts = [];
108
+ const sources = await filterEnable('web3Accounts', extensions);
109
+ const retrieved = await Promise.all(sources.map(async ({ accounts, name: source }) => {
110
+ try {
111
+ const list = await accounts.get();
112
+ return mapAccounts(source, filterAccounts(list, genesisHash, accountType), ss58Format);
113
+ }
114
+ catch {
115
+ return [];
116
+ }
117
+ }));
118
+ retrieved.forEach((result) => {
119
+ accounts.push(...result);
120
+ });
121
+ console.info(`web3Accounts: Found ${accounts.length} address${accounts.length !== 1 ? 'es' : ''}`);
122
+ return accounts;
123
+ }
124
+ async function web3AccountsSubscribe(cb, { accountType, extensions, genesisHash, ss58Format } = {}) {
125
+ const sources = await filterEnable('web3AccountsSubscribe', extensions);
126
+ const accounts = {};
127
+ const triggerUpdate = () => cb(Object
128
+ .entries(accounts)
129
+ .reduce((result, [source, list]) => {
130
+ result.push(...mapAccounts(source, filterAccounts(list, genesisHash, accountType), ss58Format));
131
+ return result;
132
+ }, []));
133
+ const unsubs = sources.map(({ accounts: { subscribe }, name: source }) => subscribe((result) => {
134
+ accounts[source] = result;
135
+ try {
136
+ const result = triggerUpdate();
137
+ if (result && util.isPromise(result)) {
138
+ result.catch(console.error);
139
+ }
140
+ }
141
+ catch (error) {
142
+ console.error(error);
143
+ }
144
+ }));
145
+ return () => {
146
+ unsubs.forEach((unsub) => {
147
+ unsub();
148
+ });
149
+ };
150
+ }
151
+ async function web3FromSource(source) {
152
+ if (!exports.web3EnablePromise) {
153
+ return throwError('web3FromSource');
154
+ }
155
+ const sources = await exports.web3EnablePromise;
156
+ const found = source && sources.find(({ name }) => name === source);
157
+ if (!found) {
158
+ throw new Error(`web3FromSource: Unable to find an injected ${source}`);
159
+ }
160
+ return found;
161
+ }
162
+ async function web3FromAddress(address) {
163
+ if (!exports.web3EnablePromise) {
164
+ return throwError('web3FromAddress');
165
+ }
166
+ const accounts = await web3Accounts();
167
+ let found;
168
+ if (address) {
169
+ const accountU8a = utilCrypto.decodeAddress(address);
170
+ found = accounts.find((account) => util.u8aEq(utilCrypto.decodeAddress(account.address), accountU8a));
171
+ }
172
+ if (!found) {
173
+ throw new Error(`web3FromAddress: Unable to find injected ${address}`);
174
+ }
175
+ return web3FromSource(found.meta.source);
176
+ }
177
+ async function web3ListRpcProviders(source) {
178
+ const { provider } = await web3FromSource(source);
179
+ if (!provider) {
180
+ console.warn(`Extension ${source} does not expose any provider`);
181
+ return null;
182
+ }
183
+ return provider.listProviders();
184
+ }
185
+ async function web3UseRpcProvider(source, key) {
186
+ const { provider } = await web3FromSource(source);
187
+ if (!provider) {
188
+ throw new Error(`Extension ${source} does not expose any provider`);
189
+ }
190
+ const meta = await provider.startProvider(key);
191
+ return { meta, provider };
192
+ }
193
+
194
+ exports.packageInfo = packageInfo;
195
+ exports.unwrapBytes = unwrapBytes;
196
+ exports.web3Accounts = web3Accounts;
197
+ exports.web3AccountsSubscribe = web3AccountsSubscribe;
198
+ exports.web3Enable = web3Enable;
199
+ exports.web3FromAddress = web3FromAddress;
200
+ exports.web3FromSource = web3FromSource;
201
+ exports.web3ListRpcProviders = web3ListRpcProviders;
202
+ exports.web3UseRpcProvider = web3UseRpcProvider;
203
+ exports.wrapBytes = wrapBytes;
204
+
205
+ }));
package/bundle.d.ts ADDED
@@ -0,0 +1,61 @@
1
+ import type { InjectedAccountWithMeta, InjectedExtension, InjectedProviderWithMeta, ProviderList, Unsubcall, Web3AccountsOptions } from '@polkadot/extension-inject/types';
2
+ export { packageInfo } from './packageInfo.js';
3
+ export { unwrapBytes, wrapBytes } from './wrapBytes.js';
4
+ declare let isWeb3Injected: boolean;
5
+ declare let web3EnablePromise: Promise<InjectedExtension[]> | null;
6
+ export { isWeb3Injected, web3EnablePromise };
7
+ /**
8
+ * @summary Enables all the providers found on the injected window interface
9
+ * @description
10
+ * Enables all injected extensions that has been found on the page. This
11
+ * should be called before making use of any other web3* functions.
12
+ */
13
+ export declare function web3Enable(originName: string, compatInits?: (() => Promise<boolean>)[]): Promise<InjectedExtension[]>;
14
+ /**
15
+ * @summary Retrieves all the accounts across all providers
16
+ * @description
17
+ * This returns the full list of account available (across all extensions) to
18
+ * the page. Filtering options are available of a per-extension, per type and
19
+ * per-genesisHash basis. Optionally the accounts can be encoded with the provided
20
+ * ss58Format
21
+ */
22
+ export declare function web3Accounts({ accountType, extensions, genesisHash, ss58Format }?: Web3AccountsOptions): Promise<InjectedAccountWithMeta[]>;
23
+ /**
24
+ * @summary Subscribes to all the accounts across all providers
25
+ * @description
26
+ * This is the subscription version of the web3Accounts interface with
27
+ * updates as to when new accounts do become available. The list of filtering
28
+ * options are the same as for the web3Accounts interface.
29
+ */
30
+ export declare function web3AccountsSubscribe(cb: (accounts: InjectedAccountWithMeta[]) => void | Promise<void>, { accountType, extensions, genesisHash, ss58Format }?: Web3AccountsOptions): Promise<Unsubcall>;
31
+ /**
32
+ * @summary Finds a specific provider based on the name
33
+ * @description
34
+ * This retrieves a specific source (extension) based on the name. In most
35
+ * cases it should not be needed to call it directly (e.g. it is used internally
36
+ * by calls such as web3FromAddress) but would allow operation on a specific
37
+ * known extension.
38
+ */
39
+ export declare function web3FromSource(source: string): Promise<InjectedExtension>;
40
+ /**
41
+ * @summary Find a specific provider that provides a specific address
42
+ * @description
43
+ * Based on an address, return the provider that has makes this address
44
+ * available to the page.
45
+ */
46
+ export declare function web3FromAddress(address: string): Promise<InjectedExtension>;
47
+ /**
48
+ * @summary List all providers exposed by one source
49
+ * @description
50
+ * For extensions that supply RPC providers, this call would return the list
51
+ * of RPC providers that any extension may supply.
52
+ */
53
+ export declare function web3ListRpcProviders(source: string): Promise<ProviderList | null>;
54
+ /**
55
+ * @summary Start an RPC provider provider by a specific source
56
+ * @description
57
+ * For extensions that supply RPC providers, this call would return an
58
+ * enabled provider (initialized with the specific key) from the
59
+ * specified extension source.
60
+ */
61
+ export declare function web3UseRpcProvider(source: string, key: string): Promise<InjectedProviderWithMeta>;
package/bundle.js ADDED
@@ -0,0 +1,232 @@
1
+ import { isPromise, objectSpread, u8aEq } from '@polkadot/util';
2
+ import { decodeAddress, encodeAddress } from '@polkadot/util-crypto';
3
+ import { documentReadyPromise } from './util.js';
4
+ export { packageInfo } from './packageInfo.js';
5
+ export { unwrapBytes, wrapBytes } from './wrapBytes.js';
6
+ const win = window;
7
+ win.injectedWeb3 = win.injectedWeb3 || {};
8
+ let isWeb3Injected = web3IsInjected();
9
+ let web3EnablePromise = null;
10
+ export { isWeb3Injected, web3EnablePromise };
11
+ /** @internal true when anything has been injected and is available */
12
+ function web3IsInjected() {
13
+ return Object
14
+ .values(win.injectedWeb3)
15
+ .filter(({ connect, enable }) => !!(connect || enable))
16
+ .length !== 0;
17
+ }
18
+ /** @internal throw a consistent error when not extensions have not been enabled */
19
+ function throwError(method) {
20
+ throw new Error(`${method}: web3Enable(originName) needs to be called before ${method}`);
21
+ }
22
+ /** @internal map from Array<InjectedAccount> to Array<InjectedAccountWithMeta> */
23
+ function mapAccounts(source, list, ss58Format) {
24
+ return list.map(({ address, genesisHash, name, type }) => ({
25
+ address: address.length === 42
26
+ ? address
27
+ : encodeAddress(decodeAddress(address), ss58Format),
28
+ meta: { genesisHash, name, source },
29
+ type
30
+ }));
31
+ }
32
+ /** @internal filter accounts based on genesisHash and type of account */
33
+ function filterAccounts(list, genesisHash, type) {
34
+ return list.filter((a) => (!a.type || !type || type.includes(a.type)) &&
35
+ (!a.genesisHash || !genesisHash || a.genesisHash === genesisHash));
36
+ }
37
+ /** @internal retrieves all the extensions available on the window */
38
+ function getWindowExtensions(originName) {
39
+ return Promise
40
+ .all(Object
41
+ .entries(win.injectedWeb3)
42
+ .map(([nameOrHash, { connect, enable, version }]) => Promise
43
+ .resolve()
44
+ .then(() => connect
45
+ // new style, returning all info
46
+ ? connect(originName)
47
+ : enable
48
+ // previous interface, leakages on name/version
49
+ ? enable(originName).then((e) => objectSpread({ name: nameOrHash, version: version || 'unknown' }, e))
50
+ : Promise.reject(new Error('No connect(..) or enable(...) hook found')))
51
+ .catch(({ message }) => {
52
+ console.error(`Error initializing ${nameOrHash}: ${message}`);
53
+ })))
54
+ .then((exts) => exts.filter((e) => !!e));
55
+ }
56
+ /** @internal Ensure the enable promise is resolved and filter by extensions */
57
+ async function filterEnable(caller, extensions) {
58
+ if (!web3EnablePromise) {
59
+ return throwError(caller);
60
+ }
61
+ const sources = await web3EnablePromise;
62
+ return sources.filter(({ name }) => !extensions ||
63
+ extensions.includes(name));
64
+ }
65
+ /**
66
+ * @summary Enables all the providers found on the injected window interface
67
+ * @description
68
+ * Enables all injected extensions that has been found on the page. This
69
+ * should be called before making use of any other web3* functions.
70
+ */
71
+ export function web3Enable(originName, compatInits = []) {
72
+ if (!originName) {
73
+ throw new Error('You must pass a name for your app to the web3Enable function');
74
+ }
75
+ const initCompat = compatInits.length
76
+ ? Promise.all(compatInits.map((c) => c().catch(() => false)))
77
+ : Promise.resolve([true]);
78
+ web3EnablePromise = documentReadyPromise(() => initCompat.then(() => getWindowExtensions(originName)
79
+ .then((values) => values.map((e) => {
80
+ // if we don't have an accounts subscriber, add a single-shot version
81
+ if (!e.accounts.subscribe) {
82
+ e.accounts.subscribe = (cb) => {
83
+ e.accounts
84
+ .get()
85
+ .then(cb)
86
+ .catch(console.error);
87
+ return () => {
88
+ // no ubsubscribe needed, this is a single-shot
89
+ };
90
+ };
91
+ }
92
+ return e;
93
+ }))
94
+ .catch(() => [])
95
+ .then((values) => {
96
+ const names = values.map(({ name, version }) => `${name}/${version}`);
97
+ isWeb3Injected = web3IsInjected();
98
+ console.info(`web3Enable: Enabled ${values.length} extension${values.length !== 1 ? 's' : ''}: ${names.join(', ')}`);
99
+ return values;
100
+ })));
101
+ return web3EnablePromise;
102
+ }
103
+ /**
104
+ * @summary Retrieves all the accounts across all providers
105
+ * @description
106
+ * This returns the full list of account available (across all extensions) to
107
+ * the page. Filtering options are available of a per-extension, per type and
108
+ * per-genesisHash basis. Optionally the accounts can be encoded with the provided
109
+ * ss58Format
110
+ */
111
+ export async function web3Accounts({ accountType, extensions, genesisHash, ss58Format } = {}) {
112
+ const accounts = [];
113
+ const sources = await filterEnable('web3Accounts', extensions);
114
+ const retrieved = await Promise.all(sources.map(async ({ accounts, name: source }) => {
115
+ try {
116
+ const list = await accounts.get();
117
+ return mapAccounts(source, filterAccounts(list, genesisHash, accountType), ss58Format);
118
+ }
119
+ catch {
120
+ // cannot handle this one
121
+ return [];
122
+ }
123
+ }));
124
+ retrieved.forEach((result) => {
125
+ accounts.push(...result);
126
+ });
127
+ console.info(`web3Accounts: Found ${accounts.length} address${accounts.length !== 1 ? 'es' : ''}`);
128
+ return accounts;
129
+ }
130
+ /**
131
+ * @summary Subscribes to all the accounts across all providers
132
+ * @description
133
+ * This is the subscription version of the web3Accounts interface with
134
+ * updates as to when new accounts do become available. The list of filtering
135
+ * options are the same as for the web3Accounts interface.
136
+ */
137
+ export async function web3AccountsSubscribe(cb, { accountType, extensions, genesisHash, ss58Format } = {}) {
138
+ const sources = await filterEnable('web3AccountsSubscribe', extensions);
139
+ const accounts = {};
140
+ const triggerUpdate = () => cb(Object
141
+ .entries(accounts)
142
+ .reduce((result, [source, list]) => {
143
+ result.push(...mapAccounts(source, filterAccounts(list, genesisHash, accountType), ss58Format));
144
+ return result;
145
+ }, []));
146
+ const unsubs = sources.map(({ accounts: { subscribe }, name: source }) => subscribe((result) => {
147
+ accounts[source] = result;
148
+ try {
149
+ const result = triggerUpdate();
150
+ if (result && isPromise(result)) {
151
+ result.catch(console.error);
152
+ }
153
+ }
154
+ catch (error) {
155
+ console.error(error);
156
+ }
157
+ }));
158
+ return () => {
159
+ unsubs.forEach((unsub) => {
160
+ unsub();
161
+ });
162
+ };
163
+ }
164
+ /**
165
+ * @summary Finds a specific provider based on the name
166
+ * @description
167
+ * This retrieves a specific source (extension) based on the name. In most
168
+ * cases it should not be needed to call it directly (e.g. it is used internally
169
+ * by calls such as web3FromAddress) but would allow operation on a specific
170
+ * known extension.
171
+ */
172
+ export async function web3FromSource(source) {
173
+ if (!web3EnablePromise) {
174
+ return throwError('web3FromSource');
175
+ }
176
+ const sources = await web3EnablePromise;
177
+ const found = source && sources.find(({ name }) => name === source);
178
+ if (!found) {
179
+ throw new Error(`web3FromSource: Unable to find an injected ${source}`);
180
+ }
181
+ return found;
182
+ }
183
+ /**
184
+ * @summary Find a specific provider that provides a specific address
185
+ * @description
186
+ * Based on an address, return the provider that has makes this address
187
+ * available to the page.
188
+ */
189
+ export async function web3FromAddress(address) {
190
+ if (!web3EnablePromise) {
191
+ return throwError('web3FromAddress');
192
+ }
193
+ const accounts = await web3Accounts();
194
+ let found;
195
+ if (address) {
196
+ const accountU8a = decodeAddress(address);
197
+ found = accounts.find((account) => u8aEq(decodeAddress(account.address), accountU8a));
198
+ }
199
+ if (!found) {
200
+ throw new Error(`web3FromAddress: Unable to find injected ${address}`);
201
+ }
202
+ return web3FromSource(found.meta.source);
203
+ }
204
+ /**
205
+ * @summary List all providers exposed by one source
206
+ * @description
207
+ * For extensions that supply RPC providers, this call would return the list
208
+ * of RPC providers that any extension may supply.
209
+ */
210
+ export async function web3ListRpcProviders(source) {
211
+ const { provider } = await web3FromSource(source);
212
+ if (!provider) {
213
+ console.warn(`Extension ${source} does not expose any provider`);
214
+ return null;
215
+ }
216
+ return provider.listProviders();
217
+ }
218
+ /**
219
+ * @summary Start an RPC provider provider by a specific source
220
+ * @description
221
+ * For extensions that supply RPC providers, this call would return an
222
+ * enabled provider (initialized with the specific key) from the
223
+ * specified extension source.
224
+ */
225
+ export async function web3UseRpcProvider(source, key) {
226
+ const { provider } = await web3FromSource(source);
227
+ if (!provider) {
228
+ throw new Error(`Extension ${source} does not expose any provider`);
229
+ }
230
+ const meta = await provider.startProvider(key);
231
+ return { meta, provider };
232
+ }
@@ -0,0 +1,61 @@
1
+ import type { InjectedAccountWithMeta, InjectedExtension, InjectedProviderWithMeta, ProviderList, Unsubcall, Web3AccountsOptions } from '@polkadot/extension-inject/types';
2
+ export { packageInfo } from './packageInfo.js';
3
+ export { unwrapBytes, wrapBytes } from './wrapBytes.js';
4
+ declare let isWeb3Injected: boolean;
5
+ declare let web3EnablePromise: Promise<InjectedExtension[]> | null;
6
+ export { isWeb3Injected, web3EnablePromise };
7
+ /**
8
+ * @summary Enables all the providers found on the injected window interface
9
+ * @description
10
+ * Enables all injected extensions that has been found on the page. This
11
+ * should be called before making use of any other web3* functions.
12
+ */
13
+ export declare function web3Enable(originName: string, compatInits?: (() => Promise<boolean>)[]): Promise<InjectedExtension[]>;
14
+ /**
15
+ * @summary Retrieves all the accounts across all providers
16
+ * @description
17
+ * This returns the full list of account available (across all extensions) to
18
+ * the page. Filtering options are available of a per-extension, per type and
19
+ * per-genesisHash basis. Optionally the accounts can be encoded with the provided
20
+ * ss58Format
21
+ */
22
+ export declare function web3Accounts({ accountType, extensions, genesisHash, ss58Format }?: Web3AccountsOptions): Promise<InjectedAccountWithMeta[]>;
23
+ /**
24
+ * @summary Subscribes to all the accounts across all providers
25
+ * @description
26
+ * This is the subscription version of the web3Accounts interface with
27
+ * updates as to when new accounts do become available. The list of filtering
28
+ * options are the same as for the web3Accounts interface.
29
+ */
30
+ export declare function web3AccountsSubscribe(cb: (accounts: InjectedAccountWithMeta[]) => void | Promise<void>, { accountType, extensions, genesisHash, ss58Format }?: Web3AccountsOptions): Promise<Unsubcall>;
31
+ /**
32
+ * @summary Finds a specific provider based on the name
33
+ * @description
34
+ * This retrieves a specific source (extension) based on the name. In most
35
+ * cases it should not be needed to call it directly (e.g. it is used internally
36
+ * by calls such as web3FromAddress) but would allow operation on a specific
37
+ * known extension.
38
+ */
39
+ export declare function web3FromSource(source: string): Promise<InjectedExtension>;
40
+ /**
41
+ * @summary Find a specific provider that provides a specific address
42
+ * @description
43
+ * Based on an address, return the provider that has makes this address
44
+ * available to the page.
45
+ */
46
+ export declare function web3FromAddress(address: string): Promise<InjectedExtension>;
47
+ /**
48
+ * @summary List all providers exposed by one source
49
+ * @description
50
+ * For extensions that supply RPC providers, this call would return the list
51
+ * of RPC providers that any extension may supply.
52
+ */
53
+ export declare function web3ListRpcProviders(source: string): Promise<ProviderList | null>;
54
+ /**
55
+ * @summary Start an RPC provider provider by a specific source
56
+ * @description
57
+ * For extensions that supply RPC providers, this call would return an
58
+ * enabled provider (initialized with the specific key) from the
59
+ * specified extension source.
60
+ */
61
+ export declare function web3UseRpcProvider(source: string, key: string): Promise<InjectedProviderWithMeta>;
package/cjs/bundle.js ADDED
@@ -0,0 +1,246 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.web3EnablePromise = exports.isWeb3Injected = exports.wrapBytes = exports.unwrapBytes = exports.packageInfo = void 0;
4
+ exports.web3Enable = web3Enable;
5
+ exports.web3Accounts = web3Accounts;
6
+ exports.web3AccountsSubscribe = web3AccountsSubscribe;
7
+ exports.web3FromSource = web3FromSource;
8
+ exports.web3FromAddress = web3FromAddress;
9
+ exports.web3ListRpcProviders = web3ListRpcProviders;
10
+ exports.web3UseRpcProvider = web3UseRpcProvider;
11
+ const util_1 = require("@polkadot/util");
12
+ const util_crypto_1 = require("@polkadot/util-crypto");
13
+ const util_js_1 = require("./util.js");
14
+ var packageInfo_js_1 = require("./packageInfo.js");
15
+ Object.defineProperty(exports, "packageInfo", { enumerable: true, get: function () { return packageInfo_js_1.packageInfo; } });
16
+ var wrapBytes_js_1 = require("./wrapBytes.js");
17
+ Object.defineProperty(exports, "unwrapBytes", { enumerable: true, get: function () { return wrapBytes_js_1.unwrapBytes; } });
18
+ Object.defineProperty(exports, "wrapBytes", { enumerable: true, get: function () { return wrapBytes_js_1.wrapBytes; } });
19
+ const win = window;
20
+ win.injectedWeb3 = win.injectedWeb3 || {};
21
+ let isWeb3Injected = web3IsInjected();
22
+ exports.isWeb3Injected = isWeb3Injected;
23
+ let web3EnablePromise = null;
24
+ exports.web3EnablePromise = web3EnablePromise;
25
+ /** @internal true when anything has been injected and is available */
26
+ function web3IsInjected() {
27
+ return Object
28
+ .values(win.injectedWeb3)
29
+ .filter(({ connect, enable }) => !!(connect || enable))
30
+ .length !== 0;
31
+ }
32
+ /** @internal throw a consistent error when not extensions have not been enabled */
33
+ function throwError(method) {
34
+ throw new Error(`${method}: web3Enable(originName) needs to be called before ${method}`);
35
+ }
36
+ /** @internal map from Array<InjectedAccount> to Array<InjectedAccountWithMeta> */
37
+ function mapAccounts(source, list, ss58Format) {
38
+ return list.map(({ address, genesisHash, name, type }) => ({
39
+ address: address.length === 42
40
+ ? address
41
+ : (0, util_crypto_1.encodeAddress)((0, util_crypto_1.decodeAddress)(address), ss58Format),
42
+ meta: { genesisHash, name, source },
43
+ type
44
+ }));
45
+ }
46
+ /** @internal filter accounts based on genesisHash and type of account */
47
+ function filterAccounts(list, genesisHash, type) {
48
+ return list.filter((a) => (!a.type || !type || type.includes(a.type)) &&
49
+ (!a.genesisHash || !genesisHash || a.genesisHash === genesisHash));
50
+ }
51
+ /** @internal retrieves all the extensions available on the window */
52
+ function getWindowExtensions(originName) {
53
+ return Promise
54
+ .all(Object
55
+ .entries(win.injectedWeb3)
56
+ .map(([nameOrHash, { connect, enable, version }]) => Promise
57
+ .resolve()
58
+ .then(() => connect
59
+ // new style, returning all info
60
+ ? connect(originName)
61
+ : enable
62
+ // previous interface, leakages on name/version
63
+ ? enable(originName).then((e) => (0, util_1.objectSpread)({ name: nameOrHash, version: version || 'unknown' }, e))
64
+ : Promise.reject(new Error('No connect(..) or enable(...) hook found')))
65
+ .catch(({ message }) => {
66
+ console.error(`Error initializing ${nameOrHash}: ${message}`);
67
+ })))
68
+ .then((exts) => exts.filter((e) => !!e));
69
+ }
70
+ /** @internal Ensure the enable promise is resolved and filter by extensions */
71
+ async function filterEnable(caller, extensions) {
72
+ if (!web3EnablePromise) {
73
+ return throwError(caller);
74
+ }
75
+ const sources = await web3EnablePromise;
76
+ return sources.filter(({ name }) => !extensions ||
77
+ extensions.includes(name));
78
+ }
79
+ /**
80
+ * @summary Enables all the providers found on the injected window interface
81
+ * @description
82
+ * Enables all injected extensions that has been found on the page. This
83
+ * should be called before making use of any other web3* functions.
84
+ */
85
+ function web3Enable(originName, compatInits = []) {
86
+ if (!originName) {
87
+ throw new Error('You must pass a name for your app to the web3Enable function');
88
+ }
89
+ const initCompat = compatInits.length
90
+ ? Promise.all(compatInits.map((c) => c().catch(() => false)))
91
+ : Promise.resolve([true]);
92
+ exports.web3EnablePromise = web3EnablePromise = (0, util_js_1.documentReadyPromise)(() => initCompat.then(() => getWindowExtensions(originName)
93
+ .then((values) => values.map((e) => {
94
+ // if we don't have an accounts subscriber, add a single-shot version
95
+ if (!e.accounts.subscribe) {
96
+ e.accounts.subscribe = (cb) => {
97
+ e.accounts
98
+ .get()
99
+ .then(cb)
100
+ .catch(console.error);
101
+ return () => {
102
+ // no ubsubscribe needed, this is a single-shot
103
+ };
104
+ };
105
+ }
106
+ return e;
107
+ }))
108
+ .catch(() => [])
109
+ .then((values) => {
110
+ const names = values.map(({ name, version }) => `${name}/${version}`);
111
+ exports.isWeb3Injected = isWeb3Injected = web3IsInjected();
112
+ console.info(`web3Enable: Enabled ${values.length} extension${values.length !== 1 ? 's' : ''}: ${names.join(', ')}`);
113
+ return values;
114
+ })));
115
+ return web3EnablePromise;
116
+ }
117
+ /**
118
+ * @summary Retrieves all the accounts across all providers
119
+ * @description
120
+ * This returns the full list of account available (across all extensions) to
121
+ * the page. Filtering options are available of a per-extension, per type and
122
+ * per-genesisHash basis. Optionally the accounts can be encoded with the provided
123
+ * ss58Format
124
+ */
125
+ async function web3Accounts({ accountType, extensions, genesisHash, ss58Format } = {}) {
126
+ const accounts = [];
127
+ const sources = await filterEnable('web3Accounts', extensions);
128
+ const retrieved = await Promise.all(sources.map(async ({ accounts, name: source }) => {
129
+ try {
130
+ const list = await accounts.get();
131
+ return mapAccounts(source, filterAccounts(list, genesisHash, accountType), ss58Format);
132
+ }
133
+ catch {
134
+ // cannot handle this one
135
+ return [];
136
+ }
137
+ }));
138
+ retrieved.forEach((result) => {
139
+ accounts.push(...result);
140
+ });
141
+ console.info(`web3Accounts: Found ${accounts.length} address${accounts.length !== 1 ? 'es' : ''}`);
142
+ return accounts;
143
+ }
144
+ /**
145
+ * @summary Subscribes to all the accounts across all providers
146
+ * @description
147
+ * This is the subscription version of the web3Accounts interface with
148
+ * updates as to when new accounts do become available. The list of filtering
149
+ * options are the same as for the web3Accounts interface.
150
+ */
151
+ async function web3AccountsSubscribe(cb, { accountType, extensions, genesisHash, ss58Format } = {}) {
152
+ const sources = await filterEnable('web3AccountsSubscribe', extensions);
153
+ const accounts = {};
154
+ const triggerUpdate = () => cb(Object
155
+ .entries(accounts)
156
+ .reduce((result, [source, list]) => {
157
+ result.push(...mapAccounts(source, filterAccounts(list, genesisHash, accountType), ss58Format));
158
+ return result;
159
+ }, []));
160
+ const unsubs = sources.map(({ accounts: { subscribe }, name: source }) => subscribe((result) => {
161
+ accounts[source] = result;
162
+ try {
163
+ const result = triggerUpdate();
164
+ if (result && (0, util_1.isPromise)(result)) {
165
+ result.catch(console.error);
166
+ }
167
+ }
168
+ catch (error) {
169
+ console.error(error);
170
+ }
171
+ }));
172
+ return () => {
173
+ unsubs.forEach((unsub) => {
174
+ unsub();
175
+ });
176
+ };
177
+ }
178
+ /**
179
+ * @summary Finds a specific provider based on the name
180
+ * @description
181
+ * This retrieves a specific source (extension) based on the name. In most
182
+ * cases it should not be needed to call it directly (e.g. it is used internally
183
+ * by calls such as web3FromAddress) but would allow operation on a specific
184
+ * known extension.
185
+ */
186
+ async function web3FromSource(source) {
187
+ if (!web3EnablePromise) {
188
+ return throwError('web3FromSource');
189
+ }
190
+ const sources = await web3EnablePromise;
191
+ const found = source && sources.find(({ name }) => name === source);
192
+ if (!found) {
193
+ throw new Error(`web3FromSource: Unable to find an injected ${source}`);
194
+ }
195
+ return found;
196
+ }
197
+ /**
198
+ * @summary Find a specific provider that provides a specific address
199
+ * @description
200
+ * Based on an address, return the provider that has makes this address
201
+ * available to the page.
202
+ */
203
+ async function web3FromAddress(address) {
204
+ if (!web3EnablePromise) {
205
+ return throwError('web3FromAddress');
206
+ }
207
+ const accounts = await web3Accounts();
208
+ let found;
209
+ if (address) {
210
+ const accountU8a = (0, util_crypto_1.decodeAddress)(address);
211
+ found = accounts.find((account) => (0, util_1.u8aEq)((0, util_crypto_1.decodeAddress)(account.address), accountU8a));
212
+ }
213
+ if (!found) {
214
+ throw new Error(`web3FromAddress: Unable to find injected ${address}`);
215
+ }
216
+ return web3FromSource(found.meta.source);
217
+ }
218
+ /**
219
+ * @summary List all providers exposed by one source
220
+ * @description
221
+ * For extensions that supply RPC providers, this call would return the list
222
+ * of RPC providers that any extension may supply.
223
+ */
224
+ async function web3ListRpcProviders(source) {
225
+ const { provider } = await web3FromSource(source);
226
+ if (!provider) {
227
+ console.warn(`Extension ${source} does not expose any provider`);
228
+ return null;
229
+ }
230
+ return provider.listProviders();
231
+ }
232
+ /**
233
+ * @summary Start an RPC provider provider by a specific source
234
+ * @description
235
+ * For extensions that supply RPC providers, this call would return an
236
+ * enabled provider (initialized with the specific key) from the
237
+ * specified extension source.
238
+ */
239
+ async function web3UseRpcProvider(source, key) {
240
+ const { provider } = await web3FromSource(source);
241
+ if (!provider) {
242
+ throw new Error(`Extension ${source} does not expose any provider`);
243
+ }
244
+ const meta = await provider.startProvider(key);
245
+ return { meta, provider };
246
+ }
package/cjs/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './bundle.js';
package/cjs/index.js ADDED
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./bundle.js"), exports);
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const packageInfo_1 = require("@polkadot/extension-inject/cjs/packageInfo");
4
+ const util_1 = require("@polkadot/util");
5
+ const packageInfo_js_1 = require("./packageInfo.js");
6
+ (0, util_1.detectPackage)(packageInfo_js_1.packageInfo, null, [packageInfo_1.packageInfo]);
@@ -0,0 +1,6 @@
1
+ export declare const packageInfo: {
2
+ name: string;
3
+ path: string;
4
+ type: string;
5
+ version: string;
6
+ };
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.packageInfo = void 0;
4
+ exports.packageInfo = { name: '@polkadot/extension-dapp', path: typeof __dirname === 'string' ? __dirname : 'auto', type: 'cjs', version: '0.62.6' };
package/cjs/util.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare function documentReadyPromise<T>(creator: () => Promise<T>): Promise<T>;
package/cjs/util.js ADDED
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.documentReadyPromise = documentReadyPromise;
4
+ function documentReadyPromise(creator) {
5
+ return new Promise((resolve) => {
6
+ if (document.readyState === 'complete') {
7
+ resolve(creator());
8
+ }
9
+ else {
10
+ window.addEventListener('load', () => resolve(creator()));
11
+ }
12
+ });
13
+ }
@@ -0,0 +1,7 @@
1
+ import { u8aIsWrapped, u8aUnwrapBytes, u8aWrapBytes } from '@polkadot/util';
2
+ export declare const ETHEREUM: Uint8Array<ArrayBufferLike>;
3
+ export declare const POSTFIX: Uint8Array<ArrayBufferLike>;
4
+ export declare const PREFIX: Uint8Array<ArrayBufferLike>;
5
+ export declare const isWrapped: typeof u8aIsWrapped;
6
+ export declare const unwrapBytes: typeof u8aUnwrapBytes;
7
+ export declare const wrapBytes: typeof u8aWrapBytes;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.wrapBytes = exports.unwrapBytes = exports.isWrapped = exports.PREFIX = exports.POSTFIX = exports.ETHEREUM = void 0;
4
+ const util_1 = require("@polkadot/util");
5
+ exports.ETHEREUM = util_1.U8A_WRAP_ETHEREUM;
6
+ exports.POSTFIX = util_1.U8A_WRAP_POSTFIX;
7
+ exports.PREFIX = util_1.U8A_WRAP_PREFIX;
8
+ exports.isWrapped = util_1.u8aIsWrapped;
9
+ exports.unwrapBytes = util_1.u8aUnwrapBytes;
10
+ exports.wrapBytes = util_1.u8aWrapBytes;
package/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './bundle.js';
package/index.js ADDED
@@ -0,0 +1 @@
1
+ export * from './bundle.js';
package/package.json ADDED
@@ -0,0 +1,142 @@
1
+ {
2
+ "author": "Jaco Greeff <jacogr@gmail.com>",
3
+ "bugs": "https://github.com/pezkuwichain/pezkuwi-extension/issues",
4
+ "description": "Provides an interfaces around the injected globals for ease of access by dapp developers.",
5
+ "engines": {
6
+ "node": ">=18"
7
+ },
8
+ "homepage": "https://github.com/pezkuwichain/pezkuwi-extension/tree/master/packages/extension-dapp#readme",
9
+ "license": "Apache-2.0",
10
+ "name": "@pezkuwi/extension-dapp",
11
+ "repository": {
12
+ "directory": "packages/extension-dapp",
13
+ "type": "git",
14
+ "url": "https://github.com/pezkuwichain/pezkuwi-extension.git"
15
+ },
16
+ "sideEffects": [
17
+ "./packageDetect.js",
18
+ "./cjs/packageDetect.js"
19
+ ],
20
+ "type": "module",
21
+ "version": "0.62.6",
22
+ "main": "./cjs/index.js",
23
+ "module": "./index.js",
24
+ "types": "./index.d.ts",
25
+ "exports": {
26
+ "./cjs/package.json": "./cjs/package.json",
27
+ "./cjs/*": "./cjs/*.js",
28
+ ".": {
29
+ "module": {
30
+ "types": "./index.d.ts",
31
+ "default": "./index.js"
32
+ },
33
+ "require": {
34
+ "types": "./cjs/index.d.ts",
35
+ "default": "./cjs/index.js"
36
+ },
37
+ "default": {
38
+ "types": "./index.d.ts",
39
+ "default": "./index.js"
40
+ }
41
+ },
42
+ "./bundle": {
43
+ "module": {
44
+ "types": "./bundle.d.ts",
45
+ "default": "./bundle.js"
46
+ },
47
+ "require": {
48
+ "types": "./cjs/bundle.d.ts",
49
+ "default": "./cjs/bundle.js"
50
+ },
51
+ "default": {
52
+ "types": "./bundle.d.ts",
53
+ "default": "./bundle.js"
54
+ }
55
+ },
56
+ "./package.json": {
57
+ "require": "./cjs/package.json",
58
+ "default": "./package.json"
59
+ },
60
+ "./packageDetect": {
61
+ "module": {
62
+ "types": "./packageDetect.d.ts",
63
+ "default": "./packageDetect.js"
64
+ },
65
+ "require": {
66
+ "types": "./cjs/packageDetect.d.ts",
67
+ "default": "./cjs/packageDetect.js"
68
+ },
69
+ "default": {
70
+ "types": "./packageDetect.d.ts",
71
+ "default": "./packageDetect.js"
72
+ }
73
+ },
74
+ "./packageInfo.js": {
75
+ "module": {
76
+ "types": "./packageInfo.d.ts",
77
+ "default": "./packageInfo.js"
78
+ },
79
+ "require": {
80
+ "types": "./cjs/packageInfo.d.ts",
81
+ "default": "./cjs/packageInfo.js"
82
+ },
83
+ "default": {
84
+ "types": "./packageInfo.d.ts",
85
+ "default": "./packageInfo.js"
86
+ }
87
+ },
88
+ "./packageInfo": {
89
+ "module": {
90
+ "types": "./packageInfo.d.ts",
91
+ "default": "./packageInfo.js"
92
+ },
93
+ "require": {
94
+ "types": "./cjs/packageInfo.d.ts",
95
+ "default": "./cjs/packageInfo.js"
96
+ },
97
+ "default": {
98
+ "types": "./packageInfo.d.ts",
99
+ "default": "./packageInfo.js"
100
+ }
101
+ },
102
+ "./util": {
103
+ "module": {
104
+ "types": "./util.d.ts",
105
+ "default": "./util.js"
106
+ },
107
+ "require": {
108
+ "types": "./cjs/util.d.ts",
109
+ "default": "./cjs/util.js"
110
+ },
111
+ "default": {
112
+ "types": "./util.d.ts",
113
+ "default": "./util.js"
114
+ }
115
+ },
116
+ "./wrapBytes": {
117
+ "module": {
118
+ "types": "./wrapBytes.d.ts",
119
+ "default": "./wrapBytes.js"
120
+ },
121
+ "require": {
122
+ "types": "./cjs/wrapBytes.d.ts",
123
+ "default": "./cjs/wrapBytes.js"
124
+ },
125
+ "default": {
126
+ "types": "./wrapBytes.d.ts",
127
+ "default": "./wrapBytes.js"
128
+ }
129
+ }
130
+ },
131
+ "dependencies": {
132
+ "@pezkuwi/extension-inject": "0.62.6",
133
+ "@pezkuwi/util": "^14.0.5",
134
+ "@pezkuwi/util-crypto": "^14.0.5",
135
+ "tslib": "^2.8.1"
136
+ },
137
+ "peerDependencies": {
138
+ "@pezkuwi/api": "*",
139
+ "@pezkuwi/util": "*",
140
+ "@pezkuwi/util-crypto": "*"
141
+ }
142
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ import { packageInfo as injectInfo } from '@polkadot/extension-inject/packageInfo';
2
+ import { detectPackage } from '@polkadot/util';
3
+ import { packageInfo } from './packageInfo.js';
4
+ detectPackage(packageInfo, null, [injectInfo]);
@@ -0,0 +1,6 @@
1
+ export declare const packageInfo: {
2
+ name: string;
3
+ path: string;
4
+ type: string;
5
+ version: string;
6
+ };
package/packageInfo.js ADDED
@@ -0,0 +1 @@
1
+ export const packageInfo = { name: '@polkadot/extension-dapp', path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto', type: 'esm', version: '0.62.6' };
package/util.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare function documentReadyPromise<T>(creator: () => Promise<T>): Promise<T>;
package/util.js ADDED
@@ -0,0 +1,10 @@
1
+ export function documentReadyPromise(creator) {
2
+ return new Promise((resolve) => {
3
+ if (document.readyState === 'complete') {
4
+ resolve(creator());
5
+ }
6
+ else {
7
+ window.addEventListener('load', () => resolve(creator()));
8
+ }
9
+ });
10
+ }
package/wrapBytes.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ import { u8aIsWrapped, u8aUnwrapBytes, u8aWrapBytes } from '@polkadot/util';
2
+ export declare const ETHEREUM: Uint8Array<ArrayBufferLike>;
3
+ export declare const POSTFIX: Uint8Array<ArrayBufferLike>;
4
+ export declare const PREFIX: Uint8Array<ArrayBufferLike>;
5
+ export declare const isWrapped: typeof u8aIsWrapped;
6
+ export declare const unwrapBytes: typeof u8aUnwrapBytes;
7
+ export declare const wrapBytes: typeof u8aWrapBytes;
package/wrapBytes.js ADDED
@@ -0,0 +1,7 @@
1
+ import { U8A_WRAP_ETHEREUM, U8A_WRAP_POSTFIX, U8A_WRAP_PREFIX, u8aIsWrapped, u8aUnwrapBytes, u8aWrapBytes } from '@polkadot/util';
2
+ export const ETHEREUM = U8A_WRAP_ETHEREUM;
3
+ export const POSTFIX = U8A_WRAP_POSTFIX;
4
+ export const PREFIX = U8A_WRAP_PREFIX;
5
+ export const isWrapped = u8aIsWrapped;
6
+ export const unwrapBytes = u8aUnwrapBytes;
7
+ export const wrapBytes = u8aWrapBytes;