@pezkuwi/extension-dapp 0.62.7 → 0.62.10
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/README.md +1 -1
- package/bundle.d.ts +1 -1
- package/bundle.js +304 -141
- package/index.js +4 -0
- package/package.json +7 -112
- package/packageDetect.js +6 -2
- package/packageInfo.js +4 -1
- package/util.js +4 -2
- package/wrapBytes.d.ts +1 -1
- package/wrapBytes.js +9 -7
- package/LICENSE +0 -201
- package/bundle-polkadot-extension-dapp.js +0 -205
- package/cjs/bundle.d.ts +0 -61
- package/cjs/bundle.js +0 -246
- package/cjs/index.d.ts +0 -1
- package/cjs/index.js +0 -4
- package/cjs/package.json +0 -3
- package/cjs/packageDetect.d.ts +0 -1
- package/cjs/packageDetect.js +0 -6
- package/cjs/packageInfo.d.ts +0 -6
- package/cjs/packageInfo.js +0 -4
- package/cjs/util.d.ts +0 -1
- package/cjs/util.js +0 -13
- package/cjs/wrapBytes.d.ts +0 -7
- package/cjs/wrapBytes.js +0 -10
package/README.md
CHANGED
package/bundle.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { InjectedAccountWithMeta, InjectedExtension, InjectedProviderWithMeta, ProviderList, Unsubcall, Web3AccountsOptions } from '@
|
|
1
|
+
import type { InjectedAccountWithMeta, InjectedExtension, InjectedProviderWithMeta, ProviderList, Unsubcall, Web3AccountsOptions } from '@pezkuwi/extension-inject/types';
|
|
2
2
|
export { packageInfo } from './packageInfo.js';
|
|
3
3
|
export { unwrapBytes, wrapBytes } from './wrapBytes.js';
|
|
4
4
|
declare let isWeb3Injected: boolean;
|
package/bundle.js
CHANGED
|
@@ -1,66 +1,138 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// Copyright 2019-2025 @pezkuwi/extension-dapp authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
4
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
5
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
6
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
7
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
8
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
9
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
13
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
14
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
15
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
16
|
+
function step(op) {
|
|
17
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
18
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
19
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
20
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
21
|
+
switch (op[0]) {
|
|
22
|
+
case 0: case 1: t = op; break;
|
|
23
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
24
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
25
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
26
|
+
default:
|
|
27
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
28
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
29
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
30
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
31
|
+
if (t[2]) _.ops.pop();
|
|
32
|
+
_.trys.pop(); continue;
|
|
33
|
+
}
|
|
34
|
+
op = body.call(thisArg, _);
|
|
35
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
36
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
import { isPromise, objectSpread, u8aEq } from '@pezkuwi/util';
|
|
40
|
+
import { decodeAddress, encodeAddress } from '@pezkuwi/util-crypto';
|
|
3
41
|
import { documentReadyPromise } from './util.js';
|
|
42
|
+
// expose utility functions
|
|
4
43
|
export { packageInfo } from './packageInfo.js';
|
|
5
44
|
export { unwrapBytes, wrapBytes } from './wrapBytes.js';
|
|
6
|
-
|
|
45
|
+
// just a helper (otherwise we cast all-over, so shorter and more readable)
|
|
46
|
+
var win = window;
|
|
47
|
+
// don't clobber the existing object, but ensure non-undefined
|
|
7
48
|
win.injectedWeb3 = win.injectedWeb3 || {};
|
|
8
|
-
|
|
9
|
-
|
|
49
|
+
// have we found a properly constructed window.injectedWeb3
|
|
50
|
+
var isWeb3Injected = web3IsInjected();
|
|
51
|
+
// we keep the last promise created around (for queries)
|
|
52
|
+
var web3EnablePromise = null;
|
|
10
53
|
export { isWeb3Injected, web3EnablePromise };
|
|
11
54
|
/** @internal true when anything has been injected and is available */
|
|
12
55
|
function web3IsInjected() {
|
|
13
56
|
return Object
|
|
14
57
|
.values(win.injectedWeb3)
|
|
15
|
-
.filter((
|
|
58
|
+
.filter(function (_a) {
|
|
59
|
+
var connect = _a.connect, enable = _a.enable;
|
|
60
|
+
return !!(connect || enable);
|
|
61
|
+
})
|
|
16
62
|
.length !== 0;
|
|
17
63
|
}
|
|
18
64
|
/** @internal throw a consistent error when not extensions have not been enabled */
|
|
19
65
|
function throwError(method) {
|
|
20
|
-
throw new Error(
|
|
66
|
+
throw new Error("".concat(method, ": web3Enable(originName) needs to be called before ").concat(method));
|
|
21
67
|
}
|
|
22
68
|
/** @internal map from Array<InjectedAccount> to Array<InjectedAccountWithMeta> */
|
|
23
69
|
function mapAccounts(source, list, ss58Format) {
|
|
24
|
-
return list.map((
|
|
25
|
-
address
|
|
26
|
-
|
|
27
|
-
:
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
70
|
+
return list.map(function (_a) {
|
|
71
|
+
var address = _a.address, genesisHash = _a.genesisHash, name = _a.name, type = _a.type;
|
|
72
|
+
return ({
|
|
73
|
+
address: address.length === 42
|
|
74
|
+
? address
|
|
75
|
+
: encodeAddress(decodeAddress(address), ss58Format),
|
|
76
|
+
meta: { genesisHash: genesisHash, name: name, source: source },
|
|
77
|
+
type: type
|
|
78
|
+
});
|
|
79
|
+
});
|
|
31
80
|
}
|
|
32
81
|
/** @internal filter accounts based on genesisHash and type of account */
|
|
33
82
|
function filterAccounts(list, genesisHash, type) {
|
|
34
|
-
return list.filter(
|
|
35
|
-
(!a.
|
|
83
|
+
return list.filter(function (a) {
|
|
84
|
+
return (!a.type || !type || type.includes(a.type)) &&
|
|
85
|
+
(!a.genesisHash || !genesisHash || a.genesisHash === genesisHash);
|
|
86
|
+
});
|
|
36
87
|
}
|
|
37
88
|
/** @internal retrieves all the extensions available on the window */
|
|
38
89
|
function getWindowExtensions(originName) {
|
|
39
90
|
return Promise
|
|
40
91
|
.all(Object
|
|
41
92
|
.entries(win.injectedWeb3)
|
|
42
|
-
.map((
|
|
43
|
-
.
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
93
|
+
.map(function (_a) {
|
|
94
|
+
var nameOrHash = _a[0], _b = _a[1], connect = _b.connect, enable = _b.enable, version = _b.version;
|
|
95
|
+
return Promise
|
|
96
|
+
.resolve()
|
|
97
|
+
.then(function () {
|
|
98
|
+
return connect
|
|
99
|
+
// new style, returning all info
|
|
100
|
+
? connect(originName)
|
|
101
|
+
: enable
|
|
102
|
+
// previous interface, leakages on name/version
|
|
103
|
+
? enable(originName).then(function (e) {
|
|
104
|
+
return objectSpread({ name: nameOrHash, version: version || 'unknown' }, e);
|
|
105
|
+
})
|
|
106
|
+
: Promise.reject(new Error('No connect(..) or enable(...) hook found'));
|
|
107
|
+
})
|
|
108
|
+
.catch(function (_a) {
|
|
109
|
+
var message = _a.message;
|
|
110
|
+
console.error("Error initializing ".concat(nameOrHash, ": ").concat(message));
|
|
111
|
+
});
|
|
112
|
+
}))
|
|
113
|
+
.then(function (exts) { return exts.filter(function (e) { return !!e; }); });
|
|
55
114
|
}
|
|
56
115
|
/** @internal Ensure the enable promise is resolved and filter by extensions */
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
116
|
+
function filterEnable(caller, extensions) {
|
|
117
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
118
|
+
var sources;
|
|
119
|
+
return __generator(this, function (_a) {
|
|
120
|
+
switch (_a.label) {
|
|
121
|
+
case 0:
|
|
122
|
+
if (!web3EnablePromise) {
|
|
123
|
+
return [2 /*return*/, throwError(caller)];
|
|
124
|
+
}
|
|
125
|
+
return [4 /*yield*/, web3EnablePromise];
|
|
126
|
+
case 1:
|
|
127
|
+
sources = _a.sent();
|
|
128
|
+
return [2 /*return*/, sources.filter(function (_a) {
|
|
129
|
+
var name = _a.name;
|
|
130
|
+
return !extensions ||
|
|
131
|
+
extensions.includes(name);
|
|
132
|
+
})];
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
});
|
|
64
136
|
}
|
|
65
137
|
/**
|
|
66
138
|
* @summary Enables all the providers found on the injected window interface
|
|
@@ -68,36 +140,46 @@ async function filterEnable(caller, extensions) {
|
|
|
68
140
|
* Enables all injected extensions that has been found on the page. This
|
|
69
141
|
* should be called before making use of any other web3* functions.
|
|
70
142
|
*/
|
|
71
|
-
export function web3Enable(originName, compatInits
|
|
143
|
+
export function web3Enable(originName, compatInits) {
|
|
144
|
+
if (compatInits === void 0) { compatInits = []; }
|
|
72
145
|
if (!originName) {
|
|
73
146
|
throw new Error('You must pass a name for your app to the web3Enable function');
|
|
74
147
|
}
|
|
75
|
-
|
|
76
|
-
? Promise.all(compatInits.map((c)
|
|
148
|
+
var initCompat = compatInits.length
|
|
149
|
+
? Promise.all(compatInits.map(function (c) { return c().catch(function () { return false; }); }))
|
|
77
150
|
: Promise.resolve([true]);
|
|
78
|
-
web3EnablePromise = documentReadyPromise(
|
|
79
|
-
.then(
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
.
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
151
|
+
web3EnablePromise = documentReadyPromise(function () {
|
|
152
|
+
return initCompat.then(function () {
|
|
153
|
+
return getWindowExtensions(originName)
|
|
154
|
+
.then(function (values) {
|
|
155
|
+
return values.map(function (e) {
|
|
156
|
+
// if we don't have an accounts subscriber, add a single-shot version
|
|
157
|
+
if (!e.accounts.subscribe) {
|
|
158
|
+
e.accounts.subscribe = function (cb) {
|
|
159
|
+
e.accounts
|
|
160
|
+
.get()
|
|
161
|
+
.then(cb)
|
|
162
|
+
.catch(console.error);
|
|
163
|
+
return function () {
|
|
164
|
+
// no ubsubscribe needed, this is a single-shot
|
|
165
|
+
};
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
return e;
|
|
169
|
+
});
|
|
170
|
+
})
|
|
171
|
+
.catch(function () { return []; })
|
|
172
|
+
.then(function (values) {
|
|
173
|
+
var names = values.map(function (_a) {
|
|
174
|
+
var name = _a.name, version = _a.version;
|
|
175
|
+
return "".concat(name, "/").concat(version);
|
|
176
|
+
});
|
|
177
|
+
isWeb3Injected = web3IsInjected();
|
|
178
|
+
console.info("web3Enable: Enabled ".concat(values.length, " extension").concat(values.length !== 1 ? 's' : '', ": ").concat(names.join(', ')));
|
|
179
|
+
return values;
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
});
|
|
101
183
|
return web3EnablePromise;
|
|
102
184
|
}
|
|
103
185
|
/**
|
|
@@ -108,24 +190,47 @@ export function web3Enable(originName, compatInits = []) {
|
|
|
108
190
|
* per-genesisHash basis. Optionally the accounts can be encoded with the provided
|
|
109
191
|
* ss58Format
|
|
110
192
|
*/
|
|
111
|
-
export
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
193
|
+
export function web3Accounts() {
|
|
194
|
+
return __awaiter(this, arguments, void 0, function (_a) {
|
|
195
|
+
var accounts, sources, retrieved;
|
|
196
|
+
var _this = this;
|
|
197
|
+
var _b = _a === void 0 ? {} : _a, accountType = _b.accountType, extensions = _b.extensions, genesisHash = _b.genesisHash, ss58Format = _b.ss58Format;
|
|
198
|
+
return __generator(this, function (_c) {
|
|
199
|
+
switch (_c.label) {
|
|
200
|
+
case 0:
|
|
201
|
+
accounts = [];
|
|
202
|
+
return [4 /*yield*/, filterEnable('web3Accounts', extensions)];
|
|
203
|
+
case 1:
|
|
204
|
+
sources = _c.sent();
|
|
205
|
+
return [4 /*yield*/, Promise.all(sources.map(function (_a) { return __awaiter(_this, [_a], void 0, function (_b) {
|
|
206
|
+
var list, _c;
|
|
207
|
+
var accounts = _b.accounts, source = _b.name;
|
|
208
|
+
return __generator(this, function (_d) {
|
|
209
|
+
switch (_d.label) {
|
|
210
|
+
case 0:
|
|
211
|
+
_d.trys.push([0, 2, , 3]);
|
|
212
|
+
return [4 /*yield*/, accounts.get()];
|
|
213
|
+
case 1:
|
|
214
|
+
list = _d.sent();
|
|
215
|
+
return [2 /*return*/, mapAccounts(source, filterAccounts(list, genesisHash, accountType), ss58Format)];
|
|
216
|
+
case 2:
|
|
217
|
+
_c = _d.sent();
|
|
218
|
+
// cannot handle this one
|
|
219
|
+
return [2 /*return*/, []];
|
|
220
|
+
case 3: return [2 /*return*/];
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
}); }))];
|
|
224
|
+
case 2:
|
|
225
|
+
retrieved = _c.sent();
|
|
226
|
+
retrieved.forEach(function (result) {
|
|
227
|
+
accounts.push.apply(accounts, result);
|
|
228
|
+
});
|
|
229
|
+
console.info("web3Accounts: Found ".concat(accounts.length, " address").concat(accounts.length !== 1 ? 'es' : ''));
|
|
230
|
+
return [2 /*return*/, accounts];
|
|
231
|
+
}
|
|
232
|
+
});
|
|
126
233
|
});
|
|
127
|
-
console.info(`web3Accounts: Found ${accounts.length} address${accounts.length !== 1 ? 'es' : ''}`);
|
|
128
|
-
return accounts;
|
|
129
234
|
}
|
|
130
235
|
/**
|
|
131
236
|
* @summary Subscribes to all the accounts across all providers
|
|
@@ -134,32 +239,48 @@ export async function web3Accounts({ accountType, extensions, genesisHash, ss58F
|
|
|
134
239
|
* updates as to when new accounts do become available. The list of filtering
|
|
135
240
|
* options are the same as for the web3Accounts interface.
|
|
136
241
|
*/
|
|
137
|
-
export
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
242
|
+
export function web3AccountsSubscribe(cb_1) {
|
|
243
|
+
return __awaiter(this, arguments, void 0, function (cb, _a) {
|
|
244
|
+
var sources, accounts, triggerUpdate, unsubs;
|
|
245
|
+
var _b = _a === void 0 ? {} : _a, accountType = _b.accountType, extensions = _b.extensions, genesisHash = _b.genesisHash, ss58Format = _b.ss58Format;
|
|
246
|
+
return __generator(this, function (_c) {
|
|
247
|
+
switch (_c.label) {
|
|
248
|
+
case 0: return [4 /*yield*/, filterEnable('web3AccountsSubscribe', extensions)];
|
|
249
|
+
case 1:
|
|
250
|
+
sources = _c.sent();
|
|
251
|
+
accounts = {};
|
|
252
|
+
triggerUpdate = function () {
|
|
253
|
+
return cb(Object
|
|
254
|
+
.entries(accounts)
|
|
255
|
+
.reduce(function (result, _a) {
|
|
256
|
+
var source = _a[0], list = _a[1];
|
|
257
|
+
result.push.apply(result, mapAccounts(source, filterAccounts(list, genesisHash, accountType), ss58Format));
|
|
258
|
+
return result;
|
|
259
|
+
}, []));
|
|
260
|
+
};
|
|
261
|
+
unsubs = sources.map(function (_a) {
|
|
262
|
+
var subscribe = _a.accounts.subscribe, source = _a.name;
|
|
263
|
+
return subscribe(function (result) {
|
|
264
|
+
accounts[source] = result;
|
|
265
|
+
try {
|
|
266
|
+
var result_1 = triggerUpdate();
|
|
267
|
+
if (result_1 && isPromise(result_1)) {
|
|
268
|
+
result_1.catch(console.error);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
catch (error) {
|
|
272
|
+
console.error(error);
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
});
|
|
276
|
+
return [2 /*return*/, function () {
|
|
277
|
+
unsubs.forEach(function (unsub) {
|
|
278
|
+
unsub();
|
|
279
|
+
});
|
|
280
|
+
}];
|
|
152
281
|
}
|
|
153
|
-
}
|
|
154
|
-
catch (error) {
|
|
155
|
-
console.error(error);
|
|
156
|
-
}
|
|
157
|
-
}));
|
|
158
|
-
return () => {
|
|
159
|
-
unsubs.forEach((unsub) => {
|
|
160
|
-
unsub();
|
|
161
282
|
});
|
|
162
|
-
};
|
|
283
|
+
});
|
|
163
284
|
}
|
|
164
285
|
/**
|
|
165
286
|
* @summary Finds a specific provider based on the name
|
|
@@ -169,16 +290,29 @@ export async function web3AccountsSubscribe(cb, { accountType, extensions, genes
|
|
|
169
290
|
* by calls such as web3FromAddress) but would allow operation on a specific
|
|
170
291
|
* known extension.
|
|
171
292
|
*/
|
|
172
|
-
export
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
293
|
+
export function web3FromSource(source) {
|
|
294
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
295
|
+
var sources, found;
|
|
296
|
+
return __generator(this, function (_a) {
|
|
297
|
+
switch (_a.label) {
|
|
298
|
+
case 0:
|
|
299
|
+
if (!web3EnablePromise) {
|
|
300
|
+
return [2 /*return*/, throwError('web3FromSource')];
|
|
301
|
+
}
|
|
302
|
+
return [4 /*yield*/, web3EnablePromise];
|
|
303
|
+
case 1:
|
|
304
|
+
sources = _a.sent();
|
|
305
|
+
found = source && sources.find(function (_a) {
|
|
306
|
+
var name = _a.name;
|
|
307
|
+
return name === source;
|
|
308
|
+
});
|
|
309
|
+
if (!found) {
|
|
310
|
+
throw new Error("web3FromSource: Unable to find an injected ".concat(source));
|
|
311
|
+
}
|
|
312
|
+
return [2 /*return*/, found];
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
});
|
|
182
316
|
}
|
|
183
317
|
/**
|
|
184
318
|
* @summary Find a specific provider that provides a specific address
|
|
@@ -186,20 +320,29 @@ export async function web3FromSource(source) {
|
|
|
186
320
|
* Based on an address, return the provider that has makes this address
|
|
187
321
|
* available to the page.
|
|
188
322
|
*/
|
|
189
|
-
export
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
323
|
+
export function web3FromAddress(address) {
|
|
324
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
325
|
+
var accounts, found, accountU8a_1;
|
|
326
|
+
return __generator(this, function (_a) {
|
|
327
|
+
switch (_a.label) {
|
|
328
|
+
case 0:
|
|
329
|
+
if (!web3EnablePromise) {
|
|
330
|
+
return [2 /*return*/, throwError('web3FromAddress')];
|
|
331
|
+
}
|
|
332
|
+
return [4 /*yield*/, web3Accounts()];
|
|
333
|
+
case 1:
|
|
334
|
+
accounts = _a.sent();
|
|
335
|
+
if (address) {
|
|
336
|
+
accountU8a_1 = decodeAddress(address);
|
|
337
|
+
found = accounts.find(function (account) { return u8aEq(decodeAddress(account.address), accountU8a_1); });
|
|
338
|
+
}
|
|
339
|
+
if (!found) {
|
|
340
|
+
throw new Error("web3FromAddress: Unable to find injected ".concat(address));
|
|
341
|
+
}
|
|
342
|
+
return [2 /*return*/, web3FromSource(found.meta.source)];
|
|
343
|
+
}
|
|
344
|
+
});
|
|
345
|
+
});
|
|
203
346
|
}
|
|
204
347
|
/**
|
|
205
348
|
* @summary List all providers exposed by one source
|
|
@@ -207,13 +350,22 @@ export async function web3FromAddress(address) {
|
|
|
207
350
|
* For extensions that supply RPC providers, this call would return the list
|
|
208
351
|
* of RPC providers that any extension may supply.
|
|
209
352
|
*/
|
|
210
|
-
export
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
353
|
+
export function web3ListRpcProviders(source) {
|
|
354
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
355
|
+
var provider;
|
|
356
|
+
return __generator(this, function (_a) {
|
|
357
|
+
switch (_a.label) {
|
|
358
|
+
case 0: return [4 /*yield*/, web3FromSource(source)];
|
|
359
|
+
case 1:
|
|
360
|
+
provider = (_a.sent()).provider;
|
|
361
|
+
if (!provider) {
|
|
362
|
+
console.warn("Extension ".concat(source, " does not expose any provider"));
|
|
363
|
+
return [2 /*return*/, null];
|
|
364
|
+
}
|
|
365
|
+
return [2 /*return*/, provider.listProviders()];
|
|
366
|
+
}
|
|
367
|
+
});
|
|
368
|
+
});
|
|
217
369
|
}
|
|
218
370
|
/**
|
|
219
371
|
* @summary Start an RPC provider provider by a specific source
|
|
@@ -222,11 +374,22 @@ export async function web3ListRpcProviders(source) {
|
|
|
222
374
|
* enabled provider (initialized with the specific key) from the
|
|
223
375
|
* specified extension source.
|
|
224
376
|
*/
|
|
225
|
-
export
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
377
|
+
export function web3UseRpcProvider(source, key) {
|
|
378
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
379
|
+
var provider, meta;
|
|
380
|
+
return __generator(this, function (_a) {
|
|
381
|
+
switch (_a.label) {
|
|
382
|
+
case 0: return [4 /*yield*/, web3FromSource(source)];
|
|
383
|
+
case 1:
|
|
384
|
+
provider = (_a.sent()).provider;
|
|
385
|
+
if (!provider) {
|
|
386
|
+
throw new Error("Extension ".concat(source, " does not expose any provider"));
|
|
387
|
+
}
|
|
388
|
+
return [4 /*yield*/, provider.startProvider(key)];
|
|
389
|
+
case 2:
|
|
390
|
+
meta = _a.sent();
|
|
391
|
+
return [2 /*return*/, { meta: meta, provider: provider }];
|
|
392
|
+
}
|
|
393
|
+
});
|
|
394
|
+
});
|
|
232
395
|
}
|