@polkadot/extension-dapp 0.44.8 → 0.45.1
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/bundle-polkadot-extension-dapp.js +183 -213
- package/bundle.d.ts +48 -0
- package/bundle.js +204 -209
- package/cjs/bundle.js +219 -272
- package/cjs/detectOther.js +3 -10
- package/cjs/detectPackage.js +6 -11
- package/cjs/index.js +3 -15
- package/cjs/packageInfo.js +2 -16
- package/cjs/util.js +12 -16
- package/cjs/wrapBytes.js +8 -20
- package/detectOther.js +0 -3
- package/detectPackage.js +2 -7
- package/index.js +1 -7
- package/package.json +9 -6
- package/packageInfo.js +1 -11
- package/util.js +8 -10
- package/wrapBytes.js +0 -3
package/cjs/bundle.js
CHANGED
|
@@ -1,299 +1,246 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
});
|
|
13
|
-
Object.defineProperty(exports, "unwrapBytes", {
|
|
14
|
-
enumerable: true,
|
|
15
|
-
get: function () {
|
|
16
|
-
return _wrapBytes.unwrapBytes;
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
exports.web3Accounts = web3Accounts;
|
|
20
|
-
exports.web3AccountsSubscribe = web3AccountsSubscribe;
|
|
21
|
-
exports.web3Enable = web3Enable;
|
|
22
|
-
exports.web3EnablePromise = void 0;
|
|
23
|
-
exports.web3FromAddress = web3FromAddress;
|
|
24
|
-
exports.web3FromSource = web3FromSource;
|
|
25
|
-
exports.web3ListRpcProviders = web3ListRpcProviders;
|
|
26
|
-
exports.web3UseRpcProvider = web3UseRpcProvider;
|
|
27
|
-
Object.defineProperty(exports, "wrapBytes", {
|
|
28
|
-
enumerable: true,
|
|
29
|
-
get: function () {
|
|
30
|
-
return _wrapBytes.wrapBytes;
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
var _util = require("@polkadot/util");
|
|
34
|
-
var _utilCrypto = require("@polkadot/util-crypto");
|
|
35
|
-
var _util2 = require("./util");
|
|
36
|
-
var _packageInfo = require("./packageInfo");
|
|
37
|
-
var _wrapBytes = require("./wrapBytes");
|
|
38
|
-
// Copyright 2019-2023 @polkadot/extension-dapp authors & contributors
|
|
39
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
40
|
-
|
|
41
|
-
// expose utility functions
|
|
42
|
-
|
|
43
|
-
// just a helper (otherwise we cast all-over, so shorter and more readable)
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.web3UseRpcProvider = exports.web3ListRpcProviders = exports.web3FromAddress = exports.web3FromSource = exports.web3AccountsSubscribe = exports.web3Accounts = exports.web3Enable = exports.web3EnablePromise = exports.isWeb3Injected = exports.wrapBytes = exports.unwrapBytes = exports.packageInfo = void 0;
|
|
4
|
+
const util_1 = require("@polkadot/util");
|
|
5
|
+
const util_crypto_1 = require("@polkadot/util-crypto");
|
|
6
|
+
const util_2 = require("./util");
|
|
7
|
+
var packageInfo_1 = require("./packageInfo");
|
|
8
|
+
Object.defineProperty(exports, "packageInfo", { enumerable: true, get: function () { return packageInfo_1.packageInfo; } });
|
|
9
|
+
var wrapBytes_1 = require("./wrapBytes");
|
|
10
|
+
Object.defineProperty(exports, "unwrapBytes", { enumerable: true, get: function () { return wrapBytes_1.unwrapBytes; } });
|
|
11
|
+
Object.defineProperty(exports, "wrapBytes", { enumerable: true, get: function () { return wrapBytes_1.wrapBytes; } });
|
|
44
12
|
const win = window;
|
|
45
|
-
|
|
46
|
-
// don't clobber the existing object, but ensure non-undefined
|
|
47
13
|
win.injectedWeb3 = win.injectedWeb3 || {};
|
|
48
|
-
|
|
49
|
-
|
|
14
|
+
let isWeb3Injected = web3IsInjected();
|
|
15
|
+
exports.isWeb3Injected = isWeb3Injected;
|
|
16
|
+
let web3EnablePromise = null;
|
|
17
|
+
exports.web3EnablePromise = web3EnablePromise;
|
|
18
|
+
/** @internal true when anything has been injected and is available */
|
|
50
19
|
function web3IsInjected() {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
} = _ref;
|
|
56
|
-
return !!(connect || enable);
|
|
57
|
-
}).length !== 0;
|
|
20
|
+
return Object
|
|
21
|
+
.values(win.injectedWeb3)
|
|
22
|
+
.filter(({ connect, enable }) => !!(connect || enable))
|
|
23
|
+
.length !== 0;
|
|
58
24
|
}
|
|
59
|
-
|
|
60
|
-
// helper to throw a consistent error when not enabled
|
|
25
|
+
/** @internal throw a consistent error when not extensions have not been enabled */
|
|
61
26
|
function throwError(method) {
|
|
62
|
-
|
|
27
|
+
throw new Error(`${method}: web3Enable(originName) needs to be called before ${method}`);
|
|
63
28
|
}
|
|
64
|
-
|
|
65
|
-
// internal helper to map from Array<InjectedAccount> -> Array<InjectedAccountWithMeta>
|
|
29
|
+
/** @internal map from Array<InjectedAccount> to Array<InjectedAccountWithMeta> */
|
|
66
30
|
function mapAccounts(source, list, ss58Format) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
return {
|
|
75
|
-
address: address.length === 42 ? address : (0, _utilCrypto.encodeAddress)((0, _utilCrypto.decodeAddress)(address), ss58Format),
|
|
76
|
-
meta: {
|
|
77
|
-
genesisHash,
|
|
78
|
-
name,
|
|
79
|
-
source
|
|
80
|
-
},
|
|
81
|
-
type
|
|
82
|
-
};
|
|
83
|
-
});
|
|
31
|
+
return list.map(({ address, genesisHash, name, type }) => ({
|
|
32
|
+
address: address.length === 42
|
|
33
|
+
? address
|
|
34
|
+
: (0, util_crypto_1.encodeAddress)((0, util_crypto_1.decodeAddress)(address), ss58Format),
|
|
35
|
+
meta: { genesisHash, name, source },
|
|
36
|
+
type
|
|
37
|
+
}));
|
|
84
38
|
}
|
|
85
|
-
|
|
86
|
-
// internal helper to filter accounts
|
|
39
|
+
/** @internal filter accounts based on genesisHash and type of account */
|
|
87
40
|
function filterAccounts(list, genesisHash, type) {
|
|
88
|
-
|
|
41
|
+
return list.filter((a) => (!a.type || !type || type.includes(a.type)) &&
|
|
42
|
+
(!a.genesisHash || !genesisHash || a.genesisHash === genesisHash));
|
|
89
43
|
}
|
|
90
|
-
|
|
91
|
-
// have we found a properly constructed window.injectedWeb3
|
|
92
|
-
let isWeb3Injected = web3IsInjected();
|
|
93
|
-
|
|
94
|
-
// we keep the last promise created around (for queries)
|
|
95
|
-
exports.isWeb3Injected = isWeb3Injected;
|
|
96
|
-
let web3EnablePromise = null;
|
|
97
|
-
exports.web3EnablePromise = web3EnablePromise;
|
|
44
|
+
/** @internal retrieves all the extensions available on the window */
|
|
98
45
|
function getWindowExtensions(originName) {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
} = _ref4;
|
|
116
|
-
console.error(`Error initializing ${nameOrHash}: ${message}`);
|
|
117
|
-
});
|
|
118
|
-
})).then(exts => exts.filter(e => !!e));
|
|
46
|
+
return Promise
|
|
47
|
+
.all(Object
|
|
48
|
+
.entries(win.injectedWeb3)
|
|
49
|
+
.map(([nameOrHash, { connect, enable, version }]) => Promise
|
|
50
|
+
.resolve()
|
|
51
|
+
.then(() => connect
|
|
52
|
+
// new style, returning all info
|
|
53
|
+
? connect(originName)
|
|
54
|
+
: enable
|
|
55
|
+
// previous interface, leakages on name/version
|
|
56
|
+
? enable(originName).then((e) => (0, util_1.objectSpread)({ name: nameOrHash, version: version || 'unknown' }, e))
|
|
57
|
+
: Promise.reject(new Error('No connect(..) or enable(...) hook found')))
|
|
58
|
+
.catch(({ message }) => {
|
|
59
|
+
console.error(`Error initializing ${nameOrHash}: ${message}`);
|
|
60
|
+
})))
|
|
61
|
+
.then((exts) => exts.filter((e) => !!e));
|
|
119
62
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
if (!originName) {
|
|
125
|
-
throw new Error('You must pass a name for your app to the web3Enable function');
|
|
126
|
-
}
|
|
127
|
-
const initCompat = compatInits.length ? Promise.all(compatInits.map(c => c().catch(() => false))) : Promise.resolve([true]);
|
|
128
|
-
exports.web3EnablePromise = web3EnablePromise = (0, _util2.documentReadyPromise)(() => initCompat.then(() => getWindowExtensions(originName).then(values => values.map(e => {
|
|
129
|
-
// if we don't have an accounts subscriber, add a single-shot version
|
|
130
|
-
if (!e.accounts.subscribe) {
|
|
131
|
-
e.accounts.subscribe = cb => {
|
|
132
|
-
e.accounts.get().then(cb).catch(console.error);
|
|
133
|
-
return () => {
|
|
134
|
-
// no ubsubscribe needed, this is a single-shot
|
|
135
|
-
};
|
|
136
|
-
};
|
|
63
|
+
/** @internal Ensure the enable promise is resolved and filter by extensions */
|
|
64
|
+
async function filterEnable(caller, extensions) {
|
|
65
|
+
if (!web3EnablePromise) {
|
|
66
|
+
return throwError(caller);
|
|
137
67
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
let {
|
|
142
|
-
name,
|
|
143
|
-
version
|
|
144
|
-
} = _ref5;
|
|
145
|
-
return `${name}/${version}`;
|
|
146
|
-
});
|
|
147
|
-
exports.isWeb3Injected = isWeb3Injected = web3IsInjected();
|
|
148
|
-
console.info(`web3Enable: Enabled ${values.length} extension${values.length !== 1 ? 's' : ''}: ${names.join(', ')}`);
|
|
149
|
-
return values;
|
|
150
|
-
})));
|
|
151
|
-
return web3EnablePromise;
|
|
68
|
+
const sources = await web3EnablePromise;
|
|
69
|
+
return sources.filter(({ name }) => !extensions ||
|
|
70
|
+
extensions.includes(name));
|
|
152
71
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
if (!web3EnablePromise) {
|
|
163
|
-
return throwError('web3Accounts');
|
|
164
|
-
}
|
|
165
|
-
const accounts = [];
|
|
166
|
-
const sources = await web3EnablePromise;
|
|
167
|
-
const retrieved = await Promise.all(sources.filter(_ref6 => {
|
|
168
|
-
let {
|
|
169
|
-
name: source
|
|
170
|
-
} = _ref6;
|
|
171
|
-
return !extensions || extensions.includes(source);
|
|
172
|
-
}).map(async _ref7 => {
|
|
173
|
-
let {
|
|
174
|
-
accounts,
|
|
175
|
-
name: source
|
|
176
|
-
} = _ref7;
|
|
177
|
-
try {
|
|
178
|
-
const list = await accounts.get();
|
|
179
|
-
return mapAccounts(source, filterAccounts(list, genesisHash, accountType), ss58Format);
|
|
180
|
-
} catch (error) {
|
|
181
|
-
// cannot handle this one
|
|
182
|
-
return [];
|
|
72
|
+
/**
|
|
73
|
+
* @summary Enables all the providers found on the injected window interface
|
|
74
|
+
* @description
|
|
75
|
+
* Enables all injected extensions that has been found on the page. This
|
|
76
|
+
* should be called before making use of any other web3* functions.
|
|
77
|
+
*/
|
|
78
|
+
function web3Enable(originName, compatInits = []) {
|
|
79
|
+
if (!originName) {
|
|
80
|
+
throw new Error('You must pass a name for your app to the web3Enable function');
|
|
183
81
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
82
|
+
const initCompat = compatInits.length
|
|
83
|
+
? Promise.all(compatInits.map((c) => c().catch(() => false)))
|
|
84
|
+
: Promise.resolve([true]);
|
|
85
|
+
exports.web3EnablePromise = web3EnablePromise = (0, util_2.documentReadyPromise)(() => initCompat.then(() => getWindowExtensions(originName)
|
|
86
|
+
.then((values) => values.map((e) => {
|
|
87
|
+
// if we don't have an accounts subscriber, add a single-shot version
|
|
88
|
+
if (!e.accounts.subscribe) {
|
|
89
|
+
e.accounts.subscribe = (cb) => {
|
|
90
|
+
e.accounts
|
|
91
|
+
.get()
|
|
92
|
+
.then(cb)
|
|
93
|
+
.catch(console.error);
|
|
94
|
+
return () => {
|
|
95
|
+
// no ubsubscribe needed, this is a single-shot
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
return e;
|
|
100
|
+
}))
|
|
101
|
+
.catch(() => [])
|
|
102
|
+
.then((values) => {
|
|
103
|
+
const names = values.map(({ name, version }) => `${name}/${version}`);
|
|
104
|
+
exports.isWeb3Injected = isWeb3Injected = web3IsInjected();
|
|
105
|
+
console.info(`web3Enable: Enabled ${values.length} extension${values.length !== 1 ? 's' : ''}: ${names.join(', ')}`);
|
|
106
|
+
return values;
|
|
107
|
+
})));
|
|
108
|
+
return web3EnablePromise;
|
|
190
109
|
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
const sources = await web3EnablePromise;
|
|
208
|
-
const unsubs = sources.filter(_ref9 => {
|
|
209
|
-
let {
|
|
210
|
-
name: source
|
|
211
|
-
} = _ref9;
|
|
212
|
-
return !extensions || extensions.includes(source);
|
|
213
|
-
}).map(_ref10 => {
|
|
214
|
-
let {
|
|
215
|
-
accounts: {
|
|
216
|
-
subscribe
|
|
217
|
-
},
|
|
218
|
-
name: source
|
|
219
|
-
} = _ref10;
|
|
220
|
-
return subscribe(result => {
|
|
221
|
-
accounts[source] = result;
|
|
222
|
-
try {
|
|
223
|
-
const result = triggerUpdate();
|
|
224
|
-
if (result && (0, _util.isPromise)(result)) {
|
|
225
|
-
result.catch(console.error);
|
|
110
|
+
exports.web3Enable = web3Enable;
|
|
111
|
+
/**
|
|
112
|
+
* @summary Retrieves all the accounts across all providers
|
|
113
|
+
* @description
|
|
114
|
+
* This returns the full list of account available (accross all extensions) to
|
|
115
|
+
* the page. Filtereing options are available of a per-extension, per type and
|
|
116
|
+
* per-genesisHash basis. Optionally the accounts can be encoded with the provided
|
|
117
|
+
* ss58Format
|
|
118
|
+
*/
|
|
119
|
+
async function web3Accounts({ accountType, extensions, genesisHash, ss58Format } = {}) {
|
|
120
|
+
const accounts = [];
|
|
121
|
+
const sources = await filterEnable('web3Accounts', extensions);
|
|
122
|
+
const retrieved = await Promise.all(sources.map(async ({ accounts, name: source }) => {
|
|
123
|
+
try {
|
|
124
|
+
const list = await accounts.get();
|
|
125
|
+
return mapAccounts(source, filterAccounts(list, genesisHash, accountType), ss58Format);
|
|
226
126
|
}
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
unsub();
|
|
127
|
+
catch (error) {
|
|
128
|
+
// cannot handle this one
|
|
129
|
+
return [];
|
|
130
|
+
}
|
|
131
|
+
}));
|
|
132
|
+
retrieved.forEach((result) => {
|
|
133
|
+
accounts.push(...result);
|
|
235
134
|
});
|
|
236
|
-
|
|
135
|
+
console.info(`web3Accounts: Found ${accounts.length} address${accounts.length !== 1 ? 'es' : ''}`);
|
|
136
|
+
return accounts;
|
|
137
|
+
}
|
|
138
|
+
exports.web3Accounts = web3Accounts;
|
|
139
|
+
/**
|
|
140
|
+
* @summary Subscribes to all the accounts across all providers
|
|
141
|
+
* @description
|
|
142
|
+
* This is the subscription version of the web3Accounts interface with
|
|
143
|
+
* updates as to when new accounts do become available. The list of filtering
|
|
144
|
+
* options are the same as for the web3Accounts interface.
|
|
145
|
+
*/
|
|
146
|
+
async function web3AccountsSubscribe(cb, { accountType, extensions, genesisHash, ss58Format } = {}) {
|
|
147
|
+
const sources = await filterEnable('web3AccountsSubscribe', extensions);
|
|
148
|
+
const accounts = {};
|
|
149
|
+
const triggerUpdate = () => cb(Object
|
|
150
|
+
.entries(accounts)
|
|
151
|
+
.reduce((result, [source, list]) => {
|
|
152
|
+
result.push(...mapAccounts(source, filterAccounts(list, genesisHash, accountType), ss58Format));
|
|
153
|
+
return result;
|
|
154
|
+
}, []));
|
|
155
|
+
const unsubs = sources.map(({ accounts: { subscribe }, name: source }) => subscribe((result) => {
|
|
156
|
+
accounts[source] = result;
|
|
157
|
+
try {
|
|
158
|
+
const result = triggerUpdate();
|
|
159
|
+
if (result && (0, util_1.isPromise)(result)) {
|
|
160
|
+
result.catch(console.error);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
catch (error) {
|
|
164
|
+
console.error(error);
|
|
165
|
+
}
|
|
166
|
+
}));
|
|
167
|
+
return () => {
|
|
168
|
+
unsubs.forEach((unsub) => {
|
|
169
|
+
unsub();
|
|
170
|
+
});
|
|
171
|
+
};
|
|
237
172
|
}
|
|
238
|
-
|
|
239
|
-
|
|
173
|
+
exports.web3AccountsSubscribe = web3AccountsSubscribe;
|
|
174
|
+
/**
|
|
175
|
+
* @summary Finds a specific provider based on the name
|
|
176
|
+
* @description
|
|
177
|
+
* This retrieves a specific source (extension) based on the name. In most
|
|
178
|
+
* cases it should not be needed to call it directly (e.g. it is used internally
|
|
179
|
+
* by calls such as web3FromAddress) but would allow operation on a specific
|
|
180
|
+
* known extension.
|
|
181
|
+
*/
|
|
240
182
|
async function web3FromSource(source) {
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
}
|
|
249
|
-
return
|
|
250
|
-
});
|
|
251
|
-
if (!found) {
|
|
252
|
-
throw new Error(`web3FromSource: Unable to find an injected ${source}`);
|
|
253
|
-
}
|
|
254
|
-
return found;
|
|
183
|
+
if (!web3EnablePromise) {
|
|
184
|
+
return throwError('web3FromSource');
|
|
185
|
+
}
|
|
186
|
+
const sources = await web3EnablePromise;
|
|
187
|
+
const found = source && sources.find(({ name }) => name === source);
|
|
188
|
+
if (!found) {
|
|
189
|
+
throw new Error(`web3FromSource: Unable to find an injected ${source}`);
|
|
190
|
+
}
|
|
191
|
+
return found;
|
|
255
192
|
}
|
|
256
|
-
|
|
257
|
-
|
|
193
|
+
exports.web3FromSource = web3FromSource;
|
|
194
|
+
/**
|
|
195
|
+
* @summary Find a specific provider that provides a specific address
|
|
196
|
+
* @description
|
|
197
|
+
* Based on an address, return the provider that has makes this address
|
|
198
|
+
* available to the page.
|
|
199
|
+
*/
|
|
258
200
|
async function web3FromAddress(address) {
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
201
|
+
if (!web3EnablePromise) {
|
|
202
|
+
return throwError('web3FromAddress');
|
|
203
|
+
}
|
|
204
|
+
const accounts = await web3Accounts();
|
|
205
|
+
let found;
|
|
206
|
+
if (address) {
|
|
207
|
+
const accountU8a = (0, util_crypto_1.decodeAddress)(address);
|
|
208
|
+
found = accounts.find((account) => (0, util_1.u8aEq)((0, util_crypto_1.decodeAddress)(account.address), accountU8a));
|
|
209
|
+
}
|
|
210
|
+
if (!found) {
|
|
211
|
+
throw new Error(`web3FromAddress: Unable to find injected ${address}`);
|
|
212
|
+
}
|
|
213
|
+
return web3FromSource(found.meta.source);
|
|
272
214
|
}
|
|
273
|
-
|
|
274
|
-
|
|
215
|
+
exports.web3FromAddress = web3FromAddress;
|
|
216
|
+
/**
|
|
217
|
+
* @summary List all providers exposed by one source
|
|
218
|
+
* @description
|
|
219
|
+
* For extensions that supply RPC providers, this call would return the list
|
|
220
|
+
* of RPC providers that any extension may supply.
|
|
221
|
+
*/
|
|
275
222
|
async function web3ListRpcProviders(source) {
|
|
276
|
-
|
|
277
|
-
provider
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
return
|
|
282
|
-
}
|
|
283
|
-
return provider.listProviders();
|
|
223
|
+
const { provider } = await web3FromSource(source);
|
|
224
|
+
if (!provider) {
|
|
225
|
+
console.warn(`Extension ${source} does not expose any provider`);
|
|
226
|
+
return null;
|
|
227
|
+
}
|
|
228
|
+
return provider.listProviders();
|
|
284
229
|
}
|
|
285
|
-
|
|
286
|
-
|
|
230
|
+
exports.web3ListRpcProviders = web3ListRpcProviders;
|
|
231
|
+
/**
|
|
232
|
+
* @summary Start an RPC provider provider by a specific source
|
|
233
|
+
* @description
|
|
234
|
+
* For extensions that supply RPC providers, this call would return an
|
|
235
|
+
* enabled provider (initialized with the specific key) from the
|
|
236
|
+
* specified extension source.
|
|
237
|
+
*/
|
|
287
238
|
async function web3UseRpcProvider(source, key) {
|
|
288
|
-
|
|
289
|
-
provider
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
meta,
|
|
297
|
-
provider
|
|
298
|
-
};
|
|
299
|
-
}
|
|
239
|
+
const { provider } = await web3FromSource(source);
|
|
240
|
+
if (!provider) {
|
|
241
|
+
throw new Error(`Extension ${source} does not expose any provider`);
|
|
242
|
+
}
|
|
243
|
+
const meta = await provider.startProvider(key);
|
|
244
|
+
return { meta, provider };
|
|
245
|
+
}
|
|
246
|
+
exports.web3UseRpcProvider = web3UseRpcProvider;
|
package/cjs/detectOther.js
CHANGED
|
@@ -1,11 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _packageInfo = require("@polkadot/extension-inject/cjs/packageInfo");
|
|
8
|
-
// Copyright 2017-2023 @polkadot/extension-dapp authors & contributors
|
|
9
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
10
|
-
var _default = [_packageInfo.packageInfo];
|
|
11
|
-
exports.default = _default;
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const packageInfo_1 = require("@polkadot/extension-inject/cjs/packageInfo");
|
|
4
|
+
exports.default = [packageInfo_1.packageInfo];
|
package/cjs/detectPackage.js
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
9
|
-
|
|
10
|
-
// Do not edit, auto-generated by @polkadot/dev
|
|
11
|
-
|
|
12
|
-
(0, _util.detectPackage)(_packageInfo.packageInfo, null, _detectOther.default);
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const util_1 = require("@polkadot/util");
|
|
5
|
+
const detectOther_1 = tslib_1.__importDefault(require("./detectOther"));
|
|
6
|
+
const packageInfo_1 = require("./packageInfo");
|
|
7
|
+
(0, util_1.detectPackage)(packageInfo_1.packageInfo, null, detectOther_1.default);
|
package/cjs/index.js
CHANGED
|
@@ -1,16 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
});
|
|
6
|
-
var _bundle = require("./bundle");
|
|
7
|
-
Object.keys(_bundle).forEach(function (key) {
|
|
8
|
-
if (key === "default" || key === "__esModule") return;
|
|
9
|
-
if (key in exports && exports[key] === _bundle[key]) return;
|
|
10
|
-
Object.defineProperty(exports, key, {
|
|
11
|
-
enumerable: true,
|
|
12
|
-
get: function () {
|
|
13
|
-
return _bundle[key];
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
});
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./bundle"), exports);
|
package/cjs/packageInfo.js
CHANGED
|
@@ -1,18 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.packageInfo = void 0;
|
|
7
|
-
|
|
8
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
9
|
-
|
|
10
|
-
// Do not edit, auto-generated by @polkadot/dev
|
|
11
|
-
|
|
12
|
-
const packageInfo = {
|
|
13
|
-
name: '@polkadot/extension-dapp',
|
|
14
|
-
path: typeof __dirname === 'string' ? __dirname : 'auto',
|
|
15
|
-
type: 'cjs',
|
|
16
|
-
version: '0.44.8'
|
|
17
|
-
};
|
|
18
|
-
exports.packageInfo = packageInfo;
|
|
4
|
+
exports.packageInfo = { name: '@polkadot/extension-dapp', path: typeof __dirname === 'string' ? __dirname : 'auto', type: 'cjs', version: '0.45.1' };
|
package/cjs/util.js
CHANGED
|
@@ -1,18 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.documentReadyPromise = documentReadyPromise;
|
|
7
|
-
// Copyright 2019-2023 @polkadot/extension-dapp authors & contributors
|
|
8
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
9
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.documentReadyPromise = void 0;
|
|
10
4
|
function documentReadyPromise(creator) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
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
|
+
}
|
|
14
|
+
exports.documentReadyPromise = documentReadyPromise;
|
package/cjs/wrapBytes.js
CHANGED
|
@@ -1,22 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.wrapBytes = exports.unwrapBytes = exports.isWrapped = exports.PREFIX = exports.POSTFIX = exports.ETHEREUM = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
exports.
|
|
13
|
-
|
|
14
|
-
exports.POSTFIX = POSTFIX;
|
|
15
|
-
const PREFIX = _util.U8A_WRAP_PREFIX;
|
|
16
|
-
exports.PREFIX = PREFIX;
|
|
17
|
-
const isWrapped = _util.u8aIsWrapped;
|
|
18
|
-
exports.isWrapped = isWrapped;
|
|
19
|
-
const unwrapBytes = _util.u8aUnwrapBytes;
|
|
20
|
-
exports.unwrapBytes = unwrapBytes;
|
|
21
|
-
const wrapBytes = _util.u8aWrapBytes;
|
|
22
|
-
exports.wrapBytes = wrapBytes;
|
|
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;
|